@canonical/react-ds-core 0.9.0-experimental.5 → 0.9.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 +1 -1
- package/dist/esm/ui/Button/Button.js +2 -2
- package/dist/esm/ui/Button/Button.js.map +1 -1
- package/dist/esm/ui/Button/types.js +10 -0
- package/dist/esm/ui/Button/types.js.map +1 -1
- package/dist/esm/ui/Tooltip/Tooltip.js +18 -0
- package/dist/esm/ui/Tooltip/Tooltip.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/TooltipArea.js +38 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/TooltipArea.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/index.js +4 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/index.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/styles.css +13 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/types.js +2 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/types.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/index.js +2 -0
- package/dist/esm/ui/Tooltip/common/index.js.map +1 -0
- package/dist/esm/ui/Tooltip/index.js +6 -0
- package/dist/esm/ui/Tooltip/index.js.map +1 -0
- package/dist/esm/ui/Tooltip/styles.css +122 -0
- package/dist/esm/ui/Tooltip/types.js +2 -0
- package/dist/esm/ui/Tooltip/types.js.map +1 -0
- package/dist/esm/ui/Tooltip/withTooltip.js +18 -0
- package/dist/esm/ui/Tooltip/withTooltip.js.map +1 -0
- package/dist/esm/ui/hooks/index.js +6 -0
- package/dist/esm/ui/hooks/index.js.map +1 -0
- package/dist/esm/ui/hooks/useDelayedToggle/index.js +3 -0
- package/dist/esm/ui/hooks/useDelayedToggle/index.js.map +1 -0
- package/dist/esm/ui/hooks/useDelayedToggle/types.js +2 -0
- package/dist/esm/ui/hooks/useDelayedToggle/types.js.map +1 -0
- package/dist/esm/ui/hooks/useDelayedToggle/useDelayedToggle.js +45 -0
- package/dist/esm/ui/hooks/useDelayedToggle/useDelayedToggle.js.map +1 -0
- package/dist/esm/ui/hooks/usePopup/index.js +3 -0
- package/dist/esm/ui/hooks/usePopup/index.js.map +1 -0
- package/dist/esm/ui/hooks/usePopup/types.js +2 -0
- package/dist/esm/ui/hooks/usePopup/types.js.map +1 -0
- package/dist/esm/ui/hooks/usePopup/usePopup.js +94 -0
- package/dist/esm/ui/hooks/usePopup/usePopup.js.map +1 -0
- package/dist/esm/ui/hooks/useResizeObserver/index.js +3 -0
- package/dist/esm/ui/hooks/useResizeObserver/index.js.map +1 -0
- package/dist/esm/ui/hooks/useResizeObserver/types.js +2 -0
- package/dist/esm/ui/hooks/useResizeObserver/types.js.map +1 -0
- package/dist/esm/ui/hooks/useResizeObserver/useResizeObserver.js +32 -0
- package/dist/esm/ui/hooks/useResizeObserver/useResizeObserver.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowDimensions/index.js +3 -0
- package/dist/esm/ui/hooks/useWindowDimensions/index.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowDimensions/types.js +2 -0
- package/dist/esm/ui/hooks/useWindowDimensions/types.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowDimensions/useWindowDimensions.js +47 -0
- package/dist/esm/ui/hooks/useWindowDimensions/useWindowDimensions.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowFitment/index.js +3 -0
- package/dist/esm/ui/hooks/useWindowFitment/index.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowFitment/types.js +2 -0
- package/dist/esm/ui/hooks/useWindowFitment/types.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowFitment/useWindowFitment.js +221 -0
- package/dist/esm/ui/hooks/useWindowFitment/useWindowFitment.js.map +1 -0
- package/dist/esm/ui/index.js +1 -0
- package/dist/esm/ui/index.js.map +1 -1
- package/dist/types/ui/Button/Button.d.ts +1 -1
- package/dist/types/ui/Button/Button.d.ts.map +1 -1
- package/dist/types/ui/Button/types.d.ts +9 -6
- package/dist/types/ui/Button/types.d.ts.map +1 -1
- package/dist/types/ui/Chip/Chip.d.ts.map +1 -1
- package/dist/types/ui/Tooltip/Tooltip.d.ts +12 -0
- package/dist/types/ui/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/TooltipArea.d.ts +10 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/TooltipArea.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/index.d.ts +3 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/index.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/types.d.ts +35 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/types.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/index.d.ts +2 -0
- package/dist/types/ui/Tooltip/common/index.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/index.d.ts +5 -0
- package/dist/types/ui/Tooltip/index.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/types.d.ts +16 -0
- package/dist/types/ui/Tooltip/types.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/withTooltip.d.ts +11 -0
- package/dist/types/ui/Tooltip/withTooltip.d.ts.map +1 -0
- package/dist/types/ui/hooks/index.d.ts +6 -0
- package/dist/types/ui/hooks/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useDelayedToggle/index.d.ts +3 -0
- package/dist/types/ui/hooks/useDelayedToggle/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useDelayedToggle/types.d.ts +27 -0
- package/dist/types/ui/hooks/useDelayedToggle/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useDelayedToggle/useDelayedToggle.d.ts +13 -0
- package/dist/types/ui/hooks/useDelayedToggle/useDelayedToggle.d.ts.map +1 -0
- package/dist/types/ui/hooks/usePopup/index.d.ts +3 -0
- package/dist/types/ui/hooks/usePopup/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/usePopup/types.d.ts +65 -0
- package/dist/types/ui/hooks/usePopup/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/usePopup/usePopup.d.ts +19 -0
- package/dist/types/ui/hooks/usePopup/usePopup.d.ts.map +1 -0
- package/dist/types/ui/hooks/useResizeObserver/index.d.ts +3 -0
- package/dist/types/ui/hooks/useResizeObserver/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useResizeObserver/types.d.ts +7 -0
- package/dist/types/ui/hooks/useResizeObserver/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useResizeObserver/useResizeObserver.d.ts +8 -0
- package/dist/types/ui/hooks/useResizeObserver/useResizeObserver.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowDimensions/index.d.ts +3 -0
- package/dist/types/ui/hooks/useWindowDimensions/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowDimensions/types.d.ts +21 -0
- package/dist/types/ui/hooks/useWindowDimensions/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowDimensions/useWindowDimensions.d.ts +6 -0
- package/dist/types/ui/hooks/useWindowDimensions/useWindowDimensions.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowFitment/index.d.ts +3 -0
- package/dist/types/ui/hooks/useWindowFitment/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowFitment/types.d.ts +73 -0
- package/dist/types/ui/hooks/useWindowFitment/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowFitment/useWindowFitment.d.ts +4 -0
- package/dist/types/ui/hooks/useWindowFitment/useWindowFitment.d.ts.map +1 -0
- package/dist/types/ui/index.d.ts +1 -0
- package/dist/types/ui/index.d.ts.map +1 -1
- package/package.json +23 -24
@@ -0,0 +1,47 @@
|
|
1
|
+
import { debounce } from "@canonical/utils";
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
3
|
+
/**
|
4
|
+
* Hook to get the window dimensions and scroll position.
|
5
|
+
*/
|
6
|
+
export default function useWindowDimensions({ onResize, onScroll, resizeDelay = 100, scrollDelay = 100, } = {}) {
|
7
|
+
const isServer = typeof window === "undefined";
|
8
|
+
const [windowWidth, setWindowWidth] = useState(isServer ? 0 : window.innerWidth);
|
9
|
+
const [windowHeight, setWindowHeight] = useState(isServer ? 0 : window.innerHeight);
|
10
|
+
const [scrollHeight, setScrollHeight] = useState(isServer ? 0 : window.scrollY);
|
11
|
+
const [scrollWidth, setScrollWidth] = useState(isServer ? 0 : window.scrollX);
|
12
|
+
const result = useMemo(() => ({
|
13
|
+
windowWidth,
|
14
|
+
windowHeight,
|
15
|
+
scrollWidth,
|
16
|
+
scrollHeight,
|
17
|
+
}), [windowWidth, windowHeight, scrollWidth, scrollHeight]);
|
18
|
+
useEffect(() => {
|
19
|
+
if (isServer)
|
20
|
+
return;
|
21
|
+
const handleResize = debounce(() => {
|
22
|
+
setWindowWidth(window.innerWidth);
|
23
|
+
setWindowHeight(window.innerHeight);
|
24
|
+
if (onResize)
|
25
|
+
onResize(result);
|
26
|
+
}, resizeDelay);
|
27
|
+
const handleScroll = debounce(() => {
|
28
|
+
setScrollWidth(window.scrollX);
|
29
|
+
setScrollHeight(window.scrollY);
|
30
|
+
if (onScroll)
|
31
|
+
onScroll(result);
|
32
|
+
}, scrollDelay);
|
33
|
+
window.addEventListener("resize", handleResize);
|
34
|
+
window.addEventListener("scroll", handleScroll);
|
35
|
+
// Initial trigger in case the values need to be passed immediately after mount
|
36
|
+
void handleResize();
|
37
|
+
void handleScroll();
|
38
|
+
return () => {
|
39
|
+
handleResize.cancel();
|
40
|
+
handleScroll.cancel();
|
41
|
+
window.removeEventListener("resize", handleResize);
|
42
|
+
window.removeEventListener("scroll", handleScroll);
|
43
|
+
};
|
44
|
+
}, [onResize, onScroll, resizeDelay, scrollDelay, result, isServer]);
|
45
|
+
return result;
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=useWindowDimensions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useWindowDimensions.js","sourceRoot":"","sources":["../../../../../src/ui/hoo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@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowFitment/types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,221 @@
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, } from "react";
|
2
|
+
import { useResizeObserver } from "../useResizeObserver/index.js";
|
3
|
+
import { useWindowDimensions } from "../useWindowDimensions/index.js";
|
4
|
+
const useWindowFitment = ({ preferredDirections = ["top", "bottom", "left", "right"], distance = "0px", gutter = "0px", maxWidth = "350px", resizeDelay = 150, scrollDelay = 150, onBestPositionChange, autoFit = false, }) => {
|
5
|
+
const isServer = typeof window === "undefined";
|
6
|
+
const targetRef = useRef(null);
|
7
|
+
const popupRef = useRef(null);
|
8
|
+
const prevBestPosition = useRef(undefined);
|
9
|
+
const windowDimensions = useWindowDimensions({ resizeDelay, scrollDelay });
|
10
|
+
const targetSize = useResizeObserver(targetRef?.current);
|
11
|
+
const popupSize = useResizeObserver(popupRef?.current);
|
12
|
+
/** The distance, in pixels, between the target and the popup. */
|
13
|
+
const distanceAsPixelsNumber = useMemo(() => Number.parseInt(distance, 10) || 0, [distance]);
|
14
|
+
/** The bounds of the window, accounting for the `gutter` prop. */
|
15
|
+
const bounds = useMemo(() => {
|
16
|
+
if (isServer)
|
17
|
+
return;
|
18
|
+
const gutterValues = gutter
|
19
|
+
.split(" ")
|
20
|
+
.map((val) => Number.parseInt(val, 10));
|
21
|
+
const topGutter = gutterValues[0] || 0;
|
22
|
+
const rightGutter = gutterValues[1] || gutterValues[0] || 0;
|
23
|
+
const bottomGutter = gutterValues[2] || gutterValues[0] || 0;
|
24
|
+
const leftGutter = gutterValues[3] || gutterValues[1] || gutterValues[0] || 0;
|
25
|
+
return {
|
26
|
+
top: topGutter,
|
27
|
+
left: leftGutter,
|
28
|
+
right: windowDimensions.windowWidth - rightGutter,
|
29
|
+
bottom: windowDimensions.windowHeight - bottomGutter,
|
30
|
+
};
|
31
|
+
}, [gutter, windowDimensions, isServer]);
|
32
|
+
/**
|
33
|
+
* Calculate the relative position of the popup when oriented in a given direction.
|
34
|
+
* @param direction The side of the target element to position the popup on.
|
35
|
+
* @param targetRect The bounding client rect of the target element.
|
36
|
+
* @param popupRect The bounding client rect of the popup element.
|
37
|
+
* @returns The calculated relative position of the popup.
|
38
|
+
*/
|
39
|
+
const calculateRelativePosition = useCallback((direction, targetRect, popupRect) => {
|
40
|
+
let left = 0;
|
41
|
+
let top = 0;
|
42
|
+
if (isServer) {
|
43
|
+
return {
|
44
|
+
left,
|
45
|
+
top,
|
46
|
+
};
|
47
|
+
}
|
48
|
+
/*
|
49
|
+
We use left and top offsets to position the popup relative to the target element.
|
50
|
+
Then, we apply a margin on the opposite side of the popup to create a buffer zone between the target and the popup, to prevent a mouseleave event when moving from the target to the popup.
|
51
|
+
The fake margin is already included in `targetRect` dimensions, as it is rendered hidden at least once before the popup is shown.
|
52
|
+
In cases where `targetRect` is not included in the calculation, we add `distanceAsPixelsNumber` to account for the fake margin.
|
53
|
+
*/
|
54
|
+
// horizontal offset
|
55
|
+
switch (direction) {
|
56
|
+
case "top":
|
57
|
+
case "bottom":
|
58
|
+
left = (targetRect.width - popupRect.width) / 2;
|
59
|
+
break;
|
60
|
+
case "right":
|
61
|
+
left = targetRect.width;
|
62
|
+
break;
|
63
|
+
case "left":
|
64
|
+
left = -(popupRect.width + distanceAsPixelsNumber);
|
65
|
+
break;
|
66
|
+
}
|
67
|
+
// vertical offset
|
68
|
+
switch (direction) {
|
69
|
+
case "top":
|
70
|
+
top = -(popupRect.height + distanceAsPixelsNumber);
|
71
|
+
break;
|
72
|
+
case "bottom":
|
73
|
+
top = targetRect.height;
|
74
|
+
break;
|
75
|
+
case "right":
|
76
|
+
case "left":
|
77
|
+
top = (targetRect.height - popupRect.height) / 2;
|
78
|
+
break;
|
79
|
+
}
|
80
|
+
return { left, top };
|
81
|
+
}, [distanceAsPixelsNumber, isServer]);
|
82
|
+
/**
|
83
|
+
* Check if the popup fits within the window. Accounts for `gutter` prop.
|
84
|
+
* @param candidatePosition The absolute position of the popup
|
85
|
+
* @param popupRect The bounding client rect of the popup element.
|
86
|
+
* @returns Whether the popup fits within the window.
|
87
|
+
*/
|
88
|
+
const fitsInWindow = useCallback((candidatePosition, popupRect) => {
|
89
|
+
if (isServer || !bounds)
|
90
|
+
return false;
|
91
|
+
// Absolute position of the popup's vertices, relative to the viewport
|
92
|
+
const vertices = {
|
93
|
+
top: candidatePosition.top,
|
94
|
+
right: candidatePosition.left + popupRect.width,
|
95
|
+
bottom: candidatePosition.top + popupRect.height,
|
96
|
+
left: candidatePosition.left,
|
97
|
+
};
|
98
|
+
return (vertices.top >= bounds.top &&
|
99
|
+
vertices.right <= bounds.right &&
|
100
|
+
vertices.bottom <= bounds.bottom &&
|
101
|
+
vertices.left >= bounds.left);
|
102
|
+
}, [bounds, isServer]);
|
103
|
+
/**
|
104
|
+
* Find the best position for the popup based on the preferred directions.
|
105
|
+
* @param targetRect The bounding client rect of the target element.
|
106
|
+
* @param popupRect The bounding client rect of the popup element.
|
107
|
+
* @returns The best absolute position for the popup.
|
108
|
+
*/
|
109
|
+
const findBestPosition = useCallback((targetRect, popupRect, preferredDirections) => {
|
110
|
+
if (isServer)
|
111
|
+
return;
|
112
|
+
let fallbackPosition = undefined;
|
113
|
+
if (!preferredDirections.length) {
|
114
|
+
throw new Error("Preferred directions must not be empty.");
|
115
|
+
}
|
116
|
+
for (const direction of preferredDirections) {
|
117
|
+
const relativePosition = calculateRelativePosition(direction, targetRect, popupRect);
|
118
|
+
const absolutePosition = {
|
119
|
+
top: targetRect.top + relativePosition.top,
|
120
|
+
left: targetRect.left + relativePosition.left,
|
121
|
+
};
|
122
|
+
const autoFitOffset = { top: 0, left: 0 };
|
123
|
+
if (autoFit && bounds) {
|
124
|
+
// Adjust position if it overflows the bounds
|
125
|
+
if (absolutePosition.top < bounds.top) {
|
126
|
+
autoFitOffset.top = bounds.top - absolutePosition.top;
|
127
|
+
absolutePosition.top = bounds.top;
|
128
|
+
}
|
129
|
+
else if (absolutePosition.top + popupRect.height > bounds.bottom) {
|
130
|
+
autoFitOffset.top =
|
131
|
+
bounds.bottom - (absolutePosition.top + popupRect.height);
|
132
|
+
absolutePosition.top = bounds.bottom - popupRect.height;
|
133
|
+
}
|
134
|
+
if (absolutePosition.left < bounds.left) {
|
135
|
+
autoFitOffset.left = -1 * (bounds.left - absolutePosition.left);
|
136
|
+
absolutePosition.left = bounds.left;
|
137
|
+
}
|
138
|
+
else if (absolutePosition.left + popupRect.width > bounds.right) {
|
139
|
+
autoFitOffset.left =
|
140
|
+
-1 * (bounds.right - (absolutePosition.left + popupRect.width));
|
141
|
+
absolutePosition.left = bounds.right - popupRect.width;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
const bestPositionForName = {
|
145
|
+
positionName: direction,
|
146
|
+
position: absolutePosition,
|
147
|
+
fits: fitsInWindow(absolutePosition, popupRect),
|
148
|
+
autoFitOffset,
|
149
|
+
};
|
150
|
+
// Save the calculated position as a fallback in case no other position fits.
|
151
|
+
fallbackPosition ||= bestPositionForName;
|
152
|
+
// If this position fits, use it.
|
153
|
+
if (bestPositionForName.fits) {
|
154
|
+
return bestPositionForName;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
// biome-ignore lint/style/noNonNullAssertion: Fallback position is always defined here, due to the loop above and the thrown error if preferredDirections is empty.
|
158
|
+
return fallbackPosition;
|
159
|
+
}, [calculateRelativePosition, fitsInWindow, isServer, autoFit, bounds]);
|
160
|
+
/** The best possible position for the popup. */
|
161
|
+
const bestPosition = useMemo(() => {
|
162
|
+
if (!isServer &&
|
163
|
+
targetRef.current &&
|
164
|
+
popupRef.current &&
|
165
|
+
windowDimensions &&
|
166
|
+
popupSize &&
|
167
|
+
targetSize)
|
168
|
+
return findBestPosition(targetRef.current.getBoundingClientRect(), popupRef.current.getBoundingClientRect(), preferredDirections);
|
169
|
+
}, [
|
170
|
+
findBestPosition,
|
171
|
+
preferredDirections,
|
172
|
+
windowDimensions,
|
173
|
+
popupSize,
|
174
|
+
targetSize,
|
175
|
+
isServer,
|
176
|
+
]);
|
177
|
+
/** Notify the consumer when the best position changes. */
|
178
|
+
useEffect(() => {
|
179
|
+
if (bestPosition?.positionName !== prevBestPosition.current?.positionName) {
|
180
|
+
prevBestPosition.current = bestPosition;
|
181
|
+
if (onBestPositionChange)
|
182
|
+
onBestPositionChange(bestPosition);
|
183
|
+
}
|
184
|
+
}, [bestPosition, onBestPositionChange]);
|
185
|
+
const fakeMargin = useMemo(() => {
|
186
|
+
let side = "Top";
|
187
|
+
switch (bestPosition?.positionName) {
|
188
|
+
case "top":
|
189
|
+
side = "Bottom";
|
190
|
+
break;
|
191
|
+
case "bottom":
|
192
|
+
side = "Top";
|
193
|
+
break;
|
194
|
+
case "left":
|
195
|
+
side = "Right";
|
196
|
+
break;
|
197
|
+
case "right":
|
198
|
+
side = "Left";
|
199
|
+
break;
|
200
|
+
}
|
201
|
+
return {
|
202
|
+
[`margin${side}`]: `${distanceAsPixelsNumber}px`,
|
203
|
+
};
|
204
|
+
}, [bestPosition, distanceAsPixelsNumber]);
|
205
|
+
/** The style object to be applied to the popup element. */
|
206
|
+
const popupPositionStyle = useMemo(() => ({
|
207
|
+
maxWidth: maxWidth,
|
208
|
+
top: bestPosition?.position?.top || 0,
|
209
|
+
left: bestPosition?.position?.left || 0,
|
210
|
+
// Fake margin around the popup to prevent a mouseleave event when moving from the target to the popup.
|
211
|
+
...fakeMargin,
|
212
|
+
}), [bestPosition, maxWidth, fakeMargin]);
|
213
|
+
return {
|
214
|
+
targetRef,
|
215
|
+
popupRef,
|
216
|
+
bestPosition,
|
217
|
+
popupPositionStyle,
|
218
|
+
};
|
219
|
+
};
|
220
|
+
export default useWindowFitment;
|
221
|
+
//# sourceMappingURL=useWindowFitment.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useWindowFitment.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowFitment/useWindowFitment.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AC,EAAE,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAE3C,2DAA2D;IAC3D,MAAM,kBAAkB,GAAkB,OAAO,CAC/C,GAAG,EAAE,CAAC,CAAC;QACL,QAAQ,EAAE,QAAQ;QAClB,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QACrC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC;QACvC,uGAAuG;QACvG,GAAG,UAAU;KACd,CAAC,EACF,CAAC,YAAY,EAAE,QAAQ,EAAE,UAAU,CAAC,CACrC,CAAC;IAEF,OAAO;QACL,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/dist/esm/ui/index.js
CHANGED
package/dist/esm/ui/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type Props from "./types.js";
|
2
2
|
import "./styles.css";
|
3
3
|
/** Buttons are clickable elements used to perform an action. */
|
4
|
-
declare const Button: ({ id, className,
|
4
|
+
declare const Button: ({ id, className, children, style, appearance, ...props }: Props) => React.ReactElement;
|
5
5
|
export default Button;
|
6
6
|
//# sourceMappingURL=Button.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../../src/ui/Button/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,cAAc,CAAC;AAEtB,gEAAgE;AAChE,QAAA,MAAM,MAAM,
|
1
|
+
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../../src/ui/Button/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,cAAc,CAAC;AAEtB,gEAAgE;AAChE,QAAA,MAAM,MAAM,GAAI,0DAOb,KAAK,KAAG,KAAK,CAAC,YAiBhB,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
@@ -1,15 +1,18 @@
|
|
1
|
-
import type
|
1
|
+
import type { ButtonHTMLAttributes, ReactNode } from "react";
|
2
2
|
export interface BaseProps {
|
3
3
|
id?: string;
|
4
4
|
/** Additional CSS classes */
|
5
5
|
className?: string;
|
6
|
+
/**
|
7
|
+
* Button contents.
|
8
|
+
* This will also be used for the `aria-label`.
|
9
|
+
* If this contains anything other than a string literal (such as a <p> element), you should specify an
|
10
|
+
* `aria-label` prop to ensure that the button label is applied properly. Otherwise, the label will be set to [object Object].
|
11
|
+
* */
|
12
|
+
children: ReactNode;
|
6
13
|
/** The visual style of the button */
|
7
14
|
appearance?: "neutral" | "base" | "positive" | "negative" | "link";
|
8
|
-
/** Button contents */
|
9
|
-
label: string;
|
10
|
-
/** Optional click handler */
|
11
|
-
onClick?: () => void;
|
12
15
|
}
|
13
|
-
type Props = BaseProps &
|
16
|
+
type Props = BaseProps & ButtonHTMLAttributes<HTMLButtonElement>;
|
14
17
|
export default Props;
|
15
18
|
//# sourceMappingURL=types.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ui/Button/types.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ui/Button/types.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7D,MAAM,WAAW,SAAS;IAExB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;SAKK;IACL,QAAQ,EAAE,SAAS,CAAC;IACpB,qCAAqC;IACrC,UAAU,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;CACpE;AAED,KAAK,KAAK,GAAG,SAAS,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEjE,eAAe,KAAK,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Chip.d.ts","sourceRoot":"","sources":["../../../../src/ui/Chip/Chip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD;;;GAGG;AACH,QAAA,MAAM,IAAI,
|
1
|
+
{"version":3,"file":"Chip.d.ts","sourceRoot":"","sources":["../../../../src/ui/Chip/Chip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD;;;GAGG;AACH,QAAA,MAAM,IAAI,GAAI,iFAUX,aAAa,KAAG,KAAK,CAAC,YAwBxB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type React from "react";
|
2
|
+
import "./styles.css";
|
3
|
+
import type { TooltipProps } from "./types.js";
|
4
|
+
/**
|
5
|
+
* The Tooltip component is used to display a message.
|
6
|
+
* This component is just the "message" part of the tooltip, and has no interactivity or positioning logic. It is generally not consumed directly, but rather in one of two ways
|
7
|
+
* - The [TooltipArea](?path=/docs/tooltip-tooltiparea--docs) component
|
8
|
+
* - The [withTooltip](?path=/docs/tooltip-withtooltip--docs) HOC
|
9
|
+
*/
|
10
|
+
declare const Tooltip: ({ id, children, className, style, ref, isOpen, zIndex, onPointerEnter, onFocus, }: TooltipProps) => React.ReactElement;
|
11
|
+
export default Tooltip;
|
12
|
+
//# sourceMappingURL=Tooltip.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../../src/ui/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C;;;;;GAKG;AACH,QAAA,MAAM,OAAO,GAAI,mFAUd,YAAY,KAAG,KAAK,CAAC,YAmBvB,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { ReactElement } from "react";
|
2
|
+
import type { TooltipAreaProps } from "./types.js";
|
3
|
+
import "./styles.css";
|
4
|
+
/**
|
5
|
+
* Wraps a target element with a tooltip.
|
6
|
+
* This component allows you to attach a tooltip to any JSX fragment.
|
7
|
+
*/
|
8
|
+
declare const TooltipArea: ({ children, style, className, Message, distance, targetElementId, targetElementClassName, targetElementStyle, messageElementClassName, messageElementStyle, parentElement, autoFit, ...props }: TooltipAreaProps) => ReactElement;
|
9
|
+
export default TooltipArea;
|
10
|
+
//# sourceMappingURL=TooltipArea.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TooltipArea.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/Tooltip/common/TooltipArea/TooltipArea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,cAAc,CAAC;AAKtB;;;GAGG;AACH,QAAA,MAAM,WAAW,GAAI,gMAclB,gBAAgB,KAAG,YAyErB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/Tooltip/common/TooltipArea/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
2
|
+
import type { UsePopupProps } from "../../../hooks/index.js";
|
3
|
+
export interface TooltipAreaProps extends UsePopupProps {
|
4
|
+
/**
|
5
|
+
* The target element to which the tooltip should be attached.
|
6
|
+
* This can be any valid React element.
|
7
|
+
*/
|
8
|
+
children: ReactNode;
|
9
|
+
/**
|
10
|
+
* The content of the tooltip. This can be a string or any valid React node.
|
11
|
+
*/
|
12
|
+
Message: ReactNode;
|
13
|
+
/** Styles applied to the tooltip area */
|
14
|
+
style?: CSSProperties;
|
15
|
+
/** Class name applied to the tooltip area */
|
16
|
+
className?: string;
|
17
|
+
/** ID applied to the target element */
|
18
|
+
targetElementId?: string;
|
19
|
+
/** Class name applied to the target element */
|
20
|
+
targetElementClassName?: string;
|
21
|
+
/** Style object applied to the target element */
|
22
|
+
targetElementStyle?: CSSProperties;
|
23
|
+
/** Class name applied to the tooltip/message element */
|
24
|
+
messageElementClassName?: string;
|
25
|
+
/** Styles applied to the tooltip/message element */
|
26
|
+
messageElementStyle?: CSSProperties;
|
27
|
+
/**
|
28
|
+
* The element to which the tooltip should be attached.
|
29
|
+
* This can be any valid React element.
|
30
|
+
* When not provided, the tooltip will be attached to the `document.body`.
|
31
|
+
* No default is provided at the TooltipArea signature level in order to prevent the component from failing builds in server environments, where `document` is not available.
|
32
|
+
*/
|
33
|
+
parentElement?: HTMLElement;
|
34
|
+
}
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/Tooltip/common/TooltipArea/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD;;;OAGG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;OAEG;IACH,OAAO,EAAE,SAAS,CAAC;IACnB,yCAAyC;IACzC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,iDAAiD;IACjD,kBAAkB,CAAC,EAAE,aAAa,CAAC;IACnC,wDAAwD;IACxD,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,oDAAoD;IACpD,mBAAmB,CAAC,EAAE,aAAa,CAAC;IACpC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC;CAC7B"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/Tooltip/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/Tooltip/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { CSSProperties, FocusEventHandler, PointerEventHandler, ReactNode, RefObject } from "react";
|
2
|
+
export interface TooltipProps {
|
3
|
+
id?: string;
|
4
|
+
className?: string;
|
5
|
+
children: ReactNode;
|
6
|
+
style?: CSSProperties;
|
7
|
+
/** Whether the tooltip is open or not */
|
8
|
+
isOpen?: boolean;
|
9
|
+
/** Ref to the tooltip, useful for calculating its dimensions */
|
10
|
+
ref?: RefObject<HTMLDivElement | null>;
|
11
|
+
/** The z-index of the tooltip */
|
12
|
+
zIndex?: number;
|
13
|
+
onPointerEnter?: PointerEventHandler;
|
14
|
+
onFocus?: FocusEventHandler;
|
15
|
+
}
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ui/Tooltip/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,SAAS,EACV,MAAM,OAAO,CAAC;AAGf,MAAM,WAAW,YAAY;IAE3B,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,EAAE,SAAS,CAAC;IAEpB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,yCAAyC;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gEAAgE;IAChE,GAAG,CAAC,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACvC,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { type ComponentType, type FC, type ReactNode } from "react";
|
2
|
+
import type { UsePopupProps } from "../hooks/index.js";
|
3
|
+
/**
|
4
|
+
* A higher-order component that wraps a component with a tooltip.
|
5
|
+
* @param Component The component function to wrap. If you need to use a Node instead of a function, use [`TooltipArea`](/?path=/docs/tooltip-withtooltip--docs) instead.
|
6
|
+
* @param Message The content of the tooltip
|
7
|
+
* @param popupProps The props to pass to the usePopup hook
|
8
|
+
*/
|
9
|
+
declare const withTooltip: <TProps extends object>(Component: ComponentType<TProps>, Message: ReactNode, popupProps?: UsePopupProps) => FC<TProps>;
|
10
|
+
export default withTooltip;
|
11
|
+
//# sourceMappingURL=withTooltip.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"withTooltip.d.ts","sourceRoot":"","sources":["../../../../src/ui/Tooltip/withTooltip.tsx"],"names":[],"mappings":"AAAA,OAAc,EACZ,KAAK,aAAa,EAClB,KAAK,EAAE,EAEP,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD;;;;;GAKG;AACH,QAAA,MAAM,WAAW,GAAI,MAAM,SAAS,MAAM,EACxC,WAAW,aAAa,CAAC,MAAM,CAAC,EAChC,SAAS,SAAS,EAClB,aAAY,aAAkB,KAC7B,EAAE,CAAC,MAAM,CAkBX,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useDelayedToggle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACpE,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
export interface UseDelayedToggleProps {
|
2
|
+
/**
|
3
|
+
* Delay in milliseconds before setting the flag to true
|
4
|
+
* Defaults to 150ms.
|
5
|
+
*/
|
6
|
+
activateDelay?: number;
|
7
|
+
/**
|
8
|
+
* Delay in milliseconds before setting the flag to false
|
9
|
+
* Defaults to 150ms.
|
10
|
+
*/
|
11
|
+
deactivateDelay?: number;
|
12
|
+
/** A callback to be called when the flag is set to true. */
|
13
|
+
onActivate?: DelayedToggleActivateEventHandler;
|
14
|
+
/** A callback to be called when the flag is set to false. */
|
15
|
+
onDeactivate?: DelayedToggleActivateEventHandler;
|
16
|
+
}
|
17
|
+
export interface UseDelayedToggleResult {
|
18
|
+
/** The current state of the flag. */
|
19
|
+
flag: boolean;
|
20
|
+
/** Sets the flag to true after the specified delay. */
|
21
|
+
activate: DelayedToggleActivateEventHandler;
|
22
|
+
/** Sets the flag to false after the specified delay. */
|
23
|
+
deactivate: DelayedToggleActivateEventHandler;
|
24
|
+
}
|
25
|
+
/** Event handler for delayed toggle activation events. */
|
26
|
+
export type DelayedToggleActivateEventHandler = (event: Event) => void;
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useDelayedToggle/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,iCAAiC,CAAC;IAC/C,6DAA6D;IAC7D,YAAY,CAAC,EAAE,iCAAiC,CAAC;CAClD;AAED,MAAM,WAAW,sBAAsB;IACrC,qCAAqC;IACrC,IAAI,EAAE,OAAO,CAAC;IACd,uDAAuD;IACvD,QAAQ,EAAE,iCAAiC,CAAC;IAC5C,wDAAwD;IACxD,UAAU,EAAE,iCAAiC,CAAC;CAC/C;AAED,0DAA0D;AAC1D,MAAM,MAAM,iCAAiC,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { UseDelayedToggleProps, UseDelayedToggleResult } from "./types.js";
|
2
|
+
/**
|
3
|
+
* Hook to toggle a flag with a delay.
|
4
|
+
* Allows the caller to `activate()` or `deactivate()` some flag
|
5
|
+
* @param activateDelay The delay in milliseconds before setting the flag to true.
|
6
|
+
* @param deactivateDelay The delay in milliseconds before setting the flag to false.
|
7
|
+
* @param onActivate A callback to be called when the flag is set to true.
|
8
|
+
* @param onDeactivate A callback to be called when the flag is set to false.
|
9
|
+
* @returns The current state of the flag, functions to activate and deactivate the flag.
|
10
|
+
*/
|
11
|
+
declare const useDelayedToggle: ({ activateDelay, deactivateDelay, onActivate, onDeactivate, }: UseDelayedToggleProps) => UseDelayedToggleResult;
|
12
|
+
export default useDelayedToggle;
|
13
|
+
//# sourceMappingURL=useDelayedToggle.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useDelayedToggle.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useDelayedToggle/useDelayedToggle.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEhF;;;;;;;;GAQG;AACH,QAAA,MAAM,gBAAgB,GAAI,+DAKvB,qBAAqB,KAAG,sBAkD1B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/usePopup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,cAAc,YAAY,CAAC"}
|