diff --git a/web/index.html b/web/index.html index ffe06d8ba..907c168a3 100644 --- a/web/index.html +++ b/web/index.html @@ -2,6 +2,7 @@ + diff --git a/web/src/components/MemoEditor/README.md b/web/src/components/MemoEditor/README.md index dc071d7b0..5a02b8ac6 100644 --- a/web/src/components/MemoEditor/README.md +++ b/web/src/components/MemoEditor/README.md @@ -27,6 +27,8 @@ MemoEditor memo level: name | draft seed, mode, data, draft stor - **`view/`** is the read-only surface over `MemoMarkdown`: tags and mentions navigate, in-memo anchors scroll, a paragraph that is one bare link becomes a preview card through the editor's block view (`linkCards.ts`), the page's search matches are painted, and heading ids match the outline. Tag and mention clicks arrive through the editor's `onClick` callbacks. Read-only tags with a click handler are focusable buttons; Enter activates on press and Space on release through the same click callback. Editable tags remain text. Nothing in memos matches the editor's class names or mutates its DOM. Previews that have Markdown but no memo query (the link-memo search, the share image) use `MemoContentView` directly. - **`edit/`** is the editing surface: `EditSession` renders the chrome (timestamp, attachments, suggestions, toolbar, focus mode, audio recording) over the draft store `MemoEditor` provides, persists the draft while open, and saves through the memo mutations. `Editor.tsx` is the composer's editor: `MemoMarkdown` editable with the composer's own extensions (`#tag` and `:emoji` autocomplete, file paste and drop), behind the `EditorController` contract in `controller.ts`. +Memo content uses 16px text on 24px lines with 12px between blocks; the editor keeps list rows compact. Code blocks use the full `well` fill so they remain distinct from the surrounding surface in Dark. Task items use `control-edge` for their checkbox border and darken Dark's pale accent behind the editor's white checkmark. Callouts use the app's accent, success, warning and danger colors. Custom tag tints bound lightness and sRGB channels so black and white remain visible across themes without coloring the text. + Code blocks use lazy-loaded `@pierre/highlights` tokens as editor decorations, without an HTML conversion. GitHub Light and GitHub Dark Dimmed colors follow the document's color scheme; ordinary text and structural punctuation keep the editor's text color. Unsupported languages, unavailable WebAssembly, or browsers without `light-dark()` colors leave the code as plain text. Highlighting never changes the saved Markdown. ## Data diff --git a/web/src/index.css b/web/src/index.css index 7ee0bb350..aba6d993d 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -17,6 +17,13 @@ @custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *)); @layer base { + .memos-theme-changing, + .memos-theme-changing *, + .memos-theme-changing *::before, + .memos-theme-changing *::after { + transition: none !important; + } + * { @apply border-mu-line outline-none ring-0; scrollbar-color: color-mix(in oklch, var(--mu-text-secondary) 55%, transparent) transparent; diff --git a/web/src/lib/markdownStyles.ts b/web/src/lib/markdownStyles.ts index 2774020d1..5a61ca7fb 100644 --- a/web/src/lib/markdownStyles.ts +++ b/web/src/lib/markdownStyles.ts @@ -22,6 +22,10 @@ export const headingClasses: Readonly>> = { export const markdownStyles = { // Relative size so code inside headings scales with the heading. inlineCode: "font-mono text-[0.875em] bg-mu-well px-1 py-0.5 rounded-mu-md", + codeBlock: "bg-mu-well!", + // Keep the editor's white checkmark readable when Dark uses a pale accent. + taskList: + "[--mbe-border:var(--mu-control-edge)] [--mbe-accent:light-dark(var(--mu-accent),color-mix(in_oklab,var(--mu-accent)_55%,var(--mu-surface)))]", link: "text-mu-accent underline decoration-mu-accent/50 underline-offset-2 transition-colors hover:decoration-mu-accent", image: "max-w-full my-2 rounded-mu-lg", } as const; @@ -38,11 +42,11 @@ export const tagStyles = { defaultColor: "text-mu-text rich:bg-mu-well rich:[&[role=button]]:hover:bg-mu-hover", /** * The user's color, read from `--tag-color` on the element, as the package's Badge `color` draws - * it: an 18% tint behind ink text, the same in both themes. The text never takes the color, since - * no chosen color is readable as text on its own tint in both themes. + * it: lightness kept between 50% and 75%, then clipped to sRGB before the 18% tint. + * The text stays ink so user-chosen colors cannot reduce its contrast. */ customColor: - "text-mu-text rich:bg-[color-mix(in_srgb,var(--tag-color)_18%,transparent)] rich:[&[role=button]]:hover:bg-[color-mix(in_srgb,var(--tag-color)_26%,transparent)]", + "text-mu-text rich:[--tag-tint:color(from_oklch(from_var(--tag-color)_clamp(0.5,l,0.75)_c_h)_srgb_clamp(0,r,1)_clamp(0,g,1)_clamp(0,b,1))] rich:bg-[color-mix(in_srgb,var(--tag-tint)_18%,transparent)] rich:[&[role=button]]:hover:bg-[color-mix(in_srgb,var(--tag-tint)_26%,transparent)]", } as const; /** diff --git a/web/src/lib/memo-markdown.ts b/web/src/lib/memo-markdown.ts index e0944e430..ecd6f2360 100644 --- a/web/src/lib/memo-markdown.ts +++ b/web/src/lib/memo-markdown.ts @@ -246,6 +246,11 @@ export const MEMO_EDITOR_THEME: Theme = (() => { popupBorder: "var(--mu-line)", hover: "var(--mu-hover)", danger: "var(--mu-danger)", + calloutNote: "var(--mu-accent)", + calloutTip: "var(--mu-success)", + calloutImportant: "var(--mu-accent)", + calloutWarning: "var(--mu-warning)", + calloutCaution: "var(--mu-danger)", }; return { colorScheme: "inherit", @@ -256,11 +261,13 @@ export const MEMO_EDITOR_THEME: Theme = (() => { fontSize: 16, lineHeight: 24, radius: "var(--mu-radius-md)", - blockGap: 8, + blockGap: 12, }, classes: { heading: headingClasses, code: markdownStyles.inlineCode, + codeBlock: markdownStyles.codeBlock, + taskList: markdownStyles.taskList, link: markdownStyles.link, // The editor sizes and spaces its images; raw HTML images keep markdownStyles.image. image: "rounded-mu-lg", diff --git a/web/src/utils/theme.ts b/web/src/utils/theme.ts index 362be2663..1e42e662d 100644 --- a/web/src/utils/theme.ts +++ b/web/src/utils/theme.ts @@ -149,7 +149,13 @@ export const getThemeWithFallback = (userTheme?: string): Theme => { * tokens and the `color-scheme` from it, and popups portaled to inherit them. */ const setThemeAttribute = (appearance: Appearance): void => { - document.documentElement.setAttribute("data-theme", appearance); + const root = document.documentElement; + if (root.getAttribute("data-theme") === appearance) return; + root.classList.add("memos-theme-changing"); + root.setAttribute("data-theme", appearance); + // Commit every surface and text color together before restoring interaction transitions. + void root.offsetHeight; + root.classList.remove("memos-theme-changing"); }; /**