@enact/ui 4.5.2 → 4.6.1

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 (222) hide show
  1. package/AnnounceDecorator/Announce.js +1 -40
  2. package/AnnounceDecorator/AnnounceDecorator.js +3 -21
  3. package/AnnounceDecorator/tests/Announce-specs.js +2 -7
  4. package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +2 -6
  5. package/AnnounceDecorator/tests/useAnnounce-specs.js +8 -19
  6. package/AnnounceDecorator/useAnnounce.js +0 -6
  7. package/BodyText/BodyText.js +8 -28
  8. package/BodyText/tests/BodyText-specs.js +0 -19
  9. package/Button/Button.js +33 -63
  10. package/Button/tests/Button-specs.js +0 -26
  11. package/CHANGELOG.md +45 -0
  12. package/Cancelable/Cancelable.js +8 -47
  13. package/Cancelable/cancelHandler.js +5 -12
  14. package/Cancelable/modalHandler.js +3 -11
  15. package/Cancelable/tests/Cancelable-specs.js +3 -57
  16. package/Changeable/Changeable.js +2 -34
  17. package/Changeable/tests/Changeable-specs.js +20 -66
  18. package/ComponentOverride/ComponentOverride.js +1 -13
  19. package/FloatingLayer/FloatingLayer.js +17 -73
  20. package/FloatingLayer/FloatingLayerContainer.js +0 -15
  21. package/FloatingLayer/FloatingLayerDecorator.js +4 -17
  22. package/FloatingLayer/Scrim.js +9 -53
  23. package/FloatingLayer/index.js +0 -4
  24. package/FloatingLayer/package.json +3 -0
  25. package/FloatingLayer/tests/FloatingLayer-specs.js +8 -22
  26. package/FloatingLayer/tests/Scrim-specs.js +0 -9
  27. package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +0 -13
  28. package/FloatingLayer/useFloatingLayer.js +3 -14
  29. package/FloatingLayer/useFloatingLayerDecorator.js +3 -11
  30. package/ForwardRef/ForwardRef.js +1 -10
  31. package/GridListImageItem/GridListImageItem.js +18 -51
  32. package/Group/Group.js +5 -36
  33. package/Group/GroupItem.js +16 -33
  34. package/Group/tests/Group-specs.js +0 -32
  35. package/Heading/Heading.js +8 -36
  36. package/Heading/tests/Heading-specs.js +81 -14
  37. package/Icon/Icon.js +19 -53
  38. package/Icon/tests/Icon-specs.js +0 -22
  39. package/IconButton/IconButton.js +24 -57
  40. package/IconButton/tests/IconButton-specs.js +0 -7
  41. package/Image/Image.js +17 -46
  42. package/Image/tests/Image-specs.js +0 -14
  43. package/ImageItem/ImageItem.js +18 -47
  44. package/ImageItem/tests/ImageItem-specs.js +0 -25
  45. package/Item/Item.js +9 -33
  46. package/Item/tests/Item-specs.js +0 -24
  47. package/LabeledIcon/LabeledIcon.js +22 -53
  48. package/LabeledIcon/tests/LabeledIcon-specs.js +0 -14
  49. package/Layout/Cell.js +18 -44
  50. package/Layout/Layout.js +23 -46
  51. package/Layout/tests/Layout-specs.js +10 -39
  52. package/Marquee/MarqueeBase.js +29 -63
  53. package/Marquee/MarqueeController.js +11 -72
  54. package/Marquee/MarqueeDecorator.js +70 -196
  55. package/Marquee/index.js +1 -5
  56. package/Marquee/tests/Marquee-specs.js +295 -87
  57. package/Measurable/Measurable.js +12 -34
  58. package/Measurable/tests/Measurable-specs.js +115 -0
  59. package/Media/Media.js +15 -65
  60. package/Media/tests/Media-specs.js +168 -0
  61. package/Placeholder/PlaceholderControllerDecorator.js +7 -43
  62. package/Placeholder/PlaceholderDecorator.js +7 -38
  63. package/Placeholder/index.js +1 -5
  64. package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +25 -0
  65. package/Placeholder/tests/PlaceholderDecorator-specs.js +28 -0
  66. package/ProgressBar/ProgressBar.js +14 -45
  67. package/ProgressBar/tests/ProgressBar-specs.js +0 -17
  68. package/RadioDecorator/RadioControllerDecorator.js +7 -29
  69. package/RadioDecorator/RadioDecorator.js +9 -42
  70. package/RadioDecorator/tests/RadioDecorator-specs.js +12 -49
  71. package/Repeater/Repeater.js +9 -33
  72. package/Repeater/tests/Repeater-specs.js +0 -38
  73. package/Resizable/Resizable.js +9 -37
  74. package/Resizable/tests/Resizable-specs.js +34 -0
  75. package/Routable/Link.js +11 -47
  76. package/Routable/Routable.js +12 -35
  77. package/Routable/Route.js +0 -6
  78. package/Routable/Router.js +15 -58
  79. package/Routable/tests/Routable-specs.js +7 -33
  80. package/Routable/tests/Router-specs.js +18 -44
  81. package/Routable/useLink.js +4 -8
  82. package/Routable/util.js +18 -24
  83. package/Scrollable/ScrollAnimator.js +49 -65
  84. package/Scrollable/ScrollThumb.js +2 -13
  85. package/Scrollable/Scrollable.js +180 -387
  86. package/Scrollable/ScrollableNative.js +189 -392
  87. package/Scrollable/Scrollbar.js +30 -102
  88. package/Scroller/Scroller.js +15 -39
  89. package/Scroller/ScrollerBasic.js +34 -89
  90. package/Scroller/UiScrollerBase.js +37 -84
  91. package/Scroller/tests/Scroller-specs.js +56 -0
  92. package/Skinnable/Skinnable.js +11 -38
  93. package/Skinnable/tests/Skinnable-specs.js +3 -74
  94. package/Skinnable/tests/useSkins-specs.js +1 -13
  95. package/Skinnable/tests/util-specs.js +0 -14
  96. package/Skinnable/useSkins.js +8 -15
  97. package/Skinnable/util.js +9 -20
  98. package/Slider/Knob.js +5 -24
  99. package/Slider/PositionDecorator.js +16 -54
  100. package/Slider/Slider.js +29 -67
  101. package/Slider/tests/Slider-specs.js +94 -7
  102. package/Slider/utils.js +0 -2
  103. package/SlotItem/SlotItem.js +23 -45
  104. package/SlotItem/tests/SlotItem-specs.js +0 -5
  105. package/Slottable/Slottable.js +4 -12
  106. package/Slottable/tests/Slottable-specs.js +19 -46
  107. package/Slottable/tests/useSlots-specs.js +27 -65
  108. package/Slottable/useSlots.js +8 -33
  109. package/Spinner/Spinner.js +16 -43
  110. package/Spinner/tests/Spinner-specs.js +0 -15
  111. package/ToggleIcon/ToggleIcon.js +10 -36
  112. package/ToggleIcon/tests/ToggleIcon-specs.js +0 -16
  113. package/ToggleItem/ToggleItem.js +24 -57
  114. package/ToggleItem/tests/ToggleItem-specs.js +0 -30
  115. package/Toggleable/Toggle.js +1 -15
  116. package/Toggleable/Toggleable.js +12 -45
  117. package/Toggleable/tests/Toggleable-specs.js +28 -96
  118. package/Toggleable/useToggle.js +3 -19
  119. package/Touchable/ClickAllow.js +5 -14
  120. package/Touchable/Drag.js +16 -54
  121. package/Touchable/Flick.js +11 -42
  122. package/Touchable/Hold.js +21 -68
  123. package/Touchable/Pinch.js +185 -0
  124. package/Touchable/Touch.js +71 -76
  125. package/Touchable/Touchable.js +95 -75
  126. package/Touchable/config.js +27 -24
  127. package/Touchable/tests/Touchable-specs.js +360 -119
  128. package/Touchable/tests/useTouch-specs.js +6 -80
  129. package/Touchable/useTouch.js +57 -65
  130. package/Transition/Transition.js +37 -118
  131. package/Transition/tests/Transition-specs.js +20 -60
  132. package/ViewManager/Arranger.js +10 -22
  133. package/ViewManager/TransitionGroup.js +32 -107
  134. package/ViewManager/View.js +35 -91
  135. package/ViewManager/ViewManager.js +20 -84
  136. package/ViewManager/tests/View-specs.js +0 -17
  137. package/ViewManager/tests/ViewManager-specs.js +236 -305
  138. package/ViewManager/tests/test-utils.js +0 -8
  139. package/VirtualList/UiVirtualListBase.js +265 -409
  140. package/VirtualList/VirtualList.js +29 -69
  141. package/VirtualList/VirtualListBase.js +0 -3
  142. package/VirtualList/VirtualListBasic.js +273 -431
  143. package/VirtualList/tests/VirtualGridList-native-specs.js +161 -0
  144. package/VirtualList/tests/VirtualGridList-specs.js +614 -0
  145. package/VirtualList/tests/VirtualList-native-specs.js +152 -0
  146. package/VirtualList/tests/VirtualList-specs.js +423 -95
  147. package/internal/IdProvider/IdProvider.js +7 -21
  148. package/internal/IdProvider/Provider.js +4 -17
  149. package/internal/IdProvider/tests/IdProvider-specs.js +44 -0
  150. package/internal/IdProvider/tests/useId-specs.js +6 -20
  151. package/internal/IdProvider/useId.js +0 -6
  152. package/internal/Pure/Pure.js +3 -30
  153. package/internal/Pure/tests/Pure-specs.js +88 -0
  154. package/internal/localized-fonts/localized-fonts.js +33 -62
  155. package/internal/localized-fonts/tests/localized-fonts-specs.js +33 -0
  156. package/internal/selection/selection.js +1 -6
  157. package/internal/selection/tests/selection-specs.js +6 -4
  158. package/internal/validators/tests/validators-specs.js +80 -0
  159. package/internal/validators/validators.js +14 -34
  160. package/package.json +9 -3
  161. package/resolution/ResolutionDecorator.js +4 -40
  162. package/resolution/index.js +0 -7
  163. package/resolution/resolution.js +42 -80
  164. package/resolution/tests/ResolutionDecorator-specs.js +4 -11
  165. package/resolution/tests/resolution-specs.js +2 -2
  166. package/useControlledState/tests/useControlledState-specs.js +15 -46
  167. package/useControlledState/useControlledState.js +11 -22
  168. package/useScroll/ScrollAnimator.js +49 -65
  169. package/useScroll/Scrollbar.js +22 -58
  170. package/useScroll/ScrollbarTrack.js +3 -19
  171. package/useScroll/useScroll.js +267 -454
  172. package/useScroll/utilDOM.js +8 -14
  173. package/useScroll/utilEvent.js +0 -4
  174. package/AnnounceDecorator/AnnounceDecorator.d.ts +0 -64
  175. package/BodyText/BodyText.d.ts +0 -66
  176. package/Button/Button.d.ts +0 -125
  177. package/Cancelable/Cancelable.d.ts +0 -64
  178. package/Changeable/Changeable.d.ts +0 -54
  179. package/ComponentOverride/ComponentOverride.d.ts +0 -52
  180. package/ForwardRef/ForwardRef.d.ts +0 -22
  181. package/GridListImageItem/GridListImageItem.d.ts +0 -85
  182. package/Group/Group.d.ts +0 -107
  183. package/Heading/Heading.d.ts +0 -90
  184. package/Icon/Icon.d.ts +0 -88
  185. package/IconButton/IconButton.d.ts +0 -115
  186. package/Image/Image.d.ts +0 -113
  187. package/ImageItem/ImageItem.d.ts +0 -83
  188. package/Item/Item.d.ts +0 -64
  189. package/LabeledIcon/LabeledIcon.d.ts +0 -130
  190. package/Layout/Layout.d.ts +0 -247
  191. package/Marquee/index.d.ts +0 -258
  192. package/Measurable/Measurable.d.ts +0 -26
  193. package/Media/Media.d.ts +0 -99
  194. package/Placeholder/index.d.ts +0 -53
  195. package/ProgressBar/ProgressBar.d.ts +0 -92
  196. package/RadioDecorator/RadioDecorator.d.ts +0 -35
  197. package/Repeater/Repeater.d.ts +0 -83
  198. package/Resizable/Resizable.d.ts +0 -31
  199. package/Routable/Routable.d.ts +0 -148
  200. package/Scrollable/Scrollable.d.ts +0 -0
  201. package/Scroller/Scroller.d.ts +0 -276
  202. package/Skinnable/Skinnable.d.ts +0 -94
  203. package/Slider/Slider.d.ts +0 -202
  204. package/SlotItem/SlotItem.d.ts +0 -118
  205. package/Slottable/Slottable.d.ts +0 -22
  206. package/Spinner/Spinner.d.ts +0 -95
  207. package/ToggleIcon/ToggleIcon.d.ts +0 -90
  208. package/ToggleItem/ToggleItem.d.ts +0 -134
  209. package/Toggleable/Toggleable.d.ts +0 -103
  210. package/Touchable/Touchable.d.ts +0 -175
  211. package/Transition/Transition.d.ts +0 -196
  212. package/ViewManager/ViewManager.d.ts +0 -191
  213. package/VirtualList/VirtualList.d.ts +0 -530
  214. package/index.d.ts +0 -0
  215. package/internal/IdProvider/IdProvider.d.ts +0 -0
  216. package/internal/Pure/Pure.d.ts +0 -0
  217. package/internal/localized-fonts/localized-fonts.d.ts +0 -53
  218. package/internal/selection/selection.d.ts +0 -0
  219. package/internal/validators/validators.d.ts +0 -0
  220. package/resolution/index.d.ts +0 -187
  221. package/useControlledState/useControlledState.d.ts +0 -0
  222. package/useScroll/useScroll.d.ts +0 -0
