Virtual whiteboard for sketching hand-drawn like diagrams
feat(editor): sticky notes (#12064)
David Luzarafa3a653fc5d
diff --git a/dev-docs/docs/@excalidraw/excalidraw/api/excalidraw-element-skeleton.mdx b/dev-docs/docs/@excalidraw/excalidraw/api/excalidraw-element-skeleton.mdxindex e1dd071eac..db3841a640 100644--- a/dev-docs/docs/@excalidraw/excalidraw/api/excalidraw-element-skeleton.mdx+++ b/dev-docs/docs/@excalidraw/excalidraw/api/excalidraw-element-skeleton.mdx@@ -274,6 +274,35 @@ convertToExcalidrawElements([+### Sticky Notes++A sticky note is an always-filled note whose label auto-fits: the font shrinks from the label's `fontSize` (the note's font ceiling) down to a minimum, and only then does the note grow in height. Only `type`, `x` and `y` are required; `width`/`height` default to a 250×250 square and `label` is optional. The note's `strokeColor` is its ink — its text and creation-date footer are always one color; a label that sets its own `strokeColor` gives it to the note. A footer band below the label shows the note's creation date (`created`); pass `created: null` for a note without one (the band stays reserved, but empty).++```js+convertToExcalidrawElements([+ {+ type: "stickynote",+ x: 100,+ y: 100,+ label: {+ text: "Remember to ship it",+ fontSize: 28,+ },+ },+ {+ type: "stickynote",+ x: 400,+ y: 100,+ width: 200,+ height: 200,+ backgroundColor: "#fcc2d7",+ strokeColor: "#c2255c",+ },+]);+```++Notes keep their invariants regardless of the properties you pass: the background is never transparent (it falls back to the default yellow), the fill is solid, and the size is at least 75×75. The height you pass is kept as the note's `baseHeight`; if a label needs more room at the minimum font size, the created note is taller.+### Labelled ArrowsSimilar to Text Containers, you can create labelled arrows as well.diff --git a/packages/common/src/colors.ts b/packages/common/src/colors.tsindex 07bf6186ed..b0d6c7d084 100644--- a/packages/common/src/colors.ts+++ b/packages/common/src/colors.ts@@ -264,6 +264,22 @@ export const BUCKET_FILL_BACKGROUND_PICKS = [COLOR_PALETTE.yellow[DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX],] as ColorTuple;+// sticky notes are their own color domain (own defaults, own picks)+export const DEFAULT_STICKY_NOTE_BG = "#ffdf6b";++export const STICKY_NOTE_STROKE_PICKS: ColorTuple =+ DEFAULT_ELEMENT_STROKE_PICKS;++// ORDER matters for positioning in quick picker. Classic note colors; the+// first one is `DEFAULT_STICKY_NOTE_BG`. Never transparent.+export const STICKY_NOTE_BACKGROUND_PICKS = [+ DEFAULT_STICKY_NOTE_BG,+ COLOR_PALETTE.pink[1],+ COLOR_PALETTE.green[1],+ COLOR_PALETTE.blue[1],+ COLOR_PALETTE.orange[1],+] as ColorTuple;+// ORDER matters for positioning in quick pickerexport const DEFAULT_CANVAS_BACKGROUND_PICKS = [COLOR_PALETTE.white,diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.tsindex a9ee944df9..4d407c988f 100644--- a/packages/common/src/constants.ts+++ b/packages/common/src/constants.ts@@ -6,6 +6,8 @@ import type { AppProps, AppState } from "@excalidraw/excalidraw/types";import { COLOR_PALETTE } from "./colors";+export { DEFAULT_STICKY_NOTE_BG } from "./colors";+export const supportsResizeObserver =typeof window !== "undefined" && "ResizeObserver" in window;@@ -69,6 +71,7 @@ export enum EVENT {POINTER_MOVE = "pointermove",POINTER_DOWN = "pointerdown",POINTER_UP = "pointerup",+ POINTER_CANCEL = "pointercancel",STATE_CHANGE = "statechange",WHEEL = "wheel",TOUCH_START = "touchstart",@@ -211,6 +214,50 @@ export const FRAME_STYLE = {export const MIN_FONT_SIZE = 1;export const DEFAULT_FONT_SIZE = 20;+export const STICKY_NOTE_MIN_FONT_SIZE = 16;+export const STICKY_NOTE_MAX_FONT_SIZE = 512;+export const STICKY_NOTE_FALLBACK_FONT_SIZE = 28;+export const STICKY_NOTE_FONT_STEP = 2;+export const STICKY_NOTE_PADDING = 16;+/**+ * The creation-date footer: a 20px text row under the label body plus a 12px+ * gap above it, inside the note's bottom padding. Reserved for every note —+ * also when `created` is unknown — so geometry never depends on data+ * availability. The label is chosen by width bucket, never measured, so+ * painting stays measurement-free (the server has no text measurer):+ * `minBodyWidthForYear` is the worst case ("30 May 2026") in the system sans+ * stack at 12px, with margin for wider fallbacks such as DejaVu Sans.+ */+/**+ * The creation-date footer of a sticky note. The label body ends `height`+ * above the note's bottom padding, and the date's baseline sits+ * `baselineFromBottom` above the note's bottom edge — so the 12px glyphs+ * (~9px above the baseline, ~3px below) end up roughly 11px from the edge+ * with a ~13px gap to the label body above them.+ */+export const STICKY_NOTE_FOOTER = {+ height: 20,+ fontSize: 12,+ fontFamily: "Helvetica, Arial, sans-serif",+ baselineFromBottom: 14,+ opacity: 1,+ minBodyWidthForYear: 80,+} as const;+/**+ * outer height → label body height: top + bottom padding + footer. The body+ * is what the label is fitted into; a middle-aligned label is still centered+ * in the whole padded note when it fits (see `computeBoundTextPosition`).+ */+export const STICKY_NOTE_BODY_INSET_Y =+ STICKY_NOTE_PADDING * 2 + STICKY_NOTE_FOOTER.height;+export const DEFAULT_STICKY_NOTE_SIZE = 250;+// floor for a finalized note's width and base height; the UI floor is font-aware+// on top of it (see `getStickyNoteMinSize`)+export const STICKY_NOTE_MIN_SIZE = 75;+export const STICKY_NOTE_SHADOW_OFFSET = 3;+export const STICKY_NOTE_SHADOW_OPACITY = 0.16;+export const STICKY_NOTE_EDGE_SHADOW_WIDTH = 0.5;+export const STICKY_NOTE_EDGE_SHADOW_OPACITY = 0.08;export const DEFAULT_FONT_FAMILY: FontFamilyValues = FONT_FAMILY.Excalifont;export const DEFAULT_TEXT_ALIGN = "left";export const DEFAULT_VERTICAL_ALIGN = "top";@@ -497,6 +544,7 @@ export const TOOL_TYPE = {hand: "hand",frame: "frame",magicframe: "magicframe",+ stickynote: "stickynote",embeddable: "embeddable",laser: "laser",autoshape: "autoshape",diff --git a/packages/common/src/keys.ts b/packages/common/src/keys.tsindex ac4cabe1ff..59fe05a829 100644--- a/packages/common/src/keys.ts+++ b/packages/common/src/keys.ts@@ -60,6 +60,7 @@ export const KEYS = {H: "h",I: "i",L: "l",+ N: "n",O: "o",P: "p",Q: "q",diff --git a/packages/common/src/random.ts b/packages/common/src/random.tsindex 4a4424a76d..581cf79cae 100644--- a/packages/common/src/random.ts+++ b/packages/common/src/random.ts@@ -14,3 +14,20 @@ export const reseed = (seed: number) => {};export const randomId = () => (isTestEnv() ? `id${testIdBase++}` : nanoid());++/**+ * Deterministic PRNG (mulberry32) for a given seed: same seed, same+ * sequence — used where a render must be stable across frames and clients+ * (e.g. the sticky note's corner jitter) and roughjs's `Random` is+ * unsuitable (it degenerates for seed 0). Returns numbers in [0, 1).+ */+export const seededRandom = (seed: number) => {+ let value = seed >>> 0;+ return () => {+ value += 0x6d2b79f5;+ let next = value;+ next = Math.imul(next ^ (next >>> 15), next | 1);+ next ^= next + Math.imul(next ^ (next >>> 7), next | 61);+ return ((next ^ (next >>> 14)) >>> 0) / 4294967296;+ };+};diff --git a/packages/element/src/__tests__/__snapshots__/transform.test.ts.snap b/packages/element/src/__tests__/__snapshots__/transform.test.ts.snapindex a61cd0fc44..5488f6448b 100644--- a/packages/element/src/__tests__/__snapshots__/transform.test.ts.snap+++ b/packages/element/src/__tests__/__snapshots__/transform.test.ts.snap@@ -247,6 +247,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": [{"id": "id50",@@ -295,6 +296,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": [{"id": "id50",@@ -410,6 +412,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id50","created": 1,@@ -520,6 +523,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id39","created": 1,@@ -706,6 +710,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id43","created": 1,@@ -749,6 +754,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": [{"id": "id43",@@ -797,6 +803,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": [{"id": "id43",@@ -1268,6 +1275,7 @@ exports[`Test Transform > should transform text element 1`] = `"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -1311,6 +1319,7 @@ exports[`Test Transform > should transform text element 2`] = `"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -1664,6 +1673,7 @@ exports[`Test Transform > should transform the elements correctly when linear el"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "B","created": 1,@@ -1709,6 +1719,7 @@ exports[`Test Transform > should transform the elements correctly when linear el"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "A","created": 1,@@ -1754,6 +1765,7 @@ exports[`Test Transform > should transform the elements correctly when linear el"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "Alice","created": 1,@@ -1799,6 +1811,7 @@ exports[`Test Transform > should transform the elements correctly when linear el"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "Bob","created": 1,@@ -1844,6 +1857,7 @@ exports[`Test Transform > should transform the elements correctly when linear el"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "Bob_Alice","created": 1,@@ -1887,6 +1901,7 @@ exports[`Test Transform > should transform the elements correctly when linear el"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "Bob_B","created": 1,@@ -2142,6 +2157,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id25","created": 1,@@ -2185,6 +2201,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id26","created": 1,@@ -2228,6 +2245,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id27","created": 1,@@ -2272,6 +2290,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id28","created": 1,@@ -2544,6 +2563,7 @@ exports[`Test Transform > should transform to text containers when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id13","created": 1,@@ -2587,6 +2607,7 @@ exports[`Test Transform > should transform to text containers when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id14","created": 1,@@ -2631,6 +2652,7 @@ exports[`Test Transform > should transform to text containers when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id15","created": 1,@@ -2677,6 +2699,7 @@ exports[`Test Transform > should transform to text containers when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id16","created": 1,@@ -2721,6 +2744,7 @@ exports[`Test Transform > should transform to text containers when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id17","created": 1,@@ -2766,6 +2790,7 @@ exports[`Test Transform > should transform to text containers when label provide"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id18","created": 1,diff --git a/packages/element/src/__tests__/flowchart.test.ts b/packages/element/src/__tests__/flowchart.test.tsnew file mode 100644index 0000000000..5f49dd751c--- /dev/null+++ b/packages/element/src/__tests__/flowchart.test.ts@@ -0,0 +1,60 @@+import { ROUNDNESS } from "@excalidraw/common";++import type { AppState } from "@excalidraw/excalidraw/types";++import { Scene } from "../Scene";+import { addNewNodes } from "../flowchart";+import { newStickyNoteElement } from "../newElement";+import { isFlowchartNodeElement, isStickyNoteElement } from "../typeChecks";++describe("flowchart", () => {+ it("creates connected sticky notes", () => {+ const sticky = newStickyNoteElement({+ type: "stickynote",+ x: 100,+ y: 100,+ width: 240,+ height: 260,+ baseHeight: 220,+ roundness: { type: ROUNDNESS.PROPORTIONAL_RADIUS },+ roughness: 2,+ backgroundColor: "#ffec99",+ strokeColor: "#1e1e1e",+ strokeWidth: 2,+ });+ const scene = new Scene([sticky], { skipValidation: true });+ const {+ nodes: [nextNode, bindingArrow],+ } = addNewNodes(+ sticky,+ {+ currentItemEndArrowhead: "arrow",+ } as AppState,+ "right",+ scene,+ 1,+ );++ expect(isFlowchartNodeElement(sticky)).toBe(true);+ expect(isFlowchartNodeElement(nextNode)).toBe(true);+ expect(isStickyNoteElement(nextNode)).toBe(true);+ expect(nextNode).toMatchObject({+ type: "stickynote",+ x: sticky.x + sticky.width + 100,+ y: sticky.y,+ width: sticky.width,+ height: sticky.height,+ baseHeight: sticky.baseHeight,+ roundness: sticky.roundness,+ roughness: sticky.roughness,+ backgroundColor: sticky.backgroundColor,+ strokeColor: sticky.strokeColor,+ strokeWidth: sticky.strokeWidth,+ });+ expect(bindingArrow).toMatchObject({+ type: "arrow",+ startBinding: { elementId: sticky.id },+ endBinding: { elementId: nextNode.id },+ });+ });+});diff --git a/packages/element/src/__tests__/stickyNote.test.ts b/packages/element/src/__tests__/stickyNote.test.tsnew file mode 100644index 0000000000..a8d8e58e81--- /dev/null+++ b/packages/element/src/__tests__/stickyNote.test.ts@@ -0,0 +1,1129 @@+import {+ DEFAULT_STICKY_NOTE_SIZE,+ FONT_FAMILY,+ MIN_FONT_SIZE,+ ROUNDNESS,+ STICKY_NOTE_FALLBACK_FONT_SIZE,+ STICKY_NOTE_MAX_FONT_SIZE,+ STICKY_NOTE_MIN_FONT_SIZE,+ STICKY_NOTE_BODY_INSET_Y,+ STICKY_NOTE_FOOTER,+ STICKY_NOTE_MIN_SIZE,+ STICKY_NOTE_PADDING,+ VERTICAL_ALIGN,+ arrayToMap,+} from "@excalidraw/common";+import {+ lineSegment,+ pointFrom,+ pointRotateRads,+ type GlobalPoint,+ type Radians,+} from "@excalidraw/math";+import { vi } from "vitest";++import { Scene } from "../Scene";+import { intersectElementWithLineSegment } from "../collision";+import { newElementWith } from "../mutateElement";+import {+ newElement,+ newStickyNoteElement,+ newTextElement,+} from "../newElement";+import { resizeMultipleElements, resizeSingleElement } from "../resizeElements";+import {+ getStickyNoteLayout,+ getStickyNoteCornerRadius,+ getStickyNoteDateLabel,+ getStickyNoteFooter,+ getStickyNoteMinSize,+ syncStickyNoteInk,+ normalizeStickyNoteFontSize,+ updateStickyNoteLayout,+} from "../stickyNote";+import * as textMeasurements from "../textMeasurements";+import {+ computeBoundTextPosition,+ getBoundTextMaxHeight,+ redrawTextBoundingBox,+} from "../textElement";++import type {+ ExcalidrawElement,+ ExcalidrawStickyNoteElement,+ ExcalidrawTextElementWithContainer,+ NonDeleted,+} from "../types";++const STICKY_FONT_SIZE = 28;++const getSticky = (scene: Scene, id: string) =>+ scene.getNonDeletedElement(id) as NonDeleted<ExcalidrawStickyNoteElement>;++const getBoundText = (scene: Scene, id: string) =>+ scene.getNonDeletedElement(+ id,+ ) as NonDeleted<ExcalidrawTextElementWithContainer>;++const createStickyWithText = (+ originalText: string,+ extraElements: ExcalidrawElement[] = [],+) => {+ const baseSticky = newStickyNoteElement({+ type: "stickynote",+ x: 100,+ y: 100,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ });+ const text = newTextElement({+ x: baseSticky.x + baseSticky.width / 2,+ y: baseSticky.y + baseSticky.height / 2,+ text: originalText,+ originalText,+ fontSize: STICKY_FONT_SIZE,+ baseFontSize: STICKY_FONT_SIZE,+ textAlign: "center",+ verticalAlign: VERTICAL_ALIGN.MIDDLE,+ containerId: baseSticky.id,+ autoResize: true,+ });+ const sticky = newElementWith(baseSticky, {+ boundElements: [{ type: "text", id: text.id }],+ });+ const scene = new Scene([sticky, text, ...extraElements], {+ skipValidation: true,+ });+ const sceneSticky = getSticky(scene, sticky.id);+ const sceneText = getBoundText(scene, text.id);++ redrawTextBoundingBox(sceneText, sceneSticky, scene);++ return {+ scene,+ stickyId: sticky.id,+ textId: text.id,+ };+};++describe("sticky note text layout", () => {+ it("preserves rounded corners with reduced radius", () => {+ const sticky = newStickyNoteElement({+ type: "stickynote",+ x: 0,+ y: 0,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ roundness: { type: ROUNDNESS.PROPORTIONAL_RADIUS },+ });++ expect(sticky.roundness).toEqual({ type: ROUNDNESS.PROPORTIONAL_RADIUS });+ expect(getStickyNoteCornerRadius(sticky)).toBeLessThan(+ DEFAULT_STICKY_NOTE_SIZE * 0.25,+ );+ });++ it("uses reduced rounded corners for binding intersections", () => {+ const sticky = newStickyNoteElement({+ type: "stickynote",+ x: 0,+ y: 0,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ roundness: { type: ROUNDNESS.PROPORTIONAL_RADIUS },+ });+ const elementsMap = arrayToMap([sticky]);+ const intersection = intersectElementWithLineSegment(+ sticky,+ elementsMap,+ lineSegment<GlobalPoint>(+ pointFrom<GlobalPoint>(+ sticky.x + sticky.width / 2,+ sticky.y + sticky.height / 2,+ ),+ pointFrom<GlobalPoint>(sticky.x - 10, sticky.y - 10),+ ),+ 0,+ true,+ )[0];++ expect(intersection[0]).toBeLessThan(getStickyNoteCornerRadius(sticky));+ expect(intersection[1]).toBeLessThan(getStickyNoteCornerRadius(sticky));+ });++ it("preserves roughness for render-only shape variation", () => {+ const sticky = newStickyNoteElement({+ type: "stickynote",+ x: 0,+ y: 0,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ roughness: 2,+ });++ expect(sticky.roughness).toBe(2);+ });++ it("respects user font size below the sticky note minimum font size", () => {+ const fontSize = STICKY_NOTE_MIN_FONT_SIZE - 1;+ const { scene, textId } = createStickyWithText("short");+ const text = getBoundText(scene, textId);++ scene.mutateElement(text, {+ fontSize,+ baseFontSize: fontSize,+ });++ const layout = getStickyNoteLayout(+ getSticky(scene, text.containerId),+ text,+ );++ expect(layout.text!.fontSize).toBe(fontSize);+ });++ it("normalizes non-finite and out-of-range font ceilings", () => {+ expect(normalizeStickyNoteFontSize(NaN)).toBe(+ STICKY_NOTE_FALLBACK_FONT_SIZE,+ );+ expect(normalizeStickyNoteFontSize(Infinity)).toBe(+ STICKY_NOTE_FALLBACK_FONT_SIZE,+ );+ expect(normalizeStickyNoteFontSize(-Infinity)).toBe(+ STICKY_NOTE_FALLBACK_FONT_SIZE,+ );+ expect(normalizeStickyNoteFontSize(1e20)).toBe(STICKY_NOTE_MAX_FONT_SIZE);+ expect(normalizeStickyNoteFontSize(0)).toBe(MIN_FONT_SIZE);+ expect(normalizeStickyNoteFontSize(24)).toBe(24);+ });++ it("terminates the font fit for pathological font ceilings", () => {+ const { scene, textId } = createStickyWithText("some text that must wrap");+ const text = getBoundText(scene, textId);++ // 1e20 - STICKY_NOTE_FONT_STEP === 1e20 in doubles: without the ceiling+ // clamp the descent loop would never progress+ for (const baseFontSize of [1e20, Infinity, NaN]) {+ scene.mutateElement(text, { baseFontSize });++ const layout = getStickyNoteLayout(+ getSticky(scene, text.containerId),+ text,+ );++ expect(Number.isFinite(layout.text!.fontSize)).toBe(true);+ expect(layout.text!.fontSize).toBeLessThanOrEqual(+ STICKY_NOTE_MAX_FONT_SIZE,+ );+ expect(Number.isFinite(layout.container.height)).toBe(true);+ }+ });++ it("downscales font to fit the base size before growing height", () => {+ const sevenBaseHeightLines = Array(7).fill("abcdefghij").join("\n");+ const { scene, stickyId, textId } =+ createStickyWithText(sevenBaseHeightLines);+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);++ expect(sticky.width).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(sticky.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(sticky.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(text.x - sticky.x).toBeGreaterThanOrEqual(STICKY_NOTE_PADDING);+ expect(text.y - sticky.y).toBeGreaterThanOrEqual(STICKY_NOTE_PADDING);+ expect(text.fontSize).toBeLessThan(text.baseFontSize!);+ expect(text.fontSize).toBeGreaterThan(STICKY_NOTE_MIN_FONT_SIZE);+ });++ it("grows downward at min font and shrinks back to base when text is deleted", () => {+ const overflowingText = Array(40)+ .fill("abcdefghijklmnopqrstuvwx")+ .join("\n");+ const { scene, stickyId, textId } = createStickyWithText(overflowingText);+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);++ expect(text.fontSize).toBe(STICKY_NOTE_MIN_FONT_SIZE);+ expect(sticky.height).toBeGreaterThan(sticky.baseHeight);+ expect(sticky.y).toBe(100);++ scene.mutateElement(text, {+ originalText: "short",+ text: "short",+ });+ redrawTextBoundingBox(text, sticky, scene);++ const updatedSticky = getSticky(scene, stickyId);+ const updatedText = getBoundText(scene, textId);++ expect(updatedSticky.height).toBe(updatedSticky.baseHeight);+ expect(updatedSticky.y).toBe(100);+ expect(updatedText.fontSize).toBe(updatedText.baseFontSize);+ });++ it("keeps the bottom edge anchored when a north resize is content-pinned", () => {+ const overflowingText = Array(40)+ .fill("abcdefghijklmnopqrstuvwx")+ .join("\n");+ const { scene, stickyId, textId } = createStickyWithText(overflowingText);+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const originalSticky = { ...sticky };+ const originalText = { ...text };+ const originalElementsMap = arrayToMap([originalSticky, originalText]);+ const originalBottom = sticky.y + sticky.height;++ // drag the "n" handle downward past the content minimum — the note+ // must rubber-band in place instead of translating down+ resizeSingleElement(+ sticky.width,+ sticky.height - 100,+ sticky,+ originalSticky,+ originalElementsMap,+ scene,+ "n",+ );++ const updatedSticky = getSticky(scene, stickyId);++ expect(updatedSticky.height).toBeCloseTo(originalSticky.height);+ expect(updatedSticky.y).toBeCloseTo(originalSticky.y);+ expect(updatedSticky.y + updatedSticky.height).toBeCloseTo(originalBottom);+ expect(updatedSticky.baseHeight).toBeCloseTo(originalSticky.height - 100);+ });++ it("keeps the requested height as the base when a corner drag is content-pinned", () => {+ const overflowingText = Array(40)+ .fill("abcdefghijklmnopqrstuvwx")+ .join("\n");+ const { scene, stickyId, textId } = createStickyWithText(overflowingText);+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const originalSticky = { ...sticky };+ const originalText = { ...text };+ const originalElementsMap = arrayToMap([originalSticky, originalText]);+ const nextWidth = 120;+ const nextHeight = DEFAULT_STICKY_NOTE_SIZE;+ const expectedLayout = getStickyNoteLayout(+ {+ ...sticky,+ width: nextWidth,+ height: nextHeight,+ baseHeight: nextHeight,+ },+ text,+ );++ resizeSingleElement(+ nextWidth,+ nextHeight,+ sticky,+ originalSticky,+ originalElementsMap,+ scene,+ "se",+ );++ const updatedSticky = getSticky(scene, stickyId);+ const updatedText = getBoundText(scene, textId);++ expect(updatedSticky.width).toBe(nextWidth);+ // the note refuses to shrink below its content, but the user's intent is+ // remembered as the base: delete the text later and it snaps to 250+ expect(updatedSticky.baseHeight).toBe(nextHeight);+ expect(updatedSticky.height).toBeCloseTo(expectedLayout.container.height);+ expect(updatedSticky.height).toBeGreaterThan(nextHeight);+ // "se" holds the top-left corner+ expect(updatedSticky.y).toBeCloseTo(originalSticky.y);+ expect(updatedText.fontSize).toBe(originalText.fontSize);+ expect(updatedText.baseFontSize).toBe(originalText.baseFontSize);+ });++ it("scales the note, its base height and its font ceiling on a proportional resize", () => {+ const { scene, stickyId, textId } = createStickyWithText("short");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const originalSticky = { ...sticky };+ const originalElementsMap = arrayToMap([originalSticky, { ...text }]);++ // Shift + east handle: both axes scale, and the label with them+ resizeSingleElement(+ 500,+ 500,+ sticky,+ originalSticky,+ originalElementsMap,+ scene,+ "e",+ { shouldMaintainAspectRatio: true },+ );++ const updatedSticky = getSticky(scene, stickyId);+ const updatedText = getBoundText(scene, textId);++ expect(updatedSticky.width).toBe(500);+ expect(updatedSticky.height).toBe(500);+ expect(updatedSticky.baseHeight).toBe(500);+ expect(updatedText.baseFontSize).toBe(STICKY_FONT_SIZE * 2);+ expect(updatedText.fontSize).toBe(STICKY_FONT_SIZE * 2);+ });++ it("keeps the base height on a width-only drag of a content-grown note", () => {+ const overflowingText = Array(40)+ .fill("abcdefghijklmnopqrstuvwx")+ .join("\n");+ const { scene, stickyId, textId } = createStickyWithText(overflowingText);+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const originalSticky = { ...sticky };+ const originalElementsMap = arrayToMap([originalSticky, { ...text }]);++ expect(sticky.height).toBeGreaterThan(sticky.baseHeight);++ resizeSingleElement(+ 400,+ sticky.height,+ sticky,+ originalSticky,+ originalElementsMap,+ scene,+ "e",+ );++ const updatedSticky = getSticky(scene, stickyId);++ expect(updatedSticky.width).toBe(400);+ expect(updatedSticky.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(updatedSticky.height).toBeGreaterThan(updatedSticky.baseHeight);+ expect(updatedSticky.y).toBe(100);+ });++ it("restores the gesture-start base height and ceiling when Shift is released mid-gesture", () => {+ const { scene, stickyId, textId } = createStickyWithText("short");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const originalSticky = { ...sticky };+ const originalElementsMap = arrayToMap([originalSticky, { ...text }]);++ // first pointer-move with Shift: everything scales ×2+ resizeSingleElement(+ 500,+ 500,+ sticky,+ originalSticky,+ originalElementsMap,+ scene,+ "se",+ { shouldMaintainAspectRatio: true },+ );+ expect(getSticky(scene, stickyId).baseHeight).toBe(500);+ expect(getBoundText(scene, textId).baseFontSize).toBe(STICKY_FONT_SIZE * 2);++ // Shift released, same gesture: the ceiling goes back to the+ // gesture-start value instead of compounding from the live 56+ resizeSingleElement(+ 400,+ 300,+ getSticky(scene, stickyId),+ originalSticky,+ originalElementsMap,+ scene,+ "se",+ );+ expect(getSticky(scene, stickyId).width).toBe(400);+ expect(getSticky(scene, stickyId).baseHeight).toBe(300);+ expect(getBoundText(scene, textId).baseFontSize).toBe(STICKY_FONT_SIZE);+ expect(getBoundText(scene, textId).fontSize).toBe(STICKY_FONT_SIZE);++ // and a width-only move restores the gesture-start base height too+ resizeSingleElement(+ 350,+ DEFAULT_STICKY_NOTE_SIZE,+ getSticky(scene, stickyId),+ originalSticky,+ originalElementsMap,+ scene,+ "e",+ );+ expect(getSticky(scene, stickyId).baseHeight).toBe(+ DEFAULT_STICKY_NOTE_SIZE,+ );+ });++ it("flips a rotated note without promoting its grown height or losing the label's angle", () => {+ const overflowingText = Array(40)+ .fill("abcdefghijklmnopqrstuvwx")+ .join("\n");+ const { scene, stickyId, textId } = createStickyWithText(overflowingText);+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ scene.mutateElement(sticky, { angle: 0.5 as Radians });+ scene.mutateElement(text, { angle: 0.5 as Radians });+ const grownHeight = sticky.height;+ expect(grownHeight).toBeGreaterThan(sticky.baseHeight);+ const originalElementsMap = arrayToMap([{ ...sticky }, { ...text }]);++ resizeMultipleElements(+ [sticky, text],+ scene.getNonDeletedElementsMap(),+ "nw",+ scene,+ originalElementsMap,+ {+ flipByX: true,+ shouldResizeFromCenter: true,+ shouldMaintainAspectRatio: true,+ },+ );++ const updatedSticky = getSticky(scene, stickyId);+ const updatedText = getBoundText(scene, textId);++ expect(updatedSticky.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(updatedSticky.height).toBeCloseTo(grownHeight);+ expect(updatedText.baseFontSize).toBe(STICKY_FONT_SIZE);+ expect(updatedSticky.angle).not.toBeCloseTo(0.5);+ expect(updatedText.angle).toBeCloseTo(updatedSticky.angle);+ });++ it("syncs the base height of an empty note on a multi-select resize", () => {+ const sticky = newStickyNoteElement({+ type: "stickynote",+ x: 0,+ y: 0,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ });+ const rectangle = newElement({+ type: "rectangle",+ x: 300,+ y: 0,+ width: 100,+ height: 100,+ });+ const scene = new Scene([sticky, rectangle], { skipValidation: true });+ const originalElementsMap = arrayToMap([{ ...sticky }, { ...rectangle }]);++ resizeMultipleElements(+ scene.getNonDeletedElements(),+ scene.getNonDeletedElementsMap(),+ "se",+ scene,+ originalElementsMap,+ { nextWidth: 800, nextHeight: 500 },+ );++ const updatedSticky = getSticky(scene, sticky.id);++ expect(updatedSticky.height).toBe(500);+ expect(updatedSticky.baseHeight).toBe(500);+ });++ it("keeps the center on an Alt (center) resize that is content-pinned", () => {+ const overflowingText = Array(40)+ .fill("abcdefghijklmnopqrstuvwx")+ .join("\n");+ const { scene, stickyId, textId } = createStickyWithText(overflowingText);+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const originalSticky = { ...sticky };+ const originalElementsMap = arrayToMap([originalSticky, { ...text }]);+ const centerY = sticky.y + sticky.height / 2;++ for (const handle of ["n", "s"] as const) {+ resizeSingleElement(+ sticky.width,+ originalSticky.height - 100,+ getSticky(scene, stickyId),+ originalSticky,+ originalElementsMap,+ scene,+ handle,+ { shouldResizeFromCenter: true },+ );+ const updated = getSticky(scene, stickyId);+ // content-pinned: the height springs back, but around the center+ expect(updated.height).toBeCloseTo(originalSticky.height);+ expect(updated.y + updated.height / 2).toBeCloseTo(centerY);+ expect(updated.baseHeight).toBeCloseTo(originalSticky.height - 100);+ }+ });++ it("scales the label's ceiling on a proportional multi-select resize", () => {+ const rectangle = newElement({+ type: "rectangle",+ x: 400,+ y: 100,+ width: 100,+ height: DEFAULT_STICKY_NOTE_SIZE,+ });+ const { scene, stickyId, textId } = createStickyWithText("short", [+ rectangle,+ ]);+ const originalElementsMap = arrayToMap(+ scene.getNonDeletedElements().map((element) => ({ ...element })),+ );++ // selection bbox is 400×250; a labeled note forces aspect lock anyway+ resizeMultipleElements(+ scene.getNonDeletedElements(),+ scene.getNonDeletedElementsMap(),+ "se",+ scene,+ originalElementsMap,+ { nextWidth: 800, nextHeight: 500, shouldMaintainAspectRatio: true },+ );++ const updatedSticky = getSticky(scene, stickyId);+ const updatedText = getBoundText(scene, textId);+ expect(updatedSticky.width).toBe(500);+ expect(updatedSticky.height).toBe(500);+ expect(updatedSticky.baseHeight).toBe(500);+ expect(updatedText.baseFontSize).toBe(STICKY_FONT_SIZE * 2);+ expect(updatedText.fontSize).toBe(STICKY_FONT_SIZE * 2);+ });++ it("uses the requested height as the base on a free multi-select resize of an empty note", () => {+ const sticky = newStickyNoteElement({+ type: "stickynote",+ x: 0,+ y: 0,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ });+ const rectangle = newElement({+ type: "rectangle",+ x: 300,+ y: 0,+ width: 100,+ height: DEFAULT_STICKY_NOTE_SIZE,+ });+ const scene = new Scene([sticky, rectangle], { skipValidation: true });+ const originalElementsMap = arrayToMap([{ ...sticky }, { ...rectangle }]);++ // 2× wide, 1.5× tall — nothing in the selection forces aspect lock+ resizeMultipleElements(+ scene.getNonDeletedElements(),+ scene.getNonDeletedElementsMap(),+ "se",+ scene,+ originalElementsMap,+ { nextWidth: 800, nextHeight: 375 },+ );++ const updated = getSticky(scene, sticky.id);+ expect(updated.width).toBe(500);+ expect(updated.height).toBe(375);+ expect(updated.baseHeight).toBe(375);+ });++ it("restores everything when a proportional gesture returns to scale 1", () => {+ const { scene, stickyId, textId } = createStickyWithText("short");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const originalSticky = { ...sticky };+ const originalElementsMap = arrayToMap([originalSticky, { ...text }]);++ resizeSingleElement(+ 500,+ 500,+ sticky,+ originalSticky,+ originalElementsMap,+ scene,+ "se",+ {+ shouldMaintainAspectRatio: true,+ },+ );+ resizeSingleElement(+ DEFAULT_STICKY_NOTE_SIZE,+ DEFAULT_STICKY_NOTE_SIZE,+ getSticky(scene, stickyId),+ originalSticky,+ originalElementsMap,+ scene,+ "se",+ { shouldMaintainAspectRatio: true },+ );++ const updatedSticky = getSticky(scene, stickyId);+ const updatedText = getBoundText(scene, textId);+ expect(updatedSticky.width).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(updatedSticky.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(updatedText.baseFontSize).toBe(STICKY_FONT_SIZE);+ expect(updatedText.fontSize).toBe(STICKY_FONT_SIZE);+ });++ it("keeps the rotated top edge in place while the note grows", () => {+ const { scene, stickyId, textId } = createStickyWithText("short");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ scene.mutateElement(sticky, { angle: 0.6 as Radians });+ scene.mutateElement(text, { angle: 0.6 as Radians });+ const topEdgeMidpoint = (element: ExcalidrawStickyNoteElement) =>+ pointRotateRads(+ pointFrom(element.x + element.width / 2, element.y),+ pointFrom(+ element.x + element.width / 2,+ element.y + element.height / 2,+ ),+ element.angle,+ );+ const before = topEdgeMidpoint(sticky);+ const heightBefore = sticky.height;++ updateStickyNoteLayout(sticky, scene, {+ originalText: Array(40).fill("abcdefghijklmnopqrstuvwx").join("\n"),+ });++ const after = getSticky(scene, stickyId);+ expect(after.height).toBeGreaterThan(heightBefore);+ const [x, y] = topEdgeMidpoint(after);+ expect(x).toBeCloseTo(before[0]);+ expect(y).toBeCloseTo(before[1]);+ });++ it("fits in a handful of measurements: a warm keystroke in ≤ 2, a cold search in ≤ 12", () => {+ const { scene, stickyId, textId } = createStickyWithText("hello world");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const measure = vi.spyOn(textMeasurements, "measureText");++ measure.mockClear();+ getStickyNoteLayout(sticky, text, { originalText: "hello world!" });+ expect(measure.mock.calls.length).toBeLessThanOrEqual(2);++ // nothing fits at a 512 ceiling: the descent used to take ~250 passes+ measure.mockClear();+ getStickyNoteLayout(+ sticky,+ { ...text, fontSize: STICKY_NOTE_MAX_FONT_SIZE },+ {+ originalText: Array(40).fill("abcdefghijklmnopqrstuvwx").join("\n"),+ baseFontSize: STICKY_NOTE_MAX_FONT_SIZE,+ },+ );+ expect(measure.mock.calls.length).toBeLessThanOrEqual(12);+ measure.mockRestore();+ });++ it("honors a lowered ceiling even when the old fitted size still fits", () => {+ const { scene, stickyId, textId } = createStickyWithText("short");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ expect(text.fontSize).toBe(STICKY_FONT_SIZE);++ const layout = getStickyNoteLayout(sticky, text, { baseFontSize: 20 });++ expect(layout.text!.fontSize).toBe(20);+ expect(layout.text!.baseFontSize).toBe(20);+ });++ it("keeps odd and fractional ceilings reachable and stays on the ceiling-anchored grid", () => {+ const { scene, stickyId, textId } = createStickyWithText("short");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);++ expect(+ getStickyNoteLayout(sticky, text, { baseFontSize: 27 }).text!.fontSize,+ ).toBe(27);+ expect(+ getStickyNoteLayout(sticky, text, { baseFontSize: 27.5 }).text!.fontSize,+ ).toBe(27.5);++ const overflowing = Array(7).fill("abcdefghij").join("\n");+ const fitted = getStickyNoteLayout(sticky, text, {+ originalText: overflowing,+ baseFontSize: 27,+ }).text!.fontSize;+ expect(fitted).toBeLessThan(27);+ expect(+ fitted === STICKY_NOTE_MIN_FONT_SIZE || (27 - fitted) % 2 === 0,+ ).toBe(true);+ });++ it("sizes the minimum note to fit one line at the ceiling", () => {+ // a 25px line (20 × 1.25): the constant floor wins horizontally, the+ // footer pushes the height above it+ expect(+ getStickyNoteMinSize({+ fontSize: 20,+ fontFamily: FONT_FAMILY.Excalifont,+ }),+ ).toEqual({+ width: STICKY_NOTE_MIN_SIZE,+ height: 25 + STICKY_NOTE_BODY_INSET_Y,+ });+ // a 60px line (48 × 1.25)+ expect(+ getStickyNoteMinSize({+ fontSize: 48,+ fontFamily: FONT_FAMILY.Excalifont,+ }),+ ).toEqual({+ width: 60 + STICKY_NOTE_PADDING * 2,+ height: 60 + STICKY_NOTE_BODY_INSET_Y,+ });+ });++ it("never resizes a note below one line at its ceiling plus the footer", () => {+ const { scene, stickyId } = createStickyWithText("A");+ const sticky = getSticky(scene, stickyId);+ const originalElementsMap = arrayToMap(+ scene.getNonDeletedElements().map((element) => ({ ...element })),+ );+ // 28 × 1.25 = 35px line: 75 wide (floor), 35 + the vertical inset high+ const minSize = getStickyNoteMinSize({+ fontSize: STICKY_FONT_SIZE,+ fontFamily: FONT_FAMILY.Excalifont,+ });+ expect(minSize).toEqual({+ width: STICKY_NOTE_MIN_SIZE,+ height: 35 + STICKY_NOTE_BODY_INSET_Y,+ });++ resizeSingleElement(+ 40,+ 40,+ sticky,+ { ...sticky },+ originalElementsMap,+ scene,+ "se",+ );++ const resized = getSticky(scene, stickyId);+ expect(resized.width).toBe(minSize.width);+ expect(resized.baseHeight).toBe(minSize.height);+ expect(resized.height).toBe(minSize.height);+ scene.destroy();+ });++ it("flips a proportional corner resize over the far side, like a rectangle", () => {+ // the SE corner dragged up past the top edge: the note mirrors over its+ // top side at the dragged size (clamping the axes one by one used to pin+ // the height at its minimum under a still-growing width)+ const { scene, stickyId, textId } = createStickyWithText("A");+ const sticky = getSticky(scene, stickyId);+ const originalElementsMap = arrayToMap(+ scene.getNonDeletedElements().map((element) => ({ ...element })),+ );++ resizeSingleElement(+ 400,+ -400,+ sticky,+ { ...sticky },+ originalElementsMap,+ scene,+ "se",+ { shouldMaintainAspectRatio: true },+ );++ const resized = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ expect(resized.width).toBe(400);+ expect(resized.height).toBe(400);+ expect(resized.x).toBe(100);+ // mirrored over the original top edge (y = 100)+ expect(resized.y).toBe(100 - 400);+ expect(text.baseFontSize).toBeCloseTo(STICKY_FONT_SIZE * (400 / 250));+ // the label is laid out inside the flipped note, upright+ expect(text.angle).toBe(0);+ expect(text.y).toBeGreaterThan(resized.y);+ expect(text.y + text.height).toBeLessThan(resized.y + resized.height);+ scene.destroy();+ });++ it("keeps a proportional shrink below the minimum proportional", () => {+ const { scene, stickyId } = createStickyWithText("A");+ const sticky = getSticky(scene, stickyId);+ const originalElementsMap = arrayToMap(+ scene.getNonDeletedElements().map((element) => ({ ...element })),+ );++ resizeSingleElement(+ 60,+ 60,+ sticky,+ { ...sticky },+ originalElementsMap,+ scene,+ "se",+ { shouldMaintainAspectRatio: true },+ );++ const resized = getSticky(scene, stickyId);+ // one scale for both axes, so the square is kept through the clamp+ expect(resized.width).toBeCloseTo(resized.height);+ expect(resized.height).toBeGreaterThanOrEqual(+ 35 + STICKY_NOTE_BODY_INSET_Y,+ );+ scene.destroy();+ });++ it("flips a free edge resize over the far side", () => {+ const { scene, stickyId } = createStickyWithText("A");+ const sticky = getSticky(scene, stickyId);+ const originalElementsMap = arrayToMap(+ scene.getNonDeletedElements().map((element) => ({ ...element })),+ );++ // the east edge dragged left, 300px past the west edge+ resizeSingleElement(+ -300,+ sticky.height,+ sticky,+ { ...sticky },+ originalElementsMap,+ scene,+ "e",+ );++ const resized = getSticky(scene, stickyId);+ expect(resized.width).toBe(300);+ expect(resized.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(resized.x).toBe(100 - 300);+ scene.destroy();+ });++ it("applies the minimum to a flipped size's magnitude", () => {+ const { scene, stickyId } = createStickyWithText("A");+ const sticky = getSticky(scene, stickyId);+ const originalElementsMap = arrayToMap(+ scene.getNonDeletedElements().map((element) => ({ ...element })),+ );++ // just past the west edge: the mirrored note is the minimum wide+ resizeSingleElement(+ -10,+ sticky.height,+ sticky,+ { ...sticky },+ originalElementsMap,+ scene,+ "e",+ );++ const resized = getSticky(scene, stickyId);+ expect(resized.width).toBe(STICKY_NOTE_MIN_SIZE);+ expect(resized.x).toBe(100 - STICKY_NOTE_MIN_SIZE);+ scene.destroy();+ });++ it.each([0, Math.PI / 4, Math.PI / 2])(+ "centers a middle-aligned label in the whole note, footer ignored, at angle %s",+ (angle) => {+ const { scene, stickyId, textId } = createStickyWithText("Balanced");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ scene.mutateElement(sticky, { angle: angle as Radians });+ redrawTextBoundingBox(text, sticky, scene);++ // the label's center is the note's center, not the center of the body+ // above the footer (which would sit half a footer higher)+ const [centerX, centerY] = pointRotateRads(+ pointFrom(text.x + text.width / 2, text.y + text.height / 2),+ pointFrom(sticky.x + sticky.width / 2, sticky.y + sticky.height / 2),+ -angle as Radians,+ );+ expect(centerX).toBeCloseTo(sticky.x + sticky.width / 2);+ expect(centerY).toBeCloseTo(sticky.y + sticky.height / 2);+ scene.destroy();+ },+ );++ it("pushes a middle-aligned label up only once centering would overlap the footer", () => {+ const { scene, stickyId, textId } = createStickyWithText("Tall");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ const elementsMap = scene.getNonDeletedElementsMap();+ const paddedHeight = sticky.height - STICKY_NOTE_PADDING * 2;+ const bodyBottom =+ sticky.y ++ sticky.height -+ STICKY_NOTE_PADDING -+ STICKY_NOTE_FOOTER.height;++ // fits centered with room to spare above the footer+ const short = { ...text, height: 100 };+ expect(computeBoundTextPosition(sticky, short, elementsMap).y).toBeCloseTo(+ sticky.y + STICKY_NOTE_PADDING + (paddedHeight - 100) / 2,+ );++ // centered it would run into the footer: it ends at the body's bottom+ const tall = { ...text, height: paddedHeight - STICKY_NOTE_FOOTER.height };+ expect(computeBoundTextPosition(sticky, tall, elementsMap).y).toBeCloseTo(+ bodyBottom - tall.height,+ );+ scene.destroy();+ });++ it.each([0, Math.PI / 4, Math.PI / 2])(+ "keeps bottom-aligned text above the date footer at angle %s",+ (angle) => {+ const { scene, stickyId, textId } = createStickyWithText("Last line");+ const sticky = getSticky(scene, stickyId);+ const text = getBoundText(scene, textId);+ scene.mutateElement(sticky, { angle: angle as Radians });+ scene.mutateElement(text, { verticalAlign: VERTICAL_ALIGN.BOTTOM });+ redrawTextBoundingBox(text, sticky, scene);++ // Bring the rendered label center back into the note's local frame.+ const [, centerY] = pointRotateRads(+ pointFrom(text.x + text.width / 2, text.y + text.height / 2),+ pointFrom(sticky.x + sticky.width / 2, sticky.y + sticky.height / 2),+ -angle as Radians,+ );+ expect(centerY + text.height / 2).toBeCloseTo(+ sticky.y ++ sticky.height -+ STICKY_NOTE_PADDING -+ STICKY_NOTE_FOOTER.height,+ );+ expect(sticky.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(sticky.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ scene.destroy();+ },+ );+});++describe("sticky note creation date", () => {+ // local noon, so the calendar day is the same in every time zone+ const NOW = new Date(2026, 8, 8, 12).getTime();+ const at = (year: number, month: number, day: number) =>+ new Date(year, month, day, 12).getTime();++ it("formats an absolute date, short while the year is the current one", () => {+ expect(getStickyNoteDateLabel(at(2026, 8, 7), { now: NOW })).toBe("7 Sep");+ expect(getStickyNoteDateLabel(at(2025, 11, 31), { now: NOW })).toBe(+ "31 Dec 2025",+ );+ expect(+ getStickyNoteDateLabel(at(2025, 11, 31), { now: NOW, short: true }),+ ).toBe("31 Dec");+ // a creator's clock ahead of ours is still a date+ expect(getStickyNoteDateLabel(at(2027, 0, 1), { now: NOW })).toBe(+ "1 Jan 2027",+ );+ });++ it.each([null, NaN, Infinity, 8.64e15 + 1])(+ "hides an unknown or invalid timestamp: %s",+ (created) => {+ expect(getStickyNoteDateLabel(created, { now: NOW })).toBeNull();+ },+ );++ it("picks the footer form by width bucket, without measuring", () => {+ const created = at(2025, 4, 30);+ const footer = (width: number, height = DEFAULT_STICKY_NOTE_SIZE) =>+ getStickyNoteFooter({ created, width, height }, NOW);+ const yearWidth =+ STICKY_NOTE_PADDING * 2 + STICKY_NOTE_FOOTER.minBodyWidthForYear;++ expect(footer(DEFAULT_STICKY_NOTE_SIZE)).toEqual({+ text: "30 May 2025",+ x: DEFAULT_STICKY_NOTE_SIZE - STICKY_NOTE_PADDING,+ y: DEFAULT_STICKY_NOTE_SIZE - STICKY_NOTE_FOOTER.baselineFromBottom,+ });+ expect(footer(yearWidth)?.text).toBe("30 May 2025");+ expect(footer(yearWidth - 1)?.text).toBe("30 May");+ // the data floor always fits the short form+ expect(footer(STICKY_NOTE_MIN_SIZE, STICKY_NOTE_MIN_SIZE)?.text).toBe(+ "30 May",+ );+ // the 0×0 creation draft paints no footer, nor does an unknown date+ expect(footer(0, 0)).toBeNull();+ expect(+ getStickyNoteFooter({ created: null, width: 250, height: 250 }, NOW),+ ).toBeNull();+ });++ it("reserves the footer below the label body", () => {+ const { scene, stickyId, textId } = createStickyWithText("A");+ const sticky = getSticky(scene, stickyId);+ expect(getBoundTextMaxHeight(sticky, getBoundText(scene, textId))).toBe(+ sticky.height - STICKY_NOTE_BODY_INSET_Y,+ );+ scene.destroy();+ });+});++describe("sticky note ink", () => {+ const RED = "#e03131";+ const BLUE = "#1971c2";+ const pair = (containerInk: string, labelInk: string) => {+ const container = newStickyNoteElement({+ type: "stickynote",+ x: 0,+ y: 0,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ strokeColor: containerInk,+ });+ const label = newTextElement({+ x: 0,+ y: 0,+ text: "hi",+ originalText: "hi",+ containerId: container.id,+ strokeColor: labelInk,+ });+ return [+ newElementWith(container, {+ boundElements: [{ type: "text", id: label.id }],+ }),+ label,+ ] as const;+ };+ const inks = (elements: readonly ExcalidrawElement[]) =>+ elements.map((element) => element.strokeColor);++ it("is a no-op when the note and its label agree", () => {+ const elements = pair(RED, RED);+ expect(syncStickyNoteInk(elements, arrayToMap(elements))).toBe(elements);+ });++ it("follows whichever side changed", () => {+ const [container, label] = pair(RED, RED);+ const prev = arrayToMap([container, label]);+ // the note was recolored (selection): the label follows+ expect(+ inks(+ syncStickyNoteInk(+ [newElementWith(container, { strokeColor: BLUE }), label],+ prev,+ ),+ ),+ ).toEqual([BLUE, BLUE]);+ // the label was recolored (editing): the note follows+ expect(+ inks(+ syncStickyNoteInk(+ [container, newElementWith(label, { strokeColor: BLUE })],+ prev,+ ),+ ),+ ).toEqual([BLUE, BLUE]);+ });++ it("lets the label win when both changed or the data drifted", () => {+ expect(inks(syncStickyNoteInk(pair(RED, BLUE), new Map()))).toEqual([+ BLUE,+ BLUE,+ ]);+ });++ it("gives a transparent label the note's color", () => {+ expect(+ inks(syncStickyNoteInk(pair(RED, "transparent"), new Map())),+ ).toEqual([RED, RED]);+ });+});diff --git a/packages/element/src/__tests__/transform.test.ts b/packages/element/src/__tests__/transform.test.tsindex a0cb99dd2a..9c44e59812 100644--- a/packages/element/src/__tests__/transform.test.ts+++ b/packages/element/src/__tests__/transform.test.ts@@ -1,8 +1,13 @@+import {+ DEFAULT_STICKY_NOTE_BG,+ DEFAULT_STICKY_NOTE_SIZE,+ STICKY_NOTE_MIN_FONT_SIZE,+ STICKY_NOTE_MIN_SIZE,+ getUpdatedTimestamp,+} from "@excalidraw/common";import { pointFrom } from "@excalidraw/math";import { vi } from "vitest";-import { getUpdatedTimestamp } from "@excalidraw/common";-import {newElement,newEmbeddableElement,@@ -15,7 +20,11 @@ import {type ExcalidrawElementSkeleton,} from "../transform";-import type { ExcalidrawArrowElement } from "../types";+import type {+ ExcalidrawArrowElement,+ ExcalidrawStickyNoteElement,+ ExcalidrawTextElement,+} from "../types";const opts = { regenerateIds: false };@@ -1058,4 +1067,124 @@ describe("Test Transform", () => {);});});++ describe("sticky notes", () => {+ const find = <+ T extends ExcalidrawStickyNoteElement | ExcalidrawTextElement,+ >(+ elements: readonly { type: string }[],+ type: T["type"],+ ) => elements.find((element) => element.type === type) as T;++ it("creates a finalized note with the sticky defaults", () => {+ const elements = convertToExcalidrawElements(+ [{ type: "stickynote", x: 100, y: 100 }],+ opts,+ );+ const note = find<ExcalidrawStickyNoteElement>(elements, "stickynote");++ expect(elements).toHaveLength(1);+ expect(note.width).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(note.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(note.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(note.backgroundColor).toBe(DEFAULT_STICKY_NOTE_BG);+ expect(note.fillStyle).toBe("solid");+ });++ it("enforces the note invariants on the given properties", () => {+ const note = find<ExcalidrawStickyNoteElement>(+ convertToExcalidrawElements(+ [+ {+ type: "stickynote",+ x: 0,+ y: 0,+ width: 10,+ height: 300,+ backgroundColor: "transparent",+ strokeColor: "transparent",+ },+ ],+ opts,+ ),+ "stickynote",+ );++ expect(note.width).toBe(STICKY_NOTE_MIN_SIZE);+ expect(note.height).toBe(300);+ expect(note.baseHeight).toBe(300);+ expect(note.backgroundColor).toBe(DEFAULT_STICKY_NOTE_BG);+ expect(note.strokeColor).not.toBe("transparent");+ });++ it("gives the note the color of a label that sets its own", () => {+ const elements = convertToExcalidrawElements(+ [+ {+ type: "stickynote",+ x: 0,+ y: 0,+ strokeColor: "#1971c2",+ label: { text: "hello", strokeColor: "#e03131" },+ },+ ],+ opts,+ );+ const note = find<ExcalidrawStickyNoteElement>(elements, "stickynote");+ const label = find<ExcalidrawTextElement>(elements, "text");++ expect(label.strokeColor).toBe("#e03131");+ expect(note.strokeColor).toBe("#e03131");+ });++ it("binds a label whose font size becomes the note's ceiling", () => {+ const elements = convertToExcalidrawElements(+ [+ {+ type: "stickynote",+ x: 100,+ y: 100,+ strokeColor: "#1971c2",+ label: { text: "hello", fontSize: 28 },+ },+ ],+ opts,+ );+ const note = find<ExcalidrawStickyNoteElement>(elements, "stickynote");+ const label = find<ExcalidrawTextElement>(elements, "text");++ expect(elements).toHaveLength(2);+ expect(label.containerId).toBe(note.id);+ expect(note.boundElements).toEqual([{ type: "text", id: label.id }]);+ expect(label.baseFontSize).toBe(28);+ expect(label.fontSize).toBe(28);+ // the label is the note's visible text: it takes the note's stroke+ expect(label.strokeColor).toBe("#1971c2");+ expect(note.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ });++ it("grows the note for a label that overflows at the minimum font size", () => {+ const elements = convertToExcalidrawElements(+ [+ {+ type: "stickynote",+ x: 0,+ y: 0,+ label: {+ text: Array(40).fill("abcdefghijklmnopqrstuvwx").join("\n"),+ fontSize: 28,+ },+ },+ ],+ opts,+ );+ const note = find<ExcalidrawStickyNoteElement>(elements, "stickynote");+ const label = find<ExcalidrawTextElement>(elements, "text");++ expect(label.fontSize).toBe(STICKY_NOTE_MIN_FONT_SIZE);+ expect(label.baseFontSize).toBe(28);+ expect(note.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(note.height).toBeGreaterThan(DEFAULT_STICKY_NOTE_SIZE);+ });+ });});diff --git a/packages/element/src/bounds.ts b/packages/element/src/bounds.tsindex 09c4ae5148..493fe9919f 100644--- a/packages/element/src/bounds.ts+++ b/packages/element/src/bounds.ts@@ -420,6 +420,7 @@ const _isRectanguloidElement = (return (element != null &&(element.type === "rectangle" ||+ element.type === "stickynote" ||element.type === "image" ||element.type === "iframe" ||element.type === "embeddable" ||diff --git a/packages/element/src/collision.ts b/packages/element/src/collision.tsindex bbc5698f29..68ff96a08e 100644--- a/packages/element/src/collision.ts+++ b/packages/element/src/collision.ts@@ -467,6 +467,7 @@ export const intersectElementWithLineSegment = (// Do the actual intersection test against the element's shapeswitch (element.type) {case "rectangle":+ case "stickynote":case "image":case "text":case "iframe":diff --git a/packages/element/src/comparisons.ts b/packages/element/src/comparisons.tsindex ea4fc7f2a4..73418daa7c 100644--- a/packages/element/src/comparisons.ts+++ b/packages/element/src/comparisons.ts@@ -2,6 +2,7 @@ import type { ElementOrToolType } from "@excalidraw/excalidraw/types";export const hasBackground = (type: ElementOrToolType) =>type === "rectangle" ||+ type === "stickynote" ||type === "iframe" ||type === "embeddable" ||type === "ellipse" ||@@ -12,8 +13,12 @@ export const hasBackground = (type: ElementOrToolType) =>// tool-only type; makes the `G` background shortcut work for bucket filltype === "bucketfill";+export const hasFillStyle = (type: ElementOrToolType) =>+ hasBackground(type) && type !== "stickynote";+export const hasStrokeColor = (type: ElementOrToolType) =>type === "rectangle" ||+ type === "stickynote" ||type === "ellipse" ||type === "diamond" ||type === "freedraw" ||@@ -44,6 +49,9 @@ export const hasStrokeStyle = (type: ElementOrToolType) =>type === "line" ||type === "autoshape";+export const hasRoughness = (type: ElementOrToolType) =>+ hasStrokeStyle(type) || type === "stickynote";+export const hasFreedrawMode = (type: ElementOrToolType) => type === "freedraw";export const canChangeRoundness = (type: ElementOrToolType) =>@@ -52,6 +60,7 @@ export const canChangeRoundness = (type: ElementOrToolType) =>type === "embeddable" ||type === "line" ||type === "diamond" ||+ type === "stickynote" ||type === "image";export const toolIsArrow = (type: ElementOrToolType) => type === "arrow";diff --git a/packages/element/src/delta.ts b/packages/element/src/delta.tsindex c1c0f737f4..8219389fd8 100644--- a/packages/element/src/delta.ts+++ b/packages/element/src/delta.ts@@ -47,6 +47,7 @@ import { mutateElement, newElementWith } from "./mutateElement";import { getBoundTextElementId, redrawTextBoundingBox } from "./textElement";import {hasBoundTextElement,+ isArrowElement,isBindableElement,isBoundToContainer,isTextElement,@@ -1442,6 +1443,48 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {}try {+ // Whether this delta results in a visible change is decided from the+ // *applied* result, not from the property patches: binding repair and+ // layout (text bounding boxes, bound arrows) run below and can move+ // elements the delta never named, and an `isDeleted` flip or a+ // `boundElements` edit is not visible by itself — deleting a note's+ // empty label is the canonical case. History relies on this answer to+ // skip such entries on undo/redo (see `History`'s apply loop).+ //+ // `idsToCheck` is every element whose "before" and "after" get+ // compared: the changed elements plus what layout can move for them —+ // a text's container, and everything in `boundElements` (a container's+ // label and arrows). The set is walked as it grows, so an arrow added+ // for its container brings in its own label in turn. The dev/test+ // assertion after the redraw verifies the set is complete.+ const idsToCheck = new Set(changedElements.keys());+ // Unchanged elements are shared between `elements` and `nextElements`,+ // and layout mutates them in place — their "before" must be a shallow+ // copy taken now. Changed elements already have a fresh instance in+ // `nextElements`, so the instance in `elements` is their "before" as+ // is. Only `idsToCheck` is saved; the whole scene is never copied.+ const previousElements = new Map<string, OrderedExcalidrawElement>();+ for (const id of idsToCheck) {+ const previous = elements.get(id);+ const next = nextElements.get(id);+ for (const element of [previous, next]) {+ if (element) {+ if (isTextElement(element) && element.containerId) {+ idsToCheck.add(element.containerId);+ }+ for (const binding of element.boundElements ?? []) {+ idsToCheck.add(binding.id);+ }+ }+ }+ if (previous) {+ previousElements.set(+ id,+ previous === next ? { ...previous } : previous,+ );+ }+ }+// the following reorder performs mutations, but only on new instances of changed elements,// unless something goes really bad and it fallbacks to fixing all invalid indicesnextElements = ElementsDelta.reorderElements(@@ -1450,8 +1493,53 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {flags,);+ // Guard for `idsToCheck`: layout bumps the version of everything it+ // mutates, so an element whose version moved during the redraw but was+ // never collected is a layout dependency the expansion above does not+ // know about — and a visible change that undo would silently skip.+ // Fail loudly instead (dev and tests only; this is a scene-wide pass).+ const versionsBeforeRedraw =+ isTestEnv() || isDevEnv()+ ? new Map(+ Array.from(nextElements, ([id, element]) => [+ id,+ element.version,+ ]),+ )+ : undefined;+ElementsDelta.redrawElements(nextElements, changedElements);++ if (versionsBeforeRedraw) {+ for (const [id, element] of nextElements) {+ if (+ versionsBeforeRedraw.get(id) !== element.version &&+ !idsToCheck.has(id)+ ) {+ throw new Error(+ `Redrawn element "${id}" is missing from idsToCheck`,+ );+ }+ }+ }++ if (!flags.containsVisibleDifference) {+ for (const id of idsToCheck) {+ if (+ ElementsDelta.checkForVisibleDifference(+ previousElements.get(id),+ nextElements.get(id),+ previousElements,+ nextElements,+ )+ ) {+ flags.containsVisibleDifference = true;+ break;+ }+ }+ }} catch (e) {+ flags.containsVisibleDifference = true;console.error(`Couldn't mutate elements after applying elements change`,e,@@ -1460,9 +1548,9 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {if (isTestEnv() || isDevEnv()) {throw e;}- } finally {- return [nextElements, flags.containsVisibleDifference];}++ return [nextElements, flags.containsVisibleDifference];}public squash(delta: ElementsDelta): this {@@ -1625,12 +1713,8 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {if (element) {// as the element was brought from the snapshot, it automatically results in a possible zindex difference+ // (whether it is *visible* is decided in `applyTo`, from the applied result)flags.containsZindexDifference = true;-- // as the element was force deleted, we need to check if adding it back results in a visible change- if (!partial.isDeleted || (partial.isDeleted && !element.isDeleted)) {- flags.containsVisibleDifference = true;- }} else {// not in elements, not in snapshot? element might have been added remotely!element = newElementWith(@@ -1687,18 +1771,8 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {});}- if (!flags.containsVisibleDifference) {- // Creation metadata is not visible; a different fractional index does- // not necessarily change the visible order either.- const { index, created, ...rest } = directlyApplicablePartial;- const containsVisibleDifference = ElementsDelta.checkForVisibleDifference(- element,- rest,- );-- flags.containsVisibleDifference = containsVisibleDifference;- }-+ // visibility is not decided here: `applyTo` compares the applied result+ // once layout has run, so that its effects count tooif (!flags.containsZindexDifference) {flags.containsZindexDifference =delta.deleted.index !== delta.inserted.index;@@ -1708,29 +1782,96 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {}/**- * Check for visible changes regardless of whether they were removed, added or updated.+ * Whether an element looks different after the delta — and the layout that+ * followed it — was applied. The input to history's "skip entries with no+ * visible change" loop.+ *+ * Both sides are first reduced to what actually paints:+ * - a missing or deleted element paints nothing;+ * - an empty text element paints nothing either — unless it carries arrow+ * bindings (an arrow may end at it) or sits on an arrow (an empty label+ * still cuts the arrow's gap);+ * so an empty label's deletion or restoration compares as nothing against+ * nothing. Two painting elements are then compared property by property:+ * - `version`, `versionNonce`, `updated`, `created` are metadata, and+ * `index` is covered by the separate z-order check (`reorderElements`);+ * - `boundElements` is compared as `type:id` references with references to+ * empty labels dropped, so adding or removing an empty label's reference+ * is not visible on its own, and binding repair that rebuilt equal+ * objects is not either;+ * - everything else counts. Nested arrays (`points`, binding fixed points)+ * compare by reference, which can only over-report a change — the safe+ * direction, where undo stops one entry early.+ *+ * `previousElements` holds only `idsToCheck` (see `applyTo`); the label+ * lookups it serves are for elements whose labels are in that set.*/private static checkForVisibleDifference(- element: OrderedExcalidrawElement,- partial: ElementPartial,+ previous: OrderedExcalidrawElement | undefined,+ next: OrderedExcalidrawElement | undefined,+ previousElements: ReadonlyMap<string, OrderedExcalidrawElement>,+ nextElements: ReadonlyMap<string, OrderedExcalidrawElement>,) {- if (element.isDeleted && partial.isDeleted !== false) {- // when it's deleted and partial is not false, it cannot end up with a visible change- return false;- }+ const visibleElement = (+ element: OrderedExcalidrawElement | undefined,+ elements: ReadonlyMap<string, OrderedExcalidrawElement>,+ ) => {+ if (!element || element.isDeleted) {+ return null;+ }+ if (+ isTextElement(element) &&+ !element.text.trim() &&+ !element.boundElements?.length &&+ !isArrowElement(elements.get(element.containerId ?? ""))+ ) {+ return null;+ }- if (element.isDeleted && partial.isDeleted === false) {- // when we add an element, it results in a visible change- return true;- }+ return element;+ };- if (element.isDeleted === false && partial.isDeleted) {- // when we remove an element, it results in a visible change- return true;+ const before = visibleElement(previous, previousElements);+ const after = visibleElement(next, nextElements);+ if (!before || !after) {+ return before !== after;}- // check for any difference on a visible element- return Delta.isRightDifferent(element, partial);+ const visibleBindings = (+ element: OrderedExcalidrawElement,+ elements: ReadonlyMap<string, OrderedExcalidrawElement>,+ ) =>+ (element.boundElements ?? [])+ .filter((binding) => {+ const label = elements.get(binding.id);+ return (+ binding.type !== "text" ||+ isArrowElement(element) ||+ !label ||+ !isTextElement(label) ||+ !!label.text.trim()+ );+ })+ .map(({ id, type }) => `${type}:${id}`);++ return Delta.getDifferences(before, after).some((key) => {+ switch (key) {+ // Ordering is checked separately; the remaining fields are metadata.+ case "index":+ case "version":+ case "versionNonce":+ case "updated":+ case "created":+ return false;+ case "boundElements":+ return !isShallowEqual(+ visibleBindings(before, previousElements),+ visibleBindings(after, nextElements),+ );+ default:+ return true;+ }+ });}/**diff --git a/packages/element/src/distance.ts b/packages/element/src/distance.tsindex 1b6960fbec..b7fc11e953 100644--- a/packages/element/src/distance.ts+++ b/packages/element/src/distance.ts@@ -34,6 +34,7 @@ export const distanceToElement = (switch (element.type) {case "selection":case "rectangle":+ case "stickynote":case "image":case "text":case "iframe":diff --git a/packages/element/src/flowchart.ts b/packages/element/src/flowchart.tsindex b2b32807f2..432abb3b5d 100644--- a/packages/element/src/flowchart.ts+++ b/packages/element/src/flowchart.ts@@ -25,7 +25,11 @@ import {} from "./heading";import { LinearElementEditor } from "./linearElementEditor";import { mutateElement } from "./mutateElement";-import { newArrowElement, newElement } from "./newElement";+import {+ newArrowElement,+ newElement,+ newStickyNoteElement,+} from "./newElement";import { aabbForElement } from "./bounds";import { elementsAreInFrameBounds, elementOverlapsWithFrame } from "./frame";import {@@ -230,8 +234,7 @@ const cloneFlowchartNode = (x: number,y: number,) => {- const node = newElement({- type: template.type,+ const commonNodeProps = {x,y,width: template.width,@@ -244,7 +247,19 @@ const cloneFlowchartNode = (opacity: template.opacity,fillStyle: template.fillStyle,strokeStyle: template.strokeStyle,- });+ };++ const node =+ template.type === "stickynote"+ ? newStickyNoteElement({+ type: "stickynote",+ ...commonNodeProps,+ baseHeight: template.baseHeight,+ })+ : newElement({+ type: template.type,+ ...commonNodeProps,+ });invariant(isFlowchartNodeElement(node),@@ -254,7 +269,7 @@ const cloneFlowchartNode = (return node;};-const addNewNodes = (+export const addNewNodes = (startNode: NonDeleted<ExcalidrawFlowchartNodeElement>,appState: AppState,direction: LinkDirection,diff --git a/packages/element/src/index.ts b/packages/element/src/index.tsindex e30ba2b3b2..c45184036f 100644--- a/packages/element/src/index.ts+++ b/packages/element/src/index.ts@@ -94,6 +94,7 @@ export * from "./showSelectedShapeActions";export * from "./sizeHelpers";export * from "./sortElements";export * from "./store";+export * from "./stickyNote";export * from "./textElement";export * from "./textMeasurements";export * from "./textWrapping";diff --git a/packages/element/src/newElement.ts b/packages/element/src/newElement.tsindex 2d5ec8e0ba..e342abdc9d 100644--- a/packages/element/src/newElement.ts+++ b/packages/element/src/newElement.ts@@ -3,6 +3,8 @@ import {DEFAULT_FONT_FAMILY,DEFAULT_FONT_SIZE,DEFAULT_TEXT_ALIGN,+ DEFAULT_STICKY_NOTE_SIZE,+ STICKY_NOTE_MIN_SIZE,DEFAULT_VERTICAL_ALIGN,DEFAULT_STROKE_STREAMLINE,VERTICAL_ALIGN,@@ -22,6 +24,10 @@ import {getResizedElementAbsoluteCoords,} from "./bounds";import { newElementWith } from "./mutateElement";+import {+ normalizeStickyNoteBackgroundColor,+ normalizeStickyNoteStrokeColor,+} from "./stickyNote";import { getBoundTextMaxWidth } from "./textElement";import { normalizeText, measureText } from "./textMeasurements";import { wrapText } from "./textWrapping";@@ -49,6 +55,7 @@ import type {ExcalidrawArrowElement,ExcalidrawElbowArrowElement,ExcalidrawLineElement,+ ExcalidrawStickyNoteElement,} from "./types";export type ElementConstructorOpts = MarkOptional<@@ -171,6 +178,70 @@ export const newElement = (): NonDeleted<ExcalidrawGenericElement> =>_newElementBase<ExcalidrawGenericElement>(opts.type, opts);+/**+ * Style invariants of a sticky note: never-transparent colors, solid fill.+ * Applied by the constructor and by every normalization pass. Returns the+ * same object when nothing needs fixing.+ */+export const normalizeStickyNoteStyle = <T extends ExcalidrawStickyNoteElement>(+ element: T,+): T => {+ return newElementWith(element as ExcalidrawStickyNoteElement, {+ backgroundColor: normalizeStickyNoteBackgroundColor(+ element.backgroundColor,+ ),+ strokeColor: normalizeStickyNoteStrokeColor(element.strokeColor),+ fillStyle: "solid",+ }) as T;+};++/**+ * Geometry invariants of a *finalized* sticky note: minimum size and+ * `baseHeight ≤ height`. Deliberately not part of the constructor — a+ * pointer-down draft starts at 0×0 like every other tool and is previewed at+ * its true dragged size; pointer-up, restore, the skeleton path and the+ * action post-passes enforce this.+ */+export const normalizeStickyNoteGeometry = <+ T extends ExcalidrawStickyNoteElement,+>(+ element: T,+): T => {+ const width = Math.max(element.width, STICKY_NOTE_MIN_SIZE);+ const baseHeight = Math.max(+ element.baseHeight || element.height || DEFAULT_STICKY_NOTE_SIZE,+ STICKY_NOTE_MIN_SIZE,+ );++ return newElementWith(element as ExcalidrawStickyNoteElement, {+ width,+ height: Math.max(element.height, baseHeight),+ baseHeight,+ }) as T;+};++/** all sticky note invariants (style + finalized geometry) */+export const normalizeStickyNote = <T extends ExcalidrawStickyNoteElement>(+ element: T,+): T => {+ return normalizeStickyNoteGeometry(normalizeStickyNoteStyle(element));+};++export const newStickyNoteElement = (+ opts: {+ type: "stickynote";+ baseHeight?: number;+ } & ElementConstructorOpts,+): NonDeleted<ExcalidrawStickyNoteElement> => {+ const base = _newElementBase<ExcalidrawStickyNoteElement>("stickynote", opts);++ // no size inflation here (see `normalizeStickyNoteGeometry`)+ return normalizeStickyNoteStyle({+ ...base,+ baseHeight: opts.baseHeight ?? base.height,+ });+};+export const newEmbeddableElement = (opts: {type: "embeddable";@@ -273,6 +344,7 @@ export const newTextElement = (lineHeight?: ExcalidrawTextElement["lineHeight"];autoResize?: ExcalidrawTextElement["autoResize"];labelPosition?: ExcalidrawTextElement["labelPosition"];+ baseFontSize?: ExcalidrawTextElement["baseFontSize"];} & ElementConstructorOpts,): NonDeleted<ExcalidrawTextElement> => {const fontFamily = opts.fontFamily || DEFAULT_FONT_FAMILY;@@ -295,6 +367,7 @@ export const newTextElement = (..._newElementBase<ExcalidrawTextElement>("text", opts),text,fontSize,+ baseFontSize: opts.baseFontSize ?? null,fontFamily,textAlign,verticalAlign,diff --git a/packages/element/src/renderElement.ts b/packages/element/src/renderElement.tsindex eb740aba96..1cd349bf0f 100644--- a/packages/element/src/renderElement.ts+++ b/packages/element/src/renderElement.ts@@ -24,6 +24,10 @@ import {invariant,applyDarkModeFilter,isSafari,+ STICKY_NOTE_EDGE_SHADOW_OPACITY,+ STICKY_NOTE_EDGE_SHADOW_WIDTH,+ STICKY_NOTE_FOOTER,+ STICKY_NOTE_SHADOW_OPACITY,} from "@excalidraw/common";import type {@@ -67,6 +71,11 @@ import { getContainingFrame } from "./frame";import { getCornerRadius } from "./utils";import { ShapeCache } from "./shape";+import {+ getStickyNoteFooter,+ getStickyNotePathCommands,+ type StickyNotePathCommand,+} from "./stickyNote";import type {ExcalidrawElement,@@ -315,6 +324,50 @@ const drawImagePlaceholder = ();};+const drawStickyNotePath = (+ context: CanvasRenderingContext2D,+ commands: StickyNotePathCommand[],+) => {+ context.beginPath();+ for (const command of commands) {+ if (command.type === "move") {+ context.moveTo(command.point.x, command.point.y);+ } else if (command.type === "line") {+ context.lineTo(command.point.x, command.point.y);+ } else {+ context.quadraticCurveTo(+ command.control.x,+ command.control.y,+ command.point.x,+ command.point.y,+ );+ }+ }+ context.closePath();+};++const fillStickyNoteShape = (+ context: CanvasRenderingContext2D,+ commands: StickyNotePathCommand[],+) => {+ drawStickyNotePath(context, commands);+ context.fill();+};++const strokeStickyNoteEdge = (+ context: CanvasRenderingContext2D,+ commands: StickyNotePathCommand[],+) => {+ context.save();+ drawStickyNotePath(context, commands);+ context.clip();+ context.lineWidth = STICKY_NOTE_EDGE_SHADOW_WIDTH * 2;+ context.strokeStyle = `rgba(0, 0, 0, ${STICKY_NOTE_EDGE_SHADOW_OPACITY})`;+ drawStickyNotePath(context, commands);+ context.stroke();+ context.restore();+};+const drawElementOnCanvas = (element: NonDeletedExcalidrawElement,rc: RoughCanvas,@@ -322,6 +375,41 @@ const drawElementOnCanvas = (renderConfig: StaticCanvasRenderConfig,) => {switch (element.type) {+ case "stickynote": {+ context.save();+ context.fillStyle = `rgba(0, 0, 0, ${STICKY_NOTE_SHADOW_OPACITY})`;+ fillStickyNoteShape(+ context,+ getStickyNotePathCommands(element, { shadow: true }),+ );++ const commands = getStickyNotePathCommands(element);+ context.fillStyle = applyDarkModeFilter(+ element.backgroundColor,+ renderConfig.theme === THEME.DARK,+ );+ fillStickyNoteShape(context, commands);+ strokeStickyNoteEdge(context, commands);++ // the label is absolute, so this cached canvas only goes stale at a+ // year boundary — and is regenerated on the next zoom, theme or+ // element change anyway+ const footer = getStickyNoteFooter(element);+ if (footer) {+ context.font = `${STICKY_NOTE_FOOTER.fontSize}px ${STICKY_NOTE_FOOTER.fontFamily}`;+ context.textAlign = "right";+ context.textBaseline = "alphabetic";+ context.fillStyle = applyDarkModeFilter(+ element.strokeColor,+ renderConfig.theme === THEME.DARK,+ );+ context.globalAlpha *= STICKY_NOTE_FOOTER.opacity;+ context.fillText(footer.text, footer.x, footer.y);+ }++ context.restore();+ break;+ }case "rectangle":case "iframe":case "embeddable":@@ -909,6 +997,7 @@ export const renderElement = (break;}case "rectangle":+ case "stickynote":case "diamond":case "ellipse":case "line":diff --git a/packages/element/src/resizeElements.ts b/packages/element/src/resizeElements.tsindex 9915df266b..b6d9a355ba 100644--- a/packages/element/src/resizeElements.ts+++ b/packages/element/src/resizeElements.ts@@ -10,6 +10,7 @@ import {import {MIN_FONT_SIZE,SHIFT_LOCKING_ANGLE,+ STICKY_NOTE_MIN_SIZE,rescalePoints,getFontString,} from "@excalidraw/common";@@ -57,10 +58,16 @@ import {isFreeDrawElement,isImageElement,isLinearElement,+ isStickyNoteElement,isTextElement,} from "./typeChecks";import { isInGroup } from "./groups";+import {+ getStickyNoteMinSize,+ getStickyNoteResizeIntent,+ updateStickyNoteLayout,+} from "./stickyNote";import type { Scene } from "./Scene";@@ -749,11 +756,54 @@ export const resizeSingleElement = ();}- let boundTextFont: { fontSize?: number } = {};+ // Constraints and font scaling use magnitudes. Keep the signs for the+ // geometry below, where crossing the opposite edge flips the element.+ const flipFactorX = nextWidth < 0 ? -1 : 1;+ const flipFactorY = nextHeight < 0 ? -1 : 1;+ nextWidth = Math.abs(nextWidth);+ nextHeight = Math.abs(nextHeight);+const elementsMap = scene.getNonDeletedElementsMap();const boundTextElement = getBoundTextElement(latestElement, elementsMap);+ const isResizingStickyNote = isStickyNoteElement(latestElement);+ let minSize: { width: number; height: number } | undefined;+ if (isResizingStickyNote) {+ // A note must fit one line at its label's font ceiling.+ minSize = boundTextElement+ ? getStickyNoteMinSize({+ fontSize: boundTextElement.baseFontSize ?? boundTextElement.fontSize,+ fontFamily: boundTextElement.fontFamily,+ })+ : { width: STICKY_NOTE_MIN_SIZE, height: STICKY_NOTE_MIN_SIZE };+ } else if (boundTextElement && !shouldMaintainAspectRatio) {+ minSize = {+ width: getApproxMinLineWidth(+ getFontString(boundTextElement),+ boundTextElement.lineHeight,+ ),+ height: getApproxMinLineHeight(+ boundTextElement.fontSize,+ boundTextElement.lineHeight,+ ),+ };+ }++ if (minSize) {+ nextWidth = Math.max(nextWidth, minSize.width);+ nextHeight = Math.max(nextHeight, minSize.height);+ if (shouldMaintainAspectRatio) {+ // Both dimensions must use the same scale even at the minimum size.+ const scale = Math.max(+ nextWidth / origElement.width,+ nextHeight / origElement.height,+ );+ nextWidth = origElement.width * scale;+ nextHeight = origElement.height * scale;+ }+ }- if (boundTextElement) {+ let boundTextFont: { fontSize?: number } = {};+ if (boundTextElement && !isResizingStickyNote) {const stateOfBoundTextElementAtResize = originalElementsMap.get(boundTextElement.id,) as typeof boundTextElement | undefined;@@ -780,20 +830,12 @@ export const resizeSingleElement = (boundTextFont = {fontSize: nextFont.size,};- } else {- const minWidth = getApproxMinLineWidth(- getFontString(boundTextElement),- boundTextElement.lineHeight,- );- const minHeight = getApproxMinLineHeight(- boundTextElement.fontSize,- boundTextElement.lineHeight,- );- nextWidth = Math.max(nextWidth, minWidth);- nextHeight = Math.max(nextHeight, minHeight);}}+ nextWidth *= flipFactorX;+ nextHeight *= flipFactorY;+const rescaledPoints = rescalePointsInElement(origElement,nextWidth,@@ -865,7 +907,7 @@ export const resizeSingleElement = (shouldMaintainAspectRatio) {const fontSize =- (nextWidth / latestElement.width) * boundTextElement.fontSize;+ (Math.abs(nextWidth) / latestElement.width) * boundTextElement.fontSize;if (fontSize < MIN_FONT_SIZE) {return;}@@ -909,18 +951,35 @@ export const resizeSingleElement = (isDragging: false,});- if (boundTextElement && boundTextFont != null) {- scene.mutateElement(boundTextElement, {- fontSize: boundTextFont.fontSize,+ if (isStickyNoteElement(latestElement)) {+ updateStickyNoteLayout(latestElement, scene, {+ ...getStickyNoteResizeIntent(+ latestElement,+ originalElementsMap,+ handleDirection,+ {+ proportional: shouldMaintainAspectRatio,+ fromCenter: shouldResizeFromCenter,+ },+ ),+ // the arrow pass below is this function's — keep it single+ bindings: false,});+ } else {+ if (boundTextElement && boundTextFont != null) {+ scene.mutateElement(boundTextElement, {+ fontSize: boundTextFont.fontSize,+ });+ }+ handleBindTextResize(+ latestElement,+ scene,+ handleDirection,+ shouldMaintainAspectRatio,+ shouldResizeFromCenter,+ flipFactorY < 0,+ );}- handleBindTextResize(- latestElement,- scene,- handleDirection,- shouldMaintainAspectRatio,- shouldResizeFromCenter,- );updateBoundElements(latestElement, scene);}@@ -1441,7 +1500,8 @@ export const resizeMultipleElements = (getBoundTextElementId(orig) ?? "",) as ExcalidrawTextElementWithContainer | undefined;- if (boundTextElement) {+ // sticky notes derive their label's size from the layout below+ if (boundTextElement && !isStickyNoteElement(orig)) {if (keepAspectRatio) {const newFontSize = boundTextElement.fontSize * scale;if (newFontSize < MIN_FONT_SIZE) {@@ -1473,9 +1533,27 @@ export const resizeMultipleElements = (scene.mutateElement(element, update);- updateBoundElements(element, scene, {- simultaneouslyUpdated: elementsToUpdate,- });+ if (isStickyNoteElement(element)) {+ // the content correction runs before the (single) arrow pass, which+ // must still skip arrows resized in the same gesture+ updateStickyNoteLayout(element, scene, {+ ...getStickyNoteResizeIntent(+ element,+ originalElementsMap,+ handleDirection,+ {+ proportional: keepAspectRatio,+ fromCenter: shouldResizeFromCenter,+ flip: flipByX || flipByY,+ },+ ),+ bindings: { simultaneouslyUpdated: elementsToUpdate },+ });+ } else {+ updateBoundElements(element, scene, {+ simultaneouslyUpdated: elementsToUpdate,+ });+ }if (isBindingElement(element)) {if (element.startBinding) {@@ -1491,7 +1569,11 @@ export const resizeMultipleElements = (}const boundTextElement = getBoundTextElement(element, elementsMap);- if (boundTextElement && boundTextFontSize) {+ if (+ boundTextElement &&+ boundTextFontSize &&+ !isStickyNoteElement(element)+ ) {scene.mutateElement(boundTextElement, {fontSize: boundTextFontSize,angle: isLinearElement(element) ? undefined : angle,@@ -1502,6 +1584,7 @@ export const resizeMultipleElements = (handleDirection,true,shouldResizeFromCenter,+ flipByY,);}}diff --git a/packages/element/src/shape.ts b/packages/element/src/shape.tsindex 4e7c747535..7b905b4e07 100644--- a/packages/element/src/shape.ts+++ b/packages/element/src/shape.ts@@ -979,6 +979,9 @@ const _generateElementShape = (return shapes;}+ // sticky notes are painted directly (canvas + SVG) from+ // `getStickyNoteRenderPoints`, never through roughjs+ case "stickynote":case "frame":case "magicframe":case "text":@@ -1073,6 +1076,7 @@ export const getElementShape = <Point extends GlobalPoint | LocalPoint>(): GeometricShape<Point> => {switch (element.type) {case "rectangle":+ case "stickynote":case "diamond":case "frame":case "magicframe":diff --git a/packages/element/src/sizeHelpers.ts b/packages/element/src/sizeHelpers.tsindex ae973d90e7..30c0d2a249 100644--- a/packages/element/src/sizeHelpers.ts+++ b/packages/element/src/sizeHelpers.ts@@ -22,6 +22,37 @@ import {import type { ElementsMap, ExcalidrawElement } from "./types";+export type VerticalResizeAnchor = "top" | "bottom" | "center";++/** Keeps the chosen edge or center fixed when an element's height changes. */+export const getPositionAfterHeightChange = (+ element: Pick<ExcalidrawElement, "x" | "y" | "height" | "angle">,+ nextHeight: number,+ anchor: VerticalResizeAnchor = "top",+) => {+ const delta = (element.height - nextHeight) / 2;++ if (anchor === "center") {+ // Rotation is about the center, so holding it is angle-independent.+ return { x: element.x, y: element.y + delta };+ }++ const sin = Math.sin(element.angle);+ const cos = Math.cos(element.angle);++ if (anchor === "bottom") {+ return {+ x: element.x - delta * sin,+ y: element.y + delta * (1 + cos),+ };+ }++ return {+ x: element.x + delta * sin,+ y: element.y + delta * (1 - cos),+ };+};+export const INVISIBLY_SMALL_ELEMENT_SIZE = 0.1;// TODO: remove invisible elements consistently actions, so that invisible elements are not recorded by the store, exported, broadcasted or persisteddiff --git a/packages/element/src/stickyNote.ts b/packages/element/src/stickyNote.tsnew file mode 100644index 0000000000..9036136da0--- /dev/null+++ b/packages/element/src/stickyNote.ts@@ -0,0 +1,971 @@+import {+ DEFAULT_ELEMENT_PROPS,+ DEFAULT_STICKY_NOTE_BG,+ MIN_FONT_SIZE,+ arrayToMap,+ STICKY_NOTE_BODY_INSET_Y,+ STICKY_NOTE_FALLBACK_FONT_SIZE,+ STICKY_NOTE_FOOTER,+ STICKY_NOTE_FONT_STEP,+ STICKY_NOTE_MAX_FONT_SIZE,+ STICKY_NOTE_MIN_SIZE,+ STICKY_NOTE_MIN_FONT_SIZE,+ STICKY_NOTE_PADDING,+ STICKY_NOTE_SHADOW_OFFSET,+ getFontString,+ getLineHeight,+ isTransparent,+ seededRandom,+} from "@excalidraw/common";++import { clamp } from "@excalidraw/math";++import { updateBoundElements } from "./binding";+import { newElementWith } from "./mutateElement";+import { getPositionAfterHeightChange } from "./sizeHelpers";+import { computeBoundTextPosition, getBoundTextElement } from "./textElement";+import { measureText } from "./textMeasurements";+import { wrapText } from "./textWrapping";+import { isStickyNoteElement, isTextElement } from "./typeChecks";++import type { Scene } from "./Scene";+import type { VerticalResizeAnchor } from "./sizeHelpers";+import type { TransformHandleDirection } from "./transformHandles";+import type {+ ElementsMap,+ ExcalidrawElement,+ ExcalidrawStickyNoteElement,+ ExcalidrawTextElement,+ ExcalidrawTextElementWithContainer,+ NonDeletedExcalidrawElement,+} from "./types";++export type StickyNoteRenderPoint = {+ x: number;+ y: number;+};++export type StickyNotePathCommand =+ | {+ type: "move";+ point: StickyNoteRenderPoint;+ }+ | {+ type: "line";+ point: StickyNoteRenderPoint;+ }+ | {+ type: "quadratic";+ control: StickyNoteRenderPoint;+ point: StickyNoteRenderPoint;+ };++const STICKY_NOTE_RENDER_ROUGHNESS = [0, 1.5, 8] as const;+const STICKY_NOTE_CORNER_RADIUS_RATIO = 0.04;+const STICKY_NOTE_MAX_CORNER_RADIUS = 16;++export const normalizeStickyNoteStrokeColor = (+ strokeColor: string | null | undefined,+) => {+ return !strokeColor || isTransparent(strokeColor)+ ? DEFAULT_ELEMENT_PROPS.strokeColor+ : strokeColor;+};++export const normalizeStickyNoteBackgroundColor = (+ backgroundColor: string | null | undefined,+) => {+ return !backgroundColor || isTransparent(backgroundColor)+ ? DEFAULT_STICKY_NOTE_BG+ : backgroundColor;+};++/**+ * The update that applies a picked color to an element under the sticky+ * note policy: a note is always filled and its label — the visible text,+ * which the note's own `strokeColor` seeds — never goes transparent. Every+ * color surface (actions, both eyedroppers, paste styles, bind) routes+ * through this instead of re-deriving the rule.+ */+/**+ * The element a color pick on `element` lands on. A note's label has no fill+ * of its own, so a background pick on the label — the styles panel while+ * editing it — goes to the note; everything else colors itself.+ */+export const getColorTargetElement = (+ element: ExcalidrawElement,+ property: "strokeColor" | "backgroundColor",+ elementsMap: ElementsMap,+): ExcalidrawElement => {+ if (+ property === "backgroundColor" &&+ isTextElement(element) &&+ isStickyNoteBoundText(element, elementsMap)+ ) {+ return elementsMap.get(element.containerId!) ?? element;+ }+ return element;+};++export const getColorUpdate = (+ element: ExcalidrawElement,+ property: "strokeColor" | "backgroundColor",+ color: string,+ elementsMap: ElementsMap,+): { strokeColor: string } | { backgroundColor: string } => {+ if (isStickyNoteElement(element)) {+ return property === "backgroundColor"+ ? { backgroundColor: normalizeStickyNoteBackgroundColor(color) }+ : { strokeColor: normalizeStickyNoteStrokeColor(color) };+ }+ if (+ property === "strokeColor" &&+ isTextElement(element) &&+ isStickyNoteBoundText(element, elementsMap)+ ) {+ const container = elementsMap.get(element.containerId!);+ return {+ strokeColor: isTransparent(color)+ ? normalizeStickyNoteStrokeColor(container?.strokeColor)+ : color,+ };+ }+ return property === "backgroundColor"+ ? { backgroundColor: color }+ : { strokeColor: color };+};++/**+ * A note's ink is one color: the container's `strokeColor` — the seed for a+ * new label and what the creation-date footer paints with — and its label's.+ * Run after a property write to copy the side that changed onto the other;+ * when both changed, or neither (data that drifted), the label wins: it is+ * the text the user styled. A transparent label always takes the note's+ * color. Returns the same array when nothing needs to change.+ */+export const syncStickyNoteInk = <T extends ExcalidrawElement>(+ elements: readonly T[],+ prevElementsMap: ElementsMap,+): readonly T[] => {+ const elementsMap = arrayToMap(elements);+ const inkById = new Map<string, string>();+ for (const container of elements) {+ if (!isStickyNoteElement(container) || container.isDeleted) {+ continue;+ }+ const label = getBoundTextElement(container, elementsMap);+ if (!label || label.strokeColor === container.strokeColor) {+ continue;+ }+ const containerChanged =+ prevElementsMap.get(container.id)?.strokeColor !== container.strokeColor;+ const labelChanged =+ prevElementsMap.get(label.id)?.strokeColor !== label.strokeColor;+ if (+ isTransparent(label.strokeColor) ||+ (containerChanged && !labelChanged)+ ) {+ inkById.set(+ label.id,+ normalizeStickyNoteStrokeColor(container.strokeColor),+ );+ } else {+ inkById.set(+ container.id,+ normalizeStickyNoteStrokeColor(label.strokeColor),+ );+ }+ }+ if (!inkById.size) {+ return elements;+ }+ return elements.map((element) => {+ const strokeColor = inkById.get(element.id);+ return strokeColor === undefined+ ? element+ : (newElementWith(element as ExcalidrawElement, { strokeColor }) as T);+ });+};++const jitter = (random: () => number, amount: number) =>+ (random() * 2 - 1) * amount;++const pointAtDistance = (+ from: StickyNoteRenderPoint,+ to: StickyNoteRenderPoint,+ distance: number,+) => {+ const dx = to.x - from.x;+ const dy = to.y - from.y;+ const length = Math.hypot(dx, dy);++ if (!length) {+ return from;+ }++ const ratio = Math.min(distance / length, 1);+ return {+ x: from.x + dx * ratio,+ y: from.y + dy * ratio,+ };+};++export const getStickyNoteCornerRadius = (+ element: ExcalidrawStickyNoteElement,+) => {+ if (!element.roundness) {+ return 0;+ }++ return Math.min(+ Math.min(element.width, element.height) * STICKY_NOTE_CORNER_RADIUS_RATIO,+ STICKY_NOTE_MAX_CORNER_RADIUS,+ );+};++export const getStickyNoteRenderPoints = (+ element: ExcalidrawStickyNoteElement,+ {+ offsetX = 0,+ offsetY = 0,+ seedOffset = 0,+ }: {+ offsetX?: number;+ offsetY?: number;+ seedOffset?: number;+ } = {},+): StickyNoteRenderPoint[] => {+ const roughness = Math.max(0, Math.min(2, Math.round(element.roughness)));+ const amount = Math.min(+ STICKY_NOTE_RENDER_ROUGHNESS[roughness],+ Math.min(element.width, element.height) * 0.012,+ );++ if (!amount) {+ return [+ { x: offsetX, y: offsetY },+ { x: offsetX + element.width, y: offsetY },+ { x: offsetX + element.width, y: offsetY + element.height },+ { x: offsetX, y: offsetY + element.height },+ ];+ }++ const random = seededRandom(element.seed + seedOffset);++ return [+ {+ x: offsetX + jitter(random, amount),+ y: offsetY + jitter(random, amount),+ },+ {+ x: offsetX + element.width + jitter(random, amount),+ y: offsetY + jitter(random, amount),+ },+ {+ x: offsetX + element.width + jitter(random, amount),+ y: offsetY + element.height + jitter(random, amount),+ },+ {+ x: offsetX + jitter(random, amount),+ y: offsetY + element.height + jitter(random, amount),+ },+ ];+};++export const getStickyNotePathCommands = (+ element: ExcalidrawStickyNoteElement,+ { shadow = false }: { shadow?: boolean } = {},+): StickyNotePathCommand[] => {+ const points = getStickyNoteRenderPoints(+ element,+ shadow+ ? {+ offsetX: STICKY_NOTE_SHADOW_OFFSET,+ offsetY: STICKY_NOTE_SHADOW_OFFSET,+ seedOffset: 1,+ }+ : undefined,+ );+ const radius = getStickyNoteCornerRadius(element);+ // The note's seed keeps the same corner for the paper and shadow through+ // redraws and resizes.+ const liftedCorner =+ element.roughness === 2+ ? Math.floor(seededRandom(element.seed)() * points.length)+ : -1;++ if (!radius && liftedCorner === -1) {+ return [+ { type: "move", point: points[0] },+ ...points.slice(1).map(+ (point): StickyNotePathCommand => ({+ type: "line",+ point,+ }),+ ),+ ];+ }++ const corners = points.map((point, index): StickyNotePathCommand[] => {+ const prev = points[(index + points.length - 1) % points.length];+ const next = points[(index + 1) % points.length];+ const cornerRadius = Math.min(+ radius,+ Math.hypot(point.x - prev.x, point.y - prev.y) / 2,+ Math.hypot(point.x - next.x, point.y - next.y) / 2,+ );++ if (index === liftedCorner) {+ const size = Math.min(element.width, element.height);+ const reach = Math.min(size * 0.18, 40);+ // The shadow follows the paper inward at half the bend, keeping its+ // usual down-right offset from the light at the top left.+ const lift = Math.min(size * 0.02, 5) * (shadow ? 0.5 : 1);+ // The bend joins the straight edges before the corner, keeping it local.+ const tip = {+ x: point.x + (index === 1 || index === 2 ? -lift : lift),+ y: point.y + (index >= 2 ? -lift : lift),+ };+ const start = pointAtDistance(point, prev, reach);+ const end = pointAtDistance(point, next, reach);+ return [+ { type: "line", point: start },+ {+ type: "quadratic",+ control: pointAtDistance(point, prev, reach / 2),+ point: pointAtDistance(tip, start, cornerRadius),+ },+ {+ type: "quadratic",+ control: tip,+ point: pointAtDistance(tip, end, cornerRadius),+ },+ {+ type: "quadratic",+ control: pointAtDistance(point, next, reach / 2),+ point: end,+ },+ ];+ }++ return [+ { type: "line", point: pointAtDistance(point, prev, cornerRadius) },+ {+ type: "quadratic",+ control: point,+ point: pointAtDistance(point, next, cornerRadius),+ },+ ];+ });++ const commands: StickyNotePathCommand[] = [+ { type: "move", point: corners[0][corners[0].length - 1].point },+ ];++ for (let index = 1; index <= corners.length; index++) {+ commands.push(...corners[index % corners.length]);+ }++ return commands;+};++// -----------------------------------------------------------------------------+// font size — `baseFontSize` is the size the user picked, `fontSize` the fitted one+// -----------------------------------------------------------------------------++// clamping the ceiling: the fit steps down from it in `STICKY_NOTE_FONT_STEP`+// increments, and for values >= ~2^56 (1e20 - 2 === 1e20) that would never+// progress and hang the editor+export const normalizeStickyNoteFontSize = (fontSize: number) => {+ if (!Number.isFinite(fontSize)) {+ return STICKY_NOTE_FALLBACK_FONT_SIZE;+ }+ return Math.min(STICKY_NOTE_MAX_FONT_SIZE, Math.max(MIN_FONT_SIZE, fontSize));+};++/** whether the text element is the label of a sticky note */+export const isStickyNoteBoundText = (+ textElement: ExcalidrawTextElement,+ elementsMap: ElementsMap,+) => {+ return (+ !!textElement.containerId &&+ isStickyNoteElement(elementsMap.get(textElement.containerId))+ );+};++/**+ * The font size the user picked: the ceiling the auto-fit shrinks from for a+ * sticky note label, plain `fontSize` for any other text.+ *+ * Container-aware on purpose — generic binding repair (duplication, history)+ * rewrites `containerId` without touching the ceiling, so a numeric+ * `baseFontSize` alone does not prove the text is still sticky-bound.+ */+export const getBaseFontSize = (+ textElement: ExcalidrawTextElement,+ elementsMap: ElementsMap,+) => {+ return isStickyNoteBoundText(textElement, elementsMap)+ ? textElement.baseFontSize ?? textElement.fontSize+ : textElement.fontSize;+};++/** the update that applies a user-picked font size (see `getBaseFontSize`) */+export const getBaseFontSizeUpdate = (+ textElement: ExcalidrawTextElement,+ fontSize: number,+ elementsMap: ElementsMap,+): { fontSize: number } | { baseFontSize: number } => {+ return isStickyNoteBoundText(textElement, elementsMap)+ ? { baseFontSize: normalizeStickyNoteFontSize(fontSize) }+ : { fontSize };+};++const MONTHS = [+ "Jan",+ "Feb",+ "Mar",+ "Apr",+ "May",+ "Jun",+ "Jul",+ "Aug",+ "Sep",+ "Oct",+ "Nov",+ "Dec",+];++/**+ * The creation-date label: absolute, so painting needs no clock and exports+ * don't go stale, and short ("7 Sep") while the year is the current one.+ * `null` when the note has no usable timestamp (files restored without one).+ * Fixed English in the viewer's local time zone — the element package has no+ * locale, and the footer is chosen by width bucket rather than measured.+ */+export const getStickyNoteDateLabel = (+ created: ExcalidrawStickyNoteElement["created"],+ { short = false, now = Date.now() }: { short?: boolean; now?: number } = {},+): string | null => {+ if (created === null || !Number.isFinite(created)) {+ return null;+ }+ const date = new Date(created);+ if (Number.isNaN(date.getTime())) {+ return null;+ }+ const label = `${date.getDate()} ${MONTHS[date.getMonth()]}`;+ const year = date.getFullYear();+ return short || year === new Date(now).getFullYear()+ ? label+ : `${label} ${year}`;+};++/**+ * What the footer paints and where, in note-local coordinates — shared by the+ * canvas and SVG renderers, which take the font and opacity from+ * `STICKY_NOTE_FOOTER`. `null` for the 0×0 creation draft and anything under+ * the data floor, where the band would overlap the top padding.+ */+export const getStickyNoteFooter = (+ element: Pick<ExcalidrawStickyNoteElement, "created" | "width" | "height">,+ now = Date.now(),+) => {+ if (+ element.width < STICKY_NOTE_MIN_SIZE ||+ element.height < STICKY_NOTE_MIN_SIZE+ ) {+ return null;+ }+ const text = getStickyNoteDateLabel(element.created, {+ short:+ element.width - STICKY_NOTE_PADDING * 2 <+ STICKY_NOTE_FOOTER.minBodyWidthForYear,+ now,+ });+ if (!text) {+ return null;+ }+ return {+ text,+ x: element.width - STICKY_NOTE_PADDING,+ y: element.height - STICKY_NOTE_FOOTER.baselineFromBottom,+ };+};++/**+ * The smallest note the UI lets a user create or resize to: one line at the+ * label's font ceiling plus padding (and, vertically, the footer), never below+ * `STICKY_NOTE_MIN_SIZE`. Without the font term a fresh note would grow on+ * the very first keystroke. Data-level passes (restore, action post-passes)+ * only enforce the constant floor — the layout grows a note as needed.+ */+export const getStickyNoteMinSize = ({+ fontSize,+ fontFamily,+}: Pick<ExcalidrawTextElement, "fontSize" | "fontFamily">) => {+ const lineHeightPx = Math.ceil(+ normalizeStickyNoteFontSize(fontSize) * getLineHeight(fontFamily),+ );+ return {+ width: Math.max(+ STICKY_NOTE_MIN_SIZE,+ lineHeightPx + STICKY_NOTE_PADDING * 2,+ ),+ height: Math.max(+ STICKY_NOTE_MIN_SIZE,+ lineHeightPx + STICKY_NOTE_BODY_INSET_Y,+ ),+ };+};++// -----------------------------------------------------------------------------+// layout — one pure calculation, two ways of applying it+// -----------------------------------------------------------------------------++export type StickyNoteLayoutAnchor = VerticalResizeAnchor;++export type StickyNoteLayoutOpts = {+ /** unwrapped text to lay out; defaults to the label's `originalText` */+ originalText?: string;+ /**+ * absolute base-height intent — the gesture-start value to preserve, or the+ * height a resize asked for. Omitted = keep the note's live `baseHeight`+ * (typing, style changes, restore).+ */+ baseHeight?: number;+ /**+ * absolute font-ceiling intent (a proportional resize passes+ * `gesture-start ceiling × scale`). Omitted = keep the label's live ceiling.+ * Never a multiplier on the live value — that compounds across pointer-moves.+ */+ baseFontSize?: number;+ /** the edge that stays put when the content correction changes the height */+ anchor?: StickyNoteLayoutAnchor;+};++export type StickyNoteLayout = {+ container: Pick<+ ExcalidrawStickyNoteElement,+ "x" | "y" | "width" | "height" | "baseHeight"+ >;+ text: Pick<+ ExcalidrawTextElement,+ | "text"+ | "fontSize"+ | "baseFontSize"+ | "width"+ | "height"+ | "x"+ | "y"+ | "angle"+ > | null;+};++type FontFit = {+ text: string;+ fontSize: number;+ width: number;+ height: number;+};++// `computeBoundTextPosition` only consults the map for arrow containers+const NO_ELEMENTS: ElementsMap = new Map();++const getStickyNoteBaseWidth = (container: ExcalidrawStickyNoteElement) => {+ return Math.max(container.width, STICKY_NOTE_MIN_SIZE);+};++/**+ * Largest font size on the grid `{ceiling − k·STEP} ∪ {min}` whose wrapped+ * text fits the note; `min` when nothing fits (the note then grows). The grid+ * is anchored at the ceiling so the result never depends on earlier edits.+ * Warm-started from the previously fitted size: the common keystroke costs one+ * or two wrap+measure passes, a cold search at most log2(steps) + 2.+ */+const fitStickyNoteFont = (+ fit: (fontSize: number) => FontFit,+ {+ baseFontSize,+ fontSizeMin,+ maxWidth,+ maxHeight,+ warmStart,+ }: {+ baseFontSize: number;+ fontSizeMin: number;+ maxWidth: number;+ maxHeight: number;+ warmStart: number;+ },+): FontFit => {+ const steps = Math.max(+ 0,+ Math.ceil((baseFontSize - fontSizeMin) / STICKY_NOTE_FONT_STEP),+ );+ const sizeAt = (index: number) =>+ index >= steps ? fontSizeMin : baseFontSize - index * STICKY_NOTE_FONT_STEP;++ const fits = new Map<number, FontFit>();+ const at = (index: number) => {+ let result = fits.get(index);+ if (!result) {+ result = fit(sizeAt(index));+ fits.set(index, result);+ }+ return result;+ };+ const doesFit = (index: number) => {+ const result = at(index);+ return result.width <= maxWidth && result.height <= maxHeight;+ };++ if (steps === 0) {+ return at(0);+ }++ // the previous fitted size, snapped onto the grid and clamped into the+ // current interval (a lowered ceiling must not keep the old larger size)+ const warm = clamp(+ Math.round((baseFontSize - warmStart) / STICKY_NOTE_FONT_STEP),+ 0,+ steps,+ );++ // binary search for the smallest index (largest font) that fits+ let lo: number;+ let hi: number;+ if (doesFit(warm)) {+ if (warm === 0 || !doesFit(warm - 1)) {+ return at(warm);+ }+ lo = 0;+ hi = warm - 1;+ } else {+ if (warm === steps) {+ return at(steps);+ }+ lo = warm + 1;+ hi = steps;+ }+ while (lo < hi) {+ const mid = (lo + hi) >> 1;+ if (doesFit(mid)) {+ hi = mid;+ } else {+ lo = mid + 1;+ }+ }+ return at(lo);+};++/**+ * The single source of truth for a sticky note's geometry: wraps the label at+ * the note's width, fits the font under the ceiling, grows the note past+ * `baseHeight` only when the text still overflows at the minimum size, and+ * positions the label inside. Pure — returns the updates for both elements.+ */+export const getStickyNoteLayout = (+ container: ExcalidrawStickyNoteElement,+ textElement: ExcalidrawTextElement | null,+ opts: StickyNoteLayoutOpts = {},+): StickyNoteLayout => {+ const baseWidth = getStickyNoteBaseWidth(container);+ const baseHeight = Math.max(+ opts.baseHeight ?? (container.baseHeight || container.height),+ STICKY_NOTE_MIN_SIZE,+ );+ const anchor = opts.anchor ?? "top";++ if (!textElement) {+ // an empty note sits at its base height+ return {+ container: {+ ...getPositionAfterHeightChange(container, baseHeight, anchor),+ width: baseWidth,+ height: baseHeight,+ baseHeight,+ },+ text: null,+ };+ }++ const originalText = opts.originalText ?? textElement.originalText;+ const baseFontSize = normalizeStickyNoteFontSize(+ opts.baseFontSize ?? textElement.baseFontSize ?? textElement.fontSize,+ );+ const fontSizeMin = Math.min(STICKY_NOTE_MIN_FONT_SIZE, baseFontSize);+ const maxWidth = Math.max(baseWidth - STICKY_NOTE_PADDING * 2, 1);+ const maxHeight = Math.max(baseHeight - STICKY_NOTE_BODY_INSET_Y, 0);+ const { fontFamily, lineHeight } = textElement;++ const fit = (fontSize: number): FontFit => {+ const font = getFontString({ fontFamily, fontSize });+ const text = wrapText(originalText, font, maxWidth);+ return { text, fontSize, ...measureText(text, font, lineHeight) };+ };++ const isBlank = !originalText.trim();+ const fitted: FontFit = isBlank+ ? {+ text: "",+ fontSize: baseFontSize,+ ...measureText(+ "",+ getFontString({ fontFamily, fontSize: baseFontSize }),+ lineHeight,+ ),+ }+ : fitStickyNoteFont(fit, {+ baseFontSize,+ fontSizeMin,+ maxWidth,+ maxHeight,+ warmStart: textElement.fontSize,+ });++ const height = isBlank+ ? baseHeight+ : Math.max(baseHeight, fitted.height + STICKY_NOTE_BODY_INSET_Y);+ const nextContainer = {+ ...getPositionAfterHeightChange(container, height, anchor),+ width: baseWidth,+ height,+ baseHeight,+ };+ const { x, y } = computeBoundTextPosition(+ { ...container, ...nextContainer },+ {+ ...textElement,+ text: fitted.text,+ fontSize: fitted.fontSize,+ width: fitted.width,+ height: fitted.height,+ } as ExcalidrawTextElementWithContainer,+ NO_ELEMENTS,+ );++ return {+ container: nextContainer,+ text: {+ text: fitted.text,+ fontSize: fitted.fontSize,+ baseFontSize,+ width: fitted.width,+ height: fitted.height,+ x,+ y,+ angle: container.angle,+ },+ };+};++/**+ * Resize intents for a sticky note — the §3.3 matrix of the plan. Every value+ * is absolute and derived from the gesture-start snapshot on each pointer-move,+ * so releasing Shift (or Alt) mid-gesture restores the original base height+ * and ceiling instead of keeping values a previous move scaled.+ *+ * - width-only gestures (free E/W, Stats W) preserve the base height+ * - height-changing gestures use the requested height as the new base+ * - proportional gestures (Shift on any handle, aspect-locked multi-select,+ * Stats group) additionally scale the font ceiling with the note+ * - flips preserve everything+ * - the content correction anchors at the edge the gesture holds still+ */+export const getStickyNoteResizeIntent = (+ /** the note with the requested geometry already applied */+ container: ExcalidrawStickyNoteElement,+ originalElementsMap: ElementsMap,+ handleDirection: TransformHandleDirection,+ {+ proportional,+ fromCenter,+ flip = false,+ }: { proportional: boolean; fromCenter: boolean; flip?: boolean },+): Pick<StickyNoteLayoutOpts, "baseHeight" | "baseFontSize" | "anchor"> => {+ const origContainer = originalElementsMap.get(container.id);+ const origSticky = isStickyNoteElement(origContainer)+ ? origContainer+ : container;+ const origText = getBoundTextElement(origSticky, originalElementsMap);+ const ceiling = origText+ ? origText.baseFontSize ?? origText.fontSize+ : undefined;++ if (flip) {+ return { baseHeight: origSticky.baseHeight, baseFontSize: ceiling };+ }++ const changesHeight =+ proportional ||+ handleDirection.includes("n") ||+ handleDirection.includes("s");+ const scale =+ proportional && origSticky.width ? container.width / origSticky.width : 1;+ const isSideHandle = handleDirection.length === 1;++ return {+ baseHeight: changesHeight ? container.height : origSticky.baseHeight,+ baseFontSize: ceiling === undefined ? undefined : ceiling * scale,+ anchor: fromCenter+ ? "center"+ : handleDirection.includes("n")+ ? "bottom"+ : proportional &&+ isSideHandle &&+ (handleDirection === "e" || handleDirection === "w")+ ? // Shift+E/W holds the opposite side's midpoint, i.e. the vertical center+ "center"+ : "top",+ };+};++/**+ * Applies `getStickyNoteLayout` to a live scene, then runs the bound-arrow+ * pass unless the caller already owns one (`bindings: false`) or needs to+ * forward its context (`bindings: { simultaneouslyUpdated }` — arrows resized+ * in the same gesture must not be moved by the pass, `updateBoundElements`+ * skips them only when told).+ */+export const updateStickyNoteLayout = (+ container: ExcalidrawStickyNoteElement,+ scene: Scene,+ {+ text,+ bindings,+ ...layoutOpts+ }: StickyNoteLayoutOpts & {+ /** the label to lay out when it is an uncommitted clone (font actions clone before install) */+ text?: ExcalidrawTextElement | null;+ bindings?:+ | { simultaneouslyUpdated?: readonly NonDeletedExcalidrawElement[] }+ | false;+ } = {},+): StickyNoteLayout => {+ const elementsMap = scene.getNonDeletedElementsMap();+ const textElement =+ text === undefined ? getBoundTextElement(container, elementsMap) : text;+ const layout = getStickyNoteLayout(container, textElement, layoutOpts);++ scene.mutateElement(container, layout.container);+ if (textElement && layout.text) {+ scene.mutateElement(textElement, layout.text);+ }+ if (bindings !== false && !container.isDeleted) {+ updateBoundElements(+ container as NonDeletedExcalidrawElement,+ scene,+ bindings || undefined,+ );+ }++ return layout;+};++const STICKY_NOTE_LAYOUT_INPUTS = {+ container: ["x", "y", "width", "baseHeight", "angle"],+ text: [+ "originalText",+ "baseFontSize",+ "fontFamily",+ "lineHeight",+ "textAlign",+ "verticalAlign",+ ],+} as const;++const hasStickyNoteLayoutInputChanged = (+ container: ExcalidrawStickyNoteElement,+ textElement: ExcalidrawTextElement | null,+ prevElementsMap: ElementsMap,+) => {+ const prevContainer = prevElementsMap.get(container.id);+ const prevText = textElement ? prevElementsMap.get(textElement.id) : null;+ if (+ !prevContainer ||+ (textElement && !prevText) ||+ (!textElement &&+ prevContainer.boundElements?.some(({ type }) => type === "text"))+ ) {+ return true;+ }+ return (+ STICKY_NOTE_LAYOUT_INPUTS.container.some(+ (key) => (prevContainer as any)[key] !== container[key],+ ) ||+ (!!textElement &&+ STICKY_NOTE_LAYOUT_INPUTS.text.some(+ (key) => (prevText as any)[key] !== textElement[key],+ ))+ );+};++/**+ * Applies `getStickyNoteLayout` inside an immutable elements array (property+ * actions, paste styles, restore): the notes among `affectedIds` — or the+ * notes whose labels are — get both halves merged into their clones. Elements+ * that need no change keep their identity and version; when `prevElementsMap`+ * is given, notes whose layout inputs did not change skip the fit entirely.+ * Bound arrows are the caller's job once the result is installed.+ */+export const relayoutStickyNotes = <T extends ExcalidrawElement>(+ elements: readonly T[],+ affectedIds: ReadonlySet<ExcalidrawElement["id"]>,+ opts?: { prevElementsMap?: ElementsMap },+): readonly T[] => {+ if (!affectedIds.size) {+ return elements;+ }+ const elementsMap = arrayToMap(elements);+ const containerIds = new Set<ExcalidrawElement["id"]>();+ for (const id of affectedIds) {+ const element = elementsMap.get(id);+ if (!element || element.isDeleted) {+ continue;+ }+ if (isStickyNoteElement(element)) {+ containerIds.add(element.id);+ } else if (isTextElement(element) && element.containerId) {+ const container = elementsMap.get(element.containerId);+ if (container && !container.isDeleted && isStickyNoteElement(container)) {+ containerIds.add(container.id);+ }+ }+ }+ if (!containerIds.size) {+ return elements;+ }++ const replacements = new Map<ExcalidrawElement["id"], T>();+ for (const id of containerIds) {+ const container = elementsMap.get(id) as ExcalidrawStickyNoteElement;+ const textElement = getBoundTextElement(container, elementsMap);+ if (+ opts?.prevElementsMap &&+ !hasStickyNoteLayoutInputChanged(+ container,+ textElement,+ opts.prevElementsMap,+ )+ ) {+ continue;+ }+ const layout = getStickyNoteLayout(container, textElement);+ const nextContainer = newElementWith(container, layout.container);+ if (nextContainer !== container) {+ replacements.set(id, nextContainer as unknown as T);+ }+ if (textElement && layout.text) {+ const nextText = newElementWith(textElement, layout.text);+ if (nextText !== textElement) {+ replacements.set(textElement.id, nextText as unknown as T);+ }+ }+ }+ if (!replacements.size) {+ return elements;+ }+ return elements.map((element) => replacements.get(element.id) ?? element);+};diff --git a/packages/element/src/textElement.ts b/packages/element/src/textElement.tsindex f91d6a6396..1469137bb1 100644--- a/packages/element/src/textElement.ts+++ b/packages/element/src/textElement.ts@@ -3,6 +3,8 @@ import {ARROW_LABEL_WIDTH_FRACTION,BOUND_TEXT_PADDING,DEFAULT_FONT_SIZE,+ STICKY_NOTE_BODY_INSET_Y,+ STICKY_NOTE_PADDING,TEXT_ALIGN,VERTICAL_ALIGN,getFontString,@@ -19,12 +21,15 @@ import {updateOriginalContainerCache,} from "./containerCache";import { LinearElementEditor } from "./linearElementEditor";+import { getPositionAfterHeightChange } from "./sizeHelpers";+import { updateStickyNoteLayout } from "./stickyNote";import { measureText } from "./textMeasurements";import { wrapText } from "./textWrapping";import {isBoundToContainer,isArrowElement,+ isStickyNoteElement,isTextElement,} from "./typeChecks";@@ -50,6 +55,14 @@ export const redrawTextBoundingBox = () => {const elementsMap = scene.getNonDeletedElementsMap();+ if (container && isStickyNoteElement(container)) {+ // the sticky fit owns both halves (label + note geometry). `textElement`+ // may be an uncommitted clone (font actions clone before install), so it+ // is passed explicitly instead of looked up in the scene+ updateStickyNoteLayout(container, scene, { text: textElement });+ return;+ }+let maxWidth = undefined;if (!isProdEnv()) {@@ -145,7 +158,14 @@ export const handleBindTextResize = (transformHandleType: MaybeTransformHandleType,shouldMaintainAspectRatio = false,shouldResizeFromCenter = false,+ flipByY = false,) => {+ if (isStickyNoteElement(container)) {+ // resize callers pass their intents to `updateStickyNoteLayout` directly+ // and own the bound-arrow pass; this is the fallback for generic callers+ updateStickyNoteLayout(container, scene, { bindings: false });+ return;+ }const elementsMap = scene.getNonDeletedElementsMap();const boundTextElementId = getBoundTextElementId(container);if (!boundTextElementId) {@@ -190,24 +210,24 @@ export const handleBindTextResize = (container.type,);- const diff = containerHeight - container.height;- // fix the y coord when resizing from ne/nw/n+ // Crossing the opposite edge swaps the anchor for text-driven growth.const shouldResizeFromTop =- transformHandleType === "n" ||- transformHandleType === "ne" ||- transformHandleType === "nw";-- let offsetY = 0;- if (!isArrowElement(container)) {- if (shouldResizeFromCenter) {- offsetY = diff / 2;- } else if (shouldResizeFromTop) {- offsetY = diff;- }- }+ (transformHandleType === "n" ||+ transformHandleType === "ne" ||+ transformHandleType === "nw") !== flipByY;+scene.mutateElement(container, {height: containerHeight,- y: container.y - offsetY,+ ...(!isArrowElement(container) &&+ getPositionAfterHeightChange(+ container,+ containerHeight,+ shouldResizeFromCenter+ ? "center"+ : shouldResizeFromTop+ ? "bottom"+ : "top",+ )),});}@@ -248,6 +268,18 @@ export const computeBoundTextPosition = (y = containerCoords.y;} else if (boundTextElement.verticalAlign === VERTICAL_ALIGN.BOTTOM) {y = containerCoords.y + (maxContainerHeight - boundTextElement.height);+ } else if (isStickyNoteElement(container)) {+ // a note's label body ends above the creation-date footer, but a label+ // centered in that body sits visibly high — center it in the whole+ // padded note while it stays clear of the footer, and only push it up+ // against the body's bottom once it would overlap+ const paddedHeight = container.height - STICKY_NOTE_PADDING * 2;+ y =+ containerCoords.y ++ Math.min(+ (paddedHeight - boundTextElement.height) / 2,+ maxContainerHeight - boundTextElement.height,+ );} else {y =containerCoords.y +@@ -264,10 +296,17 @@ export const computeBoundTextPosition = (const angle = (container.angle ?? 0) as Radians;if (angle !== 0) {- const contentCenter = pointFrom(- containerCoords.x + maxContainerWidth / 2,- containerCoords.y + maxContainerHeight / 2,- );+ // A sticky's footer makes its body asymmetric. The body still rotates+ // about the note's center, rather than about its own (higher) center.+ const contentCenter = isStickyNoteElement(container)+ ? pointFrom(+ container.x + container.width / 2,+ container.y + container.height / 2,+ )+ : pointFrom(+ containerCoords.x + maxContainerWidth / 2,+ containerCoords.y + maxContainerHeight / 2,+ );const textCenter = pointFrom(x + boundTextElement.width / 2,y + boundTextElement.height / 2,@@ -355,8 +394,11 @@ export const getContainerCenter = (};export const getContainerCoords = (container: ExcalidrawElement) => {- let offsetX = BOUND_TEXT_PADDING;- let offsetY = BOUND_TEXT_PADDING;+ const padding = isStickyNoteElement(container)+ ? STICKY_NOTE_PADDING+ : BOUND_TEXT_PADDING;+ let offsetX = padding;+ let offsetY = padding;if (container.type === "ellipse") {// The derivation of coordinates is explained in https://github.com/excalidraw/excalidraw/pull/6172@@ -436,6 +478,7 @@ export const suppportsHorizontalAlign = (const VALID_CONTAINER_TYPES = new Set(["rectangle",+ "stickynote","ellipse","diamond","arrow",@@ -487,7 +530,13 @@ export const getBoundTextMaxWidth = (// Math.round(width / 2) - https://github.com/excalidraw/excalidraw/pull/6265return Math.round(width / 2) - BOUND_TEXT_PADDING * 2;}- return width - BOUND_TEXT_PADDING * 2;+ return (+ width -+ (isStickyNoteElement(container)+ ? STICKY_NOTE_PADDING+ : BOUND_TEXT_PADDING) *+ 2+ );};export const getBoundTextMaxHeight = (@@ -495,6 +544,10 @@ export const getBoundTextMaxHeight = (boundTextElement: ExcalidrawTextElementWithContainer,) => {const { height } = container;+ if (isStickyNoteElement(container)) {+ // the label body ends above the creation-date footer+ return Math.max(0, height - STICKY_NOTE_BODY_INSET_Y);+ }if (isArrowElement(container)) {const containerHeight = height - BOUND_TEXT_PADDING * 8 * 2;if (containerHeight <= 0) {diff --git a/packages/element/src/transform.ts b/packages/element/src/transform.tsindex 8b0b46aac9..7199ec1dc5 100644--- a/packages/element/src/transform.ts+++ b/packages/element/src/transform.ts@@ -15,6 +15,8 @@ import {isDevEnv,toBrandedType,getLineHeight,+ DEFAULT_STICKY_NOTE_SIZE,+ isTransparent,} from "@excalidraw/common";import type { MarkOptional } from "@excalidraw/common/utility-types";@@ -32,9 +34,12 @@ import {newMagicFrameElement,newTextElement,type ElementConstructorOpts,+ newStickyNoteElement,+ normalizeStickyNoteGeometry,} from "./newElement";+import { normalizeStickyNoteStrokeColor } from "./stickyNote";import { measureText, normalizeText } from "./textMeasurements";-import { isArrowElement } from "./typeChecks";+import { isArrowElement, isStickyNoteElement } from "./typeChecks";import { syncInvalidIndices } from "./fractionalIndex";@@ -70,6 +75,7 @@ import type {Ordered,TextAlign,VerticalAlign,+ ExcalidrawStickyNoteElement,} from "./types";/**@@ -192,6 +198,18 @@ export type ValidContainer =} & FragmentConstructorOpts;} & ElementConstructorOpts;+/**+ * A sticky note: an always-filled note whose label auto-fits. `label.fontSize`+ * is the font ceiling the fit shrinks from; the note grows past its height+ * (kept as `baseHeight`) only once the label hits the minimum font size.+ */+export type ValidStickyNote = {+ type: "stickynote";+ id?: ExcalidrawStickyNoteElement["id"];+ label?: Extract<ValidContainer, { label?: unknown }>["label"];+} & ElementConstructorOpts &+ Partial<Pick<ExcalidrawStickyNoteElement, "baseHeight">>;+export type ExcalidrawElementSkeleton =| Extract<Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,@@ -203,6 +221,7 @@ export type ExcalidrawElementSkeleton =y: number;} & Partial<ExcalidrawLinearElement>)| ValidContainer+ | ValidStickyNote| ValidLinearElement| ({type: "text";@@ -240,6 +259,16 @@ const bindTextToContainer = (textProps: { text: string } & FragmentConstructorOpts,scene: Scene,) => {+ // a note and its label share one ink: a label that sets its own color+ // gives it to the note (the footer paints with it); transparent falls+ // back to the note's+ const stickyInk = isStickyNoteElement(container)+ ? normalizeStickyNoteStrokeColor(+ textProps.strokeColor && !isTransparent(textProps.strokeColor)+ ? textProps.strokeColor+ : container.strokeColor,+ )+ : null;const textElement: ExcalidrawTextElement = newTextElement({x: 0,y: 0,@@ -247,7 +276,7 @@ const bindTextToContainer = (verticalAlign: VERTICAL_ALIGN.MIDDLE,...textProps,containerId: container.id,- strokeColor: textProps.strokeColor || container.strokeColor,+ strokeColor: stickyInk ?? (textProps.strokeColor || container.strokeColor),labelPosition: isArrowElement(container)? DEFAULT_BOUND_TEXT_LABEL_POSITION: null,@@ -258,6 +287,9 @@ const bindTextToContainer = (type: "text",id: textElement.id,}),+ ...(stickyInk && stickyInk !== container.strokeColor+ ? { strokeColor: stickyInk }+ : null),});redrawTextBoundingBox(textElement, container, scene);@@ -659,6 +691,22 @@ export const convertToExcalidrawElements = (excalidrawElement = newIframeElement({ ...element });break;}+ case "stickynote": {+ const width = element.width || DEFAULT_STICKY_NOTE_SIZE;+ const height = element.height || DEFAULT_STICKY_NOTE_SIZE;+ // finalized geometry (min size, baseHeight ≤ height) — only a+ // pointer-down draft is exempt from it+ excalidrawElement = normalizeStickyNoteGeometry(+ newStickyNoteElement({+ ...element,+ type: "stickynote",+ width,+ height,+ baseHeight: element.baseHeight ?? height,+ }),+ );+ break;+ }case "embeddable": {excalidrawElement = newEmbeddableElement({ ...element });break;@@ -697,8 +745,11 @@ export const convertToExcalidrawElements = (case "rectangle":case "ellipse":case "diamond":+ case "stickynote":case "arrow": {if (element.label?.text) {+ // for a sticky note this runs the sticky fit (via+ // `redrawTextBoundingBox`): the label's font size becomes its ceilinglet [container, text] = bindTextToContainer(excalidrawElement,element?.label,diff --git a/packages/element/src/typeChecks.ts b/packages/element/src/typeChecks.tsindex 53b9a654b0..b02c97515f 100644--- a/packages/element/src/typeChecks.ts+++ b/packages/element/src/typeChecks.ts@@ -29,6 +29,7 @@ import type {ExcalidrawLineElement,ExcalidrawFlowchartNodeElement,ExcalidrawLinearElementSubType,+ ExcalidrawStickyNoteElement,} from "./types";export const isInitializedImageElement = <T extends ExcalidrawElement>(@@ -69,6 +70,12 @@ export const isTextElement = <T extends ExcalidrawElement>(return element != null && element.type === "text";};+export const isStickyNoteElement = <T extends ExcalidrawElement>(+ element: T | null | undefined,+): element is T & ExcalidrawStickyNoteElement => {+ return element != null && element.type === "stickynote";+};+export const isFrameElement = <T extends ExcalidrawElement>(element: T | null,): element is T & ExcalidrawFrameElement => {@@ -182,6 +189,7 @@ export const isBindableElement = <T extends ExcalidrawElement>(element != null &&(!element.locked || includeLocked === true) &&(element.type === "rectangle" ||+ element.type === "stickynote" ||element.type === "diamond" ||element.type === "ellipse" ||element.type === "image" ||@@ -199,6 +207,7 @@ export const isRectanguloidElement = <T extends ExcalidrawElement>(return (element != null &&(element.type === "rectangle" ||+ element.type === "stickynote" ||element.type === "diamond" ||element.type === "image" ||element.type === "iframe" ||@@ -217,6 +226,7 @@ export const isRectangularElement = <T extends ExcalidrawElement>(return (element != null &&(element.type === "rectangle" ||+ element.type === "stickynote" ||element.type === "image" ||element.type === "text" ||element.type === "iframe" ||@@ -235,6 +245,7 @@ export const isTextBindableContainer = <T extends ExcalidrawElement>(element != null &&(!element.locked || includeLocked === true) &&(element.type === "rectangle" ||+ element.type === "stickynote" ||element.type === "diamond" ||element.type === "ellipse" ||isArrowElement(element))@@ -252,6 +263,7 @@ export const isExcalidrawElement = (case "text":case "diamond":case "rectangle":+ case "stickynote":case "iframe":case "embeddable":case "ellipse":@@ -276,6 +288,7 @@ export const isFlowchartNodeElement = <T extends ExcalidrawElement>(): element is T & ExcalidrawFlowchartNodeElement => {return (element.type === "rectangle" ||+ element.type === "stickynote" ||element.type === "ellipse" ||element.type === "diamond");@@ -313,7 +326,10 @@ export const isUsingAdaptiveRadius = (type: string) =>type === "image";export const isUsingProportionalRadius = (type: string) =>- type === "line" || type === "arrow" || type === "diamond";+ type === "line" ||+ type === "arrow" ||+ type === "diamond" ||+ type === "stickynote";export const canApplyRoundnessTypeToElement = (roundnessType: RoundnessType,@@ -397,6 +413,7 @@ export const canBecomePolygon = (export const isEligibleFrameChildType = (type: ElementOrToolType) => {switch (type) {case "rectangle":+ case "stickynote":case "diamond":case "ellipse":case "arrow":diff --git a/packages/element/src/types.ts b/packages/element/src/types.tsindex aff6f52708..68891be19f 100644--- a/packages/element/src/types.ts+++ b/packages/element/src/types.ts@@ -94,6 +94,16 @@ export type ExcalidrawRectangleElement = _ExcalidrawElementBase & {type: "rectangle";};+export type ExcalidrawStickyNoteElement = _ExcalidrawElementBase &+ Readonly<{+ type: "stickynote";+ /**+ * The height the user set, from which the layout derives `height`: the+ * note grows above it to fit its label and never shrinks below it+ */+ baseHeight: number;+ }>;+export type ExcalidrawDiamondElement = _ExcalidrawElementBase & {type: "diamond";};@@ -190,11 +200,13 @@ export type ExcalidrawGenericElement =export type ExcalidrawFlowchartNodeElement =| ExcalidrawRectangleElement+ | ExcalidrawStickyNoteElement| ExcalidrawDiamondElement| ExcalidrawEllipseElement;export type ExcalidrawRectanguloidElement =| ExcalidrawRectangleElement+ | ExcalidrawStickyNoteElement| ExcalidrawImageElement| ExcalidrawTextElement| ExcalidrawFreeDrawElement@@ -210,6 +222,7 @@ export type ExcalidrawRectanguloidElement =*/export type ExcalidrawElement =| ExcalidrawGenericElement+ | ExcalidrawStickyNoteElement| ExcalidrawTextElement| ExcalidrawLinearElement| ExcalidrawArrowElement@@ -242,10 +255,19 @@ export type ExcalidrawTextElement = _ExcalidrawElementBase &type: "text";fontSize: number;fontFamily: FontFamilyValues;+ /**+ * The font size the user picked, from which the layout derives `fontSize`.+ * Today only sticky note labels have one: the auto-fit shrinks below it+ * and never above it (compare `baseHeight`, which the note grows above).+ * `null` for every other text. Read it through `getBaseFontSize` —+ * generic binding repair can detach a label without clearing this, so+ * the container decides its meaning.+ */+ baseFontSize: number | null;text: string;textAlign: TextAlign;verticalAlign: VerticalAlign;- containerId: ExcalidrawGenericElement["id"] | null;+ containerId: ExcalidrawTextContainer["id"] | null;originalText: string;/*** If `true` the width will fit the text. If `false`, the text will@@ -270,6 +292,7 @@ export type ExcalidrawTextElement = _ExcalidrawElementBase &export type ExcalidrawBindableElement =| ExcalidrawRectangleElement+ | ExcalidrawStickyNoteElement| ExcalidrawDiamondElement| ExcalidrawEllipseElement| ExcalidrawTextElement@@ -281,6 +304,7 @@ export type ExcalidrawBindableElement =export type ExcalidrawTextContainer =| ExcalidrawRectangleElement+ | ExcalidrawStickyNoteElement| ExcalidrawDiamondElement| ExcalidrawEllipseElement| ExcalidrawArrowElement;diff --git a/packages/element/src/utils.ts b/packages/element/src/utils.tsindex 3421b8b20d..d1f2aa8ccb 100644--- a/packages/element/src/utils.ts+++ b/packages/element/src/utils.ts@@ -47,6 +47,7 @@ import {getGlobalFixedPointForBindableElement,normalizeFixedPoint,} from "./binding";+import { getStickyNoteCornerRadius } from "./stickyNote";import type {ElementsMap,@@ -250,10 +251,10 @@ export function deconstructRectanguloidElement(return cachedShape;}- let radius = getCornerRadius(- Math.min(element.width, element.height),- element,- );+ let radius =+ element.type === "stickynote"+ ? getStickyNoteCornerRadius(element)+ : getCornerRadius(Math.min(element.width, element.height), element);if (radius === 0) {radius = 0.01;diff --git a/packages/element/tests/delta.test.tsx b/packages/element/tests/delta.test.tsxindex 2b39b32df7..bc2265c022 100644--- a/packages/element/tests/delta.test.tsx+++ b/packages/element/tests/delta.test.tsx@@ -1,12 +1,292 @@import { API } from "@excalidraw/excalidraw/tests/helpers/api";+import { arrayToMap } from "@excalidraw/common";+import { pointFrom } from "@excalidraw/math";import type { ObservedAppState } from "@excalidraw/excalidraw/types";import type { LinearElementEditor } from "@excalidraw/element";-import type { SceneElementsMap } from "@excalidraw/element/types";+import type {+ ExcalidrawTextElement,+ FractionalIndex,+ SceneElementsMap,+} from "@excalidraw/element/types";import { AppStateDelta, Delta, ElementsDelta } from "../src/delta";+import { mutateElement, newElementWith } from "../src/mutateElement";describe("ElementsDelta", () => {+ describe("visible changes", () => {+ const apply = (before: SceneElementsMap, after: SceneElementsMap) =>+ ElementsDelta.calculate(before, after).applyTo(before, before, {+ excludedProperties: new Set(["version", "versionNonce"]),+ });++ const boundText = (+ type: "rectangle" | "stickynote" | "arrow",+ text = "",+ ) => {+ const container = API.createElement({+ type,+ id: "container",+ index: "a0" as FractionalIndex,+ width: 250,+ height: type === "arrow" ? 0 : 250,+ baseHeight: type === "stickynote" ? 250 : undefined,+ points:+ type === "arrow" ? [pointFrom(0, 0), pointFrom(250, 0)] : undefined,+ boundElements: [{ id: "label", type: "text" }],+ });+ const label: ExcalidrawTextElement = {+ ...API.createElement({+ type: "text",+ id: "label",+ index: "a1" as FractionalIndex,+ containerId: container.id,+ fontSize: 20,+ textAlign: "center",+ verticalAlign: "middle",+ }),+ // API.createElement substitutes "test" for an empty string.+ text,+ originalText: text,+ };+ const before = arrayToMap([container, label]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(container, { boundElements: [] }),+ newElementWith(label, { isDeleted: true }),+ ]) as SceneElementsMap;+ return { container, label, before, after };+ };++ it.each(["rectangle", "stickynote"] as const)(+ "ignores empty-label deletion and restoration on a %s",+ (type) => {+ const { before, after, container, label } = boundText(type);+ const [deleted, deletionIsVisible] = apply(before, after);+ expect(deletionIsVisible).toBe(false);+ expect(deleted.get(label.id)?.isDeleted).toBe(true);+ expect(deleted.get(container.id)?.boundElements).toEqual([]);++ const [restored, restorationIsVisible] = apply(after, before);+ expect(restorationIsVisible).toBe(false);+ expect(restored.get(label.id)?.isDeleted).toBe(false);+ expect(restored.get(container.id)?.boundElements).toEqual([+ { id: label.id, type: "text" },+ ]);+ },+ );++ it("keeps deletion and restoration of nonempty labels visible", () => {+ const { before, after } = boundText("stickynote", "hello");+ expect(apply(before, after)[1]).toBe(true);+ expect(apply(after, before)[1]).toBe(true);+ });++ it.each(["excluded", "already applied"])(+ "ignores %s properties when deciding visibility",+ (mode) => {+ const element = API.createElement({+ type: "rectangle",+ index: "a0" as FractionalIndex,+ });+ const before = arrayToMap([element]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(element, { strokeColor: "red" }),+ ]) as SceneElementsMap;+ const delta = ElementsDelta.calculate(before, after);+ const current = mode === "excluded" ? before : after;+ const [elements, isVisible] = delta.applyTo(current, current, {+ excludedProperties: new Set([+ "version",+ "versionNonce",+ ...(mode === "excluded" ? ["strokeColor" as const] : []),+ ]),+ });++ expect(elements.get(element.id)?.strokeColor).toBe(+ current.get(element.id)?.strokeColor,+ );+ expect(isVisible).toBe(false);+ },+ );++ it("keeps snapshot restoration visible for a metadata-only update", () => {+ const element = API.createElement({+ type: "rectangle",+ index: "a0" as FractionalIndex,+ });+ const before = arrayToMap([element]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(element, { version: element.version + 1 }),+ ]) as SceneElementsMap;+ const delta = ElementsDelta.calculate(before, after);+ const [elements, isVisible] = delta.applyTo(+ new Map() as SceneElementsMap,+ before,+ );++ expect(elements.get(element.id)?.isDeleted).toBe(false);+ expect(isVisible).toBe(true);+ });++ it("keeps an arrow's empty-label gap visible", () => {+ const { before, after } = boundText("arrow");+ expect(apply(before, after)[1]).toBe(true);+ expect(apply(after, before)[1]).toBe(true);+ });++ it("detects a container resized by restoring an empty label", () => {+ const { container, label } = boundText("rectangle");+ const smallContainer = newElementWith(container, {+ width: 20,+ height: 10,+ boundElements: [],+ });+ const before = arrayToMap([+ smallContainer,+ newElementWith(label, { isDeleted: true }),+ ]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(smallContainer, {+ boundElements: [{ id: label.id, type: "text" }],+ }),+ newElementWith(label, { isDeleted: false }),+ ]) as SceneElementsMap;++ const [elements, isVisible] = apply(before, after);+ expect(elements.get(container.id)?.height).toBeGreaterThan(10);+ expect(isVisible).toBe(true);+ });++ it("detects a bound label repositioned by a container's redraw", () => {+ const { container, label } = boundText("rectangle", "hello");+ const misplacedLabel = newElementWith(label, { x: -100, y: -100 });+ const before = arrayToMap([+ container,+ misplacedLabel,+ ]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(container, { version: container.version + 1 }),+ misplacedLabel,+ ]) as SceneElementsMap;++ const [elements, isVisible] = apply(before, after);+ expect(elements.get(container.id)?.height).toBe(container.height);+ expect(elements.get(label.id)?.x).not.toBe(-100);+ expect(isVisible).toBe(true);+ });++ it("detects a bound arrow repositioned by a container's redraw", () => {+ const container = API.createElement({+ type: "rectangle",+ id: "container",+ index: "a0" as FractionalIndex,+ boundElements: [{ id: "arrow", type: "arrow" }],+ });+ const arrow = API.createElement({+ type: "arrow",+ id: "arrow",+ index: "a1" as FractionalIndex,+ x: 200,+ y: 50,+ points: [pointFrom(0, 0), pointFrom(100, 0)],+ startBinding: {+ elementId: container.id,+ mode: "orbit",+ fixedPoint: [1, 0.5],+ },+ });+ const before = arrayToMap([container, arrow]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(container, { version: container.version + 1 }),+ arrow,+ ]) as SceneElementsMap;++ const [elements, isVisible] = apply(before, after);+ expect(elements.get(container.id)?.width).toBe(container.width);+ expect(elements.get(arrow.id)?.x).not.toBe(200);+ expect(isVisible).toBe(true);+ });++ it.each(["test", "development", "production"])(+ "guards against untracked layout mutations in %s mode",+ (mode) => {+ const element = API.createElement({+ type: "rectangle",+ id: "changed",+ index: "a0" as FractionalIndex,+ });+ const unrelated = API.createElement({+ type: "rectangle",+ id: "unrelated",+ index: "a1" as FractionalIndex,+ });+ const before = arrayToMap([element, unrelated]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(element, { strokeColor: "red" }),+ unrelated,+ ]) as SceneElementsMap;+ // Simulate a future layout dependency missing from idsToCheck.+ // Mutate the shared instance so the guard must snapshot version values.+ const redraw = vi+ .spyOn(ElementsDelta, "redrawElements")+ .mockImplementationOnce((elements) => {+ mutateElement(elements.get(unrelated.id)!, elements, {+ x: unrelated.x + 1,+ });+ return elements;+ });+ const consoleError = vi+ .spyOn(console, "error")+ .mockImplementation(() => {});+ vi.stubEnv("MODE", mode);++ try {+ if (mode === "production") {+ expect(apply(before, after)[1]).toBe(true);+ expect(consoleError).not.toHaveBeenCalled();+ } else {+ expect(() => apply(before, after)).toThrow(+ 'Redrawn element "unrelated" is missing from idsToCheck',+ );+ }+ } finally {+ redraw.mockRestore();+ consoleError.mockRestore();+ vi.unstubAllEnvs();+ }+ },+ );++ it("keeps an empty text element's arrow bindings visible", () => {+ const label: ExcalidrawTextElement = {+ ...API.createElement({+ type: "text",+ id: "label",+ index: "a0" as FractionalIndex,+ boundElements: [{ id: "arrow", type: "arrow" }],+ }),+ text: "",+ originalText: "",+ };+ const arrow = API.createElement({+ type: "arrow",+ id: "arrow",+ index: "a1" as FractionalIndex,+ startBinding: {+ elementId: label.id,+ mode: "orbit",+ fixedPoint: [1, 0.5],+ },+ });+ const before = arrayToMap([label, arrow]) as SceneElementsMap;+ const after = arrayToMap([+ newElementWith(label, { isDeleted: true, boundElements: [] }),+ newElementWith(arrow, { startBinding: null }),+ ]) as SceneElementsMap;+ expect(apply(before, after)[1]).toBe(true);+ });+ });+describe("elements delta calculation", () => {it("should not throw when element gets removed but was already deleted", () => {const element = API.createElement({diff --git a/packages/element/tests/linearElementEditor.test.tsx b/packages/element/tests/linearElementEditor.test.tsxindex 468f6f8a5f..a0940ce359 100644--- a/packages/element/tests/linearElementEditor.test.tsx+++ b/packages/element/tests/linearElementEditor.test.tsx@@ -1416,7 +1416,7 @@ describe("Test Linear Elements", () => {expect({ width: container.width, height: container.height }).toMatchInlineSnapshot(`{- "height": 130,+ "height": 150,"width": "366.11716",}`);@@ -1445,11 +1445,11 @@ describe("Test Linear Elements", () => {).toMatchInlineSnapshot(`[20,- 35,+ 45,"501.11716",- 95,+ 220,"205.45894",- "52.50000",+ 145,]`);});@@ -1560,6 +1560,7 @@ describe("Test Linear Elements", () => {"nw",false,false,+ false,);expect(wrapText(diff --git a/packages/element/tests/resize.test.tsx b/packages/element/tests/resize.test.tsxindex 1f16326448..9efe69a181 100644--- a/packages/element/tests/resize.test.tsx+++ b/packages/element/tests/resize.test.tsx@@ -17,6 +17,7 @@ import {import { API } from "@excalidraw/excalidraw/tests/helpers/api";import { UI, Keyboard, Pointer } from "@excalidraw/excalidraw/tests/helpers/ui";import {+ act,render,unmountComponent,} from "@excalidraw/excalidraw/tests/test-utils";@@ -238,6 +239,45 @@ describe("generic element", () => {expect(label.fontSize).toEqual(20);});+ describe.each(["rectangle", "ellipse", "diamond"] as const)(+ "%s with a label",+ (type) => {+ it.each([false, true])(+ "flips horizontally while resizing (proportional: %s)",+ async (proportional) => {+ const container = UI.createElement(type, {+ width: 200,+ height: 100,+ });+ const label = await UI.editText(container, "Hello");++ UI.resize(container, proportional ? "se" : "e", [-500, 0], {+ shift: proportional,+ });++ expect(container.x).toBeCloseTo(-300);+ expect(container.y).toBeCloseTo(0);+ expect(container.width).toBeCloseTo(300);+ expect(container.height).toBeCloseTo(proportional ? 150 : 100);+ expect(label.x + label.width / 2).toBeCloseTo(+ container.x + container.width / 2,+ 0,+ );+ expect(label.y + label.height / 2).toBeCloseTo(+ container.y + container.height / 2,+ 0,+ );+ expect(label.angle).toBe(0);+ if (proportional) {+ expect(label.fontSize).toBeGreaterThan(20);+ } else {+ expect(label.fontSize).toBe(20);+ }+ },+ );+ },+ );+it.each<{ handle: TransformHandleDirection; move: [number, number] }>([{ handle: "n", move: [0, 100] },{ handle: "s", move: [0, -100] },@@ -267,6 +307,47 @@ describe("generic element", () => {expect(rectangle.height).toBeCloseTo(minContainerHeight);},);++ it("keeps the flipped corner anchored while wrapped text sets the minimum height", async () => {+ const rectangle = UI.createElement("rectangle", {+ width: 200,+ height: 200,+ });+ const label = await UI.editText(rectangle, "first second third fourth");+ const originalElements = arrayToMap(+ h.app.scene.getNonDeletedElements().map((element) => ({ ...element })),+ );+ const originalRectangle = originalElements.get(rectangle.id)!;+ let minHeight = 0;++ // One SE drag crosses the top edge, stays below the wrapped text's+ // minimum height, then grows far enough for the pointer to control it.+ for (const nextHeight of [-10, -40, -80, -200]) {+ act(() => {+ resizeSingleElement(+ 80,+ nextHeight,+ h.app.scene.getNonDeletedElement(rectangle.id)!,+ originalRectangle,+ originalElements,+ h.app.scene,+ "se",+ );+ });++ expect(rectangle.x).toBe(originalRectangle.x);+ expect(rectangle.y + rectangle.height).toBe(originalRectangle.y);+ expect(label.y).toBeGreaterThan(rectangle.y);+ expect(label.y + label.height).toBeLessThan(+ rectangle.y + rectangle.height,+ );+ if (nextHeight === -10) {+ minHeight = rectangle.height;+ expect(minHeight).toBeGreaterThan(80);+ }+ expect(rectangle.height).toBe(Math.max(minHeight, -nextHeight));+ }+ });});describe.each(["line", "freedraw"] as const)("%s element", (type) => {@@ -559,6 +640,26 @@ describe("arrow element", () => {expectLabelAtPathMidpoint();expect(label.angle).toBeCloseTo(0);expect(label.fontSize).toEqual(20);++ const { x, width, height } = arrow;+ const latestArrow = h.app.scene.getNonDeletedElement(arrow.id)!;+ act(() => {+ resizeSingleElement(+ -2 * width,+ 2 * height,+ latestArrow,+ { ...latestArrow },+ arrayToMap(h.elements.map((element) => ({ ...element }))),+ h.app.scene,+ "se",+ { shouldMaintainAspectRatio: true },+ );+ });+ expect(getBoundsFromPoints(arrow)[2]).toBeCloseTo(x);+ expect(arrow.width).toBeCloseTo(2 * width);+ expect(label.fontSize).toBeCloseTo(40);+ expect(label.angle).toBeCloseTo(0);+ expectLabelAtPathMidpoint();});it("flips the fixed point binding on negative resize for single bindable", () => {@@ -904,6 +1005,30 @@ describe("image element", () => {});describe("multiple selection", () => {+ it("keeps a flipped text container anchored when its label requires extra height", async () => {+ const rectangle = UI.createElement("rectangle", {+ position: 0,+ width: 200,+ height: 35,+ });+ const label = await UI.editText(rectangle, "hello");+ const other = UI.createElement("rectangle", {+ x: 300,+ y: 0,+ size: 100,+ });+ const originalHeight = rectangle.height;++ // Halve the selection and flip vertically. Padding does not scale with+ // the font, so even a single-line label needs extra container height.+ UI.resize([rectangle, other], "se", [-200, -150], { shift: true });++ expect(label.fontSize).toBeCloseTo(10);+ expect(label.text).toBe("hello");+ expect(rectangle.height).toBeGreaterThan(originalHeight / 2);+ expect(rectangle.y + rectangle.height).toBeCloseTo(0);+ });+it("resizes with generic elements", async () => {const rectangle = UI.createElement("rectangle", {position: 0,diff --git a/packages/excalidraw/CHANGELOG.md b/packages/excalidraw/CHANGELOG.mdindex 705bec3915..91a4150f36 100644--- a/packages/excalidraw/CHANGELOG.md+++ b/packages/excalidraw/CHANGELOG.md@@ -13,6 +13,17 @@ Please add the latest change on the top under the correct section.## Unreleased+### Sticky notes (2026-09-06) [#XXXX](https://github.com/excalidraw/excalidraw/pull/XXXX)++- New `stickynote` element type and toolbar tool (`N`): an always-filled, flat-rendered note whose label auto-fits — the font shrinks from the user's size down to a minimum, and only then does the note grow in height (it never shrinks below the height the user gave it). Click to place a 250×250 note, drag to size it (previewed at the dragged size, snapped to a font-aware minimum on release); text editing starts right away.+- Element model: the note carries `baseHeight` (the user's height; `height ≥ baseHeight`), its label carries `baseFontSize` (the user's font ceiling, `null`/absent on any other text) while `fontSize` holds the fitted size. Read a text element's user-facing size through `getBaseFontSize(text, elementsMap)`.+- Sticky notes are their own color domain: new `appState.currentItemStickynoteStrokeColor` (the note's text color) and `appState.currentItemStickynoteBackgroundColor` defaults, and new customizable top-pick slots `appState.colorTopPicks.stickyNoteStroke` / `stickyNoteBackground`. The stroke and background pickers, both eyedroppers and paste-styles resolve their target (regular / sticky / mixed) at execution time. A note and its label share one ink (the stroke picker reads "Text color" for notes): coloring the label while editing colors the note too, binding a colored text gives the note its color, and the creation-date footer always paints in that ink.+- Skeleton API: `convertToExcalidrawElements([{ type: "stickynote", x, y, label?: { text, fontSize? } }])` creates a note (and fitted label); see the element-skeleton docs.+- Tools can be dragged out of the toolbar: drag the sticky note button onto the canvas to drop a default-sized note where you release it, previewed translucently while dragging (nothing reaches the scene, history or collaborators until the drop; Escape cancels). The mechanism is generic — other tools can opt in.+- Toolbar: on desktop and tablet the image tool moved into the "More tools" menu (still `9`; `UIOptions.tools.image` keeps hiding it; the mobile toolbar keeps its image slot), and tool badges now show the letter shortcuts (`R`, `T`, `N`, …) instead of the numbers, which are no longer contiguous. The number keys keep working.+- Each note shows its creation date (`element.created`) in a footer band — "7 Sep", or "7 Sep 2025" once the year differs — on canvas and in SVG/PNG exports. The band is reserved in the note's layout, so the label never overlaps it; notes without a timestamp keep the band empty.+- Resize semantics: a note's corners resize proportionally by default and scale the label's font ceiling with the note (Shift frees them); its edges resize freely by default (Shift constrains them). Drag-creation is proportional by default too (Shift frees it) and never touches the font ceiling. Width-only gestures keep the base height, height gestures set it, aspect-locked multi-select and Stats group edits scale the ceiling; flips preserve everything. Arrows bound to a note follow it as it grows.+## Excalidraw API### Host-controlled active tool (2026-07-14) [#11665](https://github.com/excalidraw/excalidraw/pull/11665)diff --git a/packages/excalidraw/actions/actionBoundText.tsx b/packages/excalidraw/actions/actionBoundText.tsxindex 806f6eed59..fcdb221b5f 100644--- a/packages/excalidraw/actions/actionBoundText.tsx+++ b/packages/excalidraw/actions/actionBoundText.tsx@@ -6,6 +6,7 @@ import {arrayToMap,getFontString,getStrokeWidthByKey,+ isTransparent,} from "@excalidraw/common";import {getOriginalContainerHeightFromCache,@@ -19,12 +20,15 @@ import {computeBoundTextPosition,computeContainerDimensionForBoundText,getBoundTextElement,+ normalizeStickyNoteFontSize,redrawTextBoundingBox,+ updateStickyNoteLayout,} from "@excalidraw/element";import {hasBoundTextElement,isArrowElement,+ isStickyNoteElement,isTextBindableContainer,isTextElement,isUsingAdaptiveRadius,@@ -87,6 +91,7 @@ export const actionUnbindText = register({width,height,text: boundTextElement.originalText,+ baseFontSize: null,x,y,labelPosition: null,@@ -95,10 +100,17 @@ export const actionUnbindText = register({boundElements: element.boundElements?.filter((ele) => ele.id !== boundTextElement.id,),- height: originalContainerHeight- ? originalContainerHeight- : element.height,});+ if (isStickyNoteElement(element)) {+ // an empty note sits at its base height; bound arrows follow+ updateStickyNoteLayout(element, app.scene);+ } else {+ app.scene.mutateElement(element, {+ height: originalContainerHeight+ ? originalContainerHeight+ : element.height,+ });+ }}});return {@@ -156,6 +168,13 @@ export const actionBindText = register({textElement = selectedElements[1] as ExcalidrawTextElement;container = selectedElements[0] as ExcalidrawTextContainer;}+ // a note and its label share one ink: the text the user styled wins,+ // unless it is transparent (a note's label never is)+ const stickyInk = isStickyNoteElement(container)+ ? isTransparent(textElement.strokeColor)+ ? container.strokeColor+ : textElement.strokeColor+ : null;app.scene.mutateElement(textElement, {containerId: container.id,verticalAlign: VERTICAL_ALIGN.MIDDLE,@@ -165,12 +184,22 @@ export const actionBindText = register({labelPosition: isArrowElement(container)? DEFAULT_BOUND_TEXT_LABEL_POSITION: null,+ ...(stickyInk+ ? {+ baseFontSize: normalizeStickyNoteFontSize(+ textElement.baseFontSize ?? textElement.fontSize,+ ),+ strokeColor: stickyInk,+ }+ : null),});app.scene.mutateElement(container, {boundElements: (container.boundElements || []).concat({type: "text",id: textElement.id,}),+ // the footer paints with the note's ink+ ...(stickyInk ? { strokeColor: stickyInk } : null),});const originalContainerHeight = container.height;redrawTextBoundingBox(textElement, container, app.scene);diff --git a/packages/excalidraw/actions/actionProperties.test.tsx b/packages/excalidraw/actions/actionProperties.test.tsxindex ddcc667652..15a54ddc67 100644--- a/packages/excalidraw/actions/actionProperties.test.tsx+++ b/packages/excalidraw/actions/actionProperties.test.tsx@@ -71,6 +71,18 @@ describe("element locking", () => {expect(hachureFillButton).toBe(null);});+ it("should not show fill style for sticky note tool", () => {+ UI.clickTool("stickynote");++ API.setAppState({+ currentItemBackgroundColor: DEFAULT_ELEMENT_BACKGROUND_PICKS[1],+ currentItemFillStyle: "hachure",+ });+ const hachureFillButton = queryByTestId(document.body, `fill-hachure`);++ expect(hachureFillButton).toBe(null);+ });+it("should show horizontal text align for text tool", () => {UI.clickTool("text");@@ -110,6 +122,19 @@ describe("element locking", () => {expect(crossHatchButton).toBe(null);});+ it("should not show fill style for selected sticky note", () => {+ const stickyNote = API.createElement({+ type: "stickynote",+ backgroundColor: DEFAULT_ELEMENT_BACKGROUND_PICKS[1],+ fillStyle: "hachure",+ });+ API.setElements([stickyNote]);+ API.setSelectedElements([stickyNote]);++ const hachureFillButton = queryByTestId(document.body, `fill-hachure`);+ expect(hachureFillButton).toBe(null);+ });+it("should highlight common stroke width of selected elements", () => {const rect1 = API.createElement({type: "rectangle",diff --git a/packages/excalidraw/actions/actionProperties.tsx b/packages/excalidraw/actions/actionProperties.tsxindex 5b04fc2b68..4464b80c37 100644--- a/packages/excalidraw/actions/actionProperties.tsx+++ b/packages/excalidraw/actions/actionProperties.tsx@@ -6,9 +6,6 @@ import {BUCKET_FILL_BACKGROUND_PICKS,COLOR_PALETTE,DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE,- DEFAULT_ELEMENT_BACKGROUND_PICKS,- DEFAULT_ELEMENT_STROKE_COLOR_PALETTE,- DEFAULT_ELEMENT_STROKE_PICKS,ARROW_TYPE,DEFAULT_FONT_FAMILY,DEFAULT_FONT_SIZE,@@ -31,8 +28,10 @@ import {import {canBecomePolygon,+ normalizeStickyNote,getNonDeletedElements,isNonDeletedElement,+ syncStickyNoteInk,} from "@excalidraw/element";import {@@ -48,6 +47,8 @@ import { getArrowheadForPicker } from "@excalidraw/element";import {getBoundTextElement,+ getBaseFontSize,+ getBaseFontSizeUpdate,redrawTextBoundingBox,} from "@excalidraw/element";@@ -57,11 +58,17 @@ import {isElbowArrow,isLinearElement,isLineElement,+ isStickyNoteElement,isTextElement,isUsingAdaptiveRadius,} from "@excalidraw/element";-import { hasStrokeColor } from "@excalidraw/element";+import {+ getColorTargetElement,+ getColorUpdate,+ hasFillStyle,+ hasStrokeColor,+} from "@excalidraw/element";import {updateElbowArrowPoints,@@ -164,6 +171,10 @@ import {import { getShortcutKey } from "../shortcut";+import {+ getColorTargetAppStateUpdates,+ resolveColorTarget,+} from "./colorTargets";import { register } from "./register";import type { AppClassProperties, AppState, Primitive } from "../types";@@ -203,7 +214,13 @@ export const changeProperty = ("[NONDELETED][INVARIANT] changeProperty(): skipping deleted selected/editing element",);}- return callback(element as NonDeletedExcalidrawElement);+ const nextElement = callback(element as NonDeletedExcalidrawElement);+ // sticky notes keep their data invariants (never-transparent colors,+ // solid fill, minimum size) whatever property was written; a no-op+ // normalization returns the same object+ return isStickyNoteElement(nextElement)+ ? normalizeStickyNote(nextElement)+ : nextElement;}return element;});@@ -282,6 +299,7 @@ const changeFontSize = (fallbackValue?: ExcalidrawTextElement["fontSize"],) => {const newFontSizes = new Set<number>();+ const elementsMap = app.scene.getNonDeletedElementsMap();const updatedElements = changeProperty(elements,@@ -290,15 +308,13 @@ const changeFontSize = (if (isTextElement(oldElement)) {const newFontSize = getNewFontSize(oldElement);newFontSizes.add(newFontSize);+ const container = app.scene.getContainerElement(oldElement);- let newElement: ExcalidrawTextElement = newElementWith(oldElement, {- fontSize: newFontSize,- });- redrawTextBoundingBox(- newElement,- app.scene.getContainerElement(oldElement),- app.scene,+ let newElement: ExcalidrawTextElement = newElementWith(+ oldElement,+ getBaseFontSizeUpdate(oldElement, newFontSize, elementsMap),);+ redrawTextBoundingBox(newElement, container, app.scene);newElement = offsetElementAfterFontResize(oldElement,@@ -340,59 +356,75 @@ const changeFontSize = (// -----------------------------------------------------------------------------export const actionChangeStrokeColor = register<- Pick<AppState, "currentItemStrokeColor">+ Partial<AppState> & { color?: string }>({name: "changeStrokeColor",label: "labels.stroke",trackEvent: false,perform: (elements, appState, value) => {+ const { color, ...appStateUpdates } = value ?? {};+ if (color === undefined) {+ return {+ appState: { ...appState, ...appStateUpdates },+ captureUpdate: CaptureUpdateAction.EVENTUALLY,+ };+ }+ // resolved from the state the action runs against — never from the+ // render-time closure of the memoized picker (see `resolveColorTarget`)+ const target = resolveColorTarget(appState, elements, "strokeColor");+ const elementsMap = arrayToMap(elements);+return {- ...(value?.currentItemStrokeColor && {- elements: changeProperty(+ // a note and its label share one ink: coloring the label while editing+ // it (no selection) colors the note too — the footer paints with it+ elements: syncStickyNoteInk(+ changeProperty(elements,appState,- (el) => {- return hasStrokeColor(el.type)- ? newElementWith(el, {- strokeColor: value.currentItemStrokeColor,- })- : el;- },+ (el) =>+ hasStrokeColor(el.type)+ ? newElementWith(+ el,+ getColorUpdate(el, "strokeColor", color, elementsMap),+ )+ : el,true,),- }),+ elementsMap,+ ),appState: {...appState,- ...value,+ ...appStateUpdates,+ ...getColorTargetAppStateUpdates(target, color),},- captureUpdate: !!value?.currentItemStrokeColor- ? CaptureUpdateAction.IMMEDIATELY- : CaptureUpdateAction.EVENTUALLY,+ captureUpdate: CaptureUpdateAction.IMMEDIATELY,};},- PanelComponent: ({ elements, appState, updateData, app, data }) => {+ PanelComponent: ({ elements, appState, updateData, app }) => {const { stylesPanelMode } = getStylesPanelInfo(app);+ const target = resolveColorTarget(appState, elements, "strokeColor");+ // a note has no stroke: its "stroke" is the ink of its text and footer+ const label =+ target.kind === "sticky" ? t("labels.textColor") : t("labels.stroke");return (<>- {stylesPanelMode === "full" && (- <h3 aria-hidden="true">{t("labels.stroke")}</h3>- )}+ {stylesPanelMode === "full" && <h3 aria-hidden="true">{label}</h3>}<ColorPicker- topPicks={DEFAULT_ELEMENT_STROKE_PICKS}- palette={DEFAULT_ELEMENT_STROKE_COLOR_PALETTE}- customizableTopPicks="elementStroke"+ topPicks={target.topPicks}+ palette={target.palette}+ customizableTopPicks={target.customizableTopPicks}+ excludedColors={target.excludedColors}type="elementStroke"- label={t("labels.stroke")}+ label={label}color={getFormValue(elements,app,(element) => element.strokeColor,true,- (hasSelection) =>- !hasSelection ? appState.currentItemStrokeColor : null,+ (hasSelection) => (!hasSelection ? target.currentValue : null),)}- onChange={(color) => updateData({ currentItemStrokeColor: color })}+ onChange={(color) => updateData({ color })}elements={elements}appState={appState}updateData={updateData}@@ -403,27 +435,29 @@ export const actionChangeStrokeColor = register<});export const actionChangeBackgroundColor = register<- Pick<AppState, "currentItemBackgroundColor" | "viewBackgroundColor">+ Partial<AppState> & { color?: string }>({name: "changeBackgroundColor",label: "labels.changeBackground",trackEvent: false,perform: (elements, appState, value, app) => {- if (!value?.currentItemBackgroundColor) {+ const { color, ...appStateUpdates } = value ?? {};+ if (color === undefined) {return {- appState: {- ...appState,- ...value,- },+ appState: { ...appState, ...appStateUpdates },captureUpdate: CaptureUpdateAction.EVENTUALLY,};}+ const target = resolveColorTarget(appState, elements, "backgroundColor");+ const elementsMap = arrayToMap(elements);let nextElements;const selectedElements = app.scene.getSelectedElements(appState);const shouldEnablePolygon =- !isTransparent(value.currentItemBackgroundColor) &&+ !isTransparent(color) &&+ // `every` is vacuously true with nothing selected (editing text)+ selectedElements.length > 0 &&selectedElements.every((el) => isLineElement(el) && canBecomePolygon(el.points),);@@ -433,7 +467,7 @@ export const actionChangeBackgroundColor = register<nextElements = elements.map((el) => {if (selectedElementsMap.has(el.id) && isLineElement(el)) {return newElementWith(el, {- backgroundColor: value.currentItemBackgroundColor,+ backgroundColor: color,...toggleLinePolygonState(el, true),});}@@ -441,23 +475,49 @@ export const actionChangeBackgroundColor = register<});} else {nextElements = changeProperty(elements, appState, (el) =>- newElementWith(el, {- backgroundColor: value.currentItemBackgroundColor,- }),+ // a note's label passes the pick on to the note (below)+ getColorTargetElement(el, "backgroundColor", elementsMap) === el+ ? newElementWith(+ el,+ getColorUpdate(el, "backgroundColor", color, elementsMap),+ )+ : el,);+ // editing a note's label (no selection): the label has no fill, the+ // pick colors the note — text and background in one editing pass+ const editingText =+ appState.editingTextElement &&+ elementsMap.get(appState.editingTextElement.id);+ const editingTarget =+ editingText &&+ getColorTargetElement(editingText, "backgroundColor", elementsMap);+ if (editingTarget && editingTarget !== editingText) {+ nextElements = nextElements.map((el) =>+ el.id === editingTarget.id+ ? newElementWith(+ el,+ getColorUpdate(el, "backgroundColor", color, elementsMap),+ )+ : el,+ );+ }}return {elements: nextElements,appState: {...appState,- ...value,+ ...appStateUpdates,+ ...getColorTargetAppStateUpdates(target, color),},captureUpdate: CaptureUpdateAction.IMMEDIATELY,};},- PanelComponent: ({ elements, appState, updateData, app, data }) => {+ PanelComponent: ({ elements, appState, updateData, app }) => {const { stylesPanelMode } = getStylesPanelInfo(app);+ const target = resolveColorTarget(appState, elements, "backgroundColor");+ // while editing a note's label the picker shows and sets the note's fill+ const elementsMap = app.scene.getNonDeletedElementsMap();return (<>@@ -465,22 +525,22 @@ export const actionChangeBackgroundColor = register<<h3 aria-hidden="true">{t("labels.background")}</h3>)}<ColorPicker- topPicks={DEFAULT_ELEMENT_BACKGROUND_PICKS}- palette={DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE}- customizableTopPicks="elementBackground"+ topPicks={target.topPicks}+ palette={target.palette}+ customizableTopPicks={target.customizableTopPicks}+ excludedColors={target.excludedColors}type="elementBackground"label={t("labels.background")}color={getFormValue(elements,app,- (element) => element.backgroundColor,+ (element) =>+ getColorTargetElement(element, "backgroundColor", elementsMap)+ .backgroundColor,true,- (hasSelection) =>- !hasSelection ? appState.currentItemBackgroundColor : null,+ (hasSelection) => (!hasSelection ? target.currentValue : null),)}- onChange={(color) =>- updateData({ currentItemBackgroundColor: color })- }+ onChange={(color) => updateData({ color })}elements={elements}appState={appState}updateData={updateData}@@ -557,9 +617,7 @@ export const actionChangeFillStyle = register<ExcalidrawElement["fillStyle"]>({);return {elements: changeProperty(elements, appState, (el) =>- newElementWith(el, {- fillStyle: value,- }),+ hasFillStyle(el.type) ? newElementWith(el, { fillStyle: value }) : el,),appState: { ...appState, currentItemFillStyle: value },captureUpdate: CaptureUpdateAction.IMMEDIATELY,@@ -567,9 +625,12 @@ export const actionChangeFillStyle = register<ExcalidrawElement["fillStyle"]>({},PanelComponent: ({ elements, appState, updateData, app }) => {const selectedElements = getSelectedElements(elements, appState);+ const selectedFillStyleElements = selectedElements.filter((element) =>+ hasFillStyle(element.type),+ );const allElementsZigZag =- selectedElements.length > 0 &&- selectedElements.every((el) => el.fillStyle === "zigzag");+ selectedFillStyleElements.length > 0 &&+ selectedFillStyleElements.every((el) => el.fillStyle === "zigzag");return (<fieldset>@@ -604,7 +665,7 @@ export const actionChangeFillStyle = register<ExcalidrawElement["fillStyle"]>({elements,app,(element) => element.fillStyle,- (element) => element.hasOwnProperty("fillStyle"),+ (element) => hasFillStyle(element.type),(hasSelection) =>hasSelection ? null : appState.currentItemFillStyle,)}@@ -612,7 +673,9 @@ export const actionChangeFillStyle = register<ExcalidrawElement["fillStyle"]>({const nextValue =event.altKey &&value === "hachure" &&- selectedElements.every((el) => el.fillStyle === "hachure")+ selectedFillStyleElements.every(+ (el) => el.fillStyle === "hachure",+ )? "zigzag": value;@@ -989,15 +1052,16 @@ export const actionChangeFontSize = register<ExcalidrawTextElement["fontSize"]>(elements,app,(element) => {+ const elementsMap = app.scene.getNonDeletedElementsMap();if (isTextElement(element)) {- return element.fontSize;+ return getBaseFontSize(element, elementsMap);}const boundTextElement = getBoundTextElement(element,- app.scene.getNonDeletedElementsMap(),+ elementsMap,);if (boundTextElement) {- return boundTextElement.fontSize;+ return getBaseFontSize(boundTextElement, elementsMap);}return null;},@@ -1038,7 +1102,8 @@ export const actionDecreaseFontSize = register({Math.round(// get previous value before relative increase (doesn't work fully// due to rounding and float precision issues)- (1 / (1 + FONT_SIZE_RELATIVE_INCREASE_STEP)) * element.fontSize,+ (1 / (1 + FONT_SIZE_RELATIVE_INCREASE_STEP)) *+ getBaseFontSize(element, app.scene.getNonDeletedElementsMap()),),);},@@ -1059,7 +1124,10 @@ export const actionIncreaseFontSize = register({trackEvent: false,perform: (elements, appState, value, app) => {return changeFontSize(elements, appState, app, (element) =>- Math.round(element.fontSize * (1 + FONT_SIZE_RELATIVE_INCREASE_STEP)),+ Math.round(+ getBaseFontSize(element, app.scene.getNonDeletedElementsMap()) *+ (1 + FONT_SIZE_RELATIVE_INCREASE_STEP),+ ),);},keyTest: (event) => {@@ -1683,7 +1751,7 @@ export const actionChangeRoundness = register<"sharp" | "round">({return el;}- return newElementWith(el, {+ const nextElement = newElementWith(el, {roundness:value === "round"? {@@ -1693,6 +1761,8 @@ export const actionChangeRoundness = register<"sharp" | "round">({}: null,});++ return nextElement;}),appState: {...appState,diff --git a/packages/excalidraw/actions/actionStyles.ts b/packages/excalidraw/actions/actionStyles.tsindex aa1dc78f00..bb1b96906a 100644--- a/packages/excalidraw/actions/actionStyles.ts+++ b/packages/excalidraw/actions/actionStyles.ts@@ -5,18 +5,28 @@ import {CODES,KEYS,getLineHeight,+ arrayToMap,} from "@excalidraw/common";-import { newElementWith } from "@excalidraw/element";+import { newElementWith, syncStickyNoteInk } from "@excalidraw/element";import {+ normalizeStickyNote,hasBoundTextElement,canApplyRoundnessTypeToElement,getDefaultRoundnessTypeForElement,isFrameLikeElement,isArrowElement,isExcalidrawElement,+ getColorUpdate,+ isNonDeletedElement,+ isStickyNoteBoundText,+ isStickyNoteElement,isTextElement,+ getBaseFontSize,+ getBaseFontSizeUpdate,+ relayoutStickyNotes,+ updateBoundElements,} from "@excalidraw/element";import {@@ -86,84 +96,133 @@ export const actionPasteStyles = register({includeBoundTextElement: true,});const selectedElementIds = selectedElements.map((element) => element.id);- return {- elements: elements.map((element) => {- if (selectedElementIds.includes(element.id)) {- let elementStylesToCopyFrom = pastedElement;- if (isTextElement(element) && element.containerId) {- elementStylesToCopyFrom = boundTextElement;- }- if (!elementStylesToCopyFrom) {- return element;- }- let newElement = newElementWith(element, {- backgroundColor: elementStylesToCopyFrom?.backgroundColor,- strokeWidth: elementStylesToCopyFrom?.strokeWidth,- strokeColor: elementStylesToCopyFrom?.strokeColor,- strokeStyle: elementStylesToCopyFrom?.strokeStyle,- fillStyle: elementStylesToCopyFrom?.fillStyle,- opacity: elementStylesToCopyFrom?.opacity,- roughness: elementStylesToCopyFrom?.roughness,- roundness: elementStylesToCopyFrom.roundness- ? canApplyRoundnessTypeToElement(- elementStylesToCopyFrom.roundness.type,- element,- )- ? elementStylesToCopyFrom.roundness- : getDefaultRoundnessTypeForElement(element)- : null,- });-- if (isTextElement(newElement)) {- const fontSize =- (elementStylesToCopyFrom as ExcalidrawTextElement).fontSize ||- DEFAULT_FONT_SIZE;- const fontFamily =- (elementStylesToCopyFrom as ExcalidrawTextElement).fontFamily ||- DEFAULT_FONT_FAMILY;- const newTextElement = newElementWith(newElement, {- fontSize,- fontFamily,- textAlign:- (elementStylesToCopyFrom as ExcalidrawTextElement).textAlign ||- DEFAULT_TEXT_ALIGN,- lineHeight:- (elementStylesToCopyFrom as ExcalidrawTextElement).lineHeight ||- getLineHeight(fontFamily),+ const elementsMap = arrayToMap(elements);+ // whether the copied text was a sticky label is decided by the copied+ // snapshot — its container may be gone from the live scene by now+ const copiedElementsMap = arrayToMap(+ (elementsCopied as unknown[]).filter(isExcalidrawElement),+ );+ const nextElements = relayoutStickyNotes(+ // a restyled note and its label end up with one ink — the label's,+ // when the copied styles carry two colors+ syncStickyNoteInk(+ elements.map((element) => {+ if (selectedElementIds.includes(element.id)) {+ let elementStylesToCopyFrom = pastedElement;+ if (isTextElement(element) && element.containerId) {+ elementStylesToCopyFrom = boundTextElement;+ }+ if (!elementStylesToCopyFrom) {+ return element;+ }+ let newElement = newElementWith(element, {+ backgroundColor: elementStylesToCopyFrom?.backgroundColor,+ strokeWidth: elementStylesToCopyFrom?.strokeWidth,+ strokeColor: elementStylesToCopyFrom?.strokeColor,+ strokeStyle: elementStylesToCopyFrom?.strokeStyle,+ fillStyle: elementStylesToCopyFrom?.fillStyle,+ opacity: elementStylesToCopyFrom?.opacity,+ roughness: elementStylesToCopyFrom?.roughness,+ roundness: elementStylesToCopyFrom.roundness+ ? canApplyRoundnessTypeToElement(+ elementStylesToCopyFrom.roundness.type,+ element,+ )+ ? elementStylesToCopyFrom.roundness+ : getDefaultRoundnessTypeForElement(element)+ : null,});- newElement = newTextElement;- let container = null;- if (newTextElement.containerId) {- container =- selectedElements.find(- (element) => element.id === newTextElement.containerId,- ) || null;++ if (isTextElement(newElement)) {+ const sourceText =+ elementStylesToCopyFrom as ExcalidrawTextElement;+ const fontSize =+ (isTextElement(elementStylesToCopyFrom)+ ? getBaseFontSize(elementStylesToCopyFrom, copiedElementsMap)+ : sourceText.fontSize) || DEFAULT_FONT_SIZE;+ const fontFamily = sourceText.fontFamily || DEFAULT_FONT_FAMILY;+ let container = null;+ const containerId = newElement.containerId;+ if (containerId) {+ container =+ selectedElements.find(+ (element) => element.id === containerId,+ ) || null;+ }+ const newTextElement = newElementWith(newElement, {+ ...getBaseFontSizeUpdate(newElement, fontSize, elementsMap),+ fontFamily,+ textAlign: sourceText.textAlign || DEFAULT_TEXT_ALIGN,+ lineHeight: sourceText.lineHeight || getLineHeight(fontFamily),+ });+ newElement = newTextElement;++ if (isStickyNoteBoundText(newTextElement, elementsMap)) {+ // the copied stroke may be transparent; a note's label never is+ newElement = newElementWith(+ newTextElement,+ getColorUpdate(+ newTextElement,+ "strokeColor",+ newTextElement.strokeColor,+ elementsMap,+ ),+ );+ } else {+ // sticky labels are laid out together with their (possibly+ // also restyled) note in the post-pass below+ redrawTextBoundingBox(newTextElement, container, app.scene);+ }}- redrawTextBoundingBox(newTextElement, container, app.scene);- }+ if (+ newElement.type === "arrow" &&+ isArrowElement(elementStylesToCopyFrom)+ ) {+ newElement = newElementWith(newElement, {+ startArrowhead: elementStylesToCopyFrom.startArrowhead,+ endArrowhead: elementStylesToCopyFrom.endArrowhead,+ });+ }- if (- newElement.type === "arrow" &&- isArrowElement(elementStylesToCopyFrom)- ) {- newElement = newElementWith(newElement, {- startArrowhead: elementStylesToCopyFrom.startArrowhead,- endArrowhead: elementStylesToCopyFrom.endArrowhead,- });- }+ if (isFrameLikeElement(element)) {+ newElement = newElementWith(newElement, {+ roundness: null,+ backgroundColor: "transparent",+ });+ }- if (isFrameLikeElement(element)) {- newElement = newElementWith(newElement, {- roundness: null,- backgroundColor: "transparent",- });+ if (isStickyNoteElement(newElement)) {+ newElement = normalizeStickyNote(newElement);+ }++ return newElement;}+ return element;+ }),+ elementsMap,+ ),+ new Set(selectedElementIds),+ { prevElementsMap: elementsMap },+ );++ // a restyled note may have grown or shrunk — arrows bound to it follow+ for (const element of nextElements) {+ const prev = elementsMap.get(element.id);+ if (+ isStickyNoteElement(element) &&+ isNonDeletedElement(element) &&+ prev &&+ (prev.height !== element.height ||+ prev.x !== element.x ||+ prev.y !== element.y)+ ) {+ updateBoundElements(element, app.scene);+ }+ }- return newElement;- }- return element;- }),+ return {+ elements: nextElements,captureUpdate: CaptureUpdateAction.IMMEDIATELY,};},diff --git a/packages/excalidraw/actions/colorTargets.ts b/packages/excalidraw/actions/colorTargets.tsnew file mode 100644index 0000000000..c38de44679--- /dev/null+++ b/packages/excalidraw/actions/colorTargets.ts@@ -0,0 +1,192 @@+import {+ COLOR_PALETTE,+ DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE,+ DEFAULT_ELEMENT_BACKGROUND_PICKS,+ DEFAULT_ELEMENT_STROKE_COLOR_PALETTE,+ DEFAULT_ELEMENT_STROKE_PICKS,+ STICKY_NOTE_BACKGROUND_PICKS,+ STICKY_NOTE_STROKE_PICKS,+ arrayToMap,+} from "@excalidraw/common";++import {+ getColorTargetElement,+ hasBackground,+ hasStrokeColor,+ isStickyNoteBoundText,+ isStickyNoteElement,+ isTextElement,+ normalizeStickyNoteBackgroundColor,+ normalizeStickyNoteStrokeColor,+} from "@excalidraw/element";++import type { ColorPaletteCustom, ColorTuple } from "@excalidraw/common";+import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";++import { getSelectedElements } from "../scene";++import type { AppState } from "../types";++export type ColorProperty = "strokeColor" | "backgroundColor";++/**+ * Sticky notes are their own color domain: own defaults, own top picks, no+ * transparent. A pick targets the regular domain, the sticky domain, or both+ * ("mixed" selections write both defaults and use the regular picker).+ */+export type ColorTargetKind = "regular" | "sticky" | "mixed";++export type ColorDefaultKey =+ | "currentItemStrokeColor"+ | "currentItemBackgroundColor"+ | "currentItemStickynoteStrokeColor"+ | "currentItemStickynoteBackgroundColor";++export type ColorTargetAppState = Pick<+ AppState,+ "selectedElementIds" | "editingTextElement" | "activeTool" | ColorDefaultKey+>;++export type ColorTarget = {+ kind: ColorTargetKind;+ property: ColorProperty;+ /** the current-item defaults a pick is written to (normalized per domain) */+ appStateKeys: readonly ColorDefaultKey[];+ /** the default shown when no element is targeted */+ currentValue: string;+ palette: ColorPaletteCustom;+ topPicks: ColorTuple;+ customizableTopPicks: keyof AppState["colorTopPicks"];+ excludedColors: readonly string[] | undefined;+};++const DEFAULT_KEYS: Record<+ ColorProperty,+ Record<"regular" | "sticky", ColorDefaultKey>+> = {+ strokeColor: {+ regular: "currentItemStrokeColor",+ sticky: "currentItemStickynoteStrokeColor",+ },+ backgroundColor: {+ regular: "currentItemBackgroundColor",+ sticky: "currentItemStickynoteBackgroundColor",+ },+};++// transparent is hidden rather than removed from the palette so the remaining+// colors keep their usual hotkeys (same mechanism as the bucket fill picker);+// a module constant so the memoized picker's identity comparison holds+const STICKY_NOTE_EXCLUDED_COLORS: readonly string[] = [+ COLOR_PALETTE.transparent,+];++const isStickyNoteColorTarget = (+ element: ExcalidrawElement,+ elementsMap: ElementsMap,+) =>+ isStickyNoteElement(element) ||+ (isTextElement(element) && isStickyNoteBoundText(element, elementsMap));++/**+ * Who a stroke/background pick targets. Resolve it from the state an action+ * runs against, at execution time — never capture it in a render closure:+ * the memoized picker keeps a stale `onChange`, and the always-visible top+ * picks fire it without a re-render.+ *+ * Targets are the selected color-capable elements (for stroke incl. bound+ * labels, since a note's visible text is its label) plus the text being+ * edited (`handleTextWysiwyg` deselects while editing) — or, for a+ * background pick on a note's label, the note (see `getColorTargetElement`).+ * With no target, the active tool decides the domain.+ */+export const resolveColorTarget = (+ appState: ColorTargetAppState,+ elements: readonly ExcalidrawElement[],+ property: ColorProperty,+): ColorTarget => {+ const elementsMap = arrayToMap(elements);+ const supports = (element: ExcalidrawElement) =>+ property === "strokeColor"+ ? hasStrokeColor(element.type)+ : hasBackground(element.type);++ const targets: ExcalidrawElement[] = getSelectedElements(elements, appState, {+ includeBoundTextElement: property === "strokeColor",+ }).filter(supports);+ const editingText =+ appState.editingTextElement &&+ elementsMap.get(appState.editingTextElement.id);+ const editing =+ editingText && getColorTargetElement(editingText, property, elementsMap);+ if (+ editing &&+ !editing.isDeleted &&+ supports(editing) &&+ !targets.some((element) => element.id === editing.id)+ ) {+ targets.push(editing);+ }++ let kind: ColorTargetKind;+ if (!targets.length) {+ kind = appState.activeTool.type === "stickynote" ? "sticky" : "regular";+ } else {+ const stickyCount = targets.filter((element) =>+ isStickyNoteColorTarget(element, elementsMap),+ ).length;+ kind =+ stickyCount === 0+ ? "regular"+ : stickyCount === targets.length+ ? "sticky"+ : "mixed";+ }++ const keys = DEFAULT_KEYS[property];+ const isStroke = property === "strokeColor";++ return {+ kind,+ property,+ appStateKeys: kind === "mixed" ? [keys.regular, keys.sticky] : [keys[kind]],+ currentValue: appState[kind === "sticky" ? keys.sticky : keys.regular],+ palette: isStroke+ ? DEFAULT_ELEMENT_STROKE_COLOR_PALETTE+ : DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE,+ topPicks:+ kind === "sticky"+ ? isStroke+ ? STICKY_NOTE_STROKE_PICKS+ : STICKY_NOTE_BACKGROUND_PICKS+ : isStroke+ ? DEFAULT_ELEMENT_STROKE_PICKS+ : DEFAULT_ELEMENT_BACKGROUND_PICKS,+ customizableTopPicks:+ kind === "sticky"+ ? isStroke+ ? "stickyNoteStroke"+ : "stickyNoteBackground"+ : isStroke+ ? "elementStroke"+ : "elementBackground",+ excludedColors: kind === "sticky" ? STICKY_NOTE_EXCLUDED_COLORS : undefined,+ };+};++/** the current-item default updates for a picked color */+export const getColorTargetAppStateUpdates = (+ target: ColorTarget,+ color: string,+): Partial<AppState> => {+ const updates: Partial<AppState> = {};+ for (const key of target.appStateKeys) {+ updates[key] =+ key === "currentItemStickynoteStrokeColor"+ ? normalizeStickyNoteStrokeColor(color)+ : key === "currentItemStickynoteBackgroundColor"+ ? normalizeStickyNoteBackgroundColor(color)+ : color;+ }+ return updates;+};diff --git a/packages/excalidraw/appState.ts b/packages/excalidraw/appState.tsindex 2fe4a6801c..4686895299 100644--- a/packages/excalidraw/appState.ts+++ b/packages/excalidraw/appState.ts@@ -12,6 +12,7 @@ import {THEME,DEFAULT_GRID_STEP,isTestEnv,+ DEFAULT_STICKY_NOTE_BG,} from "@excalidraw/common";import type { AppState, NormalizedZoomValue } from "./types";@@ -38,6 +39,8 @@ export const getDefaultAppState = (): Omit<currentItemStrokeVariability: "constant",currentItemStartArrowhead: null,currentItemStrokeColor: DEFAULT_ELEMENT_PROPS.strokeColor,+ currentItemStickynoteStrokeColor: DEFAULT_ELEMENT_PROPS.strokeColor,+ currentItemStickynoteBackgroundColor: DEFAULT_STICKY_NOTE_BG,currentItemRoundness: isTestEnv() ? "sharp" : "round",currentItemArrowType: ARROW_TYPE.round,currentItemStrokeStyle: DEFAULT_ELEMENT_PROPS.strokeStyle,@@ -134,6 +137,8 @@ export const getDefaultAppState = (): Omit<elementStroke: null,elementBackground: null,bucketFill: null,+ stickyNoteStroke: null,+ stickyNoteBackground: null,},};};@@ -181,6 +186,16 @@ const APP_STATE_STORAGE_CONF = (<},currentItemStartArrowhead: { browser: true, export: false, server: false },currentItemStrokeColor: { browser: true, export: false, server: false },+ currentItemStickynoteStrokeColor: {+ browser: true,+ export: false,+ server: false,+ },+ currentItemStickynoteBackgroundColor: {+ browser: true,+ export: false,+ server: false,+ },currentItemStrokeStyle: { browser: true, export: false, server: false },currentItemStrokeWidthKey: { browser: true, export: false, server: false },currentItemTextAlign: { browser: true, export: false, server: false },diff --git a/packages/excalidraw/components/App.toolDrag.ts b/packages/excalidraw/components/App.toolDrag.tsnew file mode 100644index 0000000000..b6401858aa--- /dev/null+++ b/packages/excalidraw/components/App.toolDrag.ts@@ -0,0 +1,246 @@+import {+ DEFAULT_STICKY_NOTE_SIZE,+ DRAGGING_THRESHOLD,+ EVENT,+ KEYS,+ getGridPoint,+ viewportCoordsToSceneCoords,+} from "@excalidraw/common";++import { isStickyNoteElement, newStickyNoteElement } from "@excalidraw/element";++import type {+ ExcalidrawNonSelectionElement,+ NonDeleted,+} from "@excalidraw/element/types";++import { trackEvent } from "../analytics";++import type App from "./App";+import type { ToolType } from "../types";++type ScenePoint = { x: number; y: number };++/** what a drag places: any element the new-element canvas can preview */+type DraggedElement = NonDeleted<ExcalidrawNonSelectionElement>;++/**+ * A tool the user can drag out of the toolbar to drop a default-sized element+ * where the pointer is released.+ */+type DraggableTool = {+ /** the element the drop creates, centered on the pointer */+ createElement: (app: App, center: ScenePoint) => DraggedElement;+ /** what the tool does once its element is on the canvas (e.g. start editing) */+ onDrop?: (app: App, element: DraggedElement) => void;+};++const centered = (center: ScenePoint, width: number, height: number) => ({+ x: center.x - width / 2,+ y: center.y - height / 2,+ width,+ height,+});++/**+ * The tools that can be dragged out of the toolbar. Add an entry to make a+ * tool's button draggable — the gesture, preview and drop are shared.+ */+export const DRAGGABLE_TOOLS: Partial<Record<ToolType, DraggableTool>> = {+ stickynote: {+ createElement: (app, center) => {+ const size = DEFAULT_STICKY_NOTE_SIZE;+ const { state } = app;+ return newStickyNoteElement({+ type: "stickynote",+ ...centered(center, size, size),+ baseHeight: size,+ strokeColor: state.currentItemStickynoteStrokeColor,+ backgroundColor: state.currentItemStickynoteBackgroundColor,+ fillStyle: state.currentItemFillStyle,+ strokeWidth: app.getCurrentItemStrokeWidth("stickynote"),+ strokeStyle: state.currentItemStrokeStyle,+ roughness: state.currentItemRoughness,+ opacity: state.currentItemOpacity,+ roundness: app.getCurrentItemRoundness("stickynote"),+ locked: false,+ frameId: app.getTopLayerFrameAtSceneCoords(center)?.id ?? null,+ });+ },+ onDrop: (app, element) => {+ if (isStickyNoteElement(element)) {+ app.startTextEditing({+ sceneX: element.x + element.width / 2,+ sceneY: element.y + element.height / 2,+ container: element,+ });+ }+ },+ },+};++/** CSS opacity of the preview canvas while dragging */+export const TOOL_DRAG_PREVIEW_OPACITY = 0.5;++/**+ * Dragging a tool out of the toolbar. The preview element exists only here+ * until the drop — it is not in the scene, the store or the history, so+ * collaborators never see it and an aborted drag leaves nothing behind. It+ * is painted by the `NewElementCanvas`, drawn exactly as it will land, with+ * the canvas itself made translucent.+ *+ * The button arms on pointerdown; the drag starts once the pointer has+ * moved `DRAGGING_THRESHOLD`, so a plain click still selects the tool. The+ * gesture lives on the owner window (the pointer leaves the button at once),+ * like the other pointer gestures in `App`.+ */+export class AppToolDrag {+ constructor(private app: App) {}++ /** the element under the pointer while dragging, `null` otherwise */+ public preview: DraggedElement | null = null;++ private armed: {+ type: ToolType;+ pointerId: number;+ clientX: number;+ clientY: number;+ } | null = null;++ private tool: DraggableTool | null = null;+ private type: ToolType | null = null;++ static isDraggable = (type: ToolType) => type in DRAGGABLE_TOOLS;++ isDragging = () => this.preview !== null;++ /**+ * Arm a drag from a tool button's pointerdown. Returns whether the tool is+ * draggable (the caller lets a non-draggable press fall through).+ */+ handleButtonPointerDown = (type: ToolType, event: PointerEvent) => {+ const tool = DRAGGABLE_TOOLS[type];+ if (!tool || event.button !== 0 || !this.app.isInteractionEnabled()) {+ return false;+ }+ this.cancel();+ this.armed = {+ type,+ pointerId: event.pointerId,+ clientX: event.clientX,+ clientY: event.clientY,+ };+ this.tool = tool;+ this.type = type;+ this.addListeners();+ return true;+ };++ private onPointerMove = (event: PointerEvent) => {+ if (!this.armed || event.pointerId !== this.armed.pointerId) {+ return;+ }+ if (!this.preview) {+ const moved = Math.hypot(+ event.clientX - this.armed.clientX,+ event.clientY - this.armed.clientY,+ );+ if (moved < DRAGGING_THRESHOLD) {+ return;+ }+ trackEvent("toolbar", this.armed.type, "drag");+ }+ const preview = this.tool!.createElement(+ this.app,+ viewportCoordsToSceneCoords(event, this.app.state),+ );+ // Snap after the tool centers its element, just like click-to-place.+ const [x, y] = getGridPoint(+ preview.x,+ preview.y,+ event[KEYS.CTRL_OR_CMD] ? null : this.app.getEffectiveGridSize(),+ );+ this.preview = { ...preview, x, y };+ this.app.triggerRender();+ };++ private onPointerUp = (event: PointerEvent) => {+ if (!this.armed || event.pointerId !== this.armed.pointerId) {+ return;+ }+ const { preview, tool, type } = this;+ // the button's own click handles a press that never became a drag+ if (!preview) {+ this.cancel();+ return;+ }+ this.cancel();+ if (!this.isOverCanvas(event)) {+ return;+ }+ const { app } = this;+ app.insertNewElement(preview);+ app.store.scheduleCapture();+ app.setState({+ selectedElementIds: { [preview.id]: true },+ selectedGroupIds: {},+ });+ // the drop is a one-off placement: whatever tool was active (an arrow,+ // say) must not stay armed under the dropped element or its editor+ app.setActiveTool(+ { type: app.state.preferredSelectionTool.type },+ { keepSelection: true },+ );+ trackEvent("toolbar", type!, "drop");+ tool!.onDrop?.(app, preview);+ };++ private onKeyDown = (event: KeyboardEvent) => {+ if (event.key === KEYS.ESCAPE) {+ event.stopPropagation();+ this.cancel();+ }+ };++ /** drop the gesture without a trace */+ cancel = () => {+ const wasDragging = this.preview !== null;+ this.armed = null;+ this.tool = null;+ this.type = null;+ this.preview = null;+ this.removeListeners();+ if (wasDragging) {+ this.app.triggerRender();+ }+ };++ private isOverCanvas = (event: PointerEvent) => {+ // the element under the pointer. `elementFromPoint` sees through the+ // implicit capture a touch gives the button; jsdom doesn't implement it,+ // so fall back to the event's target+ const target = (this.app.ownerDocument.elementFromPoint?.(+ event.clientX,+ event.clientY,+ ) ?? event.target) as Element | null;+ return !!target?.closest?.(".excalidraw__canvas");+ };++ private addListeners = () => {+ const { ownerWindow } = this.app;+ ownerWindow.addEventListener(EVENT.POINTER_MOVE, this.onPointerMove);+ ownerWindow.addEventListener(EVENT.POINTER_UP, this.onPointerUp);+ ownerWindow.addEventListener(EVENT.POINTER_CANCEL, this.cancel);+ ownerWindow.addEventListener(EVENT.BLUR, this.cancel);+ ownerWindow.addEventListener(EVENT.KEYDOWN, this.onKeyDown, true);+ };++ private removeListeners = () => {+ const { ownerWindow } = this.app;+ ownerWindow.removeEventListener(EVENT.POINTER_MOVE, this.onPointerMove);+ ownerWindow.removeEventListener(EVENT.POINTER_UP, this.onPointerUp);+ ownerWindow.removeEventListener(EVENT.POINTER_CANCEL, this.cancel);+ ownerWindow.removeEventListener(EVENT.BLUR, this.cancel);+ ownerWindow.removeEventListener(EVENT.KEYDOWN, this.onKeyDown, true);+ };+}diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsxindex da64b07c15..caab87c90b 100644--- a/packages/excalidraw/components/App.tsx+++ b/packages/excalidraw/components/App.tsx@@ -58,6 +58,7 @@ import {DEFAULT_TEXT_ALIGN,ARROW_TYPE,DEFAULT_REDUCED_GLOBAL_ALPHA,+ DEFAULT_STICKY_NOTE_SIZE,isLocalLink,normalizeLink,toValidURL,@@ -127,6 +128,7 @@ import {newFreeDrawElement,newEmbeddableElement,newMagicFrameElement,+ newStickyNoteElement,newIframeElement,newArrowElement,newElement,@@ -155,6 +157,7 @@ import {isElbowArrow,isBindableElement,isTextElement,+ isStickyNoteElement,getNormalizedDimensions,isElementCompletelyInViewport,isElementInViewport,@@ -171,6 +174,9 @@ import {getBoundTextElement,getContainerCenter,getContainerElement,+ getColorUpdate,+ getStickyNoteLayout,+ getStickyNoteMinSize,isValidTextContainer,redrawTextBoundingBox,hasBoundingBox,@@ -289,7 +295,10 @@ import type {ExcalidrawBindableElement,} from "@excalidraw/element/types";-import type { ArrowEndpoint } from "@excalidraw/element";+import type {+ ArrowEndpoint,+ TransformHandleDirection,+} from "@excalidraw/element";import type { Mutable, ValueOf } from "@excalidraw/common/utility-types";@@ -424,6 +433,11 @@ import { EraserTrail } from "../eraser";import { getShortcutKey } from "../shortcut";import { tryParseSpreadsheet } from "../charts";+import {+ getColorTargetAppStateUpdates,+ resolveColorTarget,+} from "../actions/colorTargets";+import ConvertElementTypePopup, {getConversionTypeFromElements,convertElementTypePopupAtom,@@ -433,6 +447,7 @@ import ConvertElementTypePopup, {import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";import { AppArrowText } from "./App.arrowText";import { AppBucketFill } from "./App.bucketFill";+import { AppToolDrag, TOOL_DRAG_PREVIEW_OPACITY } from "./App.toolDrag";import { AppCursor } from "./App.cursor";import { AppDrawShape } from "./App.drawshape";import { AppFlowchart } from "./App.flowchart";@@ -655,7 +670,7 @@ class App extends React.Component<AppProps, AppState> {public library: AppClassProperties["library"];public libraryItemsFromStorage: LibraryItems | undefined;public id: string;- private store: Store;+ public store: Store;private history: History;public excalidrawContainerValue: {container: HTMLDivElement | null;@@ -697,6 +712,7 @@ class App extends React.Component<AppProps, AppState> {public onStateChange: OnStateChange = this.appStateObserver.onStateChange;public bucketFill: AppBucketFill = new AppBucketFill(this);+ public toolDrag: AppToolDrag = new AppToolDrag(this);public flowchart: AppFlowchart = new AppFlowchart(this);public cursor: AppCursor = new AppCursor(this);public arrowText: AppArrowText = new AppArrowText(this);@@ -712,6 +728,13 @@ class App extends React.Component<AppProps, AppState> {hitLinkElement?: NonDeletedExcalidrawElement;lastPointerDownEvent: React.PointerEvent<HTMLElement> | null = null;+ /**+ * the handle of the resize in progress while `state.isResizing` — for UI+ * that words itself by handle (a sticky note's corners resize+ * proportionally, its edges freely); not app state, so it costs no+ * re-render of its own+ */+ activeResizeHandle: TransformHandleDirection | null = null;lastPointerUpEvent: React.PointerEvent<HTMLElement> | PointerEvent | null =null;// TODO this is a hack and we should ideally unify touch and pointer events@@ -2325,6 +2348,10 @@ class App extends React.Component<AppProps, AppState> {const allElementsMap = this.scene.getNonDeletedElementsMap();+ // a tool dragged out of the toolbar previews on the new-element canvas+ // (it is not in the scene until dropped)+ const previewElement = newElementCanvasElement ?? this.toolDrag.preview;+const shouldBlockPointerEvents =// default back to `--ui-pointerEvents` flow if setPointerCapture// not supported@@ -2605,10 +2632,10 @@ class App extends React.Component<AppProps, AppState> {theme: this.state.theme,}}/>- {newElementCanvasElement && (+ {previewElement && (<NewElementCanvasappState={this.state}- newElement={newElementCanvasElement}+ newElement={previewElement}scale={this.ownerWindow.devicePixelRatio}rc={this.rc}elementsMap={renderableElementsMap}@@ -2626,6 +2653,14 @@ class App extends React.Component<AppProps, AppState> {pendingFlowchartNodes: null,theme: this.state.theme,}}+ // a tool dragged out of the toolbar previews+ // translucently; the element itself is drawn+ // exactly as it will land+ opacity={+ this.toolDrag.preview+ ? TOOL_DRAG_PREVIEW_OPACITY+ : undefined+ }/>)}<InteractiveCanvas@@ -2997,36 +3032,54 @@ class App extends React.Component<AppProps, AppState> {colorPickerType:type === "stroke" ? "elementStroke" : "elementBackground",onSelect: (color, event) => {- const shouldUpdateStrokeColor =+ const property =(type === "background" && event.altKey) ||- (type === "stroke" && !event.altKey);+ (type === "stroke" && !event.altKey)+ ? "strokeColor"+ : "backgroundColor";const selectedElements = this.scene.getSelectedElements(this.state);if (!selectedElements.length ||this.state.activeTool.type !== "selection") {- if (shouldUpdateStrokeColor) {- this.syncActionResult({- appState: { ...this.state, currentItemStrokeColor: color },- captureUpdate: CaptureUpdateAction.IMMEDIATELY,- });- } else {- this.syncActionResult({- appState: { ...this.state, currentItemBackgroundColor: color },- captureUpdate: CaptureUpdateAction.IMMEDIATELY,- });- }+ // no target: the pick becomes the default of whichever color+ // domain (regular / sticky note) the active tool draws in+ this.syncActionResult({+ appState: {+ ...this.state,+ ...getColorTargetAppStateUpdates(+ resolveColorTarget(+ this.state,+ this.scene.getNonDeletedElements(),+ property,+ ),+ color,+ ),+ },+ captureUpdate: CaptureUpdateAction.IMMEDIATELY,+ });} else {+ const elementsMap = this.scene.getNonDeletedElementsMap();+ // a note's visible text is its label, so stroke picks include it+ const targetIds = new Set(+ this.scene+ .getSelectedElements({+ selectedElementIds: this.state.selectedElementIds,+ includeBoundTextElement: property === "strokeColor",+ })+ .map((element) => element.id),+ );this.updateScene({- elements: this.scene.getElementsIncludingDeleted().map((el) => {- if (this.state.selectedElementIds[el.id]) {- return newElementWith(el, {- [shouldUpdateStrokeColor ? "strokeColor" : "backgroundColor"]:- color,- });- }- return el;- }),+ elements: this.scene+ .getElementsIncludingDeleted()+ .map((el) =>+ targetIds.has(el.id)+ ? newElementWith(+ el,+ getColorUpdate(el, property, color, elementsMap),+ )+ : el,+ ),captureUpdate: CaptureUpdateAction.IMMEDIATELY,});}@@ -3848,6 +3901,7 @@ class App extends React.Component<AppProps, AppState> {this.library.destroy();this.laserTrails.stop();this.drawShape.stop();+ this.toolDrag.cancel();this.eraserTrail.stop();this.onChangeEmitter.clear();this.store.onStoreIncrementEmitter.clear();@@ -6264,25 +6318,61 @@ class App extends React.Component<AppProps, AppState> {const elementsMap = this.scene.getElementsMapIncludingDeleted();const updateElement = (nextOriginalText: string, isDeleted: boolean) => {+ const latestTextElement = this.scene.getElement<ExcalidrawTextElement>(+ element.id,+ );++ if (!latestTextElement || !isTextElement(latestTextElement)) {+ return;+ }++ const container = getContainerElement(latestTextElement, elementsMap);+ const stickyContainer =+ container && isStickyNoteElement(container) ? container : null;+ // sticky notes: the fit owns both the label and the note geometry+ const stickyLayout = stickyContainer+ ? getStickyNoteLayout(stickyContainer, latestTextElement, {+ originalText: nextOriginalText,+ })+ : null;+this.scene.replaceAllElements([// Not sure why we include deleted elements as well hence using deleted elements map...this.scene.getElementsIncludingDeleted().map((_element) => {- if (_element.id === element.id && isTextElement(_element)) {+ if (+ stickyLayout &&+ _element.id === stickyContainer?.id &&+ isStickyNoteElement(_element)+ ) {+ return newElementWith(_element, stickyLayout.container);+ }+ if (_element.id === latestTextElement.id && isTextElement(_element)) {return newElementWith(_element, {originalText: nextOriginalText,isDeleted: isDeleted ?? _element.isDeleted,- // returns (wrapped) text and new dimensions- ...refreshTextDimensions(- _element,- getContainerElement(_element, elementsMap),- elementsMap,- nextOriginalText,- ),+ ...(stickyLayout?.text ??+ // returns (wrapped) text and new dimensions+ refreshTextDimensions(+ _element,+ getContainerElement(_element, elementsMap),+ elementsMap,+ nextOriginalText,+ )),});}return _element;}),]);++ if (stickyContainer) {+ // the note may have grown or shrunk — arrows bound to it must follow+ const latestContainer = this.scene.getNonDeletedElement(+ stickyContainer.id,+ );+ if (latestContainer) {+ updateBoundElements(latestContainer, this.scene);+ }+ }};this.textWysiwygSubmitHandler = textWysiwyg({@@ -6759,7 +6849,7 @@ class App extends React.Component<AppProps, AppState> {);}- private startTextEditing = ({+ public startTextEditing = ({sceneX,sceneY,insertAtParentCenter = true,@@ -6845,7 +6935,8 @@ class App extends React.Component<AppProps, AppState> {!existingTextElement &&shouldBindToContainer &&container &&- !isArrowElement(container)+ !isArrowElement(container) &&+ !isStickyNoteElement(container)) {const fontString = {fontSize,@@ -6918,7 +7009,11 @@ class App extends React.Component<AppProps, AppState> {newTextElement({x: newTextElementPosition.x,y: newTextElementPosition.y,- strokeColor: this.state.currentItemStrokeColor,+ // a note's stroke color is its text color: the label inherits it+ strokeColor:+ shouldBindToContainer && isStickyNoteElement(container)+ ? container.strokeColor+ : this.state.currentItemStrokeColor,backgroundColor: this.state.currentItemBackgroundColor,fillStyle: this.state.currentItemFillStyle,strokeWidth: this.getCurrentItemStrokeWidth("text"),@@ -6927,6 +7022,10 @@ class App extends React.Component<AppProps, AppState> {opacity: this.state.currentItemOpacity,text: "",fontSize,+ baseFontSize:+ shouldBindToContainer && isStickyNoteElement(container)+ ? fontSize+ : null,fontFamily,textAlign:arrowEndpointBinding?.textAlign ??@@ -10383,10 +10482,11 @@ class App extends React.Component<AppProps, AppState> {}};- private getCurrentItemRoundness(+ public getCurrentItemRoundness(elementType:| "selection"| "rectangle"+ | "stickynote"| "diamond"| "ellipse"| "iframe"@@ -10401,7 +10501,7 @@ class App extends React.Component<AppProps, AppState> {: null;}- private getCurrentItemStrokeWidth(elementType: ExcalidrawElement["type"]) {+ public getCurrentItemStrokeWidth(elementType: ExcalidrawElement["type"]) {return getStrokeWidthByKey(elementType,this.state.currentItemStrokeWidthKey,@@ -10409,7 +10509,7 @@ class App extends React.Component<AppProps, AppState> {}private createGenericElementOnPointerDown = (- elementType: ExcalidrawGenericElement["type"] | "embeddable",+ elementType: ExcalidrawGenericElement["type"] | "embeddable" | "stickynote",pointerDownState: PointerDownState,): void => {const [gridX, gridY] = getGridPoint(@@ -10428,8 +10528,14 @@ class App extends React.Component<AppProps, AppState> {const baseElementAttributes = {x: gridX,y: gridY,- strokeColor: this.state.currentItemStrokeColor,- backgroundColor: this.state.currentItemBackgroundColor,+ strokeColor:+ elementType === "stickynote"+ ? this.state.currentItemStickynoteStrokeColor+ : this.state.currentItemStrokeColor,+ backgroundColor:+ elementType === "stickynote"+ ? this.state.currentItemStickynoteBackgroundColor+ : this.state.currentItemBackgroundColor,fillStyle: this.state.currentItemFillStyle,strokeWidth: this.getCurrentItemStrokeWidth(elementType),strokeStyle: this.state.currentItemStrokeStyle,@@ -10446,6 +10552,11 @@ class App extends React.Component<AppProps, AppState> {type: "embeddable",...baseElementAttributes,});+ } else if (elementType === "stickynote") {+ element = newStickyNoteElement({+ type: "stickynote",+ ...baseElementAttributes,+ });} else {element = newElement({type: elementType,@@ -11545,6 +11656,7 @@ class App extends React.Component<AppProps, AppState> {isCropping,} = this.state;+ this.activeResizeHandle = null;this.setState((prevState) => ({isResizing: false,isRotating: false,@@ -11912,6 +12024,94 @@ class App extends React.Component<AppProps, AppState> {});}+ if (newElement && isStickyNoteElement(newElement)) {+ // a gesture under the drag threshold is a click: the default square,+ // centered on the pointer. A drag keeps its size — previewed+ // unclamped while the pointer is down — and snaps to the minimum+ // only now, growing away from the origin corner like the drag did+ const zoom = this.state.zoom.value;+ const isClick =+ newElement.width * zoom < DRAGGING_THRESHOLD &&+ newElement.height * zoom < DRAGGING_THRESHOLD;+ let nextGeometry;+ if (isClick) {+ const size = DEFAULT_STICKY_NOTE_SIZE;+ // Snap after centering: half the default size need not be on the grid.+ const [x, y] = getGridPoint(+ pointerDownState.origin.x - size / 2,+ pointerDownState.origin.y - size / 2,+ childEvent[KEYS.CTRL_OR_CMD] ? null : this.getEffectiveGridSize(),+ );+ nextGeometry = {+ x,+ y,+ width: size,+ height: size,+ };+ } else {+ // one line at the current font ceiling must fit, or the note would+ // grow on the first keystroke+ const minSize = getStickyNoteMinSize({+ fontSize: this.state.currentItemFontSize,+ fontFamily: this.state.currentItemFontFamily,+ });+ let width = Math.max(newElement.width, minSize.width);+ let height = Math.max(newElement.height, minSize.height);+ if (!shouldMaintainAspectRatio(childEvent)) {+ // a plain drag is proportional (Shift frees it); the two floors+ // differ, so the square is kept through the snap+ width = height = Math.max(width, height);+ }+ const { originInGrid } = pointerDownState;+ nextGeometry = {+ // a drag toward the top/left put the note's origin before the+ // pointer origin; that far edge stays put when the size grows+ x:+ newElement.x < originInGrid.x+ ? originInGrid.x - width+ : newElement.x,+ y:+ newElement.y < originInGrid.y+ ? originInGrid.y - height+ : newElement.y,+ width,+ height,+ };+ }++ this.scene.mutateElement(+ newElement,+ { ...nextGeometry, baseHeight: nextGeometry.height },+ { informMutation: false, isDragging: false },+ );++ this.store.scheduleCapture();+ this.scene.triggerUpdate();++ if (activeTool.locked) {+ this.setState((prevState) => ({+ newElement: null,+ selectedElementIds: makeNextSelectedElementIds({}, prevState),+ }));+ this.cursor.applyForTool();+ return;+ }++ this.cursor.reset();+ this.setState({+ newElement: null,+ activeTool: updateActiveTool(this.state, {+ type: this.state.preferredSelectionTool.type,+ }),+ });+ this.startTextEditing({+ sceneX: newElement.x + newElement.width / 2,+ sceneY: newElement.y + newElement.height / 2,+ container: newElement,+ });+ return;+ }+if (activeTool.type !== "selection" &&newElement &&@@ -13407,9 +13607,12 @@ class App extends React.Component<AppProps, AppState> {y: gridY,width: distance(pointerDownState.originInGrid.x, gridX),height: distance(pointerDownState.originInGrid.y, gridY),- shouldMaintainAspectRatio: isImageElement(newElement)- ? !shouldMaintainAspectRatio(event)- : shouldMaintainAspectRatio(event),+ // images and sticky notes are proportional by default — Shift frees+ // them; every other shape is free by default and Shift constrains it+ shouldMaintainAspectRatio:+ isImageElement(newElement) || isStickyNoteElement(newElement)+ ? !shouldMaintainAspectRatio(event)+ : shouldMaintainAspectRatio(event),shouldResizeFromCenter: shouldResizeFromCenter(event),zoom: this.state.zoom.value,scene: this.scene,@@ -13551,6 +13754,10 @@ class App extends React.Component<AppProps, AppState> {return false;}+ this.activeResizeHandle =+ transformHandleType && transformHandleType !== "rotation"+ ? transformHandleType+ : null;this.setState({// TODO: rename this state field to "isScaling" to distinguish// it from the generic "isResizing" which includes scaling and@@ -13623,6 +13830,16 @@ class App extends React.Component<AppProps, AppState> {});}+ // images are proportional by default, and so is a sticky note's corner+ // (its label's font ceiling scales with it); Shift frees them. A note's+ // edges stay free by default — Shift constrains them like any shape.+ const proportionalByDefault =+ selectedElements.some((element) => isImageElement(element)) ||+ (selectedElements.length === 1 &&+ isStickyNoteElement(selectedElements[0]) &&+ typeof transformHandleType === "string" &&+ transformHandleType.length === 2);+if (transformElements(pointerDownState.originalElements,@@ -13631,7 +13848,7 @@ class App extends React.Component<AppProps, AppState> {this.scene,shouldRotateWithDiscreteAngle(event),shouldResizeFromCenter(event),- selectedElements.some((element) => isImageElement(element))+ proportionalByDefault? !shouldMaintainAspectRatio(event): shouldMaintainAspectRatio(event),resizeX,diff --git a/packages/excalidraw/components/CommandPalette/CommandPalette.tsx b/packages/excalidraw/components/CommandPalette/CommandPalette.tsxindex a58c7958cb..31dafd50ca 100644--- a/packages/excalidraw/components/CommandPalette/CommandPalette.tsx+++ b/packages/excalidraw/components/CommandPalette/CommandPalette.tsx@@ -6,6 +6,7 @@ import {DEFAULT_SIDEBAR,EVENT,KEYS,+ arrayToMap,isWritableElement,} from "@excalidraw/common";@@ -486,7 +487,11 @@ function CommandPaletteInner({const selectedElements = getSelectedElements(elements, appState);return (selectedElements.length > 0 &&- canChangeBackgroundColor(appState, selectedElements)+ canChangeBackgroundColor(+ appState,+ selectedElements,+ arrayToMap(elements),+ ));},perform: () => {diff --git a/packages/excalidraw/components/HelpDialog.tsx b/packages/excalidraw/components/HelpDialog.tsxindex 82d0032289..4f373c2702 100644--- a/packages/excalidraw/components/HelpDialog.tsx+++ b/packages/excalidraw/components/HelpDialog.tsx@@ -179,6 +179,7 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {label={t("toolBar.text")}shortcuts={[KEYS.T, KEYS["8"]]}/>+ <Shortcut label={t("toolBar.stickynote")} shortcuts={[KEYS.N]} /><Shortcut label={t("toolBar.image")} shortcuts={[KEYS["9"]]} /><Shortcutlabel={t("toolBar.eraser")}diff --git a/packages/excalidraw/components/HintViewer.tsx b/packages/excalidraw/components/HintViewer.tsxindex e6f3b5a16a..a344b96039 100644--- a/packages/excalidraw/components/HintViewer.tsx+++ b/packages/excalidraw/components/HintViewer.tsx@@ -6,6 +6,7 @@ import {isImageElement,isLinearElement,isLineElement,+ isStickyNoteElement,isTextBindableContainer,isTextElement,} from "@excalidraw/element";@@ -104,6 +105,10 @@ const getHints = ({return t("hints.embeddable");}+ if (activeTool.type === "stickynote") {+ return t("hints.stickynote");+ }+if (activeTool.type === "autoshape") {return t("hints.autoshape");}@@ -119,6 +124,17 @@ const getHints = ({shortcut: getTaggedShortcutKey("Shift"),});}+ if (+ isStickyNoteElement(targetElement) &&+ // a note's corners are proportional by default (Shift frees them); its+ // edges are free by default, so they get the generic hint below+ app.activeResizeHandle?.length === 2+ ) {+ return t("hints.resizeStickyNote", {+ shortcut_1: getTaggedShortcutKey("Shift"),+ shortcut_2: getTaggedShortcutKey("Alt"),+ });+ }return isImageElement(targetElement)? t("hints.resizeImage", {shortcut_1: getTaggedShortcutKey("Shift"),diff --git a/packages/excalidraw/components/IconButton.tsx b/packages/excalidraw/components/IconButton.tsxindex dc5dff6409..7413907cf1 100644--- a/packages/excalidraw/components/IconButton.tsx+++ b/packages/excalidraw/components/IconButton.tsx@@ -56,6 +56,8 @@ type IconButtonProps =* (unlike the click event's own pointerType on iOS).*/onSelect?(data: { pointerType: PointerType | null }): void;+ /** the press that may become a click — e.g. to arm a drag out of the toolbar */+ onPointerDown?(event: React.PointerEvent<HTMLButtonElement>): void;});export const IconButton = React.forwardRef(@@ -172,6 +174,7 @@ export const IconButton = React.forwardRef(aria-disabled={!!props.disabled}onPointerDown={(event) => {lastPointerTypeRef.current = event.pointerType || null;+ props.onPointerDown?.(event);}}onPointerUp={() => {requestAnimationFrame(() => {diff --git a/packages/excalidraw/components/LayerUI.tsx b/packages/excalidraw/components/LayerUI.tsxindex 006e581cf7..798570e58f 100644--- a/packages/excalidraw/components/LayerUI.tsx+++ b/packages/excalidraw/components/LayerUI.tsx@@ -10,7 +10,7 @@ import {isShallowEqual,} from "@excalidraw/common";-import { mutateElement } from "@excalidraw/element";+import { getColorUpdate, mutateElement } from "@excalidraw/element";import { showSelectedShapeActions } from "@excalidraw/element";@@ -25,7 +25,12 @@ import { UIAppStateContext } from "../context/ui-appState";import { useAtom, useAtomValue } from "../editor-jotai";import { t } from "../i18n";-import { getScrollToContentState } from "../scene";+import { getScrollToContentState, getSelectedElements } from "../scene";+import {+ getColorTargetAppStateUpdates,+ resolveColorTarget,+ type ColorDefaultKey,+} from "../actions/colorTargets";import { SelectedShapeActions, CompactShapeActions } from "./Actions";import { LoadingMessage } from "./LoadingMessage";@@ -527,26 +532,38 @@ const LayerUI = ({return;}+ const property =+ altKey && eyeDropperState.swapPreviewOnAlt+ ? colorPickerType === "elementBackground"+ ? "strokeColor"+ : "backgroundColor"+ : colorPickerType === "elementBackground"+ ? "backgroundColor"+ : "strokeColor";+if (selectedElements.length) {- for (const element of selectedElements) {- mutateElement(element, arrayToMap(elements), {- [altKey && eyeDropperState.swapPreviewOnAlt- ? colorPickerType === "elementBackground"- ? "strokeColor"- : "backgroundColor"- : colorPickerType === "elementBackground"- ? "backgroundColor"- : "strokeColor"]: color,- });+ const elementsMap = arrayToMap(elements);+ // a note's visible text is its label, so stroke picks+ // include bound labels+ const targets = getSelectedElements(elements, appState, {+ includeBoundTextElement: property === "strokeColor",+ });+ for (const element of targets) {+ mutateElement(+ element,+ elementsMap,+ getColorUpdate(element, property, color, elementsMap),+ );ShapeCache.delete(element);}app.scene.triggerUpdate();- } else if (colorPickerType === "elementBackground") {- setAppState({- currentItemBackgroundColor: color,- });} else {- setAppState({ currentItemStrokeColor: color });+ setAppState(+ getColorTargetAppStateUpdates(+ resolveColorTarget(appState, elements, property),+ color,+ ) as Pick<AppState, ColorDefaultKey>,+ );}}}onSelect={(color, event) => {diff --git a/packages/excalidraw/components/MobileToolbar.tsx b/packages/excalidraw/components/MobileToolbar.tsxindex 6591c95f0a..15c3559580 100644--- a/packages/excalidraw/components/MobileToolbar.tsx+++ b/packages/excalidraw/components/MobileToolbar.tsx@@ -33,6 +33,7 @@ import {bucketFillIcon,mermaidLogoIcon,MagicIcon,+ stickyNoteToolIcon,} from "./icons";import "./ToolIcon.scss";@@ -78,6 +79,7 @@ export const MobileToolbar = ({ app, setAppState }: MobileToolbarProps) => {const laserToolSelected = activeTool.type === "laser";const embeddableToolSelected = activeTool.type === "embeddable";const bucketFillToolSelected = activeTool.type === "bucketfill";+ const stickyNoteToolSelected = activeTool.type === "stickynote";const { TTDDialogTriggerTunnel } = useTunnels();@@ -114,6 +116,7 @@ export const MobileToolbar = ({ app, setAppState }: MobileToolbarProps) => {const extraTools: readonly typeof activeTool.type[] = (["text",+ "stickynote","frame","embeddable","laser",@@ -137,6 +140,8 @@ export const MobileToolbar = ({ app, setAppState }: MobileToolbarProps) => {? ImageIcon: activeTool.type === "frame"? frameToolIcon+ : activeTool.type === "stickynote"+ ? stickyNoteToolIcon: activeTool.type === "embeddable"? EmbedIcon: activeTool.type === "laser"@@ -278,6 +283,17 @@ export const MobileToolbar = ({ app, setAppState }: MobileToolbarProps) => {{t("toolBar.image")}</DropdownMenu.Item>)}+ <DropdownMenu.Item+ onSelect={() => app.setActiveTool({ type: "stickynote" })}+ icon={stickyNoteToolIcon}+ shortcut={KEYS.N.toLocaleUpperCase()}+ data-testid="toolbar-stickynote"+ selected={stickyNoteToolSelected}+ disabled={isToolButtonDisabled(app, "stickynote")}+ >+ {t("toolBar.stickynote")}+ </DropdownMenu.Item>+{!showFrameToolOutside && (<DropdownMenu.ItemonSelect={() => app.setActiveTool({ type: "frame" })}diff --git a/packages/excalidraw/components/Stats/DragInput.tsx b/packages/excalidraw/components/Stats/DragInput.tsxindex 2943d767da..f673d3a5d9 100644--- a/packages/excalidraw/components/Stats/DragInput.tsx+++ b/packages/excalidraw/components/Stats/DragInput.tsx@@ -128,7 +128,10 @@ const StatsDragInput = <stateRef.current.updatePending = false;const parsed = Number(updatedValue);- if (isNaN(parsed)) {+ // Number.isFinite also rejects "Infinity"/"1e999", which `isNaN` lets+ // through — non-finite values corrupt element geometry (NaN/Infinity+ // don't survive the JSON round-trip on save)+ if (!Number.isFinite(parsed)) {setInputValue(value.toString());return;}@@ -143,11 +146,20 @@ const StatsDragInput = <// reason: idempotent to avoid unnecessaryif (isNaN(original) || Math.abs(rounded - original) >= SMALLEST_DELTA) {stateRef.current.lastUpdatedValue = updatedValue;+ // a real snapshot (copies), like the pointer-drag path builds: the+ // callbacks derive gesture-start values from it — e.g. a sticky note's+ // width and its label's font ceiling — and the live map would already+ // carry the change they apply. A typed value is applied once, so the+ // scene at this point still is the original.+ const originalElementsMap: ElementsMap = new Map();+ for (const element of app.scene.getNonDeletedElements()) {+ originalElementsMap.set(element.id, deepCopyElement(element));+ }dragInputCallback({accumulatedChange: 0,instantChange: 0,originalElements: elements,- originalElementsMap: app.scene.getNonDeletedElementsMap(),+ originalElementsMap,shouldKeepAspectRatio: shouldKeepAspectRatio!!,shouldChangeByStepSize: false,scene,diff --git a/packages/excalidraw/components/Stats/FontSize.tsx b/packages/excalidraw/components/Stats/FontSize.tsxindex 62edcf7b46..5cbdce8cce 100644--- a/packages/excalidraw/components/Stats/FontSize.tsx+++ b/packages/excalidraw/components/Stats/FontSize.tsx@@ -1,5 +1,7 @@import {getBoundTextElement,+ getBaseFontSize,+ getBaseFontSizeUpdate,redrawTextBoundingBox,} from "@excalidraw/element";import { hasBoundTextElement, isTextElement } from "@excalidraw/element";@@ -53,7 +55,9 @@ const handleFontSizeChange: DragInputCallbackType<if (nextValue !== undefined) {nextFontSize = Math.max(Math.round(nextValue), MIN_FONT_SIZE);} else if (origElement.type === "text") {- const originalFontSize = Math.round(origElement.fontSize);+ const originalFontSize = Math.round(+ getBaseFontSize(origElement, elementsMap),+ );const changeInFontSize = Math.round(accumulatedChange);nextFontSize = Math.max(originalFontSize + changeInFontSize,@@ -65,9 +69,10 @@ const handleFontSizeChange: DragInputCallbackType<}if (nextFontSize) {- scene.mutateElement(latestElement, {- fontSize: nextFontSize,- });+ scene.mutateElement(+ latestElement,+ getBaseFontSizeUpdate(latestElement, nextFontSize, elementsMap),+ );redrawTextBoundingBox(latestElement,scene.getContainerElement(latestElement),@@ -91,7 +96,11 @@ const FontSize = ({ element, scene, appState, property }: FontSizeProps) => {return (<StatsDragInputlabel="F"- value={Math.round(_element.fontSize * 10) / 10}+ value={+ Math.round(+ getBaseFontSize(_element, scene.getNonDeletedElementsMap()) * 10,+ ) / 10+ }elements={[_element]}dragInputCallback={handleFontSizeChange}icon={fontSizeIcon}diff --git a/packages/excalidraw/components/Stats/MultiDimension.tsx b/packages/excalidraw/components/Stats/MultiDimension.tsxindex ec59bd568b..64a83172da 100644--- a/packages/excalidraw/components/Stats/MultiDimension.tsx+++ b/packages/excalidraw/components/Stats/MultiDimension.tsx@@ -9,6 +9,12 @@ import {replaceAllElementsInFrame,updateBoundElements,} from "@excalidraw/element";+import {+ getStickyNoteResizeIntent,+ isStickyNoteBoundText,+ isStickyNoteElement,+ updateStickyNoteLayout,+} from "@excalidraw/element";import {rescalePointsInElement,resizeSingleElement,@@ -85,10 +91,35 @@ const resizeElementInGroup = (scene: Scene,) => {const elementsMap = scene.getNonDeletedElementsMap();++ if (+ isTextElement(latestElement) &&+ isStickyNoteBoundText(latestElement, elementsMap)+ ) {+ // a group unit lists the note's label too; the note's layout owns it+ // entirely (a direct scale here would overwrite the fitted size)+ return;+ }+const updates = getResizedUpdates(anchorX, anchorY, scale, origElement);scene.mutateElement(latestElement, updates);+ if (isStickyNoteElement(latestElement)) {+ // group scaling is uniform: base height and font ceiling scale with the+ // note (empty notes included); the layout runs the arrow pass itself+ updateStickyNoteLayout(latestElement, scene, {+ ...getStickyNoteResizeIntent(+ latestElement,+ originalElementsMap,+ property === "width" ? "e" : "s",+ { proportional: true, fromCenter: false },+ ),+ anchor: "top",+ });+ return;+ }+const boundTextElement = getBoundTextElement(origElement,originalElementsMap,diff --git a/packages/excalidraw/components/Stats/MultiFontSize.tsx b/packages/excalidraw/components/Stats/MultiFontSize.tsxindex 921bfb021c..8d1f76965a 100644--- a/packages/excalidraw/components/Stats/MultiFontSize.tsx+++ b/packages/excalidraw/components/Stats/MultiFontSize.tsx@@ -1,5 +1,7 @@import {getBoundTextElement,+ getBaseFontSize,+ getBaseFontSizeUpdate,redrawTextBoundingBox,} from "@excalidraw/element";import { hasBoundTextElement, isTextElement } from "@excalidraw/element";@@ -81,9 +83,10 @@ const handleFontSizeChange: DragInputCallbackType<nextFontSize = Math.max(Math.round(nextValue), MIN_FONT_SIZE);for (const textElement of latestTextElements) {- scene.mutateElement(textElement, {- fontSize: nextFontSize,- });+ scene.mutateElement(+ textElement,+ getBaseFontSizeUpdate(textElement, nextFontSize, elementsMap),+ );redrawTextBoundingBox(textElement,@@ -100,7 +103,9 @@ const handleFontSizeChange: DragInputCallbackType<const latestElement = latestTextElements[i];const originalElement = originalTextElements[i];- const originalFontSize = Math.round(originalElement.fontSize);+ const originalFontSize = Math.round(+ getBaseFontSize(originalElement, elementsMap),+ );const changeInFontSize = Math.round(accumulatedChange);let nextFontSize = Math.max(originalFontSize + changeInFontSize,@@ -109,9 +114,10 @@ const handleFontSizeChange: DragInputCallbackType<if (shouldChangeByStepSize) {nextFontSize = getStepSizedValue(nextFontSize, STEP_SIZE);}- scene.mutateElement(latestElement, {- fontSize: nextFontSize,- });+ scene.mutateElement(+ latestElement,+ getBaseFontSizeUpdate(latestElement, nextFontSize, elementsMap),+ );redrawTextBoundingBox(latestElement,@@ -138,7 +144,7 @@ const MultiFontSize = ({}const fontSizes = latestTextElements.map(- (textEl) => Math.round(textEl.fontSize * 10) / 10,+ (textEl) => Math.round(getBaseFontSize(textEl, elementsMap) * 10) / 10,);const value = new Set(fontSizes).size === 1 ? fontSizes[0] : "Mixed";const editable = fontSizes.length > 0;diff --git a/packages/excalidraw/components/Stats/stats.test.tsx b/packages/excalidraw/components/Stats/stats.test.tsxindex a146f9a476..e74cd7d8cb 100644--- a/packages/excalidraw/components/Stats/stats.test.tsx+++ b/packages/excalidraw/components/Stats/stats.test.tsx@@ -241,6 +241,24 @@ describe("stats for a generic element", () => {expect(rectangle.width).toBe(88.99);});+ it("should reject non-finite values", () => {+ const rectangle = h.elements[0];++ const input = UI.queryStatsProperty("W")?.querySelector(+ ".drag-input",+ ) as HTMLInputElement;+ expect(input).toBeDefined();++ UI.updateInput(input, "100");+ expect(rectangle.width).toBe(100);++ for (const garbage of ["Infinity", "-Infinity", "1e999"]) {+ UI.updateInput(input, garbage);+ expect(rectangle.width).toBe(100);+ expect(input.value).toBe("100");+ }+ });+it("should update input x and y when angle is changed", () => {const rectangle = h.elements[0];const [cx, cy] = [diff --git a/packages/excalidraw/components/Toolbar.tsx b/packages/excalidraw/components/Toolbar.tsxindex cc85b8c0a2..3507672821 100644--- a/packages/excalidraw/components/Toolbar.tsx+++ b/packages/excalidraw/components/Toolbar.tsx@@ -17,6 +17,7 @@ import {drawShapeToolIcon,EmbedIcon,frameToolIcon,+ ImageIcon,LassoIcon,laserPointerToolIcon,bucketFillIcon,@@ -33,13 +34,13 @@ import {FreedrawToolButton,getToolShortcut,HandToolButton,- ImageToolButton,isToolButtonDisabled,LassoToolButton,LineToolButton,RectangleToolButton,SelectionToolButton,SelectionToolPopover,+ StickyNoteToolButton,TextToolButton,} from "./Tools";@@ -54,15 +55,18 @@ const ExtraToolsDropdown = ({app,activeTool,setAppState,+ UIOptions,}: {app: AppClassProperties;activeTool: UIAppState["activeTool"];setAppState: React.Component<any, AppState>["setState"];+ UIOptions: AppProps["UIOptions"];}) => {const [isExtraToolsMenuOpen, setIsExtraToolsMenuOpen] = useState(false);const isFullStylesPanel = useStylesPanelMode() === "full";const { TTDDialogTriggerTunnel } = useTunnels();+ const imageToolSelected = activeTool.type === "image";const frameToolSelected = activeTool.type === "frame";const drawShapeToolSelected = activeTool.type === "autoshape";const laserToolSelected = activeTool.type === "laser";@@ -78,6 +82,7 @@ const ExtraToolsDropdown = ({<DropdownMenu.TriggerclassName={clsx("App-toolbar__extra-tools-trigger", {"App-toolbar__extra-tools-trigger--selected":+ imageToolSelected ||frameToolSelected ||embeddableToolSelected ||(isFullStylesPanel && drawShapeToolSelected) ||@@ -94,7 +99,9 @@ const ExtraToolsDropdown = ({}}title={t("toolBar.extraTools")}>- {frameToolSelected+ {imageToolSelected+ ? ImageIcon+ : frameToolSelected? frameToolIcon: embeddableToolSelected? EmbedIcon@@ -113,6 +120,18 @@ const ExtraToolsDropdown = ({onSelect={() => setIsExtraToolsMenuOpen(false)}className="App-toolbar__extra-tools-dropdown">+ {UIOptions.tools?.image !== false && (+ <DropdownMenu.Item+ onSelect={() => app.setActiveTool({ type: "image" })}+ icon={ImageIcon}+ shortcut={KEYS["9"]}+ data-testid="toolbar-image"+ selected={imageToolSelected}+ disabled={isToolButtonDisabled(app, "image")}+ >+ {t("toolBar.image")}+ </DropdownMenu.Item>+ )}<DropdownMenu.ItemonSelect={() => app.setActiveTool({ type: "frame" })}icon={frameToolIcon}@@ -287,7 +306,7 @@ export const Toolbar = ({<FreedrawToolButton {...toolProps} />)}<TextToolButton {...toolProps} />- {UIOptions.tools?.image !== false && <ImageToolButton {...toolProps} />}+ <StickyNoteToolButton {...toolProps} /><EraserToolButton {...toolProps} /><div@@ -299,6 +318,7 @@ export const Toolbar = ({app={app}activeTool={activeTool}setAppState={setAppState}+ UIOptions={UIOptions}/></Stack.Row></Island>diff --git a/packages/excalidraw/components/Tools.tsx b/packages/excalidraw/components/Tools.tsxindex 30930504ce..25e60c33f9 100644--- a/packages/excalidraw/components/Tools.tsx+++ b/packages/excalidraw/components/Tools.tsx@@ -29,6 +29,7 @@ import {handIcon,frameToolIcon,EmbedIcon,+ stickyNoteToolIcon,} from "./icons";import type {@@ -40,7 +41,7 @@ import type {export type ToolConfig = {icon: React.ReactNode;- /** letter shortcut(s) — the first one is shown in tooltips */+ /** letter shortcut(s) — the first one is shown in tooltips and badges */letterKey?: string | readonly string[];/** whether `letterKey` requires Shift to be held (e.g. Shift+X) */shiftKey?: boolean;@@ -117,6 +118,10 @@ export const TOOLS = defineTools({letterKey: KEYS.T,numericKey: KEYS["8"],},+ stickynote: {+ icon: stickyNoteToolIcon,+ letterKey: KEYS.N,+ },image: {icon: ImageIcon,numericKey: KEYS["9"],@@ -286,11 +291,16 @@ const createToolButton = (keyBindingLabel={hideKeyBinding || hideShortcut? undefined- : TOOLS[shortcutType].numericKey || getToolLetter(shortcutType)+ : getToolLetter(shortcutType) || TOOLS[shortcutType].numericKey}aria-label={label}aria-keyshortcuts={shortcut ?? undefined}data-testid={`toolbar-${type}`}+ onPointerDown={(event) => {+ // a draggable tool can be dragged out onto the canvas; a press that+ // stays put is still a click (`onSelect`)+ app.toolDrag.handleButtonPointerDown(type, event.nativeEvent);+ }}onSelect={({ pointerType }) => {if (!app.state.penDetected && pointerType === "pen") {app.togglePenMode(true);@@ -323,6 +333,7 @@ export const ArrowToolButton = createToolButton("arrow");export const LineToolButton = createToolButton("line");export const FreedrawToolButton = createToolButton("freedraw");export const TextToolButton = createToolButton("text");+export const StickyNoteToolButton = createToolButton("stickynote");export const ImageToolButton = createToolButton("image");export const EraserToolButton = createToolButton("eraser");export const FrameToolButton = createToolButton("frame");diff --git a/packages/excalidraw/components/canvases/NewElementCanvas.tsx b/packages/excalidraw/components/canvases/NewElementCanvas.tsxindex dd8948b1f3..288b3d1d8a 100644--- a/packages/excalidraw/components/canvases/NewElementCanvas.tsx+++ b/packages/excalidraw/components/canvases/NewElementCanvas.tsx@@ -20,6 +20,8 @@ interface NewElementCanvasProps {scale: number;rc: RoughCanvas;renderConfig: StaticCanvasRenderConfig;+ /** CSS opacity of the whole canvas — a translucent preview of a finished element */+ opacity?: number;}const NewElementCanvas = (props: NewElementCanvasProps) => {@@ -49,6 +51,7 @@ const NewElementCanvas = (props: NewElementCanvasProps) => {style={{width: props.appState.width,height: props.appState.height,+ opacity: props.opacity,}}width={props.appState.width * props.scale}height={props.appState.height * props.scale}diff --git a/packages/excalidraw/components/icons.tsx b/packages/excalidraw/components/icons.tsxindex de4f899435..a05d5b27e8 100644--- a/packages/excalidraw/components/icons.tsx+++ b/packages/excalidraw/components/icons.tsx@@ -1987,6 +1987,17 @@ export const frameToolIcon = createIcon(tablerIconProps,);+export const stickyNoteToolIcon = createIcon(+ <g strokeWidth={1.5}>+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>+ <path d="M6 4h12a2 2 0 0 1 2 2v9l-5 5h-9a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z"></path>+ <path d="M14 20v-4a2 2 0 0 1 2 -2h4"></path>+ <path d="M8 9h8"></path>+ <path d="M8 13h5"></path>+ </g>,+ tablerIconProps,+);+export const mermaidLogoIcon = createIcon(<pathfill="currentColor"diff --git a/packages/excalidraw/components/shapeActionPredicates.ts b/packages/excalidraw/components/shapeActionPredicates.tsindex f1857e4f4e..d1f0c14b91 100644--- a/packages/excalidraw/components/shapeActionPredicates.ts+++ b/packages/excalidraw/components/shapeActionPredicates.ts@@ -3,6 +3,7 @@ import { isTransparent } from "@excalidraw/common";import {shouldAllowVerticalAlign,suppportsHorizontalAlign,+ getColorTargetElement,hasBoundTextElement,isElbowArrow,isImageElement,@@ -13,6 +14,7 @@ import {} from "@excalidraw/element";import type {+ ElementsMap,ExcalidrawElement,ExcalidrawElementType,NonDeletedElementsMap,@@ -25,7 +27,9 @@ import {canHaveArrowheads,getSelectedElements,hasBackground,+ hasFillStyle,hasFreedrawMode,+ hasRoughness,hasStrokeStyle,hasStrokeWidth,} from "../scene";@@ -60,10 +64,17 @@ export const canChangeStrokeColor = (export const canChangeBackgroundColor = (appState: UIAppState,targetElements: ExcalidrawElement[],+ elementsMap: ElementsMap,) => {return (hasBackground(appState.activeTool.type) ||- targetElements.some((element) => hasBackground(element.type))+ // a note's label (the target while editing it) has no fill, but a+ // background pick on it colors the note — so the picker stays available+ targetElements.some((element) =>+ hasBackground(+ getColorTargetElement(element, "backgroundColor", elementsMap).type,+ ),+ ));};@@ -111,24 +122,27 @@ export const getShapeActionPredicates = (// colorstrokeColor: canChangeStrokeColor(appState, targetElements),- backgroundColor: canChangeBackgroundColor(appState, targetElements),+ backgroundColor: canChangeBackgroundColor(+ appState,+ targetElements,+ elementsMap,+ ),fill:// bucket fill never renders transparent (it falls back to a real// color), so its fill style stays relevant either wayactiveToolType === "bucketfill" ||- (hasBackground(activeToolType) &&+ (hasFillStyle(activeToolType) &&!isTransparent(appState.currentItemBackgroundColor)) ||targetElements.some((element) =>- hasBackground(element.type) &&- !isTransparent(element.backgroundColor),+ hasFillStyle(element.type) && !isTransparent(element.backgroundColor),),// stroke / shape propertiesstrokeWidth: forToolOrSelection(hasStrokeWidth),freedrawMode: forToolOrSelection(hasFreedrawMode),strokeStyle: forToolOrSelection(hasStrokeStyle),- sloppiness: forToolOrSelection(hasStrokeStyle),+ sloppiness: forToolOrSelection(hasRoughness),roundness: forToolOrSelection(canChangeRoundness),arrowType: forToolOrSelection(toolIsArrow),arrowheads: forToolOrSelection(canHaveArrowheads),diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.tsindex b6932a4632..cc52b29f8e 100644--- a/packages/excalidraw/data/restore.ts+++ b/packages/excalidraw/data/restore.ts@@ -10,6 +10,7 @@ import {COLOR_TOP_PICKS_SLOTS,type CombineBrandsIfNeeded,DEFAULT_FONT_FAMILY,+ DEFAULT_FONT_SIZE,DEFAULT_STROKE_STREAMLINE,DEFAULT_TEXT_ALIGN,DEFAULT_VERTICAL_ALIGN,@@ -29,6 +30,7 @@ import {STROKE_WIDTH,STROKE_WIDTH_KEYS,type StrokeWidthKey,+ isTransparent,} from "@excalidraw/common";import {calculateFixedPointForNonElbowArrowBinding,@@ -45,8 +47,17 @@ import {validateElbowPoints,} from "@excalidraw/element";import { LinearElementEditor } from "@excalidraw/element";-import { bumpVersion } from "@excalidraw/element";-import { getContainerElement } from "@excalidraw/element";+import {+ bumpVersion,+ getStickyNoteLayout,+ isStickyNoteBoundText,+ normalizeStickyNote,+ normalizeStickyNoteBackgroundColor,+ normalizeStickyNoteFontSize,+ normalizeStickyNoteStrokeColor,+} from "@excalidraw/element";+import { getBoundTextElement, getContainerElement } from "@excalidraw/element";+import { isStickyNoteElement } from "@excalidraw/element";import { detectLineHeight } from "@excalidraw/element";import {isArrowBoundToElement,@@ -222,6 +233,7 @@ export const AllowedExcalidrawActiveTools: Record<image: true,arrow: true,freedraw: true,+ stickynote: true,eraser: false,custom: true,frame: true,@@ -532,6 +544,9 @@ export const restoreElement = (fontSize = parseFloat(fontPx);fontFamily = getFontFamilyByName(_fontFamily);}+ if (!isFiniteNumber(fontSize)) {+ fontSize = DEFAULT_FONT_SIZE;+ }const text = (typeof element.text === "string" && element.text) || "";// line-height might not be specified either when creating elements@@ -560,6 +575,11 @@ export const restoreElement = (labelPosition: isFiniteNumber(element.labelPosition)? clamp(element.labelPosition, 0, 1): null,+ // only meaningful for sticky note labels; reconciled against the+ // container in `restoreStickyNotes` once bindings are repaired+ baseFontSize: isFiniteNumber(element.baseFontSize)+ ? normalizeStickyNoteFontSize(element.baseFontSize)+ : null,});// if empty text, mark as deleted. We keep in array@@ -711,6 +731,15 @@ export const restoreElement = (case "iframe":case "embeddable":return restoreElementWithProperties(element, {});+ case "stickynote":+ return normalizeStickyNote(+ restoreElementWithProperties(element, {+ baseHeight:+ element.baseHeight ??+ (element as typeof element & { maxHeight?: number }).maxHeight ??+ element.height,+ }),+ );case "magicframe":case "frame":return restoreElementWithProperties(element, {@@ -859,6 +888,63 @@ const repairFrameMembership = (}};+/**+ * Sticky note invariants that need both halves of the pair present, so they+ * run after binding repair. Mutates elements (like the repair helpers).+ * - a label's `baseFontSize` is meaningful only while bound to a sticky note:+ * seeded from `fontSize` when missing, cleared everywhere else+ * - a sticky label's stroke is never transparent (it is the visible text)+ * - a note's stroke — its ink, which the footer paints with — equals its label's+ * - with `refreshDimensions`, the note and its label are refitted together+ */+const restoreStickyNotes = (+ elements: readonly ExcalidrawElement[],+ elementsMap: ElementsMap,+ opts: { refreshDimensions: boolean },+) => {+ for (const element of elements) {+ if (!isTextElement(element) || element.isDeleted) {+ continue;+ }+ if (isStickyNoteBoundText(element, elementsMap)) {+ const container = elementsMap.get(element.containerId!);+ // one ink per note: a transparent label takes the note's color;+ // otherwise the label — the visible text — wins over a note that+ // drifted (edit-mode coloring on older builds)+ const strokeColor = normalizeStickyNoteStrokeColor(+ isTransparent(element.strokeColor)+ ? container?.strokeColor+ : element.strokeColor,+ );+ Object.assign(element, {+ baseFontSize: normalizeStickyNoteFontSize(+ element.baseFontSize ?? element.fontSize,+ ),+ strokeColor,+ });+ if (container && container.strokeColor !== strokeColor) {+ Object.assign(container, { strokeColor });+ }+ } else if (element.baseFontSize != null) {+ Object.assign(element, { baseFontSize: null });+ }+ }++ if (opts.refreshDimensions) {+ for (const element of elements) {+ if (!isStickyNoteElement(element) || element.isDeleted) {+ continue;+ }+ const textElement = getBoundTextElement(element, elementsMap);+ const layout = getStickyNoteLayout(element, textElement);+ Object.assign(element, layout.container);+ if (textElement && layout.text) {+ Object.assign(textElement, layout.text);+ }+ }+ }+};+export const restoreElements = <T extends ExcalidrawElement>(targetElements: readonly T[] | undefined | null,/** used for additional context (e.g. repairing arrow bindings) */@@ -945,7 +1031,12 @@ export const restoreElements = <T extends ExcalidrawElement>(repairContainerElement(element, restoredElementsMap);}- if (opts.refreshDimensions && isTextElement(element)) {+ if (+ opts.refreshDimensions &&+ isTextElement(element) &&+ // sticky labels are refitted together with their note below+ !isStickyNoteBoundText(element, restoredElementsMap)+ ) {Object.assign(element,refreshTextDimensions(@@ -974,6 +1065,10 @@ export const restoreElements = <T extends ExcalidrawElement>(}}+ restoreStickyNotes(restoredElements, restoredElementsMap, {+ refreshDimensions: !!opts.refreshDimensions,+ });+const repairedElements = repairBoundTextElementOrder(restoredElements);// NOTE (mtolmacs): Temporary fix for invalid/self-bound elbow arrows@@ -1193,6 +1288,12 @@ export const restoreAppState = (bucketFill: restoreColorTopPicksList(nextAppState.colorTopPicks?.bucketFill,),+ stickyNoteStroke: restoreColorTopPicksList(+ nextAppState.colorTopPicks?.stickyNoteStroke,+ ),+ stickyNoteBackground: restoreColorTopPicksList(+ nextAppState.colorTopPicks?.stickyNoteBackground,+ ),};// legacy@@ -1239,6 +1340,12 @@ export const restoreAppState = (gridStep: getNormalizedGridStep(isFiniteNumber(appState.gridStep) ? appState.gridStep : DEFAULT_GRID_STEP,),+ currentItemStickynoteStrokeColor: normalizeStickyNoteStrokeColor(+ nextAppState.currentItemStickynoteStrokeColor,+ ),+ currentItemStickynoteBackgroundColor: normalizeStickyNoteBackgroundColor(+ nextAppState.currentItemStickynoteBackgroundColor,+ ),editingFrame: null,};};diff --git a/packages/excalidraw/locales/en.json b/packages/excalidraw/locales/en.jsonindex 4a6fa1de49..3c0733e2fc 100644--- a/packages/excalidraw/locales/en.json+++ b/packages/excalidraw/locales/en.json@@ -27,6 +27,7 @@"copyStyles": "Copy styles","pasteStyles": "Paste styles","stroke": "Stroke",+ "textColor": "Text color","changeStroke": "Change stroke color","background": "Background","changeBackground": "Change background color",@@ -332,6 +333,7 @@"eraser": "Eraser","frame": "Frame tool","magicframe": "Wireframe to code",+ "stickynote": "Sticky note","embeddable": "Web Embed","laser": "Laser pointer","autoshape": "Draw to shape",@@ -357,6 +359,7 @@"group": "Group","frame": "Frame","magicframe": "Wireframe to code",+ "stickynote": "Sticky note","embeddable": "Web Embed","selection": "Selection","iframe": "IFrame"@@ -375,6 +378,7 @@"freeDraw": "Click and drag, release when you're finished","text": "Tip: you can also add text by double-clicking anywhere with the selection tool","embeddable": "Click-drag to create a website embed",+ "stickynote": "Click to place a note, or drag to size it","autoshape": "Draw rectangles, circles, diamonds, lines and arrows","text_selected": "Double-click or press {{shortcut}} to edit text","text_editing": "Press {{shortcut_1}} or {{shortcut_2}} to finish editing",@@ -382,6 +386,7 @@"lockAngle": "You can constrain angle by holding {{shortcut}}","resize": "You can constrain proportions by holding {{shortcut_1}} while resizing,\nhold {{shortcut_2}} to resize from the center","resizeImage": "You can resize freely by holding {{shortcut_1}},\nhold {{shortcut_2}} to resize from the center",+ "resizeStickyNote": "hold {{shortcut_1}} to resize freely, {{shortcut_2}} to resize from the center","rotate": "You can constrain angles by holding {{shortcut}} while rotating","toggleArrowhead": "Double-click to toggle the arrowhead","lineEditor_info": "Hold {{shortcut_1}} and Double-click or press {{shortcut_2}} to edit points",diff --git a/packages/excalidraw/renderer/staticSvgScene.ts b/packages/excalidraw/renderer/staticSvgScene.tsindex 488fbaa475..17f69cfa50 100644--- a/packages/excalidraw/renderer/staticSvgScene.ts+++ b/packages/excalidraw/renderer/staticSvgScene.ts@@ -11,6 +11,10 @@ import {getVerticalOffset,applyDarkModeFilter,MIME_TYPES,+ STICKY_NOTE_EDGE_SHADOW_OPACITY,+ STICKY_NOTE_EDGE_SHADOW_WIDTH,+ STICKY_NOTE_FOOTER,+ STICKY_NOTE_SHADOW_OPACITY,} from "@excalidraw/common";import { normalizeLink, toValidURL } from "@excalidraw/common";import { hashString } from "@excalidraw/element";@@ -34,6 +38,11 @@ import { getContainingFrame } from "@excalidraw/element";import { getCornerRadius, isPathALoop } from "@excalidraw/element";import { ShapeCache } from "@excalidraw/element";+import {+ getStickyNoteFooter,+ getStickyNotePathCommands,+ type StickyNotePathCommand,+} from "@excalidraw/element";import { getElementAbsoluteCoords } from "@excalidraw/element";@@ -146,6 +155,119 @@ const renderElementToSvg = (// this should not happenthrow new Error("Selection rendering is not supported for SVG");}+ case "stickynote": {+ const getPathData = (commands: StickyNotePathCommand[]) =>+ commands+ .map((command) => {+ if (command.type === "move") {+ return `M ${command.point.x} ${command.point.y}`;+ }+ if (command.type === "line") {+ return `L ${command.point.x} ${command.point.y}`;+ }+ return `Q ${command.control.x} ${command.control.y} ${command.point.x} ${command.point.y}`;+ })+ .join(" ")+ .concat(" Z");++ const createPath = (+ commands: StickyNotePathCommand[],+ fill: string,+ fillOpacity?: number,+ ) => {+ const path = svgRoot.ownerDocument.createElementNS(SVG_NS, "path");+ path.setAttribute("d", getPathData(commands));+ path.setAttribute("fill", fill);+ if (typeof fillOpacity !== "undefined") {+ path.setAttribute("fill-opacity", `${fillOpacity}`);+ }+ path.setAttribute("stroke", "none");+ return path;+ };++ const group = svgRoot.ownerDocument.createElementNS(SVG_NS, "g");+ group.setAttribute(+ "transform",+ `translate(${offsetX || 0} ${+ offsetY || 0+ }) rotate(${degree} ${cx} ${cy})`,+ );+ if (opacity !== 1) {+ group.setAttribute("opacity", `${opacity}`);+ }++ const shadow = createPath(+ getStickyNotePathCommands(element, { shadow: true }),+ "#000",+ STICKY_NOTE_SHADOW_OPACITY,+ );+ const commands = getStickyNotePathCommands(element);+ const rect = createPath(+ commands,+ applyDarkModeFilter(+ element.backgroundColor,+ renderConfig.theme === THEME.DARK,+ ),+ );+ const clipPath = svgRoot.ownerDocument.createElementNS(+ SVG_NS,+ "clipPath",+ );+ clipPath.setAttribute("id", `sticky-note-clipPath-${element.id}`);+ clipPath.setAttribute("clipPathUnits", "userSpaceOnUse");+ clipPath.appendChild(createPath(commands, "#000"));+ addToRoot(clipPath, element);++ const edgeShadow = createPath(commands, "none");+ edgeShadow.setAttribute("stroke", "#000");+ edgeShadow.setAttribute(+ "stroke-opacity",+ `${STICKY_NOTE_EDGE_SHADOW_OPACITY}`,+ );+ edgeShadow.setAttribute(+ "stroke-width",+ `${STICKY_NOTE_EDGE_SHADOW_WIDTH * 2}`,+ );+ edgeShadow.setAttribute("clip-path", `url(#${clipPath.id})`);++ group.appendChild(shadow);+ group.appendChild(rect);+ group.appendChild(edgeShadow);++ const footer = getStickyNoteFooter(element);+ if (footer) {+ const dateText = svgRoot.ownerDocument.createElementNS(SVG_NS, "text");+ dateText.setAttribute("x", `${footer.x}`);+ dateText.setAttribute("y", `${footer.y}`);+ dateText.setAttribute("font-family", STICKY_NOTE_FOOTER.fontFamily);+ dateText.setAttribute("font-size", `${STICKY_NOTE_FOOTER.fontSize}px`);+ // `text-anchor` is logical in SVG: pin the direction so an RTL host+ // page can't flip the label to the left edge+ dateText.setAttribute("text-anchor", "end");+ dateText.setAttribute("direction", "ltr");+ dateText.setAttribute(+ "fill",+ applyDarkModeFilter(+ element.strokeColor,+ renderConfig.theme === THEME.DARK,+ ),+ );+ dateText.setAttribute("fill-opacity", `${STICKY_NOTE_FOOTER.opacity}`);+ dateText.textContent = footer.text;+ group.appendChild(dateText);+ }++ const g = maybeWrapNodesInFrameClipPath(+ element,+ root,+ [group],+ renderConfig.frameRendering,+ elementsMap,+ );++ addToRoot(g || group, element);+ break;+ }case "rectangle":case "diamond":case "ellipse": {diff --git a/packages/excalidraw/scene/index.ts b/packages/excalidraw/scene/index.tsindex 75ee9933a2..68f1acccf8 100644--- a/packages/excalidraw/scene/index.ts+++ b/packages/excalidraw/scene/index.ts@@ -7,6 +7,8 @@ export {export { getScrollToContentState } from "../viewport";export {hasBackground,+ hasFillStyle,+ hasRoughness,hasStrokeWidth,hasStrokeStyle,hasFreedrawMode,diff --git a/packages/excalidraw/scene/types.ts b/packages/excalidraw/scene/types.tsindex a98dc884d1..d67628388a 100644--- a/packages/excalidraw/scene/types.ts+++ b/packages/excalidraw/scene/types.ts@@ -170,6 +170,7 @@ export type ElementShapes = {arrow: Drawable[];line: Drawable[];text: null;+ stickynote: null;image: null;frame: null;magicframe: null;diff --git a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snapindex 05f0af708a..55066011c6 100644--- a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap+++ b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap@@ -19,6 +19,8 @@ exports[`contextMenu element > right-clicking on a group should select whole gro"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": {"items": [@@ -907,6 +909,8 @@ exports[`contextMenu element > right-clicking on a group should select whole gro"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1100,6 +1104,8 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1114,6 +1120,8 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1322,6 +1330,8 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1336,6 +1346,8 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1663,6 +1675,8 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1677,6 +1691,8 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2004,6 +2020,8 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2018,6 +2036,8 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2226,6 +2246,8 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2240,6 +2262,8 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2475,6 +2499,8 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2489,6 +2515,8 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2783,6 +2811,8 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2797,6 +2827,8 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3165,6 +3197,8 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3179,6 +3213,8 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s"currentItemRoughness": 2,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#e03131","currentItemStrokeStyle": "dotted","currentItemStrokeVariability": "constant",@@ -3695,6 +3731,8 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3709,6 +3747,8 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4028,6 +4068,8 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4042,6 +4084,8 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4361,6 +4405,8 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4375,6 +4421,8 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4782,6 +4830,8 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": {"items": [@@ -5670,6 +5720,8 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -6009,6 +6061,8 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": {"items": [@@ -6897,6 +6951,8 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7287,6 +7343,8 @@ exports[`contextMenu element > shows context menu for canvas > [end of test] app"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": {"items": [@@ -7864,6 +7922,8 @@ exports[`contextMenu element > shows context menu for canvas > [end of test] app"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7982,6 +8042,8 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": {"items": [@@ -8870,6 +8932,8 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8979,6 +9043,8 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": {"items": [@@ -9867,6 +9933,8 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",diff --git a/packages/excalidraw/tests/__snapshots__/export.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/export.test.tsx.snapindex b56ff0ef37..475a336842 100644--- a/packages/excalidraw/tests/__snapshots__/export.test.tsx.snap+++ b/packages/excalidraw/tests/__snapshots__/export.test.tsx.snap@@ -1,7 +1,7 @@// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.htmlexports[`export > export svg-embedded scene > svg-embdedded scene export output 1`] = `-"<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36" width="36" height="36"><!-- svg-source:excalidraw --><metadata><!-- payload-type:application/vnd.excalidraw+json --><!-- payload-version:2 --><!-- payload-start -->eyJ2ZXJzaW9uIjoiMSIsImVuY29kaW5nIjoiYnN0cmluZyIsImNvbXByZXNzZWQiOnRydWUsImVuY29kZWQiOiJ4nHVTwY7TMFx1MDAxML3zXHUwMDE1UfaK2LRcYlx1MDAwZb0tsCv2sFxiUSRcdTAwMGWIg1x1MDAxYk+TUV3bsifblqpcdTAwMTKfwY1f5Fx1MDAxM1x1MDAxODshrtPdVorkNzN+b96Mjy+KoqSDhXJRlLCvhULpxK58XHUwMDE58EdwXHUwMDFljebQPJ696VxcXHUwMDFkM1tcIru4vlaGXHUwMDBiWuNp8bqqqr5cYlx1MDAxNGxBk+e073wuimP8clx1MDAwNGUovYlpXHUwMDEx+M9LsKeE7lx1MDAxOarG0yE77VBSy8js7VxitYBNSzkmdKMgK/TkzFx1MDAwNt5cdTAwMWJlXFxgvJpB+CfSlag3jTOdlmNcdTAwMGU5ob1cdTAwMTWOm0l5a1RqSYd4O/vBbpVcdTAwMTOOb4PE+Vx1MDAwNH+uikmbVoNcdTAwMGaGzUbUWFEjheZnVepcIii09zJ6+yNpcmJcdTAwMGL3wVxc3Sk1wqgl7KdgbHFgy1x1MDAwMlx1MDAxZUBmXG7S8C+wT0bXub3oP/DcKV6xXHUwMDE2ykMyNlx1MDAxMN6mnchIOytcdTAwMDVNeGtcdTAwMDdcdTAwMTeYQr2Z1vLubZ7gi7vELv/98/vX2diMpiX+XGai51WG3oktquDzm+yKXHUwMDFihU3ovVSwPlx1MDAxYj9cdTAwMWJAyDs/hsnYXHUwMDE0rfk+gVx1MDAxYdzlMIzDXHUwMDA2tVBfn5QnOjJfwPdcdTAwMDLJdXDeOXxcdTAwMWM3/NU8qVRiXHUwMDA16rPxSP2UXHUwMDAyXYyd+Fx1MDAxYpejXHUwMDE01i6JzeRo/1xieYFQTnzoMVx1MDAwMps8iNCDkXCrxUpNTS5cdTAwMWZcdTAwMTF27y7fy9U6/oauhvk8dIpwybtRXHUwMDA3mWFcdTAwMDGOQd8p6uPHXHUwMDA0XHUwMDAzdPpcdTAwMDfOLTWbIn0=<!-- payload-end --></metadata><defs><style class="style-fonts">+"<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36" width="36" height="36"><!-- svg-source:excalidraw --><metadata><!-- payload-type:application/vnd.excalidraw+json --><!-- payload-version:2 --><!-- payload-start -->eyJ2ZXJzaW9uIjoiMSIsImVuY29kaW5nIjoiYnN0cmluZyIsImNvbXByZXNzZWQiOnRydWUsImVuY29kZWQiOiJ4nHVTwY7TMFx1MDAxML3zXHUwMDE1UfaK2LRcYlx1MDAwZb3twq7Yw1wiRJE4IFx1MDAwZW48TUZ1bcuebFuqSnxcdTAwMDY3fpFPYOyEuE6XVorkN555b96Mjy+KoqSDhXJRlLCvhULpxK58XHUwMDE58CdwXHUwMDFljebQPJ696VxcXHUwMDFkb7ZEdnF9rVxmJ7TG0+J1VVV9XHUwMDEyKNiCJs/XvvG5KI7xy1x1MDAxMZQh9SZei8A/XoI9JXTPUDWeXHUwMDBl2WmHklpGZm9HqFx1MDAwNWxayjGhXHUwMDFiXHUwMDA1WaInZzbwzijjXHUwMDAy49VcZsI/ka5EvWmc6bRcdTAwMWPvkFx1MDAxM9pb4biZdG+NSi3pXHUwMDEwq7NcdTAwMWbsVjnh+DpInE/w/2UxadNq8MGw2YhcdTAwMWEraqTQ/KxKXVx1MDAwNIX2QUZvvydNTmzhIZirO6VGXHUwMDE4tYT9XHUwMDE0jC1cdTAwMGVsWcBcdTAwMDPITEFcdTAwMWH+XHUwMDA19tHoOrdcdTAwMTf9e547xVx1MDAxMmuhPCRjXHUwMDAz4V3aiYy0s1LQhLd2cIEp1JtpLu/e5lx1MDAxOb64S+zyn9+/fp6NzWha4o8gel6dXHLdw32KZOVDxr3YolxuM3iTlb9R2Fx1MDAwNF9KXHUwMDA167PVYHNcYvk9jGEyNkVrridQg7tcdTAwMWOUcdigXHUwMDE26suz0kVH5jP4XlwiuVx1MDAwZc5dgVx1MDAwZuP2v5onlUqsQH0yXHUwMDFlqZ9goIuxXHUwMDEzf+PilMLaJbHRXHUwMDFj7Vx1MDAxZigvXHUwMDE3yolHPUZgk1x1MDAwN1x1MDAxMXo0XHUwMDEy7rRYqelcdTAwMDDKJ4Td7eVbulrH39DVMLvHTlx1MDAxMS55b+ogMyzHMeg7RX380GCATn9cdTAwMDFWrz23In0=<!-- payload-end --></metadata><defs><style class="style-fonts"></style></defs><rect x="0" y="0" width="36" height="36" fill="#ffffff"></rect><g transform="translate(10 10) rotate(0 8 8)" data-id="A"><text x="0" y="17.619999999999997" font-family="Excalifont, Xiaolai, sans-serif, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="start" style="white-space: pre;" direction="ltr" dominant-baseline="alphabetic">😀</text></g></svg>"`;diff --git a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snapindex a93459daf4..2eb9478123 100644--- a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap+++ b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap@@ -19,6 +19,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -33,6 +35,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -665,6 +669,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -679,6 +685,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1238,6 +1246,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1252,6 +1262,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1609,6 +1621,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1623,6 +1637,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1981,6 +1997,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1995,6 +2013,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2254,6 +2274,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2268,6 +2290,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2719,6 +2743,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2733,6 +2759,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2862,6 +2890,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -2903,6 +2932,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -3034,6 +3064,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3048,6 +3080,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3177,6 +3211,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -3218,6 +3253,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -3279,6 +3315,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -3366,6 +3403,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3380,6 +3419,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3509,6 +3550,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -3550,6 +3592,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -3671,6 +3714,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3685,6 +3730,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3845,6 +3892,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id5","created": 1,@@ -3967,6 +4015,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3981,6 +4031,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4105,6 +4157,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -4211,6 +4264,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4225,6 +4280,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4354,6 +4411,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -4478,6 +4536,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4492,6 +4552,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4621,6 +4683,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -4680,6 +4743,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -4760,6 +4824,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4774,6 +4840,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4903,6 +4971,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -4998,6 +5067,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -5012,6 +5083,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -5141,6 +5214,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 90,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -5236,6 +5310,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -5250,6 +5326,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -5374,6 +5452,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -5493,6 +5572,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -5507,6 +5588,8 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -5636,6 +5719,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -5695,6 +5779,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -5760,6 +5845,8 @@ exports[`history > multiplayer undo/redo > conflicts in frames and their childre"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -5774,6 +5861,8 @@ exports[`history > multiplayer undo/redo > conflicts in frames and their childre"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -6027,6 +6116,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -6041,6 +6132,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -6366,6 +6459,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -6380,6 +6475,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -6805,6 +6902,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -6819,6 +6918,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7191,6 +7292,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -7205,6 +7308,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7513,6 +7618,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -7527,6 +7634,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7813,6 +7922,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -7827,6 +7938,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8051,6 +8164,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8065,6 +8180,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8415,6 +8532,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8429,6 +8548,8 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8779,6 +8900,8 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8793,6 +8916,8 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9196,6 +9321,8 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9210,6 +9337,8 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9492,6 +9621,8 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9506,6 +9637,8 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9765,6 +9898,8 @@ exports[`history > multiplayer undo/redo > should not override remote changes on"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9779,6 +9914,8 @@ exports[`history > multiplayer undo/redo > should not override remote changes on"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10039,6 +10176,8 @@ exports[`history > multiplayer undo/redo > should not override remote changes on"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10053,6 +10192,8 @@ exports[`history > multiplayer undo/redo > should not override remote changes on"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10279,6 +10420,8 @@ exports[`history > multiplayer undo/redo > should override remotely added groups"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10293,6 +10436,8 @@ exports[`history > multiplayer undo/redo > should override remotely added groups"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10586,6 +10731,8 @@ exports[`history > multiplayer undo/redo > should override remotely added points"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10600,6 +10747,8 @@ exports[`history > multiplayer undo/redo > should override remotely added points"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10911,6 +11060,8 @@ exports[`history > multiplayer undo/redo > should redistribute deltas when eleme"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10925,6 +11076,8 @@ exports[`history > multiplayer undo/redo > should redistribute deltas when eleme"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -11155,6 +11308,8 @@ exports[`history > multiplayer undo/redo > should redraw arrows on undo > [end o"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -11169,6 +11324,8 @@ exports[`history > multiplayer undo/redo > should redraw arrows on undo > [end o"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -12092,6 +12249,8 @@ exports[`history > multiplayer undo/redo > should update history entries after r"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -12106,6 +12265,8 @@ exports[`history > multiplayer undo/redo > should update history entries after r"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -12360,6 +12521,8 @@ exports[`history > singleplayer undo/redo > remounting undo/redo buttons should"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -12374,6 +12537,8 @@ exports[`history > singleplayer undo/redo > remounting undo/redo buttons should"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -12604,6 +12769,8 @@ exports[`history > singleplayer undo/redo > should clear the redo stack on eleme"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -12618,6 +12785,8 @@ exports[`history > singleplayer undo/redo > should clear the redo stack on eleme"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -12850,6 +13019,8 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -12864,6 +13035,8 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#e03131","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -13264,6 +13437,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on e"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -13278,6 +13453,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on e"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -13482,6 +13659,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on e"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -13496,6 +13675,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on e"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -13697,6 +13878,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on i"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -13711,6 +13894,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on i"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14008,6 +14193,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on i"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14022,6 +14209,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on i"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14316,6 +14505,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on s"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14330,6 +14521,8 @@ exports[`history > singleplayer undo/redo > should create new history entry on s"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14570,6 +14763,8 @@ exports[`history > singleplayer undo/redo > should disable undo/redo buttons whe"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14584,6 +14779,8 @@ exports[`history > singleplayer undo/redo > should disable undo/redo buttons whe"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14816,6 +15013,8 @@ exports[`history > singleplayer undo/redo > should end up with no history entry"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14830,6 +15029,8 @@ exports[`history > singleplayer undo/redo > should end up with no history entry"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -15062,6 +15263,8 @@ exports[`history > singleplayer undo/redo > should iterate through the history w"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -15076,6 +15279,8 @@ exports[`history > singleplayer undo/redo > should iterate through the history w"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -15317,6 +15522,8 @@ exports[`history > singleplayer undo/redo > should not clear the redo stack on s"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -15331,6 +15538,8 @@ exports[`history > singleplayer undo/redo > should not clear the redo stack on s"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -15658,6 +15867,8 @@ exports[`history > singleplayer undo/redo > should not collapse when applying co"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -15672,6 +15883,8 @@ exports[`history > singleplayer undo/redo > should not collapse when applying co"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -15835,6 +16048,8 @@ exports[`history > singleplayer undo/redo > should not end up with history entry"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -15849,6 +16064,8 @@ exports[`history > singleplayer undo/redo > should not end up with history entry"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -16129,6 +16346,8 @@ exports[`history > singleplayer undo/redo > should not end up with history entry"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -16143,6 +16362,8 @@ exports[`history > singleplayer undo/redo > should not end up with history entry"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -16402,6 +16623,8 @@ exports[`history > singleplayer undo/redo > should not modify anything on unrela"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -16416,6 +16639,8 @@ exports[`history > singleplayer undo/redo > should not modify anything on unrela"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -16562,6 +16787,8 @@ exports[`history > singleplayer undo/redo > should not override appstate changes"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -16576,6 +16803,8 @@ exports[`history > singleplayer undo/redo > should not override appstate changes"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -16852,6 +17081,8 @@ exports[`history > singleplayer undo/redo > should support appstate name or view"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -16866,6 +17097,8 @@ exports[`history > singleplayer undo/redo > should support appstate name or view"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -17020,6 +17253,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -17034,6 +17269,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -17168,6 +17405,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -17468,6 +17706,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -17784,6 +18023,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -17798,6 +18039,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -17932,6 +18175,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -18122,6 +18366,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -18446,6 +18691,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -18460,6 +18707,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -18594,6 +18843,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -18784,6 +19034,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -19108,6 +19359,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -19122,6 +19375,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -19254,6 +19509,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -19530,6 +19786,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -19873,6 +20130,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -19887,6 +20146,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -20022,6 +20283,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": "id0","created": 1,@@ -20294,6 +20556,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": null,"containerId": null,"created": 1,@@ -20657,6 +20920,8 @@ exports[`history > singleplayer undo/redo > should support changes in elements'"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -20671,6 +20936,8 @@ exports[`history > singleplayer undo/redo > should support changes in elements'"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -21149,6 +21416,8 @@ exports[`history > singleplayer undo/redo > should support duplication of groups"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -21163,6 +21432,8 @@ exports[`history > singleplayer undo/redo > should support duplication of groups"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -21676,6 +21947,8 @@ exports[`history > singleplayer undo/redo > should support element creation, del"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -21690,6 +21963,8 @@ exports[`history > singleplayer undo/redo > should support element creation, del"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -22147,6 +22422,8 @@ exports[`history > singleplayer undo/redo > should support linear element creati"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -22161,6 +22438,8 @@ exports[`history > singleplayer undo/redo > should support linear element creati"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",diff --git a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snapindex 0debb972da..220316f8dd 100644--- a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap+++ b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap@@ -19,6 +19,8 @@ exports[`given element A and group of elements B and given both are selected whe"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -33,6 +35,8 @@ exports[`given element A and group of elements B and given both are selected whe"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -454,6 +458,8 @@ exports[`given element A and group of elements B and given both are selected whe"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -468,6 +474,8 @@ exports[`given element A and group of elements B and given both are selected whe"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -879,6 +887,8 @@ exports[`regression tests > Cmd/Ctrl-click exclusively select element under poin"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -893,6 +903,8 @@ exports[`regression tests > Cmd/Ctrl-click exclusively select element under poin"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1454,6 +1466,8 @@ exports[`regression tests > Drags selected element when hitting only bounding bo"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1468,6 +1482,8 @@ exports[`regression tests > Drags selected element when hitting only bounding bo"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -1668,6 +1684,8 @@ exports[`regression tests > adjusts z order when grouping > [end of test] appSta"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -1682,6 +1700,8 @@ exports[`regression tests > adjusts z order when grouping > [end of test] appSta"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2061,6 +2081,8 @@ exports[`regression tests > alt-drag duplicates an element > [end of test] appSt"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2075,6 +2097,8 @@ exports[`regression tests > alt-drag duplicates an element > [end of test] appSt"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2314,6 +2338,8 @@ exports[`regression tests > arrow keys > [end of test] appState 1`] = `"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2328,6 +2354,8 @@ exports[`regression tests > arrow keys > [end of test] appState 1`] = `"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2501,6 +2529,8 @@ exports[`regression tests > can drag element that covers another element, while"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2515,6 +2545,8 @@ exports[`regression tests > can drag element that covers another element, while"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -2835,6 +2867,8 @@ exports[`regression tests > change the properties of a shape > [end of test] app"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -2849,6 +2883,8 @@ exports[`regression tests > change the properties of a shape > [end of test] app"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1971c2","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3097,6 +3133,8 @@ exports[`regression tests > click on an element and drag it > [dragged] appState"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3111,6 +3149,8 @@ exports[`regression tests > click on an element and drag it > [dragged] appState"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3346,6 +3386,8 @@ exports[`regression tests > click on an element and drag it > [end of test] appS"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3360,6 +3402,8 @@ exports[`regression tests > click on an element and drag it > [end of test] appS"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3589,6 +3633,8 @@ exports[`regression tests > click to select a shape > [end of test] appState 1`]"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3603,6 +3649,8 @@ exports[`regression tests > click to select a shape > [end of test] appState 1`]"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -3855,6 +3903,8 @@ exports[`regression tests > click-drag to select a group > [end of test] appStat"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -3869,6 +3919,8 @@ exports[`regression tests > click-drag to select a group > [end of test] appStat"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4178,6 +4230,8 @@ exports[`regression tests > deleting last but one element in editing group shoul"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4192,6 +4246,8 @@ exports[`regression tests > deleting last but one element in editing group shoul"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4622,6 +4678,8 @@ exports[`regression tests > deselects group of selected elements on pointer down"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4636,6 +4694,8 @@ exports[`regression tests > deselects group of selected elements on pointer down"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -4914,6 +4974,8 @@ exports[`regression tests > deselects group of selected elements on pointer up w"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -4928,6 +4990,8 @@ exports[`regression tests > deselects group of selected elements on pointer up w"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -5198,6 +5262,8 @@ exports[`regression tests > deselects selected element on pointer down when poin"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -5212,6 +5278,8 @@ exports[`regression tests > deselects selected element on pointer down when poin"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -5414,6 +5482,8 @@ exports[`regression tests > deselects selected element, on pointer up, when clic"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -5428,6 +5498,8 @@ exports[`regression tests > deselects selected element, on pointer up, when clic"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -5621,6 +5693,8 @@ exports[`regression tests > double click to edit a group > [end of test] appStat"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -5635,6 +5709,8 @@ exports[`regression tests > double click to edit a group > [end of test] appStat"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -6023,6 +6099,8 @@ exports[`regression tests > drags selected elements from point inside common bou"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -6037,6 +6115,8 @@ exports[`regression tests > drags selected elements from point inside common bou"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -6328,6 +6408,8 @@ exports[`regression tests > draw every type of shape > [end of test] appState 1`"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -6342,6 +6424,8 @@ exports[`regression tests > draw every type of shape > [end of test] appState 1`"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7134,6 +7218,8 @@ exports[`regression tests > given a group of selected elements with an element t"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -7148,6 +7234,8 @@ exports[`regression tests > given a group of selected elements with an element t"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7477,6 +7565,8 @@ exports[`regression tests > given a selected element A and a not selected elemen"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -7491,6 +7581,8 @@ exports[`regression tests > given a selected element A and a not selected elemen"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -7764,6 +7856,8 @@ exports[`regression tests > given selected element A with lower z-index than uns"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -7778,6 +7872,8 @@ exports[`regression tests > given selected element A with lower z-index than uns"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8007,6 +8103,8 @@ exports[`regression tests > given selected element A with lower z-index than uns"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8021,6 +8119,8 @@ exports[`regression tests > given selected element A with lower z-index than uns"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8255,6 +8355,8 @@ exports[`regression tests > key 2 selects rectangle tool > [end of test] appStat"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8269,6 +8371,8 @@ exports[`regression tests > key 2 selects rectangle tool > [end of test] appStat"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8442,6 +8546,8 @@ exports[`regression tests > key 3 selects diamond tool > [end of test] appState"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8456,6 +8562,8 @@ exports[`regression tests > key 3 selects diamond tool > [end of test] appState"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8629,6 +8737,8 @@ exports[`regression tests > key 4 selects ellipse tool > [end of test] appState"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8643,6 +8753,8 @@ exports[`regression tests > key 4 selects ellipse tool > [end of test] appState"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -8816,6 +8928,8 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -8830,6 +8944,8 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9056,6 +9172,8 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9070,6 +9188,8 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9294,6 +9414,8 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] appState"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9308,6 +9430,8 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] appState"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9497,6 +9621,8 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9511,6 +9637,8 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9737,6 +9865,8 @@ exports[`regression tests > key d selects diamond tool > [end of test] appState"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9751,6 +9881,8 @@ exports[`regression tests > key d selects diamond tool > [end of test] appState"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -9924,6 +10056,8 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -9938,6 +10072,8 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10162,6 +10298,8 @@ exports[`regression tests > key o selects ellipse tool > [end of test] appState"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10176,6 +10314,8 @@ exports[`regression tests > key o selects ellipse tool > [end of test] appState"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10349,6 +10489,8 @@ exports[`regression tests > key p selects freedraw tool > [end of test] appState"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10363,6 +10505,8 @@ exports[`regression tests > key p selects freedraw tool > [end of test] appState"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10552,6 +10696,8 @@ exports[`regression tests > key r selects rectangle tool > [end of test] appStat"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10566,6 +10712,8 @@ exports[`regression tests > key r selects rectangle tool > [end of test] appStat"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -10739,6 +10887,8 @@ exports[`regression tests > make a group and duplicate it > [end of test] appSta"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -10753,6 +10903,8 @@ exports[`regression tests > make a group and duplicate it > [end of test] appSta"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -11282,6 +11434,8 @@ exports[`regression tests > noop interaction after undo shouldn't create history"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -11296,6 +11450,8 @@ exports[`regression tests > noop interaction after undo shouldn't create history"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -11570,6 +11726,8 @@ exports[`regression tests > pinch-to-zoom works > [end of test] appState 1`] = `"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -11584,6 +11742,8 @@ exports[`regression tests > pinch-to-zoom works > [end of test] appState 1`] = `"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -11699,6 +11859,8 @@ exports[`regression tests > shift click on selected element should deselect it o"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -11713,6 +11875,8 @@ exports[`regression tests > shift click on selected element should deselect it o"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -11906,6 +12070,8 @@ exports[`regression tests > shift-click to multiselect, then drag > [end of test"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -11920,6 +12086,8 @@ exports[`regression tests > shift-click to multiselect, then drag > [end of test"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -12233,6 +12401,8 @@ exports[`regression tests > should group elements and ungroup them > [end of tes"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -12247,6 +12417,8 @@ exports[`regression tests > should group elements and ungroup them > [end of tes"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -12671,6 +12843,8 @@ exports[`regression tests > single-clicking on a subgroup of a selected group sh"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -12685,6 +12859,8 @@ exports[`regression tests > single-clicking on a subgroup of a selected group sh"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -13321,6 +13497,8 @@ exports[`regression tests > spacebar + drag scrolls the canvas > [end of test] a"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -13335,6 +13513,8 @@ exports[`regression tests > spacebar + drag scrolls the canvas > [end of test] a"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -13453,6 +13633,8 @@ exports[`regression tests > supports nested groups > [end of test] appState 1`]"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -13467,6 +13649,8 @@ exports[`regression tests > supports nested groups > [end of test] appState 1`]"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14093,6 +14277,8 @@ exports[`regression tests > switches from group of selected elements to another"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14107,6 +14293,8 @@ exports[`regression tests > switches from group of selected elements to another"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14442,6 +14630,8 @@ exports[`regression tests > switches selected element on pointer down > [end of"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14456,6 +14646,8 @@ exports[`regression tests > switches selected element on pointer down > [end of"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14715,6 +14907,8 @@ exports[`regression tests > two-finger scroll works > [end of test] appState 1`]"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14729,6 +14923,8 @@ exports[`regression tests > two-finger scroll works > [end of test] appState 1`]"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -14844,6 +15040,8 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -14858,6 +15056,8 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -15217,6 +15417,8 @@ exports[`regression tests > updates fontSize & fontFamily appState > [end of tes"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -15231,6 +15433,8 @@ exports[`regression tests > updates fontSize & fontFamily appState > [end of tes"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",@@ -15346,6 +15550,8 @@ exports[`regression tests > zoom hotkeys > [end of test] appState 1`] = `"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -15360,6 +15566,8 @@ exports[`regression tests > zoom hotkeys > [end of test] appState 1`] = `"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",diff --git a/packages/excalidraw/tests/actionStyles.test.tsx b/packages/excalidraw/tests/actionStyles.test.tsxindex fc40cf4d6c..8f930e8340 100644--- a/packages/excalidraw/tests/actionStyles.test.tsx+++ b/packages/excalidraw/tests/actionStyles.test.tsx@@ -1,6 +1,11 @@import React from "react";-import { CODES, STROKE_WIDTH } from "@excalidraw/common";+import {+ CODES,+ COLOR_PALETTE,+ ROUNDNESS,+ STROKE_WIDTH,+} from "@excalidraw/common";import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";@@ -85,4 +90,93 @@ describe("actionStyles", () => {expect(firstRect.roughness).toBe(2); // Cartoonist: 2expect(firstRect.opacity).toBe(60);});++ it("should show and apply roughness for sticky notes", async () => {+ const stickyNote = API.createElement({+ type: "stickynote",+ roughness: 0,+ });++ API.setElements([stickyNote]);+ API.setSelectedElements([stickyNote]);++ fireEvent.click(screen.getByTitle("Cartoonist"));++ expect(API.getSelectedElement().roughness).toBe(2);+ });++ it("should show and apply roundness for sticky notes", async () => {+ const stickyNote = API.createElement({+ type: "stickynote",+ roundness: null,+ });++ API.setElements([stickyNote]);+ API.setSelectedElements([stickyNote]);++ fireEvent.click(screen.getByTitle("Round"));++ expect(API.getSelectedElement().roundness).toEqual({+ type: ROUNDNESS.PROPORTIONAL_RADIUS,+ });+ });++ it("should hide transparent stroke color for sticky notes", async () => {+ UI.clickTool("stickynote");++ togglePopover("Text color");++ // hidden via `excludedColors` (same mechanism as bucket fill): the swatch+ // is gone, but an invisible placeholder keeps the grid so the remaining+ // colors stay on their usual positions and hotkeys+ expect(screen.queryByTestId("color-transparent")).toBeNull();+ expect(+ document.querySelector(+ '.color-picker-content--default [aria-hidden="true"]',+ ),+ ).not.toBeNull();+ expect(screen.queryByTestId("color-black")).not.toBeNull();+ });++ it("keeps the transparent hotkey dead and the others intact for sticky notes", async () => {+ UI.clickTool("stickynote");++ togglePopover("Text color");++ const picker = document.querySelector(".color-picker-content")!;+ const before = h.state.currentItemStickynoteStrokeColor;++ // `q` maps to the hidden transparent swatch (and to the global tool-lock+ // shortcut) — inside the popup it must be inert, not leaked+ fireEvent.keyDown(picker, { key: "q" });+ expect(h.state.currentItemStickynoteStrokeColor).toBe(before);+ expect(h.state.activeTool.locked).toBe(false);++ // the remaining colors keep their usual keys (w = white)+ fireEvent.keyDown(picker, { key: "w" });+ expect(h.state.currentItemStickynoteStrokeColor).toBe(COLOR_PALETTE.white);+ });++ it("should track sticky note stroke color separately", async () => {+ API.setAppState({+ currentItemStrokeColor: COLOR_PALETTE.red[4],+ currentItemStickynoteStrokeColor: COLOR_PALETTE.black,+ });+ const stickyNote = API.createElement({+ type: "stickynote",+ strokeColor: COLOR_PALETTE.black,+ });++ API.setElements([stickyNote]);+ API.setSelectedElements([stickyNote]);++ togglePopover("Text color");+ UI.clickOnTestId("color-blue");++ expect(API.getSelectedElement().strokeColor).toBe(COLOR_PALETTE.blue[4]);+ expect(h.state.currentItemStickynoteStrokeColor).toBe(+ COLOR_PALETTE.blue[4],+ );+ expect(h.state.currentItemStrokeColor).toBe(COLOR_PALETTE.red[4]);+ });});diff --git a/packages/excalidraw/tests/colorPickerHotkeys.test.ts b/packages/excalidraw/tests/colorPickerHotkeys.test.tsindex 84347eb0d3..ef1bf48efb 100644--- a/packages/excalidraw/tests/colorPickerHotkeys.test.ts+++ b/packages/excalidraw/tests/colorPickerHotkeys.test.ts@@ -79,4 +79,50 @@ describe("color picker hotkeys", () => {expect(handled).toBe(true);expect(onChange).toHaveBeenCalledWith("#ff0000");});++ it("steps over an excluded entry when navigating vertically", () => {+ // three rows of five; `transparent` sits in column 0 of row 1 and is+ // excluded, so vertical moves through that cell must skip it in the+ // arrow's direction (wrapping) instead of landing on the hidden swatch+ const palette = {+ transparent: COLOR_PALETTE.transparent,+ white: "#w0",+ gray: "#g0",+ black: "#k0",+ bronze: "#b0",+ red: "#r1",+ green: "#g1",+ blue: "#b1",+ yellow: "#y1",+ orange: "#o1",+ pink: "#r2",+ grape: "#g2",+ violet: "#b2",+ cyan: "#y2",+ teal: "#o2",+ } as unknown as ColorPaletteCustom;+ const excluded = [COLOR_PALETTE.transparent];++ // up from row 2 / column 0 wraps past the excluded cell to row 3+ let onChange = vi.fn();+ expect(+ colorPickerKeyNavHandler({+ ...handlerArgs("ArrowUp", palette, onChange, excluded),+ activeColorPickerSection: "baseColors",+ color: "#r1",+ }),+ ).toBe(true);+ expect(onChange).toHaveBeenCalledWith("#r2");++ // down from row 3 / column 0 wraps past the excluded cell to row 2+ onChange = vi.fn();+ expect(+ colorPickerKeyNavHandler({+ ...handlerArgs("ArrowDown", palette, onChange, excluded),+ activeColorPickerSection: "baseColors",+ color: "#r2",+ }),+ ).toBe(true);+ expect(onChange).toHaveBeenCalledWith("#r1");+ });});diff --git a/packages/excalidraw/tests/colorTargets.test.ts b/packages/excalidraw/tests/colorTargets.test.tsnew file mode 100644index 0000000000..750c8714d5--- /dev/null+++ b/packages/excalidraw/tests/colorTargets.test.ts@@ -0,0 +1,130 @@+import {+ COLOR_PALETTE,+ DEFAULT_ELEMENT_STROKE_PICKS,+ DEFAULT_STICKY_NOTE_BG,+ STICKY_NOTE_BACKGROUND_PICKS,+} from "@excalidraw/common";++import {+ getColorTargetAppStateUpdates,+ resolveColorTarget,+} from "../actions/colorTargets";+import { getDefaultAppState } from "../appState";++import { API } from "./helpers/api";++import type { AppState } from "../types";++const appState = (overrides: Partial<AppState> = {}): AppState =>+ ({+ ...getDefaultAppState(),+ selectedElementIds: {},+ editingTextElement: null,+ ...overrides,+ } as AppState);++describe("resolveColorTarget", () => {+ const note = API.createElement({ type: "stickynote", id: "note" });+ const label = API.createElement({+ type: "text",+ id: "label",+ containerId: "note",+ });+ const rectangle = API.createElement({ type: "rectangle", id: "rectangle" });+ const elements = [note, label, rectangle];++ it("follows the active tool when nothing is targeted", () => {+ const regular = resolveColorTarget(appState(), elements, "strokeColor");+ expect(regular.kind).toBe("regular");+ expect(regular.appStateKeys).toEqual(["currentItemStrokeColor"]);+ expect(regular.topPicks).toBe(DEFAULT_ELEMENT_STROKE_PICKS);+ expect(regular.excludedColors).toBeUndefined();++ const sticky = resolveColorTarget(+ appState({+ activeTool: {+ ...getDefaultAppState().activeTool,+ type: "stickynote" as const,+ customType: null,+ },+ }),+ elements,+ "backgroundColor",+ );+ expect(sticky.kind).toBe("sticky");+ expect(sticky.appStateKeys).toEqual([+ "currentItemStickynoteBackgroundColor",+ ]);+ expect(sticky.topPicks).toBe(STICKY_NOTE_BACKGROUND_PICKS);+ expect(sticky.customizableTopPicks).toBe("stickyNoteBackground");+ expect(sticky.excludedColors).toContain(COLOR_PALETTE.transparent);+ });++ it("classifies a note (and its label) as the sticky domain", () => {+ const target = resolveColorTarget(+ appState({ selectedElementIds: { note: true } }),+ elements,+ "strokeColor",+ );+ expect(target.kind).toBe("sticky");+ expect(target.appStateKeys).toEqual(["currentItemStickynoteStrokeColor"]);+ });++ it("writes both domains for a mixed selection but shows the regular picker", () => {+ const target = resolveColorTarget(+ appState({ selectedElementIds: { note: true, rectangle: true } }),+ elements,+ "strokeColor",+ );+ expect(target.kind).toBe("mixed");+ expect(target.appStateKeys).toEqual([+ "currentItemStrokeColor",+ "currentItemStickynoteStrokeColor",+ ]);+ expect(target.topPicks).toBe(DEFAULT_ELEMENT_STROKE_PICKS);+ expect(target.excludedColors).toBeUndefined();+ });++ it("treats the sticky label being edited as a sticky target even with no selection", () => {+ // `handleTextWysiwyg` deselects while editing; `changeProperty` still+ // targets the edited text explicitly+ const target = resolveColorTarget(+ appState({ editingTextElement: label }),+ elements,+ "strokeColor",+ );+ expect(target.kind).toBe("sticky");+ });++ it("normalizes transparent for the sticky defaults only", () => {+ const stickyStroke = resolveColorTarget(+ appState({ selectedElementIds: { note: true } }),+ elements,+ "strokeColor",+ );+ expect(+ getColorTargetAppStateUpdates(stickyStroke, COLOR_PALETTE.transparent),+ ).toEqual({ currentItemStickynoteStrokeColor: COLOR_PALETTE.black });++ const stickyBackground = resolveColorTarget(+ appState({ selectedElementIds: { note: true } }),+ elements,+ "backgroundColor",+ );+ expect(+ getColorTargetAppStateUpdates(+ stickyBackground,+ COLOR_PALETTE.transparent,+ ),+ ).toEqual({ currentItemStickynoteBackgroundColor: DEFAULT_STICKY_NOTE_BG });++ const regular = resolveColorTarget(+ appState({ selectedElementIds: { rectangle: true } }),+ elements,+ "backgroundColor",+ );+ expect(+ getColorTargetAppStateUpdates(regular, COLOR_PALETTE.transparent),+ ).toEqual({ currentItemBackgroundColor: COLOR_PALETTE.transparent });+ });+});diff --git a/packages/excalidraw/tests/created.test.tsx b/packages/excalidraw/tests/created.test.tsxindex 772bf67292..b37b33da70 100644--- a/packages/excalidraw/tests/created.test.tsx+++ b/packages/excalidraw/tests/created.test.tsx@@ -19,11 +19,16 @@ describe("element creation timestamps", () => {await render(<Excalidraw handleKeyboardGlobally={true} />);});- it.each([123, null])(- "preserves created=%s through capture, edits, and creation undo/redo",- (created) => {+ it.each([+ { type: "rectangle", created: 123 },+ { type: "rectangle", created: null },+ { type: "stickynote", created: 123 },+ { type: "stickynote", created: null },+ ] as const)(+ "preserves $type created=$created through capture, edits, and creation undo/redo",+ ({ type, created }) => {const element = API.createElement({- type: "rectangle",+ type,x: 10,created,index: "a0" as FractionalIndex,diff --git a/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap b/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snapindex d30b22bf06..fbe31eabe0 100644--- a/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap+++ b/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap@@ -363,6 +363,7 @@ exports[`restoreElements > should restore text element correctly passing value f"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": [],"containerId": null,"created": 1,@@ -406,6 +407,7 @@ exports[`restoreElements > should restore text element correctly with unknown fo"angle": 0,"autoResize": true,"backgroundColor": "transparent",+ "baseFontSize": null,"boundElements": [],"containerId": null,"created": 1,diff --git a/packages/excalidraw/tests/data/restore.test.ts b/packages/excalidraw/tests/data/restore.test.tsindex 521e098359..3f58e24af2 100644--- a/packages/excalidraw/tests/data/restore.test.ts+++ b/packages/excalidraw/tests/data/restore.test.ts@@ -1,14 +1,26 @@import { pointFrom } from "@excalidraw/math";import { vi } from "vitest";-import { DEFAULT_SIDEBAR, FONT_FAMILY, ROUNDNESS } from "@excalidraw/common";+import {+ COLOR_PALETTE,+ DEFAULT_FONT_SIZE,+ DEFAULT_SIDEBAR,+ FONT_FAMILY,+ ROUNDNESS,+ STICKY_NOTE_MAX_FONT_SIZE,+ DEFAULT_STICKY_NOTE_BG,+ STICKY_NOTE_MIN_FONT_SIZE,+} from "@excalidraw/common";import { newElementWith } from "@excalidraw/element";import * as sizeHelpers from "@excalidraw/element";+import { getStickyNoteLayout } from "@excalidraw/element";+import type { LocalPoint } from "@excalidraw/math";import type {+ ExcalidrawStickyNoteElement,ExcalidrawArrowElement,ExcalidrawElement,ExcalidrawFreeDrawElement,@@ -90,6 +102,17 @@ describe("restoreElements", () => {expect(restored[0].id).not.toBe(restored[1].id);});+ it("should restore transparent sticky note stroke as black", () => {+ const stickyNote = {+ ...API.createElement({ type: "stickynote" }),+ strokeColor: COLOR_PALETTE.transparent,+ };++ const restoredElement = restore.restoreElements([stickyNote], null)[0];++ expect(restoredElement.strokeColor).toBe(COLOR_PALETTE.black);+ });+it("when imported data state is null it should return an empty array of elements", () => {const restoredElements = restore.restoreElements(null, null);expect(restoredElements.length).toBe(0);@@ -189,6 +212,172 @@ describe("restoreElements", () => {});});+ it("should sanitize non-finite font sizes on text elements", () => {+ const textElement: any = API.createElement({+ type: "text",+ text: "text",+ });+ textElement.fontSize = NaN;+ textElement.baseFontSize = "abc";++ const restoredText = restore.restoreElements(+ [textElement],+ null,+ )[0] as ExcalidrawTextElement;++ expect(restoredText.fontSize).toBe(DEFAULT_FONT_SIZE);+ expect(restoredText.baseFontSize).toBe(null);+ });++ it("should clamp restored font ceilings to the sticky note maximum", () => {+ const textElement: any = API.createElement({+ type: "text",+ text: "text",+ });+ textElement.baseFontSize = 1e20;++ const restoredText = restore.restoreElements(+ [textElement],+ null,+ )[0] as ExcalidrawTextElement;++ expect(restoredText.baseFontSize).toBe(STICKY_NOTE_MAX_FONT_SIZE);+ });++ it("should clear a font ceiling on text that is not bound to a sticky note", () => {+ // generic binding repair (duplication, history) can detach a label without+ // touching its ceiling; restore reconciles it against the container+ const textElement: any = API.createElement({+ type: "text",+ text: "text",+ fontSize: 20,+ });+ textElement.baseFontSize = 28;++ const restoredText = restore.restoreElements([textElement], null, {+ repairBindings: true,+ })[0] as ExcalidrawTextElement;++ expect(restoredText.baseFontSize).toBe(null);+ });++ it("should seed the font ceiling and a visible stroke on a sticky note label", () => {+ const stickyNote = API.createElement({+ type: "stickynote",+ id: "sticky",+ boundElements: [{ type: "text", id: "label" }],+ });+ const label: any = {+ ...API.createElement({+ type: "text",+ id: "label",+ text: "text",+ fontSize: 20,+ containerId: "sticky",+ }),+ strokeColor: COLOR_PALETTE.transparent,+ };+ delete label.baseFontSize;++ const restored = restore.restoreElements([stickyNote, label], null, {+ repairBindings: true,+ });+ const restoredLabel = restored.find(+ (element) => element.id === "label",+ ) as ExcalidrawTextElement;++ expect(restoredLabel.baseFontSize).toBe(20);+ expect(restoredLabel.strokeColor).toBe(COLOR_PALETTE.black);+ });++ it("should give a note its label's color when the two drifted apart", () => {+ const stickyNote = API.createElement({+ type: "stickynote",+ id: "sticky",+ strokeColor: COLOR_PALETTE.black,+ boundElements: [{ type: "text", id: "label" }],+ });+ const label = API.createElement({+ type: "text",+ id: "label",+ text: "text",+ fontSize: 20,+ containerId: "sticky",+ strokeColor: COLOR_PALETTE.red[4],+ });++ const restored = restore.restoreElements([stickyNote, label], null, {+ repairBindings: true,+ });++ expect(+ restored.find((element) => element.id === "sticky")!.strokeColor,+ ).toBe(COLOR_PALETTE.red[4]);+ expect(+ restored.find((element) => element.id === "label")!.strokeColor,+ ).toBe(COLOR_PALETTE.red[4]);+ });++ it("should restore the sticky note defaults and top-pick slots", () => {+ const restored = restore.restoreAppState(+ {+ currentItemStickynoteBackgroundColor: COLOR_PALETTE.transparent,+ currentItemStickynoteStrokeColor: COLOR_PALETTE.transparent,+ colorTopPicks: { stickyNoteBackground: ["#fcc2d7", "#b2f2bb"] },+ } as any,+ null,+ );++ expect(restored.currentItemStickynoteBackgroundColor).toBe(+ DEFAULT_STICKY_NOTE_BG,+ );+ expect(restored.currentItemStickynoteStrokeColor).toBe(COLOR_PALETTE.black);+ expect(restored.colorTopPicks.stickyNoteBackground).toEqual([+ "#fcc2d7",+ "#b2f2bb",+ ]);+ expect(restored.colorTopPicks.stickyNoteStroke).toBe(null);+ });++ it("should refit a sticky note together with its label when refreshing dimensions", () => {+ const stickyNote = API.createElement({+ type: "stickynote",+ id: "sticky",+ width: 250,+ height: 250,+ baseHeight: 250,+ boundElements: [{ type: "text", id: "label" }],+ });+ const label = API.createElement({+ type: "text",+ id: "label",+ text: Array(40).fill("abcdefghijklmnopqrstuvwx").join("\n"),+ fontSize: 28,+ containerId: "sticky",+ });++ const restored = restore.restoreElements([stickyNote, label], null, {+ repairBindings: true,+ refreshDimensions: true,+ });+ const note = restored.find(+ (element) => element.id === "sticky",+ ) as ExcalidrawStickyNoteElement;+ const text = restored.find(+ (element) => element.id === "label",+ ) as ExcalidrawTextElement;++ // both halves: the note grew for the text at the minimum font, the base+ // is untouched, and the pair agrees with the layout+ expect(note.baseHeight).toBe(250);+ expect(note.height).toBeGreaterThan(250);+ expect(text.fontSize).toBe(STICKY_NOTE_MIN_FONT_SIZE);+ expect(text.baseFontSize).toBe(28);+ expect(note.height).toBeCloseTo(+ getStickyNoteLayout(note, text).container.height,+ );+ });+it("should restore freedraw element correctly", () => {const freedrawElement = API.createElement({type: "freedraw",@@ -861,6 +1050,19 @@ describe("restoreAppState", () => {expect(restoredAppState.currentItemStrokeWidthKey).toBe("bold");});+ it("should restore transparent current sticky note stroke as black", () => {+ const restoredAppState = restore.restoreAppState(+ {+ currentItemStickynoteStrokeColor: COLOR_PALETTE.transparent,+ } as any,+ null,+ );++ expect(restoredAppState.currentItemStickynoteStrokeColor).toBe(+ COLOR_PALETTE.black,+ );+ });+it("should restore with current app state when imported data state is undefined", () => {const stubImportedAppState = {...getDefaultAppState(),diff --git a/packages/excalidraw/tests/dragCreate.test.tsx b/packages/excalidraw/tests/dragCreate.test.tsxindex 3c9aadf477..a82327b424 100644--- a/packages/excalidraw/tests/dragCreate.test.tsx+++ b/packages/excalidraw/tests/dragCreate.test.tsx@@ -1,21 +1,39 @@import React from "react";import { vi } from "vitest";-import { KEYS, reseed } from "@excalidraw/common";--import type { ExcalidrawLinearElement } from "@excalidraw/element/types";+import {+ DEFAULT_STICKY_NOTE_SIZE,+ KEYS,+ STICKY_NOTE_BODY_INSET_Y,+ STICKY_NOTE_MIN_SIZE,+ reseed,+} from "@excalidraw/common";++import type {+ ExcalidrawLinearElement,+ ExcalidrawStickyNoteElement,+} from "@excalidraw/element/types";import { Excalidraw } from "../index";+import * as InteractiveScene from "../renderer/interactiveScene";import * as StaticScene from "../renderer/staticScene";+import { API } from "./helpers/api";+import {render,fireEvent,+ waitFor,mockBoundingClientRect,restoreOriginalGetBoundingClientRect,unmountComponent,} from "./test-utils";+import {+ getTextEditor,+ TEXT_EDITOR_SELECTOR,+ updateTextEditor,+} from "./queries/dom";unmountComponent();@@ -215,6 +233,228 @@ describe("Test dragCreate", () => {});});+ describe("sticky note creation", () => {+ const createDefaultStickyNote = (canvas: Element) => {+ fireEvent.pointerDown(canvas, { clientX: 300, clientY: 300 });+ fireEvent.pointerUp(canvas, { clientX: 300, clientY: 300 });+ };++ it("places a clicked note on the grid", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ API.setAppState({ gridModeEnabled: true, gridSize: 20 });+ fireEvent.click(getByToolName("stickynote"));++ createDefaultStickyNote(container.querySelector("canvas.interactive")!);+ await getTextEditor();++ expect(+ h.elements.find((element) => element.type === "stickynote"),+ ).toMatchObject({ x: 180, y: 180 });+ });++ it("switches back to selection and starts editing when tool is unlocked", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ fireEvent.click(getByToolName("stickynote"));++ const canvas = container.querySelector("canvas.interactive")!;+ createDefaultStickyNote(canvas);++ await getTextEditor();++ const stickyNote = h.elements.find(+ (element) => element.type === "stickynote",+ );+ const boundText = h.elements.find((element) => element.type === "text");++ expect(stickyNote).toBeDefined();+ expect(boundText).toEqual(+ expect.objectContaining({+ containerId: stickyNote?.id,+ }),+ );+ expect(h.state.editingTextElement?.id).toBe(boundText?.id);+ expect(h.state.activeTool.type).toBe("selection");+ expect(h.state.activeTool.locked).toBe(false);+ });++ it("keeps sticky note tool active without editing when tool is locked", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ fireEvent.click(getByToolName("stickynote"));+ fireEvent.click(getByToolName("lock"));++ const canvas = container.querySelector("canvas.interactive")!;+ createDefaultStickyNote(canvas);++ await waitFor(() => {+ expect(+ h.elements.filter((element) => element.type === "stickynote"),+ ).toHaveLength(1);+ });++ expect(h.elements.filter((element) => element.type === "text")).toEqual(+ [],+ );+ expect(h.state.editingTextElement).toBeNull();+ expect(document.querySelector(TEXT_EDITOR_SELECTOR)).toBeNull();+ expect(h.state.activeTool.type).toBe("stickynote");+ expect(h.state.activeTool.locked).toBe(true);+ expect(h.state.selectedElementIds).toEqual({});+ });++ it("treats a wobble under the drag threshold as a click", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ fireEvent.click(getByToolName("stickynote"));++ const canvas = container.querySelector("canvas.interactive")!;+ fireEvent.pointerDown(canvas, { clientX: 300, clientY: 300 });+ fireEvent.pointerMove(canvas, { clientX: 306, clientY: 305 });+ fireEvent.pointerUp(canvas, { clientX: 306, clientY: 305 });++ await getTextEditor();++ const stickyNote = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ expect(stickyNote.width).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(stickyNote.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(stickyNote.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ });++ it("previews a drag at its true size and snaps to the minimum on release", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ fireEvent.click(getByToolName("stickynote"));++ const canvas = container.querySelector("canvas.interactive")!;+ fireEvent.pointerDown(canvas, { clientX: 300, clientY: 300 });+ fireEvent.pointerMove(canvas, { clientX: 320, clientY: 320 });++ // mid-gesture: no clamp, the note is exactly what was dragged+ const draft = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ expect(draft.width).toBe(20);+ expect(draft.height).toBe(20);++ fireEvent.pointerUp(canvas, { clientX: 320, clientY: 320 });+ await getTextEditor();++ // on release it grows to the minimum, away from the origin corner: one+ // 25px line at the default 20px ceiling plus padding and the date footer+ // high — and as wide, since a plain drag is proportional and the square+ // survives the snap+ const stickyNote = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ expect(stickyNote.x).toBe(300);+ expect(stickyNote.y).toBe(300);+ expect(stickyNote.width).toBe(25 + STICKY_NOTE_BODY_INSET_Y);+ expect(stickyNote.height).toBe(25 + STICKY_NOTE_BODY_INSET_Y);+ expect(stickyNote.baseHeight).toBe(25 + STICKY_NOTE_BODY_INSET_Y);+ });++ it("sizes the minimum note to fit one line at a large font ceiling", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ // a 60px line (48 × 1.25) plus padding and the date footer high — and as+ // wide, since a plain drag is proportional+ API.setAppState({ currentItemFontSize: 48 });+ fireEvent.click(getByToolName("stickynote"));++ const canvas = container.querySelector("canvas.interactive")!;+ fireEvent.pointerDown(canvas, { clientX: 300, clientY: 300 });+ fireEvent.pointerMove(canvas, { clientX: 320, clientY: 320 });+ fireEvent.pointerUp(canvas, { clientX: 320, clientY: 320 });+ const editor = await getTextEditor();++ const stickyNote = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ expect(stickyNote.width).toBe(60 + STICKY_NOTE_BODY_INSET_Y);+ expect(stickyNote.height).toBe(60 + STICKY_NOTE_BODY_INSET_Y);++ // one line fits without growing the note+ updateTextEditor(editor, "A");+ expect(+ (+ h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement+ ).height,+ ).toBe(60 + STICKY_NOTE_BODY_INSET_Y);+ });++ it("drags out a square note by default and keeps it square through the snap", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ fireEvent.click(getByToolName("stickynote"));+ const canvas = container.querySelector("canvas.interactive")!;+ fireEvent.pointerDown(canvas, { clientX: 300, clientY: 300 });+ // an uneven drag: proportional by default, so the draft is square+ fireEvent.pointerMove(canvas, { clientX: 340, clientY: 320 });+ const draft = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ expect([draft.width, draft.height]).toEqual([40, 40]);++ fireEvent.pointerUp(canvas, { clientX: 340, clientY: 320 });+ await getTextEditor();++ // the two minimums differ; the square survives the snap+ const note = h.elements.find((element) => element.type === "stickynote")!;+ expect(note.width).toBe(25 + STICKY_NOTE_BODY_INSET_Y);+ expect(note.height).toBe(25 + STICKY_NOTE_BODY_INSET_Y);+ });++ it("drags out a free-form note with Shift", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ fireEvent.click(getByToolName("stickynote"));+ const canvas = container.querySelector("canvas.interactive")!;+ fireEvent.pointerDown(canvas, {+ clientX: 300,+ clientY: 300,+ shiftKey: true,+ });+ fireEvent.pointerMove(canvas, {+ clientX: 340,+ clientY: 320,+ shiftKey: true,+ });+ const draft = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ expect([draft.width, draft.height]).toEqual([40, 20]);++ fireEvent.pointerUp(canvas, {+ clientX: 340,+ clientY: 320,+ shiftKey: true,+ });+ await getTextEditor();++ // each side snaps to its own minimum+ const note = h.elements.find((element) => element.type === "stickynote")!;+ expect(note.width).toBe(STICKY_NOTE_MIN_SIZE);+ expect(note.height).toBe(25 + STICKY_NOTE_BODY_INSET_Y);+ });++ it("keeps the origin corner fixed when a drag toward the top-left snaps to the minimum", async () => {+ const { getByToolName, container } = await render(<Excalidraw />);+ fireEvent.click(getByToolName("stickynote"));++ const canvas = container.querySelector("canvas.interactive")!;+ fireEvent.pointerDown(canvas, { clientX: 300, clientY: 300 });+ fireEvent.pointerMove(canvas, { clientX: 280, clientY: 280 });+ fireEvent.pointerUp(canvas, { clientX: 280, clientY: 280 });+ await getTextEditor();++ const stickyNote = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ // the bottom-right corner is where the pointer went down+ expect(stickyNote.x + stickyNote.width).toBe(300);+ expect(stickyNote.y + stickyNote.height).toBe(300);+ expect(stickyNote.width).toBe(25 + STICKY_NOTE_BODY_INSET_Y);+ });+ });+describe("do not add element to the scene if size is too small", () => {beforeAll(() => {mockBoundingClientRect();diff --git a/packages/excalidraw/tests/fixtures/elementFixture.ts b/packages/excalidraw/tests/fixtures/elementFixture.tsindex 73def64234..9c3b0ec863 100644--- a/packages/excalidraw/tests/fixtures/elementFixture.ts+++ b/packages/excalidraw/tests/fixtures/elementFixture.ts@@ -59,6 +59,7 @@ export const textFixture: ExcalidrawElement = {...elementBase,type: "text",fontSize: 20,+ baseFontSize: null,fontFamily: DEFAULT_FONT_FAMILY,strokeColor: "#1e1e1e",text: "original text",diff --git a/packages/excalidraw/tests/helpers/api.ts b/packages/excalidraw/tests/helpers/api.tsindex 6a9f2b8f8f..5b4a21a66f 100644--- a/packages/excalidraw/tests/helpers/api.ts+++ b/packages/excalidraw/tests/helpers/api.ts@@ -22,6 +22,7 @@ import {newImageElement,newLinearElement,newMagicFrameElement,+ newStickyNoteElement,newTextElement,} from "@excalidraw/element";@@ -43,6 +44,7 @@ import type {ExcalidrawMagicFrameElement,ExcalidrawElbowArrowElement,ExcalidrawArrowElement,+ ExcalidrawStickyNoteElement,FixedSegment,NonDeleted,NonDeletedExcalidrawElement,@@ -205,6 +207,9 @@ export class API {? ExcalidrawTextElement["verticalAlign"]: never;boundElements?: ExcalidrawGenericElement["boundElements"];+ baseHeight?: T extends "stickynote"+ ? ExcalidrawStickyNoteElement["baseHeight"]+ : never;containerId?: T extends "text"? ExcalidrawTextElement["containerId"]: never;@@ -244,6 +249,8 @@ export class API {? ExcalidrawFrameElement: T extends "magicframe"? ExcalidrawMagicFrameElement+ : T extends "stickynote"+ ? ExcalidrawStickyNoteElement: ExcalidrawGenericElement> => {let element: Mutable<ExcalidrawElement> = null!;@@ -269,9 +276,16 @@ export class API {frameId: rest.frameId ?? null,index: rest.index ?? null,angle: (rest.angle ?? 0) as Radians,- strokeColor: rest.strokeColor ?? appState.currentItemStrokeColor,+ strokeColor:+ rest.strokeColor ??+ (type === "stickynote"+ ? appState.currentItemStickynoteStrokeColor+ : appState.currentItemStrokeColor),backgroundColor:- rest.backgroundColor ?? appState.currentItemBackgroundColor,+ rest.backgroundColor ??+ (type === "stickynote"+ ? appState.currentItemStickynoteBackgroundColor+ : appState.currentItemBackgroundColor),fillStyle: rest.fillStyle ?? appState.currentItemFillStyle,strokeWidth:rest.strokeWidth ??@@ -315,6 +329,15 @@ export class API {...base,});break;+ case "stickynote":+ element = newStickyNoteElement({+ ...base,+ width,+ height,+ type,+ baseHeight: rest.baseHeight ?? height,+ });+ break;case "text":const fontSize = rest.fontSize ?? appState.currentItemFontSize;const fontFamily = rest.fontFamily ?? appState.currentItemFontFamily;diff --git a/packages/excalidraw/tests/helpers/ui.ts b/packages/excalidraw/tests/helpers/ui.tsindex 079af75969..63cf479aaa 100644--- a/packages/excalidraw/tests/helpers/ui.ts+++ b/packages/excalidraw/tests/helpers/ui.ts@@ -451,6 +451,14 @@ export class UI {fireEvent.click(GlobalTestState.renderResult.getByToolName(toolName));};+ /** clicks a tool that lives in the extra-tools dropdown, opening it first */+ static clickExtraTool = (toolName: ToolType) => {+ fireEvent.click(+ document.querySelector(".App-toolbar__extra-tools-trigger")!,+ );+ UI.clickTool(toolName);+ };+static clickLabeledElement = (label: string) => {const element = document.querySelector(`[aria-label='${label}']`);if (!element) {diff --git a/packages/excalidraw/tests/image.test.tsx b/packages/excalidraw/tests/image.test.tsxindex 0c94791856..afbf1e79c1 100644--- a/packages/excalidraw/tests/image.test.tsx+++ b/packages/excalidraw/tests/image.test.tsx@@ -131,7 +131,7 @@ describe("image insertion", () => {API.loadFile("./fixtures/smiley.png"),]),);- UI.clickTool("image");+ UI.clickExtraTool("image");await assert();});diff --git a/packages/excalidraw/tests/scene/__snapshots__/export.test.ts.snap b/packages/excalidraw/tests/scene/__snapshots__/export.test.ts.snapindex 3cc7c38dad..25d6dc3b22 100644--- a/packages/excalidraw/tests/scene/__snapshots__/export.test.ts.snap+++ b/packages/excalidraw/tests/scene/__snapshots__/export.test.ts.snap@@ -240,7 +240,7 @@ exports[`exportToSvg > with elements that have a link 1`] = ``;exports[`exportToSvg > with exportEmbedScene 1`] = `-"<!-- svg-source:excalidraw --><metadata><!-- payload-type:application/vnd.excalidraw+json --><!-- payload-version:2 --><!-- payload-start -->eyJ2ZXJzaW9uIjoiMSIsImVuY29kaW5nIjoiYnN0cmluZyIsImNvbXByZXNzZWQiOnRydWUsImVuY29kZWQiOiJ4nO1WW2vbMFx1MDAxNH7vrzDea1llJ2myvGXrLoWxwTIobPRBtY5tYVlyJTmXhfz3SnJj2W7pXtclXHUwMDBlXHUwMDE4zneu+vRcdTAwMWSc3VlcdTAwMTCEeltBOFx1MDAwZkLYJJhRXCLxOjy3+FxupKKCXHUwMDFiV+xsJWqZuMhcXOtqfnHBhEnIhdLzXHUwMDExQqhJXHUwMDAyXHUwMDA2JXCtTNhvY1x1MDAwN8HOvY2HXHUwMDEym7q6kfffXHUwMDE3aUE5ie+Tcvr1avH5l0t1QVx1MDAxYlx1MDAxMzOOxq29td1H09ZeU6Jzg0VcYrVYXHUwMDBlNMv1XHUwMDAwxDxjdlaPKC1FXHUwMDAxXHUwMDFmXHUwMDA0XHUwMDEz0lx1MDAwZfJcdTAwMDa5x7e+w0mRSVFz4mOiXHTGd6mPSSljS71lXHJcdTAwMGI4yWtcdOGgw81hxFx1MDAwMd7mKWFY9lmmZZZzUKqXIyqcUL1cdTAwMWScys5XXVx1MDAxM8furZ9K4lx1MDAxMq4tvbxmrFuYk8fCPYfhXHUwMDFlLNEh7lx1MDAxY19cdTAwMDFcdTAwMTDXbVx1MDAxY11Opu/QrPV4XHUwMDFkRDFcdTAwMWGi31x1MDAwNHeaiKLZXGahcTy99G3UlVGDdmVTzFx1MDAxNHiq7WRcdTAwMWa9UnrT1Vx1MDAxNcFNkmcjkfCI9UJcdTAwMTnlxVx1MDAxM0wkxTMtXHUwMDBmXCInXHUwMDE0l4KT0OH785NE/3WJRkcnUWCMVlxuXodEI7C/45ZofHRcdTAwMTLVsNGd+1x1MDAxNFxcL+lcdTAwMWbr6Vx1MDAxY82in3BJmaV/4kvYVFNCSJpRjlnQr3WAf75cdTAwMWNmrVx1MDAwNaOZ5TNkkHZcXIZSTc1cdTAwMWaT1q1F5b2JmVxuU1x1MDAwZfLpTVx1MDAxYlx1MDAxZeBLu1x1MDAwNW9jPzOutfhcdTAwMDGqOaJj5LSbr2Q3R6fd/Ntu+vP8T7tp3k4/Ia6qpTbcXHUwMDFhd7Op4YrC+v0zu5C6x3533WbbXVx1MDAwMHt5u/3Z/lx1MDAwMaRcbl5vIn0=<!-- payload-end --></metadata><defs><style class="style-fonts">+"<!-- svg-source:excalidraw --><metadata><!-- payload-type:application/vnd.excalidraw+json --><!-- payload-version:2 --><!-- payload-start -->eyJ2ZXJzaW9uIjoiMSIsImVuY29kaW5nIjoiYnN0cmluZyIsImNvbXByZXNzZWQiOnRydWUsImVuY29kZWQiOiJ4nO1WXW/TMFx1MDAxNH3fr4jC68SctF1L31xuYzBcdIFEkSaBeHDjm8SKY2e201x1MDAwZqr+d2xnjZNs4oVcdTAwMTdGm0qR7rmfPj5X6f5cIlxiQr2rIJxcdTAwMDchbFx1MDAxM8wokXhcdTAwMTNeWnxcclJRwY0rdrZcdTAwMTK1TFxcZK51Nb+6YsIk5ELp+VxiIdQkXHUwMDAxg1x1MDAxMrhWJuyHsYNg797GQ4lNXd/Lhy+LtKCcxFx1MDAwZkk5/XSz+PDdpbqgrYlcdTAwMTlH49be2e6jaWtvKNG5wVwihFosXHUwMDA3muV6XHUwMDAwYp4xO6tHlJaigHeCXHRpXHUwMDA3eYXc41uvcFJkUtSc+JhogvEq9TEpZWypd6xhXHUwMDAxJ3ktIVx1MDAxY3S4P444wNs8JVxmyz7LtMxyXHUwMDBlSvVyRIVcdTAwMTOqd4NT2fmqO+LY/emnkriEO0svr1x1MDAxOetcdTAwMTbm5LFwz2G4XHUwMDA3S3SIO8dXXHUwMDAwxHVcdTAwMWJH15PpXHUwMDFiNGs9Xlx1MDAwN1GMhuhnwZ0momg2Q2hcdTAwMWNPr31cdTAwMWJ1Y9SgXdlcdTAwMTQzXHUwMDA1nmo72XuvlN50dUVwk+TZSCQ8Yr1QRnnxXHUwMDA0XHUwMDEzSfFMy6PIXHTFpeAkdPjh8izRf12i0clJXHUwMDE0XHUwMDE4o5WClyHRXGLs77QlXHUwMDFhn5xENWx15z5cdTAwMDXXS/rLejpHW2FcdTAwMDW33tMrbzNucUmZvZqJL2/LmvJC0oxyzIJ+nyP87c9h1lowmlmuQ1x1MDAwNmnHZejW1Pxpad1aVN6bmKkw5SCfqsBwXHUwMDA0XHUwMDFm21xyeVx1MDAxZPuZca3FV1DNIVx1MDAxZFvnvX0hezs67+3f7K0/6/+0t+bttFx1MDAxNeKqWmrDu3E3W1x1MDAxY64pbN4+syepe+z32m293Vx1MDAxM7BcdTAwMTe7P1xcXHUwMDFjflx1MDAwM/d6bqcifQ==<!-- payload-end --></metadata><defs><style class="style-fonts">@font-face { font-family: Excalifont; src: url(data:font/woff2;base64,d09GMgABAAAAAAf0AA4AAAAADbQAAAegAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGhYbgjgcNAZgAHwRCAqPYItcCxoAATYCJAMwBCAFgxgHIBujClGUblKX7Edh3Pg8OJbt5MlDFPwWk6FmJ08terdayeDx9O8Fa5eunTJ1ykAUGuAvgOF5bPfuH0nXrvQrNkFoNlERBLIQDd/mj2kP7fdg8avL4M/sm4cbu4L2i1VQVjShz/+90/YE3IJFmOC+f0Z1Xhs3bVxiJZZGa1IgY5sHCJ2EM2iBndkLWsZvFxCAhRBGCknKEOQenHCpmE2fVQTl1atzWyjvzs3aQPnWd20PJQZeG3mQp1lnLimFBAhOKFIQSrGa+vOB69gLCRkjLr4NIjd5rXiz8hhu+LIe9DZCgkJjmZEy34MkhXNBJ8GhNMMnJUgmSYA0AowAwT2zRor05iZAeN/80c4UkYlgSTOaKgOQCUOSE5F+z6+DXqndDTk4CEHP2v3/aKw7lXQXgAUAQP5+kgIpTYMHT9MEjIyWxJ5V5jAzgnrNtNBKWx101tXee86rA5O1f1fiIzEtJsS4GBMjYlikIhEvwwXDjYgiApUFdjgCFAA1m2GorwgdA5a6fzxxX0ei+Eqw6MspHfbmte7eLSh2FSEREgnySedVN+VfsbKAVQygCrGALXgDQoSA0kZqfB2OiyyaZolc/i3tnXswySlmifL9eo1ReyWQcYadAK/DD9c80uaI4pamykJM2hp/MF2uj+teZm9LiRlrltgBlcVYlWVWf+WPTpVJj40Kz9Gvi5p21Zcov8bKEL+5Uirz+j2Hjzr+99zosad2XtbpfsbKgyIQ3RJHxrTH1ysQQAjTUaii13B+OTtxrFoLubjpMYtit2uul6DdSPvKaQl/9FkppthYCXEvjoEdStVVjti2fUQf34q9YjychmIsxCAjKkj0GW4mIhlX1snPOEVRVq4UMRQwkzJNhK143IsBOlghz9meJAGf4apbAmYRMj2hsj5X1OGDPuIKXoOyN8yIMYbeusXTa9f4a+1UvYG9FgQxzoQBUoSPD5/ezAuQIP8s8IyVrUGrwSxC95WPAdlx3EkkQq5yNjcaKAAZ4LEHheIMvgHV3fe6X41/6rzCiMBwSxrnvl9RcR0gK5fy4jDVigBySy99iwlppT9aTlWIMSMKBx9WkbupSbZXNC/CKUC6z53jA0mS7340zruutV7xYguW6p/01tYHOQZQ7ptAagFiLAzFWqyWUwN8/eNGSyn2elPguvF9At0XUNlNv4t202nq+EnkKvdW6aLVlJUxhpXYUqMsn5svp9eoTpvKKf6BY8QwAkaJWYSggEuximEYiCVE0TjN5ojkVoznAP0GytsVT1SesrOn/s8LsMpVpXtSc6To4sT6XIl1q0jH96rd5/g5vmi35+y6eeYPNqjBGHtX0nKFGywfPr19aO9Gh/Q1sWZGuqckOoOJmlK2pSPTSgm/46h389ap+VmOnxsPdspP82Xyy2l7u6i2908pVjRkDbEddOKOprOPJ/94eJ59fi6jDtB6VbzuwXb5puJcqcKnUeM72fFnIlssAv/Z6uMq2s1Jd8qpd7DZo538w5PG7cHm2TU2TD41PjYiaUSikYspa/kjJ84AdgqXsT226/L+fW6j99QmJZlWN99tfcdbUPO17tLu8+gVw73h3OfmurdS9BCa5twNfokJhx7/agK3fHC9rXVewbT0kZG9vXqRBOtS6xGOZ5dC3pwleZIyidL1le+xC3btOlwJkXqGESosoDUG2TqcuE/6OcolnOykkpKdD+5l7+JODWBpAycPke+STDMRWidsWCLvfQJbKM7JpnkLG1WV73qjg6eZ1EMVF1NgG5rTaZF2r7tJNs2VzabNrTQfhSOtgxRxRLP5mldJB6/b6R5LWk9ss9nNUGyTTx8iytdCS9xlAlvtN/1hTrYObLVe5T8zLWNk2oko/bq0dv1cvjXrGC5k+pfYm+L1MtXCFsSzKDTY/dhu66JJWqlfkIxw7T5ufjDBa4pCy7ObPC0cojzlZMlCh2VjKwfX8qy5cpyRt1hp6DeKs/UZjc6zfGxC0rJHl1IUtIm2p7Tg+6VKn8vbfWR9fHljiebwTXPXTQ13HmoSbMssDsa32NnSfmmoH92xuU/E7U2qS8vWYFD9D73VJodqvWU8l7tB+b9ZdPiXvC2qoboerfoamG78+oOX7uWn1/WJy87rJPSHcVmUO7sN0ypzcG5zdfzU8k/NSh5OCbHvUSJlOk2xGrkmubA+nV7YtUCdoJk2vZ/dNSvrAkFnE0toKlC7rHllSrrOzt4Yb91LaLga9TtY+etg/uCpE8rVr604yv7YaE2x450wAACIfUvVNvFrrWXyNylLvwSAR70CtQDwePGbPuLQ/32Y10wCAClKi8AXKzralCj+/e0Dwri9RW2ArkwEqBW+cYJzghDkKyuPEB0FElKG8DIXEQkASS4s/2PSN2DGs1Bi6eh9EhVoZDAH0NblyEbw9tsoChtttEDDbQxvDTZWKm+YcYcDOj01qtdWK8110F5XIQq+nMJuwnpSopmb7KJVWbUgQqhwkyQxlOd76aglFYEKoxAJ8OeFkYPjBPTuQejsbXStQgY5klp1cr1LoQHSUa8StKqVbKnrXAqNAgg8wm1EB6RBL7ejLWnSmSI9hGJQZdAW2trTXRJoBsJm6M5VNQlFM3yJ/7EAAAA=); }@font-face { font-family: Excalifont; src: url(data:font/woff2;base64,d09GMgABAAAAAAHcAA0AAAAAA9gAAAGMAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGx4cNAZgAAQRCAoAKgsEAAE2AiQDBAQgBYMYByAbHQPIrgp4MjSeIQLqpl4jnPFQwveqm205gmrZevZ2/8kKGaJ6ictBuCwMMnsKo8hC4RwaLBrJ7dXaFrFk0Re1e/Dk3t9wCUVrYAiZkgiZ5rGDVFdY04wBF4APOCzXHr/ljrNIDqLAY/slkQf0SyjxLNBaAq8Z1AJqYW5j0GjbckRLQhoJCgwYoyfY3q33QS5DrSAwYB4hFruNve4WoN2On4P29GEFWsC+nVM/UvSlVwIcsWycI/5gbqfUhE/9Q2P7UppTOAVeIR4TYIocELVKIEACZJgXCJ5GXl0o+esbFP3g+763DcDPx6/60MrnBaBPAsGPUDRC/8+FGIqGUSBA+NIJOwTWe13HRCIrgEvfRhj1RjLiE42eG7I5DIpVNuqkNNhxwaItTI2srRz4dfHGjhZoO0O8nb2pilFYQKhenFaycLUxsYcoAQRyoRBEnPvcgfysPq+npClt8UxLyvHWjaudqbGJA+TCckNECBGBGFforuTs0M4CUMbCAvp+P4in4o864XECREBtFQAAAAA=); }@font-face { font-family: Nunito; src: url(data:font/woff2;base64,d09GMgABAAAAAAIsAA4AAAAABLQAAAHYAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGx4cLgZgP1NUQVREAAQRCAoAKgsEAAE2AiQDBAQgBYQkByAb5wPIrgp4Mt6IIcJZFNCfWmZY6KzqazTt6AiVHCFawzJ7V0CQBKoSQQEpFKrCVxiSFbqqqsaTevKs/q7s6uBYmujMyA9wxb6a7XnEOcNnDLgG4nW8PoPzHzYpS2uqp51pL3eB/xZoxIllCQc80B9o4j/4xMbxQB+j+SC3hsm6JmI8RMaHj+aJApW6ZbkXlg4vXSE5FECg0og6LzxP9pOarug4tF1RLpbHeZqLX0pIt2mfy3pNG6eyGaRIjrnrr/gv2c//yGdjpJ/7DuJLin5eIZRLaObBMM/NpYpuXJ8z3SE088mEFANcCARESfwChCioAwESsVxBgeyxp6+vZ3Xzv8uz7Ae8tRk+p6RUTPOR7BmlEgh+STsAimNuKibilyluhBNe5/wCACSBKrcykVfgyb+RYcK/TGq9yMyCt3bOskSnR1FqTLMSVBsMGLQVltDKKw2IYA+wcGxHJCINY9mDOCaN4IZEo1ChY4xNg8DaB0RxDqnbMNjXJJRzF9iInqahtm67M8dOHFvXaYbn+wrGxKG3YZI+2V4CW58ovdfV1tFHXFJJiPH7T1FAJxEgYo5BKkA5iDIVQluOqZYWhQapGF6TAFhaFAAoTBIZsCFHi/0oV3gpVKwbAA==); }diff --git a/packages/excalidraw/tests/stickyNotes.test.tsx b/packages/excalidraw/tests/stickyNotes.test.tsxnew file mode 100644index 0000000000..1a22503493--- /dev/null+++ b/packages/excalidraw/tests/stickyNotes.test.tsx@@ -0,0 +1,1177 @@+import React from "react";++import {+ COLOR_PALETTE,+ DEFAULT_STICKY_NOTE_SIZE,+ KEYS,+ STICKY_NOTE_MIN_FONT_SIZE,+ arrayToMap,+} from "@excalidraw/common";+import { queryByTestId } from "@testing-library/react";+import { pointFrom } from "@excalidraw/math";++import {+ getStickyNoteLayout,+ getTransformHandles,+ getBaseFontSize,+ resizeMultipleElements,+ resizeSingleElement,+ updateStickyNoteLayout,+} from "@excalidraw/element";+import { exportToCanvas } from "@excalidraw/utils";++import type {+ ExcalidrawArrowElement,+ ExcalidrawStickyNoteElement,+ ExcalidrawTextElement,+ NonDeleted,+} from "@excalidraw/element/types";++import { actionBindText, actionGroup, actionUnbindText } from "../actions";+import {+ actionChangeBackgroundColor,+ actionChangeFontSize,+ actionChangeRoundness,+ actionIncreaseFontSize,+} from "../actions/actionProperties";+import { actionCopyStyles, actionPasteStyles } from "../actions/actionStyles";+import { activeEyeDropperAtom } from "../components/EyeDropper";+import { getShapeActionPredicates } from "../components/shapeActionPredicates";+import { editorJotaiStore } from "../editor-jotai";+import { Excalidraw } from "../index";+import { exportToSvg } from "../scene/export";++import { API } from "./helpers/api";+import { Keyboard, Pointer, UI } from "./helpers/ui";+import { getTextEditor, updateTextEditor } from "./queries/dom";+import {+ act,+ fireEvent,+ GlobalTestState,+ mockBoundingClientRect,+ render,+ restoreOriginalGetBoundingClientRect,+} from "./test-utils";++const { h } = window;+const mouse = new Pointer("mouse");++const LONG_TEXT = Array(40).fill("abcdefghijklmnopqrstuvwx").join("\n");+const RED = COLOR_PALETTE.red[4];++const getElement = <+ T extends+ | ExcalidrawStickyNoteElement+ | ExcalidrawTextElement+ | ExcalidrawArrowElement,+>(+ id: string,+) => h.elements.find((element) => element.id === id) as NonDeleted<T>;++/** a note with a label, laid out through the sticky fit */+const createNote = ({+ id,+ x = 100,+ y = 100,+ text,+ fontSize,+ boundArrowIds = [],+}: {+ id: string;+ x?: number;+ y?: number;+ text: string;+ fontSize: number;+ boundArrowIds?: string[];+}) => {+ const labelId = `${id}-label`;+ const note = API.createElement({+ type: "stickynote",+ id,+ x,+ y,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ boundElements: [+ { type: "text", id: labelId },+ ...boundArrowIds.map((arrowId) => ({+ type: "arrow" as const,+ id: arrowId,+ })),+ ],+ });+ const label = API.createElement({+ type: "text",+ id: labelId,+ x: x + DEFAULT_STICKY_NOTE_SIZE / 2,+ y: y + DEFAULT_STICKY_NOTE_SIZE / 2,+ text,+ fontSize,+ containerId: id,+ textAlign: "center",+ verticalAlign: "middle",+ });+ return { note, label };+};++const layoutNotes = (...ids: string[]) => {+ act(() => {+ for (const id of ids) {+ updateStickyNoteLayout(+ getElement<ExcalidrawStickyNoteElement>(id),+ h.app.scene,+ );+ }+ });+};++const arrowEndY = (id: string) => {+ const arrow = getElement<ExcalidrawArrowElement>(id);+ return arrow.y + arrow.points[arrow.points.length - 1][1];+};++describe("sticky notes", () => {+ beforeEach(async () => {+ await render(<Excalidraw handleKeyboardGlobally={true} />);+ });++ afterEach(async () => {+ await act(async () => {});+ });++ it("keeps arrows bound to a note attached while typing grows it", async () => {+ const { note, label } = createNote({+ id: "note",+ text: "short",+ fontSize: 28,+ boundArrowIds: ["arrow"],+ });+ const arrow = API.createElement({+ type: "arrow",+ id: "arrow",+ x: note.x + note.width / 2,+ y: 700,+ width: 0,+ height: -300,+ points: [pointFrom(0, 0), pointFrom(0, -300)],+ endBinding: {+ elementId: note.id,+ fixedPoint: [0.5, 1],+ mode: "orbit",+ },+ });+ API.setElements([note, label, arrow]);+ layoutNotes(note.id);++ const heightBefore = getElement<ExcalidrawStickyNoteElement>(+ note.id,+ ).height;+ const endYBefore = arrowEndY(arrow.id);+ expect(heightBefore).toBe(DEFAULT_STICKY_NOTE_SIZE);++ mouse.doubleClickAt(note.x + note.width / 2, note.y + note.height / 2);+ const editor = await getTextEditor();+ updateTextEditor(editor, LONG_TEXT);++ const grown = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(grown.height).toBeGreaterThan(heightBefore);+ expect(grown.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ // the bottom edge moved by the growth, and so did the arrow's end (the+ // orbit ring re-solves the exact contact point, hence the tolerance)+ const growth = grown.height - heightBefore;+ const endDelta = arrowEndY(arrow.id) - endYBefore;+ expect(Math.abs(endDelta - growth)).toBeLessThan(10);++ Keyboard.keyPress(KEYS.ESCAPE, editor);+ expect(getElement<ExcalidrawTextElement>(label.id).fontSize).toBe(+ STICKY_NOTE_MIN_FONT_SIZE,+ );+ });++ it("binds free text with a seeded ceiling and unbinding returns the note to its base height", () => {+ const note = API.createElement({+ type: "stickynote",+ id: "note",+ x: 100,+ y: 100,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ });+ const text = API.createElement({+ type: "text",+ id: "text",+ x: 600,+ y: 100,+ text: LONG_TEXT,+ fontSize: 28,+ });+ API.setElements([note, text]);+ API.setSelectedElements([note, text]);++ API.executeAction(actionBindText);++ const label = getElement<ExcalidrawTextElement>(text.id);+ const grown = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(label.containerId).toBe(note.id);+ expect(label.baseFontSize).toBe(28);+ expect(label.fontSize).toBe(STICKY_NOTE_MIN_FONT_SIZE);+ expect(grown.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(grown.height).toBeGreaterThan(DEFAULT_STICKY_NOTE_SIZE);++ API.setSelectedElements([grown]);+ API.executeAction(actionUnbindText);++ const freed = getElement<ExcalidrawTextElement>(text.id);+ const emptied = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(freed.containerId).toBe(null);+ // the ceiling is cleared for good (`undefined` would be skipped by the mutator)+ expect(freed.baseFontSize).toBe(null);+ expect(emptied.boundElements ?? []).toEqual([]);+ expect(emptied.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ });++ it("pasting styles onto a grown note lays out the note together with its label", () => {+ const source = createNote({+ id: "source",+ x: 600,+ text: "source",+ fontSize: 10,+ });+ const target = createNote({ id: "target", text: LONG_TEXT, fontSize: 28 });+ API.setElements([source.note, source.label, target.note, target.label]);+ layoutNotes(source.note.id, target.note.id);++ const grownHeight = getElement<ExcalidrawStickyNoteElement>(+ target.note.id,+ ).height;+ expect(grownHeight).toBeGreaterThan(DEFAULT_STICKY_NOTE_SIZE);++ API.setSelectedElements([getElement(source.note.id)]);+ API.executeAction(actionCopyStyles);+ API.setSelectedElements([getElement(target.note.id)]);+ API.executeAction(actionPasteStyles);++ const note = getElement<ExcalidrawStickyNoteElement>(target.note.id);+ const label = getElement<ExcalidrawTextElement>(target.label.id);+ // the user's ceiling was copied, not the source's fitted size+ expect(label.baseFontSize).toBe(10);+ // the note shrank with its smaller label, and the pair is self-consistent+ // (no phantom container: the returned note carries the new layout)+ expect(note.height).toBeLessThan(grownHeight);+ const layout = getStickyNoteLayout(note, label);+ expect(note.height).toBeCloseTo(layout.container.height);+ expect(label.fontSize).toBe(layout.text!.fontSize);+ expect(label.y).toBeCloseTo(layout.text!.y);+ });++ it("leaves unselected notes untouched by property actions", () => {+ const { note, label } = createNote({+ id: "note",+ text: "unrelated",+ fontSize: 28,+ });+ const rectangle = API.createElement({+ type: "rectangle",+ id: "rectangle",+ x: 600,+ y: 100,+ width: 100,+ height: 100,+ });+ API.setElements([note, label, rectangle]);+ layoutNotes(note.id);+ const noteBefore = getElement<ExcalidrawStickyNoteElement>(note.id);+ const labelBefore = getElement<ExcalidrawTextElement>(label.id);++ API.setSelectedElements([getElement(rectangle.id)]);+ act(() => {+ h.app.actionManager.executeAction(actionChangeBackgroundColor, "ui", {+ color: "#ffc9c9",+ });+ h.app.actionManager.executeAction(actionChangeRoundness, "ui", "sharp");+ });++ expect(getElement(rectangle.id).backgroundColor).toBe("#ffc9c9");+ expect(getElement(note.id)).toBe(noteBefore);+ expect(getElement(label.id)).toBe(labelBefore);+ });++ it("keeps a note's invariants through plain property actions", () => {+ const { note, label } = createNote({+ id: "note",+ text: "hi",+ fontSize: 28,+ });+ API.setElements([note, label]);+ layoutNotes(note.id);+ API.setSelectedElements([getElement(note.id)]);++ act(() => {+ h.app.actionManager.executeAction(actionChangeBackgroundColor, "ui", {+ color: "transparent",+ });+ });++ // never transparent — the normalization runs inside `changeProperty`+ expect(getElement(note.id).backgroundColor).not.toBe("transparent");+ });++ describe("colors", () => {+ it("routes a closed-popup top pick to the sticky default after switching tools", () => {+ // regression: the memoized picker kept a stale `onChange` that had+ // captured the rectangle tool's target, so the top pick wrote the+ // shape default while the sticky tool was active+ UI.clickTool("rectangle");+ UI.clickTool("stickynote");+ const shapeDefault = h.state.currentItemStrokeColor;++ UI.clickOnTestId(`color-top-pick-${RED}`);++ expect(h.state.currentItemStickynoteStrokeColor).toBe(RED);+ expect(h.state.currentItemStrokeColor).toBe(shapeDefault);+ });++ it("writes both defaults and colors both domains for a mixed selection", () => {+ const { note, label } = createNote({+ id: "note",+ text: "hi",+ fontSize: 28,+ });+ const rectangle = API.createElement({+ type: "rectangle",+ id: "rectangle",+ x: 600,+ y: 100,+ width: 100,+ height: 100,+ });+ API.setElements([note, label, rectangle]);+ layoutNotes(note.id);+ API.setSelectedElements([getElement(note.id), getElement(rectangle.id)]);++ UI.clickOnTestId(`color-top-pick-${RED}`);++ expect(getElement(rectangle.id).strokeColor).toBe(RED);+ expect(getElement(note.id).strokeColor).toBe(RED);+ // the note's visible text is its label+ expect(getElement(label.id).strokeColor).toBe(RED);+ expect(h.state.currentItemStrokeColor).toBe(RED);+ expect(h.state.currentItemStickynoteStrokeColor).toBe(RED);+ });++ it("creates notes from the sticky defaults, not the shape defaults", async () => {+ API.setAppState({+ currentItemBackgroundColor: COLOR_PALETTE.transparent,+ currentItemStrokeColor: COLOR_PALETTE.blue[4],+ currentItemStickynoteBackgroundColor: COLOR_PALETTE.pink[1],+ currentItemStickynoteStrokeColor: COLOR_PALETTE.black,+ });+ UI.clickTool("stickynote");+ mouse.downAt(300, 300);+ mouse.up();++ const note = h.elements.find(+ (element) => element.type === "stickynote",+ ) as ExcalidrawStickyNoteElement;+ expect(note.backgroundColor).toBe(COLOR_PALETTE.pink[1]);+ expect(note.strokeColor).toBe(COLOR_PALETTE.black);+ Keyboard.keyPress(KEYS.ESCAPE, await getTextEditor());+ });++ it("binding a transparent text to a note gives it the note's text color", () => {+ const note = API.createElement({+ type: "stickynote",+ id: "note",+ x: 100,+ y: 100,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ strokeColor: COLOR_PALETTE.blue[4],+ });+ const text = API.createElement({+ type: "text",+ id: "text",+ x: 600,+ y: 100,+ text: "hello",+ fontSize: 20,+ strokeColor: COLOR_PALETTE.transparent,+ });+ API.setElements([note, text]);+ API.setSelectedElements([note, text]);++ API.executeAction(actionBindText);++ expect(getElement<ExcalidrawTextElement>(text.id).strokeColor).toBe(+ COLOR_PALETTE.blue[4],+ );+ });++ it("binding a colored text to a note gives the note the text's color", () => {+ const note = API.createElement({+ type: "stickynote",+ id: "note",+ x: 100,+ y: 100,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ baseHeight: DEFAULT_STICKY_NOTE_SIZE,+ strokeColor: COLOR_PALETTE.blue[4],+ });+ const text = API.createElement({+ type: "text",+ id: "text",+ x: 600,+ y: 100,+ text: "hello",+ fontSize: 20,+ strokeColor: RED,+ });+ API.setElements([note, text]);+ API.setSelectedElements([note, text]);++ API.executeAction(actionBindText);++ expect(getElement(note.id).strokeColor).toBe(RED);+ expect(getElement<ExcalidrawTextElement>(text.id).strokeColor).toBe(RED);+ });++ it("colors a selected note's label with the keyboard eyedropper", () => {+ const { note, label } = createNote({+ id: "note",+ text: "hi",+ fontSize: 28,+ });+ API.setElements([note, label]);+ layoutNotes(note.id);+ API.setSelectedElements([getElement(note.id)]);++ const backgroundBefore = getElement(note.id).backgroundColor;+ // Shift+S opens the stroke eyedropper (`I` would pick the background)+ Keyboard.withModifierKeys({ shift: true }, () => {+ Keyboard.keyPress("s");+ });+ const eyeDropper = editorJotaiStore.get(activeEyeDropperAtom);+ expect(eyeDropper).not.toBeNull();+ act(() => {+ eyeDropper!.onSelect(RED, { altKey: false } as PointerEvent);+ });++ expect(getElement(note.id).strokeColor).toBe(RED);+ expect(getElement(label.id).strokeColor).toBe(RED);+ expect(getElement(note.id).backgroundColor).toBe(backgroundBefore);+ });+ });++ describe("bound arrows", () => {+ const createNoteWithArrow = (text: string, fontSize = 28) => {+ const { note, label } = createNote({+ id: "note",+ text,+ fontSize,+ boundArrowIds: ["arrow"],+ });+ const arrow = API.createElement({+ type: "arrow",+ id: "arrow",+ x: note.x + note.width / 2,+ y: 900,+ width: 0,+ height: -500,+ points: [pointFrom(0, 0), pointFrom(0, -500)],+ endBinding: {+ elementId: note.id,+ fixedPoint: [0.5, 1],+ mode: "orbit",+ },+ });+ API.setElements([note, label, arrow]);+ layoutNotes(note.id);+ return { note, label, arrow };+ };+ const noteBottom = (id: string) => {+ const note = getElement<ExcalidrawStickyNoteElement>(id);+ return note.y + note.height;+ };++ it("follow the note back to its base height on unbind", () => {+ const { note, arrow } = createNoteWithArrow(LONG_TEXT);+ expect(getElement(note.id).height).toBeGreaterThan(+ DEFAULT_STICKY_NOTE_SIZE,+ );+ const gap = arrowEndY(arrow.id) - noteBottom(note.id);++ API.setSelectedElements([getElement(note.id)]);+ API.executeAction(actionUnbindText);++ expect(getElement(note.id).height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ // the orbit ring re-solves the contact point, hence the tolerance+ expect(+ Math.abs(arrowEndY(arrow.id) - noteBottom(note.id) - gap),+ ).toBeLessThan(10);+ });++ it("stay at the content bottom after a content-constrained resize", () => {+ const { note, arrow } = createNoteWithArrow(LONG_TEXT);+ const grown = getElement<ExcalidrawStickyNoteElement>(note.id);+ const heightBefore = grown.height;+ const gap = arrowEndY(arrow.id) - noteBottom(note.id);+ const originalElementsMap = arrayToMap(+ h.elements.map((element) => ({ ...element })),+ );++ act(() => {+ resizeSingleElement(+ grown.width,+ DEFAULT_STICKY_NOTE_SIZE,+ grown,+ { ...grown },+ originalElementsMap,+ h.app.scene,+ "s",+ );+ });++ const after = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(after.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(after.height).toBeCloseTo(heightBefore);+ // the arrow pass ran after the content correction, not before it+ expect(arrowEndY(arrow.id) - noteBottom(note.id)).toBeCloseTo(gap, 0);+ });++ it("follow a font-size change that grows the note", () => {+ // 12 lines at a 12px ceiling fit the base height; at 20 they don't+ const twelveLines = Array(12).fill("abcdefghij").join("\n");+ const { note, label, arrow } = createNoteWithArrow(twelveLines, 12);+ expect(getElement(note.id).height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ const gap = arrowEndY(arrow.id) - noteBottom(note.id);++ API.setSelectedElements([getElement(note.id)]);+ act(() => {+ h.app.actionManager.executeAction(actionChangeFontSize, "ui", 20);+ });++ expect(getElement<ExcalidrawTextElement>(label.id).baseFontSize).toBe(20);+ expect(getElement(note.id).height).toBeGreaterThan(+ DEFAULT_STICKY_NOTE_SIZE,+ );+ expect(arrowEndY(arrow.id) - noteBottom(note.id)).toBeCloseTo(gap, 0);+ });++ it("are not moved twice when they are part of a multi-select resize", () => {+ const { note, arrow } = createNoteWithArrow("short");+ const gap = arrowEndY(arrow.id) - noteBottom(note.id);+ const originalElementsMap = arrayToMap(+ h.elements.map((element) => ({ ...element })),+ );++ // selection bbox: note (100..350) + arrow down to y=900 → 250×800+ act(() => {+ resizeMultipleElements(+ h.app.scene.getNonDeletedElements(),+ h.app.scene.getNonDeletedElementsMap(),+ "se",+ h.app.scene,+ originalElementsMap,+ { nextWidth: 500, nextHeight: 1600, shouldMaintainAspectRatio: true },+ );+ });++ // the arrow was scaled with the selection (gap doubled); had the note's+ // arrow pass re-snapped it, the gap would be back at its ring distance+ expect(getElement(note.id).width).toBe(500);+ expect(arrowEndY(arrow.id) - noteBottom(note.id)).toBeCloseTo(gap * 2, 0);+ });+ });++ describe("editing", () => {+ it("routes a top pick to the label and the sticky default while editing a note", async () => {+ const { note, label } = createNote({+ id: "note",+ text: "hi",+ fontSize: 28,+ });+ API.setElements([note, label]);+ layoutNotes(note.id);+ const shapeDefault = h.state.currentItemStrokeColor;++ mouse.doubleClickAt(note.x + note.width / 2, note.y + note.height / 2);+ await getTextEditor();+ UI.clickOnTestId(`color-top-pick-${RED}`);++ expect(getElement(label.id).strokeColor).toBe(RED);+ // one ink: the note (and so its footer) follows the label+ expect(getElement(note.id).strokeColor).toBe(RED);+ expect(h.state.currentItemStickynoteStrokeColor).toBe(RED);+ expect(h.state.currentItemStrokeColor).toBe(shapeDefault);+ Keyboard.keyPress(KEYS.ESCAPE, await getTextEditor());+ });++ it("offers the note's background while editing its label and colors the note with it", async () => {+ const { note, label } = createNote({+ id: "note",+ text: "hi",+ fontSize: 28,+ });+ API.setElements([note, label]);+ layoutNotes(note.id);+ const shapeDefault = h.state.currentItemBackgroundColor;+ const noteBackground = getElement(note.id).backgroundColor;++ mouse.doubleClickAt(note.x + note.width / 2, note.y + note.height / 2);+ await getTextEditor();++ // the label is the styles panel's target and has no fill of its own,+ // yet the background picker stays available and shows the note's fill+ const elementsMap = h.app.scene.getNonDeletedElementsMap();+ expect(+ getShapeActionPredicates(+ h.state,+ [getElement(label.id)],+ elementsMap,+ h.app,+ ).backgroundColor,+ ).toBe(true);+ const backgroundPicker = document.querySelector(+ ".color-picker__top-picks .color-picker__button.active[title]",+ );+ const activeSwatches = Array.from(+ document.querySelectorAll(".color-picker__top-picks .active"),+ ).map((button) => button.getAttribute("title"));+ expect(backgroundPicker).not.toBeNull();+ expect(activeSwatches).toContain(noteBackground);++ act(() => {+ h.app.actionManager.executeAction(actionChangeBackgroundColor, "ui", {+ color: COLOR_PALETTE.pink[1],+ });+ });++ // text and background in one editing pass: the pick lands on the note+ expect(getElement(note.id).backgroundColor).toBe(COLOR_PALETTE.pink[1]);+ expect(getElement(label.id).backgroundColor).toBe(label.backgroundColor);+ expect(h.state.currentItemStickynoteBackgroundColor).toBe(+ COLOR_PALETTE.pink[1],+ );+ expect(h.state.currentItemBackgroundColor).toBe(shapeDefault);+ Keyboard.keyPress(KEYS.ESCAPE, await getTextEditor());+ });++ it("keeps the background picker away from plain text being edited", async () => {+ const text = API.createElement({+ type: "text",+ id: "text",+ x: 100,+ y: 100,+ text: "hi",+ fontSize: 28,+ });+ API.setElements([text]);++ mouse.doubleClickAt(text.x + text.width / 2, text.y + text.height / 2);+ await getTextEditor();++ expect(+ getShapeActionPredicates(+ h.state,+ [getElement(text.id)],+ h.app.scene.getNonDeletedElementsMap(),+ h.app,+ ).backgroundColor,+ ).toBe(false);+ Keyboard.keyPress(KEYS.ESCAPE, await getTextEditor());+ });++ it("colors a selected note's label with the preview eyedropper", () => {+ const { note, label } = createNote({+ id: "note",+ text: "hi",+ fontSize: 28,+ });+ API.setElements([note, label]);+ layoutNotes(note.id);+ API.setSelectedElements([getElement(note.id)]);++ Keyboard.withModifierKeys({ shift: true }, () => {+ Keyboard.keyPress("s");+ });+ // the preview samples the canvas under the pointer (the mock yields+ // black) and applies it live — to the label as well as the note+ const backdrop = document.querySelector(+ ".excalidraw-eye-dropper-backdrop",+ )!;+ expect(backdrop).not.toBeNull();+ // the pick applies live only while the pointer is held down+ fireEvent.pointerDown(backdrop, { clientX: 150, clientY: 150 });+ fireEvent.pointerMove(window, { clientX: 150, clientY: 150 });++ const picked = getElement(label.id).strokeColor;+ expect(picked).not.toBe(COLOR_PALETTE.black);+ expect(getElement(note.id).strokeColor).toBe(picked);+ fireEvent.keyDown(backdrop, { key: KEYS.ESCAPE });+ });+ });++ describe("paste styles", () => {+ it("resolves the source ceiling from the copied snapshot after the source is gone", () => {+ const source = createNote({+ id: "source",+ x: 600,+ text: LONG_TEXT,+ fontSize: 28,+ });+ const target = createNote({ id: "target", text: "hi", fontSize: 10 });+ API.setElements([source.note, source.label, target.note, target.label]);+ layoutNotes(source.note.id, target.note.id);++ API.setSelectedElements([getElement(source.note.id)]);+ API.executeAction(actionCopyStyles);+ API.setElements([+ getElement(target.note.id),+ getElement(target.label.id),+ ]);+ API.setSelectedElements([getElement(target.note.id)]);+ API.executeAction(actionPasteStyles);++ expect(+ getElement<ExcalidrawTextElement>(target.label.id).baseFontSize,+ ).toBe(28);+ });++ it("gives a note one ink when the copied styles carry two colors", () => {+ // a rectangle with a differently colored label: the label's color is+ // the visible text color, so it becomes the note's ink+ const rectangle = API.createElement({+ type: "rectangle",+ id: "rect",+ x: 600,+ y: 100,+ width: 200,+ height: 100,+ strokeColor: COLOR_PALETTE.blue[4],+ boundElements: [{ type: "text", id: "rect-label" }],+ });+ const rectangleLabel = API.createElement({+ type: "text",+ id: "rect-label",+ x: 650,+ y: 130,+ text: "hi",+ fontSize: 20,+ containerId: "rect",+ strokeColor: RED,+ });+ const target = createNote({ id: "target", text: "hi", fontSize: 20 });+ API.setElements([rectangle, rectangleLabel, target.note, target.label]);+ layoutNotes(target.note.id);++ API.setSelectedElements([getElement(rectangle.id)]);+ API.executeAction(actionCopyStyles);+ API.setSelectedElements([getElement(target.note.id)]);+ API.executeAction(actionPasteStyles);++ expect(getElement(target.label.id).strokeColor).toBe(RED);+ expect(getElement(target.note.id).strokeColor).toBe(RED);+ });+ });++ describe("ceiling lifecycle", () => {+ it("ignores a stale ceiling on text that is no longer bound to a note", () => {+ const text = API.createElement({+ type: "text",+ id: "text",+ x: 100,+ y: 100,+ text: "plain",+ fontSize: 20,+ });+ API.setElements([text]);+ // what generic binding repair can leave behind+ act(() => {+ h.app.scene.mutateElement(getElement<ExcalidrawTextElement>(text.id), {+ baseFontSize: 28,+ });+ });+ expect(+ getBaseFontSize(+ getElement<ExcalidrawTextElement>(text.id),+ h.app.scene.getNonDeletedElementsMap(),+ ),+ ).toBe(20);++ API.setSelectedElements([getElement(text.id)]);+ API.executeAction(actionIncreaseFontSize);++ const after = getElement<ExcalidrawTextElement>(text.id);+ expect(after.fontSize).toBe(22);+ expect(after.baseFontSize).toBe(28);+ });++ it("duplicates a note with its label's ceiling and base height", () => {+ const { note, label } = createNote({+ id: "note",+ text: LONG_TEXT,+ fontSize: 28,+ });+ API.setElements([note, label]);+ layoutNotes(note.id);+ API.setSelectedElements([getElement(note.id)]);++ Keyboard.withModifierKeys({ ctrl: true }, () => {+ Keyboard.keyPress("d");+ });++ const notes = h.elements.filter(+ (element) => element.type === "stickynote" && !element.isDeleted,+ ) as ExcalidrawStickyNoteElement[];+ expect(notes).toHaveLength(2);+ const copy = notes.find((candidate) => candidate.id !== note.id)!;+ const copyLabel = h.elements.find(+ (element) =>+ element.type === "text" &&+ (element as ExcalidrawTextElement).containerId === copy.id,+ ) as ExcalidrawTextElement;+ expect(copy.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(copy.height).toBeCloseTo(getElement(note.id).height);+ expect(copyLabel.baseFontSize).toBe(28);+ expect(+ getBaseFontSize(copyLabel, h.app.scene.getNonDeletedElementsMap()),+ ).toBe(28);+ });+ });++ describe("creation", () => {+ it("keeps an empty note escaped from editing and removes it on undo", async () => {+ UI.clickTool("stickynote");+ mouse.downAt(300, 300);+ mouse.up();+ expect(h.state.editingTextElement).not.toBeNull();++ // the editor owns Escape (a document-level keypress would not end+ // editing, and undo is suppressed while editing)+ Keyboard.keyPress(KEYS.ESCAPE, await getTextEditor());+ expect(h.state.editingTextElement).toBeNull();+ const note = h.elements.find(+ (element) => element.type === "stickynote" && !element.isDeleted,+ ) as ExcalidrawStickyNoteElement;+ expect(note.width).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(note.height).toBe(DEFAULT_STICKY_NOTE_SIZE);++ // the placement is one entry; the empty editing session may add another+ const liveNotes = () =>+ h.elements.filter(+ (element) => element.type === "stickynote" && !element.isDeleted,+ );+ Keyboard.undo();+ if (liveNotes().length) {+ Keyboard.undo();+ }+ expect(liveNotes()).toHaveLength(0);+ });+ });++ describe("history", () => {+ const liveNotes = () =>+ h.elements.filter(+ (element) => element.type === "stickynote" && !element.isDeleted,+ );+ const createNoteByClick = async () => {+ UI.clickTool("stickynote");+ mouse.downAt(300, 300);+ mouse.up();+ const editor = await getTextEditor();+ // the editor arms its submit-on-blur a tick after the pointer-up+ await act(() => new Promise((resolve) => setTimeout(resolve, 0)));+ return editor;+ };++ it("undoes an abandoned note when the editor is escaped", async () => {+ const editor = await createNoteByClick();+ expect(API.getUndoStack()).toHaveLength(1);++ Keyboard.keyPress(KEYS.ESCAPE, editor);++ expect(liveNotes()).toHaveLength(1);+ expect(API.getUndoStack()).toHaveLength(1);+ Keyboard.undo();+ expect(liveNotes()).toHaveLength(0);+ Keyboard.redo();+ expect(liveNotes()).toHaveLength(1);+ });++ it("skips the empty label's history entry when clicking out", async () => {+ const editor = await createNoteByClick();++ // a click on empty canvas blurs the editor (submitting it), then its+ // pointer-up records — which used to leave the empty label's deletion+ // as a second, invisible entry. The wysiwyg's own outside-pointerdown+ // submit is disabled under vitest, so the blur is fired explicitly.+ fireEvent.blur(editor);+ mouse.downAt(900, 800);+ mouse.up();++ expect(h.state.editingTextElement).toBeNull();+ expect(liveNotes()).toHaveLength(1);+ expect(API.getUndoStack()).toHaveLength(2);+ Keyboard.undo();+ expect(liveNotes()).toHaveLength(0);+ expect(API.getUndoStack()).toHaveLength(0);+ Keyboard.redo();+ expect(liveNotes()).toHaveLength(1);+ });++ it("skips empty-label cleanup after a font change captures creation", async () => {+ const editor = await createNoteByClick();+ // Changing the empty label's baseFontSize is invisible too.+ act(() => {+ h.app.actionManager.executeAction(actionChangeFontSize, "ui", 28);+ });+ expect(h.state.editingTextElement).not.toBeNull();++ fireEvent.blur(editor);+ mouse.downAt(900, 800);+ mouse.up();++ Keyboard.undo();+ expect(liveNotes()).toHaveLength(0);+ expect(API.getUndoStack()).toHaveLength(0);+ Keyboard.redo();+ expect(liveNotes()).toHaveLength(1);+ });++ it("undoes typing separately from creating the note", async () => {+ const editor = await createNoteByClick();+ updateTextEditor(editor, "hello");+ Keyboard.keyPress(KEYS.ESCAPE, editor);++ const label = h.elements.find(+ (element) => element.type === "text" && !element.isDeleted,+ ) as ExcalidrawTextElement;+ expect(label.text).toBe("hello");+ expect(API.getUndoStack()).toHaveLength(2);+ Keyboard.undo();+ expect(liveNotes()).toHaveLength(1);+ expect(getElement<ExcalidrawTextElement>(label.id).text).toBe("");+ Keyboard.undo();+ expect(liveNotes()).toHaveLength(0);+ Keyboard.redo();+ expect(liveNotes()).toHaveLength(1);+ Keyboard.redo();+ expect(getElement<ExcalidrawTextElement>(label.id).text).toBe("hello");+ });+ });++ describe("resize handles", () => {+ const setup = () => {+ const { note, label } = createNote({+ id: "note",+ text: "hi",+ fontSize: 28,+ });+ API.setElements([note, label]);+ layoutNotes(note.id);+ API.setSelectedElements([getElement(note.id)]);+ return { note: getElement<ExcalidrawStickyNoteElement>(note.id), label };+ };+ const ceiling = (id: string) =>+ getElement<ExcalidrawTextElement>(id).baseFontSize;++ it("resizes proportionally from a corner by default and scales the ceiling", () => {+ const { note, label } = setup();+ UI.resize(note, "se", [50, 0]);++ const resized = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(resized.width).toBeGreaterThan(DEFAULT_STICKY_NOTE_SIZE);+ expect(resized.height).toBeCloseTo(resized.width);+ expect(resized.baseHeight).toBeCloseTo(resized.height);+ expect(ceiling(label.id)).toBeCloseTo(+ (28 * resized.width) / DEFAULT_STICKY_NOTE_SIZE,+ );+ });++ it("resizes freely from a corner with Shift, leaving the ceiling alone", () => {+ const { note, label } = setup();+ UI.resize(note, "se", [50, 0], { shift: true });++ const resized = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(resized.width).toBe(DEFAULT_STICKY_NOTE_SIZE + 50);+ expect(resized.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(ceiling(label.id)).toBe(28);+ });++ it("resizes an edge freely by default, keeping the base height and ceiling", () => {+ const { note, label } = setup();+ UI.resize(note, "e", [50, 0]);++ const resized = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(resized.width).toBe(DEFAULT_STICKY_NOTE_SIZE + 50);+ expect(resized.height).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(resized.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(ceiling(label.id)).toBe(28);+ });++ it("flips over the far corner like a rectangle, keeping the label upright", () => {+ const { note, label } = setup();+ // `note` is the live element; keep the pre-resize position to compare+ const { x: originalX, y: originalY } = note;+ // the SE corner dragged 400px up and left: past the NW corner+ UI.resize(note, "se", [-400, -400]);++ const resized = getElement<ExcalidrawStickyNoteElement>(note.id);+ const resizedLabel = getElement<ExcalidrawTextElement>(label.id);+ // proportional: 150px past the corner on both axes → a 150 square,+ // mirrored so its bottom-right sits on the original top-left+ expect(resized.width).toBeCloseTo(150);+ expect(resized.height).toBeCloseTo(150);+ expect(resized.x + resized.width).toBeCloseTo(originalX);+ expect(resized.y + resized.height).toBeCloseTo(originalY);+ expect(ceiling(label.id)).toBeCloseTo(+ (28 * 150) / DEFAULT_STICKY_NOTE_SIZE,+ );+ // the label is inside the flipped note and not mirrored+ expect(resizedLabel.angle).toBe(0);+ expect(resizedLabel.x).toBeGreaterThan(resized.x);+ expect(resizedLabel.y).toBeGreaterThan(resized.y);+ });++ const hintWhileDragging = (+ note: ExcalidrawStickyNoteElement,+ handle: "se" | "e",+ ) => {+ const [x, y, width, height] = getTransformHandles(+ note,+ h.state.zoom,+ h.app.scene.getNonDeletedElementsMap(),+ "mouse",+ {},+ )[handle]!;+ mouse.reset();+ mouse.downAt(x + width / 2, y + height / 2);+ mouse.moveTo(x + width / 2 + 30, y + height / 2 + 30);+ const hint =+ h.app.ownerDocument.querySelector(".HintViewer")?.textContent ?? "";+ mouse.up();+ return hint;+ };++ it("hints that a corner is proportional and Shift frees it", () => {+ const { note } = setup();+ expect(hintWhileDragging(note, "se")).toContain("resize freely");+ });++ it("hints that an edge is free and Shift constrains it", () => {+ const { note } = setup();+ expect(hintWhileDragging(note, "e")).toContain("constrain proportions");+ });++ it("constrains an edge with Shift and scales the ceiling", () => {+ const { note, label } = setup();+ UI.resize(note, "e", [50, 0], { shift: true });++ const resized = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(resized.width).toBeGreaterThan(DEFAULT_STICKY_NOTE_SIZE);+ expect(resized.height).toBeCloseTo(resized.width);+ expect(ceiling(label.id)).toBeCloseTo(+ (28 * resized.width) / DEFAULT_STICKY_NOTE_SIZE,+ );+ });+ });++ describe("Stats", () => {+ beforeAll(() => {+ mockBoundingClientRect();+ });+ afterAll(() => {+ restoreOriginalGetBoundingClientRect();+ });++ const openStats = () => {+ fireEvent.contextMenu(GlobalTestState.interactiveCanvas, {+ button: 2,+ clientX: 1,+ clientY: 1,+ });+ const contextMenu = UI.queryContextMenu();+ fireEvent.click(queryByTestId(contextMenu!, "stats")!);+ };+ const statsInput = (label: string) =>+ UI.queryStatsProperty(label)?.querySelector(+ ".drag-input",+ ) as HTMLInputElement;++ it("keeps the base height on a width edit and scales the ceiling on a group edit", () => {+ const { note, label } = createNote({+ id: "note",+ text: LONG_TEXT,+ fontSize: 28,+ });+ const rectangle = API.createElement({+ type: "rectangle",+ id: "rectangle",+ x: 400,+ y: 100,+ width: 100,+ height: DEFAULT_STICKY_NOTE_SIZE,+ });+ API.setElements([note, label, rectangle]);+ layoutNotes(note.id);+ openStats();++ API.setSelectedElements([getElement(note.id)]);+ UI.updateInput(statsInput("W"), "400");+ let updated = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(updated.width).toBe(400);+ expect(updated.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);++ API.setSelectedElements([getElement(note.id), getElement(rectangle.id)]);+ // a group is one atomic unit with a common width (an ungrouped pair+ // shows "Mixed"); group scaling is uniform+ API.executeAction(actionGroup);+ const groupWidth = statsInput("W");+ UI.updateInput(groupWidth, String(Number(groupWidth.value) * 2));+ updated = getElement<ExcalidrawStickyNoteElement>(note.id);+ expect(updated.width).toBe(800);+ expect(getElement<ExcalidrawTextElement>(label.id).baseFontSize).toBe(56);+ });+ });++ describe("creation date", () => {+ it("exports the same absolute date to SVG and canvas, omitting unknown dates", async () => {+ const elements = [+ API.createElement({+ type: "stickynote",+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ // a past year, so the label carries it in every "current year"+ created: new Date(2025, 2, 7, 12).getTime(),+ }),+ API.createElement({+ type: "stickynote",+ x: 300,+ width: DEFAULT_STICKY_NOTE_SIZE,+ height: DEFAULT_STICKY_NOTE_SIZE,+ created: null,+ }),+ ];++ const svg = await exportToSvg(+ elements,+ { exportBackground: false, viewBackgroundColor: "#ffffff" },+ {},+ );+ expect(+ [...svg.querySelectorAll("text")].map((text) => text.textContent),+ ).toEqual(["7 Mar 2025"]);++ const canvas = await exportToCanvas({ elements, files: {} });+ expect(canvas.getContext("2d")?.fillText).toHaveBeenCalledWith(+ "7 Mar 2025",+ expect.any(Number),+ expect.any(Number),+ );+ });+ });+});diff --git a/packages/excalidraw/tests/tool.test.tsx b/packages/excalidraw/tests/tool.test.tsxindex 2d2b0532e9..02c1104610 100644--- a/packages/excalidraw/tests/tool.test.tsx+++ b/packages/excalidraw/tests/tool.test.tsx@@ -348,3 +348,41 @@ describe("props.activeTool (forced tool)", () => {expect(h.state.activeTool.type).toBe("laser");});});++describe("toolbar", () => {+ const queryTool = (type: string) =>+ document.querySelector<HTMLButtonElement>(+ `[data-testid="toolbar-${type}"]`,+ );+ const openExtraTools = () =>+ fireEvent.click(+ document.querySelector(".App-toolbar__extra-tools-trigger")!,+ );++ it("keeps the image tool in the extra-tools menu", async () => {+ await render(<Excalidraw />);+ expect(queryTool("image")).toBe(null);++ openExtraTools();+ expect(queryTool("image")).not.toBe(null);+ expect(queryTool("frame")).not.toBe(null);+ });++ it("hides the image tool through UIOptions.tools.image", async () => {+ await render(<Excalidraw UIOptions={{ tools: { image: false } }} />);+ openExtraTools();+ expect(queryTool("image")).toBe(null);+ expect(queryTool("frame")).not.toBe(null);+ });++ it("badges tools with their letter shortcut", async () => {+ await render(<Excalidraw />);+ const badge = (type: string) =>+ queryTool(type)?.querySelector(".ToolIcon__keybinding")?.textContent;+ expect(badge("selection")).toBe("V");+ expect(badge("rectangle")).toBe("R");+ expect(badge("text")).toBe("T");+ expect(badge("stickynote")).toBe("N");+ expect(badge("eraser")).toBe("E");+ });+});diff --git a/packages/excalidraw/tests/toolDrag.test.tsx b/packages/excalidraw/tests/toolDrag.test.tsxnew file mode 100644index 0000000000..46748e5ea7--- /dev/null+++ b/packages/excalidraw/tests/toolDrag.test.tsx@@ -0,0 +1,163 @@+import React from "react";++import {+ DEFAULT_STICKY_NOTE_SIZE,+ KEYS,+ viewportCoordsToSceneCoords,+} from "@excalidraw/common";++import type { ExcalidrawStickyNoteElement } from "@excalidraw/element/types";++import { Excalidraw } from "../index";++import { API } from "./helpers/api";+import { Keyboard, UI } from "./helpers/ui";+import { getTextEditor } from "./queries/dom";+import { fireEvent, GlobalTestState, render } from "./test-utils";++const { h } = window;++const POINTER = { pointerId: 1, pointerType: "mouse", isPrimary: true };++const stickyButton = () =>+ GlobalTestState.renderResult.getByToolName("stickynote");++/** press the tool button and move the pointer to (x, y) on the canvas */+const dragOut = (x: number, y: number) => {+ fireEvent.pointerDown(stickyButton(), {+ ...POINTER,+ button: 0,+ clientX: 0,+ clientY: 0,+ });+ fireEvent.pointerMove(window, { ...POINTER, clientX: x, clientY: y });+};++const liveNotes = () =>+ h.elements.filter(+ (element) => element.type === "stickynote" && !element.isDeleted,+ ) as ExcalidrawStickyNoteElement[];++describe("dragging a tool out of the toolbar", () => {+ beforeEach(async () => {+ await render(<Excalidraw handleKeyboardGlobally={true} />);+ API.setAppState({ width: 1000, height: 800 });+ });++ it("previews while dragging without touching the scene, and drops one note", async () => {+ // whatever tool is active must not stay armed under the dropped note+ UI.clickTool("arrow");+ expect(h.state.activeTool.type).toBe("arrow");++ // under the drag threshold nothing happens — a press is still a click+ fireEvent.pointerDown(stickyButton(), {+ ...POINTER,+ button: 0,+ clientX: 0,+ clientY: 0,+ });+ fireEvent.pointerMove(window, { ...POINTER, clientX: 3, clientY: 3 });+ expect(h.app.toolDrag.preview).toBeNull();++ fireEvent.pointerMove(window, { ...POINTER, clientX: 300, clientY: 260 });+ const preview = h.app.toolDrag.preview!;+ expect(preview).not.toBeNull();+ expect(preview.type).toBe("stickynote");+ expect([preview.width, preview.height]).toEqual([+ DEFAULT_STICKY_NOTE_SIZE,+ DEFAULT_STICKY_NOTE_SIZE,+ ]);+ // the preview is not an element yet: nothing for collaborators or history+ expect(h.elements).toHaveLength(0);+ expect(API.getUndoStack()).toHaveLength(0);++ fireEvent.pointerMove(window, { ...POINTER, clientX: 400, clientY: 350 });+ fireEvent.pointerUp(GlobalTestState.interactiveCanvas, {+ ...POINTER,+ button: 0,+ clientX: 400,+ clientY: 350,+ });++ expect(h.app.toolDrag.preview).toBeNull();+ const [note] = liveNotes();+ expect(liveNotes()).toHaveLength(1);+ // centered on the pointer, at the default size+ const center = viewportCoordsToSceneCoords(+ { clientX: 400, clientY: 350 },+ h.state,+ );+ expect(note.x + note.width / 2).toBeCloseTo(center.x);+ expect(note.y + note.height / 2).toBeCloseTo(center.y);+ expect(note.width).toBe(DEFAULT_STICKY_NOTE_SIZE);+ expect(note.baseHeight).toBe(DEFAULT_STICKY_NOTE_SIZE);+ // The drop is recorded while its label is being edited.+ expect(h.state.editingTextElement).not.toBeNull();+ expect(API.getUndoStack()).toHaveLength(1);+ // back on the selection tool (the editor owns the selection meanwhile,+ // as on the click path)+ expect(h.state.activeTool.type).toBe("selection");++ // Abandoning the editor leaves one visible action; undo removes the note.+ Keyboard.keyPress(KEYS.ESCAPE, await getTextEditor());+ expect(API.getUndoStack()).toHaveLength(1);+ Keyboard.undo();+ expect(liveNotes()).toHaveLength(0);+ });++ it("places the preview and dropped note on the grid", () => {+ API.setAppState({ gridModeEnabled: true, gridSize: 20 });+ dragOut(300, 300);+ expect(h.app.toolDrag.preview).toMatchObject({ x: 180, y: 180 });++ fireEvent.pointerUp(GlobalTestState.interactiveCanvas, {+ ...POINTER,+ button: 0,+ clientX: 300,+ clientY: 300,+ });+ expect(liveNotes()[0]).toMatchObject({ x: 180, y: 180 });+ });++ it("leaves nothing behind when Escape cancels the drag", () => {+ dragOut(300, 260);+ expect(h.app.toolDrag.preview).not.toBeNull();++ fireEvent.keyDown(window, { key: KEYS.ESCAPE });+ expect(h.app.toolDrag.preview).toBeNull();++ // a pointer-up arriving after the cancel is inert+ fireEvent.pointerUp(GlobalTestState.interactiveCanvas, {+ ...POINTER,+ button: 0,+ clientX: 300,+ clientY: 260,+ });+ expect(h.elements).toHaveLength(0);+ expect(API.getUndoStack()).toHaveLength(0);+ expect(h.state.editingTextElement).toBeNull();+ });++ it("drops nothing when released outside the canvas", () => {+ dragOut(300, 260);+ fireEvent.pointerUp(document.body, {+ ...POINTER,+ button: 0,+ clientX: 300,+ clientY: 260,+ });+ expect(h.app.toolDrag.preview).toBeNull();+ expect(h.elements).toHaveLength(0);+ expect(API.getUndoStack()).toHaveLength(0);+ });++ it("keeps a plain click selecting the tool", () => {+ const button = stickyButton();+ fireEvent.pointerDown(button, { ...POINTER, button: 0 });+ fireEvent.pointerUp(button, { ...POINTER, button: 0 });+ fireEvent.click(button);+ expect(h.state.activeTool.type).toBe("stickynote");+ expect(h.app.toolDrag.preview).toBeNull();+ expect(h.elements).toHaveLength(0);+ });+});diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.tsindex e35937c40e..44fcc9aa16 100644--- a/packages/excalidraw/types.ts+++ b/packages/excalidraw/types.ts@@ -159,6 +159,7 @@ export type ToolType =| "hand"| "frame"| "magicframe"+ | "stickynote"| "embeddable"| "laser"| "autoshape"@@ -416,6 +417,8 @@ export interface AppState {exportWithDarkMode: boolean;exportScale: number;currentItemStrokeColor: string;+ currentItemStickynoteStrokeColor: string;+ currentItemStickynoteBackgroundColor: string;currentItemBackgroundColor: string;currentItemFillStyle: ExcalidrawElement["fillStyle"];currentItemStrokeWidthKey: StrokeWidthKey;@@ -546,6 +549,9 @@ export interface AppState {* even though both drive `currentItemBackgroundColor` (its defaults and* use case differ — no transparent) */bucketFill: readonly string[] | null;+ /** sticky notes are their own color domain (own defaults, own picks) */+ stickyNoteStroke: readonly string[] | null;+ stickyNoteBackground: readonly string[] | null;};}@@ -1145,6 +1151,8 @@ export type AppClassProperties = {arrowText: App["arrowText"];cursor: App["cursor"];bucketFill: App["bucketFill"];+ toolDrag: App["toolDrag"];+ activeResizeHandle: App["activeResizeHandle"];isToolLocked: App["isToolLocked"];getEffectiveGridSize: App["getEffectiveGridSize"];setPlugins: App["setPlugins"];diff --git a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsxindex bc4ff671f5..5ad3ee2423 100644--- a/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx+++ b/packages/excalidraw/wysiwyg/textWysiwyg.test.tsx@@ -1381,13 +1381,11 @@ describe("textWysiwyg", () => {const originalRectY = rectangle.y;const originalTextX = text.x;const originalTextY = text.y;- mouse.select(rectangle);- mouse.downAt(rectangle.x, rectangle.y);- mouse.moveTo(rectangle.x + 100, rectangle.y + 50);- mouse.up(rectangle.x + 100, rectangle.y + 50);- expect(rectangle.x).toBe(80);+ UI.resize(rectangle, "nw", [100, 50]);+ // The NW handle crossed the right edge, so the container flips past it.+ expect(rectangle.x).toBe(100);expect(rectangle.y).toBe(-40);- expect(text.x).toBe(85);+ expect(text.x).toBe(105);expect(text.y).toBe(-35);Keyboard.withModifierKeys({ ctrl: true }, () => {diff --git a/packages/excalidraw/wysiwyg/textWysiwyg.tsx b/packages/excalidraw/wysiwyg/textWysiwyg.tsxindex b7973f2d4b..ec356d1b63 100644--- a/packages/excalidraw/wysiwyg/textWysiwyg.tsx+++ b/packages/excalidraw/wysiwyg/textWysiwyg.tsx@@ -43,6 +43,7 @@ import { getWrappedTextLines } from "@excalidraw/element";import {isArrowElement,isBoundToContainer,+ isStickyNoteElement,isTextElement,} from "@excalidraw/element";@@ -305,57 +306,15 @@ export const textWysiwyg = ({coordX = boundTextCoords.x;coordY = boundTextCoords.y;}- const propertiesUpdated = textPropertiesUpdated(- updatedTextElement,- editable,- );-- let originalContainerData;- if (propertiesUpdated) {- originalContainerData = updateOriginalContainerCache(- container.id,- container.height,- );- } else {- originalContainerData = originalContainerCache[container.id];- if (!originalContainerData) {- originalContainerData = updateOriginalContainerCache(- container.id,- container.height,- );- }- }-maxWidth = getBoundTextMaxWidth(container, updatedTextElement);maxHeight = getBoundTextMaxHeight(container,updatedTextElement as ExcalidrawTextElementWithContainer,);- // autogrow container height if text exceeds- if (!isArrowElement(container) && height > maxHeight) {- const targetContainerHeight = computeContainerDimensionForBoundText(- height,- container.type,- );-- app.scene.mutateElement(container, { height: targetContainerHeight });- updateBoundElements(container, app.scene);- return;- } else if (- // autoshrink container height until original container height- // is reached when text is removed- !isArrowElement(container) &&- container.height > originalContainerData.height &&- height < maxHeight- ) {- const targetContainerHeight = computeContainerDimensionForBoundText(- height,- container.type,- );- app.scene.mutateElement(container, { height: targetContainerHeight });- updateBoundElements(container, app.scene);- } else {+ if (isStickyNoteElement(container)) {+ // the sticky fit (App.updateElement) owns the note's height; the+ // editor only mirrors the fitted label's positionconst { x, y } = computeBoundTextPosition(container,updatedTextElement as ExcalidrawTextElementWithContainer,@@ -363,6 +322,64 @@ export const textWysiwyg = ({);coordX = x;coordY = y;+ } else {+ const propertiesUpdated = textPropertiesUpdated(+ updatedTextElement,+ editable,+ );++ let originalContainerData;+ if (propertiesUpdated) {+ originalContainerData = updateOriginalContainerCache(+ container.id,+ container.height,+ );+ } else {+ originalContainerData = originalContainerCache[container.id];+ if (!originalContainerData) {+ originalContainerData = updateOriginalContainerCache(+ container.id,+ container.height,+ );+ }+ }++ // autogrow container height if text exceeds+ if (!isArrowElement(container) && height > maxHeight) {+ const targetContainerHeight = computeContainerDimensionForBoundText(+ height,+ container.type,+ );++ app.scene.mutateElement(container, {+ height: targetContainerHeight,+ });+ updateBoundElements(container, app.scene);+ return;+ } else if (+ // autoshrink container height until original container height+ // is reached when text is removed+ !isArrowElement(container) &&+ container.height > originalContainerData.height &&+ height < maxHeight+ ) {+ const targetContainerHeight = computeContainerDimensionForBoundText(+ height,+ container.type,+ );+ app.scene.mutateElement(container, {+ height: targetContainerHeight,+ });+ updateBoundElements(container, app.scene);+ } else {+ const { x, y } = computeBoundTextPosition(+ container,+ updatedTextElement as ExcalidrawTextElementWithContainer,+ elementsMap,+ );+ coordX = x;+ coordY = y;+ }}}const [viewportX, viewportY] = getViewportCoords(coordX, coordY);@@ -603,21 +620,27 @@ export const textWysiwyg = ({app.scene.getNonDeletedElementsMap(),);- const font = getFontString({- fontSize: app.state.currentItemFontSize,- fontFamily: app.state.currentItemFontFamily,- });if (container) {const boundTextElement = getBoundTextElement(container,app.scene.getNonDeletedElementsMap(),);- const wrappedText = wrapText(- `${editable.value}${text}`,- font,- getBoundTextMaxWidth(container, boundTextElement),- );- const width = getTextWidth(wrappedText, font);+ const font = getFontString({+ fontSize:+ isStickyNoteElement(container) && boundTextElement+ ? boundTextElement.fontSize+ : app.state.currentItemFontSize,+ fontFamily:+ isStickyNoteElement(container) && boundTextElement+ ? boundTextElement.fontFamily+ : app.state.currentItemFontFamily,+ });+ const maxWidth = getBoundTextMaxWidth(container, boundTextElement);+ const { selectionStart, selectionEnd, value } = editable;+ const nextText =+ value.slice(0, selectionStart) + text + value.slice(selectionEnd);+ const wrappedText = wrapText(nextText, font, maxWidth);+ const width = Math.min(getTextWidth(wrappedText, font), maxWidth);editable.style.width = `${width}px`;}};diff --git a/packages/utils/src/shape.ts b/packages/utils/src/shape.tsindex 5d50f4b473..2d0e27aec7 100644--- a/packages/utils/src/shape.ts+++ b/packages/utils/src/shape.ts@@ -50,6 +50,7 @@ import type {ExcalidrawLinearElement,ExcalidrawRectangleElement,ExcalidrawSelectionElement,+ ExcalidrawStickyNoteElement,ExcalidrawTextElement,} from "@excalidraw/element/types";import type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";@@ -104,6 +105,7 @@ export type GeometricShape<Point extends GlobalPoint | LocalPoint> =type RectangularElement =| ExcalidrawRectangleElement+ | ExcalidrawStickyNoteElement| ExcalidrawDiamondElement| ExcalidrawFrameLikeElement| ExcalidrawEmbeddableElementdiff --git a/packages/utils/tests/__snapshots__/export.test.ts.snap b/packages/utils/tests/__snapshots__/export.test.ts.snapindex 6954af24ef..4382fe84a6 100644--- a/packages/utils/tests/__snapshots__/export.test.ts.snap+++ b/packages/utils/tests/__snapshots__/export.test.ts.snap@@ -19,6 +19,8 @@ exports[`exportToSvg > with default arguments 1`] = `"bucketFill": null,"elementBackground": null,"elementStroke": null,+ "stickyNoteBackground": null,+ "stickyNoteStroke": null,},"contextMenu": null,"croppingElementId": null,@@ -33,6 +35,8 @@ exports[`exportToSvg > with default arguments 1`] = `"currentItemRoughness": 1,"currentItemRoundness": "sharp","currentItemStartArrowhead": null,+ "currentItemStickynoteBackgroundColor": "#ffdf6b",+ "currentItemStickynoteStrokeColor": "#1e1e1e","currentItemStrokeColor": "#1e1e1e","currentItemStrokeStyle": "solid","currentItemStrokeVariability": "constant",