fix: report preview is always an A4 sheet, scaled to fit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b267b98f18
commit
f27d8441a9
2 files changed
+31
-7
No files matched your search
@@ -10,5 +10,7 @@
|
|||||||
.rpt-status { display: flex; gap: 10px; align-items: center; font-size: .8125rem; color: var(--ink-muted); }
|
.rpt-status { display: flex; gap: 10px; align-items: center; font-size: .8125rem; color: var(--ink-muted); }
|
||||||
.rpt-status[hidden] { display: none; }
|
.rpt-status[hidden] { display: none; }
|
||||||
.rpt-sheetwrap { background: var(--surface-sunken, rgba(127, 127, 127, .12)); border: 1px solid var(--line); border-radius: var(--radius, 10px); padding: clamp(6px, 2vw, 20px); min-width: 0; }
|
.rpt-sheetwrap { background: var(--surface-sunken, rgba(127, 127, 127, .12)); border: 1px solid var(--line); border-radius: var(--radius, 10px); padding: clamp(6px, 2vw, 20px); min-width: 0; }
|
||||||
.rpt-frame { display: block; width: 100%; max-width: 900px; height: calc(100vh - 220px); min-height: 520px; margin: 0 auto; border: 0; border-radius: 4px; background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }
|
.rpt-fit { position: relative; max-width: 794px; margin: 0 auto; overflow: hidden; }
|
||||||
@media (max-width: 600px) { .rpt-actions { margin-left: 0; width: 100%; } .rpt-actions .btn { flex: 1; } .rpt-frame { height: 75vh; min-height: 420px; } }
|
/* always an A4 sheet (794 px wide, the full report height); reports.js scales it to fit */
|
||||||
|
.rpt-frame { display: block; width: 794px; height: 1123px; border: 0; background: #fff; transform-origin: 0 0; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }
|
||||||
|
@media (max-width: 600px) { .rpt-actions { margin-left: 0; width: 100%; } .rpt-actions .btn { flex: 1; } }
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
var ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 3h7l5 5v13H7z"/><path d="M14 3v5h5M10 13h6M10 17h6"/></svg>';
|
var ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 3h7l5 5v13H7z"/><path d="M14 3v5h5M10 13h6M10 17h6"/></svg>';
|
||||||
var LANG_KEY = 'urutau.report.lang';
|
var LANG_KEY = 'urutau.report.lang';
|
||||||
|
var A4_PX = 794; // A4 width at 96 dpi: the preview is always an A4 sheet, scaled to fit
|
||||||
|
|
||||||
function boot() {
|
function boot() {
|
||||||
var U = window.Urutau;
|
var U = window.Urutau;
|
||||||
@@ -37,7 +38,21 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var t = U.t, el = U.el;
|
var t = U.t, el = U.el;
|
||||||
var ctx0 = null, root = null, frame = null, status = null, lang = '';
|
var ctx0 = null, root = null, frame = null, status = null, wrap = null, lang = '';
|
||||||
|
var docH = 1123;
|
||||||
|
|
||||||
|
// fit: the iframe keeps the A4 width (so the report never reflows to the
|
||||||
|
// screen) and is scaled down to the space available.
|
||||||
|
function fit() {
|
||||||
|
if (!frame || !wrap) return;
|
||||||
|
var avail = wrap.clientWidth;
|
||||||
|
var scale = Math.min(1, avail / A4_PX);
|
||||||
|
frame.style.width = A4_PX + 'px';
|
||||||
|
frame.style.height = docH + 'px';
|
||||||
|
frame.style.transform = 'scale(' + scale + ')';
|
||||||
|
wrap.style.height = Math.ceil(docH * scale) + 'px';
|
||||||
|
}
|
||||||
|
function onResize() { fit(); }
|
||||||
|
|
||||||
try { lang = localStorage.getItem(LANG_KEY) || ''; } catch (e) { lang = ''; }
|
try { lang = localStorage.getItem(LANG_KEY) || ''; } catch (e) { lang = ''; }
|
||||||
|
|
||||||
@@ -106,20 +121,27 @@
|
|||||||
frame = el('iframe', { class: 'rpt-frame', title: t('rpt.preview') });
|
frame = el('iframe', { class: 'rpt-frame', title: t('rpt.preview') });
|
||||||
frame.addEventListener('load', function () {
|
frame.addEventListener('load', function () {
|
||||||
var ok = false;
|
var ok = false;
|
||||||
try { ok = !!(frame.contentDocument && frame.contentDocument.querySelector('h1')); } catch (e) { ok = false; }
|
try {
|
||||||
|
var d = frame.contentDocument;
|
||||||
|
ok = !!(d && d.querySelector('h1'));
|
||||||
|
if (ok) docH = Math.max(d.documentElement.scrollHeight, d.body ? d.body.scrollHeight : 0, 1123);
|
||||||
|
} catch (e) { ok = false; }
|
||||||
|
fit();
|
||||||
showStatus(ok ? '' : 'rpt.err', !ok);
|
showStatus(ok ? '' : 'rpt.err', !ok);
|
||||||
});
|
});
|
||||||
root.appendChild(bar);
|
root.appendChild(bar);
|
||||||
root.appendChild(status);
|
root.appendChild(status);
|
||||||
root.appendChild(el('div', { class: 'rpt-sheetwrap' }, frame));
|
wrap = el('div', { class: 'rpt-fit' }, frame);
|
||||||
|
root.appendChild(el('div', { class: 'rpt-sheetwrap' }, wrap));
|
||||||
|
window.addEventListener('resize', onResize);
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
U.registerPage({
|
U.registerPage({
|
||||||
id: 'reports', group: 'reports', icon: ICON, titleKey: 'rpt.title',
|
id: 'reports', group: 'reports', icon: ICON, titleKey: 'rpt.title',
|
||||||
mount: function (host, c) { host.appendChild(build(c)); refresh(); },
|
mount: function (host, c) { host.appendChild(build(c)); fit(); refresh(); },
|
||||||
update: function (c) { ctx0 = c; refresh(); },
|
update: function (c) { ctx0 = c; refresh(); },
|
||||||
unmount: function () { if (root && root.parentNode) root.parentNode.removeChild(root); root = frame = status = null; }
|
unmount: function () { window.removeEventListener('resize', onResize); if (root && root.parentNode) root.parentNode.removeChild(root); root = frame = status = wrap = null; }
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user