@hyperframes/studio 0.6.5 → 0.6.6

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.
@@ -185,15 +185,21 @@ export function useTimelinePlayer() {
185
185
  const time = adapter.getTime();
186
186
  const dur = adapter.getDuration();
187
187
  liveTime.notify(time); // direct DOM updates, no React re-render
188
- if (time >= dur && !adapter.isPlaying()) {
188
+ const { inPoint, outPoint } = usePlayerStore.getState();
189
+ const rawLoopEnd = outPoint !== null ? outPoint : dur;
190
+ const rawLoopStart = inPoint !== null ? inPoint : 0;
191
+ const loopEnd = rawLoopStart < rawLoopEnd ? rawLoopEnd : dur;
192
+ const loopStart = rawLoopStart < rawLoopEnd ? rawLoopStart : 0;
193
+ if (time >= loopEnd) {
189
194
  if (usePlayerStore.getState().loopEnabled && dur > 0) {
190
- adapter.seek(0);
191
- liveTime.notify(0);
195
+ adapter.seek(loopStart);
196
+ liveTime.notify(loopStart);
192
197
  adapter.play();
193
198
  setIsPlaying(true);
194
199
  rafRef.current = requestAnimationFrame(tick);
195
200
  return;
196
201
  }
202
+ if (adapter.isPlaying()) adapter.pause();
197
203
  setCurrentTime(time); // sync Zustand once at end
198
204
  setIsPlaying(false);
199
205
  cancelAnimationFrame(rafRef.current);
@@ -241,7 +247,7 @@ export function useTimelinePlayer() {
241
247
  const adapter = getAdapter();
242
248
  if (!adapter) return;
243
249
  if (adapter.getTime() >= adapter.getDuration()) {
244
- adapter.seek(0);
250
+ adapter.seek(usePlayerStore.getState().inPoint ?? 0);
245
251
  }
246
252
  unmutePreviewMedia(iframeRef.current);
247
253
  applyPlaybackRate(usePlayerStore.getState().playbackRate);
@@ -269,15 +275,20 @@ export function useTimelinePlayer() {
269
275
  const tick = (now: number) => {
270
276
  const elapsed = ((now - startedAt) / 1000) * speed;
271
277
  let nextTime = startTime - elapsed;
272
- if (nextTime <= 0) {
278
+ const { inPoint, outPoint } = usePlayerStore.getState();
279
+ const rawLoopEnd = outPoint !== null ? outPoint : duration;
280
+ const rawLoopStart = inPoint !== null ? inPoint : 0;
281
+ const loopEnd = rawLoopStart < rawLoopEnd ? rawLoopEnd : duration;
282
+ const loopStart = rawLoopStart < rawLoopEnd ? rawLoopStart : 0;
283
+ if (nextTime <= loopStart) {
273
284
  if (usePlayerStore.getState().loopEnabled && duration > 0) {
274
- startTime = duration;
285
+ startTime = loopEnd;
275
286
  startedAt = now;
276
- nextTime = duration;
287
+ nextTime = loopEnd;
277
288
  } else {
278
- adapter.seek(0);
279
- liveTime.notify(0);
280
- setCurrentTime(0);
289
+ adapter.seek(loopStart);
290
+ liveTime.notify(loopStart);
291
+ setCurrentTime(loopStart);
281
292
  setIsPlaying(false);
282
293
  shuttleDirectionRef.current = null;
283
294
  reverseRafRef.current = 0;
@@ -43,6 +43,10 @@ interface PlayerState {
43
43
  zoomMode: ZoomMode;
44
44
  /** Timeline zoom percent relative to the fit width when in manual mode */
45
45
  manualZoomPercent: number;
46
+ /** Work-area in-point (seconds). When set, loop starts here and A jumps here. */
47
+ inPoint: number | null;
48
+ /** Work-area out-point (seconds). When set, loop ends here and E jumps here. */
49
+ outPoint: number | null;
46
50
 
47
51
  setIsPlaying: (playing: boolean) => void;
48
52
  setCurrentTime: (time: number) => void;
@@ -58,6 +62,8 @@ interface PlayerState {
58
62
  ) => void;
59
63
  setZoomMode: (mode: ZoomMode) => void;
60
64
  setManualZoomPercent: (percent: number) => void;
65
+ setInPoint: (time: number | null) => void;
66
+ setOutPoint: (time: number | null) => void;
61
67
  reset: () => void;
62
68
 
63
69
  /**
@@ -93,6 +99,8 @@ export const usePlayerStore = create<PlayerState>((set) => ({
93
99
  loopEnabled: false,
94
100
  zoomMode: "fit",
95
101
  manualZoomPercent: 100,
102
+ inPoint: null,
103
+ outPoint: null,
96
104
 
97
105
  requestedSeekTime: null,
98
106
  requestSeek: (time) => set({ requestedSeekTime: time }),
@@ -105,6 +113,23 @@ export const usePlayerStore = create<PlayerState>((set) => ({
105
113
  },
106
114
  setLoopEnabled: (enabled) => set({ loopEnabled: enabled }),
107
115
  setZoomMode: (mode) => set({ zoomMode: mode }),
116
+ setInPoint: (time) =>
117
+ set((state) => {
118
+ const t = time !== null && Number.isFinite(time) ? time : null;
119
+ return {
120
+ inPoint: t,
121
+ outPoint:
122
+ t !== null && state.outPoint !== null && t >= state.outPoint ? null : state.outPoint,
123
+ };
124
+ }),
125
+ setOutPoint: (time) =>
126
+ set((state) => {
127
+ const t = time !== null && Number.isFinite(time) ? time : null;
128
+ return {
129
+ outPoint: t,
130
+ inPoint: t !== null && state.inPoint !== null && t <= state.inPoint ? null : state.inPoint,
131
+ };
132
+ }),
108
133
  setManualZoomPercent: (percent) =>
109
134
  set({ manualZoomPercent: Math.max(10, Math.min(2000, Math.round(percent))) }),
110
135
  setCurrentTime: (time) => set({ currentTime: Number.isFinite(time) ? time : 0 }),
@@ -129,5 +154,7 @@ export const usePlayerStore = create<PlayerState>((set) => ({
129
154
  timelineReady: false,
130
155
  elements: [],
131
156
  selectedElementId: null,
157
+ inPoint: null,
158
+ outPoint: null,
132
159
  }),
133
160
  }));