diff --git a/website/de/book/elements/typst.md b/website/de/book/elements/typst.md
index 6f492751..973256af 100644
--- a/website/de/book/elements/typst.md
+++ b/website/de/book/elements/typst.md
@@ -80,7 +80,7 @@ $ sum_(i=1)^n i = (n(n+1))/2 $
| Option | Beschreibung | Standard |
|--------|--------------|----------|
| `mode` | Anzeigemodus: `preview` (nur Ansicht) oder `edit` (mit Editor) | `preview` |
-| `height` | Höhe des Vorschau-Containers in Pixel | `400` |
+| `height` | Höhe des Vorschau-Containers. Akzeptiert CSS-Werte wie `100px`, `50vh`, `calc(100dvh - 200px)` | `auto` für preview, `calc(100dvh - 128px)` für edit |
| `src` | Pfad zu einer externen `.typ`-Datei | - |
### Laden aus externer Datei
diff --git a/website/en/book/elements/typst.md b/website/en/book/elements/typst.md
index 32184a13..41e884b1 100644
--- a/website/en/book/elements/typst.md
+++ b/website/en/book/elements/typst.md
@@ -80,7 +80,7 @@ $ sum_(i=1)^n i = (n(n+1))/2 $
| Option | Description | Default |
|--------|-------------|---------|
| `mode` | Display mode: `preview` (view only) or `edit` (with editor) | `preview` |
-| `height` | Height of the preview container in pixels | `400` |
+| `height` | Height of the preview container. Accepts CSS values like `100px`, `50vh`, `calc(100dvh - 200px)` | `auto` for preview, `calc(100dvh - 128px)` for edit |
| `src` | Path to an external `.typ` file to load | - |
### Loading from External File
From 6af02956a69bce4b64fa8a9a126230a850ecbbce Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 31 Dec 2025 16:33:09 +0000
Subject: [PATCH 8/8] Remove scaling feature and typst-preview box-shadow
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
---
.../markdown/assets/directive-typst/client.js | 93 +------------------
.../markdown/assets/directive-typst/style.css | 9 --
packages/markdown/locales/de.json | 6 +-
packages/markdown/locales/en.json | 6 +-
packages/markdown/src/remarkDirectiveTypst.ts | 58 +-----------
.../remarkDirectiveTypst.test.ts.snap | 6 +-
6 files changed, 10 insertions(+), 168 deletions(-)
diff --git a/packages/markdown/assets/directive-typst/client.js b/packages/markdown/assets/directive-typst/client.js
index 38e25d8e..17e1a2d3 100644
--- a/packages/markdown/assets/directive-typst/client.js
+++ b/packages/markdown/assets/directive-typst/client.js
@@ -57,11 +57,8 @@ hyperbook.typst = (function () {
return typstLoadPromise;
};
- // Store original SVG dimensions
- const svgOriginalDimensions = new Map();
-
// Render typst code to SVG
- const renderTypst = async (code, container, loadingIndicator, scaleState) => {
+ const renderTypst = async (code, container, loadingIndicator) => {
// Show loading indicator
if (loadingIndicator) {
loadingIndicator.style.display = "flex";
@@ -72,19 +69,6 @@ hyperbook.typst = (function () {
try {
const svg = await $typst.svg({ mainContent: code });
container.innerHTML = svg;
-
- // Store original dimensions and apply scale
- const svgElem = container.firstElementChild;
- if (svgElem) {
- const originalWidth = Number.parseFloat(svgElem.getAttribute("width"));
- const originalHeight = Number.parseFloat(svgElem.getAttribute("height"));
-
- // Store original dimensions
- svgOriginalDimensions.set(container, { width: originalWidth, height: originalHeight });
-
- // Apply current scale
- applyScale(container, scaleState);
- }
} catch (error) {
container.innerHTML = `
${error.message || "Error rendering Typst"}
`;
console.error("Typst rendering error:", error);
@@ -96,39 +80,6 @@ hyperbook.typst = (function () {
}
};
- // Apply scale to SVG
- const applyScale = (container, scaleState) => {
- const svgElem = container.firstElementChild;
- const original = svgOriginalDimensions.get(container);
-
- if (!svgElem || !original) return;
-
- const containerWidth = container.clientWidth - 32; // Account for padding
- const containerHeight = container.clientHeight - 32; // Account for padding
-
- let newWidth, newHeight;
-
- if (scaleState.mode === "fit-width") {
- // Fit to container width
- newWidth = containerWidth;
- newHeight = (original.height * containerWidth) / original.width;
- } else if (scaleState.mode === "full-page") {
- // Fit entire page in container without cut-offs
- const scaleX = containerWidth / original.width;
- const scaleY = containerHeight / original.height;
- const scale = Math.min(scaleX, scaleY);
- newWidth = original.width * scale;
- newHeight = original.height * scale;
- } else {
- // Manual scale
- newWidth = original.width * scaleState.scale;
- newHeight = original.height * scaleState.scale;
- }
-
- svgElem.setAttribute("width", newWidth);
- svgElem.setAttribute("height", newHeight);
- };
-
// Export to PDF
const exportPdf = async (code, id) => {
await loadTypst();
@@ -155,18 +106,8 @@ hyperbook.typst = (function () {
const downloadBtn = elem.querySelector(".download-pdf");
const copyBtn = elem.querySelector(".copy");
const resetBtn = elem.querySelector(".reset");
- const zoomInBtn = elem.querySelector(".zoom-in");
- const zoomOutBtn = elem.querySelector(".zoom-out");
- const fitWidthBtn = elem.querySelector(".fit-width");
- const fullPageBtn = elem.querySelector(".full-page");
const sourceTextarea = elem.querySelector(".typst-source");
- // Scale state for this element
- const scaleState = {
- scale: 1.0,
- mode: "fit-width" // "fit-width", "full-page", or "manual"
- };
-
// Get initial code
let initialCode = "";
if (editor) {
@@ -179,48 +120,22 @@ hyperbook.typst = (function () {
editor.value = result.code;
}
initialCode = editor.value;
- renderTypst(initialCode, preview, loadingIndicator, scaleState);
+ renderTypst(initialCode, preview, loadingIndicator);
// Listen for input changes
editor.addEventListener("input", () => {
store.typst?.put({ id, code: editor.value });
- renderTypst(editor.value, preview, loadingIndicator, scaleState);
+ renderTypst(editor.value, preview, loadingIndicator);
});
});
} else if (sourceTextarea) {
// Preview mode - code is in hidden textarea
initialCode = sourceTextarea.value;
loadTypst().then(() => {
- renderTypst(initialCode, preview, loadingIndicator, scaleState);
+ renderTypst(initialCode, preview, loadingIndicator);
});
}
- // Zoom in button
- zoomInBtn?.addEventListener("click", () => {
- scaleState.mode = "manual";
- scaleState.scale = Math.min(scaleState.scale + 0.25, 5.0);
- applyScale(preview, scaleState);
- });
-
- // Zoom out button
- zoomOutBtn?.addEventListener("click", () => {
- scaleState.mode = "manual";
- scaleState.scale = Math.max(scaleState.scale - 0.25, 0.25);
- applyScale(preview, scaleState);
- });
-
- // Fit width button
- fitWidthBtn?.addEventListener("click", () => {
- scaleState.mode = "fit-width";
- applyScale(preview, scaleState);
- });
-
- // Full page button
- fullPageBtn?.addEventListener("click", () => {
- scaleState.mode = "full-page";
- applyScale(preview, scaleState);
- });
-
// Download PDF button
downloadBtn?.addEventListener("click", async () => {
const code = editor ? editor.value : initialCode;
diff --git a/packages/markdown/assets/directive-typst/style.css b/packages/markdown/assets/directive-typst/style.css
index 703db173..e10a4455 100644
--- a/packages/markdown/assets/directive-typst/style.css
+++ b/packages/markdown/assets/directive-typst/style.css
@@ -39,7 +39,6 @@ code-input {
max-width: 100%;
height: auto;
border-radius: 8px;
- box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.16) 0px 3px 6px;
}
.directive-typst .typst-loading {
@@ -130,14 +129,6 @@ code-input {
cursor: pointer;
}
-.directive-typst button.zoom-in,
-.directive-typst button.zoom-out {
- flex: 0;
- min-width: 40px;
- font-weight: bold;
- font-size: 1.2em;
-}
-
.directive-typst button:last-child {
border-right: none;
}
diff --git a/packages/markdown/locales/de.json b/packages/markdown/locales/de.json
index 5d43fe66..b550e263 100644
--- a/packages/markdown/locales/de.json
+++ b/packages/markdown/locales/de.json
@@ -60,9 +60,5 @@
"typst-download-pdf": "PDF herunterladen",
"typst-pdf-error": "Fehler beim PDF-Export",
"typst-copy": "Kopieren",
- "typst-loading": "Typst wird geladen...",
- "typst-zoom-in": "+",
- "typst-zoom-out": "-",
- "typst-fit-width": "Breite anpassen",
- "typst-full-page": "Volle Seite"
+ "typst-loading": "Typst wird geladen..."
}
diff --git a/packages/markdown/locales/en.json b/packages/markdown/locales/en.json
index b72468be..d7b57b7a 100644
--- a/packages/markdown/locales/en.json
+++ b/packages/markdown/locales/en.json
@@ -60,9 +60,5 @@
"typst-download-pdf": "Download PDF",
"typst-pdf-error": "Error exporting PDF",
"typst-copy": "Copy",
- "typst-loading": "Loading Typst...",
- "typst-zoom-in": "+",
- "typst-zoom-out": "-",
- "typst-fit-width": "Fit Width",
- "typst-full-page": "Full Page"
+ "typst-loading": "Loading Typst..."
}
diff --git a/packages/markdown/src/remarkDirectiveTypst.ts b/packages/markdown/src/remarkDirectiveTypst.ts
index ab755a5d..6dfd8b84 100644
--- a/packages/markdown/src/remarkDirectiveTypst.ts
+++ b/packages/markdown/src/remarkDirectiveTypst.ts
@@ -151,62 +151,6 @@ export default (ctx: HyperbookContext) => () => {
],
};
- const zoomInButton: Element = {
- type: "element",
- tagName: "button",
- properties: {
- class: "zoom-in",
- },
- children: [
- {
- type: "text",
- value: i18n.get("typst-zoom-in"),
- },
- ],
- };
-
- const zoomOutButton: Element = {
- type: "element",
- tagName: "button",
- properties: {
- class: "zoom-out",
- },
- children: [
- {
- type: "text",
- value: i18n.get("typst-zoom-out"),
- },
- ],
- };
-
- const fitWidthButton: Element = {
- type: "element",
- tagName: "button",
- properties: {
- class: "fit-width",
- },
- children: [
- {
- type: "text",
- value: i18n.get("typst-fit-width"),
- },
- ],
- };
-
- const fullPageButton: Element = {
- type: "element",
- tagName: "button",
- properties: {
- class: "full-page",
- },
- children: [
- {
- type: "text",
- value: i18n.get("typst-full-page"),
- },
- ],
- };
-
if (isEditMode) {
// Edit mode: show editor and preview side by side
data.hChildren = [
@@ -292,7 +236,7 @@ export default (ctx: HyperbookContext) => () => {
properties: {
class: "buttons-container",
},
- children: [zoomOutButton, zoomInButton, fitWidthButton, fullPageButton, copyButton, downloadButton],
+ children: [copyButton, downloadButton],
},
{
type: "element",
diff --git a/packages/markdown/tests/__snapshots__/remarkDirectiveTypst.test.ts.snap b/packages/markdown/tests/__snapshots__/remarkDirectiveTypst.test.ts.snap
index 61e9cb72..eba39821 100644
--- a/packages/markdown/tests/__snapshots__/remarkDirectiveTypst.test.ts.snap
+++ b/packages/markdown/tests/__snapshots__/remarkDirectiveTypst.test.ts.snap
@@ -9,7 +9,7 @@ exports[`remarkDirectiveTypst > should default to preview mode 1`] = `