Files
Pulse Agent 0889ee9117 feat(lib): add useLiveStream WS hook + useLiveMetrics + LiveMetricChart
feat(hooks): add useLiveStream generic WebSocket hook
  - supports websocket/sse/polling transports
  - exponential backoff reconnect with jitter
  - circular buffer with configurable size
  - typed filter callback per use case
  - manual disconnect + reconnect + error state

feat(hooks): add useLiveMetrics derived hook
  - sliding time-window cut
  - moving average (configurable window)
  - current / avg / min / max / ratePerSecond
  - zero allocations per tick (memoized)

feat(charts): add LiveMetricChart molecule (Recharts)
  - line + area variants, grid + tooltip
  - moving-average overlay (dashed)
  - ConnectionStatus atom in header
  - status bar + compact mode
  - 100% responsive, GPU via SVG ViewBox

feat(atoms): add ConnectionStatus indicator
  - 5 states: disconnected/connecting/connected/reconnecting/error
  - animated pulse, JetBrains Mono, pill style
  - exported helpers: formatLatency / formatBytes

docs(pkg): bump v0.1.0 → v0.2.0, add recharts peerDep
2026-05-20 22:59:10 -03:00

150 lines
4.8 KiB
JavaScript
Executable File

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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);
// src/utils/index.ts
var utils_exports = {};
__export(utils_exports, {
arr: () => arr,
cn: () => cn,
date: () => date,
debounce: () => debounce,
num: () => num,
obj: () => obj,
storage: () => storage,
str: () => str,
throttle: () => throttle
});
module.exports = __toCommonJS(utils_exports);
var date = {
now: () => (/* @__PURE__ */ new Date()).toISOString(),
format: (d, fmt = "YYYY-MM-DD HH:mm") => {
const date2 = typeof d === "number" ? new Date(d) : new Date(d);
const map = {
YYYY: String(date2.getFullYear()),
MM: String(date2.getMonth() + 1).padStart(2, "0"),
DD: String(date2.getDate()).padStart(2, "0"),
HH: String(date2.getHours()).padStart(2, "0"),
mm: String(date2.getMinutes()).padStart(2, "0"),
ss: String(date2.getSeconds()).padStart(2, "0")
};
return fmt.replace(/YYYY|MM|DD|HH|mm|ss/g, (m) => map[m]);
},
isToday: (d) => {
const date2 = new Date(d);
const today = /* @__PURE__ */ new Date();
return date2.toDateString() === today.toDateString();
},
daysBetween: (a, b) => Math.ceil((b.getTime() - a.getTime()) / 864e5)
};
var str = {
capitalize: (s) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase(),
truncate: (s, max, suffix = "\u2026") => s.length <= max ? s : s.slice(0, max).trimEnd() + suffix,
camelCase: (s) => s.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : ""),
kebabCase: (s) => s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(),
slugify: (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""),
removeAccents: (s) => s.normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
maskEmail: (email) => {
const [user, domain] = email.split("@");
return user.length <= 2 ? `${user[0]}*@${domain}` : `${user[0]}${"*".repeat(user.length - 2)}${user.at(-1)}@${domain}`;
}
};
var num = {
clamp: (value, min, max) => Math.min(Math.max(value, min), max),
rand: (min, max) => Math.floor(Math.random() * (max - min + 1)) + min,
format: (n) => n.toLocaleString("pt-BR"),
percent: (part, total, decimals = 1) => {
if (total === 0) return 0;
return parseFloat((part / total * 100).toFixed(decimals));
}
};
var CLEAN_CLASSES_REGEX = /\s+/g;
function cn(...inputs) {
return inputs.flat(2).filter(Boolean).join(" ").replace(CLEAN_CLASSES_REGEX, " ").trim();
}
function debounce(fn, ms) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), ms);
};
}
function throttle(fn, ms) {
let last = 0;
return (...args) => {
const now = Date.now();
if (now - last >= ms) {
last = now;
fn(...args);
}
};
}
var storage = {
get: (key, fallback) => {
try {
const v = typeof localStorage !== "undefined" ? localStorage.getItem(key) : null;
return v ? JSON.parse(v) : fallback;
} catch {
return fallback;
}
},
set: (key, value) => {
localStorage.setItem(key, JSON.stringify(value));
},
remove: (key) => {
try {
localStorage.removeItem(key);
} catch {
}
},
clear: (prefix) => {
if (prefix) Object.keys(localStorage).filter((k) => k.startsWith(prefix)).forEach((k) => localStorage.removeItem(k));
else localStorage.clear();
}
};
var arr = {
unique: (items, key) => {
if (!key) return [...new Set(items)];
return items.filter((v, i, a) => a.findIndex((item) => item[key] === v[key]) === i);
},
chunk: (items, size) => {
return Array.from({ length: Math.ceil(items.length / size) }, (_, i) => items.slice(i * size, i * size + size));
},
shuffle: (items) => [...items].sort(() => Math.random() - 0.5)
};
var obj = {
pick: (o, keys) => keys.reduce((r, k) => {
if (k in o) r[k] = o[k];
return r;
}, {}),
omit: (o, keys) => Object.fromEntries(Object.entries(o).filter(([k]) => !keys.includes(k))),
isEmpty: (o) => o == null || Object.keys(o).length === 0
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
arr,
cn,
date,
debounce,
num,
obj,
storage,
str,
throttle
});
//# sourceMappingURL=index.js.map