heatspot 0.2.2 → 0.2.3
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/README.md +64 -1
- package/dist/heatspot-element.d.ts +12 -0
- package/dist/heatspot-element.js +30 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,43 @@ Example with hidden toolbar:
|
|
|
63
63
|
|
|
64
64
|

|
|
65
65
|
|
|
66
|
-
### 3.
|
|
66
|
+
### 3. Read heatmap data from a `<heat-spot>` element
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const element = document.querySelector<HeatSpotElement>('heat-spot');
|
|
70
|
+
|
|
71
|
+
const snapshot = element.getHeatmapData();
|
|
72
|
+
|
|
73
|
+
console.log(snapshot);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Example data shape:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"totalSamples": 42,
|
|
81
|
+
"trackedSince": 1741351200000,
|
|
82
|
+
"viewport": { "width": 960, "height": 540 },
|
|
83
|
+
"hotspots": [
|
|
84
|
+
{
|
|
85
|
+
"id": "hs-0",
|
|
86
|
+
"x": 418.2,
|
|
87
|
+
"y": 225.6,
|
|
88
|
+
"count": 18,
|
|
89
|
+
"intensity": 1
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"id": "hs-1",
|
|
93
|
+
"x": 701.1,
|
|
94
|
+
"y": 392.8,
|
|
95
|
+
"count": 9,
|
|
96
|
+
"intensity": 0.5
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 4. Optional global tracking API
|
|
67
103
|
|
|
68
104
|
```ts
|
|
69
105
|
import {
|
|
@@ -84,6 +120,33 @@ stopMouseTracking();
|
|
|
84
120
|
resetMouseHeatmap();
|
|
85
121
|
```
|
|
86
122
|
|
|
123
|
+
### 5. Export the heatmap visualization as an image
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
const element = document.querySelector<HeatSpotElement>("heat-spot");
|
|
127
|
+
|
|
128
|
+
if (element) {
|
|
129
|
+
const imageDataUrl = element.getHeatmapImage();
|
|
130
|
+
|
|
131
|
+
if (imageDataUrl) {
|
|
132
|
+
console.log(imageDataUrl);
|
|
133
|
+
// Example prefix:
|
|
134
|
+
// data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
|
|
135
|
+
|
|
136
|
+
// Optional download example
|
|
137
|
+
const link = document.createElement("a");
|
|
138
|
+
link.href = imageDataUrl;
|
|
139
|
+
link.download = "heatmap.png";
|
|
140
|
+
link.click();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`getHeatmapImage()` returns:
|
|
146
|
+
|
|
147
|
+
- A `data:` URL string when the component has measurable dimensions.
|
|
148
|
+
- `null` if the element has no measurable surface yet (for example, hidden or not laid out).
|
|
149
|
+
|
|
87
150
|
## Scripts
|
|
88
151
|
|
|
89
152
|
- `npm run build` - compile library to `dist/`
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LitElement } from "lit";
|
|
2
|
+
import { type HeatmapSnapshot } from "./contracts/heatmap-contracts.js";
|
|
2
3
|
export declare class HeatSpotElement extends LitElement {
|
|
3
4
|
static properties: {
|
|
4
5
|
heatmapVisible: {
|
|
@@ -15,6 +16,17 @@ export declare class HeatSpotElement extends LitElement {
|
|
|
15
16
|
private readonly tracker;
|
|
16
17
|
static styles: import("lit").CSSResult;
|
|
17
18
|
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Returns the current tracked heatmap snapshot for this element instance.
|
|
21
|
+
*/
|
|
22
|
+
getHeatmapData(): HeatmapSnapshot;
|
|
23
|
+
/**
|
|
24
|
+
* Renders the current heatmap visualization into an image data URL.
|
|
25
|
+
*/
|
|
26
|
+
getHeatmapImage(options?: {
|
|
27
|
+
type?: string;
|
|
28
|
+
quality?: number;
|
|
29
|
+
}): string | null;
|
|
18
30
|
/**
|
|
19
31
|
* Stops frame rendering when element leaves the document.
|
|
20
32
|
*/
|
package/dist/heatspot-element.js
CHANGED
|
@@ -64,6 +64,36 @@ export class HeatSpotElement extends LitElement {
|
|
|
64
64
|
this.heatmapVisible = false;
|
|
65
65
|
this.toolbar = "simple";
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns the current tracked heatmap snapshot for this element instance.
|
|
69
|
+
*/
|
|
70
|
+
getHeatmapData() {
|
|
71
|
+
return this.tracker.getSnapshot();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Renders the current heatmap visualization into an image data URL.
|
|
75
|
+
*/
|
|
76
|
+
getHeatmapImage(options = {}) {
|
|
77
|
+
const surface = this.renderRoot.querySelector(".surface");
|
|
78
|
+
if (!surface) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const width = Math.round(surface.clientWidth);
|
|
82
|
+
const height = Math.round(surface.clientHeight);
|
|
83
|
+
if (width <= 0 || height <= 0) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const imageCanvas = document.createElement("canvas");
|
|
87
|
+
imageCanvas.width = width;
|
|
88
|
+
imageCanvas.height = height;
|
|
89
|
+
const context = imageCanvas.getContext("2d");
|
|
90
|
+
if (!context) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const snapshot = this.tracker.getSnapshot();
|
|
94
|
+
renderHeatmapOverlay(context, width, height, snapshot.hotspots);
|
|
95
|
+
return imageCanvas.toDataURL(options.type ?? "image/png", options.quality);
|
|
96
|
+
}
|
|
67
97
|
/**
|
|
68
98
|
* Stops frame rendering when element leaves the document.
|
|
69
99
|
*/
|