test: harden visual resource rendering

This commit is contained in:
2026-07-22 19:27:10 +02:00
parent eb15fecb3f
commit 268b7d01fd
3 changed files with 85 additions and 11 deletions

View File

@@ -94,11 +94,8 @@ const page: OneNotePageDto = {
describe('PageReader structured content', () => {
beforeEach(() => {
vi.stubGlobal('URL', {
...URL,
createObjectURL: vi.fn(() => 'blob:local-image'),
revokeObjectURL: vi.fn(),
});
vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:local-image');
vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined);
});
it('renders semantic formatting, links, tables, and a signed image resource', async () => {

View File

@@ -426,15 +426,20 @@ function ImageView({
function InkView({ ink }: { ink: OneNoteInkBlock }) {
const box = ink.boundingBox ?? boundingBoxFromInk(ink.strokes);
const padding = Math.max(
140,
...ink.strokes.map((stroke) => stroke.width ?? 0)
const widestStroke = ink.strokes.reduce(
(widest, stroke) => Math.max(widest, stroke.width ?? 0),
0
);
const padding = Math.max(140, Math.min(1_000_000, widestStroke));
const viewBox = box
? `${box.x - padding / 2} ${box.y - padding / 2} ${Math.max(box.width + padding, 1)} ${Math.max(box.height + padding, 1)}`
: '0 0 1 1';
const width = box ? Math.max((box.width + padding) / (2540 / 96), 1) : 1;
const height = box ? Math.max((box.height + padding) / (2540 / 96), 1) : 1;
const width = box
? Math.min(Math.max((box.width + padding) / (2540 / 96), 1), 10_000)
: 1;
const height = box
? Math.min(Math.max((box.height + padding) / (2540 / 96), 1), 10_000)
: 1;
return (
<div className="onenote-ink" style={layoutStyle(ink.layout)}>
@@ -452,7 +457,10 @@ function InkView({ ink }: { ink: OneNoteInkBlock }) {
d={inkPath(stroke)}
fill="none"
stroke={inkColor(stroke.color)}
strokeWidth={Math.max(stroke.width ?? 140, 1)}
strokeWidth={Math.min(
Math.max(stroke.width ?? 140, 1),
1_000_000
)}
strokeOpacity={
stroke.transparency === undefined
? undefined