UNPKG

eye-analysis

Version:

Eye Analysis - Browser-based eye tracking and screen recording library for research and experiments

128 lines (125 loc) 3.41 kB
var __defProp = Object.defineProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true, configurable: true, set: (newValue) => all[name] = () => newValue }); }; var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); // recorder/browser-info.ts var getBrowserWindowInfo = () => { return { innerWidth: window.innerWidth, innerHeight: window.innerHeight, scrollX: window.scrollX, scrollY: window.scrollY, devicePixelRatio: window.devicePixelRatio, screenX: window.screenX, screenY: window.screenY, outerWidth: window.outerWidth, outerHeight: window.outerHeight }; }, getScreenInfo = () => { return { width: screen.width, height: screen.height, availWidth: screen.availWidth, availHeight: screen.availHeight }; }, screenToWindowCoordinatesSync = (screenX, screenY, windowInfo) => { return { windowX: screenX - windowInfo.screenX, windowY: screenY - windowInfo.screenY }; }; // utils.ts var formatDuration = (seconds) => { const mins = Math.floor(seconds / 60); const secs = seconds % 60; return `${mins}:${secs.toString().padStart(2, "0")}`; }; var generateTimestamp = () => { return new Date().toLocaleTimeString(); }; var isValidWebSocketUrl = (url) => { if (!url || url.trim() === "") return false; try { const urlObj = new URL(url); return urlObj.protocol === "ws:" || urlObj.protocol === "wss:"; } catch { return false; } }; var generateSessionId = () => { const date = new Date; const dateStr = date.toISOString().split("T")[0]; const timeStr = date.getHours().toString().padStart(2, "0") + date.getMinutes().toString().padStart(2, "0"); const randomStr = Math.random().toString(36).substr(2, 6); return `session_${dateStr}_${timeStr}_${randomStr}`; }; var generateEventId = () => { return `event_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; }; var isValidParticipantId = (id) => { return id.trim().length > 0 && id.trim().length <= 100; }; var formatFileSize = (bytes) => { if (bytes === 0) return "0 B"; const k = 1024; const sizes = ["B", "KB", "MB", "GB"]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`; }; var deepClone = (obj) => { return JSON.parse(JSON.stringify(obj)); }; var throttle = (func, delay) => { let timeoutId = null; let lastExecTime = 0; return (...args) => { const currentTime = Date.now(); if (currentTime - lastExecTime > delay) { func(...args); lastExecTime = currentTime; } else { if (timeoutId) { clearTimeout(timeoutId); } timeoutId = setTimeout(() => { func(...args); lastExecTime = Date.now(); }, delay - (currentTime - lastExecTime)); } }; }; var debounce = (func, delay) => { let timeoutId = null; return (...args) => { if (timeoutId) { clearTimeout(timeoutId); } timeoutId = setTimeout(() => { func(...args); }, delay); }; }; export { throttle, isValidWebSocketUrl, isValidParticipantId, getScreenInfo, getBrowserWindowInfo, generateTimestamp, generateSessionId, generateEventId, formatFileSize, formatDuration, deepClone, debounce, screenToWindowCoordinatesSync as convertScreenToWindowCoordinates };