zp-figma-converter
Version:
Convert Figma designs to various code formats
89 lines • 4.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ButtonParser = void 0;
const xml_utils_1 = require("../../../../utils/xml-utils");
const widget_parser_1 = require("./widget-parser");
/**
* Parser for ButtonData
*/
class ButtonParser extends widget_parser_1.WidgetParser {
parse(nodeData) {
const result = this.parseBaseAttributes(nodeData);
// Button 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.ButtonText !== undefined)
result['@_ButtonText'] = nodeData.ButtonText;
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.DisabledFileData) {
result.DisabledFileData = {
'@_Type': nodeData.DisabledFileData.Type,
'@_Path': nodeData.DisabledFileData.Path,
'@_Plist': nodeData.DisabledFileData.Plist
};
}
if (nodeData.PressedFileData) {
result.PressedFileData = {
'@_Type': nodeData.PressedFileData.Type,
'@_Path': nodeData.PressedFileData.Path,
'@_Plist': nodeData.PressedFileData.Plist
};
}
if (nodeData.NormalFileData) {
result.NormalFileData = {
'@_Type': nodeData.NormalFileData.Type,
'@_Path': nodeData.NormalFileData.Path,
'@_Plist': nodeData.NormalFileData.Plist
};
}
if (nodeData.Scale9Enable !== undefined)
result['@_Scale9Enable'] = (0, xml_utils_1.boolToString)(nodeData.Scale9Enable);
if (nodeData.Scale9OriginX !== undefined)
result['@_Scale9OriginX'] = (0, xml_utils_1.toString)(nodeData.Scale9OriginX);
if (nodeData.Scale9OriginY !== undefined)
result['@_Scale9OriginY'] = (0, xml_utils_1.toString)(nodeData.Scale9OriginY);
if (nodeData.Scale9Width !== undefined)
result['@_Scale9Width'] = (0, xml_utils_1.toString)(nodeData.Scale9Width);
if (nodeData.Scale9Height !== undefined)
result['@_Scale9Height'] = (0, xml_utils_1.toString)(nodeData.Scale9Height);
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.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)
};
}
if (nodeData.ShadowOffsetX !== undefined)
result['@_ShadowOffsetX'] = (0, xml_utils_1.toString)(nodeData.ShadowOffsetX);
if (nodeData.ShadowOffsetY !== undefined)
result['@_ShadowOffsetY'] = (0, xml_utils_1.toString)(nodeData.ShadowOffsetY);
return result;
}
}
exports.ButtonParser = ButtonParser;
//# sourceMappingURL=button-parser.js.map