@jjlmoya/utils-hardware 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +60 -0
- package/src/category/i18n/en.ts +107 -0
- package/src/category/i18n/es.ts +107 -0
- package/src/category/i18n/fr.ts +107 -0
- package/src/category/index.ts +18 -0
- package/src/category/seo.astro +15 -0
- package/src/components/PreviewNavSidebar.astro +116 -0
- package/src/components/PreviewToolbar.astro +143 -0
- package/src/data.ts +11 -0
- package/src/env.d.ts +5 -0
- package/src/index.ts +26 -0
- package/src/layouts/PreviewLayout.astro +117 -0
- package/src/pages/[locale]/[slug].astro +146 -0
- package/src/pages/[locale].astro +251 -0
- package/src/pages/index.astro +4 -0
- package/src/tests/faq_count.test.ts +19 -0
- package/src/tests/locale_completeness.test.ts +42 -0
- package/src/tests/mocks/astro_mock.js +2 -0
- package/src/tests/no_h1_in_components.test.ts +48 -0
- package/src/tests/schemas_fulfillment.test.ts +23 -0
- package/src/tests/seo_length.test.ts +23 -0
- package/src/tests/title_quality.test.ts +55 -0
- package/src/tests/tool_validation.test.ts +17 -0
- package/src/tool/batteryHealthEstimator/bibliography.astro +14 -0
- package/src/tool/batteryHealthEstimator/component.astro +606 -0
- package/src/tool/batteryHealthEstimator/i18n/en.ts +158 -0
- package/src/tool/batteryHealthEstimator/i18n/es.ts +158 -0
- package/src/tool/batteryHealthEstimator/i18n/fr.ts +158 -0
- package/src/tool/batteryHealthEstimator/index.ts +34 -0
- package/src/tool/batteryHealthEstimator/seo.astro +14 -0
- package/src/tool/batteryHealthEstimator/ui.ts +31 -0
- package/src/tool/deadPixelTest/bibliography.astro +31 -0
- package/src/tool/deadPixelTest/component.astro +717 -0
- package/src/tool/deadPixelTest/i18n/en.ts +218 -0
- package/src/tool/deadPixelTest/i18n/es.ts +218 -0
- package/src/tool/deadPixelTest/i18n/fr.ts +218 -0
- package/src/tool/deadPixelTest/index.ts +34 -0
- package/src/tool/deadPixelTest/seo.astro +14 -0
- package/src/tool/deadPixelTest/ui.ts +20 -0
- package/src/tool/gamepadTest/bibliography.astro +30 -0
- package/src/tool/gamepadTest/component.astro +1419 -0
- package/src/tool/gamepadTest/i18n/en.ts +186 -0
- package/src/tool/gamepadTest/i18n/es.ts +186 -0
- package/src/tool/gamepadTest/i18n/fr.ts +186 -0
- package/src/tool/gamepadTest/index.ts +34 -0
- package/src/tool/gamepadTest/seo.astro +14 -0
- package/src/tool/gamepadTest/ui.ts +57 -0
- package/src/tool/gamepadVibrationTester/bibliography.astro +14 -0
- package/src/tool/gamepadVibrationTester/component.astro +694 -0
- package/src/tool/gamepadVibrationTester/i18n/en.ts +155 -0
- package/src/tool/gamepadVibrationTester/i18n/es.ts +155 -0
- package/src/tool/gamepadVibrationTester/i18n/fr.ts +150 -0
- package/src/tool/gamepadVibrationTester/index.ts +34 -0
- package/src/tool/gamepadVibrationTester/seo.astro +14 -0
- package/src/tool/gamepadVibrationTester/ui.ts +28 -0
- package/src/tool/keyboardTest/bibliography.astro +30 -0
- package/src/tool/keyboardTest/component.astro +601 -0
- package/src/tool/keyboardTest/i18n/en.ts +146 -0
- package/src/tool/keyboardTest/i18n/es.ts +146 -0
- package/src/tool/keyboardTest/i18n/fr.ts +146 -0
- package/src/tool/keyboardTest/index.ts +34 -0
- package/src/tool/keyboardTest/seo.astro +14 -0
- package/src/tool/keyboardTest/ui.ts +8 -0
- package/src/tool/mousePollingTest/bibliography.astro +14 -0
- package/src/tool/mousePollingTest/component.astro +237 -0
- package/src/tool/mousePollingTest/i18n/en.ts +135 -0
- package/src/tool/mousePollingTest/i18n/es.ts +135 -0
- package/src/tool/mousePollingTest/i18n/fr.ts +135 -0
- package/src/tool/mousePollingTest/index.ts +34 -0
- package/src/tool/mousePollingTest/logic/MovingAverage.ts +20 -0
- package/src/tool/mousePollingTest/logic/RatonManager.ts +97 -0
- package/src/tool/mousePollingTest/logic/StatisticalFilter.ts +48 -0
- package/src/tool/mousePollingTest/seo.astro +14 -0
- package/src/tool/mousePollingTest/ui.ts +8 -0
- package/src/tool/mousePollingTest/worker/mouseWorker.ts +50 -0
- package/src/tool/toneGenerator/bibliography.astro +14 -0
- package/src/tool/toneGenerator/component.astro +571 -0
- package/src/tool/toneGenerator/i18n/en.ts +146 -0
- package/src/tool/toneGenerator/i18n/es.ts +146 -0
- package/src/tool/toneGenerator/i18n/fr.ts +146 -0
- package/src/tool/toneGenerator/index.ts +34 -0
- package/src/tool/toneGenerator/seo.astro +14 -0
- package/src/tool/toneGenerator/ui.ts +19 -0
- package/src/tools.ts +10 -0
- package/src/types.ts +72 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class MovingAverage {
|
|
2
|
+
private window: number[] = [];
|
|
3
|
+
private readonly size: number;
|
|
4
|
+
|
|
5
|
+
constructor(size: number = 20) {
|
|
6
|
+
this.size = size;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public next(value: number): number {
|
|
10
|
+
this.window.push(value);
|
|
11
|
+
if (this.window.length > this.size) {
|
|
12
|
+
this.window.shift();
|
|
13
|
+
}
|
|
14
|
+
return this.window.reduce((acc, val) => acc + val, 0) / this.window.length;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public reset(): void {
|
|
18
|
+
this.window = [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export interface UIToolElements {
|
|
2
|
+
avg: HTMLElement | null;
|
|
3
|
+
max: HTMLElement | null;
|
|
4
|
+
follower: HTMLElement | null;
|
|
5
|
+
placeholder: HTMLElement | null;
|
|
6
|
+
canvas: HTMLCanvasElement | null;
|
|
7
|
+
area: HTMLElement | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class RatonManager {
|
|
11
|
+
private el: UIToolElements;
|
|
12
|
+
private ctx: CanvasRenderingContext2D | null;
|
|
13
|
+
private worker: Worker;
|
|
14
|
+
private history: number[] = [];
|
|
15
|
+
private readonly MAX_HISTORY = 100;
|
|
16
|
+
private idleTimer: ReturnType<typeof setTimeout> | null = null;
|
|
17
|
+
private lastMouseEvent: MouseEvent | null = null;
|
|
18
|
+
|
|
19
|
+
constructor(el: UIToolElements, workerUrl: URL) {
|
|
20
|
+
this.el = el;
|
|
21
|
+
this.ctx = el.canvas?.getContext('2d') ?? null;
|
|
22
|
+
this.worker = new Worker(workerUrl, { type: 'module' });
|
|
23
|
+
this.init();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private init(): void {
|
|
27
|
+
window.addEventListener('resize', () => this.resize());
|
|
28
|
+
this.resize();
|
|
29
|
+
|
|
30
|
+
this.worker.onmessage = (event) => this.handleWorkerMessage(event.data);
|
|
31
|
+
|
|
32
|
+
this.el.area?.addEventListener('mousemove', (e) => this.processMove(e));
|
|
33
|
+
this.el.area?.addEventListener('mouseleave', () => this.handleMouseLeave());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private resize(): void {
|
|
37
|
+
if (!this.el.area || !this.el.canvas) return;
|
|
38
|
+
const rect = this.el.area.getBoundingClientRect();
|
|
39
|
+
this.el.canvas.width = rect.width;
|
|
40
|
+
this.el.canvas.height = rect.height;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private handleWorkerMessage(data: { hz: number; smoothedHz: number; avgHz: number; maxHz: number }): void {
|
|
44
|
+
const { hz, smoothedHz, avgHz, maxHz } = data;
|
|
45
|
+
|
|
46
|
+
this.history.push(smoothedHz);
|
|
47
|
+
if (this.history.length > this.MAX_HISTORY) this.history.shift();
|
|
48
|
+
|
|
49
|
+
if (this.el.max) this.el.max.textContent = Math.round(maxHz).toString();
|
|
50
|
+
if (this.el.avg) this.el.avg.textContent = Math.round(avgHz).toString();
|
|
51
|
+
|
|
52
|
+
this.updateGraph();
|
|
53
|
+
|
|
54
|
+
if (this.el.follower && this.lastMouseEvent) {
|
|
55
|
+
this.el.follower.textContent = `${Math.round(hz)} Hz`;
|
|
56
|
+
const rect = this.el.area!.getBoundingClientRect();
|
|
57
|
+
this.el.follower.style.transform = `translate(${this.lastMouseEvent.clientX - rect.left + 15}px, ${this.lastMouseEvent.clientY - rect.top + 15}px)`;
|
|
58
|
+
this.el.follower.style.opacity = '1';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (this.el.placeholder) this.el.placeholder.style.opacity = '0';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private updateGraph(): void {
|
|
65
|
+
if (!this.ctx || !this.el.canvas) return;
|
|
66
|
+
const { width: w, height: h } = this.el.canvas;
|
|
67
|
+
this.ctx.clearRect(0, 0, w, h);
|
|
68
|
+
this.ctx.beginPath();
|
|
69
|
+
this.ctx.strokeStyle = '#10b981';
|
|
70
|
+
this.ctx.lineWidth = 2;
|
|
71
|
+
const currentMax = Math.max(1000, ...this.history);
|
|
72
|
+
const stepX = w / this.MAX_HISTORY;
|
|
73
|
+
this.history.forEach((hz, i) => {
|
|
74
|
+
const x = i * stepX;
|
|
75
|
+
const y = h - (hz / currentMax) * (h * 0.8);
|
|
76
|
+
if (i === 0) this.ctx!.moveTo(x, y);
|
|
77
|
+
else this.ctx!.lineTo(x, y);
|
|
78
|
+
});
|
|
79
|
+
this.ctx.stroke();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private processMove(e: MouseEvent): void {
|
|
83
|
+
this.lastMouseEvent = e;
|
|
84
|
+
this.worker.postMessage({ time: performance.now() });
|
|
85
|
+
|
|
86
|
+
if (this.idleTimer) clearTimeout(this.idleTimer);
|
|
87
|
+
this.idleTimer = setTimeout(() => {
|
|
88
|
+
if (this.el.follower) this.el.follower.style.opacity = '0';
|
|
89
|
+
this.worker.postMessage('reset');
|
|
90
|
+
}, 100);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private handleMouseLeave(): void {
|
|
94
|
+
if (this.el.follower) this.el.follower.style.opacity = '0';
|
|
95
|
+
this.worker.postMessage('reset');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface FilterConfig {
|
|
2
|
+
maxThreshold?: number;
|
|
3
|
+
stdDevMultiplier?: number;
|
|
4
|
+
minSamples?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class StatisticalFilter {
|
|
8
|
+
private samples: number[] = [];
|
|
9
|
+
private readonly config: FilterConfig;
|
|
10
|
+
|
|
11
|
+
constructor(config: FilterConfig = {}) {
|
|
12
|
+
this.config = {
|
|
13
|
+
maxThreshold: 1100,
|
|
14
|
+
stdDevMultiplier: 2,
|
|
15
|
+
minSamples: 20,
|
|
16
|
+
...config,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public isOutlier(value: number): boolean {
|
|
21
|
+
if (this.config.maxThreshold && value > this.config.maxThreshold) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (this.samples.length < (this.config.minSamples || 20)) {
|
|
26
|
+
this.samples.push(value);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const avg = this.samples.reduce((a, b) => a + b, 0) / this.samples.length;
|
|
31
|
+
const stdDev = Math.sqrt(
|
|
32
|
+
this.samples.reduce((a, b) => a + Math.pow(b - avg, 2), 0) / this.samples.length
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const isFiltered = Math.abs(value - avg) > stdDev * (this.config.stdDevMultiplier || 2.5);
|
|
36
|
+
|
|
37
|
+
if (!isFiltered) {
|
|
38
|
+
this.samples.push(value);
|
|
39
|
+
if (this.samples.length > 100) this.samples.shift();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return isFiltered;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public reset(): void {
|
|
46
|
+
this.samples = [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { SEORenderer } from '@jjlmoya/utils-shared';
|
|
3
|
+
import type { KnownLocale } from '../../types';
|
|
4
|
+
import { testRaton } from './index';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
locale?: KnownLocale;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { locale = 'es' } = Astro.props;
|
|
11
|
+
const content = await testRaton.i18n[locale]?.();
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
{content && <SEORenderer content={{ locale, sections: content.seo }} />}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { StatisticalFilter } from '../logic/StatisticalFilter';
|
|
2
|
+
import { MovingAverage } from '../logic/MovingAverage';
|
|
3
|
+
|
|
4
|
+
const statisticalFilter = new StatisticalFilter();
|
|
5
|
+
const smoothingFilter = new MovingAverage(20);
|
|
6
|
+
|
|
7
|
+
let lastTime = 0;
|
|
8
|
+
let maxHz = 0;
|
|
9
|
+
const history: number[] = [];
|
|
10
|
+
|
|
11
|
+
self.onmessage = (event: MessageEvent<{ time: number } | 'reset'>) => {
|
|
12
|
+
if (event.data === 'reset') {
|
|
13
|
+
lastTime = 0;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { time } = event.data;
|
|
18
|
+
|
|
19
|
+
if (lastTime === 0) {
|
|
20
|
+
lastTime = time;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const delta = time - lastTime;
|
|
25
|
+
lastTime = time;
|
|
26
|
+
|
|
27
|
+
if (delta <= 0 || delta > 100) return;
|
|
28
|
+
|
|
29
|
+
const hz = 1000 / delta;
|
|
30
|
+
|
|
31
|
+
if (statisticalFilter.isOutlier(hz)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const smoothedHz = smoothingFilter.next(hz);
|
|
36
|
+
|
|
37
|
+
history.push(hz);
|
|
38
|
+
if (history.length > 200) history.shift();
|
|
39
|
+
|
|
40
|
+
if (hz > maxHz) maxHz = hz;
|
|
41
|
+
|
|
42
|
+
const avgHz = history.reduce((a, b) => a + b, 0) / history.length;
|
|
43
|
+
|
|
44
|
+
self.postMessage({
|
|
45
|
+
hz,
|
|
46
|
+
smoothedHz,
|
|
47
|
+
avgHz,
|
|
48
|
+
maxHz
|
|
49
|
+
});
|
|
50
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { Bibliography as SharedBibliography } from '@jjlmoya/utils-shared';
|
|
3
|
+
import type { KnownLocale } from '../../types';
|
|
4
|
+
import { toneGenerator } from './index';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
locale?: KnownLocale;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { locale = 'es' } = Astro.props;
|
|
11
|
+
const content = await toneGenerator.i18n[locale]?.();
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
{content && content.bibliography.length > 0 && <SharedBibliography links={content.bibliography} />}
|