@rafaelaugusto/jolt 0.1.0-rc.12 → 0.1.0-rc.13
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 +2 -2
- package/dist/core/circle-math.d.ts.map +1 -1
- package/dist/core/easing.d.ts +8 -0
- package/dist/core/easing.d.ts.map +1 -1
- package/dist/core/easing.js +12 -4
- package/dist/core/easing.js.map +1 -1
- package/dist/core/gesture-math.d.ts.map +1 -1
- package/dist/core/gradient-text.d.ts +24 -0
- package/dist/core/gradient-text.d.ts.map +1 -0
- package/dist/core/gradient-text.js +30 -0
- package/dist/core/gradient-text.js.map +1 -0
- package/dist/core/inspection-plot.d.ts +11 -0
- package/dist/core/inspection-plot.d.ts.map +1 -0
- package/dist/core/inspection-plot.js +57 -0
- package/dist/core/inspection-plot.js.map +1 -0
- package/dist/core/motion-behaviors.d.ts +68 -0
- package/dist/core/motion-behaviors.d.ts.map +1 -0
- package/dist/core/motion-behaviors.js +276 -0
- package/dist/core/motion-behaviors.js.map +1 -0
- package/dist/core/numeric-map.js.map +1 -1
- package/dist/core/particle-motion.d.ts +8 -0
- package/dist/core/particle-motion.d.ts.map +1 -0
- package/dist/core/particle-motion.js +11 -0
- package/dist/core/particle-motion.js.map +1 -0
- package/dist/core/pointer.d.ts +1 -1
- package/dist/core/preset-recipe.d.ts +20 -0
- package/dist/core/preset-recipe.d.ts.map +1 -0
- package/dist/core/preset-recipe.js +79 -0
- package/dist/core/preset-recipe.js.map +1 -0
- package/dist/core/reorder.d.ts +5 -0
- package/dist/core/reorder.d.ts.map +1 -1
- package/dist/core/reorder.js +17 -0
- package/dist/core/reorder.js.map +1 -1
- package/dist/core/rig.d.ts +73 -0
- package/dist/core/rig.d.ts.map +1 -0
- package/dist/core/rig.js +99 -0
- package/dist/core/rig.js.map +1 -0
- package/dist/core/scroll-header.js.map +1 -1
- package/dist/core/sensor-kinds.d.ts +1 -1
- package/dist/core/sensor-kinds.d.ts.map +1 -1
- package/dist/core/sensor-replay.d.ts +10 -0
- package/dist/core/sensor-replay.d.ts.map +1 -0
- package/dist/core/sensor-replay.js +32 -0
- package/dist/core/sensor-replay.js.map +1 -0
- package/dist/gradient-text/index.d.ts +2 -10
- package/dist/gradient-text/index.d.ts.map +1 -1
- package/dist/gradient-text/index.js +2 -25
- package/dist/gradient-text/index.js.map +1 -1
- package/dist/gradient-text/native.d.ts +2 -8
- package/dist/gradient-text/native.d.ts.map +1 -1
- package/dist/gradient-text/native.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector/plot.d.ts +1 -3
- package/dist/inspector/plot.d.ts.map +1 -1
- package/dist/inspector/plot.js +1 -22
- package/dist/inspector/plot.js.map +1 -1
- package/dist/motion-behaviors.d.ts +5 -54
- package/dist/motion-behaviors.d.ts.map +1 -1
- package/dist/motion-behaviors.js +18 -267
- package/dist/motion-behaviors.js.map +1 -1
- package/dist/rig/index.d.ts +2 -27
- package/dist/rig/index.d.ts.map +1 -1
- package/dist/rig/index.js +5 -89
- package/dist/rig/index.js.map +1 -1
- package/dist/testing/sensors.d.ts +2 -9
- package/dist/testing/sensors.d.ts.map +1 -1
- package/dist/testing/sensors.js +3 -21
- package/dist/testing/sensors.js.map +1 -1
- package/dist/web/angular/index.d.ts +62 -0
- package/dist/web/angular/index.d.ts.map +1 -0
- package/dist/web/angular/index.js +190 -0
- package/dist/web/angular/index.js.map +1 -0
- package/dist/web/behaviors.d.ts +5 -0
- package/dist/web/behaviors.d.ts.map +1 -0
- package/dist/web/behaviors.js +2 -0
- package/dist/web/behaviors.js.map +1 -0
- package/dist/web/bottom-sheet.js.map +1 -1
- package/dist/web/compose.js.map +1 -1
- package/dist/web/curve.js.map +1 -1
- package/dist/web/decay.js.map +1 -1
- package/dist/web/diagnostics.d.ts +1 -1
- package/dist/web/diagnostics.d.ts.map +1 -1
- package/dist/web/diagnostics.js.map +1 -1
- package/dist/web/drag.d.ts +11 -11
- package/dist/web/drag.d.ts.map +1 -1
- package/dist/web/effect.d.ts +2 -1
- package/dist/web/effect.d.ts.map +1 -1
- package/dist/web/effect.js +11 -4
- package/dist/web/effect.js.map +1 -1
- package/dist/web/frameworks/binding.d.ts +39 -0
- package/dist/web/frameworks/binding.d.ts.map +1 -0
- package/dist/web/frameworks/binding.js +356 -0
- package/dist/web/frameworks/binding.js.map +1 -0
- package/dist/web/gestures.js.map +1 -1
- package/dist/web/gradient-css.d.ts +2 -0
- package/dist/web/gradient-css.d.ts.map +1 -0
- package/dist/web/gradient-css.js +5 -0
- package/dist/web/gradient-css.js.map +1 -0
- package/dist/web/gradient-text.d.ts +24 -0
- package/dist/web/gradient-text.d.ts.map +1 -0
- package/dist/web/gradient-text.js +179 -0
- package/dist/web/gradient-text.js.map +1 -0
- package/dist/web/gradient.d.ts.map +1 -1
- package/dist/web/gradient.js +2 -1
- package/dist/web/gradient.js.map +1 -1
- package/dist/web/image-surface.d.ts.map +1 -1
- package/dist/web/image-surface.js.map +1 -1
- package/dist/web/inspector.d.ts +24 -0
- package/dist/web/inspector.d.ts.map +1 -1
- package/dist/web/inspector.js +76 -5
- package/dist/web/inspector.js.map +1 -1
- package/dist/web/interaction.d.ts +4 -0
- package/dist/web/interaction.d.ts.map +1 -1
- package/dist/web/interaction.js.map +1 -1
- package/dist/web/keyboard.js.map +1 -1
- package/dist/web/layout.d.ts +75 -75
- package/dist/web/layout.d.ts.map +1 -1
- package/dist/web/layout.js.map +1 -1
- package/dist/web/particles.d.ts.map +1 -1
- package/dist/web/particles.js +5 -6
- package/dist/web/particles.js.map +1 -1
- package/dist/web/plan.d.ts +2 -0
- package/dist/web/plan.d.ts.map +1 -1
- package/dist/web/plan.js.map +1 -1
- package/dist/web/press.js.map +1 -1
- package/dist/web/progress.d.ts.map +1 -1
- package/dist/web/properties.d.ts +4 -4
- package/dist/web/properties.d.ts.map +1 -1
- package/dist/web/property.d.ts.map +1 -1
- package/dist/web/property.js.map +1 -1
- package/dist/web/public.d.ts +19 -3
- package/dist/web/public.d.ts.map +1 -1
- package/dist/web/public.js +9 -0
- package/dist/web/public.js.map +1 -1
- package/dist/web/react/index.d.ts +12 -0
- package/dist/web/react/index.d.ts.map +1 -0
- package/dist/web/react/index.js +119 -0
- package/dist/web/react/index.js.map +1 -0
- package/dist/web/reorder.d.ts.map +1 -1
- package/dist/web/reorder.js +23 -2
- package/dist/web/reorder.js.map +1 -1
- package/dist/web/rig.d.ts +43 -0
- package/dist/web/rig.d.ts.map +1 -0
- package/dist/web/rig.js +307 -0
- package/dist/web/rig.js.map +1 -0
- package/dist/web/runtime.d.ts +37 -25
- package/dist/web/runtime.d.ts.map +1 -1
- package/dist/web/runtime.js +111 -8
- package/dist/web/runtime.js.map +1 -1
- package/dist/web/scheduler.d.ts.map +1 -1
- package/dist/web/scheduler.js.map +1 -1
- package/dist/web/scope.d.ts +7 -1
- package/dist/web/scope.d.ts.map +1 -1
- package/dist/web/scope.js +16 -2
- package/dist/web/scope.js.map +1 -1
- package/dist/web/scroll-header.js.map +1 -1
- package/dist/web/scroll-range.d.ts.map +1 -1
- package/dist/web/scroll-range.js.map +1 -1
- package/dist/web/scroll.d.ts +1 -1
- package/dist/web/scroll.d.ts.map +1 -1
- package/dist/web/scroll.js.map +1 -1
- package/dist/web/sensor-replay-bridge.d.ts +16 -0
- package/dist/web/sensor-replay-bridge.d.ts.map +1 -0
- package/dist/web/sensor-replay-bridge.js +12 -0
- package/dist/web/sensor-replay-bridge.js.map +1 -0
- package/dist/web/sensor-replay.d.ts +22 -0
- package/dist/web/sensor-replay.d.ts.map +1 -0
- package/dist/web/sensor-replay.js +124 -0
- package/dist/web/sensor-replay.js.map +1 -0
- package/dist/web/sensors.d.ts +14 -5
- package/dist/web/sensors.d.ts.map +1 -1
- package/dist/web/sensors.js +159 -41
- package/dist/web/sensors.js.map +1 -1
- package/dist/web/shape.d.ts +2 -0
- package/dist/web/shape.d.ts.map +1 -1
- package/dist/web/shape.js +44 -12
- package/dist/web/shape.js.map +1 -1
- package/dist/web/shared-layout.js.map +1 -1
- package/dist/web/size.d.ts.map +1 -1
- package/dist/web/size.js.map +1 -1
- package/dist/web/solid/index.d.ts +16 -0
- package/dist/web/solid/index.d.ts.map +1 -0
- package/dist/web/solid/index.js +89 -0
- package/dist/web/solid/index.js.map +1 -0
- package/dist/web/spring-value.d.ts.map +1 -1
- package/dist/web/spring-value.js.map +1 -1
- package/dist/web/stroke.d.ts.map +1 -1
- package/dist/web/stroke.js.map +1 -1
- package/dist/web/style.d.ts.map +1 -1
- package/dist/web/style.js.map +1 -1
- package/dist/web/surface-effect.d.ts.map +1 -1
- package/dist/web/surface-effect.js.map +1 -1
- package/dist/web/svelte/index.d.ts +50 -0
- package/dist/web/svelte/index.d.ts.map +1 -0
- package/dist/web/svelte/index.js +68 -0
- package/dist/web/svelte/index.js.map +1 -0
- package/dist/web/testing.d.ts +1 -0
- package/dist/web/testing.d.ts.map +1 -1
- package/dist/web/testing.js +1 -0
- package/dist/web/testing.js.map +1 -1
- package/dist/web/timers.d.ts.map +1 -1
- package/dist/web/timers.js.map +1 -1
- package/dist/web/types.d.ts.map +1 -1
- package/dist/web/value-playback.d.ts +17 -17
- package/dist/web/value-playback.js.map +1 -1
- package/dist/web/value.d.ts.map +1 -1
- package/dist/web/value.js.map +1 -1
- package/dist/web/viewport.js.map +1 -1
- package/dist/web/vue/index.d.ts +12 -3
- package/dist/web/vue/index.d.ts.map +1 -1
- package/dist/web/vue/index.js +115 -35
- package/dist/web/vue/index.js.map +1 -1
- package/package.json +35 -6
- package/src/core/easing.ts +12 -4
- package/src/core/gradient-text.ts +56 -0
- package/src/core/inspection-plot.ts +74 -0
- package/src/core/motion-behaviors.ts +337 -0
- package/src/core/particle-motion.ts +20 -0
- package/src/core/preset-recipe.ts +111 -0
- package/src/core/reorder.ts +23 -0
- package/src/core/rig.ts +149 -0
- package/src/core/sensor-replay.ts +48 -0
- package/src/gradient-text/index.ts +7 -43
- package/src/gradient-text/native.ts +2 -7
- package/src/index.ts +6 -0
- package/src/inspector/plot.ts +1 -27
- package/src/motion-behaviors.ts +34 -316
- package/src/rig/index.ts +25 -124
- package/src/testing/sensors.ts +4 -36
- package/src/web/angular/index.ts +171 -0
- package/src/web/behaviors.ts +12 -0
- package/src/web/effect.ts +10 -5
- package/src/web/frameworks/binding.ts +408 -0
- package/src/web/gradient-css.ts +8 -0
- package/src/web/gradient-text.ts +234 -0
- package/src/web/gradient.ts +2 -1
- package/src/web/inspector.ts +80 -5
- package/src/web/interaction.ts +4 -0
- package/src/web/particles.ts +15 -9
- package/src/web/plan.ts +2 -0
- package/src/web/public.ts +51 -4
- package/src/web/react/index.ts +208 -0
- package/src/web/reorder.ts +21 -3
- package/src/web/rig.ts +377 -0
- package/src/web/runtime.ts +128 -11
- package/src/web/scope.ts +32 -4
- package/src/web/sensor-replay-bridge.ts +23 -0
- package/src/web/sensor-replay.ts +140 -0
- package/src/web/sensors.ts +179 -57
- package/src/web/shape.ts +42 -9
- package/src/web/solid/index.ts +102 -0
- package/src/web/svelte/index.ts +88 -0
- package/src/web/testing.ts +6 -0
- package/src/web/vue/index.ts +122 -31
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Directive,
|
|
3
|
+
ElementRef,
|
|
4
|
+
Input,
|
|
5
|
+
TemplateRef,
|
|
6
|
+
ViewContainerRef,
|
|
7
|
+
afterEveryRender,
|
|
8
|
+
inject,
|
|
9
|
+
type EmbeddedViewRef,
|
|
10
|
+
type OnChanges,
|
|
11
|
+
type OnDestroy,
|
|
12
|
+
} from '@angular/core'
|
|
13
|
+
import { type WebRuntime } from '../public.js'
|
|
14
|
+
import {
|
|
15
|
+
animateBinding,
|
|
16
|
+
fromCurrent,
|
|
17
|
+
motionBinding,
|
|
18
|
+
type MotionSetup,
|
|
19
|
+
pressBinding,
|
|
20
|
+
type AnimateValue,
|
|
21
|
+
type PressValue,
|
|
22
|
+
type BindingOptions,
|
|
23
|
+
} from '../frameworks/binding.js'
|
|
24
|
+
export type {
|
|
25
|
+
AnimateValue,
|
|
26
|
+
PressValue,
|
|
27
|
+
BindingOptions,
|
|
28
|
+
MotionSetup,
|
|
29
|
+
} from '../frameworks/binding.js'
|
|
30
|
+
|
|
31
|
+
@Directive({ selector: '[joltAnimate]', standalone: true })
|
|
32
|
+
export class JoltAnimateDirective implements OnDestroy {
|
|
33
|
+
@Input() joltAnimate?: AnimateValue
|
|
34
|
+
@Input() joltRuntime?: WebRuntime
|
|
35
|
+
private readonly element = inject<ElementRef<HTMLElement>>(ElementRef)
|
|
36
|
+
private binding?: ReturnType<typeof animateBinding>
|
|
37
|
+
private runtime?: WebRuntime
|
|
38
|
+
private readonly render = afterEveryRender(() => {
|
|
39
|
+
if (this.binding && (this.runtime !== this.joltRuntime || this.binding.disposed)) {
|
|
40
|
+
this.binding.destroy()
|
|
41
|
+
this.binding = undefined
|
|
42
|
+
}
|
|
43
|
+
if (!this.binding) {
|
|
44
|
+
this.runtime = this.joltRuntime
|
|
45
|
+
this.binding = animateBinding(this.element.nativeElement, this.joltAnimate, {
|
|
46
|
+
runtime: this.runtime,
|
|
47
|
+
})
|
|
48
|
+
} else this.binding.update(this.joltAnimate)
|
|
49
|
+
})
|
|
50
|
+
ngOnDestroy() {
|
|
51
|
+
this.render.destroy()
|
|
52
|
+
this.binding?.destroy()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Directive({ selector: '[joltPress]', standalone: true })
|
|
57
|
+
export class JoltPressDirective implements OnDestroy {
|
|
58
|
+
@Input() joltPress?: PressValue
|
|
59
|
+
@Input() joltRuntime?: WebRuntime
|
|
60
|
+
private readonly element = inject<ElementRef<HTMLElement>>(ElementRef)
|
|
61
|
+
private binding?: ReturnType<typeof pressBinding>
|
|
62
|
+
private runtime?: WebRuntime
|
|
63
|
+
private readonly render = afterEveryRender(() => {
|
|
64
|
+
if (this.binding && (this.runtime !== this.joltRuntime || this.binding.disposed)) {
|
|
65
|
+
this.binding.destroy()
|
|
66
|
+
this.binding = undefined
|
|
67
|
+
}
|
|
68
|
+
if (!this.binding) {
|
|
69
|
+
this.runtime = this.joltRuntime
|
|
70
|
+
this.binding = pressBinding(this.element.nativeElement, this.joltPress, {
|
|
71
|
+
runtime: this.runtime,
|
|
72
|
+
})
|
|
73
|
+
} else this.binding.update(this.joltPress)
|
|
74
|
+
})
|
|
75
|
+
ngOnDestroy() {
|
|
76
|
+
this.render.destroy()
|
|
77
|
+
this.binding?.destroy()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Retain one DOM root through exit; Angular continues to own creation/destruction. */
|
|
82
|
+
@Directive({ selector: '[joltIf]', standalone: true })
|
|
83
|
+
export class JoltIfDirective implements OnChanges, OnDestroy {
|
|
84
|
+
@Input() joltIf = false
|
|
85
|
+
@Input() joltIfEnter: AnimateValue = 'fadeIn'
|
|
86
|
+
@Input() joltIfLeave: AnimateValue = 'fadeOut'
|
|
87
|
+
@Input() joltIfRuntime?: WebRuntime
|
|
88
|
+
private readonly template = inject(TemplateRef<unknown>)
|
|
89
|
+
private readonly container = inject(ViewContainerRef)
|
|
90
|
+
private view?: EmbeddedViewRef<unknown>
|
|
91
|
+
private binding?: ReturnType<typeof animateBinding>
|
|
92
|
+
private runtime?: WebRuntime
|
|
93
|
+
private dirty = false
|
|
94
|
+
private leaving = false
|
|
95
|
+
private destroyed = false
|
|
96
|
+
private epoch = 0
|
|
97
|
+
private readonly render = afterEveryRender(() => this.reconcile())
|
|
98
|
+
ngOnChanges() {
|
|
99
|
+
if (this.destroyed) return
|
|
100
|
+
this.epoch++
|
|
101
|
+
this.dirty = true
|
|
102
|
+
// Structural rendering also happens on the server. DOM animation waits for render.
|
|
103
|
+
if (this.joltIf && !this.view)
|
|
104
|
+
this.view = this.container.createEmbeddedView(this.template)
|
|
105
|
+
}
|
|
106
|
+
private reconcile() {
|
|
107
|
+
if (!this.dirty || this.destroyed || !this.view) return
|
|
108
|
+
this.dirty = false
|
|
109
|
+
const roots = this.view.rootNodes.filter((node: Node) => node.nodeType === 1)
|
|
110
|
+
if (
|
|
111
|
+
roots.length !== 1 ||
|
|
112
|
+
!(roots[0] instanceof roots[0].ownerDocument.defaultView.HTMLElement)
|
|
113
|
+
)
|
|
114
|
+
throw new Error('joltIf requires exactly one HTML root; wrap sibling roots.')
|
|
115
|
+
if (!this.binding || this.runtime !== this.joltIfRuntime) {
|
|
116
|
+
this.binding?.destroy()
|
|
117
|
+
this.runtime = this.joltIfRuntime
|
|
118
|
+
this.binding = animateBinding(roots[0], undefined, { runtime: this.runtime })
|
|
119
|
+
}
|
|
120
|
+
const epoch = this.epoch,
|
|
121
|
+
interrupted = this.leaving || !this.joltIf
|
|
122
|
+
this.leaving = !this.joltIf
|
|
123
|
+
const input = this.joltIf ? this.joltIfEnter : this.joltIfLeave
|
|
124
|
+
const value = interrupted ? fromCurrent(input) : input
|
|
125
|
+
const animation = this.binding.update(value, true)
|
|
126
|
+
if (!this.joltIf && animation)
|
|
127
|
+
void animation.finished.then((completed) => {
|
|
128
|
+
if (!completed || this.destroyed || this.epoch !== epoch || this.joltIf) return
|
|
129
|
+
this.binding?.destroy()
|
|
130
|
+
this.binding = undefined
|
|
131
|
+
this.container.clear()
|
|
132
|
+
this.view = undefined
|
|
133
|
+
this.leaving = false
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
ngOnDestroy() {
|
|
137
|
+
this.destroyed = true
|
|
138
|
+
this.epoch++
|
|
139
|
+
this.render.destroy()
|
|
140
|
+
this.binding?.destroy()
|
|
141
|
+
this.container.clear()
|
|
142
|
+
this.binding = undefined
|
|
143
|
+
this.view = undefined
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Set up existing runtime resources after render, with transactional scope cleanup. */
|
|
148
|
+
@Directive({ selector: '[joltMotion]', standalone: true })
|
|
149
|
+
export class JoltMotionDirective implements OnDestroy {
|
|
150
|
+
@Input({ required: true }) joltMotion!: MotionSetup
|
|
151
|
+
@Input() joltRuntime?: WebRuntime
|
|
152
|
+
private readonly element = inject<ElementRef<HTMLElement>>(ElementRef)
|
|
153
|
+
private binding?: ReturnType<typeof motionBinding>
|
|
154
|
+
private runtime?: WebRuntime
|
|
155
|
+
private readonly render = afterEveryRender(() => {
|
|
156
|
+
if (this.binding && (this.runtime !== this.joltRuntime || this.binding.disposed)) {
|
|
157
|
+
this.binding.destroy()
|
|
158
|
+
this.binding = undefined
|
|
159
|
+
}
|
|
160
|
+
if (!this.binding) {
|
|
161
|
+
this.runtime = this.joltRuntime
|
|
162
|
+
this.binding = motionBinding(this.element.nativeElement, this.joltMotion, {
|
|
163
|
+
runtime: this.runtime,
|
|
164
|
+
})
|
|
165
|
+
} else this.binding.update(this.joltMotion)
|
|
166
|
+
})
|
|
167
|
+
ngOnDestroy() {
|
|
168
|
+
this.render.destroy()
|
|
169
|
+
this.binding?.destroy()
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WebMotionScope } from './scope.js'
|
|
2
|
+
export type {
|
|
3
|
+
BehaviorStatus,
|
|
4
|
+
BehaviorResult,
|
|
5
|
+
BehaviorRun,
|
|
6
|
+
MotionBehaviorsOptions,
|
|
7
|
+
MotionBehaviors,
|
|
8
|
+
} from '../core/motion-behaviors.js'
|
|
9
|
+
export type WebBehaviorContext =
|
|
10
|
+
import('../core/motion-behaviors.js').BehaviorContext<WebMotionScope>
|
|
11
|
+
export type WebMotionBehavior =
|
|
12
|
+
import('../core/motion-behaviors.js').MotionBehavior<WebMotionScope>
|
package/src/web/effect.ts
CHANGED
|
@@ -150,8 +150,10 @@ export class EffectAnimation implements WebAnimation, WebInteraction {
|
|
|
150
150
|
frames: readonly EffectFrames[],
|
|
151
151
|
private readonly render: ((elapsed: number) => void) | undefined,
|
|
152
152
|
private readonly settle: (completed: boolean, elapsed: number) => void,
|
|
153
|
+
private readonly terminalTime = duration,
|
|
153
154
|
) {
|
|
154
|
-
finiteOption(duration, 'Effect duration')
|
|
155
|
+
if (duration !== Infinity) finiteOption(duration, 'Effect duration')
|
|
156
|
+
finiteOption(terminalTime, 'Effect terminal time')
|
|
155
157
|
this.finished = new Promise((resolve) => {
|
|
156
158
|
this.resolve = resolve
|
|
157
159
|
})
|
|
@@ -203,6 +205,8 @@ export class EffectAnimation implements WebAnimation, WebInteraction {
|
|
|
203
205
|
return Math.min(this.duration, Math.max(0, this.clock.time()))
|
|
204
206
|
}
|
|
205
207
|
get progress() {
|
|
208
|
+
if (!Number.isFinite(this.duration))
|
|
209
|
+
throw new RangeError('Progress requires a finite animation.')
|
|
206
210
|
return this.duration ? this.time() / this.duration : 1
|
|
207
211
|
}
|
|
208
212
|
set progress(value: number) {
|
|
@@ -250,14 +254,15 @@ export class EffectAnimation implements WebAnimation, WebInteraction {
|
|
|
250
254
|
}
|
|
251
255
|
if (!this.held) {
|
|
252
256
|
if (this.render) this.host.scheduler.add(this.task)
|
|
253
|
-
|
|
254
|
-
this.
|
|
255
|
-
|
|
257
|
+
if (Number.isFinite(this.duration))
|
|
258
|
+
this.cancelTimer = this.host.after(Math.max(0, this.duration - this.time()), () =>
|
|
259
|
+
this.finish(true),
|
|
260
|
+
)
|
|
256
261
|
}
|
|
257
262
|
}
|
|
258
263
|
finish(completed: boolean) {
|
|
259
264
|
if (this.ended) return
|
|
260
|
-
const time = completed ? this.
|
|
265
|
+
const time = completed ? this.terminalTime : this.time()
|
|
261
266
|
this.clock.seek(time)
|
|
262
267
|
this.clock.cancel()
|
|
263
268
|
this.ended = true
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWebRuntime,
|
|
3
|
+
presets,
|
|
4
|
+
type WebRuntime,
|
|
5
|
+
type WebAnimation,
|
|
6
|
+
type WebPress,
|
|
7
|
+
type WebPressOptions,
|
|
8
|
+
type Keyframes,
|
|
9
|
+
type Values,
|
|
10
|
+
type AnimateOptions,
|
|
11
|
+
type SpringName,
|
|
12
|
+
type WebMotionScope,
|
|
13
|
+
type WebMotionResource,
|
|
14
|
+
} from '../public.js'
|
|
15
|
+
import { observeConnection } from '../vue/attachment.js'
|
|
16
|
+
|
|
17
|
+
export type AnimateValue =
|
|
18
|
+
string | Keyframes | readonly [string | Keyframes, (AnimateOptions | SpringName)?]
|
|
19
|
+
export type PressValue = Values | readonly [Values, WebPressOptions?]
|
|
20
|
+
export interface BindingOptions {
|
|
21
|
+
/** Borrowed; never configured, released or disposed by a framework binding. */
|
|
22
|
+
runtime?: WebRuntime
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Only live DOM bindings acquire a context. Imports and server renders do not.
|
|
26
|
+
// Sharing the context lets press compose with animate on the same element.
|
|
27
|
+
const contexts = new WeakMap<
|
|
28
|
+
Document,
|
|
29
|
+
{ runtime: WebRuntime; users: number; targets: Map<HTMLElement, number> }
|
|
30
|
+
>()
|
|
31
|
+
|
|
32
|
+
/** Copy plain declarative input so in-place user changes are not mistaken for equality. */
|
|
33
|
+
function snapshot<T>(value: T, seen = new Set<object>()): T {
|
|
34
|
+
if (!value || typeof value !== 'object') return value
|
|
35
|
+
if (seen.has(value)) throw new TypeError('Motion definitions cannot contain cycles.')
|
|
36
|
+
if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype)
|
|
37
|
+
throw new TypeError('Motion definitions require plain objects and arrays.')
|
|
38
|
+
seen.add(value)
|
|
39
|
+
const result = Array.isArray(value)
|
|
40
|
+
? value.map((item) => snapshot(item, seen))
|
|
41
|
+
: Object.fromEntries(Object.entries(value).map(([k, v]) => [k, snapshot(v, seen)]))
|
|
42
|
+
seen.delete(value)
|
|
43
|
+
return result as T
|
|
44
|
+
}
|
|
45
|
+
function same(a: unknown, b: unknown): boolean {
|
|
46
|
+
if (Object.is(a, b)) return true
|
|
47
|
+
if (!a || !b || typeof a !== 'object' || typeof b !== 'object') return false
|
|
48
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false
|
|
49
|
+
const keys = Object.keys(a)
|
|
50
|
+
return (
|
|
51
|
+
keys.length === Object.keys(b).length &&
|
|
52
|
+
keys.every(
|
|
53
|
+
(key) =>
|
|
54
|
+
Object.hasOwn(b, key) &&
|
|
55
|
+
same((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]),
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function owner(
|
|
61
|
+
node: HTMLElement,
|
|
62
|
+
options: BindingOptions,
|
|
63
|
+
change: (connected: boolean) => void,
|
|
64
|
+
) {
|
|
65
|
+
const document = node?.ownerDocument
|
|
66
|
+
const view = document?.defaultView as (Window & typeof globalThis) | null
|
|
67
|
+
if (!view || !(node instanceof view.HTMLElement))
|
|
68
|
+
throw new TypeError('Web motion bindings require a DOM HTMLElement.')
|
|
69
|
+
let entry = contexts.get(document)
|
|
70
|
+
if (!options.runtime) {
|
|
71
|
+
if (!entry) {
|
|
72
|
+
entry = { runtime: createWebRuntime(document), users: 0, targets: new Map() }
|
|
73
|
+
contexts.set(document, entry)
|
|
74
|
+
}
|
|
75
|
+
entry.users++
|
|
76
|
+
entry.targets.set(node, (entry.targets.get(node) ?? 0) + 1)
|
|
77
|
+
}
|
|
78
|
+
const runtime = options.runtime ?? entry!.runtime
|
|
79
|
+
const scope = runtime.scope()
|
|
80
|
+
let disposed = false
|
|
81
|
+
const connection = observeConnection(node, (connected) => {
|
|
82
|
+
if (disposed) return
|
|
83
|
+
if (node.ownerDocument !== document) {
|
|
84
|
+
destroy()
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
if (connected) scope.resume()
|
|
88
|
+
change(connected)
|
|
89
|
+
if (!connected) scope.suspend()
|
|
90
|
+
})
|
|
91
|
+
function destroy() {
|
|
92
|
+
if (disposed) return
|
|
93
|
+
disposed = true
|
|
94
|
+
connection.dispose()
|
|
95
|
+
try {
|
|
96
|
+
scope.dispose()
|
|
97
|
+
} finally {
|
|
98
|
+
if (!options.runtime) {
|
|
99
|
+
const count = entry!.targets.get(node)! - 1
|
|
100
|
+
if (count) entry!.targets.set(node, count)
|
|
101
|
+
else {
|
|
102
|
+
entry!.targets.delete(node)
|
|
103
|
+
runtime.release(node)
|
|
104
|
+
}
|
|
105
|
+
if (--entry!.users === 0) {
|
|
106
|
+
contexts.delete(document)
|
|
107
|
+
runtime.dispose()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
runtime,
|
|
114
|
+
scope,
|
|
115
|
+
destroy,
|
|
116
|
+
get disposed() {
|
|
117
|
+
return disposed
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type MotionSetup = (
|
|
123
|
+
scope: WebMotionScope,
|
|
124
|
+
node: HTMLElement,
|
|
125
|
+
runtime: WebRuntime,
|
|
126
|
+
) => void | WebMotionResource
|
|
127
|
+
|
|
128
|
+
/** Transactional setup uses existing scope factories. Disconnect tears down and reconnect rebuilds it. */
|
|
129
|
+
export function motionBinding(
|
|
130
|
+
node: HTMLElement,
|
|
131
|
+
initial: MotionSetup,
|
|
132
|
+
options: BindingOptions = {},
|
|
133
|
+
) {
|
|
134
|
+
let setup = initial
|
|
135
|
+
if (typeof setup !== 'function') throw new TypeError('Motion setup must be a function.')
|
|
136
|
+
const binding = owner(node, options, () => {})
|
|
137
|
+
let release: (() => void) | undefined
|
|
138
|
+
function install(next: MotionSetup) {
|
|
139
|
+
if (typeof next !== 'function')
|
|
140
|
+
throw new TypeError('Motion setup must be a function.')
|
|
141
|
+
// Scope.use owns transactional setup, resource adoption and reentrant cleanup.
|
|
142
|
+
const nextRelease = binding.scope.use((scope) => next(scope, node, binding.runtime))
|
|
143
|
+
release?.()
|
|
144
|
+
release = nextRelease
|
|
145
|
+
setup = next
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
if (!node.isConnected) binding.scope.suspend()
|
|
149
|
+
install(setup)
|
|
150
|
+
} catch (error) {
|
|
151
|
+
binding.destroy()
|
|
152
|
+
throw error
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
get disposed() {
|
|
156
|
+
return binding.disposed
|
|
157
|
+
},
|
|
158
|
+
update(next: MotionSetup) {
|
|
159
|
+
if (!binding.disposed && next !== setup) install(next)
|
|
160
|
+
},
|
|
161
|
+
destroy: binding.destroy,
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Framework-independent owner; detached nodes retain the latest declaration. */
|
|
166
|
+
export function animateBinding(
|
|
167
|
+
node: HTMLElement,
|
|
168
|
+
initial?: AnimateValue,
|
|
169
|
+
options: BindingOptions = {},
|
|
170
|
+
) {
|
|
171
|
+
let value = snapshot(initial),
|
|
172
|
+
pending = true,
|
|
173
|
+
manualPause = false
|
|
174
|
+
let current: WebAnimation | undefined
|
|
175
|
+
const binding = owner(node, options, (connected) => {
|
|
176
|
+
if (connected) play()
|
|
177
|
+
else {
|
|
178
|
+
manualPause = current?.paused ?? false
|
|
179
|
+
pending = true
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
function play() {
|
|
183
|
+
if (binding.disposed || !node.isConnected || !pending) return current
|
|
184
|
+
if (value === undefined) {
|
|
185
|
+
binding.scope.reset()
|
|
186
|
+
current = undefined
|
|
187
|
+
} else {
|
|
188
|
+
const [frames, transition] = Array.isArray(value) ? value : [value, undefined]
|
|
189
|
+
const next = binding.scope.animate(
|
|
190
|
+
node,
|
|
191
|
+
frames as string | Keyframes,
|
|
192
|
+
transition as AnimateOptions | SpringName | undefined,
|
|
193
|
+
)
|
|
194
|
+
current = next
|
|
195
|
+
if (manualPause) next.pause()
|
|
196
|
+
}
|
|
197
|
+
pending = false
|
|
198
|
+
return current
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
play()
|
|
202
|
+
} catch (error) {
|
|
203
|
+
binding.destroy()
|
|
204
|
+
throw error
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
get current() {
|
|
208
|
+
return current
|
|
209
|
+
},
|
|
210
|
+
get disposed() {
|
|
211
|
+
return binding.disposed
|
|
212
|
+
},
|
|
213
|
+
update(next?: AnimateValue, replay = false) {
|
|
214
|
+
if (binding.disposed) return
|
|
215
|
+
const copied = snapshot(next)
|
|
216
|
+
if (!replay && same(value, copied)) return current
|
|
217
|
+
const previous = value
|
|
218
|
+
value = copied
|
|
219
|
+
pending = true
|
|
220
|
+
try {
|
|
221
|
+
return play()
|
|
222
|
+
} catch (error) {
|
|
223
|
+
value = previous
|
|
224
|
+
pending = false
|
|
225
|
+
throw error
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
destroy: binding.destroy,
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function pressBinding(
|
|
233
|
+
node: HTMLElement,
|
|
234
|
+
initial?: PressValue,
|
|
235
|
+
options: BindingOptions = {},
|
|
236
|
+
) {
|
|
237
|
+
let value = snapshot(initial),
|
|
238
|
+
current: WebPress | undefined
|
|
239
|
+
const binding = owner(node, options, (connected) => {
|
|
240
|
+
if (connected) {
|
|
241
|
+
if (!current) play()
|
|
242
|
+
} else {
|
|
243
|
+
if (current) binding.scope.release(current)
|
|
244
|
+
current = undefined
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
function play() {
|
|
248
|
+
if (binding.disposed || !node.isConnected) return
|
|
249
|
+
const [values, settings] = Array.isArray(value) ? value : [value, undefined]
|
|
250
|
+
// Validate/create the replacement before releasing working feedback.
|
|
251
|
+
const next = binding.scope.retain(
|
|
252
|
+
binding.runtime.press(
|
|
253
|
+
node,
|
|
254
|
+
values as Values | undefined,
|
|
255
|
+
settings as WebPressOptions | undefined,
|
|
256
|
+
),
|
|
257
|
+
)
|
|
258
|
+
if (current) binding.scope.release(current)
|
|
259
|
+
current = next
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
play()
|
|
263
|
+
} catch (error) {
|
|
264
|
+
binding.destroy()
|
|
265
|
+
throw error
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
get disposed() {
|
|
269
|
+
return binding.disposed
|
|
270
|
+
},
|
|
271
|
+
update(next?: PressValue) {
|
|
272
|
+
if (binding.disposed) return
|
|
273
|
+
const copied = snapshot(next)
|
|
274
|
+
if (same(value, copied)) return
|
|
275
|
+
const previous = value
|
|
276
|
+
value = copied
|
|
277
|
+
try {
|
|
278
|
+
play()
|
|
279
|
+
} catch (error) {
|
|
280
|
+
value = previous
|
|
281
|
+
throw error
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
destroy: binding.destroy,
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface PresenceOptions extends BindingOptions {
|
|
289
|
+
enter?: AnimateValue
|
|
290
|
+
leave?: AnimateValue
|
|
291
|
+
}
|
|
292
|
+
/** Resolve only explicit/built-in recipes: custom registry lookup remains runtime-private. */
|
|
293
|
+
export function fromCurrent(value: AnimateValue): AnimateValue {
|
|
294
|
+
const [definition, options] = Array.isArray(value) ? value : [value, undefined]
|
|
295
|
+
if (typeof definition === 'string' && !Object.hasOwn(presets, definition))
|
|
296
|
+
throw new TypeError(
|
|
297
|
+
'Interrupted presence presets must be built-in or explicit keyframes.',
|
|
298
|
+
)
|
|
299
|
+
const preset =
|
|
300
|
+
typeof definition === 'string'
|
|
301
|
+
? presets[definition as keyof typeof presets]
|
|
302
|
+
: undefined
|
|
303
|
+
const frames = preset?.keyframes ?? (definition as Keyframes)
|
|
304
|
+
return [
|
|
305
|
+
Object.fromEntries(
|
|
306
|
+
Object.entries(frames).map(([key, v]) => [
|
|
307
|
+
key,
|
|
308
|
+
Array.isArray(v) ? [null, ...v.slice(1)] : v,
|
|
309
|
+
]),
|
|
310
|
+
) as Keyframes,
|
|
311
|
+
options ?? preset?.transition,
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
/** The framework retains/removes its own node; this owner only reports completed exits. */
|
|
315
|
+
export function presenceBinding(
|
|
316
|
+
node: HTMLElement,
|
|
317
|
+
initial: boolean,
|
|
318
|
+
onExit: () => void,
|
|
319
|
+
options: PresenceOptions = {},
|
|
320
|
+
) {
|
|
321
|
+
let present = initial,
|
|
322
|
+
enter = snapshot(options.enter ?? 'fadeIn'),
|
|
323
|
+
leave = snapshot(options.leave ?? 'fadeOut')
|
|
324
|
+
let pending = true,
|
|
325
|
+
entered = false,
|
|
326
|
+
epoch = 0,
|
|
327
|
+
exiting = false
|
|
328
|
+
let restore: (() => void) | undefined
|
|
329
|
+
const binding = owner(node, options, (connected) => {
|
|
330
|
+
if (connected) run()
|
|
331
|
+
else {
|
|
332
|
+
epoch++
|
|
333
|
+
pending = true
|
|
334
|
+
}
|
|
335
|
+
})
|
|
336
|
+
function accessibility() {
|
|
337
|
+
if (!present && !exiting) {
|
|
338
|
+
const hidden = node.getAttribute('aria-hidden'),
|
|
339
|
+
inert = node.inert
|
|
340
|
+
node.setAttribute('aria-hidden', 'true')
|
|
341
|
+
node.inert = true
|
|
342
|
+
restore = () => {
|
|
343
|
+
if (hidden === null) node.removeAttribute('aria-hidden')
|
|
344
|
+
else node.setAttribute('aria-hidden', hidden)
|
|
345
|
+
node.inert = inert
|
|
346
|
+
}
|
|
347
|
+
exiting = true
|
|
348
|
+
} else if (present && exiting) {
|
|
349
|
+
restore?.()
|
|
350
|
+
restore = undefined
|
|
351
|
+
exiting = false
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function run() {
|
|
355
|
+
if (binding.disposed || !node.isConnected || !pending) return
|
|
356
|
+
const value = present ? enter : leave
|
|
357
|
+
const input = entered || !present ? fromCurrent(value) : value
|
|
358
|
+
const [definition, transition] = Array.isArray(input) ? input : [input, undefined]
|
|
359
|
+
const animation = binding.scope.animate(
|
|
360
|
+
node,
|
|
361
|
+
definition as string | Keyframes,
|
|
362
|
+
transition as AnimateOptions | SpringName | undefined,
|
|
363
|
+
)
|
|
364
|
+
const generation = ++epoch
|
|
365
|
+
pending = false
|
|
366
|
+
entered = true
|
|
367
|
+
accessibility()
|
|
368
|
+
if (!present)
|
|
369
|
+
void animation.finished.then((completed) => {
|
|
370
|
+
if (completed && !binding.disposed && generation === epoch && !present) onExit()
|
|
371
|
+
})
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
run()
|
|
375
|
+
} catch (error) {
|
|
376
|
+
binding.destroy()
|
|
377
|
+
throw error
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
get disposed() {
|
|
381
|
+
return binding.disposed
|
|
382
|
+
},
|
|
383
|
+
update(next: boolean, settings: PresenceOptions = options) {
|
|
384
|
+
if (binding.disposed) return
|
|
385
|
+
const nextEnter = snapshot(settings.enter ?? 'fadeIn'),
|
|
386
|
+
nextLeave = snapshot(settings.leave ?? 'fadeOut')
|
|
387
|
+
if (next === present && same(enter, nextEnter) && same(leave, nextLeave)) return
|
|
388
|
+
const previous = { present, enter, leave }
|
|
389
|
+
present = next
|
|
390
|
+
enter = nextEnter
|
|
391
|
+
leave = nextLeave
|
|
392
|
+
pending = true
|
|
393
|
+
try {
|
|
394
|
+
run()
|
|
395
|
+
} catch (error) {
|
|
396
|
+
;({ present, enter, leave } = previous)
|
|
397
|
+
pending = false
|
|
398
|
+
throw error
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
destroy() {
|
|
402
|
+
epoch++
|
|
403
|
+
restore?.()
|
|
404
|
+
restore = undefined
|
|
405
|
+
binding.destroy()
|
|
406
|
+
},
|
|
407
|
+
}
|
|
408
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { colorCSS } from './properties.js'
|
|
2
|
+
export function linearGradientCSS(
|
|
3
|
+
angle: number,
|
|
4
|
+
colors: readonly number[],
|
|
5
|
+
stops: readonly number[],
|
|
6
|
+
) {
|
|
7
|
+
return `linear-gradient(${angle}deg,${colors.map((color, i) => `${colorCSS(color)} ${stops[i]! * 100}%`).join(',')})`
|
|
8
|
+
}
|