ag-psd 30.1.1 → 31.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/.v8-cache/v24.13.1-x64-cf738c9d/017325ac +0 -0
  2. package/.v8-cache/v24.13.1-x64-cf738c9d/01e5e61b +0 -0
  3. package/.v8-cache/v24.13.1-x64-cf738c9d/043c7b90 +0 -0
  4. package/.v8-cache/v24.13.1-x64-cf738c9d/05135617 +0 -0
  5. package/.v8-cache/v24.13.1-x64-cf738c9d/059f8558 +0 -0
  6. package/.v8-cache/v24.13.1-x64-cf738c9d/06423db9 +0 -0
  7. package/.v8-cache/v24.13.1-x64-cf738c9d/06e765df +0 -0
  8. package/.v8-cache/v24.13.1-x64-cf738c9d/0706ecb8 +0 -0
  9. package/.v8-cache/v24.13.1-x64-cf738c9d/0930679d +0 -0
  10. package/.v8-cache/v24.13.1-x64-cf738c9d/09519a62 +0 -0
  11. package/.v8-cache/v24.13.1-x64-cf738c9d/0a6607b0 +0 -0
  12. package/.v8-cache/v24.13.1-x64-cf738c9d/0ad8fa6e +0 -0
  13. package/.v8-cache/v24.13.1-x64-cf738c9d/0d390e10 +0 -0
  14. package/.v8-cache/v24.13.1-x64-cf738c9d/0db754a7 +0 -0
  15. package/.v8-cache/v24.13.1-x64-cf738c9d/0dfa7b16 +0 -0
  16. package/.v8-cache/v24.13.1-x64-cf738c9d/0e9e09db +0 -0
  17. package/.v8-cache/v24.13.1-x64-cf738c9d/1130885f +0 -0
  18. package/.v8-cache/v24.13.1-x64-cf738c9d/1222cb8c +0 -0
  19. package/.v8-cache/v24.13.1-x64-cf738c9d/15e2c039 +0 -0
  20. package/.v8-cache/v24.13.1-x64-cf738c9d/15f0e479 +0 -0
  21. package/.v8-cache/v24.13.1-x64-cf738c9d/1a2d469d +0 -0
  22. package/.v8-cache/v24.13.1-x64-cf738c9d/1b300c82 +0 -0
  23. package/.v8-cache/v24.13.1-x64-cf738c9d/1bc3d370 +0 -0
  24. package/.v8-cache/v24.13.1-x64-cf738c9d/1e44e5af +0 -0
  25. package/.v8-cache/v24.13.1-x64-cf738c9d/1efa10a1 +0 -0
  26. package/.v8-cache/v24.13.1-x64-cf738c9d/1f6c8743 +0 -0
  27. package/.v8-cache/v24.13.1-x64-cf738c9d/20477c23 +0 -0
  28. package/.v8-cache/v24.13.1-x64-cf738c9d/20b27e40 +0 -0
  29. package/.v8-cache/v24.13.1-x64-cf738c9d/20dfa422 +0 -0
  30. package/.v8-cache/v24.13.1-x64-cf738c9d/257c62ba +0 -0
  31. package/.v8-cache/v24.13.1-x64-cf738c9d/25d60154 +0 -0
  32. package/.v8-cache/v24.13.1-x64-cf738c9d/26f822f3 +0 -0
  33. package/.v8-cache/v24.13.1-x64-cf738c9d/2a19133e +0 -0
  34. package/.v8-cache/v24.13.1-x64-cf738c9d/2a1e2a8d +0 -0
  35. package/.v8-cache/v24.13.1-x64-cf738c9d/2b02fded +0 -0
  36. package/.v8-cache/v24.13.1-x64-cf738c9d/2b069ee0 +0 -0
  37. package/.v8-cache/v24.13.1-x64-cf738c9d/2c76dc0d +0 -0
  38. package/.v8-cache/v24.13.1-x64-cf738c9d/2de09439 +0 -0
  39. package/.v8-cache/v24.13.1-x64-cf738c9d/2deb286a +0 -0
  40. package/.v8-cache/v24.13.1-x64-cf738c9d/2e44f5f0 +0 -0
  41. package/.v8-cache/v24.13.1-x64-cf738c9d/2fb229a9 +0 -0
  42. package/.v8-cache/v24.13.1-x64-cf738c9d/3144b401 +0 -0
  43. package/.v8-cache/v24.13.1-x64-cf738c9d/32018e44 +0 -0
  44. package/.v8-cache/v24.13.1-x64-cf738c9d/341402c3 +0 -0
  45. package/.v8-cache/v24.13.1-x64-cf738c9d/34e0fa2e +0 -0
  46. package/.v8-cache/v24.13.1-x64-cf738c9d/37481985 +0 -0
  47. package/.v8-cache/v24.13.1-x64-cf738c9d/3bbf643e +0 -0
  48. package/.v8-cache/v24.13.1-x64-cf738c9d/3ceff89e +0 -0
  49. package/.v8-cache/v24.13.1-x64-cf738c9d/404f5cdc +0 -0
  50. package/.v8-cache/v24.13.1-x64-cf738c9d/4087aa2b +0 -0
  51. package/.v8-cache/v24.13.1-x64-cf738c9d/4376c1f9 +0 -0
  52. package/.v8-cache/v24.13.1-x64-cf738c9d/44903df4 +0 -0
  53. package/.v8-cache/v24.13.1-x64-cf738c9d/44d58dc8 +0 -0
  54. package/.v8-cache/v24.13.1-x64-cf738c9d/4511bacf +0 -0
  55. package/.v8-cache/v24.13.1-x64-cf738c9d/47da0ce8 +0 -0
  56. package/.v8-cache/v24.13.1-x64-cf738c9d/48cd54a9 +0 -0
  57. package/.v8-cache/v24.13.1-x64-cf738c9d/49d22b79 +0 -0
  58. package/.v8-cache/v24.13.1-x64-cf738c9d/4d938476 +0 -0
  59. package/.v8-cache/v24.13.1-x64-cf738c9d/4ec6d390 +0 -0
  60. package/.v8-cache/v24.13.1-x64-cf738c9d/4f5702bd +0 -0
  61. package/.v8-cache/v24.13.1-x64-cf738c9d/514cc428 +0 -0
  62. package/.v8-cache/v24.13.1-x64-cf738c9d/557d3b42 +0 -0
  63. package/.v8-cache/v24.13.1-x64-cf738c9d/56abbff7 +0 -0
  64. package/.v8-cache/v24.13.1-x64-cf738c9d/57b540ee +0 -0
  65. package/.v8-cache/v24.13.1-x64-cf738c9d/57d3380b +0 -0
  66. package/.v8-cache/v24.13.1-x64-cf738c9d/5e20c081 +0 -0
  67. package/.v8-cache/v24.13.1-x64-cf738c9d/6024ce3f +0 -0
  68. package/.v8-cache/v24.13.1-x64-cf738c9d/61735b23 +0 -0
  69. package/.v8-cache/v24.13.1-x64-cf738c9d/63dbdb75 +0 -0
  70. package/.v8-cache/v24.13.1-x64-cf738c9d/651c4ada +0 -0
  71. package/.v8-cache/v24.13.1-x64-cf738c9d/652a0d59 +0 -0
  72. package/.v8-cache/v24.13.1-x64-cf738c9d/6a0e89ee +0 -0
  73. package/.v8-cache/v24.13.1-x64-cf738c9d/6af33b91 +0 -0
  74. package/.v8-cache/v24.13.1-x64-cf738c9d/6c2562d2 +0 -0
  75. package/.v8-cache/v24.13.1-x64-cf738c9d/6cbfc0ec +0 -0
  76. package/.v8-cache/v24.13.1-x64-cf738c9d/6dae0cfa +0 -0
  77. package/.v8-cache/v24.13.1-x64-cf738c9d/6e2529ce +0 -0
  78. package/.v8-cache/v24.13.1-x64-cf738c9d/6f08372c +0 -0
  79. package/.v8-cache/v24.13.1-x64-cf738c9d/7100ee08 +0 -0
  80. package/.v8-cache/v24.13.1-x64-cf738c9d/71df9cb3 +0 -0
  81. package/.v8-cache/v24.13.1-x64-cf738c9d/72e1d543 +0 -0
  82. package/.v8-cache/v24.13.1-x64-cf738c9d/75519c80 +0 -0
  83. package/.v8-cache/v24.13.1-x64-cf738c9d/75e41e43 +0 -0
  84. package/.v8-cache/v24.13.1-x64-cf738c9d/79bf115c +0 -0
  85. package/.v8-cache/v24.13.1-x64-cf738c9d/7a39347c +0 -0
  86. package/.v8-cache/v24.13.1-x64-cf738c9d/7b83e3d3 +0 -0
  87. package/.v8-cache/v24.13.1-x64-cf738c9d/7cd71bc5 +0 -0
  88. package/.v8-cache/v24.13.1-x64-cf738c9d/7da78512 +0 -0
  89. package/.v8-cache/v24.13.1-x64-cf738c9d/7ea06cea +0 -0
  90. package/.v8-cache/v24.13.1-x64-cf738c9d/82c3b573 +0 -0
  91. package/.v8-cache/v24.13.1-x64-cf738c9d/84c186e4 +0 -0
  92. package/.v8-cache/v24.13.1-x64-cf738c9d/8568576b +0 -0
  93. package/.v8-cache/v24.13.1-x64-cf738c9d/8607bd36 +0 -0
  94. package/.v8-cache/v24.13.1-x64-cf738c9d/87372817 +0 -0
  95. package/.v8-cache/v24.13.1-x64-cf738c9d/87cf2209 +0 -0
  96. package/.v8-cache/v24.13.1-x64-cf738c9d/882aaa05 +0 -0
  97. package/.v8-cache/v24.13.1-x64-cf738c9d/8a4d3de8 +0 -0
  98. package/.v8-cache/v24.13.1-x64-cf738c9d/8e223473 +0 -0
  99. package/.v8-cache/v24.13.1-x64-cf738c9d/92b7aefd +0 -0
  100. package/.v8-cache/v24.13.1-x64-cf738c9d/932f0770 +0 -0
  101. package/.v8-cache/v24.13.1-x64-cf738c9d/937c03a1 +0 -0
  102. package/.v8-cache/v24.13.1-x64-cf738c9d/991e4758 +0 -0
  103. package/.v8-cache/v24.13.1-x64-cf738c9d/9af658fb +0 -0
  104. package/.v8-cache/v24.13.1-x64-cf738c9d/9ed80ba5 +0 -0
  105. package/.v8-cache/v24.13.1-x64-cf738c9d/9f0dc993 +0 -0
  106. package/.v8-cache/v24.13.1-x64-cf738c9d/a19c0c4f +0 -0
  107. package/.v8-cache/v24.13.1-x64-cf738c9d/a6409d95 +0 -0
  108. package/.v8-cache/v24.13.1-x64-cf738c9d/a79a40bb +0 -0
  109. package/.v8-cache/v24.13.1-x64-cf738c9d/a7e80865 +0 -0
  110. package/.v8-cache/v24.13.1-x64-cf738c9d/ac9802c6 +0 -0
  111. package/.v8-cache/v24.13.1-x64-cf738c9d/acc36e66 +0 -0
  112. package/.v8-cache/v24.13.1-x64-cf738c9d/ad11e2dc +0 -0
  113. package/.v8-cache/v24.13.1-x64-cf738c9d/b0c8fcd8 +0 -0
  114. package/.v8-cache/v24.13.1-x64-cf738c9d/b1762958 +0 -0
  115. package/.v8-cache/v24.13.1-x64-cf738c9d/b3c2fab7 +0 -0
  116. package/.v8-cache/v24.13.1-x64-cf738c9d/b5b3329b +0 -0
  117. package/.v8-cache/v24.13.1-x64-cf738c9d/b69ed3a3 +0 -0
  118. package/.v8-cache/v24.13.1-x64-cf738c9d/b806679e +0 -0
  119. package/.v8-cache/v24.13.1-x64-cf738c9d/bc1cdd48 +0 -0
  120. package/.v8-cache/v24.13.1-x64-cf738c9d/bc7ebd1d +0 -0
  121. package/.v8-cache/v24.13.1-x64-cf738c9d/bdff1628 +0 -0
  122. package/.v8-cache/v24.13.1-x64-cf738c9d/c0b789d2 +0 -0
  123. package/.v8-cache/v24.13.1-x64-cf738c9d/c314aece +0 -0
  124. package/.v8-cache/v24.13.1-x64-cf738c9d/c399a5dc +0 -0
  125. package/.v8-cache/v24.13.1-x64-cf738c9d/c681cbc8 +0 -0
  126. package/.v8-cache/v24.13.1-x64-cf738c9d/c6834ffc +0 -0
  127. package/.v8-cache/v24.13.1-x64-cf738c9d/c6f12ed5 +0 -0
  128. package/.v8-cache/v24.13.1-x64-cf738c9d/cb0f0a3d +0 -0
  129. package/.v8-cache/v24.13.1-x64-cf738c9d/cbcb7c95 +0 -0
  130. package/.v8-cache/v24.13.1-x64-cf738c9d/cdd9107c +0 -0
  131. package/.v8-cache/v24.13.1-x64-cf738c9d/cdf2c4a3 +0 -0
  132. package/.v8-cache/v24.13.1-x64-cf738c9d/cfc49f4f +0 -0
  133. package/.v8-cache/v24.13.1-x64-cf738c9d/cff9434a +0 -0
  134. package/.v8-cache/v24.13.1-x64-cf738c9d/d02dd6f7 +0 -0
  135. package/.v8-cache/v24.13.1-x64-cf738c9d/d0507bf3 +0 -0
  136. package/.v8-cache/v24.13.1-x64-cf738c9d/d60fce19 +0 -0
  137. package/.v8-cache/v24.13.1-x64-cf738c9d/d733d619 +0 -0
  138. package/.v8-cache/v24.13.1-x64-cf738c9d/d75b7803 +0 -0
  139. package/.v8-cache/v24.13.1-x64-cf738c9d/dc86f000 +0 -0
  140. package/.v8-cache/v24.13.1-x64-cf738c9d/de74e659 +0 -0
  141. package/.v8-cache/v24.13.1-x64-cf738c9d/defa4f7f +0 -0
  142. package/.v8-cache/v24.13.1-x64-cf738c9d/e03e2acd +0 -0
  143. package/.v8-cache/v24.13.1-x64-cf738c9d/e0e3f52c +0 -0
  144. package/.v8-cache/v24.13.1-x64-cf738c9d/e158d332 +0 -0
  145. package/.v8-cache/v24.13.1-x64-cf738c9d/e6735171 +0 -0
  146. package/.v8-cache/v24.13.1-x64-cf738c9d/e6745c2b +0 -0
  147. package/.v8-cache/v24.13.1-x64-cf738c9d/e6b99945 +0 -0
  148. package/.v8-cache/v24.13.1-x64-cf738c9d/e6d8ceb8 +0 -0
  149. package/.v8-cache/v24.13.1-x64-cf738c9d/e7ffec37 +0 -0
  150. package/.v8-cache/v24.13.1-x64-cf738c9d/ea33b6de +0 -0
  151. package/.v8-cache/v24.13.1-x64-cf738c9d/eaafa3c4 +0 -0
  152. package/.v8-cache/v24.13.1-x64-cf738c9d/ebb50fca +0 -0
  153. package/.v8-cache/v24.13.1-x64-cf738c9d/ec805f2e +0 -0
  154. package/.v8-cache/v24.13.1-x64-cf738c9d/edaef8f1 +0 -0
  155. package/.v8-cache/v24.13.1-x64-cf738c9d/ee4401c8 +0 -0
  156. package/.v8-cache/v24.13.1-x64-cf738c9d/eeeebdfe +0 -0
  157. package/.v8-cache/v24.13.1-x64-cf738c9d/f3d51676 +0 -0
  158. package/.v8-cache/v24.13.1-x64-cf738c9d/f7b50a75 +0 -0
  159. package/.v8-cache/v24.13.1-x64-cf738c9d/fa58ca72 +0 -0
  160. package/.v8-cache/v24.13.1-x64-cf738c9d/fbca6276 +0 -0
  161. package/.v8-cache/v24.13.1-x64-cf738c9d/fc97d72d +0 -0
  162. package/.v8-cache/v24.13.1-x64-cf738c9d/fd0a2987 +0 -0
  163. package/CHANGELOG.md +9 -0
  164. package/README.md +65 -1
  165. package/README_PSD.md +1 -1
  166. package/TODO.md +2 -0
  167. package/dist/abr.d.ts +196 -196
  168. package/dist/abr.js +364 -378
  169. package/dist/abr.js.map +1 -1
  170. package/dist/additionalInfo.d.ts +26 -26
  171. package/dist/additionalInfo.js +3478 -3516
  172. package/dist/additionalInfo.js.map +1 -1
  173. package/dist/ase.d.ts +32 -32
  174. package/dist/ase.js +81 -82
  175. package/dist/ase.js.map +1 -1
  176. package/dist/bundle.js +12380 -12445
  177. package/dist/csh.d.ts +10 -10
  178. package/dist/csh.js +35 -47
  179. package/dist/csh.js.map +1 -1
  180. package/dist/descriptor.d.ts +601 -601
  181. package/dist/descriptor.js +2003 -2038
  182. package/dist/descriptor.js.map +1 -1
  183. package/dist/effectsHelpers.d.ts +5 -5
  184. package/dist/effectsHelpers.js +286 -308
  185. package/dist/effectsHelpers.js.map +1 -1
  186. package/dist/engineData.d.ts +2 -2
  187. package/dist/engineData.js +334 -341
  188. package/dist/engineData.js.map +1 -1
  189. package/dist/engineData2.d.ts +2 -2
  190. package/dist/engineData2.js +409 -411
  191. package/dist/engineData2.js.map +1 -1
  192. package/dist/helpers.d.ts +74 -74
  193. package/dist/helpers.js +353 -348
  194. package/dist/helpers.js.map +1 -1
  195. package/dist/imageResources.d.ts +17 -17
  196. package/dist/imageResources.js +1040 -1079
  197. package/dist/imageResources.js.map +1 -1
  198. package/dist/index.d.ts +20 -22
  199. package/dist/index.js +61 -56
  200. package/dist/index.js.map +1 -1
  201. package/dist/initializeCanvas.d.ts +1 -1
  202. package/dist/initializeCanvas.js +9 -10
  203. package/dist/initializeCanvas.js.map +1 -1
  204. package/dist/jpeg.d.ts +1 -1
  205. package/dist/jpeg.js +1020 -1021
  206. package/dist/jpeg.js.map +1 -1
  207. package/dist/psd.d.ts +1877 -1873
  208. package/dist/psd.js +45 -45
  209. package/dist/psd.js.map +1 -1
  210. package/dist/psdReader.d.ts +52 -45
  211. package/dist/psdReader.js +1385 -1293
  212. package/dist/psdReader.js.map +1 -1
  213. package/dist/psdWriter.d.ts +34 -33
  214. package/dist/psdWriter.js +834 -805
  215. package/dist/psdWriter.js.map +1 -1
  216. package/dist/text.d.ts +179 -179
  217. package/dist/text.js +552 -577
  218. package/dist/text.js.map +1 -1
  219. package/dist/utf8.d.ts +4 -6
  220. package/dist/utf8.js +156 -157
  221. package/dist/utf8.js.map +1 -1
  222. package/dist-es/abr.d.ts +196 -196
  223. package/dist-es/abr.js +364 -374
  224. package/dist-es/abr.js.map +1 -1
  225. package/dist-es/additionalInfo.d.ts +26 -26
  226. package/dist-es/additionalInfo.js +3478 -3510
  227. package/dist-es/additionalInfo.js.map +1 -1
  228. package/dist-es/ase.d.ts +32 -32
  229. package/dist-es/ase.js +81 -78
  230. package/dist-es/ase.js.map +1 -1
  231. package/dist-es/csh.d.ts +10 -10
  232. package/dist-es/csh.js +35 -43
  233. package/dist-es/csh.js.map +1 -1
  234. package/dist-es/descriptor.d.ts +601 -601
  235. package/dist-es/descriptor.js +2003 -2005
  236. package/dist-es/descriptor.js.map +1 -1
  237. package/dist-es/effectsHelpers.d.ts +5 -5
  238. package/dist-es/effectsHelpers.js +286 -303
  239. package/dist-es/effectsHelpers.js.map +1 -1
  240. package/dist-es/engineData.d.ts +2 -2
  241. package/dist-es/engineData.js +334 -336
  242. package/dist-es/engineData.js.map +1 -1
  243. package/dist-es/engineData2.d.ts +2 -2
  244. package/dist-es/engineData2.js +409 -407
  245. package/dist-es/engineData2.js.map +1 -1
  246. package/dist-es/helpers.d.ts +74 -74
  247. package/dist-es/helpers.js +353 -330
  248. package/dist-es/helpers.js.map +1 -1
  249. package/dist-es/imageResources.d.ts +17 -17
  250. package/dist-es/imageResources.js +1040 -1076
  251. package/dist-es/imageResources.js.map +1 -1
  252. package/dist-es/index.d.ts +20 -22
  253. package/dist-es/index.js +61 -33
  254. package/dist-es/index.js.map +1 -1
  255. package/dist-es/initializeCanvas.d.ts +1 -1
  256. package/dist-es/initializeCanvas.js +9 -6
  257. package/dist-es/initializeCanvas.js.map +1 -1
  258. package/dist-es/jpeg.d.ts +1 -1
  259. package/dist-es/jpeg.js +1020 -1017
  260. package/dist-es/jpeg.js.map +1 -1
  261. package/dist-es/psd.d.ts +1877 -1873
  262. package/dist-es/psd.js +45 -42
  263. package/dist-es/psd.js.map +1 -1
  264. package/dist-es/psdReader.d.ts +52 -45
  265. package/dist-es/psdReader.js +1385 -1255
  266. package/dist-es/psdReader.js.map +1 -1
  267. package/dist-es/psdWriter.d.ts +34 -33
  268. package/dist-es/psdWriter.js +834 -776
  269. package/dist-es/psdWriter.js.map +1 -1
  270. package/dist-es/text.d.ts +179 -179
  271. package/dist-es/text.js +552 -572
  272. package/dist-es/text.js.map +1 -1
  273. package/dist-es/utf8.d.ts +4 -6
  274. package/dist-es/utf8.js +156 -150
  275. package/dist-es/utf8.js.map +1 -1
  276. package/package.json +4 -3
  277. package/publish.js +24 -0
  278. package/src/additionalInfo.ts +15 -11
  279. package/src/helpers.ts +13 -3
  280. package/src/index.ts +4 -6
  281. package/src/psd.ts +4 -0
  282. package/src/psdReader.ts +136 -43
  283. package/src/psdWriter.ts +118 -24
  284. package/tsconfig-es6.json +2 -1
  285. package/tsconfig.json +5 -3
