@pandacss/node 0.0.0-dev-20230117105201 → 0.0.0-dev-20230118114316

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +69 -39
  2. package/dist/index.mjs +69 -39
  3. package/package.json +11 -11
package/dist/index.js CHANGED
@@ -207,8 +207,8 @@ function generateCssFn(ctx) {
207
207
  export declare function css(styles: SystemStyleObject): string
208
208
  `,
209
209
  js: import_outdent2.outdent`
210
- import { createCss, withoutSpace } from "../helpers"
211
- import { sortConditions, finalizeConditions } from "./conditions"
210
+ import { createCss, withoutSpace } from '../helpers'
211
+ import { sortConditions, finalizeConditions } from './conditions'
212
212
 
213
213
  const classNameMap = ${stringify(utility.entries())}
214
214
 
@@ -221,9 +221,9 @@ function generateCssFn(ctx) {
221
221
  const resolveShorthand = (prop) => shorthands[prop] || prop
222
222
 
223
223
  function transform(prop, value) {
224
- let key = resolveShorthand(prop)
225
- let propKey = classNameMap[key] || prop
226
- let className = \`$\{propKey}${separator}$\{withoutSpace(value)}\`
224
+ const key = resolveShorthand(prop)
225
+ const propKey = classNameMap[key] || prop
226
+ const className = \`$\{propKey}${separator}$\{withoutSpace(value)}\`
227
227
  return { className }
228
228
  }
229
229
 
@@ -246,27 +246,51 @@ function generateCssFn(ctx) {
246
246
  };
247
247
  }
248
248
 
249
- // src/generators/css-map.ts
249
+ // src/generators/cva.ts
250
250
  var import_outdent3 = require("outdent");
251
- function generateCssMap() {
251
+ function generateCvaFn() {
252
252
  return {
253
253
  js: import_outdent3.outdent`
254
- import { css } from "./css"
254
+ import { compact, deepMerge } from '../helpers'
255
+ import { css } from './css'
255
256
 
256
- export function cssMap(obj){
257
- return (...args) => {
258
- const finalCss = args.reduce((acc, arg) => {
259
- Object.assign(acc, obj[arg]);
260
- return acc;
261
- }, {})
262
- return css(finalCss);
257
+ export function cva(config) {
258
+ const { base = {}, variants = {}, defaultVariants = {} } = config
259
+ return (props) => {
260
+ const computedVariants = { ...defaultVariants, ...compact(props) }
261
+ let result = { ...base }
262
+ for (const [key, value] of Object.entries(computedVariants)) {
263
+ if (variants[key]?.[value]) {
264
+ result = deepMerge(result, variants[key][value])
265
+ }
266
+ }
267
+ return css(result)
263
268
  }
264
269
  }
265
270
  `,
266
271
  dts: import_outdent3.outdent`
267
- import { SystemStyleObject } from "../types"
268
-
269
- export declare function cssMap<T extends string>(obj: Record<T, SystemStyleObject>): (...args: Array<T>) => string;
272
+ import { SystemStyleObject } from '../types'
273
+
274
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T
275
+
276
+ type Variants = Record<string, Record<string, SystemStyleObject>>
277
+
278
+ type VariantSelection<T extends Variants> = {
279
+ [Variant in keyof T]?: StringToBoolean<keyof T[Variant]>
280
+ }
281
+
282
+ type AtomicRecipe<T extends Variants> = {
283
+ base?: SystemStyleObject
284
+ variants?: T | Variants
285
+ defaultVariants?: VariantSelection<T>
286
+ }
287
+
288
+ type VariantFn<T extends Variants> = (props: VariantSelection<T>) => string
289
+
290
+ export type VariantProps<T extends VariantFn<Variants>> = Parameters<T>[0]
291
+
292
+ export declare function cva<T extends Variants>(recipe?: AtomicRecipe<T>): VariantFn<T>
293
+
270
294
  `
271
295
  };
272
296
  }
@@ -342,8 +366,9 @@ function generatePreactJsxFactory(ctx) {
342
366
  import { h } from 'preact'
343
367
  import { forwardRef } from 'preact/compat'
344
368
  import { useMemo } from 'preact/hooks'
345
- import { isCssProperty } from './is-valid-prop'
346
369
  import { css, cx } from '../css'
370
+ import { deepMerge } from '../helpers'
371
+ import { isCssProperty } from './is-valid-prop'
347
372
 
348
373
  const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
349
374
 
@@ -373,8 +398,8 @@ function generatePreactJsxFactory(ctx) {
373
398
  const [styleProps, elementProps] = useMemo(() => splitProps(restProps), [restProps])
374
399
 
375
400
  function classes(){
376
- const { css: cssStyles, ...otherStyles } = styleProps
377
- const atomicClass = css({ ...otherStyles, ...cssStyles })
401
+ const { css: cssStyles, sx: sxStyles, ...otherStyles } = styleProps
402
+ const atomicClass = css(deepMerge(otherStyles, cssStyles, sxStyles))
378
403
  return cx(atomicClass, elementProps.className)
379
404
  }
380
405
 
@@ -551,8 +576,9 @@ function generateReactJsxFactory(ctx) {
551
576
  return {
552
577
  js: import_outdent9.outdent`
553
578
  import { forwardRef, useMemo } from 'react'
554
- import { isCssProperty } from './is-valid-prop'
555
579
  import { css, cx } from '../css'
580
+ import { deepMerge } from '../helpers'
581
+ import { isCssProperty } from './is-valid-prop'
556
582
 
557
583
  const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
558
584
 
@@ -582,8 +608,8 @@ function generateReactJsxFactory(ctx) {
582
608
  const [styleProps, elementProps] = useMemo(() => splitProps(restProps), [restProps])
583
609
 
584
610
  function classes(){
585
- const { css: cssStyles, ...otherStyles } = styleProps
586
- const atomicClass = css({ ...otherStyles, ...cssStyles })
611
+ const { css: cssStyles, sx: sxStyles, ...otherStyles } = styleProps
612
+ const atomicClass = css(deepMerge(otherStyles, cssStyles, sxStyles))
587
613
  return cx(atomicClass, elementProps.className)
588
614
  }
589
615
 
@@ -762,8 +788,9 @@ function generateSolidJsxFactory(ctx) {
762
788
  js: import_outdent13.outdent`
763
789
  import { Dynamic } from 'solid-js/web'
764
790
  import { mergeProps, splitProps } from 'solid-js'
765
- import { allCssProperties } from './is-valid-prop'
766
791
  import { css, cx } from '../css'
792
+ import { deepMerge } from '../helpers'
793
+ import { allCssProperties } from './is-valid-prop'
767
794
 
768
795
  const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
769
796
 
@@ -791,8 +818,8 @@ function generateSolidJsxFactory(ctx) {
791
818
  )
792
819
 
793
820
  const classes = () => {
794
- const { css: cssStyles, ...otherStyles } = styleProps
795
- const atomicClass = css({ ...otherStyles, ...cssStyles })
821
+ const { css: cssStyles, sx: sxStyles, ...otherStyles } = styleProps
822
+ const atomicClass = css(deepMerge(otherStyles, cssStyles, sxStyles))
796
823
  return cx(atomicClass, localProps.class, localProps.className)
797
824
  }
798
825
 
@@ -1094,7 +1121,7 @@ function generatePropTypes(utility, strict) {
1094
1121
  ? ConditionalValue<PropertyTypes[T]${strictText}>
1095
1122
  : T extends keyof CSSProperties
1096
1123
  ? ConditionalValue<CSSProperties[T]>
1097
- : never
1124
+ : ConditionalValue<string | number>
1098
1125
  `;
1099
1126
  }
1100
1127
 
@@ -1418,8 +1445,13 @@ function generateCssType(ctx) {
1418
1445
  `,
1419
1446
  styleProps: import_outdent22.default`
1420
1447
  import { PropertyValue } from './prop-type'
1448
+ import { Token } from './token'
1449
+
1450
+ type CssVarProperties = {
1451
+ [key in \`--\${string}\`]?: Token | (string & {}) | (number & {})
1452
+ }
1421
1453
 
1422
- export type SystemProperties = {
1454
+ export type SystemProperties = CssVarProperties & {
1423
1455
  ${Array.from(propList).map((v) => ` ${v}?: PropertyValue<'${v}'>`).join("\n")}
1424
1456
  }
1425
1457
  `
@@ -1488,13 +1520,13 @@ function setupCss(ctx) {
1488
1520
  ]
1489
1521
  };
1490
1522
  }
1491
- function setupCssMap(ctx) {
1492
- const code = generateCssMap();
1523
+ function setupCva(ctx) {
1524
+ const code = generateCvaFn();
1493
1525
  return {
1494
1526
  dir: ctx.paths.css,
1495
1527
  files: [
1496
- { file: "css-map.mjs", code: code.js },
1497
- { file: "css-map.d.ts", code: code.dts }
1528
+ { file: "cva.mjs", code: code.js },
1529
+ { file: "cva.d.ts", code: code.dts }
1498
1530
  ]
1499
1531
  };
1500
1532
  }
@@ -1575,7 +1607,7 @@ function setupCssIndex(ctx) {
1575
1607
  const code = import_outdent23.default`
1576
1608
  export * from './css'
1577
1609
  export * from './cx'
1578
- export * from './css-map'
1610
+ export * from './cva'
1579
1611
  `;
1580
1612
  return {
1581
1613
  dir: ctx.paths.css,
@@ -1597,7 +1629,7 @@ function generateSystem(ctx) {
1597
1629
  setupDesignTokens(ctx),
1598
1630
  setupKeyframes(ctx),
1599
1631
  setupTypes(ctx),
1600
- setupCssMap(ctx),
1632
+ setupCva(ctx),
1601
1633
  setupCx(ctx),
1602
1634
  setupCss(ctx),
1603
1635
  setupRecipes(ctx),
@@ -2037,10 +2069,8 @@ function createContext(conf, io = fileSystem) {
2037
2069
  collector.css.forEach((result) => {
2038
2070
  sheet.processAtomic(result.data);
2039
2071
  });
2040
- collector.cssMap.forEach((result) => {
2041
- for (const data of Object.values(result.data)) {
2042
- sheet.processAtomic(data);
2043
- }
2072
+ collector.cva.forEach((result) => {
2073
+ sheet.processAtomicRecipe(result.data);
2044
2074
  });
2045
2075
  collector.jsx.forEach((result) => {
2046
2076
  const { data, type, name } = result;
package/dist/index.mjs CHANGED
@@ -161,8 +161,8 @@ function generateCssFn(ctx) {
161
161
  export declare function css(styles: SystemStyleObject): string
162
162
  `,
163
163
  js: outdent2`
164
- import { createCss, withoutSpace } from "../helpers"
165
- import { sortConditions, finalizeConditions } from "./conditions"
164
+ import { createCss, withoutSpace } from '../helpers'
165
+ import { sortConditions, finalizeConditions } from './conditions'
166
166
 
167
167
  const classNameMap = ${stringify(utility.entries())}
168
168
 
@@ -175,9 +175,9 @@ function generateCssFn(ctx) {
175
175
  const resolveShorthand = (prop) => shorthands[prop] || prop
176
176
 
177
177
  function transform(prop, value) {
178
- let key = resolveShorthand(prop)
179
- let propKey = classNameMap[key] || prop
180
- let className = \`$\{propKey}${separator}$\{withoutSpace(value)}\`
178
+ const key = resolveShorthand(prop)
179
+ const propKey = classNameMap[key] || prop
180
+ const className = \`$\{propKey}${separator}$\{withoutSpace(value)}\`
181
181
  return { className }
182
182
  }
183
183
 
@@ -200,27 +200,51 @@ function generateCssFn(ctx) {
200
200
  };
201
201
  }
202
202
 
203
- // src/generators/css-map.ts
203
+ // src/generators/cva.ts
204
204
  import { outdent as outdent3 } from "outdent";
205
- function generateCssMap() {
205
+ function generateCvaFn() {
206
206
  return {
207
207
  js: outdent3`
208
- import { css } from "./css"
208
+ import { compact, deepMerge } from '../helpers'
209
+ import { css } from './css'
209
210
 
210
- export function cssMap(obj){
211
- return (...args) => {
212
- const finalCss = args.reduce((acc, arg) => {
213
- Object.assign(acc, obj[arg]);
214
- return acc;
215
- }, {})
216
- return css(finalCss);
211
+ export function cva(config) {
212
+ const { base = {}, variants = {}, defaultVariants = {} } = config
213
+ return (props) => {
214
+ const computedVariants = { ...defaultVariants, ...compact(props) }
215
+ let result = { ...base }
216
+ for (const [key, value] of Object.entries(computedVariants)) {
217
+ if (variants[key]?.[value]) {
218
+ result = deepMerge(result, variants[key][value])
219
+ }
220
+ }
221
+ return css(result)
217
222
  }
218
223
  }
219
224
  `,
220
225
  dts: outdent3`
221
- import { SystemStyleObject } from "../types"
222
-
223
- export declare function cssMap<T extends string>(obj: Record<T, SystemStyleObject>): (...args: Array<T>) => string;
226
+ import { SystemStyleObject } from '../types'
227
+
228
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T
229
+
230
+ type Variants = Record<string, Record<string, SystemStyleObject>>
231
+
232
+ type VariantSelection<T extends Variants> = {
233
+ [Variant in keyof T]?: StringToBoolean<keyof T[Variant]>
234
+ }
235
+
236
+ type AtomicRecipe<T extends Variants> = {
237
+ base?: SystemStyleObject
238
+ variants?: T | Variants
239
+ defaultVariants?: VariantSelection<T>
240
+ }
241
+
242
+ type VariantFn<T extends Variants> = (props: VariantSelection<T>) => string
243
+
244
+ export type VariantProps<T extends VariantFn<Variants>> = Parameters<T>[0]
245
+
246
+ export declare function cva<T extends Variants>(recipe?: AtomicRecipe<T>): VariantFn<T>
247
+
224
248
  `
225
249
  };
226
250
  }
@@ -296,8 +320,9 @@ function generatePreactJsxFactory(ctx) {
296
320
  import { h } from 'preact'
297
321
  import { forwardRef } from 'preact/compat'
298
322
  import { useMemo } from 'preact/hooks'
299
- import { isCssProperty } from './is-valid-prop'
300
323
  import { css, cx } from '../css'
324
+ import { deepMerge } from '../helpers'
325
+ import { isCssProperty } from './is-valid-prop'
301
326
 
302
327
  const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
303
328
 
@@ -327,8 +352,8 @@ function generatePreactJsxFactory(ctx) {
327
352
  const [styleProps, elementProps] = useMemo(() => splitProps(restProps), [restProps])
328
353
 
329
354
  function classes(){
330
- const { css: cssStyles, ...otherStyles } = styleProps
331
- const atomicClass = css({ ...otherStyles, ...cssStyles })
355
+ const { css: cssStyles, sx: sxStyles, ...otherStyles } = styleProps
356
+ const atomicClass = css(deepMerge(otherStyles, cssStyles, sxStyles))
332
357
  return cx(atomicClass, elementProps.className)
333
358
  }
334
359
 
@@ -505,8 +530,9 @@ function generateReactJsxFactory(ctx) {
505
530
  return {
506
531
  js: outdent9`
507
532
  import { forwardRef, useMemo } from 'react'
508
- import { isCssProperty } from './is-valid-prop'
509
533
  import { css, cx } from '../css'
534
+ import { deepMerge } from '../helpers'
535
+ import { isCssProperty } from './is-valid-prop'
510
536
 
511
537
  const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
512
538
 
@@ -536,8 +562,8 @@ function generateReactJsxFactory(ctx) {
536
562
  const [styleProps, elementProps] = useMemo(() => splitProps(restProps), [restProps])
537
563
 
538
564
  function classes(){
539
- const { css: cssStyles, ...otherStyles } = styleProps
540
- const atomicClass = css({ ...otherStyles, ...cssStyles })
565
+ const { css: cssStyles, sx: sxStyles, ...otherStyles } = styleProps
566
+ const atomicClass = css(deepMerge(otherStyles, cssStyles, sxStyles))
541
567
  return cx(atomicClass, elementProps.className)
542
568
  }
543
569
 
@@ -716,8 +742,9 @@ function generateSolidJsxFactory(ctx) {
716
742
  js: outdent13`
717
743
  import { Dynamic } from 'solid-js/web'
718
744
  import { mergeProps, splitProps } from 'solid-js'
719
- import { allCssProperties } from './is-valid-prop'
720
745
  import { css, cx } from '../css'
746
+ import { deepMerge } from '../helpers'
747
+ import { allCssProperties } from './is-valid-prop'
721
748
 
722
749
  const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
723
750
 
@@ -745,8 +772,8 @@ function generateSolidJsxFactory(ctx) {
745
772
  )
746
773
 
747
774
  const classes = () => {
748
- const { css: cssStyles, ...otherStyles } = styleProps
749
- const atomicClass = css({ ...otherStyles, ...cssStyles })
775
+ const { css: cssStyles, sx: sxStyles, ...otherStyles } = styleProps
776
+ const atomicClass = css(deepMerge(otherStyles, cssStyles, sxStyles))
750
777
  return cx(atomicClass, localProps.class, localProps.className)
751
778
  }
752
779
 
@@ -1048,7 +1075,7 @@ function generatePropTypes(utility, strict) {
1048
1075
  ? ConditionalValue<PropertyTypes[T]${strictText}>
1049
1076
  : T extends keyof CSSProperties
1050
1077
  ? ConditionalValue<CSSProperties[T]>
1051
- : never
1078
+ : ConditionalValue<string | number>
1052
1079
  `;
1053
1080
  }
1054
1081
 
@@ -1372,8 +1399,13 @@ function generateCssType(ctx) {
1372
1399
  `,
1373
1400
  styleProps: outdent22`
1374
1401
  import { PropertyValue } from './prop-type'
1402
+ import { Token } from './token'
1403
+
1404
+ type CssVarProperties = {
1405
+ [key in \`--\${string}\`]?: Token | (string & {}) | (number & {})
1406
+ }
1375
1407
 
1376
- export type SystemProperties = {
1408
+ export type SystemProperties = CssVarProperties & {
1377
1409
  ${Array.from(propList).map((v) => ` ${v}?: PropertyValue<'${v}'>`).join("\n")}
1378
1410
  }
1379
1411
  `
@@ -1442,13 +1474,13 @@ function setupCss(ctx) {
1442
1474
  ]
1443
1475
  };
1444
1476
  }
1445
- function setupCssMap(ctx) {
1446
- const code = generateCssMap();
1477
+ function setupCva(ctx) {
1478
+ const code = generateCvaFn();
1447
1479
  return {
1448
1480
  dir: ctx.paths.css,
1449
1481
  files: [
1450
- { file: "css-map.mjs", code: code.js },
1451
- { file: "css-map.d.ts", code: code.dts }
1482
+ { file: "cva.mjs", code: code.js },
1483
+ { file: "cva.d.ts", code: code.dts }
1452
1484
  ]
1453
1485
  };
1454
1486
  }
@@ -1529,7 +1561,7 @@ function setupCssIndex(ctx) {
1529
1561
  const code = outdent23`
1530
1562
  export * from './css'
1531
1563
  export * from './cx'
1532
- export * from './css-map'
1564
+ export * from './cva'
1533
1565
  `;
1534
1566
  return {
1535
1567
  dir: ctx.paths.css,
@@ -1551,7 +1583,7 @@ function generateSystem(ctx) {
1551
1583
  setupDesignTokens(ctx),
1552
1584
  setupKeyframes(ctx),
1553
1585
  setupTypes(ctx),
1554
- setupCssMap(ctx),
1586
+ setupCva(ctx),
1555
1587
  setupCx(ctx),
1556
1588
  setupCss(ctx),
1557
1589
  setupRecipes(ctx),
@@ -1998,10 +2030,8 @@ function createContext(conf, io = fileSystem) {
1998
2030
  collector.css.forEach((result) => {
1999
2031
  sheet.processAtomic(result.data);
2000
2032
  });
2001
- collector.cssMap.forEach((result) => {
2002
- for (const data of Object.values(result.data)) {
2003
- sheet.processAtomic(data);
2004
- }
2033
+ collector.cva.forEach((result) => {
2034
+ sheet.processAtomicRecipe(result.data);
2005
2035
  });
2006
2036
  collector.jsx.forEach((result) => {
2007
2037
  const { data, type, name } = result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/node",
3
- "version": "0.0.0-dev-20230117105201",
3
+ "version": "0.0.0-dev-20230118114316",
4
4
  "description": "The core css panda library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -30,15 +30,15 @@
30
30
  "telejson": "7.0.4",
31
31
  "ts-pattern": "4.1.3",
32
32
  "ts-morph": "17.0.1",
33
- "@pandacss/types": "0.0.0-dev-20230117105201",
34
- "@pandacss/is-valid-prop": "0.0.0-dev-20230117105201",
35
- "@pandacss/error": "0.0.0-dev-20230117105201",
36
- "@pandacss/parser": "0.0.0-dev-20230117105201",
37
- "@pandacss/shared": "0.0.0-dev-20230117105201",
38
- "@pandacss/token-dictionary": "0.0.0-dev-20230117105201",
39
- "@pandacss/logger": "0.0.0-dev-20230117105201",
40
- "@pandacss/core": "0.0.0-dev-20230117105201",
41
- "@pandacss/config": "0.0.0-dev-20230117105201"
33
+ "@pandacss/types": "0.0.0-dev-20230118114316",
34
+ "@pandacss/is-valid-prop": "0.0.0-dev-20230118114316",
35
+ "@pandacss/error": "0.0.0-dev-20230118114316",
36
+ "@pandacss/parser": "0.0.0-dev-20230118114316",
37
+ "@pandacss/shared": "0.0.0-dev-20230118114316",
38
+ "@pandacss/token-dictionary": "0.0.0-dev-20230118114316",
39
+ "@pandacss/logger": "0.0.0-dev-20230118114316",
40
+ "@pandacss/core": "0.0.0-dev-20230118114316",
41
+ "@pandacss/config": "0.0.0-dev-20230118114316"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/fs-extra": "11.0.1",
@@ -46,7 +46,7 @@
46
46
  "@types/glob-parent": "^5.1.1",
47
47
  "@types/pluralize": "0.0.29",
48
48
  "@types/lodash.merge": "4.6.7",
49
- "@pandacss/fixture": "0.0.0-dev-20230117105201"
49
+ "@pandacss/fixture": "0.0.0-dev-20230118114316"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup src/index.ts --format=cjs,esm --shims --dts",