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,74 +1,10 @@
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 __values = (this && this.__values) || function(o) {
50
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
- if (m) return m.call(o);
52
- if (o && typeof o.length === "number") return {
53
- next: function () {
54
- if (o && i >= o.length) o = void 0;
55
- return { value: o && o[i++], done: !o };
56
- }
57
- };
58
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
- };
60
- var __importDefault = (this && this.__importDefault) || function (mod) {
61
- return (mod && mod.__esModule) ? mod : { "default": mod };
62
- };
63
- Object.defineProperty(exports, "__esModule", { value: true });
64
- exports.MasonryGrid = void 0;
65
- var jsx_runtime_1 = require("react/jsx-runtime");
66
- var clsx_1 = __importDefault(require("clsx"));
67
- var react_1 = require("react");
68
- var spase_1 = require("spase");
69
- var useResizeEffect_1 = require("../hooks/useResizeEffect");
70
- var utils_1 = require("../utils");
71
- var BASE_MODIFIER_CLASS_PREFIX = 'base-';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import clsx from 'clsx';
3
+ import { forwardRef, useEffect, useRef, useState } from 'react';
4
+ import { Rect, Size } from 'spase';
5
+ import { useResizeEffect } from '../hooks/useResizeEffect.js';
6
+ import { asClassNameDict, asStyleDict } from '../utils/index.js';
7
+ const BASE_MODIFIER_CLASS_PREFIX = 'base-';
72
8
  /**
73
9
  * This is a React component that arranges all of its immediate children in a
74
10
  * masonry grid. Refrain from assigning CSS styles to it via `className` or
@@ -86,146 +22,102 @@ var BASE_MODIFIER_CLASS_PREFIX = 'base-';
86
22
  * rows*, whereas in a horizontally oriented grid, *number of sections* refers
87
23
  * to the *number of columns*.
88
24
  */
