Skip to content

Commit 43221cb

Browse files
committed
fix: externalize css types by adding type annotations
1 parent 8ad06ef commit 43221cb

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

src/reactiveStyle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Ref } from 'vue'
1+
import type { Reactive, Ref } from 'vue'
22
import { reactive, ref, watch } from 'vue'
33
import type { StyleProperties } from './types'
44
import { getValueAsType, getValueType } from './utils/style'
@@ -8,13 +8,13 @@ import { getValueAsType, getValueType } from './utils/style'
88
*
99
* @param props
1010
*/
11-
export function reactiveStyle(props: StyleProperties = {}) {
11+
export function reactiveStyle(props: StyleProperties = {}): { state: Reactive<StyleProperties>, style: Ref<StyleProperties> } {
1212
// Reactive StyleProperties object
1313
const state = reactive<StyleProperties>({
1414
...props,
1515
})
1616

17-
const style = ref({}) as Ref<StyleProperties>
17+
const style = ref<StyleProperties>({})
1818

1919
// Reactive DOM Element compatible `style` object bound to state
2020
watch(

src/reactiveTransform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { px } from 'style-value-types'
22
import { reactive, ref, watch } from 'vue'
3+
import type { Reactive, Ref } from 'vue'
34
import type { TransformProperties } from './types'
45
import { getValueAsType, getValueType } from './utils/style'
56

@@ -18,7 +19,7 @@ const translateAlias: Record<string, string> = {
1819
* @param props
1920
* @param enableHardwareAcceleration
2021
*/
21-
export function reactiveTransform(props: TransformProperties = {}, enableHardwareAcceleration = true) {
22+
export function reactiveTransform(props: TransformProperties = {}, enableHardwareAcceleration = true): { state: Reactive<TransformProperties>, transform: Ref<string> } {
2223
// Reactive TransformProperties object
2324
const state = reactive<TransformProperties>({ ...props })
2425

src/types/variants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export interface TransformProperties {
4848
/**
4949
* Relevant styling properties
5050
*/
51-
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
5251
export type StyleProperties = Omit<CSSProperties, 'transition' | 'rotate' | 'scale' | 'perspective' | 'transform' | 'transformBox' | 'transformOrigin' | 'transformStyle'>
5352

5453
/**

src/useElementStyle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { MaybeRef } from '@vueuse/core'
2+
import type { Reactive } from 'vue'
23
import { watch } from 'vue'
34
import { reactiveStyle } from './reactiveStyle'
45
import type { MotionTarget, PermissiveTarget, StyleProperties } from './types'
@@ -11,7 +12,7 @@ import { isTransformOriginProp, isTransformProp } from './utils/transform'
1112
*
1213
* @param target
1314
*/
14-
export function useElementStyle(target: MaybeRef<PermissiveTarget>, onInit?: (initData: Partial<StyleProperties>) => void) {
15+
export function useElementStyle(target: MaybeRef<PermissiveTarget>, onInit?: (initData: Partial<StyleProperties>) => void): { style: Reactive<StyleProperties> } {
1516
// Transform cache available before the element is mounted
1617
let _cache: StyleProperties | undefined
1718
// Local target cache as we need to resolve the element from PermissiveTarget

src/useElementTransform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { MaybeRef } from '@vueuse/core'
22
import { watch } from 'vue'
3+
import type { Reactive } from 'vue'
34
import { reactiveTransform } from './reactiveTransform'
45
import type { MotionTarget, PermissiveTarget, TransformProperties } from './types'
56
import { usePermissiveTarget } from './usePermissiveTarget'
@@ -10,7 +11,7 @@ import { stateFromTransform } from './utils/transform-parser'
1011
*
1112
* @param target
1213
*/
13-
export function useElementTransform(target: MaybeRef<PermissiveTarget>, onInit?: (initData: Partial<TransformProperties>) => void) {
14+
export function useElementTransform(target: MaybeRef<PermissiveTarget>, onInit?: (initData: Partial<TransformProperties>) => void): { transform: Reactive<TransformProperties> } {
1415
// Transform cache available before the element is mounted
1516
let _cache: string | undefined
1617
// Local target cache as we need to resolve the element from PermissiveTarget

src/useMotionProperties.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { MaybeRef } from '@vueuse/core'
22
import { reactive, watch } from 'vue'
3-
import type { MotionProperties, PermissiveTarget } from './types'
3+
import type { Reactive } from 'vue'
4+
import type { MotionProperties, PermissiveTarget, StyleProperties, TransformProperties } from './types'
45
import { useElementStyle } from './useElementStyle'
56
import { useElementTransform } from './useElementTransform'
67
import { usePermissiveTarget } from './usePermissiveTarget'
@@ -12,7 +13,7 @@ import { objectEntries } from './utils/type-feature'
1213
*
1314
* @param target
1415
*/
15-
export function useMotionProperties(target: MaybeRef<PermissiveTarget>, defaultValues?: Partial<MotionProperties>) {
16+
export function useMotionProperties(target: MaybeRef<PermissiveTarget>, defaultValues?: Partial<MotionProperties>): { motionProperties: Reactive<MotionProperties>, style: Reactive<StyleProperties>, transform: Reactive<TransformProperties> } {
1617
// Local motion properties
1718
const motionProperties = reactive<MotionProperties>({})
1819

0 commit comments

Comments
 (0)