ag-psd 30.2.0 → 31.0.1

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