ag-psd 30.1.1 → 31.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/.v8-cache/v24.13.1-x64-cf738c9d/017325ac +0 -0
  2. package/.v8-cache/v24.13.1-x64-cf738c9d/01e5e61b +0 -0
  3. package/.v8-cache/v24.13.1-x64-cf738c9d/043c7b90 +0 -0
  4. package/.v8-cache/v24.13.1-x64-cf738c9d/05135617 +0 -0
  5. package/.v8-cache/v24.13.1-x64-cf738c9d/059f8558 +0 -0
  6. package/.v8-cache/v24.13.1-x64-cf738c9d/06423db9 +0 -0
  7. package/.v8-cache/v24.13.1-x64-cf738c9d/06e765df +0 -0
  8. package/.v8-cache/v24.13.1-x64-cf738c9d/0706ecb8 +0 -0
  9. package/.v8-cache/v24.13.1-x64-cf738c9d/0930679d +0 -0
  10. package/.v8-cache/v24.13.1-x64-cf738c9d/09519a62 +0 -0
  11. package/.v8-cache/v24.13.1-x64-cf738c9d/0a6607b0 +0 -0
  12. package/.v8-cache/v24.13.1-x64-cf738c9d/0ad8fa6e +0 -0
  13. package/.v8-cache/v24.13.1-x64-cf738c9d/0d390e10 +0 -0
  14. package/.v8-cache/v24.13.1-x64-cf738c9d/0db754a7 +0 -0
  15. package/.v8-cache/v24.13.1-x64-cf738c9d/0dfa7b16 +0 -0
  16. package/.v8-cache/v24.13.1-x64-cf738c9d/0e9e09db +0 -0
  17. package/.v8-cache/v24.13.1-x64-cf738c9d/1130885f +0 -0
  18. package/.v8-cache/v24.13.1-x64-cf738c9d/1222cb8c +0 -0
  19. package/.v8-cache/v24.13.1-x64-cf738c9d/15e2c039 +0 -0
  20. package/.v8-cache/v24.13.1-x64-cf738c9d/15f0e479 +0 -0
  21. package/.v8-cache/v24.13.1-x64-cf738c9d/1a2d469d +0 -0
  22. package/.v8-cache/v24.13.1-x64-cf738c9d/1b300c82 +0 -0
  23. package/.v8-cache/v24.13.1-x64-cf738c9d/1bc3d370 +0 -0
  24. package/.v8-cache/v24.13.1-x64-cf738c9d/1e44e5af +0 -0
  25. package/.v8-cache/v24.13.1-x64-cf738c9d/1efa10a1 +0 -0
  26. package/.v8-cache/v24.13.1-x64-cf738c9d/1f6c8743 +0 -0
  27. package/.v8-cache/v24.13.1-x64-cf738c9d/20477c23 +0 -0
  28. package/.v8-cache/v24.13.1-x64-cf738c9d/20b27e40 +0 -0
  29. package/.v8-cache/v24.13.1-x64-cf738c9d/20dfa422 +0 -0
  30. package/.v8-cache/v24.13.1-x64-cf738c9d/257c62ba +0 -0
  31. package/.v8-cache/v24.13.1-x64-cf738c9d/25d60154 +0 -0
  32. package/.v8-cache/v24.13.1-x64-cf738c9d/26f822f3 +0 -0
  33. package/.v8-cache/v24.13.1-x64-cf738c9d/2a19133e +0 -0
  34. package/.v8-cache/v24.13.1-x64-cf738c9d/2a1e2a8d +0 -0
  35. package/.v8-cache/v24.13.1-x64-cf738c9d/2b02fded +0 -0
  36. package/.v8-cache/v24.13.1-x64-cf738c9d/2b069ee0 +0 -0
  37. package/.v8-cache/v24.13.1-x64-cf738c9d/2c76dc0d +0 -0
  38. package/.v8-cache/v24.13.1-x64-cf738c9d/2de09439 +0 -0
  39. package/.v8-cache/v24.13.1-x64-cf738c9d/2deb286a +0 -0
  40. package/.v8-cache/v24.13.1-x64-cf738c9d/2e44f5f0 +0 -0
  41. package/.v8-cache/v24.13.1-x64-cf738c9d/2fb229a9 +0 -0
  42. package/.v8-cache/v24.13.1-x64-cf738c9d/3144b401 +0 -0
  43. package/.v8-cache/v24.13.1-x64-cf738c9d/32018e44 +0 -0
  44. package/.v8-cache/v24.13.1-x64-cf738c9d/341402c3 +0 -0
  45. package/.v8-cache/v24.13.1-x64-cf738c9d/34e0fa2e +0 -0
  46. package/.v8-cache/v24.13.1-x64-cf738c9d/37481985 +0 -0
  47. package/.v8-cache/v24.13.1-x64-cf738c9d/3bbf643e +0 -0
  48. package/.v8-cache/v24.13.1-x64-cf738c9d/3ceff89e +0 -0
  49. package/.v8-cache/v24.13.1-x64-cf738c9d/404f5cdc +0 -0
  50. package/.v8-cache/v24.13.1-x64-cf738c9d/4087aa2b +0 -0
  51. package/.v8-cache/v24.13.1-x64-cf738c9d/4376c1f9 +0 -0
  52. package/.v8-cache/v24.13.1-x64-cf738c9d/44903df4 +0 -0
  53. package/.v8-cache/v24.13.1-x64-cf738c9d/44d58dc8 +0 -0
  54. package/.v8-cache/v24.13.1-x64-cf738c9d/4511bacf +0 -0
  55. package/.v8-cache/v24.13.1-x64-cf738c9d/47da0ce8 +0 -0
  56. package/.v8-cache/v24.13.1-x64-cf738c9d/48cd54a9 +0 -0
  57. package/.v8-cache/v24.13.1-x64-cf738c9d/49d22b79 +0 -0
  58. package/.v8-cache/v24.13.1-x64-cf738c9d/4d938476 +0 -0
  59. package/.v8-cache/v24.13.1-x64-cf738c9d/4ec6d390 +0 -0
  60. package/.v8-cache/v24.13.1-x64-cf738c9d/4f5702bd +0 -0
  61. package/.v8-cache/v24.13.1-x64-cf738c9d/514cc428 +0 -0
  62. package/.v8-cache/v24.13.1-x64-cf738c9d/557d3b42 +0 -0
  63. package/.v8-cache/v24.13.1-x64-cf738c9d/56abbff7 +0 -0
  64. package/.v8-cache/v24.13.1-x64-cf738c9d/57b540ee +0 -0
  65. package/.v8-cache/v24.13.1-x64-cf738c9d/57d3380b +0 -0
  66. package/.v8-cache/v24.13.1-x64-cf738c9d/5e20c081 +0 -0
  67. package/.v8-cache/v24.13.1-x64-cf738c9d/6024ce3f +0 -0
  68. package/.v8-cache/v24.13.1-x64-cf738c9d/61735b23 +0 -0
  69. package/.v8-cache/v24.13.1-x64-cf738c9d/63dbdb75 +0 -0
  70. package/.v8-cache/v24.13.1-x64-cf738c9d/651c4ada +0 -0
  71. package/.v8-cache/v24.13.1-x64-cf738c9d/652a0d59 +0 -0
  72. package/.v8-cache/v24.13.1-x64-cf738c9d/6a0e89ee +0 -0
  73. package/.v8-cache/v24.13.1-x64-cf738c9d/6af33b91 +0 -0
  74. package/.v8-cache/v24.13.1-x64-cf738c9d/6c2562d2 +0 -0
  75. package/.v8-cache/v24.13.1-x64-cf738c9d/6cbfc0ec +0 -0
  76. package/.v8-cache/v24.13.1-x64-cf738c9d/6dae0cfa +0 -0
  77. package/.v8-cache/v24.13.1-x64-cf738c9d/6e2529ce +0 -0
  78. package/.v8-cache/v24.13.1-x64-cf738c9d/6f08372c +0 -0
  79. package/.v8-cache/v24.13.1-x64-cf738c9d/7100ee08 +0 -0
  80. package/.v8-cache/v24.13.1-x64-cf738c9d/71df9cb3 +0 -0
  81. package/.v8-cache/v24.13.1-x64-cf738c9d/72e1d543 +0 -0
  82. package/.v8-cache/v24.13.1-x64-cf738c9d/75519c80 +0 -0
  83. package/.v8-cache/v24.13.1-x64-cf738c9d/75e41e43 +0 -0
  84. package/.v8-cache/v24.13.1-x64-cf738c9d/79bf115c +0 -0
  85. package/.v8-cache/v24.13.1-x64-cf738c9d/7a39347c +0 -0
  86. package/.v8-cache/v24.13.1-x64-cf738c9d/7b83e3d3 +0 -0
  87. package/.v8-cache/v24.13.1-x64-cf738c9d/7cd71bc5 +0 -0
  88. package/.v8-cache/v24.13.1-x64-cf738c9d/7da78512 +0 -0
  89. package/.v8-cache/v24.13.1-x64-cf738c9d/7ea06cea +0 -0
  90. package/.v8-cache/v24.13.1-x64-cf738c9d/82c3b573 +0 -0
  91. package/.v8-cache/v24.13.1-x64-cf738c9d/84c186e4 +0 -0
  92. package/.v8-cache/v24.13.1-x64-cf738c9d/8568576b +0 -0
  93. package/.v8-cache/v24.13.1-x64-cf738c9d/8607bd36 +0 -0
  94. package/.v8-cache/v24.13.1-x64-cf738c9d/87372817 +0 -0
  95. package/.v8-cache/v24.13.1-x64-cf738c9d/87cf2209 +0 -0
  96. package/.v8-cache/v24.13.1-x64-cf738c9d/882aaa05 +0 -0
  97. package/.v8-cache/v24.13.1-x64-cf738c9d/8a4d3de8 +0 -0
  98. package/.v8-cache/v24.13.1-x64-cf738c9d/8e223473 +0 -0
  99. package/.v8-cache/v24.13.1-x64-cf738c9d/92b7aefd +0 -0
  100. package/.v8-cache/v24.13.1-x64-cf738c9d/932f0770 +0 -0
  101. package/.v8-cache/v24.13.1-x64-cf738c9d/937c03a1 +0 -0
  102. package/.v8-cache/v24.13.1-x64-cf738c9d/991e4758 +0 -0
  103. package/.v8-cache/v24.13.1-x64-cf738c9d/9af658fb +0 -0
  104. package/.v8-cache/v24.13.1-x64-cf738c9d/9ed80ba5 +0 -0
  105. package/.v8-cache/v24.13.1-x64-cf738c9d/9f0dc993 +0 -0
  106. package/.v8-cache/v24.13.1-x64-cf738c9d/a19c0c4f +0 -0
  107. package/.v8-cache/v24.13.1-x64-cf738c9d/a6409d95 +0 -0
  108. package/.v8-cache/v24.13.1-x64-cf738c9d/a79a40bb +0 -0
  109. package/.v8-cache/v24.13.1-x64-cf738c9d/a7e80865 +0 -0
  110. package/.v8-cache/v24.13.1-x64-cf738c9d/ac9802c6 +0 -0
  111. package/.v8-cache/v24.13.1-x64-cf738c9d/acc36e66 +0 -0
  112. package/.v8-cache/v24.13.1-x64-cf738c9d/ad11e2dc +0 -0
  113. package/.v8-cache/v24.13.1-x64-cf738c9d/b0c8fcd8 +0 -0
  114. package/.v8-cache/v24.13.1-x64-cf738c9d/b1762958 +0 -0
  115. package/.v8-cache/v24.13.1-x64-cf738c9d/b3c2fab7 +0 -0
  116. package/.v8-cache/v24.13.1-x64-cf738c9d/b5b3329b +0 -0
  117. package/.v8-cache/v24.13.1-x64-cf738c9d/b69ed3a3 +0 -0
  118. package/.v8-cache/v24.13.1-x64-cf738c9d/b806679e +0 -0
  119. package/.v8-cache/v24.13.1-x64-cf738c9d/bc1cdd48 +0 -0
  120. package/.v8-cache/v24.13.1-x64-cf738c9d/bc7ebd1d +0 -0
  121. package/.v8-cache/v24.13.1-x64-cf738c9d/bdff1628 +0 -0
  122. package/.v8-cache/v24.13.1-x64-cf738c9d/c0b789d2 +0 -0
  123. package/.v8-cache/v24.13.1-x64-cf738c9d/c314aece +0 -0
  124. package/.v8-cache/v24.13.1-x64-cf738c9d/c399a5dc +0 -0
  125. package/.v8-cache/v24.13.1-x64-cf738c9d/c681cbc8 +0 -0
  126. package/.v8-cache/v24.13.1-x64-cf738c9d/c6834ffc +0 -0
  127. package/.v8-cache/v24.13.1-x64-cf738c9d/c6f12ed5 +0 -0
  128. package/.v8-cache/v24.13.1-x64-cf738c9d/cb0f0a3d +0 -0
  129. package/.v8-cache/v24.13.1-x64-cf738c9d/cbcb7c95 +0 -0
  130. package/.v8-cache/v24.13.1-x64-cf738c9d/cdd9107c +0 -0
  131. package/.v8-cache/v24.13.1-x64-cf738c9d/cdf2c4a3 +0 -0
  132. package/.v8-cache/v24.13.1-x64-cf738c9d/cfc49f4f +0 -0
  133. package/.v8-cache/v24.13.1-x64-cf738c9d/cff9434a +0 -0
  134. package/.v8-cache/v24.13.1-x64-cf738c9d/d02dd6f7 +0 -0
  135. package/.v8-cache/v24.13.1-x64-cf738c9d/d0507bf3 +0 -0
  136. package/.v8-cache/v24.13.1-x64-cf738c9d/d60fce19 +0 -0
  137. package/.v8-cache/v24.13.1-x64-cf738c9d/d733d619 +0 -0
  138. package/.v8-cache/v24.13.1-x64-cf738c9d/d75b7803 +0 -0
  139. package/.v8-cache/v24.13.1-x64-cf738c9d/dc86f000 +0 -0
  140. package/.v8-cache/v24.13.1-x64-cf738c9d/de74e659 +0 -0
  141. package/.v8-cache/v24.13.1-x64-cf738c9d/defa4f7f +0 -0
  142. package/.v8-cache/v24.13.1-x64-cf738c9d/e03e2acd +0 -0
  143. package/.v8-cache/v24.13.1-x64-cf738c9d/e0e3f52c +0 -0
  144. package/.v8-cache/v24.13.1-x64-cf738c9d/e158d332 +0 -0
  145. package/.v8-cache/v24.13.1-x64-cf738c9d/e6735171 +0 -0
  146. package/.v8-cache/v24.13.1-x64-cf738c9d/e6745c2b +0 -0
  147. package/.v8-cache/v24.13.1-x64-cf738c9d/e6b99945 +0 -0
  148. package/.v8-cache/v24.13.1-x64-cf738c9d/e6d8ceb8 +0 -0
  149. package/.v8-cache/v24.13.1-x64-cf738c9d/e7ffec37 +0 -0
  150. package/.v8-cache/v24.13.1-x64-cf738c9d/ea33b6de +0 -0
  151. package/.v8-cache/v24.13.1-x64-cf738c9d/eaafa3c4 +0 -0
  152. package/.v8-cache/v24.13.1-x64-cf738c9d/ebb50fca +0 -0
  153. package/.v8-cache/v24.13.1-x64-cf738c9d/ec805f2e +0 -0
  154. package/.v8-cache/v24.13.1-x64-cf738c9d/edaef8f1 +0 -0
  155. package/.v8-cache/v24.13.1-x64-cf738c9d/ee4401c8 +0 -0
  156. package/.v8-cache/v24.13.1-x64-cf738c9d/eeeebdfe +0 -0
  157. package/.v8-cache/v24.13.1-x64-cf738c9d/f3d51676 +0 -0
  158. package/.v8-cache/v24.13.1-x64-cf738c9d/f7b50a75 +0 -0
  159. package/.v8-cache/v24.13.1-x64-cf738c9d/fa58ca72 +0 -0
  160. package/.v8-cache/v24.13.1-x64-cf738c9d/fbca6276 +0 -0
  161. package/.v8-cache/v24.13.1-x64-cf738c9d/fc97d72d +0 -0
  162. package/.v8-cache/v24.13.1-x64-cf738c9d/fd0a2987 +0 -0
  163. package/CHANGELOG.md +9 -0
  164. package/README.md +65 -1
  165. package/README_PSD.md +1 -1
  166. package/TODO.md +2 -0
  167. package/dist/abr.d.ts +196 -196
  168. package/dist/abr.js +364 -378
  169. package/dist/abr.js.map +1 -1
  170. package/dist/additionalInfo.d.ts +26 -26
  171. package/dist/additionalInfo.js +3478 -3516
  172. package/dist/additionalInfo.js.map +1 -1
  173. package/dist/ase.d.ts +32 -32
  174. package/dist/ase.js +81 -82
  175. package/dist/ase.js.map +1 -1
  176. package/dist/bundle.js +12380 -12445
  177. package/dist/csh.d.ts +10 -10
  178. package/dist/csh.js +35 -47
  179. package/dist/csh.js.map +1 -1
  180. package/dist/descriptor.d.ts +601 -601
  181. package/dist/descriptor.js +2003 -2038
  182. package/dist/descriptor.js.map +1 -1
  183. package/dist/effectsHelpers.d.ts +5 -5
  184. package/dist/effectsHelpers.js +286 -308
  185. package/dist/effectsHelpers.js.map +1 -1
  186. package/dist/engineData.d.ts +2 -2
  187. package/dist/engineData.js +334 -341
  188. package/dist/engineData.js.map +1 -1
  189. package/dist/engineData2.d.ts +2 -2
  190. package/dist/engineData2.js +409 -411
  191. package/dist/engineData2.js.map +1 -1
  192. package/dist/helpers.d.ts +74 -74
  193. package/dist/helpers.js +353 -348
  194. package/dist/helpers.js.map +1 -1
  195. package/dist/imageResources.d.ts +17 -17
  196. package/dist/imageResources.js +1040 -1079
  197. package/dist/imageResources.js.map +1 -1
  198. package/dist/index.d.ts +20 -22
  199. package/dist/index.js +61 -56
  200. package/dist/index.js.map +1 -1
  201. package/dist/initializeCanvas.d.ts +1 -1
  202. package/dist/initializeCanvas.js +9 -10
  203. package/dist/initializeCanvas.js.map +1 -1
  204. package/dist/jpeg.d.ts +1 -1
  205. package/dist/jpeg.js +1020 -1021
  206. package/dist/jpeg.js.map +1 -1
  207. package/dist/psd.d.ts +1877 -1873
  208. package/dist/psd.js +45 -45
  209. package/dist/psd.js.map +1 -1
  210. package/dist/psdReader.d.ts +52 -45
  211. package/dist/psdReader.js +1385 -1293
  212. package/dist/psdReader.js.map +1 -1
  213. package/dist/psdWriter.d.ts +34 -33
  214. package/dist/psdWriter.js +834 -805
  215. package/dist/psdWriter.js.map +1 -1
  216. package/dist/text.d.ts +179 -179
  217. package/dist/text.js +552 -577
  218. package/dist/text.js.map +1 -1
  219. package/dist/utf8.d.ts +4 -6
  220. package/dist/utf8.js +156 -157
  221. package/dist/utf8.js.map +1 -1
  222. package/dist-es/abr.d.ts +196 -196
  223. package/dist-es/abr.js +364 -374
  224. package/dist-es/abr.js.map +1 -1
  225. package/dist-es/additionalInfo.d.ts +26 -26
  226. package/dist-es/additionalInfo.js +3478 -3510
  227. package/dist-es/additionalInfo.js.map +1 -1
  228. package/dist-es/ase.d.ts +32 -32
  229. package/dist-es/ase.js +81 -78
  230. package/dist-es/ase.js.map +1 -1
  231. package/dist-es/csh.d.ts +10 -10
  232. package/dist-es/csh.js +35 -43
  233. package/dist-es/csh.js.map +1 -1
  234. package/dist-es/descriptor.d.ts +601 -601
  235. package/dist-es/descriptor.js +2003 -2005
  236. package/dist-es/descriptor.js.map +1 -1
  237. package/dist-es/effectsHelpers.d.ts +5 -5
  238. package/dist-es/effectsHelpers.js +286 -303
  239. package/dist-es/effectsHelpers.js.map +1 -1
  240. package/dist-es/engineData.d.ts +2 -2
  241. package/dist-es/engineData.js +334 -336
  242. package/dist-es/engineData.js.map +1 -1
  243. package/dist-es/engineData2.d.ts +2 -2
  244. package/dist-es/engineData2.js +409 -407
  245. package/dist-es/engineData2.js.map +1 -1
  246. package/dist-es/helpers.d.ts +74 -74
  247. package/dist-es/helpers.js +353 -330
  248. package/dist-es/helpers.js.map +1 -1
  249. package/dist-es/imageResources.d.ts +17 -17
  250. package/dist-es/imageResources.js +1040 -1076
  251. package/dist-es/imageResources.js.map +1 -1
  252. package/dist-es/index.d.ts +20 -22
  253. package/dist-es/index.js +61 -33
  254. package/dist-es/index.js.map +1 -1
  255. package/dist-es/initializeCanvas.d.ts +1 -1
  256. package/dist-es/initializeCanvas.js +9 -6
  257. package/dist-es/initializeCanvas.js.map +1 -1
  258. package/dist-es/jpeg.d.ts +1 -1
  259. package/dist-es/jpeg.js +1020 -1017
  260. package/dist-es/jpeg.js.map +1 -1
  261. package/dist-es/psd.d.ts +1877 -1873
  262. package/dist-es/psd.js +45 -42
  263. package/dist-es/psd.js.map +1 -1
  264. package/dist-es/psdReader.d.ts +52 -45
  265. package/dist-es/psdReader.js +1385 -1255
  266. package/dist-es/psdReader.js.map +1 -1
  267. package/dist-es/psdWriter.d.ts +34 -33
  268. package/dist-es/psdWriter.js +834 -776
  269. package/dist-es/psdWriter.js.map +1 -1
  270. package/dist-es/text.d.ts +179 -179
  271. package/dist-es/text.js +552 -572
  272. package/dist-es/text.js.map +1 -1
  273. package/dist-es/utf8.d.ts +4 -6
  274. package/dist-es/utf8.js +156 -150
  275. package/dist-es/utf8.js.map +1 -1
  276. package/package.json +4 -3
  277. package/publish.js +24 -0
  278. package/src/additionalInfo.ts +15 -11
  279. package/src/helpers.ts +13 -3
  280. package/src/index.ts +4 -6
  281. package/src/psd.ts +4 -0
  282. package/src/psdReader.ts +136 -43
  283. package/src/psdWriter.ts +118 -24
  284. package/tsconfig-es6.json +2 -1
  285. package/tsconfig.json +5 -3
