@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,111 @@
|
|
|
1
|
+
import { presets } from './presets.js'
|
|
2
|
+
import type { Transition } from './transition.js'
|
|
3
|
+
|
|
4
|
+
/** The finite two-endpoint recipes supported by all three execution adapters. */
|
|
5
|
+
export type PortablePresetName =
|
|
6
|
+
| 'fadeIn'
|
|
7
|
+
| 'fadeInUp'
|
|
8
|
+
| 'fadeInDown'
|
|
9
|
+
| 'fadeInLeft'
|
|
10
|
+
| 'fadeInRight'
|
|
11
|
+
| 'zoomIn'
|
|
12
|
+
| 'popIn'
|
|
13
|
+
| 'fadeOut'
|
|
14
|
+
| 'fadeOutUp'
|
|
15
|
+
| 'fadeOutDown'
|
|
16
|
+
| 'fadeOutLeft'
|
|
17
|
+
| 'fadeOutRight'
|
|
18
|
+
| 'zoomOut'
|
|
19
|
+
export interface PresetParameters {
|
|
20
|
+
/** Points on Apple, DIP in NativeScript, CSS pixels on Web. */
|
|
21
|
+
distance?: number
|
|
22
|
+
scale?: number
|
|
23
|
+
direction?: 'up' | 'down' | 'left' | 'right'
|
|
24
|
+
/** Override all channels with a finite tween in milliseconds (including zero). */
|
|
25
|
+
duration?: number
|
|
26
|
+
}
|
|
27
|
+
type Channel = 'x' | 'y' | 'scale' | 'opacity'
|
|
28
|
+
export interface PresetRecipe {
|
|
29
|
+
keyframes: Partial<Record<Channel, number | readonly number[]>>
|
|
30
|
+
transition: Transition & Partial<Record<Channel, Transition>>
|
|
31
|
+
}
|
|
32
|
+
const names = new Set<string>([
|
|
33
|
+
'fadeIn',
|
|
34
|
+
'fadeInUp',
|
|
35
|
+
'fadeInDown',
|
|
36
|
+
'fadeInLeft',
|
|
37
|
+
'fadeInRight',
|
|
38
|
+
'zoomIn',
|
|
39
|
+
'popIn',
|
|
40
|
+
'fadeOut',
|
|
41
|
+
'fadeOutUp',
|
|
42
|
+
'fadeOutDown',
|
|
43
|
+
'fadeOutLeft',
|
|
44
|
+
'fadeOutRight',
|
|
45
|
+
'zoomOut',
|
|
46
|
+
])
|
|
47
|
+
|
|
48
|
+
/** Pure recipe construction; registration and resource ownership stay in the runtime. */
|
|
49
|
+
export function createPreset(
|
|
50
|
+
name: PortablePresetName,
|
|
51
|
+
parameters: PresetParameters = {},
|
|
52
|
+
): PresetRecipe {
|
|
53
|
+
if (!names.has(name)) throw new TypeError('Expected a portable finite preset name.')
|
|
54
|
+
if (!parameters || typeof parameters !== 'object' || Array.isArray(parameters))
|
|
55
|
+
throw new TypeError('Preset parameters must be an object.')
|
|
56
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
57
|
+
if (!['distance', 'scale', 'direction', 'duration'].includes(key))
|
|
58
|
+
throw new TypeError(`Unknown preset parameter "${key}".`)
|
|
59
|
+
if (value === undefined) continue
|
|
60
|
+
if (key === 'direction') {
|
|
61
|
+
if (!['up', 'down', 'left', 'right'].includes(value as string))
|
|
62
|
+
throw new TypeError('Invalid preset direction.')
|
|
63
|
+
} else if (
|
|
64
|
+
typeof value !== 'number' ||
|
|
65
|
+
!Number.isFinite(value) ||
|
|
66
|
+
value < 0 ||
|
|
67
|
+
value > (key === 'duration' ? 60_000 : key === 'scale' ? 100 : 1_000_000)
|
|
68
|
+
)
|
|
69
|
+
throw new RangeError(`Invalid preset ${key}.`)
|
|
70
|
+
}
|
|
71
|
+
const original = presets[name] as PresetRecipe
|
|
72
|
+
const keyframes = Object.fromEntries(
|
|
73
|
+
Object.entries(original.keyframes).map(([key, value]) => [
|
|
74
|
+
key,
|
|
75
|
+
Array.isArray(value) ? [...value] : value,
|
|
76
|
+
]),
|
|
77
|
+
) as PresetRecipe['keyframes']
|
|
78
|
+
const transition = { ...original.transition } as PresetRecipe['transition']
|
|
79
|
+
for (const channel of ['x', 'y', 'scale', 'opacity'] as const)
|
|
80
|
+
if (transition[channel]) transition[channel] = { ...transition[channel] }
|
|
81
|
+
const entering = !name.includes('Out')
|
|
82
|
+
const direction = parameters.direction
|
|
83
|
+
if (direction) {
|
|
84
|
+
delete keyframes.x
|
|
85
|
+
delete keyframes.y
|
|
86
|
+
const horizontal = direction === 'left' || direction === 'right'
|
|
87
|
+
const sign = direction === 'left' || direction === 'up' ? -1 : 1
|
|
88
|
+
const amount = (parameters.distance ?? 24) * sign * (!horizontal && entering ? -1 : 1)
|
|
89
|
+
keyframes[horizontal ? 'x' : 'y'] = entering ? [amount, 0] : amount
|
|
90
|
+
} else if (parameters.distance !== undefined) {
|
|
91
|
+
for (const channel of ['x', 'y'] as const) {
|
|
92
|
+
const value = keyframes[channel]
|
|
93
|
+
if (typeof value === 'number')
|
|
94
|
+
keyframes[channel] = Math.sign(value) * parameters.distance
|
|
95
|
+
else if (value)
|
|
96
|
+
keyframes[channel] = value.map((n) => Math.sign(n) * parameters.distance!)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (parameters.scale !== undefined)
|
|
100
|
+
keyframes.scale = entering ? [parameters.scale, 1] : parameters.scale
|
|
101
|
+
if (parameters.duration !== undefined)
|
|
102
|
+
return {
|
|
103
|
+
keyframes,
|
|
104
|
+
transition: {
|
|
105
|
+
type: 'tween',
|
|
106
|
+
duration: parameters.duration,
|
|
107
|
+
ease: entering ? 'easeOut' : 'easeIn',
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
return { keyframes, transition }
|
|
111
|
+
}
|
package/src/core/reorder.ts
CHANGED
|
@@ -51,3 +51,26 @@ export function moveAt<K extends ReorderKey>(
|
|
|
51
51
|
toIndex,
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
/** Destination in a measured, realized layout. The caller supplies the dragged row's center. */
|
|
56
|
+
export function reorderDestination(
|
|
57
|
+
rows: readonly { start: number; size: number }[],
|
|
58
|
+
from: number,
|
|
59
|
+
center: number,
|
|
60
|
+
): number | undefined {
|
|
61
|
+
if (
|
|
62
|
+
!Number.isInteger(from) ||
|
|
63
|
+
from < 0 ||
|
|
64
|
+
from >= rows.length ||
|
|
65
|
+
!Number.isFinite(center)
|
|
66
|
+
)
|
|
67
|
+
return undefined
|
|
68
|
+
let destination = 0
|
|
69
|
+
for (let i = 0; i < rows.length; i++) {
|
|
70
|
+
const row = rows[i]!
|
|
71
|
+
if (!Number.isFinite(row.start) || !Number.isFinite(row.size) || row.size < 0)
|
|
72
|
+
return undefined
|
|
73
|
+
if (i !== from && center > row.start + row.size / 2) destination++
|
|
74
|
+
}
|
|
75
|
+
return destination
|
|
76
|
+
}
|
package/src/core/rig.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { Track } from './track.js'
|
|
2
|
+
export const rigChannels = ['x', 'y', 'scaleX', 'scaleY', 'rotate'] as const
|
|
3
|
+
export type RigChannel = (typeof rigChannels)[number]
|
|
4
|
+
export type RigTransform = Partial<Record<RigChannel, number>>
|
|
5
|
+
export interface RigPart {
|
|
6
|
+
parent?: string
|
|
7
|
+
/** Fractions of the part's border-box size. */
|
|
8
|
+
pivot?: { x: number; y: number }
|
|
9
|
+
rest?: RigTransform
|
|
10
|
+
/** Degrees; the entire sampled rotation, including spring overshoot, is bounded. */
|
|
11
|
+
rotation?: readonly [number, number]
|
|
12
|
+
}
|
|
13
|
+
export interface RigSocket {
|
|
14
|
+
part: string
|
|
15
|
+
/** Local logical units (native DIPs / CSS pixels), or fractions when relative. */
|
|
16
|
+
x: number
|
|
17
|
+
y: number
|
|
18
|
+
units?: 'dip' | 'relative'
|
|
19
|
+
}
|
|
20
|
+
export interface RigDefinition {
|
|
21
|
+
parts: Record<string, RigPart>
|
|
22
|
+
poses: Record<string, Record<string, RigTransform>>
|
|
23
|
+
sockets?: Record<string, RigSocket>
|
|
24
|
+
}
|
|
25
|
+
const finite = (n: unknown): n is number => typeof n === 'number' && Number.isFinite(n)
|
|
26
|
+
export const shortestRigAngle = (angle: number) =>
|
|
27
|
+
((((angle + 180) % 360) + 360) % 360) - 180
|
|
28
|
+
export interface RigPoseLayer {
|
|
29
|
+
pose: Record<string, RigTransform>
|
|
30
|
+
weight: number
|
|
31
|
+
}
|
|
32
|
+
export function resolveRigDefinition(definition: RigDefinition) {
|
|
33
|
+
const parts = new Map(
|
|
34
|
+
Object.entries(definition.parts).map(([name, part]) => [
|
|
35
|
+
name,
|
|
36
|
+
{
|
|
37
|
+
...part,
|
|
38
|
+
pivot: part.pivot && { ...part.pivot },
|
|
39
|
+
rest: { ...part.rest },
|
|
40
|
+
rotation: part.rotation && ([...part.rotation] as [number, number]),
|
|
41
|
+
},
|
|
42
|
+
]),
|
|
43
|
+
)
|
|
44
|
+
if (!parts.size || parts.size > 64) throw new RangeError('A rig supports 1..64 parts.')
|
|
45
|
+
const validateTransform = (values: RigTransform) => {
|
|
46
|
+
for (const [key, value] of Object.entries(values))
|
|
47
|
+
if (!rigChannels.includes(key as RigChannel) || !finite(value))
|
|
48
|
+
throw new TypeError('Invalid rig transform.')
|
|
49
|
+
}
|
|
50
|
+
const used = new Map<string, Set<RigChannel>>()
|
|
51
|
+
for (const [name, part] of parts) {
|
|
52
|
+
validateTransform(part.rest)
|
|
53
|
+
used.set(name, new Set(Object.keys(part.rest) as RigChannel[]))
|
|
54
|
+
if (part.pivot && (!finite(part.pivot.x) || !finite(part.pivot.y)))
|
|
55
|
+
throw new TypeError('Invalid rig pivot.')
|
|
56
|
+
if (
|
|
57
|
+
part.rotation &&
|
|
58
|
+
(part.rotation.length !== 2 ||
|
|
59
|
+
!part.rotation.every(finite) ||
|
|
60
|
+
part.rotation[0] > part.rotation[1])
|
|
61
|
+
)
|
|
62
|
+
throw new TypeError('Invalid rotation limits.')
|
|
63
|
+
const visited = new Set([name])
|
|
64
|
+
let parent = part.parent
|
|
65
|
+
while (parent !== undefined) {
|
|
66
|
+
if (!parts.has(parent) || visited.has(parent))
|
|
67
|
+
throw new TypeError('Rig hierarchy contains a cycle or missing parent.')
|
|
68
|
+
visited.add(parent)
|
|
69
|
+
parent = parts.get(parent)!.parent
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const poses = new Map(
|
|
73
|
+
Object.entries(definition.poses).map(([name, pose]) => [
|
|
74
|
+
name,
|
|
75
|
+
Object.fromEntries(
|
|
76
|
+
Object.entries(pose).map(([part, values]) => {
|
|
77
|
+
if (!parts.has(part)) throw new TypeError(`Unknown rig part "${part}".`)
|
|
78
|
+
validateTransform(values)
|
|
79
|
+
Object.keys(values).forEach((key) => used.get(part)!.add(key as RigChannel))
|
|
80
|
+
return [part, { ...values }]
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
]),
|
|
84
|
+
)
|
|
85
|
+
const sockets = new Map(
|
|
86
|
+
Object.entries(definition.sockets ?? {}).map(([name, socket]) => {
|
|
87
|
+
if (
|
|
88
|
+
!parts.has(socket.part) ||
|
|
89
|
+
!finite(socket.x) ||
|
|
90
|
+
!finite(socket.y) ||
|
|
91
|
+
(socket.units !== undefined && !['dip', 'relative'].includes(socket.units))
|
|
92
|
+
)
|
|
93
|
+
throw new TypeError('Invalid rig socket.')
|
|
94
|
+
return [name, { ...socket }]
|
|
95
|
+
}),
|
|
96
|
+
)
|
|
97
|
+
const select = (
|
|
98
|
+
layers: readonly { pose: string; weight: number }[],
|
|
99
|
+
): RigPoseLayer[] => {
|
|
100
|
+
return layers.map((layer) => {
|
|
101
|
+
if (!finite(layer.weight) || layer.weight < 0 || !poses.has(layer.pose))
|
|
102
|
+
throw new TypeError('Unknown pose or invalid blend weight.')
|
|
103
|
+
return { pose: poses.get(layer.pose)!, weight: layer.weight }
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
return { parts, poses, sockets, used, select }
|
|
107
|
+
}
|
|
108
|
+
export function rigDestination(
|
|
109
|
+
part: RigPart,
|
|
110
|
+
name: string,
|
|
111
|
+
property: RigChannel,
|
|
112
|
+
rest: number,
|
|
113
|
+
current: number,
|
|
114
|
+
selected: readonly RigPoseLayer[],
|
|
115
|
+
) {
|
|
116
|
+
let total = 0,
|
|
117
|
+
offset = 0
|
|
118
|
+
for (const layer of selected) {
|
|
119
|
+
const value = layer.pose[name]?.[property]
|
|
120
|
+
if (value === undefined) continue
|
|
121
|
+
total += layer.weight
|
|
122
|
+
offset +=
|
|
123
|
+
(property === 'rotate' && !part.rotation
|
|
124
|
+
? shortestRigAngle(value - rest)
|
|
125
|
+
: value - rest) * layer.weight
|
|
126
|
+
}
|
|
127
|
+
const destination = rest + offset / Math.max(1, total)
|
|
128
|
+
return property === 'rotate' && !part.rotation
|
|
129
|
+
? current + shortestRigAngle(destination - current)
|
|
130
|
+
: destination
|
|
131
|
+
}
|
|
132
|
+
export function limitRigTrack(
|
|
133
|
+
original: Track,
|
|
134
|
+
limits?: readonly [number, number],
|
|
135
|
+
): Track {
|
|
136
|
+
if (!limits) return original
|
|
137
|
+
const [min, max] = limits,
|
|
138
|
+
clamp = (value: number) => Math.max(min, Math.min(max, value))
|
|
139
|
+
return {
|
|
140
|
+
...original,
|
|
141
|
+
values: original.values.map(clamp),
|
|
142
|
+
to: clamp(original.to),
|
|
143
|
+
valueAt: (time) => clamp(original.valueAt(time)),
|
|
144
|
+
velocityAt: (time) =>
|
|
145
|
+
original.valueAt(time) <= min || original.valueAt(time) >= max
|
|
146
|
+
? 0
|
|
147
|
+
: original.velocityAt(time),
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { sensorKinds, type SensorKind } from './sensor-kinds.js'
|
|
2
|
+
|
|
3
|
+
/** Canonical, explicitly synthetic input; timestamps are relative milliseconds. */
|
|
4
|
+
export interface SensorSample {
|
|
5
|
+
time: number
|
|
6
|
+
/** Quaternion xyzw for rotation; canonical device-coordinate xyz for vectors. */
|
|
7
|
+
values: readonly number[]
|
|
8
|
+
orientation?: 0 | 90 | 180 | 270
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function validateSensorSamples(
|
|
12
|
+
kind: SensorKind,
|
|
13
|
+
samples: readonly SensorSample[],
|
|
14
|
+
): SensorSample[] {
|
|
15
|
+
if (!sensorKinds.includes(kind)) throw new TypeError('Unknown sensor kind.')
|
|
16
|
+
if (!Array.isArray(samples) || samples.length < 2 || samples.length > 10000)
|
|
17
|
+
throw new RangeError('Use 2–10000 sensor samples.')
|
|
18
|
+
let previous = -1
|
|
19
|
+
return samples.map((sample) => {
|
|
20
|
+
if (
|
|
21
|
+
!sample ||
|
|
22
|
+
!Number.isFinite(sample.time) ||
|
|
23
|
+
sample.time <= previous ||
|
|
24
|
+
sample.time > 60000 ||
|
|
25
|
+
sample.time < 0
|
|
26
|
+
)
|
|
27
|
+
throw new RangeError('Sensor times must increase within 0–60000 milliseconds.')
|
|
28
|
+
previous = sample.time
|
|
29
|
+
if (
|
|
30
|
+
!Array.isArray(sample.values) ||
|
|
31
|
+
sample.values.length !== (kind === 'rotation' ? 4 : 3) ||
|
|
32
|
+
sample.values.some((v: number) => !Number.isFinite(v))
|
|
33
|
+
)
|
|
34
|
+
throw new TypeError('Invalid canonical sensor sample.')
|
|
35
|
+
if (kind === 'rotation' && Math.hypot(...sample.values) < 1e-8)
|
|
36
|
+
throw new RangeError('A quaternion cannot be zero.')
|
|
37
|
+
if (
|
|
38
|
+
sample.orientation !== undefined &&
|
|
39
|
+
![0, 90, 180, 270].includes(sample.orientation)
|
|
40
|
+
)
|
|
41
|
+
throw new RangeError('Invalid interface orientation.')
|
|
42
|
+
return {
|
|
43
|
+
time: sample.time,
|
|
44
|
+
values: [...sample.values],
|
|
45
|
+
...(sample.orientation === undefined ? {} : { orientation: sample.orientation }),
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveGradientText,
|
|
3
|
+
type GradientTextDefinition,
|
|
4
|
+
} from '../core/gradient-text.js'
|
|
1
5
|
import { Application, Label } from '@nativescript/core'
|
|
2
6
|
import { toView } from '../animate.js'
|
|
3
7
|
import { parseColor, type ColorValue } from '../color.js'
|
|
@@ -7,15 +11,9 @@ import { createTrack } from '../track.js'
|
|
|
7
11
|
import { resolveTransition, type Transition } from '../transition.js'
|
|
8
12
|
import type { Target } from '../types.js'
|
|
9
13
|
import type { PlaybackAnimation } from '../playback.js'
|
|
10
|
-
import { createTextPainter, type
|
|
14
|
+
import { createTextPainter, type TextPainter } from './native.js'
|
|
11
15
|
|
|
12
|
-
export interface GradientTextOptions {
|
|
13
|
-
colors: readonly ColorValue[]
|
|
14
|
-
stops?: readonly number[]
|
|
15
|
-
/** Degrees clockwise from left-to-right; default 0. */
|
|
16
|
-
angle?: number
|
|
17
|
-
sheen?: { color?: ColorValue; width?: number; direction?: 'left' | 'right' }
|
|
18
|
-
}
|
|
16
|
+
export interface GradientTextOptions extends GradientTextDefinition<ColorValue> {}
|
|
19
17
|
export interface GradientText {
|
|
20
18
|
readonly disposed: boolean
|
|
21
19
|
readonly suspended: boolean
|
|
@@ -51,41 +49,7 @@ export function gradientText(target: Target, options: GradientTextOptions): Grad
|
|
|
51
49
|
if (view.formattedText)
|
|
52
50
|
throw new TypeError('gradientText does not support formattedText spans.')
|
|
53
51
|
if (owners.has(view)) throw new Error('This label already owns gradient text.')
|
|
54
|
-
|
|
55
|
-
!Array.isArray(options.colors) ||
|
|
56
|
-
options.colors.length < 2 ||
|
|
57
|
-
options.colors.length > 8
|
|
58
|
-
)
|
|
59
|
-
throw new TypeError('Gradient text needs 2..8 colors.')
|
|
60
|
-
const colors = options.colors.map(parseColor),
|
|
61
|
-
stops = options.stops
|
|
62
|
-
? [...options.stops]
|
|
63
|
-
: colors.map((_, i) => i / (colors.length - 1))
|
|
64
|
-
if (
|
|
65
|
-
stops.length !== colors.length ||
|
|
66
|
-
stops.some(
|
|
67
|
-
(stop, i) =>
|
|
68
|
-
!Number.isFinite(stop) || stop < 0 || stop > 1 || (i > 0 && stop < stops[i - 1]!),
|
|
69
|
-
)
|
|
70
|
-
)
|
|
71
|
-
throw new TypeError('Gradient stops must be ordered in 0..1 and match colors.')
|
|
72
|
-
const paint: TextPaint = {
|
|
73
|
-
colors,
|
|
74
|
-
stops,
|
|
75
|
-
angle: options.angle ?? 0,
|
|
76
|
-
sheen: parseColor(options.sheen?.color ?? '#BFFFFFFF'),
|
|
77
|
-
width: options.sheen?.width ?? 0.3,
|
|
78
|
-
}
|
|
79
|
-
const direction = options.sheen?.direction ?? 'right'
|
|
80
|
-
if (direction !== 'left' && direction !== 'right')
|
|
81
|
-
throw new TypeError('Invalid text sheen direction.')
|
|
82
|
-
if (
|
|
83
|
-
!Number.isFinite(paint.angle) ||
|
|
84
|
-
!Number.isFinite(paint.width) ||
|
|
85
|
-
paint.width <= 0 ||
|
|
86
|
-
paint.width > 1
|
|
87
|
-
)
|
|
88
|
-
throw new TypeError('Invalid text gradient angle or sheen width.')
|
|
52
|
+
const { paint, direction } = resolveGradientText(options, parseColor)
|
|
89
53
|
let disposed = false,
|
|
90
54
|
suspended = false,
|
|
91
55
|
background = Application.suspended,
|
|
@@ -2,13 +2,8 @@ import { isAndroid, type Label } from '@nativescript/core'
|
|
|
2
2
|
import type { Track } from '../track.js'
|
|
3
3
|
import { iosGradientText } from './ios.js'
|
|
4
4
|
import { androidGradientText } from './android.js'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
stops: number[]
|
|
8
|
-
angle: number
|
|
9
|
-
sheen: number
|
|
10
|
-
width: number
|
|
11
|
-
}
|
|
5
|
+
import type { TextPaint } from '../core/gradient-text.js'
|
|
6
|
+
export type { TextPaint } from '../core/gradient-text.js'
|
|
12
7
|
export interface TextPainter {
|
|
13
8
|
refresh(): void
|
|
14
9
|
play(track: Track): void
|
package/src/index.ts
CHANGED
|
@@ -106,6 +106,12 @@ export type {
|
|
|
106
106
|
export { configure, onReducedMotion, reducedMotion } from './config.js'
|
|
107
107
|
export type { JoltConfig } from './config.js'
|
|
108
108
|
export { definePreset, presets } from './presets.js'
|
|
109
|
+
export { createPreset } from './core/preset-recipe.js'
|
|
110
|
+
export type {
|
|
111
|
+
PortablePresetName,
|
|
112
|
+
PresetParameters,
|
|
113
|
+
PresetRecipe,
|
|
114
|
+
} from './core/preset-recipe.js'
|
|
109
115
|
export type { Preset, PresetName, Presets } from './presets.js'
|
|
110
116
|
export { origamiSpring, springs } from './transition.js'
|
|
111
117
|
export type {
|
package/src/inspector/plot.ts
CHANGED
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** Separate paths preserve unavailable observations instead of fabricating a line. */
|
|
4
|
-
export function inspectorPlot(samples: readonly InspectorSample[]): string {
|
|
5
|
-
const values = samples
|
|
6
|
-
.flatMap((s) => [s.expected, s.observed])
|
|
7
|
-
.filter((v): v is number => v !== null && Number.isFinite(v))
|
|
8
|
-
const min = Math.min(0, ...values),
|
|
9
|
-
max = Math.max(1, ...values)
|
|
10
|
-
const first = samples[0]?.at ?? 0,
|
|
11
|
-
span = Math.max(1, (samples.at(-1)?.at ?? 1) - first)
|
|
12
|
-
const path = (key: 'expected' | 'observed') => {
|
|
13
|
-
let drawing = false,
|
|
14
|
-
result = ''
|
|
15
|
-
for (const s of samples) {
|
|
16
|
-
const value = s[key]
|
|
17
|
-
if (value === null || !Number.isFinite(value)) {
|
|
18
|
-
drawing = false
|
|
19
|
-
continue
|
|
20
|
-
}
|
|
21
|
-
result += `${drawing ? 'L' : 'M'}${(12 + ((s.at - first) / span) * 296).toFixed(2)},${(88 - ((value - min) / (max - min)) * 72).toFixed(2)} `
|
|
22
|
-
drawing = true
|
|
23
|
-
}
|
|
24
|
-
return result
|
|
25
|
-
}
|
|
26
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" width="320" height="104" viewBox="0 0 320 104"><rect width="320" height="104" rx="14" fill="#252A34"/><path d="M12 16H308M12 52H308M12 88H308" stroke="#444956" stroke-width=".5"/><path d="${path('expected')}" fill="none" stroke="#DFFF69" stroke-width="2.5"/><path d="${path('observed')}" fill="none" stroke="#F0ABCE" stroke-width="2" stroke-dasharray="4 2"/></svg>`
|
|
27
|
-
}
|
|
1
|
+
export { inspectorPlot } from '../core/inspection-plot.js'
|