Skip to content

Commit 5286731

Browse files
committed
feat: support new css properties
1 parent 1d057e1 commit 5286731

23 files changed

+1302
-881
lines changed

.changeset/rare-ways-reflect.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@pandacss/is-valid-prop': minor
3+
'@pandacss/generator': minor
4+
'@pandacss/types': minor
5+
---
6+
7+
Add support for recent baseline and experimental css properties:
8+
9+
- **Size interpolation:** fieldSizing, interpolateSize
10+
- **Text rendering:** textWrapMode, textWrapStyle and textSpacingTrim
11+
- **[Experimental] Anchor positioning:** anchorName, anchorScope, positionAnchor, positionArea, positionTry,
12+
positionTryFallback, positionTryOrder, positionVisibility

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"tsup": "8.0.2",
5151
"tsx": "4.7.1",
5252
"typescript": "5.6.2",
53-
"vite-tsconfig-paths": "4.3.1",
53+
"vite-tsconfig-paths": "5.1.4",
5454
"vitest": "1.5.0"
5555
},
5656
"devDependencies": {

packages/config/src/merge-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export function mergeConfigs(configs: ExtendableConfig[]) {
8989
globalCss: mergeExtensions(reversed.map((config) => config.globalCss ?? {})),
9090
globalVars: mergeExtensions(reversed.map((config) => config.globalVars ?? {})),
9191
globalFontface: mergeExtensions(reversed.map((config) => config.globalFontface ?? {})),
92+
globalPositionTry: mergeExtensions(reversed.map((config) => config.globalPositionTry ?? {})),
9293
staticCss: mergeExtensions(reversed.map((config) => config.staticCss ?? {})),
9394
themes: mergeExtensions(reversed.map((config) => config.themes ?? {})),
9495
hooks: mergeHooks(pluginHooks),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { GlobalPositionTry } from '../src/global-position-try'
2+
3+
describe('global position try', () => {
4+
test('dash ident', () => {
5+
const pos = new GlobalPositionTry({
6+
globalPositionTry: {
7+
'--bottom-scrollable': {
8+
alignSelf: 'stretch',
9+
},
10+
},
11+
})
12+
13+
expect(pos.toString()).toMatchInlineSnapshot(`
14+
"@position-try --bottom-scrollable {
15+
align-self: stretch;
16+
17+
}"
18+
`)
19+
})
20+
21+
test('without dash ident', () => {
22+
const pos = new GlobalPositionTry({
23+
globalPositionTry: {
24+
'bottom-scrollable': {
25+
positionArea: 'block-start span-inline-end',
26+
alignSelf: 'stretch',
27+
},
28+
},
29+
})
30+
31+
expect(pos.toString()).toMatchInlineSnapshot(`
32+
"@position-try --bottom-scrollable {
33+
position-area: block-start span-inline-end;
34+
align-self: stretch;
35+
36+
}"
37+
`)
38+
})
39+
})

packages/core/src/context.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import type {
1818
} from '@pandacss/types'
1919
import { Conditions } from './conditions'
2020
import { FileEngine } from './file'
21+
import { GlobalFontface } from './global-fontface'
22+
import { GlobalPositionTry } from './global-position-try'
2123
import { GlobalVars } from './global-vars'
2224
import { HooksApi } from './hooks-api'
2325
import { ImportMap } from './import-map'
@@ -34,7 +36,6 @@ import { StyleEncoder } from './style-encoder'
3436
import { Stylesheet } from './stylesheet'
3537
import type { ParserOptions, StylesheetContext } from './types'
3638
import { Utility } from './utility'
37-
import { GlobalFontface } from './global-fontface'
3839

3940
const defaults = (config: UserConfig): UserConfig => ({
4041
cssVarRoot: ':where(:root, :host)',
@@ -71,6 +72,7 @@ export class Context {
7172

7273
globalVars: GlobalVars
7374
globalFontface: GlobalFontface
75+
globalPositionTry: GlobalPositionTry
7476

7577
encoder: StyleEncoder
7678
decoder: StyleDecoder
@@ -189,6 +191,10 @@ export class Context {
189191
globalFontface: this.config.globalFontface,
190192
})
191193

194+
this.globalPositionTry = new GlobalPositionTry({
195+
globalPositionTry: this.config.globalPositionTry,
196+
})
197+
192198
this.messages = getMessages({
193199
jsx: this.jsx,
194200
config: this.config,
@@ -343,6 +349,7 @@ export class Context {
343349
helpers: patternFns,
344350
globalVars: this.globalVars,
345351
globalFontface: this.globalFontface,
352+
globalPositionTry: this.globalPositionTry,
346353
} satisfies Omit<StylesheetContext, 'layers'>
347354
}
348355

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { FontfaceRule, GlobalPositionTry as GlobalPositionTryDefinition } from '@pandacss/types'
2+
import { stringify } from './stringify'
3+
4+
interface GlobalFontfaceOptions {
5+
globalPositionTry?: GlobalPositionTryDefinition
6+
}
7+
8+
export class GlobalPositionTry {
9+
names: string[]
10+
11+
constructor(private opts: GlobalFontfaceOptions) {
12+
this.names = Object.keys(opts.globalPositionTry ?? {})
13+
}
14+
15+
isEmpty() {
16+
return this.names.length === 0
17+
}
18+
19+
toString() {
20+
return stringifyGlobalPositionTry(this.opts.globalPositionTry ?? {})
21+
}
22+
}
23+
24+
const stringifyGlobalPositionTry = (dfns: GlobalPositionTryDefinition) => {
25+
if (!dfns) return ''
26+
27+
const lines: string[] = []
28+
29+
Object.entries(dfns).forEach(([key, value]) => {
30+
const _value = Array.isArray(value) ? value : [value]
31+
_value.forEach((v) => {
32+
lines.push(stringifyPositionTry(key, v))
33+
})
34+
})
35+
36+
return lines.join('\n\n')
37+
}
38+
39+
const ident = (key: string) => (key.startsWith('--') ? key : `--${key}`)
40+
41+
function stringifyPositionTry(key: string, config: FontfaceRule) {
42+
return `@position-try ${ident(key)} {
43+
${stringify(config)}
44+
}`
45+
}

packages/core/src/stylesheet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class Stylesheet {
6262
let css = stringify(result)
6363
css += this.context.globalVars.toString()
6464
css += this.context.globalFontface.toString()
65+
css += this.context.globalPositionTry.toString()
6566

6667
if (this.context.hooks['cssgen:done']) {
6768
css = this.context.hooks['cssgen:done']({ artifact: 'global', content: css }) ?? css

packages/core/src/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ export interface TransformResult {
2929
export interface StylesheetContext
3030
extends Pick<
3131
Context,
32-
'utility' | 'conditions' | 'encoder' | 'decoder' | 'isValidProperty' | 'hooks' | 'globalVars' | 'globalFontface'
32+
| 'utility'
33+
| 'conditions'
34+
| 'encoder'
35+
| 'decoder'
36+
| 'isValidProperty'
37+
| 'hooks'
38+
| 'globalVars'
39+
| 'globalFontface'
40+
| 'globalPositionTry'
3341
> {
3442
layers: Layers
3543
helpers: PatternHelpers

packages/fixture/src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ const textStyles = {
6060
},
6161
}
6262

63-
export const fixturePreset: Omit<PresetCore, 'globalCss' | 'staticCss' | 'globalVars' | 'globalFontface'> = {
63+
export const fixturePreset: Omit<
64+
PresetCore,
65+
'globalCss' | 'staticCss' | 'globalVars' | 'globalFontface' | 'globalPositionTry'
66+
> = {
6467
...presetBase,
6568
conditions,
6669
theme: {

0 commit comments

Comments
 (0)