KMCompLightParser.swift 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. //
  2. // KMCompLightParser.swift
  3. // Cisdem PDFMaster
  4. //
  5. // Created by wanjun on 2022/12/21.
  6. //
  7. import Cocoa
  8. class KMCompLightParser: KMBaseParser {
  9. func startParse() -> KMCompLight {
  10. self.fileName = "comp-light"
  11. self.fileType = "json"
  12. return compLightParser(self.jsonParser)
  13. }
  14. func compLightParser(_ jsonData: [String: Any]) -> KMCompLight {
  15. let data = jsonData
  16. let allKey = data.keys
  17. let compLightModel = KMCompLight.init()
  18. if allKey.contains("btn") {
  19. compLightModel.btn = ["btn" : btnNodeParser((data["btn"] as! [String : Any]))]
  20. }
  21. if allKey.contains("dropdown") {
  22. compLightModel.dropdown = ["dropdown" : dropdownNodeParser((data["dropdown"] as! [String : Any]))]
  23. }
  24. if allKey.contains("navmenu") {
  25. compLightModel.navmenu = ["navmenu" : navmenuNodeParser((data["navmenu"] as! [String : Any]))]
  26. }
  27. if allKey.contains("multi-tab") {
  28. compLightModel.multi_tab = ["multi-tab" : multitabNodeParser((data["multi-tab"] as! [String : Any]))]
  29. }
  30. if allKey.contains("checkbox-radio") {
  31. compLightModel.checkbox_radio = ["checkbox-radio" : checkboxradioNodeParser((data["checkbox-radio"] as! [String : Any]))]
  32. }
  33. if allKey.contains("input") {
  34. compLightModel.input = ["input" : inputNodeParser((data["input"] as! [String : Any]))]
  35. }
  36. if allKey.contains("pagination") {
  37. compLightModel.pagination = ["pagination" : paginationNodeParser((data["pagination"] as! [String : Any]))]
  38. }
  39. if allKey.contains("select") {
  40. compLightModel.select = ["select" : selectNodeParser((data["select"] as! [String : Any]))]
  41. }
  42. if allKey.contains("slider") {
  43. compLightModel.slider = ["slider" : sliderNodeParser((data["slider"] as! [String : Any]))]
  44. }
  45. if allKey.contains("stepper") {
  46. compLightModel.stepper = ["stepper" : stepperNodeParser((data["stepper"] as! [String : Any]))]
  47. }
  48. if allKey.contains("badge") {
  49. compLightModel.badge = ["badge" : badgeNodeParser((data["badge"] as! [String : Any]))]
  50. }
  51. if allKey.contains("collapse") {
  52. compLightModel.collapse = ["collapse" : collapseNodeParser((data["collapse"] as! [String : Any]))]
  53. }
  54. if allKey.contains("list") {
  55. compLightModel.list = ["list" : listNodeParser((data["list"] as! [String : Any]))]
  56. }
  57. if allKey.contains("progress") {
  58. compLightModel.progress = ["progress" : progressNodeParser((data["progress"] as! [String : Any]))]
  59. }
  60. if allKey.contains("segmented") {
  61. compLightModel.segmented = ["segmented" : segmentedNodeParser((data["segmented"] as! [String : Any]))]
  62. }
  63. if allKey.contains("tree") {
  64. compLightModel.tree = ["tree" : treeNodeParser((data["tree"] as! [String : Any]))]
  65. }
  66. if allKey.contains("alert") {
  67. compLightModel.alert = ["alert" : alertNodeParser((data["alert"] as! [String : Any]))]
  68. }
  69. if allKey.contains("drawer") {
  70. compLightModel.drawer = ["drawer" : drawerNodeParser((data["drawer"] as! [String : Any]))]
  71. }
  72. if allKey.contains("notification") {
  73. compLightModel.notification = ["notification" : notificationNodeParser((data["notification"] as! [String : Any]))]
  74. }
  75. if allKey.contains("table") {
  76. compLightModel.table = ["table" : tableNodeParser((data["table"] as! [String : Any]))]
  77. }
  78. if allKey.contains("divider") {
  79. compLightModel.divider = ["divider" : dividerNodeParser((data["divider"] as! [String : Any]))]
  80. }
  81. return compLightModel
  82. }
  83. // MARK: Node Parser
  84. func btnNodeParser(_ jsonData: [String: Any]) -> KMCompLight_btn {
  85. let allKey = jsonData.keys
  86. let model = KMCompLight_btn.init()
  87. if allKey.contains("cta") {
  88. model.cta = ["cta" : sizeNodeParser(jsonData["cta"] as! [String : Any])]
  89. }
  90. if allKey.contains("brand") {
  91. model.brand = ["brand" : sizeNodeParser(jsonData["brand"] as! [String : Any])]
  92. }
  93. if allKey.contains("sec") {
  94. model.sec = ["sec" : sizeNodeParser(jsonData["sec"] as! [String : Any])]
  95. }
  96. if allKey.contains("ghost") {
  97. model.ghost = ["ghost" : sizeNodeParser(jsonData["ghost"] as! [String : Any])]
  98. }
  99. if allKey.contains("link") {
  100. model.link = ["link" : sizeNodeParser(jsonData["link"] as! [String : Any])]
  101. }
  102. if allKey.contains("upgrade") {
  103. model.upgrade = ["upgrade" : sizeNodeParser(jsonData["upgrade"] as! [String : Any])]
  104. }
  105. if allKey.contains("icon-fill") {
  106. model.icon_fill = ["icon-fill" : sizeNodeParser(jsonData["icon-fill"] as! [String : Any])]
  107. }
  108. if allKey.contains("sec-icon") {
  109. model.sec_icon = ["sec-icon" : sizeNodeParser(jsonData["sec-icon"] as! [String : Any])]
  110. }
  111. return model
  112. }
  113. func dropdownNodeParser(_ jsonData: [String: Any]) -> KMCompLight_dropdown {
  114. let allKey = jsonData.keys
  115. let model = KMCompLight_dropdown.init()
  116. if allKey.contains("s") {
  117. model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])]
  118. }
  119. return model
  120. }
  121. func navmenuNodeParser(_ jsonData: [String: Any]) -> KMCompLight_navmenu {
  122. let allKey = jsonData.keys
  123. let model = KMCompLight_navmenu.init()
  124. if allKey.contains("mac-text") {
  125. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  126. }
  127. if allKey.contains("base") {
  128. model.base = ["base" : sizeNodeParser(jsonData["base"] as! [String : Any])]
  129. }
  130. if allKey.contains("has-icon") {
  131. model.has_icon = ["has-icon" : sizeNodeParser(jsonData["has-icon"] as! [String : Any])]
  132. }
  133. if allKey.contains("win-text") {
  134. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  135. }
  136. return model
  137. }
  138. func multitabNodeParser(_ jsonData: [String: Any]) -> KMCompLight_multiTab {
  139. let allKey = jsonData.keys
  140. let model = KMCompLight_multiTab.init()
  141. if allKey.contains("bg") {
  142. model.bg = ["bg" : uiAttributeParser(jsonData["bg"] as! [String : Any])]
  143. }
  144. if allKey.contains("mac-text") {
  145. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  146. }
  147. if allKey.contains("win-text") {
  148. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  149. }
  150. return model
  151. }
  152. func checkboxradioNodeParser(_ jsonData: [String: Any]) -> KMCompLight_checkboxRadio {
  153. let allKey = jsonData.keys
  154. let model = KMCompLight_checkboxRadio.init()
  155. if allKey.contains("bg") {
  156. model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])]
  157. }
  158. if allKey.contains("mac-text") {
  159. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  160. }
  161. if allKey.contains("win-text") {
  162. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  163. }
  164. return model
  165. }
  166. func inputNodeParser(_ jsonData: [String: Any]) -> KMCompLight_input {
  167. let allKey = jsonData.keys
  168. let model = KMCompLight_input.init()
  169. if allKey.contains("m") {
  170. model.m = ["m" : uiAttributeParser(jsonData["m"] as! [String : Any])]
  171. }
  172. if allKey.contains("tips") {
  173. model.tips = ["tips" : uiAttributeParser(jsonData["tips"] as! [String : Any])]
  174. }
  175. if allKey.contains("s") {
  176. model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])]
  177. }
  178. return model
  179. }
  180. func paginationNodeParser(_ jsonData: [String: Any]) -> KMCompLight_pagination {
  181. let allKey = jsonData.keys
  182. let model = KMCompLight_pagination.init()
  183. if allKey.contains("Simple") {
  184. model.simple = ["Simple" : uiAttributeParser2(jsonData["Simple"] as! [String : Any])]
  185. }
  186. if allKey.contains("multiple") {
  187. model.multiple = ["multiple" : uiAttributeParser2(jsonData["multiple"] as! [String : Any])]
  188. }
  189. return model
  190. }
  191. func selectNodeParser(_ jsonData: [String: Any]) -> KMCompLight_select {
  192. let allKey = jsonData.keys
  193. let model = KMCompLight_select.init()
  194. if allKey.contains("s") {
  195. model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])]
  196. }
  197. if allKey.contains("m") {
  198. model.m = ["m" : uiAttributeParser(jsonData["m"] as! [String : Any])]
  199. }
  200. if allKey.contains("Simple") {
  201. model.simple = ["Simple" : uiAttributeParser2(jsonData["Simple"] as! [String : Any])]
  202. }
  203. return model
  204. }
  205. func sliderNodeParser(_ jsonData: [String: Any]) -> KMCompLight_slider {
  206. let allKey = jsonData.keys
  207. let model = KMCompLight_slider.init()
  208. if allKey.contains("knob") {
  209. model.knob = ["knob" : uiStateParser(jsonData["knob"] as! [String : Any])]
  210. }
  211. if allKey.contains("track") {
  212. model.track = ["track" : uiStateParser(jsonData["track"] as! [String : Any])]
  213. }
  214. if allKey.contains("track-filled") {
  215. model.track_filled = ["track-filled" : uiStateParser(jsonData["track-filled"] as! [String : Any])]
  216. }
  217. return model
  218. }
  219. func stepperNodeParser(_ jsonData: [String: Any]) -> KMCompLight_stepper {
  220. let allKey = jsonData.keys
  221. let model = KMCompLight_stepper.init()
  222. if allKey.contains("item-spacing") {
  223. model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])]
  224. }
  225. if allKey.contains("mac-text") {
  226. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  227. }
  228. if allKey.contains("bg") {
  229. model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])]
  230. }
  231. if allKey.contains("arrow") {
  232. model.arrow = ["arrow" : uiAttributeParser(jsonData["arrow"] as! [String : Any])]
  233. }
  234. if allKey.contains("win-text") {
  235. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  236. }
  237. return model
  238. }
  239. func badgeNodeParser(_ jsonData: [String: Any]) -> KMCompLight_badge {
  240. let allKey = jsonData.keys
  241. let model = KMCompLight_badge.init()
  242. if allKey.contains("dot") {
  243. model.dot = ["dot" : valueTypeParser(jsonData["dot"] as! [String : Any])]
  244. }
  245. if allKey.contains("text") {
  246. model.text = ["text" : uiAttributeParser2(jsonData["text"] as! [String : Any])]
  247. }
  248. return model
  249. }
  250. func cardNodeParser(_ jsonData: [String: Any]) -> KMCompLight_card {
  251. let allKey = jsonData.keys
  252. let model = KMCompLight_card.init()
  253. if allKey.contains("has-desc") {
  254. model.has_desc = ["has-desc" : uiAttributeParser(jsonData["has-desc"] as! [String : Any])]
  255. }
  256. if allKey.contains("Simple") {
  257. model.simple = ["Simple" : uiAttributeParser(jsonData["Simple"] as! [String : Any])]
  258. }
  259. if allKey.contains("mac-text") {
  260. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  261. }
  262. if allKey.contains("item-spacing") {
  263. model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])]
  264. }
  265. if allKey.contains("win-text") {
  266. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  267. }
  268. return model
  269. }
  270. func collapseNodeParser(_ jsonData: [String: Any]) -> KMCompLight_collapse {
  271. let allKey = jsonData.keys
  272. let model = KMCompLight_collapse.init()
  273. if allKey.contains("ad-list") {
  274. let subData = jsonData["ad-list"] as! [String : Any]
  275. let subKeys = subData.keys
  276. let submodel = KMCompLight_UIAttribute.init()
  277. if subKeys.contains("mac-text") {
  278. submodel.mac_text = ["mac-text" : uiStateParser(subData["mac-text"] as! [String : Any])]
  279. }
  280. if subKeys.contains("bg") {
  281. submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])]
  282. }
  283. if subKeys.contains("win-text") {
  284. submodel.win_text = ["win-text" : uiStateParser(subData["win-text"] as! [String : Any])]
  285. }
  286. if subKeys.contains("item-spacing") {
  287. submodel.item_spacing = ["item-spacing" : valueTypeParser(subData["item-spacing"] as! [String : Any])]
  288. }
  289. model.ad_list = ["ad-list" : submodel]
  290. }
  291. if allKey.contains("bota-list") {
  292. let subData = jsonData["bota-list"] as! [String : Any]
  293. let subKeys = subData.keys
  294. let submodel = KMCompLight_UIAttribute.init()
  295. if subKeys.contains("bg") {
  296. submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])]
  297. }
  298. if subKeys.contains("mac-text-title") {
  299. submodel.mac_text_title = ["mac-text-title" : uiStateParser(subData["mac-text-title"] as! [String : Any])]
  300. }
  301. if subKeys.contains("mac-text-desc") {
  302. submodel.mac_text_desc = ["mac-text-desc" : uiStateParser(subData["mac-text-desc"] as! [String : Any])]
  303. }
  304. if subKeys.contains("win-text-title") {
  305. submodel.win_text_title = ["win-text-title" : uiStateParser(subData["win-text-title"] as! [String : Any])]
  306. }
  307. if subKeys.contains("win-text-desc") {
  308. submodel.win_text_desc = ["win-text-desc" : uiStateParser(subData["win-text-desc"] as! [String : Any])]
  309. }
  310. model.bota_list = ["bota-list" : submodel]
  311. }
  312. return model
  313. }
  314. func listNodeParser(_ jsonData: [String: Any]) -> KMCompLight_list {
  315. let allKey = jsonData.keys
  316. let model = KMCompLight_list.init()
  317. if allKey.contains("bookmark") {
  318. let subData = jsonData["bookmark"] as! [String : Any]
  319. let subKeys = subData.keys
  320. let submodel = KMCompLight_UIAttribute.init()
  321. if subKeys.contains("mac-text") {
  322. submodel.mac_text = ["mac-text" : valueTypeParser(subData["mac-text"] as! [String : Any])]
  323. }
  324. if subKeys.contains("win-text") {
  325. submodel.win_text = ["win-text" : valueTypeParser(subData["win-text"] as! [String : Any])]
  326. }
  327. if subKeys.contains("bg") {
  328. submodel.bg = ["bg" : uiStateParser(subData["bg"] as! [String : Any])]
  329. }
  330. model.bookmark = ["bookmark" : submodel]
  331. }
  332. if allKey.contains("markup-header") {
  333. model.markup_header = ["markup-header" : uiAttributeParser2(jsonData["markup-header"] as! [String : Any])]
  334. }
  335. if allKey.contains("markup-note") {
  336. model.markup_note = ["markup-note" : uiAttributeParser2(jsonData["markup-note"] as! [String : Any])]
  337. }
  338. return model
  339. }
  340. func progressNodeParser(_ jsonData: [String: Any]) -> KMCompLight_progress {
  341. let allKey = jsonData.keys
  342. let model = KMCompLight_progress.init()
  343. if allKey.contains("popup") {
  344. let subData = jsonData["popup"] as! [String : Any]
  345. let subKeys = subData.keys
  346. let submodel = KMCompLight_UIAttribute.init()
  347. if subKeys.contains("bg") {
  348. submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])]
  349. }
  350. if subKeys.contains("mac-text") {
  351. submodel.mac_text = ["mac-text" : valueTypeParser(subData["mac-text"] as! [String : Any])]
  352. }
  353. if subKeys.contains("win-text") {
  354. submodel.win_text = ["win-text" : valueTypeParser(subData["win-text"] as! [String : Any])]
  355. }
  356. if subKeys.contains("progress-bar") {
  357. submodel.progress_bar = ["progress-bar" : progressBarParser(subData["progress-bar"] as! [String : Any])]
  358. }
  359. if subKeys.contains("item-spacing") {
  360. submodel.item_spacing = ["item-spacing" : valueTypeParser(subData["item-spacing"] as! [String : Any])]
  361. }
  362. model.popup = ["popup" : submodel]
  363. }
  364. if allKey.contains("loading") {
  365. let subData = jsonData["loading"] as! [String : Any]
  366. let subKeys = subData.keys
  367. let submodel = KMCompLight_sizeNode.init()
  368. if subKeys.contains("m") {
  369. submodel.m = ["m" : valueTypeParser(subData["m"] as! [String : Any])]
  370. }
  371. if subKeys.contains("s") {
  372. submodel.s = ["s" : valueTypeParser(subData["s"] as! [String : Any])]
  373. }
  374. model.loading = ["loading" : submodel]
  375. }
  376. return model
  377. }
  378. func segmentedNodeParser(_ jsonData: [String: Any]) -> KMCompLight_segmented {
  379. let allKey = jsonData.keys
  380. let model = KMCompLight_segmented.init()
  381. if allKey.contains("bg") {
  382. model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])]
  383. }
  384. if allKey.contains("bg-item") {
  385. model.bg_item = ["bg-item" : uiStateParser(jsonData["bg-item"] as! [String : Any])]
  386. }
  387. if allKey.contains("mac-text") {
  388. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  389. }
  390. if allKey.contains("win-text") {
  391. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  392. }
  393. return model
  394. }
  395. func treeNodeParser(_ jsonData: [String: Any]) -> KMCompLight_tree {
  396. let allKey = jsonData.keys
  397. let model = KMCompLight_tree.init()
  398. if allKey.contains("base") {
  399. model.base = ["base" : baseNodeParser(jsonData["base"] as! [String : Any])]
  400. }
  401. if allKey.contains("mac-text") {
  402. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  403. }
  404. if allKey.contains("rename") {
  405. let subData = jsonData["rename"] as! [String : Any]
  406. let subKeys = subData.keys
  407. let submodel = KMCompLight_UIAttribute.init()
  408. if subKeys.contains("bg-text") {
  409. submodel.bg_text = ["bg-text" : uiStateParser(subData["bg-text"] as! [String : Any])]
  410. }
  411. if subKeys.contains("bg-field") {
  412. submodel.bg_field = ["bg-field" : valueTypeParser(subData["bg-field"] as! [String : Any])]
  413. }
  414. model.rename = ["rename" : submodel]
  415. }
  416. if allKey.contains("has-arrow") {
  417. model.has_arrow = ["has-arrow" : baseNodeParser(jsonData["has-arrow"] as! [String : Any])]
  418. }
  419. if allKey.contains("win-text") {
  420. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  421. }
  422. return model
  423. }
  424. func alertNodeParser(_ jsonData: [String: Any]) -> KMCompLight_alert {
  425. let allKey = jsonData.keys
  426. let model = KMCompLight_alert.init()
  427. if allKey.contains("mac-text") {
  428. model.mac_text = ["mac-text" : valueTypeParser(jsonData["mac-text"] as! [String : Any])]
  429. }
  430. if allKey.contains("win-text") {
  431. model.win_text = ["win-text" : valueTypeParser(jsonData["win-text"] as! [String : Any])]
  432. }
  433. if allKey.contains("bg") {
  434. model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])]
  435. }
  436. if allKey.contains("item-spacing") {
  437. model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])]
  438. }
  439. return model
  440. }
  441. func drawerNodeParser(_ jsonData: [String: Any]) -> KMCompLight_drawer {
  442. let allKey = jsonData.keys
  443. let model = KMCompLight_drawer.init()
  444. if allKey.contains("mac-text") {
  445. model.mac_text = ["mac-text" : valueTypeParser(jsonData["mac-text"] as! [String : Any])]
  446. }
  447. if allKey.contains("win-text") {
  448. model.win_text = ["win-text" : valueTypeParser(jsonData["win-text"] as! [String : Any])]
  449. }
  450. if allKey.contains("bg") {
  451. model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])]
  452. }
  453. if allKey.contains("item-spacing") {
  454. model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])]
  455. }
  456. return model
  457. }
  458. func notificationNodeParser(_ jsonData: [String: Any]) -> KMCompLight_notification {
  459. let allKey = jsonData.keys
  460. let model = KMCompLight_notification.init()
  461. if allKey.contains("toast") {
  462. model.toast = ["toast" : uiAttributeParser2(jsonData["toast"] as! [String : Any])]
  463. }
  464. if allKey.contains("modal") {
  465. let subData = jsonData["modal"] as! [String : Any]
  466. let subKeys = subData.keys
  467. let submodel = KMCompLight_UIAttribute.init()
  468. if subKeys.contains("bg") {
  469. submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])]
  470. }
  471. if subKeys.contains("item-spacing") {
  472. submodel.item_spacing = ["item-spacing" : valueTypeParser(subData["item-spacing"] as! [String : Any])]
  473. }
  474. if subKeys.contains("mac-text") {
  475. submodel.mac_text = ["mac-text" : uiStateParser(subData["mac-text"] as! [String : Any])]
  476. }
  477. if subKeys.contains("win-text") {
  478. submodel.win_text = ["win-text" : uiStateParser(subData["win-text"] as! [String : Any])]
  479. }
  480. model.modal = ["modal" : submodel]
  481. }
  482. return model
  483. }
  484. func tableNodeParser(_ jsonData: [String: Any]) -> KMCompLight_table {
  485. let allKey = jsonData.keys
  486. let model = KMCompLight_table.init()
  487. if allKey.contains("header") {
  488. model.header = ["header" : uiAttributeParser2(jsonData["header"] as! [String : Any])]
  489. }
  490. if allKey.contains("mac-text") {
  491. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  492. }
  493. if allKey.contains("list") {
  494. model.list = ["list" : tableListNodeParser(jsonData["list"] as! [String : Any])]
  495. }
  496. if allKey.contains("win-text") {
  497. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  498. }
  499. return model
  500. }
  501. func dividerNodeParser(_ jsonData: [String: Any]) -> KMCompLight_divider {
  502. let allKey = jsonData.keys
  503. let model = KMCompLight_divider.init()
  504. if allKey.contains("horiz") {
  505. model.horiz = ["horiz" : valueTypeParser(jsonData["horiz"] as! [String : Any])]
  506. }
  507. if allKey.contains("vert") {
  508. model.vert = ["vert" : valueTypeParser(jsonData["vert"] as! [String : Any])]
  509. }
  510. return model
  511. }
  512. // MARK:
  513. func sizeNodeParser(_ jsonData: [String: Any]) -> KMCompLight_sizeNode {
  514. let allKey = jsonData.keys
  515. let model = KMCompLight_sizeNode.init()
  516. if allKey.contains("s") {
  517. model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])]
  518. }
  519. if allKey.contains("m") {
  520. model.m = ["m" : uiAttributeParser(jsonData["m"] as! [String : Any])]
  521. }
  522. if allKey.contains("l") {
  523. model.l = ["l" : uiAttributeParser(jsonData["l"] as! [String : Any])]
  524. }
  525. return model
  526. }
  527. func tableListNodeParser(_ jsonData: [String: Any]) -> KMCompLight_tableListNode {
  528. let allKey = jsonData.keys
  529. let model = KMCompLight_tableListNode.init()
  530. if allKey.contains("file") {
  531. model.file = ["file" : uiAttributeParser3(jsonData["file"] as! [String : Any])]
  532. }
  533. if allKey.contains("batch") {
  534. model.batch = ["batch" : uiAttributeParser(jsonData["batch"] as! [String : Any])]
  535. }
  536. return model
  537. }
  538. func uiAttributeParser(_ jsonData: [String: Any]) -> KMCompLight_UIAttribute {
  539. //btn - cta - mac-text/
  540. let allKey = jsonData.keys
  541. let model = KMCompLight_UIAttribute.init()
  542. if allKey.contains("mac-text") {
  543. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  544. }
  545. if allKey.contains("bg") {
  546. model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])]
  547. }
  548. if allKey.contains("win-text") {
  549. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  550. }
  551. if allKey.contains("item-spacing") {
  552. model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])]
  553. }
  554. return model
  555. }
  556. func uiAttributeParser2(_ jsonData: [String: Any]) -> KMCompLight_UIAttribute {
  557. let allKey = jsonData.keys
  558. let model = KMCompLight_UIAttribute.init()
  559. if allKey.contains("mac-text") {
  560. model.mac_text = ["mac-text" : valueTypeParser(jsonData["mac-text"] as! [String : Any])]
  561. }
  562. if allKey.contains("bg") {
  563. model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])]
  564. }
  565. if allKey.contains("win-text") {
  566. model.win_text = ["win-text" : valueTypeParser(jsonData["win-text"] as! [String : Any])]
  567. }
  568. if allKey.contains("item-spacing") {
  569. model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])]
  570. }
  571. return model
  572. }
  573. func uiAttributeParser3(_ jsonData: [String: Any]) -> KMCompLight_UIAttribute {
  574. //btn - cta - mac-text/
  575. let allKey = jsonData.keys
  576. let model = KMCompLight_UIAttribute.init()
  577. if allKey.contains("mac-text") {
  578. model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])]
  579. }
  580. if allKey.contains("bg") {
  581. model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])]
  582. }
  583. if allKey.contains("win-text") {
  584. model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])]
  585. }
  586. if allKey.contains("item-spacing") {
  587. model.item_spacing = ["item-spacing" : uiStateParser(jsonData["item-spacing"] as! [String : Any])]
  588. }
  589. return model
  590. }
  591. func uiStateParser(_ jsonData: [String: Any]) -> KMCompLight_UIState {
  592. let allKey = jsonData.keys
  593. let model = KMCompLight_UIState.init()
  594. if allKey.contains("def") {
  595. model.def = ["def" : valueTypeParser(jsonData["def"] as! [String : Any])]
  596. }
  597. if allKey.contains("dis") {
  598. model.dis = ["dis" : valueTypeParser(jsonData["dis"] as! [String : Any])]
  599. }
  600. if allKey.contains("norm") {
  601. model.norm = ["norm" : valueTypeParser(jsonData["norm"] as! [String : Any])]
  602. }
  603. if allKey.contains("hov") {
  604. model.hov = ["hov" : valueTypeParser(jsonData["hov"] as! [String : Any])]
  605. }
  606. if allKey.contains("act") {
  607. model.act = ["act" : valueTypeParser(jsonData["act"] as! [String : Any])]
  608. }
  609. if allKey.contains("sel") {
  610. model.sel = ["sel" : valueTypeParser(jsonData["sel"] as! [String : Any])]
  611. }
  612. if allKey.contains("placeholder") {
  613. model.placeholder = ["placeholder" : valueTypeParser(jsonData["placeholder"] as! [String : Any])]
  614. }
  615. if allKey.contains("focus") {
  616. model.focus = ["focus" : valueTypeParser(jsonData["focus"] as! [String : Any])]
  617. }
  618. if allKey.contains("error-def") {
  619. model.error_def = ["error-def" : valueTypeParser(jsonData["error-def"] as! [String : Any])]
  620. }
  621. if allKey.contains("error-focus") {
  622. model.error_focus = ["error-focus" : valueTypeParser(jsonData["error-focus"] as! [String : Any])]
  623. }
  624. if allKey.contains("error") {
  625. model.error = ["error" : valueTypeParser(jsonData["error"] as! [String : Any])]
  626. }
  627. if allKey.contains("none") {
  628. model.none = ["none" : valueTypeParser(jsonData["none"] as! [String : Any])]
  629. }
  630. if allKey.contains("custom") {
  631. model.custom = ["custom" : valueTypeParser(jsonData["custom"] as! [String : Any])]
  632. }
  633. if allKey.contains("move") {
  634. model.move = ["move" : valueTypeParser(jsonData["move"] as! [String : Any])]
  635. }
  636. if allKey.contains("change") {
  637. model.change = ["change" : valueTypeParser(jsonData["change"] as! [String : Any])]
  638. }
  639. if allKey.contains("title") {
  640. model.title = ["title" : valueTypeParser(jsonData["title"] as! [String : Any])]
  641. }
  642. if allKey.contains("desc") {
  643. model.desc = ["desc" : valueTypeParser(jsonData["desc"] as! [String : Any])]
  644. }
  645. if allKey.contains("unsel") {
  646. model.unsel = ["unsel" : valueTypeParser(jsonData["unsel"] as! [String : Any])]
  647. }
  648. if allKey.contains("main") {
  649. model.main = ["main" : valueTypeParser(jsonData["main"] as! [String : Any])]
  650. }
  651. if allKey.contains("info") {
  652. model.info = ["info" : valueTypeParser(jsonData["info"] as! [String : Any])]
  653. }
  654. if allKey.contains("warning") {
  655. model.warning = ["warning" : valueTypeParser(jsonData["warning"] as! [String : Any])]
  656. }
  657. if allKey.contains("item") {
  658. model.item = ["item" : valueTypeParser(jsonData["item"] as! [String : Any])]
  659. }
  660. return model
  661. }
  662. func valueTypeParser(_ jsonData: [String: Any]) -> KMCompLight_valueType {
  663. let allKey = jsonData.keys
  664. let model = KMCompLight_valueType.init()
  665. if allKey.contains("value") {
  666. model.value = ["value" : uiValueParser(jsonData["value"] as! [String : Any])]
  667. }
  668. if allKey.contains("type") {
  669. model.type = ["type" : jsonData["type"] as! String]
  670. }
  671. return model
  672. }
  673. func uiValueParser(_ jsonData: [String: Any]) -> KMCompLight_UIValue {
  674. let allKey = jsonData.keys
  675. let model = KMCompLight_UIValue.init()
  676. if allKey.contains("fill") {
  677. model.fill = ["fill" : jsonData["fill"] as! String]
  678. }
  679. if allKey.contains("typography") {
  680. model.typography = ["typography" : jsonData["typography"] as! String]
  681. }
  682. if allKey.contains("height") {
  683. model.height = ["height" : jsonData["height"] as! String]
  684. }
  685. if allKey.contains("horizontalPadding") {
  686. model.horizontalPadding = ["horizontalPadding" : jsonData["horizontalPadding"] as! String]
  687. }
  688. if allKey.contains("borderRadius") {
  689. model.borderRadius = ["borderRadius" : jsonData["borderRadius"] as! String]
  690. }
  691. if allKey.contains("itemSpacing") {
  692. model.itemSpacing = ["itemSpacing" : jsonData["itemSpacing"] as! String]
  693. }
  694. if allKey.contains("borderWidth") {
  695. model.borderWidth = ["borderWidth" : jsonData["borderWidth"] as! String]
  696. }
  697. if allKey.contains("border") {
  698. model.border = ["border" : jsonData["border"] as! String]
  699. }
  700. if allKey.contains("borderRadiusTopLeft") {
  701. model.borderRadiusTopLeft = ["borderRadiusTopLeft" : jsonData["borderRadiusTopLeft"] as! String]
  702. }
  703. if allKey.contains("borderRadiusTopRight") {
  704. model.borderRadiusTopRight = ["borderRadiusTopRight" : jsonData["borderRadiusTopRight"] as! String]
  705. }
  706. if allKey.contains("borderWidthBottom") {
  707. model.borderWidthBottom = ["borderWidthBottom" : jsonData["borderWidthBottom"] as! String]
  708. }
  709. if allKey.contains("boxShadow") {
  710. model.boxShadow = ["boxShadow" : jsonData["boxShadow"] as! String]
  711. }
  712. if allKey.contains("paddingLeft") {
  713. model.paddingLeft = ["paddingLeft" : jsonData["paddingLeft"] as! String]
  714. }
  715. if allKey.contains("paddingRight") {
  716. model.paddingRight = ["paddingRight" : jsonData["paddingRight"] as! String]
  717. }
  718. if allKey.contains("paddingTop") {
  719. model.paddingTop = ["paddingTop" : jsonData["paddingTop"] as! String]
  720. }
  721. if allKey.contains("paddingBottom") {
  722. model.paddingBottom = ["paddingBottom" : jsonData["paddingBottom"] as! String]
  723. }
  724. return model
  725. }
  726. func progressBarParser(_ jsonData: [String: Any]) -> KMCompLight_progressBar {
  727. let allKey = jsonData.keys
  728. let model = KMCompLight_progressBar.init()
  729. if allKey.contains("track") {
  730. model.track = ["track" : valueTypeParser(jsonData["track"] as! [String : Any])]
  731. }
  732. if allKey.contains("track-filled") {
  733. model.track_filled = ["track-filled" : valueTypeParser(jsonData["track-filled"] as! [String : Any])]
  734. }
  735. return model
  736. }
  737. func baseNodeParser(_ jsonData: [String: Any]) -> KMCompLight_baseNode {
  738. let allKey = jsonData.keys
  739. let model = KMCompLight_baseNode.init()
  740. if allKey.contains("parent") {
  741. model.parent = ["parent" : uiAttributeParser(jsonData["parent"] as! [String : Any])]
  742. }
  743. if allKey.contains("children-lv2") {
  744. model.children_lv2 = ["children-lv2" : uiAttributeParser(jsonData["children-lv2"] as! [String : Any])]
  745. }
  746. if allKey.contains("children-lv3") {
  747. model.children_lv3 = ["children-lv3" : uiAttributeParser(jsonData["children-lv3"] as! [String : Any])]
  748. }
  749. if allKey.contains("children-lv4") {
  750. model.children_lv4 = ["children-lv4" : uiAttributeParser(jsonData["children-lv4"] as! [String : Any])]
  751. }
  752. return model
  753. }
  754. }
  755. // MARK: - Parser Action
  756. extension KMCompLightParser {
  757. func startJSONParse() -> [String : Any] {
  758. self.fileName = "comp-light"
  759. self.fileType = "json"
  760. return self.jsonParser
  761. }
  762. func parserValueNode(_ dict: [String : Any], _ tokenKey: String) -> Void {
  763. let valueDict = dict
  764. var tokenStr = tokenKey
  765. let allKey = valueDict.keys
  766. if allKey.contains("value") {
  767. let value = valueDict["value"]
  768. if (value is [String : String]) {
  769. var rootNode = value as! [String : Any]
  770. let rootNodeKeys = rootNode.keys
  771. for rootNodeKey in rootNodeKeys {
  772. let rootValue: String = rootNode[rootNodeKey] as! String
  773. if (rootValue.first == "{") && (rootValue.last == "}") {
  774. rootNode.updateValue(valueParser(key: rootValue), forKey: rootNodeKey)
  775. }
  776. }
  777. finalDict[tokenStr] = rootNode
  778. }
  779. } else {
  780. for node in allKey {
  781. if tokenKey == "" {
  782. tokenStr = node
  783. } else {
  784. tokenStr = String(format: "%@.%@", tokenKey, node)
  785. }
  786. parserValueNode(valueDict[node] as! [String : Any], tokenStr)
  787. }
  788. }
  789. }
  790. }