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
fix(presentation): size desktop web view slides from Reveal.js's scale
Elian Doran37df86f96ba7
diff --git a/apps/client/src/widgets/collections/presentation/index.spec.ts b/apps/client/src/widgets/collections/presentation/index.spec.tsindex 6357ed49ac..e05ce55200 100644--- a/apps/client/src/widgets/collections/presentation/index.spec.ts+++ b/apps/client/src/widgets/collections/presentation/index.spec.ts@@ -1,6 +1,6 @@import { describe, expect, it, vi } from "vitest";-import { createFitObserver, fitSlideContent, setViewportSize } from "./index";+import { createFitObserver, fitSlideContent } from "./index";describe("fitSlideContent", () => {it("zooms out only the content that is larger than the slide", () => {@@ -35,24 +35,6 @@ describe("fitSlideContent", () => {});});-describe("setViewportSize", () => {- it("sizes the viewport in slide pixels from the scale that Reveal.js applied", () => {- const container = document.createElement("div");- // offsetHeight would round this to 619.- container.getBoundingClientRect = () => ({ width: 1100, height: 618.75 }) as DOMRect;-- // 1100px less the 4% margin gives a scale of 0.825, which Reveal.js rounds to 0.83.- setViewportSize(container, { getScale: () => 0.83 });- expect(parseFloat(container.style.getPropertyValue("--viewport-width"))).toBeCloseTo(1100 / 0.83);- expect(parseFloat(container.style.getPropertyValue("--viewport-height"))).toBeCloseTo(618.75 / 0.83);-- // Before the first layout there is no scale yet, and the CSS fallbacks stay.- const unscaled = document.createElement("div");- setViewportSize(unscaled, { getScale: () => 0 });- expect(unscaled.style.getPropertyValue("--viewport-width")).toBe("");- });-});-describe("createFitObserver", () => {it("fits again when the size changes, but not for the size its own fit leaves", () => {let notify: ResizeObserverCallback = () => {};diff --git a/apps/client/src/widgets/collections/presentation/index.tsx b/apps/client/src/widgets/collections/presentation/index.tsxindex 7e5def3a6b..b594d130d7 100644--- a/apps/client/src/widgets/collections/presentation/index.tsx+++ b/apps/client/src/widgets/collections/presentation/index.tsx@@ -264,14 +264,11 @@ function Presentation({ presentation, setApi, ntxId, editedNoteId, onEditSlide,setRevealApi(api);setApi(api);rewireLinks(container, api);- setViewportSize(container, api);});// Reveal.js listens only to window resizes, not to the note pane changing size.const resizeObserver = new ResizeObserver(() => {- if (!api.isReady()) return;- api.layout();- setViewportSize(container, api);+ if (api.isReady()) api.layout();});resizeObserver.observe(container);@@ -434,20 +431,6 @@ function getNoteIdFromSlide(slide: HTMLElement | undefined) {return slide.dataset.noteId;}-/**- * Sets `--viewport-width` and `--viewport-height` on the `.reveal` element to its size in slide pixels.- * Reveal.js fits the slide inside a margin and rounds the scale, so this is what a `<webview>` takes to- * cover the whole viewport, as a background iframe does.- */-export function setViewportSize(container: HTMLElement, api: Pick<RevealApi, "getScale">) {- const scale = api.getScale();- if (!scale) return;- // `offsetWidth` and `offsetHeight` round to whole pixels, which can leave a sub-pixel seam at the edges.- const { width, height } = container.getBoundingClientRect();- container.style.setProperty("--viewport-width", `${width / scale}px`);- container.style.setProperty("--viewport-height", `${height / scale}px`);-}-function rewireLinks(container: HTMLElement, api: RevealApi) {const links = container.querySelectorAll<HTMLLinkElement>("a.reference-link");for (const link of links) {diff --git a/apps/client/src/widgets/collections/presentation/slidejs.css b/apps/client/src/widgets/collections/presentation/slidejs.cssindex 37e781babb..f49fa095af 100644--- a/apps/client/src/widgets/collections/presentation/slidejs.css+++ b/apps/client/src/widgets/collections/presentation/slidejs.css@@ -148,7 +148,7 @@ footer.file-footer {position: absolute;top: 50%;left: 50%;- width: calc(var(--viewport-width, 100%) + 2px);- height: calc(var(--viewport-height, 100cqh) + 2px);+ width: calc(var(--viewport-width, 1280px) / var(--slide-scale, 1) + 2px);+ height: calc(var(--viewport-height, 720px) / var(--slide-scale, 1) + 2px);transform: translate(-50%, -50%);}\ No newline at end of file