Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/content/2.composables/1.use-animate.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The `useAnimate` composable wraps the [animate](https://animejs.com/documentatio
```ts
function useAnimate(
target: AnimeTargets,
parameters: MaybeRefOrGetter<AnimationParams>
): JSAnimation
params: AnimeParams
): AnimeInstance
```

### Arguments
Expand All @@ -28,7 +28,7 @@ Passing an object created with `ref` will fail. You should pass a
The value to animate. Can be a CSS selector, DOM element, Vue component, JS object, or an array of these.
::

::field{name="parameters" type="AnimeParams"}
::field{name="params" type="AnimeParams"}
See [AnimeJS Animatable Properties](https://animejs.com/documentation/animation/animatable-properties).
::
::
Expand Down
5 changes: 2 additions & 3 deletions docs/content/2.composables/2.use-waapi-animate.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ navigation:
The `useWaapiAnimate` composable wraps the [waapi.animate](https://animejs.com/documentation/web-animation-api) function
from AnimeJS to help create [WAAPI](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) powered animations.


## Type Definition

```ts
function useWaapiAnimate(
target: WaapiTargets,
parameters: MaybeRefOrGetter<WAAPIAnimationParams>
params: MaybeRefOrGetter<WAAPIAnimationParams>
): WAAPIAnimation
```

Expand All @@ -25,7 +24,7 @@ function useWaapiAnimate(
The DOM element(s) to animate.
::

::field{name="options" type="MaybeRefOrGetter&lt;WAAPIAnimationParams&gt;"}
::field{name="params" type="MaybeRefOrGetter&lt;WAAPIAnimationParams&gt;"}
Object containing keyframes and animation options.
::
::
Expand Down
6 changes: 3 additions & 3 deletions docs/content/2.composables/3.use-animatable.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ navigation:

Wrapper for the [createAnimatable](https://animejs.com/documentation/animatable) function from AnimeJS.

> Efficiently animates target properties, making it an ideal replacement for `animate()`
> Efficiently animates target properties, making it an ideal replacement for `animate()`
> and `utils.set()` in situations where values change frequently,
> such as cursor events or animation loops.

Expand All @@ -16,7 +16,7 @@ Wrapper for the [createAnimatable](https://animejs.com/documentation/animatable)
```ts
function useAnimatable(
target: AnimeTargets,
parameters: AnimatableParams
params: MaybeRefOrGetter<AnimatableParams>
): AnimatableObject
```

Expand All @@ -27,7 +27,7 @@ function useAnimatable(
The reactive object or array of objects to animate.
::

::field{name="parameters" type="AnimatableParams"}
::field{name="params" type="AnimatableParams"}
See [AnimeJS Animatable Properties](https://animejs.com/documentation/animatable/animatable-settings).
::
::
Expand Down
4 changes: 2 additions & 2 deletions docs/content/2.composables/4.use-split-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Reactive wrapper for the [splitText](https://animejs.com/documentation/text) fun
```ts
function useSplitText(
target: SplitTextTargets,
parameters: TextSplitterParams
params: TextSplitterParams
): {
lines: Ref<HTMLElement[]>,
words: Ref<HTMLElement[]>,
Expand All @@ -34,7 +34,7 @@ function useSplitText(
The element or selector containing the text to split.
::

::field{name="parameters" type="TextSplitterParams"}
::field{name="params" type="TextSplitterParams"}
See [AnimeJS Text documentation](https://animejs.com/documentation/text) for split options like `lines`, `words`, `chars`.
::
::
Expand Down
6 changes: 3 additions & 3 deletions docs/content/2.composables/6.use-draggable.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The `useDraggable` composable wraps the [createDraggable](https://animejs.com/do
```ts
function useDraggable(
target: DraggableTypes["target"],
options?: DraggableOptions
params?: DraggableOptions
): ProxyReturns<Draggable>
```

Expand All @@ -23,7 +23,7 @@ function useDraggable(
The element(s) to make draggable. Supports CSS selectors, DOM elements, or template refs.
::

::field{name="options" type="DraggableOptions"}
::field{name="params" type="DraggableOptions"}
Configuration for dragging behavior. Highly reactive, supporting Vue refs and getters for most properties.
::
::
Expand All @@ -43,7 +43,7 @@ properties and methods on the returned object may be `undefined` until the initi
Always use optional chaining or check for existence before calling methods!
::

#### Example
### Example

```ts
const draggable = useDraggable('.square');
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/app/composables/useAnimatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { AnimatableObject, AnimatableParams, TargetsParam } from 'animejs'

export function useAnimatable(
target: Parameters<typeof normalizeAnimeTarget>[0],
options?: MaybeRefOrGetter<AnimatableParams>,
params?: MaybeRefOrGetter<AnimatableParams>,
): AnimatableObject {
const mounted = useMounted()
const animatable = shallowReactive(createAnimatable({}, {}))
Expand All @@ -17,7 +17,7 @@ export function useAnimatable(
const targets = normalizeAnimeTarget(target)
if (oldTarget === targets) return
oldTarget = targets
const newAnimatable = createAnimatable(targets, toValue(options) || {})
const newAnimatable = createAnimatable(targets, toValue(params) || {})
Object.assign(animatable, newAnimatable)
})

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/app/composables/useAnimate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { animate, type JSAnimation } from 'animejs/animation'

export function useAnimate(
target: Parameters<typeof normalizeAnimeTarget>[0],
parameters?: MaybeRefOrGetter<AnimationParams>,
params?: MaybeRefOrGetter<AnimationParams>,
): JSAnimation {
const mounted = useMounted()
const animation = shallowRef(animate({}, {}))
Expand All @@ -18,7 +18,7 @@ export function useAnimate(
if (oldTarget === targets) return
if (animation.value) animation.value.revert()
oldTarget = targets
const newAnimation = animate(targets, toValue(parameters) || {})
const newAnimation = animate(targets, toValue(params) || {})
animation.value = newAnimation
})

Expand Down
34 changes: 18 additions & 16 deletions src/runtime/app/composables/useDraggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type DraggableOptions = MakeRefable<Omit<DraggableParams, 'trigger' | 'container

export function useDraggable(
target: DraggableTypes['target'],
options?: DraggableOptions,
params?: DraggableOptions,
): ProxyReturns<Draggable> {
const mounted = useMounted()
const dragController = shallowRef<Draggable | null>(null)
Expand All @@ -41,8 +41,8 @@ export function useDraggable(
watch(
[
() => target,
() => options?.trigger,
() => options?.container,
() => params?.trigger,
() => params?.container,
() => mounted.value,
],
() => {
Expand All @@ -52,8 +52,8 @@ export function useDraggable(
if (dragController.value) dragController.value.revert()
oldTarget = targets

const trigger = normalizeLayoutTarget(toValue(options)?.trigger)
const container = normalizeDraggableContainer(toValue(options)?.container)
const trigger = normalizeLayoutTarget(toValue(params)?.trigger)
const container = normalizeDraggableContainer(toValue(params)?.container)

const resolveAxis = <T extends DraggableOptions['x'] | DraggableOptions['y']>(axis: T) => {
if (!axis || typeof axis !== 'object') return axis
Expand All @@ -63,41 +63,43 @@ export function useDraggable(
}

const dragEngine = createDraggable(targets, {
...options,
...params,
trigger: trigger || undefined,
container: container || undefined,
...(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const acc: any = {}
REFFABLE_PROPS.forEach((key) => {
if (!options || !(key in options)) return
acc[key] = (d: Draggable) => normalizeReffable(options[key], d)
if (!params || !(key in params)) return
acc[key] = (d: Draggable) => normalizeReffable(params[key], d)
})
return acc
})(),
x: resolveAxis(options?.x),
y: resolveAxis(options?.y),
x: resolveAxis(params?.x),
y: resolveAxis(params?.y),
})

console.log('initializing')

dragController.value = dragEngine
}, {
flush: 'post',
})

watchPostEffect(() => {
if (!options || !dragController.value) return
if (!params || !dragController.value) return

// Access all refable values to register them as dependencies
REFFABLE_PROPS.forEach((key) => {
if (key in options) toValue(options[key])
if (key in params) toValue(params[key])
})

if (typeof options.x === 'object' && options.x !== null) {
toValue((options.x).snap)
if (typeof params.x === 'object' && params.x !== null) {
toValue((params.x).snap)
}

if (typeof options.y === 'object' && options.y !== null) {
toValue((options.y).snap)
if (typeof params.y === 'object' && params.y !== null) {
toValue((params.y).snap)
}

nextTick(() => dragController.value?.refresh())
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/app/composables/useLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { tryOnScopeDispose, useMounted } from '@vueuse/core'

export function useAnimeLayout(
target: MaybeRef<Parameters<typeof normalizeLayoutTarget>[0]>,
options?: MaybeRefOrGetter<AutoLayoutParams>,
params?: MaybeRefOrGetter<AutoLayoutParams>,
) {
const mounted = useMounted()
const layout = shallowRef<ReturnType<typeof createLayout> | null>(null)
Expand All @@ -15,7 +15,7 @@ export function useAnimeLayout(
if (!mounted.value) return
const wrapper = normalizeLayoutTarget(toValue(target))
if (!wrapper) return
const newLayout = createLayout(wrapper, toValue(options) || {})
const newLayout = createLayout(wrapper, toValue(params) || {})
layout.value = newLayout
})

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/app/composables/useSplitText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { tryOnScopeDispose, useMounted } from '@vueuse/core'

export function useSplitText(
target: MaybeRef<Parameters<typeof normalizeSplitTextTarget>[0]>,
parameters?: MaybeRefOrGetter<Parameters<typeof splitText>[1]>,
params?: MaybeRefOrGetter<Parameters<typeof splitText>[1]>,
) {
const mounted = useMounted()
const splitter = ref<TextSplitter | null>(null)
Expand All @@ -28,7 +28,7 @@ export function useSplitText(
if (!element) return

if (splitter.value) splitter.value.revert()
const newSplitter = splitText(element, toValue(parameters))
const newSplitter = splitText(element, toValue(params))
splitter.value = newSplitter

newSplitter.addEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/app/composables/useWaapiAnimate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { waapi, type WAAPIAnimation } from 'animejs/waapi'

export function useWaapiAnimate(
target: Parameters<typeof normalizeWaapiAnimeTarget>[0],
parameters?: MaybeRefOrGetter<WAAPIAnimationParams>,
params?: MaybeRefOrGetter<WAAPIAnimationParams>,
): WAAPIAnimation {
const mounted = useMounted()
const animation = shallowRef(waapi.animate([], {}))
Expand All @@ -15,7 +15,7 @@ export function useWaapiAnimate(
const targets = normalizeWaapiAnimeTarget(target)
if (!mounted.value || !targets) return
if (animation.value) animation.value.revert()
const newAnimation = waapi.animate(targets, toValue(parameters) || {})
const newAnimation = waapi.animate(targets, toValue(params) || {})
animation.value = newAnimation
})

Expand Down