Bihar Police Notebook displays A4 pages at their true print dimensions in the DOM, then applies a CSSDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/arverma/Bihar-Police-Notebook/llms.txt
Use this file to discover all available pages before exploring further.
transform: scale() to shrink or grow them visually to fit the available window width. The scale is purely cosmetic — all layout measurements, overflow detection, and print geometry operate on the original unscaled dimensions. The scaling system is implemented in editor/js/page-scale.js and editor/css/page-preview.css.
DOM Hierarchy
The scale mechanism operates on three nested elements:transform is applied to .editor-scale. Inner page elements always render at their true A4 pixel dimensions; only the containing scale element is transformed.
Why a separate .editor-scale wrapper?
Applying transform directly to .editor-stage would interfere with scroll geometry. The intermediate .editor-scale wrapper gives the scale system a clean target that does not affect the scroll container or the layout of sibling elements.
Scale Logic
initPageScale() in page-scale.js sets up the scale controller and returns a handle used by main.js.
Fit-to-Width Calculation
On everyrefresh() call the controller:
- Reads the available width of
.editor-stage(the scroll port). - Reads the natural rendered width of the
.editor-scaleelement (the A4 content width plus margins). - Computes
scale = stageWidth / contentWidth, clamped to a sensible range. - Sets
transform: scale(scale)andtransform-origin: top centeron.editor-scale.
Negative-Margin Collapse
A naive scale implementation would leave a gap equal to(1 - scale) * contentHeight below the scaled content — the DOM still reserves space for the unscaled dimensions. page-preview.css uses a negative bottom margin technique to collapse this surplus:
height: 0 clipping or absolute positioning because it allows multi-page diary layouts to flow naturally — no page is cut off mid-scroll.
The negative margin is recalculated after every
refresh() call so it stays accurate as the user resizes the window or adds diary pages.Behaviour by Device Class
- Desktop and Tablet (> 768 px)
- Mobile (≤ 768 px)
- Print
The page is automatically scaled to fill the available width. There is no manual zoom UI — fit-to-width is always maintained.
refresh() is called on:- Window resize (via
ResizeObserveron.editor-stage) - Template switch (
switchTemplate) - Document load (
loadDocumentState) - New document creation (
startNewDocument) onPageFocuscallback (when the diary adds a page)
pageScale.getScale() so the transliteration suggestion popup (showSuggestions) can offset its coordinates correctly.API
initPageScale()
ResizeObserver to .editor-stage and calls refresh() on the first available animation frame. Returns a controller object.
Returned controller:
Recomputes and applies the fit-to-width scale immediately. Call this after any layout change that affects the page content area (template switch, page add/delete, document load).
Returns the current numeric scale factor (e.g.
0.72 for 72 % scale). Used by the transliteration popup to convert element-relative coordinates to viewport coordinates.CSS Files
| File | Scope |
|---|---|
page-preview.css | .editor-scale transform and negative-margin rules, @media print reset, Fit chip styles, mobile pinch-zoom touch-action rules |
page-scale.js | Runtime scale computation, ResizeObserver wiring, pinch/double-tap event handlers |