@rafaelaugusto/jolt 0.1.0-rc.13 → 0.1.0-rc.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/README.md +2 -2
  2. package/dist/animate.d.ts +2 -0
  3. package/dist/animate.d.ts.map +1 -1
  4. package/dist/animate.js +4 -4
  5. package/dist/animate.js.map +1 -1
  6. package/dist/core/drop.d.ts +34 -1
  7. package/dist/core/drop.d.ts.map +1 -1
  8. package/dist/core/drop.js +93 -8
  9. package/dist/core/drop.js.map +1 -1
  10. package/dist/core/layout-exit.d.ts +16 -0
  11. package/dist/core/layout-exit.d.ts.map +1 -0
  12. package/dist/core/layout-exit.js +29 -0
  13. package/dist/core/layout-exit.js.map +1 -0
  14. package/dist/core/list-changes.d.ts +52 -0
  15. package/dist/core/list-changes.d.ts.map +1 -0
  16. package/dist/core/list-changes.js +153 -0
  17. package/dist/core/list-changes.js.map +1 -0
  18. package/dist/core/loading.d.ts +125 -0
  19. package/dist/core/loading.d.ts.map +1 -0
  20. package/dist/core/loading.js +119 -0
  21. package/dist/core/loading.js.map +1 -0
  22. package/dist/core/numeric-map.d.ts +3 -0
  23. package/dist/core/numeric-map.d.ts.map +1 -1
  24. package/dist/core/numeric-map.js +1 -1
  25. package/dist/core/numeric-map.js.map +1 -1
  26. package/dist/core/pointer.d.ts +1 -1
  27. package/dist/core/preset-recipe.d.ts +2 -2
  28. package/dist/core/preset-recipe.d.ts.map +1 -1
  29. package/dist/core/preset-recipe.js +3 -1
  30. package/dist/core/preset-recipe.js.map +1 -1
  31. package/dist/core/scalar-program.d.ts +22 -0
  32. package/dist/core/scalar-program.d.ts.map +1 -0
  33. package/dist/core/scalar-program.js +47 -0
  34. package/dist/core/scalar-program.js.map +1 -0
  35. package/dist/core/scalar.d.ts +25 -0
  36. package/dist/core/scalar.d.ts.map +1 -0
  37. package/dist/core/scalar.js +84 -0
  38. package/dist/core/scalar.js.map +1 -0
  39. package/dist/core/text-pieces.d.ts +18 -0
  40. package/dist/core/text-pieces.d.ts.map +1 -0
  41. package/dist/core/text-pieces.js +43 -0
  42. package/dist/core/text-pieces.js.map +1 -0
  43. package/dist/drag.d.ts +7 -1
  44. package/dist/drag.d.ts.map +1 -1
  45. package/dist/drag.js +72 -37
  46. package/dist/drag.js.map +1 -1
  47. package/dist/drop-zones.d.ts +1 -1
  48. package/dist/drop-zones.d.ts.map +1 -1
  49. package/dist/drop-zones.js +2 -0
  50. package/dist/drop-zones.js.map +1 -1
  51. package/dist/engine.d.ts.map +1 -1
  52. package/dist/engine.js +7 -2
  53. package/dist/engine.js.map +1 -1
  54. package/dist/index.d.ts +4 -2
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +1 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/layout-exit.d.ts +19 -0
  59. package/dist/layout-exit.d.ts.map +1 -0
  60. package/dist/layout-exit.js +105 -0
  61. package/dist/layout-exit.js.map +1 -0
  62. package/dist/layout.d.ts +5 -0
  63. package/dist/layout.d.ts.map +1 -1
  64. package/dist/layout.js +50 -2
  65. package/dist/layout.js.map +1 -1
  66. package/dist/list-changes.d.ts +14 -0
  67. package/dist/list-changes.d.ts.map +1 -0
  68. package/dist/list-changes.js +251 -0
  69. package/dist/list-changes.js.map +1 -0
  70. package/dist/list-focus.d.ts +10 -0
  71. package/dist/list-focus.d.ts.map +1 -0
  72. package/dist/list-focus.js +103 -0
  73. package/dist/list-focus.js.map +1 -0
  74. package/dist/live-spring-driver.d.ts +2 -0
  75. package/dist/live-spring-driver.d.ts.map +1 -1
  76. package/dist/live-spring-driver.js +12 -0
  77. package/dist/live-spring-driver.js.map +1 -1
  78. package/dist/loader.d.ts +2 -1
  79. package/dist/loader.d.ts.map +1 -1
  80. package/dist/loader.js +17 -15
  81. package/dist/loader.js.map +1 -1
  82. package/dist/motion-value.d.ts +52 -19
  83. package/dist/motion-value.d.ts.map +1 -1
  84. package/dist/motion-value.js +615 -40
  85. package/dist/motion-value.js.map +1 -1
  86. package/dist/reveal.d.ts.map +1 -1
  87. package/dist/reveal.js +4 -3
  88. package/dist/reveal.js.map +1 -1
  89. package/dist/scroll-linked.d.ts +2 -1
  90. package/dist/scroll-linked.d.ts.map +1 -1
  91. package/dist/scroll-linked.js +101 -4
  92. package/dist/scroll-linked.js.map +1 -1
  93. package/dist/scroll-source.d.ts +18 -0
  94. package/dist/scroll-source.d.ts.map +1 -0
  95. package/dist/scroll-source.js +28 -0
  96. package/dist/scroll-source.js.map +1 -0
  97. package/dist/shared-layout/native.d.ts +1 -0
  98. package/dist/shared-layout/native.d.ts.map +1 -1
  99. package/dist/shared-layout/native.js +2 -0
  100. package/dist/shared-layout/native.js.map +1 -1
  101. package/dist/shimmer.d.ts.map +1 -1
  102. package/dist/shimmer.js +6 -4
  103. package/dist/shimmer.js.map +1 -1
  104. package/dist/value-track.d.ts +4 -0
  105. package/dist/value-track.d.ts.map +1 -1
  106. package/dist/value-track.js +3 -0
  107. package/dist/value-track.js.map +1 -1
  108. package/dist/vue/index.d.ts +45 -1
  109. package/dist/vue/index.d.ts.map +1 -1
  110. package/dist/vue/index.js +41 -2
  111. package/dist/vue/index.js.map +1 -1
  112. package/dist/web/drag.d.ts +8 -0
  113. package/dist/web/drag.d.ts.map +1 -1
  114. package/dist/web/drag.js +68 -14
  115. package/dist/web/drag.js.map +1 -1
  116. package/dist/web/drop-zones.d.ts +2 -2
  117. package/dist/web/drop-zones.d.ts.map +1 -1
  118. package/dist/web/drop-zones.js +21 -4
  119. package/dist/web/drop-zones.js.map +1 -1
  120. package/dist/web/layout-exit.d.ts +9 -0
  121. package/dist/web/layout-exit.d.ts.map +1 -0
  122. package/dist/web/layout-exit.js +148 -0
  123. package/dist/web/layout-exit.js.map +1 -0
  124. package/dist/web/layout.d.ts +25 -8
  125. package/dist/web/layout.d.ts.map +1 -1
  126. package/dist/web/layout.js +83 -2
  127. package/dist/web/layout.js.map +1 -1
  128. package/dist/web/list-changes.d.ts +41 -0
  129. package/dist/web/list-changes.d.ts.map +1 -0
  130. package/dist/web/list-changes.js +126 -0
  131. package/dist/web/list-changes.js.map +1 -0
  132. package/dist/web/loading.d.ts +2 -1
  133. package/dist/web/loading.d.ts.map +1 -1
  134. package/dist/web/loading.js +19 -15
  135. package/dist/web/loading.js.map +1 -1
  136. package/dist/web/pointer.d.ts +2 -0
  137. package/dist/web/pointer.d.ts.map +1 -1
  138. package/dist/web/pointer.js +13 -0
  139. package/dist/web/pointer.js.map +1 -1
  140. package/dist/web/presentation-copy.d.ts +9 -0
  141. package/dist/web/presentation-copy.d.ts.map +1 -0
  142. package/dist/web/presentation-copy.js +104 -0
  143. package/dist/web/presentation-copy.js.map +1 -0
  144. package/dist/web/public.d.ts +6 -1
  145. package/dist/web/public.d.ts.map +1 -1
  146. package/dist/web/public.js +1 -0
  147. package/dist/web/public.js.map +1 -1
  148. package/dist/web/reveal.d.ts.map +1 -1
  149. package/dist/web/reveal.js +4 -3
  150. package/dist/web/reveal.js.map +1 -1
  151. package/dist/web/runtime.d.ts +7 -7
  152. package/dist/web/runtime.d.ts.map +1 -1
  153. package/dist/web/runtime.js +85 -8
  154. package/dist/web/runtime.js.map +1 -1
  155. package/dist/web/scroll.d.ts +12 -1
  156. package/dist/web/scroll.d.ts.map +1 -1
  157. package/dist/web/scroll.js +25 -0
  158. package/dist/web/scroll.js.map +1 -1
  159. package/dist/web/shared-layout.d.ts.map +1 -1
  160. package/dist/web/shared-layout.js +2 -101
  161. package/dist/web/shared-layout.js.map +1 -1
  162. package/dist/web/spring-value.d.ts +3 -2
  163. package/dist/web/spring-value.d.ts.map +1 -1
  164. package/dist/web/spring-value.js +5 -5
  165. package/dist/web/spring-value.js.map +1 -1
  166. package/dist/web/text-effect.d.ts.map +1 -1
  167. package/dist/web/text-effect.js +10 -16
  168. package/dist/web/text-effect.js.map +1 -1
  169. package/dist/web/value.d.ts +43 -4
  170. package/dist/web/value.d.ts.map +1 -1
  171. package/dist/web/value.js +139 -6
  172. package/dist/web/value.js.map +1 -1
  173. package/dist/web/vue/index.d.ts +49 -2
  174. package/dist/web/vue/index.d.ts.map +1 -1
  175. package/dist/web/vue/index.js +45 -2
  176. package/dist/web/vue/index.js.map +1 -1
  177. package/package.json +13 -3
  178. package/platforms/android/java/org/rafaelaugusto/jolt/LiveSpring.java +52 -6
  179. package/platforms/android/java/org/rafaelaugusto/jolt/PointerInput.java +26 -4
  180. package/platforms/android/java/org/rafaelaugusto/jolt/ScalarProgram.java +76 -0
  181. package/platforms/android/java/org/rafaelaugusto/jolt/ScrollSource.java +86 -0
  182. package/platforms/android/java/org/rafaelaugusto/jolt/SharedLayoutFlight.java +8 -2
  183. package/platforms/ios/src/JoltLiveSpring.h +2 -0
  184. package/platforms/ios/src/JoltLiveSpring.m +52 -6
  185. package/platforms/ios/src/JoltScalarProgram.h +9 -0
  186. package/platforms/ios/src/JoltScalarProgram.m +80 -0
  187. package/platforms/ios/src/JoltScrollSource.h +11 -0
  188. package/platforms/ios/src/JoltScrollSource.m +57 -0
  189. package/platforms/ios/src/JoltSharedLayoutFlight.h +1 -0
  190. package/platforms/ios/src/JoltSharedLayoutFlight.m +7 -1
  191. package/platforms/ios/src/module.modulemap +1 -0
  192. package/src/android-plugin.d.ts +25 -0
  193. package/src/animate.ts +4 -4
  194. package/src/core/drop.ts +123 -5
  195. package/src/core/layout-exit.ts +43 -0
  196. package/src/core/list-changes.ts +206 -0
  197. package/src/core/loading.ts +172 -0
  198. package/src/core/numeric-map.ts +1 -1
  199. package/src/core/preset-recipe.ts +6 -2
  200. package/src/core/scalar-program.ts +69 -0
  201. package/src/core/scalar.ts +125 -0
  202. package/src/core/text-pieces.ts +52 -0
  203. package/src/drag.ts +81 -38
  204. package/src/drop-zones.ts +13 -3
  205. package/src/engine.ts +8 -3
  206. package/src/index.ts +8 -0
  207. package/src/ios-plugin.d.ts +17 -0
  208. package/src/layout-exit.ts +120 -0
  209. package/src/layout.ts +57 -1
  210. package/src/list-changes.ts +317 -0
  211. package/src/list-focus.ts +101 -0
  212. package/src/live-spring-driver.ts +18 -0
  213. package/src/loader.ts +23 -20
  214. package/src/motion-value.ts +689 -50
  215. package/src/reveal.ts +4 -3
  216. package/src/scroll-linked.ts +121 -5
  217. package/src/scroll-source.ts +60 -0
  218. package/src/shared-layout/native.ts +3 -0
  219. package/src/shimmer.ts +6 -4
  220. package/src/value-track.ts +7 -0
  221. package/src/vue/index.ts +51 -0
  222. package/src/web/drag.ts +70 -12
  223. package/src/web/drop-zones.ts +31 -6
  224. package/src/web/layout-exit.ts +179 -0
  225. package/src/web/layout.ts +103 -2
  226. package/src/web/list-changes.ts +194 -0
  227. package/src/web/loading.ts +38 -17
  228. package/src/web/pointer.ts +14 -0
  229. package/src/web/presentation-copy.ts +125 -0
  230. package/src/web/public.ts +17 -0
  231. package/src/web/reveal.ts +7 -8
  232. package/src/web/runtime.ts +116 -9
  233. package/src/web/scroll.ts +41 -0
  234. package/src/web/shared-layout.ts +3 -115
  235. package/src/web/spring-value.ts +7 -6
  236. package/src/web/text-effect.ts +20 -17
  237. package/src/web/value.ts +167 -12
  238. package/src/web/vue/index.ts +51 -0