@@ -1,337 +1,335 @@
1
- function isWhitespace(char) {
2
- // ' ', '\n', '\r', '\t'
3
- return char === 32 || char === 10 || char === 13 || char === 9;
4
- }
5
- function isNumber(char) {
6
- // 0123456789.-
7
- return (char >= 48 && char <= 57) || char === 46 || char === 45;
8
- }
9
- export function parseEngineData(data) {
10
- var index = 0;
11
- function skipWhitespace() {
12
- while (index < data.length && isWhitespace(data[index])) {
13
- index++;
14
- }
15
- }
16
- function getTextByte() {
17
- var byte = data[index];
18
- index++;
19
- if (byte === 92) { // \
20
- byte = data[index];
21
- index++;
22
- }
23
- return byte;
24
- }
25
- function getText() {
26
- var result = '';
27
- if (data[index] === 41) { // )
28
- index++;
29
- return result;
30
- }
31
- // Strings start with utf-16 BOM
32
- if (data[index] !== 0xFE || data[index + 1] !== 0xFF) {
33
- throw new Error('Invalid utf-16 BOM');
34
- }
35
- index += 2;
36
- // ), ( and \ characters are escaped in ascii manner, remove the escapes before interpreting
37
- // the bytes as utf-16
38
- while (index < data.length && data[index] !== 41) { // )
39
- var high = getTextByte();
40
- var low = getTextByte();
41
- var char = (high << 8) | low;
42
- result += String.fromCharCode(char);
43
- }
44
- index++;
45
- return result;
46
- }
47
- var root = null;
48
- var stack = [];
49
- function pushContainer(value) {
50
- if (!stack.length) {
51
- stack.push(value);
52
- root = value;
53
- }
54
- else {
55
- pushValue(value);
56
- stack.push(value);
57
- }
58
- }
59
- function pushValue(value) {
60
- if (!stack.length)
61
- throw new Error('Invalid data');
62
- var top = stack[stack.length - 1];
63
- if (typeof top === 'string') {
64
- stack[stack.length - 2][top] = value;
65
- pop();
66
- }
67
- else if (Array.isArray(top)) {
68
- top.push(value);
69
- }
70
- else {
71
- throw new Error('Invalid data');
72
- }
73
- }
74
- function pushProperty(name) {
75
- if (!stack.length)
76
- pushContainer({});
77
- var top = stack[stack.length - 1];
78
- if (top && typeof top === 'string') {
79
- if (name === 'nil') {
80
- pushValue(null);
81
- }
82
- else {
83
- pushValue("/".concat(name));
84
- }
85
- }
86
- else if (top && typeof top === 'object') {
87
- stack.push(name);
88
- }
89
- else {
90
- throw new Error('Invalid data');
91
- }
92
- }
93
- function pop() {
94
- if (!stack.length)
95
- throw new Error('Invalid data');
96
- stack.pop();
97
- }
98
- skipWhitespace();
99
- var dataLength = data.length;
100
- while (dataLength > 0 && data[dataLength - 1] === 0)
101
- dataLength--; // trim 0 bytes from end
102
- while (index < dataLength) {
103
- var i = index;
104
- var char = data[i];
105
- if (char === 60 && data[i + 1] === 60) { // <<
106
- index += 2;
107
- pushContainer({});
108
- }
109
- else if (char === 62 && data[i + 1] === 62) { // >>
110
- index += 2;
111
- pop();
112
- }
113
- else if (char === 47) { // /
114
- index += 1;
115
- var start = index;
116
- while (index < data.length && !isWhitespace(data[index])) {
117
- index++;
118
- }
119
- var name_1 = '';
120
- for (var i_1 = start; i_1 < index; i_1++) {
121
- name_1 += String.fromCharCode(data[i_1]);
122
- }
123
- pushProperty(name_1);
124
- }
125
- else if (char === 40) { // (
126
- index += 1;
127
- pushValue(getText());
128
- }
129
- else if (char === 91) { // [
130
- index += 1;
131
- pushContainer([]);
132
- }
133
- else if (char === 93) { // ]
134
- index += 1;
135
- pop();
136
- }
137
- else if (char === 110 && data[i + 1] === 117 && data[i + 2] === 108 && data[i + 3] === 108) { // null
138
- index += 4;
139
- pushValue(null);
140
- }
141
- else if (char === 116 && data[i + 1] === 114 && data[i + 2] === 117 && data[i + 3] === 101) { // true
142
- index += 4;
143
- pushValue(true);
144
- }
145
- else if (char === 102 && data[i + 1] === 97 && data[i + 2] === 108 && data[i + 3] === 115 && data[i + 4] === 101) { // false
146
- index += 5;
147
- pushValue(false);
148
- }
149
- else if (isNumber(char)) {
150
- var value = '';
151
- while (index < data.length && isNumber(data[index])) {
152
- value += String.fromCharCode(data[index]);
153
- index++;
154
- }
155
- pushValue(parseFloat(value));
156
- }
157
- else {
158
- index += 1;
159
- console.log("Invalid token '".concat(String.fromCharCode(char), "' (").concat(char, ") at ").concat(index)
160
- // + ` near '${String.fromCharCode.apply(null, data.slice(index - 10, index + 20) as any)}'`
161
- // + ` data [${Array.from(data.slice(index - 10, index + 20)).join(', ')}]`
162
- );
163
- // throw new Error(`Invalid token ${String.fromCharCode(char)} at ${index}`);
164
- }
165
- skipWhitespace();
166
- }
167
- return root;
168
- }
169
- var floatKeys = [
170
- 'Axis', 'XY', 'Zone', 'WordSpacing', 'FirstLineIndent', 'GlyphSpacing', 'StartIndent', 'EndIndent', 'SpaceBefore',
171
- 'SpaceAfter', 'LetterSpacing', 'Values', 'GridSize', 'GridLeading', 'PointBase', 'BoxBounds', 'TransformPoint0', 'TransformPoint1',
172
- 'TransformPoint2', 'FontSize', 'Leading', 'HorizontalScale', 'VerticalScale', 'BaselineShift', 'Tsume',
173
- 'OutlineWidth', 'AutoLeading',
174
- ];
175
- var intArrays = ['RunLengthArray'];
176
- // TODO: handle /nil
177
- export function serializeEngineData(data, condensed) {
178
- if (condensed === void 0) { condensed = false; }
179
- var buffer = new Uint8Array(1024);
180
- var offset = 0;
181
- var indent = 0;
182
- function write(value) {
183
- if (offset >= buffer.length) {
184
- var newBuffer = new Uint8Array(buffer.length * 2);
185
- newBuffer.set(buffer);
186
- buffer = newBuffer;
187
- }
188
- buffer[offset] = value;
189
- offset++;
190
- }
191
- function writeString(value) {
192
- for (var i = 0; i < value.length; i++) {
193
- write(value.charCodeAt(i));
194
- }
195
- }
196
- function writeIndent() {
197
- if (condensed) {
198
- writeString(' ');
199
- }
200
- else {
201
- for (var i = 0; i < indent; i++) {
202
- writeString('\t');
203
- }
204
- }
205
- }
206
- function writeProperty(key, value) {
207
- writeIndent();
208
- writeString("/".concat(key));
209
- writeValue(value, key, true);
210
- if (!condensed)
211
- writeString('\n');
212
- }
213
- function serializeInt(value) {
214
- return value.toString();
215
- }
216
- function serializeFloat(value) {
217
- return value.toFixed(5)
218
- .replace(/(\d)0+$/g, '$1')
219
- .replace(/^0+\.([1-9])/g, '.$1')
220
- .replace(/^-0+\.0(\d)/g, '-.0$1');
221
- }
222
- function serializeNumber(value, key) {
223
- var isFloat = (key && floatKeys.indexOf(key) !== -1) || (value | 0) !== value;
224
- return isFloat ? serializeFloat(value) : serializeInt(value);
225
- }
226
- function getKeys(value) {
227
- var keys = Object.keys(value);
228
- if (keys.indexOf('98') !== -1)
229
- keys.unshift.apply(keys, keys.splice(keys.indexOf('99'), 1));
230
- if (keys.indexOf('99') !== -1)
231
- keys.unshift.apply(keys, keys.splice(keys.indexOf('99'), 1));
232
- return keys;
233
- }
234
- function writeStringByte(value) {
235
- if (value === 40 || value === 41 || value === 92) { // ( ) \
236
- write(92); // \
237
- }
238
- write(value);
239
- }
240
- function writeValue(value, key, inProperty) {
241
- if (inProperty === void 0) { inProperty = false; }
242
- function writePrefix() {
243
- if (inProperty) {
244
- writeString(' ');
245
- }
246
- else {
247
- writeIndent();
248
- }
249
- }
250
- if (value === null) {
251
- writePrefix();
252
- writeString(condensed ? '/nil' : 'null');
253
- }
254
- else if (typeof value === 'number') {
255
- writePrefix();
256
- writeString(serializeNumber(value, key));
257
- }
258
- else if (typeof value === 'boolean') {
259
- writePrefix();
260
- writeString(value ? 'true' : 'false');
261
- }
262
- else if (typeof value === 'string') {
263
- writePrefix();
264
- if ((key === '99' || key === '98') && value.charAt(0) === '/') {
265
- writeString(value);
266
- }
267
- else {
268
- writeString('(');
269
- write(0xfe);
270
- write(0xff);
271
- for (var i = 0; i < value.length; i++) {
272
- var code = value.charCodeAt(i);
273
- writeStringByte((code >> 8) & 0xff);
274
- writeStringByte(code & 0xff);
275
- }
276
- writeString(')');
277
- }
278
- }
279
- else if (Array.isArray(value)) {
280
- writePrefix();
281
- if (value.every(function (x) { return typeof x === 'number'; })) {
282
- writeString('[');
283
- var intArray = intArrays.indexOf(key) !== -1;
284
- for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
285
- var x = value_1[_i];
286
- writeString(' ');
287
- writeString(intArray ? serializeNumber(x) : serializeFloat(x));
288
- }
289
- writeString(' ]');
290
- }
291
- else {
292
- writeString('[');
293
- if (!condensed)
294
- writeString('\n');
295
- for (var _a = 0, value_2 = value; _a < value_2.length; _a++) {
296
- var x = value_2[_a];
297
- writeValue(x, key);
298
- if (!condensed)
299
- writeString('\n');
300
- }
301
- writeIndent();
302
- writeString(']');
303
- }
304
- }
305
- else if (typeof value === 'object') {
306
- if (inProperty && !condensed)
307
- writeString('\n');
308
- writeIndent();
309
- writeString('<<');
310
- if (!condensed)
311
- writeString('\n');
312
- indent++;
313
- for (var _b = 0, _c = getKeys(value); _b < _c.length; _b++) {
314
- var key_1 = _c[_b];
315
- writeProperty(key_1, value[key_1]);
316
- }
317
- indent--;
318
- writeIndent();
319
- writeString('>>');
320
- }
321
- return undefined;
322
- }
323
- if (condensed) {
324
- if (typeof data === 'object') {
325
- for (var _i = 0, _a = getKeys(data); _i < _a.length; _i++) {
326
- var key = _a[_i];
327
- writeProperty(key, data[key]);
328
- }
329
- }
330
- }
331
- else {
332
- writeString('\n\n');
333
- writeValue(data);
334
- }
335
- return buffer.slice(0, offset);
336
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseEngineData = parseEngineData;
4
+ exports.serializeEngineData = serializeEngineData;
5
+ function isWhitespace(char) {
6
+ // ' ', '\n', '\r', '\t'
7
+ return char === 32 || char === 10 || char === 13 || char === 9;
8
+ }
9
+ function isNumber(char) {
10
+ // 0123456789.-
11
+ return (char >= 48 && char <= 57) || char === 46 || char === 45;
12
+ }
13
+ function parseEngineData(data) {
14
+ let index = 0;
15
+ function skipWhitespace() {
16
+ while (index < data.length && isWhitespace(data[index])) {
17
+ index++;
18
+ }
19
+ }
20
+ function getTextByte() {
21
+ let byte = data[index];
22
+ index++;
23
+ if (byte === 92) { // \
24
+ byte = data[index];
25
+ index++;
26
+ }
27
+ return byte;
28
+ }
29
+ function getText() {
30
+ let result = '';
31
+ if (data[index] === 41) { // )
32
+ index++;
33
+ return result;
34
+ }
35
+ // Strings start with utf-16 BOM
36
+ if (data[index] !== 0xFE || data[index + 1] !== 0xFF) {
37
+ throw new Error('Invalid utf-16 BOM');
38
+ }
39
+ index += 2;
40
+ // ), ( and \ characters are escaped in ascii manner, remove the escapes before interpreting
41
+ // the bytes as utf-16
42
+ while (index < data.length && data[index] !== 41) { // )
43
+ const high = getTextByte();
44
+ const low = getTextByte();
45
+ const char = (high << 8) | low;
46
+ result += String.fromCharCode(char);
47
+ }
48
+ index++;
49
+ return result;
50
+ }
51
+ let root = null;
52
+ const stack = [];
53
+ function pushContainer(value) {
54
+ if (!stack.length) {
55
+ stack.push(value);
56
+ root = value;
57
+ }
58
+ else {
59
+ pushValue(value);
60
+ stack.push(value);
61
+ }
62
+ }
63
+ function pushValue(value) {
64
+ if (!stack.length)
65
+ throw new Error('Invalid data');
66
+ const top = stack[stack.length - 1];
67
+ if (typeof top === 'string') {
68
+ stack[stack.length - 2][top] = value;
69
+ pop();
70
+ }
71
+ else if (Array.isArray(top)) {
72
+ top.push(value);
73
+ }
74
+ else {
75
+ throw new Error('Invalid data');
76
+ }
77
+ }
78
+ function pushProperty(name) {
79
+ if (!stack.length)
80
+ pushContainer({});
81
+ const top = stack[stack.length - 1];
82
+ if (top && typeof top === 'string') {
83
+ if (name === 'nil') {
84
+ pushValue(null);
85
+ }
86
+ else {
87
+ pushValue(`/${name}`);
88
+ }
89
+ }
90
+ else if (top && typeof top === 'object') {
91
+ stack.push(name);
92
+ }
93
+ else {
94
+ throw new Error('Invalid data');
95
+ }
96
+ }
97
+ function pop() {
98
+ if (!stack.length)
99
+ throw new Error('Invalid data');
100
+ stack.pop();
101
+ }
102
+ skipWhitespace();
103
+ let dataLength = data.length;
104
+ while (dataLength > 0 && data[dataLength - 1] === 0)
105
+ dataLength--; // trim 0 bytes from end
106
+ while (index < dataLength) {
107
+ const i = index;
108
+ const char = data[i];
109
+ if (char === 60 && data[i + 1] === 60) { // <<
110
+ index += 2;
111
+ pushContainer({});
112
+ }
113
+ else if (char === 62 && data[i + 1] === 62) { // >>
114
+ index += 2;
115
+ pop();
116
+ }
117
+ else if (char === 47) { // /
118
+ index += 1;
119
+ const start = index;
120
+ while (index < data.length && !isWhitespace(data[index])) {
121
+ index++;
122
+ }
123
+ let name = '';
124
+ for (let i = start; i < index; i++) {
125
+ name += String.fromCharCode(data[i]);
126
+ }
127
+ pushProperty(name);
128
+ }
129
+ else if (char === 40) { // (
130
+ index += 1;
131
+ pushValue(getText());
132
+ }
133
+ else if (char === 91) { // [
134
+ index += 1;
135
+ pushContainer([]);
136
+ }
137
+ else if (char === 93) { // ]
138
+ index += 1;
139
+ pop();
140
+ }
141
+ else if (char === 110 && data[i + 1] === 117 && data[i + 2] === 108 && data[i + 3] === 108) { // null
142
+ index += 4;
143
+ pushValue(null);
144
+ }
145
+ else if (char === 116 && data[i + 1] === 114 && data[i + 2] === 117 && data[i + 3] === 101) { // true
146
+ index += 4;
147
+ pushValue(true);
148
+ }
149
+ else if (char === 102 && data[i + 1] === 97 && data[i + 2] === 108 && data[i + 3] === 115 && data[i + 4] === 101) { // false
150
+ index += 5;
151
+ pushValue(false);
152
+ }
153
+ else if (isNumber(char)) {
154
+ let value = '';
155
+ while (index < data.length && isNumber(data[index])) {
156
+ value += String.fromCharCode(data[index]);
157
+ index++;
158
+ }
159
+ pushValue(parseFloat(value));
160
+ }
161
+ else {
162
+ index += 1;
163
+ console.log(`Invalid token '${String.fromCharCode(char)}' (${char}) at ${index}`
164
+ // + ` near '${String.fromCharCode.apply(null, data.slice(index - 10, index + 20) as any)}'`
165
+ // + ` data [${Array.from(data.slice(index - 10, index + 20)).join(', ')}]`
166
+ );
167
+ // throw new Error(`Invalid token ${String.fromCharCode(char)} at ${index}`);
168
+ }
169
+ skipWhitespace();
170
+ }
171
+ return root;
172
+ }
173
+ const floatKeys = [
174
+ 'Axis', 'XY', 'Zone', 'WordSpacing', 'FirstLineIndent', 'GlyphSpacing', 'StartIndent', 'EndIndent', 'SpaceBefore',
175
+ 'SpaceAfter', 'LetterSpacing', 'Values', 'GridSize', 'GridLeading', 'PointBase', 'BoxBounds', 'TransformPoint0', 'TransformPoint1',
176
+ 'TransformPoint2', 'FontSize', 'Leading', 'HorizontalScale', 'VerticalScale', 'BaselineShift', 'Tsume',
177
+ 'OutlineWidth', 'AutoLeading',
178
+ ];
179
+ const intArrays = ['RunLengthArray'];
180
+ // TODO: handle /nil
181
+ function serializeEngineData(data, condensed = false) {
182
+ let buffer = new Uint8Array(1024);
183
+ let offset = 0;
184
+ let indent = 0;
185
+ function write(value) {
186
+ if (offset >= buffer.length) {
187
+ const newBuffer = new Uint8Array(buffer.length * 2);
188
+ newBuffer.set(buffer);
189
+ buffer = newBuffer;
190
+ }
191
+ buffer[offset] = value;
192
+ offset++;
193
+ }
194
+ function writeString(value) {
195
+ for (let i = 0; i < value.length; i++) {
196
+ write(value.charCodeAt(i));
197
+ }
198
+ }
199
+ function writeIndent() {
200
+ if (condensed) {
201
+ writeString(' ');
202
+ }
203
+ else {
204
+ for (let i = 0; i < indent; i++) {
205
+ writeString('\t');
206
+ }
207
+ }
208
+ }
209
+ function writeProperty(key, value) {
210
+ writeIndent();
211
+ writeString(`/${key}`);
212
+ writeValue(value, key, true);
213
+ if (!condensed)
214
+ writeString('\n');
215
+ }
216
+ function serializeInt(value) {
217
+ return value.toString();
218
+ }
219
+ function serializeFloat(value) {
220
+ return value.toFixed(5)
221
+ .replace(/(\d)0+$/g, '$1')
222
+ .replace(/^0+\.([1-9])/g, '.$1')
223
+ .replace(/^-0+\.0(\d)/g, '-.0$1');
224
+ }
225
+ function serializeNumber(value, key) {
226
+ const isFloat = (key && floatKeys.indexOf(key) !== -1) || (value | 0) !== value;
227
+ return isFloat ? serializeFloat(value) : serializeInt(value);
228
+ }
229
+ function getKeys(value) {
230
+ const keys = Object.keys(value);
231
+ if (keys.indexOf('98') !== -1)
232
+ keys.unshift(...keys.splice(keys.indexOf('99'), 1));
233
+ if (keys.indexOf('99') !== -1)
234
+ keys.unshift(...keys.splice(keys.indexOf('99'), 1));
235
+ return keys;
236
+ }
237
+ function writeStringByte(value) {
238
+ if (value === 40 || value === 41 || value === 92) { // ( ) \
239
+ write(92); // \
240
+ }
241
+ write(value);
242
+ }
243
+ function writeValue(value, key, inProperty = false) {
244
+ function writePrefix() {
245
+ if (inProperty) {
246
+ writeString(' ');
247
+ }
248
+ else {
249
+ writeIndent();
250
+ }
251
+ }
252
+ if (value === null) {
253
+ writePrefix();
254
+ writeString(condensed ? '/nil' : 'null');
255
+ }
256
+ else if (typeof value === 'number') {
257
+ writePrefix();
258
+ writeString(serializeNumber(value, key));
259
+ }
260
+ else if (typeof value === 'boolean') {
261
+ writePrefix();
262
+ writeString(value ? 'true' : 'false');
263
+ }
264
+ else if (typeof value === 'string') {
265
+ writePrefix();
266
+ if ((key === '99' || key === '98') && value.charAt(0) === '/') {
267
+ writeString(value);
268
+ }
269
+ else {
270
+ writeString('(');
271
+ write(0xfe);
272
+ write(0xff);
273
+ for (let i = 0; i < value.length; i++) {
274
+ const code = value.charCodeAt(i);
275
+ writeStringByte((code >> 8) & 0xff);
276
+ writeStringByte(code & 0xff);
277
+ }
278
+ writeString(')');
279
+ }
280
+ }
281
+ else if (Array.isArray(value)) {
282
+ writePrefix();
283
+ if (value.every(x => typeof x === 'number')) {
284
+ writeString('[');
285
+ const intArray = intArrays.indexOf(key) !== -1;
286
+ for (const x of value) {
287
+ writeString(' ');
288
+ writeString(intArray ? serializeNumber(x) : serializeFloat(x));
289
+ }
290
+ writeString(' ]');
291
+ }
292
+ else {
293
+ writeString('[');
294
+ if (!condensed)
295
+ writeString('\n');
296
+ for (const x of value) {
297
+ writeValue(x, key);
298
+ if (!condensed)
299
+ writeString('\n');
300
+ }
301
+ writeIndent();
302
+ writeString(']');
303
+ }
304
+ }
305
+ else if (typeof value === 'object') {
306
+ if (inProperty && !condensed)
307
+ writeString('\n');
308
+ writeIndent();
309
+ writeString('<<');
310
+ if (!condensed)
311
+ writeString('\n');
312
+ indent++;
313
+ for (const key of getKeys(value)) {
314
+ writeProperty(key, value[key]);
315
+ }
316
+ indent--;
317
+ writeIndent();
318
+ writeString('>>');
319
+ }
320
+ return undefined;
321
+ }
322
+ if (condensed) {
323
+ if (typeof data === 'object') {
324
+ for (const key of getKeys(data)) {
325
+ writeProperty(key, data[key]);
326
+ }
327
+ }
328
+ }
329
+ else {
330
+ writeString('\n\n');
331
+ writeValue(data);
332
+ }
333
+ return buffer.slice(0, offset);
334
+ }
337
335
  //# sourceMappingURL=engineData.js.map