@inertiaui/vanilla 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,8 +25,13 @@ npm install @inertiaui/vanilla
25
25
  - [Positioning](#positioning)
26
26
  - [Accessibility](#accessibility)
27
27
  - [Animation](#animation)
28
+ - [Dark Mode Detection](#dark-mode-detection)
29
+ - [RTL Support](#rtl-support)
30
+ - [Debounce](#debounce)
28
31
  - [Helpers](#helpers)
29
32
  - [generateId](#generateid)
33
+ - [blank](#blank)
34
+ - [onceChildrenRendered](#oncechildrenrendered)
30
35
  - [Object Filtering](#object-filtering)
31
36
  - [String Utilities](#string-utilities)
32
37
  - [URL Utilities](#url-utilities)
@@ -653,6 +658,96 @@ function forceHideModal(modal: HTMLElement) {
653
658
  }
654
659
  ```
655
660
 
661
+ ## Dark Mode Detection
662
+
663
+ The `prefersDarkMode` function detects whether the user prefers dark mode, with support for multiple detection strategies.
664
+
665
+ ### Basic Usage
666
+
667
+ ```typescript
668
+ import { prefersDarkMode } from '@inertiaui/vanilla'
669
+
670
+ const isDark = prefersDarkMode()
671
+ ```
672
+
673
+ ### Strategies
674
+
675
+ | Strategy | Behavior |
676
+ |----------|----------|
677
+ | `'auto'` (default) | Checks `<html class="dark">` first, then `prefers-color-scheme: dark` media query |
678
+ | `'class'` / `'selector'` | Checks `<html class="dark">` |
679
+ | `'media'` | Checks `prefers-color-scheme: dark` media query |
680
+ | Custom function | Called directly for full control |
681
+
682
+ ```typescript
683
+ // Class-based detection (e.g., Tailwind dark mode)
684
+ prefersDarkMode('class')
685
+
686
+ // Media query only
687
+ prefersDarkMode('media')
688
+
689
+ // Custom logic
690
+ prefersDarkMode(() => document.body.dataset.theme === 'dark')
691
+ ```
692
+
693
+ ## RTL Support
694
+
695
+ Utilities for detecting and observing right-to-left document direction.
696
+
697
+ ### isRtl
698
+
699
+ Check whether the document is currently in RTL direction:
700
+
701
+ ```typescript
702
+ import { isRtl } from '@inertiaui/vanilla'
703
+
704
+ if (isRtl()) {
705
+ // Document is right-to-left
706
+ }
707
+ ```
708
+
709
+ ### onRtlChange
710
+
711
+ Observe changes to the document's `dir` attribute and invoke a callback whenever it changes. Returns a cleanup function.
712
+
713
+ ```typescript
714
+ import { onRtlChange } from '@inertiaui/vanilla'
715
+
716
+ const cleanup = onRtlChange((rtl) => {
717
+ console.log('RTL changed:', rtl)
718
+ })
719
+
720
+ // Later, stop observing
721
+ cleanup()
722
+ ```
723
+
724
+ ## Debounce
725
+
726
+ ### debounce
727
+
728
+ Debounce a function using `requestAnimationFrame`. Ensures the function runs at most once per animation frame.
729
+
730
+ ```typescript
731
+ import { debounce } from '@inertiaui/vanilla'
732
+
733
+ const handleScroll = debounce(() => {
734
+ updatePosition()
735
+ })
736
+
737
+ window.addEventListener('scroll', handleScroll)
738
+ ```
739
+
740
+ ### detectFramerate
741
+
742
+ Detect the browser's current framerate. Returns a Promise that resolves with the detected FPS (capped to the 30–240 range). Falls back to 60 if `requestAnimationFrame` is unavailable or detection times out.
743
+
744
+ ```typescript
745
+ import { detectFramerate } from '@inertiaui/vanilla'
746
+
747
+ const fps = await detectFramerate()
748
+ console.log(`Running at ${fps} FPS`)
749
+ ```
750
+
656
751
  ## Helpers
657
752
 
658
753
  ### generateId
@@ -706,6 +801,36 @@ title.id = titleId
706
801
  description.id = descId
707
802
  ```
708
803
 
804
+ ### blank
805
+
806
+ A port of Laravel's `blank` function. Returns `true` if the value is "empty" — `null`, `undefined`, empty string (or whitespace-only), empty array, or empty object.
807
+
808
+ ```typescript
809
+ import { blank } from '@inertiaui/vanilla'
810
+
811
+ blank(null) // true
812
+ blank(undefined) // true
813
+ blank('') // true
814
+ blank(' ') // true
815
+ blank([]) // true
816
+ blank('hello') // false
817
+ blank(0) // false
818
+ blank(false) // false
819
+ ```
820
+
821
+ ### onceChildrenRendered
822
+
823
+ Invokes a callback once the given element has child elements. If the element already has children, the callback fires immediately. Otherwise, it uses a `MutationObserver` to wait for children to appear.
824
+
825
+ ```typescript
826
+ import { onceChildrenRendered } from '@inertiaui/vanilla'
827
+
828
+ onceChildrenRendered(containerElement, () => {
829
+ // Children are now present in the DOM
830
+ initializeContent()
831
+ })
832
+ ```
833
+
709
834
  ### Object Filtering
710
835
 
711
836
  #### except
@@ -981,6 +1106,7 @@ import type {
981
1106
  Placement,
982
1107
  PositionOptions,
983
1108
  PositionResult,
1109
+ DarkModeStrategy,
984
1110
  } from '@inertiaui/vanilla'
985
1111
  ```
986
1112
 
package/dist/index.d.ts CHANGED
@@ -86,6 +86,25 @@ export declare interface FocusTrapOptions {
86
86
 
87
87
  export declare function generateId(prefix?: string): string;
88
88
 
89
+ /**
90
+ * Convert a hex color string to HSL values.
91
+ * Accepts with or without leading '#'.
92
+ */
93
+ export declare function hexToHsl(hex: string): HslColor;
94
+
95
+ export declare interface HslColor {
96
+ h: number;
97
+ s: number;
98
+ l: number;
99
+ }
100
+
101
+ /**
102
+ * Convert HSL values to a hex color string.
103
+ * h: 0-360, s: 0-100, l: 0-100
104
+ * Returns string with leading '#'.
105
+ */
106
+ export declare function hslToHex(h: number, s: number, l: number): string;
107
+
89
108
  /**
90
109
  * Check whether the document is currently in RTL direction.
91
110
  */