refactor(painters/dom): unify image block rendering (SD-2838)#3328
Open
luccas-harbour wants to merge 14 commits into
Open
refactor(painters/dom): unify image block rendering (SD-2838)#3328luccas-harbour wants to merge 14 commits into
luccas-harbour wants to merge 14 commits into
Conversation
Extract image <img> element creation, clip-path resolution, and hyperlink-anchor wrapping into shared helpers under `painters/dom/src/images/`, and route the renderer's block/drawing image paths plus renderTableCell's flowing, drawing, and anchored image paths through them. Eliminates five near-identical copies of the same img setup (objectFit, cover→left-top, clip-path, filters, hyperlink wrap) so behavior stays consistent across all image surfaces. Adds coverage for clip-path, filters, and hyperlinks on both flowing and anchored images inside table cells (SD-2838).
Removes the now-dead deriveBlockVersion machinery from renderer.ts (paragraph/image/drawing/table version hashing, SDT metadata helpers, list-marker guards) along with renderedBlockImageVersion in image-block.ts. No remaining call sites consume these helpers after the image-block rendering unification.
Move image fragment and drawing image creation out of renderer.ts into dedicated modules under images/. Renderer now delegates: - renderImageFragment → images/image-fragment.ts (with the buildImageGeometryTransform / applyImageGeometryTransform helpers it owned) - createDrawingImageElement, createShapeGroupImageElement, and the inline shape-text image element creation → images/drawing-image.ts No behavior change — pure extraction. Trims ~157 lines from renderer.ts.
Move image-clip-path and image-selectors (plus their tests) from utils/ into the images/ directory alongside image-block, drawing-image, hyperlink, and image-fragment. Update import paths in callers. No behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<img>creation, clip-path resolution, and hyperlink-anchor wrapping into shared helpers underpainters/dom/src/images/, and routes the renderer's block/drawing image paths plusrenderTableCell's flowing, drawing, and anchored image paths through them — eliminating five near-identical copies of the same setup (objectFit, cover→left-top, clip-path, filters, hyperlink wrap).image-clip-path,image-selectors) underimages/alongside the new modules and shares the inline-style applier + clip-path reader.deriveBlockVersion, and raw inline clip paths are hashed rather than dropped.deriveBlockVersion-on-render machinery (paragraph/image/drawing/table version hashing, SDT version helpers, list-marker guards) fromrenderer.tssince image-block rendering no longer derives its own per-block versions.AIDEV-NOTE(clip-path scaling stays on the<img>; rotation/flip stays on the fragment wrapper) so future edits don't collapse them onto the same element.Changes by area
painters/dom/src/images/(new)image-block.ts—createBlockImageContent(single source of truth for sizing, objectFit, clip-path, filters, hyperlink wrap) +resolveBlockImageClipPath.image-fragment.ts—renderImageFragment+buildImageGeometryTransform/applyImageGeometryTransform, lifted out ofrenderer.ts.drawing-image.ts—createDrawingImageElement,createShapeGroupImageElement,createShapeTextImageElement.hyperlink.ts— sharedbuildImageHyperlinkAnchor(sanitized href, target/rel, tooltip, role/tabindex, block vs inline-block display).types.ts— sharedBuildImageHyperlinkAnchoranchor type.image-clip-path.ts,image-selectors.ts— moved fromutils/.painters/dom/src/renderer.tsrenderImageFragmentis now a thin call intorenderImageFragmentElement.deriveBlockVersion, paragraph/cell-border hashing, SDT version helpers, list-marker guards,applyImageClipPath, andbuildImageFiltersimports (~530 lines net reduction in this file).painters/dom/src/table/renderTableCell.tscreateBlockImageContentwith a per-cellbuildImageHyperlinkAnchorbound to the cell's document.display: blockregardless ofblock.display(matches prior renderer behavior).layout-resolved/src/versionSignature.tsrenderedBlockImageVersion/renderedInlineImageRunVersioncapturing src/dims/alt/title/objectFit/display/filters/lum/rotation/flip/hyperlink/clip-path.clipPathon inline image runs is hashed instead of dropped; table cell signatures recurse into nested blocks viaderiveBlockVersion.Tests
images/image-block.test.ts—resolveBlockImageClipPathprecedence and unsupported-value handling; drawing image filters and hyperlink wrapping.table/renderTableCell.test.ts— flowing-image block display, clip-path containeroverflow: hidden, filters, and hyperlink anchors on both flowing and anchored images.layout-resolved/versionSignature.test.ts— coverage for the new image hashing paths.Why
Five copies of the img-setup logic had already drifted (e.g.,
objectPosition: left topforcoverwas missing from some paths, hyperlinks weren't wrapped in table cells, clip-path containeroverflow: hiddenwasn't always set). Centralizing prevents future drift and lets inline visual edits (hyperlink, luminance, gain/blacklevel, rotation, flip) invalidate caches reliably so re-renders pick them up.