Skip to content

Commit f1d52d3

Browse files
authored
Merge pull request #255 from BobbieGoede/fix/externalize-css-properties-types
fix: externalize `CSSProperties` types
2 parents 90c95dc + c83fc77 commit f1d52d3

15 files changed

+255
-114
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"dependencies": {
8383
"@vueuse/core": "^13.0.0",
8484
"@vueuse/shared": "^13.0.0",
85-
"csstype": "^3.1.3",
8685
"framesync": "^6.1.2",
8786
"popmotion": "^11.0.5",
8887
"style-value-types": "^5.1.2"
@@ -111,7 +110,7 @@
111110
"unbuild": "^3.5.0",
112111
"vite": "5.2.12",
113112
"vitest": "^1.6.0",
114-
"vue": "^3.4.38",
113+
"vue": "^3.5.13",
115114
"yorkie": "^2.0.0"
116115
},
117116
"pnpm": {

pnpm-lock.yaml

+235-88
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Motion.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Component } from '@nuxt/schema'
2-
import type { PropType } from 'vue'
1+
import type { Component, PropType } from 'vue'
32

43
import { defineComponent, h, useSlots } from 'vue'
54
import { variantToStyle } from '../utils/transform'

src/components/MotionGroup.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { PropType, VNode } from 'vue'
2-
import type { Component } from '@nuxt/schema'
1+
import type { Component, PropType, VNode } from 'vue'
32

43
import { Fragment, defineComponent, h, useSlots } from 'vue'
54
import { variantToStyle } from '../utils/transform'

src/nuxt/tsconfig.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
"moduleResolution": "Node",
99

1010
"resolveJsonModule": true,
11-
"types": [
12-
"node",
13-
"csstype",
14-
"vitest",
15-
"vitest/globals",
16-
"vite/client"
17-
],
11+
"types": ["node", "vitest", "vitest/globals", "vite/client"],
1812
"allowJs": true,
1913
"strict": true,
2014
"noEmit": true,

src/plugin/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const MotionPlugin = {
3232
const variants = options.directives[key] as MotionVariants<any>
3333

3434
// Development warning, showing definitions missing `initial` key
35-
if (!variants.initial && import.meta.dev) {
35+
if (!variants.initial && import.meta.env.MODE === 'development') {
3636
console.warn(
3737
`Your directive v-motion-${key} is missing initial variant!`,
3838
)

src/reactiveStyle.ts

+3-3
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

+2-1
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

-1
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

+2-1
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

+2-1
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

+3-2
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

src/utils/component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export function setupMotionComponent(
195195
})
196196

197197
// Replay animations on component update Vue
198-
if (import.meta.dev) {
198+
if (import.meta.env.MODE === 'development') {
199199
// Validate passed preset
200200
if (
201201
props.preset != null

src/utils/keys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const CUSTOM_PRESETS = Symbol(
2-
import.meta.dev ? 'motionCustomPresets' : '',
2+
import.meta.env.MODE === 'development' ? 'motionCustomPresets' : '',
33
)

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"#components": [".nuxt/components"]
3030
},
3131
"resolveJsonModule": true,
32-
"types": ["node", "csstype", "vitest", "vitest/globals", "vite/client"],
32+
"types": ["node", "vitest/globals", "vite/client"],
3333
"allowJs": true,
3434
"strict": true,
3535
"noEmit": true,

0 commit comments

Comments
 (0)