@antv/util 3.0.0 → 3.1.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 (489) hide show
  1. package/README.md +167 -4
  2. package/dist/util.min.js +1 -1
  3. package/esm/color/arr2rgb.js +3 -3
  4. package/esm/color/arr2rgb.js.map +1 -1
  5. package/esm/color/gradient.js +9 -9
  6. package/esm/color/gradient.js.map +1 -1
  7. package/esm/color/tocssgradient.js +18 -18
  8. package/esm/color/tocssgradient.js.map +1 -1
  9. package/esm/color/torgb.js +6 -6
  10. package/esm/color/torgb.js.map +1 -1
  11. package/esm/helper/to-radian.js +1 -1
  12. package/esm/helper/to-radian.js.map +1 -1
  13. package/esm/matrix/index.js +8 -8
  14. package/esm/matrix/index.js.map +1 -1
  15. package/esm/path/convert/path-2-absolute.d.ts +2 -0
  16. package/esm/path/convert/path-2-absolute.js +83 -0
  17. package/esm/path/convert/path-2-absolute.js.map +1 -0
  18. package/esm/path/convert/path-2-curve.d.ts +2 -0
  19. package/esm/path/convert/path-2-curve.js +56 -0
  20. package/esm/path/convert/path-2-curve.js.map +1 -0
  21. package/esm/path/convert/path-2-string.d.ts +6 -0
  22. package/esm/path/convert/path-2-string.js +11 -0
  23. package/esm/path/convert/path-2-string.js.map +1 -0
  24. package/esm/path/index.d.ts +17 -16
  25. package/esm/path/index.js +17 -16
  26. package/esm/path/index.js.map +1 -1
  27. package/esm/path/parser/finalize-segment.d.ts +5 -0
  28. package/esm/path/parser/finalize-segment.js +27 -0
  29. package/esm/path/parser/finalize-segment.js.map +1 -0
  30. package/esm/path/parser/is-arc-command.d.ts +4 -0
  31. package/esm/path/parser/is-arc-command.js +7 -0
  32. package/esm/path/parser/is-arc-command.js.map +1 -0
  33. package/esm/path/parser/is-digit-start.d.ts +6 -0
  34. package/esm/path/parser/is-digit-start.js +11 -0
  35. package/esm/path/parser/is-digit-start.js.map +1 -0
  36. package/esm/path/parser/is-path-command.d.ts +4 -0
  37. package/esm/path/parser/is-path-command.js +23 -0
  38. package/esm/path/parser/is-path-command.js.map +1 -0
  39. package/esm/path/parser/is-space.d.ts +4 -0
  40. package/esm/path/parser/is-space.js +22 -0
  41. package/esm/path/parser/is-space.js.map +1 -0
  42. package/esm/path/parser/params-count.d.ts +13 -0
  43. package/esm/path/parser/params-count.js +14 -0
  44. package/esm/path/parser/params-count.js.map +1 -0
  45. package/esm/path/parser/params-parser.d.ts +10 -0
  46. package/esm/path/parser/params-parser.js +11 -0
  47. package/esm/path/parser/params-parser.js.map +1 -0
  48. package/esm/path/parser/parse-path-string.d.ts +6 -0
  49. package/esm/path/parser/parse-path-string.js +21 -0
  50. package/esm/path/parser/parse-path-string.js.map +1 -0
  51. package/esm/path/parser/path-parser.d.ts +16 -0
  52. package/esm/path/parser/path-parser.js +18 -0
  53. package/esm/path/parser/path-parser.js.map +1 -0
  54. package/esm/path/parser/scan-flag.d.ts +6 -0
  55. package/esm/path/parser/scan-flag.js +20 -0
  56. package/esm/path/parser/scan-flag.js.map +1 -0
  57. package/esm/path/parser/scan-param.d.ts +6 -0
  58. package/esm/path/parser/scan-param.js +83 -0
  59. package/esm/path/parser/scan-param.js.map +1 -0
  60. package/esm/path/parser/scan-segment.d.ts +6 -0
  61. package/esm/path/parser/scan-segment.js +57 -0
  62. package/esm/path/parser/scan-segment.js.map +1 -0
  63. package/esm/path/parser/skip-spaces.d.ts +7 -0
  64. package/esm/path/parser/skip-spaces.js +13 -0
  65. package/esm/path/parser/skip-spaces.js.map +1 -0
  66. package/esm/path/process/arc-2-cubic.d.ts +7 -1
  67. package/esm/path/process/arc-2-cubic.js +276 -133
  68. package/esm/path/process/arc-2-cubic.js.map +1 -1
  69. package/esm/path/process/clone-path.d.ts +2 -0
  70. package/esm/path/process/clone-path.js +4 -0
  71. package/esm/path/process/clone-path.js.map +1 -0
  72. package/esm/path/process/fix-arc.d.ts +2 -0
  73. package/esm/path/process/fix-arc.js +16 -0
  74. package/esm/path/process/fix-arc.js.map +1 -0
  75. package/esm/path/process/line-2-cubic.js +17 -32
  76. package/esm/path/process/line-2-cubic.js.map +1 -1
  77. package/esm/path/process/normalize-path.d.ts +8 -0
  78. package/esm/path/process/normalize-path.js +35 -0
  79. package/esm/path/process/normalize-path.js.map +1 -0
  80. package/esm/path/process/normalize-segment.d.ts +6 -0
  81. package/esm/path/process/normalize-segment.js +42 -0
  82. package/esm/path/process/normalize-segment.js.map +1 -0
  83. package/esm/path/process/quad-2-cubic.js +2 -2
  84. package/esm/path/process/quad-2-cubic.js.map +1 -1
  85. package/esm/path/process/reverse-curve.d.ts +2 -0
  86. package/esm/path/process/reverse-curve.js +13 -0
  87. package/esm/path/process/reverse-curve.js.map +1 -0
  88. package/esm/path/process/round-path.d.ts +6 -0
  89. package/esm/path/process/round-path.js +20 -0
  90. package/esm/path/process/round-path.js.map +1 -0
  91. package/esm/path/process/segment-2-cubic.d.ts +2 -2
  92. package/esm/path/process/segment-2-cubic.js +23 -19
  93. package/esm/path/process/segment-2-cubic.js.map +1 -1
  94. package/esm/path/types.d.ts +114 -17
  95. package/esm/path/util/distance-square-root.d.ts +1 -0
  96. package/esm/path/util/distance-square-root.js +4 -0
  97. package/esm/path/util/distance-square-root.js.map +1 -0
  98. package/esm/path/util/equalize-segments.d.ts +2 -0
  99. package/esm/path/util/equalize-segments.js +68 -0
  100. package/esm/path/util/equalize-segments.js.map +1 -0
  101. package/esm/path/util/get-draw-direction.d.ts +2 -0
  102. package/esm/path/util/get-draw-direction.js +5 -0
  103. package/esm/path/util/get-draw-direction.js.map +1 -0
  104. package/esm/path/util/get-path-area.d.ts +8 -0
  105. package/esm/path/util/get-path-area.js +68 -0
  106. package/esm/path/util/get-path-area.js.map +1 -0
  107. package/esm/path/util/get-path-bbox-total-length.d.ts +5 -0
  108. package/esm/path/util/get-path-bbox-total-length.js +37 -0
  109. package/esm/path/util/get-path-bbox-total-length.js.map +1 -0
  110. package/esm/path/util/get-path-bbox.d.ts +5 -0
  111. package/esm/path/util/get-path-bbox.js +35 -0
  112. package/esm/path/util/get-path-bbox.js.map +1 -0
  113. package/esm/path/util/get-point-at-length.d.ts +5 -0
  114. package/esm/path/util/get-point-at-length.js +8 -0
  115. package/esm/path/util/get-point-at-length.js.map +1 -0
  116. package/esm/path/util/get-properties-at-length.d.ts +6 -0
  117. package/esm/path/util/get-properties-at-length.js +58 -0
  118. package/esm/path/util/get-properties-at-length.js.map +1 -0
  119. package/esm/path/util/get-properties-at-point.d.ts +7 -0
  120. package/esm/path/util/get-properties-at-point.js +69 -0
  121. package/esm/path/util/get-properties-at-point.js.map +1 -0
  122. package/esm/path/util/get-rotated-curve.d.ts +2 -0
  123. package/esm/path/util/get-rotated-curve.js +34 -0
  124. package/esm/path/util/get-rotated-curve.js.map +1 -0
  125. package/esm/path/util/get-total-length.d.ts +8 -0
  126. package/esm/path/util/get-total-length.js +11 -0
  127. package/esm/path/util/get-total-length.js.map +1 -0
  128. package/esm/path/util/is-absolute-array.d.ts +6 -0
  129. package/esm/path/util/is-absolute-array.js +11 -0
  130. package/esm/path/util/is-absolute-array.js.map +1 -0
  131. package/esm/path/util/is-curve-array.d.ts +9 -0
  132. package/esm/path/util/is-curve-array.js +12 -0
  133. package/esm/path/util/is-curve-array.js.map +1 -0
  134. package/esm/path/util/is-normalized-array.d.ts +7 -0
  135. package/esm/path/util/is-normalized-array.js +10 -0
  136. package/esm/path/util/is-normalized-array.js.map +1 -0
  137. package/esm/path/util/is-path-array.d.ts +5 -0
  138. package/esm/path/util/is-path-array.js +12 -0
  139. package/esm/path/util/is-path-array.js.map +1 -0
  140. package/esm/path/util/is-point-in-stroke.d.ts +5 -0
  141. package/esm/path/util/is-point-in-stroke.js +9 -0
  142. package/esm/path/util/is-point-in-stroke.js.map +1 -0
  143. package/esm/path/util/mid-point.d.ts +1 -0
  144. package/esm/path/util/mid-point.js +8 -0
  145. package/esm/path/util/mid-point.js.map +1 -0
  146. package/esm/path/util/path-length-factory.d.ts +7 -0
  147. package/esm/path/util/path-length-factory.js +94 -0
  148. package/esm/path/util/path-length-factory.js.map +1 -0
  149. package/esm/path/util/rotate-vector.d.ts +4 -0
  150. package/esm/path/util/rotate-vector.js +6 -0
  151. package/esm/path/util/rotate-vector.js.map +1 -0
  152. package/esm/path/util/segment-arc-factory.d.ts +6 -0
  153. package/esm/path/util/segment-arc-factory.js +135 -0
  154. package/esm/path/util/segment-arc-factory.js.map +1 -0
  155. package/esm/path/util/segment-cubic-factory.d.ts +6 -0
  156. package/esm/path/util/segment-cubic-factory.js +63 -0
  157. package/esm/path/util/segment-cubic-factory.js.map +1 -0
  158. package/esm/path/util/segment-line-factory.d.ts +6 -0
  159. package/esm/path/util/segment-line-factory.js +36 -0
  160. package/esm/path/util/segment-line-factory.js.map +1 -0
  161. package/esm/path/util/segment-quad-factory.d.ts +6 -0
  162. package/esm/path/util/segment-quad-factory.js +65 -0
  163. package/esm/path/util/segment-quad-factory.js.map +1 -0
  164. package/lib/color/arr2rgb.js +3 -3
  165. package/lib/color/arr2rgb.js.map +1 -1
  166. package/lib/color/gradient.js +12 -12
  167. package/lib/color/gradient.js.map +1 -1
  168. package/lib/color/tocssgradient.js +18 -18
  169. package/lib/color/tocssgradient.js.map +1 -1
  170. package/lib/color/torgb.js +7 -7
  171. package/lib/color/torgb.js.map +1 -1
  172. package/lib/helper/to-radian.js +1 -1
  173. package/lib/helper/to-radian.js.map +1 -1
  174. package/lib/matrix/index.js +9 -9
  175. package/lib/matrix/index.js.map +1 -1
  176. package/lib/path/convert/path-2-absolute.d.ts +2 -0
  177. package/lib/path/convert/path-2-absolute.js +87 -0
  178. package/lib/path/convert/path-2-absolute.js.map +1 -0
  179. package/lib/path/convert/path-2-curve.d.ts +2 -0
  180. package/lib/path/convert/path-2-curve.js +60 -0
  181. package/lib/path/convert/path-2-curve.js.map +1 -0
  182. package/lib/path/convert/path-2-string.d.ts +6 -0
  183. package/lib/path/convert/path-2-string.js +15 -0
  184. package/lib/path/convert/path-2-string.js.map +1 -0
  185. package/lib/path/index.d.ts +17 -16
  186. package/lib/path/index.js +42 -31
  187. package/lib/path/index.js.map +1 -1
  188. package/lib/path/parser/finalize-segment.d.ts +5 -0
  189. package/lib/path/parser/finalize-segment.js +31 -0
  190. package/lib/path/parser/finalize-segment.js.map +1 -0
  191. package/lib/path/parser/is-arc-command.d.ts +4 -0
  192. package/lib/path/parser/is-arc-command.js +11 -0
  193. package/lib/path/parser/is-arc-command.js.map +1 -0
  194. package/lib/path/parser/is-digit-start.d.ts +6 -0
  195. package/lib/path/parser/is-digit-start.js +16 -0
  196. package/lib/path/parser/is-digit-start.js.map +1 -0
  197. package/lib/path/parser/is-path-command.d.ts +4 -0
  198. package/lib/path/parser/is-path-command.js +27 -0
  199. package/lib/path/parser/is-path-command.js.map +1 -0
  200. package/lib/path/parser/is-space.d.ts +4 -0
  201. package/lib/path/parser/is-space.js +26 -0
  202. package/lib/path/parser/is-space.js.map +1 -0
  203. package/lib/path/parser/params-count.d.ts +13 -0
  204. package/lib/path/parser/params-count.js +17 -0
  205. package/lib/path/parser/params-count.js.map +1 -0
  206. package/lib/path/parser/params-parser.d.ts +10 -0
  207. package/lib/path/parser/params-parser.js +14 -0
  208. package/lib/path/parser/params-parser.js.map +1 -0
  209. package/lib/path/parser/parse-path-string.d.ts +6 -0
  210. package/lib/path/parser/parse-path-string.js +25 -0
  211. package/lib/path/parser/parse-path-string.js.map +1 -0
  212. package/lib/path/parser/path-parser.d.ts +16 -0
  213. package/lib/path/parser/path-parser.js +22 -0
  214. package/lib/path/parser/path-parser.js.map +1 -0
  215. package/lib/path/parser/scan-flag.d.ts +6 -0
  216. package/lib/path/parser/scan-flag.js +24 -0
  217. package/lib/path/parser/scan-flag.js.map +1 -0
  218. package/lib/path/parser/scan-param.d.ts +6 -0
  219. package/lib/path/parser/scan-param.js +87 -0
  220. package/lib/path/parser/scan-param.js.map +1 -0
  221. package/lib/path/parser/scan-segment.d.ts +6 -0
  222. package/lib/path/parser/scan-segment.js +61 -0
  223. package/lib/path/parser/scan-segment.js.map +1 -0
  224. package/lib/path/parser/skip-spaces.d.ts +7 -0
  225. package/lib/path/parser/skip-spaces.js +17 -0
  226. package/lib/path/parser/skip-spaces.js.map +1 -0
  227. package/lib/path/process/arc-2-cubic.d.ts +7 -1
  228. package/lib/path/process/arc-2-cubic.js +276 -133
  229. package/lib/path/process/arc-2-cubic.js.map +1 -1
  230. package/lib/path/process/clone-path.d.ts +2 -0
  231. package/lib/path/process/clone-path.js +8 -0
  232. package/lib/path/process/clone-path.js.map +1 -0
  233. package/lib/path/process/fix-arc.d.ts +2 -0
  234. package/lib/path/process/fix-arc.js +20 -0
  235. package/lib/path/process/fix-arc.js.map +1 -0
  236. package/lib/path/process/line-2-cubic.js +17 -32
  237. package/lib/path/process/line-2-cubic.js.map +1 -1
  238. package/lib/path/process/normalize-path.d.ts +8 -0
  239. package/lib/path/process/normalize-path.js +39 -0
  240. package/lib/path/process/normalize-path.js.map +1 -0
  241. package/lib/path/process/normalize-segment.d.ts +6 -0
  242. package/lib/path/process/normalize-segment.js +46 -0
  243. package/lib/path/process/normalize-segment.js.map +1 -0
  244. package/lib/path/process/quad-2-cubic.js +2 -2
  245. package/lib/path/process/quad-2-cubic.js.map +1 -1
  246. package/lib/path/process/reverse-curve.d.ts +2 -0
  247. package/lib/path/process/reverse-curve.js +17 -0
  248. package/lib/path/process/reverse-curve.js.map +1 -0
  249. package/lib/path/process/round-path.d.ts +6 -0
  250. package/lib/path/process/round-path.js +24 -0
  251. package/lib/path/process/round-path.js.map +1 -0
  252. package/lib/path/process/segment-2-cubic.d.ts +2 -2
  253. package/lib/path/process/segment-2-cubic.js +26 -22
  254. package/lib/path/process/segment-2-cubic.js.map +1 -1
  255. package/lib/path/types.d.ts +114 -17
  256. package/lib/path/util/distance-square-root.d.ts +1 -0
  257. package/lib/path/util/distance-square-root.js +8 -0
  258. package/lib/path/util/distance-square-root.js.map +1 -0
  259. package/lib/path/util/equalize-segments.d.ts +2 -0
  260. package/lib/path/util/equalize-segments.js +72 -0
  261. package/lib/path/util/equalize-segments.js.map +1 -0
  262. package/lib/path/util/get-draw-direction.d.ts +2 -0
  263. package/lib/path/util/get-draw-direction.js +9 -0
  264. package/lib/path/util/get-draw-direction.js.map +1 -0
  265. package/lib/path/util/get-path-area.d.ts +8 -0
  266. package/lib/path/util/get-path-area.js +72 -0
  267. package/lib/path/util/get-path-area.js.map +1 -0
  268. package/lib/path/util/get-path-bbox-total-length.d.ts +5 -0
  269. package/lib/path/util/get-path-bbox-total-length.js +41 -0
  270. package/lib/path/util/get-path-bbox-total-length.js.map +1 -0
  271. package/lib/path/util/get-path-bbox.d.ts +5 -0
  272. package/lib/path/util/get-path-bbox.js +39 -0
  273. package/lib/path/util/get-path-bbox.js.map +1 -0
  274. package/lib/path/util/get-point-at-length.d.ts +5 -0
  275. package/lib/path/util/get-point-at-length.js +12 -0
  276. package/lib/path/util/get-point-at-length.js.map +1 -0
  277. package/lib/path/util/get-properties-at-length.d.ts +6 -0
  278. package/lib/path/util/get-properties-at-length.js +62 -0
  279. package/lib/path/util/get-properties-at-length.js.map +1 -0
  280. package/lib/path/util/get-properties-at-point.d.ts +7 -0
  281. package/lib/path/util/get-properties-at-point.js +73 -0
  282. package/lib/path/util/get-properties-at-point.js.map +1 -0
  283. package/lib/path/util/get-rotated-curve.d.ts +2 -0
  284. package/lib/path/util/get-rotated-curve.js +38 -0
  285. package/lib/path/util/get-rotated-curve.js.map +1 -0
  286. package/lib/path/util/get-total-length.d.ts +8 -0
  287. package/lib/path/util/get-total-length.js +15 -0
  288. package/lib/path/util/get-total-length.js.map +1 -0
  289. package/lib/path/util/is-absolute-array.d.ts +6 -0
  290. package/lib/path/util/is-absolute-array.js +15 -0
  291. package/lib/path/util/is-absolute-array.js.map +1 -0
  292. package/lib/path/util/is-curve-array.d.ts +9 -0
  293. package/lib/path/util/is-curve-array.js +16 -0
  294. package/lib/path/util/is-curve-array.js.map +1 -0
  295. package/lib/path/util/is-normalized-array.d.ts +7 -0
  296. package/lib/path/util/is-normalized-array.js +14 -0
  297. package/lib/path/util/is-normalized-array.js.map +1 -0
  298. package/lib/path/util/is-path-array.d.ts +5 -0
  299. package/lib/path/util/is-path-array.js +16 -0
  300. package/lib/path/util/is-path-array.js.map +1 -0
  301. package/lib/path/util/is-point-in-stroke.d.ts +5 -0
  302. package/lib/path/util/is-point-in-stroke.js +13 -0
  303. package/lib/path/util/is-point-in-stroke.js.map +1 -0
  304. package/lib/path/util/mid-point.d.ts +1 -0
  305. package/lib/path/util/mid-point.js +12 -0
  306. package/lib/path/util/mid-point.js.map +1 -0
  307. package/lib/path/util/path-length-factory.d.ts +7 -0
  308. package/lib/path/util/path-length-factory.js +98 -0
  309. package/lib/path/util/path-length-factory.js.map +1 -0
  310. package/lib/path/util/rotate-vector.d.ts +4 -0
  311. package/lib/path/util/rotate-vector.js +10 -0
  312. package/lib/path/util/rotate-vector.js.map +1 -0
  313. package/lib/path/util/segment-arc-factory.d.ts +6 -0
  314. package/lib/path/util/segment-arc-factory.js +139 -0
  315. package/lib/path/util/segment-arc-factory.js.map +1 -0
  316. package/lib/path/util/segment-cubic-factory.d.ts +6 -0
  317. package/lib/path/util/segment-cubic-factory.js +67 -0
  318. package/lib/path/util/segment-cubic-factory.js.map +1 -0
  319. package/lib/path/util/segment-line-factory.d.ts +6 -0
  320. package/lib/path/util/segment-line-factory.js +40 -0
  321. package/lib/path/util/segment-line-factory.js.map +1 -0
  322. package/lib/path/util/segment-quad-factory.d.ts +6 -0
  323. package/lib/path/util/segment-quad-factory.js +69 -0
  324. package/lib/path/util/segment-quad-factory.js.map +1 -0
  325. package/package.json +1 -1
  326. package/src/.DS_Store +0 -0
  327. package/src/path/.DS_Store +0 -0
  328. package/src/path/convert/path-2-absolute.ts +90 -0
  329. package/src/path/convert/path-2-curve.ts +68 -0
  330. package/src/path/convert/path-2-string.ts +12 -0
  331. package/src/path/index.ts +18 -16
  332. package/src/path/parser/finalize-segment.ts +30 -0
  333. package/src/path/parser/is-arc-command.ts +6 -0
  334. package/src/path/parser/is-digit-start.ts +13 -0
  335. package/src/path/parser/is-path-command.ts +22 -0
  336. package/src/path/parser/is-space.ts +23 -0
  337. package/src/path/parser/params-count.ts +13 -0
  338. package/src/path/parser/params-parser.ts +10 -0
  339. package/src/path/parser/parse-path-string.ts +26 -0
  340. package/src/path/parser/path-parser.ts +35 -0
  341. package/src/path/parser/scan-flag.ts +24 -0
  342. package/src/path/parser/scan-param.ts +98 -0
  343. package/src/path/parser/scan-segment.ts +68 -0
  344. package/src/path/parser/skip-spaces.ts +14 -0
  345. package/src/path/process/arc-2-cubic.ts +332 -215
  346. package/src/path/process/clone-path.ts +5 -0
  347. package/src/path/process/fix-arc.ts +17 -0
  348. package/src/path/process/line-2-cubic.ts +17 -33
  349. package/src/path/process/normalize-path.ts +42 -0
  350. package/src/path/process/normalize-segment.ts +42 -0
  351. package/src/path/process/reverse-curve.ts +18 -0
  352. package/src/path/process/round-path.ts +22 -0
  353. package/src/path/process/segment-2-cubic.ts +28 -27
  354. package/src/path/types.ts +190 -17
  355. package/src/path/util/distance-square-root.ts +3 -0
  356. package/src/path/util/equalize-segments.ts +79 -0
  357. package/src/path/util/get-draw-direction.ts +6 -0
  358. package/src/path/util/get-path-area.ts +83 -0
  359. package/src/path/util/get-path-bbox-total-length.ts +45 -0
  360. package/src/path/util/get-path-bbox.ts +42 -0
  361. package/src/path/util/get-point-at-length.ts +9 -0
  362. package/src/path/util/get-properties-at-length.ts +65 -0
  363. package/src/path/util/get-properties-at-point.ts +73 -0
  364. package/src/path/util/get-rotated-curve.ts +42 -0
  365. package/src/path/util/get-total-length.ts +12 -0
  366. package/src/path/util/is-absolute-array.ts +14 -0
  367. package/src/path/util/is-curve-array.ts +13 -0
  368. package/src/path/util/is-normalized-array.ts +11 -0
  369. package/src/path/util/is-path-array.ts +15 -0
  370. package/src/path/util/is-point-in-stroke.ts +10 -0
  371. package/src/path/util/mid-point.ts +7 -0
  372. package/src/path/util/path-length-factory.ts +98 -0
  373. package/src/path/util/rotate-vector.ts +5 -0
  374. package/src/path/util/segment-arc-factory.ts +186 -0
  375. package/src/path/util/segment-cubic-factory.ts +92 -0
  376. package/src/path/util/segment-line-factory.ts +37 -0
  377. package/src/path/util/segment-quad-factory.ts +90 -0
  378. package/esm/path/catmull-rom-2-bezier.d.ts +0 -10
  379. package/esm/path/catmull-rom-2-bezier.js +0 -115
  380. package/esm/path/catmull-rom-2-bezier.js.map +0 -1
  381. package/esm/path/fill-path-by-diff.d.ts +0 -5
  382. package/esm/path/fill-path-by-diff.js +0 -110
  383. package/esm/path/fill-path-by-diff.js.map +0 -1
  384. package/esm/path/fill-path.d.ts +0 -1
  385. package/esm/path/fill-path.js +0 -129
  386. package/esm/path/fill-path.js.map +0 -1
  387. package/esm/path/format-path.d.ts +0 -1
  388. package/esm/path/format-path.js +0 -139
  389. package/esm/path/format-path.js.map +0 -1
  390. package/esm/path/get-arc-params.d.ts +0 -17
  391. package/esm/path/get-arc-params.js +0 -90
  392. package/esm/path/get-arc-params.js.map +0 -1
  393. package/esm/path/get-line-intersect.d.ts +0 -14
  394. package/esm/path/get-line-intersect.js +0 -33
  395. package/esm/path/get-line-intersect.js.map +0 -1
  396. package/esm/path/is-polygons-intersect.d.ts +0 -1
  397. package/esm/path/is-polygons-intersect.js +0 -81
  398. package/esm/path/is-polygons-intersect.js.map +0 -1
  399. package/esm/path/parse-path-array.d.ts +0 -1
  400. package/esm/path/parse-path-array.js +0 -5
  401. package/esm/path/parse-path-array.js.map +0 -1
  402. package/esm/path/parse-path-string.d.ts +0 -1
  403. package/esm/path/parse-path-string.js +0 -57
  404. package/esm/path/parse-path-string.js.map +0 -1
  405. package/esm/path/parse-path.d.ts +0 -1
  406. package/esm/path/parse-path.js +0 -33
  407. package/esm/path/parse-path.js.map +0 -1
  408. package/esm/path/path-2-absolute.d.ts +0 -1
  409. package/esm/path/path-2-absolute.js +0 -124
  410. package/esm/path/path-2-absolute.js.map +0 -1
  411. package/esm/path/path-2-curve.d.ts +0 -2
  412. package/esm/path/path-2-curve.js +0 -63
  413. package/esm/path/path-2-curve.js.map +0 -1
  414. package/esm/path/path-2-segments.d.ts +0 -1
  415. package/esm/path/path-2-segments.js +0 -138
  416. package/esm/path/path-2-segments.js.map +0 -1
  417. package/esm/path/path-intersection.d.ts +0 -9
  418. package/esm/path/path-intersection.js +0 -366
  419. package/esm/path/path-intersection.js.map +0 -1
  420. package/esm/path/point-in-polygon.d.ts +0 -5
  421. package/esm/path/point-in-polygon.js +0 -49
  422. package/esm/path/point-in-polygon.js.map +0 -1
  423. package/esm/path/rect-path.d.ts +0 -4
  424. package/esm/path/rect-path.js +0 -19
  425. package/esm/path/rect-path.js.map +0 -1
  426. package/lib/path/catmull-rom-2-bezier.d.ts +0 -10
  427. package/lib/path/catmull-rom-2-bezier.js +0 -119
  428. package/lib/path/catmull-rom-2-bezier.js.map +0 -1
  429. package/lib/path/fill-path-by-diff.d.ts +0 -5
  430. package/lib/path/fill-path-by-diff.js +0 -117
  431. package/lib/path/fill-path-by-diff.js.map +0 -1
  432. package/lib/path/fill-path.d.ts +0 -1
  433. package/lib/path/fill-path.js +0 -133
  434. package/lib/path/fill-path.js.map +0 -1
  435. package/lib/path/format-path.d.ts +0 -1
  436. package/lib/path/format-path.js +0 -143
  437. package/lib/path/format-path.js.map +0 -1
  438. package/lib/path/get-arc-params.d.ts +0 -17
  439. package/lib/path/get-arc-params.js +0 -95
  440. package/lib/path/get-arc-params.js.map +0 -1
  441. package/lib/path/get-line-intersect.d.ts +0 -14
  442. package/lib/path/get-line-intersect.js +0 -37
  443. package/lib/path/get-line-intersect.js.map +0 -1
  444. package/lib/path/is-polygons-intersect.d.ts +0 -1
  445. package/lib/path/is-polygons-intersect.js +0 -85
  446. package/lib/path/is-polygons-intersect.js.map +0 -1
  447. package/lib/path/parse-path-array.d.ts +0 -1
  448. package/lib/path/parse-path-array.js +0 -9
  449. package/lib/path/parse-path-array.js.map +0 -1
  450. package/lib/path/parse-path-string.d.ts +0 -1
  451. package/lib/path/parse-path-string.js +0 -61
  452. package/lib/path/parse-path-string.js.map +0 -1
  453. package/lib/path/parse-path.d.ts +0 -1
  454. package/lib/path/parse-path.js +0 -37
  455. package/lib/path/parse-path.js.map +0 -1
  456. package/lib/path/path-2-absolute.d.ts +0 -1
  457. package/lib/path/path-2-absolute.js +0 -128
  458. package/lib/path/path-2-absolute.js.map +0 -1
  459. package/lib/path/path-2-curve.d.ts +0 -2
  460. package/lib/path/path-2-curve.js +0 -67
  461. package/lib/path/path-2-curve.js.map +0 -1
  462. package/lib/path/path-2-segments.d.ts +0 -1
  463. package/lib/path/path-2-segments.js +0 -142
  464. package/lib/path/path-2-segments.js.map +0 -1
  465. package/lib/path/path-intersection.d.ts +0 -9
  466. package/lib/path/path-intersection.js +0 -370
  467. package/lib/path/path-intersection.js.map +0 -1
  468. package/lib/path/point-in-polygon.d.ts +0 -5
  469. package/lib/path/point-in-polygon.js +0 -53
  470. package/lib/path/point-in-polygon.js.map +0 -1
  471. package/lib/path/rect-path.d.ts +0 -4
  472. package/lib/path/rect-path.js +0 -23
  473. package/lib/path/rect-path.js.map +0 -1
  474. package/src/path/catmull-rom-2-bezier.ts +0 -141
  475. package/src/path/fill-path-by-diff.ts +0 -116
  476. package/src/path/fill-path.ts +0 -129
  477. package/src/path/format-path.ts +0 -142
  478. package/src/path/get-arc-params.ts +0 -102
  479. package/src/path/get-line-intersect.ts +0 -46
  480. package/src/path/is-polygons-intersect.ts +0 -95
  481. package/src/path/parse-path-array.ts +0 -5
  482. package/src/path/parse-path-string.ts +0 -63
  483. package/src/path/parse-path.ts +0 -34
  484. package/src/path/path-2-absolute.ts +0 -132
  485. package/src/path/path-2-curve.ts +0 -69
  486. package/src/path/path-2-segments.ts +0 -142
  487. package/src/path/path-intersection.ts +0 -419
  488. package/src/path/point-in-polygon.ts +0 -56
  489. package/src/path/rect-path.ts +0 -22
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPathBBoxTotalLength = void 0;
4
+ const path_length_factory_1 = require("./path-length-factory");
5
+ /**
6
+ * Returns the bounding box of a shape.
7
+ */
8
+ function getPathBBoxTotalLength(path) {
9
+ if (!path) {
10
+ return {
11
+ length: 0,
12
+ x: 0,
13
+ y: 0,
14
+ width: 0,
15
+ height: 0,
16
+ x2: 0,
17
+ y2: 0,
18
+ cx: 0,
19
+ cy: 0,
20
+ cz: 0,
21
+ };
22
+ }
23
+ const { length, min: { x: xMin, y: yMin }, max: { x: xMax, y: yMax }, } = (0, path_length_factory_1.pathLengthFactory)(path);
24
+ const width = xMax - xMin;
25
+ const height = yMax - yMin;
26
+ return {
27
+ length,
28
+ width,
29
+ height,
30
+ x: xMin,
31
+ y: yMin,
32
+ x2: xMax,
33
+ y2: yMax,
34
+ cx: xMin + width / 2,
35
+ cy: yMin + height / 2,
36
+ // an estimted guess
37
+ cz: Math.max(width, height) + Math.min(width, height) / 2,
38
+ };
39
+ }
40
+ exports.getPathBBoxTotalLength = getPathBBoxTotalLength;
41
+ //# sourceMappingURL=get-path-bbox-total-length.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-path-bbox-total-length.js","sourceRoot":"src/","sources":["path/util/get-path-bbox-total-length.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAE1D;;GAEG;AACH,SAAgB,sBAAsB,CAAC,IAAe;IACpD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO;YACL,MAAM,EAAE,CAAC;YACT,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,CAAC;YACJ,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;YACT,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;SACN,CAAC;KACH;IAED,MAAM,EACJ,MAAM,EACN,GAAG,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EACzB,GAAG,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,GAC1B,GAAG,IAAA,uCAAiB,EAAC,IAAI,CAAC,CAAC;IAE5B,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAE3B,OAAO;QACL,MAAM;QACN,KAAK;QACL,MAAM;QACN,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,EAAE,EAAE,IAAI;QACR,EAAE,EAAE,IAAI;QACR,EAAE,EAAE,IAAI,GAAG,KAAK,GAAG,CAAC;QACpB,EAAE,EAAE,IAAI,GAAG,MAAM,GAAG,CAAC;QACrB,oBAAoB;QACpB,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;KAC1D,CAAC;AACJ,CAAC;AAtCD,wDAsCC"}
@@ -0,0 +1,5 @@
1
+ import type { PathArray, PathBBox } from '../types';
2
+ /**
3
+ * Returns the bounding box of a shape.
4
+ */
5
+ export declare function getPathBBox(path: string | PathArray): PathBBox;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPathBBox = void 0;
4
+ const path_length_factory_1 = require("./path-length-factory");
5
+ /**
6
+ * Returns the bounding box of a shape.
7
+ */
8
+ function getPathBBox(path) {
9
+ if (!path) {
10
+ return {
11
+ x: 0,
12
+ y: 0,
13
+ width: 0,
14
+ height: 0,
15
+ x2: 0,
16
+ y2: 0,
17
+ cx: 0,
18
+ cy: 0,
19
+ cz: 0,
20
+ };
21
+ }
22
+ const { min: { x: xMin, y: yMin }, max: { x: xMax, y: yMax }, } = (0, path_length_factory_1.pathLengthFactory)(path);
23
+ const width = xMax - xMin;
24
+ const height = yMax - yMin;
25
+ return {
26
+ width,
27
+ height,
28
+ x: xMin,
29
+ y: yMin,
30
+ x2: xMax,
31
+ y2: yMax,
32
+ cx: xMin + width / 2,
33
+ cy: yMin + height / 2,
34
+ // an estimted guess
35
+ cz: Math.max(width, height) + Math.min(width, height) / 2,
36
+ };
37
+ }
38
+ exports.getPathBBox = getPathBBox;
39
+ //# sourceMappingURL=get-path-bbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-path-bbox.js","sourceRoot":"src/","sources":["path/util/get-path-bbox.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAE1D;;GAEG;AACH,SAAgB,WAAW,CAAC,IAAwB;IAClD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO;YACL,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,CAAC;YACJ,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;YACT,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;SACN,CAAC;KACH;IAED,MAAM,EACJ,GAAG,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EACzB,GAAG,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,GAC1B,GAAG,IAAA,uCAAiB,EAAC,IAAI,CAAC,CAAC;IAE5B,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAE3B,OAAO;QACL,KAAK;QACL,MAAM;QACN,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,EAAE,EAAE,IAAI;QACR,EAAE,EAAE,IAAI;QACR,EAAE,EAAE,IAAI,GAAG,KAAK,GAAG,CAAC;QACpB,EAAE,EAAE,IAAI,GAAG,MAAM,GAAG,CAAC;QACrB,oBAAoB;QACpB,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;KAC1D,CAAC;AACJ,CAAC;AAnCD,kCAmCC"}
@@ -0,0 +1,5 @@
1
+ import type { PathArray } from '../types';
2
+ /**
3
+ * Returns [x,y] coordinates of a point at a given length of a shape.
4
+ */
5
+ export declare function getPointAtLength(pathInput: string | PathArray, distance: number): import("../types").Point;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPointAtLength = void 0;
4
+ const path_length_factory_1 = require("./path-length-factory");
5
+ /**
6
+ * Returns [x,y] coordinates of a point at a given length of a shape.
7
+ */
8
+ function getPointAtLength(pathInput, distance) {
9
+ return (0, path_length_factory_1.pathLengthFactory)(pathInput, distance).point;
10
+ }
11
+ exports.getPointAtLength = getPointAtLength;
12
+ //# sourceMappingURL=get-point-at-length.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-point-at-length.js","sourceRoot":"src/","sources":["path/util/get-point-at-length.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAE1D;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAA6B,EAAE,QAAgB;IAC9E,OAAO,IAAA,uCAAiB,EAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC;AACtD,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,6 @@
1
+ import type { PathArray, SegmentProperties } from '../types';
2
+ /**
3
+ * Returns the segment, its index and length as well as
4
+ * the length to that segment at a given length in a path.
5
+ */
6
+ export declare function getPropertiesAtLength(pathInput: string | PathArray, distance?: number): SegmentProperties;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPropertiesAtLength = void 0;
4
+ const parse_path_string_1 = require("../parser/parse-path-string");
5
+ const get_total_length_1 = require("./get-total-length");
6
+ /**
7
+ * Returns the segment, its index and length as well as
8
+ * the length to that segment at a given length in a path.
9
+ */
10
+ function getPropertiesAtLength(pathInput, distance) {
11
+ const pathArray = (0, parse_path_string_1.parsePathString)(pathInput);
12
+ if (typeof pathArray === 'string') {
13
+ throw TypeError(pathArray);
14
+ }
15
+ let pathTemp = [...pathArray];
16
+ let pathLength = (0, get_total_length_1.getTotalLength)(pathTemp);
17
+ let index = pathTemp.length - 1;
18
+ let lengthAtSegment = 0;
19
+ let length = 0;
20
+ let segment = pathArray[0];
21
+ const [x, y] = segment.slice(-2);
22
+ const point = { x, y };
23
+ // If the path is empty, return 0.
24
+ if (index <= 0 || !distance || !Number.isFinite(distance)) {
25
+ return {
26
+ segment,
27
+ index: 0,
28
+ length,
29
+ point,
30
+ lengthAtSegment,
31
+ };
32
+ }
33
+ if (distance >= pathLength) {
34
+ pathTemp = pathArray.slice(0, -1);
35
+ lengthAtSegment = (0, get_total_length_1.getTotalLength)(pathTemp);
36
+ length = pathLength - lengthAtSegment;
37
+ return {
38
+ segment: pathArray[index],
39
+ index,
40
+ length,
41
+ lengthAtSegment,
42
+ };
43
+ }
44
+ const segments = [];
45
+ while (index > 0) {
46
+ segment = pathTemp[index];
47
+ pathTemp = pathTemp.slice(0, -1);
48
+ lengthAtSegment = (0, get_total_length_1.getTotalLength)(pathTemp);
49
+ length = pathLength - lengthAtSegment;
50
+ pathLength = lengthAtSegment;
51
+ segments.push({
52
+ segment,
53
+ index,
54
+ length,
55
+ lengthAtSegment,
56
+ });
57
+ index -= 1;
58
+ }
59
+ return segments.find(({ lengthAtSegment: l }) => l <= distance);
60
+ }
61
+ exports.getPropertiesAtLength = getPropertiesAtLength;
62
+ //# sourceMappingURL=get-properties-at-length.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-properties-at-length.js","sourceRoot":"src/","sources":["path/util/get-properties-at-length.ts"],"names":[],"mappings":";;;AACA,mEAA8D;AAC9D,yDAAoD;AAEpD;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,SAA6B,EAAE,QAAiB;IACpF,MAAM,SAAS,GAAG,IAAA,mCAAe,EAAC,SAAS,CAAC,CAAC;IAE7C,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,MAAM,SAAS,CAAC,SAAS,CAAC,CAAC;KAC5B;IAED,IAAI,QAAQ,GAAc,CAAC,GAAG,SAAS,CAAC,CAAC;IACzC,IAAI,UAAU,GAAG,IAAA,iCAAc,EAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,OAAO,GAAgB,SAAS,CAAC,CAAC,CAAC,CAAC;IACxC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAEvB,kCAAkC;IAClC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACzD,OAAO;YACL,OAAO;YACP,KAAK,EAAE,CAAC;YACR,MAAM;YACN,KAAK;YACL,eAAe;SAChB,CAAC;KACH;IAED,IAAI,QAAQ,IAAI,UAAU,EAAE;QAC1B,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAc,CAAC;QAC/C,eAAe,GAAG,IAAA,iCAAc,EAAC,QAAQ,CAAC,CAAC;QAC3C,MAAM,GAAG,UAAU,GAAG,eAAe,CAAC;QACtC,OAAO;YACL,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC;YACzB,KAAK;YACL,MAAM;YACN,eAAe;SAChB,CAAC;KACH;IAED,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,OAAO,KAAK,GAAG,CAAC,EAAE;QAChB,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1B,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAc,CAAC;QAC9C,eAAe,GAAG,IAAA,iCAAc,EAAC,QAAQ,CAAC,CAAC;QAC3C,MAAM,GAAG,UAAU,GAAG,eAAe,CAAC;QACtC,UAAU,GAAG,eAAe,CAAC;QAC7B,QAAQ,CAAC,IAAI,CAAC;YACZ,OAAO;YACP,KAAK;YACL,MAAM;YACN,eAAe;SAChB,CAAC,CAAC;QACH,KAAK,IAAI,CAAC,CAAC;KACZ;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC;AAClE,CAAC;AAxDD,sDAwDC"}
@@ -0,0 +1,7 @@
1
+ import type { Point, PathArray, PointProperties } from '../types';
2
+ /**
3
+ * Returns the point and segment in path closest to a given point as well as
4
+ * the distance to the path stroke.
5
+ * @see https://bl.ocks.org/mbostock/8027637
6
+ */
7
+ export declare function getPropertiesAtPoint(pathInput: string | PathArray, point: Point): PointProperties;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPropertiesAtPoint = void 0;
4
+ const parse_path_string_1 = require("../parser/parse-path-string");
5
+ const normalize_path_1 = require("../process/normalize-path");
6
+ const get_point_at_length_1 = require("./get-point-at-length");
7
+ const get_properties_at_length_1 = require("./get-properties-at-length");
8
+ const get_total_length_1 = require("./get-total-length");
9
+ /**
10
+ * Returns the point and segment in path closest to a given point as well as
11
+ * the distance to the path stroke.
12
+ * @see https://bl.ocks.org/mbostock/8027637
13
+ */
14
+ function getPropertiesAtPoint(pathInput, point) {
15
+ const path = (0, parse_path_string_1.parsePathString)(pathInput);
16
+ const normalPath = (0, normalize_path_1.normalizePath)(path);
17
+ const pathLength = (0, get_total_length_1.getTotalLength)(path);
18
+ const distanceTo = (p) => {
19
+ const dx = p.x - point.x;
20
+ const dy = p.y - point.y;
21
+ return dx * dx + dy * dy;
22
+ };
23
+ let precision = 8;
24
+ let scan;
25
+ let scanDistance = 0;
26
+ let closest;
27
+ let bestLength = 0;
28
+ let bestDistance = Infinity;
29
+ // linear scan for coarse approximation
30
+ for (let scanLength = 0; scanLength <= pathLength; scanLength += precision) {
31
+ scan = (0, get_point_at_length_1.getPointAtLength)(normalPath, scanLength);
32
+ scanDistance = distanceTo(scan);
33
+ if (scanDistance < bestDistance) {
34
+ closest = scan;
35
+ bestLength = scanLength;
36
+ bestDistance = scanDistance;
37
+ }
38
+ }
39
+ // binary search for precise estimate
40
+ precision /= 2;
41
+ let before;
42
+ let after;
43
+ let beforeLength = 0;
44
+ let afterLength = 0;
45
+ let beforeDistance = 0;
46
+ let afterDistance = 0;
47
+ while (precision > 0.5) {
48
+ beforeLength = bestLength - precision;
49
+ before = (0, get_point_at_length_1.getPointAtLength)(normalPath, beforeLength);
50
+ beforeDistance = distanceTo(before);
51
+ afterLength = bestLength + precision;
52
+ after = (0, get_point_at_length_1.getPointAtLength)(normalPath, afterLength);
53
+ afterDistance = distanceTo(after);
54
+ if (beforeLength >= 0 && beforeDistance < bestDistance) {
55
+ closest = before;
56
+ bestLength = beforeLength;
57
+ bestDistance = beforeDistance;
58
+ }
59
+ else if (afterLength <= pathLength && afterDistance < bestDistance) {
60
+ closest = after;
61
+ bestLength = afterLength;
62
+ bestDistance = afterDistance;
63
+ }
64
+ else {
65
+ precision /= 2;
66
+ }
67
+ }
68
+ const segment = (0, get_properties_at_length_1.getPropertiesAtLength)(path, bestLength);
69
+ const distance = Math.sqrt(bestDistance);
70
+ return { closest, distance, segment };
71
+ }
72
+ exports.getPropertiesAtPoint = getPropertiesAtPoint;
73
+ //# sourceMappingURL=get-properties-at-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-properties-at-point.js","sourceRoot":"src/","sources":["path/util/get-properties-at-point.ts"],"names":[],"mappings":";;;AACA,mEAA8D;AAC9D,8DAA0D;AAC1D,+DAAyD;AACzD,yEAAmE;AACnE,yDAAoD;AAEpD;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,SAA6B,EAAE,KAAY;IAC9E,MAAM,IAAI,GAAG,IAAA,mCAAe,EAAC,SAAS,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,IAAA,8BAAa,EAAC,IAAI,CAAC,CAAC;IACvC,MAAM,UAAU,GAAG,IAAA,iCAAc,EAAC,IAAI,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,CAAC,CAAQ,EAAE,EAAE;QAC9B,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;QACzB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;QACzB,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAC3B,CAAC,CAAC;IACF,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,IAAW,CAAC;IAChB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,OAAc,CAAC;IACnB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,YAAY,GAAG,QAAQ,CAAC;IAE5B,uCAAuC;IACvC,KAAK,IAAI,UAAU,GAAG,CAAC,EAAE,UAAU,IAAI,UAAU,EAAE,UAAU,IAAI,SAAS,EAAE;QAC1E,IAAI,GAAG,IAAA,sCAAgB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAChD,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,YAAY,GAAG,YAAY,EAAE;YAC/B,OAAO,GAAG,IAAI,CAAC;YACf,UAAU,GAAG,UAAU,CAAC;YACxB,YAAY,GAAG,YAAY,CAAC;SAC7B;KACF;IAED,qCAAqC;IACrC,SAAS,IAAI,CAAC,CAAC;IACf,IAAI,MAAa,CAAC;IAClB,IAAI,KAAY,CAAC;IACjB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,OAAO,SAAS,GAAG,GAAG,EAAE;QACtB,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;QACtC,MAAM,GAAG,IAAA,sCAAgB,EAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QACpD,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QACpC,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC;QACrC,KAAK,GAAG,IAAA,sCAAgB,EAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAClD,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,YAAY,IAAI,CAAC,IAAI,cAAc,GAAG,YAAY,EAAE;YACtD,OAAO,GAAG,MAAM,CAAC;YACjB,UAAU,GAAG,YAAY,CAAC;YAC1B,YAAY,GAAG,cAAc,CAAC;SAC/B;aAAM,IAAI,WAAW,IAAI,UAAU,IAAI,aAAa,GAAG,YAAY,EAAE;YACpE,OAAO,GAAG,KAAK,CAAC;YAChB,UAAU,GAAG,WAAW,CAAC;YACzB,YAAY,GAAG,aAAa,CAAC;SAC9B;aAAM;YACL,SAAS,IAAI,CAAC,CAAC;SAChB;KACF;IAED,MAAM,OAAO,GAAG,IAAA,gDAAqB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AACxC,CAAC;AA5DD,oDA4DC"}
@@ -0,0 +1,2 @@
1
+ import type { CurveArray } from '../types';
2
+ export declare function getRotatedCurve(a: CurveArray, b: CurveArray): (string[] | import("../types").MSegment | import("../types").CSegment)[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRotatedCurve = void 0;
4
+ const distance_square_root_1 = require("./distance-square-root");
5
+ function getRotations(a) {
6
+ const segCount = a.length;
7
+ const pointCount = segCount - 1;
8
+ return a.map((f, idx) => a.map((p, i) => {
9
+ let oldSegIdx = idx + i;
10
+ let seg;
11
+ if (i === 0 || (a[oldSegIdx] && a[oldSegIdx][0] === 'M')) {
12
+ seg = a[oldSegIdx];
13
+ return ['M'].concat(seg.slice(-2));
14
+ }
15
+ if (oldSegIdx >= segCount)
16
+ oldSegIdx -= pointCount;
17
+ return a[oldSegIdx];
18
+ }));
19
+ }
20
+ function getRotatedCurve(a, b) {
21
+ const segCount = a.length - 1;
22
+ const lineLengths = [];
23
+ let computedIndex = 0;
24
+ let sumLensSqrd = 0;
25
+ const rotations = getRotations(a);
26
+ rotations.forEach((r, i) => {
27
+ a.slice(1).forEach((s, j) => {
28
+ // @ts-ignore
29
+ sumLensSqrd += (0, distance_square_root_1.distanceSquareRoot)(a[(i + j) % segCount].slice(-2), b[j % segCount].slice(-2));
30
+ });
31
+ lineLengths[i] = sumLensSqrd;
32
+ sumLensSqrd = 0;
33
+ });
34
+ computedIndex = lineLengths.indexOf(Math.min.apply(null, lineLengths));
35
+ return rotations[computedIndex];
36
+ }
37
+ exports.getRotatedCurve = getRotatedCurve;
38
+ //# sourceMappingURL=get-rotated-curve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-rotated-curve.js","sourceRoot":"src/","sources":["path/util/get-rotated-curve.ts"],"names":[],"mappings":";;;AACA,iEAA4D;AAE5D,SAAS,YAAY,CAAC,CAAa;IACjC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,MAAM,UAAU,GAAG,QAAQ,GAAG,CAAC,CAAC;IAEhC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,IAAI,SAAS,GAAG,GAAG,GAAG,CAAC,CAAC;QACxB,IAAI,GAAG,CAAC;QAER,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE;YACxD,GAAG,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;YACnB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACpC;QACD,IAAI,SAAS,IAAI,QAAQ;YAAE,SAAS,IAAI,UAAU,CAAC;QACnD,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC;IACtB,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,SAAgB,eAAe,CAAC,CAAa,EAAE,CAAa;IAC1D,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9B,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAElC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACzB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC1B,aAAa;YACb,WAAW,IAAI,IAAA,yCAAkB,EAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAChG,CAAC,CAAC,CAAC;QACH,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;QAC7B,WAAW,GAAG,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,aAAa,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAEvE,OAAO,SAAS,CAAC,aAAa,CAAC,CAAC;AAClC,CAAC;AAnBD,0CAmBC"}
@@ -0,0 +1,8 @@
1
+ import type { PathArray } from '../types';
2
+ /**
3
+ * Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
4
+ *
5
+ * The `normalizePath` version is lighter, faster, more efficient and more accurate
6
+ * with paths that are not `curveArray`.
7
+ */
8
+ export declare function getTotalLength(pathInput: string | PathArray): number;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTotalLength = void 0;
4
+ const path_length_factory_1 = require("./path-length-factory");
5
+ /**
6
+ * Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
7
+ *
8
+ * The `normalizePath` version is lighter, faster, more efficient and more accurate
9
+ * with paths that are not `curveArray`.
10
+ */
11
+ function getTotalLength(pathInput) {
12
+ return (0, path_length_factory_1.pathLengthFactory)(pathInput).length;
13
+ }
14
+ exports.getTotalLength = getTotalLength;
15
+ //# sourceMappingURL=get-total-length.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-total-length.js","sourceRoot":"src/","sources":["path/util/get-total-length.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAE1D;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,SAA6B;IAC1D,OAAO,IAAA,uCAAiB,EAAC,SAAS,CAAC,CAAC,MAAM,CAAC;AAC7C,CAAC;AAFD,wCAEC"}
@@ -0,0 +1,6 @@
1
+ import type { PathArray, AbsoluteArray } from '../types';
2
+ /**
3
+ * Iterates an array to check if it's a `PathArray`
4
+ * with all absolute values.
5
+ */
6
+ export declare function isAbsoluteArray(path: string | PathArray): path is AbsoluteArray;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAbsoluteArray = void 0;
4
+ const is_path_array_1 = require("./is-path-array");
5
+ /**
6
+ * Iterates an array to check if it's a `PathArray`
7
+ * with all absolute values.
8
+ */
9
+ function isAbsoluteArray(path) {
10
+ return ((0, is_path_array_1.isPathArray)(path) &&
11
+ // @ts-ignore -- `isPathArray` also checks if it's `Array`
12
+ path.every(([x]) => x === x.toUpperCase()));
13
+ }
14
+ exports.isAbsoluteArray = isAbsoluteArray;
15
+ //# sourceMappingURL=is-absolute-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-absolute-array.js","sourceRoot":"src/","sources":["path/util/is-absolute-array.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAE9C;;;GAGG;AACH,SAAgB,eAAe,CAAC,IAAwB;IACtD,OAAO,CACL,IAAA,2BAAW,EAAC,IAAI,CAAC;QACjB,0DAA0D;QAC1D,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAC3C,CAAC;AACJ,CAAC;AAND,0CAMC"}
@@ -0,0 +1,9 @@
1
+ import type { PathArray } from '../types';
2
+ /**
3
+ * Iterates an array to check if it's a `PathArray`
4
+ * with all C (cubic bezier) segments.
5
+ *
6
+ * @param {string | PathArray} path the `Array` to be checked
7
+ * @returns {boolean} iteration result
8
+ */
9
+ export declare function isCurveArray(path: string | PathArray): path is PathArray;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCurveArray = void 0;
4
+ const is_normalized_array_1 = require("./is-normalized-array");
5
+ /**
6
+ * Iterates an array to check if it's a `PathArray`
7
+ * with all C (cubic bezier) segments.
8
+ *
9
+ * @param {string | PathArray} path the `Array` to be checked
10
+ * @returns {boolean} iteration result
11
+ */
12
+ function isCurveArray(path) {
13
+ return (0, is_normalized_array_1.isNormalizedArray)(path) && path.every(([pc]) => 'MC'.includes(pc));
14
+ }
15
+ exports.isCurveArray = isCurveArray;
16
+ //# sourceMappingURL=is-curve-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-curve-array.js","sourceRoot":"src/","sources":["path/util/is-curve-array.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAE1D;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,IAAwB;IACnD,OAAO,IAAA,uCAAiB,EAAC,IAAI,CAAC,IAAK,IAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3F,CAAC;AAFD,oCAEC"}
@@ -0,0 +1,7 @@
1
+ import type { PathArray } from '../types';
2
+ /**
3
+ * Iterates an array to check if it's a `PathArray`
4
+ * with all segments are in non-shorthand notation
5
+ * with absolute values.
6
+ */
7
+ export declare function isNormalizedArray(path: string | PathArray): path is PathArray;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNormalizedArray = void 0;
4
+ const is_absolute_array_1 = require("./is-absolute-array");
5
+ /**
6
+ * Iterates an array to check if it's a `PathArray`
7
+ * with all segments are in non-shorthand notation
8
+ * with absolute values.
9
+ */
10
+ function isNormalizedArray(path) {
11
+ return (0, is_absolute_array_1.isAbsoluteArray)(path) && path.every(([pc]) => 'ACLMQZ'.includes(pc));
12
+ }
13
+ exports.isNormalizedArray = isNormalizedArray;
14
+ //# sourceMappingURL=is-normalized-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-normalized-array.js","sourceRoot":"src/","sources":["path/util/is-normalized-array.ts"],"names":[],"mappings":";;;AACA,2DAAsD;AAEtD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAwB;IACxD,OAAO,IAAA,mCAAe,EAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9E,CAAC;AAFD,8CAEC"}
@@ -0,0 +1,5 @@
1
+ import type { PathArray } from '../types';
2
+ /**
3
+ * Iterates an array to check if it's an actual `PathArray`.
4
+ */
5
+ export declare function isPathArray(path: string | PathArray): path is PathArray;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPathArray = void 0;
4
+ const params_count_1 = require("../parser/params-count");
5
+ /**
6
+ * Iterates an array to check if it's an actual `PathArray`.
7
+ */
8
+ function isPathArray(path) {
9
+ return (Array.isArray(path) &&
10
+ path.every((seg) => {
11
+ const lk = seg[0].toLowerCase();
12
+ return params_count_1.paramsCount[lk] === seg.length - 1 && 'achlmqstvz'.includes(lk);
13
+ }));
14
+ }
15
+ exports.isPathArray = isPathArray;
16
+ //# sourceMappingURL=is-path-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-path-array.js","sourceRoot":"src/","sources":["path/util/is-path-array.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAGrD;;GAEG;AACH,SAAgB,WAAW,CAAC,IAAwB;IAClD,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACjB,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;YAChC,OAAO,0BAAW,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACzE,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AARD,kCAQC"}
@@ -0,0 +1,5 @@
1
+ import type { Point, PathArray } from '../types';
2
+ /**
3
+ * Checks if a given point is in the stroke of a path.
4
+ */
5
+ export declare function isPointInStroke(pathInput: string | PathArray, point: Point): boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPointInStroke = void 0;
4
+ const get_properties_at_point_1 = require("./get-properties-at-point");
5
+ /**
6
+ * Checks if a given point is in the stroke of a path.
7
+ */
8
+ function isPointInStroke(pathInput, point) {
9
+ const { distance } = (0, get_properties_at_point_1.getPropertiesAtPoint)(pathInput, point);
10
+ return Math.abs(distance) < 0.001; // 0.01 might be more permissive
11
+ }
12
+ exports.isPointInStroke = isPointInStroke;
13
+ //# sourceMappingURL=is-point-in-stroke.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-point-in-stroke.js","sourceRoot":"src/","sources":["path/util/is-point-in-stroke.ts"],"names":[],"mappings":";;;AACA,uEAAiE;AAEjE;;GAEG;AACH,SAAgB,eAAe,CAAC,SAA6B,EAAE,KAAY;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,8CAAoB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,CAAC,gCAAgC;AACrE,CAAC;AAHD,0CAGC"}
@@ -0,0 +1 @@
1
+ export declare function midPoint(a: number[], b: number[], t: number): number[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.midPoint = void 0;
4
+ function midPoint(a, b, t) {
5
+ const ax = a[0];
6
+ const ay = a[1];
7
+ const bx = b[0];
8
+ const by = b[1];
9
+ return [ax + (bx - ax) * t, ay + (by - ay) * t];
10
+ }
11
+ exports.midPoint = midPoint;
12
+ //# sourceMappingURL=mid-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mid-point.js","sourceRoot":"src/","sources":["path/util/mid-point.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,CAAW,EAAE,CAAW,EAAE,CAAS;IAC1D,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AAND,4BAMC"}
@@ -0,0 +1,7 @@
1
+ import type { PathArray, LengthFactory } from '../types';
2
+ /**
3
+ * Returns a {x,y} point at a given length
4
+ * of a shape, the shape total length and
5
+ * the shape minimum and maximum {x,y} coordinates.
6
+ */
7
+ export declare function pathLengthFactory(pathInput: string | PathArray, distance?: number): LengthFactory;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pathLengthFactory = void 0;
4
+ const normalize_path_1 = require("../process/normalize-path");
5
+ const segment_line_factory_1 = require("./segment-line-factory");
6
+ const segment_arc_factory_1 = require("./segment-arc-factory");
7
+ const segment_cubic_factory_1 = require("./segment-cubic-factory");
8
+ const segment_quad_factory_1 = require("./segment-quad-factory");
9
+ /**
10
+ * Returns a {x,y} point at a given length
11
+ * of a shape, the shape total length and
12
+ * the shape minimum and maximum {x,y} coordinates.
13
+ */
14
+ function pathLengthFactory(pathInput, distance) {
15
+ const path = (0, normalize_path_1.normalizePath)(pathInput);
16
+ const distanceIsNumber = typeof distance === 'number';
17
+ let isM;
18
+ let data = [];
19
+ let pathCommand;
20
+ let x = 0;
21
+ let y = 0;
22
+ let mx = 0;
23
+ let my = 0;
24
+ let seg;
25
+ let MIN = [];
26
+ let MAX = [];
27
+ let length = 0;
28
+ let min = { x: 0, y: 0 };
29
+ let max = min;
30
+ let point = min;
31
+ let POINT = min;
32
+ let LENGTH = 0;
33
+ for (let i = 0, ll = path.length; i < ll; i += 1) {
34
+ seg = path[i];
35
+ [pathCommand] = seg;
36
+ isM = pathCommand === 'M';
37
+ data = !isM ? [x, y, ...seg.slice(1)] : data;
38
+ // this segment is always ZERO
39
+ /* istanbul ignore else */
40
+ if (isM) {
41
+ // remember mx, my for Z
42
+ [, mx, my] = seg;
43
+ min = { x: mx, y: my };
44
+ max = min;
45
+ length = 0;
46
+ if (distanceIsNumber && distance < 0.001) {
47
+ POINT = min;
48
+ }
49
+ }
50
+ else if (pathCommand === 'L') {
51
+ // @ts-ignore
52
+ ({ length, min, max, point } = (0, segment_line_factory_1.segmentLineFactory)(...data, (distance || 0) - LENGTH));
53
+ }
54
+ else if (pathCommand === 'A') {
55
+ // @ts-ignore
56
+ ({ length, min, max, point } = (0, segment_arc_factory_1.segmentArcFactory)(...data, (distance || 0) - LENGTH));
57
+ }
58
+ else if (pathCommand === 'C') {
59
+ // @ts-ignore
60
+ ({ length, min, max, point } = (0, segment_cubic_factory_1.segmentCubicFactory)(...data, (distance || 0) - LENGTH));
61
+ }
62
+ else if (pathCommand === 'Q') {
63
+ // @ts-ignore
64
+ ({ length, min, max, point } = (0, segment_quad_factory_1.segmentQuadFactory)(...data, (distance || 0) - LENGTH));
65
+ }
66
+ else if (pathCommand === 'Z') {
67
+ data = [x, y, mx, my];
68
+ // @ts-ignore
69
+ ({ length, min, max, point } = (0, segment_line_factory_1.segmentLineFactory)(...data, (distance || 0) - LENGTH));
70
+ }
71
+ if (distanceIsNumber && LENGTH < distance && LENGTH + length >= distance) {
72
+ POINT = point;
73
+ }
74
+ MAX = [...MAX, max];
75
+ MIN = [...MIN, min];
76
+ LENGTH += length;
77
+ [x, y] = pathCommand !== 'Z' ? seg.slice(-2) : [mx, my];
78
+ }
79
+ // native `getPointAtLength` behavior when the given distance
80
+ // is higher than total length
81
+ if (distanceIsNumber && distance >= LENGTH) {
82
+ POINT = { x, y };
83
+ }
84
+ return {
85
+ length: LENGTH,
86
+ point: POINT,
87
+ min: {
88
+ x: Math.min(...MIN.map((n) => n.x)),
89
+ y: Math.min(...MIN.map((n) => n.y)),
90
+ },
91
+ max: {
92
+ x: Math.max(...MAX.map((n) => n.x)),
93
+ y: Math.max(...MAX.map((n) => n.y)),
94
+ },
95
+ };
96
+ }
97
+ exports.pathLengthFactory = pathLengthFactory;
98
+ //# sourceMappingURL=path-length-factory.js.map