123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 'use strict';
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(function () {
- var booleanProperties = ['weight', 'style'];
- var suffixToPart = {
- 'size': 'fontSize',
- 'family': 'font',
- 'weight': 'bold',
- 'style': 'italic'
- };
- var PropertiesHelper = function () {
- function PropertiesHelper() {
- _classCallCheck(this, PropertiesHelper);
- }
- PropertiesHelper.buildVidaFontPropertiesFromParts = function buildVidaFontPropertiesFromParts(VIPRUtils, fontChanges, currentFontProperty) {
- var vidaFont = {
- 'family': [],
- 'size': null,
- 'style': null,
- 'weight': null
- };
- var parsedCurrentVidaFontProperty = currentFontProperty;
- if (typeof currentFontProperty === 'string') {
- parsedCurrentVidaFontProperty = VIPRUtils.parseVidaFontProperty(currentFontProperty);
- }
- parsedCurrentVidaFontProperty = parsedCurrentVidaFontProperty ? parsedCurrentVidaFontProperty : vidaFont;
- for (var fontPart in parsedCurrentVidaFontProperty) {
- if (parsedCurrentVidaFontProperty.hasOwnProperty(fontPart)) {
- var part = suffixToPart[fontPart];
- //the steps to apply the value: 1) If changed states is valid, apply it;2)Then override the missing values from old property value;3) If changed states is null, apply null
- if (booleanProperties.indexOf(fontPart) !== -1) {
- if (fontChanges[part]) {
- vidaFont[fontPart] = part;
- } else if (typeof fontChanges[part] === 'undefined' && parsedCurrentVidaFontProperty[fontPart]) {
- vidaFont[fontPart] = parsedCurrentVidaFontProperty[fontPart].toString();
- }
- } else if (Array.isArray(vidaFont[fontPart])) {
- //in text toolbar, we only supports one family option at one time, so the array length is no more than 1
- vidaFont[fontPart].length = 0;
- if (fontChanges[part]) {
- vidaFont[fontPart].push(fontChanges[part]);
- } else if (typeof fontChanges[part] === 'undefined' && parsedCurrentVidaFontProperty[fontPart].length) {
- vidaFont[fontPart].push(parsedCurrentVidaFontProperty[fontPart][0].toString());
- }
- } else {
- if (fontChanges[part]) {
- vidaFont[fontPart] = fontChanges[part];
- } else if (typeof fontChanges[part] === 'undefined' && parsedCurrentVidaFontProperty[fontPart]) {
- vidaFont[fontPart] = parsedCurrentVidaFontProperty[fontPart].toString();
- }
- }
- }
- }
- var vidaFontValues = Object.keys(vidaFont).map(function (fontPart) {
- return vidaFont[fontPart];
- });
- var vidaFontProperty = VIPRUtils.createVidaFontProperty(vidaFontValues);
- //vida does not accept empty string, need to convert the empty string to null value
- var vidaFontString = vidaFontProperty && vidaFontProperty.toString ? vidaFontProperty.toString() : null;
- var propertyValueToApply = vidaFontString === '' ? null : vidaFontString;
- return propertyValueToApply;
- };
- PropertiesHelper.getVidaFontPropertiesPart = function getVidaFontPropertiesPart(VIPRUtils, part, fontPropertyValue) {
- var vidaFontValue = fontPropertyValue;
- if (typeof fontPropertyValue === 'string') {
- vidaFontValue = VIPRUtils.parseVidaFontProperty(fontPropertyValue);
- }
- var fontPropValue = vidaFontValue && vidaFontValue[part] ? vidaFontValue[part] : null;
- var isBooleanProperty = booleanProperties.indexOf(part) !== -1;
- if (fontPropValue) {
- if (isBooleanProperty) {
- return true;
- } else if (part === 'size' && (typeof fontPropValue === 'undefined' ? 'undefined' : _typeof(fontPropValue)) === 'object') {
- var fontvalue = fontPropValue['value'].toString() + fontPropValue['unit'].toString();
- return fontvalue;
- } else {
- return fontPropValue.toString();
- }
- } else {
- return isBooleanProperty ? false : null;
- }
- };
- PropertiesHelper.splitEscapedString = function splitEscapedString(input, delimiter, outputs) {
- var index = input.indexOf(delimiter);
- if (index !== -1 && index !== input.length && input[index - 1] !== '\\') {
- var result = input.slice(0, index);
- input = input.slice(index + 1, input.length);
- outputs.push(result);
- PropertiesHelper.splitEscapedString(input, delimiter, outputs);
- } else {
- outputs.push(input);
- }
- };
- return PropertiesHelper;
- }();
- return PropertiesHelper;
- });
- //# sourceMappingURL=PropertiesHelper.js.map
|