Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove deps of lodash omit #72

Merged
merged 1 commit into from
May 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
## Installation

```
npm install hero-motion
npm install hero-motion @vueuse/motion @vueuse/core
```

## Usage
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@
"vue": ">=3.0.0"
},
"dependencies": {
"defu": "^6.1.4",
"lodash.omit": "^4.5.0"
"defu": "^6.1.4"
},
"devDependencies": {
"@antfu/eslint-config": "^2.15.0",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@types/lodash.omit": "^4.5.9",
"@vue/tsconfig": "^0.5.0",
"@vueuse/core": "^10.9.0",
"@vueuse/motion": "^2.1.0",
Expand Down
71 changes: 24 additions & 47 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/composables/use-hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { type Ref, computed, nextTick, unref, useAttrs } from 'vue'
import { tryOnBeforeUnmount, tryOnMounted, useElementBounding } from '@vueuse/core'
import { useElementTransform, useMotion } from '@vueuse/motion'
import { defu } from 'defu'
import omit from 'lodash.omit'
import type { HeroProps } from '../components/hero'
import { useHeroContext } from '../composables/use-hero-context'
import type { Transition } from '../types'

export type UseHeroProps = Omit<HeroProps, 'as'>

Expand All @@ -15,6 +13,17 @@ export const defaultTransition = {
damping: 35,
}

function omit<T extends Record<string, any>, K extends keyof T>(source: T, keys: K[] = []): Omit<T, K> {
if (!keys.length)
return source
const picks: any = {}
for (const key in source) {
if (!keys.includes(key as unknown as K))
picks[key] = source[key]
}
return picks as Omit<T, K>
}

export function useHero(domRef: Ref<any>, props: UseHeroProps, emit: any) {
let motionInstance: any

Expand Down Expand Up @@ -67,8 +76,8 @@ export function useHero(domRef: Ref<any>, props: UseHeroProps, emit: any) {
const enter = { ...style.value, x: 0, y: 0, width: bounding.width, height: bounding.height, transition: _transition }

motionInstance = useMotion(domRef, {
initial: omit(initial, props.ignore),
enter: omit(enter, props.ignore) as Transition,
initial: omit(initial, props.ignore as any),
enter: omit(enter, props.ignore as any),
})
})

Expand Down