// // KMAliasLightParser.swift // Cisdem PDFMaster // // Created by wanjun on 2022/12/21. // import Cocoa class KMAliasLightParser: KMBaseParser { func startParse() -> KMAliasLight { self.fileName = "alias-light" self.fileType = "json" return aliasLightParser(self.jsonParser) } func aliasLightParser(_ jsonData: [String: Any]) -> KMAliasLight { let data = jsonData let allKey = data.keys let aliasLightModel = KMAliasLight.init() if allKey.contains("spacing") { aliasLightModel.spacing = ["spacing" : spacingNodeParser((data["spacing"] as! [String : Any]))] } if allKey.contains("color") { aliasLightModel.color = ["color" : colorNodeParser((data["color"] as! [String : Any]))] } if allKey.contains("radius") { aliasLightModel.radius = ["radius" : radiusNodeParser((data["radius"] as! [String : Any]))] } if allKey.contains("text") { aliasLightModel.text = ["text" : textNodeParser((data["text"] as! [String : Any]))] } if allKey.contains("shadow") { aliasLightModel.shadow = ["shadow" : shadowNodeParser((data["shadow"] as! [String : Any]))] } return aliasLightModel } // MARK: spacing func spacingNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_spacing { let allKey = jsonData.keys let model = KMAliasLight_spacing.init() if allKey.contains("base") { model.base = ["base" : spacingSubNodeParser(jsonData["base"] as! [String : Any])] } if allKey.contains("tree") { model.tree = ["tree" : numberNodeParser(jsonData["tree"] as! [String : Any])] } return model } // MARK: color func colorNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_color { let allKey = jsonData.keys let model = KMAliasLight_color.init() if allKey.contains("btn") { model.btn = ["btn" : controlNodeParser(jsonData["btn"] as! [String : Any])] } if allKey.contains("sys") { model.sys = ["sys" : controlNodeParser(jsonData["sys"] as! [String : Any])] } if allKey.contains("item-state") { model.item_state = ["item-state" : controlNodeParser(jsonData["item-state"] as! [String : Any])] } if allKey.contains("field") { model.field = ["field" : attributeNodeParser(jsonData["field"] as! [String : Any])] } if allKey.contains("slider") { model.slider = ["slider" : attributeNodeParser(jsonData["slider"] as! [String : Any])] } if allKey.contains("icon") { model.icon = ["icon" : color_icon_baseParser(jsonData["icon"] as! [String : Any])] } if allKey.contains("badge") { let subData = jsonData["badge"] as! [String : Any] let subKeys = subData.keys let submodel = KMAliasLight_control.init() if subKeys.contains("red") { submodel.red = ["red" : attributeNodeParser2(subData["red"] as! [String : Any])] } model.badge = ["badge" : submodel] } return model } func color_icon_baseParser(_ jsonData: [String: Any]) -> KMAliasLight_attribute { let allKey = jsonData.keys let model = KMAliasLight_attribute.init() if allKey.contains("neutral") { model.neutral = ["neutral" : color_icon_base_neutralParser(jsonData["neutral"] as! [String : Any])] } if allKey.contains("brand") { model.brand = ["brand" : valueTypeParser(jsonData["brand"] as! [String : Any])] } if allKey.contains("accent") { model.accent = ["accent" : valueTypeParser(jsonData["accent"] as! [String : Any])] } if allKey.contains("state") { model.state = ["state" : stateParser(jsonData["state"] as! [String : Any])] } if allKey.contains("anti") { model.anti = ["anti" : stateParser(jsonData["anti"] as! [String : Any])] } return model } func color_icon_base_neutralParser(_ jsonData: [String: Any]) -> KMAliasLight_state { let allKey = jsonData.keys let model = KMAliasLight_state.init() if allKey.contains("norm") { model.norm = ["norm" : lvParser(jsonData["norm"] as! [String : Any])] } if allKey.contains("sel") { model.sel = ["sel" : valueTypeParser(jsonData["sel"] as! [String : Any])] } if allKey.contains("dis") { model.dis = ["dis" : valueTypeParser(jsonData["dis"] as! [String : Any])] } return model } // MARK: radius func radiusNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_radius { let allKey = jsonData.keys let model = KMAliasLight_radius.init() if allKey.contains("base") { model.base = ["base" : sizeParser(jsonData["base"] as! [String : Any])] } if allKey.contains("fullround-btn") { model.fullround_btn = ["fullround-btn" : sizeParser(jsonData["fullround-btn"] as! [String : Any])] } return model } // MARK: text func textNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_text { let allKey = jsonData.keys let model = KMAliasLight_text.init() if allKey.contains("mac") { let subData = jsonData["mac"] as! [String : Any] let subKeys = subData.keys let submodel = KMAliasLight_attribute.init() if subKeys.contains("footnote") { submodel.footnote = ["footnote" : attributeNodeParser2(subData["footnote"] as! [String : Any])] } if subKeys.contains("body") { submodel.body = ["body" : sizeParser(subData["body"] as! [String : Any])] } if subKeys.contains("title") { submodel.title = ["title" : sizeParser(subData["title"] as! [String : Any])] } model.mac = ["fullround-btn" : submodel] } if allKey.contains("win") { let subData = jsonData["win"] as! [String : Any] let subKeys = subData.keys let submodel = KMAliasLight_attribute.init() if subKeys.contains("footnote") { submodel.footnote = ["footnote" : attributeNodeParser2(subData["footnote"] as! [String : Any])] } if subKeys.contains("body") { submodel.body = ["body" : sizeParser(subData["body"] as! [String : Any])] } if subKeys.contains("title") { submodel.title = ["title" : sizeParser(subData["title"] as! [String : Any])] } model.win = ["fullround-btn" : submodel] } return model } // MARK: shadow func shadowNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_shadow { let allKey = jsonData.keys let model = KMAliasLight_shadow.init() if allKey.contains("neutral") { model.neutral = ["neutral" : sizeParser(jsonData["neutral"] as! [String : Any])] } if allKey.contains("accent") { model.accent = ["accent" : sizeParser(jsonData["accent"] as! [String : Any])] } if allKey.contains("error") { model.error = ["error" : sizeParser(jsonData["error"] as! [String : Any])] } return model } // MARK: - sub node func controlNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_control { let allKey = jsonData.keys let model = KMAliasLight_control.init() if allKey.contains("cta") { model.cta = ["cta" : attributeNodeParser(jsonData["cta"] as! [String : Any])] } if allKey.contains("brand") { model.brand = ["brand" : attributeNodeParser(jsonData["brand"] as! [String : Any])] } if allKey.contains("sec") { let subData = jsonData["sec"] as! [String : Any] let subKeys = subData.keys let submodel = KMAliasLight_attribute.init() if subKeys.contains("border-color") { submodel.border_color = ["border-color" : valueTypeParser(subData["border-color"] as! [String : Any])] } if subKeys.contains("bg") { submodel.bg = ["bg" : stateParser(subData["bg"] as! [String : Any])] } if subKeys.contains("text") { submodel.text = ["text" : stateParser(subData["text"] as! [String : Any])] } model.sec = ["sec" : submodel] } if allKey.contains("icon-fill") { model.icon_fill = ["icon-fill" : attributeNodeParser(jsonData["icon-fill"] as! [String : Any])] } if allKey.contains("ghost") { model.ghost = ["ghost" : attributeNodeParser(jsonData["ghost"] as! [String : Any])] } if allKey.contains("link") { model.link = ["link" : attributeNodeParser(jsonData["link"] as! [String : Any])] } if allKey.contains("upgrade") { model.upgrade = ["upgrade" : attributeNodeParser(jsonData["upgrade"] as! [String : Any])] } if allKey.contains("text") { model.text = ["text" : attributeNodeParser(jsonData["text"] as! [String : Any])] } if allKey.contains("border") { let subData = jsonData["border"] as! [String : Any] let subKeys = subData.keys let submodel = KMAliasLight_attribute.init() if subKeys.contains("error") { submodel.error = ["error" : valueTypeParser(subData["error"] as! [String : Any])] } if subKeys.contains("neutral") { submodel.neutral = ["neutral" : stateParser(subData["neutral"] as! [String : Any])] } if subKeys.contains("accent") { submodel.accent = ["accent" : stateParser(subData["accent"] as! [String : Any])] } model.border = ["border" : submodel] } if allKey.contains("layout") { let subData = jsonData["layout"] as! [String : Any] let subKeys = subData.keys let submodel = KMAliasLight_attribute.init() if subKeys.contains("bg") { submodel.bg = ["bg" : stateParser(subData["bg"] as! [String : Any])] } if subKeys.contains("mg") { submodel.mg = ["mg" : valueTypeParser(subData["mg"] as! [String : Any])] } if subKeys.contains("fg") { submodel.fg = ["fg" : stateParser(subData["fg"] as! [String : Any])] } if subKeys.contains("dark") { submodel.dark = ["dark" : stateParser(subData["dark"] as! [String : Any])] } if subKeys.contains("state") { submodel.state = ["state" : stateParser(subData["state"] as! [String : Any])] } if subKeys.contains("anti") { submodel.anti = ["anti" : valueTypeParser(subData["anti"] as! [String : Any])] } if subKeys.contains("accent") { submodel.accent = ["accent" : valueTypeParser(subData["accent"] as! [String : Any])] } if subKeys.contains("brand") { submodel.brand = ["brand" : valueTypeParser(subData["brand"] as! [String : Any])] } if subKeys.contains("divider") { submodel.divider = ["divider" : valueTypeParser(subData["divider"] as! [String : Any])] } model.layout = ["layout" : submodel] } if allKey.contains("sel") { model.sel = ["sel" : attributeNodeParser(jsonData["sel"] as! [String : Any])] } if allKey.contains("hov") { model.hov = ["hov" : attributeNodeParser2(jsonData["hov"] as! [String : Any])] } if allKey.contains("red") { model.red = ["red" : attributeNodeParser(jsonData["red"] as! [String : Any])] } return model } func spacingSubNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_attribute { let allKey = jsonData.keys let model = KMAliasLight_attribute.init() if allKey.contains("element") { model.element = ["element" : numberNodeParser(jsonData["element"] as! [String : Any])] } if allKey.contains("module") { model.module = ["module" : numberNodeParser(jsonData["module"] as! [String : Any])] } return model } func attributeNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_attribute { let allKey = jsonData.keys let model = KMAliasLight_attribute.init() if allKey.contains("bg") { model.bg = ["bg" : stateParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("text") { model.text = ["text" : stateParser(jsonData["text"] as! [String : Any])] } if allKey.contains("border") { model.border = ["border" : stateParser(jsonData["border"] as! [String : Any])] } if allKey.contains("anti") { model.anti = ["anti" : stateParser(jsonData["anti"] as! [String : Any])] } if allKey.contains("accent") { model.accent = ["accent" : stateParser(jsonData["accent"] as! [String : Any])] } if allKey.contains("neutral") { model.neutral = ["neutral" : stateParser(jsonData["neutral"] as! [String : Any])] } if allKey.contains("brand") { model.brand = ["brand" : stateParser(jsonData["brand"] as! [String : Any])] } if allKey.contains("error") { model.error = ["error" : stateParser(jsonData["error"] as! [String : Any])] } if allKey.contains("mg") { model.mg = ["mg" : valueTypeParser(jsonData["mg"] as! [String : Any])] } if allKey.contains("fg") { model.fg = ["fg" : stateParser(jsonData["fg"] as! [String : Any])] } if allKey.contains("dark") { model.dark = ["dark" : stateParser(jsonData["dark"] as! [String : Any])] } if allKey.contains("state") { model.state = ["state" : stateParser(jsonData["state"] as! [String : Any])] } if allKey.contains("bg-text") { model.bg_text = ["bg-text" : stateParser(jsonData["bg-text"] as! [String : Any])] } if allKey.contains("track") { model.track = ["track" : stateParser(jsonData["track"] as! [String : Any])] } if allKey.contains("track-filled") { model.track_filled = ["track-filled" : stateParser(jsonData["track-filled"] as! [String : Any])] } if allKey.contains("knob") { model.knob = ["knob" : stateParser(jsonData["knob"] as! [String : Any])] } return model } func attributeNodeParser2(_ jsonData: [String: Any]) -> KMAliasLight_attribute { let allKey = jsonData.keys let model = KMAliasLight_attribute.init() if allKey.contains("bg") { model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("footnote") { model.footnote = ["footnote" : valueTypeParser(jsonData["footnote"] as! [String : Any])] } return model } func stateParser(_ jsonData: [String: Any]) -> KMAliasLight_state { let allKey = jsonData.keys let model = KMAliasLight_state.init() if allKey.contains("norm") { model.norm = ["norm" : valueTypeParser(jsonData["norm"] as! [String : Any])] } if allKey.contains("hov") { model.hov = ["hov" : valueTypeParser(jsonData["hov"] as! [String : Any])] } if allKey.contains("act") { model.act = ["act" : valueTypeParser(jsonData["act"] as! [String : Any])] } if allKey.contains("dis") { model.dis = ["dis" : valueTypeParser(jsonData["dis"] as! [String : Any])] } if allKey.contains("def") { model.def = ["def" : valueTypeParser(jsonData["def"] as! [String : Any])] } if allKey.contains("lv1") { model.lv1 = ["lv1" : valueTypeParser(jsonData["lv1"] as! [String : Any])] } if allKey.contains("lv2") { model.lv2 = ["lv2" : valueTypeParser(jsonData["lv2"] as! [String : Any])] } if allKey.contains("lv3") { model.lv3 = ["lv3" : valueTypeParser(jsonData["lv3"] as! [String : Any])] } if allKey.contains("home") { model.home = ["home" : valueTypeParser(jsonData["home"] as! [String : Any])] } if allKey.contains("view") { model.view = ["view" : valueTypeParser(jsonData["view"] as! [String : Any])] } if allKey.contains("tabbar") { model.tabbar = ["tabbar" : valueTypeParser(jsonData["tabbar"] as! [String : Any])] } if allKey.contains("light") { model.light = ["light" : valueTypeParser(jsonData["light"] as! [String : Any])] } if allKey.contains("light-dis") { model.light_dis = ["light-dis" : valueTypeParser(jsonData["light-dis"] as! [String : Any])] } if allKey.contains("dark") { model.dark = ["dark" : valueTypeParser(jsonData["dark"] as! [String : Any])] } if allKey.contains("bg") { model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("note") { model.note = ["note" : valueTypeParser(jsonData["note"] as! [String : Any])] } if allKey.contains("info") { model.info = ["info" : valueTypeParser(jsonData["info"] as! [String : Any])] } if allKey.contains("error") { model.error = ["error" : valueTypeParser(jsonData["error"] as! [String : Any])] } if allKey.contains("warning") { model.warning = ["warning" : valueTypeParser(jsonData["warning"] as! [String : Any])] } if allKey.contains("focus") { model.focus = ["focus" : valueTypeParser(jsonData["focus"] as! [String : Any])] } if allKey.contains("sel") { model.sel = ["sel" : valueTypeParser(jsonData["sel"] as! [String : Any])] } return model } func stateParser2(_ jsonData: [String: Any]) -> KMAliasLight_state { let allKey = jsonData.keys let model = KMAliasLight_state.init() if allKey.contains("norm") { model.norm = ["norm" : lvParser(jsonData["norm"] as! [String : Any])] } return model } func lvParser(_ jsonData: [String: Any]) -> KMAliasLight_lv { let allKey = jsonData.keys let model = KMAliasLight_lv.init() if allKey.contains("lv1") { model.lv1 = ["lv1" : valueTypeParser(jsonData["lv1"] as! [String : Any])] } if allKey.contains("lv2") { model.lv2 = ["lv2" : valueTypeParser(jsonData["lv2"] as! [String : Any])] } if allKey.contains("lv3") { model.lv3 = ["lv3" : valueTypeParser(jsonData["lv3"] as! [String : Any])] } return model } func numberNodeParser(_ jsonData: [String: Any]) -> KMAliasLight_number { let allKey = jsonData.keys let model = KMAliasLight_number.init() if allKey.contains("0") { model.number0 = ["0" : valueTypeParser(jsonData["0"] as! [String : Any])] } if allKey.contains("1") { model.number1 = ["1" : valueTypeParser(jsonData["1"] as! [String : Any])] } if allKey.contains("2") { model.number2 = ["2" : valueTypeParser(jsonData["2"] as! [String : Any])] } if allKey.contains("4") { model.number4 = ["4" : valueTypeParser(jsonData["4"] as! [String : Any])] } if allKey.contains("6") { model.number6 = ["6" : valueTypeParser(jsonData["6"] as! [String : Any])] } if allKey.contains("8") { model.number8 = ["8" : valueTypeParser(jsonData["8"] as! [String : Any])] } if allKey.contains("12") { model.number12 = ["12" : valueTypeParser(jsonData["12"] as! [String : Any])] } if allKey.contains("16") { model.number16 = ["16" : valueTypeParser(jsonData["16"] as! [String : Any])] } if allKey.contains("24") { model.number24 = ["24" : valueTypeParser(jsonData["24"] as! [String : Any])] } if allKey.contains("32") { model.number32 = ["32" : valueTypeParser(jsonData["32"] as! [String : Any])] } if allKey.contains("40") { model.number40 = ["40" : valueTypeParser(jsonData["40"] as! [String : Any])] } if allKey.contains("56") { model.number56 = ["56" : valueTypeParser(jsonData["56"] as! [String : Any])] } if allKey.contains("64") { model.number64 = ["64" : valueTypeParser(jsonData["64"] as! [String : Any])] } if allKey.contains("80") { model.number80 = ["80" : valueTypeParser(jsonData["80"] as! [String : Any])] } if allKey.contains("88") { model.number88 = ["88" : valueTypeParser(jsonData["88"] as! [String : Any])] } return model } func sizeParser(_ jsonData: [String: Any]) -> KMAliasLight_size { let allKey = jsonData.keys let model = KMAliasLight_size.init() if allKey.contains("s") { model.s = ["s" : valueTypeParser(jsonData["s"] as! [String : Any])] } if allKey.contains("m") { model.m = ["m" : valueTypeParser(jsonData["m"] as! [String : Any])] } if allKey.contains("l") { model.l = ["l" : valueTypeParser(jsonData["l"] as! [String : Any])] } if allKey.contains("xs") { model.xs = ["xs" : valueTypeParser(jsonData["xs"] as! [String : Any])] } if allKey.contains("m-base") { model.m_base = ["m-base" : valueTypeParser(jsonData["m-base"] as! [String : Any])] } if allKey.contains("xl") { model.xl = ["xl" : valueTypeParser(jsonData["xl"] as! [String : Any])] } return model } func valueTypeParser(_ jsonData: [String: Any]) -> KMAliasLight_valueType { let allKey = jsonData.keys let model = KMAliasLight_valueType.init() if allKey.contains("value") { model.value = ["value" : jsonData["value"] as! String] } if allKey.contains("type") { model.type = ["type" : jsonData["type"] as! String] } return model } } // MARK: - Parser Action extension KMAliasLightParser { func startJSONParse() -> [String : Any] { self.fileName = "alias-light" self.fileType = "json" return self.jsonParser } }