@pandacss/generator 0.15.2 → 0.15.4
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.
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +249 -162
- package/dist/index.mjs +249 -162
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1023,7 +1023,15 @@ function generateRecipes(ctx) {
|
|
|
1023
1023
|
${ctx.file.import("compact, createCss, withoutSpace", "../helpers")}
|
|
1024
1024
|
|
|
1025
1025
|
export const createRecipe = (name, defaultVariants, compoundVariants) => {
|
|
1026
|
-
|
|
1026
|
+
const getRecipeStyles = (variants) => {
|
|
1027
|
+
return {
|
|
1028
|
+
[name]: '__ignore__',
|
|
1029
|
+
...defaultVariants,
|
|
1030
|
+
...compact(variants),
|
|
1031
|
+
};
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
const recipeFn = (variants, withCompoundVariants = true) => {
|
|
1027
1035
|
const transform = (prop, value) => {
|
|
1028
1036
|
assertCompoundVariant(name, compoundVariants, variants, prop)
|
|
1029
1037
|
|
|
@@ -1043,16 +1051,21 @@ function generateRecipes(ctx) {
|
|
|
1043
1051
|
}
|
|
1044
1052
|
})
|
|
1045
1053
|
|
|
1046
|
-
const recipeStyles =
|
|
1047
|
-
[name]: '__ignore__',
|
|
1048
|
-
...defaultVariants,
|
|
1049
|
-
...compact(variants),
|
|
1050
|
-
}
|
|
1054
|
+
const recipeStyles = getRecipeStyles(variants)
|
|
1051
1055
|
|
|
1052
|
-
|
|
1056
|
+
if (withCompoundVariants) {
|
|
1057
|
+
const compoundVariantStyles = getCompoundVariantCss(compoundVariants, recipeStyles)
|
|
1058
|
+
return cx(recipeCss(recipeStyles), css(compoundVariantStyles))
|
|
1059
|
+
}
|
|
1053
1060
|
|
|
1054
|
-
return
|
|
1061
|
+
return recipeCss(recipeStyles)
|
|
1055
1062
|
}
|
|
1063
|
+
|
|
1064
|
+
return Object.assign(recipeFn, {
|
|
1065
|
+
__getCompoundVariantCss__: (variants) => {
|
|
1066
|
+
return getCompoundVariantCss(compoundVariants, getRecipeStyles(variants));
|
|
1067
|
+
},
|
|
1068
|
+
})
|
|
1056
1069
|
}
|
|
1057
1070
|
`
|
|
1058
1071
|
};
|
|
@@ -1081,6 +1094,7 @@ function generateRecipes(ctx) {
|
|
|
1081
1094
|
|
|
1082
1095
|
export const ${baseName} = Object.assign(${baseName}Fn, {
|
|
1083
1096
|
__recipe__: false,
|
|
1097
|
+
__name__: '${baseName}',
|
|
1084
1098
|
raw: (props) => props,
|
|
1085
1099
|
variantKeys: ${baseName}VariantKeys,
|
|
1086
1100
|
variantMap: ${stringify2(variantKeyMap)},
|
|
@@ -1102,6 +1116,7 @@ function generateRecipes(ctx) {
|
|
|
1102
1116
|
const ${baseName}VariantKeys = Object.keys(${baseName}VariantMap)
|
|
1103
1117
|
export const ${baseName} = Object.assign(${baseName}Fn, {
|
|
1104
1118
|
__recipe__: true,
|
|
1119
|
+
__name__: '${baseName}',
|
|
1105
1120
|
raw: (props) => props,
|
|
1106
1121
|
variantKeys: ${baseName}VariantKeys,
|
|
1107
1122
|
variantMap: ${baseName}VariantMap,
|
|
@@ -1249,38 +1264,51 @@ function generatePreactJsxFactory(ctx) {
|
|
|
1249
1264
|
import { h } from 'preact'
|
|
1250
1265
|
import { forwardRef } from 'preact/compat'
|
|
1251
1266
|
import { useMemo } from 'preact/hooks'
|
|
1252
|
-
${ctx.file.import("css, cx, cva
|
|
1267
|
+
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
1253
1268
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1254
1269
|
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1255
1270
|
|
|
1256
|
-
|
|
1271
|
+
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
1272
|
+
|
|
1273
|
+
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
1257
1274
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
1258
1275
|
|
|
1276
|
+
const forwardFn = options.shouldForwardProp || defaultShouldForwardProp
|
|
1277
|
+
const shouldForwardProp = (prop) => forwardFn(prop, cvaFn.variantKeys)
|
|
1278
|
+
|
|
1279
|
+
const defaultProps = Object.assign(
|
|
1280
|
+
options.dataAttr && configOrCva.__name__ ? { 'data-recipe': configOrCva.__name__ } : {},
|
|
1281
|
+
options.defaultProps,
|
|
1282
|
+
)
|
|
1283
|
+
|
|
1259
1284
|
const ${componentName} = /* @__PURE__ */ forwardRef(function ${componentName}(props, ref) {
|
|
1260
|
-
const { as: Element = Dynamic, ...restProps } = props
|
|
1285
|
+
const { as: Element = Dynamic, children, ...restProps } = props
|
|
1286
|
+
|
|
1287
|
+
const combinedProps = useMemo(() => Object.assign({}, defaultProps, restProps), [restProps])
|
|
1261
1288
|
|
|
1262
|
-
const [variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
1263
|
-
return splitProps(
|
|
1264
|
-
}, [
|
|
1289
|
+
const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
1290
|
+
return splitProps(combinedProps, shouldForwardProp, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1291
|
+
}, [combinedProps])
|
|
1265
1292
|
|
|
1266
1293
|
function recipeClass() {
|
|
1267
1294
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1268
|
-
const
|
|
1269
|
-
return cx(cvaFn(variantProps), css(
|
|
1295
|
+
const compoundVariantStyles = cvaFn.__getCompoundVariantCss__?.(variantProps);
|
|
1296
|
+
return cx(cvaFn(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.class, combinedProps.className)
|
|
1270
1297
|
}
|
|
1271
1298
|
|
|
1272
1299
|
function cvaClass() {
|
|
1273
1300
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1274
1301
|
const cvaStyles = cvaFn.raw(variantProps)
|
|
1275
|
-
|
|
1276
|
-
return cx(css(styles), elementProps.className, elementProps.class)
|
|
1302
|
+
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.class, combinedProps.className)
|
|
1277
1303
|
}
|
|
1278
1304
|
|
|
1279
1305
|
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1280
1306
|
|
|
1281
1307
|
return h(Element, {
|
|
1308
|
+
...forwardedProps,
|
|
1282
1309
|
...elementProps,
|
|
1283
1310
|
...normalizeHTMLProps(htmlProps),
|
|
1311
|
+
children,
|
|
1284
1312
|
ref,
|
|
1285
1313
|
className: classes()
|
|
1286
1314
|
})
|
|
@@ -1362,7 +1390,7 @@ function generatePreactJsxPattern(ctx) {
|
|
|
1362
1390
|
// src/artifacts/preact-jsx/types.ts
|
|
1363
1391
|
import { outdent as outdent16 } from "outdent";
|
|
1364
1392
|
function generatePreactJsxTypes(ctx) {
|
|
1365
|
-
const { factoryName,
|
|
1393
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1366
1394
|
return {
|
|
1367
1395
|
jsxFactory: outdent16`
|
|
1368
1396
|
import type { ${upperName} } from '../types/jsx'
|
|
@@ -1384,18 +1412,26 @@ export interface ${componentName}<T extends ElementType, P extends Dict = {}> {
|
|
|
1384
1412
|
|
|
1385
1413
|
interface RecipeFn = { __type: any }
|
|
1386
1414
|
|
|
1415
|
+
interface JsxFactoryOptions<TProps extends Dict> {
|
|
1416
|
+
dataAttr?: boolean
|
|
1417
|
+
defaultProps?: TProps
|
|
1418
|
+
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
1422
|
+
|
|
1387
1423
|
interface JsxFactory {
|
|
1388
|
-
|
|
1389
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P
|
|
1424
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1425
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): ${componentName}<
|
|
1390
1426
|
T,
|
|
1391
1427
|
RecipeSelection<P>
|
|
1392
1428
|
>
|
|
1393
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1429
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): ${componentName}<T, P['__type']>
|
|
1394
1430
|
}
|
|
1395
1431
|
|
|
1396
1432
|
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
1397
1433
|
|
|
1398
|
-
export type ${upperName} = JsxFactory
|
|
1434
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1399
1435
|
|
|
1400
1436
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
1401
1437
|
`
|
|
@@ -1456,7 +1492,7 @@ function generatePreactJsxStringLiteralFactory(ctx) {
|
|
|
1456
1492
|
// src/artifacts/preact-jsx/types.string-literal.ts
|
|
1457
1493
|
import { outdent as outdent18 } from "outdent";
|
|
1458
1494
|
function generatePreactJsxStringLiteralTypes(ctx) {
|
|
1459
|
-
const { factoryName,
|
|
1495
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1460
1496
|
return {
|
|
1461
1497
|
jsxFactory: outdent18`
|
|
1462
1498
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -1480,7 +1516,7 @@ interface JsxFactory {
|
|
|
1480
1516
|
|
|
1481
1517
|
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K> }
|
|
1482
1518
|
|
|
1483
|
-
export type ${upperName} = JsxFactory
|
|
1519
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1484
1520
|
|
|
1485
1521
|
export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
1486
1522
|
`
|
|
@@ -1494,37 +1530,50 @@ function generateQwikJsxFactory(ctx) {
|
|
|
1494
1530
|
return {
|
|
1495
1531
|
js: outdent19`
|
|
1496
1532
|
import { h } from '@builder.io/qwik'
|
|
1497
|
-
${ctx.file.import("css, cx, cva
|
|
1533
|
+
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
1498
1534
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1499
1535
|
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1500
1536
|
|
|
1501
|
-
|
|
1537
|
+
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
1538
|
+
|
|
1539
|
+
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
1502
1540
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
1503
1541
|
|
|
1542
|
+
const forwardFn = options.shouldForwardProp || defaultShouldForwardProp
|
|
1543
|
+
const shouldForwardProp = (prop) => forwardFn(prop, cvaFn.variantKeys)
|
|
1544
|
+
|
|
1545
|
+
const defaultProps = Object.assign(
|
|
1546
|
+
options.dataAttr && configOrCva.__name__ ? { 'data-recipe': configOrCva.__name__ } : {},
|
|
1547
|
+
options.defaultProps,
|
|
1548
|
+
)
|
|
1549
|
+
|
|
1504
1550
|
const ${componentName} = function ${componentName}(props) {
|
|
1505
|
-
const { as: Element = Dynamic, ...restProps } = props
|
|
1551
|
+
const { as: Element = Dynamic, children, className, ...restProps } = props
|
|
1506
1552
|
|
|
1507
|
-
const
|
|
1508
|
-
|
|
1553
|
+
const combinedProps = Object.assign({}, defaultProps, restProps)
|
|
1554
|
+
|
|
1555
|
+
const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] =
|
|
1556
|
+
splitProps(combinedProps, shouldForwardProp, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1509
1557
|
|
|
1510
1558
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1511
1559
|
|
|
1512
1560
|
function recipeClass() {
|
|
1513
|
-
const
|
|
1514
|
-
return cx(cvaFn(variantProps), css(
|
|
1561
|
+
const compoundVariantStyles = cvaFn.__getCompoundVariantCss__?.(variantProps);
|
|
1562
|
+
return cx(cvaFn(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.class, className)
|
|
1515
1563
|
}
|
|
1516
1564
|
|
|
1517
1565
|
function cvaClass() {
|
|
1518
1566
|
const cvaStyles = cvaFn.raw(variantProps)
|
|
1519
|
-
|
|
1520
|
-
return cx(css(styles), elementProps.class)
|
|
1567
|
+
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.class, className)
|
|
1521
1568
|
}
|
|
1522
1569
|
|
|
1523
1570
|
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1524
1571
|
|
|
1525
1572
|
return h(Element, {
|
|
1573
|
+
...forwardedProps,
|
|
1526
1574
|
...elementProps,
|
|
1527
1575
|
...normalizeHTMLProps(htmlProps),
|
|
1576
|
+
children,
|
|
1528
1577
|
class: classes(),
|
|
1529
1578
|
})
|
|
1530
1579
|
}
|
|
@@ -1605,7 +1654,7 @@ function generateQwikJsxPattern(ctx) {
|
|
|
1605
1654
|
// src/artifacts/qwik-jsx/types.ts
|
|
1606
1655
|
import { outdent as outdent21 } from "outdent";
|
|
1607
1656
|
function generateQwikJsxTypes(ctx) {
|
|
1608
|
-
const { factoryName,
|
|
1657
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1609
1658
|
return {
|
|
1610
1659
|
jsxFactory: outdent21`
|
|
1611
1660
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -1630,18 +1679,26 @@ export interface ${componentName}<T extends ElementType, P extends Dict = {}> ex
|
|
|
1630
1679
|
|
|
1631
1680
|
interface RecipeFn { __type: any }
|
|
1632
1681
|
|
|
1682
|
+
interface JsxFactoryOptions<TProps extends Dict> {
|
|
1683
|
+
dataAttr?: boolean
|
|
1684
|
+
defaultProps?: TProps
|
|
1685
|
+
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
1689
|
+
|
|
1633
1690
|
interface JsxFactory {
|
|
1634
|
-
|
|
1635
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P
|
|
1691
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1692
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): ${componentName}<
|
|
1636
1693
|
T,
|
|
1637
1694
|
RecipeSelection<P>
|
|
1638
1695
|
>
|
|
1639
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1696
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): ${componentName}<T, P['__type']>
|
|
1640
1697
|
}
|
|
1641
1698
|
|
|
1642
1699
|
type JsxElements = { [K in keyof QwikIntrinsicElements]: ${componentName}<K, {}> }
|
|
1643
1700
|
|
|
1644
|
-
export type ${upperName} = JsxFactory
|
|
1701
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1645
1702
|
|
|
1646
1703
|
export type ${typeName}<T extends ElementType> = Assign<ComponentProps<T>, JsxStyleProps>
|
|
1647
1704
|
`
|
|
@@ -1701,7 +1758,7 @@ function generateQwikJsxStringLiteralFactory(ctx) {
|
|
|
1701
1758
|
// src/artifacts/qwik-jsx/types.string-literal.ts
|
|
1702
1759
|
import { outdent as outdent23 } from "outdent";
|
|
1703
1760
|
function generateQwikJsxStringLiteralTypes(ctx) {
|
|
1704
|
-
const { factoryName,
|
|
1761
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1705
1762
|
return {
|
|
1706
1763
|
jsxFactory: outdent23`
|
|
1707
1764
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -1730,7 +1787,7 @@ interface JsxFactory {
|
|
|
1730
1787
|
|
|
1731
1788
|
type JsxElements = { [K in keyof QwikIntrinsicElements]: ${componentName}<K> }
|
|
1732
1789
|
|
|
1733
|
-
export type ${upperName} = JsxFactory
|
|
1790
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1734
1791
|
|
|
1735
1792
|
export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
1736
1793
|
`
|
|
@@ -1739,79 +1796,57 @@ export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
|
1739
1796
|
|
|
1740
1797
|
// src/artifacts/react-jsx/jsx.ts
|
|
1741
1798
|
import { outdent as outdent24 } from "outdent";
|
|
1742
|
-
import { match as match6 } from "ts-pattern";
|
|
1743
1799
|
function generateReactJsxFactory(ctx) {
|
|
1744
1800
|
const { factoryName, componentName } = ctx.jsx;
|
|
1745
1801
|
return {
|
|
1746
1802
|
js: outdent24`
|
|
1747
1803
|
import { createElement, forwardRef, useMemo } from 'react'
|
|
1748
|
-
${ctx.file.import("css, cx, cva
|
|
1804
|
+
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
1749
1805
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1750
|
-
${ctx.
|
|
1806
|
+
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1751
1807
|
|
|
1752
|
-
|
|
1808
|
+
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
1809
|
+
|
|
1810
|
+
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
1753
1811
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
1754
1812
|
|
|
1755
|
-
const
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
}, [restProps])
|
|
1813
|
+
const forwardFn = options.shouldForwardProp || defaultShouldForwardProp
|
|
1814
|
+
const shouldForwardProp = (prop) => forwardFn(prop, cvaFn.variantKeys)
|
|
1815
|
+
|
|
1816
|
+
const defaultProps = Object.assign(
|
|
1817
|
+
options.dataAttr && configOrCva.__name__ ? { 'data-recipe': configOrCva.__name__ } : {},
|
|
1818
|
+
options.defaultProps,
|
|
1819
|
+
)
|
|
1763
1820
|
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
const styles = assignCss(propStyles, cssStyles)
|
|
1767
|
-
return cx(cvaFn(variantProps), css(styles), elementProps.className)
|
|
1768
|
-
}
|
|
1821
|
+
const ${componentName} = /* @__PURE__ */ forwardRef(function ${componentName}(props, ref) {
|
|
1822
|
+
const { as: Element = Dynamic, children, ...restProps } = props
|
|
1769
1823
|
|
|
1770
|
-
|
|
1771
|
-
const { css: cssStyles, ...propStyles } = styleProps
|
|
1772
|
-
const cvaStyles = cvaFn.raw(variantProps)
|
|
1773
|
-
const styles = assignCss(cvaStyles, propStyles, cssStyles)
|
|
1774
|
-
return cx(css(styles), elementProps.className)
|
|
1775
|
-
}`;
|
|
1776
|
-
}).with("minimal", () => {
|
|
1777
|
-
return outdent24`
|
|
1778
|
-
const [variantProps, htmlProps, elementProps] = useMemo(() => {
|
|
1779
|
-
return splitProps(restProps, cvaFn.variantKeys, normalizeHTMLProps.keys)
|
|
1780
|
-
}, [restProps])
|
|
1781
|
-
|
|
1782
|
-
function recipeClass() {
|
|
1783
|
-
return cx(cvaFn(variantProps), css(assignCss(elementProps.css)), elementProps.className)
|
|
1784
|
-
}
|
|
1824
|
+
const combinedProps = useMemo(() => Object.assign({}, defaultProps, restProps), [restProps])
|
|
1785
1825
|
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
return cx(css(styles), elementProps.className)
|
|
1790
|
-
}`;
|
|
1791
|
-
}).with("none", () => {
|
|
1792
|
-
return outdent24`
|
|
1793
|
-
const [variantProps, htmlProps, elementProps] = useMemo(() => {
|
|
1794
|
-
return splitProps(restProps, cvaFn.variantKeys, normalizeHTMLProps.keys)
|
|
1795
|
-
}, [restProps])
|
|
1796
|
-
|
|
1797
|
-
function recipeClass() {
|
|
1798
|
-
return cx(cvaFn(variantProps), elementProps.className)
|
|
1799
|
-
}
|
|
1826
|
+
const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
1827
|
+
return splitProps(combinedProps, shouldForwardProp, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1828
|
+
}, [combinedProps])
|
|
1800
1829
|
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
}).run()}
|
|
1830
|
+
function recipeClass() {
|
|
1831
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1832
|
+
const compoundVariantStyles = cvaFn.__getCompoundVariantCss__?.(variantProps);
|
|
1833
|
+
return cx(cvaFn(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.className)
|
|
1834
|
+
}
|
|
1807
1835
|
|
|
1836
|
+
function cvaClass() {
|
|
1837
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1838
|
+
const cvaStyles = cvaFn.raw(variantProps)
|
|
1839
|
+
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.className)
|
|
1840
|
+
}
|
|
1808
1841
|
|
|
1809
1842
|
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1810
1843
|
|
|
1811
1844
|
return createElement(Element, {
|
|
1812
1845
|
ref,
|
|
1846
|
+
...forwardedProps,
|
|
1813
1847
|
...elementProps,
|
|
1814
1848
|
...normalizeHTMLProps(htmlProps),
|
|
1849
|
+
children,
|
|
1815
1850
|
className: classes(),
|
|
1816
1851
|
})
|
|
1817
1852
|
})
|
|
@@ -1845,7 +1880,7 @@ function generateReactJsxFactory(ctx) {
|
|
|
1845
1880
|
|
|
1846
1881
|
// src/artifacts/react-jsx/pattern.ts
|
|
1847
1882
|
import { outdent as outdent25 } from "outdent";
|
|
1848
|
-
import { match as
|
|
1883
|
+
import { match as match6 } from "ts-pattern";
|
|
1849
1884
|
function generateReactJsxPattern(ctx) {
|
|
1850
1885
|
const { typeName, factoryName } = ctx.jsx;
|
|
1851
1886
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -1859,7 +1894,7 @@ function generateReactJsxPattern(ctx) {
|
|
|
1859
1894
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1860
1895
|
|
|
1861
1896
|
export const ${jsxName} = /* @__PURE__ */ forwardRef(function ${jsxName}(props, ref) {
|
|
1862
|
-
${
|
|
1897
|
+
${match6(props.length).with(
|
|
1863
1898
|
0,
|
|
1864
1899
|
() => outdent25`
|
|
1865
1900
|
const styleProps = ${styleFnName}()
|
|
@@ -1892,7 +1927,7 @@ function generateReactJsxPattern(ctx) {
|
|
|
1892
1927
|
// src/artifacts/react-jsx/types.ts
|
|
1893
1928
|
import { outdent as outdent26 } from "outdent";
|
|
1894
1929
|
function generateReactJsxTypes(ctx) {
|
|
1895
|
-
const { factoryName,
|
|
1930
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1896
1931
|
return {
|
|
1897
1932
|
jsxFactory: outdent26`
|
|
1898
1933
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -1916,18 +1951,26 @@ export interface ${componentName}<T extends ElementType, P extends Dict = {}> {
|
|
|
1916
1951
|
|
|
1917
1952
|
interface RecipeFn { __type: any }
|
|
1918
1953
|
|
|
1954
|
+
interface JsxFactoryOptions<TProps extends Dict> {
|
|
1955
|
+
dataAttr?: boolean
|
|
1956
|
+
defaultProps?: TProps
|
|
1957
|
+
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
1961
|
+
|
|
1919
1962
|
interface JsxFactory {
|
|
1920
|
-
|
|
1921
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P
|
|
1963
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1964
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): ${componentName}<
|
|
1922
1965
|
T,
|
|
1923
1966
|
RecipeSelection<P>
|
|
1924
1967
|
>
|
|
1925
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1968
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): ${componentName}<T, P['__type']>
|
|
1926
1969
|
}
|
|
1927
1970
|
|
|
1928
1971
|
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
1929
1972
|
|
|
1930
|
-
export type ${upperName} = JsxFactory
|
|
1973
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1931
1974
|
|
|
1932
1975
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
1933
1976
|
`
|
|
@@ -1988,7 +2031,7 @@ function generateReactJsxStringLiteralFactory(ctx) {
|
|
|
1988
2031
|
// src/artifacts/react-jsx/types.string-literal.ts
|
|
1989
2032
|
import { outdent as outdent28 } from "outdent";
|
|
1990
2033
|
function generateReactJsxStringLiteralTypes(ctx) {
|
|
1991
|
-
const { factoryName,
|
|
2034
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1992
2035
|
return {
|
|
1993
2036
|
jsxFactory: outdent28`
|
|
1994
2037
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -2015,7 +2058,7 @@ interface JsxFactory {
|
|
|
2015
2058
|
|
|
2016
2059
|
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K> }
|
|
2017
2060
|
|
|
2018
|
-
export type ${upperName} = JsxFactory
|
|
2061
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
2019
2062
|
|
|
2020
2063
|
export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
2021
2064
|
`
|
|
@@ -2029,21 +2072,33 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2029
2072
|
return {
|
|
2030
2073
|
js: outdent29`
|
|
2031
2074
|
import { Dynamic } from 'solid-js/web'
|
|
2032
|
-
import { mergeProps, splitProps } from 'solid-js'
|
|
2075
|
+
import { createMemo, mergeProps, splitProps } from 'solid-js'
|
|
2033
2076
|
import { createComponent } from 'solid-js/web'
|
|
2034
|
-
${ctx.file.import("css, cx, cva
|
|
2077
|
+
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
2035
2078
|
${ctx.file.import("normalizeHTMLProps", "../helpers")}
|
|
2036
|
-
${ctx.file.import("allCssProperties", "./is-valid-prop")}
|
|
2037
|
-
|
|
2038
|
-
|
|
2079
|
+
${ctx.file.import("isCssProperty, allCssProperties", "./is-valid-prop")}
|
|
2080
|
+
|
|
2081
|
+
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
2082
|
+
|
|
2083
|
+
function styledFn(element, configOrCva = {}, options = {}) {
|
|
2039
2084
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
2040
2085
|
|
|
2086
|
+
const forwardFn = options.shouldForwardProp || defaultShouldForwardProp
|
|
2087
|
+
const shouldForwardProp = (prop) => forwardFn(prop, cvaFn.variantKeys)
|
|
2088
|
+
|
|
2089
|
+
const defaultProps = Object.assign(
|
|
2090
|
+
options.dataAttr && configOrCva.__name__ ? { 'data-recipe': configOrCva.__name__ } : {},
|
|
2091
|
+
options.defaultProps,
|
|
2092
|
+
)
|
|
2093
|
+
|
|
2041
2094
|
return function ${componentName}(props) {
|
|
2042
|
-
const mergedProps = mergeProps({ as: element }, props)
|
|
2095
|
+
const mergedProps = mergeProps({ as: element }, defaultProps, props)
|
|
2096
|
+
const forwardedKeys = createMemo(() => Object.keys(props).filter(shouldForwardProp))
|
|
2043
2097
|
|
|
2044
|
-
const [localProps, variantProps, styleProps, htmlProps, elementProps] = splitProps(
|
|
2098
|
+
const [localProps, forwardedProps, variantProps, styleProps, htmlProps, elementProps] = splitProps(
|
|
2045
2099
|
mergedProps,
|
|
2046
|
-
['as', 'class'],
|
|
2100
|
+
['as', 'class', 'className'],
|
|
2101
|
+
forwardedKeys(),
|
|
2047
2102
|
cvaFn.variantKeys,
|
|
2048
2103
|
allCssProperties,
|
|
2049
2104
|
normalizeHTMLProps.keys
|
|
@@ -2051,22 +2106,28 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2051
2106
|
|
|
2052
2107
|
function recipeClass() {
|
|
2053
2108
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2054
|
-
const
|
|
2055
|
-
return cx(cvaFn(variantProps), css(
|
|
2109
|
+
const compoundVariantStyles = cvaFn.__getCompoundVariantCss__?.(variantProps);
|
|
2110
|
+
return cx(cvaFn(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), localProps.class, localProps.className)
|
|
2056
2111
|
}
|
|
2057
2112
|
|
|
2058
2113
|
function cvaClass() {
|
|
2059
2114
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2060
2115
|
const cvaStyles = cvaFn.raw(variantProps)
|
|
2061
|
-
|
|
2062
|
-
return cx(css(styles), localProps.class)
|
|
2116
|
+
return cx(css(cvaStyles, propStyles, cssStyles), localProps.class, localProps.className)
|
|
2063
2117
|
}
|
|
2064
2118
|
|
|
2065
2119
|
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
2066
2120
|
|
|
2121
|
+
if (forwardedProps.className) {
|
|
2122
|
+
delete forwardedProps.className
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2067
2125
|
return createComponent(
|
|
2068
2126
|
Dynamic,
|
|
2069
2127
|
mergeProps(
|
|
2128
|
+
forwardedProps,
|
|
2129
|
+
elementProps,
|
|
2130
|
+
normalizeHTMLProps(htmlProps),
|
|
2070
2131
|
{
|
|
2071
2132
|
get component() {
|
|
2072
2133
|
return localProps.as
|
|
@@ -2075,8 +2136,6 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2075
2136
|
return classes()
|
|
2076
2137
|
}
|
|
2077
2138
|
},
|
|
2078
|
-
elementProps,
|
|
2079
|
-
normalizeHTMLProps(htmlProps)
|
|
2080
2139
|
)
|
|
2081
2140
|
)
|
|
2082
2141
|
}
|
|
@@ -2105,7 +2164,7 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2105
2164
|
|
|
2106
2165
|
// src/artifacts/solid-jsx/pattern.ts
|
|
2107
2166
|
import { outdent as outdent30 } from "outdent";
|
|
2108
|
-
import { match as
|
|
2167
|
+
import { match as match7 } from "ts-pattern";
|
|
2109
2168
|
function generateSolidJsxPattern(ctx) {
|
|
2110
2169
|
const { typeName, factoryName } = ctx.jsx;
|
|
2111
2170
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -2120,7 +2179,7 @@ function generateSolidJsxPattern(ctx) {
|
|
|
2120
2179
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
2121
2180
|
|
|
2122
2181
|
export function ${jsxName}(props) {
|
|
2123
|
-
${
|
|
2182
|
+
${match7(props.length).with(
|
|
2124
2183
|
0,
|
|
2125
2184
|
() => outdent30`
|
|
2126
2185
|
const styleProps = ${styleFnName}()
|
|
@@ -2153,7 +2212,7 @@ function generateSolidJsxPattern(ctx) {
|
|
|
2153
2212
|
// src/artifacts/solid-jsx/types.ts
|
|
2154
2213
|
import { outdent as outdent31 } from "outdent";
|
|
2155
2214
|
function generateSolidJsxTypes(ctx) {
|
|
2156
|
-
const { factoryName,
|
|
2215
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
2157
2216
|
return {
|
|
2158
2217
|
jsxFactory: outdent31`
|
|
2159
2218
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -2175,18 +2234,26 @@ export interface ${componentName}<T extends ElementType, P extends Dict = {}> {
|
|
|
2175
2234
|
|
|
2176
2235
|
interface RecipeFn { __type: any }
|
|
2177
2236
|
|
|
2237
|
+
interface JsxFactoryOptions<TProps extends Dict> {
|
|
2238
|
+
dataAttr?: boolean
|
|
2239
|
+
defaultProps?: TProps
|
|
2240
|
+
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
2244
|
+
|
|
2178
2245
|
interface JsxFactory {
|
|
2179
|
-
|
|
2180
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P
|
|
2246
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
2247
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): ${componentName}<
|
|
2181
2248
|
T,
|
|
2182
2249
|
RecipeSelection<P>
|
|
2183
2250
|
>
|
|
2184
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
2251
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): ${componentName}<T, P['__type']>
|
|
2185
2252
|
}
|
|
2186
2253
|
|
|
2187
2254
|
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
2188
2255
|
|
|
2189
|
-
export type ${upperName} = JsxFactory
|
|
2256
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
2190
2257
|
|
|
2191
2258
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
2192
2259
|
`
|
|
@@ -2252,7 +2319,7 @@ export const ${factoryName} = /* @__PURE__ */ createJsxFactory()
|
|
|
2252
2319
|
// src/artifacts/solid-jsx/types.string-literal.ts
|
|
2253
2320
|
import { outdent as outdent33 } from "outdent";
|
|
2254
2321
|
function generateSolidJsxStringLiteralTypes(ctx) {
|
|
2255
|
-
const { factoryName,
|
|
2322
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
2256
2323
|
return {
|
|
2257
2324
|
jsxFactory: outdent33`
|
|
2258
2325
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -2276,7 +2343,7 @@ interface JsxFactory {
|
|
|
2276
2343
|
|
|
2277
2344
|
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K> }
|
|
2278
2345
|
|
|
2279
|
-
export type ${upperName} = JsxFactory
|
|
2346
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
2280
2347
|
|
|
2281
2348
|
export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
2282
2349
|
`
|
|
@@ -2290,12 +2357,23 @@ function generateVueJsxFactory(ctx) {
|
|
|
2290
2357
|
return {
|
|
2291
2358
|
js: outdent34`
|
|
2292
2359
|
import { defineComponent, h, computed } from 'vue'
|
|
2293
|
-
${ctx.file.import("css, cx, cva
|
|
2360
|
+
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
2294
2361
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
2295
2362
|
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
2296
2363
|
|
|
2297
|
-
|
|
2364
|
+
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
2365
|
+
|
|
2366
|
+
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
2298
2367
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
2368
|
+
|
|
2369
|
+
const forwardFn = options.shouldForwardProp || defaultShouldForwardProp
|
|
2370
|
+
const shouldForwardProp = (prop) => forwardFn(prop, cvaFn.variantKeys)
|
|
2371
|
+
|
|
2372
|
+
const defaultProps = Object.assign(
|
|
2373
|
+
options.dataAttr && configOrCva.__name__ ? { 'data-recipe': configOrCva.__name__ } : {},
|
|
2374
|
+
options.defaultProps,
|
|
2375
|
+
)
|
|
2376
|
+
|
|
2299
2377
|
const name = (typeof Dynamic === 'string' ? Dynamic : Dynamic.displayName || Dynamic.name) || 'Component'
|
|
2300
2378
|
|
|
2301
2379
|
return defineComponent({
|
|
@@ -2303,35 +2381,37 @@ function generateVueJsxFactory(ctx) {
|
|
|
2303
2381
|
inheritAttrs: false,
|
|
2304
2382
|
props: { as: { type: [String, Object], default: Dynamic } },
|
|
2305
2383
|
setup(props, { slots, attrs }) {
|
|
2384
|
+
const combinedProps = computed(() => Object.assign({}, defaultProps, attrs))
|
|
2385
|
+
|
|
2306
2386
|
const splittedProps = computed(() => {
|
|
2307
|
-
return splitProps(
|
|
2387
|
+
return splitProps(combinedProps.value, shouldForwardProp, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
2308
2388
|
})
|
|
2309
2389
|
|
|
2310
2390
|
const recipeClass = computed(() => {
|
|
2311
|
-
const [variantProps, styleProps, _htmlProps,
|
|
2391
|
+
const [_forwardedProps, variantProps, styleProps, _htmlProps, _elementProps] = splittedProps.value
|
|
2312
2392
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2313
|
-
const
|
|
2314
|
-
return cx(cvaFn(variantProps), css(
|
|
2393
|
+
const compoundVariantStyles = cvaFn.__getCompoundVariantCss__?.(variantProps);
|
|
2394
|
+
return cx(cvaFn(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.value.className)
|
|
2315
2395
|
})
|
|
2316
2396
|
|
|
2317
2397
|
const cvaClass = computed(() => {
|
|
2318
|
-
const [variantProps, styleProps, _htmlProps,
|
|
2398
|
+
const [_forwardedProps, variantProps, styleProps, _htmlProps, _elementProps] = splittedProps.value
|
|
2319
2399
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2320
|
-
const
|
|
2321
|
-
return cx(
|
|
2400
|
+
const cvaStyles = cvaFn.raw(variantProps)
|
|
2401
|
+
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.value.className)
|
|
2322
2402
|
})
|
|
2323
2403
|
|
|
2324
2404
|
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
2325
2405
|
|
|
2326
2406
|
return () => {
|
|
2327
|
-
const [
|
|
2328
|
-
|
|
2407
|
+
const [forwardedProps, _variantProps, _styleProps, htmlProps, elementProps] = splittedProps.value
|
|
2329
2408
|
return h(
|
|
2330
2409
|
props.as,
|
|
2331
2410
|
{
|
|
2332
|
-
|
|
2411
|
+
...forwardedProps.value,
|
|
2333
2412
|
...elementProps,
|
|
2334
2413
|
...normalizeHTMLProps(htmlProps),
|
|
2414
|
+
class: classes.value,
|
|
2335
2415
|
},
|
|
2336
2416
|
slots.default && slots.default(),
|
|
2337
2417
|
)
|
|
@@ -2341,17 +2421,12 @@ function generateVueJsxFactory(ctx) {
|
|
|
2341
2421
|
}
|
|
2342
2422
|
|
|
2343
2423
|
function createJsxFactory() {
|
|
2344
|
-
const cache = new Map()
|
|
2345
|
-
|
|
2346
2424
|
return new Proxy(styledFn, {
|
|
2347
2425
|
apply(_, __, args) {
|
|
2348
2426
|
return styledFn(...args)
|
|
2349
2427
|
},
|
|
2350
2428
|
get(_, el) {
|
|
2351
|
-
|
|
2352
|
-
cache.set(el, styledFn(el))
|
|
2353
|
-
}
|
|
2354
|
-
return cache.get(el)
|
|
2429
|
+
return styledFn(el)
|
|
2355
2430
|
},
|
|
2356
2431
|
})
|
|
2357
2432
|
}
|
|
@@ -2464,7 +2539,7 @@ function generateVueJsxPattern(ctx) {
|
|
|
2464
2539
|
// src/artifacts/vue-jsx/types.ts
|
|
2465
2540
|
import { outdent as outdent37 } from "outdent";
|
|
2466
2541
|
function generateVueJsxTypes(ctx) {
|
|
2467
|
-
const { factoryName,
|
|
2542
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
2468
2543
|
return {
|
|
2469
2544
|
jsxFactory: outdent37`
|
|
2470
2545
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -2492,18 +2567,26 @@ JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P>>
|
|
|
2492
2567
|
|
|
2493
2568
|
interface RecipeFn = { __type: any }
|
|
2494
2569
|
|
|
2570
|
+
interface JsxFactoryOptions<TProps extends Dict> {
|
|
2571
|
+
dataAttr?: boolean
|
|
2572
|
+
defaultProps?: TProps
|
|
2573
|
+
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
export type JsxRecipeProps<T extends ElementType, P extends RecipeFn> = JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P['__type']>>;
|
|
2577
|
+
|
|
2495
2578
|
interface JsxFactory {
|
|
2496
|
-
|
|
2497
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P
|
|
2579
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
2580
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): ${componentName}<
|
|
2498
2581
|
T,
|
|
2499
2582
|
RecipeSelection<P>
|
|
2500
2583
|
>
|
|
2501
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
2584
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>> ): ${componentName}<T, P['__type']>
|
|
2502
2585
|
}
|
|
2503
2586
|
|
|
2504
2587
|
type JsxElements = { [K in IntrinsicElement]: ${componentName}<K, {}> }
|
|
2505
2588
|
|
|
2506
|
-
export type ${upperName} = JsxFactory
|
|
2589
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
2507
2590
|
|
|
2508
2591
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
2509
2592
|
`
|
|
@@ -2513,7 +2596,7 @@ export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>,
|
|
|
2513
2596
|
// src/artifacts/vue-jsx/types.string-literal.ts
|
|
2514
2597
|
import { outdent as outdent38 } from "outdent";
|
|
2515
2598
|
function generateVueJsxStringLiteralTypes(ctx) {
|
|
2516
|
-
const { factoryName,
|
|
2599
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
2517
2600
|
return {
|
|
2518
2601
|
jsxFactory: outdent38`
|
|
2519
2602
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
@@ -2541,7 +2624,7 @@ interface JsxFactory {
|
|
|
2541
2624
|
|
|
2542
2625
|
type JsxElements = { [K in IntrinsicElement]: ${componentName}<K> }
|
|
2543
2626
|
|
|
2544
|
-
export type ${upperName} = JsxFactory
|
|
2627
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
2545
2628
|
|
|
2546
2629
|
export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
2547
2630
|
`
|
|
@@ -2666,7 +2749,7 @@ var composition_d_ts_default = {
|
|
|
2666
2749
|
|
|
2667
2750
|
// src/artifacts/generated/recipe.d.ts.json
|
|
2668
2751
|
var recipe_d_ts_default = {
|
|
2669
|
-
content: "import type { SystemStyleObject, DistributiveOmit } from './system-types'\n\ntype Pretty<T> = { [K in keyof T]: T[K] } & {}\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T\n\nexport type RecipeVariantRecord = Record<any, Record<any, SystemStyleObject>>\n\nexport type RecipeSelection<T extends RecipeVariantRecord> = keyof any extends keyof T\n ? {}\n : {\n [K in keyof T]?: StringToBoolean<keyof T[K]>\n }\n\nexport type RecipeVariantFn<T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => string\n\nexport type RecipeVariantProps<\n T extends RecipeVariantFn<RecipeVariantRecord> | SlotRecipeVariantFn<string, SlotRecipeVariantRecord<string>>,\n> = Pretty<Parameters<T>[0]>\n\ntype RecipeVariantMap<T extends RecipeVariantRecord> = {\n [K in keyof T]: Array<keyof T[K]>\n}\n\n/* -----------------------------------------------------------------------------\n * Recipe / Standard\n * -----------------------------------------------------------------------------*/\n\nexport interface RecipeRuntimeFn<T extends RecipeVariantRecord> extends RecipeVariantFn<T> {\n __type: RecipeSelection<T>\n variantKeys: (keyof T)[]\n variantMap: RecipeVariantMap<T>\n raw: (props?: RecipeSelection<T>) => SystemStyleObject\n config: RecipeConfig<T>\n splitVariantProps<Props extends RecipeSelection<T>>(\n props: Props,\n ): [RecipeSelection<T>, Pretty<DistributiveOmit<Props, keyof T>>]\n}\n\nexport type RecipeCompoundSelection<T
|
|
2752
|
+
content: "import type { SystemStyleObject, DistributiveOmit } from './system-types'\n\ntype Pretty<T> = { [K in keyof T]: T[K] } & {}\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T\n\nexport type RecipeVariantRecord = Record<any, Record<any, SystemStyleObject>>\n\nexport type RecipeSelection<T extends RecipeVariantRecord> = keyof any extends keyof T\n ? {}\n : {\n [K in keyof T]?: StringToBoolean<keyof T[K]>\n }\n\nexport type RecipeVariantFn<T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => string\n\nexport type RecipeVariantProps<\n T extends RecipeVariantFn<RecipeVariantRecord> | SlotRecipeVariantFn<string, SlotRecipeVariantRecord<string>>,\n> = Pretty<Parameters<T>[0]>\n\ntype RecipeVariantMap<T extends RecipeVariantRecord> = {\n [K in keyof T]: Array<keyof T[K]>\n}\n\n/* -----------------------------------------------------------------------------\n * Recipe / Standard\n * -----------------------------------------------------------------------------*/\n\nexport interface RecipeRuntimeFn<T extends RecipeVariantRecord> extends RecipeVariantFn<T> {\n __type: RecipeSelection<T>\n variantKeys: (keyof T)[]\n variantMap: RecipeVariantMap<T>\n raw: (props?: RecipeSelection<T>) => SystemStyleObject\n config: RecipeConfig<T>\n splitVariantProps<Props extends RecipeSelection<T>>(\n props: Props,\n ): [RecipeSelection<T>, Pretty<DistributiveOmit<Props, keyof T>>]\n}\n\ntype OneOrMore<T> = T | Array<T>\n\nexport type RecipeCompoundSelection<T> = {\n [K in keyof T]?: OneOrMore<StringToBoolean<keyof T[K]>>\n}\n\nexport type RecipeCompoundVariant<T> = T & {\n css: SystemStyleObject\n}\n\nexport interface RecipeDefinition<T extends RecipeVariantRecord> {\n /**\n * The base styles of the recipe.\n */\n base?: SystemStyleObject\n /**\n * The multi-variant styles of the recipe.\n */\n variants?: T\n /**\n * The default variants of the recipe.\n */\n defaultVariants?: RecipeSelection<T>\n /**\n * The styles to apply when a combination of variants is selected.\n */\n compoundVariants?: Pretty<RecipeCompoundVariant<RecipeCompoundSelection<T>>>[]\n}\n\nexport type RecipeCreatorFn = <T extends RecipeVariantRecord>(config: RecipeDefinition<T>) => RecipeRuntimeFn<T>\n\ninterface RecipeConfigMeta {\n /**\n * The name of the recipe.\n */\n className: string\n /**\n * The description of the recipe. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The jsx elements to track for this recipe. Can be string or Regexp.\n *\n * @default capitalize(recipe.name)\n * @example ['Button', 'Link', /Button$/]\n */\n jsx?: Array<string | RegExp>\n}\n\nexport interface RecipeConfig<T extends RecipeVariantRecord = RecipeVariantRecord>\n extends RecipeDefinition<T>,\n RecipeConfigMeta {}\n\n/* -----------------------------------------------------------------------------\n * Recipe / Slot\n * -----------------------------------------------------------------------------*/\n\ntype SlotRecord<S extends string, T> = Partial<Record<S, T>>\n\nexport type SlotRecipeVariantRecord<S extends string> = Record<any, Record<any, SlotRecord<S, SystemStyleObject>>>\n\nexport type SlotRecipeVariantFn<S extends string, T extends RecipeVariantRecord> = (\n props?: RecipeSelection<T>,\n) => SlotRecord<S, string>\n\nexport interface SlotRecipeRuntimeFn<S extends string, T extends SlotRecipeVariantRecord<S>>\n extends SlotRecipeVariantFn<S, T> {\n raw: (props?: RecipeSelection<T>) => Record<S, SystemStyleObject>\n variantKeys: (keyof T)[]\n variantMap: RecipeVariantMap<T>\n splitVariantProps<Props extends RecipeSelection<T>>(props: Props): [RecipeSelection<T>, Pretty<Omit<Props, keyof T>>]\n}\n\nexport type SlotRecipeCompoundVariant<S extends string, T> = T & {\n css: SlotRecord<S, SystemStyleObject>\n}\n\nexport interface SlotRecipeDefinition<S extends string, T extends SlotRecipeVariantRecord<S>> {\n /**\n * The parts/slots of the recipe.\n */\n slots: S[] | Readonly<S[]>\n /**\n * The base styles of the recipe.\n */\n base?: SlotRecord<S, SystemStyleObject>\n /**\n * The multi-variant styles of the recipe.\n */\n variants?: T\n /**\n * The default variants of the recipe.\n */\n defaultVariants?: RecipeSelection<T>\n /**\n * The styles to apply when a combination of variants is selected.\n */\n compoundVariants?: Pretty<SlotRecipeCompoundVariant<S, RecipeCompoundSelection<T>>>[]\n}\n\nexport type SlotRecipeCreatorFn = <S extends string, T extends SlotRecipeVariantRecord<S>>(\n config: SlotRecipeDefinition<S, T>,\n) => SlotRecipeRuntimeFn<S, T>\n\nexport type SlotRecipeConfig<\n S extends string = string,\n T extends SlotRecipeVariantRecord<S> = SlotRecipeVariantRecord<S>,\n> = SlotRecipeDefinition<S, T> & RecipeConfigMeta\n"
|
|
2670
2753
|
};
|
|
2671
2754
|
|
|
2672
2755
|
// src/artifacts/generated/pattern.d.ts.json
|
|
@@ -2685,7 +2768,7 @@ var selectors_d_ts_default = {
|
|
|
2685
2768
|
};
|
|
2686
2769
|
|
|
2687
2770
|
// src/artifacts/types/generated.ts
|
|
2688
|
-
import { match as
|
|
2771
|
+
import { match as match8 } from "ts-pattern";
|
|
2689
2772
|
var jsxStyleProps = "export type JsxStyleProps = StyleProps & WithCss";
|
|
2690
2773
|
function getGeneratedTypes(ctx) {
|
|
2691
2774
|
const rewriteImports = (code) => code.replace(/import\s+type\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g, ctx.file.importType("$1", "$2"));
|
|
@@ -2697,7 +2780,7 @@ function getGeneratedTypes(ctx) {
|
|
|
2697
2780
|
composition: rewriteImports(composition_d_ts_default.content),
|
|
2698
2781
|
selectors: rewriteImports(selectors_d_ts_default.content),
|
|
2699
2782
|
system: rewriteImports(
|
|
2700
|
-
|
|
2783
|
+
match8(ctx.jsx.styleProps).with("all", () => system_types_d_ts_default.content).with("minimal", () => system_types_d_ts_default.content.replace(jsxStyleProps, "export type JsxStyleProps = WithCss")).with("none", () => system_types_d_ts_default.content.replace(jsxStyleProps, "export type JsxStyleProps = {}")).exhaustive()
|
|
2701
2784
|
)
|
|
2702
2785
|
};
|
|
2703
2786
|
}
|
|
@@ -3145,7 +3228,7 @@ var generateFlattenedCss = (ctx) => (options) => {
|
|
|
3145
3228
|
// src/artifacts/css/parser-css.ts
|
|
3146
3229
|
import { logger } from "@pandacss/logger";
|
|
3147
3230
|
import { pipe, tap, tryCatch } from "lil-fp/func";
|
|
3148
|
-
import { P, match as
|
|
3231
|
+
import { P, match as match9 } from "ts-pattern";
|
|
3149
3232
|
var generateParserCss = (ctx) => (result) => pipe(
|
|
3150
3233
|
{ ...ctx, sheet: ctx.createSheet(), result },
|
|
3151
3234
|
tap(({ sheet, result: result2, patterns, recipes }) => {
|
|
@@ -3175,7 +3258,7 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
3175
3258
|
const recipeConfig = recipes.getConfig(recipeName);
|
|
3176
3259
|
if (!recipeConfig)
|
|
3177
3260
|
continue;
|
|
3178
|
-
|
|
3261
|
+
match9(recipe).with({ type: "jsx-recipe" }, () => {
|
|
3179
3262
|
recipe.data.forEach((data) => {
|
|
3180
3263
|
const [recipeProps, styleProps] = recipes.splitProps(recipeName, data);
|
|
3181
3264
|
sheet.processStyleProps(filterProps(ctx, styleProps));
|
|
@@ -3194,7 +3277,7 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
3194
3277
|
result2.pattern.forEach((patternSet, name) => {
|
|
3195
3278
|
try {
|
|
3196
3279
|
for (const pattern of patternSet) {
|
|
3197
|
-
|
|
3280
|
+
match9(pattern).with({ type: "jsx-pattern", name: P.string }, ({ name: jsxName }) => {
|
|
3198
3281
|
pattern.data.forEach((data) => {
|
|
3199
3282
|
const fnName = patterns.find(jsxName);
|
|
3200
3283
|
const styleProps = patterns.transform(fnName, data);
|
|
@@ -3405,6 +3488,7 @@ var getPatternEngine = (config) => {
|
|
|
3405
3488
|
};
|
|
3406
3489
|
});
|
|
3407
3490
|
return {
|
|
3491
|
+
keys: Object.keys(patterns),
|
|
3408
3492
|
getConfig: (name) => patterns[name],
|
|
3409
3493
|
transform: (name, data) => {
|
|
3410
3494
|
return patterns[name]?.transform?.(data, helpers2) ?? {};
|
|
@@ -3484,11 +3568,11 @@ var defaults = (conf) => ({
|
|
|
3484
3568
|
}
|
|
3485
3569
|
}
|
|
3486
3570
|
});
|
|
3487
|
-
var getImportMap = (outdir) => ({
|
|
3488
|
-
css: [outdir, "css"],
|
|
3489
|
-
recipe: [outdir, "recipes"],
|
|
3490
|
-
pattern: [outdir, "patterns"],
|
|
3491
|
-
jsx: [outdir, "jsx"]
|
|
3571
|
+
var getImportMap = (outdir, configImportMap) => ({
|
|
3572
|
+
css: configImportMap?.css ? [configImportMap.css] : [outdir, "css"],
|
|
3573
|
+
recipe: configImportMap?.recipes ? [configImportMap.recipes] : [outdir, "recipes"],
|
|
3574
|
+
pattern: configImportMap?.patterns ? [configImportMap.patterns] : [outdir, "patterns"],
|
|
3575
|
+
jsx: configImportMap?.jsx ? [configImportMap.jsx] : [outdir, "jsx"]
|
|
3492
3576
|
});
|
|
3493
3577
|
var createGenerator = (conf) => {
|
|
3494
3578
|
const ctx = getEngine(defaults(conf));
|
|
@@ -3504,13 +3588,16 @@ var createGenerator = (conf) => {
|
|
|
3504
3588
|
getParserCss: generateParserCss(ctx),
|
|
3505
3589
|
messages: getMessages(ctx),
|
|
3506
3590
|
parserOptions: {
|
|
3507
|
-
importMap: getImportMap(config.outdir.replace(relativeBaseUrl, "")),
|
|
3591
|
+
importMap: getImportMap(config.outdir.replace(relativeBaseUrl, ""), config.importMap),
|
|
3508
3592
|
jsx: {
|
|
3593
|
+
framework: jsx.framework,
|
|
3509
3594
|
factory: jsx.factoryName,
|
|
3510
3595
|
styleProps: jsx.styleProps,
|
|
3511
3596
|
isStyleProp: isValidProperty,
|
|
3512
3597
|
nodes: [...patterns.details, ...recipes.details]
|
|
3513
3598
|
},
|
|
3599
|
+
patternKeys: patterns.keys,
|
|
3600
|
+
recipeKeys: recipes.keys,
|
|
3514
3601
|
getRecipesByJsxName: recipes.filter,
|
|
3515
3602
|
getPatternsByJsxName: patterns.filter,
|
|
3516
3603
|
compilerOptions,
|