mirror of
https://github.com/peritus/obsidian-interactive-ratings.git
synced 2026-07-22 05:43:17 +00:00
Extract calculateRatingFromHover function from RatingWidget.ts
This commit is contained in:
parent
ca5cd0fd46
commit
2e53c1e164
1 changed files with 35 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
import { isFullOnlySymbol } from '../../utils/isFullOnlySymbol';
|
||||
|
||||
/**
|
||||
* Calculate rating from hover position with full-only validation
|
||||
*/
|
||||
export function calculateRatingFromHover(
|
||||
event: MouseEvent,
|
||||
span: HTMLElement,
|
||||
symbolIndex: number,
|
||||
symbolSet: any
|
||||
): number {
|
||||
const isFullOnly = isFullOnlySymbol(symbolSet);
|
||||
|
||||
// For full-only symbols, don't support half ratings and enforce minimum rating of 1
|
||||
if (isFullOnly) {
|
||||
return Math.max(1, symbolIndex + 1);
|
||||
}
|
||||
|
||||
if (!symbolSet.half) {
|
||||
// No half-symbol support, return full symbol rating
|
||||
return symbolIndex + 1;
|
||||
}
|
||||
|
||||
const rect = span.getBoundingClientRect();
|
||||
const relativeX = event.clientX - rect.left;
|
||||
const symbolWidth = rect.width;
|
||||
const position = relativeX / symbolWidth;
|
||||
|
||||
// More responsive half-symbol detection for hover
|
||||
if (position <= 0.5) {
|
||||
return symbolIndex + 0.5;
|
||||
} else {
|
||||
return symbolIndex + 1;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue