@zag-js/dom-query
Version:
The dom helper library for zag.js machines
96 lines (94 loc) • 2.8 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
// src/raf.ts
var raf_exports = {};
__export(raf_exports, {
AnimationFrame: () => AnimationFrame,
nextTick: () => nextTick,
queueBeforeEvent: () => queueBeforeEvent,
raf: () => raf
});
module.exports = __toCommonJS(raf_exports);
var AnimationFrame = class _AnimationFrame {
constructor() {
__publicField(this, "id", null);
__publicField(this, "fn_cleanup");
__publicField(this, "cleanup", () => {
this.cancel();
});
}
static create() {
return new _AnimationFrame();
}
request(fn) {
this.cancel();
this.id = globalThis.requestAnimationFrame(() => {
this.id = null;
this.fn_cleanup = fn?.();
});
}
cancel() {
if (this.id !== null) {
globalThis.cancelAnimationFrame(this.id);
this.id = null;
}
this.fn_cleanup?.();
this.fn_cleanup = void 0;
}
isActive() {
return this.id !== null;
}
};
function raf(fn) {
const frame = AnimationFrame.create();
frame.request(fn);
return frame.cleanup;
}
function nextTick(fn) {
const set = /* @__PURE__ */ new Set();
function raf2(fn2) {
const id = globalThis.requestAnimationFrame(fn2);
set.add(() => globalThis.cancelAnimationFrame(id));
}
raf2(() => raf2(fn));
return function cleanup() {
set.forEach((fn2) => fn2());
};
}
function queueBeforeEvent(el, type, cb) {
const cancelTimer = raf(() => {
el.removeEventListener(type, exec, true);
cb();
});
const exec = () => {
cancelTimer();
cb();
};
el.addEventListener(type, exec, { once: true, capture: true });
return cancelTimer;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AnimationFrame,
nextTick,
queueBeforeEvent,
raf
});