UNPKG

zeplin-extension-style-kit

Version:

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

104 lines (82 loc) 3.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _constants = require("../constants"); 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; } var INDENTATION = " "; var VARIABLE_FORMAT = { format: "woff2-variations", ext: "woff2" }; var FORMATS = [{ format: "woff2", ext: "woff2" }, { format: "woff", ext: "woff" }, { format: "truetype", ext: "ttf" }]; var FontSrc = /*#__PURE__*/function () { function FontSrc(fontFace) { var variable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; _classCallCheck(this, FontSrc); this.fontFace = fontFace; this.variable = variable; } _createClass(FontSrc, [{ key: "equals", value: function equals(other) { return this.fontFace === other.fontFace; } }, { key: "hasDefaultValue", value: function hasDefaultValue() { return this.fontFace === FontSrc.DEFAULT_VALUE; } }, { key: "getValue", value: function getValue() { var _this = this; if (this.hasDefaultValue()) { return FontSrc.DEFAULT_VALUE; } var joiner = ",\n".concat(INDENTATION.repeat(2)); var sources = ["local(".concat(this.fontFace, ")")]; if (this.variable) { sources.push("url(/path/to/".concat(this.fontFace, ".").concat(VARIABLE_FORMAT.ext, ") format(\"").concat(VARIABLE_FORMAT.format, "\")")); } else { sources.push.apply(sources, _toConsumableArray(FORMATS.map(function (_ref) { var ext = _ref.ext, format = _ref.format; return "url(/path/to/".concat(_this.fontFace, ".").concat(ext, ") format(\"").concat(format, "\")"); }))); } return sources.join(joiner); } }, { key: "name", get: function get() { return _constants.STYLE_PROPS.FONT_SRC; } }], [{ key: "DEFAULT_VALUE", get: function get() { return ""; } }]); return FontSrc; }(); var _default = FontSrc; exports.default = _default;