ag-psd 30.2.0 → 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 (252) hide show
  1. package/.v8-cache/v24.13.1-x64-cf738c9d/01e5e61b +0 -0
  2. package/.v8-cache/v24.13.1-x64-cf738c9d/05135617 +0 -0
  3. package/.v8-cache/v24.13.1-x64-cf738c9d/06423db9 +0 -0
  4. package/.v8-cache/v24.13.1-x64-cf738c9d/06e765df +0 -0
  5. package/.v8-cache/v24.13.1-x64-cf738c9d/0930679d +0 -0
  6. package/.v8-cache/v24.13.1-x64-cf738c9d/09519a62 +0 -0
  7. package/.v8-cache/v24.13.1-x64-cf738c9d/0a6607b0 +0 -0
  8. package/.v8-cache/v24.13.1-x64-cf738c9d/0ad8fa6e +0 -0
  9. package/.v8-cache/v24.13.1-x64-cf738c9d/0d390e10 +0 -0
  10. package/.v8-cache/v24.13.1-x64-cf738c9d/0dfa7b16 +0 -0
  11. package/.v8-cache/v24.13.1-x64-cf738c9d/0e9e09db +0 -0
  12. package/.v8-cache/v24.13.1-x64-cf738c9d/1130885f +0 -0
  13. package/.v8-cache/v24.13.1-x64-cf738c9d/1222cb8c +0 -0
  14. package/.v8-cache/v24.13.1-x64-cf738c9d/15e2c039 +0 -0
  15. package/.v8-cache/v24.13.1-x64-cf738c9d/1a2d469d +0 -0
  16. package/.v8-cache/v24.13.1-x64-cf738c9d/1b300c82 +0 -0
  17. package/.v8-cache/v24.13.1-x64-cf738c9d/1bc3d370 +0 -0
  18. package/.v8-cache/v24.13.1-x64-cf738c9d/1e44e5af +0 -0
  19. package/.v8-cache/v24.13.1-x64-cf738c9d/1efa10a1 +0 -0
  20. package/.v8-cache/v24.13.1-x64-cf738c9d/1f6c8743 +0 -0
  21. package/.v8-cache/v24.13.1-x64-cf738c9d/20b27e40 +0 -0
  22. package/.v8-cache/v24.13.1-x64-cf738c9d/257c62ba +0 -0
  23. package/.v8-cache/v24.13.1-x64-cf738c9d/25d60154 +0 -0
  24. package/.v8-cache/v24.13.1-x64-cf738c9d/26f822f3 +0 -0
  25. package/.v8-cache/v24.13.1-x64-cf738c9d/2a1e2a8d +0 -0
  26. package/.v8-cache/v24.13.1-x64-cf738c9d/2b02fded +0 -0
  27. package/.v8-cache/v24.13.1-x64-cf738c9d/2c76dc0d +0 -0
  28. package/.v8-cache/v24.13.1-x64-cf738c9d/2deb286a +0 -0
  29. package/.v8-cache/v24.13.1-x64-cf738c9d/32018e44 +0 -0
  30. package/.v8-cache/v24.13.1-x64-cf738c9d/341402c3 +0 -0
  31. package/.v8-cache/v24.13.1-x64-cf738c9d/34e0fa2e +0 -0
  32. package/.v8-cache/v24.13.1-x64-cf738c9d/3bbf643e +0 -0
  33. package/.v8-cache/v24.13.1-x64-cf738c9d/3ceff89e +0 -0
  34. package/.v8-cache/v24.13.1-x64-cf738c9d/404f5cdc +0 -0
  35. package/.v8-cache/v24.13.1-x64-cf738c9d/4087aa2b +0 -0
  36. package/.v8-cache/v24.13.1-x64-cf738c9d/4376c1f9 +0 -0
  37. package/.v8-cache/v24.13.1-x64-cf738c9d/44903df4 +0 -0
  38. package/.v8-cache/v24.13.1-x64-cf738c9d/44d58dc8 +0 -0
  39. package/.v8-cache/v24.13.1-x64-cf738c9d/4511bacf +0 -0
  40. package/.v8-cache/v24.13.1-x64-cf738c9d/47da0ce8 +0 -0
  41. package/.v8-cache/v24.13.1-x64-cf738c9d/48cd54a9 +0 -0
  42. package/.v8-cache/v24.13.1-x64-cf738c9d/4d938476 +0 -0
  43. package/.v8-cache/v24.13.1-x64-cf738c9d/4ec6d390 +0 -0
  44. package/.v8-cache/v24.13.1-x64-cf738c9d/4f5702bd +0 -0
  45. package/.v8-cache/v24.13.1-x64-cf738c9d/514cc428 +0 -0
  46. package/.v8-cache/v24.13.1-x64-cf738c9d/557d3b42 +0 -0
  47. package/.v8-cache/v24.13.1-x64-cf738c9d/56abbff7 +0 -0
  48. package/.v8-cache/v24.13.1-x64-cf738c9d/57b540ee +0 -0
  49. package/.v8-cache/v24.13.1-x64-cf738c9d/5e20c081 +0 -0
  50. package/.v8-cache/v24.13.1-x64-cf738c9d/651c4ada +0 -0
  51. package/.v8-cache/v24.13.1-x64-cf738c9d/652a0d59 +0 -0
  52. package/.v8-cache/v24.13.1-x64-cf738c9d/6a0e89ee +0 -0
  53. package/.v8-cache/v24.13.1-x64-cf738c9d/6af33b91 +0 -0
  54. package/.v8-cache/v24.13.1-x64-cf738c9d/6c2562d2 +0 -0
  55. package/.v8-cache/v24.13.1-x64-cf738c9d/6dae0cfa +0 -0
  56. package/.v8-cache/v24.13.1-x64-cf738c9d/6e2529ce +0 -0
  57. package/.v8-cache/v24.13.1-x64-cf738c9d/71df9cb3 +0 -0
  58. package/.v8-cache/v24.13.1-x64-cf738c9d/72e1d543 +0 -0
  59. package/.v8-cache/v24.13.1-x64-cf738c9d/75519c80 +0 -0
  60. package/.v8-cache/v24.13.1-x64-cf738c9d/79bf115c +0 -0
  61. package/.v8-cache/v24.13.1-x64-cf738c9d/7a39347c +0 -0
  62. package/.v8-cache/v24.13.1-x64-cf738c9d/7b83e3d3 +0 -0
  63. package/.v8-cache/v24.13.1-x64-cf738c9d/7cd71bc5 +0 -0
  64. package/.v8-cache/v24.13.1-x64-cf738c9d/7da78512 +0 -0
  65. package/.v8-cache/v24.13.1-x64-cf738c9d/7ea06cea +0 -0
  66. package/.v8-cache/v24.13.1-x64-cf738c9d/82c3b573 +0 -0
  67. package/.v8-cache/v24.13.1-x64-cf738c9d/84c186e4 +0 -0
  68. package/.v8-cache/v24.13.1-x64-cf738c9d/8607bd36 +0 -0
  69. package/.v8-cache/v24.13.1-x64-cf738c9d/87372817 +0 -0
  70. package/.v8-cache/v24.13.1-x64-cf738c9d/87cf2209 +0 -0
  71. package/.v8-cache/v24.13.1-x64-cf738c9d/882aaa05 +0 -0
  72. package/.v8-cache/v24.13.1-x64-cf738c9d/8a4d3de8 +0 -0
  73. package/.v8-cache/v24.13.1-x64-cf738c9d/8e223473 +0 -0
  74. package/.v8-cache/v24.13.1-x64-cf738c9d/92b7aefd +0 -0
  75. package/.v8-cache/v24.13.1-x64-cf738c9d/932f0770 +0 -0
  76. package/.v8-cache/v24.13.1-x64-cf738c9d/937c03a1 +0 -0
  77. package/.v8-cache/v24.13.1-x64-cf738c9d/991e4758 +0 -0
  78. package/.v8-cache/v24.13.1-x64-cf738c9d/9af658fb +0 -0
  79. package/.v8-cache/v24.13.1-x64-cf738c9d/9ed80ba5 +0 -0
  80. package/.v8-cache/v24.13.1-x64-cf738c9d/9f0dc993 +0 -0
  81. package/.v8-cache/v24.13.1-x64-cf738c9d/a19c0c4f +0 -0
  82. package/.v8-cache/v24.13.1-x64-cf738c9d/a6409d95 +0 -0
  83. package/.v8-cache/v24.13.1-x64-cf738c9d/a7e80865 +0 -0
  84. package/.v8-cache/v24.13.1-x64-cf738c9d/ac9802c6 +0 -0
  85. package/.v8-cache/v24.13.1-x64-cf738c9d/acc36e66 +0 -0
  86. package/.v8-cache/v24.13.1-x64-cf738c9d/ad11e2dc +0 -0
  87. package/.v8-cache/v24.13.1-x64-cf738c9d/b0c8fcd8 +0 -0
  88. package/.v8-cache/v24.13.1-x64-cf738c9d/b1762958 +0 -0
  89. package/.v8-cache/v24.13.1-x64-cf738c9d/b3c2fab7 +0 -0
  90. package/.v8-cache/v24.13.1-x64-cf738c9d/b5b3329b +0 -0
  91. package/.v8-cache/v24.13.1-x64-cf738c9d/b806679e +0 -0
  92. package/.v8-cache/v24.13.1-x64-cf738c9d/bc1cdd48 +0 -0
  93. package/.v8-cache/v24.13.1-x64-cf738c9d/bc7ebd1d +0 -0
  94. package/.v8-cache/v24.13.1-x64-cf738c9d/c0b789d2 +0 -0
  95. package/.v8-cache/v24.13.1-x64-cf738c9d/c314aece +0 -0
  96. package/.v8-cache/v24.13.1-x64-cf738c9d/c399a5dc +0 -0
  97. package/.v8-cache/v24.13.1-x64-cf738c9d/c681cbc8 +0 -0
  98. package/.v8-cache/v24.13.1-x64-cf738c9d/c6834ffc +0 -0
  99. package/.v8-cache/v24.13.1-x64-cf738c9d/c6f12ed5 +0 -0
  100. package/.v8-cache/v24.13.1-x64-cf738c9d/cb0f0a3d +0 -0
  101. package/.v8-cache/v24.13.1-x64-cf738c9d/cbcb7c95 +0 -0
  102. package/.v8-cache/v24.13.1-x64-cf738c9d/cdd9107c +0 -0
  103. package/.v8-cache/v24.13.1-x64-cf738c9d/cdf2c4a3 +0 -0
  104. package/.v8-cache/v24.13.1-x64-cf738c9d/cfc49f4f +0 -0
  105. package/.v8-cache/v24.13.1-x64-cf738c9d/cff9434a +0 -0
  106. package/.v8-cache/v24.13.1-x64-cf738c9d/d02dd6f7 +0 -0
  107. package/.v8-cache/v24.13.1-x64-cf738c9d/d0507bf3 +0 -0
  108. package/.v8-cache/v24.13.1-x64-cf738c9d/d60fce19 +0 -0
  109. package/.v8-cache/v24.13.1-x64-cf738c9d/d733d619 +0 -0
  110. package/.v8-cache/v24.13.1-x64-cf738c9d/d75b7803 +0 -0
  111. package/.v8-cache/v24.13.1-x64-cf738c9d/dc86f000 +0 -0
  112. package/.v8-cache/v24.13.1-x64-cf738c9d/defa4f7f +0 -0
  113. package/.v8-cache/v24.13.1-x64-cf738c9d/e03e2acd +0 -0
  114. package/.v8-cache/v24.13.1-x64-cf738c9d/e0e3f52c +0 -0
  115. package/.v8-cache/v24.13.1-x64-cf738c9d/e158d332 +0 -0
  116. package/.v8-cache/v24.13.1-x64-cf738c9d/e6735171 +0 -0
  117. package/.v8-cache/v24.13.1-x64-cf738c9d/e6745c2b +0 -0
  118. package/.v8-cache/v24.13.1-x64-cf738c9d/e6b99945 +0 -0
  119. package/.v8-cache/v24.13.1-x64-cf738c9d/e6d8ceb8 +0 -0
  120. package/.v8-cache/v24.13.1-x64-cf738c9d/e7ffec37 +0 -0
  121. package/.v8-cache/v24.13.1-x64-cf738c9d/ea33b6de +0 -0
  122. package/.v8-cache/v24.13.1-x64-cf738c9d/eaafa3c4 +0 -0
  123. package/.v8-cache/v24.13.1-x64-cf738c9d/ebb50fca +0 -0
  124. package/.v8-cache/v24.13.1-x64-cf738c9d/ec805f2e +0 -0
  125. package/.v8-cache/v24.13.1-x64-cf738c9d/edaef8f1 +0 -0
  126. package/.v8-cache/v24.13.1-x64-cf738c9d/ee4401c8 +0 -0
  127. package/.v8-cache/v24.13.1-x64-cf738c9d/eeeebdfe +0 -0
  128. package/.v8-cache/v24.13.1-x64-cf738c9d/f3d51676 +0 -0
  129. package/.v8-cache/v24.13.1-x64-cf738c9d/f7b50a75 +0 -0
  130. package/.v8-cache/v24.13.1-x64-cf738c9d/fa58ca72 +0 -0
  131. package/.v8-cache/v24.13.1-x64-cf738c9d/fc97d72d +0 -0
  132. package/.v8-cache/v24.13.1-x64-cf738c9d/fd0a2987 +0 -0
  133. package/CHANGELOG.md +6 -0
  134. package/README.md +64 -0
  135. package/TODO.md +2 -0
  136. package/dist/abr.d.ts +196 -196
  137. package/dist/abr.js +364 -365
  138. package/dist/abr.js.map +1 -1
  139. package/dist/additionalInfo.d.ts +26 -26
  140. package/dist/additionalInfo.js +3478 -3478
  141. package/dist/additionalInfo.js.map +1 -1
  142. package/dist/ase.d.ts +32 -32
  143. package/dist/ase.js +81 -82
  144. package/dist/ase.js.map +1 -1
  145. package/dist/bundle.js +12380 -12259
  146. package/dist/csh.d.ts +10 -10
  147. package/dist/csh.js +35 -36
  148. package/dist/csh.js.map +1 -1
  149. package/dist/descriptor.d.ts +601 -601
  150. package/dist/descriptor.js +2003 -2003
  151. package/dist/descriptor.js.map +1 -1
  152. package/dist/effectsHelpers.d.ts +5 -5
  153. package/dist/effectsHelpers.js +286 -287
  154. package/dist/effectsHelpers.js.map +1 -1
  155. package/dist/engineData.d.ts +2 -2
  156. package/dist/engineData.js +334 -335
  157. package/dist/engineData.js.map +1 -1
  158. package/dist/engineData2.d.ts +2 -2
  159. package/dist/engineData2.js +409 -410
  160. package/dist/engineData2.js.map +1 -1
  161. package/dist/helpers.d.ts +74 -74
  162. package/dist/helpers.js +353 -342
  163. package/dist/helpers.js.map +1 -1
  164. package/dist/imageResources.d.ts +17 -17
  165. package/dist/imageResources.js +1040 -1040
  166. package/dist/imageResources.js.map +1 -1
  167. package/dist/index.d.ts +20 -22
  168. package/dist/index.js +61 -56
  169. package/dist/index.js.map +1 -1
  170. package/dist/initializeCanvas.d.ts +1 -1
  171. package/dist/initializeCanvas.js +9 -10
  172. package/dist/initializeCanvas.js.map +1 -1
  173. package/dist/jpeg.d.ts +1 -1
  174. package/dist/jpeg.js +1020 -1021
  175. package/dist/jpeg.js.map +1 -1
  176. package/dist/psd.d.ts +1877 -1873
  177. package/dist/psd.js +45 -45
  178. package/dist/psd.js.map +1 -1
  179. package/dist/psdReader.d.ts +52 -45
  180. package/dist/psdReader.js +1385 -1282
  181. package/dist/psdReader.js.map +1 -1
  182. package/dist/psdWriter.d.ts +34 -34
  183. package/dist/psdWriter.js +834 -824
  184. package/dist/psdWriter.js.map +1 -1
  185. package/dist/text.d.ts +179 -179
  186. package/dist/text.js +552 -553
  187. package/dist/text.js.map +1 -1
  188. package/dist/utf8.d.ts +4 -6
  189. package/dist/utf8.js +156 -157
  190. package/dist/utf8.js.map +1 -1
  191. package/dist-es/abr.d.ts +196 -196
  192. package/dist-es/abr.js +364 -361
  193. package/dist-es/abr.js.map +1 -1
  194. package/dist-es/additionalInfo.d.ts +26 -26
  195. package/dist-es/additionalInfo.js +3478 -3472
  196. package/dist-es/additionalInfo.js.map +1 -1
  197. package/dist-es/ase.d.ts +32 -32
  198. package/dist-es/ase.js +81 -78
  199. package/dist-es/ase.js.map +1 -1
  200. package/dist-es/csh.d.ts +10 -10
  201. package/dist-es/csh.js +35 -32
  202. package/dist-es/csh.js.map +1 -1
  203. package/dist-es/descriptor.d.ts +601 -601
  204. package/dist-es/descriptor.js +2003 -1970
  205. package/dist-es/descriptor.js.map +1 -1
  206. package/dist-es/effectsHelpers.d.ts +5 -5
  207. package/dist-es/effectsHelpers.js +286 -282
  208. package/dist-es/effectsHelpers.js.map +1 -1
  209. package/dist-es/engineData.d.ts +2 -2
  210. package/dist-es/engineData.js +334 -330
  211. package/dist-es/engineData.js.map +1 -1
  212. package/dist-es/engineData2.d.ts +2 -2
  213. package/dist-es/engineData2.js +409 -406
  214. package/dist-es/engineData2.js.map +1 -1
  215. package/dist-es/helpers.d.ts +74 -74
  216. package/dist-es/helpers.js +353 -324
  217. package/dist-es/helpers.js.map +1 -1
  218. package/dist-es/imageResources.d.ts +17 -17
  219. package/dist-es/imageResources.js +1040 -1037
  220. package/dist-es/imageResources.js.map +1 -1
  221. package/dist-es/index.d.ts +20 -22
  222. package/dist-es/index.js +61 -33
  223. package/dist-es/index.js.map +1 -1
  224. package/dist-es/initializeCanvas.d.ts +1 -1
  225. package/dist-es/initializeCanvas.js +9 -6
  226. package/dist-es/initializeCanvas.js.map +1 -1
  227. package/dist-es/jpeg.d.ts +1 -1
  228. package/dist-es/jpeg.js +1020 -1017
  229. package/dist-es/jpeg.js.map +1 -1
  230. package/dist-es/psd.d.ts +1877 -1873
  231. package/dist-es/psd.js +45 -42
  232. package/dist-es/psd.js.map +1 -1
  233. package/dist-es/psdReader.d.ts +52 -45
  234. package/dist-es/psdReader.js +1385 -1244
  235. package/dist-es/psdReader.js.map +1 -1
  236. package/dist-es/psdWriter.d.ts +34 -34
  237. package/dist-es/psdWriter.js +834 -794
  238. package/dist-es/psdWriter.js.map +1 -1
  239. package/dist-es/text.d.ts +179 -179
  240. package/dist-es/text.js +552 -548
  241. package/dist-es/text.js.map +1 -1
  242. package/dist-es/utf8.d.ts +4 -6
  243. package/dist-es/utf8.js +156 -150
  244. package/dist-es/utf8.js.map +1 -1
  245. package/package.json +4 -3
  246. package/src/helpers.ts +13 -3
  247. package/src/index.ts +4 -6
  248. package/src/psd.ts +4 -0
  249. package/src/psdReader.ts +136 -43
  250. package/src/psdWriter.ts +42 -23
  251. package/tsconfig-es6.json +2 -1
  252. package/tsconfig.json +1 -0
