@gympass/yoga-common
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -12,18 +12,83 @@ "use strict"; | ||
/** | ||
* Elevation function | ||
* | ||
* @param {String} color=#000 - Color to elevate | ||
* @param {Number} level - Elevation level. It must be between 0 and 4 | ||
* @returns {String} | ||
*/ | ||
function elevate() { | ||
var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '#000'; | ||
var level = arguments.length > 1 ? arguments[1] : undefined; | ||
var normalizedColor = (0, _hexToRgb["default"])(color, 0.25); | ||
var all = ['none', "0 2px 6px ".concat(normalizedColor), "0 4px 12px ".concat(normalizedColor), "0 8px 20px ".concat(normalizedColor)]; | ||
return level ? all[level] : all; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
// values from | ||
// https://github.com/material-components/material-components-web/blob/master/packages/mdc-elevation/_elevation-theme.scss | ||
var UMBRA_OPACITY = 0.2; | ||
var PENUMBRA_OPACITY = 0.14; | ||
var AMBIENT_OPACITY = 0.12; | ||
var umbra = ['0 2px 4px -1px', '0 5px 5px -3px', '0 7px 8px -4px']; | ||
var penumbra = ['0 4px 5px 0px', '0 8px 10px 1px', '0 12px 17px 2px']; | ||
var ambient = ['0 1px 10px 0px', '0 3px 14px 2px', '0 5px 22px 4px']; | ||
function sanitizeShadow(_ref) { | ||
var shadow = _ref.shadow, | ||
spread = _ref.spread; | ||
if (!spread) { | ||
var values = shadow.split(' '); | ||
return _toConsumableArray(values.slice(0, values.length - 1)).join(' '); | ||
} | ||
return shadow; | ||
} | ||
function createShadow(_ref2) { | ||
var level = _ref2.level, | ||
color = _ref2.color, | ||
depth = _ref2.depth, | ||
spread = _ref2.spread; | ||
var shadows = ["".concat(sanitizeShadow({ | ||
shadow: umbra[level], | ||
spread: spread | ||
}), " ").concat((0, _hexToRgb["default"])(color, UMBRA_OPACITY)), "".concat(sanitizeShadow({ | ||
shadow: penumbra[level], | ||
spread: spread | ||
}), " ").concat((0, _hexToRgb["default"])(color, PENUMBRA_OPACITY)), "".concat(sanitizeShadow({ | ||
shadow: ambient[level], | ||
spread: spread | ||
}), " ").concat((0, _hexToRgb["default"])(color, AMBIENT_OPACITY))]; | ||
return shadows.slice(0, depth).join(); | ||
} | ||
function elevate(_ref3) { | ||
var _ref3$color = _ref3.color, | ||
color = _ref3$color === void 0 ? '#000' : _ref3$color, | ||
level = _ref3.level, | ||
_ref3$depth = _ref3.depth, | ||
depth = _ref3$depth === void 0 ? 3 : _ref3$depth, | ||
_ref3$spread = _ref3.spread, | ||
spread = _ref3$spread === void 0 ? true : _ref3$spread, | ||
_ref3$fallback = _ref3.fallback, | ||
fallback = _ref3$fallback === void 0 ? true : _ref3$fallback; | ||
var all = [fallback ? '0 0 0 rgba(0, 0, 0, 0)' : 'none', createShadow({ | ||
level: 0, | ||
color: color, | ||
depth: depth, | ||
spread: spread | ||
}), createShadow({ | ||
level: 1, | ||
color: color, | ||
depth: depth, | ||
spread: spread | ||
}), createShadow({ | ||
level: 2, | ||
color: color, | ||
depth: depth, | ||
spread: spread | ||
})]; | ||
return all[level] || all; | ||
} | ||
var _default = elevate; | ||
exports["default"] = _default; |
@@ -10,3 +10,3 @@ "use strict"; | ||
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 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; } | ||
@@ -13,0 +13,0 @@ 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; } |
@@ -1,18 +0,82 @@ | ||
import hexToRgb from './hexToRgb'; | ||
/** | ||
* Elevation function | ||
* | ||
* @param {String} color=#000 - Color to elevate | ||
* @param {Number} level - Elevation level. It must be between 0 and 4 | ||
* @returns {String} | ||
*/ | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function elevate() { | ||
var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '#000'; | ||
var level = arguments.length > 1 ? arguments[1] : undefined; | ||
var normalizedColor = hexToRgb(color, 0.25); | ||
var all = ['none', "0 2px 6px ".concat(normalizedColor), "0 4px 12px ".concat(normalizedColor), "0 8px 20px ".concat(normalizedColor)]; | ||
return level ? all[level] : all; | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
import hexToRgb from './hexToRgb'; // values from | ||
// https://github.com/material-components/material-components-web/blob/master/packages/mdc-elevation/_elevation-theme.scss | ||
var UMBRA_OPACITY = 0.2; | ||
var PENUMBRA_OPACITY = 0.14; | ||
var AMBIENT_OPACITY = 0.12; | ||
var umbra = ['0 2px 4px -1px', '0 5px 5px -3px', '0 7px 8px -4px']; | ||
var penumbra = ['0 4px 5px 0px', '0 8px 10px 1px', '0 12px 17px 2px']; | ||
var ambient = ['0 1px 10px 0px', '0 3px 14px 2px', '0 5px 22px 4px']; | ||
function sanitizeShadow(_ref) { | ||
var shadow = _ref.shadow, | ||
spread = _ref.spread; | ||
if (!spread) { | ||
var values = shadow.split(' '); | ||
return _toConsumableArray(values.slice(0, values.length - 1)).join(' '); | ||
} | ||
return shadow; | ||
} | ||
function createShadow(_ref2) { | ||
var level = _ref2.level, | ||
color = _ref2.color, | ||
depth = _ref2.depth, | ||
spread = _ref2.spread; | ||
var shadows = ["".concat(sanitizeShadow({ | ||
shadow: umbra[level], | ||
spread: spread | ||
}), " ").concat(hexToRgb(color, UMBRA_OPACITY)), "".concat(sanitizeShadow({ | ||
shadow: penumbra[level], | ||
spread: spread | ||
}), " ").concat(hexToRgb(color, PENUMBRA_OPACITY)), "".concat(sanitizeShadow({ | ||
shadow: ambient[level], | ||
spread: spread | ||
}), " ").concat(hexToRgb(color, AMBIENT_OPACITY))]; | ||
return shadows.slice(0, depth).join(); | ||
} | ||
function elevate(_ref3) { | ||
var _ref3$color = _ref3.color, | ||
color = _ref3$color === void 0 ? '#000' : _ref3$color, | ||
level = _ref3.level, | ||
_ref3$depth = _ref3.depth, | ||
depth = _ref3$depth === void 0 ? 3 : _ref3$depth, | ||
_ref3$spread = _ref3.spread, | ||
spread = _ref3$spread === void 0 ? true : _ref3$spread, | ||
_ref3$fallback = _ref3.fallback, | ||
fallback = _ref3$fallback === void 0 ? true : _ref3$fallback; | ||
var all = [fallback ? '0 0 0 rgba(0, 0, 0, 0)' : 'none', createShadow({ | ||
level: 0, | ||
color: color, | ||
depth: depth, | ||
spread: spread | ||
}), createShadow({ | ||
level: 1, | ||
color: color, | ||
depth: depth, | ||
spread: spread | ||
}), createShadow({ | ||
level: 2, | ||
color: color, | ||
depth: depth, | ||
spread: spread | ||
})]; | ||
return all[level] || all; | ||
} | ||
export default elevate; |
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
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 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; } | ||
@@ -5,0 +5,0 @@ 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; } |
{ | ||
"name": "@gympass/yoga-common", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Shared resources between packages", | ||
@@ -19,5 +19,5 @@ "homepage": "https://github.com/Gympass/yoga", | ||
}, | ||
"gitHead": "ddf0d7d5639ed289510c9a9f36937f8ede16e553", | ||
"gitHead": "eb37abf10df25e2b773c425706ba48fd153b847c", | ||
"module": "./esm", | ||
"private": false | ||
} |
14800
244