This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
generated from productdevbookcom/vue-ts-bundle-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update Vue package configuration and files
- Loading branch information
1 parent
6aad21d
commit e77fa43
Showing
18 changed files
with
1,494 additions
and
367 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
declaration: true, | ||
}) |
This file was deleted.
Oops, something went wrong.
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,5 +1,5 @@ | ||
{ | ||
"name": "playground", | ||
"name": "playground-vue", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"private": true, | ||
|
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,10 +1,25 @@ | ||
<script setup lang="ts"> | ||
// TODO: change to your package name | ||
import { Button } from '@oku-ui/motion' | ||
import { Motion } from '@oku-ui/motion' | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<Button>Test button</Button> | ||
</div> | ||
<Motion | ||
:animate="{ rotate: 1000, backgroundColor: 'var(--yellow)' }" | ||
:transition="{ | ||
duration: 1, | ||
rotate: { duration: 2 }, | ||
}" | ||
/> | ||
</template> | ||
|
||
<style> | ||
:root { | ||
--yellow: #000 | ||
} | ||
div { | ||
width: 100px; | ||
height: 100px; | ||
border-radius: 10px; | ||
} | ||
</style> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import type { | ||
CSSProperties, | ||
PropType, | ||
} from 'vue' | ||
import { | ||
defineComponent, | ||
h, | ||
inject, | ||
onMounted, | ||
onUpdated, | ||
provide, | ||
ref, | ||
} from 'vue' | ||
import type { | ||
AnimationOptionsWithOverrides, | ||
InViewOptions, | ||
VariantDefinition, | ||
} from '@motionone/dom' | ||
import { | ||
createMotionState, | ||
createStyles, | ||
style, | ||
} from '@motionone/dom' | ||
import type { PresenceState } from '../context' | ||
import { contextId, presenceId } from '../context' | ||
|
||
function objectType<T>() { | ||
return { | ||
type: Object as PropType<T>, | ||
} | ||
} | ||
|
||
export const Motion = defineComponent({ | ||
name: 'Motion', | ||
inheritAttrs: true, | ||
props: { | ||
tag: { | ||
type: String, | ||
default: 'div', | ||
}, | ||
initial: { | ||
type: [Object, Boolean] as PropType<VariantDefinition | boolean>, | ||
}, | ||
animate: objectType<VariantDefinition>(), | ||
inView: objectType<VariantDefinition>(), | ||
hover: objectType<VariantDefinition>(), | ||
press: objectType<VariantDefinition>(), | ||
exit: objectType<VariantDefinition>(), | ||
inViewOptions: objectType<InViewOptions>(), | ||
transition: objectType<AnimationOptionsWithOverrides>(), | ||
style: objectType<CSSProperties>(), | ||
}, | ||
setup(props) { | ||
const root = ref<Element | null>(null) | ||
const parentState = inject(contextId, undefined) | ||
const presenceState = inject(presenceId, undefined) as | ||
| PresenceState | ||
| undefined | ||
|
||
const state = createMotionState( | ||
{ | ||
...props, | ||
initial: | ||
presenceState?.initial === false | ||
? presenceState.initial | ||
: props.initial === true | ||
? undefined | ||
: props.initial, | ||
}, | ||
parentState, | ||
) | ||
|
||
provide(contextId, state) | ||
|
||
onMounted(() => { | ||
const unmount = state.mount(root.value!) | ||
state.update({ | ||
...props, | ||
initial: props.initial === true ? undefined : props.initial, | ||
}) | ||
|
||
return unmount | ||
}) | ||
|
||
let manuallyAppliedMotionStyles = false | ||
onUpdated(() => { | ||
/** | ||
* Vue reapplies all styles every render, rather than diffing and | ||
* only reapplying the ones that change. This means that initially | ||
* calculated motion styles also get reapplied every render, leading | ||
* to incorrect animation origins. | ||
* | ||
* To prevent this, once an element is mounted we hand over these | ||
* styles to Motion. This will currently still lead to a jump if interrupting | ||
* transforms in browsers where the number polyfill is used. | ||
*/ | ||
if (!manuallyAppliedMotionStyles && root.value) { | ||
manuallyAppliedMotionStyles = true | ||
|
||
const styles = createStyles(state.getTarget()) | ||
for (const key in styles) | ||
style.set(root.value, key, styles[key]) | ||
} | ||
|
||
state.update({ | ||
...props, | ||
initial: props.initial === true ? undefined : props.initial, | ||
}) | ||
}) | ||
|
||
return { | ||
state, | ||
root, | ||
initialStyles: createStyles(state.getTarget()), | ||
} | ||
}, | ||
render() { | ||
return h( | ||
this.tag, | ||
{ | ||
ref: 'root', | ||
style: this.state.isMounted() | ||
? this.style | ||
: { ...this.style, ...this.initialStyles }, | ||
}, | ||
this.$slots.default?.(), | ||
) | ||
}, | ||
}) |
Oops, something went wrong.