@inertiaui/vanilla 0.4.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 +45 -0
- package/dist/index.js +88 -2
- package/package.json +1 -1
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;
|
|
@@ -89,6 +117,12 @@ export declare function only<T extends Record<string, unknown>>(target: T, keys:
|
|
|
89
117
|
|
|
90
118
|
export declare function only(target: string[], keys: string[], ignoreCase?: boolean): string[];
|
|
91
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
|
+
|
|
92
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';
|
|
93
127
|
|
|
94
128
|
declare interface PositionOptions_2 {
|
|
@@ -104,6 +138,17 @@ export declare interface PositionResult {
|
|
|
104
138
|
placement: Placement;
|
|
105
139
|
}
|
|
106
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
|
+
|
|
107
152
|
export declare function rejectNullValues<T>(target: T[]): Exclude<T, null>[];
|
|
108
153
|
|
|
109
154
|
export declare function rejectNullValues<T extends Record<string, unknown>>(target: T): Partial<T>;
|
package/dist/index.js
CHANGED
|
@@ -467,7 +467,7 @@ function supportsAnchorPositioning() {
|
|
|
467
467
|
}
|
|
468
468
|
return _supportsAnchor;
|
|
469
469
|
}
|
|
470
|
-
function isRtl() {
|
|
470
|
+
function isRtl$1() {
|
|
471
471
|
return typeof document !== "undefined" && document.documentElement.dir === "rtl";
|
|
472
472
|
}
|
|
473
473
|
function getOppositePlacement(placement) {
|
|
@@ -491,7 +491,7 @@ function computePositionFromRect(refRect, floatingRect, placement, offset) {
|
|
|
491
491
|
let x = 0;
|
|
492
492
|
let y = 0;
|
|
493
493
|
const [side, alignment] = placement.split("-");
|
|
494
|
-
const rtl = isRtl();
|
|
494
|
+
const rtl = isRtl$1();
|
|
495
495
|
switch (side) {
|
|
496
496
|
case "bottom":
|
|
497
497
|
y = refRect.bottom + offset;
|
|
@@ -719,24 +719,110 @@ function autoUpdate(reference, floating, update) {
|
|
|
719
719
|
}
|
|
720
720
|
};
|
|
721
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
|
+
}
|
|
722
802
|
export {
|
|
723
803
|
animate,
|
|
724
804
|
autoUpdate,
|
|
805
|
+
blank,
|
|
725
806
|
cancelAnimations,
|
|
726
807
|
computePosition,
|
|
727
808
|
createFocusTrap,
|
|
728
809
|
createMenuNavigation,
|
|
810
|
+
debounce,
|
|
811
|
+
detectFramerate,
|
|
729
812
|
easings,
|
|
730
813
|
except,
|
|
731
814
|
generateId,
|
|
815
|
+
isRtl,
|
|
732
816
|
isStandardDomEvent,
|
|
733
817
|
kebabCase,
|
|
734
818
|
lockScroll,
|
|
735
819
|
markAriaHidden,
|
|
736
820
|
onClickOutside,
|
|
737
821
|
onEscapeKey,
|
|
822
|
+
onRtlChange,
|
|
738
823
|
onceChildrenRendered,
|
|
739
824
|
only,
|
|
825
|
+
prefersDarkMode,
|
|
740
826
|
rejectNullValues,
|
|
741
827
|
sameUrlPath,
|
|
742
828
|
supportsAnchorPositioning
|