Let the box editor panel be resized and its code scaled
Test and deploy / deploy (push) Successful in 32s
Test and deploy / test (push) Successful in 1m15s

Drag the panel's left edge (double-click to reset, arrow keys when
focused) to change its width; the canvas pads itself by the same width.
A−/A+ in the header, or Ctrl/Cmd +/-/0 in the editor, change the code's
text size. Both are remembered per browser in localStorage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-23 20:52:17 +01:00
co-authored by Claude Opus 5.5
parent 2eacbc2e33
commit e181aa09bd
5 changed files with 201 additions and 13 deletions
+47
View File
@@ -0,0 +1,47 @@
/**
* The box editor panel's size and its code's text size, shared between
* BoxEditor (which draws the panel and its controls) and BoxCanvas (which
* pads itself by the panel's width so the canvas rescales beside it rather
* than under it). They are one admin's preference for their own screen, so
* they live in localStorage, not the database.
*/
import { ref, watch } from "vue";
const KEY = "boxEditor";
export const PANEL_WIDTH = { min: 320, default: 460 };
export const FONT_SIZE = { min: 9, max: 24, default: 13 };
function load() {
try {
return JSON.parse(localStorage.getItem(KEY)) ?? {};
} catch {
return {}; // storage unavailable or corrupted: keep the defaults
}
}
const saved = load();
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
const valid = (n) => typeof n === "number" && Number.isFinite(n);
// Not clamped to the window here: the panel's CSS caps it with min(…, 100vw),
// so a width chosen on a wide monitor survives a visit from a narrow one.
export const panelWidth = ref(valid(saved.width) ? Math.max(PANEL_WIDTH.min, saved.width) : PANEL_WIDTH.default);
export const fontSize = ref(valid(saved.fontSize) ? clamp(saved.fontSize, FONT_SIZE.min, FONT_SIZE.max) : FONT_SIZE.default);
export function setPanelWidth(width) {
panelWidth.value = Math.round(clamp(width, PANEL_WIDTH.min, window.innerWidth));
}
/** Step the code's text size by `delta` px; 0 resets it. */
export function zoom(delta) {
fontSize.value = delta === 0 ? FONT_SIZE.default : clamp(fontSize.value + delta, FONT_SIZE.min, FONT_SIZE.max);
}
watch([panelWidth, fontSize], ([width, size]) => {
try {
localStorage.setItem(KEY, JSON.stringify({ width, fontSize: size }));
} catch {
/* storage unavailable: the preference just won't outlive the tab */
}
});