@inertiaui/vanilla 0.3.0 → 0.5.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/dist/index.d.ts CHANGED
@@ -21,6 +21,12 @@ export declare interface AnimateOptions {
21
21
 
22
22
  export declare function autoUpdate(reference: HTMLElement, floating: HTMLElement, update: () => void): CleanupFunction;
23
23
 
24
+ /**
25
+ * Port of Laravel's `blank` function.
26
+ * Returns true if the value is "empty" — null, undefined, empty string, empty array/object, etc.
27
+ */
28
+ export declare function blank(value: unknown): boolean;
29
+
24
30
  /**
25
31
  * Cancel any running animations on an element
26
32
  */
@@ -34,6 +40,23 @@ export declare function createFocusTrap(container: HTMLElement, options?: FocusT
34
40
 
35
41
  export declare function createMenuNavigation(container: HTMLElement, options?: MenuNavigationOptions): CleanupFunction;
36
42
 
43
+ export declare type DarkModeStrategy = 'auto' | 'class' | 'selector' | 'media' | (() => boolean);
44
+
45
+ /**
46
+ * Debounce a function using requestAnimationFrame.
47
+ * Ensures the function runs at most once per animation frame.
48
+ *
49
+ * @see https://pqina.nl/blog/applying-styles-based-on-the-user-scroll-position-with-smart-css/
50
+ */
51
+ export declare function debounce<T extends (...args: unknown[]) => void>(fn: T): (...args: Parameters<T>) => void;
52
+
53
+ /**
54
+ * Detect the browser's current framerate.
55
+ * Returns a Promise that resolves with the detected FPS (capped to 30–240 range).
56
+ * Falls back to 60 if requestAnimationFrame is unavailable or detection times out.
57
+ */
58
+ export declare function detectFramerate(): Promise<number>;
59
+
37
60
  export declare type EasingName = keyof typeof easings;
38
61
 
39
62
  /**
@@ -63,6 +86,11 @@ export declare interface FocusTrapOptions {
63
86
 
64
87
  export declare function generateId(prefix?: string): string;
65
88
 
89
+ /**
90
+ * Check whether the document is currently in RTL direction.
91
+ */
92
+ export declare function isRtl(): boolean;
93
+
66
94
  export declare function isStandardDomEvent(eventName: string): boolean;
67
95
 
68
96
  export declare function kebabCase(string: string): string;
@@ -79,6 +107,8 @@ export declare interface MenuNavigationOptions {
79
107
  onActivate?: (item: HTMLElement) => void;
80
108
  }
81
109
 
110
+ export declare function onceChildrenRendered(element: Element, callback: () => void): void;
111
+
82
112
  export declare function onClickOutside(elements: HTMLElement | HTMLElement[], callback: (event: PointerEvent) => void): CleanupFunction;
83
113
 
84
114
  export declare function onEscapeKey(callback: (event: KeyboardEvent) => void, options?: EscapeKeyOptions): CleanupFunction;
@@ -87,6 +117,12 @@ export declare function only<T extends Record<string, unknown>>(target: T, keys:
87
117
 
88
118
  export declare function only(target: string[], keys: string[], ignoreCase?: boolean): string[];
89
119
 
120
+ /**
121
+ * Observe changes to the document's `dir` attribute and invoke the callback
122
+ * whenever it changes. Returns a cleanup function to stop observing.
123
+ */
124
+ export declare function onRtlChange(callback: (rtl: boolean) => void): CleanupFunction;
125
+
90
126
  export declare type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end';
91
127
 
92
128
  declare interface PositionOptions_2 {
@@ -102,6 +138,17 @@ export declare interface PositionResult {
102
138
  placement: Placement;
103
139
  }
104
140
 
141
+ /**
142
+ * Detect whether the user prefers dark mode.
143
+ *
144
+ * Strategies:
145
+ * - `'class'` / `'selector'` — checks `<html class="dark">`
146
+ * - `'media'` — checks `prefers-color-scheme: dark` media query
147
+ * - `'auto'` (default) — checks class first, then media query
148
+ * - custom function — called directly for full control
149
+ */
150
+ export declare function prefersDarkMode(strategy?: DarkModeStrategy): boolean;
151
+
105
152
  export declare function rejectNullValues<T>(target: T[]): Exclude<T, null>[];
106
153
 
107
154
  export declare function rejectNullValues<T extends Record<string, unknown>>(target: T): Partial<T>;
package/dist/index.js CHANGED
@@ -65,6 +65,19 @@ function isStandardDomEvent(eventName) {
65
65
  ];
66
66
  return standardPatterns.some((pattern) => pattern.test(lowerEventName));
67
67
  }
68
+ function onceChildrenRendered(element, callback) {
69
+ if (element.children.length > 0) {
70
+ callback();
71
+ return;
72
+ }
73
+ const observer = new MutationObserver(() => {
74
+ if (element.children.length > 0) {
75
+ observer.disconnect();
76
+ callback();
77
+ }
78
+ });
79
+ observer.observe(element, { childList: true });
80
+ }
68
81
  function sameUrlPath(url1, url2) {
69
82
  if (!url1 || !url2) {
70
83
  return false;
@@ -454,7 +467,7 @@ function supportsAnchorPositioning() {
454
467
  }
455
468
  return _supportsAnchor;
456
469
  }
457
- function isRtl() {
470
+ function isRtl$1() {
458
471
  return typeof document !== "undefined" && document.documentElement.dir === "rtl";
459
472
  }
460
473
  function getOppositePlacement(placement) {
@@ -478,7 +491,7 @@ function computePositionFromRect(refRect, floatingRect, placement, offset) {
478
491
  let x = 0;
479
492
  let y = 0;
480
493
  const [side, alignment] = placement.split("-");
481
- const rtl = isRtl();
494
+ const rtl = isRtl$1();
482
495
  switch (side) {
483
496
  case "bottom":
484
497
  y = refRect.bottom + offset;
@@ -706,23 +719,110 @@ function autoUpdate(reference, floating, update) {
706
719
  }
707
720
  };
708
721
  }
722
+ function blank(value) {
723
+ if (value === null || value === void 0) {
724
+ return true;
725
+ }
726
+ if (typeof value === "string") {
727
+ return value.trim() === "";
728
+ }
729
+ if (typeof value === "number" || typeof value === "boolean") {
730
+ return false;
731
+ }
732
+ if (Array.isArray(value) || typeof value === "object" && value !== null && typeof value.length === "number") {
733
+ return value.length === 0;
734
+ }
735
+ return !value;
736
+ }
737
+ function debounce(fn) {
738
+ let frame;
739
+ return (...params) => {
740
+ if (frame) {
741
+ cancelAnimationFrame(frame);
742
+ }
743
+ frame = requestAnimationFrame(() => {
744
+ fn(...params);
745
+ });
746
+ };
747
+ }
748
+ function detectFramerate() {
749
+ return new Promise((resolve) => {
750
+ if (typeof window === "undefined" || !window.requestAnimationFrame) {
751
+ return resolve(60);
752
+ }
753
+ const timestamps = [];
754
+ let rafId;
755
+ function measure(now) {
756
+ timestamps.unshift(now);
757
+ if (timestamps.length > 10) {
758
+ const lastTime = timestamps.pop();
759
+ const fps = Math.floor(1e3 * 10 / (now - lastTime));
760
+ cancelAnimationFrame(rafId);
761
+ resolve(Math.min(Math.max(fps, 30), 240));
762
+ return;
763
+ }
764
+ rafId = window.requestAnimationFrame(measure);
765
+ }
766
+ rafId = window.requestAnimationFrame(measure);
767
+ setTimeout(() => {
768
+ if (rafId !== void 0) {
769
+ cancelAnimationFrame(rafId);
770
+ }
771
+ resolve(60);
772
+ }, 1e3);
773
+ });
774
+ }
775
+ function prefersDarkMode(strategy = "auto") {
776
+ if (typeof strategy === "function") {
777
+ return strategy();
778
+ }
779
+ const containsDarkClass = () => document.documentElement.classList.contains("dark");
780
+ const matchesDarkMediaQuery = () => window.matchMedia("(prefers-color-scheme: dark)").matches;
781
+ if (strategy === "class" || strategy === "selector") {
782
+ return containsDarkClass();
783
+ }
784
+ if (strategy === "media") {
785
+ return matchesDarkMediaQuery();
786
+ }
787
+ return containsDarkClass() || matchesDarkMediaQuery();
788
+ }
789
+ function isRtl() {
790
+ return document.documentElement.dir === "rtl";
791
+ }
792
+ function onRtlChange(callback) {
793
+ const observer = new MutationObserver(() => {
794
+ callback(document.documentElement.dir === "rtl");
795
+ });
796
+ observer.observe(document.documentElement, {
797
+ attributes: true,
798
+ attributeFilter: ["dir"]
799
+ });
800
+ return () => observer.disconnect();
801
+ }
709
802
  export {
710
803
  animate,
711
804
  autoUpdate,
805
+ blank,
712
806
  cancelAnimations,
713
807
  computePosition,
714
808
  createFocusTrap,
715
809
  createMenuNavigation,
810
+ debounce,
811
+ detectFramerate,
716
812
  easings,
717
813
  except,
718
814
  generateId,
815
+ isRtl,
719
816
  isStandardDomEvent,
720
817
  kebabCase,
721
818
  lockScroll,
722
819
  markAriaHidden,
723
820
  onClickOutside,
724
821
  onEscapeKey,
822
+ onRtlChange,
823
+ onceChildrenRendered,
725
824
  only,
825
+ prefersDarkMode,
726
826
  rejectNullValues,
727
827
  sameUrlPath,
728
828
  supportsAnchorPositioning
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiaui/vanilla",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "author": "Pascal Baljet <pascal@protone.media>",
5
5
  "private": false,
6
6
  "license": "MIT",