@@ -1,2039 +1,2004 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ESliceOrigin = exports.ESliceVertAlign = exports.ESliceHorzAlign = exports.ESliceType = exports.FrFl = exports.FStl = exports.ClrS = exports.gradientInterpolationMethodType = exports.stdTrackID = exports.animInterpStyleEnum = exports.GrdT = exports.IGSr = exports.BETE = exports.BESs = exports.bvlT = exports.BESl = exports.BlnM = exports.warpStyle = exports.Annt = exports.Ornt = exports.textGridding = exports.frac = exports.unitsValue = exports.unitsPercentF = exports.unitsPercent = exports.unitsAngle = exports.parseUnitsToNumber = exports.parseUnitsOrNumber = exports.parseUnits = exports.parsePercentOrAngle = exports.parsePercent = exports.parseAngle = exports.serializeColor = exports.parseColor = exports.serializeVectorContent = exports.parseVectorContent = exports.serializeTrackList = exports.parseTrackList = exports.parseEffects = exports.serializeEffects = exports.boundsToDescBounds = exports.descBoundsToBounds = exports.xyToHorzVrtc = exports.horzVrtcToXY = exports.writeVersionAndDescriptor = exports.readVersionAndDescriptor = exports.writeDescriptorStructure = exports.readDescriptorStructure = exports.readAsciiStringOrClassId = exports.setLogErrors = void 0;
26
- exports.presetKindType = exports.prjM = exports.FlMd = exports.IntC = exports.IntE = exports.Drct = exports.WndM = exports.CntE = exports.FlCl = exports.ExtR = exports.ExtT = exports.DfsM = exports.blurType = exports.Lns = exports.MztT = exports.Chnl = exports.Dstr = exports.ZZTy = exports.Wvtp = exports.SphM = exports.RplS = exports.Cnvr = exports.UndA = exports.DspM = exports.SmBQ = exports.SmBM = exports.BlrQ = exports.BlrM = exports.strokeStyleLineAlignment = exports.strokeStyleLineJoinType = exports.strokeStyleLineCapType = exports.ESliceBGColorType = void 0;
27
- var helpers_1 = require("./helpers");
28
- var psdReader_1 = require("./psdReader");
29
- var psdWriter_1 = require("./psdWriter");
30
- function revMap(map) {
31
- var result = {};
32
- Object.keys(map).forEach(function (key) { return result[map[key]] = key; });
33
- return result;
34
- }
35
- var unitsMap = {
36
- '#Ang': 'Angle',
37
- '#Rsl': 'Density',
38
- '#Rlt': 'Distance',
39
- '#Nne': 'None',
40
- '#Prc': 'Percent',
41
- '#Pxl': 'Pixels',
42
- '#Mlm': 'Millimeters',
43
- '#Pnt': 'Points',
44
- 'RrPi': 'Picas',
45
- 'RrIn': 'Inches',
46
- 'RrCm': 'Centimeters',
47
- };
48
- var unitsMapRev = revMap(unitsMap);
49
- var logErrors = false;
50
- function setLogErrors(value) {
51
- logErrors = value;
52
- }
53
- exports.setLogErrors = setLogErrors;
54
- function makeType(name, classID) {
55
- return { name: name, classID: classID };
56
- }
57
- var nullType = makeType('', 'null');
58
- var USE_CHINESE = false; // Testing
59
- var fieldToExtType = {
60
- strokeStyleContent: makeType('', 'solidColorLayer'),
61
- printProofSetup: makeType(USE_CHINESE ? '校样设置' : 'Proof Setup', 'proofSetup'),
62
- Grad: makeType(USE_CHINESE ? '渐变' : 'Gradient', 'Grdn'),
63
- Trnf: makeType(USE_CHINESE ? '变换' : 'Transform', 'Trnf'),
64
- patternFill: makeType('', 'patternFill'),
65
- ebbl: makeType('', 'ebbl'),
66
- SoFi: makeType('', 'SoFi'),
67
- GrFl: makeType('', 'GrFl'),
68
- sdwC: makeType('', 'RGBC'),
69
- hglC: makeType('', 'RGBC'),
70
- 'Clr ': makeType('', 'RGBC'),
71
- 'tintColor': makeType('', 'RGBC'),
72
- Ofst: makeType('', 'Pnt '),
73
- ChFX: makeType('', 'ChFX'),
74
- MpgS: makeType('', 'ShpC'),
75
- DrSh: makeType('', 'DrSh'),
76
- IrSh: makeType('', 'IrSh'),
77
- OrGl: makeType('', 'OrGl'),
78
- IrGl: makeType('', 'IrGl'),
79
- TrnS: makeType('', 'ShpC'),
80
- Ptrn: makeType('', 'Ptrn'),
81
- FrFX: makeType('', 'FrFX'),
82
- phase: makeType('', 'Pnt '),
83
- frameStep: nullType,
84
- duration: nullType,
85
- workInTime: nullType,
86
- workOutTime: nullType,
87
- audioClipGroupList: nullType,
88
- bounds: makeType('', 'Rctn'),
89
- customEnvelopeWarp: makeType('', 'customEnvelopeWarp'),
90
- warp: makeType('', 'warp'),
91
- 'Sz ': makeType('', 'Pnt '),
92
- origin: makeType('', 'Pnt '),
93
- autoExpandOffset: makeType('', 'Pnt '),
94
- keyOriginShapeBBox: makeType('', 'unitRect'),
95
- Vrsn: nullType,
96
- psVersion: nullType,
97
- docDefaultNewArtboardBackgroundColor: makeType('', 'RGBC'),
98
- artboardRect: makeType('', 'classFloatRect'),
99
- keyOriginRRectRadii: makeType('', 'radii'),
100
- keyOriginBoxCorners: nullType,
101
- rectangleCornerA: makeType('', 'Pnt '),
102
- rectangleCornerB: makeType('', 'Pnt '),
103
- rectangleCornerC: makeType('', 'Pnt '),
104
- rectangleCornerD: makeType('', 'Pnt '),
105
- compInfo: nullType,
106
- quiltWarp: makeType('', 'quiltWarp'),
107
- generatorSettings: nullType,
108
- crema: nullType,
109
- FrIn: nullType,
110
- blendOptions: nullType,
111
- FXRf: nullType,
112
- Lefx: nullType,
113
- time: nullType,
114
- animKey: nullType,
115
- timeScope: nullType,
116
- inTime: nullType,
117
- outTime: nullType,
118
- sheetStyle: nullType,
119
- translation: nullType,
120
- Skew: nullType,
121
- boundingBox: makeType('', 'boundingBox'),
122
- 'Lnk ': makeType('', 'ExternalFileLink'),
123
- frameReader: makeType('', 'FrameReader'),
124
- effectParams: makeType('', 'motionTrackEffectParams'),
125
- Impr: makeType('None', 'none'),
126
- Anch: makeType('', 'Pnt '),
127
- 'Fwd ': makeType('', 'Pnt '),
128
- 'Bwd ': makeType('', 'Pnt '),
129
- FlrC: makeType('', 'Pnt '),
130
- meshBoundaryPath: makeType('', 'pathClass'),
131
- filterFX: makeType('', 'filterFXStyle'),
132
- Fltr: makeType('', 'rigidTransform'),
133
- FrgC: makeType('', 'RGBC'),
134
- BckC: makeType('', 'RGBC'),
135
- sdwM: makeType('Parameters', 'adaptCorrectTones'),
136
- hglM: makeType('Parameters', 'adaptCorrectTones'),
137
- customShape: makeType('', 'customShape'),
138
- origFXRefPoint: nullType,
139
- FXRefPoint: nullType,
140
- ClMg: makeType('', 'ClMg'),
141
- };
142
- var fieldToArrayExtType = {
143
- 'Crv ': makeType('', 'CrPt'),
144
- Clrs: makeType('', 'Clrt'),
145
- Trns: makeType('', 'TrnS'),
146
- keyDescriptorList: nullType,
147
- solidFillMulti: makeType('', 'SoFi'),
148
- gradientFillMulti: makeType('', 'GrFl'),
149
- dropShadowMulti: makeType('', 'DrSh'),
150
- innerShadowMulti: makeType('', 'IrSh'),
151
- frameFXMulti: makeType('', 'FrFX'),
152
- FrIn: nullType,
153
- FSts: nullType,
154
- LaSt: nullType,
155
- sheetTimelineOptions: nullType,
156
- trackList: makeType('', 'animationTrack'),
157
- globalTrackList: makeType('', 'animationTrack'),
158
- keyList: nullType,
159
- audioClipGroupList: nullType,
160
- audioClipList: nullType,
161
- countObjectList: makeType('', 'countObject'),
162
- countGroupList: makeType('', 'countGroup'),
163
- slices: makeType('', 'slice'),
164
- 'Pts ': makeType('', 'Pthp'),
165
- SbpL: makeType('', 'SbpL'),
166
- pathComponents: makeType('', 'PaCm'),
167
- filterFXList: makeType('', 'filterFX'),
168
- puppetShapeList: makeType('', 'puppetShape'),
169
- channelDenoise: makeType('', 'channelDenoiseParams'),
170
- ShrP: makeType('', 'Pnt '),
171
- layerSettings: nullType,
172
- list: nullType,
173
- Adjs: makeType('', 'CrvA'),
174
- };
175
- var typeToField = {
176
- 'TEXT': [
177
- 'Txt ', 'printerName', 'Nm ', 'Idnt', 'blackAndWhitePresetFileName', 'LUT3DFileName',
178
- 'presetFileName', 'curvesPresetFileName', 'mixerPresetFileName', 'placed', 'description', 'reason',
179
- 'artboardPresetName', 'json', 'clipID', 'relPath', 'fullPath', 'mediaDescriptor', 'Msge',
180
- 'altTag', 'url', 'cellText', 'preset', 'KnNm', 'FPth', 'comment', 'originalPath',
181
- ],
182
- 'tdta': [
183
- 'EngineData', 'LUT3DFileData', 'indexArray', 'originalVertexArray', 'deformedVertexArray',
184
- 'LqMe',
185
- ],
186
- 'long': [
187
- 'TextIndex', 'RndS', 'Mdpn', 'Smth', 'Lctn', 'strokeStyleVersion', 'LaID', 'Vrsn', 'Cnt ',
188
- 'Brgh', 'Cntr', 'means', 'vibrance', 'Strt', 'bwPresetKind', 'comp', 'compID', 'originalCompID',
189
- 'curvesPresetKind', 'mixerPresetKind', 'uOrder', 'vOrder', 'PgNm', 'totalPages', 'Crop',
190
- 'numerator', 'denominator', 'frameCount', 'Annt', 'keyOriginType', 'unitValueQuadVersion',
191
- 'keyOriginIndex', 'major', 'minor', 'fix', 'docDefaultNewArtboardBackgroundType', 'artboardBackgroundType',
192
- 'numModifyingFX', 'deformNumRows', 'deformNumCols', 'FrID', 'FrDl', 'FsID', 'LCnt', 'AFrm', 'AFSt',
193
- 'numBefore', 'numAfter', 'Spcn', 'minOpacity', 'maxOpacity', 'BlnM', 'sheetID', 'gblA', 'globalAltitude',
194
- 'descVersion', 'frameReaderType', 'LyrI', 'zoomOrigin', 'fontSize', 'Rds ', 'sliceID',
195
- 'topOutset', 'leftOutset', 'bottomOutset', 'rightOutset', 'filterID', 'meshQuality',
196
- 'meshExpansion', 'meshRigidity', 'VrsM', 'VrsN', 'NmbG', 'WLMn', 'WLMx', 'AmMn', 'AmMx', 'SclH', 'SclV',
197
- 'Lvl ', 'TlNm', 'TlOf', 'FlRs', 'Thsh', 'ShrS', 'ShrE', 'FlRs', 'Vrnc', 'Strg', 'ExtS', 'ExtD',
198
- 'HrzS', 'VrtS', 'NmbR', 'EdgF', 'Ang1', 'Ang2', 'Ang3', 'Ang4', 'lastAppliedComp', 'capturedInfo',
199
- ],
200
- 'enum': [
201
- 'textGridding', 'Ornt', 'warpStyle', 'warpRotate', 'Inte', 'Bltn', 'ClrS', 'BlrQ',
202
- 'bvlT', 'bvlS', 'bvlD', 'Md ', 'glwS', 'GrdF', 'GlwT', 'RplS', 'BlrM', 'SmBM',
203
- 'strokeStyleLineCapType', 'strokeStyleLineJoinType', 'strokeStyleLineAlignment',
204
- 'strokeStyleBlendMode', 'PntT', 'Styl', 'lookupType', 'LUTFormat', 'dataOrder',
205
- 'tableOrder', 'enableCompCore', 'enableCompCoreGPU', 'compCoreSupport', 'compCoreGPUSupport', 'Engn',
206
- 'enableCompCoreThreads', 'gs99', 'FrDs', 'trackID', 'animInterpStyle', 'horzAlign',
207
- 'vertAlign', 'bgColorType', 'shapeOperation', 'UndA', 'Wvtp', 'Drct', 'WndM', 'Edg ', 'FlCl', 'IntE',
208
- 'IntC', 'Cnvr', 'Fl ', 'Dstr', 'MztT', 'Lns ', 'ExtT', 'DspM', 'ExtR', 'ZZTy', 'SphM', 'SmBQ', 'placedLayerOCIOConversion', 'gradientsInterpolationMethod',
209
- ],
210
- 'bool': [
211
- 'PstS', 'printSixteenBit', 'masterFXSwitch', 'enab', 'uglg', 'antialiasGloss',
212
- 'useShape', 'useTexture', 'uglg', 'antialiasGloss', 'useShape', 'Vsbl',
213
- 'useTexture', 'Algn', 'Rvrs', 'Dthr', 'Invr', 'VctC', 'ShTr', 'layerConceals',
214
- 'strokeEnabled', 'fillEnabled', 'strokeStyleScaleLock', 'strokeStyleStrokeAdjust',
215
- 'hardProof', 'MpBl', 'paperWhite', 'useLegacy', 'Auto', 'Lab ', 'useTint', 'keyShapeInvalidated',
216
- 'autoExpandEnabled', 'autoNestEnabled', 'autoPositionEnabled', 'shrinkwrapOnSaveEnabled',
217
- 'present', 'showInDialog', 'overprint', 'sheetDisclosed', 'lightsDisclosed', 'meshesDisclosed',
218
- 'materialsDisclosed', 'hasMotion', 'muted', 'Effc', 'selected', 'autoScope', 'fillCanvas',
219
- 'cellTextIsHTML', 'Smoo', 'Clsp', 'validAtPosition', 'rigidType', 'hasoptions', 'filterMaskEnable',
220
- 'filterMaskLinked', 'filterMaskExtendWithWhite', 'removeJPEGArtifact', 'Mnch', 'ExtF', 'ExtM',
221
- 'moreAccurate', 'GpuY', 'LIWy', 'Cnty',
222
- ],
223
- 'doub': [
224
- 'warpValue', 'warpPerspective', 'warpPerspectiveOther', 'Intr', 'Wdth', 'Hght',
225
- 'strokeStyleMiterLimit', 'strokeStyleResolution', 'layerTime', 'keyOriginResolution',
226
- 'xx', 'xy', 'yx', 'yy', 'tx', 'ty', 'FrGA', 'frameRate', 'audioLevel', 'rotation',
227
- 'X ', 'Y ', 'redFloat', 'greenFloat', 'blueFloat', 'imageResolution',
228
- 'PuX0', 'PuX1', 'PuX2', 'PuX3', 'PuY0', 'PuY1', 'PuY2', 'PuY3'
229
- ],
230
- 'UntF': [
231
- 'sdwO', 'hglO', 'lagl', 'Lald', 'srgR', 'blur', 'Sftn', 'Opct', 'Dstn', 'Angl',
232
- 'Ckmt', 'Nose', 'Inpr', 'ShdN', 'strokeStyleLineWidth', 'strokeStyleLineDashOffset',
233
- 'strokeStyleOpacity', 'H ', 'Top ', 'Left', 'Btom', 'Rght', 'Rslt',
234
- 'topRight', 'topLeft', 'bottomLeft', 'bottomRight', 'ClNs', 'Shrp',
235
- ],
236
- 'VlLs': [
237
- 'Crv ', 'Clrs', 'Mnm ', 'Mxm ', 'Trns', 'pathList', 'strokeStyleLineDashSet', 'FrLs', 'slices',
238
- 'LaSt', 'Trnf', 'nonAffineTransform', 'keyDescriptorList', 'guideIndeces', 'gradientFillMulti',
239
- 'solidFillMulti', 'frameFXMulti', 'innerShadowMulti', 'dropShadowMulti', 'FrIn', 'FSts', 'FsFr',
240
- 'sheetTimelineOptions', 'audioClipList', 'trackList', 'globalTrackList', 'keyList', 'audioClipList',
241
- 'warpValues', 'selectedPin', 'Pts ', 'SbpL', 'pathComponents', 'pinOffsets', 'posFinalPins',
242
- 'pinVertexIndices', 'PinP', 'PnRt', 'PnOv', 'PnDp', 'filterFXList', 'puppetShapeList', 'ShrP',
243
- 'channelDenoise', 'Mtrx', 'layerSettings', 'list', 'compList', 'Adjs',
244
- ],
245
- 'ObAr': ['meshPoints', 'quiltSliceX', 'quiltSliceY'],
246
- 'obj ': ['null', 'Chnl'],
247
- 'Pth ': ['DspF'],
248
- };
249
- var channels = [
250
- 'Rd ', 'Grn ', 'Bl ', 'Yllw', 'Ylw ', 'Cyn ', 'Mgnt', 'Blck', 'Gry ', 'Lmnc', 'A ', 'B ',
251
- ];
252
- var fieldToArrayType = {
253
- 'Mnm ': 'long',
254
- 'Mxm ': 'long',
255
- FrLs: 'long',
256
- strokeStyleLineDashSet: 'UntF',
257
- Trnf: 'doub',
258
- nonAffineTransform: 'doub',
259
- keyDescriptorList: 'Objc',
260
- gradientFillMulti: 'Objc',
261
- solidFillMulti: 'Objc',
262
- frameFXMulti: 'Objc',
263
- innerShadowMulti: 'Objc',
264
- dropShadowMulti: 'Objc',
265
- LaSt: 'Objc',
266
- FrIn: 'Objc',
267
- FSts: 'Objc',
268
- FsFr: 'long',
269
- blendOptions: 'Objc',
270
- sheetTimelineOptions: 'Objc',
271
- keyList: 'Objc',
272
- warpValues: 'doub',
273
- selectedPin: 'long',
274
- 'Pts ': 'Objc',
275
- SbpL: 'Objc',
276
- pathComponents: 'Objc',
277
- pinOffsets: 'doub',
278
- posFinalPins: 'doub',
279
- pinVertexIndices: 'long',
280
- PinP: 'doub',
281
- PnRt: 'long',
282
- PnOv: 'bool',
283
- PnDp: 'doub',
284
- filterFXList: 'Objc',
285
- puppetShapeList: 'Objc',
286
- ShrP: 'Objc',
287
- channelDenoise: 'Objc',
288
- Mtrx: 'long',
289
- compList: 'long',
290
- Chnl: 'enum',
291
- };
292
- var fieldToType = {};
293
- for (var _i = 0, _a = Object.keys(typeToField); _i < _a.length; _i++) {
294
- var type = _a[_i];
295
- for (var _b = 0, _c = typeToField[type]; _b < _c.length; _b++) {
296
- var field = _c[_b];
297
- fieldToType[field] = type;
298
- }
299
- }
300
- for (var _d = 0, _e = Object.keys(fieldToExtType); _d < _e.length; _d++) {
301
- var field = _e[_d];
302
- if (!fieldToType[field])
303
- fieldToType[field] = 'Objc';
304
- }
305
- for (var _f = 0, _g = Object.keys(fieldToArrayExtType); _f < _g.length; _f++) {
306
- var field = _g[_f];
307
- fieldToArrayType[field] = 'Objc';
308
- }
309
- function getTypeByKey(key, value, root, parent) {
310
- if (key === 'presetKind') {
311
- return typeof value === 'string' ? 'enum' : 'long';
312
- }
313
- if (key === 'null' && root === 'slices') {
314
- return 'TEXT';
315
- }
316
- else if (key === 'groupID') {
317
- return root === 'slices' ? 'long' : 'TEXT';
318
- }
319
- else if (key === 'Sz ') {
320
- return ('Wdth' in value) ? 'Objc' : (('units' in value) ? 'UntF' : 'doub');
321
- }
322
- else if (key === 'Type') {
323
- return typeof value === 'string' ? 'enum' : 'long';
324
- }
325
- else if (key === 'AntA') {
326
- return typeof value === 'string' ? 'enum' : 'bool';
327
- }
328
- else if ((key === 'Hrzn' || key === 'Vrtc') && (parent.Type === 'keyType.Pstn' || parent._classID === 'Ofst')) {
329
- return 'long';
330
- }
331
- else if (key === 'Hrzn' || key === 'Vrtc' || key === 'Top ' || key === 'Left' || key === 'Btom' || key === 'Rght') {
332
- if (root === 'slices')
333
- return 'long';
334
- return typeof value === 'number' ? 'doub' : 'UntF';
335
- }
336
- else if (key === 'Vrsn') {
337
- return typeof value === 'number' ? 'long' : 'Objc';
338
- }
339
- else if (key === 'Rd ' || key === 'Grn ' || key === 'Bl ') {
340
- return root === 'artd' ? 'long' : 'doub';
341
- }
342
- else if (key === 'Trnf') {
343
- return Array.isArray(value) ? 'VlLs' : 'Objc';
344
- }
345
- else {
346
- return fieldToType[key];
347
- }
348
- }
349
- function readAsciiStringOrClassId(reader) {
350
- var length = (0, psdReader_1.readInt32)(reader);
351
- return (0, psdReader_1.readAsciiString)(reader, length || 4);
352
- }
353
- exports.readAsciiStringOrClassId = readAsciiStringOrClassId;
354
- function writeAsciiStringOrClassId(writer, value) {
355
- if (value.length === 4 && value !== 'warp' && value !== 'time' && value !== 'hold' && value !== 'list') {
356
- // write classId
357
- (0, psdWriter_1.writeInt32)(writer, 0);
358
- (0, psdWriter_1.writeSignature)(writer, value);
359
- }
360
- else {
361
- // write ascii string
362
- (0, psdWriter_1.writeInt32)(writer, value.length);
363
- for (var i = 0; i < value.length; i++) {
364
- (0, psdWriter_1.writeUint8)(writer, value.charCodeAt(i));
365
- }
366
- }
367
- }
368
- function readDescriptorStructure(reader, includeClass) {
369
- var struct = readClassStructure(reader);
370
- var object = includeClass ? { _name: struct.name, _classID: struct.classID } : {};
371
- // console.log('>> ', struct);
372
- var itemsCount = (0, psdReader_1.readUint32)(reader);
373
- for (var i = 0; i < itemsCount; i++) {
374
- var key = readAsciiStringOrClassId(reader);
375
- var type = (0, psdReader_1.readSignature)(reader);
376
- // console.log(`> '${key}' '${type}'`);
377
- var data = readOSType(reader, type, includeClass);
378
- // if (!getTypeByKey(key, data)) console.log(`> '${key}' '${type}'`, data);
379
- object[key] = data;
380
- }
381
- return object;
382
- }
383
- exports.readDescriptorStructure = readDescriptorStructure;
384
- function writeDescriptorStructure(writer, name, classId, value, root) {
385
- if (logErrors && !classId)
386
- console.log('Missing classId for: ', name, classId, value);
387
- // write class structure
388
- (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, name);
389
- writeAsciiStringOrClassId(writer, classId);
390
- var keys = Object.keys(value);
391
- var keyCount = keys.length;
392
- if ('_name' in value)
393
- keyCount--;
394
- if ('_classID' in value)
395
- keyCount--;
396
- (0, psdWriter_1.writeUint32)(writer, keyCount);
397
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
398
- var key = keys_1[_i];
399
- if (key === '_name' || key === '_classID')
400
- continue;
401
- var type = getTypeByKey(key, value[key], root, value);
402
- var extType = fieldToExtType[key];
403
- if (key === 'bounds' && root === 'text') {
404
- extType = makeType('', 'bounds');
405
- }
406
- else if (key === 'origin') {
407
- type = root === 'slices' ? 'enum' : 'Objc';
408
- }
409
- else if ((key === 'Cyn ' || key === 'Mgnt' || key === 'Ylw ' || key === 'Blck') && value._classID === 'CMYC') {
410
- type = 'doub';
411
- }
412
- else if (/^PN[a-z][a-z]$/.test(key)) {
413
- type = 'TEXT';
414
- }
415
- else if (/^PT[a-z][a-z]$/.test(key)) {
416
- type = 'long';
417
- }
418
- else if (/^PF[a-z][a-z]$/.test(key)) {
419
- type = 'doub';
420
- }
421
- else if ((key === 'Rds ' || key === 'Thsh') && typeof value[key] === 'number' && value._classID === 'SmrB') {
422
- type = 'doub';
423
- }
424
- else if (key === 'ClSz' || key === 'Rds ' || key === 'Amnt') {
425
- type = typeof value[key] === 'number' ? 'long' : 'UntF';
426
- }
427
- else if ((key === 'sdwM' || key === 'hglM') && typeof value[key] === 'string') {
428
- type = 'enum';
429
- }
430
- else if (key === 'blur' && typeof value[key] === 'string') {
431
- type = 'enum';
432
- }
433
- else if (key === 'Hght' && typeof value[key] === 'number' && value._classID === 'Embs') {
434
- type = 'long';
435
- }
436
- else if (key === 'Angl' && typeof value[key] === 'number' && (value._classID === 'Embs' || value._classID === 'smartSharpen' || value._classID === 'Twrl' || value._classID === 'MtnB')) {
437
- type = 'long';
438
- }
439
- else if (key === 'Angl' && typeof value[key] === 'number') {
440
- type = 'doub'; // ???
441
- }
442
- else if (key === 'bounds' && root === 'slices') {
443
- type = 'Objc';
444
- extType = makeType('', 'Rct1');
445
- }
446
- else if (key === 'Scl ') {
447
- if (typeof value[key] === 'object' && 'Hrzn' in value[key]) {
448
- type = 'Objc';
449
- extType = nullType;
450
- }
451
- else if (typeof value[key] === 'number') {
452
- type = 'long';
453
- }
454
- else {
455
- type = 'UntF';
456
- }
457
- }
458
- else if (key === 'audioClipGroupList' && keys.length === 1) {
459
- type = 'VlLs';
460
- }
461
- else if ((key === 'Strt' || key === 'Brgh') && 'H ' in value) {
462
- type = 'doub';
463
- }
464
- else if (key === 'Wdth' && typeof value[key] === 'object') {
465
- type = 'UntF';
466
- }
467
- else if (key === 'Ofst' && typeof value[key] === 'number') {
468
- type = 'long';
469
- }
470
- else if (key === 'Strt' && typeof value[key] === 'object') {
471
- type = 'Objc';
472
- extType = nullType;
473
- }
474
- else if (channels.indexOf(key) !== -1) {
475
- type = (classId === 'RGBC' && root !== 'artd') ? 'doub' : 'long';
476
- }
477
- else if (key === 'profile') {
478
- type = classId === 'printOutput' ? 'TEXT' : 'tdta';
479
- }
480
- else if (key === 'strokeStyleContent') {
481
- if (value[key]['Clr ']) {
482
- extType = makeType('', 'solidColorLayer');
483
- }
484
- else if (value[key].Grad) {
485
- extType = makeType('', 'gradientLayer');
486
- }
487
- else if (value[key].Ptrn) {
488
- extType = makeType('', 'patternLayer');
489
- }
490
- else {
491
- logErrors && console.log('Invalid strokeStyleContent value', value[key]);
492
- }
493
- }
494
- else if (key === 'bounds' && root === 'quiltWarp') {
495
- extType = makeType('', 'classFloatRect');
496
- }
497
- if (extType && extType.classID === 'RGBC') {
498
- if ('H ' in value[key])
499
- extType = { classID: 'HSBC', name: '' };
500
- // TODO: other color spaces
501
- }
502
- writeAsciiStringOrClassId(writer, key);
503
- (0, psdWriter_1.writeSignature)(writer, type || 'long');
504
- writeOSType(writer, type || 'long', value[key], key, extType, root);
505
- if (logErrors && !type)
506
- console.log("Missing descriptor field type for: '".concat(key, "' in"), value);
507
- }
508
- }
509
- exports.writeDescriptorStructure = writeDescriptorStructure;
510
- function readOSType(reader, type, includeClass) {
511
- switch (type) {
512
- case 'obj ': // Reference
513
- return readReferenceStructure(reader);
514
- case 'Objc': // Descriptor
515
- case 'GlbO': // GlobalObject same as Descriptor
516
- return readDescriptorStructure(reader, includeClass);
517
- case 'VlLs': { // List
518
- var length_1 = (0, psdReader_1.readInt32)(reader);
519
- var items = [];
520
- for (var i = 0; i < length_1; i++) {
521
- var itemType = (0, psdReader_1.readSignature)(reader);
522
- // console.log(' >', itemType);
523
- items.push(readOSType(reader, itemType, includeClass));
524
- }
525
- return items;
526
- }
527
- case 'doub': // Double
528
- return (0, psdReader_1.readFloat64)(reader);
529
- case 'UntF': { // Unit double
530
- var units = (0, psdReader_1.readSignature)(reader);
531
- var value = (0, psdReader_1.readFloat64)(reader);
532
- if (!unitsMap[units])
533
- throw new Error("Invalid units: ".concat(units));
534
- return { units: unitsMap[units], value: value };
535
- }
536
- case 'UnFl': { // Unit float
537
- var units = (0, psdReader_1.readSignature)(reader);
538
- var value = (0, psdReader_1.readFloat32)(reader);
539
- if (!unitsMap[units])
540
- throw new Error("Invalid units: ".concat(units));
541
- return { units: unitsMap[units], value: value };
542
- }
543
- case 'TEXT': // String
544
- return (0, psdReader_1.readUnicodeString)(reader);
545
- case 'enum': { // Enumerated
546
- var enumType = readAsciiStringOrClassId(reader);
547
- var value = readAsciiStringOrClassId(reader);
548
- return "".concat(enumType, ".").concat(value);
549
- }
550
- case 'long': // Integer
551
- return (0, psdReader_1.readInt32)(reader);
552
- case 'comp': { // Large Integer
553
- var low = (0, psdReader_1.readUint32)(reader);
554
- var high = (0, psdReader_1.readUint32)(reader);
555
- return { low: low, high: high };
556
- }
557
- case 'bool': // Boolean
558
- return !!(0, psdReader_1.readUint8)(reader);
559
- case 'type': // Class
560
- case 'GlbC': // Class
561
- return readClassStructure(reader);
562
- case 'alis': { // Alias
563
- var length_2 = (0, psdReader_1.readInt32)(reader);
564
- return (0, psdReader_1.readAsciiString)(reader, length_2);
565
- }
566
- case 'tdta': { // Raw Data
567
- var length_3 = (0, psdReader_1.readInt32)(reader);
568
- return (0, psdReader_1.readBytes)(reader, length_3);
569
- }
570
- case 'ObAr': { // Object array
571
- (0, psdReader_1.readInt32)(reader); // version: 16
572
- (0, psdReader_1.readUnicodeString)(reader); // name: ''
573
- readAsciiStringOrClassId(reader); // 'rationalPoint'
574
- var length_4 = (0, psdReader_1.readInt32)(reader);
575
- var items = [];
576
- for (var i = 0; i < length_4; i++) {
577
- var type1 = readAsciiStringOrClassId(reader); // type Hrzn | Vrtc
578
- (0, psdReader_1.readSignature)(reader); // UnFl
579
- (0, psdReader_1.readSignature)(reader); // units ? '#Pxl'
580
- var valuesCount = (0, psdReader_1.readInt32)(reader);
581
- var values = [];
582
- for (var j = 0; j < valuesCount; j++) {
583
- values.push((0, psdReader_1.readFloat64)(reader));
584
- }
585
- items.push({ type: type1, values: values });
586
- }
587
- return items;
588
- }
589
- case 'Pth ': { // File path
590
- /*const length =*/ (0, psdReader_1.readInt32)(reader); // total size of all fields below
591
- var sig = (0, psdReader_1.readSignature)(reader);
592
- /*const pathSize =*/ (0, psdReader_1.readInt32LE)(reader); // the same as length
593
- var charsCount = (0, psdReader_1.readInt32LE)(reader);
594
- var path = (0, psdReader_1.readUnicodeStringWithLengthLE)(reader, charsCount);
595
- return { sig: sig, path: path };
596
- }
597
- default:
598
- throw new Error("Invalid TySh descriptor OSType: ".concat(type, " at ").concat(reader.offset.toString(16)));
599
- }
600
- }
601
- var ObArTypes = {
602
- meshPoints: 'rationalPoint',
603
- quiltSliceX: 'UntF',
604
- quiltSliceY: 'UntF',
605
- };
606
- function writeOSType(writer, type, value, key, extType, root) {
607
- switch (type) {
608
- case 'obj ': // Reference
609
- writeReferenceStructure(writer, key, value);
610
- break;
611
- case 'Objc': // Descriptor
612
- case 'GlbO': { // GlobalObject same as Descriptor
613
- if (typeof value !== 'object')
614
- throw new Error("Invalid struct value: ".concat(JSON.stringify(value), ", key: ").concat(key));
615
- if (!extType)
616
- throw new Error("Missing ext type for: '".concat(key, "' (").concat(JSON.stringify(value), ")"));
617
- var name_1 = value._name || extType.name;
618
- var classID = value._classID || extType.classID;
619
- writeDescriptorStructure(writer, name_1, classID, value, root);
620
- break;
621
- }
622
- case 'VlLs': // List
623
- if (!Array.isArray(value))
624
- throw new Error("Invalid list value: ".concat(JSON.stringify(value), ", key: ").concat(key));
625
- (0, psdWriter_1.writeInt32)(writer, value.length);
626
- for (var i = 0; i < value.length; i++) {
627
- var type_1 = fieldToArrayType[key];
628
- (0, psdWriter_1.writeSignature)(writer, type_1 || 'long');
629
- writeOSType(writer, type_1 || 'long', value[i], "".concat(key, "[]"), fieldToArrayExtType[key], root);
630
- if (logErrors && !type_1)
631
- console.log("Missing descriptor array type for: '".concat(key, "' in"), value);
632
- }
633
- break;
634
- case 'doub': // Double
635
- if (typeof value !== 'number')
636
- throw new Error("Invalid number value: ".concat(JSON.stringify(value), ", key: ").concat(key));
637
- (0, psdWriter_1.writeFloat64)(writer, value);
638
- break;
639
- case 'UntF': // Unit double
640
- if (!unitsMapRev[value.units])
641
- throw new Error("Invalid units: ".concat(value.units, " in ").concat(key));
642
- (0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
643
- (0, psdWriter_1.writeFloat64)(writer, value.value);
644
- break;
645
- case 'UnFl': // Unit float
646
- if (!unitsMapRev[value.units])
647
- throw new Error("Invalid units: ".concat(value.units, " in ").concat(key));
648
- (0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
649
- (0, psdWriter_1.writeFloat32)(writer, value.value);
650
- break;
651
- case 'TEXT': // String
652
- (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, value);
653
- break;
654
- case 'enum': { // Enumerated
655
- if (typeof value !== 'string')
656
- throw new Error("Invalid enum value: ".concat(JSON.stringify(value), ", key: ").concat(key));
657
- var _a = value.split('.'), _type = _a[0], val = _a[1];
658
- writeAsciiStringOrClassId(writer, _type);
659
- writeAsciiStringOrClassId(writer, val);
660
- break;
661
- }
662
- case 'long': // Integer
663
- if (typeof value !== 'number')
664
- throw new Error("Invalid integer value: ".concat(JSON.stringify(value), ", key: ").concat(key));
665
- (0, psdWriter_1.writeInt32)(writer, value);
666
- break;
667
- // case 'comp': // Large Integer
668
- // writeLargeInteger(reader);
669
- case 'bool': // Boolean
670
- if (typeof value !== 'boolean')
671
- throw new Error("Invalid boolean value: ".concat(JSON.stringify(value), ", key: ").concat(key));
672
- (0, psdWriter_1.writeUint8)(writer, value ? 1 : 0);
673
- break;
674
- // case 'type': // Class
675
- // case 'GlbC': // Class
676
- // writeClassStructure(reader);
677
- // case 'alis': // Alias
678
- // writeAliasStructure(reader);
679
- case 'tdta': // Raw Data
680
- (0, psdWriter_1.writeInt32)(writer, value.byteLength);
681
- (0, psdWriter_1.writeBytes)(writer, value);
682
- break;
683
- case 'ObAr': { // Object array
684
- (0, psdWriter_1.writeInt32)(writer, 16); // version
685
- (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
686
- var type_2 = ObArTypes[key];
687
- if (!type_2)
688
- throw new Error("Not implemented ObArType for: ".concat(key));
689
- writeAsciiStringOrClassId(writer, type_2);
690
- (0, psdWriter_1.writeInt32)(writer, value.length);
691
- for (var i = 0; i < value.length; i++) {
692
- writeAsciiStringOrClassId(writer, value[i].type); // Hrzn | Vrtc
693
- (0, psdWriter_1.writeSignature)(writer, 'UnFl');
694
- (0, psdWriter_1.writeSignature)(writer, '#Pxl');
695
- (0, psdWriter_1.writeInt32)(writer, value[i].values.length);
696
- for (var j = 0; j < value[i].values.length; j++) {
697
- (0, psdWriter_1.writeFloat64)(writer, value[i].values[j]);
698
- }
699
- }
700
- break;
701
- }
702
- case 'Pth ': { // File path
703
- var length_5 = 4 + 4 + 4 + value.path.length * 2;
704
- (0, psdWriter_1.writeInt32)(writer, length_5);
705
- (0, psdWriter_1.writeSignature)(writer, value.sig);
706
- (0, psdWriter_1.writeInt32LE)(writer, length_5);
707
- (0, psdWriter_1.writeInt32LE)(writer, value.path.length);
708
- (0, psdWriter_1.writeUnicodeStringWithoutLengthLE)(writer, value.path);
709
- break;
710
- }
711
- default:
712
- throw new Error("Not implemented descriptor OSType: ".concat(type));
713
- }
714
- }
715
- function readReferenceStructure(reader) {
716
- var itemsCount = (0, psdReader_1.readInt32)(reader);
717
- var items = [];
718
- for (var i = 0; i < itemsCount; i++) {
719
- var type = (0, psdReader_1.readSignature)(reader);
720
- switch (type) {
721
- case 'prop': { // Property
722
- readClassStructure(reader);
723
- var keyID = readAsciiStringOrClassId(reader);
724
- items.push(keyID);
725
- break;
726
- }
727
- case 'Clss': // Class
728
- items.push(readClassStructure(reader));
729
- break;
730
- case 'Enmr': { // Enumerated Reference
731
- readClassStructure(reader);
732
- var typeID = readAsciiStringOrClassId(reader);
733
- var value = readAsciiStringOrClassId(reader);
734
- items.push("".concat(typeID, ".").concat(value));
735
- break;
736
- }
737
- case 'rele': { // Offset
738
- // const { name, classID } =
739
- readClassStructure(reader);
740
- items.push((0, psdReader_1.readUint32)(reader));
741
- break;
742
- }
743
- case 'Idnt': // Identifier
744
- items.push((0, psdReader_1.readInt32)(reader));
745
- break;
746
- case 'indx': // Index
747
- items.push((0, psdReader_1.readInt32)(reader));
748
- break;
749
- case 'name': { // Name
750
- readClassStructure(reader);
751
- items.push((0, psdReader_1.readUnicodeString)(reader));
752
- break;
753
- }
754
- default:
755
- throw new Error("Invalid descriptor reference type: ".concat(type));
756
- }
757
- }
758
- return items;
759
- }
760
- function writeReferenceStructure(writer, _key, items) {
761
- (0, psdWriter_1.writeInt32)(writer, items.length);
762
- for (var i = 0; i < items.length; i++) {
763
- var value = items[i];
764
- var type = 'unknown';
765
- if (typeof value === 'string') {
766
- if (/^[a-z ]+\.[a-z ]+$/i.test(value)) {
767
- type = 'Enmr';
768
- }
769
- else {
770
- type = 'name';
771
- }
772
- }
773
- (0, psdWriter_1.writeSignature)(writer, type);
774
- switch (type) {
775
- // case 'prop': // Property
776
- // case 'Clss': // Class
777
- case 'Enmr': { // Enumerated Reference
778
- var _a = value.split('.'), typeID = _a[0], enumValue = _a[1];
779
- writeClassStructure(writer, '\0', typeID);
780
- writeAsciiStringOrClassId(writer, typeID);
781
- writeAsciiStringOrClassId(writer, enumValue);
782
- break;
783
- }
784
- // case 'rele': // Offset
785
- // case 'Idnt': // Identifier
786
- // case 'indx': // Index
787
- case 'name': { // Name
788
- writeClassStructure(writer, '\0', 'Lyr ');
789
- (0, psdWriter_1.writeUnicodeString)(writer, value + '\0');
790
- break;
791
- }
792
- default:
793
- throw new Error("Invalid descriptor reference type: ".concat(type));
794
- }
795
- }
796
- return items;
797
- }
798
- function readClassStructure(reader) {
799
- var name = (0, psdReader_1.readUnicodeString)(reader);
800
- var classID = readAsciiStringOrClassId(reader);
801
- return { name: name, classID: classID };
802
- }
803
- function writeClassStructure(writer, name, classID) {
804
- (0, psdWriter_1.writeUnicodeString)(writer, name);
805
- writeAsciiStringOrClassId(writer, classID);
806
- }
807
- function readVersionAndDescriptor(reader, includeClass) {
808
- if (includeClass === void 0) { includeClass = false; }
809
- var version = (0, psdReader_1.readUint32)(reader);
810
- if (version !== 16)
811
- throw new Error("Invalid descriptor version: ".concat(version));
812
- var desc = readDescriptorStructure(reader, includeClass);
813
- // console.log(require('util').inspect(desc, false, 99, true));
814
- return desc;
815
- }
816
- exports.readVersionAndDescriptor = readVersionAndDescriptor;
817
- function writeVersionAndDescriptor(writer, name, classID, descriptor, root) {
818
- if (root === void 0) { root = ''; }
819
- (0, psdWriter_1.writeUint32)(writer, 16); // version
820
- writeDescriptorStructure(writer, name, classID, descriptor, root);
821
- }
822
- exports.writeVersionAndDescriptor = writeVersionAndDescriptor;
823
- function horzVrtcToXY(hv) {
824
- return { x: hv.Hrzn, y: hv.Vrtc };
825
- }
826
- exports.horzVrtcToXY = horzVrtcToXY;
827
- function xyToHorzVrtc(xy) {
828
- return { Hrzn: xy.x, Vrtc: xy.y };
829
- }
830
- exports.xyToHorzVrtc = xyToHorzVrtc;
831
- function descBoundsToBounds(desc) {
832
- return {
833
- top: parseUnits(desc['Top ']),
834
- left: parseUnits(desc.Left),
835
- right: parseUnits(desc.Rght),
836
- bottom: parseUnits(desc.Btom),
837
- };
838
- }
839
- exports.descBoundsToBounds = descBoundsToBounds;
840
- function boundsToDescBounds(bounds) {
841
- var _a;
842
- return _a = {
843
- Left: unitsValue(bounds.left, 'bounds.left')
844
- },
845
- _a['Top '] = unitsValue(bounds.top, 'bounds.top'),
846
- _a.Rght = unitsValue(bounds.right, 'bounds.right'),
847
- _a.Btom = unitsValue(bounds.bottom, 'bounds.bottom'),
848
- _a;
849
- }
850
- exports.boundsToDescBounds = boundsToDescBounds;
851
- function parseFxObject(fx) {
852
- var stroke = {
853
- enabled: !!fx.enab,
854
- position: exports.FStl.decode(fx.Styl),
855
- fillType: exports.FrFl.decode(fx.PntT),
856
- blendMode: exports.BlnM.decode(fx['Md ']),
857
- opacity: parsePercent(fx.Opct),
858
- size: parseUnits(fx['Sz ']),
859
- };
860
- if (fx.present !== undefined)
861
- stroke.present = fx.present;
862
- if (fx.showInDialog !== undefined)
863
- stroke.showInDialog = fx.showInDialog;
864
- if (fx.overprint !== undefined)
865
- stroke.overprint = fx.overprint;
866
- if (fx['Clr '])
867
- stroke.color = parseColor(fx['Clr ']);
868
- if (fx.Grad)
869
- stroke.gradient = parseGradientContent(fx);
870
- if (fx.Ptrn)
871
- stroke.pattern = parsePatternContent(fx);
872
- return stroke;
873
- }
874
- function serializeFxObject(stroke) {
875
- var FrFX = {};
876
- FrFX.enab = !!stroke.enabled;
877
- if (stroke.present !== undefined)
878
- FrFX.present = !!stroke.present;
879
- if (stroke.showInDialog !== undefined)
880
- FrFX.showInDialog = !!stroke.showInDialog;
881
- FrFX.Styl = exports.FStl.encode(stroke.position);
882
- FrFX.PntT = exports.FrFl.encode(stroke.fillType);
883
- FrFX['Md '] = exports.BlnM.encode(stroke.blendMode);
884
- FrFX.Opct = unitsPercent(stroke.opacity);
885
- FrFX['Sz '] = unitsValue(stroke.size, 'size');
886
- if (stroke.color)
887
- FrFX['Clr '] = serializeColor(stroke.color);
888
- if (stroke.gradient)
889
- FrFX = __assign(__assign({}, FrFX), serializeGradientContent(stroke.gradient));
890
- if (stroke.pattern)
891
- FrFX = __assign(__assign({}, FrFX), serializePatternContent(stroke.pattern));
892
- if (stroke.overprint !== undefined)
893
- FrFX.overprint = !!stroke.overprint;
894
- return FrFX;
895
- }
896
- function serializeEffects(e, log, multi) {
897
- var _a, _b, _c;
898
- var info = multi ? {
899
- 'Scl ': unitsPercentF((_a = e.scale) !== null && _a !== void 0 ? _a : 1),
900
- masterFXSwitch: !e.disabled,
901
- } : {
902
- masterFXSwitch: !e.disabled,
903
- 'Scl ': unitsPercentF((_b = e.scale) !== null && _b !== void 0 ? _b : 1),
904
- };
905
- var arrayKeys = ['dropShadow', 'innerShadow', 'solidFill', 'gradientOverlay', 'stroke'];
906
- for (var _i = 0, arrayKeys_1 = arrayKeys; _i < arrayKeys_1.length; _i++) {
907
- var key = arrayKeys_1[_i];
908
- if (e[key] && !Array.isArray(e[key]))
909
- throw new Error("".concat(key, " should be an array"));
910
- }
911
- var useMulti = function (arr) { return !!arr && arr.length > 1 && multi; };
912
- var useSingle = function (arr) { return !!arr && arr.length >= 1 && (!multi || arr.length === 1); };
913
- if (useSingle(e.dropShadow))
914
- info.DrSh = serializeEffectObject(e.dropShadow[0], 'dropShadow', log);
915
- if (useMulti(e.dropShadow))
916
- info.dropShadowMulti = e.dropShadow.map(function (i) { return serializeEffectObject(i, 'dropShadow', log); });
917
- if (useSingle(e.innerShadow))
918
- info.IrSh = serializeEffectObject(e.innerShadow[0], 'innerShadow', log);
919
- if (useMulti(e.innerShadow))
920
- info.innerShadowMulti = e.innerShadow.map(function (i) { return serializeEffectObject(i, 'innerShadow', log); });
921
- if (e.outerGlow)
922
- info.OrGl = serializeEffectObject(e.outerGlow, 'outerGlow', log);
923
- if (useMulti(e.solidFill))
924
- info.solidFillMulti = e.solidFill.map(function (i) { return serializeEffectObject(i, 'solidFill', log); });
925
- if (useMulti(e.gradientOverlay))
926
- info.gradientFillMulti = e.gradientOverlay.map(function (i) { return serializeEffectObject(i, 'gradientOverlay', log); });
927
- if (useMulti(e.stroke))
928
- info.frameFXMulti = e.stroke.map(function (i) { return serializeFxObject(i); });
929
- if (e.innerGlow)
930
- info.IrGl = serializeEffectObject(e.innerGlow, 'innerGlow', log);
931
- if (e.bevel)
932
- info.ebbl = serializeEffectObject(e.bevel, 'bevel', log);
933
- if (useSingle(e.solidFill))
934
- info.SoFi = serializeEffectObject(e.solidFill[0], 'solidFill', log);
935
- if (e.patternOverlay)
936
- info.patternFill = serializeEffectObject(e.patternOverlay, 'patternOverlay', log);
937
- if (useSingle(e.gradientOverlay))
938
- info.GrFl = serializeEffectObject(e.gradientOverlay[0], 'gradientOverlay', log);
939
- if (e.satin)
940
- info.ChFX = serializeEffectObject(e.satin, 'satin', log);
941
- if (useSingle(e.stroke))
942
- info.FrFX = serializeFxObject((_c = e.stroke) === null || _c === void 0 ? void 0 : _c[0]);
943
- if (multi) {
944
- info.numModifyingFX = 0;
945
- for (var _d = 0, _e = Object.keys(e); _d < _e.length; _d++) {
946
- var key = _e[_d];
947
- var value = e[key];
948
- if (Array.isArray(value)) {
949
- for (var _f = 0, value_1 = value; _f < value_1.length; _f++) {
950
- var effect = value_1[_f];
951
- if (effect.enabled)
952
- info.numModifyingFX++;
953
- }
954
- }
955
- else if (value.enabled) {
956
- info.numModifyingFX++;
957
- }
958
- }
959
- }
960
- return info;
961
- }
962
- exports.serializeEffects = serializeEffects;
963
- function parseEffects(info, log) {
964
- var effects = {};
965
- var masterFXSwitch = info.masterFXSwitch, DrSh = info.DrSh, dropShadowMulti = info.dropShadowMulti, IrSh = info.IrSh, innerShadowMulti = info.innerShadowMulti, OrGl = info.OrGl, IrGl = info.IrGl, ebbl = info.ebbl, SoFi = info.SoFi, solidFillMulti = info.solidFillMulti, patternFill = info.patternFill, GrFl = info.GrFl, gradientFillMulti = info.gradientFillMulti, ChFX = info.ChFX, FrFX = info.FrFX, frameFXMulti = info.frameFXMulti, numModifyingFX = info.numModifyingFX, rest = __rest(info, ["masterFXSwitch", "DrSh", "dropShadowMulti", "IrSh", "innerShadowMulti", "OrGl", "IrGl", "ebbl", "SoFi", "solidFillMulti", "patternFill", "GrFl", "gradientFillMulti", "ChFX", "FrFX", "frameFXMulti", "numModifyingFX"]);
966
- if (!masterFXSwitch)
967
- effects.disabled = true;
968
- if (info['Scl '])
969
- effects.scale = parsePercent(info['Scl ']);
970
- if (DrSh)
971
- effects.dropShadow = [parseEffectObject(DrSh, log)];
972
- if (dropShadowMulti)
973
- effects.dropShadow = dropShadowMulti.map(function (i) { return parseEffectObject(i, log); });
974
- if (IrSh)
975
- effects.innerShadow = [parseEffectObject(IrSh, log)];
976
- if (innerShadowMulti)
977
- effects.innerShadow = innerShadowMulti.map(function (i) { return parseEffectObject(i, log); });
978
- if (OrGl)
979
- effects.outerGlow = parseEffectObject(OrGl, log);
980
- if (IrGl)
981
- effects.innerGlow = parseEffectObject(IrGl, log);
982
- if (ebbl)
983
- effects.bevel = parseEffectObject(ebbl, log);
984
- if (SoFi)
985
- effects.solidFill = [parseEffectObject(SoFi, log)];
986
- if (solidFillMulti)
987
- effects.solidFill = solidFillMulti.map(function (i) { return parseEffectObject(i, log); });
988
- if (patternFill)
989
- effects.patternOverlay = parseEffectObject(patternFill, log);
990
- if (GrFl)
991
- effects.gradientOverlay = [parseEffectObject(GrFl, log)];
992
- if (gradientFillMulti)
993
- effects.gradientOverlay = gradientFillMulti.map(function (i) { return parseEffectObject(i, log); });
994
- if (ChFX)
995
- effects.satin = parseEffectObject(ChFX, log);
996
- if (FrFX)
997
- effects.stroke = [parseFxObject(FrFX)];
998
- if (frameFXMulti)
999
- effects.stroke = frameFXMulti.map(function (i) { return parseFxObject(i); });
1000
- if (log && Object.keys(rest).length > 1)
1001
- console.log('Unhandled effect keys:', rest);
1002
- return effects;
1003
- }
1004
- exports.parseEffects = parseEffects;
1005
- function parseKeyList(keyList, logMissingFeatures) {
1006
- var keys = [];
1007
- for (var j = 0; j < keyList.length; j++) {
1008
- var key = keyList[j];
1009
- var _a = key.time, denominator = _a.denominator, numerator = _a.numerator, selected = key.selected, animKey = key.animKey;
1010
- var time = { numerator: numerator, denominator: denominator };
1011
- var interpolation = exports.animInterpStyleEnum.decode(key.animInterpStyle);
1012
- switch (animKey.Type) {
1013
- case 'keyType.Opct':
1014
- keys.push({ interpolation: interpolation, time: time, selected: selected, type: 'opacity', value: parsePercent(animKey.Opct) });
1015
- break;
1016
- case 'keyType.Pstn':
1017
- keys.push({ interpolation: interpolation, time: time, selected: selected, type: 'position', x: animKey.Hrzn, y: animKey.Vrtc });
1018
- break;
1019
- case 'keyType.Trnf':
1020
- keys.push({
1021
- interpolation: interpolation,
1022
- time: time,
1023
- selected: selected,
1024
- type: 'transform',
1025
- scale: horzVrtcToXY(animKey['Scl ']), skew: horzVrtcToXY(animKey.Skew), rotation: animKey.rotation, translation: horzVrtcToXY(animKey.translation)
1026
- });
1027
- break;
1028
- case 'keyType.sheetStyle': {
1029
- var key_1 = { interpolation: interpolation, time: time, selected: selected, type: 'style' };
1030
- if (animKey.sheetStyle.Lefx)
1031
- key_1.style = parseEffects(animKey.sheetStyle.Lefx, logMissingFeatures);
1032
- keys.push(key_1);
1033
- break;
1034
- }
1035
- case 'keyType.globalLighting': {
1036
- keys.push({
1037
- interpolation: interpolation,
1038
- time: time,
1039
- selected: selected,
1040
- type: 'globalLighting',
1041
- globalAngle: animKey.gblA, globalAltitude: animKey.globalAltitude
1042
- });
1043
- break;
1044
- }
1045
- default: throw new Error("Unsupported keyType value");
1046
- }
1047
- }
1048
- return keys;
1049
- }
1050
- function serializeKeyList(keys) {
1051
- var keyList = [];
1052
- for (var j = 0; j < keys.length; j++) {
1053
- var key = keys[j];
1054
- var time = key.time, _a = key.selected, selected = _a === void 0 ? false : _a, interpolation = key.interpolation;
1055
- var animInterpStyle = exports.animInterpStyleEnum.encode(interpolation);
1056
- var animKey = void 0;
1057
- switch (key.type) {
1058
- case 'opacity':
1059
- animKey = { Type: 'keyType.Opct', Opct: unitsPercent(key.value) };
1060
- break;
1061
- case 'position':
1062
- animKey = { Type: 'keyType.Pstn', Hrzn: key.x, Vrtc: key.y };
1063
- break;
1064
- case 'transform':
1065
- animKey = { Type: 'keyType.Trnf', 'Scl ': xyToHorzVrtc(key.scale), Skew: xyToHorzVrtc(key.skew), rotation: key.rotation, translation: xyToHorzVrtc(key.translation) };
1066
- break;
1067
- case 'style':
1068
- animKey = { Type: 'keyType.sheetStyle', sheetStyle: { Vrsn: 1, blendOptions: {} } };
1069
- if (key.style)
1070
- animKey.sheetStyle = { Vrsn: 1, Lefx: serializeEffects(key.style, false, false), blendOptions: {} };
1071
- break;
1072
- case 'globalLighting': {
1073
- animKey = { Type: 'keyType.globalLighting', gblA: key.globalAngle, globalAltitude: key.globalAltitude };
1074
- break;
1075
- }
1076
- default: throw new Error("Unsupported keyType value");
1077
- }
1078
- keyList.push({ Vrsn: 1, animInterpStyle: animInterpStyle, time: time, animKey: animKey, selected: selected });
1079
- }
1080
- return keyList;
1081
- }
1082
- function parseTrackList(trackList, logMissingFeatures) {
1083
- var tracks = [];
1084
- for (var i = 0; i < trackList.length; i++) {
1085
- var tr = trackList[i];
1086
- var track = {
1087
- type: exports.stdTrackID.decode(tr.trackID),
1088
- enabled: tr.enab,
1089
- keys: parseKeyList(tr.keyList, logMissingFeatures),
1090
- };
1091
- if (tr.effectParams) {
1092
- track.effectParams = {
1093
- fillCanvas: tr.effectParams.fillCanvas,
1094
- zoomOrigin: tr.effectParams.zoomOrigin,
1095
- keys: parseKeyList(tr.effectParams.keyList, logMissingFeatures),
1096
- };
1097
- }
1098
- tracks.push(track);
1099
- }
1100
- return tracks;
1101
- }
1102
- exports.parseTrackList = parseTrackList;
1103
- function serializeTrackList(tracks) {
1104
- var trackList = [];
1105
- for (var i = 0; i < tracks.length; i++) {
1106
- var t = tracks[i];
1107
- trackList.push(__assign(__assign({ trackID: exports.stdTrackID.encode(t.type), Vrsn: 1, enab: !!t.enabled, Effc: !!t.effectParams }, (t.effectParams ? {
1108
- effectParams: {
1109
- keyList: serializeKeyList(t.keys),
1110
- fillCanvas: t.effectParams.fillCanvas,
1111
- zoomOrigin: t.effectParams.zoomOrigin,
1112
- }
1113
- } : {})), { keyList: serializeKeyList(t.keys) }));
1114
- }
1115
- return trackList;
1116
- }
1117
- exports.serializeTrackList = serializeTrackList;
1118
- function parseEffectObject(obj, reportErrors) {
1119
- var result = {};
1120
- for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1121
- var key = _a[_i];
1122
- var val = obj[key];
1123
- switch (key) {
1124
- case 'enab':
1125
- result.enabled = !!val;
1126
- break;
1127
- case 'uglg':
1128
- result.useGlobalLight = !!val;
1129
- break;
1130
- case 'AntA':
1131
- result.antialiased = !!val;
1132
- break;
1133
- case 'Algn':
1134
- result.align = !!val;
1135
- break;
1136
- case 'Dthr':
1137
- result.dither = !!val;
1138
- break;
1139
- case 'Invr':
1140
- result.invert = !!val;
1141
- break;
1142
- case 'Rvrs':
1143
- result.reverse = !!val;
1144
- break;
1145
- case 'Clr ':
1146
- result.color = parseColor(val);
1147
- break;
1148
- case 'hglC':
1149
- result.highlightColor = parseColor(val);
1150
- break;
1151
- case 'sdwC':
1152
- result.shadowColor = parseColor(val);
1153
- break;
1154
- case 'Styl':
1155
- result.position = exports.FStl.decode(val);
1156
- break;
1157
- case 'Md ':
1158
- result.blendMode = exports.BlnM.decode(val);
1159
- break;
1160
- case 'hglM':
1161
- result.highlightBlendMode = exports.BlnM.decode(val);
1162
- break;
1163
- case 'sdwM':
1164
- result.shadowBlendMode = exports.BlnM.decode(val);
1165
- break;
1166
- case 'bvlS':
1167
- result.style = exports.BESl.decode(val);
1168
- break;
1169
- case 'bvlD':
1170
- result.direction = exports.BESs.decode(val);
1171
- break;
1172
- case 'bvlT':
1173
- result.technique = exports.bvlT.decode(val);
1174
- break;
1175
- case 'GlwT':
1176
- result.technique = exports.BETE.decode(val);
1177
- break;
1178
- case 'glwS':
1179
- result.source = exports.IGSr.decode(val);
1180
- break;
1181
- case 'Type':
1182
- result.type = exports.GrdT.decode(val);
1183
- break;
1184
- case 'gs99':
1185
- result.interpolationMethod = exports.gradientInterpolationMethodType.decode(val);
1186
- break;
1187
- case 'Opct':
1188
- result.opacity = parsePercent(val);
1189
- break;
1190
- case 'hglO':
1191
- result.highlightOpacity = parsePercent(val);
1192
- break;
1193
- case 'sdwO':
1194
- result.shadowOpacity = parsePercent(val);
1195
- break;
1196
- case 'lagl':
1197
- result.angle = parseAngle(val);
1198
- break;
1199
- case 'Angl':
1200
- result.angle = parseAngle(val);
1201
- break;
1202
- case 'Lald':
1203
- result.altitude = parseAngle(val);
1204
- break;
1205
- case 'Sftn':
1206
- result.soften = parseUnits(val);
1207
- break;
1208
- case 'srgR':
1209
- result.strength = parsePercent(val);
1210
- break;
1211
- case 'blur':
1212
- result.size = parseUnits(val);
1213
- break;
1214
- case 'Nose':
1215
- result.noise = parsePercent(val);
1216
- break;
1217
- case 'Inpr':
1218
- result.range = parsePercent(val);
1219
- break;
1220
- case 'Ckmt':
1221
- result.choke = parseUnits(val);
1222
- break;
1223
- case 'ShdN':
1224
- result.jitter = parsePercent(val);
1225
- break;
1226
- case 'Dstn':
1227
- result.distance = parseUnits(val);
1228
- break;
1229
- case 'Scl ':
1230
- result.scale = parsePercent(val);
1231
- break;
1232
- case 'Ptrn':
1233
- result.pattern = { name: val['Nm '], id: val.Idnt };
1234
- break;
1235
- case 'phase':
1236
- result.phase = { x: val.Hrzn, y: val.Vrtc };
1237
- break;
1238
- case 'Ofst':
1239
- result.offset = { x: parsePercent(val.Hrzn), y: parsePercent(val.Vrtc) };
1240
- break;
1241
- case 'MpgS':
1242
- case 'TrnS':
1243
- result.contour = {
1244
- name: val['Nm '],
1245
- curve: val['Crv '].map(function (p) { return ({ x: p.Hrzn, y: p.Vrtc }); }),
1246
- };
1247
- break;
1248
- case 'Grad':
1249
- result.gradient = parseGradient(val);
1250
- break;
1251
- case 'useTexture':
1252
- case 'useShape':
1253
- case 'layerConceals':
1254
- case 'present':
1255
- case 'showInDialog':
1256
- case 'antialiasGloss':
1257
- result[key] = val;
1258
- break;
1259
- case '_name':
1260
- case '_classID':
1261
- break;
1262
- default:
1263
- reportErrors && console.log("Invalid effect key: '".concat(key, "', value:"), val);
1264
- }
1265
- }
1266
- return result;
1267
- }
1268
- function serializeEffectObject(obj, objName, reportErrors) {
1269
- var result = {
1270
- enab: false,
1271
- };
1272
- if (objName === 'dropShadow') {
1273
- result.TrnS = { 'Nm ': '', 'Crv ': [] };
1274
- }
1275
- for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1276
- var objKey = _a[_i];
1277
- var key = objKey;
1278
- var val = obj[key];
1279
- switch (key) {
1280
- case 'enabled':
1281
- result.enab = !!val;
1282
- break;
1283
- case 'useGlobalLight':
1284
- result.uglg = !!val;
1285
- break;
1286
- case 'antialiased':
1287
- result.AntA = !!val;
1288
- break;
1289
- case 'align':
1290
- result.Algn = !!val;
1291
- break;
1292
- case 'dither':
1293
- result.Dthr = !!val;
1294
- break;
1295
- case 'invert':
1296
- result.Invr = !!val;
1297
- break;
1298
- case 'reverse':
1299
- result.Rvrs = !!val;
1300
- break;
1301
- case 'color':
1302
- result['Clr '] = serializeColor(val);
1303
- break;
1304
- case 'highlightColor':
1305
- result.hglC = serializeColor(val);
1306
- break;
1307
- case 'shadowColor':
1308
- result.sdwC = serializeColor(val);
1309
- break;
1310
- case 'position':
1311
- result.Styl = exports.FStl.encode(val);
1312
- break;
1313
- case 'blendMode':
1314
- result['Md '] = exports.BlnM.encode(val);
1315
- break;
1316
- case 'highlightBlendMode':
1317
- result.hglM = exports.BlnM.encode(val);
1318
- break;
1319
- case 'shadowBlendMode':
1320
- result.sdwM = exports.BlnM.encode(val);
1321
- break;
1322
- case 'style':
1323
- result.bvlS = exports.BESl.encode(val);
1324
- break;
1325
- case 'direction':
1326
- result.bvlD = exports.BESs.encode(val);
1327
- break;
1328
- case 'technique':
1329
- if (objName === 'bevel') {
1330
- result.bvlT = exports.bvlT.encode(val);
1331
- }
1332
- else {
1333
- result.GlwT = exports.BETE.encode(val);
1334
- }
1335
- break;
1336
- case 'source':
1337
- result.glwS = exports.IGSr.encode(val);
1338
- break;
1339
- case 'type':
1340
- result.Type = exports.GrdT.encode(val);
1341
- break;
1342
- case 'interpolationMethod':
1343
- result.gs99 = exports.gradientInterpolationMethodType.encode(val);
1344
- break;
1345
- case 'opacity':
1346
- result.Opct = unitsPercent(val);
1347
- break;
1348
- case 'highlightOpacity':
1349
- result.hglO = unitsPercent(val);
1350
- break;
1351
- case 'shadowOpacity':
1352
- result.sdwO = unitsPercent(val);
1353
- break;
1354
- case 'angle':
1355
- if (objName === 'gradientOverlay' || objName === 'patternFill') {
1356
- result.Angl = unitsAngle(val);
1357
- }
1358
- else {
1359
- result.lagl = unitsAngle(val);
1360
- }
1361
- break;
1362
- case 'altitude':
1363
- result.Lald = unitsAngle(val);
1364
- break;
1365
- case 'soften':
1366
- result.Sftn = unitsValue(val, key);
1367
- break;
1368
- case 'strength':
1369
- result.srgR = unitsPercent(val);
1370
- break;
1371
- case 'size':
1372
- result.blur = unitsValue(val, key);
1373
- break;
1374
- case 'noise':
1375
- result.Nose = unitsPercent(val);
1376
- break;
1377
- case 'range':
1378
- result.Inpr = unitsPercent(val);
1379
- break;
1380
- case 'choke':
1381
- result.Ckmt = unitsValue(val, key);
1382
- break;
1383
- case 'jitter':
1384
- result.ShdN = unitsPercent(val);
1385
- break;
1386
- case 'distance':
1387
- result.Dstn = unitsValue(val, key);
1388
- break;
1389
- case 'scale':
1390
- result['Scl '] = unitsPercent(val);
1391
- break;
1392
- case 'pattern':
1393
- result.Ptrn = { 'Nm ': val.name, Idnt: val.id };
1394
- break;
1395
- case 'phase':
1396
- result.phase = { Hrzn: val.x, Vrtc: val.y };
1397
- break;
1398
- case 'offset':
1399
- result.Ofst = { Hrzn: unitsPercent(val.x), Vrtc: unitsPercent(val.y) };
1400
- break;
1401
- case 'contour': {
1402
- result[objName === 'satin' ? 'MpgS' : 'TrnS'] = {
1403
- 'Nm ': val.name,
1404
- 'Crv ': val.curve.map(function (p) { return ({ Hrzn: p.x, Vrtc: p.y }); }),
1405
- };
1406
- break;
1407
- }
1408
- case 'gradient':
1409
- result.Grad = serializeGradient(val);
1410
- break;
1411
- case 'useTexture':
1412
- case 'useShape':
1413
- case 'layerConceals':
1414
- case 'present':
1415
- case 'showInDialog':
1416
- case 'antialiasGloss':
1417
- result[key] = val;
1418
- break;
1419
- default:
1420
- reportErrors && console.log("Invalid effect key: '".concat(key, "', value:"), val);
1421
- }
1422
- }
1423
- return result;
1424
- }
1425
- function parseGradient(grad) {
1426
- if (grad.GrdF === 'GrdF.CstS') {
1427
- var samples_1 = grad.Intr || 4096;
1428
- return {
1429
- type: 'solid',
1430
- name: grad['Nm '],
1431
- smoothness: grad.Intr / 4096,
1432
- colorStops: grad.Clrs.map(function (s) { return ({
1433
- color: parseColor(s['Clr ']),
1434
- location: s.Lctn / samples_1,
1435
- midpoint: s.Mdpn / 100,
1436
- }); }),
1437
- opacityStops: grad.Trns.map(function (s) { return ({
1438
- opacity: parsePercent(s.Opct),
1439
- location: s.Lctn / samples_1,
1440
- midpoint: s.Mdpn / 100,
1441
- }); }),
1442
- };
1443
- }
1444
- else {
1445
- return {
1446
- type: 'noise',
1447
- name: grad['Nm '],
1448
- roughness: grad.Smth / 4096,
1449
- colorModel: exports.ClrS.decode(grad.ClrS),
1450
- randomSeed: grad.RndS,
1451
- restrictColors: !!grad.VctC,
1452
- addTransparency: !!grad.ShTr,
1453
- min: grad['Mnm '].map(function (x) { return x / 100; }),
1454
- max: grad['Mxm '].map(function (x) { return x / 100; }),
1455
- };
1456
- }
1457
- }
1458
- function serializeGradient(grad) {
1459
- var _a, _b;
1460
- if (grad.type === 'solid') {
1461
- var samples_2 = Math.round(((_a = grad.smoothness) !== null && _a !== void 0 ? _a : 1) * 4096);
1462
- return {
1463
- 'Nm ': grad.name || '',
1464
- GrdF: 'GrdF.CstS',
1465
- Intr: samples_2,
1466
- Clrs: grad.colorStops.map(function (s) {
1467
- var _a;
1468
- return ({
1469
- 'Clr ': serializeColor(s.color),
1470
- Type: 'Clry.UsrS',
1471
- Lctn: Math.round(s.location * samples_2),
1472
- Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
1473
- });
1474
- }),
1475
- Trns: grad.opacityStops.map(function (s) {
1476
- var _a;
1477
- return ({
1478
- Opct: unitsPercent(s.opacity),
1479
- Lctn: Math.round(s.location * samples_2),
1480
- Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
1481
- });
1482
- }),
1483
- };
1484
- }
1485
- else {
1486
- return {
1487
- GrdF: 'GrdF.ClNs',
1488
- 'Nm ': grad.name || '',
1489
- ShTr: !!grad.addTransparency,
1490
- VctC: !!grad.restrictColors,
1491
- ClrS: exports.ClrS.encode(grad.colorModel),
1492
- RndS: grad.randomSeed || 0,
1493
- Smth: Math.round(((_b = grad.roughness) !== null && _b !== void 0 ? _b : 1) * 4096),
1494
- 'Mnm ': (grad.min || [0, 0, 0, 0]).map(function (x) { return x * 100; }),
1495
- 'Mxm ': (grad.max || [1, 1, 1, 1]).map(function (x) { return x * 100; }),
1496
- };
1497
- }
1498
- }
1499
- function parseGradientContent(descriptor) {
1500
- var result = parseGradient(descriptor.Grad);
1501
- result.style = exports.GrdT.decode(descriptor.Type);
1502
- if (descriptor.Dthr !== undefined)
1503
- result.dither = descriptor.Dthr;
1504
- if (descriptor.gradientsInterpolationMethod !== undefined)
1505
- result.interpolationMethod = exports.gradientInterpolationMethodType.decode(descriptor.gradientsInterpolationMethod);
1506
- if (descriptor.Rvrs !== undefined)
1507
- result.reverse = descriptor.Rvrs;
1508
- if (descriptor.Angl !== undefined)
1509
- result.angle = parseAngle(descriptor.Angl);
1510
- if (descriptor['Scl '] !== undefined)
1511
- result.scale = parsePercent(descriptor['Scl ']);
1512
- if (descriptor.Algn !== undefined)
1513
- result.align = descriptor.Algn;
1514
- if (descriptor.Ofst !== undefined) {
1515
- result.offset = {
1516
- x: parsePercent(descriptor.Ofst.Hrzn),
1517
- y: parsePercent(descriptor.Ofst.Vrtc)
1518
- };
1519
- }
1520
- return result;
1521
- }
1522
- function parsePatternContent(descriptor) {
1523
- var result = {
1524
- name: descriptor.Ptrn['Nm '],
1525
- id: descriptor.Ptrn.Idnt,
1526
- };
1527
- if (descriptor.Lnkd !== undefined)
1528
- result.linked = descriptor.Lnkd;
1529
- if (descriptor.phase !== undefined)
1530
- result.phase = { x: descriptor.phase.Hrzn, y: descriptor.phase.Vrtc };
1531
- return result;
1532
- }
1533
- function parseVectorContent(descriptor) {
1534
- if ('Grad' in descriptor) {
1535
- return parseGradientContent(descriptor);
1536
- }
1537
- else if ('Ptrn' in descriptor) {
1538
- return __assign({ type: 'pattern' }, parsePatternContent(descriptor));
1539
- }
1540
- else if ('Clr ' in descriptor) {
1541
- return { type: 'color', color: parseColor(descriptor['Clr ']) };
1542
- }
1543
- else {
1544
- throw new Error('Invalid vector content');
1545
- }
1546
- }
1547
- exports.parseVectorContent = parseVectorContent;
1548
- function serializeGradientContent(content) {
1549
- var result = {};
1550
- if (content.dither !== undefined)
1551
- result.Dthr = content.dither;
1552
- if (content.interpolationMethod !== undefined)
1553
- result.gradientsInterpolationMethod = exports.gradientInterpolationMethodType.encode(content.interpolationMethod);
1554
- if (content.reverse !== undefined)
1555
- result.Rvrs = content.reverse;
1556
- if (content.angle !== undefined)
1557
- result.Angl = unitsAngle(content.angle);
1558
- result.Type = exports.GrdT.encode(content.style);
1559
- if (content.align !== undefined)
1560
- result.Algn = content.align;
1561
- if (content.scale !== undefined)
1562
- result['Scl '] = unitsPercent(content.scale);
1563
- if (content.offset) {
1564
- result.Ofst = {
1565
- Hrzn: unitsPercent(content.offset.x),
1566
- Vrtc: unitsPercent(content.offset.y),
1567
- };
1568
- }
1569
- result.Grad = serializeGradient(content);
1570
- return result;
1571
- }
1572
- function serializePatternContent(content) {
1573
- var result = {
1574
- Ptrn: {
1575
- 'Nm ': content.name || '',
1576
- Idnt: content.id || '',
1577
- }
1578
- };
1579
- if (content.linked !== undefined)
1580
- result.Lnkd = !!content.linked;
1581
- if (content.phase !== undefined)
1582
- result.phase = { Hrzn: content.phase.x, Vrtc: content.phase.y };
1583
- return result;
1584
- }
1585
- function serializeVectorContent(content) {
1586
- if (content.type === 'color') {
1587
- return { key: 'SoCo', descriptor: { 'Clr ': serializeColor(content.color) } };
1588
- }
1589
- else if (content.type === 'pattern') {
1590
- return { key: 'PtFl', descriptor: serializePatternContent(content) };
1591
- }
1592
- else {
1593
- return { key: 'GdFl', descriptor: serializeGradientContent(content) };
1594
- }
1595
- }
1596
- exports.serializeVectorContent = serializeVectorContent;
1597
- function parseColor(color) {
1598
- if ('H ' in color) {
1599
- return { h: parsePercentOrAngle(color['H ']), s: color.Strt, b: color.Brgh };
1600
- }
1601
- else if ('Rd ' in color) {
1602
- return { r: color['Rd '], g: color['Grn '], b: color['Bl '] };
1603
- }
1604
- else if ('Cyn ' in color) {
1605
- return { c: color['Cyn '], m: color.Mgnt, y: color['Ylw '], k: color.Blck };
1606
- }
1607
- else if ('Gry ' in color) {
1608
- return { k: color['Gry '] };
1609
- }
1610
- else if ('Lmnc' in color) {
1611
- return { l: color.Lmnc, a: color['A '], b: color['B '] };
1612
- }
1613
- else if ('redFloat' in color) {
1614
- return { fr: color.redFloat, fg: color.greenFloat, fb: color.blueFloat };
1615
- }
1616
- else {
1617
- throw new Error('Unsupported color descriptor');
1618
- }
1619
- }
1620
- exports.parseColor = parseColor;
1621
- function serializeColor(color) {
1622
- if (!color) {
1623
- return { _name: '', _classID: 'RGBC', 'Rd ': 0, 'Grn ': 0, 'Bl ': 0 };
1624
- }
1625
- else if ('r' in color) {
1626
- return { _name: '', _classID: 'RGBC', 'Rd ': color.r || 0, 'Grn ': color.g || 0, 'Bl ': color.b || 0 };
1627
- }
1628
- else if ('fr' in color) {
1629
- return { _name: '', _classID: 'RGBC', redFloat: color.fr, greenFloat: color.fg, blueFloat: color.fb };
1630
- }
1631
- else if ('h' in color) {
1632
- return { _name: '', _classID: 'HSBC', 'H ': unitsAngle(color.h * 360), Strt: color.s || 0, Brgh: color.b || 0 };
1633
- }
1634
- else if ('c' in color) {
1635
- return { _name: '', _classID: 'CMYC', 'Cyn ': color.c || 0, Mgnt: color.m || 0, 'Ylw ': color.y || 0, Blck: color.k || 0 };
1636
- }
1637
- else if ('l' in color) {
1638
- return { _name: '', _classID: 'LABC', Lmnc: color.l || 0, 'A ': color.a || 0, 'B ': color.b || 0 };
1639
- }
1640
- else if ('k' in color) {
1641
- return { _name: '', _classID: 'GRYC', 'Gry ': color.k };
1642
- }
1643
- else {
1644
- throw new Error('Invalid color value');
1645
- }
1646
- }
1647
- exports.serializeColor = serializeColor;
1648
- function parseAngle(x) {
1649
- if (x === undefined)
1650
- return 0;
1651
- if (x.units !== 'Angle')
1652
- throw new Error("Invalid units: ".concat(x.units));
1653
- return x.value;
1654
- }
1655
- exports.parseAngle = parseAngle;
1656
- function parsePercent(x) {
1657
- if (x === undefined)
1658
- return 1;
1659
- if (x.units !== 'Percent')
1660
- throw new Error("Invalid units: ".concat(x.units));
1661
- return x.value / 100;
1662
- }
1663
- exports.parsePercent = parsePercent;
1664
- function parsePercentOrAngle(x) {
1665
- if (x === undefined)
1666
- return 1;
1667
- if (x.units === 'Percent')
1668
- return x.value / 100;
1669
- if (x.units === 'Angle')
1670
- return x.value / 360;
1671
- throw new Error("Invalid units: ".concat(x.units));
1672
- }
1673
- exports.parsePercentOrAngle = parsePercentOrAngle;
1674
- function parseUnits(_a) {
1675
- var units = _a.units, value = _a.value;
1676
- if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
1677
- units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
1678
- throw new Error("Invalid units: ".concat(JSON.stringify({ units: units, value: value })));
1679
- }
1680
- return { value: value, units: units };
1681
- }
1682
- exports.parseUnits = parseUnits;
1683
- function parseUnitsOrNumber(value, units) {
1684
- if (units === void 0) { units = 'Pixels'; }
1685
- if (typeof value === 'number')
1686
- return { value: value, units: units };
1687
- return parseUnits(value);
1688
- }
1689
- exports.parseUnitsOrNumber = parseUnitsOrNumber;
1690
- function parseUnitsToNumber(_a, expectedUnits) {
1691
- var units = _a.units, value = _a.value;
1692
- if (units !== expectedUnits)
1693
- throw new Error("Invalid units: ".concat(JSON.stringify({ units: units, value: value })));
1694
- return value;
1695
- }
1696
- exports.parseUnitsToNumber = parseUnitsToNumber;
1697
- function unitsAngle(value) {
1698
- return { units: 'Angle', value: value || 0 };
1699
- }
1700
- exports.unitsAngle = unitsAngle;
1701
- function unitsPercent(value) {
1702
- return { units: 'Percent', value: Math.round((value || 0) * 100) };
1703
- }
1704
- exports.unitsPercent = unitsPercent;
1705
- function unitsPercentF(value) {
1706
- return { units: 'Percent', value: (value || 0) * 100 };
1707
- }
1708
- exports.unitsPercentF = unitsPercentF;
1709
- function unitsValue(x, key) {
1710
- if (x == null)
1711
- return { units: 'Pixels', value: 0 };
1712
- if (typeof x !== 'object')
1713
- throw new Error("Invalid value: ".concat(JSON.stringify(x), " (key: ").concat(key, ") (should have value and units)"));
1714
- var units = x.units, value = x.value;
1715
- if (typeof value !== 'number')
1716
- throw new Error("Invalid value in ".concat(JSON.stringify(x), " (key: ").concat(key, ")"));
1717
- if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
1718
- units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
1719
- throw new Error("Invalid units in ".concat(JSON.stringify(x), " (key: ").concat(key, ")"));
1720
- }
1721
- return { units: units, value: value };
1722
- }
1723
- exports.unitsValue = unitsValue;
1724
- function frac(_a) {
1725
- var numerator = _a.numerator, denominator = _a.denominator;
1726
- return { numerator: numerator, denominator: denominator };
1727
- }
1728
- exports.frac = frac;
1729
- exports.textGridding = (0, helpers_1.createEnum)('textGridding', 'none', {
1730
- none: 'None',
1731
- round: 'Rnd ',
1732
- });
1733
- exports.Ornt = (0, helpers_1.createEnum)('Ornt', 'horizontal', {
1734
- horizontal: 'Hrzn',
1735
- vertical: 'Vrtc',
1736
- });
1737
- exports.Annt = (0, helpers_1.createEnum)('Annt', 'sharp', {
1738
- none: 'Anno',
1739
- sharp: 'antiAliasSharp',
1740
- crisp: 'AnCr',
1741
- strong: 'AnSt',
1742
- smooth: 'AnSm',
1743
- platform: 'antiAliasPlatformGray',
1744
- platformLCD: 'antiAliasPlatformLCD',
1745
- });
1746
- exports.warpStyle = (0, helpers_1.createEnum)('warpStyle', 'none', {
1747
- none: 'warpNone',
1748
- arc: 'warpArc',
1749
- arcLower: 'warpArcLower',
1750
- arcUpper: 'warpArcUpper',
1751
- arch: 'warpArch',
1752
- bulge: 'warpBulge',
1753
- shellLower: 'warpShellLower',
1754
- shellUpper: 'warpShellUpper',
1755
- flag: 'warpFlag',
1756
- wave: 'warpWave',
1757
- fish: 'warpFish',
1758
- rise: 'warpRise',
1759
- fisheye: 'warpFisheye',
1760
- inflate: 'warpInflate',
1761
- squeeze: 'warpSqueeze',
1762
- twist: 'warpTwist',
1763
- cylinder: 'warpCylinder',
1764
- custom: 'warpCustom',
1765
- });
1766
- exports.BlnM = (0, helpers_1.createEnum)('BlnM', 'normal', {
1767
- 'normal': 'Nrml',
1768
- 'dissolve': 'Dslv',
1769
- 'darken': 'Drkn',
1770
- 'multiply': 'Mltp',
1771
- 'color burn': 'CBrn',
1772
- 'linear burn': 'linearBurn',
1773
- 'darker color': 'darkerColor',
1774
- 'lighten': 'Lghn',
1775
- 'screen': 'Scrn',
1776
- 'color dodge': 'CDdg',
1777
- 'linear dodge': 'linearDodge',
1778
- 'lighter color': 'lighterColor',
1779
- 'overlay': 'Ovrl',
1780
- 'soft light': 'SftL',
1781
- 'hard light': 'HrdL',
1782
- 'vivid light': 'vividLight',
1783
- 'linear light': 'linearLight',
1784
- 'pin light': 'pinLight',
1785
- 'hard mix': 'hardMix',
1786
- 'difference': 'Dfrn',
1787
- 'exclusion': 'Xclu',
1788
- 'subtract': 'blendSubtraction',
1789
- 'divide': 'blendDivide',
1790
- 'hue': 'H ',
1791
- 'saturation': 'Strt',
1792
- 'color': 'Clr ',
1793
- 'luminosity': 'Lmns',
1794
- // used in ABR
1795
- 'linear height': 'linearHeight',
1796
- 'height': 'Hght',
1797
- 'subtraction': 'Sbtr', // 2nd version of subtract ?
1798
- });
1799
- exports.BESl = (0, helpers_1.createEnum)('BESl', 'inner bevel', {
1800
- 'inner bevel': 'InrB',
1801
- 'outer bevel': 'OtrB',
1802
- 'emboss': 'Embs',
1803
- 'pillow emboss': 'PlEb',
1804
- 'stroke emboss': 'strokeEmboss',
1805
- });
1806
- exports.bvlT = (0, helpers_1.createEnum)('bvlT', 'smooth', {
1807
- 'smooth': 'SfBL',
1808
- 'chisel hard': 'PrBL',
1809
- 'chisel soft': 'Slmt',
1810
- });
1811
- exports.BESs = (0, helpers_1.createEnum)('BESs', 'up', {
1812
- up: 'In ',
1813
- down: 'Out ',
1814
- });
1815
- exports.BETE = (0, helpers_1.createEnum)('BETE', 'softer', {
1816
- softer: 'SfBL',
1817
- precise: 'PrBL',
1818
- });
1819
- exports.IGSr = (0, helpers_1.createEnum)('IGSr', 'edge', {
1820
- edge: 'SrcE',
1821
- center: 'SrcC',
1822
- });
1823
- exports.GrdT = (0, helpers_1.createEnum)('GrdT', 'linear', {
1824
- linear: 'Lnr ',
1825
- radial: 'Rdl ',
1826
- angle: 'Angl',
1827
- reflected: 'Rflc',
1828
- diamond: 'Dmnd',
1829
- });
1830
- exports.animInterpStyleEnum = (0, helpers_1.createEnum)('animInterpStyle', 'linear', {
1831
- linear: 'Lnr ',
1832
- hold: 'hold',
1833
- });
1834
- exports.stdTrackID = (0, helpers_1.createEnum)('stdTrackID', 'opacity', {
1835
- opacity: 'opacityTrack',
1836
- style: 'styleTrack',
1837
- sheetTransform: 'sheetTransformTrack',
1838
- sheetPosition: 'sheetPositionTrack',
1839
- globalLighting: 'globalLightingTrack',
1840
- });
1841
- exports.gradientInterpolationMethodType = (0, helpers_1.createEnum)('gradientInterpolationMethodType', 'perceptual', {
1842
- perceptual: 'Perc',
1843
- linear: 'Lnr ',
1844
- classic: 'Gcls',
1845
- smooth: 'Smoo',
1846
- // TODO: stripes
1847
- });
1848
- exports.ClrS = (0, helpers_1.createEnum)('ClrS', 'rgb', {
1849
- rgb: 'RGBC',
1850
- hsb: 'HSBl',
1851
- lab: 'LbCl',
1852
- hsl: 'HSLC',
1853
- });
1854
- exports.FStl = (0, helpers_1.createEnum)('FStl', 'outside', {
1855
- outside: 'OutF',
1856
- center: 'CtrF',
1857
- inside: 'InsF'
1858
- });
1859
- exports.FrFl = (0, helpers_1.createEnum)('FrFl', 'color', {
1860
- color: 'SClr',
1861
- gradient: 'GrFl',
1862
- pattern: 'Ptrn',
1863
- });
1864
- exports.ESliceType = (0, helpers_1.createEnum)('ESliceType', 'image', {
1865
- image: 'Img ',
1866
- noImage: 'noImage',
1867
- });
1868
- exports.ESliceHorzAlign = (0, helpers_1.createEnum)('ESliceHorzAlign', 'default', {
1869
- default: 'default',
1870
- });
1871
- exports.ESliceVertAlign = (0, helpers_1.createEnum)('ESliceVertAlign', 'default', {
1872
- default: 'default',
1873
- });
1874
- exports.ESliceOrigin = (0, helpers_1.createEnum)('ESliceOrigin', 'userGenerated', {
1875
- userGenerated: 'userGenerated',
1876
- autoGenerated: 'autoGenerated',
1877
- layer: 'layer',
1878
- });
1879
- exports.ESliceBGColorType = (0, helpers_1.createEnum)('ESliceBGColorType', 'none', {
1880
- none: 'None',
1881
- matte: 'matte',
1882
- color: 'Clr ',
1883
- });
1884
- exports.strokeStyleLineCapType = (0, helpers_1.createEnum)('strokeStyleLineCapType', 'butt', {
1885
- butt: 'strokeStyleButtCap',
1886
- round: 'strokeStyleRoundCap',
1887
- square: 'strokeStyleSquareCap',
1888
- });
1889
- exports.strokeStyleLineJoinType = (0, helpers_1.createEnum)('strokeStyleLineJoinType', 'miter', {
1890
- miter: 'strokeStyleMiterJoin',
1891
- round: 'strokeStyleRoundJoin',
1892
- bevel: 'strokeStyleBevelJoin',
1893
- });
1894
- exports.strokeStyleLineAlignment = (0, helpers_1.createEnum)('strokeStyleLineAlignment', 'inside', {
1895
- inside: 'strokeStyleAlignInside',
1896
- center: 'strokeStyleAlignCenter',
1897
- outside: 'strokeStyleAlignOutside',
1898
- });
1899
- exports.BlrM = (0, helpers_1.createEnum)('BlrM', 'ispinmage', {
1900
- spin: 'Spn ',
1901
- zoom: 'Zm ',
1902
- });
1903
- exports.BlrQ = (0, helpers_1.createEnum)('BlrQ', 'good', {
1904
- draft: 'Drft',
1905
- good: 'Gd ',
1906
- best: 'Bst ',
1907
- });
1908
- exports.SmBM = (0, helpers_1.createEnum)('SmBM', 'normal', {
1909
- normal: 'SBMN',
1910
- 'edge only': 'SBME',
1911
- 'overlay edge': 'SBMO',
1912
- });
1913
- exports.SmBQ = (0, helpers_1.createEnum)('SmBQ', 'medium', {
1914
- low: 'SBQL',
1915
- medium: 'SBQM',
1916
- high: 'SBQH',
1917
- });
1918
- exports.DspM = (0, helpers_1.createEnum)('DspM', 'stretch to fit', {
1919
- 'stretch to fit': 'StrF',
1920
- 'tile': 'Tile',
1921
- });
1922
- exports.UndA = (0, helpers_1.createEnum)('UndA', 'repeat edge pixels', {
1923
- 'wrap around': 'WrpA',
1924
- 'repeat edge pixels': 'RptE',
1925
- });
1926
- exports.Cnvr = (0, helpers_1.createEnum)('Cnvr', 'rectangular to polar', {
1927
- 'rectangular to polar': 'RctP',
1928
- 'polar to rectangular': 'PlrR',
1929
- });
1930
- exports.RplS = (0, helpers_1.createEnum)('RplS', 'medium', {
1931
- small: 'Sml ',
1932
- medium: 'Mdm ',
1933
- large: 'Lrg ',
1934
- });
1935
- exports.SphM = (0, helpers_1.createEnum)('SphM', 'normal', {
1936
- 'normal': 'Nrml',
1937
- 'horizontal only': 'HrzO',
1938
- 'vertical only': 'VrtO',
1939
- });
1940
- exports.Wvtp = (0, helpers_1.createEnum)('Wvtp', 'sine', {
1941
- sine: 'WvSn',
1942
- triangle: 'WvTr',
1943
- square: 'WvSq',
1944
- });
1945
- exports.ZZTy = (0, helpers_1.createEnum)('ZZTy', 'pond ripples', {
1946
- 'around center': 'ArnC',
1947
- 'out from center': 'OtFr',
1948
- 'pond ripples': 'PndR',
1949
- });
1950
- exports.Dstr = (0, helpers_1.createEnum)('Dstr', 'uniform', {
1951
- uniform: 'Unfr',
1952
- gaussian: 'Gsn ',
1953
- });
1954
- exports.Chnl = (0, helpers_1.createEnum)('Chnl', 'composite', {
1955
- red: 'Rd ',
1956
- green: 'Grn ',
1957
- blue: 'Bl ',
1958
- composite: 'Cmps',
1959
- });
1960
- exports.MztT = (0, helpers_1.createEnum)('MztT', 'fine dots', {
1961
- 'fine dots': 'FnDt',
1962
- 'medium dots': 'MdmD',
1963
- 'grainy dots': 'GrnD',
1964
- 'coarse dots': 'CrsD',
1965
- 'short lines': 'ShrL',
1966
- 'medium lines': 'MdmL',
1967
- 'long lines': 'LngL',
1968
- 'short strokes': 'ShSt',
1969
- 'medium strokes': 'MdmS',
1970
- 'long strokes': 'LngS',
1971
- });
1972
- exports.Lns = (0, helpers_1.createEnum)('Lns ', '50-300mm zoom', {
1973
- '50-300mm zoom': 'Zm ',
1974
- '32mm prime': 'Nkn ',
1975
- '105mm prime': 'Nkn1',
1976
- 'movie prime': 'PnVs',
1977
- });
1978
- exports.blurType = (0, helpers_1.createEnum)('blurType', 'gaussian blur', {
1979
- 'gaussian blur': 'GsnB',
1980
- 'lens blur': 'lensBlur',
1981
- 'motion blur': 'MtnB',
1982
- });
1983
- exports.DfsM = (0, helpers_1.createEnum)('DfsM', 'normal', {
1984
- 'normal': 'Nrml',
1985
- 'darken only': 'DrkO',
1986
- 'lighten only': 'LghO',
1987
- 'anisotropic': 'anisotropic',
1988
- });
1989
- exports.ExtT = (0, helpers_1.createEnum)('ExtT', 'blocks', {
1990
- blocks: 'Blks',
1991
- pyramids: 'Pyrm',
1992
- });
1993
- exports.ExtR = (0, helpers_1.createEnum)('ExtR', 'random', {
1994
- random: 'Rndm',
1995
- 'level-based': 'LvlB',
1996
- });
1997
- exports.FlCl = (0, helpers_1.createEnum)('FlCl', 'background color', {
1998
- 'background color': 'FlBc',
1999
- 'foreground color': 'FlFr',
2000
- 'inverse image': 'FlIn',
2001
- 'unaltered image': 'FlSm',
2002
- });
2003
- exports.CntE = (0, helpers_1.createEnum)('CntE', 'upper', {
2004
- lower: 'Lwr ',
2005
- upper: 'Upr ',
2006
- });
2007
- exports.WndM = (0, helpers_1.createEnum)('WndM', 'wind', {
2008
- wind: 'Wnd ',
2009
- blast: 'Blst',
2010
- stagger: 'Stgr',
2011
- });
2012
- exports.Drct = (0, helpers_1.createEnum)('Drct', 'from the right', {
2013
- left: 'Left',
2014
- right: 'Rght',
2015
- });
2016
- exports.IntE = (0, helpers_1.createEnum)('IntE', 'odd lines', {
2017
- 'odd lines': 'ElmO',
2018
- 'even lines': 'ElmE',
2019
- });
2020
- exports.IntC = (0, helpers_1.createEnum)('IntC', 'interpolation', {
2021
- duplication: 'CrtD',
2022
- interpolation: 'CrtI',
2023
- });
2024
- exports.FlMd = (0, helpers_1.createEnum)('FlMd', 'wrap around', {
2025
- 'set to transparent': 'Bckg',
2026
- 'repeat edge pixels': 'Rpt ',
2027
- 'wrap around': 'Wrp ',
2028
- });
2029
- exports.prjM = (0, helpers_1.createEnum)('prjM', 'fisheye', {
2030
- 'fisheye': 'fisP',
2031
- 'perspective': 'perP',
2032
- 'auto': 'auto',
2033
- 'full spherical': 'fusP',
2034
- });
2035
- exports.presetKindType = (0, helpers_1.createEnum)('presetKindType', 'presetKindCustom', {
2036
- custom: 'presetKindCustom',
2037
- default: 'presetKindDefault',
2038
- });
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.IntC = exports.IntE = exports.Drct = exports.WndM = exports.CntE = exports.FlCl = exports.ExtR = exports.ExtT = exports.DfsM = exports.blurType = exports.Lns = exports.MztT = exports.Chnl = exports.Dstr = exports.ZZTy = exports.Wvtp = exports.SphM = exports.RplS = exports.Cnvr = exports.UndA = exports.DspM = exports.SmBQ = exports.SmBM = exports.BlrQ = exports.BlrM = exports.strokeStyleLineAlignment = exports.strokeStyleLineJoinType = exports.strokeStyleLineCapType = exports.ESliceBGColorType = exports.ESliceOrigin = exports.ESliceVertAlign = exports.ESliceHorzAlign = exports.ESliceType = exports.FrFl = exports.FStl = exports.ClrS = exports.gradientInterpolationMethodType = exports.stdTrackID = exports.animInterpStyleEnum = exports.GrdT = exports.IGSr = exports.BETE = exports.BESs = exports.bvlT = exports.BESl = exports.BlnM = exports.warpStyle = exports.Annt = exports.Ornt = exports.textGridding = void 0;
15
+ exports.presetKindType = exports.prjM = exports.FlMd = void 0;
16
+ exports.setLogErrors = setLogErrors;
17
+ exports.readAsciiStringOrClassId = readAsciiStringOrClassId;
18
+ exports.readDescriptorStructure = readDescriptorStructure;
19
+ exports.writeDescriptorStructure = writeDescriptorStructure;
20
+ exports.readVersionAndDescriptor = readVersionAndDescriptor;
21
+ exports.writeVersionAndDescriptor = writeVersionAndDescriptor;
22
+ exports.horzVrtcToXY = horzVrtcToXY;
23
+ exports.xyToHorzVrtc = xyToHorzVrtc;
24
+ exports.descBoundsToBounds = descBoundsToBounds;
25
+ exports.boundsToDescBounds = boundsToDescBounds;
26
+ exports.serializeEffects = serializeEffects;
27
+ exports.parseEffects = parseEffects;
28
+ exports.parseTrackList = parseTrackList;
29
+ exports.serializeTrackList = serializeTrackList;
30
+ exports.parseVectorContent = parseVectorContent;
31
+ exports.serializeVectorContent = serializeVectorContent;
32
+ exports.parseColor = parseColor;
33
+ exports.serializeColor = serializeColor;
34
+ exports.parseAngle = parseAngle;
35
+ exports.parsePercent = parsePercent;
36
+ exports.parsePercentOrAngle = parsePercentOrAngle;
37
+ exports.parseUnits = parseUnits;
38
+ exports.parseUnitsOrNumber = parseUnitsOrNumber;
39
+ exports.parseUnitsToNumber = parseUnitsToNumber;
40
+ exports.unitsAngle = unitsAngle;
41
+ exports.unitsPercent = unitsPercent;
42
+ exports.unitsPercentF = unitsPercentF;
43
+ exports.unitsValue = unitsValue;
44
+ exports.frac = frac;
45
+ const helpers_1 = require("./helpers");
46
+ const psdReader_1 = require("./psdReader");
47
+ const psdWriter_1 = require("./psdWriter");
48
+ function revMap(map) {
49
+ const result = {};
50
+ Object.keys(map).forEach(key => result[map[key]] = key);
51
+ return result;
52
+ }
53
+ const unitsMap = {
54
+ '#Ang': 'Angle',
55
+ '#Rsl': 'Density',
56
+ '#Rlt': 'Distance',
57
+ '#Nne': 'None',
58
+ '#Prc': 'Percent',
59
+ '#Pxl': 'Pixels',
60
+ '#Mlm': 'Millimeters',
61
+ '#Pnt': 'Points',
62
+ 'RrPi': 'Picas',
63
+ 'RrIn': 'Inches',
64
+ 'RrCm': 'Centimeters',
65
+ };
66
+ const unitsMapRev = revMap(unitsMap);
67
+ let logErrors = false;
68
+ function setLogErrors(value) {
69
+ logErrors = value;
70
+ }
71
+ function makeType(name, classID) {
72
+ return { name, classID };
73
+ }
74
+ const nullType = makeType('', 'null');
75
+ const USE_CHINESE = false; // Testing
76
+ const fieldToExtType = {
77
+ strokeStyleContent: makeType('', 'solidColorLayer'),
78
+ printProofSetup: makeType(USE_CHINESE ? '校样设置' : 'Proof Setup', 'proofSetup'),
79
+ Grad: makeType(USE_CHINESE ? '渐变' : 'Gradient', 'Grdn'),
80
+ Trnf: makeType(USE_CHINESE ? '变换' : 'Transform', 'Trnf'),
81
+ patternFill: makeType('', 'patternFill'),
82
+ ebbl: makeType('', 'ebbl'),
83
+ SoFi: makeType('', 'SoFi'),
84
+ GrFl: makeType('', 'GrFl'),
85
+ sdwC: makeType('', 'RGBC'),
86
+ hglC: makeType('', 'RGBC'),
87
+ 'Clr ': makeType('', 'RGBC'),
88
+ 'tintColor': makeType('', 'RGBC'),
89
+ Ofst: makeType('', 'Pnt '),
90
+ ChFX: makeType('', 'ChFX'),
91
+ MpgS: makeType('', 'ShpC'),
92
+ DrSh: makeType('', 'DrSh'),
93
+ IrSh: makeType('', 'IrSh'),
94
+ OrGl: makeType('', 'OrGl'),
95
+ IrGl: makeType('', 'IrGl'),
96
+ TrnS: makeType('', 'ShpC'),
97
+ Ptrn: makeType('', 'Ptrn'),
98
+ FrFX: makeType('', 'FrFX'),
99
+ phase: makeType('', 'Pnt '),
100
+ frameStep: nullType,
101
+ duration: nullType,
102
+ workInTime: nullType,
103
+ workOutTime: nullType,
104
+ audioClipGroupList: nullType,
105
+ bounds: makeType('', 'Rctn'),
106
+ customEnvelopeWarp: makeType('', 'customEnvelopeWarp'),
107
+ warp: makeType('', 'warp'),
108
+ 'Sz ': makeType('', 'Pnt '),
109
+ origin: makeType('', 'Pnt '),
110
+ autoExpandOffset: makeType('', 'Pnt '),
111
+ keyOriginShapeBBox: makeType('', 'unitRect'),
112
+ Vrsn: nullType,
113
+ psVersion: nullType,
114
+ docDefaultNewArtboardBackgroundColor: makeType('', 'RGBC'),
115
+ artboardRect: makeType('', 'classFloatRect'),
116
+ keyOriginRRectRadii: makeType('', 'radii'),
117
+ keyOriginBoxCorners: nullType,
118
+ rectangleCornerA: makeType('', 'Pnt '),
119
+ rectangleCornerB: makeType('', 'Pnt '),
120
+ rectangleCornerC: makeType('', 'Pnt '),
121
+ rectangleCornerD: makeType('', 'Pnt '),
122
+ compInfo: nullType,
123
+ quiltWarp: makeType('', 'quiltWarp'),
124
+ generatorSettings: nullType,
125
+ crema: nullType,
126
+ FrIn: nullType,
127
+ blendOptions: nullType,
128
+ FXRf: nullType,
129
+ Lefx: nullType,
130
+ time: nullType,
131
+ animKey: nullType,
132
+ timeScope: nullType,
133
+ inTime: nullType,
134
+ outTime: nullType,
135
+ sheetStyle: nullType,
136
+ translation: nullType,
137
+ Skew: nullType,
138
+ boundingBox: makeType('', 'boundingBox'),
139
+ 'Lnk ': makeType('', 'ExternalFileLink'),
140
+ frameReader: makeType('', 'FrameReader'),
141
+ effectParams: makeType('', 'motionTrackEffectParams'),
142
+ Impr: makeType('None', 'none'),
143
+ Anch: makeType('', 'Pnt '),
144
+ 'Fwd ': makeType('', 'Pnt '),
145
+ 'Bwd ': makeType('', 'Pnt '),
146
+ FlrC: makeType('', 'Pnt '),
147
+ meshBoundaryPath: makeType('', 'pathClass'),
148
+ filterFX: makeType('', 'filterFXStyle'),
149
+ Fltr: makeType('', 'rigidTransform'),
150
+ FrgC: makeType('', 'RGBC'),
151
+ BckC: makeType('', 'RGBC'),
152
+ sdwM: makeType('Parameters', 'adaptCorrectTones'),
153
+ hglM: makeType('Parameters', 'adaptCorrectTones'),
154
+ customShape: makeType('', 'customShape'),
155
+ origFXRefPoint: nullType,
156
+ FXRefPoint: nullType,
157
+ ClMg: makeType('', 'ClMg'),
158
+ };
159
+ const fieldToArrayExtType = {
160
+ 'Crv ': makeType('', 'CrPt'),
161
+ Clrs: makeType('', 'Clrt'),
162
+ Trns: makeType('', 'TrnS'),
163
+ keyDescriptorList: nullType,
164
+ solidFillMulti: makeType('', 'SoFi'),
165
+ gradientFillMulti: makeType('', 'GrFl'),
166
+ dropShadowMulti: makeType('', 'DrSh'),
167
+ innerShadowMulti: makeType('', 'IrSh'),
168
+ frameFXMulti: makeType('', 'FrFX'),
169
+ FrIn: nullType,
170
+ FSts: nullType,
171
+ LaSt: nullType,
172
+ sheetTimelineOptions: nullType,
173
+ trackList: makeType('', 'animationTrack'),
174
+ globalTrackList: makeType('', 'animationTrack'),
175
+ keyList: nullType,
176
+ audioClipGroupList: nullType,
177
+ audioClipList: nullType,
178
+ countObjectList: makeType('', 'countObject'),
179
+ countGroupList: makeType('', 'countGroup'),
180
+ slices: makeType('', 'slice'),
181
+ 'Pts ': makeType('', 'Pthp'),
182
+ SbpL: makeType('', 'SbpL'),
183
+ pathComponents: makeType('', 'PaCm'),
184
+ filterFXList: makeType('', 'filterFX'),
185
+ puppetShapeList: makeType('', 'puppetShape'),
186
+ channelDenoise: makeType('', 'channelDenoiseParams'),
187
+ ShrP: makeType('', 'Pnt '),
188
+ layerSettings: nullType,
189
+ list: nullType,
190
+ Adjs: makeType('', 'CrvA'),
191
+ };
192
+ const typeToField = {
193
+ 'TEXT': [
194
+ 'Txt ', 'printerName', 'Nm ', 'Idnt', 'blackAndWhitePresetFileName', 'LUT3DFileName',
195
+ 'presetFileName', 'curvesPresetFileName', 'mixerPresetFileName', 'placed', 'description', 'reason',
196
+ 'artboardPresetName', 'json', 'clipID', 'relPath', 'fullPath', 'mediaDescriptor', 'Msge',
197
+ 'altTag', 'url', 'cellText', 'preset', 'KnNm', 'FPth', 'comment', 'originalPath',
198
+ ],
199
+ 'tdta': [
200
+ 'EngineData', 'LUT3DFileData', 'indexArray', 'originalVertexArray', 'deformedVertexArray',
201
+ 'LqMe',
202
+ ],
203
+ 'long': [
204
+ 'TextIndex', 'RndS', 'Mdpn', 'Smth', 'Lctn', 'strokeStyleVersion', 'LaID', 'Vrsn', 'Cnt ',
205
+ 'Brgh', 'Cntr', 'means', 'vibrance', 'Strt', 'bwPresetKind', 'comp', 'compID', 'originalCompID',
206
+ 'curvesPresetKind', 'mixerPresetKind', 'uOrder', 'vOrder', 'PgNm', 'totalPages', 'Crop',
207
+ 'numerator', 'denominator', 'frameCount', 'Annt', 'keyOriginType', 'unitValueQuadVersion',
208
+ 'keyOriginIndex', 'major', 'minor', 'fix', 'docDefaultNewArtboardBackgroundType', 'artboardBackgroundType',
209
+ 'numModifyingFX', 'deformNumRows', 'deformNumCols', 'FrID', 'FrDl', 'FsID', 'LCnt', 'AFrm', 'AFSt',
210
+ 'numBefore', 'numAfter', 'Spcn', 'minOpacity', 'maxOpacity', 'BlnM', 'sheetID', 'gblA', 'globalAltitude',
211
+ 'descVersion', 'frameReaderType', 'LyrI', 'zoomOrigin', 'fontSize', 'Rds ', 'sliceID',
212
+ 'topOutset', 'leftOutset', 'bottomOutset', 'rightOutset', 'filterID', 'meshQuality',
213
+ 'meshExpansion', 'meshRigidity', 'VrsM', 'VrsN', 'NmbG', 'WLMn', 'WLMx', 'AmMn', 'AmMx', 'SclH', 'SclV',
214
+ 'Lvl ', 'TlNm', 'TlOf', 'FlRs', 'Thsh', 'ShrS', 'ShrE', 'FlRs', 'Vrnc', 'Strg', 'ExtS', 'ExtD',
215
+ 'HrzS', 'VrtS', 'NmbR', 'EdgF', 'Ang1', 'Ang2', 'Ang3', 'Ang4', 'lastAppliedComp', 'capturedInfo',
216
+ ],
217
+ 'enum': [
218
+ 'textGridding', 'Ornt', 'warpStyle', 'warpRotate', 'Inte', 'Bltn', 'ClrS', 'BlrQ',
219
+ 'bvlT', 'bvlS', 'bvlD', 'Md ', 'glwS', 'GrdF', 'GlwT', 'RplS', 'BlrM', 'SmBM',
220
+ 'strokeStyleLineCapType', 'strokeStyleLineJoinType', 'strokeStyleLineAlignment',
221
+ 'strokeStyleBlendMode', 'PntT', 'Styl', 'lookupType', 'LUTFormat', 'dataOrder',
222
+ 'tableOrder', 'enableCompCore', 'enableCompCoreGPU', 'compCoreSupport', 'compCoreGPUSupport', 'Engn',
223
+ 'enableCompCoreThreads', 'gs99', 'FrDs', 'trackID', 'animInterpStyle', 'horzAlign',
224
+ 'vertAlign', 'bgColorType', 'shapeOperation', 'UndA', 'Wvtp', 'Drct', 'WndM', 'Edg ', 'FlCl', 'IntE',
225
+ 'IntC', 'Cnvr', 'Fl ', 'Dstr', 'MztT', 'Lns ', 'ExtT', 'DspM', 'ExtR', 'ZZTy', 'SphM', 'SmBQ', 'placedLayerOCIOConversion', 'gradientsInterpolationMethod',
226
+ ],
227
+ 'bool': [
228
+ 'PstS', 'printSixteenBit', 'masterFXSwitch', 'enab', 'uglg', 'antialiasGloss',
229
+ 'useShape', 'useTexture', 'uglg', 'antialiasGloss', 'useShape', 'Vsbl',
230
+ 'useTexture', 'Algn', 'Rvrs', 'Dthr', 'Invr', 'VctC', 'ShTr', 'layerConceals',
231
+ 'strokeEnabled', 'fillEnabled', 'strokeStyleScaleLock', 'strokeStyleStrokeAdjust',
232
+ 'hardProof', 'MpBl', 'paperWhite', 'useLegacy', 'Auto', 'Lab ', 'useTint', 'keyShapeInvalidated',
233
+ 'autoExpandEnabled', 'autoNestEnabled', 'autoPositionEnabled', 'shrinkwrapOnSaveEnabled',
234
+ 'present', 'showInDialog', 'overprint', 'sheetDisclosed', 'lightsDisclosed', 'meshesDisclosed',
235
+ 'materialsDisclosed', 'hasMotion', 'muted', 'Effc', 'selected', 'autoScope', 'fillCanvas',
236
+ 'cellTextIsHTML', 'Smoo', 'Clsp', 'validAtPosition', 'rigidType', 'hasoptions', 'filterMaskEnable',
237
+ 'filterMaskLinked', 'filterMaskExtendWithWhite', 'removeJPEGArtifact', 'Mnch', 'ExtF', 'ExtM',
238
+ 'moreAccurate', 'GpuY', 'LIWy', 'Cnty',
239
+ ],
240
+ 'doub': [
241
+ 'warpValue', 'warpPerspective', 'warpPerspectiveOther', 'Intr', 'Wdth', 'Hght',
242
+ 'strokeStyleMiterLimit', 'strokeStyleResolution', 'layerTime', 'keyOriginResolution',
243
+ 'xx', 'xy', 'yx', 'yy', 'tx', 'ty', 'FrGA', 'frameRate', 'audioLevel', 'rotation',
244
+ 'X ', 'Y ', 'redFloat', 'greenFloat', 'blueFloat', 'imageResolution',
245
+ 'PuX0', 'PuX1', 'PuX2', 'PuX3', 'PuY0', 'PuY1', 'PuY2', 'PuY3'
246
+ ],
247
+ 'UntF': [
248
+ 'sdwO', 'hglO', 'lagl', 'Lald', 'srgR', 'blur', 'Sftn', 'Opct', 'Dstn', 'Angl',
249
+ 'Ckmt', 'Nose', 'Inpr', 'ShdN', 'strokeStyleLineWidth', 'strokeStyleLineDashOffset',
250
+ 'strokeStyleOpacity', 'H ', 'Top ', 'Left', 'Btom', 'Rght', 'Rslt',
251
+ 'topRight', 'topLeft', 'bottomLeft', 'bottomRight', 'ClNs', 'Shrp',
252
+ ],
253
+ 'VlLs': [
254
+ 'Crv ', 'Clrs', 'Mnm ', 'Mxm ', 'Trns', 'pathList', 'strokeStyleLineDashSet', 'FrLs', 'slices',
255
+ 'LaSt', 'Trnf', 'nonAffineTransform', 'keyDescriptorList', 'guideIndeces', 'gradientFillMulti',
256
+ 'solidFillMulti', 'frameFXMulti', 'innerShadowMulti', 'dropShadowMulti', 'FrIn', 'FSts', 'FsFr',
257
+ 'sheetTimelineOptions', 'audioClipList', 'trackList', 'globalTrackList', 'keyList', 'audioClipList',
258
+ 'warpValues', 'selectedPin', 'Pts ', 'SbpL', 'pathComponents', 'pinOffsets', 'posFinalPins',
259
+ 'pinVertexIndices', 'PinP', 'PnRt', 'PnOv', 'PnDp', 'filterFXList', 'puppetShapeList', 'ShrP',
260
+ 'channelDenoise', 'Mtrx', 'layerSettings', 'list', 'compList', 'Adjs',
261
+ ],
262
+ 'ObAr': ['meshPoints', 'quiltSliceX', 'quiltSliceY'],
263
+ 'obj ': ['null', 'Chnl'],
264
+ 'Pth ': ['DspF'],
265
+ };
266
+ const channels = [
267
+ 'Rd ', 'Grn ', 'Bl ', 'Yllw', 'Ylw ', 'Cyn ', 'Mgnt', 'Blck', 'Gry ', 'Lmnc', 'A ', 'B ',
268
+ ];
269
+ const fieldToArrayType = {
270
+ 'Mnm ': 'long',
271
+ 'Mxm ': 'long',
272
+ FrLs: 'long',
273
+ strokeStyleLineDashSet: 'UntF',
274
+ Trnf: 'doub',
275
+ nonAffineTransform: 'doub',
276
+ keyDescriptorList: 'Objc',
277
+ gradientFillMulti: 'Objc',
278
+ solidFillMulti: 'Objc',
279
+ frameFXMulti: 'Objc',
280
+ innerShadowMulti: 'Objc',
281
+ dropShadowMulti: 'Objc',
282
+ LaSt: 'Objc',
283
+ FrIn: 'Objc',
284
+ FSts: 'Objc',
285
+ FsFr: 'long',
286
+ blendOptions: 'Objc',
287
+ sheetTimelineOptions: 'Objc',
288
+ keyList: 'Objc',
289
+ warpValues: 'doub',
290
+ selectedPin: 'long',
291
+ 'Pts ': 'Objc',
292
+ SbpL: 'Objc',
293
+ pathComponents: 'Objc',
294
+ pinOffsets: 'doub',
295
+ posFinalPins: 'doub',
296
+ pinVertexIndices: 'long',
297
+ PinP: 'doub',
298
+ PnRt: 'long',
299
+ PnOv: 'bool',
300
+ PnDp: 'doub',
301
+ filterFXList: 'Objc',
302
+ puppetShapeList: 'Objc',
303
+ ShrP: 'Objc',
304
+ channelDenoise: 'Objc',
305
+ Mtrx: 'long',
306
+ compList: 'long',
307
+ Chnl: 'enum',
308
+ };
309
+ const fieldToType = {};
310
+ for (const type of Object.keys(typeToField)) {
311
+ for (const field of typeToField[type]) {
312
+ fieldToType[field] = type;
313
+ }
314
+ }
315
+ for (const field of Object.keys(fieldToExtType)) {
316
+ if (!fieldToType[field])
317
+ fieldToType[field] = 'Objc';
318
+ }
319
+ for (const field of Object.keys(fieldToArrayExtType)) {
320
+ fieldToArrayType[field] = 'Objc';
321
+ }
322
+ function getTypeByKey(key, value, root, parent) {
323
+ if (key === 'presetKind') {
324
+ return typeof value === 'string' ? 'enum' : 'long';
325
+ }
326
+ if (key === 'null' && root === 'slices') {
327
+ return 'TEXT';
328
+ }
329
+ else if (key === 'groupID') {
330
+ return root === 'slices' ? 'long' : 'TEXT';
331
+ }
332
+ else if (key === 'Sz ') {
333
+ return ('Wdth' in value) ? 'Objc' : (('units' in value) ? 'UntF' : 'doub');
334
+ }
335
+ else if (key === 'Type') {
336
+ return typeof value === 'string' ? 'enum' : 'long';
337
+ }
338
+ else if (key === 'AntA') {
339
+ return typeof value === 'string' ? 'enum' : 'bool';
340
+ }
341
+ else if ((key === 'Hrzn' || key === 'Vrtc') && (parent.Type === 'keyType.Pstn' || parent._classID === 'Ofst')) {
342
+ return 'long';
343
+ }
344
+ else if (key === 'Hrzn' || key === 'Vrtc' || key === 'Top ' || key === 'Left' || key === 'Btom' || key === 'Rght') {
345
+ if (root === 'slices')
346
+ return 'long';
347
+ return typeof value === 'number' ? 'doub' : 'UntF';
348
+ }
349
+ else if (key === 'Vrsn') {
350
+ return typeof value === 'number' ? 'long' : 'Objc';
351
+ }
352
+ else if (key === 'Rd ' || key === 'Grn ' || key === 'Bl ') {
353
+ return root === 'artd' ? 'long' : 'doub';
354
+ }
355
+ else if (key === 'Trnf') {
356
+ return Array.isArray(value) ? 'VlLs' : 'Objc';
357
+ }
358
+ else {
359
+ return fieldToType[key];
360
+ }
361
+ }
362
+ function readAsciiStringOrClassId(reader) {
363
+ const length = (0, psdReader_1.readInt32)(reader);
364
+ return (0, psdReader_1.readAsciiString)(reader, length || 4);
365
+ }
366
+ function writeAsciiStringOrClassId(writer, value) {
367
+ if (value.length === 4 && value !== 'warp' && value !== 'time' && value !== 'hold' && value !== 'list') {
368
+ // write classId
369
+ (0, psdWriter_1.writeInt32)(writer, 0);
370
+ (0, psdWriter_1.writeSignature)(writer, value);
371
+ }
372
+ else {
373
+ // write ascii string
374
+ (0, psdWriter_1.writeInt32)(writer, value.length);
375
+ for (let i = 0; i < value.length; i++) {
376
+ (0, psdWriter_1.writeUint8)(writer, value.charCodeAt(i));
377
+ }
378
+ }
379
+ }
380
+ function readDescriptorStructure(reader, includeClass) {
381
+ const struct = readClassStructure(reader);
382
+ const object = includeClass ? { _name: struct.name, _classID: struct.classID } : {};
383
+ // console.log('>> ', struct);
384
+ const itemsCount = (0, psdReader_1.readUint32)(reader);
385
+ for (let i = 0; i < itemsCount; i++) {
386
+ const key = readAsciiStringOrClassId(reader);
387
+ const type = (0, psdReader_1.readSignature)(reader);
388
+ // console.log(`> '${key}' '${type}'`);
389
+ const data = readOSType(reader, type, includeClass);
390
+ // if (!getTypeByKey(key, data)) console.log(`> '${key}' '${type}'`, data);
391
+ object[key] = data;
392
+ }
393
+ return object;
394
+ }
395
+ function writeDescriptorStructure(writer, name, classId, value, root) {
396
+ if (logErrors && !classId)
397
+ console.log('Missing classId for: ', name, classId, value);
398
+ // write class structure
399
+ (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, name);
400
+ writeAsciiStringOrClassId(writer, classId);
401
+ const keys = Object.keys(value);
402
+ let keyCount = keys.length;
403
+ if ('_name' in value)
404
+ keyCount--;
405
+ if ('_classID' in value)
406
+ keyCount--;
407
+ (0, psdWriter_1.writeUint32)(writer, keyCount);
408
+ for (const key of keys) {
409
+ if (key === '_name' || key === '_classID')
410
+ continue;
411
+ let type = getTypeByKey(key, value[key], root, value);
412
+ let extType = fieldToExtType[key];
413
+ if (key === 'bounds' && root === 'text') {
414
+ extType = makeType('', 'bounds');
415
+ }
416
+ else if (key === 'origin') {
417
+ type = root === 'slices' ? 'enum' : 'Objc';
418
+ }
419
+ else if ((key === 'Cyn ' || key === 'Mgnt' || key === 'Ylw ' || key === 'Blck') && value._classID === 'CMYC') {
420
+ type = 'doub';
421
+ }
422
+ else if (/^PN[a-z][a-z]$/.test(key)) {
423
+ type = 'TEXT';
424
+ }
425
+ else if (/^PT[a-z][a-z]$/.test(key)) {
426
+ type = 'long';
427
+ }
428
+ else if (/^PF[a-z][a-z]$/.test(key)) {
429
+ type = 'doub';
430
+ }
431
+ else if ((key === 'Rds ' || key === 'Thsh') && typeof value[key] === 'number' && value._classID === 'SmrB') {
432
+ type = 'doub';
433
+ }
434
+ else if (key === 'ClSz' || key === 'Rds ' || key === 'Amnt') {
435
+ type = typeof value[key] === 'number' ? 'long' : 'UntF';
436
+ }
437
+ else if ((key === 'sdwM' || key === 'hglM') && typeof value[key] === 'string') {
438
+ type = 'enum';
439
+ }
440
+ else if (key === 'blur' && typeof value[key] === 'string') {
441
+ type = 'enum';
442
+ }
443
+ else if (key === 'Hght' && typeof value[key] === 'number' && value._classID === 'Embs') {
444
+ type = 'long';
445
+ }
446
+ else if (key === 'Angl' && typeof value[key] === 'number' && (value._classID === 'Embs' || value._classID === 'smartSharpen' || value._classID === 'Twrl' || value._classID === 'MtnB')) {
447
+ type = 'long';
448
+ }
449
+ else if (key === 'Angl' && typeof value[key] === 'number') {
450
+ type = 'doub'; // ???
451
+ }
452
+ else if (key === 'bounds' && root === 'slices') {
453
+ type = 'Objc';
454
+ extType = makeType('', 'Rct1');
455
+ }
456
+ else if (key === 'Scl ') {
457
+ if (typeof value[key] === 'object' && 'Hrzn' in value[key]) {
458
+ type = 'Objc';
459
+ extType = nullType;
460
+ }
461
+ else if (typeof value[key] === 'number') {
462
+ type = 'long';
463
+ }
464
+ else {
465
+ type = 'UntF';
466
+ }
467
+ }
468
+ else if (key === 'audioClipGroupList' && keys.length === 1) {
469
+ type = 'VlLs';
470
+ }
471
+ else if ((key === 'Strt' || key === 'Brgh') && 'H ' in value) {
472
+ type = 'doub';
473
+ }
474
+ else if (key === 'Wdth' && typeof value[key] === 'object') {
475
+ type = 'UntF';
476
+ }
477
+ else if (key === 'Ofst' && typeof value[key] === 'number') {
478
+ type = 'long';
479
+ }
480
+ else if (key === 'Strt' && typeof value[key] === 'object') {
481
+ type = 'Objc';
482
+ extType = nullType;
483
+ }
484
+ else if (channels.indexOf(key) !== -1) {
485
+ type = (classId === 'RGBC' && root !== 'artd') ? 'doub' : 'long';
486
+ }
487
+ else if (key === 'profile') {
488
+ type = classId === 'printOutput' ? 'TEXT' : 'tdta';
489
+ }
490
+ else if (key === 'strokeStyleContent') {
491
+ if (value[key]['Clr ']) {
492
+ extType = makeType('', 'solidColorLayer');
493
+ }
494
+ else if (value[key].Grad) {
495
+ extType = makeType('', 'gradientLayer');
496
+ }
497
+ else if (value[key].Ptrn) {
498
+ extType = makeType('', 'patternLayer');
499
+ }
500
+ else {
501
+ logErrors && console.log('Invalid strokeStyleContent value', value[key]);
502
+ }
503
+ }
504
+ else if (key === 'bounds' && root === 'quiltWarp') {
505
+ extType = makeType('', 'classFloatRect');
506
+ }
507
+ if (extType && extType.classID === 'RGBC') {
508
+ if ('H ' in value[key])
509
+ extType = { classID: 'HSBC', name: '' };
510
+ // TODO: other color spaces
511
+ }
512
+ writeAsciiStringOrClassId(writer, key);
513
+ (0, psdWriter_1.writeSignature)(writer, type || 'long');
514
+ writeOSType(writer, type || 'long', value[key], key, extType, root);
515
+ if (logErrors && !type)
516
+ console.log(`Missing descriptor field type for: '${key}' in`, value);
517
+ }
518
+ }
519
+ function readOSType(reader, type, includeClass) {
520
+ switch (type) {
521
+ case 'obj ': // Reference
522
+ return readReferenceStructure(reader);
523
+ case 'Objc': // Descriptor
524
+ case 'GlbO': // GlobalObject same as Descriptor
525
+ return readDescriptorStructure(reader, includeClass);
526
+ case 'VlLs': { // List
527
+ const length = (0, psdReader_1.readInt32)(reader);
528
+ const items = [];
529
+ for (let i = 0; i < length; i++) {
530
+ const itemType = (0, psdReader_1.readSignature)(reader);
531
+ // console.log(' >', itemType);
532
+ items.push(readOSType(reader, itemType, includeClass));
533
+ }
534
+ return items;
535
+ }
536
+ case 'doub': // Double
537
+ return (0, psdReader_1.readFloat64)(reader);
538
+ case 'UntF': { // Unit double
539
+ const units = (0, psdReader_1.readSignature)(reader);
540
+ const value = (0, psdReader_1.readFloat64)(reader);
541
+ if (!unitsMap[units])
542
+ throw new Error(`Invalid units: ${units}`);
543
+ return { units: unitsMap[units], value };
544
+ }
545
+ case 'UnFl': { // Unit float
546
+ const units = (0, psdReader_1.readSignature)(reader);
547
+ const value = (0, psdReader_1.readFloat32)(reader);
548
+ if (!unitsMap[units])
549
+ throw new Error(`Invalid units: ${units}`);
550
+ return { units: unitsMap[units], value };
551
+ }
552
+ case 'TEXT': // String
553
+ return (0, psdReader_1.readUnicodeString)(reader);
554
+ case 'enum': { // Enumerated
555
+ const enumType = readAsciiStringOrClassId(reader);
556
+ const value = readAsciiStringOrClassId(reader);
557
+ return `${enumType}.${value}`;
558
+ }
559
+ case 'long': // Integer
560
+ return (0, psdReader_1.readInt32)(reader);
561
+ case 'comp': { // Large Integer
562
+ const low = (0, psdReader_1.readUint32)(reader);
563
+ const high = (0, psdReader_1.readUint32)(reader);
564
+ return { low, high };
565
+ }
566
+ case 'bool': // Boolean
567
+ return !!(0, psdReader_1.readUint8)(reader);
568
+ case 'type': // Class
569
+ case 'GlbC': // Class
570
+ return readClassStructure(reader);
571
+ case 'alis': { // Alias
572
+ const length = (0, psdReader_1.readInt32)(reader);
573
+ return (0, psdReader_1.readAsciiString)(reader, length);
574
+ }
575
+ case 'tdta': { // Raw Data
576
+ const length = (0, psdReader_1.readInt32)(reader);
577
+ return (0, psdReader_1.readBytes)(reader, length);
578
+ }
579
+ case 'ObAr': { // Object array
580
+ (0, psdReader_1.readInt32)(reader); // version: 16
581
+ (0, psdReader_1.readUnicodeString)(reader); // name: ''
582
+ readAsciiStringOrClassId(reader); // 'rationalPoint'
583
+ const length = (0, psdReader_1.readInt32)(reader);
584
+ const items = [];
585
+ for (let i = 0; i < length; i++) {
586
+ const type1 = readAsciiStringOrClassId(reader); // type Hrzn | Vrtc
587
+ (0, psdReader_1.readSignature)(reader); // UnFl
588
+ (0, psdReader_1.readSignature)(reader); // units ? '#Pxl'
589
+ const valuesCount = (0, psdReader_1.readInt32)(reader);
590
+ const values = [];
591
+ for (let j = 0; j < valuesCount; j++) {
592
+ values.push((0, psdReader_1.readFloat64)(reader));
593
+ }
594
+ items.push({ type: type1, values });
595
+ }
596
+ return items;
597
+ }
598
+ case 'Pth ': { // File path
599
+ /*const length =*/ (0, psdReader_1.readInt32)(reader); // total size of all fields below
600
+ const sig = (0, psdReader_1.readSignature)(reader);
601
+ /*const pathSize =*/ (0, psdReader_1.readInt32LE)(reader); // the same as length
602
+ const charsCount = (0, psdReader_1.readInt32LE)(reader);
603
+ const path = (0, psdReader_1.readUnicodeStringWithLengthLE)(reader, charsCount);
604
+ return { sig, path };
605
+ }
606
+ default:
607
+ throw new Error(`Invalid TySh descriptor OSType: ${type} at ${reader.offset.toString(16)}`);
608
+ }
609
+ }
610
+ const ObArTypes = {
611
+ meshPoints: 'rationalPoint',
612
+ quiltSliceX: 'UntF',
613
+ quiltSliceY: 'UntF',
614
+ };
615
+ function writeOSType(writer, type, value, key, extType, root) {
616
+ switch (type) {
617
+ case 'obj ': // Reference
618
+ writeReferenceStructure(writer, key, value);
619
+ break;
620
+ case 'Objc': // Descriptor
621
+ case 'GlbO': { // GlobalObject same as Descriptor
622
+ if (typeof value !== 'object')
623
+ throw new Error(`Invalid struct value: ${JSON.stringify(value)}, key: ${key}`);
624
+ if (!extType)
625
+ throw new Error(`Missing ext type for: '${key}' (${JSON.stringify(value)})`);
626
+ const name = value._name || extType.name;
627
+ const classID = value._classID || extType.classID;
628
+ writeDescriptorStructure(writer, name, classID, value, root);
629
+ break;
630
+ }
631
+ case 'VlLs': // List
632
+ if (!Array.isArray(value))
633
+ throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
634
+ (0, psdWriter_1.writeInt32)(writer, value.length);
635
+ for (let i = 0; i < value.length; i++) {
636
+ const type = fieldToArrayType[key];
637
+ (0, psdWriter_1.writeSignature)(writer, type || 'long');
638
+ writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType[key], root);
639
+ if (logErrors && !type)
640
+ console.log(`Missing descriptor array type for: '${key}' in`, value);
641
+ }
642
+ break;
643
+ case 'doub': // Double
644
+ if (typeof value !== 'number')
645
+ throw new Error(`Invalid number value: ${JSON.stringify(value)}, key: ${key}`);
646
+ (0, psdWriter_1.writeFloat64)(writer, value);
647
+ break;
648
+ case 'UntF': // Unit double
649
+ if (!unitsMapRev[value.units])
650
+ throw new Error(`Invalid units: ${value.units} in ${key}`);
651
+ (0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
652
+ (0, psdWriter_1.writeFloat64)(writer, value.value);
653
+ break;
654
+ case 'UnFl': // Unit float
655
+ if (!unitsMapRev[value.units])
656
+ throw new Error(`Invalid units: ${value.units} in ${key}`);
657
+ (0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
658
+ (0, psdWriter_1.writeFloat32)(writer, value.value);
659
+ break;
660
+ case 'TEXT': // String
661
+ (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, value);
662
+ break;
663
+ case 'enum': { // Enumerated
664
+ if (typeof value !== 'string')
665
+ throw new Error(`Invalid enum value: ${JSON.stringify(value)}, key: ${key}`);
666
+ const [_type, val] = value.split('.');
667
+ writeAsciiStringOrClassId(writer, _type);
668
+ writeAsciiStringOrClassId(writer, val);
669
+ break;
670
+ }
671
+ case 'long': // Integer
672
+ if (typeof value !== 'number')
673
+ throw new Error(`Invalid integer value: ${JSON.stringify(value)}, key: ${key}`);
674
+ (0, psdWriter_1.writeInt32)(writer, value);
675
+ break;
676
+ // case 'comp': // Large Integer
677
+ // writeLargeInteger(reader);
678
+ case 'bool': // Boolean
679
+ if (typeof value !== 'boolean')
680
+ throw new Error(`Invalid boolean value: ${JSON.stringify(value)}, key: ${key}`);
681
+ (0, psdWriter_1.writeUint8)(writer, value ? 1 : 0);
682
+ break;
683
+ // case 'type': // Class
684
+ // case 'GlbC': // Class
685
+ // writeClassStructure(reader);
686
+ // case 'alis': // Alias
687
+ // writeAliasStructure(reader);
688
+ case 'tdta': // Raw Data
689
+ (0, psdWriter_1.writeInt32)(writer, value.byteLength);
690
+ (0, psdWriter_1.writeBytes)(writer, value);
691
+ break;
692
+ case 'ObAr': { // Object array
693
+ (0, psdWriter_1.writeInt32)(writer, 16); // version
694
+ (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
695
+ const type = ObArTypes[key];
696
+ if (!type)
697
+ throw new Error(`Not implemented ObArType for: ${key}`);
698
+ writeAsciiStringOrClassId(writer, type);
699
+ (0, psdWriter_1.writeInt32)(writer, value.length);
700
+ for (let i = 0; i < value.length; i++) {
701
+ writeAsciiStringOrClassId(writer, value[i].type); // Hrzn | Vrtc
702
+ (0, psdWriter_1.writeSignature)(writer, 'UnFl');
703
+ (0, psdWriter_1.writeSignature)(writer, '#Pxl');
704
+ (0, psdWriter_1.writeInt32)(writer, value[i].values.length);
705
+ for (let j = 0; j < value[i].values.length; j++) {
706
+ (0, psdWriter_1.writeFloat64)(writer, value[i].values[j]);
707
+ }
708
+ }
709
+ break;
710
+ }
711
+ case 'Pth ': { // File path
712
+ const length = 4 + 4 + 4 + value.path.length * 2;
713
+ (0, psdWriter_1.writeInt32)(writer, length);
714
+ (0, psdWriter_1.writeSignature)(writer, value.sig);
715
+ (0, psdWriter_1.writeInt32LE)(writer, length);
716
+ (0, psdWriter_1.writeInt32LE)(writer, value.path.length);
717
+ (0, psdWriter_1.writeUnicodeStringWithoutLengthLE)(writer, value.path);
718
+ break;
719
+ }
720
+ default:
721
+ throw new Error(`Not implemented descriptor OSType: ${type}`);
722
+ }
723
+ }
724
+ function readReferenceStructure(reader) {
725
+ const itemsCount = (0, psdReader_1.readInt32)(reader);
726
+ const items = [];
727
+ for (let i = 0; i < itemsCount; i++) {
728
+ const type = (0, psdReader_1.readSignature)(reader);
729
+ switch (type) {
730
+ case 'prop': { // Property
731
+ readClassStructure(reader);
732
+ const keyID = readAsciiStringOrClassId(reader);
733
+ items.push(keyID);
734
+ break;
735
+ }
736
+ case 'Clss': // Class
737
+ items.push(readClassStructure(reader));
738
+ break;
739
+ case 'Enmr': { // Enumerated Reference
740
+ readClassStructure(reader);
741
+ const typeID = readAsciiStringOrClassId(reader);
742
+ const value = readAsciiStringOrClassId(reader);
743
+ items.push(`${typeID}.${value}`);
744
+ break;
745
+ }
746
+ case 'rele': { // Offset
747
+ // const { name, classID } =
748
+ readClassStructure(reader);
749
+ items.push((0, psdReader_1.readUint32)(reader));
750
+ break;
751
+ }
752
+ case 'Idnt': // Identifier
753
+ items.push((0, psdReader_1.readInt32)(reader));
754
+ break;
755
+ case 'indx': // Index
756
+ items.push((0, psdReader_1.readInt32)(reader));
757
+ break;
758
+ case 'name': { // Name
759
+ readClassStructure(reader);
760
+ items.push((0, psdReader_1.readUnicodeString)(reader));
761
+ break;
762
+ }
763
+ default:
764
+ throw new Error(`Invalid descriptor reference type: ${type}`);
765
+ }
766
+ }
767
+ return items;
768
+ }
769
+ function writeReferenceStructure(writer, _key, items) {
770
+ (0, psdWriter_1.writeInt32)(writer, items.length);
771
+ for (let i = 0; i < items.length; i++) {
772
+ const value = items[i];
773
+ let type = 'unknown';
774
+ if (typeof value === 'string') {
775
+ if (/^[a-z ]+\.[a-z ]+$/i.test(value)) {
776
+ type = 'Enmr';
777
+ }
778
+ else {
779
+ type = 'name';
780
+ }
781
+ }
782
+ (0, psdWriter_1.writeSignature)(writer, type);
783
+ switch (type) {
784
+ // case 'prop': // Property
785
+ // case 'Clss': // Class
786
+ case 'Enmr': { // Enumerated Reference
787
+ const [typeID, enumValue] = value.split('.');
788
+ writeClassStructure(writer, '\0', typeID);
789
+ writeAsciiStringOrClassId(writer, typeID);
790
+ writeAsciiStringOrClassId(writer, enumValue);
791
+ break;
792
+ }
793
+ // case 'rele': // Offset
794
+ // case 'Idnt': // Identifier
795
+ // case 'indx': // Index
796
+ case 'name': { // Name
797
+ writeClassStructure(writer, '\0', 'Lyr ');
798
+ (0, psdWriter_1.writeUnicodeString)(writer, value + '\0');
799
+ break;
800
+ }
801
+ default:
802
+ throw new Error(`Invalid descriptor reference type: ${type}`);
803
+ }
804
+ }
805
+ return items;
806
+ }
807
+ function readClassStructure(reader) {
808
+ const name = (0, psdReader_1.readUnicodeString)(reader);
809
+ const classID = readAsciiStringOrClassId(reader);
810
+ return { name, classID };
811
+ }
812
+ function writeClassStructure(writer, name, classID) {
813
+ (0, psdWriter_1.writeUnicodeString)(writer, name);
814
+ writeAsciiStringOrClassId(writer, classID);
815
+ }
816
+ function readVersionAndDescriptor(reader, includeClass = false) {
817
+ const version = (0, psdReader_1.readUint32)(reader);
818
+ if (version !== 16)
819
+ throw new Error(`Invalid descriptor version: ${version}`);
820
+ const desc = readDescriptorStructure(reader, includeClass);
821
+ // console.log(require('util').inspect(desc, false, 99, true));
822
+ return desc;
823
+ }
824
+ function writeVersionAndDescriptor(writer, name, classID, descriptor, root = '') {
825
+ (0, psdWriter_1.writeUint32)(writer, 16); // version
826
+ writeDescriptorStructure(writer, name, classID, descriptor, root);
827
+ }
828
+ function horzVrtcToXY(hv) {
829
+ return { x: hv.Hrzn, y: hv.Vrtc };
830
+ }
831
+ function xyToHorzVrtc(xy) {
832
+ return { Hrzn: xy.x, Vrtc: xy.y };
833
+ }
834
+ function descBoundsToBounds(desc) {
835
+ return {
836
+ top: parseUnits(desc['Top ']),
837
+ left: parseUnits(desc.Left),
838
+ right: parseUnits(desc.Rght),
839
+ bottom: parseUnits(desc.Btom),
840
+ };
841
+ }
842
+ function boundsToDescBounds(bounds) {
843
+ return {
844
+ Left: unitsValue(bounds.left, 'bounds.left'),
845
+ ['Top ']: unitsValue(bounds.top, 'bounds.top'),
846
+ Rght: unitsValue(bounds.right, 'bounds.right'),
847
+ Btom: unitsValue(bounds.bottom, 'bounds.bottom'),
848
+ };
849
+ }
850
+ function parseFxObject(fx) {
851
+ const stroke = {
852
+ enabled: !!fx.enab,
853
+ position: exports.FStl.decode(fx.Styl),
854
+ fillType: exports.FrFl.decode(fx.PntT),
855
+ blendMode: exports.BlnM.decode(fx['Md ']),
856
+ opacity: parsePercent(fx.Opct),
857
+ size: parseUnits(fx['Sz ']),
858
+ };
859
+ if (fx.present !== undefined)
860
+ stroke.present = fx.present;
861
+ if (fx.showInDialog !== undefined)
862
+ stroke.showInDialog = fx.showInDialog;
863
+ if (fx.overprint !== undefined)
864
+ stroke.overprint = fx.overprint;
865
+ if (fx['Clr '])
866
+ stroke.color = parseColor(fx['Clr ']);
867
+ if (fx.Grad)
868
+ stroke.gradient = parseGradientContent(fx);
869
+ if (fx.Ptrn)
870
+ stroke.pattern = parsePatternContent(fx);
871
+ return stroke;
872
+ }
873
+ function serializeFxObject(stroke) {
874
+ let FrFX = {};
875
+ FrFX.enab = !!stroke.enabled;
876
+ if (stroke.present !== undefined)
877
+ FrFX.present = !!stroke.present;
878
+ if (stroke.showInDialog !== undefined)
879
+ FrFX.showInDialog = !!stroke.showInDialog;
880
+ FrFX.Styl = exports.FStl.encode(stroke.position);
881
+ FrFX.PntT = exports.FrFl.encode(stroke.fillType);
882
+ FrFX['Md '] = exports.BlnM.encode(stroke.blendMode);
883
+ FrFX.Opct = unitsPercent(stroke.opacity);
884
+ FrFX['Sz '] = unitsValue(stroke.size, 'size');
885
+ if (stroke.color)
886
+ FrFX['Clr '] = serializeColor(stroke.color);
887
+ if (stroke.gradient)
888
+ FrFX = Object.assign(Object.assign({}, FrFX), serializeGradientContent(stroke.gradient));
889
+ if (stroke.pattern)
890
+ FrFX = Object.assign(Object.assign({}, FrFX), serializePatternContent(stroke.pattern));
891
+ if (stroke.overprint !== undefined)
892
+ FrFX.overprint = !!stroke.overprint;
893
+ return FrFX;
894
+ }
895
+ function serializeEffects(e, log, multi) {
896
+ var _a, _b, _c;
897
+ const info = multi ? {
898
+ 'Scl ': unitsPercentF((_a = e.scale) !== null && _a !== void 0 ? _a : 1),
899
+ masterFXSwitch: !e.disabled,
900
+ } : {
901
+ masterFXSwitch: !e.disabled,
902
+ 'Scl ': unitsPercentF((_b = e.scale) !== null && _b !== void 0 ? _b : 1),
903
+ };
904
+ const arrayKeys = ['dropShadow', 'innerShadow', 'solidFill', 'gradientOverlay', 'stroke'];
905
+ for (const key of arrayKeys) {
906
+ if (e[key] && !Array.isArray(e[key]))
907
+ throw new Error(`${key} should be an array`);
908
+ }
909
+ const useMulti = (arr) => !!arr && arr.length > 1 && multi;
910
+ const useSingle = (arr) => !!arr && arr.length >= 1 && (!multi || arr.length === 1);
911
+ if (useSingle(e.dropShadow))
912
+ info.DrSh = serializeEffectObject(e.dropShadow[0], 'dropShadow', log);
913
+ if (useMulti(e.dropShadow))
914
+ info.dropShadowMulti = e.dropShadow.map(i => serializeEffectObject(i, 'dropShadow', log));
915
+ if (useSingle(e.innerShadow))
916
+ info.IrSh = serializeEffectObject(e.innerShadow[0], 'innerShadow', log);
917
+ if (useMulti(e.innerShadow))
918
+ info.innerShadowMulti = e.innerShadow.map(i => serializeEffectObject(i, 'innerShadow', log));
919
+ if (e.outerGlow)
920
+ info.OrGl = serializeEffectObject(e.outerGlow, 'outerGlow', log);
921
+ if (useMulti(e.solidFill))
922
+ info.solidFillMulti = e.solidFill.map(i => serializeEffectObject(i, 'solidFill', log));
923
+ if (useMulti(e.gradientOverlay))
924
+ info.gradientFillMulti = e.gradientOverlay.map(i => serializeEffectObject(i, 'gradientOverlay', log));
925
+ if (useMulti(e.stroke))
926
+ info.frameFXMulti = e.stroke.map(i => serializeFxObject(i));
927
+ if (e.innerGlow)
928
+ info.IrGl = serializeEffectObject(e.innerGlow, 'innerGlow', log);
929
+ if (e.bevel)
930
+ info.ebbl = serializeEffectObject(e.bevel, 'bevel', log);
931
+ if (useSingle(e.solidFill))
932
+ info.SoFi = serializeEffectObject(e.solidFill[0], 'solidFill', log);
933
+ if (e.patternOverlay)
934
+ info.patternFill = serializeEffectObject(e.patternOverlay, 'patternOverlay', log);
935
+ if (useSingle(e.gradientOverlay))
936
+ info.GrFl = serializeEffectObject(e.gradientOverlay[0], 'gradientOverlay', log);
937
+ if (e.satin)
938
+ info.ChFX = serializeEffectObject(e.satin, 'satin', log);
939
+ if (useSingle(e.stroke))
940
+ info.FrFX = serializeFxObject((_c = e.stroke) === null || _c === void 0 ? void 0 : _c[0]);
941
+ if (multi) {
942
+ info.numModifyingFX = 0;
943
+ for (const key of Object.keys(e)) {
944
+ const value = e[key];
945
+ if (Array.isArray(value)) {
946
+ for (const effect of value) {
947
+ if (effect.enabled)
948
+ info.numModifyingFX++;
949
+ }
950
+ }
951
+ else if (value.enabled) {
952
+ info.numModifyingFX++;
953
+ }
954
+ }
955
+ }
956
+ return info;
957
+ }
958
+ function parseEffects(info, log) {
959
+ const effects = {};
960
+ const { masterFXSwitch, DrSh, dropShadowMulti, IrSh, innerShadowMulti, OrGl, IrGl, ebbl, SoFi, solidFillMulti, patternFill, GrFl, gradientFillMulti, ChFX, FrFX, frameFXMulti, numModifyingFX } = info, rest = __rest(info, ["masterFXSwitch", "DrSh", "dropShadowMulti", "IrSh", "innerShadowMulti", "OrGl", "IrGl", "ebbl", "SoFi", "solidFillMulti", "patternFill", "GrFl", "gradientFillMulti", "ChFX", "FrFX", "frameFXMulti", "numModifyingFX"]);
961
+ if (!masterFXSwitch)
962
+ effects.disabled = true;
963
+ if (info['Scl '])
964
+ effects.scale = parsePercent(info['Scl ']);
965
+ if (DrSh)
966
+ effects.dropShadow = [parseEffectObject(DrSh, log)];
967
+ if (dropShadowMulti)
968
+ effects.dropShadow = dropShadowMulti.map(i => parseEffectObject(i, log));
969
+ if (IrSh)
970
+ effects.innerShadow = [parseEffectObject(IrSh, log)];
971
+ if (innerShadowMulti)
972
+ effects.innerShadow = innerShadowMulti.map(i => parseEffectObject(i, log));
973
+ if (OrGl)
974
+ effects.outerGlow = parseEffectObject(OrGl, log);
975
+ if (IrGl)
976
+ effects.innerGlow = parseEffectObject(IrGl, log);
977
+ if (ebbl)
978
+ effects.bevel = parseEffectObject(ebbl, log);
979
+ if (SoFi)
980
+ effects.solidFill = [parseEffectObject(SoFi, log)];
981
+ if (solidFillMulti)
982
+ effects.solidFill = solidFillMulti.map(i => parseEffectObject(i, log));
983
+ if (patternFill)
984
+ effects.patternOverlay = parseEffectObject(patternFill, log);
985
+ if (GrFl)
986
+ effects.gradientOverlay = [parseEffectObject(GrFl, log)];
987
+ if (gradientFillMulti)
988
+ effects.gradientOverlay = gradientFillMulti.map(i => parseEffectObject(i, log));
989
+ if (ChFX)
990
+ effects.satin = parseEffectObject(ChFX, log);
991
+ if (FrFX)
992
+ effects.stroke = [parseFxObject(FrFX)];
993
+ if (frameFXMulti)
994
+ effects.stroke = frameFXMulti.map(i => parseFxObject(i));
995
+ if (log && Object.keys(rest).length > 1)
996
+ console.log('Unhandled effect keys:', rest);
997
+ return effects;
998
+ }
999
+ function parseKeyList(keyList, logMissingFeatures) {
1000
+ const keys = [];
1001
+ for (let j = 0; j < keyList.length; j++) {
1002
+ const key = keyList[j];
1003
+ const { time: { denominator, numerator }, selected, animKey } = key;
1004
+ const time = { numerator, denominator };
1005
+ const interpolation = exports.animInterpStyleEnum.decode(key.animInterpStyle);
1006
+ switch (animKey.Type) {
1007
+ case 'keyType.Opct':
1008
+ keys.push({ interpolation, time, selected, type: 'opacity', value: parsePercent(animKey.Opct) });
1009
+ break;
1010
+ case 'keyType.Pstn':
1011
+ keys.push({ interpolation, time, selected, type: 'position', x: animKey.Hrzn, y: animKey.Vrtc });
1012
+ break;
1013
+ case 'keyType.Trnf':
1014
+ keys.push({
1015
+ interpolation, time, selected, type: 'transform',
1016
+ scale: horzVrtcToXY(animKey['Scl ']), skew: horzVrtcToXY(animKey.Skew), rotation: animKey.rotation, translation: horzVrtcToXY(animKey.translation)
1017
+ });
1018
+ break;
1019
+ case 'keyType.sheetStyle': {
1020
+ const key = { interpolation, time, selected, type: 'style' };
1021
+ if (animKey.sheetStyle.Lefx)
1022
+ key.style = parseEffects(animKey.sheetStyle.Lefx, logMissingFeatures);
1023
+ keys.push(key);
1024
+ break;
1025
+ }
1026
+ case 'keyType.globalLighting': {
1027
+ keys.push({
1028
+ interpolation, time, selected, type: 'globalLighting',
1029
+ globalAngle: animKey.gblA, globalAltitude: animKey.globalAltitude
1030
+ });
1031
+ break;
1032
+ }
1033
+ default: throw new Error(`Unsupported keyType value`);
1034
+ }
1035
+ }
1036
+ return keys;
1037
+ }
1038
+ function serializeKeyList(keys) {
1039
+ const keyList = [];
1040
+ for (let j = 0; j < keys.length; j++) {
1041
+ const key = keys[j];
1042
+ const { time, selected = false, interpolation } = key;
1043
+ const animInterpStyle = exports.animInterpStyleEnum.encode(interpolation);
1044
+ let animKey;
1045
+ switch (key.type) {
1046
+ case 'opacity':
1047
+ animKey = { Type: 'keyType.Opct', Opct: unitsPercent(key.value) };
1048
+ break;
1049
+ case 'position':
1050
+ animKey = { Type: 'keyType.Pstn', Hrzn: key.x, Vrtc: key.y };
1051
+ break;
1052
+ case 'transform':
1053
+ animKey = { Type: 'keyType.Trnf', 'Scl ': xyToHorzVrtc(key.scale), Skew: xyToHorzVrtc(key.skew), rotation: key.rotation, translation: xyToHorzVrtc(key.translation) };
1054
+ break;
1055
+ case 'style':
1056
+ animKey = { Type: 'keyType.sheetStyle', sheetStyle: { Vrsn: 1, blendOptions: {} } };
1057
+ if (key.style)
1058
+ animKey.sheetStyle = { Vrsn: 1, Lefx: serializeEffects(key.style, false, false), blendOptions: {} };
1059
+ break;
1060
+ case 'globalLighting': {
1061
+ animKey = { Type: 'keyType.globalLighting', gblA: key.globalAngle, globalAltitude: key.globalAltitude };
1062
+ break;
1063
+ }
1064
+ default: throw new Error(`Unsupported keyType value`);
1065
+ }
1066
+ keyList.push({ Vrsn: 1, animInterpStyle, time, animKey, selected });
1067
+ }
1068
+ return keyList;
1069
+ }
1070
+ function parseTrackList(trackList, logMissingFeatures) {
1071
+ const tracks = [];
1072
+ for (let i = 0; i < trackList.length; i++) {
1073
+ const tr = trackList[i];
1074
+ const track = {
1075
+ type: exports.stdTrackID.decode(tr.trackID),
1076
+ enabled: tr.enab,
1077
+ keys: parseKeyList(tr.keyList, logMissingFeatures),
1078
+ };
1079
+ if (tr.effectParams) {
1080
+ track.effectParams = {
1081
+ fillCanvas: tr.effectParams.fillCanvas,
1082
+ zoomOrigin: tr.effectParams.zoomOrigin,
1083
+ keys: parseKeyList(tr.effectParams.keyList, logMissingFeatures),
1084
+ };
1085
+ }
1086
+ tracks.push(track);
1087
+ }
1088
+ return tracks;
1089
+ }
1090
+ function serializeTrackList(tracks) {
1091
+ const trackList = [];
1092
+ for (let i = 0; i < tracks.length; i++) {
1093
+ const t = tracks[i];
1094
+ trackList.push(Object.assign(Object.assign({ trackID: exports.stdTrackID.encode(t.type), Vrsn: 1, enab: !!t.enabled, Effc: !!t.effectParams }, (t.effectParams ? {
1095
+ effectParams: {
1096
+ keyList: serializeKeyList(t.keys),
1097
+ fillCanvas: t.effectParams.fillCanvas,
1098
+ zoomOrigin: t.effectParams.zoomOrigin,
1099
+ }
1100
+ } : {})), { keyList: serializeKeyList(t.keys) }));
1101
+ }
1102
+ return trackList;
1103
+ }
1104
+ function parseEffectObject(obj, reportErrors) {
1105
+ const result = {};
1106
+ for (const key of Object.keys(obj)) {
1107
+ const val = obj[key];
1108
+ switch (key) {
1109
+ case 'enab':
1110
+ result.enabled = !!val;
1111
+ break;
1112
+ case 'uglg':
1113
+ result.useGlobalLight = !!val;
1114
+ break;
1115
+ case 'AntA':
1116
+ result.antialiased = !!val;
1117
+ break;
1118
+ case 'Algn':
1119
+ result.align = !!val;
1120
+ break;
1121
+ case 'Dthr':
1122
+ result.dither = !!val;
1123
+ break;
1124
+ case 'Invr':
1125
+ result.invert = !!val;
1126
+ break;
1127
+ case 'Rvrs':
1128
+ result.reverse = !!val;
1129
+ break;
1130
+ case 'Clr ':
1131
+ result.color = parseColor(val);
1132
+ break;
1133
+ case 'hglC':
1134
+ result.highlightColor = parseColor(val);
1135
+ break;
1136
+ case 'sdwC':
1137
+ result.shadowColor = parseColor(val);
1138
+ break;
1139
+ case 'Styl':
1140
+ result.position = exports.FStl.decode(val);
1141
+ break;
1142
+ case 'Md ':
1143
+ result.blendMode = exports.BlnM.decode(val);
1144
+ break;
1145
+ case 'hglM':
1146
+ result.highlightBlendMode = exports.BlnM.decode(val);
1147
+ break;
1148
+ case 'sdwM':
1149
+ result.shadowBlendMode = exports.BlnM.decode(val);
1150
+ break;
1151
+ case 'bvlS':
1152
+ result.style = exports.BESl.decode(val);
1153
+ break;
1154
+ case 'bvlD':
1155
+ result.direction = exports.BESs.decode(val);
1156
+ break;
1157
+ case 'bvlT':
1158
+ result.technique = exports.bvlT.decode(val);
1159
+ break;
1160
+ case 'GlwT':
1161
+ result.technique = exports.BETE.decode(val);
1162
+ break;
1163
+ case 'glwS':
1164
+ result.source = exports.IGSr.decode(val);
1165
+ break;
1166
+ case 'Type':
1167
+ result.type = exports.GrdT.decode(val);
1168
+ break;
1169
+ case 'gs99':
1170
+ result.interpolationMethod = exports.gradientInterpolationMethodType.decode(val);
1171
+ break;
1172
+ case 'Opct':
1173
+ result.opacity = parsePercent(val);
1174
+ break;
1175
+ case 'hglO':
1176
+ result.highlightOpacity = parsePercent(val);
1177
+ break;
1178
+ case 'sdwO':
1179
+ result.shadowOpacity = parsePercent(val);
1180
+ break;
1181
+ case 'lagl':
1182
+ result.angle = parseAngle(val);
1183
+ break;
1184
+ case 'Angl':
1185
+ result.angle = parseAngle(val);
1186
+ break;
1187
+ case 'Lald':
1188
+ result.altitude = parseAngle(val);
1189
+ break;
1190
+ case 'Sftn':
1191
+ result.soften = parseUnits(val);
1192
+ break;
1193
+ case 'srgR':
1194
+ result.strength = parsePercent(val);
1195
+ break;
1196
+ case 'blur':
1197
+ result.size = parseUnits(val);
1198
+ break;
1199
+ case 'Nose':
1200
+ result.noise = parsePercent(val);
1201
+ break;
1202
+ case 'Inpr':
1203
+ result.range = parsePercent(val);
1204
+ break;
1205
+ case 'Ckmt':
1206
+ result.choke = parseUnits(val);
1207
+ break;
1208
+ case 'ShdN':
1209
+ result.jitter = parsePercent(val);
1210
+ break;
1211
+ case 'Dstn':
1212
+ result.distance = parseUnits(val);
1213
+ break;
1214
+ case 'Scl ':
1215
+ result.scale = parsePercent(val);
1216
+ break;
1217
+ case 'Ptrn':
1218
+ result.pattern = { name: val['Nm '], id: val.Idnt };
1219
+ break;
1220
+ case 'phase':
1221
+ result.phase = { x: val.Hrzn, y: val.Vrtc };
1222
+ break;
1223
+ case 'Ofst':
1224
+ result.offset = { x: parsePercent(val.Hrzn), y: parsePercent(val.Vrtc) };
1225
+ break;
1226
+ case 'MpgS':
1227
+ case 'TrnS':
1228
+ result.contour = {
1229
+ name: val['Nm '],
1230
+ curve: val['Crv '].map(p => ({ x: p.Hrzn, y: p.Vrtc })),
1231
+ };
1232
+ break;
1233
+ case 'Grad':
1234
+ result.gradient = parseGradient(val);
1235
+ break;
1236
+ case 'useTexture':
1237
+ case 'useShape':
1238
+ case 'layerConceals':
1239
+ case 'present':
1240
+ case 'showInDialog':
1241
+ case 'antialiasGloss':
1242
+ result[key] = val;
1243
+ break;
1244
+ case '_name':
1245
+ case '_classID':
1246
+ break;
1247
+ default:
1248
+ reportErrors && console.log(`Invalid effect key: '${key}', value:`, val);
1249
+ }
1250
+ }
1251
+ return result;
1252
+ }
1253
+ function serializeEffectObject(obj, objName, reportErrors) {
1254
+ const result = {
1255
+ enab: false,
1256
+ };
1257
+ if (objName === 'dropShadow') {
1258
+ result.TrnS = { 'Nm ': '', 'Crv ': [] };
1259
+ }
1260
+ for (const objKey of Object.keys(obj)) {
1261
+ const key = objKey;
1262
+ const val = obj[key];
1263
+ switch (key) {
1264
+ case 'enabled':
1265
+ result.enab = !!val;
1266
+ break;
1267
+ case 'useGlobalLight':
1268
+ result.uglg = !!val;
1269
+ break;
1270
+ case 'antialiased':
1271
+ result.AntA = !!val;
1272
+ break;
1273
+ case 'align':
1274
+ result.Algn = !!val;
1275
+ break;
1276
+ case 'dither':
1277
+ result.Dthr = !!val;
1278
+ break;
1279
+ case 'invert':
1280
+ result.Invr = !!val;
1281
+ break;
1282
+ case 'reverse':
1283
+ result.Rvrs = !!val;
1284
+ break;
1285
+ case 'color':
1286
+ result['Clr '] = serializeColor(val);
1287
+ break;
1288
+ case 'highlightColor':
1289
+ result.hglC = serializeColor(val);
1290
+ break;
1291
+ case 'shadowColor':
1292
+ result.sdwC = serializeColor(val);
1293
+ break;
1294
+ case 'position':
1295
+ result.Styl = exports.FStl.encode(val);
1296
+ break;
1297
+ case 'blendMode':
1298
+ result['Md '] = exports.BlnM.encode(val);
1299
+ break;
1300
+ case 'highlightBlendMode':
1301
+ result.hglM = exports.BlnM.encode(val);
1302
+ break;
1303
+ case 'shadowBlendMode':
1304
+ result.sdwM = exports.BlnM.encode(val);
1305
+ break;
1306
+ case 'style':
1307
+ result.bvlS = exports.BESl.encode(val);
1308
+ break;
1309
+ case 'direction':
1310
+ result.bvlD = exports.BESs.encode(val);
1311
+ break;
1312
+ case 'technique':
1313
+ if (objName === 'bevel') {
1314
+ result.bvlT = exports.bvlT.encode(val);
1315
+ }
1316
+ else {
1317
+ result.GlwT = exports.BETE.encode(val);
1318
+ }
1319
+ break;
1320
+ case 'source':
1321
+ result.glwS = exports.IGSr.encode(val);
1322
+ break;
1323
+ case 'type':
1324
+ result.Type = exports.GrdT.encode(val);
1325
+ break;
1326
+ case 'interpolationMethod':
1327
+ result.gs99 = exports.gradientInterpolationMethodType.encode(val);
1328
+ break;
1329
+ case 'opacity':
1330
+ result.Opct = unitsPercent(val);
1331
+ break;
1332
+ case 'highlightOpacity':
1333
+ result.hglO = unitsPercent(val);
1334
+ break;
1335
+ case 'shadowOpacity':
1336
+ result.sdwO = unitsPercent(val);
1337
+ break;
1338
+ case 'angle':
1339
+ if (objName === 'gradientOverlay' || objName === 'patternFill') {
1340
+ result.Angl = unitsAngle(val);
1341
+ }
1342
+ else {
1343
+ result.lagl = unitsAngle(val);
1344
+ }
1345
+ break;
1346
+ case 'altitude':
1347
+ result.Lald = unitsAngle(val);
1348
+ break;
1349
+ case 'soften':
1350
+ result.Sftn = unitsValue(val, key);
1351
+ break;
1352
+ case 'strength':
1353
+ result.srgR = unitsPercent(val);
1354
+ break;
1355
+ case 'size':
1356
+ result.blur = unitsValue(val, key);
1357
+ break;
1358
+ case 'noise':
1359
+ result.Nose = unitsPercent(val);
1360
+ break;
1361
+ case 'range':
1362
+ result.Inpr = unitsPercent(val);
1363
+ break;
1364
+ case 'choke':
1365
+ result.Ckmt = unitsValue(val, key);
1366
+ break;
1367
+ case 'jitter':
1368
+ result.ShdN = unitsPercent(val);
1369
+ break;
1370
+ case 'distance':
1371
+ result.Dstn = unitsValue(val, key);
1372
+ break;
1373
+ case 'scale':
1374
+ result['Scl '] = unitsPercent(val);
1375
+ break;
1376
+ case 'pattern':
1377
+ result.Ptrn = { 'Nm ': val.name, Idnt: val.id };
1378
+ break;
1379
+ case 'phase':
1380
+ result.phase = { Hrzn: val.x, Vrtc: val.y };
1381
+ break;
1382
+ case 'offset':
1383
+ result.Ofst = { Hrzn: unitsPercent(val.x), Vrtc: unitsPercent(val.y) };
1384
+ break;
1385
+ case 'contour': {
1386
+ result[objName === 'satin' ? 'MpgS' : 'TrnS'] = {
1387
+ 'Nm ': val.name,
1388
+ 'Crv ': val.curve.map(p => ({ Hrzn: p.x, Vrtc: p.y })),
1389
+ };
1390
+ break;
1391
+ }
1392
+ case 'gradient':
1393
+ result.Grad = serializeGradient(val);
1394
+ break;
1395
+ case 'useTexture':
1396
+ case 'useShape':
1397
+ case 'layerConceals':
1398
+ case 'present':
1399
+ case 'showInDialog':
1400
+ case 'antialiasGloss':
1401
+ result[key] = val;
1402
+ break;
1403
+ default:
1404
+ reportErrors && console.log(`Invalid effect key: '${key}', value:`, val);
1405
+ }
1406
+ }
1407
+ return result;
1408
+ }
1409
+ function parseGradient(grad) {
1410
+ if (grad.GrdF === 'GrdF.CstS') {
1411
+ const samples = grad.Intr || 4096;
1412
+ return {
1413
+ type: 'solid',
1414
+ name: grad['Nm '],
1415
+ smoothness: grad.Intr / 4096,
1416
+ colorStops: grad.Clrs.map(s => ({
1417
+ color: parseColor(s['Clr ']),
1418
+ location: s.Lctn / samples,
1419
+ midpoint: s.Mdpn / 100,
1420
+ })),
1421
+ opacityStops: grad.Trns.map(s => ({
1422
+ opacity: parsePercent(s.Opct),
1423
+ location: s.Lctn / samples,
1424
+ midpoint: s.Mdpn / 100,
1425
+ })),
1426
+ };
1427
+ }
1428
+ else {
1429
+ return {
1430
+ type: 'noise',
1431
+ name: grad['Nm '],
1432
+ roughness: grad.Smth / 4096,
1433
+ colorModel: exports.ClrS.decode(grad.ClrS),
1434
+ randomSeed: grad.RndS,
1435
+ restrictColors: !!grad.VctC,
1436
+ addTransparency: !!grad.ShTr,
1437
+ min: grad['Mnm '].map(x => x / 100),
1438
+ max: grad['Mxm '].map(x => x / 100),
1439
+ };
1440
+ }
1441
+ }
1442
+ function serializeGradient(grad) {
1443
+ var _a, _b;
1444
+ if (grad.type === 'solid') {
1445
+ const samples = Math.round(((_a = grad.smoothness) !== null && _a !== void 0 ? _a : 1) * 4096);
1446
+ return {
1447
+ 'Nm ': grad.name || '',
1448
+ GrdF: 'GrdF.CstS',
1449
+ Intr: samples,
1450
+ Clrs: grad.colorStops.map(s => {
1451
+ var _a;
1452
+ return ({
1453
+ 'Clr ': serializeColor(s.color),
1454
+ Type: 'Clry.UsrS',
1455
+ Lctn: Math.round(s.location * samples),
1456
+ Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
1457
+ });
1458
+ }),
1459
+ Trns: grad.opacityStops.map(s => {
1460
+ var _a;
1461
+ return ({
1462
+ Opct: unitsPercent(s.opacity),
1463
+ Lctn: Math.round(s.location * samples),
1464
+ Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
1465
+ });
1466
+ }),
1467
+ };
1468
+ }
1469
+ else {
1470
+ return {
1471
+ GrdF: 'GrdF.ClNs',
1472
+ 'Nm ': grad.name || '',
1473
+ ShTr: !!grad.addTransparency,
1474
+ VctC: !!grad.restrictColors,
1475
+ ClrS: exports.ClrS.encode(grad.colorModel),
1476
+ RndS: grad.randomSeed || 0,
1477
+ Smth: Math.round(((_b = grad.roughness) !== null && _b !== void 0 ? _b : 1) * 4096),
1478
+ 'Mnm ': (grad.min || [0, 0, 0, 0]).map(x => x * 100),
1479
+ 'Mxm ': (grad.max || [1, 1, 1, 1]).map(x => x * 100),
1480
+ };
1481
+ }
1482
+ }
1483
+ function parseGradientContent(descriptor) {
1484
+ const result = parseGradient(descriptor.Grad);
1485
+ result.style = exports.GrdT.decode(descriptor.Type);
1486
+ if (descriptor.Dthr !== undefined)
1487
+ result.dither = descriptor.Dthr;
1488
+ if (descriptor.gradientsInterpolationMethod !== undefined)
1489
+ result.interpolationMethod = exports.gradientInterpolationMethodType.decode(descriptor.gradientsInterpolationMethod);
1490
+ if (descriptor.Rvrs !== undefined)
1491
+ result.reverse = descriptor.Rvrs;
1492
+ if (descriptor.Angl !== undefined)
1493
+ result.angle = parseAngle(descriptor.Angl);
1494
+ if (descriptor['Scl '] !== undefined)
1495
+ result.scale = parsePercent(descriptor['Scl ']);
1496
+ if (descriptor.Algn !== undefined)
1497
+ result.align = descriptor.Algn;
1498
+ if (descriptor.Ofst !== undefined) {
1499
+ result.offset = {
1500
+ x: parsePercent(descriptor.Ofst.Hrzn),
1501
+ y: parsePercent(descriptor.Ofst.Vrtc)
1502
+ };
1503
+ }
1504
+ return result;
1505
+ }
1506
+ function parsePatternContent(descriptor) {
1507
+ const result = {
1508
+ name: descriptor.Ptrn['Nm '],
1509
+ id: descriptor.Ptrn.Idnt,
1510
+ };
1511
+ if (descriptor.Lnkd !== undefined)
1512
+ result.linked = descriptor.Lnkd;
1513
+ if (descriptor.phase !== undefined)
1514
+ result.phase = { x: descriptor.phase.Hrzn, y: descriptor.phase.Vrtc };
1515
+ return result;
1516
+ }
1517
+ function parseVectorContent(descriptor) {
1518
+ if ('Grad' in descriptor) {
1519
+ return parseGradientContent(descriptor);
1520
+ }
1521
+ else if ('Ptrn' in descriptor) {
1522
+ return Object.assign({ type: 'pattern' }, parsePatternContent(descriptor));
1523
+ }
1524
+ else if ('Clr ' in descriptor) {
1525
+ return { type: 'color', color: parseColor(descriptor['Clr ']) };
1526
+ }
1527
+ else {
1528
+ throw new Error('Invalid vector content');
1529
+ }
1530
+ }
1531
+ function serializeGradientContent(content) {
1532
+ const result = {};
1533
+ if (content.dither !== undefined)
1534
+ result.Dthr = content.dither;
1535
+ if (content.interpolationMethod !== undefined)
1536
+ result.gradientsInterpolationMethod = exports.gradientInterpolationMethodType.encode(content.interpolationMethod);
1537
+ if (content.reverse !== undefined)
1538
+ result.Rvrs = content.reverse;
1539
+ if (content.angle !== undefined)
1540
+ result.Angl = unitsAngle(content.angle);
1541
+ result.Type = exports.GrdT.encode(content.style);
1542
+ if (content.align !== undefined)
1543
+ result.Algn = content.align;
1544
+ if (content.scale !== undefined)
1545
+ result['Scl '] = unitsPercent(content.scale);
1546
+ if (content.offset) {
1547
+ result.Ofst = {
1548
+ Hrzn: unitsPercent(content.offset.x),
1549
+ Vrtc: unitsPercent(content.offset.y),
1550
+ };
1551
+ }
1552
+ result.Grad = serializeGradient(content);
1553
+ return result;
1554
+ }
1555
+ function serializePatternContent(content) {
1556
+ const result = {
1557
+ Ptrn: {
1558
+ 'Nm ': content.name || '',
1559
+ Idnt: content.id || '',
1560
+ }
1561
+ };
1562
+ if (content.linked !== undefined)
1563
+ result.Lnkd = !!content.linked;
1564
+ if (content.phase !== undefined)
1565
+ result.phase = { Hrzn: content.phase.x, Vrtc: content.phase.y };
1566
+ return result;
1567
+ }
1568
+ function serializeVectorContent(content) {
1569
+ if (content.type === 'color') {
1570
+ return { key: 'SoCo', descriptor: { 'Clr ': serializeColor(content.color) } };
1571
+ }
1572
+ else if (content.type === 'pattern') {
1573
+ return { key: 'PtFl', descriptor: serializePatternContent(content) };
1574
+ }
1575
+ else {
1576
+ return { key: 'GdFl', descriptor: serializeGradientContent(content) };
1577
+ }
1578
+ }
1579
+ function parseColor(color) {
1580
+ if ('H ' in color) {
1581
+ return { h: parsePercentOrAngle(color['H ']), s: color.Strt, b: color.Brgh };
1582
+ }
1583
+ else if ('Rd ' in color) {
1584
+ return { r: color['Rd '], g: color['Grn '], b: color['Bl '] };
1585
+ }
1586
+ else if ('Cyn ' in color) {
1587
+ return { c: color['Cyn '], m: color.Mgnt, y: color['Ylw '], k: color.Blck };
1588
+ }
1589
+ else if ('Gry ' in color) {
1590
+ return { k: color['Gry '] };
1591
+ }
1592
+ else if ('Lmnc' in color) {
1593
+ return { l: color.Lmnc, a: color['A '], b: color['B '] };
1594
+ }
1595
+ else if ('redFloat' in color) {
1596
+ return { fr: color.redFloat, fg: color.greenFloat, fb: color.blueFloat };
1597
+ }
1598
+ else {
1599
+ throw new Error('Unsupported color descriptor');
1600
+ }
1601
+ }
1602
+ function serializeColor(color) {
1603
+ if (!color) {
1604
+ return { _name: '', _classID: 'RGBC', 'Rd ': 0, 'Grn ': 0, 'Bl ': 0 };
1605
+ }
1606
+ else if ('r' in color) {
1607
+ return { _name: '', _classID: 'RGBC', 'Rd ': color.r || 0, 'Grn ': color.g || 0, 'Bl ': color.b || 0 };
1608
+ }
1609
+ else if ('fr' in color) {
1610
+ return { _name: '', _classID: 'RGBC', redFloat: color.fr, greenFloat: color.fg, blueFloat: color.fb };
1611
+ }
1612
+ else if ('h' in color) {
1613
+ return { _name: '', _classID: 'HSBC', 'H ': unitsAngle(color.h * 360), Strt: color.s || 0, Brgh: color.b || 0 };
1614
+ }
1615
+ else if ('c' in color) {
1616
+ return { _name: '', _classID: 'CMYC', 'Cyn ': color.c || 0, Mgnt: color.m || 0, 'Ylw ': color.y || 0, Blck: color.k || 0 };
1617
+ }
1618
+ else if ('l' in color) {
1619
+ return { _name: '', _classID: 'LABC', Lmnc: color.l || 0, 'A ': color.a || 0, 'B ': color.b || 0 };
1620
+ }
1621
+ else if ('k' in color) {
1622
+ return { _name: '', _classID: 'GRYC', 'Gry ': color.k };
1623
+ }
1624
+ else {
1625
+ throw new Error('Invalid color value');
1626
+ }
1627
+ }
1628
+ function parseAngle(x) {
1629
+ if (x === undefined)
1630
+ return 0;
1631
+ if (x.units !== 'Angle')
1632
+ throw new Error(`Invalid units: ${x.units}`);
1633
+ return x.value;
1634
+ }
1635
+ function parsePercent(x) {
1636
+ if (x === undefined)
1637
+ return 1;
1638
+ if (x.units !== 'Percent')
1639
+ throw new Error(`Invalid units: ${x.units}`);
1640
+ return x.value / 100;
1641
+ }
1642
+ function parsePercentOrAngle(x) {
1643
+ if (x === undefined)
1644
+ return 1;
1645
+ if (x.units === 'Percent')
1646
+ return x.value / 100;
1647
+ if (x.units === 'Angle')
1648
+ return x.value / 360;
1649
+ throw new Error(`Invalid units: ${x.units}`);
1650
+ }
1651
+ function parseUnits({ units, value }) {
1652
+ if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
1653
+ units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
1654
+ throw new Error(`Invalid units: ${JSON.stringify({ units, value })}`);
1655
+ }
1656
+ return { value, units };
1657
+ }
1658
+ function parseUnitsOrNumber(value, units = 'Pixels') {
1659
+ if (typeof value === 'number')
1660
+ return { value, units };
1661
+ return parseUnits(value);
1662
+ }
1663
+ function parseUnitsToNumber({ units, value }, expectedUnits) {
1664
+ if (units !== expectedUnits)
1665
+ throw new Error(`Invalid units: ${JSON.stringify({ units, value })}`);
1666
+ return value;
1667
+ }
1668
+ function unitsAngle(value) {
1669
+ return { units: 'Angle', value: value || 0 };
1670
+ }
1671
+ function unitsPercent(value) {
1672
+ return { units: 'Percent', value: Math.round((value || 0) * 100) };
1673
+ }
1674
+ function unitsPercentF(value) {
1675
+ return { units: 'Percent', value: (value || 0) * 100 };
1676
+ }
1677
+ function unitsValue(x, key) {
1678
+ if (x == null)
1679
+ return { units: 'Pixels', value: 0 };
1680
+ if (typeof x !== 'object')
1681
+ throw new Error(`Invalid value: ${JSON.stringify(x)} (key: ${key}) (should have value and units)`);
1682
+ const { units, value } = x;
1683
+ if (typeof value !== 'number')
1684
+ throw new Error(`Invalid value in ${JSON.stringify(x)} (key: ${key})`);
1685
+ if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
1686
+ units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
1687
+ throw new Error(`Invalid units in ${JSON.stringify(x)} (key: ${key})`);
1688
+ }
1689
+ return { units, value };
1690
+ }
1691
+ function frac({ numerator, denominator }) {
1692
+ return { numerator, denominator };
1693
+ }
1694
+ exports.textGridding = (0, helpers_1.createEnum)('textGridding', 'none', {
1695
+ none: 'None',
1696
+ round: 'Rnd ',
1697
+ });
1698
+ exports.Ornt = (0, helpers_1.createEnum)('Ornt', 'horizontal', {
1699
+ horizontal: 'Hrzn',
1700
+ vertical: 'Vrtc',
1701
+ });
1702
+ exports.Annt = (0, helpers_1.createEnum)('Annt', 'sharp', {
1703
+ none: 'Anno',
1704
+ sharp: 'antiAliasSharp',
1705
+ crisp: 'AnCr',
1706
+ strong: 'AnSt',
1707
+ smooth: 'AnSm',
1708
+ platform: 'antiAliasPlatformGray',
1709
+ platformLCD: 'antiAliasPlatformLCD',
1710
+ });
1711
+ exports.warpStyle = (0, helpers_1.createEnum)('warpStyle', 'none', {
1712
+ none: 'warpNone',
1713
+ arc: 'warpArc',
1714
+ arcLower: 'warpArcLower',
1715
+ arcUpper: 'warpArcUpper',
1716
+ arch: 'warpArch',
1717
+ bulge: 'warpBulge',
1718
+ shellLower: 'warpShellLower',
1719
+ shellUpper: 'warpShellUpper',
1720
+ flag: 'warpFlag',
1721
+ wave: 'warpWave',
1722
+ fish: 'warpFish',
1723
+ rise: 'warpRise',
1724
+ fisheye: 'warpFisheye',
1725
+ inflate: 'warpInflate',
1726
+ squeeze: 'warpSqueeze',
1727
+ twist: 'warpTwist',
1728
+ cylinder: 'warpCylinder',
1729
+ custom: 'warpCustom',
1730
+ });
1731
+ exports.BlnM = (0, helpers_1.createEnum)('BlnM', 'normal', {
1732
+ 'normal': 'Nrml',
1733
+ 'dissolve': 'Dslv',
1734
+ 'darken': 'Drkn',
1735
+ 'multiply': 'Mltp',
1736
+ 'color burn': 'CBrn',
1737
+ 'linear burn': 'linearBurn',
1738
+ 'darker color': 'darkerColor',
1739
+ 'lighten': 'Lghn',
1740
+ 'screen': 'Scrn',
1741
+ 'color dodge': 'CDdg',
1742
+ 'linear dodge': 'linearDodge',
1743
+ 'lighter color': 'lighterColor',
1744
+ 'overlay': 'Ovrl',
1745
+ 'soft light': 'SftL',
1746
+ 'hard light': 'HrdL',
1747
+ 'vivid light': 'vividLight',
1748
+ 'linear light': 'linearLight',
1749
+ 'pin light': 'pinLight',
1750
+ 'hard mix': 'hardMix',
1751
+ 'difference': 'Dfrn',
1752
+ 'exclusion': 'Xclu',
1753
+ 'subtract': 'blendSubtraction',
1754
+ 'divide': 'blendDivide',
1755
+ 'hue': 'H ',
1756
+ 'saturation': 'Strt',
1757
+ 'color': 'Clr ',
1758
+ 'luminosity': 'Lmns',
1759
+ // used in ABR
1760
+ 'linear height': 'linearHeight',
1761
+ 'height': 'Hght',
1762
+ 'subtraction': 'Sbtr', // 2nd version of subtract ?
1763
+ });
1764
+ exports.BESl = (0, helpers_1.createEnum)('BESl', 'inner bevel', {
1765
+ 'inner bevel': 'InrB',
1766
+ 'outer bevel': 'OtrB',
1767
+ 'emboss': 'Embs',
1768
+ 'pillow emboss': 'PlEb',
1769
+ 'stroke emboss': 'strokeEmboss',
1770
+ });
1771
+ exports.bvlT = (0, helpers_1.createEnum)('bvlT', 'smooth', {
1772
+ 'smooth': 'SfBL',
1773
+ 'chisel hard': 'PrBL',
1774
+ 'chisel soft': 'Slmt',
1775
+ });
1776
+ exports.BESs = (0, helpers_1.createEnum)('BESs', 'up', {
1777
+ up: 'In ',
1778
+ down: 'Out ',
1779
+ });
1780
+ exports.BETE = (0, helpers_1.createEnum)('BETE', 'softer', {
1781
+ softer: 'SfBL',
1782
+ precise: 'PrBL',
1783
+ });
1784
+ exports.IGSr = (0, helpers_1.createEnum)('IGSr', 'edge', {
1785
+ edge: 'SrcE',
1786
+ center: 'SrcC',
1787
+ });
1788
+ exports.GrdT = (0, helpers_1.createEnum)('GrdT', 'linear', {
1789
+ linear: 'Lnr ',
1790
+ radial: 'Rdl ',
1791
+ angle: 'Angl',
1792
+ reflected: 'Rflc',
1793
+ diamond: 'Dmnd',
1794
+ });
1795
+ exports.animInterpStyleEnum = (0, helpers_1.createEnum)('animInterpStyle', 'linear', {
1796
+ linear: 'Lnr ',
1797
+ hold: 'hold',
1798
+ });
1799
+ exports.stdTrackID = (0, helpers_1.createEnum)('stdTrackID', 'opacity', {
1800
+ opacity: 'opacityTrack',
1801
+ style: 'styleTrack',
1802
+ sheetTransform: 'sheetTransformTrack',
1803
+ sheetPosition: 'sheetPositionTrack',
1804
+ globalLighting: 'globalLightingTrack',
1805
+ });
1806
+ exports.gradientInterpolationMethodType = (0, helpers_1.createEnum)('gradientInterpolationMethodType', 'perceptual', {
1807
+ perceptual: 'Perc',
1808
+ linear: 'Lnr ',
1809
+ classic: 'Gcls',
1810
+ smooth: 'Smoo',
1811
+ // TODO: stripes
1812
+ });
1813
+ exports.ClrS = (0, helpers_1.createEnum)('ClrS', 'rgb', {
1814
+ rgb: 'RGBC',
1815
+ hsb: 'HSBl',
1816
+ lab: 'LbCl',
1817
+ hsl: 'HSLC',
1818
+ });
1819
+ exports.FStl = (0, helpers_1.createEnum)('FStl', 'outside', {
1820
+ outside: 'OutF',
1821
+ center: 'CtrF',
1822
+ inside: 'InsF'
1823
+ });
1824
+ exports.FrFl = (0, helpers_1.createEnum)('FrFl', 'color', {
1825
+ color: 'SClr',
1826
+ gradient: 'GrFl',
1827
+ pattern: 'Ptrn',
1828
+ });
1829
+ exports.ESliceType = (0, helpers_1.createEnum)('ESliceType', 'image', {
1830
+ image: 'Img ',
1831
+ noImage: 'noImage',
1832
+ });
1833
+ exports.ESliceHorzAlign = (0, helpers_1.createEnum)('ESliceHorzAlign', 'default', {
1834
+ default: 'default',
1835
+ });
1836
+ exports.ESliceVertAlign = (0, helpers_1.createEnum)('ESliceVertAlign', 'default', {
1837
+ default: 'default',
1838
+ });
1839
+ exports.ESliceOrigin = (0, helpers_1.createEnum)('ESliceOrigin', 'userGenerated', {
1840
+ userGenerated: 'userGenerated',
1841
+ autoGenerated: 'autoGenerated',
1842
+ layer: 'layer',
1843
+ });
1844
+ exports.ESliceBGColorType = (0, helpers_1.createEnum)('ESliceBGColorType', 'none', {
1845
+ none: 'None',
1846
+ matte: 'matte',
1847
+ color: 'Clr ',
1848
+ });
1849
+ exports.strokeStyleLineCapType = (0, helpers_1.createEnum)('strokeStyleLineCapType', 'butt', {
1850
+ butt: 'strokeStyleButtCap',
1851
+ round: 'strokeStyleRoundCap',
1852
+ square: 'strokeStyleSquareCap',
1853
+ });
1854
+ exports.strokeStyleLineJoinType = (0, helpers_1.createEnum)('strokeStyleLineJoinType', 'miter', {
1855
+ miter: 'strokeStyleMiterJoin',
1856
+ round: 'strokeStyleRoundJoin',
1857
+ bevel: 'strokeStyleBevelJoin',
1858
+ });
1859
+ exports.strokeStyleLineAlignment = (0, helpers_1.createEnum)('strokeStyleLineAlignment', 'inside', {
1860
+ inside: 'strokeStyleAlignInside',
1861
+ center: 'strokeStyleAlignCenter',
1862
+ outside: 'strokeStyleAlignOutside',
1863
+ });
1864
+ exports.BlrM = (0, helpers_1.createEnum)('BlrM', 'ispinmage', {
1865
+ spin: 'Spn ',
1866
+ zoom: 'Zm ',
1867
+ });
1868
+ exports.BlrQ = (0, helpers_1.createEnum)('BlrQ', 'good', {
1869
+ draft: 'Drft',
1870
+ good: 'Gd ',
1871
+ best: 'Bst ',
1872
+ });
1873
+ exports.SmBM = (0, helpers_1.createEnum)('SmBM', 'normal', {
1874
+ normal: 'SBMN',
1875
+ 'edge only': 'SBME',
1876
+ 'overlay edge': 'SBMO',
1877
+ });
1878
+ exports.SmBQ = (0, helpers_1.createEnum)('SmBQ', 'medium', {
1879
+ low: 'SBQL',
1880
+ medium: 'SBQM',
1881
+ high: 'SBQH',
1882
+ });
1883
+ exports.DspM = (0, helpers_1.createEnum)('DspM', 'stretch to fit', {
1884
+ 'stretch to fit': 'StrF',
1885
+ 'tile': 'Tile',
1886
+ });
1887
+ exports.UndA = (0, helpers_1.createEnum)('UndA', 'repeat edge pixels', {
1888
+ 'wrap around': 'WrpA',
1889
+ 'repeat edge pixels': 'RptE',
1890
+ });
1891
+ exports.Cnvr = (0, helpers_1.createEnum)('Cnvr', 'rectangular to polar', {
1892
+ 'rectangular to polar': 'RctP',
1893
+ 'polar to rectangular': 'PlrR',
1894
+ });
1895
+ exports.RplS = (0, helpers_1.createEnum)('RplS', 'medium', {
1896
+ small: 'Sml ',
1897
+ medium: 'Mdm ',
1898
+ large: 'Lrg ',
1899
+ });
1900
+ exports.SphM = (0, helpers_1.createEnum)('SphM', 'normal', {
1901
+ 'normal': 'Nrml',
1902
+ 'horizontal only': 'HrzO',
1903
+ 'vertical only': 'VrtO',
1904
+ });
1905
+ exports.Wvtp = (0, helpers_1.createEnum)('Wvtp', 'sine', {
1906
+ sine: 'WvSn',
1907
+ triangle: 'WvTr',
1908
+ square: 'WvSq',
1909
+ });
1910
+ exports.ZZTy = (0, helpers_1.createEnum)('ZZTy', 'pond ripples', {
1911
+ 'around center': 'ArnC',
1912
+ 'out from center': 'OtFr',
1913
+ 'pond ripples': 'PndR',
1914
+ });
1915
+ exports.Dstr = (0, helpers_1.createEnum)('Dstr', 'uniform', {
1916
+ uniform: 'Unfr',
1917
+ gaussian: 'Gsn ',
1918
+ });
1919
+ exports.Chnl = (0, helpers_1.createEnum)('Chnl', 'composite', {
1920
+ red: 'Rd ',
1921
+ green: 'Grn ',
1922
+ blue: 'Bl ',
1923
+ composite: 'Cmps',
1924
+ });
1925
+ exports.MztT = (0, helpers_1.createEnum)('MztT', 'fine dots', {
1926
+ 'fine dots': 'FnDt',
1927
+ 'medium dots': 'MdmD',
1928
+ 'grainy dots': 'GrnD',
1929
+ 'coarse dots': 'CrsD',
1930
+ 'short lines': 'ShrL',
1931
+ 'medium lines': 'MdmL',
1932
+ 'long lines': 'LngL',
1933
+ 'short strokes': 'ShSt',
1934
+ 'medium strokes': 'MdmS',
1935
+ 'long strokes': 'LngS',
1936
+ });
1937
+ exports.Lns = (0, helpers_1.createEnum)('Lns ', '50-300mm zoom', {
1938
+ '50-300mm zoom': 'Zm ',
1939
+ '32mm prime': 'Nkn ',
1940
+ '105mm prime': 'Nkn1',
1941
+ 'movie prime': 'PnVs',
1942
+ });
1943
+ exports.blurType = (0, helpers_1.createEnum)('blurType', 'gaussian blur', {
1944
+ 'gaussian blur': 'GsnB',
1945
+ 'lens blur': 'lensBlur',
1946
+ 'motion blur': 'MtnB',
1947
+ });
1948
+ exports.DfsM = (0, helpers_1.createEnum)('DfsM', 'normal', {
1949
+ 'normal': 'Nrml',
1950
+ 'darken only': 'DrkO',
1951
+ 'lighten only': 'LghO',
1952
+ 'anisotropic': 'anisotropic',
1953
+ });
1954
+ exports.ExtT = (0, helpers_1.createEnum)('ExtT', 'blocks', {
1955
+ blocks: 'Blks',
1956
+ pyramids: 'Pyrm',
1957
+ });
1958
+ exports.ExtR = (0, helpers_1.createEnum)('ExtR', 'random', {
1959
+ random: 'Rndm',
1960
+ 'level-based': 'LvlB',
1961
+ });
1962
+ exports.FlCl = (0, helpers_1.createEnum)('FlCl', 'background color', {
1963
+ 'background color': 'FlBc',
1964
+ 'foreground color': 'FlFr',
1965
+ 'inverse image': 'FlIn',
1966
+ 'unaltered image': 'FlSm',
1967
+ });
1968
+ exports.CntE = (0, helpers_1.createEnum)('CntE', 'upper', {
1969
+ lower: 'Lwr ',
1970
+ upper: 'Upr ',
1971
+ });
1972
+ exports.WndM = (0, helpers_1.createEnum)('WndM', 'wind', {
1973
+ wind: 'Wnd ',
1974
+ blast: 'Blst',
1975
+ stagger: 'Stgr',
1976
+ });
1977
+ exports.Drct = (0, helpers_1.createEnum)('Drct', 'from the right', {
1978
+ left: 'Left',
1979
+ right: 'Rght',
1980
+ });
1981
+ exports.IntE = (0, helpers_1.createEnum)('IntE', 'odd lines', {
1982
+ 'odd lines': 'ElmO',
1983
+ 'even lines': 'ElmE',
1984
+ });
1985
+ exports.IntC = (0, helpers_1.createEnum)('IntC', 'interpolation', {
1986
+ duplication: 'CrtD',
1987
+ interpolation: 'CrtI',
1988
+ });
1989
+ exports.FlMd = (0, helpers_1.createEnum)('FlMd', 'wrap around', {
1990
+ 'set to transparent': 'Bckg',
1991
+ 'repeat edge pixels': 'Rpt ',
1992
+ 'wrap around': 'Wrp ',
1993
+ });
1994
+ exports.prjM = (0, helpers_1.createEnum)('prjM', 'fisheye', {
1995
+ 'fisheye': 'fisP',
1996
+ 'perspective': 'perP',
1997
+ 'auto': 'auto',
1998
+ 'full spherical': 'fusP',
1999
+ });
2000
+ exports.presetKindType = (0, helpers_1.createEnum)('presetKindType', 'presetKindCustom', {
2001
+ custom: 'presetKindCustom',
2002
+ default: 'presetKindDefault',
2003
+ });
2039
2004
  //# sourceMappingURL=descriptor.js.map