Skip to content

Commit

Permalink
Fix slow C changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Oct 4, 2024
1 parent 3a6a389 commit e4cffa7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions stores/current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ function round2(value: number): number {
return parseFloat(value.toFixed(2))
}

function round3(value: number): number {
return parseFloat(value.toFixed(3))
function round4(value: number): number {
return parseFloat(value.toFixed(4))
}

function roundValue<V extends Partial<LchValue>>(
Expand All @@ -171,7 +171,7 @@ function roundValue<V extends Partial<LchValue>>(
rounded.l = round2(rounded.l)
}
if (typeof rounded.c !== 'undefined') {
rounded.c = type === 'oklch' ? round3(rounded.c) : round2(rounded.c)
rounded.c = type === 'oklch' ? round4(rounded.c) : round2(rounded.c)
}
if (typeof rounded.h !== 'undefined') {
rounded.h = round2(rounded.h)
Expand Down
6 changes: 3 additions & 3 deletions view/card/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ type ClampAngleFn = (
range: Omit<MetaSpinInput, 'step'>
) => number

function clampInRange(useWheel: boolean): ClampAngleFn {
function clampInRange(useWheel: boolean, precision: number): ClampAngleFn {
return (value, range) => {
let angle = useWheel ? cycleByWheel(value, range.max) : value
let clamped = Math.max(range.min, Math.min(range.max, angle))

return clean(clamped)
return clean(clamped, precision)
}
}

function initInput(type: 'a' | 'c' | 'h' | 'l'): HTMLInputElement {
let card = document.querySelector<HTMLDivElement>(`.card.is-${type}`)!
let text = card.querySelector<HTMLInputElement>('[role=spinbutton]')!
let bindedClamp = clampInRange(type === 'h')
let bindedClamp = clampInRange(type === 'h', type === 'c' ? 4 : 2)

text.addEventListener('change', () => {
let { max, min } = getInputMeta(text)
Expand Down

0 comments on commit e4cffa7

Please sign in to comment.