@solid-aria/utils
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -71,3 +71,3 @@ import * as _solid_primitives_utils from '@solid-primitives/utils'; | ||
/** | ||
* Syncs ref from context with ref passed to primitve. | ||
* Syncs ref from context with ref passed to primitive. | ||
*/ | ||
@@ -134,2 +134,9 @@ declare function createSyncRef<T>(context: ContextValue<T>, ref: Accessor<T | undefined>): void; | ||
/** | ||
* Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step. | ||
*/ | ||
declare function clamp(value: number, min?: number, max?: number): number; | ||
declare function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number; | ||
declare function toFixedNumber(value: number, digits: number, base?: number): number; | ||
declare function runAfterTransition(fn: () => void): void; | ||
@@ -144,2 +151,2 @@ | ||
export { AriaLabelsResult, CreateControllableSignalProps, ID_PREFIX, MergeAriaLabelsProps, callHandler, createControllableArraySignal, createControllableBooleanSignal, createControllableSetSignal, createControllableSignal, createDescription, createGlobalListeners, createId, createSlotId, createSyncRef, filterDOMProps, focusWithoutScrolling, getScrollParent, mergeAriaLabels, runAfterTransition, scrollIntoView }; | ||
export { AriaLabelsResult, CreateControllableSignalProps, ID_PREFIX, MergeAriaLabelsProps, callHandler, clamp, createControllableArraySignal, createControllableBooleanSignal, createControllableSetSignal, createControllableSignal, createDescription, createGlobalListeners, createId, createSlotId, createSyncRef, filterDOMProps, focusWithoutScrolling, getScrollParent, mergeAriaLabels, runAfterTransition, scrollIntoView, snapValueToStep, toFixedNumber }; |
@@ -112,2 +112,3 @@ "use strict"; | ||
// src/createId.ts | ||
import { isServer as isServer2, noop } from "@solid-primitives/utils"; | ||
import { createSignal as createSignal3, createUniqueId, getListener, onCleanup as onCleanup3 } from "solid-js"; | ||
@@ -120,2 +121,4 @@ var ID_PREFIX = "solid-aria"; | ||
const id = createId(prefix); | ||
if (isServer2) | ||
return [() => id, noop]; | ||
const [slotId, setSlotId] = createSignal3(id); | ||
@@ -283,2 +286,33 @@ const updateSlotId = () => setSlotId(document.getElementById(id) ? id : void 0); | ||
// src/number.ts | ||
function clamp(value, min = -Infinity, max = Infinity) { | ||
const newValue = Math.min(Math.max(value, min), max); | ||
return newValue; | ||
} | ||
function snapValueToStep(value, min, max, step) { | ||
const remainder = (value - (min == null || isNaN(min) ? 0 : min)) % step; | ||
let snappedValue = Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder; | ||
if (min != null && !isNaN(min)) { | ||
if (snappedValue < min) { | ||
snappedValue = min; | ||
} else if (max != null && !isNaN(max) && snappedValue > max) { | ||
snappedValue = min + Math.floor((max - min) / step) * step; | ||
} | ||
} else if (max != null && !isNaN(max) && snappedValue > max) { | ||
snappedValue = Math.floor(max / step) * step; | ||
} | ||
const string = step.toString(); | ||
const index = string.indexOf("."); | ||
const precision = index >= 0 ? string.length - index : 0; | ||
if (precision > 0) { | ||
const pow = Math.pow(10, precision); | ||
snappedValue = Math.round(snappedValue * pow) / pow; | ||
} | ||
return snappedValue; | ||
} | ||
function toFixedNumber(value, digits, base = 10) { | ||
const pow = Math.pow(base, digits); | ||
return Math.round(value * pow) / pow; | ||
} | ||
// src/runAfterTransition.ts | ||
@@ -386,2 +420,3 @@ var transitionsByElement = /* @__PURE__ */ new Map(); | ||
callHandler, | ||
clamp, | ||
createControllableArraySignal, | ||
@@ -401,3 +436,5 @@ createControllableBooleanSignal, | ||
runAfterTransition, | ||
scrollIntoView | ||
scrollIntoView, | ||
snapValueToStep, | ||
toFixedNumber | ||
}; |
{ | ||
"name": "@solid-aria/utils", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "A collection of utility types and functions, for building Solid Aria primitives.", |
Sorry, the diff of this file is not supported yet
40058
1023