@@ -1,2004 +1,2004 @@
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.ESliceOrigin = exports.ESliceVertAlign = exports.ESliceHorzAlign = exports.ESliceType = exports.FrFl = exports.FStl = exports.ClrS = exports.gradientInterpolationMethodType = exports.stdTrackID = exports.animInterpStyleEnum = exports.GrdT = exports.IGSr = exports.BETE = exports.BESs = exports.bvlT = exports.BESl = exports.BlnM = exports.warpStyle = exports.Annt = exports.Ornt = exports.textGridding = exports.frac = exports.unitsValue = exports.unitsPercentF = exports.unitsPercent = exports.unitsAngle = exports.parseUnitsToNumber = exports.parseUnitsOrNumber = exports.parseUnits = exports.parsePercentOrAngle = exports.parsePercent = exports.parseAngle = exports.serializeColor = exports.parseColor = exports.serializeVectorContent = exports.parseVectorContent = exports.serializeTrackList = exports.parseTrackList = exports.parseEffects = exports.serializeEffects = exports.boundsToDescBounds = exports.descBoundsToBounds = exports.xyToHorzVrtc = exports.horzVrtcToXY = exports.writeVersionAndDescriptor = exports.readVersionAndDescriptor = exports.writeDescriptorStructure = exports.readDescriptorStructure = exports.readAsciiStringOrClassId = exports.setLogErrors = void 0;
15
- exports.presetKindType = exports.prjM = exports.FlMd = exports.IntC = exports.IntE = exports.Drct = exports.WndM = exports.CntE = exports.FlCl = exports.ExtR = exports.ExtT = exports.DfsM = exports.blurType = exports.Lns = exports.MztT = exports.Chnl = exports.Dstr = exports.ZZTy = exports.Wvtp = exports.SphM = exports.RplS = exports.Cnvr = exports.UndA = exports.DspM = exports.SmBQ = exports.SmBM = exports.BlrQ = exports.BlrM = exports.strokeStyleLineAlignment = exports.strokeStyleLineJoinType = exports.strokeStyleLineCapType = exports.ESliceBGColorType = void 0;
16
- const helpers_1 = require("./helpers");
17
- const psdReader_1 = require("./psdReader");
18
- const psdWriter_1 = require("./psdWriter");
19
- function revMap(map) {
20
- const result = {};
21
- Object.keys(map).forEach(key => result[map[key]] = key);
22
- return result;
23
- }
24
- const unitsMap = {
25
- '#Ang': 'Angle',
26
- '#Rsl': 'Density',
27
- '#Rlt': 'Distance',
28
- '#Nne': 'None',
29
- '#Prc': 'Percent',
30
- '#Pxl': 'Pixels',
31
- '#Mlm': 'Millimeters',
32
- '#Pnt': 'Points',
33
- 'RrPi': 'Picas',
34
- 'RrIn': 'Inches',
35
- 'RrCm': 'Centimeters',
36
- };
37
- const unitsMapRev = revMap(unitsMap);
38
- let logErrors = false;
39
- function setLogErrors(value) {
40
- logErrors = value;
41
- }
42
- exports.setLogErrors = setLogErrors;
43
- function makeType(name, classID) {
44
- return { name, classID };
45
- }
46
- const nullType = makeType('', 'null');
47
- const USE_CHINESE = false; // Testing
48
- const fieldToExtType = {
49
- strokeStyleContent: makeType('', 'solidColorLayer'),
50
- printProofSetup: makeType(USE_CHINESE ? '校样设置' : 'Proof Setup', 'proofSetup'),
51
- Grad: makeType(USE_CHINESE ? '渐变' : 'Gradient', 'Grdn'),
52
- Trnf: makeType(USE_CHINESE ? '变换' : 'Transform', 'Trnf'),
53
- patternFill: makeType('', 'patternFill'),
54
- ebbl: makeType('', 'ebbl'),
55
- SoFi: makeType('', 'SoFi'),
56
- GrFl: makeType('', 'GrFl'),
57
- sdwC: makeType('', 'RGBC'),
58
- hglC: makeType('', 'RGBC'),
59
- 'Clr ': makeType('', 'RGBC'),
60
- 'tintColor': makeType('', 'RGBC'),
61
- Ofst: makeType('', 'Pnt '),
62
- ChFX: makeType('', 'ChFX'),
63
- MpgS: makeType('', 'ShpC'),
64
- DrSh: makeType('', 'DrSh'),
65
- IrSh: makeType('', 'IrSh'),
66
- OrGl: makeType('', 'OrGl'),
67
- IrGl: makeType('', 'IrGl'),
68
- TrnS: makeType('', 'ShpC'),
69
- Ptrn: makeType('', 'Ptrn'),
70
- FrFX: makeType('', 'FrFX'),
71
- phase: makeType('', 'Pnt '),
72
- frameStep: nullType,
73
- duration: nullType,
74
- workInTime: nullType,
75
- workOutTime: nullType,
76
- audioClipGroupList: nullType,
77
- bounds: makeType('', 'Rctn'),
78
- customEnvelopeWarp: makeType('', 'customEnvelopeWarp'),
79
- warp: makeType('', 'warp'),
80
- 'Sz ': makeType('', 'Pnt '),
81
- origin: makeType('', 'Pnt '),
82
- autoExpandOffset: makeType('', 'Pnt '),
83
- keyOriginShapeBBox: makeType('', 'unitRect'),
84
- Vrsn: nullType,
85
- psVersion: nullType,
86
- docDefaultNewArtboardBackgroundColor: makeType('', 'RGBC'),
87
- artboardRect: makeType('', 'classFloatRect'),
88
- keyOriginRRectRadii: makeType('', 'radii'),
89
- keyOriginBoxCorners: nullType,
90
- rectangleCornerA: makeType('', 'Pnt '),
91
- rectangleCornerB: makeType('', 'Pnt '),
92
- rectangleCornerC: makeType('', 'Pnt '),
93
- rectangleCornerD: makeType('', 'Pnt '),
94
- compInfo: nullType,
95
- quiltWarp: makeType('', 'quiltWarp'),
96
- generatorSettings: nullType,
97
- crema: nullType,
98
- FrIn: nullType,
99
- blendOptions: nullType,
100
- FXRf: nullType,
101
- Lefx: nullType,
102
- time: nullType,
103
- animKey: nullType,
104
- timeScope: nullType,
105
- inTime: nullType,
106
- outTime: nullType,
107
- sheetStyle: nullType,
108
- translation: nullType,
109
- Skew: nullType,
110
- boundingBox: makeType('', 'boundingBox'),
111
- 'Lnk ': makeType('', 'ExternalFileLink'),
112
- frameReader: makeType('', 'FrameReader'),
113
- effectParams: makeType('', 'motionTrackEffectParams'),
114
- Impr: makeType('None', 'none'),
115
- Anch: makeType('', 'Pnt '),
116
- 'Fwd ': makeType('', 'Pnt '),
117
- 'Bwd ': makeType('', 'Pnt '),
118
- FlrC: makeType('', 'Pnt '),
119
- meshBoundaryPath: makeType('', 'pathClass'),
120
- filterFX: makeType('', 'filterFXStyle'),
121
- Fltr: makeType('', 'rigidTransform'),
122
- FrgC: makeType('', 'RGBC'),
123
- BckC: makeType('', 'RGBC'),
124
- sdwM: makeType('Parameters', 'adaptCorrectTones'),
125
- hglM: makeType('Parameters', 'adaptCorrectTones'),
126
- customShape: makeType('', 'customShape'),
127
- origFXRefPoint: nullType,
128
- FXRefPoint: nullType,
129
- ClMg: makeType('', 'ClMg'),
130
- };
131
- const fieldToArrayExtType = {
132
- 'Crv ': makeType('', 'CrPt'),
133
- Clrs: makeType('', 'Clrt'),
134
- Trns: makeType('', 'TrnS'),
135
- keyDescriptorList: nullType,
136
- solidFillMulti: makeType('', 'SoFi'),
137
- gradientFillMulti: makeType('', 'GrFl'),
138
- dropShadowMulti: makeType('', 'DrSh'),
139
- innerShadowMulti: makeType('', 'IrSh'),
140
- frameFXMulti: makeType('', 'FrFX'),
141
- FrIn: nullType,
142
- FSts: nullType,
143
- LaSt: nullType,
144
- sheetTimelineOptions: nullType,
145
- trackList: makeType('', 'animationTrack'),
146
- globalTrackList: makeType('', 'animationTrack'),
147
- keyList: nullType,
148
- audioClipGroupList: nullType,
149
- audioClipList: nullType,
150
- countObjectList: makeType('', 'countObject'),
151
- countGroupList: makeType('', 'countGroup'),
152
- slices: makeType('', 'slice'),
153
- 'Pts ': makeType('', 'Pthp'),
154
- SbpL: makeType('', 'SbpL'),
155
- pathComponents: makeType('', 'PaCm'),
156
- filterFXList: makeType('', 'filterFX'),
157
- puppetShapeList: makeType('', 'puppetShape'),
158
- channelDenoise: makeType('', 'channelDenoiseParams'),
159
- ShrP: makeType('', 'Pnt '),
160
- layerSettings: nullType,
161
- list: nullType,
162
- Adjs: makeType('', 'CrvA'),
163
- };
164
- const typeToField = {
165
- 'TEXT': [
166
- 'Txt ', 'printerName', 'Nm ', 'Idnt', 'blackAndWhitePresetFileName', 'LUT3DFileName',
167
- 'presetFileName', 'curvesPresetFileName', 'mixerPresetFileName', 'placed', 'description', 'reason',
168
- 'artboardPresetName', 'json', 'clipID', 'relPath', 'fullPath', 'mediaDescriptor', 'Msge',
169
- 'altTag', 'url', 'cellText', 'preset', 'KnNm', 'FPth', 'comment', 'originalPath',
170
- ],
171
- 'tdta': [
172
- 'EngineData', 'LUT3DFileData', 'indexArray', 'originalVertexArray', 'deformedVertexArray',
173
- 'LqMe',
174
- ],
175
- 'long': [
176
- 'TextIndex', 'RndS', 'Mdpn', 'Smth', 'Lctn', 'strokeStyleVersion', 'LaID', 'Vrsn', 'Cnt ',
177
- 'Brgh', 'Cntr', 'means', 'vibrance', 'Strt', 'bwPresetKind', 'comp', 'compID', 'originalCompID',
178
- 'curvesPresetKind', 'mixerPresetKind', 'uOrder', 'vOrder', 'PgNm', 'totalPages', 'Crop',
179
- 'numerator', 'denominator', 'frameCount', 'Annt', 'keyOriginType', 'unitValueQuadVersion',
180
- 'keyOriginIndex', 'major', 'minor', 'fix', 'docDefaultNewArtboardBackgroundType', 'artboardBackgroundType',
181
- 'numModifyingFX', 'deformNumRows', 'deformNumCols', 'FrID', 'FrDl', 'FsID', 'LCnt', 'AFrm', 'AFSt',
182
- 'numBefore', 'numAfter', 'Spcn', 'minOpacity', 'maxOpacity', 'BlnM', 'sheetID', 'gblA', 'globalAltitude',
183
- 'descVersion', 'frameReaderType', 'LyrI', 'zoomOrigin', 'fontSize', 'Rds ', 'sliceID',
184
- 'topOutset', 'leftOutset', 'bottomOutset', 'rightOutset', 'filterID', 'meshQuality',
185
- 'meshExpansion', 'meshRigidity', 'VrsM', 'VrsN', 'NmbG', 'WLMn', 'WLMx', 'AmMn', 'AmMx', 'SclH', 'SclV',
186
- 'Lvl ', 'TlNm', 'TlOf', 'FlRs', 'Thsh', 'ShrS', 'ShrE', 'FlRs', 'Vrnc', 'Strg', 'ExtS', 'ExtD',
187
- 'HrzS', 'VrtS', 'NmbR', 'EdgF', 'Ang1', 'Ang2', 'Ang3', 'Ang4', 'lastAppliedComp', 'capturedInfo',
188
- ],
189
- 'enum': [
190
- 'textGridding', 'Ornt', 'warpStyle', 'warpRotate', 'Inte', 'Bltn', 'ClrS', 'BlrQ',
191
- 'bvlT', 'bvlS', 'bvlD', 'Md ', 'glwS', 'GrdF', 'GlwT', 'RplS', 'BlrM', 'SmBM',
192
- 'strokeStyleLineCapType', 'strokeStyleLineJoinType', 'strokeStyleLineAlignment',
193
- 'strokeStyleBlendMode', 'PntT', 'Styl', 'lookupType', 'LUTFormat', 'dataOrder',
194
- 'tableOrder', 'enableCompCore', 'enableCompCoreGPU', 'compCoreSupport', 'compCoreGPUSupport', 'Engn',
195
- 'enableCompCoreThreads', 'gs99', 'FrDs', 'trackID', 'animInterpStyle', 'horzAlign',
196
- 'vertAlign', 'bgColorType', 'shapeOperation', 'UndA', 'Wvtp', 'Drct', 'WndM', 'Edg ', 'FlCl', 'IntE',
197
- 'IntC', 'Cnvr', 'Fl ', 'Dstr', 'MztT', 'Lns ', 'ExtT', 'DspM', 'ExtR', 'ZZTy', 'SphM', 'SmBQ', 'placedLayerOCIOConversion', 'gradientsInterpolationMethod',
198
- ],
199
- 'bool': [
200
- 'PstS', 'printSixteenBit', 'masterFXSwitch', 'enab', 'uglg', 'antialiasGloss',
201
- 'useShape', 'useTexture', 'uglg', 'antialiasGloss', 'useShape', 'Vsbl',
202
- 'useTexture', 'Algn', 'Rvrs', 'Dthr', 'Invr', 'VctC', 'ShTr', 'layerConceals',
203
- 'strokeEnabled', 'fillEnabled', 'strokeStyleScaleLock', 'strokeStyleStrokeAdjust',
204
- 'hardProof', 'MpBl', 'paperWhite', 'useLegacy', 'Auto', 'Lab ', 'useTint', 'keyShapeInvalidated',
205
- 'autoExpandEnabled', 'autoNestEnabled', 'autoPositionEnabled', 'shrinkwrapOnSaveEnabled',
206
- 'present', 'showInDialog', 'overprint', 'sheetDisclosed', 'lightsDisclosed', 'meshesDisclosed',
207
- 'materialsDisclosed', 'hasMotion', 'muted', 'Effc', 'selected', 'autoScope', 'fillCanvas',
208
- 'cellTextIsHTML', 'Smoo', 'Clsp', 'validAtPosition', 'rigidType', 'hasoptions', 'filterMaskEnable',
209
- 'filterMaskLinked', 'filterMaskExtendWithWhite', 'removeJPEGArtifact', 'Mnch', 'ExtF', 'ExtM',
210
- 'moreAccurate', 'GpuY', 'LIWy', 'Cnty',
211
- ],
212
- 'doub': [
213
- 'warpValue', 'warpPerspective', 'warpPerspectiveOther', 'Intr', 'Wdth', 'Hght',
214
- 'strokeStyleMiterLimit', 'strokeStyleResolution', 'layerTime', 'keyOriginResolution',
215
- 'xx', 'xy', 'yx', 'yy', 'tx', 'ty', 'FrGA', 'frameRate', 'audioLevel', 'rotation',
216
- 'X ', 'Y ', 'redFloat', 'greenFloat', 'blueFloat', 'imageResolution',
217
- 'PuX0', 'PuX1', 'PuX2', 'PuX3', 'PuY0', 'PuY1', 'PuY2', 'PuY3'
218
- ],
219
- 'UntF': [
220
- 'sdwO', 'hglO', 'lagl', 'Lald', 'srgR', 'blur', 'Sftn', 'Opct', 'Dstn', 'Angl',
221
- 'Ckmt', 'Nose', 'Inpr', 'ShdN', 'strokeStyleLineWidth', 'strokeStyleLineDashOffset',
222
- 'strokeStyleOpacity', 'H ', 'Top ', 'Left', 'Btom', 'Rght', 'Rslt',
223
- 'topRight', 'topLeft', 'bottomLeft', 'bottomRight', 'ClNs', 'Shrp',
224
- ],
225
- 'VlLs': [
226
- 'Crv ', 'Clrs', 'Mnm ', 'Mxm ', 'Trns', 'pathList', 'strokeStyleLineDashSet', 'FrLs', 'slices',
227
- 'LaSt', 'Trnf', 'nonAffineTransform', 'keyDescriptorList', 'guideIndeces', 'gradientFillMulti',
228
- 'solidFillMulti', 'frameFXMulti', 'innerShadowMulti', 'dropShadowMulti', 'FrIn', 'FSts', 'FsFr',
229
- 'sheetTimelineOptions', 'audioClipList', 'trackList', 'globalTrackList', 'keyList', 'audioClipList',
230
- 'warpValues', 'selectedPin', 'Pts ', 'SbpL', 'pathComponents', 'pinOffsets', 'posFinalPins',
231
- 'pinVertexIndices', 'PinP', 'PnRt', 'PnOv', 'PnDp', 'filterFXList', 'puppetShapeList', 'ShrP',
232
- 'channelDenoise', 'Mtrx', 'layerSettings', 'list', 'compList', 'Adjs',
233
- ],
234
- 'ObAr': ['meshPoints', 'quiltSliceX', 'quiltSliceY'],
235
- 'obj ': ['null', 'Chnl'],
236
- 'Pth ': ['DspF'],
237
- };
238
- const channels = [
239
- 'Rd ', 'Grn ', 'Bl ', 'Yllw', 'Ylw ', 'Cyn ', 'Mgnt', 'Blck', 'Gry ', 'Lmnc', 'A ', 'B ',
240
- ];
241
- const fieldToArrayType = {
242
- 'Mnm ': 'long',
243
- 'Mxm ': 'long',
244
- FrLs: 'long',
245
- strokeStyleLineDashSet: 'UntF',
246
- Trnf: 'doub',
247
- nonAffineTransform: 'doub',
248
- keyDescriptorList: 'Objc',
249
- gradientFillMulti: 'Objc',
250
- solidFillMulti: 'Objc',
251
- frameFXMulti: 'Objc',
252
- innerShadowMulti: 'Objc',
253
- dropShadowMulti: 'Objc',
254
- LaSt: 'Objc',
255
- FrIn: 'Objc',
256
- FSts: 'Objc',
257
- FsFr: 'long',
258
- blendOptions: 'Objc',
259
- sheetTimelineOptions: 'Objc',
260
- keyList: 'Objc',
261
- warpValues: 'doub',
262
- selectedPin: 'long',
263
- 'Pts ': 'Objc',
264
- SbpL: 'Objc',
265
- pathComponents: 'Objc',
266
- pinOffsets: 'doub',
267
- posFinalPins: 'doub',
268
- pinVertexIndices: 'long',
269
- PinP: 'doub',
270
- PnRt: 'long',
271
- PnOv: 'bool',
272
- PnDp: 'doub',
273
- filterFXList: 'Objc',
274
- puppetShapeList: 'Objc',
275
- ShrP: 'Objc',
276
- channelDenoise: 'Objc',
277
- Mtrx: 'long',
278
- compList: 'long',
279
- Chnl: 'enum',
280
- };
281
- const fieldToType = {};
282
- for (const type of Object.keys(typeToField)) {
283
- for (const field of typeToField[type]) {
284
- fieldToType[field] = type;
285
- }
286
- }
287
- for (const field of Object.keys(fieldToExtType)) {
288
- if (!fieldToType[field])
289
- fieldToType[field] = 'Objc';
290
- }
291
- for (const field of Object.keys(fieldToArrayExtType)) {
292
- fieldToArrayType[field] = 'Objc';
293
- }
294
- function getTypeByKey(key, value, root, parent) {
295
- if (key === 'presetKind') {
296
- return typeof value === 'string' ? 'enum' : 'long';
297
- }
298
- if (key === 'null' && root === 'slices') {
299
- return 'TEXT';
300
- }
301
- else if (key === 'groupID') {
302
- return root === 'slices' ? 'long' : 'TEXT';
303
- }
304
- else if (key === 'Sz ') {
305
- return ('Wdth' in value) ? 'Objc' : (('units' in value) ? 'UntF' : 'doub');
306
- }
307
- else if (key === 'Type') {
308
- return typeof value === 'string' ? 'enum' : 'long';
309
- }
310
- else if (key === 'AntA') {
311
- return typeof value === 'string' ? 'enum' : 'bool';
312
- }
313
- else if ((key === 'Hrzn' || key === 'Vrtc') && (parent.Type === 'keyType.Pstn' || parent._classID === 'Ofst')) {
314
- return 'long';
315
- }
316
- else if (key === 'Hrzn' || key === 'Vrtc' || key === 'Top ' || key === 'Left' || key === 'Btom' || key === 'Rght') {
317
- if (root === 'slices')
318
- return 'long';
319
- return typeof value === 'number' ? 'doub' : 'UntF';
320
- }
321
- else if (key === 'Vrsn') {
322
- return typeof value === 'number' ? 'long' : 'Objc';
323
- }
324
- else if (key === 'Rd ' || key === 'Grn ' || key === 'Bl ') {
325
- return root === 'artd' ? 'long' : 'doub';
326
- }
327
- else if (key === 'Trnf') {
328
- return Array.isArray(value) ? 'VlLs' : 'Objc';
329
- }
330
- else {
331
- return fieldToType[key];
332
- }
333
- }
334
- function readAsciiStringOrClassId(reader) {
335
- const length = (0, psdReader_1.readInt32)(reader);
336
- return (0, psdReader_1.readAsciiString)(reader, length || 4);
337
- }
338
- exports.readAsciiStringOrClassId = readAsciiStringOrClassId;
339
- function writeAsciiStringOrClassId(writer, value) {
340
- if (value.length === 4 && value !== 'warp' && value !== 'time' && value !== 'hold' && value !== 'list') {
341
- // write classId
342
- (0, psdWriter_1.writeInt32)(writer, 0);
343
- (0, psdWriter_1.writeSignature)(writer, value);
344
- }
345
- else {
346
- // write ascii string
347
- (0, psdWriter_1.writeInt32)(writer, value.length);
348
- for (let i = 0; i < value.length; i++) {
349
- (0, psdWriter_1.writeUint8)(writer, value.charCodeAt(i));
350
- }
351
- }
352
- }
353
- function readDescriptorStructure(reader, includeClass) {
354
- const struct = readClassStructure(reader);
355
- const object = includeClass ? { _name: struct.name, _classID: struct.classID } : {};
356
- // console.log('>> ', struct);
357
- const itemsCount = (0, psdReader_1.readUint32)(reader);
358
- for (let i = 0; i < itemsCount; i++) {
359
- const key = readAsciiStringOrClassId(reader);
360
- const type = (0, psdReader_1.readSignature)(reader);
361
- // console.log(`> '${key}' '${type}'`);
362
- const data = readOSType(reader, type, includeClass);
363
- // if (!getTypeByKey(key, data)) console.log(`> '${key}' '${type}'`, data);
364
- object[key] = data;
365
- }
366
- return object;
367
- }
368
- exports.readDescriptorStructure = readDescriptorStructure;
369
- function writeDescriptorStructure(writer, name, classId, value, root) {
370
- if (logErrors && !classId)
371
- console.log('Missing classId for: ', name, classId, value);
372
- // write class structure
373
- (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, name);
374
- writeAsciiStringOrClassId(writer, classId);
375
- const keys = Object.keys(value);
376
- let keyCount = keys.length;
377
- if ('_name' in value)
378
- keyCount--;
379
- if ('_classID' in value)
380
- keyCount--;
381
- (0, psdWriter_1.writeUint32)(writer, keyCount);
382
- for (const key of keys) {
383
- if (key === '_name' || key === '_classID')
384
- continue;
385
- let type = getTypeByKey(key, value[key], root, value);
386
- let extType = fieldToExtType[key];
387
- if (key === 'bounds' && root === 'text') {
388
- extType = makeType('', 'bounds');
389
- }
390
- else if (key === 'origin') {
391
- type = root === 'slices' ? 'enum' : 'Objc';
392
- }
393
- else if ((key === 'Cyn ' || key === 'Mgnt' || key === 'Ylw ' || key === 'Blck') && value._classID === 'CMYC') {
394
- type = 'doub';
395
- }
396
- else if (/^PN[a-z][a-z]$/.test(key)) {
397
- type = 'TEXT';
398
- }
399
- else if (/^PT[a-z][a-z]$/.test(key)) {
400
- type = 'long';
401
- }
402
- else if (/^PF[a-z][a-z]$/.test(key)) {
403
- type = 'doub';
404
- }
405
- else if ((key === 'Rds ' || key === 'Thsh') && typeof value[key] === 'number' && value._classID === 'SmrB') {
406
- type = 'doub';
407
- }
408
- else if (key === 'ClSz' || key === 'Rds ' || key === 'Amnt') {
409
- type = typeof value[key] === 'number' ? 'long' : 'UntF';
410
- }
411
- else if ((key === 'sdwM' || key === 'hglM') && typeof value[key] === 'string') {
412
- type = 'enum';
413
- }
414
- else if (key === 'blur' && typeof value[key] === 'string') {
415
- type = 'enum';
416
- }
417
- else if (key === 'Hght' && typeof value[key] === 'number' && value._classID === 'Embs') {
418
- type = 'long';
419
- }
420
- else if (key === 'Angl' && typeof value[key] === 'number' && (value._classID === 'Embs' || value._classID === 'smartSharpen' || value._classID === 'Twrl' || value._classID === 'MtnB')) {
421
- type = 'long';
422
- }
423
- else if (key === 'Angl' && typeof value[key] === 'number') {
424
- type = 'doub'; // ???
425
- }
426
- else if (key === 'bounds' && root === 'slices') {
427
- type = 'Objc';
428
- extType = makeType('', 'Rct1');
429
- }
430
- else if (key === 'Scl ') {
431
- if (typeof value[key] === 'object' && 'Hrzn' in value[key]) {
432
- type = 'Objc';
433
- extType = nullType;
434
- }
435
- else if (typeof value[key] === 'number') {
436
- type = 'long';
437
- }
438
- else {
439
- type = 'UntF';
440
- }
441
- }
442
- else if (key === 'audioClipGroupList' && keys.length === 1) {
443
- type = 'VlLs';
444
- }
445
- else if ((key === 'Strt' || key === 'Brgh') && 'H ' in value) {
446
- type = 'doub';
447
- }
448
- else if (key === 'Wdth' && typeof value[key] === 'object') {
449
- type = 'UntF';
450
- }
451
- else if (key === 'Ofst' && typeof value[key] === 'number') {
452
- type = 'long';
453
- }
454
- else if (key === 'Strt' && typeof value[key] === 'object') {
455
- type = 'Objc';
456
- extType = nullType;
457
- }
458
- else if (channels.indexOf(key) !== -1) {
459
- type = (classId === 'RGBC' && root !== 'artd') ? 'doub' : 'long';
460
- }
461
- else if (key === 'profile') {
462
- type = classId === 'printOutput' ? 'TEXT' : 'tdta';
463
- }
464
- else if (key === 'strokeStyleContent') {
465
- if (value[key]['Clr ']) {
466
- extType = makeType('', 'solidColorLayer');
467
- }
468
- else if (value[key].Grad) {
469
- extType = makeType('', 'gradientLayer');
470
- }
471
- else if (value[key].Ptrn) {
472
- extType = makeType('', 'patternLayer');
473
- }
474
- else {
475
- logErrors && console.log('Invalid strokeStyleContent value', value[key]);
476
- }
477
- }
478
- else if (key === 'bounds' && root === 'quiltWarp') {
479
- extType = makeType('', 'classFloatRect');
480
- }
481
- if (extType && extType.classID === 'RGBC') {
482
- if ('H ' in value[key])
483
- extType = { classID: 'HSBC', name: '' };
484
- // TODO: other color spaces
485
- }
486
- writeAsciiStringOrClassId(writer, key);
487
- (0, psdWriter_1.writeSignature)(writer, type || 'long');
488
- writeOSType(writer, type || 'long', value[key], key, extType, root);
489
- if (logErrors && !type)
490
- console.log(`Missing descriptor field type for: '${key}' in`, value);
491
- }
492
- }
493
- exports.writeDescriptorStructure = writeDescriptorStructure;
494
- function readOSType(reader, type, includeClass) {
495
- switch (type) {
496
- case 'obj ': // Reference
497
- return readReferenceStructure(reader);
498
- case 'Objc': // Descriptor
499
- case 'GlbO': // GlobalObject same as Descriptor
500
- return readDescriptorStructure(reader, includeClass);
501
- case 'VlLs': { // List
502
- const length = (0, psdReader_1.readInt32)(reader);
503
- const items = [];
504
- for (let i = 0; i < length; i++) {
505
- const itemType = (0, psdReader_1.readSignature)(reader);
506
- // console.log(' >', itemType);
507
- items.push(readOSType(reader, itemType, includeClass));
508
- }
509
- return items;
510
- }
511
- case 'doub': // Double
512
- return (0, psdReader_1.readFloat64)(reader);
513
- case 'UntF': { // Unit double
514
- const units = (0, psdReader_1.readSignature)(reader);
515
- const value = (0, psdReader_1.readFloat64)(reader);
516
- if (!unitsMap[units])
517
- throw new Error(`Invalid units: ${units}`);
518
- return { units: unitsMap[units], value };
519
- }
520
- case 'UnFl': { // Unit float
521
- const units = (0, psdReader_1.readSignature)(reader);
522
- const value = (0, psdReader_1.readFloat32)(reader);
523
- if (!unitsMap[units])
524
- throw new Error(`Invalid units: ${units}`);
525
- return { units: unitsMap[units], value };
526
- }
527
- case 'TEXT': // String
528
- return (0, psdReader_1.readUnicodeString)(reader);
529
- case 'enum': { // Enumerated
530
- const enumType = readAsciiStringOrClassId(reader);
531
- const value = readAsciiStringOrClassId(reader);
532
- return `${enumType}.${value}`;
533
- }
534
- case 'long': // Integer
535
- return (0, psdReader_1.readInt32)(reader);
536
- case 'comp': { // Large Integer
537
- const low = (0, psdReader_1.readUint32)(reader);
538
- const high = (0, psdReader_1.readUint32)(reader);
539
- return { low, high };
540
- }
541
- case 'bool': // Boolean
542
- return !!(0, psdReader_1.readUint8)(reader);
543
- case 'type': // Class
544
- case 'GlbC': // Class
545
- return readClassStructure(reader);
546
- case 'alis': { // Alias
547
- const length = (0, psdReader_1.readInt32)(reader);
548
- return (0, psdReader_1.readAsciiString)(reader, length);
549
- }
550
- case 'tdta': { // Raw Data
551
- const length = (0, psdReader_1.readInt32)(reader);
552
- return (0, psdReader_1.readBytes)(reader, length);
553
- }
554
- case 'ObAr': { // Object array
555
- (0, psdReader_1.readInt32)(reader); // version: 16
556
- (0, psdReader_1.readUnicodeString)(reader); // name: ''
557
- readAsciiStringOrClassId(reader); // 'rationalPoint'
558
- const length = (0, psdReader_1.readInt32)(reader);
559
- const items = [];
560
- for (let i = 0; i < length; i++) {
561
- const type1 = readAsciiStringOrClassId(reader); // type Hrzn | Vrtc
562
- (0, psdReader_1.readSignature)(reader); // UnFl
563
- (0, psdReader_1.readSignature)(reader); // units ? '#Pxl'
564
- const valuesCount = (0, psdReader_1.readInt32)(reader);
565
- const values = [];
566
- for (let j = 0; j < valuesCount; j++) {
567
- values.push((0, psdReader_1.readFloat64)(reader));
568
- }
569
- items.push({ type: type1, values });
570
- }
571
- return items;
572
- }
573
- case 'Pth ': { // File path
574
- /*const length =*/ (0, psdReader_1.readInt32)(reader); // total size of all fields below
575
- const sig = (0, psdReader_1.readSignature)(reader);
576
- /*const pathSize =*/ (0, psdReader_1.readInt32LE)(reader); // the same as length
577
- const charsCount = (0, psdReader_1.readInt32LE)(reader);
578
- const path = (0, psdReader_1.readUnicodeStringWithLengthLE)(reader, charsCount);
579
- return { sig, path };
580
- }
581
- default:
582
- throw new Error(`Invalid TySh descriptor OSType: ${type} at ${reader.offset.toString(16)}`);
583
- }
584
- }
585
- const ObArTypes = {
586
- meshPoints: 'rationalPoint',
587
- quiltSliceX: 'UntF',
588
- quiltSliceY: 'UntF',
589
- };
590
- function writeOSType(writer, type, value, key, extType, root) {
591
- switch (type) {
592
- case 'obj ': // Reference
593
- writeReferenceStructure(writer, key, value);
594
- break;
595
- case 'Objc': // Descriptor
596
- case 'GlbO': { // GlobalObject same as Descriptor
597
- if (typeof value !== 'object')
598
- throw new Error(`Invalid struct value: ${JSON.stringify(value)}, key: ${key}`);
599
- if (!extType)
600
- throw new Error(`Missing ext type for: '${key}' (${JSON.stringify(value)})`);
601
- const name = value._name || extType.name;
602
- const classID = value._classID || extType.classID;
603
- writeDescriptorStructure(writer, name, classID, value, root);
604
- break;
605
- }
606
- case 'VlLs': // List
607
- if (!Array.isArray(value))
608
- throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
609
- (0, psdWriter_1.writeInt32)(writer, value.length);
610
- for (let i = 0; i < value.length; i++) {
611
- const type = fieldToArrayType[key];
612
- (0, psdWriter_1.writeSignature)(writer, type || 'long');
613
- writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType[key], root);
614
- if (logErrors && !type)
615
- console.log(`Missing descriptor array type for: '${key}' in`, value);
616
- }
617
- break;
618
- case 'doub': // Double
619
- if (typeof value !== 'number')
620
- throw new Error(`Invalid number value: ${JSON.stringify(value)}, key: ${key}`);
621
- (0, psdWriter_1.writeFloat64)(writer, value);
622
- break;
623
- case 'UntF': // Unit double
624
- if (!unitsMapRev[value.units])
625
- throw new Error(`Invalid units: ${value.units} in ${key}`);
626
- (0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
627
- (0, psdWriter_1.writeFloat64)(writer, value.value);
628
- break;
629
- case 'UnFl': // Unit float
630
- if (!unitsMapRev[value.units])
631
- throw new Error(`Invalid units: ${value.units} in ${key}`);
632
- (0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
633
- (0, psdWriter_1.writeFloat32)(writer, value.value);
634
- break;
635
- case 'TEXT': // String
636
- (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, value);
637
- break;
638
- case 'enum': { // Enumerated
639
- if (typeof value !== 'string')
640
- throw new Error(`Invalid enum value: ${JSON.stringify(value)}, key: ${key}`);
641
- const [_type, val] = value.split('.');
642
- writeAsciiStringOrClassId(writer, _type);
643
- writeAsciiStringOrClassId(writer, val);
644
- break;
645
- }
646
- case 'long': // Integer
647
- if (typeof value !== 'number')
648
- throw new Error(`Invalid integer value: ${JSON.stringify(value)}, key: ${key}`);
649
- (0, psdWriter_1.writeInt32)(writer, value);
650
- break;
651
- // case 'comp': // Large Integer
652
- // writeLargeInteger(reader);
653
- case 'bool': // Boolean
654
- if (typeof value !== 'boolean')
655
- throw new Error(`Invalid boolean value: ${JSON.stringify(value)}, key: ${key}`);
656
- (0, psdWriter_1.writeUint8)(writer, value ? 1 : 0);
657
- break;
658
- // case 'type': // Class
659
- // case 'GlbC': // Class
660
- // writeClassStructure(reader);
661
- // case 'alis': // Alias
662
- // writeAliasStructure(reader);
663
- case 'tdta': // Raw Data
664
- (0, psdWriter_1.writeInt32)(writer, value.byteLength);
665
- (0, psdWriter_1.writeBytes)(writer, value);
666
- break;
667
- case 'ObAr': { // Object array
668
- (0, psdWriter_1.writeInt32)(writer, 16); // version
669
- (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
670
- const type = ObArTypes[key];
671
- if (!type)
672
- throw new Error(`Not implemented ObArType for: ${key}`);
673
- writeAsciiStringOrClassId(writer, type);
674
- (0, psdWriter_1.writeInt32)(writer, value.length);
675
- for (let i = 0; i < value.length; i++) {
676
- writeAsciiStringOrClassId(writer, value[i].type); // Hrzn | Vrtc
677
- (0, psdWriter_1.writeSignature)(writer, 'UnFl');
678
- (0, psdWriter_1.writeSignature)(writer, '#Pxl');
679
- (0, psdWriter_1.writeInt32)(writer, value[i].values.length);
680
- for (let j = 0; j < value[i].values.length; j++) {
681
- (0, psdWriter_1.writeFloat64)(writer, value[i].values[j]);
682
- }
683
- }
684
- break;
685
- }
686
- case 'Pth ': { // File path
687
- const length = 4 + 4 + 4 + value.path.length * 2;
688
- (0, psdWriter_1.writeInt32)(writer, length);
689
- (0, psdWriter_1.writeSignature)(writer, value.sig);
690
- (0, psdWriter_1.writeInt32LE)(writer, length);
691
- (0, psdWriter_1.writeInt32LE)(writer, value.path.length);
692
- (0, psdWriter_1.writeUnicodeStringWithoutLengthLE)(writer, value.path);
693
- break;
694
- }
695
- default:
696
- throw new Error(`Not implemented descriptor OSType: ${type}`);
697
- }
698
- }
699
- function readReferenceStructure(reader) {
700
- const itemsCount = (0, psdReader_1.readInt32)(reader);
701
- const items = [];
702
- for (let i = 0; i < itemsCount; i++) {
703
- const type = (0, psdReader_1.readSignature)(reader);
704
- switch (type) {
705
- case 'prop': { // Property
706
- readClassStructure(reader);
707
- const keyID = readAsciiStringOrClassId(reader);
708
- items.push(keyID);
709
- break;
710
- }
711
- case 'Clss': // Class
712
- items.push(readClassStructure(reader));
713
- break;
714
- case 'Enmr': { // Enumerated Reference
715
- readClassStructure(reader);
716
- const typeID = readAsciiStringOrClassId(reader);
717
- const value = readAsciiStringOrClassId(reader);
718
- items.push(`${typeID}.${value}`);
719
- break;
720
- }
721
- case 'rele': { // Offset
722
- // const { name, classID } =
723
- readClassStructure(reader);
724
- items.push((0, psdReader_1.readUint32)(reader));
725
- break;
726
- }
727
- case 'Idnt': // Identifier
728
- items.push((0, psdReader_1.readInt32)(reader));
729
- break;
730
- case 'indx': // Index
731
- items.push((0, psdReader_1.readInt32)(reader));
732
- break;
733
- case 'name': { // Name
734
- readClassStructure(reader);
735
- items.push((0, psdReader_1.readUnicodeString)(reader));
736
- break;
737
- }
738
- default:
739
- throw new Error(`Invalid descriptor reference type: ${type}`);
740
- }
741
- }
742
- return items;
743
- }
744
- function writeReferenceStructure(writer, _key, items) {
745
- (0, psdWriter_1.writeInt32)(writer, items.length);
746
- for (let i = 0; i < items.length; i++) {
747
- const value = items[i];
748
- let type = 'unknown';
749
- if (typeof value === 'string') {
750
- if (/^[a-z ]+\.[a-z ]+$/i.test(value)) {
751
- type = 'Enmr';
752
- }
753
- else {
754
- type = 'name';
755
- }
756
- }
757
- (0, psdWriter_1.writeSignature)(writer, type);
758
- switch (type) {
759
- // case 'prop': // Property
760
- // case 'Clss': // Class
761
- case 'Enmr': { // Enumerated Reference
762
- const [typeID, enumValue] = value.split('.');
763
- writeClassStructure(writer, '\0', typeID);
764
- writeAsciiStringOrClassId(writer, typeID);
765
- writeAsciiStringOrClassId(writer, enumValue);
766
- break;
767
- }
768
- // case 'rele': // Offset
769
- // case 'Idnt': // Identifier
770
- // case 'indx': // Index
771
- case 'name': { // Name
772
- writeClassStructure(writer, '\0', 'Lyr ');
773
- (0, psdWriter_1.writeUnicodeString)(writer, value + '\0');
774
- break;
775
- }
776
- default:
777
- throw new Error(`Invalid descriptor reference type: ${type}`);
778
- }
779
- }
780
- return items;
781
- }
782
- function readClassStructure(reader) {
783
- const name = (0, psdReader_1.readUnicodeString)(reader);
784
- const classID = readAsciiStringOrClassId(reader);
785
- return { name, classID };
786
- }
787
- function writeClassStructure(writer, name, classID) {
788
- (0, psdWriter_1.writeUnicodeString)(writer, name);
789
- writeAsciiStringOrClassId(writer, classID);
790
- }
791
- function readVersionAndDescriptor(reader, includeClass = false) {
792
- const version = (0, psdReader_1.readUint32)(reader);
793
- if (version !== 16)
794
- throw new Error(`Invalid descriptor version: ${version}`);
795
- const desc = readDescriptorStructure(reader, includeClass);
796
- // console.log(require('util').inspect(desc, false, 99, true));
797
- return desc;
798
- }
799
- exports.readVersionAndDescriptor = readVersionAndDescriptor;
800
- function writeVersionAndDescriptor(writer, name, classID, descriptor, root = '') {
801
- (0, psdWriter_1.writeUint32)(writer, 16); // version
802
- writeDescriptorStructure(writer, name, classID, descriptor, root);
803
- }
804
- exports.writeVersionAndDescriptor = writeVersionAndDescriptor;
805
- function horzVrtcToXY(hv) {
806
- return { x: hv.Hrzn, y: hv.Vrtc };
807
- }
808
- exports.horzVrtcToXY = horzVrtcToXY;
809
- function xyToHorzVrtc(xy) {
810
- return { Hrzn: xy.x, Vrtc: xy.y };
811
- }
812
- exports.xyToHorzVrtc = xyToHorzVrtc;
813
- function descBoundsToBounds(desc) {
814
- return {
815
- top: parseUnits(desc['Top ']),
816
- left: parseUnits(desc.Left),
817
- right: parseUnits(desc.Rght),
818
- bottom: parseUnits(desc.Btom),
819
- };
820
- }
821
- exports.descBoundsToBounds = descBoundsToBounds;
822
- function boundsToDescBounds(bounds) {
823
- return {
824
- Left: unitsValue(bounds.left, 'bounds.left'),
825
- ['Top ']: unitsValue(bounds.top, 'bounds.top'),
826
- Rght: unitsValue(bounds.right, 'bounds.right'),
827
- Btom: unitsValue(bounds.bottom, 'bounds.bottom'),
828
- };
829
- }
830
- exports.boundsToDescBounds = boundsToDescBounds;
831
- function parseFxObject(fx) {
832
- const stroke = {
833
- enabled: !!fx.enab,
834
- position: exports.FStl.decode(fx.Styl),
835
- fillType: exports.FrFl.decode(fx.PntT),
836
- blendMode: exports.BlnM.decode(fx['Md ']),
837
- opacity: parsePercent(fx.Opct),
838
- size: parseUnits(fx['Sz ']),
839
- };
840
- if (fx.present !== undefined)
841
- stroke.present = fx.present;
842
- if (fx.showInDialog !== undefined)
843
- stroke.showInDialog = fx.showInDialog;
844
- if (fx.overprint !== undefined)
845
- stroke.overprint = fx.overprint;
846
- if (fx['Clr '])
847
- stroke.color = parseColor(fx['Clr ']);
848
- if (fx.Grad)
849
- stroke.gradient = parseGradientContent(fx);
850
- if (fx.Ptrn)
851
- stroke.pattern = parsePatternContent(fx);
852
- return stroke;
853
- }
854
- function serializeFxObject(stroke) {
855
- let FrFX = {};
856
- FrFX.enab = !!stroke.enabled;
857
- if (stroke.present !== undefined)
858
- FrFX.present = !!stroke.present;
859
- if (stroke.showInDialog !== undefined)
860
- FrFX.showInDialog = !!stroke.showInDialog;
861
- FrFX.Styl = exports.FStl.encode(stroke.position);
862
- FrFX.PntT = exports.FrFl.encode(stroke.fillType);
863
- FrFX['Md '] = exports.BlnM.encode(stroke.blendMode);
864
- FrFX.Opct = unitsPercent(stroke.opacity);
865
- FrFX['Sz '] = unitsValue(stroke.size, 'size');
866
- if (stroke.color)
867
- FrFX['Clr '] = serializeColor(stroke.color);
868
- if (stroke.gradient)
869
- FrFX = Object.assign(Object.assign({}, FrFX), serializeGradientContent(stroke.gradient));
870
- if (stroke.pattern)
871
- FrFX = Object.assign(Object.assign({}, FrFX), serializePatternContent(stroke.pattern));
872
- if (stroke.overprint !== undefined)
873
- FrFX.overprint = !!stroke.overprint;
874
- return FrFX;
875
- }
876
- function serializeEffects(e, log, multi) {
877
- var _a, _b, _c;
878
- const info = multi ? {
879
- 'Scl ': unitsPercentF((_a = e.scale) !== null && _a !== void 0 ? _a : 1),
880
- masterFXSwitch: !e.disabled,
881
- } : {
882
- masterFXSwitch: !e.disabled,
883
- 'Scl ': unitsPercentF((_b = e.scale) !== null && _b !== void 0 ? _b : 1),
884
- };
885
- const arrayKeys = ['dropShadow', 'innerShadow', 'solidFill', 'gradientOverlay', 'stroke'];
886
- for (const key of arrayKeys) {
887
- if (e[key] && !Array.isArray(e[key]))
888
- throw new Error(`${key} should be an array`);
889
- }
890
- const useMulti = (arr) => !!arr && arr.length > 1 && multi;
891
- const useSingle = (arr) => !!arr && arr.length >= 1 && (!multi || arr.length === 1);
892
- if (useSingle(e.dropShadow))
893
- info.DrSh = serializeEffectObject(e.dropShadow[0], 'dropShadow', log);
894
- if (useMulti(e.dropShadow))
895
- info.dropShadowMulti = e.dropShadow.map(i => serializeEffectObject(i, 'dropShadow', log));
896
- if (useSingle(e.innerShadow))
897
- info.IrSh = serializeEffectObject(e.innerShadow[0], 'innerShadow', log);
898
- if (useMulti(e.innerShadow))
899
- info.innerShadowMulti = e.innerShadow.map(i => serializeEffectObject(i, 'innerShadow', log));
900
- if (e.outerGlow)
901
- info.OrGl = serializeEffectObject(e.outerGlow, 'outerGlow', log);
902
- if (useMulti(e.solidFill))
903
- info.solidFillMulti = e.solidFill.map(i => serializeEffectObject(i, 'solidFill', log));
904
- if (useMulti(e.gradientOverlay))
905
- info.gradientFillMulti = e.gradientOverlay.map(i => serializeEffectObject(i, 'gradientOverlay', log));
906
- if (useMulti(e.stroke))
907
- info.frameFXMulti = e.stroke.map(i => serializeFxObject(i));
908
- if (e.innerGlow)
909
- info.IrGl = serializeEffectObject(e.innerGlow, 'innerGlow', log);
910
- if (e.bevel)
911
- info.ebbl = serializeEffectObject(e.bevel, 'bevel', log);
912
- if (useSingle(e.solidFill))
913
- info.SoFi = serializeEffectObject(e.solidFill[0], 'solidFill', log);
914
- if (e.patternOverlay)
915
- info.patternFill = serializeEffectObject(e.patternOverlay, 'patternOverlay', log);
916
- if (useSingle(e.gradientOverlay))
917
- info.GrFl = serializeEffectObject(e.gradientOverlay[0], 'gradientOverlay', log);
918
- if (e.satin)
919
- info.ChFX = serializeEffectObject(e.satin, 'satin', log);
920
- if (useSingle(e.stroke))
921
- info.FrFX = serializeFxObject((_c = e.stroke) === null || _c === void 0 ? void 0 : _c[0]);
922
- if (multi) {
923
- info.numModifyingFX = 0;
924
- for (const key of Object.keys(e)) {
925
- const value = e[key];
926
- if (Array.isArray(value)) {
927
- for (const effect of value) {
928
- if (effect.enabled)
929
- info.numModifyingFX++;
930
- }
931
- }
932
- else if (value.enabled) {
933
- info.numModifyingFX++;
934
- }
935
- }
936
- }
937
- return info;
938
- }
939
- exports.serializeEffects = serializeEffects;
940
- function parseEffects(info, log) {
941
- const effects = {};
942
- 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"]);
943
- if (!masterFXSwitch)
944
- effects.disabled = true;
945
- if (info['Scl '])
946
- effects.scale = parsePercent(info['Scl ']);
947
- if (DrSh)
948
- effects.dropShadow = [parseEffectObject(DrSh, log)];
949
- if (dropShadowMulti)
950
- effects.dropShadow = dropShadowMulti.map(i => parseEffectObject(i, log));
951
- if (IrSh)
952
- effects.innerShadow = [parseEffectObject(IrSh, log)];
953
- if (innerShadowMulti)
954
- effects.innerShadow = innerShadowMulti.map(i => parseEffectObject(i, log));
955
- if (OrGl)
956
- effects.outerGlow = parseEffectObject(OrGl, log);
957
- if (IrGl)
958
- effects.innerGlow = parseEffectObject(IrGl, log);
959
- if (ebbl)
960
- effects.bevel = parseEffectObject(ebbl, log);
961
- if (SoFi)
962
- effects.solidFill = [parseEffectObject(SoFi, log)];
963
- if (solidFillMulti)
964
- effects.solidFill = solidFillMulti.map(i => parseEffectObject(i, log));
965
- if (patternFill)
966
- effects.patternOverlay = parseEffectObject(patternFill, log);
967
- if (GrFl)
968
- effects.gradientOverlay = [parseEffectObject(GrFl, log)];
969
- if (gradientFillMulti)
970
- effects.gradientOverlay = gradientFillMulti.map(i => parseEffectObject(i, log));
971
- if (ChFX)
972
- effects.satin = parseEffectObject(ChFX, log);
973
- if (FrFX)
974
- effects.stroke = [parseFxObject(FrFX)];
975
- if (frameFXMulti)
976
- effects.stroke = frameFXMulti.map(i => parseFxObject(i));
977
- if (log && Object.keys(rest).length > 1)
978
- console.log('Unhandled effect keys:', rest);
979
- return effects;
980
- }
981
- exports.parseEffects = parseEffects;
982
- function parseKeyList(keyList, logMissingFeatures) {
983
- const keys = [];
984
- for (let j = 0; j < keyList.length; j++) {
985
- const key = keyList[j];
986
- const { time: { denominator, numerator }, selected, animKey } = key;
987
- const time = { numerator, denominator };
988
- const interpolation = exports.animInterpStyleEnum.decode(key.animInterpStyle);
989
- switch (animKey.Type) {
990
- case 'keyType.Opct':
991
- keys.push({ interpolation, time, selected, type: 'opacity', value: parsePercent(animKey.Opct) });
992
- break;
993
- case 'keyType.Pstn':
994
- keys.push({ interpolation, time, selected, type: 'position', x: animKey.Hrzn, y: animKey.Vrtc });
995
- break;
996
- case 'keyType.Trnf':
997
- keys.push({
998
- interpolation, time, selected, type: 'transform',
999
- scale: horzVrtcToXY(animKey['Scl ']), skew: horzVrtcToXY(animKey.Skew), rotation: animKey.rotation, translation: horzVrtcToXY(animKey.translation)
1000
- });
1001
- break;
1002
- case 'keyType.sheetStyle': {
1003
- const key = { interpolation, time, selected, type: 'style' };
1004
- if (animKey.sheetStyle.Lefx)
1005
- key.style = parseEffects(animKey.sheetStyle.Lefx, logMissingFeatures);
1006
- keys.push(key);
1007
- break;
1008
- }
1009
- case 'keyType.globalLighting': {
1010
- keys.push({
1011
- interpolation, time, selected, type: 'globalLighting',
1012
- globalAngle: animKey.gblA, globalAltitude: animKey.globalAltitude
1013
- });
1014
- break;
1015
- }
1016
- default: throw new Error(`Unsupported keyType value`);
1017
- }
1018
- }
1019
- return keys;
1020
- }
1021
- function serializeKeyList(keys) {
1022
- const keyList = [];
1023
- for (let j = 0; j < keys.length; j++) {
1024
- const key = keys[j];
1025
- const { time, selected = false, interpolation } = key;
1026
- const animInterpStyle = exports.animInterpStyleEnum.encode(interpolation);
1027
- let animKey;
1028
- switch (key.type) {
1029
- case 'opacity':
1030
- animKey = { Type: 'keyType.Opct', Opct: unitsPercent(key.value) };
1031
- break;
1032
- case 'position':
1033
- animKey = { Type: 'keyType.Pstn', Hrzn: key.x, Vrtc: key.y };
1034
- break;
1035
- case 'transform':
1036
- animKey = { Type: 'keyType.Trnf', 'Scl ': xyToHorzVrtc(key.scale), Skew: xyToHorzVrtc(key.skew), rotation: key.rotation, translation: xyToHorzVrtc(key.translation) };
1037
- break;
1038
- case 'style':
1039
- animKey = { Type: 'keyType.sheetStyle', sheetStyle: { Vrsn: 1, blendOptions: {} } };
1040
- if (key.style)
1041
- animKey.sheetStyle = { Vrsn: 1, Lefx: serializeEffects(key.style, false, false), blendOptions: {} };
1042
- break;
1043
- case 'globalLighting': {
1044
- animKey = { Type: 'keyType.globalLighting', gblA: key.globalAngle, globalAltitude: key.globalAltitude };
1045
- break;
1046
- }
1047
- default: throw new Error(`Unsupported keyType value`);
1048
- }
1049
- keyList.push({ Vrsn: 1, animInterpStyle, time, animKey, selected });
1050
- }
1051
- return keyList;
1052
- }
1053
- function parseTrackList(trackList, logMissingFeatures) {
1054
- const tracks = [];
1055
- for (let i = 0; i < trackList.length; i++) {
1056
- const tr = trackList[i];
1057
- const track = {
1058
- type: exports.stdTrackID.decode(tr.trackID),
1059
- enabled: tr.enab,
1060
- keys: parseKeyList(tr.keyList, logMissingFeatures),
1061
- };
1062
- if (tr.effectParams) {
1063
- track.effectParams = {
1064
- fillCanvas: tr.effectParams.fillCanvas,
1065
- zoomOrigin: tr.effectParams.zoomOrigin,
1066
- keys: parseKeyList(tr.effectParams.keyList, logMissingFeatures),
1067
- };
1068
- }
1069
- tracks.push(track);
1070
- }
1071
- return tracks;
1072
- }
1073
- exports.parseTrackList = parseTrackList;
1074
- function serializeTrackList(tracks) {
1075
- const trackList = [];
1076
- for (let i = 0; i < tracks.length; i++) {
1077
- const t = tracks[i];
1078
- trackList.push(Object.assign(Object.assign({ trackID: exports.stdTrackID.encode(t.type), Vrsn: 1, enab: !!t.enabled, Effc: !!t.effectParams }, (t.effectParams ? {
1079
- effectParams: {
1080
- keyList: serializeKeyList(t.keys),
1081
- fillCanvas: t.effectParams.fillCanvas,
1082
- zoomOrigin: t.effectParams.zoomOrigin,
1083
- }
1084
- } : {})), { keyList: serializeKeyList(t.keys) }));
1085
- }
1086
- return trackList;
1087
- }
1088
- exports.serializeTrackList = serializeTrackList;
1089
- function parseEffectObject(obj, reportErrors) {
1090
- const result = {};
1091
- for (const key of Object.keys(obj)) {
1092
- const val = obj[key];
1093
- switch (key) {
1094
- case 'enab':
1095
- result.enabled = !!val;
1096
- break;
1097
- case 'uglg':
1098
- result.useGlobalLight = !!val;
1099
- break;
1100
- case 'AntA':
1101
- result.antialiased = !!val;
1102
- break;
1103
- case 'Algn':
1104
- result.align = !!val;
1105
- break;
1106
- case 'Dthr':
1107
- result.dither = !!val;
1108
- break;
1109
- case 'Invr':
1110
- result.invert = !!val;
1111
- break;
1112
- case 'Rvrs':
1113
- result.reverse = !!val;
1114
- break;
1115
- case 'Clr ':
1116
- result.color = parseColor(val);
1117
- break;
1118
- case 'hglC':
1119
- result.highlightColor = parseColor(val);
1120
- break;
1121
- case 'sdwC':
1122
- result.shadowColor = parseColor(val);
1123
- break;
1124
- case 'Styl':
1125
- result.position = exports.FStl.decode(val);
1126
- break;
1127
- case 'Md ':
1128
- result.blendMode = exports.BlnM.decode(val);
1129
- break;
1130
- case 'hglM':
1131
- result.highlightBlendMode = exports.BlnM.decode(val);
1132
- break;
1133
- case 'sdwM':
1134
- result.shadowBlendMode = exports.BlnM.decode(val);
1135
- break;
1136
- case 'bvlS':
1137
- result.style = exports.BESl.decode(val);
1138
- break;
1139
- case 'bvlD':
1140
- result.direction = exports.BESs.decode(val);
1141
- break;
1142
- case 'bvlT':
1143
- result.technique = exports.bvlT.decode(val);
1144
- break;
1145
- case 'GlwT':
1146
- result.technique = exports.BETE.decode(val);
1147
- break;
1148
- case 'glwS':
1149
- result.source = exports.IGSr.decode(val);
1150
- break;
1151
- case 'Type':
1152
- result.type = exports.GrdT.decode(val);
1153
- break;
1154
- case 'gs99':
1155
- result.interpolationMethod = exports.gradientInterpolationMethodType.decode(val);
1156
- break;
1157
- case 'Opct':
1158
- result.opacity = parsePercent(val);
1159
- break;
1160
- case 'hglO':
1161
- result.highlightOpacity = parsePercent(val);
1162
- break;
1163
- case 'sdwO':
1164
- result.shadowOpacity = parsePercent(val);
1165
- break;
1166
- case 'lagl':
1167
- result.angle = parseAngle(val);
1168
- break;
1169
- case 'Angl':
1170
- result.angle = parseAngle(val);
1171
- break;
1172
- case 'Lald':
1173
- result.altitude = parseAngle(val);
1174
- break;
1175
- case 'Sftn':
1176
- result.soften = parseUnits(val);
1177
- break;
1178
- case 'srgR':
1179
- result.strength = parsePercent(val);
1180
- break;
1181
- case 'blur':
1182
- result.size = parseUnits(val);
1183
- break;
1184
- case 'Nose':
1185
- result.noise = parsePercent(val);
1186
- break;
1187
- case 'Inpr':
1188
- result.range = parsePercent(val);
1189
- break;
1190
- case 'Ckmt':
1191
- result.choke = parseUnits(val);
1192
- break;
1193
- case 'ShdN':
1194
- result.jitter = parsePercent(val);
1195
- break;
1196
- case 'Dstn':
1197
- result.distance = parseUnits(val);
1198
- break;
1199
- case 'Scl ':
1200
- result.scale = parsePercent(val);
1201
- break;
1202
- case 'Ptrn':
1203
- result.pattern = { name: val['Nm '], id: val.Idnt };
1204
- break;
1205
- case 'phase':
1206
- result.phase = { x: val.Hrzn, y: val.Vrtc };
1207
- break;
1208
- case 'Ofst':
1209
- result.offset = { x: parsePercent(val.Hrzn), y: parsePercent(val.Vrtc) };
1210
- break;
1211
- case 'MpgS':
1212
- case 'TrnS':
1213
- result.contour = {
1214
- name: val['Nm '],
1215
- curve: val['Crv '].map(p => ({ x: p.Hrzn, y: p.Vrtc })),
1216
- };
1217
- break;
1218
- case 'Grad':
1219
- result.gradient = parseGradient(val);
1220
- break;
1221
- case 'useTexture':
1222
- case 'useShape':
1223
- case 'layerConceals':
1224
- case 'present':
1225
- case 'showInDialog':
1226
- case 'antialiasGloss':
1227
- result[key] = val;
1228
- break;
1229
- case '_name':
1230
- case '_classID':
1231
- break;
1232
- default:
1233
- reportErrors && console.log(`Invalid effect key: '${key}', value:`, val);
1234
- }
1235
- }
1236
- return result;
1237
- }
1238
- function serializeEffectObject(obj, objName, reportErrors) {
1239
- const result = {
1240
- enab: false,
1241
- };
1242
- if (objName === 'dropShadow') {
1243
- result.TrnS = { 'Nm ': '', 'Crv ': [] };
1244
- }
1245
- for (const objKey of Object.keys(obj)) {
1246
- const key = objKey;
1247
- const val = obj[key];
1248
- switch (key) {
1249
- case 'enabled':
1250
- result.enab = !!val;
1251
- break;
1252
- case 'useGlobalLight':
1253
- result.uglg = !!val;
1254
- break;
1255
- case 'antialiased':
1256
- result.AntA = !!val;
1257
- break;
1258
- case 'align':
1259
- result.Algn = !!val;
1260
- break;
1261
- case 'dither':
1262
- result.Dthr = !!val;
1263
- break;
1264
- case 'invert':
1265
- result.Invr = !!val;
1266
- break;
1267
- case 'reverse':
1268
- result.Rvrs = !!val;
1269
- break;
1270
- case 'color':
1271
- result['Clr '] = serializeColor(val);
1272
- break;
1273
- case 'highlightColor':
1274
- result.hglC = serializeColor(val);
1275
- break;
1276
- case 'shadowColor':
1277
- result.sdwC = serializeColor(val);
1278
- break;
1279
- case 'position':
1280
- result.Styl = exports.FStl.encode(val);
1281
- break;
1282
- case 'blendMode':
1283
- result['Md '] = exports.BlnM.encode(val);
1284
- break;
1285
- case 'highlightBlendMode':
1286
- result.hglM = exports.BlnM.encode(val);
1287
- break;
1288
- case 'shadowBlendMode':
1289
- result.sdwM = exports.BlnM.encode(val);
1290
- break;
1291
- case 'style':
1292
- result.bvlS = exports.BESl.encode(val);
1293
- break;
1294
- case 'direction':
1295
- result.bvlD = exports.BESs.encode(val);
1296
- break;
1297
- case 'technique':
1298
- if (objName === 'bevel') {
1299
- result.bvlT = exports.bvlT.encode(val);
1300
- }
1301
- else {
1302
- result.GlwT = exports.BETE.encode(val);
1303
- }
1304
- break;
1305
- case 'source':
1306
- result.glwS = exports.IGSr.encode(val);
1307
- break;
1308
- case 'type':
1309
- result.Type = exports.GrdT.encode(val);
1310
- break;
1311
- case 'interpolationMethod':
1312
- result.gs99 = exports.gradientInterpolationMethodType.encode(val);
1313
- break;
1314
- case 'opacity':
1315
- result.Opct = unitsPercent(val);
1316
- break;
1317
- case 'highlightOpacity':
1318
- result.hglO = unitsPercent(val);
1319
- break;
1320
- case 'shadowOpacity':
1321
- result.sdwO = unitsPercent(val);
1322
- break;
1323
- case 'angle':
1324
- if (objName === 'gradientOverlay' || objName === 'patternFill') {
1325
- result.Angl = unitsAngle(val);
1326
- }
1327
- else {
1328
- result.lagl = unitsAngle(val);
1329
- }
1330
- break;
1331
- case 'altitude':
1332
- result.Lald = unitsAngle(val);
1333
- break;
1334
- case 'soften':
1335
- result.Sftn = unitsValue(val, key);
1336
- break;
1337
- case 'strength':
1338
- result.srgR = unitsPercent(val);
1339
- break;
1340
- case 'size':
1341
- result.blur = unitsValue(val, key);
1342
- break;
1343
- case 'noise':
1344
- result.Nose = unitsPercent(val);
1345
- break;
1346
- case 'range':
1347
- result.Inpr = unitsPercent(val);
1348
- break;
1349
- case 'choke':
1350
- result.Ckmt = unitsValue(val, key);
1351
- break;
1352
- case 'jitter':
1353
- result.ShdN = unitsPercent(val);
1354
- break;
1355
- case 'distance':
1356
- result.Dstn = unitsValue(val, key);
1357
- break;
1358
- case 'scale':
1359
- result['Scl '] = unitsPercent(val);
1360
- break;
1361
- case 'pattern':
1362
- result.Ptrn = { 'Nm ': val.name, Idnt: val.id };
1363
- break;
1364
- case 'phase':
1365
- result.phase = { Hrzn: val.x, Vrtc: val.y };
1366
- break;
1367
- case 'offset':
1368
- result.Ofst = { Hrzn: unitsPercent(val.x), Vrtc: unitsPercent(val.y) };
1369
- break;
1370
- case 'contour': {
1371
- result[objName === 'satin' ? 'MpgS' : 'TrnS'] = {
1372
- 'Nm ': val.name,
1373
- 'Crv ': val.curve.map(p => ({ Hrzn: p.x, Vrtc: p.y })),
1374
- };
1375
- break;
1376
- }
1377
- case 'gradient':
1378
- result.Grad = serializeGradient(val);
1379
- break;
1380
- case 'useTexture':
1381
- case 'useShape':
1382
- case 'layerConceals':
1383
- case 'present':
1384
- case 'showInDialog':
1385
- case 'antialiasGloss':
1386
- result[key] = val;
1387
- break;
1388
- default:
1389
- reportErrors && console.log(`Invalid effect key: '${key}', value:`, val);
1390
- }
1391
- }
1392
- return result;
1393
- }
1394
- function parseGradient(grad) {
1395
- if (grad.GrdF === 'GrdF.CstS') {
1396
- const samples = grad.Intr || 4096;
1397
- return {
1398
- type: 'solid',
1399
- name: grad['Nm '],
1400
- smoothness: grad.Intr / 4096,
1401
- colorStops: grad.Clrs.map(s => ({
1402
- color: parseColor(s['Clr ']),
1403
- location: s.Lctn / samples,
1404
- midpoint: s.Mdpn / 100,
1405
- })),
1406
- opacityStops: grad.Trns.map(s => ({
1407
- opacity: parsePercent(s.Opct),
1408
- location: s.Lctn / samples,
1409
- midpoint: s.Mdpn / 100,
1410
- })),
1411
- };
1412
- }
1413
- else {
1414
- return {
1415
- type: 'noise',
1416
- name: grad['Nm '],
1417
- roughness: grad.Smth / 4096,
1418
- colorModel: exports.ClrS.decode(grad.ClrS),
1419
- randomSeed: grad.RndS,
1420
- restrictColors: !!grad.VctC,
1421
- addTransparency: !!grad.ShTr,
1422
- min: grad['Mnm '].map(x => x / 100),
1423
- max: grad['Mxm '].map(x => x / 100),
1424
- };
1425
- }
1426
- }
1427
- function serializeGradient(grad) {
1428
- var _a, _b;
1429
- if (grad.type === 'solid') {
1430
- const samples = Math.round(((_a = grad.smoothness) !== null && _a !== void 0 ? _a : 1) * 4096);
1431
- return {
1432
- 'Nm ': grad.name || '',
1433
- GrdF: 'GrdF.CstS',
1434
- Intr: samples,
1435
- Clrs: grad.colorStops.map(s => {
1436
- var _a;
1437
- return ({
1438
- 'Clr ': serializeColor(s.color),
1439
- Type: 'Clry.UsrS',
1440
- Lctn: Math.round(s.location * samples),
1441
- Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
1442
- });
1443
- }),
1444
- Trns: grad.opacityStops.map(s => {
1445
- var _a;
1446
- return ({
1447
- Opct: unitsPercent(s.opacity),
1448
- Lctn: Math.round(s.location * samples),
1449
- Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
1450
- });
1451
- }),
1452
- };
1453
- }
1454
- else {
1455
- return {
1456
- GrdF: 'GrdF.ClNs',
1457
- 'Nm ': grad.name || '',
1458
- ShTr: !!grad.addTransparency,
1459
- VctC: !!grad.restrictColors,
1460
- ClrS: exports.ClrS.encode(grad.colorModel),
1461
- RndS: grad.randomSeed || 0,
1462
- Smth: Math.round(((_b = grad.roughness) !== null && _b !== void 0 ? _b : 1) * 4096),
1463
- 'Mnm ': (grad.min || [0, 0, 0, 0]).map(x => x * 100),
1464
- 'Mxm ': (grad.max || [1, 1, 1, 1]).map(x => x * 100),
1465
- };
1466
- }
1467
- }
1468
- function parseGradientContent(descriptor) {
1469
- const result = parseGradient(descriptor.Grad);
1470
- result.style = exports.GrdT.decode(descriptor.Type);
1471
- if (descriptor.Dthr !== undefined)
1472
- result.dither = descriptor.Dthr;
1473
- if (descriptor.gradientsInterpolationMethod !== undefined)
1474
- result.interpolationMethod = exports.gradientInterpolationMethodType.decode(descriptor.gradientsInterpolationMethod);
1475
- if (descriptor.Rvrs !== undefined)
1476
- result.reverse = descriptor.Rvrs;
1477
- if (descriptor.Angl !== undefined)
1478
- result.angle = parseAngle(descriptor.Angl);
1479
- if (descriptor['Scl '] !== undefined)
1480
- result.scale = parsePercent(descriptor['Scl ']);
1481
- if (descriptor.Algn !== undefined)
1482
- result.align = descriptor.Algn;
1483
- if (descriptor.Ofst !== undefined) {
1484
- result.offset = {
1485
- x: parsePercent(descriptor.Ofst.Hrzn),
1486
- y: parsePercent(descriptor.Ofst.Vrtc)
1487
- };
1488
- }
1489
- return result;
1490
- }
1491
- function parsePatternContent(descriptor) {
1492
- const result = {
1493
- name: descriptor.Ptrn['Nm '],
1494
- id: descriptor.Ptrn.Idnt,
1495
- };
1496
- if (descriptor.Lnkd !== undefined)
1497
- result.linked = descriptor.Lnkd;
1498
- if (descriptor.phase !== undefined)
1499
- result.phase = { x: descriptor.phase.Hrzn, y: descriptor.phase.Vrtc };
1500
- return result;
1501
- }
1502
- function parseVectorContent(descriptor) {
1503
- if ('Grad' in descriptor) {
1504
- return parseGradientContent(descriptor);
1505
- }
1506
- else if ('Ptrn' in descriptor) {
1507
- return Object.assign({ type: 'pattern' }, parsePatternContent(descriptor));
1508
- }
1509
- else if ('Clr ' in descriptor) {
1510
- return { type: 'color', color: parseColor(descriptor['Clr ']) };
1511
- }
1512
- else {
1513
- throw new Error('Invalid vector content');
1514
- }
1515
- }
1516
- exports.parseVectorContent = parseVectorContent;
1517
- function serializeGradientContent(content) {
1518
- const result = {};
1519
- if (content.dither !== undefined)
1520
- result.Dthr = content.dither;
1521
- if (content.interpolationMethod !== undefined)
1522
- result.gradientsInterpolationMethod = exports.gradientInterpolationMethodType.encode(content.interpolationMethod);
1523
- if (content.reverse !== undefined)
1524
- result.Rvrs = content.reverse;
1525
- if (content.angle !== undefined)
1526
- result.Angl = unitsAngle(content.angle);
1527
- result.Type = exports.GrdT.encode(content.style);
1528
- if (content.align !== undefined)
1529
- result.Algn = content.align;
1530
- if (content.scale !== undefined)
1531
- result['Scl '] = unitsPercent(content.scale);
1532
- if (content.offset) {
1533
- result.Ofst = {
1534
- Hrzn: unitsPercent(content.offset.x),
1535
- Vrtc: unitsPercent(content.offset.y),
1536
- };
1537
- }
1538
- result.Grad = serializeGradient(content);
1539
- return result;
1540
- }
1541
- function serializePatternContent(content) {
1542
- const result = {
1543
- Ptrn: {
1544
- 'Nm ': content.name || '',
1545
- Idnt: content.id || '',
1546
- }
1547
- };
1548
- if (content.linked !== undefined)
1549
- result.Lnkd = !!content.linked;
1550
- if (content.phase !== undefined)
1551
- result.phase = { Hrzn: content.phase.x, Vrtc: content.phase.y };
1552
- return result;
1553
- }
1554
- function serializeVectorContent(content) {
1555
- if (content.type === 'color') {
1556
- return { key: 'SoCo', descriptor: { 'Clr ': serializeColor(content.color) } };
1557
- }
1558
- else if (content.type === 'pattern') {
1559
- return { key: 'PtFl', descriptor: serializePatternContent(content) };
1560
- }
1561
- else {
1562
- return { key: 'GdFl', descriptor: serializeGradientContent(content) };
1563
- }
1564
- }
1565
- exports.serializeVectorContent = serializeVectorContent;
1566
- function parseColor(color) {
1567
- if ('H ' in color) {
1568
- return { h: parsePercentOrAngle(color['H ']), s: color.Strt, b: color.Brgh };
1569
- }
1570
- else if ('Rd ' in color) {
1571
- return { r: color['Rd '], g: color['Grn '], b: color['Bl '] };
1572
- }
1573
- else if ('Cyn ' in color) {
1574
- return { c: color['Cyn '], m: color.Mgnt, y: color['Ylw '], k: color.Blck };
1575
- }
1576
- else if ('Gry ' in color) {
1577
- return { k: color['Gry '] };
1578
- }
1579
- else if ('Lmnc' in color) {
1580
- return { l: color.Lmnc, a: color['A '], b: color['B '] };
1581
- }
1582
- else if ('redFloat' in color) {
1583
- return { fr: color.redFloat, fg: color.greenFloat, fb: color.blueFloat };
1584
- }
1585
- else {
1586
- throw new Error('Unsupported color descriptor');
1587
- }
1588
- }
1589
- exports.parseColor = parseColor;
1590
- function serializeColor(color) {
1591
- if (!color) {
1592
- return { _name: '', _classID: 'RGBC', 'Rd ': 0, 'Grn ': 0, 'Bl ': 0 };
1593
- }
1594
- else if ('r' in color) {
1595
- return { _name: '', _classID: 'RGBC', 'Rd ': color.r || 0, 'Grn ': color.g || 0, 'Bl ': color.b || 0 };
1596
- }
1597
- else if ('fr' in color) {
1598
- return { _name: '', _classID: 'RGBC', redFloat: color.fr, greenFloat: color.fg, blueFloat: color.fb };
1599
- }
1600
- else if ('h' in color) {
1601
- return { _name: '', _classID: 'HSBC', 'H ': unitsAngle(color.h * 360), Strt: color.s || 0, Brgh: color.b || 0 };
1602
- }
1603
- else if ('c' in color) {
1604
- return { _name: '', _classID: 'CMYC', 'Cyn ': color.c || 0, Mgnt: color.m || 0, 'Ylw ': color.y || 0, Blck: color.k || 0 };
1605
- }
1606
- else if ('l' in color) {
1607
- return { _name: '', _classID: 'LABC', Lmnc: color.l || 0, 'A ': color.a || 0, 'B ': color.b || 0 };
1608
- }
1609
- else if ('k' in color) {
1610
- return { _name: '', _classID: 'GRYC', 'Gry ': color.k };
1611
- }
1612
- else {
1613
- throw new Error('Invalid color value');
1614
- }
1615
- }
1616
- exports.serializeColor = serializeColor;
1617
- function parseAngle(x) {
1618
- if (x === undefined)
1619
- return 0;
1620
- if (x.units !== 'Angle')
1621
- throw new Error(`Invalid units: ${x.units}`);
1622
- return x.value;
1623
- }
1624
- exports.parseAngle = parseAngle;
1625
- function parsePercent(x) {
1626
- if (x === undefined)
1627
- return 1;
1628
- if (x.units !== 'Percent')
1629
- throw new Error(`Invalid units: ${x.units}`);
1630
- return x.value / 100;
1631
- }
1632
- exports.parsePercent = parsePercent;
1633
- function parsePercentOrAngle(x) {
1634
- if (x === undefined)
1635
- return 1;
1636
- if (x.units === 'Percent')
1637
- return x.value / 100;
1638
- if (x.units === 'Angle')
1639
- return x.value / 360;
1640
- throw new Error(`Invalid units: ${x.units}`);
1641
- }
1642
- exports.parsePercentOrAngle = parsePercentOrAngle;
1643
- function parseUnits({ units, value }) {
1644
- if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
1645
- units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
1646
- throw new Error(`Invalid units: ${JSON.stringify({ units, value })}`);
1647
- }
1648
- return { value, units };
1649
- }
1650
- exports.parseUnits = parseUnits;
1651
- function parseUnitsOrNumber(value, units = 'Pixels') {
1652
- if (typeof value === 'number')
1653
- return { value, units };
1654
- return parseUnits(value);
1655
- }
1656
- exports.parseUnitsOrNumber = parseUnitsOrNumber;
1657
- function parseUnitsToNumber({ units, value }, expectedUnits) {
1658
- if (units !== expectedUnits)
1659
- throw new Error(`Invalid units: ${JSON.stringify({ units, value })}`);
1660
- return value;
1661
- }
1662
- exports.parseUnitsToNumber = parseUnitsToNumber;
1663
- function unitsAngle(value) {
1664
- return { units: 'Angle', value: value || 0 };
1665
- }
1666
- exports.unitsAngle = unitsAngle;
1667
- function unitsPercent(value) {
1668
- return { units: 'Percent', value: Math.round((value || 0) * 100) };
1669
- }
1670
- exports.unitsPercent = unitsPercent;
1671
- function unitsPercentF(value) {
1672
- return { units: 'Percent', value: (value || 0) * 100 };
1673
- }
1674
- exports.unitsPercentF = unitsPercentF;
1675
- function unitsValue(x, key) {
1676
- if (x == null)
1677
- return { units: 'Pixels', value: 0 };
1678
- if (typeof x !== 'object')
1679
- throw new Error(`Invalid value: ${JSON.stringify(x)} (key: ${key}) (should have value and units)`);
1680
- const { units, value } = x;
1681
- if (typeof value !== 'number')
1682
- throw new Error(`Invalid value in ${JSON.stringify(x)} (key: ${key})`);
1683
- if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
1684
- units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
1685
- throw new Error(`Invalid units in ${JSON.stringify(x)} (key: ${key})`);
1686
- }
1687
- return { units, value };
1688
- }
1689
- exports.unitsValue = unitsValue;
1690
- function frac({ numerator, denominator }) {
1691
- return { numerator, denominator };
1692
- }
1693
- exports.frac = frac;
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
- });
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
+ });
2004
2004
  //# sourceMappingURL=descriptor.js.map