-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(directives): reorganize directives and update docs
- Loading branch information
1 parent
c0aac41
commit 8964563
Showing
13 changed files
with
188 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,28 @@ | ||
import { directiveHooks } from "@vueuse/core"; | ||
import { defineNuxtPlugin } from "#app"; | ||
import type { BakedPresets } from "#build/types/nugget"; | ||
import type { UseBakedAnimationOptions } from "../baked"; | ||
import { vAos, vAosBaked, vAosBakedAnimate } from "./use-animate-on-scroll"; | ||
import { vFromTo, vFromToBaked, vFromToBakedAnimate } from "./use-gsap"; | ||
import { | ||
type UseBakedAnimateOnScrollOptions, | ||
useBakedAnimateOnScroll, | ||
vAos, | ||
} from "./use-animate-on-scroll"; | ||
import { useBakedFromTo, vFromTo } from "./use-gsap"; | ||
import { | ||
type UseBakedSplitTextAnimationOptions, | ||
useBakedSplitTextAnimation, | ||
vTextAnimate, | ||
vTextAnimateBaked, | ||
vTextAnimateBakedChars, | ||
vTextAnimateBakedLines, | ||
vTextAnimateBakedWords, | ||
} from "./use-split-text-animation"; | ||
|
||
type BakedPresetsArray = (keyof { | ||
[P in keyof BakedPresets as | ||
| P | ||
| (BakedPresets[P] extends infer V | ||
? V extends string | ||
? `${P}:${V}` | ||
: never | ||
: never)]: true; | ||
})[]; | ||
|
||
const transformBakedArrayToObject = <const T extends BakedPresetsArray>(v: T) => | ||
Object.fromEntries( | ||
v.map((val) => { | ||
const [key, value] = val.split(":"); | ||
return [key, value === undefined ? true : value]; | ||
}), | ||
) as { | ||
[P in T[number] as P extends `${infer K}:${string}` | ||
? K | ||
: P]: P extends `${string}:${infer V}` ? V : true; | ||
}; | ||
|
||
export default defineNuxtPlugin((nuxt) => { | ||
const app = nuxt.vueApp; | ||
|
||
app.directive("text-animate", vTextAnimate); | ||
|
||
app.directive<HTMLElement, UseBakedSplitTextAnimationOptions>( | ||
"text-animate-baked", | ||
{ | ||
[directiveHooks.mounted]: (el, binding) => { | ||
useBakedSplitTextAnimation(el, binding.value); | ||
}, | ||
}, | ||
); | ||
|
||
for (const splitBy of ["lines", "words", "chars"] as const) { | ||
app.directive<HTMLElement, BakedPresetsArray>( | ||
`text-animate-baked-${splitBy}`, | ||
{ | ||
[directiveHooks.mounted]: (el, binding) => { | ||
useBakedSplitTextAnimation(el, { | ||
splitBy, | ||
animationOptions: transformBakedArrayToObject(binding.value), | ||
}); | ||
}, | ||
}, | ||
); | ||
} | ||
app.directive("text-animate-baked", vTextAnimateBaked); | ||
app.directive("text-animate-baked-lines", vTextAnimateBakedLines); | ||
app.directive("text-animate-baked-words", vTextAnimateBakedWords); | ||
app.directive("text-animate-baked-chars", vTextAnimateBakedChars); | ||
|
||
app.directive("aos", vAos); | ||
|
||
app.directive<HTMLElement, UseBakedAnimateOnScrollOptions>("aos-baked", { | ||
[directiveHooks.mounted]: (el, binding) => { | ||
useBakedAnimateOnScroll(el, binding.value); | ||
}, | ||
}); | ||
|
||
app.directive<HTMLElement, BakedPresetsArray>("aos-baked-animate", { | ||
[directiveHooks.mounted]: (el, binding) => { | ||
useBakedAnimateOnScroll(el, { | ||
animationOptions: transformBakedArrayToObject(binding.value), | ||
}); | ||
}, | ||
}); | ||
app.directive("aos-baked", vAosBaked); | ||
app.directive("aos-baked-animate", vAosBakedAnimate); | ||
|
||
app.directive("from-to", vFromTo); | ||
|
||
app.directive<HTMLElement, UseBakedAnimationOptions>("from-to-baked", { | ||
[directiveHooks.mounted]: (el, binding) => { | ||
useBakedFromTo(el, binding.value); | ||
}, | ||
}); | ||
|
||
app.directive<HTMLElement, BakedPresetsArray>("from-to-baked-animate", { | ||
[directiveHooks.mounted]: (el, binding) => { | ||
useBakedFromTo(el, { | ||
animationOptions: transformBakedArrayToObject(binding.value), | ||
}); | ||
}, | ||
}); | ||
app.directive("from-to-baked", vFromToBaked); | ||
app.directive("from-to-baked-animate", vFromToBakedAnimate); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
import { useAnimateOnScroll, useBakedAnimateOnScroll } from "."; | ||
import { | ||
type UseBakedAnimateOnScrollOptions, | ||
useAnimateOnScroll, | ||
useBakedAnimateOnScroll, | ||
} from "."; | ||
import { defineDirective } from "../../baked"; | ||
import type { BakedPresetsArray } from "../../types"; | ||
import { directiveObj, transformBakedArrayToObject } from "../../utils"; | ||
|
||
export const vAos = defineDirective({ | ||
fn: useAnimateOnScroll, | ||
bakedFn: useBakedAnimateOnScroll, | ||
}); | ||
|
||
export const vAosBaked = directiveObj<UseBakedAnimateOnScrollOptions>( | ||
(el, binding) => { | ||
useBakedAnimateOnScroll(el, binding.value); | ||
}, | ||
); | ||
|
||
export const vAosBakedAnimate = directiveObj<BakedPresetsArray>( | ||
(el, binding) => { | ||
useBakedAnimateOnScroll(el, { | ||
animationOptions: transformBakedArrayToObject(binding.value), | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 39 additions & 1 deletion
40
src/runtime/functions/use-split-text-animation/directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,45 @@ | ||
import { useBakedSplitTextAnimation, useSplitTextAnimation } from "."; | ||
import { | ||
type UseBakedSplitTextAnimationOptions, | ||
useBakedSplitTextAnimation, | ||
useSplitTextAnimation, | ||
} from "."; | ||
import { defineDirective } from "../../baked"; | ||
import type { BakedPresetsArray } from "../../types"; | ||
import { directiveObj, transformBakedArrayToObject } from "../../utils"; | ||
|
||
export const vTextAnimate = defineDirective({ | ||
fn: useSplitTextAnimation, | ||
bakedFn: useBakedSplitTextAnimation, | ||
}); | ||
|
||
export const vTextAnimateBaked = | ||
directiveObj<UseBakedSplitTextAnimationOptions>((el, binding) => { | ||
useBakedSplitTextAnimation(el, binding.value); | ||
}); | ||
|
||
export const vTextAnimateBakedLines = directiveObj<BakedPresetsArray>( | ||
(el, binding) => { | ||
useBakedSplitTextAnimation(el, { | ||
splitBy: "lines", | ||
animationOptions: transformBakedArrayToObject(binding.value), | ||
}); | ||
}, | ||
); | ||
|
||
export const vTextAnimateBakedWords = directiveObj<BakedPresetsArray>( | ||
(el, binding) => { | ||
useBakedSplitTextAnimation(el, { | ||
splitBy: "words", | ||
animationOptions: transformBakedArrayToObject(binding.value), | ||
}); | ||
}, | ||
); | ||
|
||
export const vTextAnimateBakedChars = directiveObj<BakedPresetsArray>( | ||
(el, binding) => { | ||
useBakedSplitTextAnimation(el, { | ||
splitBy: "chars", | ||
animationOptions: transformBakedArrayToObject(binding.value), | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.