@easemate/web-kit 0.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 (358) hide show
  1. package/README.md +824 -0
  2. package/build/components/code/index.cjs +152 -0
  3. package/build/components/code/index.d.cts +11 -0
  4. package/build/components/code/index.d.ts +11 -0
  5. package/build/components/code/index.js +148 -0
  6. package/build/components/code/utils/highlight-api.cjs +18 -0
  7. package/build/components/code/utils/highlight-api.d.cts +7 -0
  8. package/build/components/code/utils/highlight-api.d.ts +7 -0
  9. package/build/components/code/utils/highlight-api.js +14 -0
  10. package/build/components/code/utils/syntax-grammars.cjs +62 -0
  11. package/build/components/code/utils/syntax-grammars.d.cts +7 -0
  12. package/build/components/code/utils/syntax-grammars.d.ts +7 -0
  13. package/build/components/code/utils/syntax-grammars.js +59 -0
  14. package/build/components/code/utils/syntax-highlighter-theme.cjs +27 -0
  15. package/build/components/code/utils/syntax-highlighter-theme.d.cts +3 -0
  16. package/build/components/code/utils/syntax-highlighter-theme.d.ts +3 -0
  17. package/build/components/code/utils/syntax-highlighter-theme.js +23 -0
  18. package/build/components/code/utils/syntax-highlighter-types.cjs +2 -0
  19. package/build/components/code/utils/syntax-highlighter-types.d.cts +12 -0
  20. package/build/components/code/utils/syntax-highlighter-types.d.ts +12 -0
  21. package/build/components/code/utils/syntax-highlighter-types.js +1 -0
  22. package/build/components/code/utils/syntax-tokenizer.cjs +63 -0
  23. package/build/components/code/utils/syntax-tokenizer.d.cts +3 -0
  24. package/build/components/code/utils/syntax-tokenizer.d.ts +3 -0
  25. package/build/components/code/utils/syntax-tokenizer.js +58 -0
  26. package/build/components/curve/bezier-conversion.cjs +23 -0
  27. package/build/components/curve/bezier-conversion.d.cts +2 -0
  28. package/build/components/curve/bezier-conversion.d.ts +2 -0
  29. package/build/components/curve/bezier-conversion.js +19 -0
  30. package/build/components/curve/canvas-controls.cjs +300 -0
  31. package/build/components/curve/canvas-controls.d.cts +12 -0
  32. package/build/components/curve/canvas-controls.d.ts +12 -0
  33. package/build/components/curve/canvas-controls.js +296 -0
  34. package/build/components/curve/canvas.cjs +1208 -0
  35. package/build/components/curve/canvas.d.cts +24 -0
  36. package/build/components/curve/canvas.d.ts +24 -0
  37. package/build/components/curve/canvas.js +1204 -0
  38. package/build/components/curve/constants.cjs +203 -0
  39. package/build/components/curve/constants.d.cts +23 -0
  40. package/build/components/curve/constants.d.ts +23 -0
  41. package/build/components/curve/constants.js +200 -0
  42. package/build/components/curve/controls.cjs +942 -0
  43. package/build/components/curve/controls.d.cts +37 -0
  44. package/build/components/curve/controls.d.ts +37 -0
  45. package/build/components/curve/controls.js +938 -0
  46. package/build/components/curve/index.cjs +335 -0
  47. package/build/components/curve/index.d.cts +31 -0
  48. package/build/components/curve/index.d.ts +31 -0
  49. package/build/components/curve/index.js +330 -0
  50. package/build/components/curve/output.cjs +141 -0
  51. package/build/components/curve/output.d.cts +19 -0
  52. package/build/components/curve/output.d.ts +19 -0
  53. package/build/components/curve/output.js +137 -0
  54. package/build/components/curve/styles.cjs +493 -0
  55. package/build/components/curve/styles.d.cts +6 -0
  56. package/build/components/curve/styles.d.ts +6 -0
  57. package/build/components/curve/styles.js +490 -0
  58. package/build/components/curve/svg-renderer.cjs +185 -0
  59. package/build/components/curve/svg-renderer.d.cts +9 -0
  60. package/build/components/curve/svg-renderer.d.ts +9 -0
  61. package/build/components/curve/svg-renderer.js +175 -0
  62. package/build/components/curve/toolbar.cjs +368 -0
  63. package/build/components/curve/toolbar.d.cts +26 -0
  64. package/build/components/curve/toolbar.d.ts +26 -0
  65. package/build/components/curve/toolbar.js +364 -0
  66. package/build/components/curve/types.cjs +10 -0
  67. package/build/components/curve/types.d.cts +33 -0
  68. package/build/components/curve/types.d.ts +33 -0
  69. package/build/components/curve/types.js +7 -0
  70. package/build/components/curve/utils.cjs +541 -0
  71. package/build/components/curve/utils.d.cts +33 -0
  72. package/build/components/curve/utils.d.ts +33 -0
  73. package/build/components/curve/utils.js +521 -0
  74. package/build/components/index.cjs +18 -0
  75. package/build/components/index.d.cts +2 -0
  76. package/build/components/index.d.ts +2 -0
  77. package/build/components/index.js +2 -0
  78. package/build/decorators/Component.cjs +127 -0
  79. package/build/decorators/Component.d.cts +28 -0
  80. package/build/decorators/Component.d.ts +28 -0
  81. package/build/decorators/Component.js +123 -0
  82. package/build/decorators/Listen.cjs +154 -0
  83. package/build/decorators/Listen.d.cts +18 -0
  84. package/build/decorators/Listen.d.ts +18 -0
  85. package/build/decorators/Listen.js +151 -0
  86. package/build/decorators/OutsideClick.cjs +64 -0
  87. package/build/decorators/OutsideClick.d.cts +16 -0
  88. package/build/decorators/OutsideClick.d.ts +16 -0
  89. package/build/decorators/OutsideClick.js +59 -0
  90. package/build/decorators/Prop.cjs +273 -0
  91. package/build/decorators/Prop.d.cts +22 -0
  92. package/build/decorators/Prop.d.ts +22 -0
  93. package/build/decorators/Prop.js +270 -0
  94. package/build/decorators/Query.cjs +79 -0
  95. package/build/decorators/Query.d.cts +27 -0
  96. package/build/decorators/Query.d.ts +27 -0
  97. package/build/decorators/Query.js +76 -0
  98. package/build/decorators/Watch.cjs +52 -0
  99. package/build/decorators/Watch.d.cts +11 -0
  100. package/build/decorators/Watch.d.ts +11 -0
  101. package/build/decorators/Watch.js +49 -0
  102. package/build/decorators/index.cjs +15 -0
  103. package/build/decorators/index.d.cts +6 -0
  104. package/build/decorators/index.d.ts +6 -0
  105. package/build/decorators/index.js +6 -0
  106. package/build/elements/button/index.cjs +214 -0
  107. package/build/elements/button/index.d.cts +11 -0
  108. package/build/elements/button/index.d.ts +11 -0
  109. package/build/elements/button/index.js +210 -0
  110. package/build/elements/checkbox/index.cjs +316 -0
  111. package/build/elements/checkbox/index.d.cts +14 -0
  112. package/build/elements/checkbox/index.d.ts +14 -0
  113. package/build/elements/checkbox/index.js +312 -0
  114. package/build/elements/color/index.cjs +154 -0
  115. package/build/elements/color/index.d.cts +18 -0
  116. package/build/elements/color/index.d.ts +18 -0
  117. package/build/elements/color/index.js +150 -0
  118. package/build/elements/color/picker.cjs +544 -0
  119. package/build/elements/color/picker.d.cts +37 -0
  120. package/build/elements/color/picker.d.ts +37 -0
  121. package/build/elements/color/picker.js +540 -0
  122. package/build/elements/color/utils.cjs +235 -0
  123. package/build/elements/color/utils.d.cts +37 -0
  124. package/build/elements/color/utils.d.ts +37 -0
  125. package/build/elements/color/utils.js +218 -0
  126. package/build/elements/dropdown/index.cjs +875 -0
  127. package/build/elements/dropdown/index.d.cts +30 -0
  128. package/build/elements/dropdown/index.d.ts +30 -0
  129. package/build/elements/dropdown/index.js +871 -0
  130. package/build/elements/field/index.cjs +82 -0
  131. package/build/elements/field/index.d.cts +4 -0
  132. package/build/elements/field/index.d.ts +4 -0
  133. package/build/elements/field/index.js +78 -0
  134. package/build/elements/icons/animation/chevron.cjs +57 -0
  135. package/build/elements/icons/animation/chevron.d.cts +10 -0
  136. package/build/elements/icons/animation/chevron.d.ts +10 -0
  137. package/build/elements/icons/animation/chevron.js +53 -0
  138. package/build/elements/icons/animation/clear.cjs +74 -0
  139. package/build/elements/icons/animation/clear.d.cts +3 -0
  140. package/build/elements/icons/animation/clear.d.ts +3 -0
  141. package/build/elements/icons/animation/clear.js +70 -0
  142. package/build/elements/icons/animation/grid.cjs +77 -0
  143. package/build/elements/icons/animation/grid.d.cts +8 -0
  144. package/build/elements/icons/animation/grid.d.ts +8 -0
  145. package/build/elements/icons/animation/grid.js +73 -0
  146. package/build/elements/icons/animation/loading.cjs +68 -0
  147. package/build/elements/icons/animation/loading.d.cts +3 -0
  148. package/build/elements/icons/animation/loading.d.ts +3 -0
  149. package/build/elements/icons/animation/loading.js +64 -0
  150. package/build/elements/icons/animation/snap.cjs +133 -0
  151. package/build/elements/icons/animation/snap.d.cts +8 -0
  152. package/build/elements/icons/animation/snap.d.ts +8 -0
  153. package/build/elements/icons/animation/snap.js +129 -0
  154. package/build/elements/icons/index.cjs +40 -0
  155. package/build/elements/icons/index.d.cts +24 -0
  156. package/build/elements/icons/index.d.ts +24 -0
  157. package/build/elements/icons/index.js +24 -0
  158. package/build/elements/icons/interface/anchor-add.cjs +35 -0
  159. package/build/elements/icons/interface/anchor-add.d.cts +3 -0
  160. package/build/elements/icons/interface/anchor-add.d.ts +3 -0
  161. package/build/elements/icons/interface/anchor-add.js +31 -0
  162. package/build/elements/icons/interface/anchor-remove.cjs +34 -0
  163. package/build/elements/icons/interface/anchor-remove.d.cts +3 -0
  164. package/build/elements/icons/interface/anchor-remove.d.ts +3 -0
  165. package/build/elements/icons/interface/anchor-remove.js +30 -0
  166. package/build/elements/icons/interface/arrow-up.cjs +30 -0
  167. package/build/elements/icons/interface/arrow-up.d.cts +3 -0
  168. package/build/elements/icons/interface/arrow-up.d.ts +3 -0
  169. package/build/elements/icons/interface/arrow-up.js +26 -0
  170. package/build/elements/icons/interface/arrows-vertical.cjs +30 -0
  171. package/build/elements/icons/interface/arrows-vertical.d.cts +3 -0
  172. package/build/elements/icons/interface/arrows-vertical.d.ts +3 -0
  173. package/build/elements/icons/interface/arrows-vertical.js +26 -0
  174. package/build/elements/icons/interface/bezier-angle.cjs +33 -0
  175. package/build/elements/icons/interface/bezier-angle.d.cts +3 -0
  176. package/build/elements/icons/interface/bezier-angle.d.ts +3 -0
  177. package/build/elements/icons/interface/bezier-angle.js +29 -0
  178. package/build/elements/icons/interface/bezier-distribute.cjs +34 -0
  179. package/build/elements/icons/interface/bezier-distribute.d.cts +3 -0
  180. package/build/elements/icons/interface/bezier-distribute.d.ts +3 -0
  181. package/build/elements/icons/interface/bezier-distribute.js +30 -0
  182. package/build/elements/icons/interface/bezier-length.cjs +31 -0
  183. package/build/elements/icons/interface/bezier-length.d.cts +3 -0
  184. package/build/elements/icons/interface/bezier-length.d.ts +3 -0
  185. package/build/elements/icons/interface/bezier-length.js +27 -0
  186. package/build/elements/icons/interface/bezier-mirror.cjs +31 -0
  187. package/build/elements/icons/interface/bezier-mirror.d.cts +3 -0
  188. package/build/elements/icons/interface/bezier-mirror.d.ts +3 -0
  189. package/build/elements/icons/interface/bezier-mirror.js +27 -0
  190. package/build/elements/icons/interface/bezier.cjs +26 -0
  191. package/build/elements/icons/interface/bezier.d.cts +3 -0
  192. package/build/elements/icons/interface/bezier.d.ts +3 -0
  193. package/build/elements/icons/interface/bezier.js +22 -0
  194. package/build/elements/icons/interface/check.cjs +30 -0
  195. package/build/elements/icons/interface/check.d.cts +3 -0
  196. package/build/elements/icons/interface/check.d.ts +3 -0
  197. package/build/elements/icons/interface/check.js +26 -0
  198. package/build/elements/icons/interface/circle-arrow-left.cjs +30 -0
  199. package/build/elements/icons/interface/circle-arrow-left.d.cts +3 -0
  200. package/build/elements/icons/interface/circle-arrow-left.d.ts +3 -0
  201. package/build/elements/icons/interface/circle-arrow-left.js +26 -0
  202. package/build/elements/icons/interface/circle-arrow-right.cjs +30 -0
  203. package/build/elements/icons/interface/circle-arrow-right.d.cts +3 -0
  204. package/build/elements/icons/interface/circle-arrow-right.d.ts +3 -0
  205. package/build/elements/icons/interface/circle-arrow-right.js +26 -0
  206. package/build/elements/icons/interface/code.cjs +30 -0
  207. package/build/elements/icons/interface/code.d.cts +3 -0
  208. package/build/elements/icons/interface/code.d.ts +3 -0
  209. package/build/elements/icons/interface/code.js +26 -0
  210. package/build/elements/icons/interface/dots.cjs +32 -0
  211. package/build/elements/icons/interface/dots.d.cts +3 -0
  212. package/build/elements/icons/interface/dots.d.ts +3 -0
  213. package/build/elements/icons/interface/dots.js +28 -0
  214. package/build/elements/icons/interface/mention.cjs +30 -0
  215. package/build/elements/icons/interface/mention.d.cts +3 -0
  216. package/build/elements/icons/interface/mention.d.ts +3 -0
  217. package/build/elements/icons/interface/mention.js +26 -0
  218. package/build/elements/icons/interface/minus.cjs +30 -0
  219. package/build/elements/icons/interface/minus.d.cts +3 -0
  220. package/build/elements/icons/interface/minus.d.ts +3 -0
  221. package/build/elements/icons/interface/minus.js +26 -0
  222. package/build/elements/icons/interface/picker.cjs +34 -0
  223. package/build/elements/icons/interface/picker.d.cts +3 -0
  224. package/build/elements/icons/interface/picker.d.ts +3 -0
  225. package/build/elements/icons/interface/picker.js +30 -0
  226. package/build/elements/icons/interface/plus.cjs +30 -0
  227. package/build/elements/icons/interface/plus.d.cts +3 -0
  228. package/build/elements/icons/interface/plus.d.ts +3 -0
  229. package/build/elements/icons/interface/plus.js +26 -0
  230. package/build/elements/icons/interface/settings.cjs +30 -0
  231. package/build/elements/icons/interface/settings.d.cts +3 -0
  232. package/build/elements/icons/interface/settings.d.ts +3 -0
  233. package/build/elements/icons/interface/settings.js +26 -0
  234. package/build/elements/index.cjs +62 -0
  235. package/build/elements/index.d.cts +22 -0
  236. package/build/elements/index.d.ts +22 -0
  237. package/build/elements/index.js +22 -0
  238. package/build/elements/input/index.cjs +273 -0
  239. package/build/elements/input/index.d.cts +17 -0
  240. package/build/elements/input/index.d.ts +17 -0
  241. package/build/elements/input/index.js +269 -0
  242. package/build/elements/logo/index.cjs +732 -0
  243. package/build/elements/logo/index.d.cts +17 -0
  244. package/build/elements/logo/index.d.ts +17 -0
  245. package/build/elements/logo/index.js +728 -0
  246. package/build/elements/monitor/fps.cjs +432 -0
  247. package/build/elements/monitor/fps.d.cts +21 -0
  248. package/build/elements/monitor/fps.d.ts +21 -0
  249. package/build/elements/monitor/fps.js +428 -0
  250. package/build/elements/monitor/index.cjs +670 -0
  251. package/build/elements/monitor/index.d.cts +112 -0
  252. package/build/elements/monitor/index.d.ts +112 -0
  253. package/build/elements/monitor/index.js +666 -0
  254. package/build/elements/number/index.cjs +173 -0
  255. package/build/elements/number/index.d.cts +19 -0
  256. package/build/elements/number/index.d.ts +19 -0
  257. package/build/elements/number/index.js +169 -0
  258. package/build/elements/origin/index.cjs +169 -0
  259. package/build/elements/origin/index.d.cts +12 -0
  260. package/build/elements/origin/index.d.ts +12 -0
  261. package/build/elements/origin/index.js +165 -0
  262. package/build/elements/popover/index.cjs +209 -0
  263. package/build/elements/popover/index.d.cts +19 -0
  264. package/build/elements/popover/index.d.ts +19 -0
  265. package/build/elements/popover/index.js +205 -0
  266. package/build/elements/radio/index.cjs +301 -0
  267. package/build/elements/radio/index.d.cts +13 -0
  268. package/build/elements/radio/index.d.ts +13 -0
  269. package/build/elements/radio/index.js +283 -0
  270. package/build/elements/radio/input.cjs +329 -0
  271. package/build/elements/radio/input.d.cts +15 -0
  272. package/build/elements/radio/input.d.ts +15 -0
  273. package/build/elements/radio/input.js +325 -0
  274. package/build/elements/radio/option.cjs +15 -0
  275. package/build/elements/radio/option.d.cts +3 -0
  276. package/build/elements/radio/option.d.ts +3 -0
  277. package/build/elements/radio/option.js +11 -0
  278. package/build/elements/shared.cjs +66 -0
  279. package/build/elements/shared.d.cts +40 -0
  280. package/build/elements/shared.d.ts +40 -0
  281. package/build/elements/shared.js +59 -0
  282. package/build/elements/slider/index.cjs +232 -0
  283. package/build/elements/slider/index.d.cts +20 -0
  284. package/build/elements/slider/index.d.ts +20 -0
  285. package/build/elements/slider/index.js +228 -0
  286. package/build/elements/state/index.cjs +681 -0
  287. package/build/elements/state/index.d.cts +86 -0
  288. package/build/elements/state/index.d.ts +86 -0
  289. package/build/elements/state/index.js +677 -0
  290. package/build/elements/toggle/index.cjs +151 -0
  291. package/build/elements/toggle/index.d.cts +9 -0
  292. package/build/elements/toggle/index.d.ts +9 -0
  293. package/build/elements/toggle/index.js +147 -0
  294. package/build/elements/tooltip/index.cjs +187 -0
  295. package/build/elements/tooltip/index.d.cts +17 -0
  296. package/build/elements/tooltip/index.d.ts +17 -0
  297. package/build/elements/tooltip/index.js +183 -0
  298. package/build/index.cjs +40 -0
  299. package/build/index.d.cts +6 -0
  300. package/build/index.d.ts +6 -0
  301. package/build/index.js +12 -0
  302. package/build/init.cjs +325 -0
  303. package/build/init.d.cts +157 -0
  304. package/build/init.d.ts +157 -0
  305. package/build/init.js +289 -0
  306. package/build/internal/component-loaders.cjs +206 -0
  307. package/build/internal/component-loaders.d.cts +52 -0
  308. package/build/internal/component-loaders.d.ts +52 -0
  309. package/build/internal/component-loaders.js +167 -0
  310. package/build/internal/fonts.cjs +128 -0
  311. package/build/internal/fonts.d.cts +32 -0
  312. package/build/internal/fonts.d.ts +32 -0
  313. package/build/internal/fonts.js +123 -0
  314. package/build/internal/lazy-load.cjs +89 -0
  315. package/build/internal/lazy-load.d.cts +32 -0
  316. package/build/internal/lazy-load.d.ts +32 -0
  317. package/build/internal/lazy-load.js +86 -0
  318. package/build/internal/style-inject.cjs +236 -0
  319. package/build/internal/style-inject.d.cts +44 -0
  320. package/build/internal/style-inject.d.ts +44 -0
  321. package/build/internal/style-inject.js +226 -0
  322. package/build/register.cjs +36 -0
  323. package/build/register.d.cts +32 -0
  324. package/build/register.d.ts +32 -0
  325. package/build/register.js +34 -0
  326. package/build/theme/index.cjs +452 -0
  327. package/build/theme/index.d.cts +146 -0
  328. package/build/theme/index.d.ts +146 -0
  329. package/build/theme/index.js +423 -0
  330. package/build/theme/presets.cjs +54 -0
  331. package/build/theme/presets.d.cts +19 -0
  332. package/build/theme/presets.d.ts +19 -0
  333. package/build/theme/presets.js +51 -0
  334. package/build/theme/registry.cjs +204 -0
  335. package/build/theme/registry.d.cts +99 -0
  336. package/build/theme/registry.d.ts +99 -0
  337. package/build/theme/registry.js +194 -0
  338. package/build/theme/tokens.cjs +148 -0
  339. package/build/theme/tokens.d.cts +163 -0
  340. package/build/theme/tokens.d.ts +163 -0
  341. package/build/theme/tokens.js +145 -0
  342. package/build/utils/dismiss-controller.cjs +77 -0
  343. package/build/utils/dismiss-controller.d.cts +14 -0
  344. package/build/utils/dismiss-controller.d.ts +14 -0
  345. package/build/utils/dismiss-controller.js +73 -0
  346. package/build/utils/index.cjs +18 -0
  347. package/build/utils/index.d.cts +3 -0
  348. package/build/utils/index.d.ts +3 -0
  349. package/build/utils/index.js +3 -0
  350. package/build/utils/outside-click.cjs +82 -0
  351. package/build/utils/outside-click.d.cts +18 -0
  352. package/build/utils/outside-click.d.ts +18 -0
  353. package/build/utils/outside-click.js +74 -0
  354. package/build/utils/template-helpers.cjs +39 -0
  355. package/build/utils/template-helpers.d.cts +13 -0
  356. package/build/utils/template-helpers.d.ts +13 -0
  357. package/build/utils/template-helpers.js +28 -0
  358. package/package.json +96 -0
