Per-Diagram Default Zoom, Stored in a Data Attribute
Each diagram carries its initial zoom in a data-zoom attribute; a generic toolbar reads it once at init, no per-diagram branches.
TL;DR
A module map SVG kept loading at 100% zoom, forcing manual resizing, but a shared 50% default would break other drawings. The fix: the generator emits a data-zoom attribute per diagram, and the toolbar reads it to apply the right scale and width. This keeps content-specific defaults in the generator, not shared code, and extends to other initial states.
The generated manual closes with a module map: one SVG carrying nine cluster boxes, a label inside each. Opening the page on my laptop, I found it rendered at 100% zoom. The drawing spans the full content width and the labels inside the boxes are too small to read without leaning in.
Every session ended the same way. I dragged the zoom slider to half, read the map, and moved on. A reload put it back at 100%, and the next day I dragged the slider again.
The toolbar itself is fine. It carries a zoom slider and a Fit button, and both do what they say. The problem is only the value they start from: one shared default for drawings that do not share the same need.
My first guess was to change the toolbar default to 50% for all of them. I stopped before touching the code. The manual holds eight other drawings, including two ERDs, and there 100% is the correct starting point; shrinking those would make table fields unreadable for the sake of one map. So the default had to be per diagram, and the fact of what each drawing needs had to come from the generator.
A default as data, not code
The generator already knows the target file. A small map there assigns the initial zoom per output: peta-modul.svg gets 50, the other eight get 100. When the page is written, the generator emits data-zoom="50" only on the pre.mermaid wrapping the module map. The shared toolbar reads that value at init and applies it; nothing else in the toolbar changes.
MDN describes dataset as read and write access to custom data-* attributes on an element [1], with mechanical name conversion: data-abc-def becomes dataset.abcDef after the prefix drop and camel-casing. Those attributes exist to carry information between HTML and the DOM for scripts [2], which is exactly this case. The generator knows what the drawing needs, the page carries the fact, and the toolbar applies it.
const pre = document.querySelector('pre.mermaid');
const zoom = Number(pre.dataset.zoom ?? 100);
// konten di-scale, lebar container mengikuti zoom
pre.firstElementChild.style.transform = `scale(${zoom / 100})`;
pre.style.width = `${baseWidth * (zoom / 100)}px`;
The zoom is applied through the transform property. MDN lists transform as the way to rotate, scale, skew, or translate an element, with the functions composing left to right [3]. Scale alone would not be enough. I also set the container width, so horizontal scrolling keeps working at any zoom level, and the label size and SVG width follow immediately from those two lines.
Why not CSS, why not the toolbar
CSS cannot know which drawing it is styling. A branch inside the shared toolbar ("if this is the module map, use 50") moves content knowledge into shared code, and every new drawing with different needs reopens the toolbar file. With the attribute, the defaults stay in the same generator that writes the page. One place, no duplication.
The reader can still zoom or press Fit after load. The attribute only sets the initial state.
I verified the result in DevTools. The first drawing measures 993px wide at 100%. The module map shows 497px inside a 1022px container at 50%, and the third drawing is back at 100%. A quick check on your own build: inspect the pre and read dataset.zoom in the console. It should return 50 for the map and undefined for the rest, where the toolbar falls back to 100.
The pattern is not limited to zoom. Any per-item initial state that belongs to the content rather than the shared interface can travel the same way: which tab opens first, whether a panel starts collapsed, what volume a player loads with.
Sources
[1] MDN HTMLElement dataset, developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
[2] MDN data-* attributes, developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*
[3] MDN CSS transform, developer.mozilla.org/en-US/docs/Web/CSS/transform