Skip to content

Fix Misaligned Annotation Rendering#8

Merged
thehabes merged 1 commit into
mainfrom
full-stack-issue7-f6ffa59
May 5, 2026
Merged

Fix Misaligned Annotation Rendering#8
thehabes merged 1 commit into
mainfrom
full-stack-issue7-f6ffa59

Conversation

@habesoftware-claude-connector
Copy link
Copy Markdown

@habesoftware-claude-connector habesoftware-claude-connector Bot commented May 5, 2026

Before

image

After

image

Summary

Fixes IIIFDataService.parseXYWH, which previously only handled selectors of the form xywh=pixel:x,y,w,h. Bare xywh=x,y,w,h (the W3C Media Fragments default, and what TPEN-Prompts emits) and URI-fragment forms like https://canvas.uri/#xywh=... produced NaN for x, causing every annotation overlay to render glued to the left edge of the canvas.

Replaces the brittle replace(...).split(",") parse with a regex that tolerates:

  • no prefix: xywh=100,200,300,400
  • pixel: prefix: xywh=pixel:100,200,300,400
  • pct: prefix: xywh=pct:10,20,30,40 (parsed, not yet converted to pixels — see Known Limitations)
  • URI fragments: https://canvas/#xywh=...
  • negative and decimal coordinates
  • null / undefined input (returns the zero box)

On no match, returns { x: 0, y: 0, w: 0, h: 0 } instead of propagating NaN into the DOM.

Closes

Files Changed

iiif-data-service.js | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

Known Limitations

  • pct: selectors are syntactically accepted but the values flow into ui-manager.js as if they were pixels, so a real percentage selector will render at the wrong location. Tracked separately — out of scope for this fix.
  • The numeric character class is [\d.]+, which would accept malformed tokens like 1.2.3 (yielding NaN). Considered acceptable for trusted IIIF input; can be tightened in a follow-up.

Generated via Full Stack Developer by HabeSoftware
@thehabes thehabes changed the title Implement #7 Fix Misaligned Annotation Rendering May 5, 2026
@thehabes thehabes self-assigned this May 5, 2026
@thehabes thehabes marked this pull request as ready for review May 5, 2026 17:51
@thehabes thehabes requested a review from cubap May 5, 2026 17:52
@thehabes thehabes temporarily deployed to github-pages May 5, 2026 17:59 — with GitHub Pages Inactive
@thehabes thehabes temporarily deployed to github-pages May 5, 2026 19:10 — with GitHub Pages Inactive
@thehabes thehabes merged commit ae3a86b into main May 5, 2026
6 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.

parseXYWH fails when selector omits 'pixel:' prefix — lines render at x=0

1 participant