@jsenv/dom 0.6.0 → 0.7.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/jsenv_dom.js +262 -330
- package/package.json +2 -4
- package/index.js +0 -124
- package/src/attr/add_attribute_effect.js +0 -93
- package/src/attr/attributes.js +0 -32
- package/src/color/color_constrast.js +0 -69
- package/src/color/color_parsing.js +0 -319
- package/src/color/color_scheme.js +0 -28
- package/src/color/pick_light_or_dark.js +0 -34
- package/src/color/resolve_css_color.js +0 -60
- package/src/demos/3_columns_resize_demo.html +0 -84
- package/src/demos/3_rows_resize_demo.html +0 -89
- package/src/demos/aside_and_main_demo.html +0 -93
- package/src/demos/coordinates_demo.html +0 -450
- package/src/demos/document_autoscroll_demo.html +0 -517
- package/src/demos/drag_gesture_constraints_demo.html +0 -701
- package/src/demos/drag_gesture_demo.html +0 -1047
- package/src/demos/drag_gesture_element_to_impact_demo.html +0 -445
- package/src/demos/drag_reference_element_demo.html +0 -480
- package/src/demos/flex_details_set_demo.html +0 -302
- package/src/demos/flex_details_set_demo_2.html +0 -315
- package/src/demos/visible_rect_demo.html +0 -525
- package/src/element_signature.js +0 -100
- package/src/interaction/drag/constraint_feedback_line.js +0 -92
- package/src/interaction/drag/drag_constraint.js +0 -659
- package/src/interaction/drag/drag_debug_markers.js +0 -635
- package/src/interaction/drag/drag_element_positioner.js +0 -382
- package/src/interaction/drag/drag_gesture.js +0 -566
- package/src/interaction/drag/drag_resize_demo.html +0 -571
- package/src/interaction/drag/drag_to_move.js +0 -301
- package/src/interaction/drag/drag_to_resize_gesture.js +0 -68
- package/src/interaction/drag/drop_target_detection.js +0 -148
- package/src/interaction/drag/sticky_frontiers.js +0 -160
- package/src/interaction/event_marker.js +0 -14
- package/src/interaction/focus/active_element.js +0 -33
- package/src/interaction/focus/arrow_navigation.js +0 -599
- package/src/interaction/focus/element_is_focusable.js +0 -57
- package/src/interaction/focus/element_visibility.js +0 -111
- package/src/interaction/focus/find_focusable.js +0 -21
- package/src/interaction/focus/focus_group.js +0 -91
- package/src/interaction/focus/focus_group_registry.js +0 -12
- package/src/interaction/focus/focus_nav.js +0 -12
- package/src/interaction/focus/focus_nav_event_marker.js +0 -14
- package/src/interaction/focus/focus_trap.js +0 -105
- package/src/interaction/focus/tab_navigation.js +0 -128
- package/src/interaction/focus/tests/focus_group_skip_tab_test.html +0 -206
- package/src/interaction/focus/tests/tree_focus_test.html +0 -304
- package/src/interaction/focus/tests/tree_focus_test.jsx +0 -261
- package/src/interaction/focus/tests/tree_focus_test_preact.html +0 -13
- package/src/interaction/isolate_interactions.js +0 -161
- package/src/interaction/keyboard.js +0 -26
- package/src/interaction/scroll/capture_scroll.js +0 -47
- package/src/interaction/scroll/is_scrollable.js +0 -159
- package/src/interaction/scroll/scroll_container.js +0 -110
- package/src/interaction/scroll/scroll_trap.js +0 -44
- package/src/interaction/scroll/scrollbar_size.js +0 -20
- package/src/interaction/scroll/wheel_through.js +0 -138
- package/src/iterable_weak_set.js +0 -66
- package/src/position/dom_coords.js +0 -340
- package/src/position/offset_parent.js +0 -15
- package/src/position/position_fixed.js +0 -15
- package/src/position/position_sticky.js +0 -213
- package/src/position/sticky_rect.js +0 -79
- package/src/position/visible_rect.js +0 -486
- package/src/pub_sub.js +0 -31
- package/src/size/can_take_size.js +0 -11
- package/src/size/details_content_full_height.js +0 -63
- package/src/size/flex_details_set.js +0 -974
- package/src/size/get_available_height.js +0 -22
- package/src/size/get_available_width.js +0 -22
- package/src/size/get_border_sizes.js +0 -14
- package/src/size/get_height.js +0 -4
- package/src/size/get_inner_height.js +0 -15
- package/src/size/get_inner_width.js +0 -15
- package/src/size/get_margin_sizes.js +0 -10
- package/src/size/get_max_height.js +0 -57
- package/src/size/get_max_width.js +0 -47
- package/src/size/get_min_height.js +0 -14
- package/src/size/get_min_width.js +0 -14
- package/src/size/get_padding_sizes.js +0 -10
- package/src/size/get_width.js +0 -4
- package/src/size/hooks/use_available_height.js +0 -27
- package/src/size/hooks/use_available_width.js +0 -27
- package/src/size/hooks/use_max_height.js +0 -10
- package/src/size/hooks/use_max_width.js +0 -10
- package/src/size/hooks/use_resize_status.js +0 -62
- package/src/size/resize.js +0 -695
- package/src/size/resolve_css_size.js +0 -32
- package/src/style/dom_styles.js +0 -97
- package/src/style/style_composition.js +0 -121
- package/src/style/style_controller.js +0 -345
- package/src/style/style_default.js +0 -153
- package/src/style/style_default_demo.html +0 -128
- package/src/style/style_parsing.js +0 -375
- package/src/transition/demos/animation_resumption_test.xhtml +0 -500
- package/src/transition/demos/height_toggle_test.xhtml +0 -515
- package/src/transition/dom_transition.js +0 -254
- package/src/transition/easing.js +0 -48
- package/src/transition/group_transition.js +0 -261
- package/src/transition/transform_style_parser.js +0 -32
- package/src/transition/transition_playback.js +0 -366
- package/src/transition/transition_timeline.js +0 -79
- package/src/traversal.js +0 -247
- package/src/ui_transition/demos/content_states_transition_demo.html +0 -628
- package/src/ui_transition/demos/smooth_height_transition_demo.html +0 -149
- package/src/ui_transition/demos/transition_testing.html +0 -354
- package/src/ui_transition/ui_transition.js +0 -1491
- package/src/utils.js +0 -69
- package/src/value_effect.js +0 -35
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getBorderSizes } from "./get_border_sizes.js";
|
|
2
|
-
import { getHeight } from "./get_height.js";
|
|
3
|
-
import { getPaddingSizes } from "./get_padding_sizes.js";
|
|
4
|
-
|
|
5
|
-
export const getAvailableHeight = (
|
|
6
|
-
element,
|
|
7
|
-
parentHeight = getHeight(element.parentElement),
|
|
8
|
-
) => {
|
|
9
|
-
const parentElement = element.parentElement;
|
|
10
|
-
const paddingSizes = getPaddingSizes(parentElement);
|
|
11
|
-
const borderSizes = getBorderSizes(parentElement);
|
|
12
|
-
let availableHeight = parentHeight;
|
|
13
|
-
availableHeight -=
|
|
14
|
-
paddingSizes.top +
|
|
15
|
-
paddingSizes.bottom +
|
|
16
|
-
borderSizes.top +
|
|
17
|
-
borderSizes.bottom;
|
|
18
|
-
if (availableHeight < 0) {
|
|
19
|
-
availableHeight = 0;
|
|
20
|
-
}
|
|
21
|
-
return availableHeight;
|
|
22
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getBorderSizes } from "./get_border_sizes.js";
|
|
2
|
-
import { getPaddingSizes } from "./get_padding_sizes.js";
|
|
3
|
-
import { getWidth } from "./get_width.js";
|
|
4
|
-
|
|
5
|
-
export const getAvailableWidth = (
|
|
6
|
-
element,
|
|
7
|
-
parentWidth = getWidth(element.parentElement),
|
|
8
|
-
) => {
|
|
9
|
-
const parentElement = element.parentElement;
|
|
10
|
-
const paddingSizes = getPaddingSizes(parentElement);
|
|
11
|
-
const borderSizes = getBorderSizes(parentElement);
|
|
12
|
-
let availableWidth = parentWidth;
|
|
13
|
-
availableWidth -=
|
|
14
|
-
paddingSizes.left +
|
|
15
|
-
paddingSizes.right +
|
|
16
|
-
borderSizes.left +
|
|
17
|
-
borderSizes.right;
|
|
18
|
-
if (availableWidth < 0) {
|
|
19
|
-
availableWidth = 0;
|
|
20
|
-
}
|
|
21
|
-
return availableWidth;
|
|
22
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const getBorderSizes = (element) => {
|
|
2
|
-
const {
|
|
3
|
-
borderLeftWidth,
|
|
4
|
-
borderRightWidth,
|
|
5
|
-
borderTopWidth,
|
|
6
|
-
borderBottomWidth,
|
|
7
|
-
} = window.getComputedStyle(element, null);
|
|
8
|
-
return {
|
|
9
|
-
left: parseFloat(borderLeftWidth),
|
|
10
|
-
right: parseFloat(borderRightWidth),
|
|
11
|
-
top: parseFloat(borderTopWidth),
|
|
12
|
-
bottom: parseFloat(borderBottomWidth),
|
|
13
|
-
};
|
|
14
|
-
};
|
package/src/size/get_height.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getBorderSizes } from "./get_border_sizes.js";
|
|
2
|
-
import { getHeight } from "./get_height.js";
|
|
3
|
-
import { getPaddingSizes } from "./get_padding_sizes.js";
|
|
4
|
-
|
|
5
|
-
export const getInnerHeight = (element) => {
|
|
6
|
-
// Always subtract paddings and borders to get the content height
|
|
7
|
-
const paddingSizes = getPaddingSizes(element);
|
|
8
|
-
const borderSizes = getBorderSizes(element);
|
|
9
|
-
const height = getHeight(element);
|
|
10
|
-
const verticalSpaceTakenByPaddings = paddingSizes.top + paddingSizes.bottom;
|
|
11
|
-
const verticalSpaceTakenByBorders = borderSizes.top + borderSizes.bottom;
|
|
12
|
-
const innerHeight =
|
|
13
|
-
height - verticalSpaceTakenByPaddings - verticalSpaceTakenByBorders;
|
|
14
|
-
return innerHeight;
|
|
15
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getBorderSizes } from "./get_border_sizes.js";
|
|
2
|
-
import { getPaddingSizes } from "./get_padding_sizes.js";
|
|
3
|
-
import { getWidth } from "./get_width.js";
|
|
4
|
-
|
|
5
|
-
export const getInnerWidth = (element) => {
|
|
6
|
-
// Always subtract paddings and borders to get the content width
|
|
7
|
-
const paddingSizes = getPaddingSizes(element);
|
|
8
|
-
const borderSizes = getBorderSizes(element);
|
|
9
|
-
const width = getWidth(element);
|
|
10
|
-
const horizontalSpaceTakenByPaddings = paddingSizes.left + paddingSizes.right;
|
|
11
|
-
const horizontalSpaceTakenByBorders = borderSizes.left + borderSizes.right;
|
|
12
|
-
const innerWidth =
|
|
13
|
-
width - horizontalSpaceTakenByPaddings - horizontalSpaceTakenByBorders;
|
|
14
|
-
return innerWidth;
|
|
15
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const getMarginSizes = (element) => {
|
|
2
|
-
const { marginLeft, marginRight, marginTop, marginBottom } =
|
|
3
|
-
window.getComputedStyle(element, null);
|
|
4
|
-
return {
|
|
5
|
-
left: parseFloat(marginLeft),
|
|
6
|
-
right: parseFloat(marginRight),
|
|
7
|
-
top: parseFloat(marginTop),
|
|
8
|
-
bottom: parseFloat(marginBottom),
|
|
9
|
-
};
|
|
10
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { getAvailableHeight } from "./get_available_height.js";
|
|
2
|
-
import { getHeight } from "./get_height.js";
|
|
3
|
-
import { getMarginSizes } from "./get_margin_sizes.js";
|
|
4
|
-
import { getMinHeight } from "./get_min_height.js";
|
|
5
|
-
|
|
6
|
-
export const getMaxHeight = (
|
|
7
|
-
element,
|
|
8
|
-
availableHeight = getAvailableHeight(element),
|
|
9
|
-
) => {
|
|
10
|
-
let maxHeight = availableHeight;
|
|
11
|
-
const marginSizes = getMarginSizes(element);
|
|
12
|
-
maxHeight -= marginSizes.top;
|
|
13
|
-
maxHeight -= marginSizes.bottom;
|
|
14
|
-
|
|
15
|
-
const parentElement = element.parentElement;
|
|
16
|
-
const parentElementComputedStyle = window.getComputedStyle(parentElement);
|
|
17
|
-
if (
|
|
18
|
-
parentElementComputedStyle.display === "flex" &&
|
|
19
|
-
parentElementComputedStyle.flexDirection === "column"
|
|
20
|
-
) {
|
|
21
|
-
let previousSibling = element.previousElementSibling;
|
|
22
|
-
while (previousSibling) {
|
|
23
|
-
if (canTakeSpace(previousSibling)) {
|
|
24
|
-
const previousSiblingHeight = getHeight(previousSibling);
|
|
25
|
-
maxHeight -= previousSiblingHeight;
|
|
26
|
-
const previousSiblingMarginSizes = getMarginSizes(previousSibling);
|
|
27
|
-
maxHeight -= previousSiblingMarginSizes.top;
|
|
28
|
-
maxHeight -= previousSiblingMarginSizes.bottom;
|
|
29
|
-
}
|
|
30
|
-
previousSibling = previousSibling.previousElementSibling;
|
|
31
|
-
}
|
|
32
|
-
let nextSibling = element.nextElementSibling;
|
|
33
|
-
while (nextSibling) {
|
|
34
|
-
if (canTakeSpace(nextSibling)) {
|
|
35
|
-
const nextSiblingMinHeight = getMinHeight(nextSibling, availableHeight);
|
|
36
|
-
maxHeight -= nextSiblingMinHeight;
|
|
37
|
-
const nextSiblingMarginSizes = getMarginSizes(nextSibling);
|
|
38
|
-
maxHeight -= nextSiblingMarginSizes.top;
|
|
39
|
-
maxHeight -= nextSiblingMarginSizes.bottom;
|
|
40
|
-
}
|
|
41
|
-
nextSibling = nextSibling.nextElementSibling;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return maxHeight;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const canTakeSpace = (element) => {
|
|
48
|
-
const computedStyle = window.getComputedStyle(element);
|
|
49
|
-
|
|
50
|
-
if (computedStyle.display === "none") {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
if (computedStyle.position === "absolute") {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { canTakeSize } from "./can_take_size.js";
|
|
2
|
-
import { getAvailableWidth } from "./get_available_width.js";
|
|
3
|
-
import { getMarginSizes } from "./get_margin_sizes.js";
|
|
4
|
-
import { getMinWidth } from "./get_min_width.js";
|
|
5
|
-
import { getWidth } from "./get_width.js";
|
|
6
|
-
|
|
7
|
-
export const getMaxWidth = (
|
|
8
|
-
element,
|
|
9
|
-
availableWidth = getAvailableWidth(element),
|
|
10
|
-
) => {
|
|
11
|
-
let maxWidth = availableWidth;
|
|
12
|
-
|
|
13
|
-
const marginSizes = getMarginSizes(element);
|
|
14
|
-
maxWidth -= marginSizes.left;
|
|
15
|
-
maxWidth -= marginSizes.right;
|
|
16
|
-
|
|
17
|
-
const parentElement = element.parentElement;
|
|
18
|
-
const parentElementComputedStyle = window.getComputedStyle(parentElement);
|
|
19
|
-
if (
|
|
20
|
-
parentElementComputedStyle.display === "flex" &&
|
|
21
|
-
parentElementComputedStyle.flexDirection === "row"
|
|
22
|
-
) {
|
|
23
|
-
let previousSibling = element.previousElementSibling;
|
|
24
|
-
while (previousSibling) {
|
|
25
|
-
if (canTakeSize(previousSibling)) {
|
|
26
|
-
const previousSiblingWidth = getWidth(previousSibling);
|
|
27
|
-
maxWidth -= previousSiblingWidth;
|
|
28
|
-
const previousSiblingMarginSizes = getMarginSizes(previousSibling);
|
|
29
|
-
maxWidth -= previousSiblingMarginSizes.left;
|
|
30
|
-
maxWidth -= previousSiblingMarginSizes.right;
|
|
31
|
-
}
|
|
32
|
-
previousSibling = previousSibling.previousElementSibling;
|
|
33
|
-
}
|
|
34
|
-
let nextSibling = element.nextElementSibling;
|
|
35
|
-
while (nextSibling) {
|
|
36
|
-
if (canTakeSize(nextSibling)) {
|
|
37
|
-
const nextSiblingMinWidth = getMinWidth(nextSibling, availableWidth);
|
|
38
|
-
maxWidth -= nextSiblingMinWidth;
|
|
39
|
-
const nextSiblingMarginSizes = getMarginSizes(nextSibling);
|
|
40
|
-
maxWidth -= nextSiblingMarginSizes.left;
|
|
41
|
-
maxWidth -= nextSiblingMarginSizes.right;
|
|
42
|
-
}
|
|
43
|
-
nextSibling = nextSibling.nextElementSibling;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return maxWidth;
|
|
47
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { getAvailableHeight } from "./get_available_height.js";
|
|
2
|
-
import { resolveCSSSize } from "./resolve_css_size.js";
|
|
3
|
-
|
|
4
|
-
export const getMinHeight = (element, availableHeight) => {
|
|
5
|
-
const computedStyle = window.getComputedStyle(element);
|
|
6
|
-
const { minHeight, fontSize } = computedStyle;
|
|
7
|
-
return resolveCSSSize(minHeight, {
|
|
8
|
-
availableSize:
|
|
9
|
-
availableHeight === undefined
|
|
10
|
-
? getAvailableHeight(element)
|
|
11
|
-
: availableHeight,
|
|
12
|
-
fontSize,
|
|
13
|
-
});
|
|
14
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { getAvailableWidth } from "./get_available_width.js";
|
|
2
|
-
import { resolveCSSSize } from "./resolve_css_size.js";
|
|
3
|
-
|
|
4
|
-
export const getMinWidth = (element, availableWidth) => {
|
|
5
|
-
const computedStyle = window.getComputedStyle(element);
|
|
6
|
-
const { minWidth, fontSize } = computedStyle;
|
|
7
|
-
return resolveCSSSize(minWidth, {
|
|
8
|
-
availableSize:
|
|
9
|
-
availableWidth === undefined
|
|
10
|
-
? getAvailableWidth(element)
|
|
11
|
-
: availableWidth,
|
|
12
|
-
fontSize,
|
|
13
|
-
});
|
|
14
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const getPaddingSizes = (element) => {
|
|
2
|
-
const { paddingLeft, paddingRight, paddingTop, paddingBottom } =
|
|
3
|
-
window.getComputedStyle(element, null);
|
|
4
|
-
return {
|
|
5
|
-
left: parseFloat(paddingLeft),
|
|
6
|
-
right: parseFloat(paddingRight),
|
|
7
|
-
top: parseFloat(paddingTop),
|
|
8
|
-
bottom: parseFloat(paddingBottom),
|
|
9
|
-
};
|
|
10
|
-
};
|
package/src/size/get_width.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useState } from "preact/hooks";
|
|
2
|
-
import { getAvailableHeight } from "../get_available_height.js";
|
|
3
|
-
|
|
4
|
-
export const useAvailableHeight = (elementRef) => {
|
|
5
|
-
const [availableHeight, availableHeightSetter] = useState(-1);
|
|
6
|
-
|
|
7
|
-
useLayoutEffect(() => {
|
|
8
|
-
const element = elementRef.current;
|
|
9
|
-
const parentElement = element.parentElement;
|
|
10
|
-
let raf;
|
|
11
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
12
|
-
const [entry] = entries;
|
|
13
|
-
const parentHeight = entry.contentRect.height;
|
|
14
|
-
const availableH = getAvailableHeight(element, parentHeight);
|
|
15
|
-
raf = requestAnimationFrame(() => {
|
|
16
|
-
availableHeightSetter(availableH);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
resizeObserver.observe(parentElement);
|
|
20
|
-
return () => {
|
|
21
|
-
resizeObserver.disconnect();
|
|
22
|
-
cancelAnimationFrame(raf);
|
|
23
|
-
};
|
|
24
|
-
}, []);
|
|
25
|
-
|
|
26
|
-
return availableHeight;
|
|
27
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useState } from "preact/hooks";
|
|
2
|
-
import { getAvailableWidth } from "../get_available_width.js";
|
|
3
|
-
|
|
4
|
-
export const useAvailableWidth = (elementRef) => {
|
|
5
|
-
const [availableWidth, availableWidthSetter] = useState(-1);
|
|
6
|
-
|
|
7
|
-
useLayoutEffect(() => {
|
|
8
|
-
const element = elementRef.current;
|
|
9
|
-
const parentElement = element.parentElement;
|
|
10
|
-
let raf;
|
|
11
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
12
|
-
const [entry] = entries;
|
|
13
|
-
const parentWidth = entry.contentRect.width;
|
|
14
|
-
const availableW = getAvailableWidth(element, parentWidth);
|
|
15
|
-
raf = requestAnimationFrame(() => {
|
|
16
|
-
availableWidthSetter(availableW);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
resizeObserver.observe(parentElement);
|
|
20
|
-
return () => {
|
|
21
|
-
resizeObserver.disconnect();
|
|
22
|
-
cancelAnimationFrame(raf);
|
|
23
|
-
};
|
|
24
|
-
}, []);
|
|
25
|
-
|
|
26
|
-
return availableWidth;
|
|
27
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getMaxHeight } from "../get_max_height.js";
|
|
2
|
-
|
|
3
|
-
export const useMaxHeight = (elementRef, availableHeight) => {
|
|
4
|
-
const element = elementRef.current;
|
|
5
|
-
if (!element) {
|
|
6
|
-
return -1;
|
|
7
|
-
}
|
|
8
|
-
const maxWidth = getMaxHeight(element, availableHeight);
|
|
9
|
-
return maxWidth;
|
|
10
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getMaxWidth } from "../get_max_width.js";
|
|
2
|
-
|
|
3
|
-
export const useMaxWidth = (elementRef, availableWidth) => {
|
|
4
|
-
const element = elementRef.current;
|
|
5
|
-
if (!element) {
|
|
6
|
-
return -1;
|
|
7
|
-
}
|
|
8
|
-
const maxWidth = getMaxWidth(element, availableWidth);
|
|
9
|
-
return maxWidth;
|
|
10
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useState } from "preact/hooks";
|
|
2
|
-
|
|
3
|
-
export const useResizeStatus = (elementRef, { as = "number" } = {}) => {
|
|
4
|
-
const [resizing, setIsResizing] = useState(false);
|
|
5
|
-
const [resizeWidth, setResizeWidth] = useState(null);
|
|
6
|
-
const [resizeHeight, setResizeHeight] = useState(null);
|
|
7
|
-
|
|
8
|
-
useLayoutEffect(() => {
|
|
9
|
-
const element = elementRef.current;
|
|
10
|
-
|
|
11
|
-
const onresizestart = (e) => {
|
|
12
|
-
const sizeInfo = e.detail;
|
|
13
|
-
setResizeWidth(
|
|
14
|
-
as === "number" ? sizeInfo.width : sizeInfo.widthAsPercentage,
|
|
15
|
-
);
|
|
16
|
-
setResizeHeight(
|
|
17
|
-
as === "number" ? sizeInfo.height : sizeInfo.heightAsPercentage,
|
|
18
|
-
);
|
|
19
|
-
setIsResizing(true);
|
|
20
|
-
};
|
|
21
|
-
const onresize = (e) => {
|
|
22
|
-
const sizeInfo = e.detail;
|
|
23
|
-
setResizeWidth(
|
|
24
|
-
as === "number" ? sizeInfo.width : sizeInfo.widthAsPercentage,
|
|
25
|
-
);
|
|
26
|
-
setResizeHeight(
|
|
27
|
-
as === "number" ? sizeInfo.height : sizeInfo.heightAsPercentage,
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
const onresizeend = () => {
|
|
31
|
-
setIsResizing(false);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
element.addEventListener("resizestart", onresizestart);
|
|
35
|
-
element.addEventListener("resize", onresize);
|
|
36
|
-
element.addEventListener("resizeend", onresizeend);
|
|
37
|
-
return () => {
|
|
38
|
-
element.removeEventListener("resizestart", onresizestart);
|
|
39
|
-
element.removeEventListener("resize", onresize);
|
|
40
|
-
element.removeEventListener("resizeend", onresizeend);
|
|
41
|
-
};
|
|
42
|
-
}, [as]);
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
resizing,
|
|
46
|
-
resizeWidth,
|
|
47
|
-
resizeHeight,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// to use when width is set as percentage
|
|
52
|
-
export const useInitialWidth = (width, elementRef) => {
|
|
53
|
-
const [initialWidth, setInitialWidth] = useState(null);
|
|
54
|
-
useLayoutEffect(() => {
|
|
55
|
-
const element = elementRef.current;
|
|
56
|
-
const availableWidth = element.parentElement.offsetWidth;
|
|
57
|
-
setInitialWidth(
|
|
58
|
-
width.endsWith("%") ? (parseFloat(width) / 100) * availableWidth : width,
|
|
59
|
-
);
|
|
60
|
-
}, [width]);
|
|
61
|
-
return initialWidth;
|
|
62
|
-
};
|