Utils

Public helpers exported from the root entry and the ./utils subpath.

Since 1.0.0BETA

This component doc is in progress

This page is still being migrated. Demos and API details may change.

import { nextZIndex, toast, hasWindow } from '@talex-touch/tuffex/utils'

API Reference

Z-index manager

One source of overlay stacking levels, so components never hard-code z-index.

ExportSignatureWhen to use
nextZIndex()() => numberClaim the next level for a new overlay
getZIndex()() => numberRead the current top level without incrementing
refreshZIndex(seed?, reason?)(seed?: number, reason?: string) => numberRecount from a given baseline
resetZIndex(seed?, reason?)(seed?: number, reason?: string) => numberReset to the seed after unmount or in tests
configureZIndex(options)(options) => voidSet the base seed and overrides globally
onZIndexEvent(listener)(listener) => () => voidSubscribe to level changes; returns an unsubscribe

Environment guards

SSR-safe checks before touching window / document / navigator.

ExportSignatureWhen to use
hasWindow()() => booleanGuard before touching window
hasDocument()() => booleanGuard before touching document
hasNavigator()() => booleanGuard before navigator (vibrate, clipboard)

Haptics (vibrate)

Semantic patterns over navigator.vibrate.

ExportSignatureWhen to use
vibrate{ light() … error(), stop, isSupported }Fire a preset directly, e.g. vibrate.success()
useVibrate(type, options?)(type: VibrateType, options?) => voidTrigger one configurable semantic vibration
stopVibrate()() => voidInterrupt an in-progress vibration
isVibrateSupported()() => booleanCapability detection

Toast

A global toast queue with no per-page host; rendering still needs TxToastHost.

ExportSignatureWhen to use
toast(options)(options) => stringShow a toast; returns an id for dismissing it
dismissToast(id)(id: string) => voidDismiss one toast
clearToasts()() => voidClear every toast

Dialog manager

Queues global dialogs by priority and runs them one at a time, with lifecycle callbacks.

ExportSignatureWhen to use
getDialogManager()() => DialogManagerGet the global singleton to queue or open dialogs

Animation

ExportSignatureWhen to use
useFlip(targetRef, opts?)(ref, opts?) => UseFlipReturnRun a FLIP transition on an element (powers TxFlipOverlay)
useAutoResize(targetRef, opts?)(ref, opts?) => UseAutoResizeReturnMeasure and transition size changes (powers TxAutoSizer)
stepSpring(position, velocity, target, spring, dt)(position, velocity, target, spring, dt) => [number, number]Step a value along a spring ({ stiffness, damping, mass? }, dt in seconds) from your own frame loop, keeping velocity when the target moves; usable as useJellyIndicator's glide integrate
resolveGsapEase(value)(value: string) => string | ((t: number) => number)Convert an ease before handing it to GSAP: spring(...) and cubic-bezier(...) become progress functions (GSAP knows neither and silently uses its default); GSAP names pass through
resolveCssEase(spec)(spec: string | undefined | null) => (t: number) => numberEvaluate a CSS timing function in JS: cubic-bezier(...), evenly spaced linear(...), and linear / ease / ease-in / ease-out / ease-in-out; anything else degrades to clamped linear, never null. Cached per spec, safe per frame
createSpringEase(omega?, zeta?)(omega = 10, zeta = 0.72) => (t: number) => numberClosed-form underdamped spring normalized to the timeline: overshoots 1, settles, lands on exactly 1. Unlike frame-stepped stepSpring, usable directly as an ease
parseSpringEase(value)(value: string | undefined | null) => ((t: number) => number) | nullParse spring / spring(omega) / spring(omega, zeta); anything else returns null
createCubicBezier(x1, y1, x2, y2)(x1, y1, x2, y2) => (t: number) => numberEquivalent to CSS cubic-bezier(); the charts entry's cubicBezier is this function
parseCubicBezier(value)(value: string | undefined | null) => [number, number, number, number] | nullParse a cubic-bezier(...) string; GSAP names, keywords, spring forms, or x controls outside 0, 1 return null

Install helper

ExportSignatureWhen to use
withInstall(component)<T>(component: T) => T & { install }Attach install so a component works with app.use()

Technologies

  • Barrel: packages/tuffex/packages/components/src/utils/index.ts re-exports packages/tuffex/packages/utils/*.
  • Subpath entry @talex-touch/tuffex/utils; the root @talex-touch/tuffex entry exports the same helpers.