import { getDifference as e } from "../utils/objects.js";
//#region src/internal/controllers/type-touch.controller.ts
var t = class extends Event {
	constructor(e, t) {
		super(e), this.x = t.x, this.y = t.y, this.offsetX = t.offsetX, this.offsetY = t.offsetY;
	}
};
function n() {
	return (e) => e.addInitializer((e) => new r(e));
}
var r = class {
	#e;
	#t;
	constructor(e) {
		this.host = e, this.host.addController(this);
	}
	hostConnected() {
		this.host.addEventListener("pointerdown", this.#n);
	}
	hostDisconnected() {
		this.host.removeEventListener("pointerdown", this.#n), globalThis.document.removeEventListener("pointerup", this.#i), globalThis.document.removeEventListener("pointermove", this.#r);
	}
	#n = (e) => {
		e.composedPath().find((e) => e === this.host) && (this.#e = {
			x: e.clientX,
			y: e.clientY
		}, this.#t = e.pointerId, this.host.setPointerCapture(this.#t), globalThis.document.addEventListener("pointerup", this.#i), globalThis.document.addEventListener("pointermove", this.#r), this.host.dispatchEvent(new t("nve-touch-start", {
			...this.#e,
			offsetX: 0,
			offsetY: 0
		})));
	};
	#r = (e) => {
		requestAnimationFrame(() => {
			let n = this.#a(e);
			this.host.dispatchEvent(new t("nve-touch-move", n)), this.#e = {
				x: e.clientX,
				y: e.clientY
			};
		});
	};
	#i = (e) => {
		/* istanbul ignore else -- #start registers #end only after setting #startPosition. */
		this.#e && (globalThis.document.removeEventListener("pointerup", this.#i, !1), globalThis.document.removeEventListener("pointermove", this.#r, !1), this.host.dispatchEvent(new t("nve-touch-end", this.#a(e))), this.host.releasePointerCapture(this.#t), this.#t = null);
	};
	#a(t) {
		return {
			offsetX: e(this.#e.x, t.clientX),
			offsetY: e(this.#e.y, t.clientY),
			x: t.clientX,
			y: t.clientY
		};
	}
};
//#endregion
export { t as NveTouchEvent, r as TypeTouchController, n as typeTouch };

//# sourceMappingURL=type-touch.controller.js.map