zp-figma-converter
Version:
Convert Figma designs to various code formats
76 lines • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextFieldParser = void 0;
const xml_utils_1 = require("../../../../utils/xml-utils");
const widget_parser_1 = require("./widget-parser");
/**
* Parser for TextFieldData
*/
class TextFieldParser extends widget_parser_1.WidgetParser {
parse(nodeData) {
const result = this.parseBaseAttributes(nodeData);
// TextField specific properties
if (nodeData.TouchEnable !== undefined)
result['@_TouchEnable'] = (0, xml_utils_1.boolToString)(nodeData.TouchEnable);
if (nodeData.FontSize !== undefined)
result['@_FontSize'] = (0, xml_utils_1.toString)(nodeData.FontSize);
if (nodeData.IsCustomSize !== undefined)
result['@_IsCustomSize'] = (0, xml_utils_1.boolToString)(nodeData.IsCustomSize);
if (nodeData.LabelText !== undefined)
result['@_LabelText'] = nodeData.LabelText;
if (nodeData.PlaceHolderText !== undefined)
result['@_PlaceHolderText'] = nodeData.PlaceHolderText;
if (nodeData.MaxLengthEnable !== undefined)
result['@_MaxLengthEnable'] = (0, xml_utils_1.boolToString)(nodeData.MaxLengthEnable);
if (nodeData.MaxLengthText !== undefined)
result['@_MaxLengthText'] = (0, xml_utils_1.toString)(nodeData.MaxLengthText);
if (nodeData.PasswordEnable !== undefined)
result['@_PasswordEnable'] = (0, xml_utils_1.boolToString)(nodeData.PasswordEnable);
if (nodeData.FontResource) {
result.FontResource = {
'@_Type': nodeData.FontResource.Type,
'@_Path': nodeData.FontResource.Path,
'@_Plist': nodeData.FontResource.Plist
};
}
if (nodeData.TextColor) {
result.TextColor = {
'@_A': '255',
'@_R': (0, xml_utils_1.toString)(nodeData.TextColor.R || 255),
'@_G': (0, xml_utils_1.toString)(nodeData.TextColor.G || 255),
'@_B': (0, xml_utils_1.toString)(nodeData.TextColor.B || 255)
};
}
if (nodeData.PlaceHolderColor) {
result.PlaceHolderColor = {
'@_A': '255',
'@_R': (0, xml_utils_1.toString)(nodeData.PlaceHolderColor.R || 150),
'@_G': (0, xml_utils_1.toString)(nodeData.PlaceHolderColor.G || 150),
'@_B': (0, xml_utils_1.toString)(nodeData.PlaceHolderColor.B || 150)
};
}
if (nodeData.OutlineEnabled !== undefined)
result['@_OutlineEnabled'] = (0, xml_utils_1.boolToString)(nodeData.OutlineEnabled);
if (nodeData.OutlineColor) {
result.OutlineColor = {
'@_A': '255',
'@_R': '255',
'@_G': (0, xml_utils_1.toString)(nodeData.OutlineColor.G || 0),
'@_B': (0, xml_utils_1.toString)(nodeData.OutlineColor.B || 0)
};
}
if (nodeData.ShadowEnabled !== undefined)
result['@_ShadowEnabled'] = (0, xml_utils_1.boolToString)(nodeData.ShadowEnabled);
if (nodeData.ShadowColor) {
result.ShadowColor = {
'@_A': '255',
'@_R': (0, xml_utils_1.toString)(nodeData.ShadowColor.R || 110),
'@_G': (0, xml_utils_1.toString)(nodeData.ShadowColor.G || 110),
'@_B': (0, xml_utils_1.toString)(nodeData.ShadowColor.B || 110)
};
}
return result;
}
}
exports.TextFieldParser = TextFieldParser;
//# sourceMappingURL=text-field-parser.js.map