@@ -0,0 +1,1204 @@
1
+ import { html, svg } from 'lit-html';
2
+ import { BEZIER_CONTROL_MAX_Y, BEZIER_CONTROL_MIN_Y, DEFAULT_HANDLE_LENGTH, DRAG_ACTIVATION_DISTANCE_PX_SQUARED, HIT_AREA_RADIUS, LINEAR_HIT_THRESHOLD, LINEAR_PATH_SAMPLES, SVG_HEIGHT, SVG_WIDTH } from "./constants.js";
3
+ import { canvasStyles } from "./styles.js";
4
+ import { generateGridLines } from "./svg-renderer.js";
5
+ import { EasingType, MAX_LINEAR_POINTS } from "./types.js";
6
+ import { clampPoint, cloneLinearPoint, cubicBezierPath, ensureLinearPointId, getLinearApproximation, linearDisplayPath, MIN_LINEAR_DELTA, normalizeLinearPoints, normalizeVector, vectorLength } from "./utils.js";
7
+ import { Component } from '~/decorators/Component';
8
+ import { Prop } from '~/decorators/Prop';
9
+ import { Query } from '~/decorators/Query';
10
+ import { dispatchControlEvent } from '~/elements/shared';
11
+ @Component({
12
+ tag: 'ease-curve-canvas',
13
+ styles: canvasStyles,
14
+ template() {
15
+ const hoverPreviewPath = this.getHoverCurvePath();
16
+ const controlElements = this.getControlElements();
17
+ const hoverInsertElements = this.getHoverInsertElements();
18
+ const curvePath = this.getCurvePath();
19
+ return html `
20
+ <svg
21
+ viewBox="0 0 ${SVG_WIDTH} ${SVG_HEIGHT}"
22
+ width="${SVG_WIDTH}"
23
+ height="${SVG_HEIGHT}"
24
+ @pointerdown=${this.handlePointerDown}
25
+ @pointermove=${this.handlePointerMove}
26
+ @pointerup=${this.handlePointerUp}
27
+ @pointerleave=${this.handlePointerLeave}
28
+ @pointercancel=${this.handlePointerLeave}
29
+ >
30
+ ${this.showGrid ? svg `<g style="view-transition-name: grid-lines">${this.getGridLines()}</g>` : null}
31
+ ${hoverPreviewPath ? html `<path class="curve-path curve-path--preview" d=${hoverPreviewPath}></path>` : null}
32
+ <path class="curve-path" d=${curvePath} />
33
+ ${controlElements}
34
+ ${hoverInsertElements}
35
+ </svg>
36
+ `;
37
+ }
38
+ })
39
+ export class CurveCanvas extends HTMLElement {
40
+ @Prop({ reflect: true })
41
+ accessor easingType;
42
+ @Prop({ type: Object, reflect: false })
43
+ accessor points;
44
+ @Prop({ type: Boolean, reflect: true, defaultValue: true })
45
+ accessor showGrid;
46
+ @Prop({ type: Boolean, reflect: true, defaultValue: false })
47
+ accessor snapToGrid;
48
+ @Prop({ type: Number, reflect: true, defaultValue: 8 })
49
+ accessor gridSize = 8;
50
+ @Prop({ type: Number, reflect: false, defaultValue: null })
51
+ accessor focusedLinearIndex = null;
52
+ @Prop({ type: Number, reflect: true, defaultValue: 0 })
53
+ accessor simplify = 0;
54
+ @Prop({ type: Number, reflect: true, defaultValue: 5 })
55
+ accessor round = 5;
56
+ @Query('svg')
57
+ accessor svgElement;
58
+ #isDragging = false;
59
+ #dragIndex = null;
60
+ #dragMode = null;
61
+ #hoverPoint = null;
62
+ #hoverInsertPreview = null;
63
+ #dragStartPoints = null;
64
+ #dragPointId = null;
65
+ #pendingDrag = null;
66
+ #getEventTarget = () => {
67
+ const root = this.getRootNode();
68
+ if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
69
+ return root.host;
70
+ }
71
+ return this;
72
+ };
73
+ #renderCubicBezier = () => {
74
+ const points = this.#getCubicBezierPoints();
75
+ if (!points) {
76
+ console.warn('Invalid cubic-bezier points for rendering:', this.points);
77
+ return [];
78
+ }
79
+ try {
80
+ const anchorStart = this.#toSvgCoords({ x: 0, y: 0 });
81
+ const anchorEnd = this.#toSvgCoords({ x: 1, y: 1 });
82
+ const controlOne = this.#toSvgCoords(points.p1);
83
+ const controlTwo = this.#toSvgCoords(points.p2);
84
+ const elements = [];
85
+ const handlePathOne = this.#createHandlePath(anchorStart, controlOne);
86
+ const handlePathTwo = this.#createHandlePath(anchorEnd, controlTwo);
87
+ elements.push(svg `<circle
88
+ class="hit-area-point"
89
+ cx="${controlOne.x}"
90
+ cy="${controlOne.y}"
91
+ r="${HIT_AREA_RADIUS}"
92
+ data-index="0"
93
+ data-role="point"
94
+ />`);
95
+ elements.push(svg `<circle
96
+ class="hit-area-point"
97
+ cx="${controlTwo.x}"
98
+ cy="${controlTwo.y}"
99
+ r="${HIT_AREA_RADIUS}"
100
+ data-index="1"
101
+ data-role="point"
102
+ />`);
103
+ if (handlePathOne) {
104
+ elements.push(svg `<path
105
+ class="control-point ${this.#dragIndex === 0 && this.#dragMode === 'point' ? 'selected' : ''}"
106
+ d="${handlePathOne}"
107
+ data-index="0"
108
+ data-role="point"
109
+ />`);
110
+ }
111
+ if (handlePathTwo) {
112
+ elements.push(svg `<path
113
+ class="control-point ${this.#dragIndex === 1 && this.#dragMode === 'point' ? 'selected' : ''}"
114
+ d="${handlePathTwo}"
115
+ data-index="1"
116
+ data-role="point"
117
+ />`);
118
+ }
119
+ elements.push(svg `<circle class="anchor-point-start" cx="${anchorStart.x}" cy="${anchorStart.y}" />`);
120
+ elements.push(svg `<circle class="anchor-point-start" cx="${anchorEnd.x}" cy="${anchorEnd.y}" />`);
121
+ return elements;
122
+ }
123
+ catch (error) {
124
+ console.error('Error rendering cubic-bezier elements:', error);
125
+ return [];
126
+ }
127
+ };
128
+ #toSvgCoords = (p) => {
129
+ return {
130
+ x: p.x * SVG_WIDTH,
131
+ y: (1 - p.y) * SVG_HEIGHT
132
+ };
133
+ };
134
+ #renderLinear = () => {
135
+ const points = this.#getLinearPoints();
136
+ if (!points) {
137
+ return [];
138
+ }
139
+ try {
140
+ const elements = [];
141
+ const focusedIndex = this.focusedLinearIndex;
142
+ points.forEach((point, index) => {
143
+ if (!point) {
144
+ return;
145
+ }
146
+ const isPointFocused = focusedIndex === index;
147
+ const isDraggingPoint = this.#isDragging && this.#dragIndex === index;
148
+ if (!isPointFocused && !isDraggingPoint) {
149
+ return;
150
+ }
151
+ const anchorSvg = this.#toSvgCoords(point);
152
+ if (index > 0 && (point.cpInX !== undefined || point.cpInY !== undefined)) {
153
+ this.#renderLinearHandle(elements, point, anchorSvg, index, 'In');
154
+ }
155
+ if (index < points.length - 1 && (point.cpOutX !== undefined || point.cpOutY !== undefined)) {
156
+ this.#renderLinearHandle(elements, point, anchorSvg, index, 'Out');
157
+ }
158
+ });
159
+ points.forEach((point, index) => {
160
+ if (!point) {
161
+ return;
162
+ }
163
+ const isPointFocused = focusedIndex === index;
164
+ const isPointActive = (this.#dragMode === 'point' && this.#dragIndex === index) || isPointFocused;
165
+ const anchorSvg = this.#toSvgCoords(point);
166
+ elements.push(svg `<circle
167
+ class="hit-area-point"
168
+ cx="${anchorSvg.x}"
169
+ cy="${anchorSvg.y}"
170
+ r="${HIT_AREA_RADIUS}"
171
+ data-index="${index}"
172
+ data-role="point"
173
+ />`);
174
+ elements.push(svg `<circle
175
+ class="linear-point ${isPointActive ? 'selected' : ''}"
176
+ cx="${anchorSvg.x}"
177
+ cy="${anchorSvg.y}"
178
+ data-index="${index}"
179
+ data-role="point"
180
+ title="Point P${index + 1}: ${Math.round(point.x * 100)}%, ${Math.round(point.y * 100)}%"
181
+ />`);
182
+ });
183
+ return elements;
184
+ }
185
+ catch (error) {
186
+ console.error('Error rendering linear points:', error);
187
+ return [];
188
+ }
189
+ };
190
+ #renderLinearHandle(elements, point, anchorSvg, index, direction) {
191
+ const dx = direction === 'In' ? (point.cpInX ?? 0) : (point.cpOutX ?? 0);
192
+ const dy = direction === 'In' ? (point.cpInY ?? 0) : (point.cpOutY ?? 0);
193
+ const handlePos = { x: point.x + dx, y: point.y + dy };
194
+ const handleSvg = this.#toSvgCoords(handlePos);
195
+ const role = direction === 'In' ? 'handleIn' : 'handleOut';
196
+ const dragMode = direction === 'In' ? 'handleIn' : 'handleOut';
197
+ const isHandleActive = this.#dragMode === dragMode && this.#dragIndex === index;
198
+ const handlePath = this.#createHandlePath(anchorSvg, handleSvg);
199
+ if (!handlePath) {
200
+ return;
201
+ }
202
+ elements.push(svg `<circle
203
+ class="hit-area-handle"
204
+ cx="${handleSvg.x}"
205
+ cy="${handleSvg.y}"
206
+ r="${HIT_AREA_RADIUS}"
207
+ data-index="${index}"
208
+ data-role="${role}"
209
+ />`);
210
+ elements.push(svg `<path
211
+ class="linear-handle ${isHandleActive ? 'selected' : ''}"
212
+ d="${handlePath}"
213
+ data-index="${index}"
214
+ data-role="${role}"
215
+ title="Handle ${direction}: ${Math.round(handlePos.x * 100)}%, ${Math.round(handlePos.y * 100)}%"
216
+ />`);
217
+ }
218
+ #getCurvePath = () => {
219
+ try {
220
+ if (this.easingType === EasingType.CUBIC_BEZIER) {
221
+ const points = this.#getCubicBezierPoints();
222
+ if (!points) {
223
+ console.warn('Invalid cubic-bezier points:', this.points);
224
+ return '';
225
+ }
226
+ return cubicBezierPath(points);
227
+ }
228
+ const points = this.#getLinearPoints();
229
+ if (!points || points.length < 2) {
230
+ return '';
231
+ }
232
+ if (this.simplify > 0) {
233
+ const approxPoints = getLinearApproximation(points, {
234
+ simplify: this.simplify,
235
+ round: this.round
236
+ });
237
+ return linearDisplayPath(approxPoints);
238
+ }
239
+ return linearDisplayPath(points);
240
+ }
241
+ catch (error) {
242
+ console.error('Error generating curve path:', error);
243
+ return '';
244
+ }
245
+ };
246
+ #getHoverCurvePath = () => {
247
+ if (this.#isDragging) {
248
+ return '';
249
+ }
250
+ try {
251
+ if (this.easingType === EasingType.CUBIC_BEZIER) {
252
+ const hoverPoint = this.#hoverPoint;
253
+ if (!hoverPoint) {
254
+ return '';
255
+ }
256
+ const points = this.#getCubicBezierPoints();
257
+ if (!points) {
258
+ return '';
259
+ }
260
+ return cubicBezierPath({
261
+ p1: hoverPoint,
262
+ p2: points.p2
263
+ });
264
+ }
265
+ if (this.easingType === EasingType.LINEAR) {
266
+ return this.#hoverInsertPreview?.path ?? '';
267
+ }
268
+ return '';
269
+ }
270
+ catch (error) {
271
+ console.error('Error generating hover curve path:', error);
272
+ return '';
273
+ }
274
+ };
275
+ getHoverInsertElements() {
276
+ if (this.easingType !== EasingType.LINEAR) {
277
+ return null;
278
+ }
279
+ const preview = this.#hoverInsertPreview;
280
+ if (!preview || !preview.insertedPoint) {
281
+ return null;
282
+ }
283
+ const point = preview.insertedPoint;
284
+ const anchor = this.#toSvgCoords(point);
285
+ const elements = [];
286
+ if (point.cpInX !== undefined || point.cpInY !== undefined) {
287
+ const handlePoint = this.#toSvgCoords({
288
+ x: point.x + (point.cpInX ?? 0),
289
+ y: point.y + (point.cpInY ?? 0)
290
+ });
291
+ const handlePath = this.#createHandlePath(anchor, handlePoint);
292
+ if (handlePath) {
293
+ elements.push(svg `<path
294
+ class="linear-handle linear-handle--preview"
295
+ d="${handlePath}"
296
+ />`);
297
+ }
298
+ }
299
+ if (point.cpOutX !== undefined || point.cpOutY !== undefined) {
300
+ const handlePoint = this.#toSvgCoords({
301
+ x: point.x + (point.cpOutX ?? 0),
302
+ y: point.y + (point.cpOutY ?? 0)
303
+ });
304
+ const handlePath = this.#createHandlePath(anchor, handlePoint);
305
+ if (handlePath) {
306
+ elements.push(svg `<path
307
+ class="linear-handle linear-handle--preview"
308
+ d="${handlePath}"
309
+ />`);
310
+ }
311
+ }
312
+ elements.push(svg `<circle class="linear-point linear-point--preview" cx="${anchor.x}" cy="${anchor.y}" />`);
313
+ return svg `<g class="linear-preview-group" pointer-events="none">${elements}</g>`;
314
+ }
315
+ #createHandlePath(anchorSvg, handleSvg) {
316
+ const vecX = handleSvg.x - anchorSvg.x;
317
+ const vecY = handleSvg.y - anchorSvg.y;
318
+ const length = Math.sqrt(vecX * vecX + vecY * vecY);
319
+ const circleRadius = 4.5;
320
+ const barHalfHeight = 0.66;
321
+ if (length < circleRadius + 2) {
322
+ return null;
323
+ }
324
+ const dirX = vecX / length;
325
+ const dirY = vecY / length;
326
+ const perpX = -dirY;
327
+ const perpY = dirX;
328
+ const cx = handleSvg.x;
329
+ const cy = handleSvg.y;
330
+ const transitionZone = Math.min(8, (length - circleRadius) * 0.5);
331
+ const barEndDist = length - circleRadius - transitionZone;
332
+ const barTopStartX = anchorSvg.x + perpX * barHalfHeight;
333
+ const barTopStartY = anchorSvg.y + perpY * barHalfHeight;
334
+ const barBottomStartX = anchorSvg.x - perpX * barHalfHeight;
335
+ const barBottomStartY = anchorSvg.y - perpY * barHalfHeight;
336
+ const barTopEndX = anchorSvg.x + dirX * barEndDist + perpX * barHalfHeight;
337
+ const barTopEndY = anchorSvg.y + dirY * barEndDist + perpY * barHalfHeight;
338
+ const barBottomEndX = anchorSvg.x + dirX * barEndDist - perpX * barHalfHeight;
339
+ const barBottomEndY = anchorSvg.y + dirY * barEndDist - perpY * barHalfHeight;
340
+ const circleTopX = cx + perpX * circleRadius;
341
+ const circleTopY = cy + perpY * circleRadius;
342
+ const circleBottomX = cx - perpX * circleRadius;
343
+ const circleBottomY = cy - perpY * circleRadius;
344
+ const ctrl1Dist = transitionZone * 0.35;
345
+ const ctrl2Dist = transitionZone * 0.65;
346
+ const ctrl1TopX = barTopEndX + dirX * ctrl1Dist;
347
+ const ctrl1TopY = barTopEndY + dirY * ctrl1Dist;
348
+ const ctrl2TopX = circleTopX - dirX * ctrl2Dist;
349
+ const ctrl2TopY = circleTopY - dirY * ctrl2Dist;
350
+ const ctrl1BottomX = barBottomEndX + dirX * ctrl1Dist;
351
+ const ctrl1BottomY = barBottomEndY + dirY * ctrl1Dist;
352
+ const ctrl2BottomX = circleBottomX - dirX * ctrl2Dist;
353
+ const ctrl2BottomY = circleBottomY - dirY * ctrl2Dist;
354
+ return `
355
+ M ${circleBottomX} ${circleBottomY}
356
+ C ${ctrl2BottomX} ${ctrl2BottomY} ${ctrl1BottomX} ${ctrl1BottomY} ${barBottomEndX} ${barBottomEndY}
357
+ L ${barBottomStartX} ${barBottomStartY}
358
+ A ${barHalfHeight} ${barHalfHeight} 0 0 0 ${barTopStartX} ${barTopStartY}
359
+ L ${barTopEndX} ${barTopEndY}
360
+ C ${ctrl1TopX} ${ctrl1TopY} ${ctrl2TopX} ${ctrl2TopY} ${circleTopX} ${circleTopY}
361
+ A ${circleRadius} ${circleRadius} 0 1 0 ${circleBottomX} ${circleBottomY}
362
+ Z
363
+ `;
364
+ }
365
+ #getCubicBezierPoints = () => {
366
+ if (Array.isArray(this.points)) {
367
+ return null;
368
+ }
369
+ return this.points ?? null;
370
+ };
371
+ #getLinearPoints = () => {
372
+ if (!Array.isArray(this.points)) {
373
+ return null;
374
+ }
375
+ this.#ensureLinearPointIds(this.points);
376
+ return this.points;
377
+ };
378
+ #ensureLinearPointIds = (points) => {
379
+ if (!points) {
380
+ return;
381
+ }
382
+ for (const point of points) {
383
+ if (!point) {
384
+ continue;
385
+ }
386
+ ensureLinearPointId(point);
387
+ }
388
+ };
389
+ #createLinearStartPointMap = (points) => {
390
+ if (!points) {
391
+ return null;
392
+ }
393
+ const map = new Map();
394
+ for (const point of points) {
395
+ if (!point) {
396
+ continue;
397
+ }
398
+ const id = ensureLinearPointId(point);
399
+ map.set(id, cloneLinearPoint(point));
400
+ }
401
+ return map;
402
+ };
403
+ #getDistanceToLinearPath(point, points) {
404
+ if (points.length < 2) {
405
+ return Number.POSITIVE_INFINITY;
406
+ }
407
+ let minDistanceSquared = Number.POSITIVE_INFINITY;
408
+ for (let index = 0; index < points.length - 1; index += 1) {
409
+ const start = points[index];
410
+ const end = points[index + 1];
411
+ if (!start || !end) {
412
+ continue;
413
+ }
414
+ const cp1 = {
415
+ x: start.x + (start.cpOutX ?? 0),
416
+ y: start.y + (start.cpOutY ?? 0)
417
+ };
418
+ const cp2 = {
419
+ x: end.x + (end.cpInX ?? 0),
420
+ y: end.y + (end.cpInY ?? 0)
421
+ };
422
+ for (let sample = 0; sample <= LINEAR_PATH_SAMPLES; sample += 1) {
423
+ const t = sample / LINEAR_PATH_SAMPLES;
424
+ const samplePoint = evaluateCubicPointNormalized(t, start, cp1, cp2, end);
425
+ const dx = point.x - samplePoint.x;
426
+ const dy = point.y - samplePoint.y;
427
+ const distanceSquared = dx * dx + dy * dy;
428
+ if (distanceSquared < minDistanceSquared) {
429
+ minDistanceSquared = distanceSquared;
430
+ }
431
+ }
432
+ }
433
+ return Math.sqrt(minDistanceSquared);
434
+ }
435
+ #isPointNearLinearPath(point, points) {
436
+ const distance = this.#getDistanceToLinearPath(point, points);
437
+ return distance <= LINEAR_HIT_THRESHOLD;
438
+ }
439
+ #isNearExistingPointOrHandle(position, points) {
440
+ const mouseSvg = this.#toSvgCoords(position);
441
+ const thresholdSquared = HIT_AREA_RADIUS * HIT_AREA_RADIUS;
442
+ for (const point of points) {
443
+ if (!point) {
444
+ continue;
445
+ }
446
+ const pointSvg = this.#toSvgCoords(point);
447
+ const dx = pointSvg.x - mouseSvg.x;
448
+ const dy = pointSvg.y - mouseSvg.y;
449
+ if (dx * dx + dy * dy < thresholdSquared) {
450
+ return true;
451
+ }
452
+ if (point.cpInX !== undefined || point.cpInY !== undefined) {
453
+ const handleIn = {
454
+ x: point.x + (point.cpInX ?? 0),
455
+ y: point.y + (point.cpInY ?? 0)
456
+ };
457
+ const handleInSvg = this.#toSvgCoords(handleIn);
458
+ const hdx = handleInSvg.x - mouseSvg.x;
459
+ const hdy = handleInSvg.y - mouseSvg.y;
460
+ if (hdx * hdx + hdy * hdy < thresholdSquared) {
461
+ return true;
462
+ }
463
+ }
464
+ if (point.cpOutX !== undefined || point.cpOutY !== undefined) {
465
+ const handleOut = {
466
+ x: point.x + (point.cpOutX ?? 0),
467
+ y: point.y + (point.cpOutY ?? 0)
468
+ };
469
+ const handleOutSvg = this.#toSvgCoords(handleOut);
470
+ const hdx = handleOutSvg.x - mouseSvg.x;
471
+ const hdy = handleOutSvg.y - mouseSvg.y;
472
+ if (hdx * hdx + hdy * hdy < thresholdSquared) {
473
+ return true;
474
+ }
475
+ }
476
+ }
477
+ return false;
478
+ }
479
+ #getMousePosition = (event, options) => {
480
+ const svgElement = this.svgElement;
481
+ if (!svgElement) {
482
+ return { x: 0, y: 0 };
483
+ }
484
+ const rect = svgElement.getBoundingClientRect();
485
+ const svgX = event.clientX - rect.left;
486
+ const svgY = event.clientY - rect.top;
487
+ let x = svgX / rect.width;
488
+ let y = 1 - svgY / rect.height;
489
+ const skipSnap = options?.skipSnap ?? false;
490
+ const shouldSnap = !skipSnap &&
491
+ this.snapToGrid &&
492
+ !(this.#isDragging && (this.#dragMode === 'handleIn' || this.#dragMode === 'handleOut'));
493
+ if (shouldSnap) {
494
+ const ratioX = SVG_WIDTH / this.gridSize;
495
+ const ratioY = SVG_HEIGHT / this.gridSize;
496
+ x = Math.round(x * ratioX) / ratioX;
497
+ y = Math.round(y * ratioY) / ratioY;
498
+ }
499
+ const bezierBounds = this.easingType === EasingType.CUBIC_BEZIER
500
+ ? { minY: BEZIER_CONTROL_MIN_Y, maxY: BEZIER_CONTROL_MAX_Y }
501
+ : undefined;
502
+ return clampPoint({ x, y }, bezierBounds);
503
+ };
504
+ #constrainLinearPoint = (index, position, points) => {
505
+ let x = position.x;
506
+ if (index === 0) {
507
+ x = 0;
508
+ }
509
+ else if (index === points.length - 1) {
510
+ x = 1;
511
+ }
512
+ else {
513
+ x = Math.min(Math.max(x, MIN_LINEAR_DELTA), 1 - MIN_LINEAR_DELTA);
514
+ }
515
+ const clamped = clampPoint({ x, y: position.y }, { minY: -2, maxY: 3 });
516
+ const sourcePoint = points[index];
517
+ return {
518
+ ...sourcePoint,
519
+ x: clamped.x,
520
+ y: clamped.y
521
+ };
522
+ };
523
+ #emitPoints = (value, event) => {
524
+ const target = this.#getEventTarget();
525
+ const detail = { value, event };
526
+ dispatchControlEvent(target, 'points-change', detail);
527
+ };
528
+ #notifyLinearFocus = (index, event) => {
529
+ if (this.easingType !== EasingType.LINEAR) {
530
+ return;
531
+ }
532
+ const target = this.#getEventTarget();
533
+ const detail = { value: index, event };
534
+ dispatchControlEvent(target, 'linear-point-focus', detail);
535
+ };
536
+ #toggleLinearHandleLinking = (index, event) => {
537
+ const points = this.#getLinearPoints();
538
+ if (!points || index < 0 || index >= points.length) {
539
+ return;
540
+ }
541
+ const point = points[index];
542
+ if (!point) {
543
+ return;
544
+ }
545
+ const updatedPoints = [...points];
546
+ const updatedPoint = { ...point };
547
+ updatedPoints[index] = updatedPoint;
548
+ const newLinkingState = !updatedPoint.isLinked;
549
+ updatedPoint.isLinked = newLinkingState;
550
+ updatedPoint.mirrorLength = Boolean(newLinkingState);
551
+ if (newLinkingState) {
552
+ this.#ensureLinkedHandles(updatedPoint, index, points);
553
+ }
554
+ const normalizedPoints = normalizeLinearPoints(updatedPoints);
555
+ this.points = normalizedPoints;
556
+ this.#emitPoints(normalizedPoints, event);
557
+ this.#notifyLinearFocus(index, event);
558
+ this.requestRender();
559
+ };
560
+ #ensureLinkedHandles(point, index, points) {
561
+ const prev = points[index - 1];
562
+ const next = points[index + 1];
563
+ let refDx = point.cpOutX ?? -(point.cpInX ?? 0);
564
+ let refDy = point.cpOutY ?? -(point.cpInY ?? 0);
565
+ if (refDx === 0 && refDy === 0) {
566
+ let dirX = 0;
567
+ let dirY = 0;
568
+ if (prev && next) {
569
+ dirX = next.x - prev.x;
570
+ dirY = next.y - prev.y;
571
+ }
572
+ else if (next) {
573
+ dirX = next.x - point.x;
574
+ dirY = next.y - point.y;
575
+ }
576
+ else if (prev) {
577
+ dirX = point.x - prev.x;
578
+ dirY = point.y - prev.y;
579
+ }
580
+ else {
581
+ dirX = 1;
582
+ dirY = 0;
583
+ }
584
+ const direction = normalizeVector(dirX, dirY);
585
+ const length = DEFAULT_HANDLE_LENGTH;
586
+ point.cpInX = -direction.dx * length;
587
+ point.cpInY = -direction.dy * length;
588
+ point.cpOutX = direction.dx * length;
589
+ point.cpOutY = direction.dy * length;
590
+ refDx = point.cpOutX;
591
+ refDy = point.cpOutY;
592
+ }
593
+ if (refDx === 0 && refDy === 0) {
594
+ return;
595
+ }
596
+ const normalized = normalizeVector(refDx, refDy);
597
+ const referenceLength = vectorLength(refDx, refDy) || DEFAULT_HANDLE_LENGTH;
598
+ const inLength = vectorLength(point.cpInX ?? 0, point.cpInY ?? 0) || referenceLength;
599
+ point.cpInX = -normalized.dx * inLength;
600
+ point.cpInY = -normalized.dy * inLength;
601
+ const outLength = vectorLength(point.cpOutX ?? 0, point.cpOutY ?? 0) || referenceLength;
602
+ point.cpOutX = normalized.dx * outLength;
603
+ point.cpOutY = normalized.dy * outLength;
604
+ if (point.mirrorLength !== false) {
605
+ this.#alignLinkedHandleLengths(point);
606
+ }
607
+ }
608
+ #alignLinkedHandleLengths(point) {
609
+ if (!point.isLinked) {
610
+ point.mirrorLength = false;
611
+ return;
612
+ }
613
+ const outLength = vectorLength(point.cpOutX ?? 0, point.cpOutY ?? 0);
614
+ const inLength = vectorLength(point.cpInX ?? 0, point.cpInY ?? 0);
615
+ const targetLength = Math.max(outLength, inLength);
616
+ if (targetLength <= 0) {
617
+ return;
618
+ }
619
+ if (outLength > 0) {
620
+ const outDirection = normalizeVector(point.cpOutX ?? 0, point.cpOutY ?? 0);
621
+ point.cpOutX = outDirection.dx * targetLength;
622
+ point.cpOutY = outDirection.dy * targetLength;
623
+ }
624
+ else if (inLength > 0) {
625
+ const inDirection = normalizeVector(point.cpInX ?? 0, point.cpInY ?? 0);
626
+ point.cpOutX = -inDirection.dx * targetLength;
627
+ point.cpOutY = -inDirection.dy * targetLength;
628
+ }
629
+ if (inLength > 0) {
630
+ const inDirection = normalizeVector(point.cpInX ?? 0, point.cpInY ?? 0);
631
+ point.cpInX = inDirection.dx * targetLength;
632
+ point.cpInY = inDirection.dy * targetLength;
633
+ }
634
+ else if (outLength > 0) {
635
+ const outDirection = normalizeVector(point.cpOutX ?? 0, point.cpOutY ?? 0);
636
+ point.cpInX = -outDirection.dx * targetLength;
637
+ point.cpInY = -outDirection.dy * targetLength;
638
+ }
639
+ }
640
+ getGridLines() {
641
+ return generateGridLines(this.gridSize);
642
+ }
643
+ getControlElements() {
644
+ return this.easingType === EasingType.CUBIC_BEZIER ? this.#renderCubicBezier() : this.#renderLinear();
645
+ }
646
+ getCurvePath() {
647
+ return this.#getCurvePath();
648
+ }
649
+ getHoverCurvePath() {
650
+ return this.#getHoverCurvePath();
651
+ }
652
+ handlePointerDown = (event) => {
653
+ event.preventDefault();
654
+ let linearPoints = this.easingType === EasingType.LINEAR ? this.#getLinearPoints() : null;
655
+ this.#dragStartPoints = this.#createLinearStartPointMap(linearPoints);
656
+ this.#pendingDrag = null;
657
+ this.#dragPointId = null;
658
+ const target = event.target;
659
+ if (!(target instanceof SVGElement)) {
660
+ return;
661
+ }
662
+ const role = target.getAttribute('data-role');
663
+ const indexAttribute = target.getAttribute('data-index');
664
+ if (indexAttribute !== null) {
665
+ const index = Number.parseInt(indexAttribute, 10);
666
+ if (Number.isNaN(index)) {
667
+ return;
668
+ }
669
+ if (this.easingType === EasingType.LINEAR) {
670
+ if (role === 'handleIn' || role === 'handleOut') {
671
+ const point = linearPoints?.[index];
672
+ if (point) {
673
+ this.#dragPointId = ensureLinearPointId(point);
674
+ }
675
+ this.svgElement?.setPointerCapture(event.pointerId);
676
+ this.#isDragging = true;
677
+ this.#dragMode = role;
678
+ this.#dragIndex = index;
679
+ this.#pendingDrag = null;
680
+ this.#hoverPoint = null;
681
+ this.#notifyLinearFocus(index, event);
682
+ this.handlePointerMove(event);
683
+ this.requestRender();
684
+ return;
685
+ }
686
+ if (role === 'point') {
687
+ if (event.detail === 2) {
688
+ this.#toggleLinearHandleLinking(index, event);
689
+ return;
690
+ }
691
+ const point = linearPoints?.[index];
692
+ if (point) {
693
+ this.#dragPointId = ensureLinearPointId(point);
694
+ }
695
+ this.#notifyLinearFocus(index, event);
696
+ this.svgElement?.setPointerCapture(event.pointerId);
697
+ this.#isDragging = false;
698
+ this.#dragMode = 'point';
699
+ this.#dragIndex = index;
700
+ this.#pendingDrag = {
701
+ mode: 'point',
702
+ index,
703
+ startX: event.clientX,
704
+ startY: event.clientY
705
+ };
706
+ this.#hoverPoint = null;
707
+ this.requestRender();
708
+ return;
709
+ }
710
+ }
711
+ if (this.easingType === EasingType.CUBIC_BEZIER && role === 'point') {
712
+ this.svgElement?.setPointerCapture(event.pointerId);
713
+ this.#isDragging = true;
714
+ this.#dragMode = 'point';
715
+ this.#dragIndex = index;
716
+ this.#hoverPoint = null;
717
+ this.requestRender();
718
+ return;
719
+ }
720
+ }
721
+ if (indexAttribute === null) {
722
+ if (this.easingType === EasingType.LINEAR) {
723
+ const insertResult = this.#insertLinearPoint(this.#getMousePosition(event), event);
724
+ if (insertResult) {
725
+ linearPoints = this.#getLinearPoints();
726
+ this.#dragStartPoints = this.#createLinearStartPointMap(linearPoints);
727
+ this.#dragPointId = insertResult.pointId;
728
+ this.svgElement?.setPointerCapture(event.pointerId);
729
+ this.#isDragging = true;
730
+ this.#dragMode = 'point';
731
+ this.#dragIndex = insertResult.index;
732
+ this.#pendingDrag = null;
733
+ this.#hoverPoint = null;
734
+ this.#notifyLinearFocus(insertResult.index, event);
735
+ this.requestRender();
736
+ return;
737
+ }
738
+ else {
739
+ this.#notifyLinearFocus(null, event);
740
+ }
741
+ }
742
+ if (this.easingType === EasingType.CUBIC_BEZIER) {
743
+ this.#hoverPoint = this.#getMousePosition(event);
744
+ this.svgElement?.setPointerCapture(event.pointerId);
745
+ this.#isDragging = true;
746
+ this.#dragMode = 'point';
747
+ this.#dragIndex = 0;
748
+ this.#pendingDrag = null;
749
+ this.handlePointerMove(event);
750
+ this.requestRender();
751
+ return;
752
+ }
753
+ }
754
+ };
755
+ handlePointerMove = (event) => {
756
+ if (!this.svgElement) {
757
+ return;
758
+ }
759
+ const skipSnapForPending = !this.#isDragging && this.#pendingDrag !== null && this.#pendingDrag.mode === 'point';
760
+ let position = this.#getMousePosition(event, { skipSnap: skipSnapForPending });
761
+ if (this.#pendingDrag && !this.#isDragging) {
762
+ const deltaX = event.clientX - this.#pendingDrag.startX;
763
+ const deltaY = event.clientY - this.#pendingDrag.startY;
764
+ const distanceSquared = deltaX * deltaX + deltaY * deltaY;
765
+ if (distanceSquared >= DRAG_ACTIVATION_DISTANCE_PX_SQUARED) {
766
+ this.#isDragging = true;
767
+ this.#pendingDrag = null;
768
+ if (skipSnapForPending) {
769
+ position = this.#getMousePosition(event);
770
+ }
771
+ }
772
+ else {
773
+ return;
774
+ }
775
+ }
776
+ if (this.#isDragging && this.#dragIndex !== null) {
777
+ event.preventDefault();
778
+ this.#hoverInsertPreview = null;
779
+ if (this.easingType === EasingType.LINEAR) {
780
+ const points = this.#getLinearPoints();
781
+ if (!points || this.#dragIndex >= points.length) {
782
+ return;
783
+ }
784
+ if (this.#dragMode === 'point') {
785
+ this.#handleLinearPointDrag(points, this.#dragIndex, position, event);
786
+ return;
787
+ }
788
+ if (this.#dragMode === 'handleIn' || this.#dragMode === 'handleOut') {
789
+ this.#handleLinearHandleDrag(points, this.#dragIndex, position, event);
790
+ return;
791
+ }
792
+ }
793
+ if (this.easingType === EasingType.CUBIC_BEZIER) {
794
+ const points = this.#getCubicBezierPoints();
795
+ if (!points) {
796
+ return;
797
+ }
798
+ const updatedPoints = { ...points };
799
+ let adjustedPosition = position;
800
+ if (event.shiftKey) {
801
+ const reference = this.#dragIndex === 0 ? points.p1 : points.p2;
802
+ if (reference) {
803
+ const deltaX = Math.abs(position.x - reference.x);
804
+ const deltaY = Math.abs(position.y - reference.y);
805
+ adjustedPosition = deltaX > deltaY ? { x: position.x, y: reference.y } : { x: reference.x, y: position.y };
806
+ }
807
+ }
808
+ const clampedPosition = clampPoint(adjustedPosition, {
809
+ minY: BEZIER_CONTROL_MIN_Y,
810
+ maxY: BEZIER_CONTROL_MAX_Y
811
+ });
812
+ if (this.#dragIndex === 0) {
813
+ updatedPoints.p1 = clampedPosition;
814
+ }
815
+ else if (this.#dragIndex === 1) {
816
+ updatedPoints.p2 = clampedPosition;
817
+ }
818
+ else {
819
+ return;
820
+ }
821
+ this.points = updatedPoints;
822
+ this.#emitPoints(updatedPoints, event);
823
+ this.requestRender();
824
+ return;
825
+ }
826
+ return;
827
+ }
828
+ if (this.easingType === EasingType.LINEAR) {
829
+ const points = this.#getLinearPoints();
830
+ // Use rawPosition for the hit test to avoid flickering when snapToGrid is on
831
+ if (points && this.#isNearExistingPointOrHandle(position, points)) {
832
+ this.#hoverInsertPreview = null;
833
+ this.#hoverPoint = null;
834
+ this.requestRender();
835
+ return;
836
+ }
837
+ const preview = this.#buildLinearInsertPreview(position);
838
+ this.#hoverInsertPreview = preview;
839
+ if (!preview) {
840
+ this.#hoverPoint = null;
841
+ this.requestRender();
842
+ return;
843
+ }
844
+ }
845
+ else {
846
+ this.#hoverInsertPreview = null;
847
+ }
848
+ this.#hoverPoint = position;
849
+ this.requestRender();
850
+ };
851
+ #handleLinearPointDrag(points, index, position, event) {
852
+ let workingPosition = position;
853
+ const currentPoint = points[index];
854
+ const activePointId = currentPoint ? (this.#dragPointId ?? ensureLinearPointId(currentPoint)) : null;
855
+ if (event.shiftKey && this.#dragStartPoints && activePointId) {
856
+ const startPoint = this.#dragStartPoints.get(activePointId);
857
+ if (startPoint) {
858
+ const deltaX = Math.abs(position.x - startPoint.x);
859
+ const deltaY = Math.abs(position.y - startPoint.y);
860
+ workingPosition = deltaX > deltaY ? { x: position.x, y: startPoint.y } : { x: startPoint.x, y: position.y };
861
+ }
862
+ }
863
+ const constrainedPoint = this.#constrainLinearPoint(index, workingPosition, points);
864
+ const updatedPoints = points.map((point, i) => {
865
+ if (i === index) {
866
+ return constrainedPoint;
867
+ }
868
+ return { ...point };
869
+ });
870
+ const normalizedPoints = normalizeLinearPoints(updatedPoints);
871
+ this.points = normalizedPoints;
872
+ this.#emitPoints(normalizedPoints, event);
873
+ if (activePointId) {
874
+ const newIndex = normalizedPoints.findIndex((point) => point?.id === activePointId);
875
+ if (newIndex !== -1) {
876
+ this.#dragIndex = newIndex;
877
+ this.#dragPointId = activePointId;
878
+ this.#notifyLinearFocus(newIndex, event);
879
+ }
880
+ else {
881
+ this.#notifyLinearFocus(index, event);
882
+ }
883
+ }
884
+ else {
885
+ this.#notifyLinearFocus(index, event);
886
+ }
887
+ this.requestRender();
888
+ }
889
+ #handleLinearHandleDrag(points, index, position, event) {
890
+ const point = points[index];
891
+ if (!point) {
892
+ return;
893
+ }
894
+ const activePointId = this.#dragPointId ?? ensureLinearPointId(point);
895
+ const direction = this.#dragMode === 'handleIn' ? 'In' : 'Out';
896
+ let dx = position.x - point.x;
897
+ const dy = position.y - point.y;
898
+ if (direction === 'In') {
899
+ dx = Math.min(0, dx);
900
+ }
901
+ else {
902
+ dx = Math.max(0, dx);
903
+ }
904
+ let isLinked = point.isLinked ?? false;
905
+ if (event.shiftKey) {
906
+ isLinked = false;
907
+ }
908
+ const updatedPoints = [...points];
909
+ const updatedPoint = { ...point };
910
+ updatedPoints[index] = updatedPoint;
911
+ updatedPoint.isLinked = isLinked;
912
+ if (direction === 'In') {
913
+ updatedPoint.cpInX = dx;
914
+ updatedPoint.cpInY = dy;
915
+ }
916
+ else {
917
+ updatedPoint.cpOutX = dx;
918
+ updatedPoint.cpOutY = dy;
919
+ }
920
+ const mirrorAngle = isLinked;
921
+ const mirrorLength = mirrorAngle && updatedPoint.mirrorLength !== false;
922
+ if (mirrorAngle || mirrorLength) {
923
+ const draggedLength = vectorLength(dx, dy);
924
+ if (draggedLength <= MIN_LINEAR_DELTA) {
925
+ if (direction === 'In') {
926
+ delete updatedPoint.cpInX;
927
+ delete updatedPoint.cpInY;
928
+ if (mirrorAngle) {
929
+ delete updatedPoint.cpOutX;
930
+ delete updatedPoint.cpOutY;
931
+ }
932
+ }
933
+ else {
934
+ delete updatedPoint.cpOutX;
935
+ delete updatedPoint.cpOutY;
936
+ if (mirrorAngle) {
937
+ delete updatedPoint.cpInX;
938
+ delete updatedPoint.cpInY;
939
+ }
940
+ }
941
+ }
942
+ else {
943
+ const normalized = normalizeVector(dx, dy);
944
+ if (mirrorAngle) {
945
+ if (direction === 'In') {
946
+ const existingLength = mirrorLength
947
+ ? draggedLength
948
+ : vectorLength(updatedPoint.cpOutX ?? 0, updatedPoint.cpOutY ?? 0) || draggedLength;
949
+ updatedPoint.cpOutX = -normalized.dx * existingLength;
950
+ updatedPoint.cpOutY = -normalized.dy * existingLength;
951
+ }
952
+ else {
953
+ const existingLength = mirrorLength
954
+ ? draggedLength
955
+ : vectorLength(updatedPoint.cpInX ?? 0, updatedPoint.cpInY ?? 0) || draggedLength;
956
+ updatedPoint.cpInX = -normalized.dx * existingLength;
957
+ updatedPoint.cpInY = -normalized.dy * existingLength;
958
+ }
959
+ }
960
+ else if (mirrorLength) {
961
+ if (direction === 'In') {
962
+ const inDirection = normalizeVector(updatedPoint.cpInX ?? 0, updatedPoint.cpInY ?? 0);
963
+ const outDirection = normalizeVector(updatedPoint.cpOutX ?? 0, updatedPoint.cpOutY ?? 0);
964
+ const outLength = vectorLength(updatedPoint.cpOutX ?? 0, updatedPoint.cpOutY ?? 0);
965
+ if (outLength > 0) {
966
+ updatedPoint.cpOutX = outDirection.dx * draggedLength;
967
+ updatedPoint.cpOutY = outDirection.dy * draggedLength;
968
+ }
969
+ updatedPoint.cpInX = inDirection.dx * draggedLength;
970
+ updatedPoint.cpInY = inDirection.dy * draggedLength;
971
+ }
972
+ else {
973
+ const inDirection = normalizeVector(updatedPoint.cpInX ?? 0, updatedPoint.cpInY ?? 0);
974
+ const outDirection = normalizeVector(updatedPoint.cpOutX ?? 0, updatedPoint.cpOutY ?? 0);
975
+ const inLength = vectorLength(updatedPoint.cpInX ?? 0, updatedPoint.cpInY ?? 0);
976
+ if (inLength > 0) {
977
+ updatedPoint.cpInX = inDirection.dx * draggedLength;
978
+ updatedPoint.cpInY = inDirection.dy * draggedLength;
979
+ }
980
+ updatedPoint.cpOutX = outDirection.dx * draggedLength;
981
+ updatedPoint.cpOutY = outDirection.dy * draggedLength;
982
+ }
983
+ }
984
+ if (mirrorLength) {
985
+ this.#alignLinkedHandleLengths(updatedPoint);
986
+ }
987
+ }
988
+ }
989
+ const normalizedPoints = normalizeLinearPoints(updatedPoints);
990
+ this.points = normalizedPoints;
991
+ this.#emitPoints(normalizedPoints, event);
992
+ if (activePointId) {
993
+ const newIndex = normalizedPoints.findIndex((candidate) => candidate?.id === activePointId);
994
+ if (newIndex !== -1) {
995
+ this.#dragIndex = newIndex;
996
+ this.#dragPointId = activePointId;
997
+ this.#notifyLinearFocus(newIndex, event);
998
+ }
999
+ else {
1000
+ this.#notifyLinearFocus(index, event);
1001
+ }
1002
+ }
1003
+ else {
1004
+ this.#notifyLinearFocus(index, event);
1005
+ }
1006
+ this.requestRender();
1007
+ }
1008
+ handlePointerUp = (event) => {
1009
+ const previousIndex = this.#dragIndex;
1010
+ if (this.svgElement?.hasPointerCapture(event.pointerId)) {
1011
+ this.svgElement.releasePointerCapture(event.pointerId);
1012
+ }
1013
+ this.#isDragging = false;
1014
+ this.#dragIndex = null;
1015
+ this.#dragMode = null;
1016
+ this.#dragStartPoints = null;
1017
+ this.#dragPointId = null;
1018
+ this.#pendingDrag = null;
1019
+ this.#hoverInsertPreview = null;
1020
+ if (previousIndex !== null && this.easingType === EasingType.LINEAR) {
1021
+ this.#notifyLinearFocus(previousIndex, event);
1022
+ }
1023
+ this.requestRender();
1024
+ };
1025
+ handlePointerLeave = (event) => {
1026
+ if (this.#isDragging) {
1027
+ this.handlePointerUp(event);
1028
+ }
1029
+ this.#pendingDrag = null;
1030
+ this.#hoverPoint = null;
1031
+ this.#dragPointId = null;
1032
+ this.#hoverInsertPreview = null;
1033
+ this.requestRender();
1034
+ };
1035
+ #insertLinearPoint(position, event) {
1036
+ const preview = this.#hoverInsertPreview ?? this.#buildLinearInsertPreview(position);
1037
+ if (!preview) {
1038
+ return null;
1039
+ }
1040
+ const { normalizedPoints, insertedIndex, insertedPoint } = preview;
1041
+ const insertedPointId = insertedPoint ? ensureLinearPointId(insertedPoint) : null;
1042
+ this.points = normalizedPoints;
1043
+ this.#emitPoints(normalizedPoints, event);
1044
+ this.requestRender();
1045
+ this.#hoverInsertPreview = null;
1046
+ return {
1047
+ index: insertedIndex,
1048
+ pointId: insertedPointId
1049
+ };
1050
+ }
1051
+ #buildLinearInsertPreview(position) {
1052
+ if (this.easingType !== EasingType.LINEAR) {
1053
+ return null;
1054
+ }
1055
+ const points = this.#getLinearPoints();
1056
+ if (!points || points.length >= MAX_LINEAR_POINTS) {
1057
+ return null;
1058
+ }
1059
+ // Allow Y values outside [0, 1] for bounce/elastic effects
1060
+ const clamped = clampPoint(position, { minY: -2, maxY: 3 });
1061
+ if (!this.#isPointNearLinearPath(clamped, points)) {
1062
+ return null;
1063
+ }
1064
+ const insertIndex = points.findIndex((point) => clamped.x < point.x);
1065
+ if (insertIndex <= 0) {
1066
+ return null;
1067
+ }
1068
+ const prev = points[insertIndex - 1];
1069
+ const next = points[insertIndex];
1070
+ if (!prev || !next) {
1071
+ return null;
1072
+ }
1073
+ if (clamped.x - prev.x < MIN_LINEAR_DELTA || next.x - clamped.x < MIN_LINEAR_DELTA) {
1074
+ return null;
1075
+ }
1076
+ let updatedPoints;
1077
+ let insertedPointId = null;
1078
+ const splitResult = splitCurveSegment(prev, next, clamped);
1079
+ if (splitResult) {
1080
+ const { prev: newPrev, newPoint, next: newNext } = splitResult;
1081
+ insertedPointId = ensureLinearPointId(newPoint);
1082
+ updatedPoints = [
1083
+ ...points.slice(0, insertIndex - 1),
1084
+ newPrev,
1085
+ newPoint,
1086
+ newNext,
1087
+ ...points.slice(insertIndex + 1)
1088
+ ];
1089
+ }
1090
+ else {
1091
+ const newPoint = {
1092
+ x: clamped.x,
1093
+ y: clamped.y,
1094
+ cpInX: -0.1,
1095
+ cpInY: 0,
1096
+ cpOutX: 0.1,
1097
+ cpOutY: 0,
1098
+ isLinked: true,
1099
+ mirrorLength: true
1100
+ };
1101
+ insertedPointId = ensureLinearPointId(newPoint);
1102
+ updatedPoints = [...points.slice(0, insertIndex), newPoint, ...points.slice(insertIndex)];
1103
+ }
1104
+ const normalizedPoints = normalizeLinearPoints(updatedPoints);
1105
+ const normalizedIndex = insertedPointId !== null ? normalizedPoints.findIndex((point) => point?.id === insertedPointId) : -1;
1106
+ const insertedIndex = normalizedIndex !== -1 ? normalizedIndex : insertIndex;
1107
+ const insertedPoint = normalizedPoints[insertedIndex];
1108
+ if (!insertedPoint) {
1109
+ return null;
1110
+ }
1111
+ return {
1112
+ path: linearDisplayPath(normalizedPoints),
1113
+ normalizedPoints,
1114
+ insertedIndex,
1115
+ insertedPoint
1116
+ };
1117
+ }
1118
+ }
1119
+ const lerp = (a, b, t) => a + (b - a) * t;
1120
+ const lerpPoint = (p1, p2, t) => {
1121
+ return {
1122
+ x: lerp(p1.x, p2.x, t),
1123
+ y: lerp(p1.y, p2.y, t)
1124
+ };
1125
+ };
1126
+ // Helper to find t for a given x on a cubic bezier curve
1127
+ const findTForX = (x, p0, cp1, cp2, p3) => {
1128
+ let minT = 0;
1129
+ let maxT = 1;
1130
+ let t = 0.5;
1131
+ const tolerance = 0.0001;
1132
+ const maxIterations = 20;
1133
+ // Use binary search since x is monotonic
1134
+ for (let i = 0; i < maxIterations; i++) {
1135
+ const px = (1 - t) ** 3 * p0.x + 3 * (1 - t) ** 2 * t * cp1.x + 3 * (1 - t) * t ** 2 * cp2.x + t ** 3 * p3.x;
1136
+ if (Math.abs(px - x) < tolerance) {
1137
+ return t;
1138
+ }
1139
+ if (px < x) {
1140
+ minT = t;
1141
+ }
1142
+ else {
1143
+ maxT = t;
1144
+ }
1145
+ t = (minT + maxT) / 2;
1146
+ }
1147
+ return t;
1148
+ };
1149
+ const splitCurveSegment = (prev, next, position) => {
1150
+ const cp1 = {
1151
+ x: prev.x + (prev.cpOutX ?? 0),
1152
+ y: prev.y + (prev.cpOutY ?? 0)
1153
+ };
1154
+ const cp2 = {
1155
+ x: next.x + (next.cpInX ?? 0),
1156
+ y: next.y + (next.cpInY ?? 0)
1157
+ };
1158
+ const wasCurved = prev.cpOutX || prev.cpOutY || next.cpInX || next.cpInY;
1159
+ if (!wasCurved) {
1160
+ return null;
1161
+ }
1162
+ // Find the correct t parameter that corresponds to the mouse X position
1163
+ const t = findTForX(position.x, prev, cp1, cp2, next);
1164
+ const P01 = lerpPoint(prev, cp1, t);
1165
+ const P12 = lerpPoint(cp1, cp2, t);
1166
+ const P23 = lerpPoint(cp2, next, t);
1167
+ const P012 = lerpPoint(P01, P12, t);
1168
+ const P123 = lerpPoint(P12, P23, t);
1169
+ const P_new = lerpPoint(P012, P123, t);
1170
+ const newPoint = {
1171
+ x: P_new.x,
1172
+ y: P_new.y,
1173
+ cpInX: P012.x - P_new.x,
1174
+ cpInY: P012.y - P_new.y,
1175
+ cpOutX: P123.x - P_new.x,
1176
+ cpOutY: P123.y - P_new.y,
1177
+ isLinked: true,
1178
+ mirrorLength: prev.mirrorLength === false && next.mirrorLength
1179
+ };
1180
+ ensureLinearPointId(newPoint);
1181
+ const newPrev = {
1182
+ ...prev,
1183
+ cpOutX: P01.x - prev.x,
1184
+ cpOutY: P01.y - prev.y
1185
+ };
1186
+ const newNext = {
1187
+ ...next,
1188
+ cpInX: P23.x - next.x,
1189
+ cpInY: P23.y - next.y
1190
+ };
1191
+ return {
1192
+ prev: newPrev,
1193
+ newPoint,
1194
+ next: newNext
1195
+ };
1196
+ };
1197
+ const evaluateCubicPointNormalized = (t, p0, cp1, cp2, p3) => {
1198
+ const P01 = lerpPoint(p0, cp1, t);
1199
+ const P12 = lerpPoint(cp1, cp2, t);
1200
+ const P23 = lerpPoint(cp2, p3, t);
1201
+ const P012 = lerpPoint(P01, P12, t);
1202
+ const P123 = lerpPoint(P12, P23, t);
1203
+ return lerpPoint(P012, P123, t);
1204
+ };