KMGlobalParser.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. //
  2. // KMGlobalParser.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2022/12/21.
  6. //
  7. import Cocoa
  8. class KMGlobalParser: KMBaseParser {
  9. func startParse() -> KMGlobal {
  10. self.fileName = "global"
  11. self.fileType = "json"
  12. return globalParser(self.jsonParser)
  13. }
  14. func globalParser(_ jsonData: [String: Any]) -> KMGlobal {
  15. let data = jsonData
  16. let allKey = data.keys
  17. let globalModel = KMGlobal.init()
  18. if allKey.contains("sizing") {
  19. globalModel.sizing = ["sizing" : sizingParser((data["sizing"] as! [String : Any]))]
  20. }
  21. if allKey.contains("spacing") {
  22. globalModel.spacing = ["spacing" : spacingParser((data["spacing"] as! [String : Any]))]
  23. }
  24. if allKey.contains("color") {
  25. globalModel.color = ["color" : colorParser((data["color"] as! [String : Any]))]
  26. }
  27. if allKey.contains("border-radius") {
  28. globalModel.border_radius = ["border-radius" : borderRadiusParser((data["border-radius"] as! [String : Any]))]
  29. }
  30. if allKey.contains("border-width") {
  31. globalModel.border_width = ["border-width" : borderWidthParser((data["border-width"] as! [String : Any]))]
  32. }
  33. if allKey.contains("shadow") {
  34. globalModel.shadow = ["shadow" : shadowParser((data["shadow"] as! [String : Any]))]
  35. }
  36. if allKey.contains("text-mac") {
  37. globalModel.text_mac = ["text-mac" : textMacParser((data["text-mac"] as! [String : Any]))]
  38. }
  39. if allKey.contains("text-windows") {
  40. globalModel.text_windows = ["text-windows" : textWindowsParser((data["text-windows"] as! [String : Any]))]
  41. }
  42. return globalModel
  43. }
  44. // MARK: sizing
  45. func sizingParser(_ jsonData: [String: Any]) -> KMGlobal_sizing {
  46. let allKey = jsonData.keys
  47. let model = KMGlobal_sizing.init()
  48. if allKey.contains("1") {
  49. model.sizing1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])]
  50. }
  51. if allKey.contains("4") {
  52. model.sizing4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])]
  53. }
  54. if allKey.contains("8") {
  55. model.sizing8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])]
  56. }
  57. if allKey.contains("10") {
  58. model.sizing10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])]
  59. }
  60. if allKey.contains("12") {
  61. model.sizing12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])]
  62. }
  63. if allKey.contains("14") {
  64. model.sizing14 = ["14" : valueTypeParser2(jsonData["14"] as! [String : Any])]
  65. }
  66. if allKey.contains("16") {
  67. model.sizing16 = ["16" : valueTypeParser2(jsonData["16"] as! [String : Any])]
  68. }
  69. if allKey.contains("18") {
  70. model.sizing18 = ["18" : valueTypeParser2(jsonData["18"] as! [String : Any])]
  71. }
  72. if allKey.contains("20") {
  73. model.sizing20 = ["20" : valueTypeParser2(jsonData["20"] as! [String : Any])]
  74. }
  75. if allKey.contains("21") {
  76. model.sizing21 = ["21" : valueTypeParser2(jsonData["21"] as! [String : Any])]
  77. }
  78. if allKey.contains("22") {
  79. model.sizing22 = ["22" : valueTypeParser2(jsonData["22"] as! [String : Any])]
  80. }
  81. if allKey.contains("24") {
  82. model.sizing24 = ["24" : valueTypeParser2(jsonData["24"] as! [String : Any])]
  83. }
  84. if allKey.contains("26") {
  85. model.sizing26 = ["26" : valueTypeParser2(jsonData["26"] as! [String : Any])]
  86. }
  87. if allKey.contains("28") {
  88. model.sizing28 = ["28" : valueTypeParser2(jsonData["28"] as! [String : Any])]
  89. }
  90. if allKey.contains("30") {
  91. model.sizing30 = ["30" : valueTypeParser2(jsonData["30"] as! [String : Any])]
  92. }
  93. if allKey.contains("32") {
  94. model.sizing32 = ["32" : valueTypeParser2(jsonData["32"] as! [String : Any])]
  95. }
  96. if allKey.contains("34") {
  97. model.sizing34 = ["34" : valueTypeParser2(jsonData["34"] as! [String : Any])]
  98. }
  99. if allKey.contains("36") {
  100. model.sizing36 = ["36" : valueTypeParser2(jsonData["36"] as! [String : Any])]
  101. }
  102. if allKey.contains("40") {
  103. model.sizing40 = ["40" : valueTypeParser2(jsonData["40"] as! [String : Any])]
  104. }
  105. if allKey.contains("48") {
  106. model.sizing48 = ["48" : valueTypeParser2(jsonData["48"] as! [String : Any])]
  107. }
  108. if allKey.contains("50") {
  109. model.sizing50 = ["50" : valueTypeParser2(jsonData["50"] as! [String : Any])]
  110. }
  111. if allKey.contains("58") {
  112. model.sizing58 = ["58" : valueTypeParser2(jsonData["58"] as! [String : Any])]
  113. }
  114. if allKey.contains("60") {
  115. model.sizing60 = ["60" : valueTypeParser2(jsonData["60"] as! [String : Any])]
  116. }
  117. if allKey.contains("64") {
  118. model.sizing64 = ["64" : valueTypeParser2(jsonData["64"] as! [String : Any])]
  119. }
  120. if allKey.contains("68") {
  121. model.sizing68 = ["68" : valueTypeParser2(jsonData["68"] as! [String : Any])]
  122. }
  123. if allKey.contains("72") {
  124. model.sizing72 = ["72" : valueTypeParser2(jsonData["72"] as! [String : Any])]
  125. }
  126. if allKey.contains("110") {
  127. model.sizing110 = ["110" : valueTypeParser2(jsonData["110"] as! [String : Any])]
  128. }
  129. if allKey.contains("116") {
  130. model.sizing116 = ["116" : valueTypeParser2(jsonData["116"] as! [String : Any])]
  131. }
  132. if allKey.contains("120") {
  133. model.sizing120 = ["120" : valueTypeParser2(jsonData["120"] as! [String : Any])]
  134. }
  135. if allKey.contains("132") {
  136. model.sizing132 = ["132" : valueTypeParser2(jsonData["132"] as! [String : Any])]
  137. }
  138. if allKey.contains("139") {
  139. model.sizing139 = ["139" : valueTypeParser2(jsonData["139"] as! [String : Any])]
  140. }
  141. if allKey.contains("180") {
  142. model.sizing180 = ["180" : valueTypeParser2(jsonData["180"] as! [String : Any])]
  143. }
  144. if allKey.contains("200") {
  145. model.sizing200 = ["200" : valueTypeParser2(jsonData["200"] as! [String : Any])]
  146. }
  147. if allKey.contains("228") {
  148. model.sizing228 = ["228" : valueTypeParser2(jsonData["228"] as! [String : Any])]
  149. }
  150. if allKey.contains("260") {
  151. model.sizing260 = ["260" : valueTypeParser2(jsonData["260"] as! [String : Any])]
  152. }
  153. return model
  154. }
  155. // MARK: spacing
  156. func spacingParser(_ jsonData: [String: Any]) -> KMGlobal_spacing {
  157. let allKey = jsonData.keys
  158. let model = KMGlobal_spacing.init()
  159. if allKey.contains("0") {
  160. model.spacing0 = ["0" : valueTypeParser2(jsonData["0"] as! [String : Any])]
  161. }
  162. if allKey.contains("1") {
  163. model.spacing1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])]
  164. }
  165. if allKey.contains("2") {
  166. model.spacing2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])]
  167. }
  168. if allKey.contains("4") {
  169. model.spacing4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])]
  170. }
  171. if allKey.contains("5") {
  172. model.spacing5 = ["5" : valueTypeParser2(jsonData["5"] as! [String : Any])]
  173. }
  174. if allKey.contains("6") {
  175. model.spacing6 = ["6" : valueTypeParser2(jsonData["6"] as! [String : Any])]
  176. }
  177. if allKey.contains("8") {
  178. model.spacing8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])]
  179. }
  180. if allKey.contains("10") {
  181. model.spacing10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])]
  182. }
  183. if allKey.contains("12") {
  184. model.spacing12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])]
  185. }
  186. if allKey.contains("16") {
  187. model.spacing16 = ["16" : valueTypeParser2(jsonData["16"] as! [String : Any])]
  188. }
  189. if allKey.contains("24") {
  190. model.spacing24 = ["24" : valueTypeParser2(jsonData["24"] as! [String : Any])]
  191. }
  192. if allKey.contains("32") {
  193. model.spacing32 = ["32" : valueTypeParser2(jsonData["32"] as! [String : Any])]
  194. }
  195. if allKey.contains("40") {
  196. model.spacing40 = ["40" : valueTypeParser2(jsonData["40"] as! [String : Any])]
  197. }
  198. if allKey.contains("56") {
  199. model.spacing56 = ["56" : valueTypeParser2(jsonData["56"] as! [String : Any])]
  200. }
  201. if allKey.contains("64") {
  202. model.spacing64 = ["64" : valueTypeParser2(jsonData["64"] as! [String : Any])]
  203. }
  204. if allKey.contains("80") {
  205. model.spacing80 = ["80" : valueTypeParser2(jsonData["80"] as! [String : Any])]
  206. }
  207. if allKey.contains("88") {
  208. model.spacing88 = ["88" : valueTypeParser2(jsonData["88"] as! [String : Any])]
  209. }
  210. return model
  211. }
  212. // MARK: color
  213. func colorParser(_ jsonData: [String: Any]) -> KMGlobal_color {
  214. let allKey = jsonData.keys
  215. let model = KMGlobal_color.init()
  216. if allKey.contains("light") {
  217. model.light = ["light" : colorValueParser(jsonData["light"] as! [String : Any])]
  218. }
  219. if allKey.contains("dark") {
  220. model.dark = ["dark" : colorValueParser(jsonData["dark"] as! [String : Any])]
  221. }
  222. return model
  223. }
  224. // MARK: border-radius
  225. func borderRadiusParser(_ jsonData: [String: Any]) -> KMGlobal_borderRadius {
  226. let allKey = jsonData.keys
  227. let model = KMGlobal_borderRadius.init()
  228. if allKey.contains("2") {
  229. model.number2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])]
  230. }
  231. if allKey.contains("4") {
  232. model.number4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])]
  233. }
  234. if allKey.contains("6") {
  235. model.number6 = ["6" : valueTypeParser2(jsonData["6"] as! [String : Any])]
  236. }
  237. if allKey.contains("8") {
  238. model.number8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])]
  239. }
  240. if allKey.contains("10") {
  241. model.number10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])]
  242. }
  243. if allKey.contains("12") {
  244. model.number12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])]
  245. }
  246. if allKey.contains("16") {
  247. model.number16 = ["16" : valueTypeParser2(jsonData["16"] as! [String : Any])]
  248. }
  249. if allKey.contains("20") {
  250. model.number20 = ["20" : valueTypeParser2(jsonData["20"] as! [String : Any])]
  251. }
  252. return model
  253. }
  254. // MARK: border-width
  255. func borderWidthParser(_ jsonData: [String: Any]) -> KMGlobal_borderWidth {
  256. let allKey = jsonData.keys
  257. let model = KMGlobal_borderWidth.init()
  258. if allKey.contains("1") {
  259. model.number1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])]
  260. }
  261. if allKey.contains("2") {
  262. model.number2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])]
  263. }
  264. return model
  265. }
  266. // MARK: shadow
  267. func shadowParser(_ jsonData: [String: Any]) -> KMGlobal_shadow {
  268. let allKey = jsonData.keys
  269. let model = KMGlobal_shadow.init()
  270. if allKey.contains("black-2-2") {
  271. model.black_2_2 = ["black-2-2" : valueTypeParser(jsonData["black-2-2"] as! [String : Any])]
  272. }
  273. if allKey.contains("black-4-8") {
  274. model.black_4_8 = ["black-4-8" : valueTypeParser(jsonData["black-4-8"] as! [String : Any])]
  275. }
  276. if allKey.contains("black-2-8") {
  277. model.black_2_8 = ["black-2-8" : valueTypeParser(jsonData["black-2-8"] as! [String : Any])]
  278. }
  279. if allKey.contains("blue-0-4") {
  280. model.blue_0_4 = ["blue-0-4" : valueTypeParser(jsonData["blue-0-4"] as! [String : Any])]
  281. }
  282. if allKey.contains("red-0-4") {
  283. model.red_0_4 = ["red-0-4" : valueTypeParser(jsonData["red-0-4"] as! [String : Any])]
  284. }
  285. return model
  286. }
  287. // MARK: text-mac
  288. func textMacParser(_ jsonData: [String: Any]) -> KMGlobal_textMac {
  289. let allKey = jsonData.keys
  290. let model = KMGlobal_textMac.init()
  291. if allKey.contains("regular") {
  292. model.regular = ["regular" : numberNodeParser(jsonData["regular"] as! [String : Any])]
  293. }
  294. if allKey.contains("semibold") {
  295. model.semibold = ["semibold" : numberNodeParser(jsonData["semibold"] as! [String : Any])]
  296. }
  297. return model
  298. }
  299. // MARK: text-windows
  300. func textWindowsParser(_ jsonData: [String: Any]) -> KMGlobal_textWindows {
  301. let allKey = jsonData.keys
  302. let model = KMGlobal_textWindows.init()
  303. if allKey.contains("regular") {
  304. model.regular = ["regular" : numberNodeParser(jsonData["regular"] as! [String : Any])]
  305. }
  306. if allKey.contains("semibold") {
  307. model.semibold = ["semibold" : numberNodeParser(jsonData["semibold"] as! [String : Any])]
  308. }
  309. return model
  310. }
  311. // MARK: -
  312. func numberNodeParser(_ jsonData: [String: Any]) -> KMGlobal_number {
  313. let allKey = jsonData.keys
  314. let model = KMGlobal_number.init()
  315. if allKey.contains("11") {
  316. model.number11 = ["11" : valueTypeParser(jsonData["11"] as! [String : Any])]
  317. }
  318. if allKey.contains("12") {
  319. model.number12 = ["12" : valueTypeParser(jsonData["12"] as! [String : Any])]
  320. }
  321. if allKey.contains("14") {
  322. model.number14 = ["14" : valueTypeParser(jsonData["14"] as! [String : Any])]
  323. }
  324. if allKey.contains("16") {
  325. model.number16 = ["16" : valueTypeParser(jsonData["16"] as! [String : Any])]
  326. }
  327. if allKey.contains("20") {
  328. model.number20 = ["20" : valueTypeParser(jsonData["20"] as! [String : Any])]
  329. }
  330. return model
  331. }
  332. func colorValueParser(_ jsonData: [String: Any]) -> KMGlobal_colorValue {
  333. let allKey = jsonData.keys
  334. let model = KMGlobal_colorValue.init()
  335. if allKey.contains("blue") {
  336. model.blue = ["blue" : colorNumberNodeParser(jsonData["blue"] as! [String : Any])]
  337. }
  338. if allKey.contains("gray") {
  339. model.gray = ["gray" : colorNumberNodeParser(jsonData["gray"] as! [String : Any])]
  340. }
  341. if allKey.contains("navy-blue") {
  342. model.navy_blue = ["navy-blue" : colorNumberNodeParser(jsonData["navy-blue"] as! [String : Any])]
  343. }
  344. if allKey.contains("green") {
  345. model.green = ["green" : colorNumberNodeParser(jsonData["green"] as! [String : Any])]
  346. }
  347. if allKey.contains("gold") {
  348. model.gold = ["gold" : colorNumberNodeParser(jsonData["gold"] as! [String : Any])]
  349. }
  350. if allKey.contains("red") {
  351. model.red = ["red" : colorNumberNodeParser(jsonData["red"] as! [String : Any])]
  352. }
  353. if allKey.contains("orange") {
  354. model.orange = ["orange" : colorNumberNodeParser(jsonData["orange"] as! [String : Any])]
  355. }
  356. if allKey.contains("cyan") {
  357. model.cyan = ["cyan" : colorNumberNodeParser(jsonData["cyan"] as! [String : Any])]
  358. }
  359. if allKey.contains("purple") {
  360. model.purple = ["purple" : colorNumberNodeParser(jsonData["purple"] as! [String : Any])]
  361. }
  362. if allKey.contains("pink") {
  363. model.pink = ["pink" : colorNumberNodeParser(jsonData["pink"] as! [String : Any])]
  364. }
  365. return model
  366. }
  367. func colorNumberNodeParser(_ jsonData: [String: Any]) -> KMGlobal_colorNumber {
  368. let allKey = jsonData.keys
  369. let model = KMGlobal_colorNumber.init()
  370. if allKey.contains("1") {
  371. model.number1 = ["1" : valueTypeParser2(jsonData["1"] as! [String : Any])]
  372. }
  373. if allKey.contains("2") {
  374. model.number2 = ["2" : valueTypeParser2(jsonData["2"] as! [String : Any])]
  375. }
  376. if allKey.contains("3") {
  377. model.number3 = ["3" : valueTypeParser2(jsonData["3"] as! [String : Any])]
  378. }
  379. if allKey.contains("4") {
  380. model.number4 = ["4" : valueTypeParser2(jsonData["4"] as! [String : Any])]
  381. }
  382. if allKey.contains("5") {
  383. model.number5 = ["5" : valueTypeParser2(jsonData["5"] as! [String : Any])]
  384. }
  385. if allKey.contains("6") {
  386. model.number6 = ["6" : valueTypeParser2(jsonData["6"] as! [String : Any])]
  387. }
  388. if allKey.contains("7") {
  389. model.number7 = ["7" : valueTypeParser2(jsonData["7"] as! [String : Any])]
  390. }
  391. if allKey.contains("8") {
  392. model.number8 = ["8" : valueTypeParser2(jsonData["8"] as! [String : Any])]
  393. }
  394. if allKey.contains("9") {
  395. model.number9 = ["9" : valueTypeParser2(jsonData["9"] as! [String : Any])]
  396. }
  397. if allKey.contains("10") {
  398. model.number10 = ["10" : valueTypeParser2(jsonData["10"] as! [String : Any])]
  399. }
  400. if allKey.contains("11") {
  401. model.number11 = ["11" : valueTypeParser2(jsonData["11"] as! [String : Any])]
  402. }
  403. if allKey.contains("12") {
  404. model.number12 = ["12" : valueTypeParser2(jsonData["12"] as! [String : Any])]
  405. }
  406. return model
  407. }
  408. func valueTypeParser(_ jsonData: [String: Any]) -> KMGlobal_valueType {
  409. let allKey = jsonData.keys
  410. let model = KMGlobal_valueType.init()
  411. if allKey.contains("value") {
  412. model.value = ["value" : uiValueParser(jsonData["value"] as! [String : Any])]
  413. }
  414. if allKey.contains("type") {
  415. model.type = ["type" : jsonData["type"] as! String]
  416. }
  417. return model
  418. }
  419. func valueTypeParser2(_ jsonData: [String: Any]) -> KMGlobal_valueType {
  420. let allKey = jsonData.keys
  421. let model = KMGlobal_valueType.init()
  422. if allKey.contains("value") {
  423. model.value = ["value" : jsonData["value"] as! String]
  424. }
  425. if allKey.contains("type") {
  426. model.type = ["type" : jsonData["type"] as! String]
  427. }
  428. return model
  429. }
  430. func uiValueParser(_ jsonData: [String: Any]) -> KMGlobal_UIValue {
  431. let allKey = jsonData.keys
  432. let model = KMGlobal_UIValue.init()
  433. if allKey.contains("fontFamily") {
  434. model.fontFamily = ["fontFamily" : jsonData["fontFamily"] as! String]
  435. }
  436. if allKey.contains("fontWeight") {
  437. model.fontWeight = ["fontWeight" : jsonData["fontWeight"] as! String]
  438. }
  439. if allKey.contains("lineHeight") {
  440. model.lineHeight = ["lineHeight" : jsonData["lineHeight"] as! String]
  441. }
  442. if allKey.contains("fontSize") {
  443. model.fontSize = ["fontSize" : jsonData["fontSize"] as! String]
  444. }
  445. if allKey.contains("x") {
  446. model.x = ["x" : jsonData["x"] as! String]
  447. }
  448. if allKey.contains("y") {
  449. model.y = ["y" : jsonData["y"] as! String]
  450. }
  451. if allKey.contains("blur") {
  452. model.blur = ["blur" : jsonData["blur"] as! String]
  453. }
  454. if allKey.contains("spread") {
  455. model.spread = ["spread" : jsonData["spread"] as! String]
  456. }
  457. if allKey.contains("color") {
  458. model.color = ["color" : jsonData["color"] as! String]
  459. }
  460. if allKey.contains("type") {
  461. model.type = ["type" : jsonData["type"] as! String]
  462. }
  463. return model
  464. }
  465. }
  466. // MARK: - Parser Action
  467. extension KMGlobalParser {
  468. func startJSONParse() -> [String : Any] {
  469. self.fileName = "global"
  470. self.fileType = "json"
  471. return self.jsonParser
  472. }
  473. }