fix: map ink transparency to SVG opacity

This commit is contained in:
2026-07-22 19:46:40 +02:00
parent 3b1777a5b3
commit 239bb3c465
4 changed files with 32 additions and 3 deletions

View File

@@ -103,7 +103,7 @@ describe('OneNote export serializers', () => {
expect(document.querySelectorAll('svg.ink')).toHaveLength(1);
expect(
document.querySelector('polyline')?.getAttribute('stroke-opacity')
).toBe('0.496');
).toBe('0.498');
expect(
document
.querySelector('meta[http-equiv="Content-Security-Policy"]')
@@ -111,6 +111,30 @@ describe('OneNote export serializers', () => {
).toContain("default-src 'none'");
});
it('maps the full ink transparency byte range to SVG opacity', () => {
const snapshot = fixtureSnapshot();
const ink = snapshot.sections[0]!.pages[0]!.blocks.find(
(block) => block.kind === 'ink'
);
if (!ink || ink.kind !== 'ink') throw new Error('Ink fixture is missing');
ink.strokes[0]!.transparency = 0;
ink.strokes.push({
...ink.strokes[0]!,
points: ink.strokes[0]!.points.map((point) => ({ ...point })),
transparency: 255,
});
const document = new DOMParser().parseFromString(
serializeOneNoteSemanticHtml(snapshot),
'text/html'
);
expect(
[...document.querySelectorAll('polyline')].map((stroke) =>
stroke.getAttribute('stroke-opacity')
)
).toEqual(['1', '0']);
});
it('creates a deterministic, path-safe static notebook ZIP', () => {
const snapshot = fixtureSnapshot();
const first = createOneNoteStaticNotebookZip(snapshot);