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