123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- //
- // KMAliasLightParser.swift
- // PDF Reader Pro
- //
- // 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
- }
- }
|