wix-style-react
Version:
81 lines (68 loc) • 3.31 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _regeneratorRuntime from "@babel/runtime/regenerator";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { baseUniDriverFactory } from '../../test/utils/unidriver';
export var proportionDriverFactory = function proportionDriverFactory(base) {
var byHook = function byHook(dataHook) {
return base.$("[data-hook=\"".concat(dataHook, "\"]"));
};
return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, {
/**
* Gets the component's aspect ratio
* @returns {Promise<number>}
*/
getAspectRatio: function () {
var _getAspectRatio = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var width, height;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return base.attr('offsetWidth');
case 2:
width = _context.sent;
_context.next = 5;
return base.attr('offsetHeight');
case 5:
height = _context.sent;
return _context.abrupt("return", width / height);
case 7:
case "end":
return _context.stop();
}
}
}, _callee);
}));
function getAspectRatio() {
return _getAspectRatio.apply(this, arguments);
}
return getAspectRatio;
}(),
/**
* Checks whether aspect ratio is disabled
* @returns {Promise<boolean>}
*/
isAspectRatioDisabled: function () {
var _isAspectRatioDisabled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
return _context2.abrupt("return", byHook('proportion-aspect').exists());
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
function isAspectRatioDisabled() {
return _isAspectRatioDisabled.apply(this, arguments);
}
return isAspectRatioDisabled;
}()
});
};