Skip to content

Reactive DOMRectΒ #15176

@Azarattum

Description

@Azarattum

Describe the problem

DOMRect is a super convenient native API to represent rectangular shapes (not only DOM ones). I encountered a situation where I needed to create a reactive rect, but found out that it is missing from svelte/reactivity. I think it would be a really nice addition to the reactivity package.

Describe the proposed solution

It could look something like this:

import { SvelteDOMRect } from "svelte/reactivity";

const rect = new SvelteDOMRect();
$inspect(rect.left); // init 0; update 100
$inspect(rect.right); // init 0; update 200

setTimeout(() => {
  rect.x = 100;
  rect.width = 100;
});

If somebody from the maintainers approves this feature, I can make a PR.

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions