@hyperframes/studio 0.6.28 → 0.6.30
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/dist/assets/index-BWBj8I6Q.css +1 -0
- package/dist/assets/index-D790O3az.js +115 -0
- package/dist/assets/index-DSLrl2tB.js +531 -0
- package/dist/index.html +2 -2
- package/package.json +4 -4
- package/src/App.tsx +13 -0
- package/src/components/StudioErrorBoundary.tsx +68 -0
- package/src/components/StudioHeader.tsx +15 -3
- package/src/components/editor/PropertyPanel.tsx +4 -1
- package/src/components/editor/domEditingLayers.ts +15 -4
- package/src/components/editor/domEditingTypes.ts +1 -0
- package/src/components/nle/CompositionBreadcrumb.tsx +12 -2
- package/src/components/renders/RenderQueue.tsx +2 -0
- package/src/components/renders/useRenderQueue.ts +9 -0
- package/src/components/sidebar/LeftSidebar.tsx +2 -0
- package/src/contexts/FileManagerContext.tsx +3 -3
- package/src/hooks/useDomEditCommits.ts +52 -24
- package/src/hooks/useFileManager.ts +15 -13
- package/src/hooks/usePanelLayout.ts +11 -1
- package/src/hooks/useRenderClipContent.test.ts +50 -0
- package/src/hooks/useRenderClipContent.ts +23 -4
- package/src/hooks/useServerConnection.ts +11 -1
- package/src/main.tsx +22 -1
- package/src/player/components/CompositionThumbnail.tsx +10 -44
- package/src/player/components/PlayerControls.tsx +16 -3
- package/src/player/components/TimelineCanvas.tsx +9 -23
- package/src/player/components/TimelineClip.tsx +63 -67
- package/src/player/components/timelineEditing.test.ts +16 -0
- package/src/player/components/timelineEditing.ts +2 -1
- package/src/player/components/timelineTheme.ts +18 -48
- package/src/player/hooks/usePlaybackKeyboard.test.ts +55 -0
- package/src/player/hooks/usePlaybackKeyboard.ts +15 -0
- package/src/player/lib/mediaProbe.ts +20 -5
- package/src/player/lib/timelineDOM.ts +4 -0
- package/src/player/store/playerStore.ts +2 -0
- package/src/styles/studio.css +9 -0
- package/src/telemetry/client.test.ts +100 -0
- package/src/telemetry/client.ts +145 -0
- package/src/telemetry/config.ts +78 -0
- package/src/telemetry/events.test.ts +57 -0
- package/src/telemetry/events.ts +27 -0
- package/src/telemetry/system.ts +48 -0
- package/src/utils/studioTelemetry.ts +128 -0
- package/dist/assets/index-DVpLGNHi.css +0 -1
- package/dist/assets/index-EdfhuQ5T.js +0 -362
|
@@ -35,33 +35,13 @@ export interface TimelineTheme {
|
|
|
35
35
|
clipRadius: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
clip: TIMELINE_TEAL,
|
|
45
|
-
accent: TIMELINE_TEAL,
|
|
46
|
-
label: TIMELINE_TEAL_LABEL,
|
|
47
|
-
iconBackground: TIMELINE_TEAL_ICON_BACKGROUND,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const TRACK_STYLES: Record<string, TimelineTrackStyle> = {
|
|
52
|
-
video: createTrackStyle(),
|
|
53
|
-
audio: createTrackStyle(),
|
|
54
|
-
img: createTrackStyle(),
|
|
55
|
-
div: createTrackStyle(),
|
|
56
|
-
span: createTrackStyle(),
|
|
57
|
-
p: createTrackStyle(),
|
|
58
|
-
h1: createTrackStyle(),
|
|
59
|
-
section: createTrackStyle(),
|
|
60
|
-
sfx: createTrackStyle(),
|
|
38
|
+
const TRACK_STYLE: TimelineTrackStyle = {
|
|
39
|
+
clip: "#1c2028",
|
|
40
|
+
accent: "#3CE6AC",
|
|
41
|
+
label: "#dde1e8",
|
|
42
|
+
iconBackground: "rgba(255,255,255,0.06)",
|
|
61
43
|
};
|
|
62
44
|
|
|
63
|
-
const DEFAULT_TRACK_STYLE: TimelineTrackStyle = createTrackStyle();
|
|
64
|
-
|
|
65
45
|
export const defaultTimelineTheme: TimelineTheme = {
|
|
66
46
|
shellBackground: "#0A0A0B",
|
|
67
47
|
shellBorder: "rgba(255,255,255,0.05)",
|
|
@@ -75,33 +55,23 @@ export const defaultTimelineTheme: TimelineTheme = {
|
|
|
75
55
|
tickText: "rgba(131,145,168,0.92)",
|
|
76
56
|
tickMajor: "rgba(255,255,255,0.13)",
|
|
77
57
|
tickMinor: "rgba(255,255,255,0.08)",
|
|
78
|
-
clipBackground: "
|
|
79
|
-
clipBackgroundActive: "
|
|
80
|
-
clipBorder: "rgba(255,255,255,0.
|
|
81
|
-
clipBorderHover: "rgba(255,255,255,0.
|
|
82
|
-
clipBorderActive: "rgba(255,255,255,0.
|
|
83
|
-
clipShadow: "
|
|
84
|
-
clipShadowHover: "
|
|
85
|
-
clipShadowActive:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"inset 0 1px 0 rgba(255,255,255,0.04), 0 18px 36px rgba(0,0,0,0.34), 0 8px 16px rgba(0,0,0,0.18), 0 0 0 1px rgba(255,255,255,0.04)",
|
|
89
|
-
handleColor: "rgba(255,255,255,0.11)",
|
|
58
|
+
clipBackground: "#141922",
|
|
59
|
+
clipBackgroundActive: "#181e28",
|
|
60
|
+
clipBorder: "rgba(255,255,255,0.10)",
|
|
61
|
+
clipBorderHover: "rgba(255,255,255,0.18)",
|
|
62
|
+
clipBorderActive: "rgba(255,255,255,0.24)",
|
|
63
|
+
clipShadow: "none",
|
|
64
|
+
clipShadowHover: "0 2px 8px rgba(0,0,0,0.2)",
|
|
65
|
+
clipShadowActive: "0 2px 8px rgba(0,0,0,0.2), 0 0 0 1px rgba(255,255,255,0.04)",
|
|
66
|
+
clipShadowDragging: "0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.06)",
|
|
67
|
+
handleColor: "rgba(255,255,255,0.2)",
|
|
90
68
|
panelResizeSeam: "rgba(255,255,255,0.12)",
|
|
91
69
|
panelResizeActive: "rgba(255,255,255,0.24)",
|
|
92
|
-
clipRadius: "
|
|
70
|
+
clipRadius: "6px",
|
|
93
71
|
};
|
|
94
72
|
|
|
95
|
-
export function getTimelineTrackStyle(
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
normalized.startsWith("h") &&
|
|
99
|
-
normalized.length === 2 &&
|
|
100
|
-
"123456".includes(normalized[1] ?? "")
|
|
101
|
-
) {
|
|
102
|
-
return TRACK_STYLES.h1;
|
|
103
|
-
}
|
|
104
|
-
return TRACK_STYLES[normalized] ?? DEFAULT_TRACK_STYLE;
|
|
73
|
+
export function getTimelineTrackStyle(_tag: string): TimelineTrackStyle {
|
|
74
|
+
return TRACK_STYLE;
|
|
105
75
|
}
|
|
106
76
|
|
|
107
77
|
export function getClipHandleOpacity({
|
|
@@ -172,3 +172,58 @@ describe("usePlaybackKeyboard — keyboard layout independence (#834)", () => {
|
|
|
172
172
|
expect(spies.play).toHaveBeenCalledTimes(1);
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
|
+
|
|
176
|
+
describe("usePlaybackKeyboard — mute & loop shortcuts (#905)", () => {
|
|
177
|
+
it("M toggles audioMuted", () => {
|
|
178
|
+
const { dispatch } = setupHook();
|
|
179
|
+
expect(usePlayerStore.getState().audioMuted).toBe(false);
|
|
180
|
+
|
|
181
|
+
act(() => {
|
|
182
|
+
dispatch(keydown({ code: "KeyM", key: "m" }));
|
|
183
|
+
});
|
|
184
|
+
expect(usePlayerStore.getState().audioMuted).toBe(true);
|
|
185
|
+
|
|
186
|
+
act(() => {
|
|
187
|
+
dispatch(keydown({ code: "KeyM", key: "m" }));
|
|
188
|
+
});
|
|
189
|
+
expect(usePlayerStore.getState().audioMuted).toBe(false);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("M does NOT toggle audioMuted above 1x playback (matches button gating)", () => {
|
|
193
|
+
const { dispatch } = setupHook();
|
|
194
|
+
usePlayerStore.setState({ playbackRate: 2, audioMuted: false });
|
|
195
|
+
|
|
196
|
+
act(() => {
|
|
197
|
+
dispatch(keydown({ code: "KeyM", key: "m" }));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
expect(usePlayerStore.getState().audioMuted).toBe(false);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("Shift+L toggles loopEnabled without starting forward shuttle", () => {
|
|
204
|
+
const { dispatch, spies } = setupHook();
|
|
205
|
+
expect(usePlayerStore.getState().loopEnabled).toBe(false);
|
|
206
|
+
|
|
207
|
+
act(() => {
|
|
208
|
+
dispatch(keydown({ code: "KeyL", key: "L", shiftKey: true }));
|
|
209
|
+
});
|
|
210
|
+
expect(usePlayerStore.getState().loopEnabled).toBe(true);
|
|
211
|
+
expect(spies.play).not.toHaveBeenCalled();
|
|
212
|
+
|
|
213
|
+
act(() => {
|
|
214
|
+
dispatch(keydown({ code: "KeyL", key: "L", shiftKey: true }));
|
|
215
|
+
});
|
|
216
|
+
expect(usePlayerStore.getState().loopEnabled).toBe(false);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("Plain L still starts forward shuttle (regression guard)", () => {
|
|
220
|
+
const { dispatch, spies } = setupHook();
|
|
221
|
+
|
|
222
|
+
act(() => {
|
|
223
|
+
dispatch(keydown({ code: "KeyL", key: "l" }));
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(spies.play).toHaveBeenCalledTimes(1);
|
|
227
|
+
expect(usePlayerStore.getState().loopEnabled).toBe(false);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
@@ -108,6 +108,21 @@ export function usePlaybackKeyboard({
|
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
if (e.repeat) return;
|
|
111
|
+
if (key === "m") {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
const state = usePlayerStore.getState();
|
|
114
|
+
// Audio is force-muted above 1x playback — match the mute button's gating.
|
|
115
|
+
if (state.playbackRate <= 1) {
|
|
116
|
+
state.setAudioMuted(!state.audioMuted);
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (key === "l" && e.shiftKey) {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
const state = usePlayerStore.getState();
|
|
123
|
+
state.setLoopEnabled(!state.loopEnabled);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
111
126
|
if (key === "k") {
|
|
112
127
|
e.preventDefault();
|
|
113
128
|
pause();
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Input, UrlSource, ALL_FORMATS } from "mediabunny";
|
|
2
|
-
|
|
3
1
|
export interface MediaProbeResult {
|
|
4
2
|
duration: number;
|
|
5
3
|
width?: number;
|
|
@@ -11,6 +9,20 @@ export interface MediaProbeResult {
|
|
|
11
9
|
const cache = new Map<string, MediaProbeResult>();
|
|
12
10
|
const inflight = new Map<string, Promise<MediaProbeResult | null>>();
|
|
13
11
|
|
|
12
|
+
let mediabunnyModule: typeof import("mediabunny") | null | false = null;
|
|
13
|
+
|
|
14
|
+
async function loadMediabunny() {
|
|
15
|
+
if (mediabunnyModule === false) return null;
|
|
16
|
+
if (mediabunnyModule) return mediabunnyModule;
|
|
17
|
+
try {
|
|
18
|
+
mediabunnyModule = await import("mediabunny");
|
|
19
|
+
return mediabunnyModule;
|
|
20
|
+
} catch {
|
|
21
|
+
mediabunnyModule = false;
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
function normalizeUrl(url: string): string {
|
|
15
27
|
try {
|
|
16
28
|
return new URL(url, window.location.href).href;
|
|
@@ -20,9 +32,12 @@ function normalizeUrl(url: string): string {
|
|
|
20
32
|
}
|
|
21
33
|
|
|
22
34
|
async function probeOne(url: string): Promise<MediaProbeResult | null> {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
const mb = await loadMediabunny();
|
|
36
|
+
if (!mb) return null;
|
|
37
|
+
|
|
38
|
+
const input = new mb.Input({
|
|
39
|
+
source: new mb.UrlSource(url),
|
|
40
|
+
formats: mb.ALL_FORMATS,
|
|
26
41
|
});
|
|
27
42
|
try {
|
|
28
43
|
const duration = await input.getDurationFromMetadata();
|
|
@@ -280,6 +280,10 @@ export function parseTimelineFromDOM(doc: Document, rootDuration: number): Timel
|
|
|
280
280
|
applyMediaMetadataFromElement(entry, el);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
if (el.hasAttribute("data-timeline-locked")) {
|
|
284
|
+
entry.timelineLocked = true;
|
|
285
|
+
}
|
|
286
|
+
|
|
283
287
|
// Sub-compositions
|
|
284
288
|
const compSrc =
|
|
285
289
|
el.getAttribute("data-composition-src") || el.getAttribute("data-composition-file");
|
|
@@ -26,6 +26,8 @@ export interface TimelineElement {
|
|
|
26
26
|
compositionSrc?: string;
|
|
27
27
|
/** Whether this row came from authored clip timing or Studio's full-duration layer fallback. */
|
|
28
28
|
timingSource?: "authored" | "implicit";
|
|
29
|
+
/** Set by data-timeline-locked on the host element — disables move and trim in Studio. */
|
|
30
|
+
timelineLocked?: boolean;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export type ZoomMode = "fit" | "manual";
|
package/src/styles/studio.css
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
4
|
+
|
|
5
|
+
// `shouldTrack()` reads `POSTHOG_API_KEY` from module-level const that's
|
|
6
|
+
// evaluated at module load time, so changing `import.meta.env` after import
|
|
7
|
+
// has no effect on the key. Each test resets module cache and re-imports.
|
|
8
|
+
|
|
9
|
+
const OPT_OUT_KEY = "hyperframes-studio:telemetryDisabled";
|
|
10
|
+
|
|
11
|
+
function setKey(value: string | undefined): void {
|
|
12
|
+
if (value === undefined) {
|
|
13
|
+
delete (import.meta.env as Record<string, unknown>).VITE_HYPERFRAMES_POSTHOG_KEY;
|
|
14
|
+
} else {
|
|
15
|
+
(import.meta.env as Record<string, unknown>).VITE_HYPERFRAMES_POSTHOG_KEY = value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function setNoTelemetry(value: string | undefined): void {
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
delete (import.meta.env as Record<string, unknown>).VITE_HYPERFRAMES_NO_TELEMETRY;
|
|
22
|
+
} else {
|
|
23
|
+
(import.meta.env as Record<string, unknown>).VITE_HYPERFRAMES_NO_TELEMETRY = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function setDev(value: boolean): void {
|
|
28
|
+
(import.meta.env as { DEV: boolean }).DEV = value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function loadShouldTrack(): Promise<() => boolean> {
|
|
32
|
+
vi.resetModules();
|
|
33
|
+
const mod = await import("./client");
|
|
34
|
+
return mod.shouldTrack;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe("studio client shouldTrack", () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
setDev(false);
|
|
40
|
+
setKey("phc_test_key");
|
|
41
|
+
setNoTelemetry(undefined);
|
|
42
|
+
localStorage.clear();
|
|
43
|
+
vi.unstubAllGlobals();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns true when key is configured, not in dev mode, and no opt-outs", async () => {
|
|
47
|
+
const shouldTrack = await loadShouldTrack();
|
|
48
|
+
expect(shouldTrack()).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns false when API key does not start with phc_", async () => {
|
|
52
|
+
setKey("not_a_real_key");
|
|
53
|
+
const shouldTrack = await loadShouldTrack();
|
|
54
|
+
expect(shouldTrack()).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("returns false when API key is empty string", async () => {
|
|
58
|
+
setKey("");
|
|
59
|
+
const shouldTrack = await loadShouldTrack();
|
|
60
|
+
expect(shouldTrack()).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("returns false when user has opted out via localStorage", async () => {
|
|
64
|
+
localStorage.setItem(OPT_OUT_KEY, "1");
|
|
65
|
+
const shouldTrack = await loadShouldTrack();
|
|
66
|
+
expect(shouldTrack()).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("returns false when navigator.doNotTrack is '1'", async () => {
|
|
70
|
+
vi.stubGlobal("navigator", { ...navigator, doNotTrack: "1" });
|
|
71
|
+
const shouldTrack = await loadShouldTrack();
|
|
72
|
+
expect(shouldTrack()).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("returns false when VITE_HYPERFRAMES_NO_TELEMETRY=1 at build time", async () => {
|
|
76
|
+
setNoTelemetry("1");
|
|
77
|
+
const shouldTrack = await loadShouldTrack();
|
|
78
|
+
expect(shouldTrack()).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("returns false when VITE_HYPERFRAMES_NO_TELEMETRY='true'", async () => {
|
|
82
|
+
setNoTelemetry("true");
|
|
83
|
+
const shouldTrack = await loadShouldTrack();
|
|
84
|
+
expect(shouldTrack()).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("returns false in vite dev mode", async () => {
|
|
88
|
+
setDev(true);
|
|
89
|
+
const shouldTrack = await loadShouldTrack();
|
|
90
|
+
expect(shouldTrack()).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("memoizes its decision after the first call", async () => {
|
|
94
|
+
const shouldTrack = await loadShouldTrack();
|
|
95
|
+
const first = shouldTrack();
|
|
96
|
+
// Flip an underlying input — memoized return must not change.
|
|
97
|
+
localStorage.setItem(OPT_OUT_KEY, "1");
|
|
98
|
+
expect(shouldTrack()).toBe(first);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Lightweight PostHog client for the studio browser bundle.
|
|
3
|
+
// Mirrors `packages/cli/src/telemetry/client.ts` but uses fetch/sendBeacon.
|
|
4
|
+
// All calls are fire-and-forget; telemetry must never break the studio UI.
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
import { getAnonymousId, hasShownNotice, isOptedOut, markNoticeShown } from "./config";
|
|
8
|
+
import { getBrowserSystemMeta } from "./system";
|
|
9
|
+
|
|
10
|
+
// HeyGen's PostHog project key — write-only, safe to embed in client code.
|
|
11
|
+
// OSS builds can override via `VITE_HYPERFRAMES_POSTHOG_KEY` at build time,
|
|
12
|
+
// or set it to an empty string to disable telemetry entirely.
|
|
13
|
+
const POSTHOG_API_KEY =
|
|
14
|
+
(import.meta.env.VITE_HYPERFRAMES_POSTHOG_KEY as string | undefined) ??
|
|
15
|
+
"phc_zjjbX0PnWxERXrMHhkEJWj9A9BhGVLRReICgsfTMmpx";
|
|
16
|
+
const POSTHOG_HOST =
|
|
17
|
+
(import.meta.env.VITE_HYPERFRAMES_POSTHOG_HOST as string | undefined) ??
|
|
18
|
+
"https://us.i.posthog.com";
|
|
19
|
+
const FLUSH_INTERVAL_MS = 1_000;
|
|
20
|
+
|
|
21
|
+
type EventProperties = Record<string, string | number | boolean | undefined>;
|
|
22
|
+
|
|
23
|
+
interface QueuedEvent {
|
|
24
|
+
event: string;
|
|
25
|
+
properties: EventProperties;
|
|
26
|
+
timestamp: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let eventQueue: QueuedEvent[] = [];
|
|
30
|
+
let flushTimer: ReturnType<typeof setTimeout> | null = null;
|
|
31
|
+
let telemetryEnabled: boolean | null = null;
|
|
32
|
+
|
|
33
|
+
function isDoNotTrackOn(): boolean {
|
|
34
|
+
return typeof navigator !== "undefined" && navigator.doNotTrack === "1";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isApiKeyConfigured(): boolean {
|
|
38
|
+
return POSTHOG_API_KEY.startsWith("phc_");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// VITE_HYPERFRAMES_NO_TELEMETRY mirrors the CLI's HYPERFRAMES_NO_TELEMETRY=1
|
|
42
|
+
// opt-out so HeyGen's own dev/CI builds can suppress telemetry from the studio
|
|
43
|
+
// bundle the same way. Vite injects it at build time. Accepts "1" or "true".
|
|
44
|
+
function isBuildTimeOptOut(): boolean {
|
|
45
|
+
const v = import.meta.env.VITE_HYPERFRAMES_NO_TELEMETRY as string | undefined;
|
|
46
|
+
return v === "1" || v === "true";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// `import.meta.env.DEV` is true under `vite dev` / `vite preview`. Auto-suppress
|
|
50
|
+
// so developers running `hyperframes preview` don't pollute production telemetry.
|
|
51
|
+
function isViteDevMode(): boolean {
|
|
52
|
+
return import.meta.env.DEV === true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function shouldTrack(): boolean {
|
|
56
|
+
if (telemetryEnabled !== null) return telemetryEnabled;
|
|
57
|
+
telemetryEnabled =
|
|
58
|
+
isApiKeyConfigured() &&
|
|
59
|
+
!isBuildTimeOptOut() &&
|
|
60
|
+
!isViteDevMode() &&
|
|
61
|
+
!isOptedOut() &&
|
|
62
|
+
!isDoNotTrackOn();
|
|
63
|
+
return telemetryEnabled;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function trackEvent(event: string, properties: EventProperties = {}): void {
|
|
67
|
+
if (!shouldTrack()) return;
|
|
68
|
+
|
|
69
|
+
const sys = getBrowserSystemMeta();
|
|
70
|
+
eventQueue.push({
|
|
71
|
+
event,
|
|
72
|
+
properties: { ...properties, ...sys },
|
|
73
|
+
timestamp: new Date().toISOString(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (flushTimer === null) {
|
|
77
|
+
flushTimer = setTimeout(() => {
|
|
78
|
+
flushTimer = null;
|
|
79
|
+
flush();
|
|
80
|
+
}, FLUSH_INTERVAL_MS);
|
|
81
|
+
}
|
|
82
|
+
showNoticeOnce();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Fire-and-forget: the queue is cleared before `send()` resolves, so a network
|
|
86
|
+
// failure drops the batch rather than retrying. Matches the CLI client's
|
|
87
|
+
// design. Do NOT add retry logic here — a retry without cross-batch dedup
|
|
88
|
+
// would risk double-counting events on transient PostHog 5xx responses.
|
|
89
|
+
function flush(): void {
|
|
90
|
+
if (eventQueue.length === 0) return;
|
|
91
|
+
const distinctId = getAnonymousId();
|
|
92
|
+
const batch = eventQueue.map((e) => ({
|
|
93
|
+
event: e.event,
|
|
94
|
+
// $ip: null tells PostHog to not record the request IP.
|
|
95
|
+
properties: { ...e.properties, $ip: null },
|
|
96
|
+
distinct_id: distinctId,
|
|
97
|
+
timestamp: e.timestamp,
|
|
98
|
+
}));
|
|
99
|
+
eventQueue = [];
|
|
100
|
+
send(`${POSTHOG_HOST}/batch/`, JSON.stringify({ api_key: POSTHOG_API_KEY, batch }));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function send(url: string, payload: string): void {
|
|
104
|
+
// Prefer fetch with keepalive (survives page navigation). sendBeacon is a
|
|
105
|
+
// fallback for older runtimes where fetch isn't available.
|
|
106
|
+
try {
|
|
107
|
+
void fetch(url, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
body: payload,
|
|
111
|
+
keepalive: true,
|
|
112
|
+
}).catch(() => {
|
|
113
|
+
/* silent */
|
|
114
|
+
});
|
|
115
|
+
return;
|
|
116
|
+
} catch {
|
|
117
|
+
/* fall through */
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
navigator.sendBeacon(url, new Blob([payload], { type: "application/json" }));
|
|
121
|
+
} catch {
|
|
122
|
+
/* silent */
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function showNoticeOnce(): void {
|
|
127
|
+
if (hasShownNotice()) return;
|
|
128
|
+
markNoticeShown();
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
130
|
+
console.info(
|
|
131
|
+
"%c[HyperFrames]%c Anonymous studio usage analytics enabled. " +
|
|
132
|
+
"Disable: localStorage.setItem('hyperframes-studio:telemetryDisabled','1') (then reload).",
|
|
133
|
+
"color:#7c3aed;font-weight:bold",
|
|
134
|
+
"color:inherit",
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Flush queued events when the tab is being hidden or closed so tail events
|
|
139
|
+
// (e.g. a render_start fired moments before the user navigates away) aren't lost.
|
|
140
|
+
if (typeof window !== "undefined") {
|
|
141
|
+
window.addEventListener("pagehide", () => flush(), { capture: true });
|
|
142
|
+
window.addEventListener("visibilitychange", () => {
|
|
143
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") flush();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// LocalStorage-backed config for studio telemetry.
|
|
3
|
+
// Anonymous ID + opt-out flag are stored per-browser-profile.
|
|
4
|
+
// Users opt out via DevTools:
|
|
5
|
+
// localStorage.setItem('hyperframes-studio:telemetryDisabled','1')
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
const ANON_ID_KEY = "hyperframes-studio:anonymousId";
|
|
9
|
+
const OPT_OUT_KEY = "hyperframes-studio:telemetryDisabled";
|
|
10
|
+
const NOTICE_KEY = "hyperframes-studio:telemetryNoticeShown";
|
|
11
|
+
|
|
12
|
+
function safeLocalStorage(): Storage | null {
|
|
13
|
+
try {
|
|
14
|
+
return typeof localStorage === "undefined" ? null : localStorage;
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function newAnonymousId(): string {
|
|
21
|
+
if (typeof crypto !== "undefined" && "randomUUID" in crypto) return crypto.randomUUID();
|
|
22
|
+
return `anon-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getAnonymousId(): string {
|
|
26
|
+
const ls = safeLocalStorage();
|
|
27
|
+
if (!ls) return "anonymous";
|
|
28
|
+
const existing = ls.getItem(ANON_ID_KEY);
|
|
29
|
+
if (existing) return existing;
|
|
30
|
+
const id = newAnonymousId();
|
|
31
|
+
try {
|
|
32
|
+
ls.setItem(ANON_ID_KEY, id);
|
|
33
|
+
} catch {
|
|
34
|
+
/* private browsing / quota — return the in-memory ID for this session */
|
|
35
|
+
}
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isOptedOut(): boolean {
|
|
40
|
+
return safeLocalStorage()?.getItem(OPT_OUT_KEY) === "1";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function hasShownNotice(): boolean {
|
|
44
|
+
return safeLocalStorage()?.getItem(NOTICE_KEY) === "1";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function markNoticeShown(): void {
|
|
48
|
+
try {
|
|
49
|
+
safeLocalStorage()?.setItem(NOTICE_KEY, "1");
|
|
50
|
+
} catch {
|
|
51
|
+
/* ignore */
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Session-scoped (cleared when the tab closes) so HMR remounts and
|
|
56
|
+
// route-level remounts within one tab don't refire `studio_session_start`.
|
|
57
|
+
// Uses sessionStorage directly because the dedupe is per-tab, not per-browser.
|
|
58
|
+
const SESSION_FIRED_KEY = "hyperframes-studio:sessionStartFired";
|
|
59
|
+
|
|
60
|
+
function safeSessionStorage(): Storage | null {
|
|
61
|
+
try {
|
|
62
|
+
return typeof sessionStorage === "undefined" ? null : sessionStorage;
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function hasFiredSessionStart(): boolean {
|
|
69
|
+
return safeSessionStorage()?.getItem(SESSION_FIRED_KEY) === "1";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function markSessionStartFired(): void {
|
|
73
|
+
try {
|
|
74
|
+
safeSessionStorage()?.setItem(SESSION_FIRED_KEY, "1");
|
|
75
|
+
} catch {
|
|
76
|
+
/* ignore */
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
// Mock client.trackEvent so we can assert event names and payloads without
|
|
4
|
+
// firing network requests or relying on memoized shouldTrack() state.
|
|
5
|
+
const trackEvent = vi.fn();
|
|
6
|
+
vi.mock("./client", () => ({
|
|
7
|
+
trackEvent: (...args: unknown[]) => trackEvent(...args),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const { trackStudioSessionStart, trackStudioRenderStart } = await import("./events");
|
|
11
|
+
|
|
12
|
+
describe("studio telemetry events", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
trackEvent.mockClear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("trackStudioSessionStart emits 'studio_session_start' with has_project", () => {
|
|
18
|
+
trackStudioSessionStart({ has_project: true });
|
|
19
|
+
expect(trackEvent).toHaveBeenCalledOnce();
|
|
20
|
+
expect(trackEvent).toHaveBeenCalledWith("studio_session_start", { has_project: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("trackStudioSessionStart preserves false for has_project (scratch open)", () => {
|
|
24
|
+
trackStudioSessionStart({ has_project: false });
|
|
25
|
+
expect(trackEvent).toHaveBeenCalledWith("studio_session_start", { has_project: false });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("trackStudioRenderStart emits 'studio_render_start' with all render opts", () => {
|
|
29
|
+
trackStudioRenderStart({
|
|
30
|
+
fps: 30,
|
|
31
|
+
quality: "standard",
|
|
32
|
+
format: "mp4",
|
|
33
|
+
resolution: "landscape",
|
|
34
|
+
composition: "intro.html",
|
|
35
|
+
});
|
|
36
|
+
expect(trackEvent).toHaveBeenCalledOnce();
|
|
37
|
+
expect(trackEvent).toHaveBeenCalledWith("studio_render_start", {
|
|
38
|
+
fps: 30,
|
|
39
|
+
quality: "standard",
|
|
40
|
+
format: "mp4",
|
|
41
|
+
resolution: "landscape",
|
|
42
|
+
composition: "intro.html",
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("trackStudioRenderStart leaves optional fields undefined when omitted", () => {
|
|
47
|
+
trackStudioRenderStart({ fps: 60, quality: "high", format: "webm" });
|
|
48
|
+
const payload = trackEvent.mock.calls[0][1];
|
|
49
|
+
expect(payload).toEqual({
|
|
50
|
+
fps: 60,
|
|
51
|
+
quality: "high",
|
|
52
|
+
format: "webm",
|
|
53
|
+
resolution: undefined,
|
|
54
|
+
composition: undefined,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { trackEvent } from "./client";
|
|
2
|
+
|
|
3
|
+
// Studio frontend events. The corresponding `render_complete` / `render_error`
|
|
4
|
+
// events are emitted server-side by `packages/cli/src/server/studioServer.ts`
|
|
5
|
+
// with `source: "studio"` — keeping rich perf data on a single unified event.
|
|
6
|
+
|
|
7
|
+
export function trackStudioSessionStart(props: { has_project: boolean }): void {
|
|
8
|
+
trackEvent("studio_session_start", {
|
|
9
|
+
has_project: props.has_project,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function trackStudioRenderStart(props: {
|
|
14
|
+
fps: number;
|
|
15
|
+
quality: string;
|
|
16
|
+
format: string;
|
|
17
|
+
resolution?: string;
|
|
18
|
+
composition?: string;
|
|
19
|
+
}): void {
|
|
20
|
+
trackEvent("studio_render_start", {
|
|
21
|
+
fps: props.fps,
|
|
22
|
+
quality: props.quality,
|
|
23
|
+
format: props.format,
|
|
24
|
+
resolution: props.resolution,
|
|
25
|
+
composition: props.composition,
|
|
26
|
+
});
|
|
27
|
+
}
|