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
package/dist/text.js CHANGED
@@ -1,554 +1,553 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeEngineData = exports.decodeEngineData = void 0;
4
- const defaultFont = {
5
- name: 'MyriadPro-Regular',
6
- script: 0,
7
- type: 0,
8
- synthetic: 0,
9
- };
10
- const defaultParagraphStyle = {
11
- justification: 'left',
12
- firstLineIndent: 0,
13
- startIndent: 0,
14
- endIndent: 0,
15
- spaceBefore: 0,
16
- spaceAfter: 0,
17
- autoHyphenate: true,
18
- hyphenatedWordSize: 6,
19
- preHyphen: 2,
20
- postHyphen: 2,
21
- consecutiveHyphens: 8,
22
- zone: 36,
23
- wordSpacing: [0.8, 1, 1.33],
24
- letterSpacing: [0, 0, 0],
25
- glyphSpacing: [1, 1, 1],
26
- autoLeading: 1.2,
27
- leadingType: 0,
28
- hanging: false,
29
- burasagari: false,
30
- kinsokuOrder: 0,
31
- everyLineComposer: false,
32
- };
33
- const defaultStyle = {
34
- font: defaultFont,
35
- fontSize: 12,
36
- fauxBold: false,
37
- fauxItalic: false,
38
- autoLeading: true,
39
- leading: 0,
40
- horizontalScale: 1,
41
- verticalScale: 1,
42
- tracking: 0,
43
- autoKerning: true,
44
- kerning: 0,
45
- baselineShift: 0,
46
- fontCaps: 0,
47
- fontBaseline: 0,
48
- underline: false,
49
- strikethrough: false,
50
- ligatures: true,
51
- dLigatures: false,
52
- baselineDirection: 2,
53
- tsume: 0,
54
- styleRunAlignment: 2,
55
- language: 0,
56
- noBreak: false,
57
- fillColor: { r: 0, g: 0, b: 0 },
58
- strokeColor: { r: 0, g: 0, b: 0 },
59
- fillFlag: true,
60
- strokeFlag: false,
61
- fillFirst: true,
62
- yUnderline: 1,
63
- outlineWidth: 1,
64
- characterDirection: 0,
65
- hindiNumbers: false,
66
- kashida: 1,
67
- diacriticPos: 2,
68
- };
69
- const defaultGridInfo = {
70
- isOn: false,
71
- show: false,
72
- size: 18,
73
- leading: 22,
74
- color: { r: 0, g: 0, b: 255 },
75
- leadingFillColor: { r: 0, g: 0, b: 255 },
76
- alignLineHeightToGridFlags: false,
77
- };
78
- const paragraphStyleKeys = [
79
- 'justification', 'firstLineIndent', 'startIndent', 'endIndent', 'spaceBefore', 'spaceAfter',
80
- 'autoHyphenate', 'hyphenatedWordSize', 'preHyphen', 'postHyphen', 'consecutiveHyphens',
81
- 'zone', 'wordSpacing', 'letterSpacing', 'glyphSpacing', 'autoLeading', 'leadingType',
82
- 'hanging', 'burasagari', 'kinsokuOrder', 'everyLineComposer',
83
- ];
84
- const styleKeys = [
85
- 'font', 'fontSize', 'fauxBold', 'fauxItalic', 'autoLeading', 'leading', 'horizontalScale',
86
- 'verticalScale', 'tracking', 'autoKerning', 'kerning', 'baselineShift', 'fontCaps', 'fontBaseline',
87
- 'underline', 'strikethrough', 'ligatures', 'dLigatures', 'baselineDirection', 'tsume',
88
- 'styleRunAlignment', 'language', 'noBreak', 'fillColor', 'strokeColor', 'fillFlag',
89
- 'strokeFlag', 'fillFirst', 'yUnderline', 'outlineWidth', 'characterDirection', 'hindiNumbers',
90
- 'kashida', 'diacriticPos',
91
- ];
92
- const antialias = ['none', 'crisp', 'strong', 'smooth', 'sharp'];
93
- const justification = [
94
- 'left',
95
- 'right',
96
- 'center',
97
- 'justify-left',
98
- 'justify-right',
99
- 'justify-center',
100
- 'justify-all', // 6
101
- ];
102
- function upperFirst(value) {
103
- return value.substring(0, 1).toUpperCase() + value.substring(1);
104
- }
105
- function decodeColor(color) {
106
- const c = color.Values;
107
- switch (color.Type) {
108
- case 0: return { k: c[1] * 255 }; // grayscale (alpha?)
109
- case 1: return c[0] === 1 ?
110
- { r: c[1] * 255, g: c[2] * 255, b: c[3] * 255 } : // rgb
111
- { r: c[1] * 255, g: c[2] * 255, b: c[3] * 255, a: c[0] * 255 }; // rgba
112
- case 2: return { c: c[1] * 255, m: c[2] * 255, y: c[3] * 255, k: c[4] * 255 }; // cmyk (alpha?)
113
- default: throw new Error('Unknown color type in text layer');
114
- }
115
- }
116
- function encodeColor(color) {
117
- if (!color) {
118
- return { Type: 1, Values: [0, 0, 0, 0] };
119
- }
120
- else if ('r' in color) {
121
- return { Type: 1, Values: ['a' in color ? color.a / 255 : 1, color.r / 255, color.g / 255, color.b / 255] };
122
- }
123
- else if ('c' in color) {
124
- return { Type: 2, Values: [1, color.c / 255, color.m / 255, color.y / 255, color.k / 255] };
125
- }
126
- else if ('k' in color) {
127
- return { Type: 0, Values: [1, color.k / 255] };
128
- }
129
- else {
130
- throw new Error('Invalid color type in text layer');
131
- }
132
- }
133
- function arraysEqual(a, b) {
134
- if (!a || !b)
135
- return false;
136
- if (a.length !== b.length)
137
- return false;
138
- for (let i = 0; i < a.length; i++)
139
- if (a[i] !== b[i])
140
- return false;
141
- return true;
142
- }
143
- function objectsEqual(a, b) {
144
- if (!a || !b)
145
- return false;
146
- for (const key of Object.keys(a))
147
- if (a[key] !== b[key])
148
- return false;
149
- for (const key of Object.keys(b))
150
- if (a[key] !== b[key])
151
- return false;
152
- return true;
153
- }
154
- function findOrAddFont(fonts, font) {
155
- for (let i = 0; i < fonts.length; i++) {
156
- if (fonts[i].name === font.name)
157
- return i;
158
- }
159
- fonts.push(font);
160
- return fonts.length - 1;
161
- }
162
- function decodeObject(obj, keys, fonts) {
163
- const result = {};
164
- for (const key of keys) {
165
- const Key = upperFirst(key);
166
- if (obj[Key] === undefined)
167
- continue;
168
- if (key === 'justification') {
169
- result[key] = justification[obj[Key]];
170
- }
171
- else if (key === 'font') {
172
- result[key] = fonts[obj[Key]];
173
- }
174
- else if (key === 'fillColor' || key === 'strokeColor') {
175
- result[key] = decodeColor(obj[Key]);
176
- }
177
- else {
178
- result[key] = obj[Key];
179
- }
180
- }
181
- return result;
182
- }
183
- function encodeObject(obj, keys, fonts) {
184
- var _a;
185
- const result = {};
186
- for (const key of keys) {
187
- const Key = upperFirst(key);
188
- if (obj[key] === undefined)
189
- continue;
190
- if (key === 'justification') {
191
- result[Key] = justification.indexOf((_a = obj[key]) !== null && _a !== void 0 ? _a : 'left');
192
- }
193
- else if (key === 'font') {
194
- result[Key] = findOrAddFont(fonts, obj[key]);
195
- }
196
- else if (key === 'fillColor' || key === 'strokeColor') {
197
- result[Key] = encodeColor(obj[key]);
198
- }
199
- else {
200
- result[Key] = obj[key];
201
- }
202
- }
203
- return result;
204
- }
205
- function decodeParagraphStyle(obj, fonts) {
206
- return decodeObject(obj, paragraphStyleKeys, fonts);
207
- }
208
- function decodeStyle(obj, fonts) {
209
- return decodeObject(obj, styleKeys, fonts);
210
- }
211
- function encodeParagraphStyle(obj, fonts) {
212
- return encodeObject(obj, paragraphStyleKeys, fonts);
213
- }
214
- function encodeStyle(obj, fonts) {
215
- return encodeObject(obj, styleKeys, fonts);
216
- }
217
- function deduplicateValues(base, runs, keys) {
218
- if (!runs.length)
219
- return;
220
- for (const key of keys) {
221
- const value = runs[0].style[key];
222
- if (value !== undefined) {
223
- let identical = false;
224
- if (Array.isArray(value)) {
225
- identical = runs.every(r => arraysEqual(r.style[key], value));
226
- }
227
- else if (typeof value === 'object') {
228
- identical = runs.every(r => objectsEqual(r.style[key], value));
229
- }
230
- else {
231
- identical = runs.every(r => r.style[key] === value);
232
- }
233
- if (identical) {
234
- base[key] = value;
235
- }
236
- }
237
- const styleValue = base[key];
238
- if (styleValue !== undefined) {
239
- for (const r of runs) {
240
- let same = false;
241
- if (Array.isArray(value)) {
242
- same = arraysEqual(r.style[key], value);
243
- }
244
- else if (typeof value === 'object') {
245
- same = objectsEqual(r.style[key], value);
246
- }
247
- else {
248
- same = r.style[key] === value;
249
- }
250
- if (same)
251
- delete r.style[key];
252
- }
253
- }
254
- }
255
- if (runs.every(x => Object.keys(x.style).length === 0)) {
256
- runs.length = 0;
257
- }
258
- }
259
- function decodeEngineData(engineData) {
260
- var _a, _b, _c, _d, _e, _f;
261
- // console.log('engineData', require('util').inspect(engineData, false, 99, true));
262
- const engineDict = engineData.EngineDict;
263
- const resourceDict = engineData.ResourceDict;
264
- const fonts = resourceDict.FontSet.map(f => ({
265
- name: f.Name,
266
- script: f.Script,
267
- type: f.FontType,
268
- synthetic: f.Synthetic,
269
- }));
270
- let text = engineDict.Editor.Text.replace(/\r/g, '\n');
271
- let removedCharacters = 0;
272
- while (/\n$/.test(text)) {
273
- text = text.substring(0, text.length - 1);
274
- removedCharacters++;
275
- }
276
- const result = {
277
- text,
278
- antiAlias: (_a = antialias[engineDict.AntiAlias]) !== null && _a !== void 0 ? _a : 'smooth',
279
- useFractionalGlyphWidths: !!engineDict.UseFractionalGlyphWidths,
280
- superscriptSize: resourceDict.SuperscriptSize,
281
- superscriptPosition: resourceDict.SuperscriptPosition,
282
- subscriptSize: resourceDict.SubscriptSize,
283
- subscriptPosition: resourceDict.SubscriptPosition,
284
- smallCapSize: resourceDict.SmallCapSize,
285
- };
286
- // shape
287
- const photoshop = (_f = (_e = (_d = (_c = (_b = engineDict.Rendered) === null || _b === void 0 ? void 0 : _b.Shapes) === null || _c === void 0 ? void 0 : _c.Children) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.Cookie) === null || _f === void 0 ? void 0 : _f.Photoshop;
288
- if (photoshop) {
289
- result.shapeType = photoshop.ShapeType === 1 ? 'box' : 'point';
290
- if (photoshop.PointBase)
291
- result.pointBase = photoshop.PointBase;
292
- if (photoshop.BoxBounds)
293
- result.boxBounds = photoshop.BoxBounds;
294
- }
295
- // paragraph style
296
- // const theNormalParagraphSheet = resourceDict.TheNormalParagraphSheet;
297
- // const paragraphSheetSet = resourceDict.ParagraphSheetSet;
298
- // const paragraphProperties = paragraphSheetSet[theNormalParagraphSheet].Properties;
299
- const paragraphRun = engineDict.ParagraphRun;
300
- result.paragraphStyle = {}; // decodeParagraphStyle(paragraphProperties, fonts);
301
- result.paragraphStyleRuns = [];
302
- for (let i = 0; i < paragraphRun.RunArray.length; i++) {
303
- const run = paragraphRun.RunArray[i];
304
- const length = paragraphRun.RunLengthArray[i];
305
- const style = decodeParagraphStyle(run.ParagraphSheet.Properties, fonts);
306
- // const adjustments = {
307
- // axis: run.Adjustments.Axis,
308
- // xy: run.Adjustments.XY,
309
- // };
310
- result.paragraphStyleRuns.push({ length, style /*, adjustments*/ });
311
- }
312
- for (let counter = removedCharacters; result.paragraphStyleRuns.length && counter > 0; counter--) {
313
- if (--result.paragraphStyleRuns[result.paragraphStyleRuns.length - 1].length === 0) {
314
- result.paragraphStyleRuns.pop();
315
- }
316
- }
317
- deduplicateValues(result.paragraphStyle, result.paragraphStyleRuns, paragraphStyleKeys);
318
- if (!result.paragraphStyleRuns.length)
319
- delete result.paragraphStyleRuns;
320
- // style
321
- // const theNormalStyleSheet = resourceDict.TheNormalStyleSheet;
322
- // const styleSheetSet = resourceDict.StyleSheetSet;
323
- // const styleSheetData = styleSheetSet[theNormalStyleSheet].StyleSheetData;
324
- const styleRun = engineDict.StyleRun;
325
- result.style = {}; // decodeStyle(styleSheetData, fonts);
326
- result.styleRuns = [];
327
- for (let i = 0; i < styleRun.RunArray.length; i++) {
328
- const length = styleRun.RunLengthArray[i];
329
- const style = decodeStyle(styleRun.RunArray[i].StyleSheet.StyleSheetData, fonts);
330
- if (!style.font)
331
- style.font = fonts[0];
332
- result.styleRuns.push({ length, style });
333
- }
334
- for (let counter = removedCharacters; result.styleRuns.length && counter > 0; counter--) {
335
- if (--result.styleRuns[result.styleRuns.length - 1].length === 0) {
336
- result.styleRuns.pop();
337
- }
338
- }
339
- deduplicateValues(result.style, result.styleRuns, styleKeys);
340
- if (!result.styleRuns.length)
341
- delete result.styleRuns;
342
- return result;
343
- }
344
- exports.decodeEngineData = decodeEngineData;
345
- function encodeEngineData(data) {
346
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
347
- const text = `${(data.text || '').replace(/\r?\n/g, '\r')}\r`;
348
- const fonts = [
349
- { name: 'AdobeInvisFont', script: 0, type: 0, synthetic: 0 },
350
- ];
351
- const defFont = ((_a = data.style) === null || _a === void 0 ? void 0 : _a.font) || ((_c = (_b = data.styleRuns) === null || _b === void 0 ? void 0 : _b.find(s => s.style.font)) === null || _c === void 0 ? void 0 : _c.style.font) || defaultFont;
352
- const paragraphRunArray = [];
353
- const paragraphRunLengthArray = [];
354
- const paragraphRuns = data.paragraphStyleRuns;
355
- if (paragraphRuns && paragraphRuns.length) {
356
- let leftLength = text.length;
357
- for (const run of paragraphRuns) {
358
- let runLength = Math.min(run.length, leftLength);
359
- leftLength -= runLength;
360
- if (!runLength)
361
- continue; // ignore 0 size runs
362
- // extend last run if it's only for trailing \r
363
- if (leftLength === 1 && run === paragraphRuns[paragraphRuns.length - 1]) {
364
- runLength++;
365
- leftLength--;
366
- }
367
- paragraphRunLengthArray.push(runLength);
368
- paragraphRunArray.push({
369
- ParagraphSheet: {
370
- DefaultStyleSheet: 0,
371
- Properties: encodeParagraphStyle(Object.assign(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), run.style), fonts),
372
- },
373
- Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
374
- });
375
- }
376
- if (leftLength) {
377
- paragraphRunLengthArray.push(leftLength);
378
- paragraphRunArray.push({
379
- ParagraphSheet: {
380
- DefaultStyleSheet: 0,
381
- Properties: encodeParagraphStyle(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), fonts),
382
- },
383
- Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
384
- });
385
- }
386
- }
387
- else {
388
- for (let i = 0, last = 0; i < text.length; i++) {
389
- if (text.charCodeAt(i) === 13) { // \r
390
- paragraphRunLengthArray.push(i - last + 1);
391
- paragraphRunArray.push({
392
- ParagraphSheet: {
393
- DefaultStyleSheet: 0,
394
- Properties: encodeParagraphStyle(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), fonts),
395
- },
396
- Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
397
- });
398
- last = i + 1;
399
- }
400
- }
401
- }
402
- const styleSheetData = encodeStyle(Object.assign(Object.assign({}, defaultStyle), { font: defFont }), fonts);
403
- const styleRuns = data.styleRuns || [{ length: text.length, style: data.style || {} }];
404
- const styleRunArray = [];
405
- const styleRunLengthArray = [];
406
- let leftLength = text.length;
407
- for (const run of styleRuns) {
408
- let runLength = Math.min(run.length, leftLength);
409
- leftLength -= runLength;
410
- if (!runLength)
411
- continue; // ignore 0 size runs
412
- // extend last run if it's only for trailing \r
413
- if (leftLength === 1 && run === styleRuns[styleRuns.length - 1]) {
414
- runLength++;
415
- leftLength--;
416
- }
417
- styleRunLengthArray.push(runLength);
418
- styleRunArray.push({
419
- StyleSheet: {
420
- StyleSheetData: encodeStyle(Object.assign(Object.assign({ kerning: 0, autoKerning: true, fillColor: { r: 0, g: 0, b: 0 } }, data.style), run.style), fonts),
421
- },
422
- });
423
- }
424
- // add extra run to the end if existing ones didn't fill it up
425
- if (leftLength && styleRuns.length) {
426
- styleRunLengthArray.push(leftLength);
427
- styleRunArray.push({
428
- StyleSheet: {
429
- StyleSheetData: encodeStyle(Object.assign({ kerning: 0, autoKerning: true, fillColor: { r: 0, g: 0, b: 0 } }, data.style), fonts),
430
- },
431
- });
432
- }
433
- const gridInfo = Object.assign(Object.assign({}, defaultGridInfo), data.gridInfo);
434
- const WritingDirection = data.orientation === 'vertical' ? 2 : 0;
435
- const Procession = data.orientation === 'vertical' ? 1 : 0;
436
- const ShapeType = data.shapeType === 'box' ? 1 : 0;
437
- const Photoshop = {
438
- ShapeType,
439
- };
440
- if (ShapeType === 0) {
441
- Photoshop.PointBase = data.pointBase || [0, 0];
442
- }
443
- else {
444
- Photoshop.BoxBounds = data.boxBounds || [0, 0, 0, 0];
445
- }
446
- // needed for correct order of properties
447
- Photoshop.Base = {
448
- ShapeType,
449
- TransformPoint0: [1, 0],
450
- TransformPoint1: [0, 1],
451
- TransformPoint2: [0, 0],
452
- };
453
- const defaultResources = {
454
- KinsokuSet: [
455
- {
456
- Name: 'PhotoshopKinsokuHard',
457
- NoStart: '、。,.・:;?!ー―’”)〕]}〉》」』】ヽヾゝゞ々ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮヵヶ゛゜?!)]},.:;℃℉¢%‰',
458
- NoEnd: '‘“(〔[{〈《「『【([{¥$£@§〒#',
459
- Keep: '―‥',
460
- Hanging: '、。.,',
461
- },
462
- {
463
- Name: 'PhotoshopKinsokuSoft',
464
- NoStart: '、。,.・:;?!’”)〕]}〉》」』】ヽヾゝゞ々',
465
- NoEnd: '‘“(〔[{〈《「『【',
466
- Keep: '―‥',
467
- Hanging: '、。.,',
468
- },
469
- ],
470
- MojiKumiSet: [
471
- { InternalName: 'Photoshop6MojiKumiSet1' },
472
- { InternalName: 'Photoshop6MojiKumiSet2' },
473
- { InternalName: 'Photoshop6MojiKumiSet3' },
474
- { InternalName: 'Photoshop6MojiKumiSet4' },
475
- ],
476
- TheNormalStyleSheet: 0,
477
- TheNormalParagraphSheet: 0,
478
- ParagraphSheetSet: [
479
- {
480
- Name: 'Normal RGB',
481
- DefaultStyleSheet: 0,
482
- Properties: encodeParagraphStyle(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), fonts),
483
- },
484
- ],
485
- StyleSheetSet: [
486
- {
487
- Name: 'Normal RGB',
488
- StyleSheetData: styleSheetData,
489
- },
490
- ],
491
- FontSet: fonts.map(f => ({
492
- Name: f.name,
493
- Script: f.script || 0,
494
- FontType: f.type || 0,
495
- Synthetic: f.synthetic || 0,
496
- })),
497
- SuperscriptSize: (_d = data.superscriptSize) !== null && _d !== void 0 ? _d : 0.583,
498
- SuperscriptPosition: (_e = data.superscriptPosition) !== null && _e !== void 0 ? _e : 0.333,
499
- SubscriptSize: (_f = data.subscriptSize) !== null && _f !== void 0 ? _f : 0.583,
500
- SubscriptPosition: (_g = data.subscriptPosition) !== null && _g !== void 0 ? _g : 0.333,
501
- SmallCapSize: (_h = data.smallCapSize) !== null && _h !== void 0 ? _h : 0.7,
502
- };
503
- const engineData = {
504
- EngineDict: {
505
- Editor: { Text: text },
506
- ParagraphRun: {
507
- DefaultRunData: {
508
- ParagraphSheet: { DefaultStyleSheet: 0, Properties: {} },
509
- Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
510
- },
511
- RunArray: paragraphRunArray,
512
- RunLengthArray: paragraphRunLengthArray,
513
- IsJoinable: 1,
514
- },
515
- StyleRun: {
516
- DefaultRunData: { StyleSheet: { StyleSheetData: {} } },
517
- RunArray: styleRunArray,
518
- RunLengthArray: styleRunLengthArray,
519
- IsJoinable: 2,
520
- },
521
- GridInfo: {
522
- GridIsOn: !!gridInfo.isOn,
523
- ShowGrid: !!gridInfo.show,
524
- GridSize: (_j = gridInfo.size) !== null && _j !== void 0 ? _j : 18,
525
- GridLeading: (_k = gridInfo.leading) !== null && _k !== void 0 ? _k : 22,
526
- GridColor: encodeColor(gridInfo.color),
527
- GridLeadingFillColor: encodeColor(gridInfo.color),
528
- AlignLineHeightToGridFlags: !!gridInfo.alignLineHeightToGridFlags,
529
- },
530
- AntiAlias: antialias.indexOf((_l = data.antiAlias) !== null && _l !== void 0 ? _l : 'sharp'),
531
- UseFractionalGlyphWidths: (_m = data.useFractionalGlyphWidths) !== null && _m !== void 0 ? _m : true,
532
- Rendered: {
533
- Version: 1,
534
- Shapes: {
535
- WritingDirection,
536
- Children: [
537
- {
538
- ShapeType,
539
- Procession,
540
- Lines: { WritingDirection, Children: [] },
541
- Cookie: { Photoshop },
542
- },
543
- ],
544
- },
545
- },
546
- },
547
- ResourceDict: Object.assign({}, defaultResources),
548
- DocumentResources: Object.assign({}, defaultResources),
549
- };
550
- // console.log('encodeEngineData', require('util').inspect(engineData, false, 99, true));
551
- return engineData;
552
- }
553
- exports.encodeEngineData = encodeEngineData;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeEngineData = decodeEngineData;
4
+ exports.encodeEngineData = encodeEngineData;
5
+ const defaultFont = {
6
+ name: 'MyriadPro-Regular',
7
+ script: 0,
8
+ type: 0,
9
+ synthetic: 0,
10
+ };
11
+ const defaultParagraphStyle = {
12
+ justification: 'left',
13
+ firstLineIndent: 0,
14
+ startIndent: 0,
15
+ endIndent: 0,
16
+ spaceBefore: 0,
17
+ spaceAfter: 0,
18
+ autoHyphenate: true,
19
+ hyphenatedWordSize: 6,
20
+ preHyphen: 2,
21
+ postHyphen: 2,
22
+ consecutiveHyphens: 8,
23
+ zone: 36,
24
+ wordSpacing: [0.8, 1, 1.33],
25
+ letterSpacing: [0, 0, 0],
26
+ glyphSpacing: [1, 1, 1],
27
+ autoLeading: 1.2,
28
+ leadingType: 0,
29
+ hanging: false,
30
+ burasagari: false,
31
+ kinsokuOrder: 0,
32
+ everyLineComposer: false,
33
+ };
34
+ const defaultStyle = {
35
+ font: defaultFont,
36
+ fontSize: 12,
37
+ fauxBold: false,
38
+ fauxItalic: false,
39
+ autoLeading: true,
40
+ leading: 0,
41
+ horizontalScale: 1,
42
+ verticalScale: 1,
43
+ tracking: 0,
44
+ autoKerning: true,
45
+ kerning: 0,
46
+ baselineShift: 0,
47
+ fontCaps: 0,
48
+ fontBaseline: 0,
49
+ underline: false,
50
+ strikethrough: false,
51
+ ligatures: true,
52
+ dLigatures: false,
53
+ baselineDirection: 2,
54
+ tsume: 0,
55
+ styleRunAlignment: 2,
56
+ language: 0,
57
+ noBreak: false,
58
+ fillColor: { r: 0, g: 0, b: 0 },
59
+ strokeColor: { r: 0, g: 0, b: 0 },
60
+ fillFlag: true,
61
+ strokeFlag: false,
62
+ fillFirst: true,
63
+ yUnderline: 1,
64
+ outlineWidth: 1,
65
+ characterDirection: 0,
66
+ hindiNumbers: false,
67
+ kashida: 1,
68
+ diacriticPos: 2,
69
+ };
70
+ const defaultGridInfo = {
71
+ isOn: false,
72
+ show: false,
73
+ size: 18,
74
+ leading: 22,
75
+ color: { r: 0, g: 0, b: 255 },
76
+ leadingFillColor: { r: 0, g: 0, b: 255 },
77
+ alignLineHeightToGridFlags: false,
78
+ };
79
+ const paragraphStyleKeys = [
80
+ 'justification', 'firstLineIndent', 'startIndent', 'endIndent', 'spaceBefore', 'spaceAfter',
81
+ 'autoHyphenate', 'hyphenatedWordSize', 'preHyphen', 'postHyphen', 'consecutiveHyphens',
82
+ 'zone', 'wordSpacing', 'letterSpacing', 'glyphSpacing', 'autoLeading', 'leadingType',
83
+ 'hanging', 'burasagari', 'kinsokuOrder', 'everyLineComposer',
84
+ ];
85
+ const styleKeys = [
86
+ 'font', 'fontSize', 'fauxBold', 'fauxItalic', 'autoLeading', 'leading', 'horizontalScale',
87
+ 'verticalScale', 'tracking', 'autoKerning', 'kerning', 'baselineShift', 'fontCaps', 'fontBaseline',
88
+ 'underline', 'strikethrough', 'ligatures', 'dLigatures', 'baselineDirection', 'tsume',
89
+ 'styleRunAlignment', 'language', 'noBreak', 'fillColor', 'strokeColor', 'fillFlag',
90
+ 'strokeFlag', 'fillFirst', 'yUnderline', 'outlineWidth', 'characterDirection', 'hindiNumbers',
91
+ 'kashida', 'diacriticPos',
92
+ ];
93
+ const antialias = ['none', 'crisp', 'strong', 'smooth', 'sharp'];
94
+ const justification = [
95
+ 'left', // 0
96
+ 'right', // 1
97
+ 'center', // 2
98
+ 'justify-left', // 3
99
+ 'justify-right', // 4
100
+ 'justify-center', // 5
101
+ 'justify-all', // 6
102
+ ];
103
+ function upperFirst(value) {
104
+ return value.substring(0, 1).toUpperCase() + value.substring(1);
105
+ }
106
+ function decodeColor(color) {
107
+ const c = color.Values;
108
+ switch (color.Type) {
109
+ case 0: return { k: c[1] * 255 }; // grayscale (alpha?)
110
+ case 1: return c[0] === 1 ?
111
+ { r: c[1] * 255, g: c[2] * 255, b: c[3] * 255 } : // rgb
112
+ { r: c[1] * 255, g: c[2] * 255, b: c[3] * 255, a: c[0] * 255 }; // rgba
113
+ case 2: return { c: c[1] * 255, m: c[2] * 255, y: c[3] * 255, k: c[4] * 255 }; // cmyk (alpha?)
114
+ default: throw new Error('Unknown color type in text layer');
115
+ }
116
+ }
117
+ function encodeColor(color) {
118
+ if (!color) {
119
+ return { Type: 1, Values: [0, 0, 0, 0] };
120
+ }
121
+ else if ('r' in color) {
122
+ return { Type: 1, Values: ['a' in color ? color.a / 255 : 1, color.r / 255, color.g / 255, color.b / 255] };
123
+ }
124
+ else if ('c' in color) {
125
+ return { Type: 2, Values: [1, color.c / 255, color.m / 255, color.y / 255, color.k / 255] };
126
+ }
127
+ else if ('k' in color) {
128
+ return { Type: 0, Values: [1, color.k / 255] };
129
+ }
130
+ else {
131
+ throw new Error('Invalid color type in text layer');
132
+ }
133
+ }
134
+ function arraysEqual(a, b) {
135
+ if (!a || !b)
136
+ return false;
137
+ if (a.length !== b.length)
138
+ return false;
139
+ for (let i = 0; i < a.length; i++)
140
+ if (a[i] !== b[i])
141
+ return false;
142
+ return true;
143
+ }
144
+ function objectsEqual(a, b) {
145
+ if (!a || !b)
146
+ return false;
147
+ for (const key of Object.keys(a))
148
+ if (a[key] !== b[key])
149
+ return false;
150
+ for (const key of Object.keys(b))
151
+ if (a[key] !== b[key])
152
+ return false;
153
+ return true;
154
+ }
155
+ function findOrAddFont(fonts, font) {
156
+ for (let i = 0; i < fonts.length; i++) {
157
+ if (fonts[i].name === font.name)
158
+ return i;
159
+ }
160
+ fonts.push(font);
161
+ return fonts.length - 1;
162
+ }
163
+ function decodeObject(obj, keys, fonts) {
164
+ const result = {};
165
+ for (const key of keys) {
166
+ const Key = upperFirst(key);
167
+ if (obj[Key] === undefined)
168
+ continue;
169
+ if (key === 'justification') {
170
+ result[key] = justification[obj[Key]];
171
+ }
172
+ else if (key === 'font') {
173
+ result[key] = fonts[obj[Key]];
174
+ }
175
+ else if (key === 'fillColor' || key === 'strokeColor') {
176
+ result[key] = decodeColor(obj[Key]);
177
+ }
178
+ else {
179
+ result[key] = obj[Key];
180
+ }
181
+ }
182
+ return result;
183
+ }
184
+ function encodeObject(obj, keys, fonts) {
185
+ var _a;
186
+ const result = {};
187
+ for (const key of keys) {
188
+ const Key = upperFirst(key);
189
+ if (obj[key] === undefined)
190
+ continue;
191
+ if (key === 'justification') {
192
+ result[Key] = justification.indexOf((_a = obj[key]) !== null && _a !== void 0 ? _a : 'left');
193
+ }
194
+ else if (key === 'font') {
195
+ result[Key] = findOrAddFont(fonts, obj[key]);
196
+ }
197
+ else if (key === 'fillColor' || key === 'strokeColor') {
198
+ result[Key] = encodeColor(obj[key]);
199
+ }
200
+ else {
201
+ result[Key] = obj[key];
202
+ }
203
+ }
204
+ return result;
205
+ }
206
+ function decodeParagraphStyle(obj, fonts) {
207
+ return decodeObject(obj, paragraphStyleKeys, fonts);
208
+ }
209
+ function decodeStyle(obj, fonts) {
210
+ return decodeObject(obj, styleKeys, fonts);
211
+ }
212
+ function encodeParagraphStyle(obj, fonts) {
213
+ return encodeObject(obj, paragraphStyleKeys, fonts);
214
+ }
215
+ function encodeStyle(obj, fonts) {
216
+ return encodeObject(obj, styleKeys, fonts);
217
+ }
218
+ function deduplicateValues(base, runs, keys) {
219
+ if (!runs.length)
220
+ return;
221
+ for (const key of keys) {
222
+ const value = runs[0].style[key];
223
+ if (value !== undefined) {
224
+ let identical = false;
225
+ if (Array.isArray(value)) {
226
+ identical = runs.every(r => arraysEqual(r.style[key], value));
227
+ }
228
+ else if (typeof value === 'object') {
229
+ identical = runs.every(r => objectsEqual(r.style[key], value));
230
+ }
231
+ else {
232
+ identical = runs.every(r => r.style[key] === value);
233
+ }
234
+ if (identical) {
235
+ base[key] = value;
236
+ }
237
+ }
238
+ const styleValue = base[key];
239
+ if (styleValue !== undefined) {
240
+ for (const r of runs) {
241
+ let same = false;
242
+ if (Array.isArray(value)) {
243
+ same = arraysEqual(r.style[key], value);
244
+ }
245
+ else if (typeof value === 'object') {
246
+ same = objectsEqual(r.style[key], value);
247
+ }
248
+ else {
249
+ same = r.style[key] === value;
250
+ }
251
+ if (same)
252
+ delete r.style[key];
253
+ }
254
+ }
255
+ }
256
+ if (runs.every(x => Object.keys(x.style).length === 0)) {
257
+ runs.length = 0;
258
+ }
259
+ }
260
+ function decodeEngineData(engineData) {
261
+ var _a, _b, _c, _d, _e, _f;
262
+ // console.log('engineData', require('util').inspect(engineData, false, 99, true));
263
+ const engineDict = engineData.EngineDict;
264
+ const resourceDict = engineData.ResourceDict;
265
+ const fonts = resourceDict.FontSet.map(f => ({
266
+ name: f.Name,
267
+ script: f.Script,
268
+ type: f.FontType,
269
+ synthetic: f.Synthetic,
270
+ }));
271
+ let text = engineDict.Editor.Text.replace(/\r/g, '\n');
272
+ let removedCharacters = 0;
273
+ while (/\n$/.test(text)) {
274
+ text = text.substring(0, text.length - 1);
275
+ removedCharacters++;
276
+ }
277
+ const result = {
278
+ text,
279
+ antiAlias: (_a = antialias[engineDict.AntiAlias]) !== null && _a !== void 0 ? _a : 'smooth',
280
+ useFractionalGlyphWidths: !!engineDict.UseFractionalGlyphWidths,
281
+ superscriptSize: resourceDict.SuperscriptSize,
282
+ superscriptPosition: resourceDict.SuperscriptPosition,
283
+ subscriptSize: resourceDict.SubscriptSize,
284
+ subscriptPosition: resourceDict.SubscriptPosition,
285
+ smallCapSize: resourceDict.SmallCapSize,
286
+ };
287
+ // shape
288
+ const photoshop = (_f = (_e = (_d = (_c = (_b = engineDict.Rendered) === null || _b === void 0 ? void 0 : _b.Shapes) === null || _c === void 0 ? void 0 : _c.Children) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.Cookie) === null || _f === void 0 ? void 0 : _f.Photoshop;
289
+ if (photoshop) {
290
+ result.shapeType = photoshop.ShapeType === 1 ? 'box' : 'point';
291
+ if (photoshop.PointBase)
292
+ result.pointBase = photoshop.PointBase;
293
+ if (photoshop.BoxBounds)
294
+ result.boxBounds = photoshop.BoxBounds;
295
+ }
296
+ // paragraph style
297
+ // const theNormalParagraphSheet = resourceDict.TheNormalParagraphSheet;
298
+ // const paragraphSheetSet = resourceDict.ParagraphSheetSet;
299
+ // const paragraphProperties = paragraphSheetSet[theNormalParagraphSheet].Properties;
300
+ const paragraphRun = engineDict.ParagraphRun;
301
+ result.paragraphStyle = {}; // decodeParagraphStyle(paragraphProperties, fonts);
302
+ result.paragraphStyleRuns = [];
303
+ for (let i = 0; i < paragraphRun.RunArray.length; i++) {
304
+ const run = paragraphRun.RunArray[i];
305
+ const length = paragraphRun.RunLengthArray[i];
306
+ const style = decodeParagraphStyle(run.ParagraphSheet.Properties, fonts);
307
+ // const adjustments = {
308
+ // axis: run.Adjustments.Axis,
309
+ // xy: run.Adjustments.XY,
310
+ // };
311
+ result.paragraphStyleRuns.push({ length, style /*, adjustments*/ });
312
+ }
313
+ for (let counter = removedCharacters; result.paragraphStyleRuns.length && counter > 0; counter--) {
314
+ if (--result.paragraphStyleRuns[result.paragraphStyleRuns.length - 1].length === 0) {
315
+ result.paragraphStyleRuns.pop();
316
+ }
317
+ }
318
+ deduplicateValues(result.paragraphStyle, result.paragraphStyleRuns, paragraphStyleKeys);
319
+ if (!result.paragraphStyleRuns.length)
320
+ delete result.paragraphStyleRuns;
321
+ // style
322
+ // const theNormalStyleSheet = resourceDict.TheNormalStyleSheet;
323
+ // const styleSheetSet = resourceDict.StyleSheetSet;
324
+ // const styleSheetData = styleSheetSet[theNormalStyleSheet].StyleSheetData;
325
+ const styleRun = engineDict.StyleRun;
326
+ result.style = {}; // decodeStyle(styleSheetData, fonts);
327
+ result.styleRuns = [];
328
+ for (let i = 0; i < styleRun.RunArray.length; i++) {
329
+ const length = styleRun.RunLengthArray[i];
330
+ const style = decodeStyle(styleRun.RunArray[i].StyleSheet.StyleSheetData, fonts);
331
+ if (!style.font)
332
+ style.font = fonts[0];
333
+ result.styleRuns.push({ length, style });
334
+ }
335
+ for (let counter = removedCharacters; result.styleRuns.length && counter > 0; counter--) {
336
+ if (--result.styleRuns[result.styleRuns.length - 1].length === 0) {
337
+ result.styleRuns.pop();
338
+ }
339
+ }
340
+ deduplicateValues(result.style, result.styleRuns, styleKeys);
341
+ if (!result.styleRuns.length)
342
+ delete result.styleRuns;
343
+ return result;
344
+ }
345
+ function encodeEngineData(data) {
346
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
347
+ const text = `${(data.text || '').replace(/\r?\n/g, '\r')}\r`;
348
+ const fonts = [
349
+ { name: 'AdobeInvisFont', script: 0, type: 0, synthetic: 0 },
350
+ ];
351
+ const defFont = ((_a = data.style) === null || _a === void 0 ? void 0 : _a.font) || ((_c = (_b = data.styleRuns) === null || _b === void 0 ? void 0 : _b.find(s => s.style.font)) === null || _c === void 0 ? void 0 : _c.style.font) || defaultFont;
352
+ const paragraphRunArray = [];
353
+ const paragraphRunLengthArray = [];
354
+ const paragraphRuns = data.paragraphStyleRuns;
355
+ if (paragraphRuns && paragraphRuns.length) {
356
+ let leftLength = text.length;
357
+ for (const run of paragraphRuns) {
358
+ let runLength = Math.min(run.length, leftLength);
359
+ leftLength -= runLength;
360
+ if (!runLength)
361
+ continue; // ignore 0 size runs
362
+ // extend last run if it's only for trailing \r
363
+ if (leftLength === 1 && run === paragraphRuns[paragraphRuns.length - 1]) {
364
+ runLength++;
365
+ leftLength--;
366
+ }
367
+ paragraphRunLengthArray.push(runLength);
368
+ paragraphRunArray.push({
369
+ ParagraphSheet: {
370
+ DefaultStyleSheet: 0,
371
+ Properties: encodeParagraphStyle(Object.assign(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), run.style), fonts),
372
+ },
373
+ Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
374
+ });
375
+ }
376
+ if (leftLength) {
377
+ paragraphRunLengthArray.push(leftLength);
378
+ paragraphRunArray.push({
379
+ ParagraphSheet: {
380
+ DefaultStyleSheet: 0,
381
+ Properties: encodeParagraphStyle(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), fonts),
382
+ },
383
+ Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
384
+ });
385
+ }
386
+ }
387
+ else {
388
+ for (let i = 0, last = 0; i < text.length; i++) {
389
+ if (text.charCodeAt(i) === 13) { // \r
390
+ paragraphRunLengthArray.push(i - last + 1);
391
+ paragraphRunArray.push({
392
+ ParagraphSheet: {
393
+ DefaultStyleSheet: 0,
394
+ Properties: encodeParagraphStyle(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), fonts),
395
+ },
396
+ Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
397
+ });
398
+ last = i + 1;
399
+ }
400
+ }
401
+ }
402
+ const styleSheetData = encodeStyle(Object.assign(Object.assign({}, defaultStyle), { font: defFont }), fonts);
403
+ const styleRuns = data.styleRuns || [{ length: text.length, style: data.style || {} }];
404
+ const styleRunArray = [];
405
+ const styleRunLengthArray = [];
406
+ let leftLength = text.length;
407
+ for (const run of styleRuns) {
408
+ let runLength = Math.min(run.length, leftLength);
409
+ leftLength -= runLength;
410
+ if (!runLength)
411
+ continue; // ignore 0 size runs
412
+ // extend last run if it's only for trailing \r
413
+ if (leftLength === 1 && run === styleRuns[styleRuns.length - 1]) {
414
+ runLength++;
415
+ leftLength--;
416
+ }
417
+ styleRunLengthArray.push(runLength);
418
+ styleRunArray.push({
419
+ StyleSheet: {
420
+ StyleSheetData: encodeStyle(Object.assign(Object.assign({ kerning: 0, autoKerning: true, fillColor: { r: 0, g: 0, b: 0 } }, data.style), run.style), fonts),
421
+ },
422
+ });
423
+ }
424
+ // add extra run to the end if existing ones didn't fill it up
425
+ if (leftLength && styleRuns.length) {
426
+ styleRunLengthArray.push(leftLength);
427
+ styleRunArray.push({
428
+ StyleSheet: {
429
+ StyleSheetData: encodeStyle(Object.assign({ kerning: 0, autoKerning: true, fillColor: { r: 0, g: 0, b: 0 } }, data.style), fonts),
430
+ },
431
+ });
432
+ }
433
+ const gridInfo = Object.assign(Object.assign({}, defaultGridInfo), data.gridInfo);
434
+ const WritingDirection = data.orientation === 'vertical' ? 2 : 0;
435
+ const Procession = data.orientation === 'vertical' ? 1 : 0;
436
+ const ShapeType = data.shapeType === 'box' ? 1 : 0;
437
+ const Photoshop = {
438
+ ShapeType,
439
+ };
440
+ if (ShapeType === 0) {
441
+ Photoshop.PointBase = data.pointBase || [0, 0];
442
+ }
443
+ else {
444
+ Photoshop.BoxBounds = data.boxBounds || [0, 0, 0, 0];
445
+ }
446
+ // needed for correct order of properties
447
+ Photoshop.Base = {
448
+ ShapeType,
449
+ TransformPoint0: [1, 0],
450
+ TransformPoint1: [0, 1],
451
+ TransformPoint2: [0, 0],
452
+ };
453
+ const defaultResources = {
454
+ KinsokuSet: [
455
+ {
456
+ Name: 'PhotoshopKinsokuHard',
457
+ NoStart: '、。,.・:;?!ー―’”)〕]}〉》」』】ヽヾゝゞ々ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮヵヶ゛゜?!)]},.:;℃℉¢%‰',
458
+ NoEnd: '‘“(〔[{〈《「『【([{¥$£@§〒#',
459
+ Keep: '―‥',
460
+ Hanging: '、。.,',
461
+ },
462
+ {
463
+ Name: 'PhotoshopKinsokuSoft',
464
+ NoStart: '、。,.・:;?!’”)〕]}〉》」』】ヽヾゝゞ々',
465
+ NoEnd: '‘“(〔[{〈《「『【',
466
+ Keep: '―‥',
467
+ Hanging: '、。.,',
468
+ },
469
+ ],
470
+ MojiKumiSet: [
471
+ { InternalName: 'Photoshop6MojiKumiSet1' },
472
+ { InternalName: 'Photoshop6MojiKumiSet2' },
473
+ { InternalName: 'Photoshop6MojiKumiSet3' },
474
+ { InternalName: 'Photoshop6MojiKumiSet4' },
475
+ ],
476
+ TheNormalStyleSheet: 0,
477
+ TheNormalParagraphSheet: 0,
478
+ ParagraphSheetSet: [
479
+ {
480
+ Name: 'Normal RGB',
481
+ DefaultStyleSheet: 0,
482
+ Properties: encodeParagraphStyle(Object.assign(Object.assign({}, defaultParagraphStyle), data.paragraphStyle), fonts),
483
+ },
484
+ ],
485
+ StyleSheetSet: [
486
+ {
487
+ Name: 'Normal RGB',
488
+ StyleSheetData: styleSheetData,
489
+ },
490
+ ],
491
+ FontSet: fonts.map(f => ({
492
+ Name: f.name,
493
+ Script: f.script || 0,
494
+ FontType: f.type || 0,
495
+ Synthetic: f.synthetic || 0,
496
+ })),
497
+ SuperscriptSize: (_d = data.superscriptSize) !== null && _d !== void 0 ? _d : 0.583,
498
+ SuperscriptPosition: (_e = data.superscriptPosition) !== null && _e !== void 0 ? _e : 0.333,
499
+ SubscriptSize: (_f = data.subscriptSize) !== null && _f !== void 0 ? _f : 0.583,
500
+ SubscriptPosition: (_g = data.subscriptPosition) !== null && _g !== void 0 ? _g : 0.333,
501
+ SmallCapSize: (_h = data.smallCapSize) !== null && _h !== void 0 ? _h : 0.7,
502
+ };
503
+ const engineData = {
504
+ EngineDict: {
505
+ Editor: { Text: text },
506
+ ParagraphRun: {
507
+ DefaultRunData: {
508
+ ParagraphSheet: { DefaultStyleSheet: 0, Properties: {} },
509
+ Adjustments: { Axis: [1, 0, 1], XY: [0, 0] },
510
+ },
511
+ RunArray: paragraphRunArray,
512
+ RunLengthArray: paragraphRunLengthArray,
513
+ IsJoinable: 1,
514
+ },
515
+ StyleRun: {
516
+ DefaultRunData: { StyleSheet: { StyleSheetData: {} } },
517
+ RunArray: styleRunArray,
518
+ RunLengthArray: styleRunLengthArray,
519
+ IsJoinable: 2,
520
+ },
521
+ GridInfo: {
522
+ GridIsOn: !!gridInfo.isOn,
523
+ ShowGrid: !!gridInfo.show,
524
+ GridSize: (_j = gridInfo.size) !== null && _j !== void 0 ? _j : 18,
525
+ GridLeading: (_k = gridInfo.leading) !== null && _k !== void 0 ? _k : 22,
526
+ GridColor: encodeColor(gridInfo.color),
527
+ GridLeadingFillColor: encodeColor(gridInfo.color),
528
+ AlignLineHeightToGridFlags: !!gridInfo.alignLineHeightToGridFlags,
529
+ },
530
+ AntiAlias: antialias.indexOf((_l = data.antiAlias) !== null && _l !== void 0 ? _l : 'sharp'),
531
+ UseFractionalGlyphWidths: (_m = data.useFractionalGlyphWidths) !== null && _m !== void 0 ? _m : true,
532
+ Rendered: {
533
+ Version: 1,
534
+ Shapes: {
535
+ WritingDirection,
536
+ Children: [
537
+ {
538
+ ShapeType,
539
+ Procession,
540
+ Lines: { WritingDirection, Children: [] },
541
+ Cookie: { Photoshop },
542
+ },
543
+ ],
544
+ },
545
+ },
546
+ },
547
+ ResourceDict: Object.assign({}, defaultResources),
548
+ DocumentResources: Object.assign({}, defaultResources),
549
+ };
550
+ // console.log('encodeEngineData', require('util').inspect(engineData, false, 99, true));
551
+ return engineData;
552
+ }
554
553
  //# sourceMappingURL=text.js.map