// // KMGlobalParser.swift // PDF Master // // Created by wanjun on 2022/12/21. // import Cocoa class KMGlobalParser: KMBaseParser { func startParse() -> KMGlobal { self.fileName = "global" self.fileType = "json" return globalParser(self.jsonParser) } func globalParser(_ jsonData: [String: Any]) -> KMGlobal { let data = jsonData let allKey = data.keys let globalModel = KMGlobal.init() if allKey.contains("sizing") { globalModel.sizing = ["sizing" : sizingParser((data["sizing"] as! [String : Any]))] } if allKey.contains("spacing") { globalModel.spacing = ["spacing" : spacingParser((data["spacing"] as! [String : Any]))] } if allKey.contains("color") { globalModel.color = ["color" : colorParser((data["color"] as! [String : Any]))] } if allKey.contains("border-radius") { globalModel.border_radius = ["border-radius" : borderRadiusParser((data["border-radius"] as! [String : Any]))] } if allKey.contains("border-width") { globalModel.border_width = ["border-width" : borderWidthParser((data["border-width"] as! [String : Any]))] } if allKey.contains("shadow") { globalModel.shadow = ["shadow" : shadowParser((data["shadow"] as! [String : Any]))] } if allKey.contains("text-mac") { globalModel.text_mac = ["text-mac" : textMacParser((data["text-mac"] as! [String : Any]))] } if allKey.contains("text-windows") { globalModel.text_windows = ["text-windows" : textWindowsParser((data["text-windows"] as! [String : Any]))] } return globalModel } // MARK: sizing func sizingParser(_ jsonData: [String: Any]) -> KMGlobal_sizing { let allKey = jsonData.keys let model = KMGlobal_sizing.init() if allKey.contains("1") { model.sizing1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])] } if allKey.contains("4") { model.sizing4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])] } if allKey.contains("8") { model.sizing8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])] } if allKey.contains("10") { model.sizing10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])] } if allKey.contains("12") { model.sizing12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])] } if allKey.contains("14") { model.sizing14 = ["14" : valueTypeParser2(jsonData["14"] as! [String : Any])] } if allKey.contains("16") { model.sizing16 = ["16" : valueTypeParser2(jsonData["16"] as! [String : Any])] } if allKey.contains("18") { model.sizing18 = ["18" : valueTypeParser2(jsonData["18"] as! [String : Any])] } if allKey.contains("20") { model.sizing20 = ["20" : valueTypeParser2(jsonData["20"] as! [String : Any])] } if allKey.contains("21") { model.sizing21 = ["21" : valueTypeParser2(jsonData["21"] as! [String : Any])] } if allKey.contains("22") { model.sizing22 = ["22" : valueTypeParser2(jsonData["22"] as! [String : Any])] } if allKey.contains("24") { model.sizing24 = ["24" : valueTypeParser2(jsonData["24"] as! [String : Any])] } if allKey.contains("26") { model.sizing26 = ["26" : valueTypeParser2(jsonData["26"] as! [String : Any])] } if allKey.contains("28") { model.sizing28 = ["28" : valueTypeParser2(jsonData["28"] as! [String : Any])] } if allKey.contains("30") { model.sizing30 = ["30" : valueTypeParser2(jsonData["30"] as! [String : Any])] } if allKey.contains("32") { model.sizing32 = ["32" : valueTypeParser2(jsonData["32"] as! [String : Any])] } if allKey.contains("34") { model.sizing34 = ["34" : valueTypeParser2(jsonData["34"] as! [String : Any])] } if allKey.contains("36") { model.sizing36 = ["36" : valueTypeParser2(jsonData["36"] as! [String : Any])] } if allKey.contains("40") { model.sizing40 = ["40" : valueTypeParser2(jsonData["40"] as! [String : Any])] } if allKey.contains("48") { model.sizing48 = ["48" : valueTypeParser2(jsonData["48"] as! [String : Any])] } if allKey.contains("50") { model.sizing50 = ["50" : valueTypeParser2(jsonData["50"] as! [String : Any])] } if allKey.contains("58") { model.sizing58 = ["58" : valueTypeParser2(jsonData["58"] as! [String : Any])] } if allKey.contains("60") { model.sizing60 = ["60" : valueTypeParser2(jsonData["60"] as! [String : Any])] } if allKey.contains("64") { model.sizing64 = ["64" : valueTypeParser2(jsonData["64"] as! [String : Any])] } if allKey.contains("68") { model.sizing68 = ["68" : valueTypeParser2(jsonData["68"] as! [String : Any])] } if allKey.contains("72") { model.sizing72 = ["72" : valueTypeParser2(jsonData["72"] as! [String : Any])] } if allKey.contains("110") { model.sizing110 = ["110" : valueTypeParser2(jsonData["110"] as! [String : Any])] } if allKey.contains("116") { model.sizing116 = ["116" : valueTypeParser2(jsonData["116"] as! [String : Any])] } if allKey.contains("120") { model.sizing120 = ["120" : valueTypeParser2(jsonData["120"] as! [String : Any])] } if allKey.contains("132") { model.sizing132 = ["132" : valueTypeParser2(jsonData["132"] as! [String : Any])] } if allKey.contains("139") { model.sizing139 = ["139" : valueTypeParser2(jsonData["139"] as! [String : Any])] } if allKey.contains("180") { model.sizing180 = ["180" : valueTypeParser2(jsonData["180"] as! [String : Any])] } if allKey.contains("200") { model.sizing200 = ["200" : valueTypeParser2(jsonData["200"] as! [String : Any])] } if allKey.contains("228") { model.sizing228 = ["228" : valueTypeParser2(jsonData["228"] as! [String : Any])] } if allKey.contains("260") { model.sizing260 = ["260" : valueTypeParser2(jsonData["260"] as! [String : Any])] } return model } // MARK: spacing func spacingParser(_ jsonData: [String: Any]) -> KMGlobal_spacing { let allKey = jsonData.keys let model = KMGlobal_spacing.init() if allKey.contains("0") { model.spacing0 = ["0" : valueTypeParser2(jsonData["0"] as! [String : Any])] } if allKey.contains("1") { model.spacing1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])] } if allKey.contains("2") { model.spacing2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])] } if allKey.contains("4") { model.spacing4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])] } if allKey.contains("5") { model.spacing5 = ["5" : valueTypeParser2(jsonData["5"] as! [String : Any])] } if allKey.contains("6") { model.spacing6 = ["6" : valueTypeParser2(jsonData["6"] as! [String : Any])] } if allKey.contains("8") { model.spacing8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])] } if allKey.contains("10") { model.spacing10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])] } if allKey.contains("12") { model.spacing12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])] } if allKey.contains("16") { model.spacing16 = ["16" : valueTypeParser2(jsonData["16"] as! [String : Any])] } if allKey.contains("24") { model.spacing24 = ["24" : valueTypeParser2(jsonData["24"] as! [String : Any])] } if allKey.contains("32") { model.spacing32 = ["32" : valueTypeParser2(jsonData["32"] as! [String : Any])] } if allKey.contains("40") { model.spacing40 = ["40" : valueTypeParser2(jsonData["40"] as! [String : Any])] } if allKey.contains("56") { model.spacing56 = ["56" : valueTypeParser2(jsonData["56"] as! [String : Any])] } if allKey.contains("64") { model.spacing64 = ["64" : valueTypeParser2(jsonData["64"] as! [String : Any])] } if allKey.contains("80") { model.spacing80 = ["80" : valueTypeParser2(jsonData["80"] as! [String : Any])] } if allKey.contains("88") { model.spacing88 = ["88" : valueTypeParser2(jsonData["88"] as! [String : Any])] } return model } // MARK: color func colorParser(_ jsonData: [String: Any]) -> KMGlobal_color { let allKey = jsonData.keys let model = KMGlobal_color.init() if allKey.contains("light") { model.light = ["light" : colorValueParser(jsonData["light"] as! [String : Any])] } if allKey.contains("dark") { model.dark = ["dark" : colorValueParser(jsonData["dark"] as! [String : Any])] } return model } // MARK: border-radius func borderRadiusParser(_ jsonData: [String: Any]) -> KMGlobal_borderRadius { let allKey = jsonData.keys let model = KMGlobal_borderRadius.init() if allKey.contains("2") { model.number2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])] } if allKey.contains("4") { model.number4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])] } if allKey.contains("6") { model.number6 = ["6" : valueTypeParser2(jsonData["6"] as! [String : Any])] } if allKey.contains("8") { model.number8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])] } if allKey.contains("10") { model.number10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])] } if allKey.contains("12") { model.number12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])] } if allKey.contains("16") { model.number16 = ["16" : valueTypeParser2(jsonData["16"] as! [String : Any])] } if allKey.contains("20") { model.number20 = ["20" : valueTypeParser2(jsonData["20"] as! [String : Any])] } return model } // MARK: border-width func borderWidthParser(_ jsonData: [String: Any]) -> KMGlobal_borderWidth { let allKey = jsonData.keys let model = KMGlobal_borderWidth.init() if allKey.contains("1") { model.number1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])] } if allKey.contains("2") { model.number2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])] } return model } // MARK: shadow func shadowParser(_ jsonData: [String: Any]) -> KMGlobal_shadow { let allKey = jsonData.keys let model = KMGlobal_shadow.init() if allKey.contains("black-2-2") { model.black_2_2 = ["black-2-2" : valueTypeParser(jsonData["black-2-2"] as! [String : Any])] } if allKey.contains("black-4-8") { model.black_4_8 = ["black-4-8" : valueTypeParser(jsonData["black-4-8"] as! [String : Any])] } if allKey.contains("black-2-8") { model.black_2_8 = ["black-2-8" : valueTypeParser(jsonData["black-2-8"] as! [String : Any])] } if allKey.contains("blue-0-4") { model.blue_0_4 = ["blue-0-4" : valueTypeParser(jsonData["blue-0-4"] as! [String : Any])] } if allKey.contains("red-0-4") { model.red_0_4 = ["red-0-4" : valueTypeParser(jsonData["red-0-4"] as! [String : Any])] } return model } // MARK: text-mac func textMacParser(_ jsonData: [String: Any]) -> KMGlobal_textMac { let allKey = jsonData.keys let model = KMGlobal_textMac.init() if allKey.contains("regular") { model.regular = ["regular" : numberNodeParser(jsonData["regular"] as! [String : Any])] } if allKey.contains("semibold") { model.semibold = ["semibold" : numberNodeParser(jsonData["semibold"] as! [String : Any])] } return model } // MARK: text-windows func textWindowsParser(_ jsonData: [String: Any]) -> KMGlobal_textWindows { let allKey = jsonData.keys let model = KMGlobal_textWindows.init() if allKey.contains("regular") { model.regular = ["regular" : numberNodeParser(jsonData["regular"] as! [String : Any])] } if allKey.contains("semibold") { model.semibold = ["semibold" : numberNodeParser(jsonData["semibold"] as! [String : Any])] } return model } // MARK: - func numberNodeParser(_ jsonData: [String: Any]) -> KMGlobal_number { let allKey = jsonData.keys let model = KMGlobal_number.init() if allKey.contains("11") { model.number11 = ["11" : valueTypeParser(jsonData["11"] as! [String : Any])] } if allKey.contains("12") { model.number12 = ["12" : valueTypeParser(jsonData["12"] as! [String : Any])] } if allKey.contains("14") { model.number14 = ["14" : valueTypeParser(jsonData["14"] as! [String : Any])] } if allKey.contains("16") { model.number16 = ["16" : valueTypeParser(jsonData["16"] as! [String : Any])] } if allKey.contains("20") { model.number20 = ["20" : valueTypeParser(jsonData["20"] as! [String : Any])] } return model } func colorValueParser(_ jsonData: [String: Any]) -> KMGlobal_colorValue { let allKey = jsonData.keys let model = KMGlobal_colorValue.init() if allKey.contains("blue") { model.blue = ["blue" : colorNumberNodeParser(jsonData["blue"] as! [String : Any])] } if allKey.contains("gray") { model.gray = ["gray" : colorNumberNodeParser(jsonData["gray"] as! [String : Any])] } if allKey.contains("navy-blue") { model.navy_blue = ["navy-blue" : colorNumberNodeParser(jsonData["navy-blue"] as! [String : Any])] } if allKey.contains("green") { model.green = ["green" : colorNumberNodeParser(jsonData["green"] as! [String : Any])] } if allKey.contains("gold") { model.gold = ["gold" : colorNumberNodeParser(jsonData["gold"] as! [String : Any])] } if allKey.contains("red") { model.red = ["red" : colorNumberNodeParser(jsonData["red"] as! [String : Any])] } if allKey.contains("orange") { model.orange = ["orange" : colorNumberNodeParser(jsonData["orange"] as! [String : Any])] } if allKey.contains("cyan") { model.cyan = ["cyan" : colorNumberNodeParser(jsonData["cyan"] as! [String : Any])] } if allKey.contains("purple") { model.purple = ["purple" : colorNumberNodeParser(jsonData["purple"] as! [String : Any])] } if allKey.contains("pink") { model.pink = ["pink" : colorNumberNodeParser(jsonData["pink"] as! [String : Any])] } return model } func colorNumberNodeParser(_ jsonData: [String: Any]) -> KMGlobal_colorNumber { let allKey = jsonData.keys let model = KMGlobal_colorNumber.init() if allKey.contains("1") { model.number1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])] } if allKey.contains("2") { model.number2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])] } if allKey.contains("3") { model.number3 = ["3" : valueTypeParser2(jsonData["3"] as! [String : Any])] } if allKey.contains("4") { model.number4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])] } if allKey.contains("5") { model.number5 = ["5" : valueTypeParser2(jsonData["5"] as! [String : Any])] } if allKey.contains("6") { model.number6 = ["6" : valueTypeParser2(jsonData["6"] as! [String : Any])] } if allKey.contains("7") { model.number7 = ["7" : valueTypeParser2(jsonData["7"] as! [String : Any])] } if allKey.contains("8") { model.number8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])] } if allKey.contains("9") { model.number9 = ["9" : valueTypeParser2(jsonData["9"] as! [String : Any])] } if allKey.contains("10") { model.number10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])] } if allKey.contains("11") { model.number11 = ["11" : valueTypeParser2(jsonData["11"] as! [String : Any])] } if allKey.contains("12") { model.number12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])] } return model } func valueTypeParser(_ jsonData: [String: Any]) -> KMGlobal_valueType { let allKey = jsonData.keys let model = KMGlobal_valueType.init() if allKey.contains("value") { model.value = ["value" : uiValueParser(jsonData["value"] as! [String : Any])] } if allKey.contains("type") { model.type = ["type" : jsonData["type"] as! String] } return model } func valueTypeParser2(_ jsonData: [String: Any]) -> KMGlobal_valueType { let allKey = jsonData.keys let model = KMGlobal_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 } func uiValueParser(_ jsonData: [String: Any]) -> KMGlobal_UIValue { let allKey = jsonData.keys let model = KMGlobal_UIValue.init() if allKey.contains("fontFamily") { model.fontFamily = ["fontFamily" : jsonData["fontFamily"] as! String] } if allKey.contains("fontWeight") { model.fontWeight = ["fontWeight" : jsonData["fontWeight"] as! String] } if allKey.contains("lineHeight") { model.lineHeight = ["lineHeight" : jsonData["lineHeight"] as! String] } if allKey.contains("fontSize") { model.fontSize = ["fontSize" : jsonData["fontSize"] as! String] } if allKey.contains("x") { model.x = ["x" : jsonData["x"] as! String] } if allKey.contains("y") { model.y = ["y" : jsonData["y"] as! String] } if allKey.contains("blur") { model.blur = ["blur" : jsonData["blur"] as! String] } if allKey.contains("spread") { model.spread = ["spread" : jsonData["spread"] as! String] } if allKey.contains("color") { model.color = ["color" : jsonData["color"] as! String] } if allKey.contains("type") { model.type = ["type" : jsonData["type"] as! String] } return model } } // MARK: - Parser Action extension KMGlobalParser { func startJSONParse() -> [String : Any] { self.fileName = "global" self.fileType = "json" return self.jsonParser } }