@onepercentio/one-ui 0.20.0 → 0.20.2

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.
@@ -57,4 +57,9 @@ export default function useHero(id: string, options?: Partial<{
57
57
  getHerosOnScreen: () => HTMLDivElement[];
58
58
  trigger: () => void;
59
59
  };
60
+ declare type EVENTS_INTERFACE = Parameters<typeof useHero>[2];
61
+ declare type TRANSITION_TYPES = "ACCELERATION";
62
+ export declare const TRANSITION_FACTORY: {
63
+ [n in TRANSITION_TYPES]: (events?: EVENTS_INTERFACE) => EVENTS_INTERFACE;
64
+ };
60
65
  export {};
@@ -1,12 +1,20 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
7
+ exports.TRANSITION_FACTORY = void 0;
6
8
  exports.default = useHero;
7
9
  var _react = require("react");
8
10
  var _ownEvent = _interopRequireDefault(require("../utils/ownEvent"));
11
+ var _useHeroModule = _interopRequireDefault(require("./useHero.module.scss"));
9
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ 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; }
14
+ 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
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
18
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
19
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
20
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
@@ -138,7 +146,7 @@ function useHero(id) {
138
146
  /** Set the clone over the new position */
139
147
  const willMove = setCloneToCoordinatesOf(el);
140
148
  if (!willMove) cleanup();else {
141
- for (let propToTransition of propsToTransition) clone.style[propToTransition] = el.style[propToTransition];
149
+ for (let propToTransition of propsToTransition) clone.style[propToTransition] = window.getComputedStyle(el)[propToTransition];
142
150
  const transitionEndCb = (0, _ownEvent.default)(function (_ref3) {
143
151
  let target = _ref3.target,
144
152
  currentTarget = _ref3.currentTarget;
@@ -181,4 +189,35 @@ function isElementOutsideContainer(container, coordinates) {
181
189
  const elementUnderflowsViewport = containerBounds.left - coordinates.left >= coordinates.width || containerBounds.top - coordinates.top >= coordinates.height;
182
190
  return elementUnderflowsViewport || elementOverflowsViewport;
183
191
  }
184
- }
192
+ }
193
+ function centerPoint(rect) {
194
+ return [rect.left + rect.width / 2, rect.top + rect.height / 2];
195
+ }
196
+ const angle = function angle(pointA, pointB) {
197
+ return Number((Math.atan2(pointA[1] - pointB[1], pointA[0] - pointB[0]) * (179.08 / Math.PI)).toFixed(5));
198
+ };
199
+ const TRANSITION_FACTORY = {
200
+ ACCELERATION: function ACCELERATION(events) {
201
+ return _objectSpread(_objectSpread({}, events), {}, {
202
+ onHeroStart: function onHeroStart(clone, origin, target) {
203
+ if (events !== null && events !== void 0 && events.onHeroStart) events.onHeroStart(clone, origin, target);
204
+ clone.classList.add(_useHeroModule.default.acceleration);
205
+ const centerPointOrigin = centerPoint(origin.getBoundingClientRect());
206
+ const centerPointDestination = centerPoint(target.getBoundingClientRect());
207
+ const angleBetweenElements = angle(centerPointOrigin, centerPointDestination);
208
+ const vectorX = Math.sin(angleBetweenElements);
209
+ const vectorY = Math.cos(angleBetweenElements);
210
+ const rotateY = (10 * vectorY).toFixed(0);
211
+ const originX = (vectorY + 1) * 50;
212
+ const rotateX = -(10 * vectorX).toFixed(0);
213
+ const originY = (vectorX + 1) * 50;
214
+ clone.style.setProperty("--stage-1", "rotateY(".concat(rotateY, "deg) rotateX(").concat(-rotateX, "deg)"));
215
+ clone.style.setProperty("--stage-2", "rotateY(".concat(-rotateY * 0.3, "deg) rotateX(").concat(rotateX * 0.3, "deg)"));
216
+ clone.style.setProperty("--origin-1", "".concat(originX, "% ").concat(originY, "%"));
217
+ clone.style.setProperty("--origin-2", "".concat(100 - originX, "% ").concat(100 - originY, "%"));
218
+ document.body.style.perspective = "100vw";
219
+ }
220
+ });
221
+ }
222
+ };
223
+ exports.TRANSITION_FACTORY = TRANSITION_FACTORY;
@@ -0,0 +1,33 @@
1
+ $timing: cubic-bezier(0.5, -0.45, 0.44, 1.37);
2
+ // $timing: cubic-bezier(0.73, -0.49, 0.16, 1.4);
3
+
4
+ .acceleration {
5
+ --animation--speed-fast: 1s;
6
+ animation-name: acceleration;
7
+ animation-duration: var(--animation--speed-fast);
8
+ animation-timing-function: $timing;
9
+ transition-timing-function: $timing !important;
10
+ transform-origin: var(--origin-1);
11
+ }
12
+
13
+ @keyframes acceleration {
14
+ 0% {
15
+ transform: rotateY(0deg);
16
+ }
17
+ 10% {
18
+ transform-origin: var(--origin-1);
19
+ transform: var(--stage-1);
20
+ }
21
+
22
+ 70% {
23
+ transform: var(--stage-1);
24
+ transform-origin: var(--origin-1);
25
+ }
26
+ 85% {
27
+ transform-origin: var(--origin-2);
28
+ transform: var(--stage-2);
29
+ }
30
+ 100% {
31
+ transform: rotateY(0deg);
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onepercentio/one-ui",
3
- "version": "0.20.0",
3
+ "version": "0.20.2",
4
4
  "description": "A set of reusable components created through the development of Onepercent projects",
5
5
  "repository": "git@github.com:onepercentio/one-ui.git",
6
6
  "author": "Murilo Oliveira de Araujo <murilo.araujo@onepercent.io>",