Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/element-size

Package Overview
Dependencies
Maintainers
1
Versions
692
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/element-size - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

9

dist/index.d.ts

@@ -8,2 +8,9 @@ declare type ElementSize = {

export { ElementSize, ElementSizeCallback, trackElementSize };
declare type TrackElementsSizeOptions<T extends HTMLElement | null> = {
getNodes: () => T[];
observeMutation?: boolean;
callback: (size: ElementSize | undefined, index: number) => void;
};
declare function trackElementsSize<T extends HTMLElement | null>(options: TrackElementsSizeOptions<T>): () => void;
export { ElementSize, ElementSizeCallback, trackElementSize, trackElementsSize };

@@ -23,5 +23,8 @@ "use strict";

__export(src_exports, {
trackElementSize: () => trackElementSize
trackElementSize: () => trackElementSize,
trackElementsSize: () => trackElementsSize
});
module.exports = __toCommonJS(src_exports);
// src/track-size.ts
function trackElementSize(element, callback) {

@@ -54,5 +57,46 @@ if (!element) {

}
// src/track-sizes.ts
function trackElementsSize(options) {
const { getNodes, observeMutation = true, callback } = options;
const cleanups = [];
let firstNode = null;
function trigger() {
const elements = getNodes();
firstNode = elements[0];
const fns = elements.map(
(element, index) => trackElementSize(element, (size) => {
callback(size, index);
})
);
cleanups.push(...fns);
}
trigger();
if (observeMutation) {
const fn = trackMutation(firstNode, trigger);
cleanups.push(fn);
}
return () => {
cleanups.forEach((cleanup) => {
cleanup == null ? void 0 : cleanup();
});
};
}
function trackMutation(el, cb) {
var _a;
if (!el || !el.parentElement)
return;
const win = ((_a = el.ownerDocument) == null ? void 0 : _a.defaultView) ?? window;
const observer = new win.MutationObserver(() => {
cb();
});
observer.observe(el.parentElement, { childList: true });
return () => {
observer.disconnect();
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
trackElementSize
trackElementSize,
trackElementsSize
});

2

package.json
{
"name": "@zag-js/element-size",
"version": "0.1.1",
"version": "0.2.0",
"description": "Observer the size of an element over time",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc