Skip to content

Fix padding/border inset + empty annotation placeholder#38

Merged
flipbit merged 11 commits into
mainfrom
fix/padding-border-inset
Jun 22, 2026
Merged

Fix padding/border inset + empty annotation placeholder#38
flipbit merged 11 commits into
mainfrom
fix/padding-border-inset

Conversation

@flipbit

@flipbit flipbit commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Padding/border fix: Plugin now correctly handles images with CSS padding and/or border (e.g. Bootstrap's .img-thumbnail). Scale factors, overlay positioning, button placement, and drag containment all account for the image's content inset.
  • Empty annotation placeholder: Annotations with empty or whitespace-only text display "(no annotation)" in the tooltip. The underlying note data retains the original empty string for save/export.
  • Version bump: 2.0.0-beta.5

What changed

  • src/annotate-image.ts — Compute contentInset from image's computed padding+border; subtract from getBoundingClientRect() for scale, rescale, and flush paths; set --image-annotate-content-{side} CSS vars on canvas
  • src/annotation.css — Overlays use CSS vars for inset; button uses calc() for positioning
  • src/annotate-edit.ts — Containment changed from canvas to editOverlay (naturally bounded to content area)
  • src/annotate-view.ts — Show "(no annotation)" placeholder for empty text in tooltip
  • demo/scaling.html — New "Image with Padding & Border" demo section
  • test/ — 16 new unit tests (padding/border scale, CSS vars, rescale, asymmetric padding, empty text)
  • e2e/ — 4 new e2e tests for padded/bordered image annotations

Test plan

  • Unit tests: 351 passing (npm test)
  • E2e tests: 62 passing (npm run test:e2e)
  • Type-check clean (npm run build:check)
  • Build clean (npm run build)
  • Visual verification: open demo/scaling.html, scroll to "Image with Padding & Border" section
  • Verify annotations stay within content area, not shifted into padding/border zone
  • Verify empty annotation shows "(no annotation)" tooltip on hover

flipbit added 11 commits June 22, 2026 13:26
Subtract CSS padding and border from getBoundingClientRect() dimensions
so scaleX/scaleY reflect the actual image content area.
Add createPaddedTestImage test helper for padding/border testing.
When the image has padding/border, sets --image-annotate-content-{top,right,bottom,left}
on the canvas so overlays and button can be positioned within the content area.
Overlays use CSS var --image-annotate-content-{side} for inset
so they align with image content area. Button offsets adjusted similarly.
The editOverlay is inset to match the image content area, so using it
as the containment element prevents dragging into the padding zone.
The ResizeObserver callback and deferred rescale both receive canvas
dimensions (which include the image's padding/border). Subtract the
cached content insets to get the true content dimensions for scaling.
- Fix operator precedence bug: guard each parseFloat individually with
  || 0 to prevent NaN propagation when only padding or border is set
- Normalize CSS fallback values to 0px (was inconsistent 0 vs 0px)
- Add tests for asymmetric padding and padding-only (no border)
When annotation text is empty or whitespace-only, the tooltip displays
"(no annotation)" as a visual placeholder. The note data retains the
original empty string for export and save operations.
@flipbit
flipbit merged commit de5dc20 into main Jun 22, 2026
3 checks passed
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