package/src/reveal.ts CHANGED
@@ -4,6 +4,7 @@ import { resolveEasing } from './easing.js'
4
4
  import type { Animation } from './engine.js'
5
5
  import type { Target } from './types.js'
6
6
  import { reducedMotion } from './config.js'
7
+ import { revealDefinition } from './core/loading.js'
7
8
 
8
9
  export interface RevealOptions {
9
10
  /** Circle origin in DIPs from the target's top-left corner. Defaults to its center. */
@@ -24,18 +25,18 @@ type MaskedView = UIView & { originalMask?: CALayer | null; maskType?: unknown }
24
25
  type Snapshot = { circle: Circle; native: UIView; bounds: CGRect }
25
26
  const running = new WeakMap<View, CircularAnimation>()
26
27
  const callbacks = new WeakMap<NSObject, (finished: boolean) => void>()
27
- const ease = resolveEasing('easeInOut')
28
+ const ease = resolveEasing(revealDefinition.ease)
28
29
  const key = 'jolt:reveal'
29
30
  let Delegate: typeof NSObject | undefined
30
31
 
31
32
  /** Reveals an iOS view through an expanding circle, then removes the temporary mask. */
32
33
  export function reveal(target: Target, options: RevealOptions = {}): Animation {
33
- return start(target, true, options.from, options.duration ?? 400)
34
+ return start(target, true, options.from, options.duration ?? revealDefinition.duration)
34
35
  }
35
36
 
36
37
  /** Contracts an iOS view to a point, then sets visibility to 'hidden' without collapsing layout. */
37
38
  export function conceal(target: Target, options: ConcealOptions = {}): Animation {
38
- return start(target, false, options.to, options.duration ?? 400)
39
+ return start(target, false, options.to, options.duration ?? revealDefinition.duration)
39
40
  }
40
41
 
41
42
  function start(
@@ -1,8 +1,26 @@
1
- import { ScrollView, type EventData, type ScrollEventData } from '@nativescript/core'
2
- import { animate, toView } from './animate.js'
1
+ import {
2
+ scrollValue,
3
+ bind,
4
+ liveValueInput,
5
+ type Bindings,
6
+ type DerivedValue,
7
+ type ScrollValueOptions,
8
+ } from './motion-value.js'
9
+ import { nativeScrollAvailable } from './scroll-source.js'
10
+ import { readValue } from './properties.js'
11
+ import { isColorProperty } from './color.js'
12
+ import { isLivePaint } from './live-paint.js'
13
+ import { onReducedMotion, reducedMotion } from './config.js'
14
+ import {
15
+ Color,
16
+ ScrollView,
17
+ type EventData,
18
+ type ScrollEventData,
19
+ } from '@nativescript/core'
20
+ import { animate, toView, expandKeyframes } from './animate.js'
3
21
  import type { Keyframes, Target } from './types.js'
4
22
 
5
- export interface ScrollLinkedOptions {
23
+ export interface ScrollLinkedOptions extends ScrollValueOptions {
6
24
  /** Scroll offsets in DIPs, mapped to progress 0 and 1. Either order is allowed. */
7
25
  range: readonly [number, number]
8
26
  /** Offset to read. Defaults to the vertical axis. */
@@ -17,8 +35,6 @@ export function scrollLinked(
17
35
  options: ScrollLinkedOptions,
18
36
  ): () => void {
19
37
  const source = toView(scrollView)
20
- if (!(source instanceof ScrollView))
21
- throw new TypeError('scrollLinked requires a NativeScript ScrollView.')
22
38
  const view = toView(target)
23
39
  const range = options?.range
24
40
  if (
@@ -33,6 +49,106 @@ export function scrollLinked(
33
49
  const axis = options.axis ?? 'y'
34
50
  if (axis !== 'x' && axis !== 'y') throw new TypeError('Scroll axis must be "x" or "y".')
35
51
 
52
+ const frames = expandKeyframes(keyframes)
53
+ const eligible =
54
+ !('path' in keyframes) &&
55
+ frames.every(
56
+ ([property]) =>
57
+ [
58
+ 'x',
59
+ 'y',
60
+ 'scaleX',
61
+ 'scaleY',
62
+ 'rotate',
63
+ 'rotateX',
64
+ 'rotateY',
65
+ 'opacity',
66
+ ].includes(property) || isLivePaint(property),
67
+ )
68
+ if (options.execution !== 'javascript' && nativeScrollAvailable() && eligible) {
69
+ const offset = scrollValue(source, {
70
+ axis,
71
+ execution: 'native',
72
+ rowHeight: options.rowHeight,
73
+ })
74
+ let stop: (() => void) | undefined,
75
+ stopDemand: (() => void) | undefined,
76
+ stopReduced: (() => void) | undefined
77
+ let ended = false,
78
+ installing = false,
79
+ demanded = false
80
+ let derived: DerivedValue[] = []
81
+ const cleanup = () => {
82
+ if (ended) return
83
+ ended = true
84
+ stopDemand?.()
85
+ stopReduced?.()
86
+ stop?.()
87
+ for (const value of derived) value.dispose()
88
+ derived = []
89
+ offset.dispose()
90
+ source.off('unloaded', cleanup)
91
+ view.off('unloaded', cleanup)
92
+ view.off('loaded', install)
93
+ }
94
+ const install = () => {
95
+ if (ended || !view.isLoaded) return
96
+ installing = true
97
+ try {
98
+ const bindings: Bindings = {}
99
+ const next: DerivedValue[] = []
100
+ for (const [property, keyframes] of frames) {
101
+ const initial = readValue(view, property)
102
+ let values = keyframes.map((value) => value ?? initial)
103
+ if (reducedMotion() && property !== 'opacity' && !isColorProperty(property))
104
+ values = values.map(() => values.at(-1)!)
105
+ const input = values.map(
106
+ (_, i) => start + ((end - start) * i) / (values.length - 1),
107
+ )
108
+ const value = isColorProperty(property)
109
+ ? offset.to(
110
+ input,
111
+ values.map((value) => new Color(value)),
112
+ )
113
+ : offset.to(input, values)
114
+ ;(bindings as Record<string, unknown>)[property] = value
115
+ next.push(value as DerivedValue)
116
+ }
117
+ const off = bind(view, bindings)
118
+ stop?.()
119
+ for (const value of derived) value.dispose()
120
+ derived = next
121
+ stop = off
122
+ } catch (error) {
123
+ cleanup()
124
+ throw error
125
+ } finally {
126
+ installing = false
127
+ }
128
+ }
129
+ try {
130
+ install()
131
+ stopReduced = onReducedMotion(install)
132
+ stopDemand = liveValueInput(offset).demand((active) => {
133
+ if (active) demanded = true
134
+ else if (demanded && !installing) cleanup()
135
+ })
136
+ source.on('unloaded', cleanup)
137
+ view.on('unloaded', cleanup)
138
+ view.on('loaded', install)
139
+ return cleanup
140
+ } catch (error) {
141
+ cleanup()
142
+ throw error
143
+ }
144
+ }
145
+ if (options.execution === 'native')
146
+ throw new Error(
147
+ 'These scroll tracks need supported native properties and rebuilt Jolt classes.',
148
+ )
149
+ if (!(source instanceof ScrollView))
150
+ throw new TypeError('The JavaScript fallback requires a NativeScript ScrollView.')
151
+
36
152
  const animation = animate(view, keyframes, { duration: 1000, ease: 'linear' })
37
153
  animation.pause()
38
154
  let disposed = false
@@ -0,0 +1,60 @@
1
+ import { isIOS, type View } from '@nativescript/core'
2
+ import { nativeLiveNode, type LiveNode } from './live-spring-driver.js'
3
+
4
+ export interface NativeScrollSource {
5
+ enabled(value: boolean): void
6
+ observe(value: boolean): void
7
+ refresh(): void
8
+ snapshot(): { offset: number; updates: number; callbacks: number }
9
+ dispose(): void
10
+ }
11
+ export type NativeScrollFactory = (
12
+ view: View,
13
+ node: LiveNode,
14
+ axis: 'x' | 'y',
15
+ rowHeight: number,
16
+ changed: () => void,
17
+ ) => NativeScrollSource
18
+ let override: NativeScrollFactory | undefined
19
+ export function setScrollSourceDriver(driver?: NativeScrollFactory) {
20
+ override = driver
21
+ }
22
+ export function nativeScrollAvailable() {
23
+ return (
24
+ !!override ||
25
+ (isIOS
26
+ ? typeof JoltScrollSource !== 'undefined'
27
+ : typeof org !== 'undefined' &&
28
+ typeof org.rafaelaugusto?.jolt?.ScrollSource === 'function')
29
+ )
30
+ }
31
+ export const createNativeScrollSource: NativeScrollFactory = (
32
+ view,
33
+ node,
34
+ axis,
35
+ rowHeight,
36
+ changed,
37
+ ) => {
38
+ if (override) return override(view, node, axis, rowHeight, changed)
39
+ const native = isIOS
40
+ ? JoltScrollSource.attachNodeHorizontalChanged(
41
+ view.nativeViewProtected,
42
+ nativeLiveNode(node) as JoltLiveSpring,
43
+ axis === 'x',
44
+ changed,
45
+ )
46
+ : new org.rafaelaugusto.jolt.ScrollSource(
47
+ view.nativeViewProtected,
48
+ nativeLiveNode(node) as org.rafaelaugusto.jolt.LiveSpring,
49
+ axis === 'x',
50
+ rowHeight,
51
+ new org.rafaelaugusto.jolt.ScrollSource.Listener({ changed }),
52
+ )
53
+ return {
54
+ enabled: (value) => native.setEnabled(value),
55
+ observe: (value) => native.setObserving(value),
56
+ refresh: () => native.refresh(),
57
+ snapshot: () => JSON.parse(native.snapshot()),
58
+ dispose: () => native.dispose(),
59
+ }
60
+ }
@@ -1,6 +1,7 @@
1
1
  import { isIOS, type View } from '@nativescript/core'
2
2
 
3
3
  export interface Flight {
4
+ prepareExit?(): void
4
5
  pixels(): number
5
6
  state(): string
6
7
  prepare(view: View, image: boolean, radius: number, budget: number): string | null
@@ -27,6 +28,7 @@ export function capture(
27
28
  )
28
29
  if (!flight) return
29
30
  return {
31
+ prepareExit: () => flight.prepareExit(),
30
32
  holdPage: (page, budget) =>
31
33
  flight.holdPageMaxPixels(page.nativeViewProtected, budget),
32
34
  fade: (duration, done) => flight.fadeOnEnd(duration, done),
@@ -49,6 +51,7 @@ export function capture(
49
51
  const flight = Native.capture(view.nativeViewProtected, image, radius, budget)
50
52
  if (!flight) return
51
53
  return {
54
+ prepareExit: () => flight.prepareExit(),
52
55
  holdPage: (page, budget) => flight.holdPage(page.nativeViewProtected, budget),
53
56
  fade: (duration, done) =>
54
57
  flight.fade(
package/src/shimmer.ts CHANGED
@@ -2,6 +2,7 @@ import { Application, isIOS, type View } from '@nativescript/core'
2
2
  import { toView } from './animate.js'
3
3
  import type { Target } from './types.js'
4
4
  import { reducedMotion } from './config.js'
5
+ import { shimmerDefinition } from './core/loading.js'
5
6
 
6
7
  export interface ShimmerOptions {
7
8
  /** Milliseconds per sweep. Defaults to 1500. */
@@ -21,7 +22,7 @@ type MaskedView = UIView & { originalMask?: CALayer | null }
21
22
  */
22
23
  export function shimmer(target: Target, options: ShimmerOptions = {}): () => void {
23
24
  const view = toView(target)
24
- const duration = options.duration ?? 1500
25
+ const duration = options.duration ?? shimmerDefinition.duration
25
26
  if (!Number.isFinite(duration) || duration <= 0)
26
27
  throw new RangeError('Shimmer duration must be a positive finite number.')
27
28
  running.get(view)?.()
@@ -138,15 +139,16 @@ class Shimmer {
138
139
 
139
140
  private createGradient(): CAGradientLayer {
140
141
  const gradient = CAGradientLayer.new()
141
- const dim = UIColor.colorWithWhiteAlpha(1, 0.35).CGColor
142
+ const { mask } = shimmerDefinition
143
+ const dim = UIColor.colorWithWhiteAlpha(1, mask.opacity).CGColor
142
144
  gradient.colors = NSArray.arrayWithArray([dim, UIColor.whiteColor.CGColor, dim])
143
145
  gradient.startPoint = CGPointMake(0, 0.5)
144
146
  gradient.endPoint = CGPointMake(1, 0.5)
145
147
 
146
148
  // A three-width mask lets the band enter and leave while every stop stays
147
149
  // within the documented 0...1 range for CAGradientLayer.locations.
148
- const from = NSArray.arrayWithArray([0, 0.125, 0.25])
149
- const to = NSArray.arrayWithArray([0.75, 0.875, 1])
150
+ const from = NSArray.arrayWithArray([...mask.from])
151
+ const to = NSArray.arrayWithArray([...mask.to])
150
152
  gradient.locations = from
151
153
  const animation = CABasicAnimation.animationWithKeyPath('locations')
152
154
  animation.fromValue = from
@@ -15,6 +15,13 @@ export function valueTrack(parts: readonly ValuePart[], rest: number) {
15
15
  sum + part.base + part.span * part.track.valueAt(part.elapsed + time),
16
16
  rest,
17
17
  )
18
+ return sampledValueTrack(parts, value)
19
+ }
20
+
21
+ export function sampledValueTrack(
22
+ parts: readonly Pick<ValuePart, 'track' | 'elapsed'>[],
23
+ value: (time: number) => number,
24
+ ) {
18
25
  const span = compositionSpan(parts)
19
26
  if (!span) return { track: instantTrack('x', value(0)), windowed: false }
20
27
  const { duration, endless, windowed } = span
package/src/vue/index.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  defineComponent,
4
4
  h,
5
5
  onUnmounted,
6
+ onBeforeUpdate,
6
7
  onActivated,
7
8
  onDeactivated,
8
9
  readonly,
@@ -15,6 +16,10 @@ import {
15
16
  type Ref,
16
17
  } from 'nativescript-vue'
17
18
  import {
19
+ animateLayout,
20
+ type LayoutOptions,
21
+ type Animation,
22
+ springs,
18
23
  gradient,
19
24
  press,
20
25
  motionScope,
@@ -40,6 +45,7 @@ import {
40
45
  type GradientOptions,
41
46
  type Transition,
42
47
  } from '../index.js'
48
+ import type { LayoutExit } from '../core/layout-exit.js'
43
49
  import { isDerived } from '../motion-value.js'
44
50
  import { prepareGradient, type GradientValues } from '../gradient.js'
45
51
  import { currentKeyboard } from '../keyboard.js'
@@ -280,12 +286,57 @@ export const JoltTransition = defineComponent({
280
286
  },
281
287
  })
282
288
 
289
+ /** Keyed direct children; fades entrances, snapshots removals, and moves survivors. */
290
+ export const JoltTransitionGroup = defineComponent({
291
+ name: 'JoltTransitionGroup',
292
+ inheritAttrs: false,
293
+ props: {
294
+ tag: { type: String, default: 'StackLayout' },
295
+ enter: { type: Boolean, default: true },
296
+ leave: {
297
+ type: [String, Object, Boolean] as PropType<LayoutExit>,
298
+ default: 'fadeOut',
299
+ },
300
+ move: {
301
+ type: [String, Object] as PropType<SpringName | LayoutOptions>,
302
+ default: 'snappy',
303
+ },
304
+ },
305
+ setup(props, { slots, attrs }) {
306
+ let host: Target | null = null,
307
+ animation: Animation | undefined
308
+ const stop = () => {
309
+ animation?.stop()
310
+ animation = undefined
311
+ }
312
+ onBeforeUpdate(() => {
313
+ if (!host) return
314
+ const move = typeof props.move === 'string' ? springs[props.move] : props.move
315
+ animation = animateLayout(host, { ...move, enter: props.enter, exit: props.leave })
316
+ })
317
+ onDeactivated(stop)
318
+ onUnmounted(stop)
319
+ return () =>
320
+ h(
321
+ props.tag,
322
+ {
323
+ ...attrs,
324
+ ref: (value: unknown) => {
325
+ host = value as Target | null
326
+ },
327
+ },
328
+ slots.default?.(),
329
+ )
330
+ },
331
+ })
332
+
283
333
  /** Registers `v-animate`, `v-press`, `v-gradient` and `JoltTransition` on the app. */
284
334
  export function install(app: App) {
285
335
  app.directive('animate', vAnimate)
286
336
  app.directive('press', vPress)
287
337
  app.directive('gradient', vGradient)
288
338
  app.component('JoltTransition', JoltTransition)
339
+ app.component('JoltTransitionGroup', JoltTransitionGroup)
289
340
  }
290
341
 
291
342
  export default { install }
package/src/web/drag.ts CHANGED
@@ -26,6 +26,8 @@ export interface WebDragOptions {
26
26
  rubberband?: boolean
27
27
  /** Drive a borrowed numeric value instead of the input element's translation. */
28
28
  value?: WebMotionValue
29
+ /** Element inside the dragged element that alone starts the drag; it may be a button. */
30
+ handle?: HTMLElement
29
31
  onStart?: (event: WebDragEvent) => void
30
32
  onMove?: (event: WebDragEvent) => void
31
33
  onRelease?: (event: WebDragRelease) => void
@@ -86,6 +88,7 @@ export function dragOptions(options: WebDragOptions) {
86
88
  'friction',
87
89
  'rubberband',
88
90
  'value',
91
+ 'handle',
89
92
  'onStart',
90
93
  'onMove',
91
94
  'onRelease',
@@ -197,14 +200,42 @@ export function assertDragSpace(target: HTMLElement, baselineIdentity: boolean)
197
200
  }
198
201
  }
199
202
 
203
+ interface DragAdapter {
204
+ shift(delta: DragPoint): void
205
+ beforeRelease?: (moved: boolean) => void
206
+ }
207
+ const adapters = new WeakMap<WebDrag, DragAdapter>()
208
+ /** Internal adapter hook: offset an active contact without moving it under the pointer. */
209
+ export function shiftDrag(drag: WebDrag, delta: DragPoint) {
210
+ adapters.get(drag)?.shift(delta)
211
+ }
212
+ /** Internal adapter hook: inspect the final input before release motion changes values. */
213
+ export function beforeDragRelease(drag: WebDrag, callback: (moved: boolean) => void) {
214
+ const adapter = adapters.get(drag)
215
+ if (adapter) adapter.beforeRelease = callback
216
+ }
217
+ const contains = (target: HTMLElement, handle: HTMLElement) => {
218
+ for (const node of renderedAncestors(handle))
219
+ if (node === target) return handle !== target
220
+ return false
221
+ }
222
+
200
223
  export function createDrag(target: HTMLElement, input: WebDragOptions, host: DragHost) {
201
224
  const options = dragOptions(input)
202
225
  const document = target.ownerDocument
203
226
  const view = document.defaultView! as Window & typeof globalThis
227
+ const handle = options.handle ?? target
228
+ if (
229
+ options.handle !== undefined &&
230
+ (!(handle instanceof view.HTMLElement) ||
231
+ handle.ownerDocument !== document ||
232
+ !contains(target, handle))
233
+ )
234
+ throw new TypeError('A drag handle must be an element inside the dragged element.')
204
235
  const abort = new view.AbortController()
205
- const originalTouch = target.style.touchAction
236
+ const originalTouch = handle.style.touchAction
206
237
  const touch = options.axis === 'x' ? 'pan-y' : options.axis === 'y' ? 'pan-x' : 'none'
207
- target.style.touchAction = touch
238
+ handle.style.touchAction = touch
208
239
  let pointer: number | undefined,
209
240
  disabled = options.disabled ?? false,
210
241
  disposed = false,
@@ -251,10 +282,11 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
251
282
  disposed ||
252
283
  !target.isConnected ||
253
284
  target.ownerDocument !== document ||
254
- target.matches(':disabled')
285
+ target.matches(':disabled') ||
286
+ (handle !== target && (handle.matches(':disabled') || !contains(target, handle)))
255
287
  )
256
288
  return true
257
- for (const node of renderedAncestors(target)) {
289
+ for (const node of renderedAncestors(handle)) {
258
290
  if (
259
291
  node.hasAttribute('inert') ||
260
292
  node.getAttribute('aria-disabled') === 'true' ||
@@ -285,7 +317,7 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
285
317
  notify('onMove', velocity(samples.at(-1)?.time ?? 0))
286
318
  }
287
319
  const releaseCapture = (id: number) => {
288
- if (target.hasPointerCapture(id)) target.releasePointerCapture(id)
320
+ if (handle.hasPointerCapture(id)) handle.releasePointerCapture(id)
289
321
  }
290
322
  const stopRelease = () => {
291
323
  const current = animation
@@ -363,7 +395,7 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
363
395
  passive,
364
396
  capture: captureEvent,
365
397
  })
366
- listen(target, 'pointerdown', (event: PointerEvent) => {
398
+ listen(handle, 'pointerdown', (event: PointerEvent) => {
367
399
  if (
368
400
  disposed ||
369
401
  pointer !== undefined ||
@@ -374,7 +406,7 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
374
406
  )
375
407
  return
376
408
  for (const node of event.composedPath()) {
377
- if (node === target) break
409
+ if (node === handle) break
378
410
  if (
379
411
  node instanceof view.Element &&
380
412
  node.matches(
@@ -404,7 +436,7 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
404
436
  samples = []
405
437
  capture(event)
406
438
  try {
407
- target.setPointerCapture(pointer)
439
+ handle.setPointerCapture(pointer)
408
440
  notify('onStart')
409
441
  } catch (error) {
410
442
  cancel()
@@ -436,6 +468,15 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
436
468
  capture(event)
437
469
  flush()
438
470
  if (pointer === undefined) return
471
+ const hook = adapter.beforeRelease
472
+ if (hook) {
473
+ try {
474
+ hook(moved)
475
+ } catch (error) {
476
+ host.error(error)
477
+ }
478
+ if (pointer === undefined) return
479
+ }
439
480
  const p = position(),
440
481
  id = pointer
441
482
  pointer = undefined
@@ -494,7 +535,7 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
494
535
  }
495
536
  watchRoot()
496
537
  listen(
497
- target,
538
+ handle,
498
539
  'dragstart',
499
540
  (event) => {
500
541
  if (pointer !== undefined) event.preventDefault()
@@ -502,7 +543,7 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
502
543
  false,
503
544
  )
504
545
  listen(
505
- target,
546
+ handle,
506
547
  'click',
507
548
  (event: MouseEvent) => {
508
549
  if (event.detail > 0 && view.performance.now() < suppressUntil) {
@@ -525,10 +566,25 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
525
566
  scrollRoot = undefined
526
567
  if (stopAnimation && target.isConnected && target.ownerDocument === document)
527
568
  animation?.stop()
528
- if (target.style.touchAction === touch) target.style.touchAction = originalTouch
569
+ if (handle.style.touchAction === touch) handle.style.touchAction = originalTouch
529
570
  host.dispose()
530
571
  }
531
- return {
572
+ const adapter: DragAdapter = {
573
+ shift: (delta) => shift(delta),
574
+ }
575
+ const shift = (delta: DragPoint) => {
576
+ if (pointer === undefined || disposed) return
577
+ const before = position()
578
+ origin = { x: origin.x + delta.x, y: origin.y + delta.y }
579
+ const after = position()
580
+ samples = samples.map((sample) => ({
581
+ ...sample,
582
+ x: sample.x + after.x - before.x,
583
+ y: sample.y + after.y - before.y,
584
+ }))
585
+ host.write(after, velocity(samples.at(-1)?.time ?? 0))
586
+ }
587
+ const controller = {
532
588
  handle: {
533
589
  get dragging() {
534
590
  return pointer !== undefined
@@ -580,4 +636,6 @@ export function createDrag(target: HTMLElement, input: WebDragOptions, host: Dra
580
636
  },
581
637
  detach: () => dispose(!!options.value),
582
638
  }
639
+ adapters.set(controller.handle, adapter)
640
+ return controller
583
641
  }
@@ -1,7 +1,20 @@
1
1
  import { createDropPolicy, type DropOptions, type DropZones } from '../core/drop.js'
2
- import type { WebDrag, WebDragOptions } from './drag.js'
2
+ import {
3
+ beforeDragRelease,
4
+ shiftDrag,
5
+ type WebDrag,
6
+ type WebDragOptions,
7
+ } from './drag.js'
3
8
  import { inputBlocked, inputEvents, type InteractionHost } from './interaction.js'
4
- export type { DropEvent, DropTarget, DropZones, DropEffect } from '../core/drop.js'
9
+ export type {
10
+ DropEvent,
11
+ DropMoveEvent,
12
+ DropPadding,
13
+ DropRect,
14
+ DropTarget,
15
+ DropZones,
16
+ DropEffect,
17
+ } from '../core/drop.js'
5
18
  export interface WebDropZoneOptions extends DropOptions<HTMLElement> {
6
19
  drag?: Omit<
7
20
  WebDragOptions,
@@ -46,6 +59,12 @@ export function createDropZones(
46
59
  enabled: () => !document.hidden && !inputOptions.disabled,
47
60
  cancelDrag: cancelInput,
48
61
  error: host.error,
62
+ translation: () => input?.position ?? { x: 0, y: 0 },
63
+ shift: (x, y) => {
64
+ if (!input) return
65
+ shiftDrag(input, { x, y })
66
+ flushSource()
67
+ },
49
68
  })
50
69
  const releases: (() => void)[] = []
51
70
  const controller: DropZones = {
@@ -65,7 +84,11 @@ export function createDropZones(
65
84
  return policy.handle.disposed
66
85
  },
67
86
  request: (id) => policy.handle.request(id),
68
- refresh: () => policy.handle.refresh(),
87
+ refresh: () => {
88
+ // Measure the painted translation, not a newer unrendered input sample.
89
+ if (policy.handle.dragging) flushSource()
90
+ policy.handle.refresh()
91
+ },
69
92
  cancel() {
70
93
  try {
71
94
  policy.handle.cancel()
@@ -104,13 +127,15 @@ export function createDropZones(
104
127
  flushSource()
105
128
  policy.move()
106
129
  },
107
- onRelease: () => {
108
- policy.release()
109
- },
110
130
  onCancel: () => {
111
131
  if (!handoff) policy.handle.cancel()
112
132
  },
113
133
  })
134
+ // Commit before the return motion starts; reduced motion would settle it at once.
135
+ beforeDragRelease(input, (moved) => {
136
+ if (moved) policy.release()
137
+ else policy.handle.cancel()
138
+ })
114
139
  releases.push(host.register(source, controller, controller.refresh))
115
140
  // A removed accepting target cancels its owned effect.
116
141
  for (const entry of options.targets)