@easemate/web-kit 0.2.0 → 0.3.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.
- package/build/decorators.cjs +921 -0
- package/build/decorators.cjs.map +1 -0
- package/build/decorators.d.cts +123 -0
- package/build/decorators.d.ts +123 -0
- package/build/decorators.js +889 -0
- package/build/decorators.js.map +1 -0
- package/build/elements.cjs +27604 -0
- package/build/elements.cjs.map +1 -0
- package/build/elements.d.cts +373 -0
- package/build/elements.d.ts +373 -0
- package/build/elements.js +27528 -0
- package/build/elements.js.map +1 -0
- package/build/{elements/monitor/index.d.ts → index-31iOHBv0.d.cts} +26 -5
- package/build/{elements/monitor/index.d.cts → index-31iOHBv0.d.ts} +26 -5
- package/build/{elements/panel/index.d.cts → index-NzGpn7ai.d.cts} +6 -3
- package/build/{elements/panel/index.d.ts → index-NzGpn7ai.d.ts} +6 -3
- package/build/{elements/state/index.d.ts → index-qZoNKsHn.d.cts} +46 -5
- package/build/{elements/state/index.d.cts → index-qZoNKsHn.d.ts} +46 -5
- package/build/index.cjs +38651 -38
- package/build/index.cjs.map +1 -0
- package/build/index.d.cts +85 -6
- package/build/index.d.ts +85 -6
- package/build/index.js +38535 -12
- package/build/index.js.map +1 -0
- package/build/init-B7gNNyTd.d.ts +235 -0
- package/build/init-DwVGVxkx.d.cts +235 -0
- package/build/jsx.cjs +31 -0
- package/build/jsx.cjs.map +1 -0
- package/build/jsx.d.cts +317 -0
- package/build/jsx.d.ts +317 -0
- package/build/jsx.js +6 -0
- package/build/jsx.js.map +1 -0
- package/build/outside-click-rZ3Di_WX.d.cts +16 -0
- package/build/outside-click-rZ3Di_WX.d.ts +16 -0
- package/build/react.cjs +37827 -0
- package/build/react.cjs.map +1 -0
- package/build/react.d.cts +356 -0
- package/build/react.d.ts +356 -0
- package/build/react.js +37802 -0
- package/build/react.js.map +1 -0
- package/build/register.cjs +35832 -36
- package/build/register.cjs.map +1 -0
- package/build/register.d.cts +4 -33
- package/build/register.d.ts +4 -33
- package/build/register.js +35831 -35
- package/build/register.js.map +1 -0
- package/build/register.server.cjs +19 -0
- package/build/register.server.cjs.map +1 -0
- package/build/register.server.d.cts +2 -0
- package/build/register.server.d.ts +2 -0
- package/build/register.server.js +1 -0
- package/build/register.server.js.map +1 -0
- package/build/registry-9GX9KTG1.d.cts +264 -0
- package/build/registry-9GX9KTG1.d.ts +264 -0
- package/build/template-helpers-CguLXtLD.d.cts +10 -0
- package/build/template-helpers-CguLXtLD.d.ts +10 -0
- package/build/theme.cjs +746 -0
- package/build/theme.cjs.map +1 -0
- package/build/{theme/index.d.cts → theme.d.cts} +41 -21
- package/build/{theme/index.d.ts → theme.d.ts} +41 -21
- package/build/theme.js +692 -0
- package/build/theme.js.map +1 -0
- package/build/utils.cjs +205 -0
- package/build/utils.cjs.map +1 -0
- package/build/utils.d.cts +26 -0
- package/build/utils.d.ts +26 -0
- package/build/utils.js +167 -0
- package/build/utils.js.map +1 -0
- package/package.json +47 -33
- package/build/components/code/index.cjs +0 -152
- package/build/components/code/index.d.cts +0 -11
- package/build/components/code/index.d.ts +0 -11
- package/build/components/code/index.js +0 -148
- package/build/components/code/utils/highlight-api.cjs +0 -18
- package/build/components/code/utils/highlight-api.d.cts +0 -7
- package/build/components/code/utils/highlight-api.d.ts +0 -7
- package/build/components/code/utils/highlight-api.js +0 -14
- package/build/components/code/utils/syntax-grammars.cjs +0 -62
- package/build/components/code/utils/syntax-grammars.d.cts +0 -7
- package/build/components/code/utils/syntax-grammars.d.ts +0 -7
- package/build/components/code/utils/syntax-grammars.js +0 -59
- package/build/components/code/utils/syntax-highlighter-theme.cjs +0 -27
- package/build/components/code/utils/syntax-highlighter-theme.d.cts +0 -3
- package/build/components/code/utils/syntax-highlighter-theme.d.ts +0 -3
- package/build/components/code/utils/syntax-highlighter-theme.js +0 -23
- package/build/components/code/utils/syntax-highlighter-types.cjs +0 -2
- package/build/components/code/utils/syntax-highlighter-types.d.cts +0 -12
- package/build/components/code/utils/syntax-highlighter-types.d.ts +0 -12
- package/build/components/code/utils/syntax-highlighter-types.js +0 -1
- package/build/components/code/utils/syntax-tokenizer.cjs +0 -63
- package/build/components/code/utils/syntax-tokenizer.d.cts +0 -3
- package/build/components/code/utils/syntax-tokenizer.d.ts +0 -3
- package/build/components/code/utils/syntax-tokenizer.js +0 -58
- package/build/components/curve/bezier-conversion.cjs +0 -23
- package/build/components/curve/bezier-conversion.d.cts +0 -2
- package/build/components/curve/bezier-conversion.d.ts +0 -2
- package/build/components/curve/bezier-conversion.js +0 -19
- package/build/components/curve/canvas-controls.cjs +0 -300
- package/build/components/curve/canvas-controls.d.cts +0 -12
- package/build/components/curve/canvas-controls.d.ts +0 -12
- package/build/components/curve/canvas-controls.js +0 -296
- package/build/components/curve/canvas.cjs +0 -1208
- package/build/components/curve/canvas.d.cts +0 -24
- package/build/components/curve/canvas.d.ts +0 -24
- package/build/components/curve/canvas.js +0 -1204
- package/build/components/curve/constants.cjs +0 -203
- package/build/components/curve/constants.d.cts +0 -23
- package/build/components/curve/constants.d.ts +0 -23
- package/build/components/curve/constants.js +0 -200
- package/build/components/curve/controls.cjs +0 -942
- package/build/components/curve/controls.d.cts +0 -37
- package/build/components/curve/controls.d.ts +0 -37
- package/build/components/curve/controls.js +0 -938
- package/build/components/curve/index.cjs +0 -335
- package/build/components/curve/index.d.cts +0 -31
- package/build/components/curve/index.d.ts +0 -31
- package/build/components/curve/index.js +0 -330
- package/build/components/curve/output.cjs +0 -141
- package/build/components/curve/output.d.cts +0 -19
- package/build/components/curve/output.d.ts +0 -19
- package/build/components/curve/output.js +0 -137
- package/build/components/curve/styles.cjs +0 -493
- package/build/components/curve/styles.d.cts +0 -6
- package/build/components/curve/styles.d.ts +0 -6
- package/build/components/curve/styles.js +0 -490
- package/build/components/curve/svg-renderer.cjs +0 -185
- package/build/components/curve/svg-renderer.d.cts +0 -9
- package/build/components/curve/svg-renderer.d.ts +0 -9
- package/build/components/curve/svg-renderer.js +0 -175
- package/build/components/curve/toolbar.cjs +0 -368
- package/build/components/curve/toolbar.d.cts +0 -26
- package/build/components/curve/toolbar.d.ts +0 -26
- package/build/components/curve/toolbar.js +0 -364
- package/build/components/curve/types.cjs +0 -10
- package/build/components/curve/types.d.cts +0 -33
- package/build/components/curve/types.d.ts +0 -33
- package/build/components/curve/types.js +0 -7
- package/build/components/curve/utils.cjs +0 -541
- package/build/components/curve/utils.d.cts +0 -33
- package/build/components/curve/utils.d.ts +0 -33
- package/build/components/curve/utils.js +0 -521
- package/build/components/index.cjs +0 -18
- package/build/components/index.d.cts +0 -2
- package/build/components/index.d.ts +0 -2
- package/build/components/index.js +0 -2
- package/build/decorators/Component.cjs +0 -127
- package/build/decorators/Component.d.cts +0 -28
- package/build/decorators/Component.d.ts +0 -28
- package/build/decorators/Component.js +0 -123
- package/build/decorators/Listen.cjs +0 -154
- package/build/decorators/Listen.d.cts +0 -18
- package/build/decorators/Listen.d.ts +0 -18
- package/build/decorators/Listen.js +0 -151
- package/build/decorators/OutsideClick.cjs +0 -64
- package/build/decorators/OutsideClick.d.cts +0 -16
- package/build/decorators/OutsideClick.d.ts +0 -16
- package/build/decorators/OutsideClick.js +0 -59
- package/build/decorators/Prop.cjs +0 -273
- package/build/decorators/Prop.d.cts +0 -22
- package/build/decorators/Prop.d.ts +0 -22
- package/build/decorators/Prop.js +0 -270
- package/build/decorators/Query.cjs +0 -79
- package/build/decorators/Query.d.cts +0 -27
- package/build/decorators/Query.d.ts +0 -27
- package/build/decorators/Query.js +0 -76
- package/build/decorators/Watch.cjs +0 -52
- package/build/decorators/Watch.d.cts +0 -11
- package/build/decorators/Watch.d.ts +0 -11
- package/build/decorators/Watch.js +0 -49
- package/build/decorators/index.cjs +0 -15
- package/build/decorators/index.d.cts +0 -6
- package/build/decorators/index.d.ts +0 -6
- package/build/decorators/index.js +0 -6
- package/build/elements/button/index.cjs +0 -214
- package/build/elements/button/index.d.cts +0 -11
- package/build/elements/button/index.d.ts +0 -11
- package/build/elements/button/index.js +0 -210
- package/build/elements/checkbox/index.cjs +0 -316
- package/build/elements/checkbox/index.d.cts +0 -14
- package/build/elements/checkbox/index.d.ts +0 -14
- package/build/elements/checkbox/index.js +0 -312
- package/build/elements/color/index.cjs +0 -154
- package/build/elements/color/index.d.cts +0 -18
- package/build/elements/color/index.d.ts +0 -18
- package/build/elements/color/index.js +0 -150
- package/build/elements/color/picker.cjs +0 -544
- package/build/elements/color/picker.d.cts +0 -37
- package/build/elements/color/picker.d.ts +0 -37
- package/build/elements/color/picker.js +0 -540
- package/build/elements/color/utils.cjs +0 -235
- package/build/elements/color/utils.d.cts +0 -37
- package/build/elements/color/utils.d.ts +0 -37
- package/build/elements/color/utils.js +0 -218
- package/build/elements/dropdown/index.cjs +0 -875
- package/build/elements/dropdown/index.d.cts +0 -30
- package/build/elements/dropdown/index.d.ts +0 -30
- package/build/elements/dropdown/index.js +0 -871
- package/build/elements/field/index.cjs +0 -82
- package/build/elements/field/index.d.cts +0 -4
- package/build/elements/field/index.d.ts +0 -4
- package/build/elements/field/index.js +0 -78
- package/build/elements/icons/animation/chevron.cjs +0 -57
- package/build/elements/icons/animation/chevron.d.cts +0 -10
- package/build/elements/icons/animation/chevron.d.ts +0 -10
- package/build/elements/icons/animation/chevron.js +0 -53
- package/build/elements/icons/animation/clear.cjs +0 -74
- package/build/elements/icons/animation/clear.d.cts +0 -3
- package/build/elements/icons/animation/clear.d.ts +0 -3
- package/build/elements/icons/animation/clear.js +0 -70
- package/build/elements/icons/animation/grid.cjs +0 -77
- package/build/elements/icons/animation/grid.d.cts +0 -8
- package/build/elements/icons/animation/grid.d.ts +0 -8
- package/build/elements/icons/animation/grid.js +0 -73
- package/build/elements/icons/animation/loading.cjs +0 -68
- package/build/elements/icons/animation/loading.d.cts +0 -3
- package/build/elements/icons/animation/loading.d.ts +0 -3
- package/build/elements/icons/animation/loading.js +0 -64
- package/build/elements/icons/animation/snap.cjs +0 -133
- package/build/elements/icons/animation/snap.d.cts +0 -8
- package/build/elements/icons/animation/snap.d.ts +0 -8
- package/build/elements/icons/animation/snap.js +0 -129
- package/build/elements/icons/index.cjs +0 -40
- package/build/elements/icons/index.d.cts +0 -24
- package/build/elements/icons/index.d.ts +0 -24
- package/build/elements/icons/index.js +0 -24
- package/build/elements/icons/interface/anchor-add.cjs +0 -35
- package/build/elements/icons/interface/anchor-add.d.cts +0 -3
- package/build/elements/icons/interface/anchor-add.d.ts +0 -3
- package/build/elements/icons/interface/anchor-add.js +0 -31
- package/build/elements/icons/interface/anchor-remove.cjs +0 -34
- package/build/elements/icons/interface/anchor-remove.d.cts +0 -3
- package/build/elements/icons/interface/anchor-remove.d.ts +0 -3
- package/build/elements/icons/interface/anchor-remove.js +0 -30
- package/build/elements/icons/interface/arrow-up.cjs +0 -30
- package/build/elements/icons/interface/arrow-up.d.cts +0 -3
- package/build/elements/icons/interface/arrow-up.d.ts +0 -3
- package/build/elements/icons/interface/arrow-up.js +0 -26
- package/build/elements/icons/interface/arrows-vertical.cjs +0 -30
- package/build/elements/icons/interface/arrows-vertical.d.cts +0 -3
- package/build/elements/icons/interface/arrows-vertical.d.ts +0 -3
- package/build/elements/icons/interface/arrows-vertical.js +0 -26
- package/build/elements/icons/interface/bezier-angle.cjs +0 -33
- package/build/elements/icons/interface/bezier-angle.d.cts +0 -3
- package/build/elements/icons/interface/bezier-angle.d.ts +0 -3
- package/build/elements/icons/interface/bezier-angle.js +0 -29
- package/build/elements/icons/interface/bezier-distribute.cjs +0 -34
- package/build/elements/icons/interface/bezier-distribute.d.cts +0 -3
- package/build/elements/icons/interface/bezier-distribute.d.ts +0 -3
- package/build/elements/icons/interface/bezier-distribute.js +0 -30
- package/build/elements/icons/interface/bezier-length.cjs +0 -31
- package/build/elements/icons/interface/bezier-length.d.cts +0 -3
- package/build/elements/icons/interface/bezier-length.d.ts +0 -3
- package/build/elements/icons/interface/bezier-length.js +0 -27
- package/build/elements/icons/interface/bezier-mirror.cjs +0 -31
- package/build/elements/icons/interface/bezier-mirror.d.cts +0 -3
- package/build/elements/icons/interface/bezier-mirror.d.ts +0 -3
- package/build/elements/icons/interface/bezier-mirror.js +0 -27
- package/build/elements/icons/interface/bezier.cjs +0 -26
- package/build/elements/icons/interface/bezier.d.cts +0 -3
- package/build/elements/icons/interface/bezier.d.ts +0 -3
- package/build/elements/icons/interface/bezier.js +0 -22
- package/build/elements/icons/interface/check.cjs +0 -30
- package/build/elements/icons/interface/check.d.cts +0 -3
- package/build/elements/icons/interface/check.d.ts +0 -3
- package/build/elements/icons/interface/check.js +0 -26
- package/build/elements/icons/interface/circle-arrow-left.cjs +0 -30
- package/build/elements/icons/interface/circle-arrow-left.d.cts +0 -3
- package/build/elements/icons/interface/circle-arrow-left.d.ts +0 -3
- package/build/elements/icons/interface/circle-arrow-left.js +0 -26
- package/build/elements/icons/interface/circle-arrow-right.cjs +0 -30
- package/build/elements/icons/interface/circle-arrow-right.d.cts +0 -3
- package/build/elements/icons/interface/circle-arrow-right.d.ts +0 -3
- package/build/elements/icons/interface/circle-arrow-right.js +0 -26
- package/build/elements/icons/interface/code.cjs +0 -30
- package/build/elements/icons/interface/code.d.cts +0 -3
- package/build/elements/icons/interface/code.d.ts +0 -3
- package/build/elements/icons/interface/code.js +0 -26
- package/build/elements/icons/interface/dots.cjs +0 -32
- package/build/elements/icons/interface/dots.d.cts +0 -3
- package/build/elements/icons/interface/dots.d.ts +0 -3
- package/build/elements/icons/interface/dots.js +0 -28
- package/build/elements/icons/interface/mention.cjs +0 -30
- package/build/elements/icons/interface/mention.d.cts +0 -3
- package/build/elements/icons/interface/mention.d.ts +0 -3
- package/build/elements/icons/interface/mention.js +0 -26
- package/build/elements/icons/interface/minus.cjs +0 -30
- package/build/elements/icons/interface/minus.d.cts +0 -3
- package/build/elements/icons/interface/minus.d.ts +0 -3
- package/build/elements/icons/interface/minus.js +0 -26
- package/build/elements/icons/interface/picker.cjs +0 -34
- package/build/elements/icons/interface/picker.d.cts +0 -3
- package/build/elements/icons/interface/picker.d.ts +0 -3
- package/build/elements/icons/interface/picker.js +0 -30
- package/build/elements/icons/interface/plus.cjs +0 -30
- package/build/elements/icons/interface/plus.d.cts +0 -3
- package/build/elements/icons/interface/plus.d.ts +0 -3
- package/build/elements/icons/interface/plus.js +0 -26
- package/build/elements/icons/interface/settings.cjs +0 -30
- package/build/elements/icons/interface/settings.d.cts +0 -3
- package/build/elements/icons/interface/settings.d.ts +0 -3
- package/build/elements/icons/interface/settings.js +0 -26
- package/build/elements/index.cjs +0 -65
- package/build/elements/index.d.cts +0 -23
- package/build/elements/index.d.ts +0 -23
- package/build/elements/index.js +0 -23
- package/build/elements/input/index.cjs +0 -273
- package/build/elements/input/index.d.cts +0 -17
- package/build/elements/input/index.d.ts +0 -17
- package/build/elements/input/index.js +0 -269
- package/build/elements/logo/index.cjs +0 -732
- package/build/elements/logo/index.d.cts +0 -17
- package/build/elements/logo/index.d.ts +0 -17
- package/build/elements/logo/index.js +0 -728
- package/build/elements/monitor/fps.cjs +0 -432
- package/build/elements/monitor/fps.d.cts +0 -21
- package/build/elements/monitor/fps.d.ts +0 -21
- package/build/elements/monitor/fps.js +0 -428
- package/build/elements/monitor/index.cjs +0 -670
- package/build/elements/monitor/index.js +0 -666
- package/build/elements/number/index.cjs +0 -173
- package/build/elements/number/index.d.cts +0 -19
- package/build/elements/number/index.d.ts +0 -19
- package/build/elements/number/index.js +0 -169
- package/build/elements/origin/index.cjs +0 -169
- package/build/elements/origin/index.d.cts +0 -12
- package/build/elements/origin/index.d.ts +0 -12
- package/build/elements/origin/index.js +0 -165
- package/build/elements/panel/index.cjs +0 -496
- package/build/elements/panel/index.js +0 -492
- package/build/elements/popover/index.cjs +0 -209
- package/build/elements/popover/index.d.cts +0 -19
- package/build/elements/popover/index.d.ts +0 -19
- package/build/elements/popover/index.js +0 -205
- package/build/elements/radio/index.cjs +0 -301
- package/build/elements/radio/index.d.cts +0 -13
- package/build/elements/radio/index.d.ts +0 -13
- package/build/elements/radio/index.js +0 -283
- package/build/elements/radio/input.cjs +0 -329
- package/build/elements/radio/input.d.cts +0 -15
- package/build/elements/radio/input.d.ts +0 -15
- package/build/elements/radio/input.js +0 -325
- package/build/elements/radio/option.cjs +0 -15
- package/build/elements/radio/option.d.cts +0 -3
- package/build/elements/radio/option.d.ts +0 -3
- package/build/elements/radio/option.js +0 -11
- package/build/elements/shared.cjs +0 -66
- package/build/elements/shared.d.cts +0 -40
- package/build/elements/shared.d.ts +0 -40
- package/build/elements/shared.js +0 -59
- package/build/elements/slider/index.cjs +0 -232
- package/build/elements/slider/index.d.cts +0 -20
- package/build/elements/slider/index.d.ts +0 -20
- package/build/elements/slider/index.js +0 -228
- package/build/elements/state/index.cjs +0 -274
- package/build/elements/state/index.js +0 -270
- package/build/elements/toggle/index.cjs +0 -151
- package/build/elements/toggle/index.d.cts +0 -9
- package/build/elements/toggle/index.d.ts +0 -9
- package/build/elements/toggle/index.js +0 -147
- package/build/elements/tooltip/index.cjs +0 -187
- package/build/elements/tooltip/index.d.cts +0 -17
- package/build/elements/tooltip/index.d.ts +0 -17
- package/build/elements/tooltip/index.js +0 -183
- package/build/init.cjs +0 -325
- package/build/init.d.cts +0 -157
- package/build/init.d.ts +0 -157
- package/build/init.js +0 -289
- package/build/internal/component-loaders.cjs +0 -208
- package/build/internal/component-loaders.d.cts +0 -52
- package/build/internal/component-loaders.d.ts +0 -52
- package/build/internal/component-loaders.js +0 -169
- package/build/internal/fonts.cjs +0 -128
- package/build/internal/fonts.d.cts +0 -32
- package/build/internal/fonts.d.ts +0 -32
- package/build/internal/fonts.js +0 -123
- package/build/internal/lazy-load.cjs +0 -89
- package/build/internal/lazy-load.d.cts +0 -32
- package/build/internal/lazy-load.d.ts +0 -32
- package/build/internal/lazy-load.js +0 -86
- package/build/internal/style-inject.cjs +0 -236
- package/build/internal/style-inject.d.cts +0 -44
- package/build/internal/style-inject.d.ts +0 -44
- package/build/internal/style-inject.js +0 -226
- package/build/react/events.cjs +0 -25
- package/build/react/events.d.cts +0 -39
- package/build/react/events.d.ts +0 -39
- package/build/react/events.js +0 -22
- package/build/react/index.cjs +0 -19
- package/build/react/index.d.cts +0 -13
- package/build/react/index.d.ts +0 -13
- package/build/react/index.js +0 -12
- package/build/react/provider.cjs +0 -134
- package/build/react/provider.d.cts +0 -81
- package/build/react/provider.d.ts +0 -81
- package/build/react/provider.js +0 -98
- package/build/react/types.cjs +0 -8
- package/build/react/types.d.cts +0 -55
- package/build/react/types.d.ts +0 -55
- package/build/react/types.js +0 -7
- package/build/react/use-ease-state.cjs +0 -129
- package/build/react/use-ease-state.d.cts +0 -95
- package/build/react/use-ease-state.d.ts +0 -95
- package/build/react/use-ease-state.js +0 -126
- package/build/react/use-web-kit.cjs +0 -150
- package/build/react/use-web-kit.d.cts +0 -80
- package/build/react/use-web-kit.d.ts +0 -80
- package/build/react/use-web-kit.js +0 -114
- package/build/theme/index.cjs +0 -452
- package/build/theme/index.js +0 -423
- package/build/theme/presets.cjs +0 -54
- package/build/theme/presets.d.cts +0 -19
- package/build/theme/presets.d.ts +0 -19
- package/build/theme/presets.js +0 -51
- package/build/theme/registry.cjs +0 -204
- package/build/theme/registry.d.cts +0 -99
- package/build/theme/registry.d.ts +0 -99
- package/build/theme/registry.js +0 -194
- package/build/theme/tokens.cjs +0 -148
- package/build/theme/tokens.d.cts +0 -163
- package/build/theme/tokens.d.ts +0 -163
- package/build/theme/tokens.js +0 -145
- package/build/utils/dismiss-controller.cjs +0 -77
- package/build/utils/dismiss-controller.d.cts +0 -14
- package/build/utils/dismiss-controller.d.ts +0 -14
- package/build/utils/dismiss-controller.js +0 -73
- package/build/utils/index.cjs +0 -18
- package/build/utils/index.d.cts +0 -3
- package/build/utils/index.d.ts +0 -3
- package/build/utils/index.js +0 -3
- package/build/utils/outside-click.cjs +0 -82
- package/build/utils/outside-click.d.cts +0 -18
- package/build/utils/outside-click.d.ts +0 -18
- package/build/utils/outside-click.js +0 -74
- package/build/utils/template-helpers.cjs +0 -39
- package/build/utils/template-helpers.d.cts +0 -13
- package/build/utils/template-helpers.d.ts +0 -13
- package/build/utils/template-helpers.js +0 -28
|
@@ -1,1204 +0,0 @@
|
|
|
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
|
-
};
|