etudes 5.2.0 → 5.3.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.
Files changed (164) hide show
  1. package/components/Accordion.js +171 -205
  2. package/components/BurgerButton.js +40 -94
  3. package/components/Carousel.js +87 -123
  4. package/components/Collection.js +84 -120
  5. package/components/Counter.js +32 -63
  6. package/components/CoverImage.js +24 -68
  7. package/components/CoverVideo.js +25 -69
  8. package/components/DebugConsole.js +27 -79
  9. package/components/Dial.js +28 -65
  10. package/components/Dropdown.js +86 -98
  11. package/components/FlatSVG.js +22 -71
  12. package/components/Image.js +21 -50
  13. package/components/MasonryGrid.js +122 -257
  14. package/components/Panorama.js +48 -92
  15. package/components/PanoramaSlider.js +57 -113
  16. package/components/RangeSlider.js +125 -182
  17. package/components/RotatingGallery.js +28 -59
  18. package/components/SelectableButton.js +10 -54
  19. package/components/Slider.js +108 -159
  20. package/components/StepwiseSlider.js +124 -176
  21. package/components/SwipeContainer.js +30 -73
  22. package/components/TextField.js +12 -49
  23. package/components/Video.js +31 -61
  24. package/components/WithTooltip.js +117 -111
  25. package/components/index.js +24 -0
  26. package/hooks/index.js +17 -0
  27. package/hooks/useClickOutsideEffect.js +8 -38
  28. package/hooks/useDragEffect.js +20 -53
  29. package/hooks/useDragValueEffect.js +31 -81
  30. package/hooks/useImageSize.js +16 -38
  31. package/hooks/useInterval.js +9 -41
  32. package/hooks/useLoadImageEffect.js +15 -48
  33. package/hooks/useLoadVideoMetadataEffect.js +15 -48
  34. package/hooks/useMounted.js +5 -25
  35. package/hooks/usePrevious.js +4 -9
  36. package/hooks/useRect.js +9 -29
  37. package/hooks/useResizeEffect.js +10 -44
  38. package/hooks/useScrollPositionEffect.js +19 -50
  39. package/hooks/useSearchParamState.js +12 -34
  40. package/hooks/useSize.js +9 -29
  41. package/hooks/useTimeout.js +8 -38
  42. package/hooks/useVideoSize.js +16 -38
  43. package/hooks/useViewportSize.js +7 -27
  44. package/operators/Conditional.js +6 -11
  45. package/operators/Each.js +6 -14
  46. package/operators/ExtractChild.js +9 -36
  47. package/operators/ExtractChildren.js +7 -34
  48. package/operators/Repeat.js +4 -37
  49. package/operators/index.js +5 -0
  50. package/package.json +27 -41
  51. package/providers/ScrollPositionProvider.js +37 -60
  52. package/providers/index.js +1 -0
  53. package/utils/asClassNameDict.js +1 -5
  54. package/utils/asComponentDict.js +11 -16
  55. package/utils/asStyleDict.js +1 -5
  56. package/utils/cloneStyledElement.js +14 -61
  57. package/utils/index.js +5 -22
  58. package/utils/styles.js +5 -21
  59. package/components/Accordion.d.ts +0 -219
  60. package/components/Accordion.js.map +0 -1
  61. package/components/BurgerButton.d.ts +0 -34
  62. package/components/BurgerButton.js.map +0 -1
  63. package/components/Carousel.d.ts +0 -53
  64. package/components/Carousel.js.map +0 -1
  65. package/components/Collection.d.ts +0 -171
  66. package/components/Collection.js.map +0 -1
  67. package/components/Counter.d.ts +0 -11
  68. package/components/Counter.js.map +0 -1
  69. package/components/CoverImage.d.ts +0 -28
  70. package/components/CoverImage.js.map +0 -1
  71. package/components/CoverVideo.d.ts +0 -28
  72. package/components/CoverVideo.js.map +0 -1
  73. package/components/DebugConsole.d.ts +0 -15
  74. package/components/DebugConsole.js.map +0 -1
  75. package/components/Dial.d.ts +0 -79
  76. package/components/Dial.js.map +0 -1
  77. package/components/Dropdown.d.ts +0 -109
  78. package/components/Dropdown.js.map +0 -1
  79. package/components/FlatSVG.d.ts +0 -72
  80. package/components/FlatSVG.js.map +0 -1
  81. package/components/Image.d.ts +0 -144
  82. package/components/Image.js.map +0 -1
  83. package/components/MasonryGrid.d.ts +0 -29
  84. package/components/MasonryGrid.js.map +0 -1
  85. package/components/Panorama.d.ts +0 -77
  86. package/components/Panorama.js.map +0 -1
  87. package/components/PanoramaSlider.d.ts +0 -71
  88. package/components/PanoramaSlider.js.map +0 -1
  89. package/components/RangeSlider.d.ts +0 -34
  90. package/components/RangeSlider.js.map +0 -1
  91. package/components/RotatingGallery.d.ts +0 -91
  92. package/components/RotatingGallery.js.map +0 -1
  93. package/components/SelectableButton.d.ts +0 -19
  94. package/components/SelectableButton.js.map +0 -1
  95. package/components/Slider.d.ts +0 -160
  96. package/components/Slider.js.map +0 -1
  97. package/components/StepwiseSlider.d.ts +0 -215
  98. package/components/StepwiseSlider.js.map +0 -1
  99. package/components/SwipeContainer.d.ts +0 -21
  100. package/components/SwipeContainer.js.map +0 -1
  101. package/components/TextField.d.ts +0 -21
  102. package/components/TextField.js.map +0 -1
  103. package/components/Video.d.ts +0 -38
  104. package/components/Video.js.map +0 -1
  105. package/components/WithTooltip.d.ts +0 -32
  106. package/components/WithTooltip.js.map +0 -1
  107. package/hooks/useClickOutsideEffect.d.ts +0 -2
  108. package/hooks/useClickOutsideEffect.js.map +0 -1
  109. package/hooks/useDragEffect.d.ts +0 -48
  110. package/hooks/useDragEffect.js.map +0 -1
  111. package/hooks/useDragValueEffect.d.ts +0 -56
  112. package/hooks/useDragValueEffect.js.map +0 -1
  113. package/hooks/useImageSize.d.ts +0 -21
  114. package/hooks/useImageSize.js.map +0 -1
  115. package/hooks/useInterval.d.ts +0 -18
  116. package/hooks/useInterval.js.map +0 -1
  117. package/hooks/useLoadImageEffect.d.ts +0 -43
  118. package/hooks/useLoadImageEffect.js.map +0 -1
  119. package/hooks/useLoadVideoMetadataEffect.d.ts +0 -35
  120. package/hooks/useLoadVideoMetadataEffect.js.map +0 -1
  121. package/hooks/useMounted.d.ts +0 -1
  122. package/hooks/useMounted.js.map +0 -1
  123. package/hooks/usePrevious.d.ts +0 -19
  124. package/hooks/usePrevious.js.map +0 -1
  125. package/hooks/useRect.d.ts +0 -11
  126. package/hooks/useRect.js.map +0 -1
  127. package/hooks/useResizeEffect.d.ts +0 -17
  128. package/hooks/useResizeEffect.js.map +0 -1
  129. package/hooks/useScrollPositionEffect.d.ts +0 -13
  130. package/hooks/useScrollPositionEffect.js.map +0 -1
  131. package/hooks/useSearchParamState.d.ts +0 -34
  132. package/hooks/useSearchParamState.js.map +0 -1
  133. package/hooks/useSize.d.ts +0 -10
  134. package/hooks/useSize.js.map +0 -1
  135. package/hooks/useTimeout.d.ts +0 -10
  136. package/hooks/useTimeout.js.map +0 -1
  137. package/hooks/useVideoSize.d.ts +0 -21
  138. package/hooks/useVideoSize.js.map +0 -1
  139. package/hooks/useViewportSize.d.ts +0 -7
  140. package/hooks/useViewportSize.js.map +0 -1
  141. package/operators/Conditional.d.ts +0 -5
  142. package/operators/Conditional.js.map +0 -1
  143. package/operators/Each.d.ts +0 -7
  144. package/operators/Each.js.map +0 -1
  145. package/operators/ExtractChild.d.ts +0 -8
  146. package/operators/ExtractChild.js.map +0 -1
  147. package/operators/ExtractChildren.d.ts +0 -6
  148. package/operators/ExtractChildren.js.map +0 -1
  149. package/operators/Repeat.d.ts +0 -11
  150. package/operators/Repeat.js.map +0 -1
  151. package/providers/ScrollPositionProvider.d.ts +0 -15
  152. package/providers/ScrollPositionProvider.js.map +0 -1
  153. package/utils/asClassNameDict.d.ts +0 -3
  154. package/utils/asClassNameDict.js.map +0 -1
  155. package/utils/asComponentDict.d.ts +0 -5
  156. package/utils/asComponentDict.js.map +0 -1
  157. package/utils/asStyleDict.d.ts +0 -4
  158. package/utils/asStyleDict.js.map +0 -1
  159. package/utils/cloneStyledElement.d.ts +0 -18
  160. package/utils/cloneStyledElement.js.map +0 -1
  161. package/utils/index.d.ts +0 -5
  162. package/utils/index.js.map +0 -1
  163. package/utils/styles.d.ts +0 -2
  164. package/utils/styles.js.map +0 -1
