style: format notebook contracts

This commit is contained in:
Evandro Fonseca Junior committed 2026-08-30 23:42:26 -03:00
1 parent 8b858528f8
commit c66ff7fde6
3 files changed
+79 -23

No files matched your search

+59 -13
View File
@@ -52,8 +52,19 @@ function getPhase(progress: number): NotebookPhase {
return "close";
}
function getActiveTabIndex(progress: number, tabCount: number, phase: NotebookPhase): number {
if (tabCount < 1 || phase === "approach" || phase === "open" || phase === "boot" || phase === "cursor-in" || phase === "close") {
function getActiveTabIndex(
progress: number,
tabCount: number,
phase: NotebookPhase,
): number {
if (
tabCount < 1 ||
phase === "approach" ||
phase === "open" ||
phase === "boot" ||
phase === "cursor-in" ||
phase === "close"
) {
return -1;
}
@@ -61,11 +72,16 @@ function getActiveTabIndex(progress: number, tabCount: number, phase: NotebookPh
return tabCount - 1;
}
const browseProgress = (progress - BROWSE_START) / (BROWSE_END - BROWSE_START);
const browseProgress =
(progress - BROWSE_START) / (BROWSE_END - BROWSE_START);
return clamp(Math.floor(browseProgress * tabCount), 0, tabCount - 1);
}
function getCursorPoint(progress: number, phase: NotebookPhase, activeTabIndex: number): { x: number; y: number } {
function getCursorPoint(
progress: number,
phase: NotebookPhase,
activeTabIndex: number,
): { x: number; y: number } {
if (phase === "cursor-in") {
const cursorProgress = (progress - 0.34) / 0.1;
return {
@@ -82,8 +98,18 @@ function getCursorPoint(progress: number, phase: NotebookPhase, activeTabIndex:
return point;
}
function isCursorClicking(progress: number, phase: NotebookPhase, tabCount: number): boolean {
if (tabCount < 1 || phase === "approach" || phase === "open" || phase === "boot" || phase === "close") {
function isCursorClicking(
progress: number,
phase: NotebookPhase,
tabCount: number,
): boolean {
if (
tabCount < 1 ||
phase === "approach" ||
phase === "open" ||
phase === "boot" ||
phase === "close"
) {
return false;
}
@@ -95,16 +121,24 @@ function isCursorClicking(progress: number, phase: NotebookPhase, tabCount: numb
return false;
}
const browseProgress = (progress - BROWSE_START) / (BROWSE_END - BROWSE_START);
const browseProgress =
(progress - BROWSE_START) / (BROWSE_END - BROWSE_START);
const slotProgress = (browseProgress * tabCount) % 1;
return slotProgress < 0.12;
}
export function getNotebookFrame(progress: number, tabCount: number): NotebookFrame {
export function getNotebookFrame(
progress: number,
tabCount: number,
): NotebookFrame {
const normalizedProgress = normalizeProgress(progress);
const normalizedTabCount = Math.max(0, Math.floor(tabCount));
const phase = getPhase(normalizedProgress);
const activeTabIndex = getActiveTabIndex(normalizedProgress, normalizedTabCount, phase);
const activeTabIndex = getActiveTabIndex(
normalizedProgress,
normalizedTabCount,
phase,
);
const isApproach = normalizedProgress < 0.1;
const isOpening = phase === "open";
const isBooting = phase === "boot";
@@ -112,7 +146,11 @@ export function getNotebookFrame(progress: number, tabCount: number): NotebookFr
const lidAngle = isOpening
? interpolate(0, OPEN_ANGLE, (normalizedProgress - 0.1) / 0.15)
: isClosing
? interpolate(OPEN_ANGLE, 0, (normalizedProgress - HOLD_END) / (1 - HOLD_END))
? interpolate(
OPEN_ANGLE,
0,
(normalizedProgress - HOLD_END) / (1 - HOLD_END),
)
: normalizedProgress >= 0.25
? OPEN_ANGLE
: 0;
@@ -128,8 +166,14 @@ export function getNotebookFrame(progress: number, tabCount: number): NotebookFr
: isClosing
? interpolate(1, 0.92, (normalizedProgress - HOLD_END) / (1 - HOLD_END))
: 1;
const cursorVisible = (phase === "cursor-in" || phase === "browse" || phase === "hold") && normalizedTabCount > 0;
const { x: cursorX, y: cursorY } = getCursorPoint(normalizedProgress, phase, activeTabIndex);
const cursorVisible =
(phase === "cursor-in" || phase === "browse" || phase === "hold") &&
normalizedTabCount > 0;
const { x: cursorX, y: cursorY } = getCursorPoint(
normalizedProgress,
phase,
activeTabIndex,
);
return {
phase,
@@ -140,6 +184,8 @@ export function getNotebookFrame(progress: number, tabCount: number): NotebookFr
cursorVisible,
cursorX,
cursorY,
cursorClicking: cursorVisible && isCursorClicking(normalizedProgress, phase, normalizedTabCount),
cursorClicking:
cursorVisible &&
isCursorClicking(normalizedProgress, phase, normalizedTabCount),
};
}