Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(share): style to-do list checkboxes like the app
Elian Dorand74c54b49eec
diff --git a/apps/client/src/index.ts b/apps/client/src/index.tsindex b60f866983..eb7862097e 100644--- a/apps/client/src/index.ts+++ b/apps/client/src/index.ts@@ -7,6 +7,7 @@ import "@triliumnext/ckeditor5/src/theme/external_links.css";import "@triliumnext/ckeditor5/src/theme/footnotes.css";import "@triliumnext/ckeditor5/src/theme/headings.css";import "@triliumnext/ckeditor5/src/theme/reference_links.css";+import "@triliumnext/ckeditor5/src/theme/todo_lists.css";import { createFontStylesheetLink } from "./services/font";import {diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 4946237e01..e58d50dd19 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -2887,17 +2887,6 @@ iframe.print-iframe {* TASK STATES*/-:where(:root) {- --task-checkbox-without-state-background: #d5d5d5;- --task-checkbox-with-state-background: orange;- --task-checkbox-done-color: green;- --task-checkbox-unknown-state-color: orange;- --task-checkbox-glyph-color: white;-- --task-checkbox-border-radius: 4px;- --task-checkbox-glyph-ratio: .8;-}-:root .tn-task-checkbox {--_checkbox-size: 18px;@@ -2934,105 +2923,6 @@ iframe.print-iframe {margin-bottom: 8px;}-/* Prevent variables from bleeding into nested items */-.ck-content .todo-list .todo-list {- --task-state-glyph: initial;- --task-state-glyph-font-family: initial;- --task-state-color: initial;- --task-state-adjusted-color: initial;- --task-state-hue: initial;- --_task-checkbox-background: initial;-}--/* All tasks with a state */-:where(.ck-content .todo-list li[data-trilium-task-state]:not([data-trilium-task-state="none"])),-.tn-task-checkbox:not([data-trilium-task-state="none"]) {- --_task-checkbox-background: var(--task-state-adjusted-color, var(--task-state-color, var(--task-checkbox-with-state-background)));-}--/* Default checked state */-:where(.ck-content .todo-list li:where(:not([data-trilium-task-state]), [data-trilium-task-state="done"]):has(> .todo-list__label input[type="checkbox"]:checked)),-.tn-task-checkbox[data-trilium-task-state="done"] {- --task-state-glyph: "";- --task-state-glyph-font-family: boxicons;- --task-state-hue: var(--task-checkbox-done-hue);- --_task-checkbox-background: var(--task-checkbox-done-color);-}--/* The read-only view renders a real <label>, which Bootstrap's reboot makes- inline-block — an empty label (its checkbox is absolutely positioned below)- then produces a full-height line of its own, pushing the item text onto the- next line. Restore the plain inline display so the empty label collapses. */-:root .ck-content.ck-content ul.todo-list li .todo-list__label {- display: inline;-}--:root .ck-content.ck-content ul.todo-list li .todo-list__label input[type="checkbox"] {- --_checkbox-size: var(--ck-content-todo-list-checkmark-size);-- /* Take the checkbox out of the inline flow in every variant and centre it- geometrically on the first text line (the li is the positioned ancestor,- `li p` has no margin, and CKEditor's own `left/right: -25px` still places- it in the gutter). Centering via `vertical-align: middle` depends on font- metrics and differs from the absolutely-positioned `_without-description`- variant — this makes both variants share one deterministic geometry. */- position: absolute;- top: calc((1lh - var(--_checkbox-size)) / 2);- inset-inline-start: -25px;- inset-inline-end: auto;- /* `1lh` must resolve against the text's line height, not the UA form-control- font, and the UA's 3px checkbox margins would offset the absolute position.- (Bootstrap's reboot happens to do both, but don't depend on it.) */- margin: 0;- font: inherit;-}--/* CKEditor middle-aligns the inline description span, while a real-<p> description- (the `_without-description` variant) sits on the plain baseline — so the text- position depended on which variant rendered. Align both on the baseline. */-:root .ck-content.ck-content ul.todo-list li .todo-list__label .todo-list__label__description {- vertical-align: baseline;-}--/* Checkbox */-:root .ck-content.ck-content ul.todo-list li .todo-list__label input[type="checkbox"],-.tn-task-checkbox {- /* Checkbox body */- &::before {- all: unset;-- content: "";- position: absolute;- inset: 0;- border-radius: var(--task-checkbox-border-radius);- background: var(--_task-checkbox-background, var(--task-checkbox-without-state-background));- }-- /* Checkbox tick */- &::after {- all: unset;- display: flex;- align-items: center;- justify-content: center;- position: absolute;- inset: 0;- content: var(--task-state-glyph);- font-family: var(--task-state-glyph-font-family, inherit);- /* Em box == checkbox box: the flex centering has zero leftover- space to round, so nothing can snap asymmetrically. */- font-size: var(--_checkbox-size);- line-height: 1;- color: var(--task-checkbox-glyph-color);- /* The shrink is geometric, not typographic — scale() doesn't snap- to the device-pixel grid, so the glyph stays centred at any zoom. */- transform: scale(var(--task-checkbox-glyph-ratio));- }-- &:disabled {- opacity: 1;- }-}-/** Collapsible blocks*/diff --git a/packages/ckeditor5/src/theme/todo_lists.css b/packages/ckeditor5/src/theme/todo_lists.cssnew file mode 100644index 0000000000..2dab74a0e1--- /dev/null+++ b/packages/ckeditor5/src/theme/todo_lists.css@@ -0,0 +1,111 @@+/* The checkboxes of to-do lists in note content, shared by the app and the share theme. */++:where(:root) {+ --task-checkbox-without-state-background: #d5d5d5;+ --task-checkbox-with-state-background: orange;+ --task-checkbox-done-color: green;+ --task-checkbox-unknown-state-color: orange;+ --task-checkbox-glyph-color: white;++ --task-checkbox-border-radius: 4px;+ --task-checkbox-glyph-ratio: .8;+}++/* Prevent variables from bleeding into nested items */+.ck-content .todo-list .todo-list {+ --task-state-glyph: initial;+ --task-state-glyph-font-family: initial;+ --task-state-color: initial;+ --task-state-adjusted-color: initial;+ --task-state-hue: initial;+ --_task-checkbox-background: initial;+}++/* All tasks with a state */+:where(.ck-content .todo-list li[data-trilium-task-state]:not([data-trilium-task-state="none"])),+.tn-task-checkbox:not([data-trilium-task-state="none"]) {+ --_task-checkbox-background: var(--task-state-adjusted-color, var(--task-state-color, var(--task-checkbox-with-state-background)));+}++/* Default checked state */+:where(.ck-content .todo-list li:where(:not([data-trilium-task-state]), [data-trilium-task-state="done"]):has(> .todo-list__label input[type="checkbox"]:checked)),+.tn-task-checkbox[data-trilium-task-state="done"] {+ --task-state-glyph: "";+ --task-state-glyph-font-family: boxicons;+ --task-state-hue: var(--task-checkbox-done-hue);+ --_task-checkbox-background: var(--task-checkbox-done-color);+}++/* The read-only view renders a real <label>, which Bootstrap's reboot makes+ inline-block — an empty label (its checkbox is absolutely positioned below)+ then produces a full-height line of its own, pushing the item text onto the+ next line. Restore the plain inline display so the empty label collapses. */+:root .ck-content.ck-content ul.todo-list li .todo-list__label {+ display: inline;+}++:root .ck-content.ck-content ul.todo-list li .todo-list__label input[type="checkbox"] {+ --_checkbox-size: var(--ck-content-todo-list-checkmark-size);++ /* Take the checkbox out of the inline flow in every variant and centre it+ geometrically on the first text line (the li is the positioned ancestor,+ `li p` has no margin, and CKEditor's own `left/right: -25px` still places+ it in the gutter). Centering via `vertical-align: middle` depends on font+ metrics and differs from the absolutely-positioned `_without-description`+ variant — this makes both variants share one deterministic geometry. */+ position: absolute;+ top: calc((1lh - var(--_checkbox-size)) / 2);+ inset-inline-start: -25px;+ inset-inline-end: auto;+ /* `1lh` must resolve against the text's line height, not the UA form-control+ font, and the UA's 3px checkbox margins would offset the absolute position.+ (Bootstrap's reboot happens to do both, but don't depend on it.) */+ margin: 0;+ font: inherit;+}++/* CKEditor middle-aligns the inline description span, while a real-<p> description+ (the `_without-description` variant) sits on the plain baseline — so the text+ position depended on which variant rendered. Align both on the baseline. */+:root .ck-content.ck-content ul.todo-list li .todo-list__label .todo-list__label__description {+ vertical-align: baseline;+}++/* Checkbox */+:root .ck-content.ck-content ul.todo-list li .todo-list__label input[type="checkbox"],+.tn-task-checkbox {+ /* Checkbox body */+ &::before {+ all: unset;++ content: "";+ position: absolute;+ inset: 0;+ border-radius: var(--task-checkbox-border-radius);+ background: var(--_task-checkbox-background, var(--task-checkbox-without-state-background));+ }++ /* Checkbox tick */+ &::after {+ all: unset;+ display: flex;+ align-items: center;+ justify-content: center;+ position: absolute;+ inset: 0;+ content: var(--task-state-glyph);+ font-family: var(--task-state-glyph-font-family, inherit);+ /* Em box == checkbox box: the flex centering has zero leftover+ space to round, so nothing can snap asymmetrically. */+ font-size: var(--_checkbox-size);+ line-height: 1;+ color: var(--task-checkbox-glyph-color);+ /* The shrink is geometric, not typographic — scale() doesn't snap+ to the device-pixel grid, so the glyph stays centred at any zoom. */+ transform: scale(var(--task-checkbox-glyph-ratio));+ }++ &:disabled {+ opacity: 1;+ }+}diff --git a/packages/share-theme/src/base.css b/packages/share-theme/src/base.cssindex 3c28607a8b..d1b2a0f575 100644--- a/packages/share-theme/src/base.css+++ b/packages/share-theme/src/base.css@@ -33,6 +33,10 @@ html.theme-light {/* The code colors of `theme-next-light.css`. */--code-block-box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1), 0px 0px 2px rgba(0, 0, 0, 0.2);--inline-code-background-color: rgba(0, 0, 0, 0.05);+ /* The task checkbox colors of `theme-next-light.css`. */+ --task-checkbox-without-state-background: #00000029;+ --task-checkbox-with-state-background: gray;+ --task-checkbox-done-color: #339933;/* The tree pane colors of `theme-next-light.css`. */--tree-background: #f2f2f2;--tree-item-color: #383838;@@ -83,6 +87,10 @@ html.theme-dark {/* The code colors of `theme-next-dark.css`. */--code-block-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);--inline-code-background-color: rgba(255, 255, 255, 0.08);+ /* The task checkbox colors of `theme-next-dark.css`. */+ --task-checkbox-without-state-background: #ffffff26;+ --task-checkbox-with-state-background: #ffffff3b;+ --task-checkbox-done-color: #408b40;/* The tree pane colors of `theme-next-dark.css`. */--tree-background: #1f1f1f;--tree-item-color: #aaaaaa;diff --git a/packages/share-theme/src/content/task_states.css b/packages/share-theme/src/content/task_states.cssindex 5f4a1515de..6d059b8488 100644--- a/packages/share-theme/src/content/task_states.css+++ b/packages/share-theme/src/content/task_states.css@@ -1,21 +1,10 @@/*- * Todo checkboxes.- *- * Custom task states carry `data-trilium-task-state` on their `<li>`; the colour,- * hue and icon glyph of each state are injected per state into the icon pack- * stylesheet. The unchecked and done states carry no attribute and keep the- * default checkbox below.- *- * The doubled class is what it takes to override CKEditor's own checkbox rules:- * they are written as `:is(<content>, <editor>)`, so they take the specificity of- * the more specific editor arm.+ * Todo checkboxes take the app's rules from `@triliumnext/ckeditor5/src/theme/todo_lists.css`.+ * Custom task states carry `data-trilium-task-state` on their `<li>`; the color, hue and icon+ * glyph of each state are injected per state into the icon pack stylesheet.*/-.ck-content .todo-list .todo-list__label > input:before {- background-color: var(--background-primary);- border-color: var(--text-primary) !important;-}-+/* The state colors of `theme-next-light.css` and `theme-next-dark.css`. */html.theme-light [data-trilium-task-state] {--task-state-adjusted-color: hsl(var(--task-state-hue), 50%, 50%);}@@ -23,63 +12,3 @@ html.theme-light [data-trilium-task-state] {html.theme-dark [data-trilium-task-state] {--task-state-adjusted-color: hsl(var(--task-state-hue), 40%, 50%);}--/* A state that defines no colour is injected as `unset`, which on a custom property- means inherit — so without this a nested task would pick up its parent's colour. */-.ck-content .todo-list .todo-list {- --task-state-hue: initial;- --task-state-color: initial;- --task-state-adjusted-color: initial;- --task-state-glyph: initial;- --task-state-glyph-font-family: initial;-}--/* Falls back to the raw colour when the state has no hue to adjust, and to the text- colour when it defines no colour at all — including states whose definition is gone. */-.ck-content .todo-list li[data-trilium-task-state] {- --_task-state-color: var(--task-state-adjusted-color, var(--task-state-color, var(--text-primary)));-}--/* Direct children only, so a nested task keeps its own state instead of the parent's. */-.ck-content.ck-content .todo-list li[data-trilium-task-state] > .todo-list__label > input[type="checkbox"]:after {- all: unset;-- position: absolute;- inset: 0;- display: flex;- align-items: center;- justify-content: center;- content: var(--task-state-glyph);- font-family: var(--task-state-glyph-font-family);- /* Em box == checkbox box, shrink via scale(): geometric, so the glyph- stays centred at any zoom/DPI instead of snapping to the pixel grid. */- font-size: var(--ck-content-todo-list-checkmark-size);- line-height: 1;- color: var(--_task-state-color);- transform: scale(0.8);-}--/* One deterministic geometry for both rendering variants (inline description span vs- the real-<p> `_without-description` one): the checkbox leaves the inline flow and is- centred geometrically on the first text line, and the description always sits on the- plain baseline instead of CKEditor's metric-dependent `vertical-align: middle`. */-.ck-content.ck-content .todo-list li .todo-list__label {- /* An empty inline-block label would create a line of its own (see the client- stylesheet); keep it collapsible. */- display: inline;-}--.ck-content.ck-content .todo-list li .todo-list__label input[type="checkbox"] {- position: absolute;- top: calc((1lh - var(--ck-content-todo-list-checkmark-size)) / 2);- inset-inline-start: -25px;- inset-inline-end: auto;- /* `1lh` must resolve against the text's line height, not the UA form-control- font, and the UA's 3px checkbox margins would offset the absolute position. */- margin: 0;- font: inherit;-}--.ck-content.ck-content .todo-list li .todo-list__label .todo-list__label__description {- vertical-align: baseline;-}diff --git a/packages/share-theme/src/index.ts b/packages/share-theme/src/index.tsindex 40de05f566..dc66baf2eb 100644--- a/packages/share-theme/src/index.ts+++ b/packages/share-theme/src/index.ts@@ -22,6 +22,7 @@ import "virtual:code-themes.css";import "@triliumnext/ckeditor5/src/theme/ck-content.css";import "@triliumnext/ckeditor5/src/theme/tabs.css";import "@triliumnext/ckeditor5/src/theme/multicolumn.css";+import "@triliumnext/ckeditor5/src/theme/todo_lists.css";import { applyTabs, revealFragment } from "@triliumnext/ckeditor5/src/plugins/tabs/tabs_read_only.js";import { enhanceLinkPreviews } from "@triliumnext/commons/src/lib/link_embed_dom.js";