zeplin-extension-style-kit
Version:
Models and utilities to generate CSS-like style code in Zeplin extensions.
102 lines (81 loc) • 4.47 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _angle = _interopRequireDefault(require("../angle"));
var _angularColorStop = _interopRequireDefault(require("./angularColorStop"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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" && Symbol.iterator in Object(iter)) 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; }
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; }
/**
* In math and design tools 0deg corresponds to the angle in east
* whereas in CSS it is the angle in north.
*/
var CSS_ANGLE_DIFFERENCE = 0.25;
var ConicGradient = /*#__PURE__*/function () {
function ConicGradient(colorStops) {
_classCallCheck(this, ConicGradient);
var sortedColorStops = _toConsumableArray(colorStops).sort(function (_ref, _ref2) {
var a = _ref.position;
var b = _ref2.position;
return a - b;
});
var firstPosition = sortedColorStops[0].position;
this.from = firstPosition + CSS_ANGLE_DIFFERENCE;
this.colorStops = sortedColorStops.map(function (_ref3) {
var color = _ref3.color,
position = _ref3.position;
return new _angularColorStop.default({
color,
position: position - firstPosition
});
});
if (sortedColorStops[sortedColorStops.length - 1].position !== 1) {
this.colorStops.push(new _angularColorStop.default({
position: 1,
color: sortedColorStops[0].color
}));
}
}
_createClass(ConicGradient, [{
key: "valueOf",
value: function valueOf() {
var center = this.center,
colorStops = this.colorStops;
return "conicGradient::cx:".concat(center.x, ":cy:").concat(center.y, ":").concat(colorStops.map(function (cs) {
return cs.valueOf();
}).join(":"));
}
}, {
key: "equals",
value: function equals(other) {
return this.center.x === other.center.x && this.center.y === other.center.y && this.colorStops.length === other.colorStops.length && this.colorStops.every(function (cs, index) {
return cs.equals(other.colorStops[index]);
});
}
}, {
key: "toStyleValue",
value: function toStyleValue(_ref4, variables) {
var colorFormat = _ref4.colorFormat;
var from = this.from,
colorStops = this.colorStops;
var colorStopStyle = colorStops.map(function (cs) {
return cs.toStyleValue({
colorFormat
}, variables);
}).join(", ");
return "conic-gradient(from ".concat(new _angle.default(from, "turn").toStyleValue(), ", ").concat(colorStopStyle, ")");
}
}]);
return ConicGradient;
}();
var _default = ConicGradient;
exports.default = _default;
;