Skip to content

Commit b9bf8cb

Browse files
committed
Latest
1 parent b80699d commit b9bf8cb

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Motion adheres to [Semantic Versioning](http://semver.org/).
44

55
Undocumented APIs should be considered internal and may change without warning.
66

7+
## [12.0.4] 2025-01-24
8+
9+
### Fixed
10+
11+
- Fix scale correction for CSS variables.
12+
713
## [12.0.3] 2025-01-23
814

915
### Fixed

packages/framer-motion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"bundlesize": [
111111
{
112112
"path": "./dist/size-rollup-motion.js",
113-
"maxSize": "34.7 kB"
113+
"maxSize": "34.75 kB"
114114
},
115115
{
116116
"path": "./dist/size-rollup-m.js",

packages/framer-motion/rollup.config.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import alias from "@rollup/plugin-alias"
12
import resolve from "@rollup/plugin-node-resolve"
2-
import { terser } from "rollup-plugin-terser"
33
import replace from "@rollup/plugin-replace"
4-
import dts from "rollup-plugin-dts"
5-
import alias from "@rollup/plugin-alias"
64
import path from "node:path"
5+
import dts from "rollup-plugin-dts"
6+
import preserveDirectives from "rollup-plugin-preserve-directives"
7+
import { terser } from "rollup-plugin-terser"
78
import { fileURLToPath } from 'url'
8-
import pkg from "./package.json" with { type: "json"}
9+
import pkg from "./package.json" with { type: "json" }
910
import tsconfig from "./tsconfig.json" with { type: "json" }
10-
import preserveDirectives from "rollup-plugin-preserve-directives";
1111

1212
const config = {
1313
input: "lib/index.js",

packages/framer-motion/src/projection/node/create-projection-node.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ export function createProjectionNode<I>({
19481948
for (const key in scaleCorrectors) {
19491949
if (valuesToRender[key] === undefined) continue
19501950

1951-
const { correct, applyTo } = scaleCorrectors[key]
1951+
const { correct, applyTo, isCSSVariable } = scaleCorrectors[key]
19521952

19531953
/**
19541954
* Only apply scale correction to the value if we have an
@@ -1967,7 +1967,16 @@ export function createProjectionNode<I>({
19671967
styles[applyTo[i]] = corrected
19681968
}
19691969
} else {
1970-
styles[key] = corrected
1970+
// If this is a CSS variable, set it directly on the instance.
1971+
// Replacing this function from creating styles to setting them
1972+
// would be a good place to remove per frame object creation
1973+
if (isCSSVariable) {
1974+
;(
1975+
this.instance as unknown as HTMLElement
1976+
).style.setProperty(key, corrected as string)
1977+
} else {
1978+
styles[key] = corrected
1979+
}
19711980
}
19721981
}
19731982

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import { isCSSVariableName } from "../../render/dom/utils/is-css-variable"
12
import { ScaleCorrectorMap } from "./types"
23

34
export const scaleCorrectors: ScaleCorrectorMap = {}
45

56
export function addScaleCorrector(correctors: ScaleCorrectorMap) {
6-
Object.assign(scaleCorrectors, correctors)
7+
for (const key in correctors) {
8+
scaleCorrectors[key] = correctors[key]
9+
if (isCSSVariableName(key)) {
10+
scaleCorrectors[key].isCSSVariable = true
11+
}
12+
}
713
}

packages/framer-motion/src/projection/styles/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type ScaleCorrector = (
88
export interface ScaleCorrectorDefinition {
99
correct: ScaleCorrector
1010
applyTo?: string[]
11+
isCSSVariable?: boolean
1112
}
1213

1314
export interface ScaleCorrectorMap {

0 commit comments

Comments
 (0)