From d5d7c1565ebc775aadc6dac1c93c4a11b8057348 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 20:24:19 +0200 Subject: [PATCH 01/37] feat(print): implement stylesheet for global note printing --- src/public/stylesheets/style.css | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 24cfee62f..654810254 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -1605,3 +1605,52 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { background: var(--hover-item-background-color); color: var(--hover-item-text-color); } + +@media print { + .tab-row-container, + #launcher-pane, + #left-pane, + #right-pane, + .title-row .button-widget, + .ribbon-container { + display: none !important; + } + + body, + #root-widget, + #rest-pane > div.component:first-child, + .note-detail-printable, + .note-detail-editable-text-editor { + height: unset !important; + overflow: auto; + } + + html, + body { + height: unset !important; + overflow: visible; + position: unset; + } + + #root-widget, + #horizontal-main-container, + #rest-pane, + #vertical-main-container, + #center-pane, + .split-note-container-widget, + .note-split { + display: block !important; + overflow: auto; + } + + #rest-pane, + .note-split { + width: 100% !important; + max-width: unset !important; + } + + .component { + contain: none !important; + } + +} \ No newline at end of file From c06642ba1ea4b36f117c3eef4a3afc47a47c479a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 20:27:32 +0200 Subject: [PATCH 02/37] fix(print): remove extra spacing --- src/public/stylesheets/style.css | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 654810254..fd4b1bf0b 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -1612,7 +1612,9 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { #left-pane, #right-pane, .title-row .button-widget, - .ribbon-container { + .ribbon-container, + .scroll-padding-widget, + .spacer { display: none !important; } @@ -1638,7 +1640,7 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { #vertical-main-container, #center-pane, .split-note-container-widget, - .note-split { + .note-split:not(.hidden-ext) { display: block !important; overflow: auto; } From 7dfba9f513501b2e1443cc43eced2fd30571c804 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 20:32:12 +0200 Subject: [PATCH 03/37] feat(print): respect page breaks --- src/public/stylesheets/style.css | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index fd4b1bf0b..df2c0b8f9 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -1655,4 +1655,14 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { contain: none !important; } + /* Respect page breaks */ + .page-break { + page-break-after: always; + break-after: always; + } + + .page-break > * { + display: none !important; + } + } \ No newline at end of file From d201fe7a063b4867d4c1ad1a317988633f996f37 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 20:40:11 +0200 Subject: [PATCH 04/37] fix(print): left padding of text notes --- src/public/stylesheets/style.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index df2c0b8f9..2c097f010 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -1627,6 +1627,10 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { overflow: auto; } + .note-detail-editable-text-editor { + padding: 0 !important; + } + html, body { height: unset !important; From 4a5bf28f06174c8183f2ec07a21900416aa42073 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 20:43:35 +0200 Subject: [PATCH 05/37] fix(print): remove title & reduce paddings --- src/public/stylesheets/style.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 2c097f010..6c47819eb 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -1611,6 +1611,7 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { #launcher-pane, #left-pane, #right-pane, + .title-row .note-icon-widget, .title-row .button-widget, .ribbon-container, .scroll-padding-widget, @@ -1627,6 +1628,8 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { overflow: auto; } + .note-title-widget input, + .note-detail-editable-text, .note-detail-editable-text-editor { padding: 0 !important; } From 561c50706eea1b1a4e78c25fe55dfa4d337fbfed Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 20:45:18 +0200 Subject: [PATCH 06/37] feat(print): carry over original print stylesheet --- src/public/stylesheets/print.css | 40 -------------------------------- src/public/stylesheets/style.css | 33 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/public/stylesheets/print.css b/src/public/stylesheets/print.css index d40396259..e69de29bb 100644 --- a/src/public/stylesheets/print.css +++ b/src/public/stylesheets/print.css @@ -1,40 +0,0 @@ -@media print { - html body { - /* https://github.com/zadam/trilium/issues/3202 */ - color: black; - } - - .no-print, - .no-print * { - display: none !important; - } - - .relation-map-wrapper { - height: 100vh !important; - } - - .table thead th, - .table td, - .table th { - /* Fix center vertical alignment of table cells */ - vertical-align: middle; - } - - pre { - box-shadow: unset !important; - border: 0.75pt solid gray !important; - border-radius: 2pt !important; - } - - span[style] { - print-color-adjust: exact; - -webkit-print-color-adjust: exact; - } - - /* Fix visibility of checkbox checkmarks - see https://github.com/TriliumNext/Notes/issues/901 */ - .ck-editor__editable.ck-content .todo-list .todo-list__label > span[contenteditable="false"] > input[checked]::after { - /* fallback to default ck-editor green */ - border-color: hsl(126, 64%, 41%); - } -} diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 6c47819eb..284e5afe3 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -1607,6 +1607,8 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { } @media print { + .no-print, + .no-print *, .tab-row-container, #launcher-pane, #left-pane, @@ -1639,6 +1641,8 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { height: unset !important; overflow: visible; position: unset; + /* https://github.com/zadam/trilium/issues/3202 */ + color: black; } #root-widget, @@ -1672,4 +1676,33 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { display: none !important; } + .relation-map-wrapper { + height: 100vh !important; + } + + .table thead th, + .table td, + .table th { + /* Fix center vertical alignment of table cells */ + vertical-align: middle; + } + + pre { + box-shadow: unset !important; + border: 0.75pt solid gray !important; + border-radius: 2pt !important; + } + + span[style] { + print-color-adjust: exact; + -webkit-print-color-adjust: exact; + } + + /* Fix visibility of checkbox checkmarks + see https://github.com/TriliumNext/Notes/issues/901 */ + .ck-editor__editable.ck-content .todo-list .todo-list__label > span[contenteditable="false"] > input[checked]::after { + /* fallback to default ck-editor green */ + border-color: hsl(126, 64%, 41%); + } + } \ No newline at end of file From 298634ceaa6b8c48e4237a2e12bc165e15154c1e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 20:47:18 +0200 Subject: [PATCH 07/37] refactor(print): use dedicated print CSS --- src/public/stylesheets/print.css | 97 +++++++++++++++++++++++++++++ src/public/stylesheets/style.css | 101 ------------------------------- src/views/desktop.ejs | 1 + src/views/mobile.ejs | 1 + 4 files changed, 99 insertions(+), 101 deletions(-) diff --git a/src/public/stylesheets/print.css b/src/public/stylesheets/print.css index e69de29bb..b02522d45 100644 --- a/src/public/stylesheets/print.css +++ b/src/public/stylesheets/print.css @@ -0,0 +1,97 @@ +.no-print, +.no-print *, +.tab-row-container, +#launcher-pane, +#left-pane, +#right-pane, +.title-row .note-icon-widget, +.title-row .button-widget, +.ribbon-container, +.scroll-padding-widget, +.spacer { + display: none !important; +} + +body, +#root-widget, +#rest-pane > div.component:first-child, +.note-detail-printable, +.note-detail-editable-text-editor { + height: unset !important; + overflow: auto; +} + +.note-title-widget input, +.note-detail-editable-text, +.note-detail-editable-text-editor { + padding: 0 !important; +} + +html, +body { + height: unset !important; + overflow: visible; + position: unset; + /* https://github.com/zadam/trilium/issues/3202 */ + color: black; +} + +#root-widget, +#horizontal-main-container, +#rest-pane, +#vertical-main-container, +#center-pane, +.split-note-container-widget, +.note-split:not(.hidden-ext) { + display: block !important; + overflow: auto; +} + +#rest-pane, +.note-split { + width: 100% !important; + max-width: unset !important; +} + +.component { + contain: none !important; +} + +/* Respect page breaks */ +.page-break { + page-break-after: always; + break-after: always; +} + +.page-break > * { + display: none !important; +} + +.relation-map-wrapper { + height: 100vh !important; +} + +.table thead th, +.table td, +.table th { + /* Fix center vertical alignment of table cells */ + vertical-align: middle; +} + +pre { + box-shadow: unset !important; + border: 0.75pt solid gray !important; + border-radius: 2pt !important; +} + +span[style] { + print-color-adjust: exact; + -webkit-print-color-adjust: exact; +} + +/* Fix visibility of checkbox checkmarks + see https://github.com/TriliumNext/Notes/issues/901 */ +.ck-editor__editable.ck-content .todo-list .todo-list__label > span[contenteditable="false"] > input[checked]::after { + /* fallback to default ck-editor green */ + border-color: hsl(126, 64%, 41%); +} \ No newline at end of file diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 284e5afe3..8f883d8ff 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -1604,105 +1604,4 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container { border-color: var(--hover-item-border-color); background: var(--hover-item-background-color); color: var(--hover-item-text-color); -} - -@media print { - .no-print, - .no-print *, - .tab-row-container, - #launcher-pane, - #left-pane, - #right-pane, - .title-row .note-icon-widget, - .title-row .button-widget, - .ribbon-container, - .scroll-padding-widget, - .spacer { - display: none !important; - } - - body, - #root-widget, - #rest-pane > div.component:first-child, - .note-detail-printable, - .note-detail-editable-text-editor { - height: unset !important; - overflow: auto; - } - - .note-title-widget input, - .note-detail-editable-text, - .note-detail-editable-text-editor { - padding: 0 !important; - } - - html, - body { - height: unset !important; - overflow: visible; - position: unset; - /* https://github.com/zadam/trilium/issues/3202 */ - color: black; - } - - #root-widget, - #horizontal-main-container, - #rest-pane, - #vertical-main-container, - #center-pane, - .split-note-container-widget, - .note-split:not(.hidden-ext) { - display: block !important; - overflow: auto; - } - - #rest-pane, - .note-split { - width: 100% !important; - max-width: unset !important; - } - - .component { - contain: none !important; - } - - /* Respect page breaks */ - .page-break { - page-break-after: always; - break-after: always; - } - - .page-break > * { - display: none !important; - } - - .relation-map-wrapper { - height: 100vh !important; - } - - .table thead th, - .table td, - .table th { - /* Fix center vertical alignment of table cells */ - vertical-align: middle; - } - - pre { - box-shadow: unset !important; - border: 0.75pt solid gray !important; - border-radius: 2pt !important; - } - - span[style] { - print-color-adjust: exact; - -webkit-print-color-adjust: exact; - } - - /* Fix visibility of checkbox checkmarks - see https://github.com/TriliumNext/Notes/issues/901 */ - .ck-editor__editable.ck-content .todo-list .todo-list__label > span[contenteditable="false"] > input[checked]::after { - /* fallback to default ck-editor green */ - border-color: hsl(126, 64%, 41%); - } - } \ No newline at end of file diff --git a/src/views/desktop.ejs b/src/views/desktop.ejs index aa325834d..da74e65c8 100644 --- a/src/views/desktop.ejs +++ b/src/views/desktop.ejs @@ -62,6 +62,7 @@ <% } %> + - - - -`, - importCSS: false, - loadCSS: cssToLoad, - debug: true - }); + window.print(); } async exportAsPdfEvent() { diff --git a/src/routes/assets.ts b/src/routes/assets.ts index c20c468d0..959de788b 100644 --- a/src/routes/assets.ts +++ b/src/routes/assets.ts @@ -66,8 +66,6 @@ async function register(app: express.Application) { app.use(`/${assetPath}/node_modules/jquery-hotkeys/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/jquery-hotkeys/"))); - app.use(`/${assetPath}/node_modules/print-this/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/print-this/"))); - app.use(`/${assetPath}/node_modules/split.js/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/split.js/dist/"))); app.use(`/${assetPath}/node_modules/panzoom/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/panzoom/dist/"))); From 8e88645fd3ceeb59d2d162eae86a8f55c6f1e1bb Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 1 Feb 2025 00:55:00 +0200 Subject: [PATCH 34/37] feat(print): hide placeholder if note is empty --- src/public/stylesheets/print.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/public/stylesheets/print.css b/src/public/stylesheets/print.css index 9dafa0980..49f4baa10 100644 --- a/src/public/stylesheets/print.css +++ b/src/public/stylesheets/print.css @@ -109,6 +109,7 @@ span[style] { outline: none !important; } +.ck-placeholder, .ck-widget__type-around, .ck-widget__selection-handle { display: none !important; From 6ad19198c63da204f1994094ce7bb8bab808699a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 1 Feb 2025 01:12:53 +0200 Subject: [PATCH 35/37] feat(print): improve on mobile --- src/public/stylesheets/print.css | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/public/stylesheets/print.css b/src/public/stylesheets/print.css index 49f4baa10..e6a5de316 100644 --- a/src/public/stylesheets/print.css +++ b/src/public/stylesheets/print.css @@ -1,5 +1,7 @@ :root { --main-background-color: white; + --root-background: var(--main-background-color); + --launcher-pane-background-color: var(--main-background-color); --main-text-color: black; --input-text-color: var(--main-text-color); } @@ -21,6 +23,20 @@ display: none !important; } +body.mobile #mobile-sidebar-wrapper, +body.mobile .classic-toolbar-widget, +body.mobile .action-button { + display: none !important; +} + +body.mobile #detail-container { + max-height: unset; +} + +body.mobile .note-title-widget { + padding: 0 !important; +} + body, #root-widget, #rest-pane > div.component:first-child, @@ -52,7 +68,8 @@ body { #vertical-main-container, #center-pane, .split-note-container-widget, -.note-split:not(.hidden-ext) { +.note-split:not(.hidden-ext), +body.mobile #mobile-rest-container { display: block !important; overflow: auto; border-radius: 0 !important; @@ -60,7 +77,8 @@ body { #center-pane, #rest-pane, -.note-split { +.note-split, +body.mobile #detail-container { width: unset !important; max-width: unset !important; } From 81755d804bc6dc0b7d744f9e220204e9b076e33a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 1 Feb 2025 01:16:35 +0200 Subject: [PATCH 36/37] feat(print): improve code notes --- src/public/stylesheets/print.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/public/stylesheets/print.css b/src/public/stylesheets/print.css index e6a5de316..34521d733 100644 --- a/src/public/stylesheets/print.css +++ b/src/public/stylesheets/print.css @@ -151,4 +151,12 @@ span[style] { .include-note .include-note-content { max-height: unset !important; overflow: unset !important; +} + +/* + * Code note specific fixes. + */ +.note-detail-code pre { + border: unset !important; + border-radius: unset !important; } \ No newline at end of file From bd363dac93d5db999393f425c4c7e268ef57de34 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 1 Feb 2025 01:21:38 +0200 Subject: [PATCH 37/37] chore(review): use async --- src/services/window.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/window.ts b/src/services/window.ts index 8927d9e7a..939ed0e90 100644 --- a/src/services/window.ts +++ b/src/services/window.ts @@ -1,4 +1,4 @@ -import fs from "fs"; +import fs from "fs/promises"; import path from "path"; import url from "url"; import port from "./port.js"; @@ -83,7 +83,7 @@ ipcMain.on("export-as-pdf", async (e, opts: ExportAsPdfOpts) => { } try { - fs.writeFileSync(filePath, buffer); + await fs.writeFile(filePath, buffer); } catch (e) { dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-save-message")); return;