89
- exports.MasonryGrid = (0, react_1.forwardRef)(function (_a, ref) {
90
- var _b = _a.areSectionsAligned, areSectionsAligned = _b === void 0 ? false : _b, children = _a.children, className = _a.className, _c = _a.horizontalSpacing, horizontalSpacing = _c === void 0 ? 0 : _c, _d = _a.isReversed, isReversed = _d === void 0 ? false : _d, _e = _a.orientation, orientation = _e === void 0 ? 'vertical' : _e, _f = _a.sections, sections = _f === void 0 ? 3 : _f, _g = _a.verticalSpacing, verticalSpacing = _g === void 0 ? 0 : _g, props = __rest(_a, ["areSectionsAligned", "children", "className", "horizontalSpacing", "isReversed", "orientation", "sections", "verticalSpacing"]);
91
- var bodyRef = (0, react_1.useRef)(null);
92
- var _h = __read((0, react_1.useState)(NaN), 2), minWidth = _h[0], setMinWidth = _h[1];
93
- var _j = __read((0, react_1.useState)(NaN), 2), minHeight = _j[0], setMinHeight = _j[1];
94
- var _k = __read((0, react_1.useState)(NaN), 2), maxWidth = _k[0], setMaxWidth = _k[1];
95
- var _l = __read((0, react_1.useState)(NaN), 2), maxHeight = _l[0], setMaxHeight = _l[1];
96
- var getCurrentWidth = function () { var _a, _b; return (_b = (_a = spase_1.Rect.from(bodyRef.current)) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0; };
97
- var getCurrentHeight = function () { var _a, _b; return (_b = (_a = spase_1.Rect.from(bodyRef.current)) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : 0; };
98
- var repositionChildren = function () {
99
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
100
- var _e, _f, _g, _h;
101
- var rootNode = bodyRef.current;
25
+ export const MasonryGrid = forwardRef(({ areSectionsAligned = false, children, className, horizontalSpacing = 0, isReversed = false, orientation = 'vertical', sections = 3, verticalSpacing = 0, ...props }, ref) => {
26
+ const bodyRef = useRef(null);
27
+ const [minWidth, setMinWidth] = useState(NaN);
28
+ const [minHeight, setMinHeight] = useState(NaN);
29
+ const [maxWidth, setMaxWidth] = useState(NaN);
30
+ const [maxHeight, setMaxHeight] = useState(NaN);
31
+ const getCurrentWidth = () => Rect.from(bodyRef.current)?.width ?? 0;
32
+ const getCurrentHeight = () => Rect.from(bodyRef.current)?.height ?? 0;
33
+ const repositionChildren = () => {
34
+ const rootNode = bodyRef.current;
102
35
  if (!rootNode)
103
36
  return;
104
- var nodes = rootNode.children;
105
- var numSections = sections;
37
+ const nodes = rootNode.children;
38
+ const numSections = sections;
106
39
  if (numSections <= 0)
107
40
  throw new Error('You must specifiy a minimum of 1 section(s) (a.k.a. row(s) for horizontal orientation, column(s) for vertical orientation) for a MasonryGrid instance');
108
41
  if (orientation === 'vertical') {
109
- var sectionHeights = __spreadArray([], __read(new Array(numSections)), false).map(function () { return 0; });
110
- try {
111
- for (var _j = __values(Array.from(nodes)), _k = _j.next(); !_k.done; _k = _j.next()) {
112
- var child = _k.value;
113
- if (!(child instanceof HTMLElement))
114
- continue;
115
- var base = computeBaseFromElement(child, sections);
116
- var _l = __read(computeNextAvailableSectionAndLengthByBase(sectionHeights, base), 2), colIdx = _l[0], y = _l[1];
117
- child.style.position = 'absolute';
118
- child.style.width = "calc(".concat(100 / numSections * base, "% - ").concat(horizontalSpacing * (numSections - 1) / numSections * base, "px + ").concat(horizontalSpacing * (base - 1), "px)");
119
- child.style.height = '';
120
- child.style.left = "calc(".concat(100 / numSections * colIdx, "% - ").concat(horizontalSpacing * (numSections - 1) / numSections * colIdx, "px + ").concat(horizontalSpacing * colIdx, "px)");
121
- child.style.top = "".concat(y + (y === 0 ? 0 : verticalSpacing), "px");
122
- for (var j = 0; j < base; j++) {
123
- sectionHeights[colIdx + j] = y + (y === 0 ? 0 : verticalSpacing) + ((_f = (_e = spase_1.Rect.from(child)) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : 0);
124
- }
125
- if (areSectionsAligned && colIdx + base === numSections) {
126
- var m = computeMaxLength(sectionHeights);
127
- for (var j = 0; j < numSections; j++) {
128
- sectionHeights[j] = m;
129
- }
130
- }
42
+ const sectionHeights = [...new Array(numSections)].map(() => 0);
43
+ for (const child of Array.from(nodes)) {
44
+ if (!(child instanceof HTMLElement))
45
+ continue;
46
+ const base = computeBaseFromElement(child, sections);
47
+ const [colIdx, y] = computeNextAvailableSectionAndLengthByBase(sectionHeights, base);
48
+ child.style.position = 'absolute';
49
+ child.style.width = `calc(${100 / numSections * base}% - ${horizontalSpacing * (numSections - 1) / numSections * base}px + ${horizontalSpacing * (base - 1)}px)`;
50
+ child.style.height = '';
51
+ child.style.left = `calc(${100 / numSections * colIdx}% - ${horizontalSpacing * (numSections - 1) / numSections * colIdx}px + ${horizontalSpacing * colIdx}px)`;
52
+ child.style.top = `${y + (y === 0 ? 0 : verticalSpacing)}px`;
53
+ for (let j = 0; j < base; j++) {
54
+ sectionHeights[colIdx + j] = y + (y === 0 ? 0 : verticalSpacing) + (Rect.from(child)?.height ?? 0);
131
55
  }
132
- }
133
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
134
- finally {
135
- try {
136
- if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
56
+ if (areSectionsAligned && colIdx + base === numSections) {
57
+ const m = computeMaxLength(sectionHeights);
58
+ for (let j = 0; j < numSections; j++) {
59
+ sectionHeights[j] = m;
60
+ }
137
61
  }
138
- finally { if (e_1) throw e_1.error; }
139
62
  }
140
- var w = getCurrentWidth();
141
- var h = computeMaxLength(sectionHeights, numSections);
63
+ const w = getCurrentWidth();
64
+ const h = computeMaxLength(sectionHeights, numSections);
142
65
  setMinWidth(w);
143
66
  setMinHeight(h);
144
67
  if (!isNaN(h))
145
- rootNode.style.height = "".concat(h, "px");
68
+ rootNode.style.height = `${h}px`;
146
69
  if (isReversed) {
147
- try {
148
- for (var _m = __values(Array.from(nodes)), _o = _m.next(); !_o.done; _o = _m.next()) {
149
- var child = _o.value;
150
- if (!(child instanceof HTMLElement))
151
- continue;
152
- var x = parseFloat(child.style.left);
153
- child.style.left = "".concat(w - x - parseFloat(child.style.width), "px");
154
- }
155
- }
156
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
157
- finally {
158
- try {
159
- if (_o && !_o.done && (_b = _m.return)) _b.call(_m);
160
- }
161
- finally { if (e_2) throw e_2.error; }
70
+ for (const child of Array.from(nodes)) {
71
+ if (!(child instanceof HTMLElement))
72
+ continue;
73
+ const x = parseFloat(child.style.left);
74
+ child.style.left = `${w - x - parseFloat(child.style.width)}px`;
162
75
  }
163
76
  }
164
77
  }
165
78
  else {
166
- var sectionWidths = __spreadArray([], __read(new Array(numSections)), false).map(function () { return 0; });
167
- try {
168
- for (var _p = __values(Array.from(nodes)), _q = _p.next(); !_q.done; _q = _p.next()) {
169
- var child = _q.value;
170
- if (!(child instanceof HTMLElement))
171
- continue;
172
- var base = computeBaseFromElement(child, sections);
173
- var _r = __read(computeNextAvailableSectionAndLengthByBase(sectionWidths, base), 2), rowIdx = _r[0], x = _r[1];
174
- child.style.position = 'absolute';
175
- child.style.width = '';
176
- child.style.height = "calc(".concat(100 / numSections * base, "% - ").concat(verticalSpacing * (numSections - 1) / numSections * base, "px + ").concat(verticalSpacing * (base - 1), "px)");
177
- child.style.top = "calc(".concat(100 / numSections * rowIdx, "% - ").concat(verticalSpacing * (numSections - 1) / numSections * rowIdx, "px + ").concat(verticalSpacing * rowIdx, "px)");
178
- child.style.left = "".concat(x + (x === 0 ? 0 : horizontalSpacing), "px");
179
- for (var j = 0; j < base; j++) {
180
- sectionWidths[rowIdx + j] = x + (x === 0 ? 0 : horizontalSpacing) + ((_h = (_g = spase_1.Rect.from(child)) === null || _g === void 0 ? void 0 : _g.width) !== null && _h !== void 0 ? _h : 0);
181
- }
182
- if (areSectionsAligned && rowIdx + base === numSections) {
183
- var m = computeMaxLength(sectionWidths);
184
- for (var j = 0; j < numSections; j++) {
185
- sectionWidths[j] = m;
186
- }
187
- }
79
+ const sectionWidths = [...new Array(numSections)].map(() => 0);
80
+ for (const child of Array.from(nodes)) {
81
+ if (!(child instanceof HTMLElement))
82
+ continue;
83
+ const base = computeBaseFromElement(child, sections);
84
+ const [rowIdx, x] = computeNextAvailableSectionAndLengthByBase(sectionWidths, base);
85
+ child.style.position = 'absolute';
86
+ child.style.width = '';
87
+ child.style.height = `calc(${100 / numSections * base}% - ${verticalSpacing * (numSections - 1) / numSections * base}px + ${verticalSpacing * (base - 1)}px)`;
88
+ child.style.top = `calc(${100 / numSections * rowIdx}% - ${verticalSpacing * (numSections - 1) / numSections * rowIdx}px + ${verticalSpacing * rowIdx}px)`;
89
+ child.style.left = `${x + (x === 0 ? 0 : horizontalSpacing)}px`;
90
+ for (let j = 0; j < base; j++) {
91
+ sectionWidths[rowIdx + j] = x + (x === 0 ? 0 : horizontalSpacing) + (Rect.from(child)?.width ?? 0);
188
92
  }
189
- }
190
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
191
- finally {
192
- try {
193
- if (_q && !_q.done && (_c = _p.return)) _c.call(_p);
93
+ if (areSectionsAligned && rowIdx + base === numSections) {
94
+ const m = computeMaxLength(sectionWidths);
95
+ for (let j = 0; j < numSections; j++) {
96
+ sectionWidths[j] = m;
97
+ }
194
98
  }
195
- finally { if (e_3) throw e_3.error; }
196
99
  }
197
- var h = getCurrentHeight();
198
- var w = computeMaxLength(sectionWidths, numSections);
100
+ const h = getCurrentHeight();
101
+ const w = computeMaxLength(sectionWidths, numSections);
199
102
  setMinHeight(h);
200
103
  setMinWidth(w);
201
104
  if (!isNaN(w))
202
- rootNode.style.width = "".concat(w, "px");
105
+ rootNode.style.width = `${w}px`;
203
106
  if (isReversed) {
204
- try {
205
- for (var _s = __values(Array.from(nodes)), _t = _s.next(); !_t.done; _t = _s.next()) {
206
- var child = _t.value;
207
- if (!(child instanceof HTMLElement))
208
- continue;
209
- var y = parseFloat(child.style.top);
210
- child.style.top = "".concat(h - y - parseFloat(child.style.height), "px");
211
- }
212
- }
213
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
214
- finally {
215
- try {
216
- if (_t && !_t.done && (_d = _s.return)) _d.call(_s);
217
- }
218
- finally { if (e_4) throw e_4.error; }
107
+ for (const child of Array.from(nodes)) {
108
+ if (!(child instanceof HTMLElement))
109
+ continue;
110
+ const y = parseFloat(child.style.top);
111
+ child.style.top = `${h - y - parseFloat(child.style.height)}px`;
219
112
  }
220
113
  }
221
114
  }
222
115
  };
223
- (0, useResizeEffect_1.useResizeEffect)(bodyRef, {
224
- onResize: function (element) {
225
- var _a, _b;
226
- var maxSize = (_b = (_a = spase_1.Rect.from(element)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : new spase_1.Size();
227
- var currWidth = getCurrentWidth();
228
- var currHeight = getCurrentHeight();
116
+ useResizeEffect(bodyRef, {
117
+ onResize: element => {
118
+ const maxSize = Rect.from(element)?.size ?? new Size();
119
+ const currWidth = getCurrentWidth();
120
+ const currHeight = getCurrentHeight();
229
121
  if (minWidth !== currWidth || minHeight !== currHeight || maxSize.width !== maxWidth || maxSize.height !== maxHeight) {
230
122
  repositionChildren();
231
123
  setMaxWidth(maxSize.width);
@@ -233,37 +125,34 @@ exports.MasonryGrid = (0, react_1.forwardRef)(function (_a, ref) {
233
125
  }
234
126
  },
235
127
  }, [areSectionsAligned, horizontalSpacing, isReversed, sections, verticalSpacing]);
236
- (0, react_1.useEffect)(function () {
237
- var _a;
238
- var imageSources = getAllImageSources((_a = bodyRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML);
128
+ useEffect(() => {
129
+ const imageSources = getAllImageSources(bodyRef.current?.innerHTML);
239
130
  if (imageSources.length === 0)
240
131
  return repositionChildren();
241
- var numImages = imageSources.length;
242
- for (var i = 0; i < numImages; i++) {
243
- var src = imageSources[i];
244
- var image = new Image();
132
+ const numImages = imageSources.length;
133
+ for (let i = 0; i < numImages; i++) {
134
+ const src = imageSources[i];
135
+ const image = new Image();
245
136
  image.src = src;
246
- image.onload = function () { return repositionChildren(); };
137
+ image.onload = () => repositionChildren();
247
138
  }
248
139
  }, [children]);
249
- var fixedClassNames = getFixedClassNames({ orientation: orientation });
250
- var fixedStyles = getFixedStyles({ orientation: orientation, minHeight: minHeight, minWidth: minWidth });
251
- return ((0, jsx_runtime_1.jsx)("div", __assign({}, props, { ref: ref, className: (0, clsx_1.default)(className, fixedClassNames.root), "data-component": 'masonry-grid', children: (0, jsx_runtime_1.jsx)("div", { ref: bodyRef, style: fixedStyles.body, children: children }) })));
140
+ const fixedClassNames = getFixedClassNames({ orientation });
141
+ const fixedStyles = getFixedStyles({ orientation, minHeight, minWidth });
142
+ return (_jsx("div", { ...props, ref: ref, className: clsx(className, fixedClassNames.root), "data-component": 'masonry-grid', children: _jsx("div", { ref: bodyRef, style: fixedStyles.body, children: children }) }));
252
143
  });
253
- Object.defineProperty(exports.MasonryGrid, 'displayName', { value: 'MasonryGrid', writable: false });
254
- function getFixedClassNames(_a) {
255
- var _b = _a.orientation, orientation = _b === void 0 ? 'horizontal' : _b;
256
- return (0, utils_1.asClassNameDict)({
257
- root: (0, clsx_1.default)(orientation),
144
+ Object.defineProperty(MasonryGrid, 'displayName', { value: 'MasonryGrid', writable: false });
145
+ function getFixedClassNames({ orientation = 'horizontal' }) {
146
+ return asClassNameDict({
147
+ root: clsx(orientation),
258
148
  });
259
149
  }
260
- function getFixedStyles(_a) {
261
- var _b = _a.orientation, orientation = _b === void 0 ? 'horizontal' : _b, _c = _a.minHeight, minHeight = _c === void 0 ? NaN : _c, _d = _a.minWidth, minWidth = _d === void 0 ? NaN : _d;
262
- return (0, utils_1.asStyleDict)({
150
+ function getFixedStyles({ orientation = 'horizontal', minHeight = NaN, minWidth = NaN }) {
151
+ return asStyleDict({
263
152
  body: {
264
153
  height: orientation === 'horizontal' ? '100%' : 'auto',
265
- minHeight: orientation === 'vertical' && !isNaN(minHeight) ? "".concat(minHeight, "px") : '',
266
- minWidth: orientation === 'horizontal' && !isNaN(minWidth) ? "".concat(minWidth, "px") : '',
154
+ minHeight: orientation === 'vertical' && !isNaN(minHeight) ? `${minHeight}px` : '',
155
+ minWidth: orientation === 'horizontal' && !isNaN(minWidth) ? `${minWidth}px` : '',
267
156
  padding: '0',
268
157
  width: orientation === 'horizontal' ? 'auto' : '100%',
269
158
  },
@@ -281,22 +170,22 @@ function getFixedStyles(_a) {
281
170
  * length if a new item were to be placed in it.
282
171
  */
283
172
  function computeNextAvailableSectionAndLengthByBase(currentSectionLengths, base) {
284
- var numSections = currentSectionLengths.length;
285
- var sectionIdx = NaN;
286
- var minLength = Infinity;
287
- for (var i = 0; i < numSections; i++) {
288
- var length_1 = currentSectionLengths[i];
289
- var isShorter = length_1 < minLength;
290
- var isEligibleSection = i + base <= numSections;
291
- var hasRoomInSubsequentSections = true;
292
- for (var j = 1; j < base; j++) {
293
- if (currentSectionLengths[i + j] > length_1) {
173
+ const numSections = currentSectionLengths.length;
174
+ let sectionIdx = NaN;
175
+ let minLength = Infinity;
176
+ for (let i = 0; i < numSections; i++) {
177
+ const length = currentSectionLengths[i];
178
+ const isShorter = length < minLength;
179
+ const isEligibleSection = i + base <= numSections;
180
+ let hasRoomInSubsequentSections = true;
181
+ for (let j = 1; j < base; j++) {
182
+ if (currentSectionLengths[i + j] > length) {
294
183
  hasRoomInSubsequentSections = false;
295
184
  }
296
185
  }
297
186
  if (isShorter && isEligibleSection && hasRoomInSubsequentSections) {
298
187
  sectionIdx = i;
299
- minLength = length_1;
188
+ minLength = length;
300
189
  }
301
190
  }
302
191
  if (isNaN(sectionIdx)) {
@@ -319,11 +208,11 @@ function computeNextAvailableSectionAndLengthByBase(currentSectionLengths, base)
319
208
  * @returns The max section length.
320
209
  */
321
210
  function computeMaxLength(currentSectionLengths, base) {
322
- var arr = currentSectionLengths;
211
+ let arr = currentSectionLengths;
323
212
  if (base !== undefined && base !== null && !isNaN(base)) {
324
213
  arr = arr.slice(0, Math.max(1, Math.min(base, currentSectionLengths.length)));
325
214
  }
326
- return arr.reduce(function (out, curr, i) { return curr > out ? curr : out; }, 0);
215
+ return arr.reduce((out, curr, i) => curr > out ? curr : out, 0);
327
216
  }
328
217
  /**
329
218
  * Computes the base value of an element from its classes.
@@ -335,25 +224,14 @@ function computeMaxLength(currentSectionLengths, base) {
335
224
  * sections.
336
225
  */
337
226
  function computeBaseFromElement(element, numSections) {
338
- var e_5, _a;
339
- var classList = element.classList;
340
- try {
341
- for (var _b = __values(Array.from(classList)), _c = _b.next(); !_c.done; _c = _b.next()) {
342
- var c = _c.value;
343
- if (c.startsWith(BASE_MODIFIER_CLASS_PREFIX)) {
344
- var base = parseFloat(c.replace(BASE_MODIFIER_CLASS_PREFIX, ''));
345
- if (!isNaN(base))
346
- return Math.min(Math.max(base, 1), numSections);
347
- }
227
+ const classList = element.classList;
228
+ for (const c of Array.from(classList)) {
229
+ if (c.startsWith(BASE_MODIFIER_CLASS_PREFIX)) {
230
+ const base = parseFloat(c.replace(BASE_MODIFIER_CLASS_PREFIX, ''));
231
+ if (!isNaN(base))
232
+ return Math.min(Math.max(base, 1), numSections);
348
233
  }
349
234
  }
350
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
351
- finally {
352
- try {
353
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
354
- }
355
- finally { if (e_5) throw e_5.error; }
356
- }
357
235
  return 1;
358
236
  }
359
237
  /**
@@ -364,30 +242,17 @@ function computeBaseFromElement(element, numSections) {
364
242
  * @returns The image sources.
365
243
  */
366
244
  function getAllImageSources(htmlString) {
367
- var e_6, _a;
368
- var _b, _c;
369
245
  if (!htmlString)
370
246
  return [];
371
- var regexImg = /<img.*?src=(["'])(.*?)\1/g;
372
- var regexSrc = /<img.*?src=(["'])(.*?)\1/;
373
- var imageTags = (_b = regexImg.exec(htmlString)) !== null && _b !== void 0 ? _b : [];
374
- var out = [];
375
- try {
376
- for (var imageTags_1 = __values(imageTags), imageTags_1_1 = imageTags_1.next(); !imageTags_1_1.done; imageTags_1_1 = imageTags_1.next()) {
377
- var tag = imageTags_1_1.value;
378
- var src = (_c = regexSrc.exec(tag)) === null || _c === void 0 ? void 0 : _c[2];
379
- if (!src)
380
- continue;
381
- out.push(src);
382
- }
383
- }
384
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
385
- finally {
386
- try {
387
- if (imageTags_1_1 && !imageTags_1_1.done && (_a = imageTags_1.return)) _a.call(imageTags_1);
388
- }
389
- finally { if (e_6) throw e_6.error; }
247
+ const regexImg = /<img.*?src=(["'])(.*?)\1/g;
248
+ const regexSrc = /<img.*?src=(["'])(.*?)\1/;
249
+ const imageTags = regexImg.exec(htmlString) ?? [];
250
+ const out = [];
251
+ for (const tag of imageTags) {
252
+ const src = regexSrc.exec(tag)?.[2];
253
+ if (!src)
254
+ continue;
255
+ out.push(src);
390
256
  }
391
257
  return out;
392
258
  }
393
- //# sourceMappingURL=MasonryGrid.js.map