Skip to content

fix(preview): render translucent solid fills and outlines - #301

Merged
baseballyama merged 1 commit into
mainfrom
fix/preview-fill-alpha
Sep 13, 2026
Merged

baseballyama merged 1 commit into
mainfrom
fix/preview-fill-alpha

Conversation

@baseballyama

Copy link
Copy Markdown
Collaborator

Summary

Solid fills and outlines whose color carries <a:alpha> / <a:alphaMod> / <a:alphaOff> now render with the matching fill-opacity / stroke-opacity in @office-kit/pptx-preview, and @office-kit/pptx exposes the opacity through resolveDrawingColorOpacity, getShapeFillOpacity, and getShapeStrokeOpacity. A translucent shape layered over layout artwork previously painted as an opaque block and hid the gradient or slide background beneath it.

Motivation

Corporate slide templates commonly stack a semi-transparent "veil" shape on the slide layout over a gradient. The color transform parser already recognised the alpha children (and deliberately left the RGB untouched), but nothing surfaced the value, so the preview painted the veil at 100% and the slide looked nothing like PowerPoint or LibreOffice. Found while previewing such a template; opened without an issue because the fix is small and self-contained.

Changes

  • @office-kit/pptx: new exports resolveDrawingColorOpacity(colorEl), getShapeFillOpacity(shape), getShapeStrokeOpacity(shape) (0–1 fraction, null when no alpha transform is present, mirroring getShapeImageOpacity). getShapeFillColorResolved / getShapeStrokeColorResolved are unchanged and still return the plain #RRGGBB.
  • @office-kit/pptx-preview: emits fill-opacity on solid fills (preset geometry and custom geometry paths) and stroke-opacity on solid outlines, for slide shapes and for artwork inherited from layouts / masters. Peer dependency on @office-kit/pptx raised to >=0.13.0.
  • Changeset: @office-kit/pptx minor, @office-kit/pptx-preview patch.

Testing

  • New unit tests: test/fn-resolve-drawing-color.test.ts (alpha / alphaMod / alphaOff order, clamping, bare-float values) and test/fn-shape-fill-opacity.test.ts (fill and outline read independently; color readers stay alpha-free).
  • New renderer tests in test/preview-effects-fills.test.ts: a slide shape with 27% fill / 50% outline alpha, and a layout-level translucent shape over the Blank layout.
  • Full suite: pnpm test → 313 files, 1334 tests passed. pnpm format:check, pnpm lint, pnpm typecheck, pnpm build, and the preview package's typecheck / build pass.
  • Manual: rendered a real template's agenda slide before and after; the fixed SVG now shows the gradient through the veil and matches the LibreOffice rasterisation.

Breaking changes

None. Consumers of @office-kit/pptx-preview need @office-kit/pptx >= 0.13.0 because the renderer imports the new readers.

Checklist

  • I have read CLAUDE.md and followed the project's conventions.
  • I have added or updated tests for the change.
  • I have added or updated documentation where user-visible behavior changed.
  • If this is a breaking change, I have added a changeset / CHANGELOG entry and
    flagged it above.
  • I have re-read my own diff and removed dead code, debug prints, and stale comments.
  • If I used an LLM to draft this PR, I have verified each change myself, the PR
    represents real work that warrants a maintainer's review, and I am willing to
    defend each line in review.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GvR7C4YF5qxjGtn3bnbG3i

`<a:alpha>` / `<a:alphaMod>` / `<a:alphaOff>` on a solid fill or outline
color were parsed but never surfaced, so a semi-transparent shape laid
over layout artwork rendered as an opaque block that hid the gradient
(or slide background) beneath it. OOXML keeps alpha beside the color
rather than inside it, so the resolved `#RRGGBB` stays as is and the
opacity is exposed through new readers (`resolveDrawingColorOpacity`,
`getShapeFillOpacity`, `getShapeStrokeOpacity`); the preview renderer
emits `fill-opacity` / `stroke-opacity` from them, including for the
custom-geometry path, which previously dropped extra attributes when a
path had no stroke.
@baseballyama
baseballyama merged commit 104f7d2 into main Sep 13, 2026
8 checks passed
@baseballyama
baseballyama deleted the fix/preview-fill-alpha branch September 13, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant