Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(preset-mini, preset-wind4): update transform perspective generated css#5114

Merged
zyyv merged 1 commit intomainfrom
issue-5097
Feb 25, 2026
Merged

fix(preset-mini, preset-wind4): update transform perspective generated css#5114
zyyv merged 1 commit intomainfrom
issue-5097

Conversation

@zyyv
Copy link
Member

@zyyv zyyv commented Feb 25, 2026

close #5097

This PR changes the following:

  • Fixed the perspective transform rule. In preset-mini, we've made perspective compatible.

mdn: https://developer.mozilla.org/zh-CN/docs/Web/CSS/Reference/Values/transform-function/perspective

  • For preset-wind4, considering that tailwind doesn't support transform perspective, we decided to align its behavior. However, you can still use this rule to support perspective transform. If you have many transform elements, to avoid perspective not working, please optimize the use of transform-perspective-xxx to increase its weight, as other transforms don't inherently support perspective.

example

Copilot AI review requested due to automatic review settings February 25, 2026 06:22
@zyyv zyyv requested a review from antfu as a code owner February 25, 2026 06:22
@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for unocss ready!

Name Link
🔨 Latest commit d6bb3e3
🔍 Latest deploy log https://app.netlify.com/projects/unocss/deploys/699e9523fcb82b00089ebf8d
😎 Deploy Preview https://deploy-preview-5114--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

Open in StackBlitz

commit: d6bb3e3

@zyyv zyyv merged commit 91ee3a5 into main Feb 25, 2026
14 checks passed
@zyyv zyyv deleted the issue-5097 branch February 25, 2026 06:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses issue #5097 by distinguishing between the CSS perspective property and the CSS perspective() transform function in both preset-mini and preset-wind4. The changes ensure that:

  • perspective-* utilities generate the CSS perspective property
  • transform-perspective-* utilities generate the perspective() transform function within the transform property

Changes:

  • Modified regex patterns to capture the optional transform- prefix for perspective utilities
  • Added perspective(var(--un-perspective)) to the beginning of the transform string in preset-mini
  • Updated transform generation logic to handle transform-perspective-* as a transform function
  • Updated autocomplete suggestions to reflect the new behavior
  • Updated all test snapshots to match the new CSS output

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages-presets/preset-mini/src/_rules/transform.ts Added perspective() to transform string; updated regex to distinguish transform-perspective from perspective
packages-presets/preset-wind4/src/rules/transform.ts Updated regex and logic to handle transform-perspective separately; removed autocomplete for transform-perspective
test/assets/preset-mini-targets.ts Added test case for transform-perspective-9cm
test/assets/output/*.css Updated all test snapshots to include perspective(var(--un-perspective)) in transform rules
test/snapshots/postcss.test.ts.snap Updated postcss test snapshot
packages-integrations/svelte-scoped/src/_preprocess/transformClasses/test-outputs/*.svelte Updated Svelte integration test outputs
packages-engine/core/test/*.ts Updated core engine test outputs
packages-integrations/runtime/test/assets/output/*.css Updated runtime integration test outputs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (v != null) {
if (t) {
return {
'--un-perspective': `perspective(${v})`,
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a critical bug in how --un-perspective is set and used. On line 86, the variable is set to include the perspective() function wrapper (e.g., perspective(9cm)), but on line 27, it's used inside another perspective() function call, resulting in double nesting: perspective(perspective(9cm)), which is invalid CSS.

You can verify this in the test output at test/assets/output/preset-mini-targets.css:336 where it generates:

.transform-perspective-9cm{--un-perspective:perspective(9cm);transform:perspective(var(--un-perspective)) ...}

The fix is to change line 86 to set --un-perspective to just the value without the function wrapper:

  • Change '--un-perspective': \perspective(${v})`to'--un-perspective': v`

Additionally, add '--un-perspective': 0 to transformBase (lines 55-69) as the default initial value. Note that perspective(0) has a special meaning in CSS (disables perspective), which may be the desired default behavior when no perspective is explicitly set.

Note: preset-wind4 handles this correctly by storing the full perspective() function in the variable and directly using var(--un-perspective) without double wrapping (see preset-wind4/src/rules/transform.ts:61-62).

Copilot uses AI. Check for mistakes.
Comment on lines 26 to 30
const transform = [
'perspective(var(--un-perspective))',
'translateX(var(--un-translate-x))',
'translateY(var(--un-translate-y))',
'translateZ(var(--un-translate-z))',
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transformGpu constant doesn't include perspective(var(--un-perspective)) at the beginning like the regular transform constant does. This inconsistency means that if a user uses transform-gpu along with transform-perspective-*, the perspective transformation won't be applied.

For consistency, consider adding perspective(var(--un-perspective)) at the beginning of the transformGpu array, or document why GPU transforms intentionally exclude perspective.

Copilot uses AI. Check for mistakes.
}
}
}, { autocomplete: [`transform-perspective-<num>`, `perspective-<num>`, `perspective-$perspective`] }],
}, { autocomplete: [`perspective-<num>`, `perspective-$perspective`] }],
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The autocomplete array removed transform-perspective-<num> from the suggestions. However, based on the regex pattern on line 48 which still matches transform-perspective-*, this autocomplete option should be retained for better developer experience.

Consider keeping transform-perspective-<num> in the autocomplete array alongside the existing entries.

Suggested change
}, { autocomplete: [`perspective-<num>`, `perspective-$perspective`] }],
}, { autocomplete: [
`perspective-<num>`,
`perspective-$perspective`,
`transform-perspective-<num>`,
`transform-perspective-$perspective`,
] }],

Copilot uses AI. Check for mistakes.
@sep2
Copy link

sep2 commented Feb 25, 2026

What is the purpose of perspective(var(--un-perspective)) in the new transform css?

This PR breaks our website styling with rotate-xxx translate-y-xxx, etc.

The old one in v66.6.0:

image

The new one from v66.6.1:

image

After manually removing the perspective part the style is good again.

We have to revert to 66.6.0.

@zyyv
Copy link
Member Author

zyyv commented Feb 26, 2026

@sep2 I apologize for the inconvenience caused. This will be fixed in version 66.6.2.

@vipero07
Copy link
Contributor

Thanks for the quick revert fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confused perspective- and transform-perspective-

4 participants