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