@easemate/web-kit 0.1.5 → 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/README.md +360 -168
- 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/index-NzGpn7ai.d.cts +70 -0
- package/build/index-NzGpn7ai.d.ts +70 -0
- package/build/index-qZoNKsHn.d.cts +136 -0
- package/build/index-qZoNKsHn.d.ts +136 -0
- 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 -35
- package/build/register.cjs.map +1 -0
- package/build/register.d.cts +4 -32
- package/build/register.d.ts +4 -32
- package/build/register.js +35831 -34
- 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 +57 -29
- 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 -62
- package/build/elements/index.d.cts +0 -22
- package/build/elements/index.d.ts +0 -22
- package/build/elements/index.js +0 -22
- 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/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 -681
- package/build/elements/state/index.d.cts +0 -86
- package/build/elements/state/index.d.ts +0 -86
- package/build/elements/state/index.js +0 -677
- 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 -206
- 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 -167
- 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/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,521 +0,0 @@
|
|
|
1
|
-
export const clampPoint = (point, bounds) => {
|
|
2
|
-
const minX = bounds?.minX ?? 0;
|
|
3
|
-
const maxX = bounds?.maxX ?? 1;
|
|
4
|
-
const minY = bounds?.minY ?? 0;
|
|
5
|
-
const maxY = bounds?.maxY ?? 1;
|
|
6
|
-
return {
|
|
7
|
-
x: Math.max(minX, Math.min(maxX, point.x)),
|
|
8
|
-
y: Math.max(minY, Math.min(maxY, point.y))
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export const MIN_LINEAR_DELTA = 0.0001;
|
|
12
|
-
let linearPointIdCounter = 0;
|
|
13
|
-
const nextLinearPointId = () => {
|
|
14
|
-
linearPointIdCounter += 1;
|
|
15
|
-
return `linear-point-${linearPointIdCounter}`;
|
|
16
|
-
};
|
|
17
|
-
export const ensureLinearPointId = (point) => {
|
|
18
|
-
if (!point.id) {
|
|
19
|
-
point.id = nextLinearPointId();
|
|
20
|
-
}
|
|
21
|
-
return point.id;
|
|
22
|
-
};
|
|
23
|
-
export const cloneLinearPoint = (point) => {
|
|
24
|
-
const sourceId = ensureLinearPointId(point);
|
|
25
|
-
return {
|
|
26
|
-
...point,
|
|
27
|
-
id: sourceId
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export const cubicBezierPath = (points) => {
|
|
31
|
-
const { p1, p2 } = points;
|
|
32
|
-
const startX = 0;
|
|
33
|
-
const startY = 300;
|
|
34
|
-
const endX = 400;
|
|
35
|
-
const endY = 0;
|
|
36
|
-
const cp1x = p1.x * 400;
|
|
37
|
-
const cp1y = (1 - p1.y) * 300;
|
|
38
|
-
const cp2x = p2.x * 400;
|
|
39
|
-
const cp2y = (1 - p2.y) * 300;
|
|
40
|
-
return `M ${startX} ${startY} C ${cp1x} ${cp1y}, ${cp2x} ${cp2y}, ${endX} ${endY}`;
|
|
41
|
-
};
|
|
42
|
-
export const linearDisplayPath = (points) => {
|
|
43
|
-
if (points.length < 2) {
|
|
44
|
-
return '';
|
|
45
|
-
}
|
|
46
|
-
const toSvg = (p) => {
|
|
47
|
-
return {
|
|
48
|
-
x: p.x * 400,
|
|
49
|
-
y: (1 - p.y) * 300
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
const startPoint = points[0];
|
|
53
|
-
if (!startPoint) {
|
|
54
|
-
return '';
|
|
55
|
-
}
|
|
56
|
-
const start = toSvg(startPoint);
|
|
57
|
-
let d = `M ${start.x} ${start.y}`;
|
|
58
|
-
for (let index = 0; index < points.length - 1; index += 1) {
|
|
59
|
-
const p1 = points[index];
|
|
60
|
-
const p2 = points[index + 1];
|
|
61
|
-
if (!p1 || !p2) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const cp1 = {
|
|
65
|
-
x: p1.x + (p1.cpOutX ?? 0),
|
|
66
|
-
y: p1.y + (p1.cpOutY ?? 0)
|
|
67
|
-
};
|
|
68
|
-
const cp2 = {
|
|
69
|
-
x: p2.x + (p2.cpInX ?? 0),
|
|
70
|
-
y: p2.y + (p2.cpInY ?? 0)
|
|
71
|
-
};
|
|
72
|
-
if (cp1.x === p1.x && cp1.y === p1.y && cp2.x === p2.x && cp2.y === p2.y) {
|
|
73
|
-
const end = toSvg(p2);
|
|
74
|
-
d += ` L ${end.x} ${end.y}`;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
const svgCp1 = toSvg(cp1);
|
|
78
|
-
const svgCp2 = toSvg(cp2);
|
|
79
|
-
const end = toSvg(p2);
|
|
80
|
-
d += ` C ${svgCp1.x} ${svgCp1.y}, ${svgCp2.x} ${svgCp2.y}, ${end.x} ${end.y}`;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return d;
|
|
84
|
-
};
|
|
85
|
-
const perpendicularDistance = (point, lineStart, lineEnd) => {
|
|
86
|
-
const dx = lineEnd.x - lineStart.x;
|
|
87
|
-
const dy = lineEnd.y - lineStart.y;
|
|
88
|
-
if (dx === 0 && dy === 0) {
|
|
89
|
-
return Math.sqrt((point.x - lineStart.x) ** 2 + (point.y - lineStart.y) ** 2);
|
|
90
|
-
}
|
|
91
|
-
const numerator = Math.abs(dy * point.x - dx * point.y + lineEnd.x * lineStart.y - lineEnd.y * lineStart.x);
|
|
92
|
-
const denominator = Math.sqrt(dx * dx + dy * dy);
|
|
93
|
-
return numerator / denominator;
|
|
94
|
-
};
|
|
95
|
-
const simplifyPoints = (points, epsilon) => {
|
|
96
|
-
if (points.length < 3) {
|
|
97
|
-
return points;
|
|
98
|
-
}
|
|
99
|
-
let dmax = 0;
|
|
100
|
-
let index = 0;
|
|
101
|
-
const end = points.length - 1;
|
|
102
|
-
const startPoint = points[0];
|
|
103
|
-
const endPoint = points[end];
|
|
104
|
-
if (!startPoint || !endPoint) {
|
|
105
|
-
return points;
|
|
106
|
-
}
|
|
107
|
-
for (let i = 1; i < end; i++) {
|
|
108
|
-
const point = points[i];
|
|
109
|
-
if (!point) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const d = perpendicularDistance(point, startPoint, endPoint);
|
|
113
|
-
if (d > dmax) {
|
|
114
|
-
index = i;
|
|
115
|
-
dmax = d;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (dmax > epsilon) {
|
|
119
|
-
const recResults1 = simplifyPoints(points.slice(0, index + 1), epsilon);
|
|
120
|
-
const recResults2 = simplifyPoints(points.slice(index, end + 1), epsilon);
|
|
121
|
-
return [...recResults1.slice(0, -1), ...recResults2];
|
|
122
|
-
}
|
|
123
|
-
return [startPoint, endPoint];
|
|
124
|
-
};
|
|
125
|
-
export const generateCubicBezierCSS = (points, name, variant = 'animation') => {
|
|
126
|
-
const { p1, p2 } = points;
|
|
127
|
-
const timingFunction = `cubic-bezier(${p1.x.toFixed(3)}, ${p1.y.toFixed(3)}, ${p2.x.toFixed(3)}, ${p2.y.toFixed(3)})`;
|
|
128
|
-
const code = `
|
|
129
|
-
.${name} {
|
|
130
|
-
${variant}-timing-function: ${timingFunction};
|
|
131
|
-
}
|
|
132
|
-
`;
|
|
133
|
-
return {
|
|
134
|
-
code,
|
|
135
|
-
timingFunction
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
export const getLinearApproximation = (points, options = {}) => {
|
|
139
|
-
const { simplify = 0, round = 5 } = options;
|
|
140
|
-
const samples = [];
|
|
141
|
-
const numSamplesPerSegment = 20;
|
|
142
|
-
const sortedPoints = [...points].sort((a, b) => a.x - b.x);
|
|
143
|
-
for (let index = 0; index < sortedPoints.length - 1; index += 1) {
|
|
144
|
-
const p1 = sortedPoints[index];
|
|
145
|
-
const p2 = sortedPoints[index + 1];
|
|
146
|
-
if (!p1 || !p2) {
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
if (index === 0) {
|
|
150
|
-
samples.push({ x: p1.x, y: p1.y });
|
|
151
|
-
}
|
|
152
|
-
const cp1 = {
|
|
153
|
-
x: p1.x + (p1.cpOutX ?? 0),
|
|
154
|
-
y: p1.y + (p1.cpOutY ?? 0)
|
|
155
|
-
};
|
|
156
|
-
const cp2 = {
|
|
157
|
-
x: p2.x + (p2.cpInX ?? 0),
|
|
158
|
-
y: p2.y + (p2.cpInY ?? 0)
|
|
159
|
-
};
|
|
160
|
-
for (let step = 1; step <= numSamplesPerSegment; step += 1) {
|
|
161
|
-
const t = step / numSamplesPerSegment;
|
|
162
|
-
const x = cubicBezier(t, p1.x, cp1.x, cp2.x, p2.x);
|
|
163
|
-
const y = cubicBezier(t, p1.y, cp1.y, cp2.y, p2.y);
|
|
164
|
-
samples.push({ x, y });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
const normalizedSamples = [];
|
|
168
|
-
let lastX = -Infinity;
|
|
169
|
-
for (const sample of samples) {
|
|
170
|
-
const clampedX = Math.max(0, Math.min(1, sample.x));
|
|
171
|
-
const clampedY = Math.max(-2, Math.min(3, sample.y));
|
|
172
|
-
if (clampedX > lastX + MIN_LINEAR_DELTA) {
|
|
173
|
-
normalizedSamples.push({ x: clampedX, y: clampedY });
|
|
174
|
-
lastX = clampedX;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (normalizedSamples.length < 2) {
|
|
178
|
-
return [
|
|
179
|
-
{ x: 0, y: 0 },
|
|
180
|
-
{ x: 1, y: 1 }
|
|
181
|
-
];
|
|
182
|
-
}
|
|
183
|
-
const firstPoint = sortedPoints[0];
|
|
184
|
-
if (firstPoint && Math.abs(firstPoint.x) < MIN_LINEAR_DELTA && normalizedSamples.length > 0) {
|
|
185
|
-
const firstSample = normalizedSamples[0];
|
|
186
|
-
if (firstSample) {
|
|
187
|
-
firstSample.x = 0;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
const lastPoint = sortedPoints[sortedPoints.length - 1];
|
|
191
|
-
if (lastPoint && Math.abs(lastPoint.x - 1) < MIN_LINEAR_DELTA && normalizedSamples.length > 0) {
|
|
192
|
-
const lastSample = normalizedSamples[normalizedSamples.length - 1];
|
|
193
|
-
if (lastSample) {
|
|
194
|
-
lastSample.x = 1;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
let finalSamples = normalizedSamples;
|
|
198
|
-
if (simplify > 0) {
|
|
199
|
-
finalSamples = simplifyPoints(normalizedSamples, simplify);
|
|
200
|
-
}
|
|
201
|
-
return finalSamples.map((sample) => {
|
|
202
|
-
return {
|
|
203
|
-
x: sample.x,
|
|
204
|
-
y: Number(sample.y.toFixed(round))
|
|
205
|
-
};
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
export const generateLinearCSS = (points, name, variant = 'animation', options = {}) => {
|
|
209
|
-
if (!Array.isArray(points) || points.length < 2) {
|
|
210
|
-
return { code: '', timingFunction: '' };
|
|
211
|
-
}
|
|
212
|
-
const finalSamples = getLinearApproximation(points, options);
|
|
213
|
-
const parts = finalSamples.map((sample) => {
|
|
214
|
-
const y = sample.y;
|
|
215
|
-
const x = Number((sample.x * 100).toFixed(2));
|
|
216
|
-
return `${y} ${x}%`;
|
|
217
|
-
});
|
|
218
|
-
const timingFunction = `linear(${parts.join(', ')})`;
|
|
219
|
-
const code = `
|
|
220
|
-
.${name} {
|
|
221
|
-
${variant}-timing-function: ${timingFunction};
|
|
222
|
-
}
|
|
223
|
-
`;
|
|
224
|
-
return { code, timingFunction };
|
|
225
|
-
};
|
|
226
|
-
export const cubicBezierToLinear = (points, steps = 20) => {
|
|
227
|
-
const linearPoints = [];
|
|
228
|
-
for (let i = 0; i <= steps; i++) {
|
|
229
|
-
const t = i / steps;
|
|
230
|
-
const x = cubicBezier(t, 0, points.p1.x, points.p2.x, 1);
|
|
231
|
-
const y = cubicBezier(t, 0, points.p1.y, points.p2.y, 1);
|
|
232
|
-
linearPoints.push({ x, y });
|
|
233
|
-
}
|
|
234
|
-
return linearPoints;
|
|
235
|
-
};
|
|
236
|
-
const cubicBezier = (t, p0, p1, p2, p3) => {
|
|
237
|
-
const u = 1 - t;
|
|
238
|
-
const tt = t * t;
|
|
239
|
-
const uu = u * u;
|
|
240
|
-
const uuu = uu * u;
|
|
241
|
-
const ttt = tt * t;
|
|
242
|
-
return uuu * p0 + 3 * uu * t * p1 + 3 * u * tt * p2 + ttt * p3;
|
|
243
|
-
};
|
|
244
|
-
export const validateCubicBezierPoints = (points) => {
|
|
245
|
-
const { p1, p2 } = points;
|
|
246
|
-
return p1.x >= 0 && p1.x <= 1 && p2.x >= 0 && p2.x <= 1;
|
|
247
|
-
};
|
|
248
|
-
export const validateLinearPoints = (points) => {
|
|
249
|
-
if (points.length < 2) {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
const sortedPoints = [...points].sort((a, b) => a.x - b.x);
|
|
253
|
-
for (let index = 0; index < sortedPoints.length; index += 1) {
|
|
254
|
-
const point = sortedPoints[index];
|
|
255
|
-
if (!point) {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
if (point.x < 0 || point.x > 1) {
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
261
|
-
if (index >= sortedPoints.length - 1) {
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
const next = sortedPoints[index + 1];
|
|
265
|
-
if (!next) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
if (next.x <= point.x + MIN_LINEAR_DELTA) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
const first = sortedPoints[0];
|
|
273
|
-
const last = sortedPoints[sortedPoints.length - 1];
|
|
274
|
-
if (first && Math.abs(first.x) > MIN_LINEAR_DELTA) {
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
if (last && Math.abs(last.x - 1) > MIN_LINEAR_DELTA) {
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
return true;
|
|
281
|
-
};
|
|
282
|
-
export const normalizeLinearPoints = (points) => {
|
|
283
|
-
if (points.length === 0) {
|
|
284
|
-
return [];
|
|
285
|
-
}
|
|
286
|
-
const normalized = [...points].sort((a, b) => a.x - b.x).map((point) => cloneLinearPoint(point));
|
|
287
|
-
const first = normalized[0];
|
|
288
|
-
if (first) {
|
|
289
|
-
first.x = 0;
|
|
290
|
-
}
|
|
291
|
-
const last = normalized[normalized.length - 1];
|
|
292
|
-
if (last) {
|
|
293
|
-
last.x = 1;
|
|
294
|
-
}
|
|
295
|
-
for (let index = 0; index < normalized.length; index += 1) {
|
|
296
|
-
const point = normalized[index];
|
|
297
|
-
if (!point) {
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
const minY = -2;
|
|
301
|
-
const maxY = 3;
|
|
302
|
-
point.y = Math.max(minY, Math.min(maxY, point.y));
|
|
303
|
-
if ((point.cpInX ?? 0) > 0) {
|
|
304
|
-
point.cpInX = 0;
|
|
305
|
-
}
|
|
306
|
-
if ((point.cpOutX ?? 0) < 0) {
|
|
307
|
-
point.cpOutX = 0;
|
|
308
|
-
}
|
|
309
|
-
const handleThreshold = 0;
|
|
310
|
-
if (Math.abs(point.cpInX ?? 0) < handleThreshold && Math.abs(point.cpInY ?? 0) < handleThreshold) {
|
|
311
|
-
delete point.cpInX;
|
|
312
|
-
delete point.cpInY;
|
|
313
|
-
}
|
|
314
|
-
if (Math.abs(point.cpOutX ?? 0) < handleThreshold && Math.abs(point.cpOutY ?? 0) < handleThreshold) {
|
|
315
|
-
delete point.cpOutX;
|
|
316
|
-
delete point.cpOutY;
|
|
317
|
-
}
|
|
318
|
-
if (point.cpInX === undefined && point.cpOutX === undefined) {
|
|
319
|
-
delete point.isLinked;
|
|
320
|
-
delete point.mirrorLength;
|
|
321
|
-
}
|
|
322
|
-
else if (point.isLinked !== true) {
|
|
323
|
-
point.mirrorLength = false;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return normalized;
|
|
327
|
-
};
|
|
328
|
-
const clamp01 = (value) => {
|
|
329
|
-
if (Number.isNaN(value)) {
|
|
330
|
-
return 0;
|
|
331
|
-
}
|
|
332
|
-
return Math.min(1, Math.max(0, value));
|
|
333
|
-
};
|
|
334
|
-
export const parseCubicBezierValue = (input) => {
|
|
335
|
-
const match = input.trim().match(/^cubic-bezier\s*\((.+)\)$/i);
|
|
336
|
-
if (!match) {
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
|
-
const body = match[1];
|
|
340
|
-
if (!body) {
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
const parts = body
|
|
344
|
-
.split(',')
|
|
345
|
-
.map((part) => Number.parseFloat(part.trim()))
|
|
346
|
-
.filter((value) => Number.isFinite(value));
|
|
347
|
-
if (parts.length !== 4) {
|
|
348
|
-
return null;
|
|
349
|
-
}
|
|
350
|
-
const [x1, y1, x2, y2] = parts;
|
|
351
|
-
if ([x1, y1, x2, y2].some((value) => Number.isNaN(value))) {
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
return {
|
|
355
|
-
p1: { x: clamp01(x1), y: y1 },
|
|
356
|
-
p2: { x: clamp01(x2), y: y2 }
|
|
357
|
-
};
|
|
358
|
-
};
|
|
359
|
-
const ensureStopPositions = (stops) => {
|
|
360
|
-
if (stops.length === 0) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
const first = stops[0];
|
|
364
|
-
if (first && first.x == null) {
|
|
365
|
-
first.x = 0;
|
|
366
|
-
}
|
|
367
|
-
const lastIndex = stops.length - 1;
|
|
368
|
-
const last = stops[lastIndex];
|
|
369
|
-
if (last && last.x == null) {
|
|
370
|
-
last.x = 1;
|
|
371
|
-
}
|
|
372
|
-
const assignBetween = (startIndex, endIndex) => {
|
|
373
|
-
const startStop = stops[startIndex];
|
|
374
|
-
const endStop = stops[endIndex];
|
|
375
|
-
if (!startStop || !endStop || startStop.x == null || endStop.x == null) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
const span = endStop.x - startStop.x;
|
|
379
|
-
const segments = endIndex - startIndex;
|
|
380
|
-
if (segments <= 1) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
for (let offset = 1; offset < segments; offset += 1) {
|
|
384
|
-
const index = startIndex + offset;
|
|
385
|
-
const ratio = offset / segments;
|
|
386
|
-
const target = stops[index];
|
|
387
|
-
if (target) {
|
|
388
|
-
target.x = startStop.x + span * ratio;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
let lastDefined = 0;
|
|
393
|
-
for (let index = 1; index < stops.length; index += 1) {
|
|
394
|
-
if (stops[index]?.x != null) {
|
|
395
|
-
assignBetween(lastDefined, index);
|
|
396
|
-
lastDefined = index;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
if (lastDefined < stops.length - 1) {
|
|
400
|
-
assignBetween(lastDefined, stops.length - 1);
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
export const parseLinearTimingFunction = (input) => {
|
|
404
|
-
const match = input.trim().match(/^linear\s*\((.+)\)$/is);
|
|
405
|
-
if (!match) {
|
|
406
|
-
return null;
|
|
407
|
-
}
|
|
408
|
-
const body = match[1];
|
|
409
|
-
if (!body) {
|
|
410
|
-
return null;
|
|
411
|
-
}
|
|
412
|
-
const segments = body
|
|
413
|
-
.split(',')
|
|
414
|
-
.map((segment) => segment.trim())
|
|
415
|
-
.filter((segment) => segment.length > 0);
|
|
416
|
-
if (segments.length < 2) {
|
|
417
|
-
return null;
|
|
418
|
-
}
|
|
419
|
-
const stops = [];
|
|
420
|
-
for (const segment of segments) {
|
|
421
|
-
const parts = segment.split(/\s+/).filter((part) => part.length > 0);
|
|
422
|
-
if (parts.length === 0) {
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
const valueToken = parts[0];
|
|
426
|
-
if (!valueToken) {
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
const value = Number.parseFloat(valueToken);
|
|
430
|
-
if (Number.isNaN(value)) {
|
|
431
|
-
return null;
|
|
432
|
-
}
|
|
433
|
-
let position = null;
|
|
434
|
-
for (let index = 1; index < parts.length; index += 1) {
|
|
435
|
-
const token = parts[index];
|
|
436
|
-
if (!token) {
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
const percentMatch = token.match(/^(-?\d+(?:\.\d+)?)%$/);
|
|
440
|
-
if (percentMatch) {
|
|
441
|
-
const [, percentValue] = percentMatch;
|
|
442
|
-
if (percentValue === undefined) {
|
|
443
|
-
break;
|
|
444
|
-
}
|
|
445
|
-
const parsed = Number.parseFloat(percentValue);
|
|
446
|
-
if (!Number.isNaN(parsed)) {
|
|
447
|
-
position = clamp01(parsed / 100);
|
|
448
|
-
}
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
stops.push({ y: value, x: position });
|
|
453
|
-
}
|
|
454
|
-
if (stops.length < 2) {
|
|
455
|
-
return null;
|
|
456
|
-
}
|
|
457
|
-
ensureStopPositions(stops);
|
|
458
|
-
const rawPoints = stops.map((stop) => {
|
|
459
|
-
const x = stop.x ?? 0;
|
|
460
|
-
return { x: clamp01(x), y: stop.y };
|
|
461
|
-
});
|
|
462
|
-
return normalizeLinearPoints(rawPoints);
|
|
463
|
-
};
|
|
464
|
-
export const vectorLength = (dx, dy) => Math.sqrt(dx * dx + dy * dy);
|
|
465
|
-
export const normalizeVector = (dx, dy) => {
|
|
466
|
-
const length = vectorLength(dx, dy);
|
|
467
|
-
if (length === 0) {
|
|
468
|
-
return { dx: 0, dy: 0 };
|
|
469
|
-
}
|
|
470
|
-
return { dx: dx / length, dy: dy / length };
|
|
471
|
-
};
|
|
472
|
-
export const smoothLinearPoints = (points, tension = 0.25) => {
|
|
473
|
-
if (points.length < 2) {
|
|
474
|
-
return points;
|
|
475
|
-
}
|
|
476
|
-
return points.map((point, index) => {
|
|
477
|
-
const prev = points[index - 1];
|
|
478
|
-
const next = points[index + 1];
|
|
479
|
-
const smoothedPoint = { ...point, isLinked: true, mirrorLength: true };
|
|
480
|
-
if (index === 0 && next) {
|
|
481
|
-
const dx = next.x - point.x;
|
|
482
|
-
const dy = next.y - point.y;
|
|
483
|
-
const length = Math.sqrt(dx * dx + dy * dy);
|
|
484
|
-
const handleLength = length * tension;
|
|
485
|
-
if (length > 0) {
|
|
486
|
-
smoothedPoint.cpOutX = (dx / length) * handleLength;
|
|
487
|
-
smoothedPoint.cpOutY = (dy / length) * handleLength;
|
|
488
|
-
}
|
|
489
|
-
return smoothedPoint;
|
|
490
|
-
}
|
|
491
|
-
if (index === points.length - 1 && prev) {
|
|
492
|
-
const dx = point.x - prev.x;
|
|
493
|
-
const dy = point.y - prev.y;
|
|
494
|
-
const length = Math.sqrt(dx * dx + dy * dy);
|
|
495
|
-
const handleLength = length * tension;
|
|
496
|
-
if (length > 0) {
|
|
497
|
-
smoothedPoint.cpInX = -(dx / length) * handleLength;
|
|
498
|
-
smoothedPoint.cpInY = -(dy / length) * handleLength;
|
|
499
|
-
}
|
|
500
|
-
return smoothedPoint;
|
|
501
|
-
}
|
|
502
|
-
if (prev && next) {
|
|
503
|
-
const tangentX = next.x - prev.x;
|
|
504
|
-
const tangentY = next.y - prev.y;
|
|
505
|
-
const tangentLength = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
|
|
506
|
-
if (tangentLength > 0) {
|
|
507
|
-
const normalizedTx = tangentX / tangentLength;
|
|
508
|
-
const normalizedTy = tangentY / tangentLength;
|
|
509
|
-
const distToPrev = Math.sqrt((point.x - prev.x) ** 2 + (point.y - prev.y) ** 2);
|
|
510
|
-
const distToNext = Math.sqrt((next.x - point.x) ** 2 + (next.y - point.y) ** 2);
|
|
511
|
-
const inHandleLength = distToPrev * tension;
|
|
512
|
-
const outHandleLength = distToNext * tension;
|
|
513
|
-
smoothedPoint.cpInX = -normalizedTx * inHandleLength;
|
|
514
|
-
smoothedPoint.cpInY = -normalizedTy * inHandleLength;
|
|
515
|
-
smoothedPoint.cpOutX = normalizedTx * outHandleLength;
|
|
516
|
-
smoothedPoint.cpOutY = normalizedTy * outHandleLength;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return smoothedPoint;
|
|
520
|
-
});
|
|
521
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./code/index.cjs"), exports);
|
|
18
|
-
__exportStar(require("./curve/index.cjs"), exports);
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Component = void 0;
|
|
4
|
-
const lit_html_1 = require("lit-html");
|
|
5
|
-
const styleCache = new Map();
|
|
6
|
-
const normalizeTemplate = (template) => {
|
|
7
|
-
if (typeof template === 'function') {
|
|
8
|
-
return template;
|
|
9
|
-
}
|
|
10
|
-
if (template && typeof template === 'object' && '_$litTemplate$' in template) {
|
|
11
|
-
return function () {
|
|
12
|
-
return template;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return function () {
|
|
16
|
-
return null;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
const fetchStyles = async (urls) => Promise.all(urls.map((url) => {
|
|
20
|
-
const cached = styleCache.get(url);
|
|
21
|
-
if (cached) {
|
|
22
|
-
return cached;
|
|
23
|
-
}
|
|
24
|
-
const request = fetch(url)
|
|
25
|
-
.then((response) => (response.ok ? response.text() : ''))
|
|
26
|
-
.catch(() => '');
|
|
27
|
-
styleCache.set(url, request);
|
|
28
|
-
return request;
|
|
29
|
-
}));
|
|
30
|
-
const Component = (options) => (Base, _context) => {
|
|
31
|
-
const { tag, template, styles = '', styleUrls = [], observedAttributes = [], shadowMode = 'open', autoSlot = true } = options;
|
|
32
|
-
if (!tag) {
|
|
33
|
-
throw new Error('@Component requires a "tag" option.');
|
|
34
|
-
}
|
|
35
|
-
const templateFn = normalizeTemplate(template);
|
|
36
|
-
class Decorated extends Base {
|
|
37
|
-
static get observedAttributes() {
|
|
38
|
-
const parent = 'observedAttributes' in Base && Array.isArray(Base.observedAttributes)
|
|
39
|
-
? Base.observedAttributes
|
|
40
|
-
: [];
|
|
41
|
-
const own = Array.isArray(observedAttributes) ? observedAttributes : [];
|
|
42
|
-
return Array.from(new Set([...parent, ...own]));
|
|
43
|
-
}
|
|
44
|
-
#shadow;
|
|
45
|
-
#styles = styles;
|
|
46
|
-
#styleUrls = [...styleUrls];
|
|
47
|
-
#renderScheduled = false;
|
|
48
|
-
constructor(...args) {
|
|
49
|
-
super(...args);
|
|
50
|
-
this.#shadow = this.attachShadow({ mode: shadowMode });
|
|
51
|
-
this.renderRoot = this.#shadow;
|
|
52
|
-
}
|
|
53
|
-
get shadow() {
|
|
54
|
-
return this.renderRoot;
|
|
55
|
-
}
|
|
56
|
-
connectedCallback() {
|
|
57
|
-
Base.prototype.connectedCallback?.call(this);
|
|
58
|
-
void this.#loadStyles().finally(() => {
|
|
59
|
-
this.requestRender();
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
disconnectedCallback() {
|
|
63
|
-
Base.prototype.disconnectedCallback?.call(this);
|
|
64
|
-
this.#renderScheduled = false;
|
|
65
|
-
}
|
|
66
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
67
|
-
Base.prototype.attributeChangedCallback?.call(this, name, oldValue, newValue);
|
|
68
|
-
if (oldValue !== newValue) {
|
|
69
|
-
this.onAttributeChange?.(name, oldValue, newValue);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
requestRender() {
|
|
73
|
-
if (this.#renderScheduled) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.#renderScheduled = true;
|
|
77
|
-
requestAnimationFrame(() => {
|
|
78
|
-
this.#renderScheduled = false;
|
|
79
|
-
this.#render();
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
async #loadStyles() {
|
|
83
|
-
if (!this.#styleUrls.length) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const fetched = await fetchStyles(this.#styleUrls);
|
|
87
|
-
const inlineStyles = this.#styles ? [this.#styles] : [];
|
|
88
|
-
this.#styles = [...inlineStyles, ...fetched.filter(Boolean)].join('\n');
|
|
89
|
-
}
|
|
90
|
-
#render() {
|
|
91
|
-
const root = this.#shadow;
|
|
92
|
-
let templateResult;
|
|
93
|
-
if (typeof this.render === 'function') {
|
|
94
|
-
templateResult = this.render();
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
templateResult = templateFn.call(this, this);
|
|
98
|
-
}
|
|
99
|
-
const styleTemplate = this.#styles ? (0, lit_html_1.html) `<style>${this.#styles}</style>` : null;
|
|
100
|
-
const slotTemplate = autoSlot ? (0, lit_html_1.html) `<slot></slot>` : null;
|
|
101
|
-
const completeTemplate = (0, lit_html_1.html) `
|
|
102
|
-
${styleTemplate}
|
|
103
|
-
${templateResult ?? null}
|
|
104
|
-
${slotTemplate}
|
|
105
|
-
`;
|
|
106
|
-
const commit = () => {
|
|
107
|
-
(0, lit_html_1.render)(completeTemplate, root);
|
|
108
|
-
this.afterRender?.();
|
|
109
|
-
};
|
|
110
|
-
if (typeof this.wrapRender === 'function') {
|
|
111
|
-
const fragment = document.createDocumentFragment();
|
|
112
|
-
const tempDiv = document.createElement('div');
|
|
113
|
-
(0, lit_html_1.render)(completeTemplate, tempDiv);
|
|
114
|
-
fragment.append(...tempDiv.childNodes);
|
|
115
|
-
this.wrapRender(commit, { fragment, root });
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
commit();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// SSR safety: only register in browser environments
|
|
122
|
-
if (typeof customElements !== 'undefined' && !customElements.get(tag)) {
|
|
123
|
-
customElements.define(tag, Decorated);
|
|
124
|
-
}
|
|
125
|
-
return Decorated;
|
|
126
|
-
};
|
|
127
|
-
exports.Component = Component;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type TemplateResult } from 'lit-html';
|
|
2
|
-
type Constructor<T extends HTMLElement> = new (...args: unknown[]) => T;
|
|
3
|
-
type RenderableElement = HTMLElement & {
|
|
4
|
-
render?(): TemplateResult | null | undefined;
|
|
5
|
-
afterRender?(): void;
|
|
6
|
-
wrapRender?(commit: () => void, context: RenderContext): void;
|
|
7
|
-
onAttributeChange?(name: string, oldValue: string | null, newValue: string | null): void;
|
|
8
|
-
requestRender?(): void;
|
|
9
|
-
renderRoot?: ShadowRoot | HTMLElement;
|
|
10
|
-
};
|
|
11
|
-
type TemplateValue<TElement extends RenderableElement> = TemplateResult | null | undefined | ((this: TElement, host: TElement) => TemplateResult | null | undefined);
|
|
12
|
-
interface ComponentOptions<TElement extends RenderableElement = RenderableElement> {
|
|
13
|
-
tag: string;
|
|
14
|
-
template?: TemplateValue<TElement>;
|
|
15
|
-
styles?: string;
|
|
16
|
-
styleUrls?: string[];
|
|
17
|
-
observedAttributes?: string[];
|
|
18
|
-
shadowMode?: ShadowRootMode;
|
|
19
|
-
autoSlot?: boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface RenderContext {
|
|
22
|
-
fragment: DocumentFragment;
|
|
23
|
-
root: ShadowRoot | HTMLElement;
|
|
24
|
-
}
|
|
25
|
-
export declare const Component: <TElement extends RenderableElement = RenderableElement>(options: ComponentOptions<TElement>) => <TBase extends Constructor<TElement> & {
|
|
26
|
-
observedAttributes?: string[];
|
|
27
|
-
}>(Base: TBase, _context: ClassDecoratorContext) => TBase;
|
|
28
|
-
export {};
|