@pandacss/studio 0.0.0-dev-20231020171339 → 0.0.0-dev-20231020184323
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/package.json +7 -7
- package/styled-system/css/cva.mjs +24 -2
- package/styled-system/helpers.mjs +15 -9
- package/styled-system/jsx/factory-helper.mjs +22 -0
- package/styled-system/jsx/factory.mjs +15 -8
- package/styled-system/types/jsx.d.ts +17 -7
- package/styled-system/types/system-types.d.ts +12 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/studio",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20231020184323",
|
|
4
4
|
"description": "The automated token documentation for Panda CSS",
|
|
5
5
|
"main": "dist/studio.js",
|
|
6
6
|
"module": "dist/studio.mjs",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"react": "18.2.0",
|
|
34
34
|
"react-dom": "18.2.0",
|
|
35
35
|
"vite": "4.4.11",
|
|
36
|
-
"@pandacss/config": "0.0.0-dev-
|
|
37
|
-
"@pandacss/logger": "0.0.0-dev-
|
|
38
|
-
"@pandacss/node": "0.0.0-dev-
|
|
39
|
-
"@pandacss/shared": "0.0.0-dev-
|
|
40
|
-
"@pandacss/token-dictionary": "0.0.0-dev-
|
|
41
|
-
"@pandacss/types": "0.0.0-dev-
|
|
36
|
+
"@pandacss/config": "0.0.0-dev-20231020184323",
|
|
37
|
+
"@pandacss/logger": "0.0.0-dev-20231020184323",
|
|
38
|
+
"@pandacss/node": "0.0.0-dev-20231020184323",
|
|
39
|
+
"@pandacss/shared": "0.0.0-dev-20231020184323",
|
|
40
|
+
"@pandacss/token-dictionary": "0.0.0-dev-20231020184323",
|
|
41
|
+
"@pandacss/types": "0.0.0-dev-20231020184323"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/react": "18.2.22",
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { compact, splitProps } from '../helpers.mjs';
|
|
1
|
+
import { compact, mergeProps, splitProps, uniq } from '../helpers.mjs';
|
|
2
2
|
import { css, mergeCss } from './css.mjs';
|
|
3
3
|
|
|
4
|
+
const defaults = (conf) => ({
|
|
5
|
+
base: {},
|
|
6
|
+
variants: {},
|
|
7
|
+
defaultVariants: {},
|
|
8
|
+
compoundVariants: [],
|
|
9
|
+
...conf,
|
|
10
|
+
})
|
|
11
|
+
|
|
4
12
|
export function cva(config) {
|
|
5
|
-
const { base
|
|
13
|
+
const { base, variants, defaultVariants, compoundVariants } = defaults(config)
|
|
6
14
|
|
|
7
15
|
function resolve(props = {}) {
|
|
8
16
|
const computedVariants = { ...defaultVariants, ...compact(props) }
|
|
@@ -16,6 +24,19 @@ export function cva(config) {
|
|
|
16
24
|
return mergeCss(variantCss, compoundVariantCss)
|
|
17
25
|
}
|
|
18
26
|
|
|
27
|
+
function merge(cvaConfig) {
|
|
28
|
+
const override = defaults(cvaConfig)
|
|
29
|
+
const variantKeys = uniq(override.variantKeys, Object.keys(variants))
|
|
30
|
+
return cva({
|
|
31
|
+
base: mergeCss(base, override.base),
|
|
32
|
+
variants: Object.fromEntries(
|
|
33
|
+
variantKeys.map((key) => [key, mergeCss(variants[key], override.variants[key])]),
|
|
34
|
+
),
|
|
35
|
+
defaultVariants: mergeProps(defaultVariants, override.defaultVariants),
|
|
36
|
+
compoundVariants: [...compoundVariants, ...override.compoundVariants],
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
function cvaFn(props) {
|
|
20
41
|
return css(resolve(props))
|
|
21
42
|
}
|
|
@@ -34,6 +55,7 @@ export function cva(config) {
|
|
|
34
55
|
variantKeys,
|
|
35
56
|
raw: resolve,
|
|
36
57
|
config,
|
|
58
|
+
merge,
|
|
37
59
|
splitVariantProps,
|
|
38
60
|
})
|
|
39
61
|
}
|
|
@@ -49,17 +49,19 @@ function toHash(value) {
|
|
|
49
49
|
|
|
50
50
|
// src/merge-props.ts
|
|
51
51
|
function mergeProps(...sources) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const objects = sources.filter(Boolean);
|
|
53
|
+
return objects.reduce((prev, obj) => {
|
|
54
|
+
Object.keys(obj).forEach((key) => {
|
|
55
|
+
const prevValue = prev[key];
|
|
56
|
+
const value = obj[key];
|
|
57
|
+
if (isObject(prevValue) && isObject(value)) {
|
|
58
|
+
prev[key] = mergeProps(prevValue, value);
|
|
57
59
|
} else {
|
|
58
|
-
|
|
60
|
+
prev[key] = value;
|
|
59
61
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
});
|
|
63
|
+
return prev;
|
|
64
|
+
}, {});
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
// src/walk-object.ts
|
|
@@ -250,6 +252,9 @@ function splitProps(props, ...keys) {
|
|
|
250
252
|
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));
|
|
251
253
|
return keys.map(fn).concat(split(dKeys));
|
|
252
254
|
}
|
|
255
|
+
|
|
256
|
+
// src/uniq.ts
|
|
257
|
+
var uniq = (...items) => items.filter(Boolean).reduce((acc, item) => Array.from(/* @__PURE__ */ new Set([...acc, ...item])), []);
|
|
253
258
|
export {
|
|
254
259
|
compact,
|
|
255
260
|
createCss,
|
|
@@ -265,6 +270,7 @@ export {
|
|
|
265
270
|
mergeProps,
|
|
266
271
|
splitProps,
|
|
267
272
|
toHash,
|
|
273
|
+
uniq,
|
|
268
274
|
walkObject,
|
|
269
275
|
withoutSpace
|
|
270
276
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isCssProperty } from './is-valid-prop.mjs';
|
|
2
|
+
|
|
3
|
+
export const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
4
|
+
|
|
5
|
+
export const composeShouldForwardProps = (tag, shouldForwardProp) =>
|
|
6
|
+
tag.__shouldForwardProps__ && shouldForwardProp
|
|
7
|
+
? (propName) => tag.__shouldForwardProps__(propName) && shouldForwardProp(propName)
|
|
8
|
+
: shouldForwardProp
|
|
9
|
+
|
|
10
|
+
export const composeCvaFn = (cvaA, cvaB) => {
|
|
11
|
+
if (cvaA && !cvaB) return cvaA
|
|
12
|
+
if (!cvaA && cvaB) return cvaB
|
|
13
|
+
if ((cvaA.__cva__ && cvaB.__cva__) || (cvaA.__recipe__ && cvaB.__recipe__)) return cvaA.merge(cvaB.config)
|
|
14
|
+
const error = new TypeError('Cannot merge cva with recipe. Please use either cva or recipe.')
|
|
15
|
+
TypeError.captureStackTrace?.(error)
|
|
16
|
+
throw error
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const getDisplayName = (Component) => {
|
|
20
|
+
if (typeof Component === 'string') return Component
|
|
21
|
+
return Component?.displayName || Component?.name || 'Component'
|
|
22
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createElement, forwardRef, useMemo } from 'react'
|
|
2
2
|
import { css, cx, cva } from '../css/index.mjs';
|
|
3
|
+
import { defaultShouldForwardProp, composeShouldForwardProps, composeCvaFn, getDisplayName } from './factory-helper.mjs';
|
|
3
4
|
import { splitProps, normalizeHTMLProps } from '../helpers.mjs';
|
|
4
5
|
import { isCssProperty } from './is-valid-prop.mjs';
|
|
5
6
|
|
|
6
|
-
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
7
|
-
|
|
8
7
|
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
9
8
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
10
9
|
|
|
@@ -17,23 +16,26 @@ function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
|
17
16
|
)
|
|
18
17
|
|
|
19
18
|
const PandaComponent = /* @__PURE__ */ forwardRef(function PandaComponent(props, ref) {
|
|
20
|
-
const { as: Element = Dynamic, children, ...restProps } = props
|
|
19
|
+
const { as: Element = Dynamic.__base__ || Dynamic, children, ...restProps } = props
|
|
20
|
+
|
|
21
|
+
const __cvaFn__ = composeCvaFn(Dynamic.__cva__, cvaFn)
|
|
22
|
+
const __shouldForwardProps__ = composeShouldForwardProps(Dynamic, shouldForwardProp)
|
|
21
23
|
|
|
22
24
|
const combinedProps = useMemo(() => Object.assign({}, defaultProps, restProps), [restProps])
|
|
23
25
|
|
|
24
26
|
const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
25
|
-
return splitProps(combinedProps,
|
|
27
|
+
return splitProps(combinedProps, __shouldForwardProps__, __cvaFn__.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
26
28
|
}, [combinedProps])
|
|
27
29
|
|
|
28
30
|
function recipeClass() {
|
|
29
31
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
30
|
-
const compoundVariantStyles =
|
|
31
|
-
return cx(
|
|
32
|
+
const compoundVariantStyles = __cvaFn__.__getCompoundVariantCss__?.(variantProps)
|
|
33
|
+
return cx(__cvaFn__(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.className)
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
function cvaClass() {
|
|
35
37
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
36
|
-
const cvaStyles =
|
|
38
|
+
const cvaStyles = __cvaFn__.raw(variantProps)
|
|
37
39
|
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.className)
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -49,8 +51,13 @@ function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
|
49
51
|
})
|
|
50
52
|
})
|
|
51
53
|
|
|
52
|
-
const name = (
|
|
54
|
+
const name = getDisplayName(Dynamic)
|
|
55
|
+
|
|
53
56
|
PandaComponent.displayName = `panda.${name}`
|
|
57
|
+
PandaComponent.__cva__ = cvaFn
|
|
58
|
+
PandaComponent.__base__ = Dynamic
|
|
59
|
+
PandaComponent.__shouldForwardProps__ = shouldForwardProp
|
|
60
|
+
|
|
54
61
|
return PandaComponent
|
|
55
62
|
}
|
|
56
63
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import type { ComponentPropsWithoutRef, ElementType, ElementRef, Ref } from 'react'
|
|
3
|
-
import type { Assign, DistributiveOmit, JsxHTMLProps, JsxStyleProps } from './system-types';
|
|
4
3
|
import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe';
|
|
4
|
+
import type { Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty } from './system-types';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface Dict {
|
|
7
|
+
[k: string]: unknown
|
|
8
|
+
}
|
|
7
9
|
|
|
8
10
|
export type ComponentProps<T extends ElementType> = DistributiveOmit<ComponentPropsWithoutRef<T>, 'ref'> & {
|
|
9
11
|
ref?: Ref<ElementRef<T>>
|
|
@@ -14,7 +16,9 @@ export interface PandaComponent<T extends ElementType, P extends Dict = {}> {
|
|
|
14
16
|
displayName?: string
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
interface RecipeFn {
|
|
19
|
+
interface RecipeFn {
|
|
20
|
+
__type: any
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
interface JsxFactoryOptions<TProps extends Dict> {
|
|
20
24
|
dataAttr?: boolean
|
|
@@ -24,16 +28,22 @@ interface JsxFactoryOptions<TProps extends Dict> {
|
|
|
24
28
|
|
|
25
29
|
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
export type JsxElement<T extends ElementType, P> = T extends PandaComponent<infer A, infer B>
|
|
32
|
+
? PandaComponent<A, Pretty<DistributiveUnion<P, B>>>
|
|
33
|
+
: PandaComponent<T, P>
|
|
34
|
+
|
|
35
|
+
export interface JsxFactory {
|
|
28
36
|
<T extends ElementType>(component: T): PandaComponent<T, {}>
|
|
29
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>):
|
|
37
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): JsxElement<
|
|
30
38
|
T,
|
|
31
39
|
RecipeSelection<P>
|
|
32
40
|
>
|
|
33
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>):
|
|
41
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): JsxElement<T, P['__type']>
|
|
34
42
|
}
|
|
35
43
|
|
|
36
|
-
type JsxElements = {
|
|
44
|
+
export type JsxElements = {
|
|
45
|
+
[K in keyof JSX.IntrinsicElements]: PandaComponent<K, {}>
|
|
46
|
+
}
|
|
37
47
|
|
|
38
48
|
export type Panda = JsxFactory & JsxElements
|
|
39
49
|
|
|
@@ -6,6 +6,18 @@ import type { SystemProperties, CssVarProperties } from './style-props';
|
|
|
6
6
|
type String = string & {}
|
|
7
7
|
type Number = number & {}
|
|
8
8
|
|
|
9
|
+
export type Pretty<T> = { [K in keyof T]: T[K] } & {}
|
|
10
|
+
|
|
11
|
+
export type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never
|
|
12
|
+
|
|
13
|
+
export type DistributiveUnion<T, U> = {
|
|
14
|
+
[K in keyof T]: K extends keyof U ? U[K] | T[K] : T[K]
|
|
15
|
+
} & DistributiveOmit<U, keyof T>
|
|
16
|
+
|
|
17
|
+
export type Assign<T, U> = {
|
|
18
|
+
[K in keyof T]: K extends keyof U ? U[K] : T[K]
|
|
19
|
+
} & U
|
|
20
|
+
|
|
9
21
|
/* -----------------------------------------------------------------------------
|
|
10
22
|
* Native css properties
|
|
11
23
|
* -----------------------------------------------------------------------------*/
|
|
@@ -62,12 +74,6 @@ type StyleProps = SystemProperties & MinimalNested<SystemStyleObject>
|
|
|
62
74
|
|
|
63
75
|
export type JsxStyleProps = StyleProps & WithCss
|
|
64
76
|
|
|
65
|
-
export type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never
|
|
66
|
-
|
|
67
|
-
export type Assign<T, U> = {
|
|
68
|
-
[K in keyof T]: K extends keyof U ? U[K] : T[K]
|
|
69
|
-
} & U
|
|
70
|
-
|
|
71
77
|
export interface PatchedHTMLProps {
|
|
72
78
|
htmlWidth?: string | number
|
|
73
79
|
htmlHeight?: string | number
|