@typestyles/react 0.0.0-unstable.f163b08f071e → 0.0.0-unstable.f58fa2ab20b7
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/README.md +16 -16
- package/dist/babel-plugin.cjs +14223 -152
- package/dist/babel-plugin.cjs.map +1 -1
- package/dist/babel-plugin.d.cts +10 -10
- package/dist/babel-plugin.d.cts.map +1 -0
- package/dist/babel-plugin.d.ts +10 -10
- package/dist/babel-plugin.d.ts.map +1 -0
- package/dist/babel-plugin.js +14223 -130
- package/dist/babel-plugin.js.map +1 -1
- package/dist/css-prop-DMDmFKhu.js +21 -0
- package/dist/css-prop-DMDmFKhu.js.map +1 -0
- package/dist/css-prop-DOMoNwJN.cjs +38 -0
- package/dist/css-prop-DOMoNwJN.cjs.map +1 -0
- package/dist/css-prop-runtime-zKybLO8E.d.cts +14 -0
- package/dist/css-prop-runtime-zKybLO8E.d.cts.map +1 -0
- package/dist/css-prop-runtime-zKybLO8E.d.ts +14 -0
- package/dist/css-prop-runtime-zKybLO8E.d.ts.map +1 -0
- package/dist/css-prop-runtime.cjs +7 -7
- package/dist/css-prop-runtime.cjs.map +1 -1
- package/dist/css-prop-runtime.d.cts +2 -7
- package/dist/css-prop-runtime.d.ts +2 -7
- package/dist/css-prop-runtime.js +8 -2
- package/dist/css-prop-runtime.js.map +1 -1
- package/dist/index.cjs +75 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -21
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +25 -21
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -75
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.cjs +20 -38
- package/dist/jsx-dev-runtime.cjs.map +1 -1
- package/dist/jsx-dev-runtime.d.cts +9 -11
- package/dist/jsx-dev-runtime.d.cts.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +9 -11
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +19 -25
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.cjs +23 -41
- package/dist/jsx-runtime.cjs.map +1 -1
- package/dist/jsx-runtime.d.cts +10 -12
- package/dist/jsx-runtime.d.cts.map +1 -0
- package/dist/jsx-runtime.d.ts +10 -12
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +20 -27
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/resolve-hash-class-DuqLJq6S.cjs +14 -0
- package/dist/resolve-hash-class-DuqLJq6S.cjs.map +1 -0
- package/dist/resolve-hash-class-Rs_7aMMQ.js +9 -0
- package/dist/resolve-hash-class-Rs_7aMMQ.js.map +1 -0
- package/dist/types-DcDsqg2q.d.cts +10 -0
- package/dist/types-DcDsqg2q.d.cts.map +1 -0
- package/dist/types-DcDsqg2q.d.ts +10 -0
- package/dist/types-DcDsqg2q.d.ts.map +1 -0
- package/package.json +9 -11
- package/dist/chunk-3YCUQVCM.js +0 -8
- package/dist/chunk-3YCUQVCM.js.map +0 -1
- package/dist/chunk-4BYX2HZ7.js +0 -22
- package/dist/chunk-4BYX2HZ7.js.map +0 -1
- package/dist/types-_vEO6H8X.d.cts +0 -9
- package/dist/types-_vEO6H8X.d.ts +0 -9
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { cx } from "typestyles";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/context.tsx
|
|
5
|
+
const TypeStylesContext = createContext(null);
|
|
6
|
+
function TypeStylesProvider({ styles, children }) {
|
|
7
|
+
return jsx(TypeStylesContext.Provider, {
|
|
8
|
+
value: styles,
|
|
9
|
+
children
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/css-prop.ts
|
|
14
|
+
function resolveCssPropClass(hashClass, css, className) {
|
|
15
|
+
if (css && typeof css === "object") return cx(hashClass(css), className);
|
|
16
|
+
return cx(className);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { TypeStylesContext as n, TypeStylesProvider as r, resolveCssPropClass as t };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=css-prop-DMDmFKhu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-prop-DMDmFKhu.js","names":[],"sources":["../src/context.tsx","../src/css-prop.ts"],"sourcesContent":["import { createContext, type ReactNode } from 'react';\nimport type { CssStylesHost } from './resolve-hash-class';\n\nexport const TypeStylesContext = createContext<CssStylesHost | null>(null);\n\nexport function TypeStylesProvider({\n styles,\n children,\n}: {\n /** Prefer a `createTypeStyles()` result; `createStyles()` instances also work. */\n styles: CssStylesHost;\n children: ReactNode;\n}): React.JSX.Element {\n return <TypeStylesContext.Provider value={styles}>{children}</TypeStylesContext.Provider>;\n}\n","import type { CSSProperties } from 'typestyles';\nimport { cx } from 'typestyles';\nimport type { CssPropValue } from './types';\n\nexport function resolveCssPropClass(\n hashClass: (properties: CSSProperties, label?: string) => string,\n css: CssPropValue | undefined,\n className?: string,\n): string {\n if (css && typeof css === 'object') {\n return cx(hashClass(css), className);\n }\n return cx(className);\n}\n"],"mappings":";;;;AAGA,MAAa,oBAAoB,cAAoC,IAAI;AAEzE,SAAgB,mBAAmB,EACjC,QACA,YAKoB;CACpB,OAAO,IAAC,kBAAkB,UAAnB;EAA4B,OAAO;EAAS;CAAqC,CAAA;AAC1F;;;ACVA,SAAgB,oBACd,WACA,KACA,WACQ;CACR,IAAI,OAAO,OAAO,QAAQ,UACxB,OAAO,GAAG,UAAU,GAAG,GAAG,SAAS;CAErC,OAAO,GAAG,SAAS;AACrB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
let typestyles = require("typestyles");
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
//#region src/context.tsx
|
|
5
|
+
const TypeStylesContext = (0, react.createContext)(null);
|
|
6
|
+
function TypeStylesProvider({ styles, children }) {
|
|
7
|
+
return (0, react_jsx_runtime.jsx)(TypeStylesContext.Provider, {
|
|
8
|
+
value: styles,
|
|
9
|
+
children
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/css-prop.ts
|
|
14
|
+
function resolveCssPropClass(hashClass, css, className) {
|
|
15
|
+
if (css && typeof css === "object") return (0, typestyles.cx)(hashClass(css), className);
|
|
16
|
+
return (0, typestyles.cx)(className);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, "TypeStylesContext", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return TypeStylesContext;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "TypeStylesProvider", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function() {
|
|
28
|
+
return TypeStylesProvider;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "resolveCssPropClass", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return resolveCssPropClass;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=css-prop-DOMoNwJN.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-prop-DOMoNwJN.cjs","names":["createContext","cx"],"sources":["../src/context.tsx","../src/css-prop.ts"],"sourcesContent":["import { createContext, type ReactNode } from 'react';\nimport type { CssStylesHost } from './resolve-hash-class';\n\nexport const TypeStylesContext = createContext<CssStylesHost | null>(null);\n\nexport function TypeStylesProvider({\n styles,\n children,\n}: {\n /** Prefer a `createTypeStyles()` result; `createStyles()` instances also work. */\n styles: CssStylesHost;\n children: ReactNode;\n}): React.JSX.Element {\n return <TypeStylesContext.Provider value={styles}>{children}</TypeStylesContext.Provider>;\n}\n","import type { CSSProperties } from 'typestyles';\nimport { cx } from 'typestyles';\nimport type { CssPropValue } from './types';\n\nexport function resolveCssPropClass(\n hashClass: (properties: CSSProperties, label?: string) => string,\n css: CssPropValue | undefined,\n className?: string,\n): string {\n if (css && typeof css === 'object') {\n return cx(hashClass(css), className);\n }\n return cx(className);\n}\n"],"mappings":";;;;AAGA,MAAa,qBAAA,GAAoBA,MAAAA,cAAAA,CAAoC,IAAI;AAEzE,SAAgB,mBAAmB,EACjC,QACA,YAKoB;CACpB,QAAO,GAAA,kBAAA,IAAA,CAAC,kBAAkB,UAAnB;EAA4B,OAAO;EAAS;CAAqC,CAAA;AAC1F;;;ACVA,SAAgB,oBACd,WACA,KACA,WACQ;CACR,IAAI,OAAO,OAAO,QAAQ,UACxB,QAAA,GAAOC,WAAAA,GAAAA,CAAG,UAAU,GAAG,GAAG,SAAS;CAErC,QAAA,GAAOA,WAAAA,GAAAA,CAAG,SAAS;AACrB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CSSProperties, StylesApi, TypeStylesApi } from "typestyles";
|
|
2
|
+
//#region src/resolve-hash-class.d.ts
|
|
3
|
+
/** Styles host for the css prop / TypeStylesProvider. */
|
|
4
|
+
type CssStylesHost = Pick<TypeStylesApi, 'hash'> | StylesApi;
|
|
5
|
+
type HashClassFn = (properties: CSSProperties, label?: string) => string;
|
|
6
|
+
/** Normalize `hash` (createTypeStyles) and `hashClass` (createStyles). */
|
|
7
|
+
declare function resolveHashClass(api: CssStylesHost): HashClassFn;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/css-prop-runtime.d.ts
|
|
10
|
+
/** Runtime helper used by the Babel plugin for static `css` props. */
|
|
11
|
+
declare function cssProp(api: CssStylesHost, properties: CSSProperties): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { resolveHashClass as i, CssStylesHost as n, HashClassFn as r, cssProp as t };
|
|
14
|
+
//# sourceMappingURL=css-prop-runtime-zKybLO8E.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-prop-runtime-zKybLO8E.d.cts","names":[],"sources":["../src/resolve-hash-class.ts","../src/css-prop-runtime.ts"],"mappings":";;;KAGY,gBAAgB,KAAK,yBAAyB;KAE9C,eAAe,YAAY,eAAe;;iBAGtC,iBAAiB,KAAK,gBAAgB;;;;iBCHtC,QAAQ,KAAK,eAAe,YAAY"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CSSProperties, StylesApi, TypeStylesApi } from "typestyles";
|
|
2
|
+
//#region src/resolve-hash-class.d.ts
|
|
3
|
+
/** Styles host for the css prop / TypeStylesProvider. */
|
|
4
|
+
type CssStylesHost = Pick<TypeStylesApi, 'hash'> | StylesApi;
|
|
5
|
+
type HashClassFn = (properties: CSSProperties, label?: string) => string;
|
|
6
|
+
/** Normalize `hash` (createTypeStyles) and `hashClass` (createStyles). */
|
|
7
|
+
declare function resolveHashClass(api: CssStylesHost): HashClassFn;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/css-prop-runtime.d.ts
|
|
10
|
+
/** Runtime helper used by the Babel plugin for static `css` props. */
|
|
11
|
+
declare function cssProp(api: CssStylesHost, properties: CSSProperties): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { resolveHashClass as i, CssStylesHost as n, HashClassFn as r, cssProp as t };
|
|
14
|
+
//# sourceMappingURL=css-prop-runtime-zKybLO8E.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-prop-runtime-zKybLO8E.d.ts","names":[],"sources":["../src/resolve-hash-class.ts","../src/css-prop-runtime.ts"],"mappings":";;;KAGY,gBAAgB,KAAK,yBAAyB;KAE9C,eAAe,YAAY,eAAe;;iBAGtC,iBAAiB,KAAK,gBAAgB;;;;iBCHtC,QAAQ,KAAK,eAAe,YAAY"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function cssProp(
|
|
5
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_resolve_hash_class = require("./resolve-hash-class-DuqLJq6S.cjs");
|
|
3
|
+
//#region src/css-prop-runtime.ts
|
|
4
|
+
function cssProp(api, properties) {
|
|
5
|
+
return require_resolve_hash_class.resolveHashClass(api)(properties);
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
//#endregion
|
|
8
8
|
exports.cssProp = cssProp;
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
//# sourceMappingURL=css-prop-runtime.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"css-prop-runtime.cjs","names":["resolveHashClass"],"sources":["../src/css-prop-runtime.ts"],"sourcesContent":["import type { CSSProperties } from 'typestyles';\nimport type { CssStylesHost } from './resolve-hash-class';\nimport { resolveHashClass } from './resolve-hash-class';\n\n/** Runtime helper used by the Babel plugin for static `css` props. */\nexport function cssProp(api: CssStylesHost, properties: CSSProperties): string {\n return resolveHashClass(api)(properties);\n}\n"],"mappings":";;;AAKA,SAAgB,QAAQ,KAAoB,YAAmC;CAC7E,OAAOA,2BAAAA,iBAAiB,GAAG,CAAC,CAAC,UAAU;AACzC"}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function cssProp(styles: {
|
|
4
|
-
hashClass: (properties: CSSProperties, label?: string) => string;
|
|
5
|
-
}, properties: CSSProperties): string;
|
|
6
|
-
|
|
7
|
-
export { cssProp };
|
|
1
|
+
import { t as cssProp } from "./css-prop-runtime-zKybLO8E.cjs";
|
|
2
|
+
export { cssProp };
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function cssProp(styles: {
|
|
4
|
-
hashClass: (properties: CSSProperties, label?: string) => string;
|
|
5
|
-
}, properties: CSSProperties): string;
|
|
6
|
-
|
|
7
|
-
export { cssProp };
|
|
1
|
+
import { t as cssProp } from "./css-prop-runtime-zKybLO8E.js";
|
|
2
|
+
export { cssProp };
|
package/dist/css-prop-runtime.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
//#
|
|
1
|
+
import { t as resolveHashClass } from "./resolve-hash-class-Rs_7aMMQ.js";
|
|
2
|
+
//#region src/css-prop-runtime.ts
|
|
3
|
+
function cssProp(api, properties) {
|
|
4
|
+
return resolveHashClass(api)(properties);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { cssProp };
|
|
8
|
+
|
|
3
9
|
//# sourceMappingURL=css-prop-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"css-prop-runtime.js","names":[],"sources":["../src/css-prop-runtime.ts"],"sourcesContent":["import type { CSSProperties } from 'typestyles';\nimport type { CssStylesHost } from './resolve-hash-class';\nimport { resolveHashClass } from './resolve-hash-class';\n\n/** Runtime helper used by the Babel plugin for static `css` props. */\nexport function cssProp(api: CssStylesHost, properties: CSSProperties): string {\n return resolveHashClass(api)(properties);\n}\n"],"mappings":";;AAKA,SAAgB,QAAQ,KAAoB,YAAmC;CAC7E,OAAO,iBAAiB,GAAG,CAAC,CAAC,UAAU;AACzC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,109 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"slots"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_css_prop = require("./css-prop-DOMoNwJN.cjs");
|
|
3
|
+
const require_resolve_hash_class = require("./resolve-hash-class-DuqLJq6S.cjs");
|
|
4
|
+
const require_css_prop_runtime = require("./css-prop-runtime.cjs");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let typestyles = require("typestyles");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
//#region src/split-props.ts
|
|
9
|
+
const RESERVED_CONFIG_KEYS = new Set([
|
|
10
|
+
"base",
|
|
11
|
+
"variants",
|
|
12
|
+
"compoundVariants",
|
|
13
|
+
"defaultVariants",
|
|
14
|
+
"slots"
|
|
16
15
|
]);
|
|
17
16
|
function splitVariantProps(props, variantKeys) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
rest
|
|
31
|
-
};
|
|
17
|
+
const variants = {};
|
|
18
|
+
const rest = { ...props };
|
|
19
|
+
for (const key of variantKeys) if (key in rest) {
|
|
20
|
+
variants[key] = rest[key];
|
|
21
|
+
delete rest[key];
|
|
22
|
+
}
|
|
23
|
+
delete rest.className;
|
|
24
|
+
delete rest.css;
|
|
25
|
+
return {
|
|
26
|
+
variants,
|
|
27
|
+
rest
|
|
28
|
+
};
|
|
32
29
|
}
|
|
33
30
|
function getVariantKeysFromConfig(config) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if ("variants" in config && config.variants && typeof config.variants === "object") {
|
|
38
|
-
return Object.keys(config.variants);
|
|
39
|
-
}
|
|
40
|
-
return Object.keys(config).filter((key) => !RESERVED_CONFIG_KEYS.has(key));
|
|
41
|
-
}
|
|
42
|
-
function resolveStyledArgs(tag, configOrNamespace, maybeConfig) {
|
|
43
|
-
if (typeof configOrNamespace === "string" && maybeConfig != null) {
|
|
44
|
-
return { tag, namespace: configOrNamespace, config: maybeConfig };
|
|
45
|
-
}
|
|
46
|
-
const namespace = typeof tag === "string" ? tag : "styled";
|
|
47
|
-
return {
|
|
48
|
-
tag,
|
|
49
|
-
namespace,
|
|
50
|
-
config: configOrNamespace
|
|
51
|
-
};
|
|
31
|
+
if (typeof config === "function") return [];
|
|
32
|
+
if ("variants" in config && config.variants && typeof config.variants === "object") return Object.keys(config.variants);
|
|
33
|
+
return Object.keys(config).filter((key) => !RESERVED_CONFIG_KEYS.has(key));
|
|
52
34
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
config
|
|
59
|
-
} = resolveStyledArgs(tag, configOrNamespace, maybeConfig);
|
|
60
|
-
const recipe = styles.component(namespace, config);
|
|
61
|
-
const variantKeys = getVariantKeysFromConfig(
|
|
62
|
-
config
|
|
63
|
-
);
|
|
64
|
-
const Component = react.forwardRef(
|
|
65
|
-
function StyledComponent(props, ref) {
|
|
66
|
-
const { className, ...propsWithoutClassName } = props;
|
|
67
|
-
const { variants, rest } = splitVariantProps(
|
|
68
|
-
propsWithoutClassName,
|
|
69
|
-
variantKeys
|
|
70
|
-
);
|
|
71
|
-
const mergedClassName = typestyles.cx(
|
|
72
|
-
recipe(variants),
|
|
73
|
-
className
|
|
74
|
-
);
|
|
75
|
-
const Element = element;
|
|
76
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Element, { ...rest, ref, className: mergedClassName });
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
Component.displayName = namespace.charAt(0).toUpperCase() + namespace.slice(1);
|
|
80
|
-
return Component;
|
|
81
|
-
}
|
|
82
|
-
return styled;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/create-styled.tsx
|
|
37
|
+
function resolveRecipeFactory(api) {
|
|
38
|
+
if ("recipe" in api) return api.recipe;
|
|
39
|
+
return api.component;
|
|
83
40
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return typestyles.cx(className);
|
|
41
|
+
function resolveStyledArgs(tag, configOrNamespace, maybeConfig) {
|
|
42
|
+
if (typeof configOrNamespace === "string" && maybeConfig != null) return {
|
|
43
|
+
tag,
|
|
44
|
+
namespace: configOrNamespace,
|
|
45
|
+
config: maybeConfig
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
tag,
|
|
49
|
+
namespace: typeof tag === "string" ? tag : "styled",
|
|
50
|
+
config: configOrNamespace
|
|
51
|
+
};
|
|
96
52
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
function
|
|
100
|
-
|
|
53
|
+
function createStyled(api) {
|
|
54
|
+
const makeRecipe = resolveRecipeFactory(api);
|
|
55
|
+
function styled(tag, configOrNamespace, maybeConfig) {
|
|
56
|
+
const { tag: element, namespace, config } = resolveStyledArgs(tag, configOrNamespace, maybeConfig);
|
|
57
|
+
const recipe = makeRecipe({
|
|
58
|
+
name: namespace,
|
|
59
|
+
styles: config
|
|
60
|
+
});
|
|
61
|
+
const variantKeys = getVariantKeysFromConfig(config);
|
|
62
|
+
const Component = (0, react.forwardRef)(function StyledComponent(props, ref) {
|
|
63
|
+
const { className, ...propsWithoutClassName } = props;
|
|
64
|
+
const { variants, rest } = splitVariantProps(propsWithoutClassName, variantKeys);
|
|
65
|
+
const mergedClassName = (0, typestyles.cx)(recipe(variants), className);
|
|
66
|
+
return (0, react_jsx_runtime.jsx)(element, {
|
|
67
|
+
...rest,
|
|
68
|
+
ref,
|
|
69
|
+
className: mergedClassName
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
Component.displayName = namespace.charAt(0).toUpperCase() + namespace.slice(1);
|
|
73
|
+
return Component;
|
|
74
|
+
}
|
|
75
|
+
return styled;
|
|
101
76
|
}
|
|
102
|
-
|
|
103
|
-
exports.TypeStylesContext = TypeStylesContext;
|
|
104
|
-
exports.TypeStylesProvider = TypeStylesProvider;
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.TypeStylesContext = require_css_prop.TypeStylesContext;
|
|
79
|
+
exports.TypeStylesProvider = require_css_prop.TypeStylesProvider;
|
|
105
80
|
exports.createStyled = createStyled;
|
|
106
|
-
exports.cssProp = cssProp;
|
|
107
|
-
exports.resolveCssPropClass = resolveCssPropClass;
|
|
108
|
-
|
|
81
|
+
exports.cssProp = require_css_prop_runtime.cssProp;
|
|
82
|
+
exports.resolveCssPropClass = require_css_prop.resolveCssPropClass;
|
|
83
|
+
exports.resolveHashClass = require_resolve_hash_class.resolveHashClass;
|
|
84
|
+
|
|
109
85
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","cx","Element"],"sources":["../src/split-props.ts","../src/create-styled.tsx"],"sourcesContent":["const RESERVED_CONFIG_KEYS = new Set([\n 'base',\n 'variants',\n 'compoundVariants',\n 'defaultVariants',\n 'slots',\n]);\n\nexport function splitVariantProps<P extends Record<string, unknown>>(\n props: P,\n variantKeys: readonly string[],\n): {\n variants: Record<string, unknown>;\n rest: Omit<P, (typeof variantKeys)[number] | 'className' | 'css'>;\n} {\n const variants: Record<string, unknown> = {};\n const rest = { ...props } as Record<string, unknown>;\n\n for (const key of variantKeys) {\n if (key in rest) {\n variants[key] = rest[key];\n delete rest[key];\n }\n }\n\n delete rest.className;\n delete rest.css;\n\n return {\n variants,\n rest: rest as Omit<P, (typeof variantKeys)[number] | 'className' | 'css'>,\n };\n}\n\nexport function getVariantKeysFromConfig(\n config: Record<string, unknown> | ((ctx: unknown) => Record<string, unknown>),\n): readonly string[] {\n if (typeof config === 'function') {\n return [];\n }\n\n if ('variants' in config && config.variants && typeof config.variants === 'object') {\n return Object.keys(config.variants);\n }\n\n return Object.keys(config).filter((key) => !RESERVED_CONFIG_KEYS.has(key));\n}\n","import {\n forwardRef,\n type ComponentPropsWithoutRef,\n type ElementType,\n type ForwardRefExoticComponent,\n type RefAttributes,\n} from 'react';\nimport type {\n ComponentConfigInput,\n ComponentReturn,\n ComponentVariants,\n FlatComponentConfigInput,\n FlatComponentReturn,\n StylesApi,\n TypeStylesApi,\n VariantDefinitions,\n} from 'typestyles';\nimport { cx } from 'typestyles';\nimport { getVariantKeysFromConfig, splitVariantProps } from './split-props';\n\ntype StyledComponentType<Tag extends ElementType, Recipe> = ForwardRefExoticComponent<\n ComponentPropsWithoutRef<Tag> & ComponentVariants<Recipe> & RefAttributes<Element>\n>;\n\nexport type StyledFactory = {\n <Tag extends ElementType, const V extends VariantDefinitions>(\n tag: Tag,\n config: ComponentConfigInput<V>,\n ): StyledComponentType<Tag, ComponentReturn<V>>;\n <Tag extends ElementType, const V extends VariantDefinitions, const N extends string>(\n tag: Tag,\n namespace: N,\n config: ComponentConfigInput<V>,\n ): StyledComponentType<Tag, ComponentReturn<V>>;\n <Tag extends ElementType, const K extends string>(\n tag: Tag,\n config: FlatComponentConfigInput<K>,\n ): StyledComponentType<Tag, FlatComponentReturn<K>>;\n <Tag extends ElementType, const K extends string, const N extends string>(\n tag: Tag,\n namespace: N,\n config: FlatComponentConfigInput<K>,\n ): StyledComponentType<Tag, FlatComponentReturn<K>>;\n};\n\ntype RecipeFactory = StylesApi['component'];\n\n/** Accepts `createTypeStyles()` (preferred) or a lower-level `createStyles()` instance. */\nexport type StyledApi = Pick<TypeStylesApi, 'recipe'> | StylesApi;\n\nfunction resolveRecipeFactory(api: StyledApi): RecipeFactory {\n if ('recipe' in api) return api.recipe;\n return api.component;\n}\n\nfunction resolveStyledArgs(\n tag: ElementType,\n configOrNamespace:\n | string\n | ComponentConfigInput<VariantDefinitions>\n | FlatComponentConfigInput<string>,\n maybeConfig?: ComponentConfigInput<VariantDefinitions> | FlatComponentConfigInput<string>,\n): {\n tag: ElementType;\n namespace: string;\n config: ComponentConfigInput<VariantDefinitions> | FlatComponentConfigInput<string>;\n} {\n if (typeof configOrNamespace === 'string' && maybeConfig != null) {\n return { tag, namespace: configOrNamespace, config: maybeConfig };\n }\n\n const namespace = typeof tag === 'string' ? tag : 'styled';\n return {\n tag,\n namespace,\n config: configOrNamespace as\n | ComponentConfigInput<VariantDefinitions>\n | FlatComponentConfigInput<string>,\n };\n}\n\nexport function createStyled(api: StyledApi): StyledFactory {\n const makeRecipe = resolveRecipeFactory(api);\n\n function styled<Tag extends ElementType>(\n tag: Tag,\n configOrNamespace:\n | string\n | ComponentConfigInput<VariantDefinitions>\n | FlatComponentConfigInput<string>,\n maybeConfig?: ComponentConfigInput<VariantDefinitions> | FlatComponentConfigInput<string>,\n ) {\n const {\n tag: element,\n namespace,\n config,\n } = resolveStyledArgs(tag, configOrNamespace, maybeConfig);\n // `styled` still takes the legacy config object (`base`, `variants`, flat keys).\n // The engine accepts that shape as `styles`; axes stay on `recipe()` itself.\n const recipe = (\n makeRecipe as (input: {\n name: string;\n styles: unknown;\n }) => (selections?: Record<string, unknown>) => { toString(): string }\n )({\n name: namespace,\n styles: config,\n });\n const variantKeys = getVariantKeysFromConfig(\n config as Record<string, unknown> | ((ctx: unknown) => Record<string, unknown>),\n );\n\n const Component = forwardRef<Element, ComponentPropsWithoutRef<Tag> & Record<string, unknown>>(\n function StyledComponent(props, ref) {\n const { className, ...propsWithoutClassName } = props;\n const { variants, rest } = splitVariantProps(\n propsWithoutClassName as Record<string, unknown>,\n variantKeys,\n );\n const mergedClassName = cx(recipe(variants), className);\n const Element = element;\n\n return <Element {...rest} ref={ref} className={mergedClassName} />;\n },\n );\n\n Component.displayName = namespace.charAt(0).toUpperCase() + namespace.slice(1);\n\n return Component;\n }\n\n return styled as StyledFactory;\n}\n"],"mappings":";;;;;;;;AAAA,MAAM,uBAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,kBACd,OACA,aAIA;CACA,MAAM,WAAoC,CAAC;CAC3C,MAAM,OAAO,EAAE,GAAG,MAAM;CAExB,KAAK,MAAM,OAAO,aAChB,IAAI,OAAO,MAAM;EACf,SAAS,OAAO,KAAK;EACrB,OAAO,KAAK;CACd;CAGF,OAAO,KAAK;CACZ,OAAO,KAAK;CAEZ,OAAO;EACL;EACM;CACR;AACF;AAEA,SAAgB,yBACd,QACmB;CACnB,IAAI,OAAO,WAAW,YACpB,OAAO,CAAC;CAGV,IAAI,cAAc,UAAU,OAAO,YAAY,OAAO,OAAO,aAAa,UACxE,OAAO,OAAO,KAAK,OAAO,QAAQ;CAGpC,OAAO,OAAO,KAAK,MAAM,CAAC,CAAC,QAAQ,QAAQ,CAAC,qBAAqB,IAAI,GAAG,CAAC;AAC3E;;;ACIA,SAAS,qBAAqB,KAA+B;CAC3D,IAAI,YAAY,KAAK,OAAO,IAAI;CAChC,OAAO,IAAI;AACb;AAEA,SAAS,kBACP,KACA,mBAIA,aAKA;CACA,IAAI,OAAO,sBAAsB,YAAY,eAAe,MAC1D,OAAO;EAAE;EAAK,WAAW;EAAmB,QAAQ;CAAY;CAIlE,OAAO;EACL;EACA,WAHgB,OAAO,QAAQ,WAAW,MAAM;EAIhD,QAAQ;CAGV;AACF;AAEA,SAAgB,aAAa,KAA+B;CAC1D,MAAM,aAAa,qBAAqB,GAAG;CAE3C,SAAS,OACP,KACA,mBAIA,aACA;EACA,MAAM,EACJ,KAAK,SACL,WACA,WACE,kBAAkB,KAAK,mBAAmB,WAAW;EAGzD,MAAM,SACJ,WAIA;GACA,MAAM;GACN,QAAQ;EACV,CAAC;EACD,MAAM,cAAc,yBAClB,MACF;EAEA,MAAM,aAAA,GAAYA,MAAAA,WAAAA,CAChB,SAAS,gBAAgB,OAAO,KAAK;GACnC,MAAM,EAAE,WAAW,GAAG,0BAA0B;GAChD,MAAM,EAAE,UAAU,SAAS,kBACzB,uBACA,WACF;GACA,MAAM,mBAAA,GAAkBC,WAAAA,GAAAA,CAAG,OAAO,QAAQ,GAAG,SAAS;GAGtD,QAAO,GAAA,kBAAA,IAAA,CAACC,SAAD;IAAS,GAAI;IAAW;IAAK,WAAW;GAAkB,CAAA;EACnE,CACF;EAEA,UAAU,cAAc,UAAU,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,UAAU,MAAM,CAAC;EAE7E,OAAO;CACT;CAEA,OAAO;AACT"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export { cssProp } from './css-prop-runtime.cjs';
|
|
7
|
-
|
|
1
|
+
import { i as resolveHashClass, n as CssStylesHost, r as HashClassFn, t as cssProp } from "./css-prop-runtime-zKybLO8E.cjs";
|
|
2
|
+
import { n as WithCssProp, t as CssPropValue } from "./types-DcDsqg2q.cjs";
|
|
3
|
+
import { CSSProperties, ComponentConfigInput, ComponentReturn, ComponentVariants, FlatComponentConfigInput, FlatComponentReturn, StylesApi, TypeStylesApi, VariantDefinitions } from "typestyles";
|
|
4
|
+
import { ComponentPropsWithoutRef, ElementType, ForwardRefExoticComponent, ReactNode, RefAttributes } from "react";
|
|
5
|
+
//#region src/create-styled.d.ts
|
|
8
6
|
type StyledComponentType<Tag extends ElementType, Recipe> = ForwardRefExoticComponent<ComponentPropsWithoutRef<Tag> & ComponentVariants<Recipe> & RefAttributes<Element>>;
|
|
9
7
|
type StyledFactory = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
<Tag extends ElementType, const V extends VariantDefinitions>(tag: Tag, config: ComponentConfigInput<V>): StyledComponentType<Tag, ComponentReturn<V>>;
|
|
9
|
+
<Tag extends ElementType, const V extends VariantDefinitions, const N extends string>(tag: Tag, namespace: N, config: ComponentConfigInput<V>): StyledComponentType<Tag, ComponentReturn<V>>;
|
|
10
|
+
<Tag extends ElementType, const K extends string>(tag: Tag, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
11
|
+
<Tag extends ElementType, const K extends string, const N extends string>(tag: Tag, namespace: N, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
declare
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
/** Accepts `createTypeStyles()` (preferred) or a lower-level `createStyles()` instance. */
|
|
14
|
+
type StyledApi = Pick<TypeStylesApi, 'recipe'> | StylesApi;
|
|
15
|
+
export declare function createStyled(api: StyledApi): StyledFactory;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/context.d.ts
|
|
18
|
+
export declare const TypeStylesContext: import("react").Context<CssStylesHost | null>;
|
|
19
|
+
export declare function TypeStylesProvider({ styles, children }: {
|
|
20
|
+
/** Prefer a `createTypeStyles()` result; `createStyles()` instances also work. */
|
|
21
|
+
styles: CssStylesHost;
|
|
22
|
+
children: ReactNode;
|
|
21
23
|
}): React.JSX.Element;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/css-prop.d.ts
|
|
26
|
+
export declare function resolveCssPropClass(hashClass: (properties: CSSProperties, label?: string) => string, css: CssPropValue | undefined, className?: string): string;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { type CssPropValue, type CssStylesHost, type HashClassFn, type StyledApi, type StyledFactory, type WithCssProp, cssProp, resolveHashClass };
|
|
29
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/create-styled.tsx","../src/context.tsx","../src/css-prop.ts"],"mappings":";;;;;KAoBK,oBAAoB,YAAY,aAAa,UAAU,0BAC1D,yBAAyB,OAAO,kBAAkB,UAAU,cAAc;KAGhE;GACT,YAAY,mBAAmB,UAAU,oBACxC,KAAK,KACL,QAAQ,qBAAqB,KAC5B,oBAAoB,KAAK,gBAAgB;GAC3C,YAAY,mBAAmB,UAAU,0BAA0B,kBAClE,KAAK,KACL,WAAW,GACX,QAAQ,qBAAqB,KAC5B,oBAAoB,KAAK,gBAAgB;GAC3C,YAAY,mBAAmB,kBAC9B,KAAK,KACL,QAAQ,yBAAyB,KAChC,oBAAoB,KAAK,oBAAoB;GAC/C,YAAY,mBAAmB,wBAAwB,kBACtD,KAAK,KACL,WAAW,GACX,QAAQ,yBAAyB,KAChC,oBAAoB,KAAK,oBAAoB;;;KAMtC,YAAY,KAAK,2BAA2B;wBAiCxC,aAAa,KAAK,YAAY;;;qBC9EjC,mCAAiB,QAAA;wBAEd,qBACd,QACA;;EAGA,QAAQ;EACR,UAAU;IACR,MAAM,IAAI;;;wBCRE,oBACd,YAAY,YAAY,eAAe,2BACvC,KAAK,0BACL"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export { cssProp } from './css-prop-runtime.js';
|
|
7
|
-
|
|
1
|
+
import { i as resolveHashClass, n as CssStylesHost, r as HashClassFn, t as cssProp } from "./css-prop-runtime-zKybLO8E.js";
|
|
2
|
+
import { n as WithCssProp, t as CssPropValue } from "./types-DcDsqg2q.js";
|
|
3
|
+
import { ComponentPropsWithoutRef, ElementType, ForwardRefExoticComponent, ReactNode, RefAttributes } from "react";
|
|
4
|
+
import { CSSProperties, ComponentConfigInput, ComponentReturn, ComponentVariants, FlatComponentConfigInput, FlatComponentReturn, StylesApi, TypeStylesApi, VariantDefinitions } from "typestyles";
|
|
5
|
+
//#region src/create-styled.d.ts
|
|
8
6
|
type StyledComponentType<Tag extends ElementType, Recipe> = ForwardRefExoticComponent<ComponentPropsWithoutRef<Tag> & ComponentVariants<Recipe> & RefAttributes<Element>>;
|
|
9
7
|
type StyledFactory = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
<Tag extends ElementType, const V extends VariantDefinitions>(tag: Tag, config: ComponentConfigInput<V>): StyledComponentType<Tag, ComponentReturn<V>>;
|
|
9
|
+
<Tag extends ElementType, const V extends VariantDefinitions, const N extends string>(tag: Tag, namespace: N, config: ComponentConfigInput<V>): StyledComponentType<Tag, ComponentReturn<V>>;
|
|
10
|
+
<Tag extends ElementType, const K extends string>(tag: Tag, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
11
|
+
<Tag extends ElementType, const K extends string, const N extends string>(tag: Tag, namespace: N, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
declare
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
/** Accepts `createTypeStyles()` (preferred) or a lower-level `createStyles()` instance. */
|
|
14
|
+
type StyledApi = Pick<TypeStylesApi, 'recipe'> | StylesApi;
|
|
15
|
+
export declare function createStyled(api: StyledApi): StyledFactory;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/context.d.ts
|
|
18
|
+
export declare const TypeStylesContext: import("react").Context<CssStylesHost | null>;
|
|
19
|
+
export declare function TypeStylesProvider({ styles, children }: {
|
|
20
|
+
/** Prefer a `createTypeStyles()` result; `createStyles()` instances also work. */
|
|
21
|
+
styles: CssStylesHost;
|
|
22
|
+
children: ReactNode;
|
|
21
23
|
}): React.JSX.Element;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/css-prop.d.ts
|
|
26
|
+
export declare function resolveCssPropClass(hashClass: (properties: CSSProperties, label?: string) => string, css: CssPropValue | undefined, className?: string): string;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { type CssPropValue, type CssStylesHost, type HashClassFn, type StyledApi, type StyledFactory, type WithCssProp, cssProp, resolveHashClass };
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/create-styled.tsx","../src/context.tsx","../src/css-prop.ts"],"mappings":";;;;;KAoBK,oBAAoB,YAAY,aAAa,UAAU,0BAC1D,yBAAyB,OAAO,kBAAkB,UAAU,cAAc;KAGhE;GACT,YAAY,mBAAmB,UAAU,oBACxC,KAAK,KACL,QAAQ,qBAAqB,KAC5B,oBAAoB,KAAK,gBAAgB;GAC3C,YAAY,mBAAmB,UAAU,0BAA0B,kBAClE,KAAK,KACL,WAAW,GACX,QAAQ,qBAAqB,KAC5B,oBAAoB,KAAK,gBAAgB;GAC3C,YAAY,mBAAmB,kBAC9B,KAAK,KACL,QAAQ,yBAAyB,KAChC,oBAAoB,KAAK,oBAAoB;GAC/C,YAAY,mBAAmB,wBAAwB,kBACtD,KAAK,KACL,WAAW,GACX,QAAQ,yBAAyB,KAChC,oBAAoB,KAAK,oBAAoB;;;KAMtC,YAAY,KAAK,2BAA2B;wBAiCxC,aAAa,KAAK,YAAY;;;qBC9EjC,mCAAiB,QAAA;wBAEd,qBACd,QACA;;EAGA,QAAQ;EACR,UAAU;IACR,MAAM,IAAI;;;wBCRE,oBACd,YAAY,YAAY,eAAe,2BACvC,KAAK,0BACL"}
|