Skip to content

fix: center gallery preview cards and add Image Occlusion fallback#2486

Merged
aalemayhu merged 1 commit into
mainfrom
fix/templates-card-centering
May 20, 2026
Merged

fix: center gallery preview cards and add Image Occlusion fallback#2486
aalemayhu merged 1 commit into
mainfrom
fix/templates-card-centering

Conversation

@aalemayhu
Copy link
Copy Markdown
Contributor

@aalemayhu aalemayhu commented May 20, 2026

Summary

Four gallery polish issues from the latest review.

1. Default-center .card content

Templates without their own `.card` display rules (Default, Only Notion, Raw Note, Minimal, parts of user-saved defaults) rendered short text in the top-left, leaving 70%+ of the thumbnail blank.

Wrapper now adds `display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; text-align: center` on `body > .card` as a default. Templates that set their own `.card` display (Quote, Vocabulary, Modern Cloze, Code Card, etc.) keep their own layout because their declarations are equally specific and come later in the cascade.

2. Inert form fields

Default (Type the answer) renders an `` in the qfmt; in the preview it became a focusable text box that looked broken at thumbnail scale. `input, button, select, textarea { pointer-events: none }` in the wrapper — they still render as styled elements but can't be focused.

3. Image Occlusion fallback

The canvas + script Anki uses to draw masks can't run in `sandbox=""`. The thumbnail was always blank except for the Header text. Hide `#image-occlusion-canvas` and inject "Image occlusion preview — install in Anki to see masks" via `::after` on the container.

4. Background defaults (still in place from #2484)

White card behind every template that doesn't set its own background — Raw Note included.

Test plan

  • `pnpm --filter 2anki-web vitest run src/pages/TemplatesPage` — 44 tests pass
  • `pnpm --filter 2anki-web typecheck` clean
  • `pnpm --filter 2anki-web lint` clean
  • After deploy: hard-refresh `/templates`, confirm Default Basic/Cloze/Type-the-answer + Only Notion + Raw Note + Minimal now center their content vertically, and Image Occlusion shows the fallback message instead of a blank canvas

🤖 Generated with Claude Code


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Four gallery polish issues from the latest review.

1. Default-center .card content. Templates without their own .card
display rules (Default, Only Notion, Raw Note, Minimal, plus parts of
the user-saved defaults) rendered short text in the top-left and left
70%+ of the thumbnail blank. Wrapper now sets
display: flex; flex-direction: column; align-items: center;
justify-content: center; padding: 16px; text-align: center on
body > .card as a default. Templates that set their own .card
display (Quote, Vocabulary, Modern Cloze, Code Card, etc.) keep their
own layout because they're equally specific and come later in the
cascade.

2. Pointer-events off on form fields. Default (Type the answer)
includes <input> in the qfmt; in the preview it was rendering as a
focusable text box that looked broken at thumbnail scale. input,
button, select, textarea now have pointer-events: none in the
wrapper — they still render as styled elements but can't be focused.

3. Image Occlusion fallback. The canvas + script that Anki uses to
draw masks can't run in sandbox=""; the thumbnail was always blank
except for the Header text. Hide #image-occlusion-canvas via CSS and
inject a "install in Anki to see masks" message via ::after on the
container.

4. Background defaults stay (from #2484). White card behind every
template that doesn't set its own — Raw Note included.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@aalemayhu aalemayhu merged commit 97b981e into main May 20, 2026
5 checks passed
@aalemayhu aalemayhu deleted the fix/templates-card-centering branch May 20, 2026 13:36
@netlify
Copy link
Copy Markdown

netlify Bot commented May 20, 2026

Deploy Preview for notion2anki ready!

Name Link
🔨 Latest commit 67aa783
🔍 Latest deploy log https://app.netlify.com/projects/notion2anki/deploys/6a0db8cf024194000850a0ba
😎 Deploy Preview https://deploy-preview-2486--notion2anki.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sonarqubecloud
Copy link
Copy Markdown

aalemayhu added a commit that referenced this pull request May 20, 2026
#2487)

## Summary

The previous fix (#2486) added \`body > .card { display: flex; ...
padding: 16px; text-align: center }\` to the iframe wrapper. That
selector is specificity 0,1,1 — higher than templates' own \`.card { ...
}\` (0,1,0) — so it stomped every template that had its own centering
and padding.

### Visible breakage

- **Live editor preview broken**: \`/templates/edit/vocab-language\` no
longer centers because Vocabulary's \`.card { display: flex;
align-items: center; padding: 32px 24px }\` was overridden by my
wrapper.
- **Clean Basic** gallery thumbnail clipped the \`?\` from "What is the
capital of France?" on the right edge (16px padding ate into the content
area while the template's font size still assumed 800px internal).
- **Alexander Deluxe (Blue)** wrapped onto a second line that clipped at
the bottom; **(Blue — Cloze)** lost the leading "The".

## What changes

One line in \`renderNoteTypePreview.ts\`: wrap the default \`.card\`
layout rule in \`:where(body > .card)\` (specificity drops to 0,0,0).
Templates' own \`.card\` rules now always win. Templates without a
\`.card\` display rule (Default, Only Notion, Raw Note, Minimal) still
get flex-column centering as the fallback. Padding removed — that's the
template's call.

## Test plan

- [x] \`pnpm --filter 2anki-web vitest run src/pages/TemplatesPage\` —
44 tests pass
- [x] \`pnpm --filter 2anki-web typecheck\` clean
- [x] \`pnpm --filter 2anki-web lint\` clean
- [ ] After deploy: \`/templates/edit/vocab-language\` shows Vocab
centered again
- [ ] After deploy: Clean Basic + Alexander Deluxe text no longer clips
at edges

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- codesmith:footer -->
---
<a
href="https://app.blacksmith.sh/2anki/codesmith/server/pr/2487"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-in-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-in-codesmith-light.svg"><img
alt="View in Codesmith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/view-in-codesmith-dark.svg"></picture></a>
<sup>Need help on this PR? Tag <code>@codesmith</code> with what you
need.</sup>

- [ ] Let Codesmith autofix CI failures and bot reviews
<!-- /codesmith:footer -->

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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