package/Touchable/Hold.js CHANGED
@@ -4,50 +4,37 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.holdConfigPropType = exports.defaultHoldConfig = exports["default"] = exports.Hold = void 0;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
9
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
-
14
10
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
-
16
11
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
-
18
12
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
-
20
13
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
21
-
22
14
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
-
24
15
  var Hold = /*#__PURE__*/function () {
25
16
  function Hold() {
26
17
  var _this = this;
27
-
28
18
  _classCallCheck(this, Hold);
29
-
30
19
  this.isHolding = function () {
31
20
  return _this.holdConfig != null;
32
21
  };
33
-
34
22
  this.isWithinTolerance = function (_ref) {
35
23
  var x = _ref.x,
36
- y = _ref.y;
24
+ y = _ref.y;
37
25
  var moveTolerance = _this.holdConfig.moveTolerance;
38
26
  var dx = _this.startX - x;
39
27
  var dy = _this.startY - y;
40
28
  return Math.sqrt(dx * dx + dy * dy) < moveTolerance;
41
29
  };
42
-
43
30
  this.begin = function (defaultConfig, _ref2, _ref3) {
44
31
  var holdConfig = _ref2.holdConfig,
45
- noResume = _ref2.noResume,
46
- onHoldStart = _ref2.onHoldStart,
47
- onHoldEnd = _ref2.onHoldEnd,
48
- onHold = _ref2.onHold;
32
+ noResume = _ref2.noResume,
33
+ onHoldStart = _ref2.onHoldStart,
34
+ onHoldEnd = _ref2.onHoldEnd,
35
+ onHold = _ref2.onHold;
49
36
  var x = _ref3.x,
50
- y = _ref3.y;
37
+ y = _ref3.y;
51
38
  if (!onHoldStart && !onHold) return;
52
39
  _this.startX = x;
53
40
  _this.startY = y;
@@ -56,47 +43,41 @@ var Hold = /*#__PURE__*/function () {
56
43
  });
57
44
  _this.onHold = onHold;
58
45
  _this.onHoldStart = onHoldStart;
59
- _this.onHoldEnd = onHoldEnd; // copy the events array since it is mutated for each hold
46
+ _this.onHoldEnd = onHoldEnd;
60
47
 
48
+ // copy the events array since it is mutated for each hold
61
49
  _this.holdConfig.events = _this.holdConfig.events.slice();
62
-
63
50
  _this.holdConfig.events.sort(function (a, b) {
64
51
  if (a.time < b.time) return -1;
65
52
  if (a.time > b.time) return 1;
66
53
  return 0;
67
54
  });
68
-
69
55
  _this.pulsing = false;
70
56
  _this.next = _this.holdConfig.events.shift();
71
-
72
57
  if (_this.next) {
73
58
  _this.holdStart = window.performance.now();
74
-
75
59
  _this.startJob();
76
60
  }
77
61
  };
78
-
79
62
  this.updateProps = function (_ref4) {
80
63
  var onHoldStart = _ref4.onHoldStart,
81
- onHoldEnd = _ref4.onHoldEnd,
82
- onHold = _ref4.onHold;
64
+ onHoldEnd = _ref4.onHoldEnd,
65
+ onHold = _ref4.onHold;
83
66
  // check `isHolding` gesture is not in progress. Check if gesture exists before updating the references to the `holdConfig`
84
- if (!_this.isHolding()) return; // Update the original values with new values of the gestures
67
+ if (!_this.isHolding()) return;
85
68
 
69
+ // Update the original values with new values of the gestures
86
70
  _this.onHold = onHold;
87
71
  _this.onHoldStart = onHoldStart;
88
72
  _this.onHoldEnd = onHoldEnd;
89
73
  };
90
-
91
74
  this.move = function (coords) {
92
75
  if (!_this.isHolding()) return;
93
76
  var _this$holdConfig = _this.holdConfig,
94
- cancelOnMove = _this$holdConfig.cancelOnMove,
95
- resume = _this$holdConfig.resume;
96
-
77
+ cancelOnMove = _this$holdConfig.cancelOnMove,
78
+ resume = _this$holdConfig.resume;
97
79
  if (cancelOnMove) {
98
80
  var shouldEnd = !_this.isWithinTolerance(coords);
99
-
100
81
  if (shouldEnd) {
101
82
  if (resume) {
102
83
  _this.suspend();
@@ -108,96 +89,75 @@ var Hold = /*#__PURE__*/function () {
108
89
  }
109
90
  }
110
91
  };
111
-
112
92
  this.blur = function () {
113
93
  if (!_this.isHolding()) return;
114
-
115
94
  if (!_this.holdConfig.global) {
116
95
  _this.end();
117
96
  }
118
97
  };
119
-
120
98
  this.end = function () {
121
99
  if (!_this.isHolding()) return;
122
-
123
100
  if (_this.pulsing && _this.onHoldEnd) {
124
101
  var time = window.performance.now() - _this.holdStart;
125
-
126
102
  _this.onHoldEnd({
127
103
  type: 'onHoldEnd',
128
104
  time: time
129
105
  });
130
106
  }
131
-
132
107
  _this.suspend();
133
-
134
108
  _this.pulsing = false;
135
109
  _this.holdConfig = null;
136
110
  };
137
-
138
111
  this.enter = function () {
139
112
  if (!_this.isHolding()) return;
140
113
  var _this$holdConfig2 = _this.holdConfig,
141
- cancelOnMove = _this$holdConfig2.cancelOnMove,
142
- resume = _this$holdConfig2.resume;
143
-
114
+ cancelOnMove = _this$holdConfig2.cancelOnMove,
115
+ resume = _this$holdConfig2.resume;
144
116
  if (resume && !cancelOnMove) {
145
117
  _this.resume();
146
118
  }
147
119
  };
148
-
149
120
  this.leave = function () {
150
121
  if (!_this.isHolding()) return;
151
122
  var _this$holdConfig3 = _this.holdConfig,
152
- isGlobal = _this$holdConfig3.global,
153
- resume = _this$holdConfig3.resume;
123
+ isGlobal = _this$holdConfig3.global,
124
+ resume = _this$holdConfig3.resume;
154
125
  if (isGlobal) return;
155
-
156
126
  if (resume) {
157
127
  _this.suspend();
158
128
  } else {
159
129
  _this.end();
160
130
  }
161
131
  };
162
-
163
132
  this.suspend = function () {
164
133
  clearInterval(_this.holdJob);
165
134
  _this.holdJob = null;
166
135
  };
167
-
168
136
  this.resume = function () {
169
137
  if (_this.holdJob !== null) return;
170
-
171
138
  _this.handlePulse();
172
-
173
139
  _this.startJob();
174
140
  };
175
-
176
141
  this.handlePulse = function () {
177
142
  var holdTime = window.performance.now() - _this.holdStart;
178
-
179
143
  var n = _this.next;
180
-
181
144
  while (n && n.time <= holdTime) {
182
145
  var events = _this.holdConfig.events;
183
146
  _this.pulsing = true;
184
-
185
147
  if (_this.onHoldStart) {
186
148
  _this.onHoldStart(_objectSpread({
187
149
  type: 'onHoldStart'
188
150
  }, n));
189
- } // if the hold is canceled from the onHoldStart handler, we should bail early and prevent
190
- // additional hold/pulse events
191
-
151
+ }
192
152
 
153
+ // if the hold is canceled from the onHoldStart handler, we should bail early and prevent
154
+ // additional hold/pulse events
193
155
  if (!_this.isHolding()) {
194
156
  _this.pulsing = false;
195
157
  break;
196
158
  }
197
-
198
159
  n = _this.next = events && events.shift();
199
160
  }
200
-
201
161
  if (_this.pulsing) {
202
162
  if (_this.onHold) {
203
163
  _this.onHold({
@@ -207,27 +167,22 @@ var Hold = /*#__PURE__*/function () {
207
167
  }
208
168
  }
209
169
  };
210
-
211
170
  this.holdJob = null;
212
171
  this.holdStart = null;
213
172
  this.pulsing = false;
214
173
  this.next = null;
215
174
  }
216
-
217
175
  _createClass(Hold, [{
218
176
  key: "startJob",
219
177
  value: function startJob() {
220
178
  var frequency = this.holdConfig.frequency;
221
-
222
179
  if (!this.holdJob) {
223
180
  this.holdJob = setInterval(this.handlePulse, frequency);
224
181
  }
225
182
  }
226
183
  }]);
227
-
228
184
  return Hold;
229
185
  }();
230
-
231
186
  exports.Hold = Hold;
232
187
  var defaultHoldConfig = {
233
188
  cancelOnMove: false,
@@ -240,7 +195,6 @@ var defaultHoldConfig = {
240
195
  moveTolerance: 16
241
196
  };
242
197
  exports.defaultHoldConfig = defaultHoldConfig;
243
-
244
198
  var holdConfigPropType = _propTypes["default"].shape({
245
199
  cancelOnMove: _propTypes["default"].bool,
246
200
  events: _propTypes["default"].arrayOf(_propTypes["default"].shape({
@@ -251,7 +205,6 @@ var holdConfigPropType = _propTypes["default"].shape({
251
205
  global: _propTypes["default"].bool,
252
206
  moveTolerance: _propTypes["default"].number
253
207
  });
254
-
255
208
  exports.holdConfigPropType = holdConfigPropType;
256
209
  var _default = Hold;
257
210
  exports["default"] = _default;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pinchConfigPropType = exports.defaultPinchConfig = exports["default"] = exports.Pinch = void 0;
7
+ var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+ var Pinch = /*#__PURE__*/_createClass(function Pinch() {
17
+ var _this = this;
18
+ _classCallCheck(this, Pinch);
19
+ this.pinchConfig = null;
20
+ this.startScale = 1.0;
21
+ this.scale = 1.0;
22
+ this.isPinching = function () {
23
+ return _this.pinchConfig != null;
24
+ };
25
+ this.setContainerBounds = function (node) {
26
+ var _this$pinchConfig = _this.pinchConfig,
27
+ isGlobal = _this$pinchConfig.global,
28
+ boxSizing = _this$pinchConfig.boxSizing;
29
+ var bounds = null;
30
+ if (typeof window === 'undefined' || !node) return;
31
+ if (isGlobal) {
32
+ bounds = {
33
+ minX: 0,
34
+ minY: 0,
35
+ maxX: window.innerWidth,
36
+ maxY: window.innerHeight
37
+ };
38
+ } else {
39
+ bounds = node.getBoundingClientRect();
40
+
41
+ // adjust for padding when using content-box
42
+ if (boxSizing === 'content-box') {
43
+ var computedStyle = window.getComputedStyle(node);
44
+ bounds = {
45
+ minX: bounds.left + parseInt(computedStyle.paddingLeft),
46
+ minY: bounds.top + parseInt(computedStyle.paddingTop),
47
+ maxX: bounds.right - parseInt(computedStyle.paddingRight),
48
+ maxY: bounds.bottom - parseInt(computedStyle.paddingBottom)
49
+ };
50
+ } else {
51
+ bounds = {
52
+ minX: bounds.left,
53
+ minY: bounds.top,
54
+ maxX: bounds.right,
55
+ maxY: bounds.bottom
56
+ };
57
+ }
58
+ }
59
+ _this.bounds = bounds;
60
+ };
61
+ this.getBoundsCoords = function (_ref) {
62
+ var x = _ref.x,
63
+ y = _ref.y;
64
+ var _this$bounds = _this.bounds,
65
+ maxX = _this$bounds.maxX,
66
+ maxY = _this$bounds.maxY,
67
+ minX = _this$bounds.minX,
68
+ minY = _this$bounds.minY;
69
+ return {
70
+ x: (0, _clamp["default"])(minX, maxX, x) - minX,
71
+ y: (0, _clamp["default"])(minY, maxY, y) - minY
72
+ };
73
+ };
74
+ this.getDistance = function (coords) {
75
+ if (Array.isArray(coords)) {
76
+ var _this$getBoundsCoords = _this.getBoundsCoords(coords[0]),
77
+ x1 = _this$getBoundsCoords.x,
78
+ y1 = _this$getBoundsCoords.y;
79
+ var _this$getBoundsCoords2 = _this.getBoundsCoords(coords[1]),
80
+ x2 = _this$getBoundsCoords2.x,
81
+ y2 = _this$getBoundsCoords2.y;
82
+ var dx = x1 - x2;
83
+ var dy = y1 - y2;
84
+ return Math.sqrt(dx * dx + dy * dy);
85
+ }
86
+ return 0;
87
+ };
88
+ this.updateScale = function (scale) {
89
+ var _this$pinchConfig2 = _this.pinchConfig,
90
+ maxScale = _this$pinchConfig2.maxScale,
91
+ minScale = _this$pinchConfig2.minScale;
92
+ var newScale = (0, _clamp["default"])(minScale, maxScale, scale);
93
+ if (newScale !== _this.scale) {
94
+ _this.scale = newScale;
95
+ return true;
96
+ }
97
+ return false;
98
+ };
99
+ this.begin = function (config, _ref2, coords, node) {
100
+ var noResume = _ref2.noResume,
101
+ onPinch = _ref2.onPinch,
102
+ onPinchEnd = _ref2.onPinchEnd,
103
+ onPinchStart = _ref2.onPinchStart;
104
+ if (!onPinch && !onPinchStart && !onPinchEnd) {
105
+ return;
106
+ }
107
+ _this.pinchConfig = _objectSpread(_objectSpread({}, config), {}, {
108
+ node: node,
109
+ resume: !noResume
110
+ });
111
+ _this.setContainerBounds(node);
112
+ _this.startDist = _this.getDistance(coords);
113
+ _this.previousDist = _this.startDist;
114
+ _this.startScale = _this.scale;
115
+ _this.onPinch = onPinch;
116
+ _this.onPinchStart = onPinchStart;
117
+ _this.onPinchEnd = onPinchEnd;
118
+ if (_this.onPinchStart) {
119
+ _this.onPinchStart({
120
+ type: 'onPinchStart',
121
+ coords: coords
122
+ });
123
+ }
124
+ };
125
+ this.updateProps = function (_ref3) {
126
+ var onPinch = _ref3.onPinch,
127
+ onPinchEnd = _ref3.onPinchEnd,
128
+ onPinchStart = _ref3.onPinchStart;
129
+ // Check `isPinching` gesture is not in progress. Check if gesture exists before updating the references to the `pinchConfig`
130
+ if (!_this.isPinching()) return;
131
+
132
+ // This will update the `pinchConfig` with the new value
133
+ _this.onPinch = onPinch;
134
+ _this.onPinchStart = onPinchStart;
135
+ _this.onPinchEnd = onPinchEnd;
136
+ };
137
+ this.move = function (coords) {
138
+ if (!_this.isPinching()) return;
139
+ var moveTolerance = _this.pinchConfig.moveTolerance;
140
+ var currentDist = _this.getDistance(coords);
141
+ var scale = currentDist / _this.startDist * _this.startScale;
142
+ if (Math.abs(_this.previousDist - currentDist) > moveTolerance && _this.onPinch && _this.updateScale(scale)) {
143
+ _this.onPinch({
144
+ type: 'onPinch',
145
+ scale: _this.scale,
146
+ coords: coords
147
+ });
148
+ _this.previousDist = currentDist;
149
+ }
150
+ };
151
+ this.blur = function () {
152
+ if (!_this.isPinching()) return;
153
+ if (!_this.pinchConfig.global) {
154
+ _this.end();
155
+ }
156
+ };
157
+ this.end = function () {
158
+ if (!_this.isPinching()) return;
159
+ if (_this.onPinchEnd) {
160
+ _this.onPinchEnd({
161
+ type: 'onPinchEnd'
162
+ });
163
+ }
164
+ _this.pinchConfig = null;
165
+ };
166
+ });
167
+ exports.Pinch = Pinch;
168
+ var defaultPinchConfig = {
169
+ boxSizing: 'border-box',
170
+ global: false,
171
+ maxScale: 4,
172
+ minScale: 0.5,
173
+ moveTolerance: 16
174
+ };
175
+ exports.defaultPinchConfig = defaultPinchConfig;
176
+ var pinchConfigPropType = _propTypes["default"].shape({
177
+ boxSizing: _propTypes["default"].string,
178
+ global: _propTypes["default"].bool,
179
+ maxScale: _propTypes["default"].number,
180
+ minScale: _propTypes["default"].number,
181
+ moveTolerance: _propTypes["default"].number
182
+ });
183
+ exports.pinchConfigPropType = pinchConfigPropType;
184
+ var _default = Pinch;
185
+ exports["default"] = _default;