elements-kit 0.27.9 → 0.27.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,19 +2,14 @@ import { r as MaybeReactive, t as Computed } from "../index-BSAqa0-0.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/utilities/element-rect.d.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* `target`'s bounding rect as one reactive `DOMRect`, every field from the
|
|
6
|
+
* same instant. Refreshed by a `ResizeObserver` (size) and capture-phase
|
|
7
|
+
* `scroll` / window `resize` (position), never on read. Size is the observer's
|
|
8
|
+
* border box, not the rect's: a transform scales the rect and never fires the
|
|
9
|
+
* observer.
|
|
10
10
|
*
|
|
11
|
-
* `target`
|
|
12
|
-
*
|
|
13
|
-
* keeps its identity across a swap, so consumers never rebind.
|
|
14
|
-
*
|
|
15
|
-
* The value is CACHED, not measured per read: it refreshes when one of the
|
|
16
|
-
* sources above fires, not at the moment you read it. Dispose explicitly, or
|
|
17
|
-
* let the enclosing scope do it.
|
|
11
|
+
* A reactive `target` is followed, keeping the computed's identity. Dispose
|
|
12
|
+
* explicitly, or let the enclosing scope do it.
|
|
18
13
|
*/
|
|
19
14
|
declare function createElementRect(target: MaybeReactive<Element>): Computed<DOMRect> & Disposable;
|
|
20
15
|
//#endregion
|
|
@@ -3,30 +3,38 @@ import { resolve } from "../signals/index.mjs";
|
|
|
3
3
|
import { createResizeObserver } from "./resize-observer.mjs";
|
|
4
4
|
//#region src/utilities/element-rect.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* `target`'s bounding rect as one reactive `DOMRect`, every field from the
|
|
7
|
+
* same instant. Refreshed by a `ResizeObserver` (size) and capture-phase
|
|
8
|
+
* `scroll` / window `resize` (position), never on read. Size is the observer's
|
|
9
|
+
* border box, not the rect's: a transform scales the rect and never fires the
|
|
10
|
+
* observer.
|
|
11
11
|
*
|
|
12
|
-
* `target`
|
|
13
|
-
*
|
|
14
|
-
* keeps its identity across a swap, so consumers never rebind.
|
|
15
|
-
*
|
|
16
|
-
* The value is CACHED, not measured per read: it refreshes when one of the
|
|
17
|
-
* sources above fires, not at the moment you read it. Dispose explicitly, or
|
|
18
|
-
* let the enclosing scope do it.
|
|
12
|
+
* A reactive `target` is followed, keeping the computed's identity. Dispose
|
|
13
|
+
* explicitly, or let the enclosing scope do it.
|
|
19
14
|
*/
|
|
20
15
|
function createElementRect(target) {
|
|
21
|
-
|
|
16
|
+
let size;
|
|
17
|
+
const read = (el) => {
|
|
18
|
+
const r = el.getBoundingClientRect();
|
|
19
|
+
return size ? new DOMRect(r.x, r.y, size.width, size.height) : r;
|
|
20
|
+
};
|
|
21
|
+
const cache = signal(read(resolve(target)));
|
|
22
22
|
const updateRect = (el) => {
|
|
23
|
-
cache(el
|
|
23
|
+
cache(read(el));
|
|
24
24
|
};
|
|
25
25
|
const stop = effectScope(() => {
|
|
26
26
|
effect(() => {
|
|
27
27
|
const el = resolve(target);
|
|
28
|
+
size = void 0;
|
|
28
29
|
createResizeObserver(el, (entries) => {
|
|
29
|
-
for (const entry of entries)
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
const box = entry.borderBoxSize?.[0];
|
|
32
|
+
if (box) size = {
|
|
33
|
+
width: box.inlineSize,
|
|
34
|
+
height: box.blockSize
|
|
35
|
+
};
|
|
36
|
+
updateRect(entry.target);
|
|
37
|
+
}
|
|
30
38
|
});
|
|
31
39
|
const remeasure = () => updateRect(el);
|
|
32
40
|
window.addEventListener("scroll", remeasure, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elements-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.27.
|
|
4
|
+
"version": "0.27.10",
|
|
5
5
|
"description": "A lightweight reactive UI library that transforms native HTMLElements into reactive components with signals. Ideal for framework-agnostic applications and web components.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webcomponents",
|