preact-perf-tracker 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Jovi De Croock
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # preact-perf-tracker
2
+
3
+ > [!NOTE]
4
+ > This package is heavily inspired by [React-scan](https://github.com/aidenybai/react-scan)
5
+
6
+ Track component renders in Preact with:
7
+ - render-change detection (props/state/force updates)
8
+ - a visual DOM overlay
9
+ - a floating toolbar with render/FPS stats, pause toggle, reset, and report copy
10
+ - a runtime report API
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pnpm add preact-perf-tracker
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```ts
21
+ import { install } from 'preact-perf-tracker';
22
+
23
+ install({
24
+ enabled: true,
25
+ log: false,
26
+ showToolbar: true,
27
+ animationSpeed: 'fast',
28
+ });
29
+ ```
30
+
31
+ Call `install()` once near app startup (for example in `main.tsx`).
32
+
33
+ ## API
34
+
35
+ ### `install(options?: Options): void`
36
+ Starts instrumentation (idempotent). If `enabled: false` and `showToolbar: false`, it does nothing.
37
+
38
+ ### `setOptions(options: Partial<Options>): void`
39
+ Updates options at runtime.
40
+
41
+ ### `getOptions(): Readonly<Options>`
42
+ Returns the active options object.
43
+
44
+ ### `getReport(type?: unknown): ReportEntry | Map<unknown, ReportEntry> | null`
45
+ Returns aggregated render data for all tracked component types or one specific type.
46
+
47
+ ### `getReportSummary(limit = 10): ReportSummaryEntry[]`
48
+ Returns top entries sorted by total self-time, including derived `avgSelfTime`.
49
+
50
+ ### `clearReport(): void`
51
+ Resets collected report data.
52
+
53
+ ### `stop(): void`
54
+ Removes instrumentation hooks, overlay, and toolbar.
55
+
56
+ ## Types
57
+
58
+ ```ts
59
+ type Options = {
60
+ enabled?: boolean; // default true
61
+ log?: boolean; // default false
62
+ showToolbar?: boolean; // default true
63
+ animationSpeed?: 'slow' | 'fast' | 'off';
64
+ onRender?: (info: RenderInfo) => void;
65
+ onCommitStart?: () => void;
66
+ onCommitFinish?: () => void;
67
+ };
68
+ ```
69
+
70
+ `RenderInfo` includes:
71
+ - `componentName`
72
+ - `phase` (`mount` | `update` | `unmount`)
73
+ - `selfTime`
74
+ - `changes`
75
+ - `timestamp`
76
+ - `domNode`
77
+
78
+ `ReportSummaryEntry` includes:
79
+ - `displayName`
80
+ - `count`
81
+ - `totalSelfTime`
82
+ - `avgSelfTime`
83
+
84
+ ## Example
85
+
86
+ A runnable demo is in `example/`.
87
+
88
+ ```bash
89
+ cd example
90
+ pnpm install
91
+ pnpm dev
92
+ ```
93
+
94
+ ## Notes
95
+
96
+ - This package hooks into Preact `options` internals.
97
+ - Built for Preact 10.x.
98
+ - `install()` resets runtime options to defaults before applying provided options.
99
+ - Browser/runtime tooling only (not intended for SSR execution).
100
+
101
+ ## License
102
+
103
+ MIT