@buoy-gg/floating-tools-core 2.2.0 → 3.0.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/lib/commonjs/FloatingToolsStore.js +501 -1
- package/lib/commonjs/colors.js +54 -1
- package/lib/commonjs/constants.js +31 -1
- package/lib/commonjs/devToolsState.js +325 -1
- package/lib/commonjs/dial.js +617 -1
- package/lib/commonjs/dialUsage.js +130 -1
- package/lib/commonjs/easing.js +69 -1
- package/lib/commonjs/icons/benchmark-icon.js +24 -1
- package/lib/commonjs/icons/env-icon.js +24 -1
- package/lib/commonjs/icons/events-icon.js +24 -1
- package/lib/commonjs/icons/highlight-icon.js +24 -1
- package/lib/commonjs/icons/icon-data.js +2268 -1
- package/lib/commonjs/icons/icon-factories.js +173 -1
- package/lib/commonjs/icons/icon-primitives.js +559 -1
- package/lib/commonjs/icons/icon-primitives.native.js +779 -1
- package/lib/commonjs/icons/icon-renderer.js +260 -1
- package/lib/commonjs/icons/network-icon.js +24 -1
- package/lib/commonjs/icons/query-icon.js +24 -1
- package/lib/commonjs/icons/redux-icon.js +85 -1
- package/lib/commonjs/icons/renders-icon.js +33 -1
- package/lib/commonjs/icons/routes-icon.js +49 -1
- package/lib/commonjs/icons/sentry-icon.js +24 -1
- package/lib/commonjs/icons/storage-icon.js +24 -1
- package/lib/commonjs/icons/wifi-icon.js +24 -1
- package/lib/commonjs/index.js +760 -1
- package/lib/commonjs/settings.js +601 -1
- package/lib/commonjs/utils.js +72 -1
- package/lib/module/FloatingToolsStore.js +496 -1
- package/lib/module/colors.js +49 -1
- package/lib/module/constants.js +27 -1
- package/lib/module/devToolsState.js +318 -1
- package/lib/module/dial.js +603 -1
- package/lib/module/dialUsage.js +122 -1
- package/lib/module/easing.js +62 -1
- package/lib/module/icons/benchmark-icon.js +15 -1
- package/lib/module/icons/env-icon.js +15 -1
- package/lib/module/icons/events-icon.js +15 -1
- package/lib/module/icons/highlight-icon.js +15 -1
- package/lib/module/icons/icon-data.js +2264 -1
- package/lib/module/icons/icon-factories.js +163 -1
- package/lib/module/icons/icon-primitives.js +547 -1
- package/lib/module/icons/icon-primitives.native.js +767 -1
- package/lib/module/icons/icon-renderer.js +255 -1
- package/lib/module/icons/network-icon.js +15 -1
- package/lib/module/icons/query-icon.js +15 -1
- package/lib/module/icons/redux-icon.js +81 -1
- package/lib/module/icons/renders-icon.js +17 -1
- package/lib/module/icons/routes-icon.js +41 -1
- package/lib/module/icons/sentry-icon.js +15 -1
- package/lib/module/icons/storage-icon.js +15 -1
- package/lib/module/icons/wifi-icon.js +15 -1
- package/lib/module/index.js +106 -1
- package/lib/module/settings.js +589 -1
- package/lib/module/utils.js +66 -1
- package/lib/typescript/commonjs/FloatingToolsStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/colors.d.ts.map +1 -0
- package/lib/typescript/commonjs/constants.d.ts.map +1 -0
- package/lib/typescript/commonjs/devToolsState.d.ts.map +1 -0
- package/lib/typescript/commonjs/dial.d.ts.map +1 -0
- package/lib/typescript/commonjs/dialUsage.d.ts.map +1 -0
- package/lib/typescript/commonjs/easing.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/benchmark-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/env-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/events-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/highlight-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/icon-data.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/icon-factories.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/icon-primitives.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/icon-primitives.native.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/icon-renderer.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/network-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/query-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/redux-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/renders-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/routes-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/sentry-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/storage-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/wifi-icon.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/settings.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils.d.ts.map +1 -0
- package/lib/typescript/module/FloatingToolsStore.d.ts.map +1 -0
- package/lib/typescript/module/colors.d.ts.map +1 -0
- package/lib/typescript/module/constants.d.ts.map +1 -0
- package/lib/typescript/module/devToolsState.d.ts.map +1 -0
- package/lib/typescript/module/dial.d.ts.map +1 -0
- package/lib/typescript/module/dialUsage.d.ts.map +1 -0
- package/lib/typescript/module/easing.d.ts.map +1 -0
- package/lib/typescript/module/icons/benchmark-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/env-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/events-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/highlight-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/icon-data.d.ts.map +1 -0
- package/lib/typescript/module/icons/icon-factories.d.ts.map +1 -0
- package/lib/typescript/module/icons/icon-primitives.d.ts.map +1 -0
- package/lib/typescript/module/icons/icon-primitives.native.d.ts.map +1 -0
- package/lib/typescript/module/icons/icon-renderer.d.ts.map +1 -0
- package/lib/typescript/module/icons/network-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/query-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/redux-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/renders-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/routes-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/sentry-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/storage-icon.d.ts.map +1 -0
- package/lib/typescript/module/icons/wifi-icon.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/settings.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/lib/typescript/module/utils.d.ts.map +1 -0
- package/package.json +1 -1
package/lib/module/dialUsage.js
CHANGED
|
@@ -1 +1,122 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dial Usage - Recency-weighted usage tracking for the dial menu.
|
|
5
|
+
*
|
|
6
|
+
* Pure scoring/ranking logic. No React or platform-specific code.
|
|
7
|
+
*
|
|
8
|
+
* The dial menu ranks tools by how recently and frequently they are used.
|
|
9
|
+
* Each press adds 1 point to a tool's score; that score decays exponentially
|
|
10
|
+
* over time (half-life ~3 days) so the ordering reflects "what I'm using most
|
|
11
|
+
* lately" rather than all-time totals.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// =============================
|
|
15
|
+
// Constants
|
|
16
|
+
// =============================
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Half-life of a usage score, in milliseconds (~3 days).
|
|
20
|
+
* After this much time, an untouched tool's score halves.
|
|
21
|
+
*/
|
|
22
|
+
export const USAGE_HALF_LIFE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Scores at or below this value are treated as zero. Entries that decay
|
|
26
|
+
* below it can be safely pruned from storage.
|
|
27
|
+
*/
|
|
28
|
+
export const USAGE_MIN_SCORE = 0.01;
|
|
29
|
+
|
|
30
|
+
// =============================
|
|
31
|
+
// Types
|
|
32
|
+
// =============================
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A single tool's usage record.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/** Map of tool id to its usage record. */
|
|
39
|
+
|
|
40
|
+
// =============================
|
|
41
|
+
// Scoring
|
|
42
|
+
// =============================
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Decay a stored score forward to `now`.
|
|
46
|
+
*
|
|
47
|
+
* @param entry - The usage entry to evaluate
|
|
48
|
+
* @param now - Current epoch ms
|
|
49
|
+
* @returns The score decayed to `now` (never negative)
|
|
50
|
+
*/
|
|
51
|
+
export function decayScore(entry, now) {
|
|
52
|
+
if (!entry || entry.score <= 0) return 0;
|
|
53
|
+
const elapsed = now - entry.lastUsed;
|
|
54
|
+
// Guard against clock skew producing a score boost.
|
|
55
|
+
if (elapsed <= 0) return entry.score;
|
|
56
|
+
return entry.score * Math.pow(0.5, elapsed / USAGE_HALF_LIFE_MS);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Record a single press of a tool, returning a new usage map.
|
|
61
|
+
*
|
|
62
|
+
* The existing score is decayed forward to `now` before adding 1, so a
|
|
63
|
+
* burst of presses accumulates while stale scores naturally fade.
|
|
64
|
+
*
|
|
65
|
+
* @param map - Current usage map
|
|
66
|
+
* @param id - Tool id that was pressed
|
|
67
|
+
* @param now - Current epoch ms
|
|
68
|
+
* @returns A new usage map (input is not mutated)
|
|
69
|
+
*/
|
|
70
|
+
export function recordUsage(map, id, now) {
|
|
71
|
+
const decayed = decayScore(map[id], now);
|
|
72
|
+
return {
|
|
73
|
+
...map,
|
|
74
|
+
[id]: {
|
|
75
|
+
score: decayed + 1,
|
|
76
|
+
lastUsed: now
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Rank tool ids by decayed usage score, highest first.
|
|
83
|
+
*
|
|
84
|
+
* The sort is stable: tools with equal scores (including never-used tools,
|
|
85
|
+
* which score 0) keep their original order in `orderedIds`. This preserves
|
|
86
|
+
* registration order as the tie-breaker.
|
|
87
|
+
*
|
|
88
|
+
* @param orderedIds - Tool ids in their default/registration order
|
|
89
|
+
* @param map - Current usage map
|
|
90
|
+
* @param now - Current epoch ms
|
|
91
|
+
* @returns A new array of ids sorted by usage
|
|
92
|
+
*/
|
|
93
|
+
export function rankToolIds(orderedIds, map, now) {
|
|
94
|
+
const scored = orderedIds.map((id, index) => ({
|
|
95
|
+
id,
|
|
96
|
+
index,
|
|
97
|
+
score: decayScore(map[id], now)
|
|
98
|
+
}));
|
|
99
|
+
scored.sort((a, b) => {
|
|
100
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
101
|
+
return a.index - b.index;
|
|
102
|
+
});
|
|
103
|
+
return scored.map(entry => entry.id);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Drop entries whose decayed score has fallen below `USAGE_MIN_SCORE`,
|
|
108
|
+
* keeping the persisted map from growing unbounded.
|
|
109
|
+
*
|
|
110
|
+
* @param map - Current usage map
|
|
111
|
+
* @param now - Current epoch ms
|
|
112
|
+
* @returns A new, pruned usage map
|
|
113
|
+
*/
|
|
114
|
+
export function pruneUsage(map, now) {
|
|
115
|
+
const pruned = {};
|
|
116
|
+
for (const [id, entry] of Object.entries(map)) {
|
|
117
|
+
if (decayScore(entry, now) > USAGE_MIN_SCORE) {
|
|
118
|
+
pruned[id] = entry;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return pruned;
|
|
122
|
+
}
|
package/lib/module/easing.js
CHANGED
|
@@ -1 +1,62 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Animation easing functions.
|
|
5
|
+
* Platform-agnostic - used by both web (RAF) and mobile (Animated).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Easing functions for animations.
|
|
10
|
+
* All functions take progress (0-1) and return eased value (0-1).
|
|
11
|
+
*/
|
|
12
|
+
export const easing = {
|
|
13
|
+
/**
|
|
14
|
+
* Linear - no easing.
|
|
15
|
+
*/
|
|
16
|
+
linear: t => t,
|
|
17
|
+
/**
|
|
18
|
+
* Ease out cubic - decelerates towards end.
|
|
19
|
+
* Used for hide/show animations.
|
|
20
|
+
*/
|
|
21
|
+
easeOutCubic: t => 1 - Math.pow(1 - t, 3),
|
|
22
|
+
/**
|
|
23
|
+
* Ease in cubic - accelerates from start.
|
|
24
|
+
*/
|
|
25
|
+
easeInCubic: t => t * t * t,
|
|
26
|
+
/**
|
|
27
|
+
* Ease in-out cubic - smooth acceleration and deceleration.
|
|
28
|
+
*/
|
|
29
|
+
easeInOutCubic: t => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2,
|
|
30
|
+
/**
|
|
31
|
+
* Ease out quad - lighter deceleration than cubic.
|
|
32
|
+
*/
|
|
33
|
+
easeOutQuad: t => 1 - (1 - t) * (1 - t),
|
|
34
|
+
/**
|
|
35
|
+
* Ease out expo - strong deceleration (snappy feel).
|
|
36
|
+
*/
|
|
37
|
+
easeOutExpo: t => t === 1 ? 1 : 1 - Math.pow(2, -10 * t)
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get an easing function by name.
|
|
41
|
+
*/
|
|
42
|
+
export function getEasing(name) {
|
|
43
|
+
return easing[name];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Interpolate between two values using an easing function.
|
|
48
|
+
*/
|
|
49
|
+
export function interpolate(from, to, progress, easingFn = easing.easeOutCubic) {
|
|
50
|
+
const eased = easingFn(Math.max(0, Math.min(1, progress)));
|
|
51
|
+
return from + (to - from) * eased;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Interpolate a position (x, y) using an easing function.
|
|
56
|
+
*/
|
|
57
|
+
export function interpolatePosition(from, to, progress, easingFn = easing.easeOutCubic) {
|
|
58
|
+
return {
|
|
59
|
+
x: interpolate(from.x, to.x, progress, easingFn),
|
|
60
|
+
y: interpolate(from.y, to.y, progress, easingFn)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BenchmarkIcon - Data-driven icon
|
|
5
|
+
*
|
|
6
|
+
* The icon is defined as pure data in icon-data.ts
|
|
7
|
+
* The renderer transforms it to components.
|
|
8
|
+
*
|
|
9
|
+
* To change: edit benchmarkIconData in icon-data.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createIcon } from "./icon-renderer.js";
|
|
13
|
+
import { benchmarkIconData, BENCHMARK_ICON_COLOR } from "./icon-data.js";
|
|
14
|
+
export { BENCHMARK_ICON_COLOR };
|
|
15
|
+
export const BenchmarkIcon = createIcon(benchmarkIconData);
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EnvIcon - Data-driven icon
|
|
5
|
+
*
|
|
6
|
+
* The icon is defined as pure data in icon-data.ts
|
|
7
|
+
* The renderer transforms it to components.
|
|
8
|
+
*
|
|
9
|
+
* To change: edit envIconData in icon-data.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createIcon } from "./icon-renderer.js";
|
|
13
|
+
import { envIconData, ENV_ICON_COLOR } from "./icon-data.js";
|
|
14
|
+
export { ENV_ICON_COLOR };
|
|
15
|
+
export const EnvIcon = createIcon(envIconData);
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EventsIcon - Data-driven icon
|
|
5
|
+
*
|
|
6
|
+
* The icon is defined as pure data in icon-data.ts
|
|
7
|
+
* The renderer transforms it to components.
|
|
8
|
+
*
|
|
9
|
+
* To change: edit eventsIconData in icon-data.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createIcon } from "./icon-renderer.js";
|
|
13
|
+
import { eventsIconData, EVENTS_ICON_COLOR } from "./icon-data.js";
|
|
14
|
+
export { EVENTS_ICON_COLOR };
|
|
15
|
+
export const EventsIcon = createIcon(eventsIconData);
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HighlightIcon - Data-driven icon (also known as StackPulseIcon/RenderPulseIcon)
|
|
5
|
+
*
|
|
6
|
+
* The icon is defined as pure data in icon-data.ts
|
|
7
|
+
* The renderer transforms it to components.
|
|
8
|
+
*
|
|
9
|
+
* To change: edit highlightIconData in icon-data.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createIcon } from "./icon-renderer.js";
|
|
13
|
+
import { highlightIconData, HIGHLIGHT_ICON_COLOR } from "./icon-data.js";
|
|
14
|
+
export { HIGHLIGHT_ICON_COLOR };
|
|
15
|
+
export const HighlightIcon = createIcon(highlightIconData);
|