8000 fix(core,preset-wind4): add `operators` type to `CSSEntry` & resovle negative value in `translate` by Simon-He95 · Pull Request #4601 · unocss/unocss · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(core,preset-wind4): add operators type to CSSEntry & resovle negative value in translate #4601

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

Merged
merged 5 commits into from
Apr 18, 2025
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
7 changes: 6 additions & 1 deletion packages-engine/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export type PartialByKeys<T, K extends keyof T = keyof T> = FlatObjectT 8000 uple<Part
export type RequiredByKey<T, K extends keyof T = keyof T> = FlatObjectTuple<Required<Pick<T, Extract<keyof T, K>>> & Omit<T, K>>

export type CSSObject = Record<string, string | number | undefined>
export type CSSEntry = [string, string | number | undefined]
/**
* [property, value, operators?]
*
* - operators: Used to perform specific operations on value or property.
*/
export type CSSEntry = [string, string | number | undefined, Arrayable<string>?]
export type CSSEntries = CSSEntry[]

export type CSSObjectInput = CSSObject | Partial<ControlSymbolsValue>
Expand Down
4 changes: 2 additions & 2 deletions packages-presets/preset-wind4/src/rules/transform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CSSValueInput, CSSValues, Rule } from '@unocss/core'
import type { Theme } from '../theme'
import { defineProperty, generateThemeVariable, h, makeGlobalStaticRules, numberResolver, positionMap, themeTracking, transformXYZ, xyzMap } from '../utils'
import { CONTROL_MINI_NO_NEGATIVE, defineProperty, generateThemeVariable, h, makeGlobalStaticRules, numberResolver, positionMap, themeTracking, transformXYZ, xyzMap } from '../utils'

const transformValues = [
'translate',
Expand Down Expand Up @@ -110,7 +110,7 @@ function handleTranslate([, d, b]: string[]): CSSValues | (CSSValueInput | strin
return [
[
...transformXYZ(d, typeof v === 'number' ? `calc(var(--spacing) * ${v})` : v, 'translate'),
['translate', `var(--un-translate-x) var(--un-translate-y)${d === 'z' ? ' var(--un-translate-z)' : ''}`],
['translate', `var(--un-translate-x) var(--un-translate-y)${d === 'z' ? ' var(--un-translate-z)' : ''}`, CONTROL_MINI_NO_NEGATIVE],
],
...['x', 'y', 'z'].map(d => defineProperty(`--un-translate-${d}`, { initialValue: 0 })),
]
Expand Down
3 changes: 3 additions & 0 deletions packages-presets/preset-wind4/src/variants/negative.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Variant } from '@unocss/core'
import type { Theme } from '../theme'
import { toArray } from '@unocss/core'
import { getStringComponent } from '@unocss/rule-utils'
import { CONTROL_MINI_NO_NEGATIVE, cssMathFnRE, cssVarFnRE } from '../utils'

Expand Down Expand Up @@ -46,6 +47,8 @@ export const variantNegative: Variant<Theme> = {
return
let changed = false
body.forEach((v) => {
if (toArray(v[2]).includes(CONTROL_MINI_NO_NEGATIVE))
return
const value = v[1]?.toString()
if (!value || value === '0')
return
Expand Down
8 changes: 5 additions & 3 deletions test/assets/output/preset-wind4-targets.css
Original file line number Diff line number Diff line change
Expand Up @@ -994,13 +994,15 @@ unocss .scope-\[unocss\]\:block{display:block;}
.translate-\[var\(--x\)\,var\(--y\)\,25\%\]{--un-translate-x:var(--x);--un-translate-y:var(--y);--un-translate-z:25%;translate:var(--un-translate-x) var(--un-translate-y);}
.translate-\[var\(--x\)\,var\(--y\)\]{--un-translate-x:var(--x);--un-translate-y:var(--y);translate:var(--un-translate-x) var(--un-translate-y);}
.scope_class .scope-\[\.scope\\_class\]\:translate-0{--un-translate-x:calc(var(--spacing) * 0);--un-translate-y:calc(var(--spacing) * 0);translate:var(--un-translate-x) var(--un-translate-y);}
.-translate-full{--un-translate-x:-100%;--un-translate-y:-100%;translate:calc(var(--un-translate-x) * -1) var(--un-translate-y);}
.-translate-full{--un-translate-x:-100%;--un-translate-y:-100%;translate:var(--un-translate-x) var(--un-translate-y);}
.translate-full{--un-translate-x:100%;--un-translate-y:100%;translate:var(--un-translate-x) var(--un-translate-y);}
.translate-none{translate:none;}
.translate-x-\$variable{--un-translate-x:var(--variable);translate:var(--un-translate-x) var(--un-translate-y);}
.-translate-x-full{--un-translate-x:-100%;translate:calc(var(--un-translate-x) * -1) var(--un-translate-y);}
.-translate-x-full{--un-translate-x:-100%;translate:var(--un-translate-x) var(--un-translate-y);}
.translate-x-full{--un-translate-x:100%;translate:var(--un-translate-x) var(--un-translate-y);}
.-translate-y-1\/2{--un-translate-y:-50%;translate:calc(var(--un-translate-x) * -1) var(--un-translate-y);}
.-translate-y-1\/2,
.-translate-y-50\%,
.translate-y--50\%{--un-translate-y:-50%;translate:var(--un-translate-x) var(--un-translate-y);}
.translate-y-1\/2{--un-translate-y:50%;translate:var(--un-translate-x) var(--un-translate-y);}
.translate-y-1\/4{--un-translate-y:25%;translate:var(--un-translate-x) var(--un-translate-y);}
.translate-y-px{--un-translate-y:1px;translate:var(--un-translate-x) var(--un-translate-y);}
Expand Down
4 changes: 4 additions & 0 deletions test/assets/preset-wind4-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ export const presetWind4Targets: string[] = [
'max-h-svh',
'max-h-lvh',

// translate
'-translate-y-50%',
'translate-y--50%',

// outline
'outline-hidden',

Expand Down
0