Skip to content

feat(web): add display-only El::web_image for cross-origin raster images - #2637

Merged
Hona merged 1 commit into
devfrom
feat/web-image-display-only
Nov 27, 2026
Merged

Hona merged 1 commit into
devfrom
feat/web-image-display-only

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Summary

Adds opt-in display-only El::web_image and El::web_image_fit so Rune apps on web can display cross-origin raster images whose servers omit CORS headers, without reading pixels or bypassing browser cross-origin restrictions.

  • Opt-in API (crates/rune/src/web_image.rs): El::web_image(url) and El::web_image_fit(url, fit) accept validated http:, https:, and relative URLs (rejecting javascript:, mailto:, file:, data:, and scheme-relative //...), combine with El::radius, El::corners, El::border, El::fill (drawn underneath on canvas as a loading/error/transparency backdrop), El::opacity, El::layer_opacity, El::rotate, El::surface_anchor, El::surface_unscaled, and El::image_filter(ImageFilter::Nearest).
  • Per-frame collection & clipping (crates/rune/src/runtime/paint/web_image.rs): Records visible WebImageDraw entries in CSS pixels on every built frame (bypassing PaintKeep and El::cache() elision), inset inside visible borders, with exact rectangular clips, enclosing rounded clips (El::clip_rounded / El::clip_corners), rotated 2D CSS affine matrices, UI zoom, and App::web_document document coordinates. Also emits <img> in --html static export and exposes Runtime::web_images() for inspection and tests.
  • Browser DOM layer (crates/rune/src/platform/web/bridge.js, web_images.rs): Lazily mounts [data-rune-web-images] above the canvas and directly before [data-rune-a11y] (pointer-events: none, aria-hidden="true", never setting crossOrigin), reuses <img> elements by stable NodeId across scroll/animation/clip changes without reassigning src, nests clip wrappers, follows App::web_document height and mobile keyboard shift, and cleans up on empty sync or destroy.
  • Documented trade-off (WEB.md): Existing ImageCache::url + El::pixels is unchanged; because the DOM <img> layer sits above the canvas, canvas-drawn popovers/overlays and shaders cannot composite over a web_image.

Fixes #1667

Verification

  • cargo test -p rune web_image (7 passed)
  • cargo test -p rune --lib export::tests (13 passed)
  • cargo check-wasm (WebGPU wasm32-unknown-unknown) and cargo check-webgl (WebGL2 wasm32-unknown-unknown)
  • node --test crates/rune/src/platform/web/bridge.test.mjs (80 passed, including new syncWebImages DOM/clip/reuse/document-mode tests)
  • Not run locally: live browser verification against a real cross-origin HTTP image server without Access-Control-Allow-Origin.

@Hona
Hona force-pushed the feat/web-image-display-only branch from 0a0a6f9 to 7e7b206 Compare November 27, 2026 15:18
@Hona
Hona merged commit d95e83a into dev Nov 27, 2026
@Hona
Hona deleted the feat/web-image-display-only branch November 27, 2026 15:18
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.

Web: display cross-origin raster images without pixel access

1 participant