@@ -1,40 +1,11 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.useClickOutsideEffect = useClickOutsideEffect;
29
- var react_1 = require("react");
30
- function useClickOutsideEffect(targetRef, handler, deps) {
31
- if (deps === void 0) { deps = []; }
32
- (0, react_1.useEffect)(function () {
33
- var clickOutsideHandler = function (event) {
1
+ import { useEffect } from 'react';
2
+ export function useClickOutsideEffect(targetRef, handler, deps = []) {
3
+ useEffect(() => {
4
+ const clickOutsideHandler = (event) => {
34
5
  if (!(event.target instanceof Node))
35
6
  return;
36
- var isOutside = true;
37
- var node = event.target;
7
+ let isOutside = true;
8
+ let node = event.target;
38
9
  while (node) {
39
10
  if (node === targetRef.current) {
40
11
  isOutside = false;
@@ -49,9 +20,8 @@ function useClickOutsideEffect(targetRef, handler, deps) {
49
20
  handler();
50
21
  };
51
22
  window.addEventListener('click', clickOutsideHandler, true);
52
- return function () {
23
+ return () => {
53
24
  window.removeEventListener('click', clickOutsideHandler, true);
54
25
  };
55
- }, __spreadArray([], __read(deps), false));
26
+ }, [...deps]);
56
27
  }
57
- //# sourceMappingURL=useClickOutsideEffect.js.map
@@ -1,33 +1,5 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.useDragEffect = useDragEffect;
29
- var react_1 = require("react");
30
- var spase_1 = require("spase");
1
+ import { useEffect, useRef } from 'react';
2
+ import { Point } from 'spase';
31
3
  /**
32
4
  * Hook for adding effectful dragging interaction to an element.
33
5
  *
@@ -39,20 +11,18 @@ var spase_1 = require("spase");
39
11
  *
40
12
  * @returns The states created for this effect.
41
13
  */
42
- function useDragEffect(targetRef, _a, deps) {
43
- var _b = _a.isEnabled, isEnabled = _b === void 0 ? true : _b, _c = _a.updatesCursor, updatesCursor = _c === void 0 ? true : _c, onDragStart = _a.onDragStart, onDragMove = _a.onDragMove, onDragEnd = _a.onDragEnd;
44
- if (deps === void 0) { deps = []; }
45
- var element = targetRef.current;
46
- var startPositionRef = (0, react_1.useRef)();
47
- var dragPositionRef = (0, react_1.useRef)();
14
+ export function useDragEffect(targetRef, { isEnabled = true, updatesCursor = true, onDragStart, onDragMove, onDragEnd, }, deps = []) {
15
+ const element = targetRef.current;
16
+ const startPositionRef = useRef();
17
+ const dragPositionRef = useRef();
48
18
  if (updatesCursor && element)
49
19
  element.style.cursor = 'grab';
50
- (0, react_1.useEffect)(function () {
20
+ useEffect(() => {
51
21
  if (!element || !isEnabled)
52
22
  return;
53
- var mouseDownHandler = function (event) {
23
+ const mouseDownHandler = (event) => {
54
24
  event.preventDefault();
55
- var position = new spase_1.Point([event.clientX, event.clientY]);
25
+ const position = new Point([event.clientX, event.clientY]);
56
26
  startPositionRef.current = position;
57
27
  dragPositionRef.current = position;
58
28
  element.addEventListener('mousemove', mouseMoveHandler);
@@ -60,24 +30,22 @@ function useDragEffect(targetRef, _a, deps) {
60
30
  element.addEventListener('mouseleave', mouseUpHandler);
61
31
  if (updatesCursor)
62
32
  element.style.cursor = 'grabbing';
63
- onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart(position);
33
+ onDragStart?.(position);
64
34
  };
65
- var mouseMoveHandler = function (event) {
66
- var _a;
35
+ const mouseMoveHandler = (event) => {
67
36
  if (!startPositionRef.current)
68
37
  return;
69
- var position = new spase_1.Point([event.clientX, event.clientY]);
70
- var displacement = ((_a = dragPositionRef.current) !== null && _a !== void 0 ? _a : startPositionRef.current).subtract(position);
38
+ const position = new Point([event.clientX, event.clientY]);
39
+ const displacement = (dragPositionRef.current ?? startPositionRef.current).subtract(position);
71
40
  dragPositionRef.current = position;
72
- onDragMove === null || onDragMove === void 0 ? void 0 : onDragMove(displacement, startPositionRef.current);
41
+ onDragMove?.(displacement, startPositionRef.current);
73
42
  };
74
- var mouseUpHandler = function (event) {
75
- var _a;
43
+ const mouseUpHandler = (event) => {
76
44
  if (!startPositionRef.current)
77
45
  return;
78
- var position = new spase_1.Point([event.clientX, event.clientY]);
79
- var displacement = ((_a = dragPositionRef.current) !== null && _a !== void 0 ? _a : startPositionRef.current).subtract(position);
80
- onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(position, displacement, startPositionRef.current);
46
+ const position = new Point([event.clientX, event.clientY]);
47
+ const displacement = (dragPositionRef.current ?? startPositionRef.current).subtract(position);
48
+ onDragEnd?.(position, displacement, startPositionRef.current);
81
49
  startPositionRef.current = undefined;
82
50
  dragPositionRef.current = undefined;
83
51
  element.removeEventListener('mousemove', mouseMoveHandler);
@@ -87,12 +55,11 @@ function useDragEffect(targetRef, _a, deps) {
87
55
  element.style.cursor = 'grab';
88
56
  };
89
57
  element.addEventListener('mousedown', mouseDownHandler);
90
- return function () {
58
+ return () => {
91
59
  element.removeEventListener('mousedown', mouseDownHandler);
92
60
  element.removeEventListener('mousemove', mouseMoveHandler);
93
61
  element.removeEventListener('mouseup', mouseUpHandler, { capture: true });
94
62
  element.removeEventListener('mouseleave', mouseUpHandler);
95
63
  };
96
- }, __spreadArray([element, isEnabled], __read(deps), false));
64
+ }, [element, isEnabled, ...deps]);
97
65
  }
98
- //# sourceMappingURL=useDragEffect.js.map
@@ -1,59 +1,6 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __read = (this && this.__read) || function (o, n) {
25
- var m = typeof Symbol === "function" && o[Symbol.iterator];
26
- if (!m) return o;
27
- var i = m.call(o), r, ar = [], e;
28
- try {
29
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
- }
31
- catch (error) { e = { error: error }; }
32
- finally {
33
- try {
34
- if (r && !r.done && (m = i["return"])) m.call(i);
35
- }
36
- finally { if (e) throw e.error; }
37
- }
38
- return ar;
39
- };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
- if (ar || !(i in from)) {
43
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
- ar[i] = from[i];
45
- }
46
- }
47
- return to.concat(ar || Array.prototype.slice.call(from));
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.useDragValueEffect = useDragValueEffect;
54
- var react_1 = __importDefault(require("fast-deep-equal/react"));
55
- var interactjs_1 = __importDefault(require("interactjs"));
56
- var react_2 = require("react");
1
+ import isDeepEqual from 'fast-deep-equal/react';
2
+ import interact from 'interactjs';
3
+ import { useEffect, useRef, useState } from 'react';
57
4
  /**
58
5
  * Hook for adding effectful dragging interaction to an element.
59
6
  *
@@ -65,8 +12,7 @@ var react_2 = require("react");
65
12
  *
66
13
  * @returns The states created for this effect.
67
14
  */
68
- function useDragValueEffect(targetRef, _a, deps) {
69
- var initialValue = _a.initialValue, transform = _a.transform, onDragStart = _a.onDragStart, onDragMove = _a.onDragMove, onDragEnd = _a.onDragEnd, options = __rest(_a, ["initialValue", "transform", "onDragStart", "onDragMove", "onDragEnd"]);
15
+ export function useDragValueEffect(targetRef, { initialValue, transform, onDragStart, onDragMove, onDragEnd, ...options }, deps) {
70
16
  /**
71
17
  * Sets the current associated value reference. This reference object is equal
72
18
  * to the `value` state but differs slightly in how they are set. Because
@@ -77,53 +23,58 @@ function useDragValueEffect(targetRef, _a, deps) {
77
23
  *
78
24
  * @returns `true` if the value was set, `false` otherwise.
79
25
  */
80
- var setValueRef = function (value) {
81
- if ((0, react_1.default)(valueRef.current, value))
26
+ const setValueRef = (value) => {
27
+ if (isDeepEqual(valueRef.current, value))
82
28
  return false;
83
29
  valueRef.current = value;
84
30
  return true;
85
31
  };
86
- var valueRef = (0, react_2.useRef)(initialValue);
87
- var _b = __read((0, react_2.useState)(false), 2), hasDragged = _b[0], setHasDragged = _b[1];
88
- var _c = __read((0, react_2.useState)(false), 2), isDragging = _c[0], setIsDragging = _c[1];
89
- var _d = __read((0, react_2.useState)(false), 2), isReleasing = _d[0], setIsReleasing = _d[1];
90
- var _e = __read((0, react_2.useState)(initialValue), 2), value = _e[0], setValue = _e[1];
91
- (0, react_2.useEffect)(function () {
32
+ const valueRef = useRef(initialValue);
33
+ const [hasDragged, setHasDragged] = useState(false);
34
+ const [isDragging, setIsDragging] = useState(false);
35
+ const [isReleasing, setIsReleasing] = useState(false);
36
+ const [value, setValue] = useState(initialValue);
37
+ useEffect(() => {
92
38
  if (targetRef.current) {
93
39
  // Do not consume states in these listeners as they will remain their
94
40
  // initial values within the scope of the listeners.
95
- (0, interactjs_1.default)(targetRef.current).draggable(__assign(__assign({ inertia: true }, options), { onstart: function () {
41
+ interact(targetRef.current).draggable({
42
+ inertia: true,
43
+ ...options,
44
+ onstart: () => {
96
45
  setHasDragged(true);
97
46
  setIsDragging(true);
98
47
  setIsReleasing(false);
99
- onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart();
100
- }, onmove: function (_a) {
101
- var dx = _a.dx, dy = _a.dy;
102
- var newValue = transform(valueRef.current, dx, dy);
48
+ onDragStart?.();
49
+ },
50
+ onmove: ({ dx, dy }) => {
51
+ const newValue = transform(valueRef.current, dx, dy);
103
52
  if (setValueRef(newValue)) {
104
53
  setValue(newValue);
105
54
  }
106
55
  setIsDragging(true);
107
56
  setIsReleasing(false);
108
- onDragMove === null || onDragMove === void 0 ? void 0 : onDragMove(dx, dy);
109
- }, onend: function () {
57
+ onDragMove?.(dx, dy);
58
+ },
59
+ onend: () => {
110
60
  setIsDragging(false);
111
61
  setIsReleasing(true);
112
- onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd();
113
- } }));
62
+ onDragEnd?.();
63
+ },
64
+ });
114
65
  }
115
- return function () {
66
+ return () => {
116
67
  if (targetRef.current) {
117
- (0, interactjs_1.default)(targetRef.current).unset();
68
+ interact(targetRef.current).unset();
118
69
  }
119
70
  };
120
- }, __spreadArray([], __read(deps !== null && deps !== void 0 ? deps : []), false));
121
- (0, react_2.useEffect)(function () {
71
+ }, [...deps ?? []]);
72
+ useEffect(() => {
122
73
  if (hasDragged)
123
74
  return;
124
75
  setValue(initialValue);
125
76
  }, [initialValue]);
126
- (0, react_2.useEffect)(function () {
77
+ useEffect(() => {
127
78
  setValueRef(value);
128
79
  }, [value]);
129
80
  return {
@@ -132,4 +83,3 @@ function useDragValueEffect(targetRef, _a, deps) {
132
83
  value: [value, setValue],
133
84
  };
134
85
  }
135
- //# sourceMappingURL=useDragValueEffect.js.map
@@ -1,25 +1,6 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.useImageSize = useImageSize;
20
- var react_1 = require("react");
21
- var spase_1 = require("spase");
22
- var useLoadImageEffect_1 = require("./useLoadImageEffect");
1
+ import { useState } from 'react';
2
+ import { Size } from 'spase';
3
+ import { useLoadImageEffect } from './useLoadImageEffect.js';
23
4
  /**
24
5
  * Hook for retrieving the size of an image.
25
6
  *
@@ -29,28 +10,26 @@ var useLoadImageEffect_1 = require("./useLoadImageEffect");
29
10
  * @returns The actual size of the image if loading was successful, `undefined`
30
11
  * otherwise.
31
12
  */
32
- function useImageSize(_a, _b) {
33
- var src = _a.src, srcSet = _a.srcSet, sizes = _a.sizes;
34
- var _c = _b === void 0 ? {} : _b, _d = _c.preservesSizeBetweenLoads, preservesSizeBetweenLoads = _d === void 0 ? true : _d, onLoadStart = _c.onLoadStart, onLoadComplete = _c.onLoadComplete, onLoadError = _c.onLoadError;
35
- var handleLoad = function (element) {
13
+ export function useImageSize({ src, srcSet, sizes }, { preservesSizeBetweenLoads = true, onLoadStart, onLoadComplete, onLoadError } = {}) {
14
+ const handleLoad = (element) => {
36
15
  if (!preservesSizeBetweenLoads)
37
16
  setImageSize(undefined);
38
- onLoadStart === null || onLoadStart === void 0 ? void 0 : onLoadStart(element);
17
+ onLoadStart?.(element);
39
18
  };
40
- var handleLoadComplete = function (element) {
19
+ const handleLoadComplete = (element) => {
41
20
  setImageSize(getSize(element));
42
- onLoadComplete === null || onLoadComplete === void 0 ? void 0 : onLoadComplete(element);
21
+ onLoadComplete?.(element);
43
22
  };
44
- var handleLoadError = function (element) {
23
+ const handleLoadError = (element) => {
45
24
  if (!preservesSizeBetweenLoads)
46
25
  setImageSize(undefined);
47
- onLoadError === null || onLoadError === void 0 ? void 0 : onLoadError(element);
26
+ onLoadError?.(element);
48
27
  };
49
- var _e = __read((0, react_1.useState)(), 2), imageSize = _e[0], setImageSize = _e[1];
50
- (0, useLoadImageEffect_1.useLoadImageEffect)({ src: src, srcSet: srcSet, sizes: sizes }, {
51
- onLoadStart: function (t) { return handleLoad(t); },
52
- onLoadComplete: function (t) { return handleLoadComplete(t); },
53
- onLoadError: function (t) { return handleLoadError(t); },
28
+ const [imageSize, setImageSize] = useState();
29
+ useLoadImageEffect({ src, srcSet, sizes }, {
30
+ onLoadStart: t => handleLoad(t),
31
+ onLoadComplete: t => handleLoadComplete(t),
32
+ onLoadError: t => handleLoadError(t),
54
33
  });
55
34
  return imageSize;
56
35
  }
@@ -61,6 +40,5 @@ function getSize(element) {
61
40
  return undefined;
62
41
  if (typeof element.height !== 'number')
63
42
  return undefined;
64
- return new spase_1.Size([element.width, element.height]);
43
+ return new Size([element.width, element.height]);
65
44
  }
66
- //# sourceMappingURL=useImageSize.js.map
@@ -1,32 +1,4 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.useInterval = useInterval;
29
- var react_1 = require("react");
1
+ import { useEffect, useRef } from 'react';
30
2
  /**
31
3
  * Hoook for invoking a method repeatedly on every set interval.
32
4
  *
@@ -35,21 +7,17 @@ var react_1 = require("react");
35
7
  * @param options See {@link Options}.
36
8
  * @param deps Dependencies that trigger this effect.
37
9
  */
38
- function useInterval(handler, interval, _a, deps) {
39
- var _b = _a === void 0 ? {} : _a, _c = _b.shouldInvokeInitially, shouldInvokeInitially = _c === void 0 ? false : _c;
40
- if (deps === void 0) { deps = []; }
41
- var handlerRef = (0, react_1.useRef)();
42
- (0, react_1.useEffect)(function () {
10
+ export function useInterval(handler, interval, { shouldInvokeInitially = false } = {}, deps = []) {
11
+ const handlerRef = useRef();
12
+ useEffect(() => {
43
13
  handlerRef.current = handler;
44
14
  }, [handler]);
45
- (0, react_1.useEffect)(function () {
46
- var _a;
15
+ useEffect(() => {
47
16
  if (interval === undefined || interval <= 0)
48
17
  return;
49
18
  if (shouldInvokeInitially === true)
50
- (_a = handlerRef.current) === null || _a === void 0 ? void 0 : _a.call(handlerRef);
51
- var timer = window.setInterval(function () { var _a; return (_a = handlerRef.current) === null || _a === void 0 ? void 0 : _a.call(handlerRef); }, interval);
52
- return function () { return clearInterval(timer); };
53
- }, __spreadArray([interval], __read(deps), false));
19
+ handlerRef.current?.();
20
+ const timer = window.setInterval(() => handlerRef.current?.(), interval);
21
+ return () => clearInterval(timer);
22
+ }, [interval, ...deps]);
54
23
  }
55
- //# sourceMappingURL=useInterval.js.map
@@ -1,32 +1,4 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.useLoadImageEffect = useLoadImageEffect;
29
- var react_1 = require("react");
1
+ import { useEffect, useRef } from 'react';
30
2
  /**
31
3
  * Hook for preloading an image.
32
4
  *
@@ -34,20 +6,17 @@ var react_1 = require("react");
34
6
  * @param options See {@link UseLoadImageEffectOptions}.
35
7
  * @param deps Additional dependencies.
36
8
  */
37
- function useLoadImageEffect(_a, _b, deps) {
38
- var src = _a.src, srcSet = _a.srcSet, sizes = _a.sizes;
39
- var _c = _b === void 0 ? {} : _b, onLoadStart = _c.onLoadStart, onLoadComplete = _c.onLoadComplete, onLoadError = _c.onLoadError;
40
- if (deps === void 0) { deps = []; }
41
- var imageLoadCompleteHandler = function (event) {
42
- var element = event.currentTarget;
43
- onLoadComplete === null || onLoadComplete === void 0 ? void 0 : onLoadComplete(element);
9
+ export function useLoadImageEffect({ src, srcSet, sizes }, { onLoadStart, onLoadComplete, onLoadError } = {}, deps = []) {
10
+ const imageLoadCompleteHandler = (event) => {
11
+ const element = event.currentTarget;
12
+ onLoadComplete?.(element);
44
13
  };
45
- var imageLoadErrorHandler = function (event) {
46
- var element = event.currentTarget;
47
- onLoadError === null || onLoadError === void 0 ? void 0 : onLoadError(element);
14
+ const imageLoadErrorHandler = (event) => {
15
+ const element = event.currentTarget;
16
+ onLoadError?.(element);
48
17
  };
49
- var imageRef = (0, react_1.useRef)(undefined);
50
- (0, react_1.useEffect)(function () {
18
+ const imageRef = useRef(undefined);
19
+ useEffect(() => {
51
20
  imageRef.current = new Image();
52
21
  if (src)
53
22
  imageRef.current.src = src;
@@ -55,15 +24,13 @@ function useLoadImageEffect(_a, _b, deps) {
55
24
  imageRef.current.srcset = srcSet;
56
25
  if (sizes)
57
26
  imageRef.current.sizes = sizes;
58
- onLoadStart === null || onLoadStart === void 0 ? void 0 : onLoadStart(imageRef.current);
27
+ onLoadStart?.(imageRef.current);
59
28
  imageRef.current.addEventListener('load', imageLoadCompleteHandler);
60
29
  imageRef.current.addEventListener('error', imageLoadErrorHandler);
61
- return function () {
62
- var _a, _b;
63
- (_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('load', imageLoadCompleteHandler);
64
- (_b = imageRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('error', imageLoadErrorHandler);
30
+ return () => {
31
+ imageRef.current?.removeEventListener('load', imageLoadCompleteHandler);
32
+ imageRef.current?.removeEventListener('error', imageLoadErrorHandler);
65
33
  imageRef.current = undefined;
66
34
  };
67
- }, __spreadArray([src, srcSet, sizes], __read(deps), false));
35
+ }, [src, srcSet, sizes, ...deps]);
68
36
  }
69
- //# sourceMappingURL=useLoadImageEffect.js.map
@@ -1,32 +1,4 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.useLoadVideoMetadataEffect = useLoadVideoMetadataEffect;
29
- var react_1 = require("react");
1
+ import { useEffect, useRef } from 'react';
30
2
  /**
31
3
  * Hook for retrieving the size of a video.
32
4
  *
@@ -34,32 +6,27 @@ var react_1 = require("react");
34
6
  * @param options See {@link UseLoadVideoMetadataEffectOptions}.
35
7
  * @param deps Additional dependencies.
36
8
  */
37
- function useLoadVideoMetadataEffect(_a, _b, deps) {
38
- var src = _a.src;
39
- var _c = _b === void 0 ? {} : _b, onLoadStart = _c.onLoadStart, onLoadComplete = _c.onLoadComplete, onLoadError = _c.onLoadError;
40
- if (deps === void 0) { deps = []; }
41
- var loadCompleteHandler = function (event) {
42
- var element = event.currentTarget;
43
- onLoadComplete === null || onLoadComplete === void 0 ? void 0 : onLoadComplete(element);
9
+ export function useLoadVideoMetadataEffect({ src }, { onLoadStart, onLoadComplete, onLoadError } = {}, deps = []) {
10
+ const loadCompleteHandler = (event) => {
11
+ const element = event.currentTarget;
12
+ onLoadComplete?.(element);
44
13
  };
45
- var loadErrorHandler = function (event) {
46
- var element = event.currentTarget;
47
- onLoadError === null || onLoadError === void 0 ? void 0 : onLoadError(element);
14
+ const loadErrorHandler = (event) => {
15
+ const element = event.currentTarget;
16
+ onLoadError?.(element);
48
17
  };
49
- var ref = (0, react_1.useRef)(undefined);
50
- (0, react_1.useEffect)(function () {
18
+ const ref = useRef(undefined);
19
+ useEffect(() => {
51
20
  ref.current = document.createElement('video');
52
21
  if (src)
53
22
  ref.current.src = src;
54
23
  ref.current.addEventListener('loadedmetadata', loadCompleteHandler);
55
24
  ref.current.addEventListener('error', loadErrorHandler);
56
- onLoadStart === null || onLoadStart === void 0 ? void 0 : onLoadStart(ref.current);
57
- return function () {
58
- var _a, _b;
59
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('loadedmetadata', loadCompleteHandler);
60
- (_b = ref.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('error', loadErrorHandler);
25
+ onLoadStart?.(ref.current);
26
+ return () => {
27
+ ref.current?.removeEventListener('loadedmetadata', loadCompleteHandler);
28
+ ref.current?.removeEventListener('error', loadErrorHandler);
61
29
  ref.current = undefined;
62
30
  };
63
- }, __spreadArray([src], __read(deps), false));
31
+ }, [src, ...deps]);
64
32
  }
65
- //# sourceMappingURL=useLoadVideoMetadataEffect.js.map