@reshaped/utilities 3.9.1-canary.2
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/LICENSE.md +21 -0
- package/dist/dom/getShadowRoot.d.ts +2 -0
- package/dist/dom/getShadowRoot.js +5 -0
- package/dist/flyout/Flyout.d.ts +13 -0
- package/dist/flyout/Flyout.js +101 -0
- package/dist/flyout/constants.d.ts +9 -0
- package/dist/flyout/constants.js +9 -0
- package/dist/flyout/index.d.ts +1 -0
- package/dist/flyout/index.js +1 -0
- package/dist/flyout/tests/Flyout.test.d.ts +1 -0
- package/dist/flyout/tests/Flyout.test.js +129 -0
- package/dist/flyout/types.d.ts +24 -0
- package/dist/flyout/types.js +1 -0
- package/dist/flyout/utilities/applyPosition.d.ts +7 -0
- package/dist/flyout/utilities/applyPosition.js +103 -0
- package/dist/flyout/utilities/calculatePosition.d.ts +33 -0
- package/dist/flyout/utilities/calculatePosition.js +159 -0
- package/dist/flyout/utilities/centerBySize.d.ts +5 -0
- package/dist/flyout/utilities/centerBySize.js +7 -0
- package/dist/flyout/utilities/findClosestFixedContainer.d.ts +5 -0
- package/dist/flyout/utilities/findClosestFixedContainer.js +18 -0
- package/dist/flyout/utilities/findClosestScrollableContainer.d.ts +5 -0
- package/dist/flyout/utilities/findClosestScrollableContainer.js +12 -0
- package/dist/flyout/utilities/getPositionFallbacks.d.ts +8 -0
- package/dist/flyout/utilities/getPositionFallbacks.js +43 -0
- package/dist/flyout/utilities/getRTLPosition.d.ts +3 -0
- package/dist/flyout/utilities/getRTLPosition.js +8 -0
- package/dist/flyout/utilities/getRectFromCoordinates.d.ts +6 -0
- package/dist/flyout/utilities/getRectFromCoordinates.js +18 -0
- package/dist/flyout/utilities/isFullyVisible.d.ts +13 -0
- package/dist/flyout/utilities/isFullyVisible.js +28 -0
- package/dist/flyout/utilities/tests/applyPosition.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/applyPosition.test.js +143 -0
- package/dist/flyout/utilities/tests/calculatePosition.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/calculatePosition.test.js +536 -0
- package/dist/flyout/utilities/tests/centerBySize.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/centerBySize.test.js +10 -0
- package/dist/flyout/utilities/tests/findClosestFixedContainer.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/findClosestFixedContainer.test.js +46 -0
- package/dist/flyout/utilities/tests/findClosestScrollableContainer.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/findClosestScrollableContainer.test.js +66 -0
- package/dist/flyout/utilities/tests/getPositionFallbacks.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/getPositionFallbacks.test.js +114 -0
- package/dist/flyout/utilities/tests/getRTLPosition.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/getRTLPosition.test.js +19 -0
- package/dist/flyout/utilities/tests/isFullyVisible.test.d.ts +1 -0
- package/dist/flyout/utilities/tests/isFullyVisible.test.js +129 -0
- package/dist/helpers/rafThrottle.d.ts +2 -0
- package/dist/helpers/rafThrottle.js +15 -0
- package/dist/helpers/tests/rafThrottle.test.d.ts +1 -0
- package/dist/helpers/tests/rafThrottle.test.js +49 -0
- package/dist/i18n/isRTL.d.ts +2 -0
- package/dist/i18n/isRTL.js +10 -0
- package/dist/i18n/tests/isRTL.test.d.ts +1 -0
- package/dist/i18n/tests/isRTL.test.js +51 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { expect, test, describe } from "vitest";
|
|
2
|
+
import getPositionFallbacks from "../getPositionFallbacks.js";
|
|
3
|
+
describe("flyout/getPositionFallbacks", () => {
|
|
4
|
+
test("returns original position first for top-start", () => {
|
|
5
|
+
const result = getPositionFallbacks("top-start");
|
|
6
|
+
expect(result[0]).toBe("top-start");
|
|
7
|
+
});
|
|
8
|
+
test("returns fallback order for top-start", () => {
|
|
9
|
+
const result = getPositionFallbacks("top-start");
|
|
10
|
+
expect(result).toEqual([
|
|
11
|
+
"top-start",
|
|
12
|
+
"top-end",
|
|
13
|
+
"top",
|
|
14
|
+
"bottom-start",
|
|
15
|
+
"bottom-end",
|
|
16
|
+
"bottom",
|
|
17
|
+
"start-top",
|
|
18
|
+
"start-bottom",
|
|
19
|
+
"start",
|
|
20
|
+
"end-top",
|
|
21
|
+
"end-bottom",
|
|
22
|
+
"end",
|
|
23
|
+
]);
|
|
24
|
+
});
|
|
25
|
+
test("returns fallback order for top", () => {
|
|
26
|
+
const result = getPositionFallbacks("top");
|
|
27
|
+
expect(result).toEqual([
|
|
28
|
+
"top",
|
|
29
|
+
"top-start",
|
|
30
|
+
"top-end",
|
|
31
|
+
"bottom",
|
|
32
|
+
"bottom-start",
|
|
33
|
+
"bottom-end",
|
|
34
|
+
"start",
|
|
35
|
+
"start-top",
|
|
36
|
+
"start-bottom",
|
|
37
|
+
"end",
|
|
38
|
+
"end-top",
|
|
39
|
+
"end-bottom",
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
test("returns fallback order for bottom-start", () => {
|
|
43
|
+
const result = getPositionFallbacks("bottom-start");
|
|
44
|
+
expect(result).toEqual([
|
|
45
|
+
"bottom-start",
|
|
46
|
+
"bottom-end",
|
|
47
|
+
"bottom",
|
|
48
|
+
"top-start",
|
|
49
|
+
"top-end",
|
|
50
|
+
"top",
|
|
51
|
+
"end-top",
|
|
52
|
+
"end-bottom",
|
|
53
|
+
"end",
|
|
54
|
+
"start-top",
|
|
55
|
+
"start-bottom",
|
|
56
|
+
"start",
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
test("returns fallback order for start-top", () => {
|
|
60
|
+
const result = getPositionFallbacks("start-top");
|
|
61
|
+
expect(result).toEqual([
|
|
62
|
+
"start-top",
|
|
63
|
+
"start-bottom",
|
|
64
|
+
"start",
|
|
65
|
+
"end-top",
|
|
66
|
+
"end-bottom",
|
|
67
|
+
"end",
|
|
68
|
+
"top-start",
|
|
69
|
+
"top-end",
|
|
70
|
+
"top",
|
|
71
|
+
"bottom-start",
|
|
72
|
+
"bottom-end",
|
|
73
|
+
"bottom",
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
76
|
+
test("returns fallback order for end-bottom", () => {
|
|
77
|
+
const result = getPositionFallbacks("end-bottom");
|
|
78
|
+
expect(result).toEqual([
|
|
79
|
+
"end-bottom",
|
|
80
|
+
"end-top",
|
|
81
|
+
"end",
|
|
82
|
+
"start-bottom",
|
|
83
|
+
"start-top",
|
|
84
|
+
"start",
|
|
85
|
+
"bottom-end",
|
|
86
|
+
"bottom-start",
|
|
87
|
+
"bottom",
|
|
88
|
+
"top-end",
|
|
89
|
+
"top-start",
|
|
90
|
+
"top",
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
test("filters positions based on availableFallbacks", () => {
|
|
94
|
+
const result = getPositionFallbacks("top-start", [
|
|
95
|
+
"top-start",
|
|
96
|
+
"top",
|
|
97
|
+
"bottom-start",
|
|
98
|
+
"start-top",
|
|
99
|
+
]);
|
|
100
|
+
expect(result).toEqual(["top-start", "top", "bottom-start", "start-top"]);
|
|
101
|
+
});
|
|
102
|
+
test("returns only original position when availableFallbacks only contains it", () => {
|
|
103
|
+
const result = getPositionFallbacks("top-start", ["top-start"]);
|
|
104
|
+
expect(result).toEqual(["top-start"]);
|
|
105
|
+
});
|
|
106
|
+
test("excludes positions not in availableFallbacks", () => {
|
|
107
|
+
const result = getPositionFallbacks("top", ["top", "bottom", "start"]);
|
|
108
|
+
expect(result).toEqual(["top", "bottom", "start"]);
|
|
109
|
+
});
|
|
110
|
+
test("maintains order priority when filtering with availableFallbacks", () => {
|
|
111
|
+
const result = getPositionFallbacks("top-end", ["top", "top-end", "bottom", "end"]);
|
|
112
|
+
expect(result).toEqual(["top-end", "top", "bottom", "end"]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expect, test, describe } from "vitest";
|
|
2
|
+
import getRTLPosition from "../getRTLPosition.js";
|
|
3
|
+
describe("flyout/getRTLPosition", () => {
|
|
4
|
+
test("keeps top position", () => {
|
|
5
|
+
expect(getRTLPosition("top")).toEqual("top");
|
|
6
|
+
});
|
|
7
|
+
test("mirrors top-start position", () => {
|
|
8
|
+
expect(getRTLPosition("top-start")).toEqual("top-end");
|
|
9
|
+
});
|
|
10
|
+
test("mirrors start position", () => {
|
|
11
|
+
expect(getRTLPosition("start")).toEqual("end");
|
|
12
|
+
});
|
|
13
|
+
test("mirrors end position", () => {
|
|
14
|
+
expect(getRTLPosition("end")).toEqual("start");
|
|
15
|
+
});
|
|
16
|
+
test("mirrors bottom-end position", () => {
|
|
17
|
+
expect(getRTLPosition("bottom-end")).toEqual("bottom-start");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { expect, test, describe } from "vitest";
|
|
2
|
+
import isFullyVisible from "../isFullyVisible.js";
|
|
3
|
+
describe("flyout/isFullyVisible", () => {
|
|
4
|
+
test("returns true when flyout is fully visible within visual container", () => {
|
|
5
|
+
const result = isFullyVisible({
|
|
6
|
+
flyoutBounds: { left: 8, top: 8, width: 50, height: 50 },
|
|
7
|
+
visualContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
8
|
+
renderContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
9
|
+
});
|
|
10
|
+
expect(result).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
test("returns true when flyout is fully visible and is exactly on the edges of the visual container", () => {
|
|
13
|
+
const result = isFullyVisible({
|
|
14
|
+
flyoutBounds: { left: 8, top: 8, width: 84, height: 84 },
|
|
15
|
+
visualContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
16
|
+
renderContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
17
|
+
});
|
|
18
|
+
expect(result).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
test("returns false when flyout extends beyond left edge", () => {
|
|
21
|
+
const result = isFullyVisible({
|
|
22
|
+
flyoutBounds: { left: 7, top: 8, width: 50, height: 50 },
|
|
23
|
+
visualContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
24
|
+
renderContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
25
|
+
});
|
|
26
|
+
expect(result).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
test("returns false when flyout extends beyond top edge", () => {
|
|
29
|
+
const result = isFullyVisible({
|
|
30
|
+
flyoutBounds: { left: 8, top: 7, width: 50, height: 50 },
|
|
31
|
+
visualContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
32
|
+
renderContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
33
|
+
});
|
|
34
|
+
expect(result).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
test("returns false when flyout extends beyond right edge", () => {
|
|
37
|
+
const result = isFullyVisible({
|
|
38
|
+
flyoutBounds: {
|
|
39
|
+
left: 100 - 50 - 7,
|
|
40
|
+
top: 8,
|
|
41
|
+
width: 50,
|
|
42
|
+
height: 50,
|
|
43
|
+
},
|
|
44
|
+
visualContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
45
|
+
renderContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
46
|
+
});
|
|
47
|
+
expect(result).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
test("returns false when flyout extends beyond bottom edge", () => {
|
|
50
|
+
const result = isFullyVisible({
|
|
51
|
+
flyoutBounds: {
|
|
52
|
+
left: 8,
|
|
53
|
+
top: 100 - 50 - 7,
|
|
54
|
+
width: 50,
|
|
55
|
+
height: 50,
|
|
56
|
+
},
|
|
57
|
+
visualContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
58
|
+
renderContainerBounds: { left: 0, top: 0, width: 100, height: 100 },
|
|
59
|
+
});
|
|
60
|
+
expect(result).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Render container
|
|
64
|
+
*/
|
|
65
|
+
test("returns true when flyout is fully visible with offset render container", () => {
|
|
66
|
+
const result = isFullyVisible({
|
|
67
|
+
flyoutBounds: { left: 58, top: 58, width: 100, height: 100 },
|
|
68
|
+
renderContainerBounds: { left: 50, top: 50, width: 200, height: 200 },
|
|
69
|
+
visualContainerBounds: { left: 100, top: 100, width: 200, height: 200 },
|
|
70
|
+
});
|
|
71
|
+
expect(result).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
test("returns false when flyout extends beyond left edge with offset render container", () => {
|
|
74
|
+
const result = isFullyVisible({
|
|
75
|
+
flyoutBounds: { left: 0, top: 58, width: 50, height: 50 },
|
|
76
|
+
renderContainerBounds: { left: 50, top: 50, width: 200, height: 200 },
|
|
77
|
+
visualContainerBounds: { left: 100, top: 100, width: 200, height: 200 },
|
|
78
|
+
});
|
|
79
|
+
expect(result).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
test("returns false when flyout extends beyond top edge with offset render container", () => {
|
|
82
|
+
const result = isFullyVisible({
|
|
83
|
+
flyoutBounds: { left: 58, top: 0, width: 50, height: 50 },
|
|
84
|
+
renderContainerBounds: { left: 50, top: 50, width: 200, height: 200 },
|
|
85
|
+
visualContainerBounds: { left: 100, top: 100, width: 200, height: 200 },
|
|
86
|
+
});
|
|
87
|
+
expect(result).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
test("returns false when flyout extends beyond right edge with offset render container", () => {
|
|
90
|
+
const result = isFullyVisible({
|
|
91
|
+
flyoutBounds: { left: 200 - 7, top: 58, width: 50, height: 50 },
|
|
92
|
+
renderContainerBounds: { left: 50, top: 50, width: 200, height: 200 },
|
|
93
|
+
visualContainerBounds: { left: 100, top: 100, width: 200, height: 200 },
|
|
94
|
+
});
|
|
95
|
+
expect(result).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
test("returns false when flyout extends beyond bottom edge with offset render container", () => {
|
|
98
|
+
const result = isFullyVisible({
|
|
99
|
+
flyoutBounds: { left: 58, top: 200 - 7, width: 50, height: 50 },
|
|
100
|
+
renderContainerBounds: { left: 50, top: 50, width: 200, height: 200 },
|
|
101
|
+
visualContainerBounds: { left: 100, top: 100, width: 200, height: 200 },
|
|
102
|
+
});
|
|
103
|
+
expect(result).toBe(false);
|
|
104
|
+
});
|
|
105
|
+
test("returns false when flyout is larger than visual container", () => {
|
|
106
|
+
const result = isFullyVisible({
|
|
107
|
+
flyoutBounds: { left: 0, top: 0, width: 300, height: 300 },
|
|
108
|
+
visualContainerBounds: { left: 0, top: 0, width: 200, height: 200 },
|
|
109
|
+
renderContainerBounds: { left: 0, top: 0, width: 200, height: 200 },
|
|
110
|
+
});
|
|
111
|
+
expect(result).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
test("returns true when flyout is fully visible with negative render container position", () => {
|
|
114
|
+
const result = isFullyVisible({
|
|
115
|
+
flyoutBounds: { left: 118, top: 118, width: 100, height: 50 },
|
|
116
|
+
visualContainerBounds: { left: 100, top: 100, width: 200, height: 200 },
|
|
117
|
+
renderContainerBounds: { left: -10, top: -10, width: 200, height: 200 },
|
|
118
|
+
});
|
|
119
|
+
expect(result).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
test("returns false when flyout extends beyond left with negative render container position", () => {
|
|
122
|
+
const result = isFullyVisible({
|
|
123
|
+
flyoutBounds: { left: 0, top: 110, width: 100, height: 50 },
|
|
124
|
+
visualContainerBounds: { left: 100, top: 100, width: 200, height: 200 },
|
|
125
|
+
renderContainerBounds: { left: -10, top: -10, width: 200, height: 200 },
|
|
126
|
+
});
|
|
127
|
+
expect(result).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
const rafThrottle = (fn) => {
|
|
3
|
+
let rafId = null;
|
|
4
|
+
let args = null;
|
|
5
|
+
return function (...newArgs) {
|
|
6
|
+
args = newArgs;
|
|
7
|
+
if (rafId === null) {
|
|
8
|
+
rafId = requestAnimationFrame(() => {
|
|
9
|
+
rafId = null;
|
|
10
|
+
fn(...args);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export default rafThrottle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { expect, test, describe, beforeEach, vi } from "vitest";
|
|
2
|
+
import rafThrottle from "../rafThrottle.js";
|
|
3
|
+
const waitForNextFrame = () => {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
requestAnimationFrame(() => {
|
|
6
|
+
resolve();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
describe("helpers/rafThrottle", () => {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
let mockFn;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockFn = vi.fn();
|
|
15
|
+
});
|
|
16
|
+
test("calls the function once per animation frame", async () => {
|
|
17
|
+
const throttled = rafThrottle(mockFn);
|
|
18
|
+
throttled("first");
|
|
19
|
+
throttled("second");
|
|
20
|
+
throttled("third");
|
|
21
|
+
expect(mockFn).not.toHaveBeenCalled();
|
|
22
|
+
await waitForNextFrame();
|
|
23
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
24
|
+
expect(mockFn).toHaveBeenCalledWith("third");
|
|
25
|
+
});
|
|
26
|
+
test("handles multiple arguments correctly", async () => {
|
|
27
|
+
const throttled = rafThrottle(mockFn);
|
|
28
|
+
throttled("arg1", "arg2", 123);
|
|
29
|
+
throttled("new1", "new2", 456);
|
|
30
|
+
await waitForNextFrame();
|
|
31
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
32
|
+
expect(mockFn).toHaveBeenCalledWith("new1", "new2", 456);
|
|
33
|
+
});
|
|
34
|
+
test("allows multiple calls across different frames", async () => {
|
|
35
|
+
const throttled = rafThrottle(mockFn);
|
|
36
|
+
// First frame
|
|
37
|
+
throttled("frame1-1");
|
|
38
|
+
throttled("frame1-2");
|
|
39
|
+
await waitForNextFrame();
|
|
40
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
41
|
+
expect(mockFn).toHaveBeenCalledWith("frame1-2");
|
|
42
|
+
// Second frame
|
|
43
|
+
throttled("frame2-1");
|
|
44
|
+
throttled("frame2-2");
|
|
45
|
+
await waitForNextFrame();
|
|
46
|
+
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
47
|
+
expect(mockFn).toHaveBeenCalledWith("frame2-2");
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const isRTL = () => {
|
|
2
|
+
const root = document.documentElement;
|
|
3
|
+
const dir = root.dir;
|
|
4
|
+
if (dir === "rtl" || dir === "ltr")
|
|
5
|
+
return dir === "rtl";
|
|
6
|
+
// Fallback to computed style if dir attribute is not set
|
|
7
|
+
const computedStyle = window.getComputedStyle(root);
|
|
8
|
+
return computedStyle.direction === "rtl";
|
|
9
|
+
};
|
|
10
|
+
export default isRTL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { expect, test, describe, beforeEach, vi, afterAll } from "vitest";
|
|
2
|
+
import isRTL from "../isRTL.js";
|
|
3
|
+
describe("i18n/isRTL", () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
document.documentElement.removeAttribute("dir");
|
|
6
|
+
});
|
|
7
|
+
afterAll(() => {
|
|
8
|
+
document.documentElement.removeAttribute("dir");
|
|
9
|
+
});
|
|
10
|
+
test("returns true when dir attribute is set to 'rtl'", () => {
|
|
11
|
+
document.documentElement.dir = "rtl";
|
|
12
|
+
expect(isRTL()).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
test("returns false when dir attribute is set to 'ltr'", () => {
|
|
15
|
+
document.documentElement.dir = "ltr";
|
|
16
|
+
expect(isRTL()).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
test("returns true when dir attribute is not set but computed style direction is 'rtl'", () => {
|
|
19
|
+
window.getComputedStyle = vi.fn(() => ({
|
|
20
|
+
direction: "rtl",
|
|
21
|
+
}));
|
|
22
|
+
expect(isRTL()).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
test("returns false when dir attribute is not set and computed style direction is 'ltr'", () => {
|
|
25
|
+
window.getComputedStyle = vi.fn(() => ({
|
|
26
|
+
direction: "ltr",
|
|
27
|
+
}));
|
|
28
|
+
expect(isRTL()).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
test("returns false when dir attribute is empty string", () => {
|
|
31
|
+
document.documentElement.dir = "";
|
|
32
|
+
window.getComputedStyle = vi.fn(() => ({
|
|
33
|
+
direction: "rtl",
|
|
34
|
+
}));
|
|
35
|
+
expect(isRTL()).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
test("returns false when dir attribute is invalid value", () => {
|
|
38
|
+
document.documentElement.dir = "invalid";
|
|
39
|
+
window.getComputedStyle = vi.fn(() => ({
|
|
40
|
+
direction: "rtl",
|
|
41
|
+
}));
|
|
42
|
+
expect(isRTL()).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
test("prioritizes dir attribute over computed style", () => {
|
|
45
|
+
document.documentElement.dir = "ltr";
|
|
46
|
+
window.getComputedStyle = vi.fn(() => ({
|
|
47
|
+
direction: "rtl",
|
|
48
|
+
}));
|
|
49
|
+
expect(isRTL()).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Flyout } from "./flyout";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Flyout } from "./flyout/index.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reshaped/utilities",
|
|
3
|
+
"description": "Vanilla JS utilities for implementing common UI patterns",
|
|
4
|
+
"version": "3.9.1-canary.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://reshaped.so",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/reshaped-ui/reshaped.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/reshaped-ui/reshaped/issues"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Dmitry Belyaev",
|
|
17
|
+
"email": "blv.dmitry@gmail.com",
|
|
18
|
+
"url": "https://reshaped.so"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/**/*"
|
|
22
|
+
],
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^18 || ^19",
|
|
34
|
+
"react-dom": "^18 || ^19"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"clean": "rm -rf dist",
|
|
38
|
+
"dev": "tsc-watch --onSuccess \"resolve-tspaths\"",
|
|
39
|
+
"build": "tsc && resolve-tspaths",
|
|
40
|
+
"test:browser": "vitest run --project=browser"
|
|
41
|
+
}
|
|
42
|
+
}
|