UNPKG

zeplin-extension-style-kit

Version:

Models and utilities to generate CSS-like style code in Zeplin extensions.

75 lines (61 loc) 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _color = _interopRequireDefault(require("../color")); var _percent = _interopRequireDefault(require("../percent")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var LinearColorStop = /*#__PURE__*/function () { /** * LinearColorStop constructor * * @param {object} colorStopObject Color stop object, with color stop color and position */ // eslint-disable-next-line max-params function LinearColorStop(colorStopObject) { _classCallCheck(this, LinearColorStop); var color = colorStopObject.color, position = colorStopObject.position; this.color = color; this.position = position; } _createClass(LinearColorStop, [{ key: "valueOf", value: function valueOf() { var position = this.position, _this$color = this.color, r = _this$color.r, g = _this$color.g, b = _this$color.b, _this$color$a = _this$color.a, a = _this$color$a === void 0 ? 1 : _this$color$a; return "linearColorStop::p:".concat(position, ":r:").concat(r, ":g:").concat(g, ":b:").concat(b, ":a:").concat(a); } }, { key: "equals", value: function equals(other) { return this.position === other.position && this.color.equals(other.color); } }, { key: "toStyleValue", value: function toStyleValue(_ref, variables) { var colorFormat = _ref.colorFormat; var position = this.position, color = this.color; var stopColor = new _color.default(color).toStyleValue({ colorFormat }, variables); if (!position || position === 1) { return stopColor; } return "".concat(stopColor, " ").concat(new _percent.default(position).toStyleValue()); } }]); return LinearColorStop; }(); var _default = LinearColorStop; exports.default = _default;