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,57 +1,20 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.TextField = void 0;
26
- var jsx_runtime_1 = require("react/jsx-runtime");
27
- var react_1 = require("react");
28
- var usePrevious_1 = require("../hooks/usePrevious");
29
- exports.TextField = (0, react_1.forwardRef)(function (_a, ref) {
30
- var _b = _a.emptyValue, emptyValue = _b === void 0 ? '' : _b, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, placeholder = _a.placeholder, externalValue = _a.value, formatter = _a.formatter, onFocus = _a.onFocus, onUnfocus = _a.onUnfocus, onValueChange = _a.onValueChange, props = __rest(_a, ["emptyValue", "isDisabled", "placeholder", "value", "formatter", "onFocus", "onUnfocus", "onValueChange"]);
31
- var handleValueChange = function (newValue) {
32
- var _a;
33
- var formatted = (newValue !== emptyValue) ? ((_a = formatter === null || formatter === void 0 ? void 0 : formatter(value, newValue)) !== null && _a !== void 0 ? _a : newValue) : emptyValue;
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect } from 'react';
3
+ import { usePrevious } from '../hooks/usePrevious.js';
4
+ export const TextField = forwardRef(({ emptyValue = '', isDisabled = false, placeholder, value: externalValue, formatter, onFocus, onUnfocus, onValueChange, ...props }, ref) => {
5
+ const handleValueChange = (newValue) => {
6
+ const formatted = (newValue !== emptyValue) ? (formatter?.(value, newValue) ?? newValue) : emptyValue;
34
7
  if (formatted === value)
35
8
  return;
36
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(formatted);
9
+ onValueChange?.(formatted);
37
10
  };
38
- var value = externalValue !== null && externalValue !== void 0 ? externalValue : emptyValue;
39
- var prevValue = (0, usePrevious_1.usePrevious)(value);
40
- (0, react_1.useEffect)(function () {
11
+ const value = externalValue ?? emptyValue;
12
+ const prevValue = usePrevious(value);
13
+ useEffect(() => {
41
14
  if (prevValue === undefined)
42
15
  return;
43
16
  handleValueChange(value);
44
17
  }, [value]);
45
- return ((0, jsx_runtime_1.jsx)("input", __assign({}, props, { ref: ref, "data-component": 'text-field', disabled: isDisabled, placeholder: placeholder, type: 'text', value: value, onBlur: function (_a) {
46
- var target = _a.target;
47
- return onUnfocus === null || onUnfocus === void 0 ? void 0 : onUnfocus(target.value);
48
- }, onChange: function (_a) {
49
- var target = _a.target;
50
- return handleValueChange(target.value);
51
- }, onFocus: function (_a) {
52
- var target = _a.target;
53
- return onFocus === null || onFocus === void 0 ? void 0 : onFocus(target.value);
54
- } })));
18
+ return (_jsx("input", { ...props, ref: ref, "data-component": 'text-field', disabled: isDisabled, placeholder: placeholder, type: 'text', value: value, onBlur: ({ target }) => onUnfocus?.(target.value), onChange: ({ target }) => handleValueChange(target.value), onFocus: ({ target }) => onFocus?.(target.value) }));
55
19
  });
56
- Object.defineProperty(exports.TextField, 'displayName', { value: 'TextField', writable: false });
57
- //# sourceMappingURL=TextField.js.map
20
+ Object.defineProperty(TextField, 'displayName', { value: 'TextField', writable: false });
@@ -1,44 +1,17 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Video = void 0;
26
- var jsx_runtime_1 = require("react/jsx-runtime");
27
- var react_1 = require("react");
28
- var useVideoSize_1 = require("../hooks/useVideoSize");
29
- exports.Video = (0, react_1.forwardRef)(function (_a, ref) {
30
- var _b;
31
- var _c = _a.autoLoop, autoLoop = _c === void 0 ? true : _c, _d = _a.autoPlay, autoPlay = _d === void 0 ? true : _d, _e = _a.hasControls, hasControls = _e === void 0 ? false : _e, _f = _a.isMuted, isMuted = _f === void 0 ? true : _f, _g = _a.playsInline, playsInline = _g === void 0 ? true : _g, posterSrc = _a.posterSrc, src = _a.src, onCanPlay = _a.onCanPlay, onEnd = _a.onEnd, onFullscreenChange = _a.onFullscreenChange, onLoadMetadata = _a.onLoadMetadata, onLoadMetadataComplete = _a.onLoadMetadataComplete, onLoadMetadataError = _a.onLoadMetadataError, onPause = _a.onPause, onPlay = _a.onPlay, onSizeChange = _a.onSizeChange, props = __rest(_a, ["autoLoop", "autoPlay", "hasControls", "isMuted", "playsInline", "posterSrc", "src", "onCanPlay", "onEnd", "onFullscreenChange", "onLoadMetadata", "onLoadMetadataComplete", "onLoadMetadataError", "onPause", "onPlay", "onSizeChange"]);
32
- var localRef = (0, react_1.useRef)(null);
33
- var videoRef = (_b = ref) !== null && _b !== void 0 ? _b : localRef;
34
- var size = (0, useVideoSize_1.useVideoSize)({
35
- src: src,
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useRef } from 'react';
3
+ import { useVideoSize } from '../hooks/useVideoSize.js';
4
+ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls = false, isMuted = true, playsInline = true, posterSrc, src, onCanPlay, onEnd, onFullscreenChange, onLoadMetadata, onLoadMetadataComplete, onLoadMetadataError, onPause, onPlay, onSizeChange, ...props }, ref) => {
5
+ const localRef = useRef(null);
6
+ const videoRef = ref ?? localRef;
7
+ const size = useVideoSize({
8
+ src,
36
9
  }, {
37
10
  onLoadStart: onLoadMetadata,
38
11
  onLoadComplete: onLoadMetadataComplete,
39
12
  onLoadError: onLoadMetadataError,
40
13
  });
41
- (0, react_1.useEffect)(function () {
14
+ useEffect(() => {
42
15
  if (!videoRef.current)
43
16
  return;
44
17
  videoRef.current.muted = isMuted;
@@ -46,50 +19,47 @@ exports.Video = (0, react_1.forwardRef)(function (_a, ref) {
46
19
  videoRef.current.addEventListener('webkitfullscreenchange', fullscreenChangeHandler);
47
20
  videoRef.current.addEventListener('mozfullscreenchange', fullscreenChangeHandler);
48
21
  videoRef.current.addEventListener('fullscreenchange', fullscreenChangeHandler);
49
- return function () {
50
- var _a, _b, _c;
22
+ return () => {
51
23
  pause();
52
- (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('webkitfullscreenchange', fullscreenChangeHandler);
53
- (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mozfullscreenchange', fullscreenChangeHandler);
54
- (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.removeEventListener('fullscreenchange', fullscreenChangeHandler);
24
+ videoRef.current?.removeEventListener('webkitfullscreenchange', fullscreenChangeHandler);
25
+ videoRef.current?.removeEventListener('mozfullscreenchange', fullscreenChangeHandler);
26
+ videoRef.current?.removeEventListener('fullscreenchange', fullscreenChangeHandler);
55
27
  };
56
28
  }, [src]);
57
- (0, react_1.useEffect)(function () {
58
- onSizeChange === null || onSizeChange === void 0 ? void 0 : onSizeChange(size);
29
+ useEffect(() => {
30
+ onSizeChange?.(size);
59
31
  }, [size]);
60
- var fullscreenChangeHandler = function (event) {
61
- var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
32
+ const fullscreenChangeHandler = (event) => {
33
+ const isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
62
34
  if (isFullscreen === undefined)
63
35
  return;
64
- onFullscreenChange === null || onFullscreenChange === void 0 ? void 0 : onFullscreenChange(isFullscreen);
36
+ onFullscreenChange?.(isFullscreen);
65
37
  };
66
- var canPlayHandler = function (event) {
67
- var _a, _b;
68
- if (autoPlay && ((_b = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : false)) {
38
+ const canPlayHandler = event => {
39
+ if (autoPlay && (videoRef.current?.paused ?? false)) {
69
40
  play();
70
41
  }
71
- onCanPlay === null || onCanPlay === void 0 ? void 0 : onCanPlay();
42
+ onCanPlay?.();
72
43
  };
73
- var playHandler = function (event) {
74
- onPlay === null || onPlay === void 0 ? void 0 : onPlay();
44
+ const playHandler = event => {
45
+ onPlay?.();
75
46
  };
76
- var pauseHandler = function (event) {
77
- onPause === null || onPause === void 0 ? void 0 : onPause();
47
+ const pauseHandler = event => {
48
+ onPause?.();
78
49
  };
79
- var endHandler = function (event) {
80
- onEnd === null || onEnd === void 0 ? void 0 : onEnd();
50
+ const endHandler = event => {
51
+ onEnd?.();
81
52
  };
82
- var play = function () {
53
+ const play = () => {
83
54
  if (!videoRef.current)
84
55
  return;
85
56
  videoRef.current.play();
86
57
  };
87
- var pause = function () {
58
+ const pause = () => {
88
59
  if (!videoRef.current)
89
60
  return;
90
61
  videoRef.current.pause();
91
62
  };
92
- return ((0, jsx_runtime_1.jsx)("video", __assign({}, props, { ref: ref, autoPlay: autoPlay, controls: hasControls, "data-component": 'video', loop: autoLoop, muted: isMuted, playsInline: playsInline, poster: posterSrc, onCanPlay: canPlayHandler, onEnded: endHandler, onPause: pauseHandler, onPlay: playHandler, children: (0, jsx_runtime_1.jsx)("source", { src: src }) })));
63
+ return (_jsx("video", { ...props, ref: ref, autoPlay: autoPlay, controls: hasControls, "data-component": 'video', loop: autoLoop, muted: isMuted, playsInline: playsInline, poster: posterSrc, onCanPlay: canPlayHandler, onEnded: endHandler, onPause: pauseHandler, onPlay: playHandler, children: _jsx("source", { src: src }) }));
93
64
  });
94
- Object.defineProperty(exports.Video, 'displayName', { value: 'Video', writable: false });
95
- //# sourceMappingURL=Video.js.map
65
+ Object.defineProperty(Video, 'displayName', { value: 'Video', writable: false });
@@ -1,55 +1,37 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.WithTooltip = WithTooltip;
18
- var jsx_runtime_1 = require("react/jsx-runtime");
19
- var clsx_1 = __importDefault(require("clsx"));
20
- var react_1 = require("react");
21
- var spase_1 = require("spase");
22
- var useRect_1 = require("../hooks/useRect");
23
- var useViewportSize_1 = require("../hooks/useViewportSize");
24
- var ExtractChild_1 = require("../operators/ExtractChild");
25
- var utils_1 = require("../utils");
26
- function WithTooltip(_a) {
27
- var children = _a.children, className = _a.className, style = _a.style, _b = _a.arrowHeight, arrowHeight = _b === void 0 ? 8 : _b, _c = _a.backgroundColor, backgroundColor = _c === void 0 ? '#000' : _c, _d = _a.gap, gap = _d === void 0 ? 5 : _d, hint = _a.hint, _e = _a.maxTextWidth, maxTextWidth = _e === void 0 ? 200 : _e, _f = _a.threshold, threshold = _f === void 0 ? 100 : _f;
28
- var createDialog = function () {
29
- var dialog = document.createElement('div');
30
- var dialogStyle = (0, utils_1.styles)(style, fixedStyles.dialog);
31
- dialog.className = (0, clsx_1.default)(className);
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import clsx from 'clsx';
3
+ import { useEffect, useRef } from 'react';
4
+ import { Rect, Size } from 'spase';
5
+ import { useRect } from '../hooks/useRect.js';
6
+ import { useViewportSize } from '../hooks/useViewportSize.js';
7
+ import { ExtractChild } from '../operators/ExtractChild.js';
8
+ import { asStyleDict, styles } from '../utils/index.js';
9
+ export function WithTooltip({ children, className, style, arrowHeight = 8, backgroundColor = '#000', gap = 5, hint, maxTextWidth = 200, threshold = 100, }) {
10
+ const createDialog = () => {
11
+ const dialog = document.createElement('div');
12
+ const dialogStyle = styles(style, fixedStyles.dialog);
13
+ dialog.className = clsx(className);
32
14
  dialog.setAttribute('data-component', 'tool-tip');
33
- Object.keys(dialogStyle).forEach(function (rule) { return dialog.style[rule] = dialogStyle[rule]; });
34
- var arrow = document.createElement('div');
35
- Object.keys(fixedStyles.arrow).forEach(function (rule) { return arrow.style[rule] = fixedStyles.arrow[rule]; });
36
- var content = document.createElement('div');
15
+ Object.keys(dialogStyle).forEach(rule => dialog.style[rule] = dialogStyle[rule]);
16
+ const arrow = document.createElement('div');
17
+ Object.keys(fixedStyles.arrow).forEach(rule => arrow.style[rule] = fixedStyles.arrow[rule]);
18
+ const content = document.createElement('div');
37
19
  content.innerText = hint;
38
- Object.keys(fixedStyles.content).forEach(function (rule) { return content.style[rule] = fixedStyles.content[rule]; });
20
+ Object.keys(fixedStyles.content).forEach(rule => content.style[rule] = fixedStyles.content[rule]);
39
21
  dialog.appendChild(arrow);
40
22
  dialog.appendChild(content);
41
23
  return dialog;
42
24
  };
43
- var computeAlignment = function () {
25
+ const computeAlignment = () => {
44
26
  if (!rootRef.current)
45
27
  return 'bc';
46
- var vrect = spase_1.Rect.fromViewport();
47
- var irect = spase_1.Rect.intersecting(rootRef.current);
28
+ const vrect = Rect.fromViewport();
29
+ const irect = Rect.intersecting(rootRef.current);
48
30
  if (irect) {
49
- var leftBound = irect.left - vrect.left < threshold;
50
- var rightBound = vrect.right - irect.right < threshold;
51
- var topBound = irect.top - vrect.top < threshold;
52
- var bottomBound = vrect.bottom - irect.bottom < threshold;
31
+ const leftBound = irect.left - vrect.left < threshold;
32
+ const rightBound = vrect.right - irect.right < threshold;
33
+ const topBound = irect.top - vrect.top < threshold;
34
+ const bottomBound = vrect.bottom - irect.bottom < threshold;
53
35
  if (leftBound && topBound)
54
36
  return 'br';
55
37
  if (leftBound && bottomBound)
@@ -67,11 +49,11 @@ function WithTooltip(_a) {
67
49
  }
68
50
  return 'bc';
69
51
  };
70
- var computeTextSize = function () {
52
+ const computeTextSize = () => {
71
53
  if (!dialogRef.current)
72
- return new spase_1.Size();
73
- var computedStyle = window.getComputedStyle(dialogRef.current);
74
- var div = document.createElement('div');
54
+ return new Size();
55
+ const computedStyle = window.getComputedStyle(dialogRef.current);
56
+ const div = document.createElement('div');
75
57
  div.innerText = hint;
76
58
  div.style.fontFamily = computedStyle.getPropertyValue('font-family');
77
59
  div.style.fontSize = computedStyle.getPropertyValue('font-size');
@@ -85,73 +67,71 @@ function WithTooltip(_a) {
85
67
  div.style.whiteSpace = 'pre';
86
68
  document.body.appendChild(div);
87
69
  // Add 1px as buffer to mitigate precision discrepancies.
88
- var width = div.clientWidth + 1;
89
- var height = div.clientHeight + 1;
70
+ const width = div.clientWidth + 1;
71
+ const height = div.clientHeight + 1;
90
72
  document.body.removeChild(div);
91
- return new spase_1.Size([width, height]);
73
+ return new Size([width, height]);
92
74
  };
93
- var mouseEnterHandler = function (event) {
75
+ const mouseEnterHandler = (event) => {
94
76
  if (!dialogRef.current)
95
77
  return;
96
78
  dialogRef.current.style.opacity = '1';
97
79
  };
98
- var mouseLeaveHandler = function (event) {
80
+ const mouseLeaveHandler = (event) => {
99
81
  if (!dialogRef.current)
100
82
  return;
101
83
  dialogRef.current.style.opacity = '0';
102
84
  };
103
- var rootRef = (0, react_1.useRef)(null);
104
- var dialogRef = (0, react_1.useRef)();
105
- var rect = (0, useRect_1.useRect)(rootRef);
106
- var viewportSize = (0, useViewportSize_1.useViewportSize)();
107
- var alignment = computeAlignment();
108
- var textSize = computeTextSize();
109
- var fixedStyles = getFixedStyles({ rect: rect, arrowHeight: arrowHeight, alignment: alignment, backgroundColor: backgroundColor, maxTextWidth: maxTextWidth, textSize: textSize, gap: gap });
110
- (0, react_1.useEffect)(function () {
111
- var _a;
112
- var dialogNode = createDialog();
113
- (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.appendChild(dialogNode);
85
+ const rootRef = useRef(null);
86
+ const dialogRef = useRef();
87
+ const rect = useRect(rootRef);
88
+ const viewportSize = useViewportSize();
89
+ const alignment = computeAlignment();
90
+ const textSize = computeTextSize();
91
+ const fixedStyles = getFixedStyles({ rect, arrowHeight, alignment, backgroundColor, maxTextWidth, textSize, gap });
92
+ useEffect(() => {
93
+ const dialogNode = createDialog();
94
+ rootRef.current?.appendChild(dialogNode);
114
95
  dialogRef.current = dialogNode;
115
- return function () {
116
- var _a;
117
- (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.removeChild(dialogNode);
96
+ return () => {
97
+ rootRef.current?.removeChild(dialogNode);
118
98
  };
119
99
  }, [rect, viewportSize]);
120
- return ((0, jsx_runtime_1.jsx)(ExtractChild_1.ExtractChild, { ref: rootRef, onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, children: children }));
100
+ return (_jsx(ExtractChild, { ref: rootRef, onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, children: children }));
121
101
  }
122
102
  function makeDisplacementStyle(alignment, arrowHeight, gap) {
123
103
  switch (alignment) {
124
104
  case 'tl': return {
125
- top: "".concat(-arrowHeight, "px"),
126
- left: "calc(50% + ".concat(arrowHeight * 2.5, "px)"),
105
+ top: `${-arrowHeight}px`,
106
+ left: `calc(50% + ${arrowHeight * 2.5}px)`,
127
107
  };
128
108
  case 'tc': return {
129
- top: "".concat(-arrowHeight, "px"),
109
+ top: `${-arrowHeight}px`,
130
110
  left: '50%',
131
111
  };
132
112
  case 'tr': return {
133
- top: "".concat(-arrowHeight, "px"),
134
- right: "calc(50% + ".concat(arrowHeight * 2.5, "px)"),
113
+ top: `${-arrowHeight}px`,
114
+ right: `calc(50% + ${arrowHeight * 2.5}px)`,
135
115
  };
136
116
  case 'cl': return {
137
117
  top: '50%',
138
- left: "".concat(-arrowHeight, "px"),
118
+ left: `${-arrowHeight}px`,
139
119
  };
140
120
  case 'cr': return {
141
121
  top: '50%',
142
- right: "".concat(-arrowHeight, "px"),
122
+ right: `${-arrowHeight}px`,
143
123
  };
144
124
  case 'bl': return {
145
- bottom: "".concat(-arrowHeight, "px"),
146
- left: "calc(50% + ".concat(arrowHeight * 2.5, "px)"),
125
+ bottom: `${-arrowHeight}px`,
126
+ left: `calc(50% + ${arrowHeight * 2.5}px)`,
147
127
  };
148
128
  case 'bc': return {
149
- bottom: "".concat(-arrowHeight, "px"),
129
+ bottom: `${-arrowHeight}px`,
150
130
  left: '50%',
151
131
  };
152
132
  case 'br': return {
153
- bottom: "".concat(-arrowHeight, "px"),
154
- right: "calc(50% + ".concat(arrowHeight * 2.5, "px)"),
133
+ bottom: `${-arrowHeight}px`,
134
+ right: `calc(50% + ${arrowHeight * 2.5}px)`,
155
135
  };
156
136
  default: return {};
157
137
  }
@@ -159,28 +139,28 @@ function makeDisplacementStyle(alignment, arrowHeight, gap) {
159
139
  function makeContentPositionStyle(alignment, arrowHeight, gap) {
160
140
  switch (alignment) {
161
141
  case 'tl': return {
162
- transform: "translate3d(calc(-100% - ".concat(gap, "px), calc(-100% - ").concat(gap, "px), 0)"),
142
+ transform: `translate3d(calc(-100% - ${gap}px), calc(-100% - ${gap}px), 0)`,
163
143
  };
164
144
  case 'tc': return {
165
- transform: "translate3d(-50%, calc(-100% - ".concat(gap, "px), 0)"),
145
+ transform: `translate3d(-50%, calc(-100% - ${gap}px), 0)`,
166
146
  };
167
147
  case 'tr': return {
168
- transform: "translate3d(calc(100% + ".concat(gap, "px), calc(-100% - ").concat(gap, "px), 0)"),
148
+ transform: `translate3d(calc(100% + ${gap}px), calc(-100% - ${gap}px), 0)`,
169
149
  };
170
150
  case 'cl': return {
171
- transform: "translate3d(calc(-100% - ".concat(gap, "px), -50%, 0)"),
151
+ transform: `translate3d(calc(-100% - ${gap}px), -50%, 0)`,
172
152
  };
173
153
  case 'cr': return {
174
- transform: "translate3d(calc(100% + ".concat(gap, "px), -50%, 0)"),
154
+ transform: `translate3d(calc(100% + ${gap}px), -50%, 0)`,
175
155
  };
176
156
  case 'bl': return {
177
- transform: "translate3d(calc(-100% - ".concat(gap, "px), calc(100% + ").concat(gap, "px), 0)"),
157
+ transform: `translate3d(calc(-100% - ${gap}px), calc(100% + ${gap}px), 0)`,
178
158
  };
179
159
  case 'bc': return {
180
- transform: "translate3d(-50%, calc(100% + ".concat(gap, "px), 0)"),
160
+ transform: `translate3d(-50%, calc(100% + ${gap}px), 0)`,
181
161
  };
182
162
  case 'br': return {
183
- transform: "translate3d(calc(100% + ".concat(gap, "px), calc(100% + ").concat(gap, "px), 0)"),
163
+ transform: `translate3d(calc(100% + ${gap}px), calc(100% + ${gap}px), 0)`,
184
164
  };
185
165
  default: return {};
186
166
  }
@@ -188,57 +168,83 @@ function makeContentPositionStyle(alignment, arrowHeight, gap) {
188
168
  function makeArrowPositionStyle(alignment, arrowHeight, gap, color) {
189
169
  switch (alignment) {
190
170
  case 'tl': return {
191
- borderColor: "".concat(color, " transparent transparent transparent"),
192
- transform: "translate3d(calc(0% - ".concat(gap, "px - ").concat(arrowHeight * 3, "px), calc(0% - ").concat(gap, "px), 0)"),
171
+ borderColor: `${color} transparent transparent transparent`,
172
+ transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% - ${gap}px), 0)`,
193
173
  };
194
174
  case 'tc': return {
195
- borderColor: "".concat(color, " transparent transparent transparent"),
196
- transform: "translate3d(-50%, calc(0% - ".concat(gap, "px), 0)"),
175
+ borderColor: `${color} transparent transparent transparent`,
176
+ transform: `translate3d(-50%, calc(0% - ${gap}px), 0)`,
197
177
  };
198
178
  case 'tr': return {
199
- borderColor: "".concat(color, " transparent transparent transparent"),
200
- transform: "translate3d(calc(100% + ".concat(gap, "px + ").concat(arrowHeight, "px), calc(0% - ").concat(gap, "px), 0)"),
179
+ borderColor: `${color} transparent transparent transparent`,
180
+ transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% - ${gap}px), 0)`,
201
181
  };
202
182
  case 'cl': return {
203
- borderColor: "transparent transparent transparent ".concat(color),
204
- transform: "translate3d(calc(0% - ".concat(gap, "px), -50%, 0)"),
183
+ borderColor: `transparent transparent transparent ${color}`,
184
+ transform: `translate3d(calc(0% - ${gap}px), -50%, 0)`,
205
185
  };
206
186
  case 'cr': return {
207
- borderColor: "transparent ".concat(color, " transparent transparent"),
208
- transform: "translate3d(calc(0% + ".concat(gap, "px), -50%, 0)"),
187
+ borderColor: `transparent ${color} transparent transparent`,
188
+ transform: `translate3d(calc(0% + ${gap}px), -50%, 0)`,
209
189
  };
210
190
  case 'bl': return {
211
- borderColor: "transparent transparent ".concat(color, " transparent"),
212
- transform: "translate3d(calc(0% - ".concat(gap, "px - ").concat(arrowHeight * 3, "px), calc(0% + ").concat(gap, "px), 0)"),
191
+ borderColor: `transparent transparent ${color} transparent`,
192
+ transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% + ${gap}px), 0)`,
213
193
  };
214
194
  case 'bc': return {
215
- borderColor: "transparent transparent ".concat(color, " transparent"),
216
- transform: "translate3d(-50%, calc(0% + ".concat(gap, "px), 0)"),
195
+ borderColor: `transparent transparent ${color} transparent`,
196
+ transform: `translate3d(-50%, calc(0% + ${gap}px), 0)`,
217
197
  };
218
198
  case 'br': return {
219
- borderColor: "transparent transparent ".concat(color, " transparent"),
220
- transform: "translate3d(calc(100% + ".concat(gap, "px + ").concat(arrowHeight, "px), calc(0% + ").concat(gap, "px), 0)"),
199
+ borderColor: `transparent transparent ${color} transparent`,
200
+ transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% + ${gap}px), 0)`,
221
201
  };
222
202
  default: return {};
223
203
  }
224
204
  }
225
- function getFixedStyles(_a) {
226
- var _b = _a.rect, rect = _b === void 0 ? new spase_1.Rect() : _b, _c = _a.arrowHeight, arrowHeight = _c === void 0 ? 0 : _c, _d = _a.alignment, alignment = _d === void 0 ? 'tl' : _d, _e = _a.backgroundColor, backgroundColor = _e === void 0 ? '' : _e, _f = _a.maxTextWidth, maxTextWidth = _f === void 0 ? 0 : _f, _g = _a.textSize, textSize = _g === void 0 ? new spase_1.Size() : _g, _h = _a.gap, gap = _h === void 0 ? 0 : _h;
227
- return (0, utils_1.asStyleDict)({
205
+ function getFixedStyles({ rect = new Rect(), arrowHeight = 0, alignment = 'tl', backgroundColor = '', maxTextWidth = 0, textSize = new Size(), gap = 0 }) {
206
+ return asStyleDict({
228
207
  dialog: {
229
208
  background: 'none',
230
209
  boxSizing: 'border-box',
231
- height: "".concat(rect.size.height, "px"),
210
+ height: `${rect.size.height}px`,
232
211
  left: '0',
233
212
  margin: '0',
234
213
  opacity: '0',
235
214
  position: 'absolute',
236
215
  top: '0',
237
- width: "".concat(rect.size.width, "px"),
216
+ width: `${rect.size.width}px`,
238
217
  zIndex: '10000',
239
218
  },
240
- arrow: __assign(__assign({ borderStyle: 'solid', borderWidth: "".concat(arrowHeight, "px"), height: '0', pointerEvents: 'none', position: 'absolute', width: '0' }, makeDisplacementStyle(alignment, arrowHeight, gap)), makeArrowPositionStyle(alignment, arrowHeight, gap, backgroundColor)),
241
- content: __assign(__assign({ background: backgroundColor, boxSizing: 'content-box', color: 'inherit', fontFamily: 'inherit', fontSize: 'inherit', fontWeight: 'inherit', letterSpacing: 'inherit', lineHeight: 'inherit', maxWidth: "".concat(maxTextWidth, "px"), overflow: 'hidden', padding: 'inherit', pointerEvents: 'none', position: 'absolute', textAlign: 'inherit', transition: 'inherit', width: textSize.width > 0 ? "".concat(textSize.width, "px") : 'auto' }, makeDisplacementStyle(alignment, arrowHeight, gap)), makeContentPositionStyle(alignment, arrowHeight, gap)),
219
+ arrow: {
220
+ borderStyle: 'solid',
221
+ borderWidth: `${arrowHeight}px`,
222
+ height: '0',
223
+ pointerEvents: 'none',
224
+ position: 'absolute',
225
+ width: '0',
226
+ ...makeDisplacementStyle(alignment, arrowHeight, gap),
227
+ ...makeArrowPositionStyle(alignment, arrowHeight, gap, backgroundColor),
228
+ },
229
+ content: {
230
+ background: backgroundColor,
231
+ boxSizing: 'content-box',
232
+ color: 'inherit',
233
+ fontFamily: 'inherit',
234
+ fontSize: 'inherit',
235
+ fontWeight: 'inherit',
236
+ letterSpacing: 'inherit',
237
+ lineHeight: 'inherit',
238
+ maxWidth: `${maxTextWidth}px`,
239
+ overflow: 'hidden',
240
+ padding: 'inherit',
241
+ pointerEvents: 'none',
242
+ position: 'absolute',
243
+ textAlign: 'inherit',
244
+ transition: 'inherit',
245
+ width: textSize.width > 0 ? `${textSize.width}px` : 'auto',
246
+ ...makeDisplacementStyle(alignment, arrowHeight, gap),
247
+ ...makeContentPositionStyle(alignment, arrowHeight, gap),
248
+ },
242
249
  });
243
250
  }
244
- //# sourceMappingURL=WithTooltip.js.map
@@ -0,0 +1,24 @@
1
+ export * from './Accordion.js';
2
+ export * from './BurgerButton.js';
3
+ export * from './Carousel.js';
4
+ export * from './Collection.js';
5
+ export * from './Counter.js';
6
+ export * from './CoverImage.js';
7
+ export * from './CoverVideo.js';
8
+ export * from './DebugConsole.js';
9
+ export * from './Dial.js';
10
+ export * from './Dropdown.js';
11
+ export * from './FlatSVG.js';
12
+ export * from './Image.js';
13
+ export * from './MasonryGrid.js';
14
+ export * from './Panorama.js';
15
+ export * from './PanoramaSlider.js';
16
+ export * from './RangeSlider.js';
17
+ export * from './RotatingGallery.js';
18
+ export * from './SelectableButton.js';
19
+ export * from './Slider.js';
20
+ export * from './StepwiseSlider.js';
21
+ export * from './SwipeContainer.js';
22
+ export * from './TextField.js';
23
+ export * from './Video.js';
24
+ export * from './WithTooltip.js';
package/hooks/index.js ADDED
@@ -0,0 +1,17 @@
1
+ export * from './useClickOutsideEffect.js';
2
+ export * from './useDragEffect.js';
3
+ export * from './useDragValueEffect.js';
4
+ export * from './useImageSize.js';
5
+ export * from './useInterval.js';
6
+ export * from './useLoadImageEffect.js';
7
+ export * from './useLoadVideoMetadataEffect.js';
8
+ export * from './useMounted.js';
9
+ export * from './usePrevious.js';
10
+ export * from './useRect.js';
11
+ export * from './useResizeEffect.js';
12
+ export * from './useScrollPositionEffect.js';
13
+ export * from './useSearchParamState.js';
14
+ export * from './useSize.js';
15
+ export * from './useTimeout.js';
16
+ export * from './useVideoSize.js';
17
+ export * from './useViewportSize.js';