test: harden visual resource rendering
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user