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,70 +1,16 @@
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.Collection = void 0;
54
- var jsx_runtime_1 = require("react/jsx-runtime");
55
- var clsx_1 = __importDefault(require("clsx"));
56
- var react_1 = __importDefault(require("fast-deep-equal/react"));
57
- var react_2 = require("react");
58
- var Each_1 = require("../operators/Each");
59
- var utils_1 = require("../utils");
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import clsx from 'clsx';
3
+ import isDeepEqual from 'fast-deep-equal/react';
4
+ import { forwardRef, useEffect, useRef } from 'react';
5
+ import { Each } from '../operators/Each.js';
6
+ import { asStyleDict, styles } from '../utils/index.js';
60
7
  /**
61
8
  * A collection of selectable items with generic data. Items are generated based
62
9
  * on the provided `ItemComponent`. This component supports different layouts in
63
10
  * both horizontal and vertical orientations.
64
11
  */
65
- exports.Collection = (0, react_2.forwardRef)(function (_a, ref) {
66
- var className = _a.className, style = _a.style, _b = _a.isSelectionTogglable, isSelectionTogglable = _b === void 0 ? false : _b, itemLength = _a.itemLength, _c = _a.itemPadding, itemPadding = _c === void 0 ? 0 : _c, items = _a.items, _d = _a.layout, layout = _d === void 0 ? 'list' : _d, _e = _a.numSegments, numSegments = _e === void 0 ? 1 : _e, _f = _a.orientation, orientation = _f === void 0 ? 'vertical' : _f, externalSelection = _a.selection, _g = _a.selectionMode, selectionMode = _g === void 0 ? 'none' : _g, onActivateAt = _a.onActivateAt, onDeselectAt = _a.onDeselectAt, onItemCustomEvent = _a.onItemCustomEvent, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, ItemComponent = _a.ItemComponent, props = __rest(_a, ["className", "style", "isSelectionTogglable", "itemLength", "itemPadding", "items", "layout", "numSegments", "orientation", "selection", "selectionMode", "onActivateAt", "onDeselectAt", "onItemCustomEvent", "onSelectAt", "onSelectionChange", "ItemComponent"]);
67
- var isIndexOutOfRange = function (index) {
12
+ export const Collection = forwardRef(({ className, style, isSelectionTogglable = false, itemLength, itemPadding = 0, items, layout = 'list', numSegments = 1, orientation = 'vertical', selection: externalSelection, selectionMode = 'none', onActivateAt, onDeselectAt, onItemCustomEvent, onSelectAt, onSelectionChange, ItemComponent, ...props }, ref) => {
13
+ const isIndexOutOfRange = (index) => {
68
14
  if (isNaN(index))
69
15
  return true;
70
16
  if (index >= items.length)
@@ -73,9 +19,9 @@ exports.Collection = (0, react_2.forwardRef)(function (_a, ref) {
73
19
  return true;
74
20
  return false;
75
21
  };
76
- var sanitizeSelection = function (indices) { return sortIndices(indices).filter(function (t) { return !isIndexOutOfRange(t); }); };
77
- var isSelectedAt = function (index) { return selection.indexOf(index) >= 0; };
78
- var toggleAt = function (index) {
22
+ const sanitizeSelection = (indices) => sortIndices(indices).filter(t => !isIndexOutOfRange(t));
23
+ const isSelectedAt = (index) => selection.indexOf(index) >= 0;
24
+ const toggleAt = (index) => {
79
25
  if (isSelectedAt(index)) {
80
26
  deselectAt(index);
81
27
  }
@@ -83,36 +29,36 @@ exports.Collection = (0, react_2.forwardRef)(function (_a, ref) {
83
29
  selectAt(index);
84
30
  }
85
31
  };
86
- var selectAt = function (index) {
32
+ const selectAt = (index) => {
87
33
  if (isSelectedAt(index))
88
34
  return;
89
- var transform;
35
+ let transform;
90
36
  switch (selectionMode) {
91
37
  case 'multiple': {
92
- transform = function (val) { return sortIndices(__spreadArray(__spreadArray([], __read(val.filter(function (t) { return t !== index; })), false), [index], false)); };
38
+ transform = val => sortIndices([...val.filter(t => t !== index), index]);
93
39
  break;
94
40
  }
95
41
  case 'single': {
96
- transform = function (val) { return [index]; };
42
+ transform = val => [index];
97
43
  break;
98
44
  }
99
45
  default:
100
46
  return;
101
47
  }
102
- var newValue = transform(selection);
48
+ const newValue = transform(selection);
103
49
  prevSelectionRef.current = newValue;
104
50
  handleSelectionChange(selection, newValue);
105
51
  };
106
- var deselectAt = function (index) {
52
+ const deselectAt = (index) => {
107
53
  if (!isSelectedAt(index))
108
54
  return;
109
- var transform = function (val) { return val.filter(function (t) { return t !== index; }); };
110
- var newValue = transform(selection);
55
+ const transform = (val) => val.filter(t => t !== index);
56
+ const newValue = transform(selection);
111
57
  prevSelectionRef.current = newValue;
112
58
  handleSelectionChange(selection, newValue);
113
59
  };
114
- var activateAt = function (index) {
115
- onActivateAt === null || onActivateAt === void 0 ? void 0 : onActivateAt(index);
60
+ const activateAt = (index) => {
61
+ onActivateAt?.(index);
116
62
  if (selectionMode === 'none')
117
63
  return;
118
64
  if (isSelectionTogglable) {
@@ -122,61 +68,79 @@ exports.Collection = (0, react_2.forwardRef)(function (_a, ref) {
122
68
  selectAt(index);
123
69
  }
124
70
  };
125
- var handleSelectionChange = function (oldValue, newValue) {
126
- var _a;
127
- if ((0, react_1.default)(oldValue, newValue))
71
+ const handleSelectionChange = (oldValue, newValue) => {
72
+ if (isDeepEqual(oldValue, newValue))
128
73
  return;
129
- var deselected = (_a = oldValue === null || oldValue === void 0 ? void 0 : oldValue.filter(function (t) { return newValue.indexOf(t) === -1; })) !== null && _a !== void 0 ? _a : [];
130
- var selected = newValue.filter(function (t) { return (oldValue === null || oldValue === void 0 ? void 0 : oldValue.indexOf(t)) === -1; });
131
- deselected.forEach(function (t) { return onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(t); });
132
- selected.forEach(function (t) { return onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(t); });
133
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newValue);
74
+ const deselected = oldValue?.filter(t => newValue.indexOf(t) === -1) ?? [];
75
+ const selected = newValue.filter(t => oldValue?.indexOf(t) === -1);
76
+ deselected.forEach(t => onDeselectAt?.(t));
77
+ selected.forEach(t => onSelectAt?.(t));
78
+ onSelectionChange?.(newValue);
134
79
  };
135
- var selection = sanitizeSelection(externalSelection !== null && externalSelection !== void 0 ? externalSelection : []);
136
- var fixedStyles = getFixedStyles({ itemLength: itemLength, itemPadding: itemPadding, layout: layout, numSegments: numSegments, orientation: orientation });
137
- var prevSelectionRef = (0, react_2.useRef)();
138
- var prevSelection = prevSelectionRef.current;
139
- (0, react_2.useEffect)(function () {
80
+ const selection = sanitizeSelection(externalSelection ?? []);
81
+ const fixedStyles = getFixedStyles({ itemLength, itemPadding, layout, numSegments, orientation });
82
+ const prevSelectionRef = useRef();
83
+ const prevSelection = prevSelectionRef.current;
84
+ useEffect(() => {
140
85
  prevSelectionRef.current = selection;
141
86
  if (prevSelection === undefined)
142
87
  return;
143
88
  handleSelectionChange(prevSelection, selection);
144
89
  }, [JSON.stringify(selection)]);
145
- return ((0, jsx_runtime_1.jsx)("div", __assign({}, props, { ref: ref, className: (0, clsx_1.default)(className), "data-component": 'collection', style: (0, utils_1.styles)(style, fixedStyles.root), children: ItemComponent && ((0, jsx_runtime_1.jsx)(Each_1.Each, { in: items, children: function (val, idx) { return ((0, jsx_runtime_1.jsx)(ItemComponent, { className: (0, clsx_1.default)({ selected: isSelectedAt(idx) }), "data-child": 'item', "data-index": idx, index: idx, isSelected: isSelectedAt(idx), item: val, orientation: orientation, style: (0, utils_1.styles)(fixedStyles.item, __assign({ pointerEvents: isSelectionTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto' }, idx >= items.length - 1 ? {} : __assign({}, layout === 'list' ? __assign({}, orientation === 'vertical' ? {
146
- marginBottom: "".concat(itemPadding, "px"),
147
- } : {
148
- marginRight: "".concat(itemPadding, "px"),
149
- }) : {}))), onClick: function () { return activateAt(idx); }, onCustomEvent: function (name, info) { return onItemCustomEvent === null || onItemCustomEvent === void 0 ? void 0 : onItemCustomEvent(idx, name, info); } })); } })) })));
90
+ return (_jsx("div", { ...props, ref: ref, className: clsx(className), "data-component": 'collection', style: styles(style, fixedStyles.root), children: ItemComponent && (_jsx(Each, { in: items, children: (val, idx) => (_jsx(ItemComponent, { className: clsx({ selected: isSelectedAt(idx) }), "data-child": 'item', "data-index": idx, index: idx, isSelected: isSelectedAt(idx), item: val, orientation: orientation, style: styles(fixedStyles.item, {
91
+ pointerEvents: isSelectionTogglable !== true && isSelectedAt(idx) ? 'none' : 'auto',
92
+ ...idx >= items.length - 1 ? {} : {
93
+ ...layout === 'list' ? {
94
+ ...orientation === 'vertical' ? {
95
+ marginBottom: `${itemPadding}px`,
96
+ } : {
97
+ marginRight: `${itemPadding}px`,
98
+ },
99
+ } : {},
100
+ },
101
+ }), onClick: () => activateAt(idx), onCustomEvent: (name, info) => onItemCustomEvent?.(idx, name, info) })) })) }));
150
102
  });
151
- Object.defineProperty(exports.Collection, 'displayName', { value: 'Collection', writable: false });
103
+ Object.defineProperty(Collection, 'displayName', { value: 'Collection', writable: false });
152
104
  function sortIndices(indices) {
153
- return indices.sort(function (a, b) { return a - b; });
105
+ return indices.sort((a, b) => a - b);
154
106
  }
155
- function getFixedStyles(_a) {
156
- var _b = _a.itemLength, itemLength = _b === void 0 ? NaN : _b, _c = _a.itemPadding, itemPadding = _c === void 0 ? 0 : _c, _d = _a.layout, layout = _d === void 0 ? 'collection' : _d, _e = _a.numSegments, numSegments = _e === void 0 ? 1 : _e, _f = _a.orientation, orientation = _f === void 0 ? 'vertical' : _f;
157
- return (0, utils_1.asStyleDict)({
158
- root: __assign({ counterReset: 'item-counter', listStyle: 'none' }, layout === 'list' ? {
159
- alignItems: 'flex-start',
160
- display: 'flex',
107
+ function getFixedStyles({ itemLength = NaN, itemPadding = 0, layout = 'collection', numSegments = 1, orientation = 'vertical' }) {
108
+ return asStyleDict({
109
+ root: {
110
+ counterReset: 'item-counter',
111
+ listStyle: 'none',
112
+ ...layout === 'list' ? {
113
+ alignItems: 'flex-start',
114
+ display: 'flex',
115
+ flex: '0 0 auto',
116
+ flexDirection: orientation === 'horizontal' ? 'row' : 'column',
117
+ justifyContent: 'flex-start',
118
+ } : {
119
+ display: 'grid',
120
+ gap: `${itemPadding}px`,
121
+ ...orientation === 'vertical' ? {
122
+ gridAutoRows: isNaN(itemLength) ? undefined : `${itemLength}px`,
123
+ gridTemplateColumns: `repeat(${numSegments}, 1fr)`,
124
+ gridAutoFlow: 'row',
125
+ } : {
126
+ gridAutoColumns: isNaN(itemLength) ? undefined : `${itemLength}px`,
127
+ gridTemplateRows: `repeat(${numSegments}, 1fr)`,
128
+ gridAutoFlow: 'column',
129
+ },
130
+ },
131
+ },
132
+ item: {
133
+ counterIncrement: 'item-counter',
161
134
  flex: '0 0 auto',
162
- flexDirection: orientation === 'horizontal' ? 'row' : 'column',
163
- justifyContent: 'flex-start',
164
- } : __assign({ display: 'grid', gap: "".concat(itemPadding, "px") }, orientation === 'vertical' ? {
165
- gridAutoRows: isNaN(itemLength) ? undefined : "".concat(itemLength, "px"),
166
- gridTemplateColumns: "repeat(".concat(numSegments, ", 1fr)"),
167
- gridAutoFlow: 'row',
168
- } : {
169
- gridAutoColumns: isNaN(itemLength) ? undefined : "".concat(itemLength, "px"),
170
- gridTemplateRows: "repeat(".concat(numSegments, ", 1fr)"),
171
- gridAutoFlow: 'column',
172
- })),
173
- item: __assign({ counterIncrement: 'item-counter', flex: '0 0 auto' }, layout === 'list' ? __assign({}, orientation === 'vertical' ? {
174
- width: '100%',
175
- height: isNaN(itemLength) ? undefined : "".concat(itemLength, "px"),
176
- } : {
177
- width: isNaN(itemLength) ? undefined : "".concat(itemLength, "px"),
178
- height: '100%',
179
- }) : {}),
135
+ ...layout === 'list' ? {
136
+ ...orientation === 'vertical' ? {
137
+ width: '100%',
138
+ height: isNaN(itemLength) ? undefined : `${itemLength}px`,
139
+ } : {
140
+ width: isNaN(itemLength) ? undefined : `${itemLength}px`,
141
+ height: '100%',
142
+ },
143
+ } : {},
144
+ },
180
145
  });
181
146
  }
182
- //# sourceMappingURL=Collection.js.map
@@ -1,102 +1,71 @@
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;
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import clsx from 'clsx';
3
+ import { forwardRef, useEffect } from 'react';
4
+ import { usePrevious } from '../hooks/usePrevious.js';
5
+ import { asStyleDict, styles } from '../utils/index.js';
6
+ import { TextField } from './TextField.js';
7
+ export const Counter = forwardRef(({ style, min = NaN, max = NaN, allowsInput = true, quantity = 0, usesDefaultStyles = true, onChange, AddButtonComponent, SubtractButtonComponent, ...props }, ref) => {
8
+ const handleSubtract = () => {
9
+ onChange?.(isNaN(min) ? quantity - 1 : Math.max(min, quantity - 1));
10
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 __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.Counter = void 0;
29
- var jsx_runtime_1 = require("react/jsx-runtime");
30
- var clsx_1 = __importDefault(require("clsx"));
31
- var react_1 = require("react");
32
- var usePrevious_1 = require("../hooks/usePrevious");
33
- var asStyleDict_1 = require("../utils/asStyleDict");
34
- var styles_1 = require("../utils/styles");
35
- var TextField_1 = require("./TextField");
36
- exports.Counter = (0, react_1.forwardRef)(function (_a, ref) {
37
- var style = _a.style, _b = _a.min, min = _b === void 0 ? NaN : _b, _c = _a.max, max = _c === void 0 ? NaN : _c, _d = _a.allowsInput, allowsInput = _d === void 0 ? true : _d, _e = _a.quantity, quantity = _e === void 0 ? 0 : _e, _f = _a.usesDefaultStyles, usesDefaultStyles = _f === void 0 ? true : _f, onChange = _a.onChange, AddButtonComponent = _a.AddButtonComponent, SubtractButtonComponent = _a.SubtractButtonComponent, props = __rest(_a, ["style", "min", "max", "allowsInput", "quantity", "usesDefaultStyles", "onChange", "AddButtonComponent", "SubtractButtonComponent"]);
38
- var handleSubtract = function () {
39
- onChange === null || onChange === void 0 ? void 0 : onChange(isNaN(min) ? quantity - 1 : Math.max(min, quantity - 1));
11
+ const handleAdd = () => {
12
+ onChange?.(isNaN(max) ? quantity + 1 : Math.min(max, quantity + 1));
40
13
  };
41
- var handleAdd = function () {
42
- onChange === null || onChange === void 0 ? void 0 : onChange(isNaN(max) ? quantity + 1 : Math.min(max, quantity + 1));
43
- };
44
- var handleQuantityChange = function (newValue) {
14
+ const handleQuantityChange = (newValue) => {
45
15
  if (newValue === quantity)
46
16
  return;
47
- onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
17
+ onChange?.(newValue);
48
18
  };
49
- var prevQuantity = (0, usePrevious_1.usePrevious)(quantity);
50
- var defaultStyles = usesDefaultStyles ? DEFAULT_STYLES : undefined;
51
- var isAddingDisabled = !isNaN(max) && quantity + 1 > max;
52
- var isSubtractingDisabled = !isNaN(min) && quantity - 1 < min;
53
- (0, react_1.useEffect)(function () {
19
+ const prevQuantity = usePrevious(quantity);
20
+ const defaultStyles = usesDefaultStyles ? DEFAULT_STYLES : undefined;
21
+ const isAddingDisabled = !isNaN(max) && quantity + 1 > max;
22
+ const isSubtractingDisabled = !isNaN(min) && quantity - 1 < min;
23
+ useEffect(() => {
54
24
  if (prevQuantity === undefined)
55
25
  return;
56
26
  handleQuantityChange(quantity);
57
27
  }, [quantity]);
58
- (0, react_1.useEffect)(function () {
28
+ useEffect(() => {
59
29
  handleQuantityChange(isNaN(min) ? quantity : Math.max(min, quantity));
60
30
  }, [min]);
61
- (0, react_1.useEffect)(function () {
31
+ useEffect(() => {
62
32
  if (isNaN(max))
63
33
  return;
64
34
  handleQuantityChange(isNaN(max) ? quantity : Math.min(max, quantity));
65
35
  }, [max]);
66
- return ((0, jsx_runtime_1.jsxs)("div", __assign({}, props, { ref: ref, "data-component": 'counter', style: (0, styles_1.styles)(style, FIXED_STYLES.root, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.root), children: [SubtractButtonComponent && ((0, jsx_runtime_1.jsx)(SubtractButtonComponent, { className: (0, clsx_1.default)({ disabled: isSubtractingDisabled }), "data-child": 'subtract-button', style: (0, styles_1.styles)(FIXED_STYLES.subtract), onClick: function () { return handleSubtract(); } })) || ((0, jsx_runtime_1.jsx)("button", { className: (0, clsx_1.default)({ disabled: isSubtractingDisabled }), "data-child": 'subtract-button', style: (0, styles_1.styles)(FIXED_STYLES.subtract, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.subtract), onClick: function () { return handleSubtract(); } })), (0, jsx_runtime_1.jsx)(TextField_1.TextField, { "data-child": 'text-field', formatter: function (oldValue, newValue) { return isNaN(Number("0".concat(newValue))) ? oldValue : newValue; }, isDisabled: !allowsInput, style: (0, styles_1.styles)(FIXED_STYLES.text, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.text), value: quantity.toString() }), AddButtonComponent && ((0, jsx_runtime_1.jsx)(AddButtonComponent, { className: (0, clsx_1.default)({ disabled: isAddingDisabled }), "data-child": 'add-button', style: (0, styles_1.styles)(FIXED_STYLES.add), onClick: function () { return handleAdd(); } })) || ((0, jsx_runtime_1.jsx)("button", { className: (0, clsx_1.default)({ disabled: isAddingDisabled }), "data-child": 'add-button', style: (0, styles_1.styles)(FIXED_STYLES.add, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.add), onClick: function () { return handleAdd(); } }))] })));
36
+ return (_jsxs("div", { ...props, ref: ref, "data-component": 'counter', style: styles(style, FIXED_STYLES.root, defaultStyles?.root), children: [SubtractButtonComponent && (_jsx(SubtractButtonComponent, { className: clsx({ disabled: isSubtractingDisabled }), "data-child": 'subtract-button', style: styles(FIXED_STYLES.subtract), onClick: () => handleSubtract() })) || (_jsx("button", { className: clsx({ disabled: isSubtractingDisabled }), "data-child": 'subtract-button', style: styles(FIXED_STYLES.subtract, defaultStyles?.subtract), onClick: () => handleSubtract() })), _jsx(TextField, { "data-child": 'text-field', formatter: (oldValue, newValue) => isNaN(Number(`0${newValue}`)) ? oldValue : newValue, isDisabled: !allowsInput, style: styles(FIXED_STYLES.text, defaultStyles?.text), value: quantity.toString() }), AddButtonComponent && (_jsx(AddButtonComponent, { className: clsx({ disabled: isAddingDisabled }), "data-child": 'add-button', style: styles(FIXED_STYLES.add), onClick: () => handleAdd() })) || (_jsx("button", { className: clsx({ disabled: isAddingDisabled }), "data-child": 'add-button', style: styles(FIXED_STYLES.add, defaultStyles?.add), onClick: () => handleAdd() }))] }));
67
37
  });
68
- Object.defineProperty(exports.Counter, 'displayName', { value: 'Counter', writable: false });
69
- var FIXED_STYLES = (0, asStyleDict_1.asStyleDict)({
70
- root: (0, styles_1.styles)({
38
+ Object.defineProperty(Counter, 'displayName', { value: 'Counter', writable: false });
39
+ const FIXED_STYLES = asStyleDict({
40
+ root: styles({
71
41
  display: 'flex',
72
42
  flexDirection: 'row',
73
43
  justifyContent: 'flex-start',
74
44
  alignItems: 'stretch',
75
45
  }),
76
- subtract: (0, styles_1.styles)({
46
+ subtract: styles({
77
47
  flex: '0 0 auto',
78
48
  }),
79
- add: (0, styles_1.styles)({
49
+ add: styles({
80
50
  flex: '0 0 auto',
81
51
  }),
82
- text: (0, styles_1.styles)({
52
+ text: styles({
83
53
  flex: '1 1 auto',
84
54
  }),
85
55
  });
86
- var DEFAULT_STYLES = (0, asStyleDict_1.asStyleDict)({
87
- root: (0, styles_1.styles)({}),
88
- subtract: (0, styles_1.styles)({
56
+ const DEFAULT_STYLES = asStyleDict({
57
+ root: styles({}),
58
+ subtract: styles({
89
59
  width: '20px',
90
60
  height: '100%',
91
61
  background: '#000',
92
62
  }),
93
- add: (0, styles_1.styles)({
63
+ add: styles({
94
64
  width: '20px',
95
65
  height: '100%',
96
66
  background: '#000',
97
67
  }),
98
- text: (0, styles_1.styles)({
68
+ text: styles({
99
69
  height: '100%',
100
70
  }),
101
71
  });
102
- //# sourceMappingURL=Counter.js.map
@@ -1,63 +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
- 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
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.CoverImage = void 0;
42
- var jsx_runtime_1 = require("react/jsx-runtime");
43
- var react_1 = require("react");
44
- var spase_1 = require("spase");
45
- var useRect_1 = require("../hooks/useRect");
46
- var utils_1 = require("../utils");
47
- var Image_1 = require("./Image");
48
- exports.CoverImage = (0, react_1.forwardRef)(function (_a, ref) {
49
- var _b;
50
- var children = _a.children, style = _a.style, alt = _a.alt, _c = _a.aspectRatio, externalAspectRatio = _c === void 0 ? NaN : _c, loadingMode = _a.loadingMode, renderViewportContent = _a.renderViewportContent, sizes = _a.sizes, src = _a.src, srcSet = _a.srcSet, onLoadStart = _a.onLoadStart, onLoadComplete = _a.onLoadComplete, onLoadError = _a.onLoadError, props = __rest(_a, ["children", "style", "alt", "aspectRatio", "loadingMode", "renderViewportContent", "sizes", "src", "srcSet", "onLoadStart", "onLoadComplete", "onLoadError"]);
51
- var handleSizeChange = function (size) {
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useRef, useState } from 'react';
3
+ import { Size } from 'spase';
4
+ import { useRect } from '../hooks/useRect.js';
5
+ import { asStyleDict, styles } from '../utils/index.js';
6
+ import { Image } from './Image.js';
7
+ export const CoverImage = forwardRef(({ children, style, alt, aspectRatio: externalAspectRatio = NaN, loadingMode, renderViewportContent, sizes, src, srcSet, onLoadStart, onLoadComplete, onLoadError, ...props }, ref) => {
8
+ const handleSizeChange = (size) => {
52
9
  setLocalAspectRatio(size ? size.width / size.height : NaN);
53
10
  };
54
- var localRef = (0, react_1.useRef)(null);
55
- var rootRef = (_b = ref) !== null && _b !== void 0 ? _b : localRef;
56
- var _d = __read((0, react_1.useState)(NaN), 2), localAspectRatio = _d[0], setLocalAspectRatio = _d[1];
57
- var aspectRatio = isNaN(externalAspectRatio) ? localAspectRatio : externalAspectRatio;
58
- var rootRect = (0, useRect_1.useRect)(rootRef);
59
- var rootAspectRatio = rootRect.width / rootRect.height;
60
- var imageSize = new spase_1.Size([
11
+ const localRef = useRef(null);
12
+ const rootRef = ref ?? localRef;
13
+ const [localAspectRatio, setLocalAspectRatio] = useState(NaN);
14
+ const aspectRatio = isNaN(externalAspectRatio) ? localAspectRatio : externalAspectRatio;
15
+ const rootRect = useRect(rootRef);
16
+ const rootAspectRatio = rootRect.width / rootRect.height;
17
+ const imageSize = new Size([
61
18
  rootAspectRatio > 1
62
19
  ? Math.max(rootRect.width, rootRect.height * aspectRatio)
63
20
  : Math.max(rootRect.width, (Math.max(rootRect.height, rootRect.width / aspectRatio)) * aspectRatio),
@@ -65,17 +22,17 @@ exports.CoverImage = (0, react_1.forwardRef)(function (_a, ref) {
65
22
  ? Math.max(rootRect.height, Math.max(rootRect.width, rootRect.height * aspectRatio) / aspectRatio)
66
23
  : Math.max(rootRect.height, rootRect.width / aspectRatio),
67
24
  ]);
68
- return ((0, jsx_runtime_1.jsxs)("div", __assign({}, props, { ref: rootRef, "data-component": 'cover-image', style: (0, utils_1.styles)(style, FIXED_STYLES.root), children: [(0, jsx_runtime_1.jsx)(Image_1.Image, { alt: alt, "data-child": 'image', sizes: sizes, src: src, srcSet: srcSet, style: (0, utils_1.styles)(FIXED_STYLES.viewport, {
69
- width: "".concat(imageSize.width, "px"),
70
- height: "".concat(imageSize.height, "px"),
71
- }), onLoadComplete: onLoadComplete, onLoadError: onLoadError, onLoadStart: onLoadStart, onSizeChange: function (size) { return handleSizeChange(size); } }), renderViewportContent && ((0, jsx_runtime_1.jsx)("div", { "data-child": 'viewport', style: (0, utils_1.styles)(FIXED_STYLES.viewport, {
72
- height: "".concat(imageSize.height, "px"),
25
+ return (_jsxs("div", { ...props, ref: rootRef, "data-component": 'cover-image', style: styles(style, FIXED_STYLES.root), children: [_jsx(Image, { alt: alt, "data-child": 'image', sizes: sizes, src: src, srcSet: srcSet, style: styles(FIXED_STYLES.viewport, {
26
+ width: `${imageSize.width}px`,
27
+ height: `${imageSize.height}px`,
28
+ }), onLoadComplete: onLoadComplete, onLoadError: onLoadError, onLoadStart: onLoadStart, onSizeChange: size => handleSizeChange(size) }), renderViewportContent && (_jsx("div", { "data-child": 'viewport', style: styles(FIXED_STYLES.viewport, {
29
+ height: `${imageSize.height}px`,
73
30
  pointerEvents: 'none',
74
- width: "".concat(imageSize.width, "px"),
75
- }), children: renderViewportContent() })), children] })));
31
+ width: `${imageSize.width}px`,
32
+ }), children: renderViewportContent() })), children] }));
76
33
  });
77
- Object.defineProperty(exports.CoverImage, 'displayName', { value: 'CoverImage', writable: false });
78
- var FIXED_STYLES = (0, utils_1.asStyleDict)({
34
+ Object.defineProperty(CoverImage, 'displayName', { value: 'CoverImage', writable: false });
35
+ const FIXED_STYLES = asStyleDict({
79
36
  root: {
80
37
  overflow: 'hidden',
81
38
  },
@@ -94,4 +51,3 @@ var FIXED_STYLES = (0, utils_1.asStyleDict)({
94
51
  width: '100%',
95
52
  },
96
53
  });
97
- //# sourceMappingURL=CoverImage.js.map