@typestyles/react 0.0.0-unstable.f96b13308930 → 0.3.0
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 +15 -15
- package/dist/{chunk-4BYX2HZ7.js → chunk-IHZMLPG2.js} +2 -2
- package/dist/chunk-IHZMLPG2.js.map +1 -0
- package/dist/chunk-KM65VQPZ.js +11 -0
- package/dist/chunk-KM65VQPZ.js.map +1 -0
- package/dist/chunk-TLEOUPD2.js +10 -0
- package/dist/chunk-TLEOUPD2.js.map +1 -0
- package/dist/css-prop-runtime-DHYMbbZm.d.cts +12 -0
- package/dist/css-prop-runtime-DHYMbbZm.d.ts +12 -0
- package/dist/css-prop-runtime.cjs +10 -2
- 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 +2 -1
- package/dist/index.cjs +18 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.cjs +12 -4
- package/dist/jsx-dev-runtime.cjs.map +1 -1
- package/dist/jsx-dev-runtime.js +6 -5
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.cjs +12 -4
- package/dist/jsx-runtime.cjs.map +1 -1
- package/dist/jsx-runtime.js +6 -5
- package/dist/jsx-runtime.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-3YCUQVCM.js +0 -8
- package/dist/chunk-3YCUQVCM.js.map +0 -1
- package/dist/chunk-4BYX2HZ7.js.map +0 -1
package/README.md
CHANGED
|
@@ -10,14 +10,14 @@ npm install @typestyles/react typestyles react react-dom
|
|
|
10
10
|
|
|
11
11
|
## `createStyled` / `styled`
|
|
12
12
|
|
|
13
|
-
Thin React wrapper over `
|
|
13
|
+
Thin React wrapper over `recipe` from `createTypeStyles` with typed variant props via `ComponentVariants`:
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
import {
|
|
16
|
+
import { createTypeStyles } from 'typestyles';
|
|
17
17
|
import { createStyled, TypeStylesProvider } from '@typestyles/react';
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
const styled = createStyled(
|
|
19
|
+
const api = createTypeStyles({ scopeId: 'app' });
|
|
20
|
+
const styled = createStyled(api);
|
|
21
21
|
|
|
22
22
|
const Button = styled('button', {
|
|
23
23
|
base: { padding: '8px 16px', border: 'none', borderRadius: '4px' },
|
|
@@ -32,7 +32,7 @@ const Button = styled('button', {
|
|
|
32
32
|
|
|
33
33
|
function App() {
|
|
34
34
|
return (
|
|
35
|
-
<TypeStylesProvider styles={
|
|
35
|
+
<TypeStylesProvider styles={api}>
|
|
36
36
|
<Button intent="ghost">Click me</Button>
|
|
37
37
|
</TypeStylesProvider>
|
|
38
38
|
);
|
|
@@ -51,12 +51,12 @@ Point JSX at `@typestyles/react` and wrap your app in `TypeStylesProvider`:
|
|
|
51
51
|
|
|
52
52
|
```tsx
|
|
53
53
|
/** @jsxImportSource @typestyles/react */
|
|
54
|
-
import {
|
|
54
|
+
import { api } from './styles';
|
|
55
55
|
import { TypeStylesProvider } from '@typestyles/react';
|
|
56
56
|
|
|
57
57
|
export function App() {
|
|
58
58
|
return (
|
|
59
|
-
<TypeStylesProvider styles={
|
|
59
|
+
<TypeStylesProvider styles={api}>
|
|
60
60
|
<div css={{ color: 'red', padding: '1rem' }}>Hello</div>
|
|
61
61
|
</TypeStylesProvider>
|
|
62
62
|
);
|
|
@@ -73,7 +73,7 @@ Or in `tsconfig.json`:
|
|
|
73
73
|
}
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
Inline style objects are converted to deterministic classes via `
|
|
76
|
+
Inline style objects are converted to deterministic classes via `hash` (or `hashClass` on a `createStyles()` instance) at runtime.
|
|
77
77
|
|
|
78
78
|
## Zero-runtime `css` prop (Babel)
|
|
79
79
|
|
|
@@ -102,13 +102,13 @@ Dynamic expressions (e.g. `css={condition && { color: 'red' }}`) are left unchan
|
|
|
102
102
|
|
|
103
103
|
## API
|
|
104
104
|
|
|
105
|
-
| Export | Description
|
|
106
|
-
| ------------------------------- |
|
|
107
|
-
| `createStyled(
|
|
108
|
-
| `TypeStylesProvider` | Supplies
|
|
109
|
-
| `resolveCssPropClass` | Low-level helper: `css` object → merged `className`
|
|
110
|
-
| `@typestyles/react/jsx-runtime` | Drop-in jsx runtime with `css` prop support
|
|
111
|
-
| `@typestyles/react/babel` | Babel plugin for zero-runtime static `css` props
|
|
105
|
+
| Export | Description |
|
|
106
|
+
| ------------------------------- | --------------------------------------------------------------------- |
|
|
107
|
+
| `createStyled(api)` | Returns a `styled(tag, config)` factory backed by `recipe` on the API |
|
|
108
|
+
| `TypeStylesProvider` | Supplies the styles API to the jsx runtime for `css` prop resolution |
|
|
109
|
+
| `resolveCssPropClass` | Low-level helper: `css` object → merged `className` |
|
|
110
|
+
| `@typestyles/react/jsx-runtime` | Drop-in jsx runtime with `css` prop support |
|
|
111
|
+
| `@typestyles/react/babel` | Babel plugin for zero-runtime static `css` props |
|
|
112
112
|
|
|
113
113
|
## Future work
|
|
114
114
|
|
|
@@ -18,5 +18,5 @@ function resolveCssPropClass(hashClass, css, className) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export { TypeStylesContext, TypeStylesProvider, resolveCssPropClass };
|
|
21
|
-
//# sourceMappingURL=chunk-
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-IHZMLPG2.js.map
|
|
22
|
+
//# sourceMappingURL=chunk-IHZMLPG2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context.tsx","../src/css-prop.ts"],"names":[],"mappings":";;;;;AAGO,IAAM,iBAAA,GAAoB,cAAoC,IAAI;AAElE,SAAS,kBAAA,CAAmB;AAAA,EACjC,MAAA;AAAA,EACA;AACF,CAAA,EAIsB;AACpB,EAAA,2BAAQ,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,QAAS,QAAA,EAAS,CAAA;AAC9D;ACVO,SAAS,mBAAA,CACd,SAAA,EACA,GAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,OAAO,EAAA,CAAG,SAAA,CAAU,GAAG,CAAA,EAAG,SAAS,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,GAAG,SAAS,CAAA;AACrB","file":"chunk-IHZMLPG2.js","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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/resolve-hash-class.ts
|
|
2
|
+
function resolveHashClass(api) {
|
|
3
|
+
if ("hash" in api && typeof api.hash === "function") {
|
|
4
|
+
return (properties, label) => api.hash(properties, { label });
|
|
5
|
+
}
|
|
6
|
+
return api.hashClass;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { resolveHashClass };
|
|
10
|
+
//# sourceMappingURL=chunk-KM65VQPZ.js.map
|
|
11
|
+
//# sourceMappingURL=chunk-KM65VQPZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resolve-hash-class.ts"],"names":[],"mappings":";AAQO,SAAS,iBAAiB,GAAA,EAAiC;AAChE,EAAA,IAAI,MAAA,IAAU,GAAA,IAAO,OAAO,GAAA,CAAI,SAAS,UAAA,EAAY;AACnD,IAAA,OAAO,CAAC,YAAY,KAAA,KAAU,GAAA,CAAI,KAAK,UAAA,EAAY,EAAE,OAAO,CAAA;AAAA,EAC9D;AACA,EAAA,OAAQ,GAAA,CAAkB,SAAA;AAC5B","file":"chunk-KM65VQPZ.js","sourcesContent":["import type { CSSProperties, StylesApi, TypeStylesApi } from 'typestyles';\n\n/** Styles host for the css prop / TypeStylesProvider. */\nexport type CssStylesHost = Pick<TypeStylesApi, 'hash'> | StylesApi;\n\nexport type HashClassFn = (properties: CSSProperties, label?: string) => string;\n\n/** Normalize `hash` (createTypeStyles) and `hashClass` (createStyles). */\nexport function resolveHashClass(api: CssStylesHost): HashClassFn {\n if ('hash' in api && typeof api.hash === 'function') {\n return (properties, label) => api.hash(properties, { label });\n }\n return (api as StylesApi).hashClass;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { resolveHashClass } from './chunk-KM65VQPZ.js';
|
|
2
|
+
|
|
3
|
+
// src/css-prop-runtime.ts
|
|
4
|
+
function cssProp(api, properties) {
|
|
5
|
+
return resolveHashClass(api)(properties);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { cssProp };
|
|
9
|
+
//# sourceMappingURL=chunk-TLEOUPD2.js.map
|
|
10
|
+
//# sourceMappingURL=chunk-TLEOUPD2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/css-prop-runtime.ts"],"names":[],"mappings":";;;AAKO,SAAS,OAAA,CAAQ,KAAoB,UAAA,EAAmC;AAC7E,EAAA,OAAO,gBAAA,CAAiB,GAAG,CAAA,CAAE,UAAU,CAAA;AACzC","file":"chunk-TLEOUPD2.js","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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TypeStylesApi, StylesApi, CSSProperties } from 'typestyles';
|
|
2
|
+
|
|
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
|
+
|
|
9
|
+
/** Runtime helper used by the Babel plugin for static `css` props. */
|
|
10
|
+
declare function cssProp(api: CssStylesHost, properties: CSSProperties): string;
|
|
11
|
+
|
|
12
|
+
export { type CssStylesHost as C, type HashClassFn as H, cssProp as c, resolveHashClass as r };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TypeStylesApi, StylesApi, CSSProperties } from 'typestyles';
|
|
2
|
+
|
|
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
|
+
|
|
9
|
+
/** Runtime helper used by the Babel plugin for static `css` props. */
|
|
10
|
+
declare function cssProp(api: CssStylesHost, properties: CSSProperties): string;
|
|
11
|
+
|
|
12
|
+
export { type CssStylesHost as C, type HashClassFn as H, cssProp as c, resolveHashClass as r };
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/resolve-hash-class.ts
|
|
4
|
+
function resolveHashClass(api) {
|
|
5
|
+
if ("hash" in api && typeof api.hash === "function") {
|
|
6
|
+
return (properties, label) => api.hash(properties, { label });
|
|
7
|
+
}
|
|
8
|
+
return api.hashClass;
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
// src/css-prop-runtime.ts
|
|
4
|
-
function cssProp(
|
|
5
|
-
return
|
|
12
|
+
function cssProp(api, properties) {
|
|
13
|
+
return resolveHashClass(api)(properties);
|
|
6
14
|
}
|
|
7
15
|
|
|
8
16
|
exports.cssProp = cssProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css-prop-runtime.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/resolve-hash-class.ts","../src/css-prop-runtime.ts"],"names":[],"mappings":";;;AAQO,SAAS,iBAAiB,GAAA,EAAiC;AAChE,EAAA,IAAI,MAAA,IAAU,GAAA,IAAO,OAAO,GAAA,CAAI,SAAS,UAAA,EAAY;AACnD,IAAA,OAAO,CAAC,YAAY,KAAA,KAAU,GAAA,CAAI,KAAK,UAAA,EAAY,EAAE,OAAO,CAAA;AAAA,EAC9D;AACA,EAAA,OAAQ,GAAA,CAAkB,SAAA;AAC5B;;;ACRO,SAAS,OAAA,CAAQ,KAAoB,UAAA,EAAmC;AAC7E,EAAA,OAAO,gBAAA,CAAiB,GAAG,CAAA,CAAE,UAAU,CAAA;AACzC","file":"css-prop-runtime.cjs","sourcesContent":["import type { CSSProperties, StylesApi, TypeStylesApi } from 'typestyles';\n\n/** Styles host for the css prop / TypeStylesProvider. */\nexport type CssStylesHost = Pick<TypeStylesApi, 'hash'> | StylesApi;\n\nexport type HashClassFn = (properties: CSSProperties, label?: string) => string;\n\n/** Normalize `hash` (createTypeStyles) and `hashClass` (createStyles). */\nexport function resolveHashClass(api: CssStylesHost): HashClassFn {\n if ('hash' in api && typeof api.hash === 'function') {\n return (properties, label) => api.hash(properties, { label });\n }\n return (api as StylesApi).hashClass;\n}\n","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"]}
|
|
@@ -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 'typestyles';
|
|
2
|
+
export { c as cssProp } from './css-prop-runtime-DHYMbbZm.cjs';
|
|
@@ -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 'typestyles';
|
|
2
|
+
export { c as cssProp } from './css-prop-runtime-DHYMbbZm.js';
|
package/dist/css-prop-runtime.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,10 @@ function getVariantKeysFromConfig(config) {
|
|
|
39
39
|
}
|
|
40
40
|
return Object.keys(config).filter((key) => !RESERVED_CONFIG_KEYS.has(key));
|
|
41
41
|
}
|
|
42
|
+
function resolveRecipeFactory(api) {
|
|
43
|
+
if ("recipe" in api) return api.recipe;
|
|
44
|
+
return api.component;
|
|
45
|
+
}
|
|
42
46
|
function resolveStyledArgs(tag, configOrNamespace, maybeConfig) {
|
|
43
47
|
if (typeof configOrNamespace === "string" && maybeConfig != null) {
|
|
44
48
|
return { tag, namespace: configOrNamespace, config: maybeConfig };
|
|
@@ -50,14 +54,15 @@ function resolveStyledArgs(tag, configOrNamespace, maybeConfig) {
|
|
|
50
54
|
config: configOrNamespace
|
|
51
55
|
};
|
|
52
56
|
}
|
|
53
|
-
function createStyled(
|
|
57
|
+
function createStyled(api) {
|
|
58
|
+
const makeRecipe = resolveRecipeFactory(api);
|
|
54
59
|
function styled(tag, configOrNamespace, maybeConfig) {
|
|
55
60
|
const {
|
|
56
61
|
tag: element,
|
|
57
62
|
namespace,
|
|
58
63
|
config
|
|
59
64
|
} = resolveStyledArgs(tag, configOrNamespace, maybeConfig);
|
|
60
|
-
const recipe =
|
|
65
|
+
const recipe = makeRecipe(namespace, config);
|
|
61
66
|
const variantKeys = getVariantKeysFromConfig(
|
|
62
67
|
config
|
|
63
68
|
);
|
|
@@ -95,9 +100,17 @@ function resolveCssPropClass(hashClass, css, className) {
|
|
|
95
100
|
return typestyles.cx(className);
|
|
96
101
|
}
|
|
97
102
|
|
|
103
|
+
// src/resolve-hash-class.ts
|
|
104
|
+
function resolveHashClass(api) {
|
|
105
|
+
if ("hash" in api && typeof api.hash === "function") {
|
|
106
|
+
return (properties, label) => api.hash(properties, { label });
|
|
107
|
+
}
|
|
108
|
+
return api.hashClass;
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
// src/css-prop-runtime.ts
|
|
99
|
-
function cssProp(
|
|
100
|
-
return
|
|
112
|
+
function cssProp(api, properties) {
|
|
113
|
+
return resolveHashClass(api)(properties);
|
|
101
114
|
}
|
|
102
115
|
|
|
103
116
|
exports.TypeStylesContext = TypeStylesContext;
|
|
@@ -105,5 +118,6 @@ exports.TypeStylesProvider = TypeStylesProvider;
|
|
|
105
118
|
exports.createStyled = createStyled;
|
|
106
119
|
exports.cssProp = cssProp;
|
|
107
120
|
exports.resolveCssPropClass = resolveCssPropClass;
|
|
121
|
+
exports.resolveHashClass = resolveHashClass;
|
|
108
122
|
//# sourceMappingURL=index.cjs.map
|
|
109
123
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/split-props.ts","../src/create-styled.tsx","../src/context.tsx","../src/css-prop.ts","../src/css-prop-runtime.ts"],"names":["forwardRef","cx","createContext","jsx"],"mappings":";;;;;;;;;AAAA,IAAM,oBAAA,uBAA2B,GAAA,CAAI;AAAA,EACnC,MAAA;AAAA,EACA,UAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAC,CAAA;AAEM,SAAS,iBAAA,CACd,OACA,WAAA,EAIA;AACA,EAAA,MAAM,WAAoC,EAAC;AAC3C,EAAA,MAAM,IAAA,GAAO,EAAE,GAAG,KAAA,EAAM;AAExB,EAAA,KAAA,MAAW,OAAO,WAAA,EAAa;AAC7B,IAAA,IAAI,OAAO,IAAA,EAAM;AACf,MAAA,QAAA,CAAS,GAAG,CAAA,GAAI,IAAA,CAAK,GAAG,CAAA;AACxB,MAAA,OAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAAA,EACF;AAEA,EAAA,OAAO,IAAA,CAAK,SAAA;AACZ,EAAA,OAAO,IAAA,CAAK,GAAA;AAEZ,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA;AAAA,GACF;AACF;AAEO,SAAS,yBACd,MAAA,EACmB;AACnB,EAAA,IAAI,OAAO,WAAW,UAAA,EAAY;AAChC,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,IAAI,cAAc,MAAA,IAAU,MAAA,CAAO,YAAY,OAAO,MAAA,CAAO,aAAa,QAAA,EAAU;AAClF,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,QAAQ,CAAA;AAAA,EACpC;AAEA,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CAAE,MAAA,CAAO,CAAC,GAAA,KAAQ,CAAC,oBAAA,CAAqB,GAAA,CAAI,GAAG,CAAC,CAAA;AAC3E;ACFA,SAAS,iBAAA,CACP,GAAA,EACA,iBAAA,EAIA,WAAA,EAKA;AACA,EAAA,IAAI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,CAAU,WAAA,GAAc,UAAU,MAAA,CAAO,CAAC,EAAE,WAAA,EAAY,GAAI,SAAA,CAAU,KAAA,CAAM,CAAC,CAAA;AAE7E,IAAA,OAAO,SAAA;AAAA,EACT;AAEA,EAAA,OAAO,MAAA;AACT;AC7GO,IAAM,iBAAA,GAAoBC,oBAAgC,IAAI;AAE9D,SAAS,kBAAA,CAAmB;AAAA,EACjC,MAAA;AAAA,EACA;AACF,CAAA,EAGsB;AACpB,EAAA,uBAAOC,cAAAA,CAAC,iBAAA,CAAkB,UAAlB,EAA2B,KAAA,EAAO,QAAS,QAAA,EAAS,CAAA;AAC9D;ACTO,SAAS,mBAAA,CACd,SAAA,EACA,GAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,OAAOF,aAAAA,CAAG,SAAA,CAAU,GAAG,CAAA,EAAG,SAAS,CAAA;AAAA,EACrC;AACA,EAAA,OAAOA,cAAG,SAAS,CAAA;AACrB;;;ACXO,SAAS,OAAA,CACd,QACA,UAAA,EACQ;AACR,EAAA,OAAO,MAAA,CAAO,UAAU,UAAU,CAAA;AACpC","file":"index.cjs","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 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\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(styles: StylesApi): StyledFactory {\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 const recipe = styles.component(namespace, config as ComponentConfigInput<VariantDefinitions>);\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(\n (recipe as (selections?: Record<string, unknown>) => string)(variants),\n className,\n );\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","import { createContext, type ReactNode } from 'react';\nimport type { StylesApi } from 'typestyles';\n\nexport const TypeStylesContext = createContext<StylesApi | null>(null);\n\nexport function TypeStylesProvider({\n styles,\n children,\n}: {\n styles: StylesApi;\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","import type { CSSProperties } from 'typestyles';\n\nexport function cssProp(\n styles: { hashClass: (properties: CSSProperties, label?: string) => string },\n properties: CSSProperties,\n): string {\n return styles.hashClass(properties);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/split-props.ts","../src/create-styled.tsx","../src/context.tsx","../src/css-prop.ts","../src/resolve-hash-class.ts","../src/css-prop-runtime.ts"],"names":["forwardRef","cx","createContext","jsx"],"mappings":";;;;;;;;;AAAA,IAAM,oBAAA,uBAA2B,GAAA,CAAI;AAAA,EACnC,MAAA;AAAA,EACA,UAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAC,CAAA;AAEM,SAAS,iBAAA,CACd,OACA,WAAA,EAIA;AACA,EAAA,MAAM,WAAoC,EAAC;AAC3C,EAAA,MAAM,IAAA,GAAO,EAAE,GAAG,KAAA,EAAM;AAExB,EAAA,KAAA,MAAW,OAAO,WAAA,EAAa;AAC7B,IAAA,IAAI,OAAO,IAAA,EAAM;AACf,MAAA,QAAA,CAAS,GAAG,CAAA,GAAI,IAAA,CAAK,GAAG,CAAA;AACxB,MAAA,OAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAAA,EACF;AAEA,EAAA,OAAO,IAAA,CAAK,SAAA;AACZ,EAAA,OAAO,IAAA,CAAK,GAAA;AAEZ,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA;AAAA,GACF;AACF;AAEO,SAAS,yBACd,MAAA,EACmB;AACnB,EAAA,IAAI,OAAO,WAAW,UAAA,EAAY;AAChC,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,IAAI,cAAc,MAAA,IAAU,MAAA,CAAO,YAAY,OAAO,MAAA,CAAO,aAAa,QAAA,EAAU;AAClF,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,QAAQ,CAAA;AAAA,EACpC;AA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,OAAO,CAAA;AAAA,EAC9D;AACA,EAAA,OAAQ,GAAA,CAAkB,SAAA;AAC5B;;;ACRO,SAAS,OAAA,CAAQ,KAAoB,UAAA,EAAmC;AAC7E,EAAA,OAAO,gBAAA,CAAiB,GAAG,CAAA,CAAE,UAAU,CAAA;AACzC","file":"index.cjs","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 const recipe = makeRecipe(namespace, config as ComponentConfigInput<VariantDefinitions>);\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(\n (recipe as (selections?: Record<string, unknown>) => string)(variants),\n className,\n );\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","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","import type { CSSProperties, StylesApi, TypeStylesApi } from 'typestyles';\n\n/** Styles host for the css prop / TypeStylesProvider. */\nexport type CssStylesHost = Pick<TypeStylesApi, 'hash'> | StylesApi;\n\nexport type HashClassFn = (properties: CSSProperties, label?: string) => string;\n\n/** Normalize `hash` (createTypeStyles) and `hashClass` (createStyles). */\nexport function resolveHashClass(api: CssStylesHost): HashClassFn {\n if ('hash' in api && typeof api.hash === 'function') {\n return (properties, label) => api.hash(properties, { label });\n }\n return (api as StylesApi).hashClass;\n}\n","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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ElementType, ForwardRefExoticComponent, ComponentPropsWithoutRef, RefAttributes, ReactNode } from 'react';
|
|
3
|
-
import { VariantDefinitions, ComponentConfigInput, ComponentVariants, ComponentReturn, FlatComponentConfigInput, FlatComponentReturn,
|
|
3
|
+
import { TypeStylesApi, StylesApi, VariantDefinitions, ComponentConfigInput, ComponentVariants, ComponentReturn, FlatComponentConfigInput, FlatComponentReturn, CSSProperties } from 'typestyles';
|
|
4
|
+
import { C as CssStylesHost } from './css-prop-runtime-DHYMbbZm.cjs';
|
|
5
|
+
export { H as HashClassFn, c as cssProp, r as resolveHashClass } from './css-prop-runtime-DHYMbbZm.cjs';
|
|
4
6
|
import { C as CssPropValue } from './types-_vEO6H8X.cjs';
|
|
5
7
|
export { W as WithCssProp } from './types-_vEO6H8X.cjs';
|
|
6
|
-
export { cssProp } from './css-prop-runtime.cjs';
|
|
7
8
|
|
|
8
9
|
type StyledComponentType<Tag extends ElementType, Recipe> = ForwardRefExoticComponent<ComponentPropsWithoutRef<Tag> & ComponentVariants<Recipe> & RefAttributes<Element>>;
|
|
9
10
|
type StyledFactory = {
|
|
@@ -12,14 +13,17 @@ type StyledFactory = {
|
|
|
12
13
|
<Tag extends ElementType, const K extends string>(tag: Tag, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
13
14
|
<Tag extends ElementType, const K extends string, const N extends string>(tag: Tag, namespace: N, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
/** Accepts `createTypeStyles()` (preferred) or a lower-level `createStyles()` instance. */
|
|
17
|
+
type StyledApi = Pick<TypeStylesApi, 'recipe'> | StylesApi;
|
|
18
|
+
declare function createStyled(api: StyledApi): StyledFactory;
|
|
16
19
|
|
|
17
|
-
declare const TypeStylesContext: react.Context<
|
|
20
|
+
declare const TypeStylesContext: react.Context<CssStylesHost | null>;
|
|
18
21
|
declare function TypeStylesProvider({ styles, children, }: {
|
|
19
|
-
|
|
22
|
+
/** Prefer a `createTypeStyles()` result; `createStyles()` instances also work. */
|
|
23
|
+
styles: CssStylesHost;
|
|
20
24
|
children: ReactNode;
|
|
21
25
|
}): React.JSX.Element;
|
|
22
26
|
|
|
23
27
|
declare function resolveCssPropClass(hashClass: (properties: CSSProperties, label?: string) => string, css: CssPropValue | undefined, className?: string): string;
|
|
24
28
|
|
|
25
|
-
export { CssPropValue, type StyledFactory, TypeStylesContext, TypeStylesProvider, createStyled, resolveCssPropClass };
|
|
29
|
+
export { CssPropValue, CssStylesHost, type StyledApi, type StyledFactory, TypeStylesContext, TypeStylesProvider, createStyled, resolveCssPropClass };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ElementType, ForwardRefExoticComponent, ComponentPropsWithoutRef, RefAttributes, ReactNode } from 'react';
|
|
3
|
-
import { VariantDefinitions, ComponentConfigInput, ComponentVariants, ComponentReturn, FlatComponentConfigInput, FlatComponentReturn,
|
|
3
|
+
import { TypeStylesApi, StylesApi, VariantDefinitions, ComponentConfigInput, ComponentVariants, ComponentReturn, FlatComponentConfigInput, FlatComponentReturn, CSSProperties } from 'typestyles';
|
|
4
|
+
import { C as CssStylesHost } from './css-prop-runtime-DHYMbbZm.js';
|
|
5
|
+
export { H as HashClassFn, c as cssProp, r as resolveHashClass } from './css-prop-runtime-DHYMbbZm.js';
|
|
4
6
|
import { C as CssPropValue } from './types-_vEO6H8X.js';
|
|
5
7
|
export { W as WithCssProp } from './types-_vEO6H8X.js';
|
|
6
|
-
export { cssProp } from './css-prop-runtime.js';
|
|
7
8
|
|
|
8
9
|
type StyledComponentType<Tag extends ElementType, Recipe> = ForwardRefExoticComponent<ComponentPropsWithoutRef<Tag> & ComponentVariants<Recipe> & RefAttributes<Element>>;
|
|
9
10
|
type StyledFactory = {
|
|
@@ -12,14 +13,17 @@ type StyledFactory = {
|
|
|
12
13
|
<Tag extends ElementType, const K extends string>(tag: Tag, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
13
14
|
<Tag extends ElementType, const K extends string, const N extends string>(tag: Tag, namespace: N, config: FlatComponentConfigInput<K>): StyledComponentType<Tag, FlatComponentReturn<K>>;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
/** Accepts `createTypeStyles()` (preferred) or a lower-level `createStyles()` instance. */
|
|
17
|
+
type StyledApi = Pick<TypeStylesApi, 'recipe'> | StylesApi;
|
|
18
|
+
declare function createStyled(api: StyledApi): StyledFactory;
|
|
16
19
|
|
|
17
|
-
declare const TypeStylesContext: react.Context<
|
|
20
|
+
declare const TypeStylesContext: react.Context<CssStylesHost | null>;
|
|
18
21
|
declare function TypeStylesProvider({ styles, children, }: {
|
|
19
|
-
|
|
22
|
+
/** Prefer a `createTypeStyles()` result; `createStyles()` instances also work. */
|
|
23
|
+
styles: CssStylesHost;
|
|
20
24
|
children: ReactNode;
|
|
21
25
|
}): React.JSX.Element;
|
|
22
26
|
|
|
23
27
|
declare function resolveCssPropClass(hashClass: (properties: CSSProperties, label?: string) => string, css: CssPropValue | undefined, className?: string): string;
|
|
24
28
|
|
|
25
|
-
export { CssPropValue, type StyledFactory, TypeStylesContext, TypeStylesProvider, createStyled, resolveCssPropClass };
|
|
29
|
+
export { CssPropValue, CssStylesHost, type StyledApi, type StyledFactory, TypeStylesContext, TypeStylesProvider, createStyled, resolveCssPropClass };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { TypeStylesContext, TypeStylesProvider, resolveCssPropClass } from './chunk-
|
|
2
|
-
export { cssProp } from './chunk-
|
|
1
|
+
export { TypeStylesContext, TypeStylesProvider, resolveCssPropClass } from './chunk-IHZMLPG2.js';
|
|
2
|
+
export { cssProp } from './chunk-TLEOUPD2.js';
|
|
3
|
+
export { resolveHashClass } from './chunk-KM65VQPZ.js';
|
|
3
4
|
import { forwardRef } from 'react';
|
|
4
5
|
import { cx } from 'typestyles';
|
|
5
6
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -37,6 +38,10 @@ function getVariantKeysFromConfig(config) {
|
|
|
37
38
|
}
|
|
38
39
|
return Object.keys(config).filter((key) => !RESERVED_CONFIG_KEYS.has(key));
|
|
39
40
|
}
|
|
41
|
+
function resolveRecipeFactory(api) {
|
|
42
|
+
if ("recipe" in api) return api.recipe;
|
|
43
|
+
return api.component;
|
|
44
|
+
}
|
|
40
45
|
function resolveStyledArgs(tag, configOrNamespace, maybeConfig) {
|
|
41
46
|
if (typeof configOrNamespace === "string" && maybeConfig != null) {
|
|
42
47
|
return { tag, namespace: configOrNamespace, config: maybeConfig };
|
|
@@ -48,14 +53,15 @@ function resolveStyledArgs(tag, configOrNamespace, maybeConfig) {
|
|
|
48
53
|
config: configOrNamespace
|
|
49
54
|
};
|
|
50
55
|
}
|
|
51
|
-
function createStyled(
|
|
56
|
+
function createStyled(api) {
|
|
57
|
+
const makeRecipe = resolveRecipeFactory(api);
|
|
52
58
|
function styled(tag, configOrNamespace, maybeConfig) {
|
|
53
59
|
const {
|
|
54
60
|
tag: element,
|
|
55
61
|
namespace,
|
|
56
62
|
config
|
|
57
63
|
} = resolveStyledArgs(tag, configOrNamespace, maybeConfig);
|
|
58
|
-
const recipe =
|
|
64
|
+
const recipe = makeRecipe(namespace, config);
|
|
59
65
|
const variantKeys = getVariantKeysFromConfig(
|
|
60
66
|
config
|
|
61
67
|
);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/split-props.ts","../src/create-styled.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/split-props.ts","../src/create-styled.tsx"],"names":[],"mappings":";;;;;;;;AAAA,IAAM,oBAAA,uBAA2B,GAAA,CAAI;AAAA,EACnC,MAAA;AAAA,EACA,UAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAC,CAAA;AAEM,SAAS,iBAAA,CACd,OACA,WAAA,EAIA;AACA,EAAA,MAAM,WAAoC,EAAC;AAC3C,EAAA,MAAM,IAAA,GAAO,EAAE,GAAG,KAAA,EAAM;AAExB,EAAA,KAAA,MAAW,OAAO,WAAA,EAAa;AAC7B,IAAA,IAAI,OAAO,IAAA,EAAM;AACf,MAAA,QAAA,CAAS,GAAG,CAAA,GAAI,IAAA,CAAK,GAAG,CAAA;AACxB,MAAA,OAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAAA,EACF;AAEA,EAAA,OAAO,IAAA,CAAK,SAAA;AACZ,EAAA,OAAO,IAAA,CAAK,GAAA;AAEZ,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA;AAAA,GACF;AACF;AAEO,SAAS,yBACd,MAAA,EACmB;AACnB,EAAA,IAAI,OAAO,WAAW,UAAA,EAAY;AAChC,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,IAAI,cAAc,MAAA,IAAU,MAAA,CAAO,YAAY,OAAO,MAAA,CAAO,aAAa,QAAA,EAAU;AAClF,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,QAAQ,CAAA;AAAA,EACpC;AAEA,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CAAE,MAAA,C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,EAAU,IAAA,EAAK,GAAI,iBAAA;AAAA,UACzB,qBAAA;AAAA,UACA;AAAA,SACF;AACA,QAAA,MAAM,eAAA,GAAkB,EAAA;AAAA,UACrB,OAA4D,QAAQ,CAAA;AAAA,UACrE;AAAA,SACF;AACA,QAAA,MAAM,OAAA,GAAU,OAAA;AAEhB,QAAA,2BAAQ,OAAA,EAAA,EAAS,GAAG,IAAA,EAAM,GAAA,EAAU,WAAW,eAAA,EAAiB,CAAA;AAAA,MAClE;AAAA,KACF;AAEA,IAAA,SAAA,CAAU,WAAA,GAAc,UAAU,MAAA,CAAO,CAAC,EAAE,WAAA,EAAY,GAAI,SAAA,CAAU,KAAA,CAAM,CAAC,CAAA;AAE7E,IAAA,OAAO,SAAA;AAAA,EACT;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.js","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 const recipe = makeRecipe(namespace, config as ComponentConfigInput<VariantDefinitions>);\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(\n (recipe as (selections?: Record<string, unknown>) => string)(variants),\n className,\n );\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"]}
|
package/dist/jsx-dev-runtime.cjs
CHANGED
|
@@ -14,15 +14,23 @@ function resolveCssPropClass(hashClass, css, className) {
|
|
|
14
14
|
}
|
|
15
15
|
var TypeStylesContext = react.createContext(null);
|
|
16
16
|
|
|
17
|
+
// src/resolve-hash-class.ts
|
|
18
|
+
function resolveHashClass(api) {
|
|
19
|
+
if ("hash" in api && typeof api.hash === "function") {
|
|
20
|
+
return (properties, label) => api.hash(properties, { label });
|
|
21
|
+
}
|
|
22
|
+
return api.hashClass;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
// src/jsx-dev-runtime.ts
|
|
18
|
-
function processCssProp(props,
|
|
26
|
+
function processCssProp(props, hashClass) {
|
|
19
27
|
if (props.css == null) {
|
|
20
28
|
return props;
|
|
21
29
|
}
|
|
22
30
|
const { css, className, ...rest } = props;
|
|
23
31
|
const nextProps = {
|
|
24
32
|
...rest,
|
|
25
|
-
className: resolveCssPropClass(
|
|
33
|
+
className: resolveCssPropClass(hashClass, css, className)
|
|
26
34
|
};
|
|
27
35
|
return nextProps;
|
|
28
36
|
}
|
|
@@ -31,10 +39,10 @@ function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
|
31
39
|
const styles = react.useContext(TypeStylesContext);
|
|
32
40
|
if (props.css != null && styles == null) {
|
|
33
41
|
throw new Error(
|
|
34
|
-
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a
|
|
42
|
+
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props."
|
|
35
43
|
);
|
|
36
44
|
}
|
|
37
|
-
const nextProps = styles ? processCssProp(props, styles) : props;
|
|
45
|
+
const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : props;
|
|
38
46
|
return jsxDevRuntime.jsxDEV(type, nextProps, key, isStaticChildren, source, self);
|
|
39
47
|
}
|
|
40
48
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css-prop.ts","../src/context.tsx","../src/jsx-dev-runtime.ts"],"names":["cx","createContext","ReactFragment","useContext","reactJsxDEV"],"mappings":";;;;;;;;AAIO,SAAS,mBAAA,CACd,SAAA,EACA,GAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,OAAOA,aAAA,CAAG,SAAA,CAAU,GAAG,CAAA,EAAG,SAAS,CAAA;AAAA,EACrC;AACA,EAAA,OAAOA,cAAG,SAAS,CAAA;AACrB;ACVO,IAAM,iBAAA,GAAoBC,
|
|
1
|
+
{"version":3,"sources":["../src/css-prop.ts","../src/context.tsx","../src/resolve-hash-class.ts","../src/jsx-dev-runtime.ts"],"names":["cx","createContext","ReactFragment","useContext","reactJsxDEV"],"mappings":";;;;;;;;AAIO,SAAS,mBAAA,CACd,SAAA,EACA,GAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,OAAOA,aAAA,CAAG,SAAA,CAAU,GAAG,CAAA,EAAG,SAAS,CAAA;AAAA,EACrC;AACA,EAAA,OAAOA,cAAG,SAAS,CAAA;AACrB;ACVO,IAAM,iBAAA,GAAoBC,oBAAoC,IAAI,CAAA;;;ACKlE,SAAS,iBAAiB,GAAA,EAAiC;AAChE,EAAA,IAAI,MAAA,IAAU,GAAA,IAAO,OAAO,GAAA,CAAI,SAAS,UAAA,EAAY;AACnD,IAAA,OAAO,CAAC,YAAY,KAAA,KAAU,GAAA,CAAI,KAAK,UAAA,EAAY,EAAE,OAAO,CAAA;AAAA,EAC9D;AACA,EAAA,OAAQ,GAAA,CAAkB,SAAA;AAC5B;;;ACLA,SAAS,cAAA,CACP,OACA,SAAA,EACG;AACH,EAAA,IAAI,KAAA,CAAM,OAAO,IAAA,EAAM;AACrB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,GAAA,EAAK,SAAA,EAAW,GAAG,MAAK,GAAI,KAAA;AACpC,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,GAAG,IAAA;AAAA,IACH,SAAA,EAAW,mBAAA,CAAoB,SAAA,EAAW,GAAA,EAAK,SAAS;AAAA,GAC1D;AAEA,EAAA,OAAO,SAAA;AACT;AAEO,IAAM,QAAA,GAAWC;AAEjB,SAAS,OACd,IAAA,EACA,KAAA,EACA,GAAA,EACA,gBAAA,EACA,QACA,IAAA,EACoB;AACpB,EAAA,MAAM,MAAA,GAASC,iBAAW,iBAAiB,CAAA;AAE3C,EAAA,IAAI,KAAA,CAAM,GAAA,IAAO,IAAA,IAAQ,MAAA,IAAU,IAAA,EAAM;AACvC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AAEA,EAAA,MAAM,YAAY,MAAA,GAAS,cAAA,CAAe,OAAO,gBAAA,CAAiB,MAAM,CAAC,CAAA,GAAK,KAAA;AAC9E,EAAA,OAAOC,qBAAY,IAAA,EAAM,SAAA,EAAW,GAAA,EAAK,gBAAA,EAAkB,QAAQ,IAAI,CAAA;AACzE","file":"jsx-dev-runtime.cjs","sourcesContent":["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","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, StylesApi, TypeStylesApi } from 'typestyles';\n\n/** Styles host for the css prop / TypeStylesProvider. */\nexport type CssStylesHost = Pick<TypeStylesApi, 'hash'> | StylesApi;\n\nexport type HashClassFn = (properties: CSSProperties, label?: string) => string;\n\n/** Normalize `hash` (createTypeStyles) and `hashClass` (createStyles). */\nexport function resolveHashClass(api: CssStylesHost): HashClassFn {\n if ('hash' in api && typeof api.hash === 'function') {\n return (properties, label) => api.hash(properties, { label });\n }\n return (api as StylesApi).hashClass;\n}\n","import { useContext, type ElementType, type ReactNode } from 'react';\nimport { jsxDEV as reactJsxDEV, Fragment as ReactFragment } from 'react/jsx-dev-runtime';\nimport type { CSSProperties } from 'typestyles';\nimport { resolveCssPropClass } from './css-prop';\nimport { TypeStylesContext } from './context';\nimport { resolveHashClass } from './resolve-hash-class';\nimport type { WithCssProp } from './types';\n\nfunction processCssProp<P extends Record<string, unknown>>(\n props: WithCssProp<P>,\n hashClass: (properties: CSSProperties, label?: string) => string,\n): P {\n if (props.css == null) {\n return props as P;\n }\n\n const { css, className, ...rest } = props;\n const nextProps = {\n ...rest,\n className: resolveCssPropClass(hashClass, css, className),\n } as unknown as P;\n\n return nextProps;\n}\n\nexport const Fragment = ReactFragment;\n\nexport function jsxDEV<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key: React.Key | undefined,\n isStaticChildren: boolean,\n source: object | undefined,\n self: unknown,\n): React.ReactElement {\n const styles = useContext(TypeStylesContext);\n\n if (props.css != null && styles == null) {\n throw new Error(\n '[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. ' +\n 'Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props.',\n );\n }\n\n const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : (props as P);\n return reactJsxDEV(type, nextProps, key, isStaticChildren, source, self);\n}\n\nexport type { ReactNode };\n"]}
|
package/dist/jsx-dev-runtime.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { TypeStylesContext, resolveCssPropClass } from './chunk-
|
|
1
|
+
import { TypeStylesContext, resolveCssPropClass } from './chunk-IHZMLPG2.js';
|
|
2
|
+
import { resolveHashClass } from './chunk-KM65VQPZ.js';
|
|
2
3
|
import { useContext } from 'react';
|
|
3
4
|
import { Fragment as Fragment$1, jsxDEV as jsxDEV$1 } from 'react/jsx-dev-runtime';
|
|
4
5
|
|
|
5
|
-
function processCssProp(props,
|
|
6
|
+
function processCssProp(props, hashClass) {
|
|
6
7
|
if (props.css == null) {
|
|
7
8
|
return props;
|
|
8
9
|
}
|
|
9
10
|
const { css, className, ...rest } = props;
|
|
10
11
|
const nextProps = {
|
|
11
12
|
...rest,
|
|
12
|
-
className: resolveCssPropClass(
|
|
13
|
+
className: resolveCssPropClass(hashClass, css, className)
|
|
13
14
|
};
|
|
14
15
|
return nextProps;
|
|
15
16
|
}
|
|
@@ -18,10 +19,10 @@ function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
|
18
19
|
const styles = useContext(TypeStylesContext);
|
|
19
20
|
if (props.css != null && styles == null) {
|
|
20
21
|
throw new Error(
|
|
21
|
-
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a
|
|
22
|
+
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props."
|
|
22
23
|
);
|
|
23
24
|
}
|
|
24
|
-
const nextProps = styles ? processCssProp(props, styles) : props;
|
|
25
|
+
const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : props;
|
|
25
26
|
return jsxDEV$1(type, nextProps, key, isStaticChildren, source, self);
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/jsx-dev-runtime.ts"],"names":["ReactFragment","reactJsxDEV"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/jsx-dev-runtime.ts"],"names":["ReactFragment","reactJsxDEV"],"mappings":";;;;;AAQA,SAAS,cAAA,CACP,OACA,SAAA,EACG;AACH,EAAA,IAAI,KAAA,CAAM,OAAO,IAAA,EAAM;AACrB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,GAAA,EAAK,SAAA,EAAW,GAAG,MAAK,GAAI,KAAA;AACpC,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,GAAG,IAAA;AAAA,IACH,SAAA,EAAW,mBAAA,CAAoB,SAAA,EAAW,GAAA,EAAK,SAAS;AAAA,GAC1D;AAEA,EAAA,OAAO,SAAA;AACT;AAEO,IAAM,QAAA,GAAWA;AAEjB,SAAS,OACd,IAAA,EACA,KAAA,EACA,GAAA,EACA,gBAAA,EACA,QACA,IAAA,EACoB;AACpB,EAAA,MAAM,MAAA,GAAS,WAAW,iBAAiB,CAAA;AAE3C,EAAA,IAAI,KAAA,CAAM,GAAA,IAAO,IAAA,IAAQ,MAAA,IAAU,IAAA,EAAM;AACvC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AAEA,EAAA,MAAM,YAAY,MAAA,GAAS,cAAA,CAAe,OAAO,gBAAA,CAAiB,MAAM,CAAC,CAAA,GAAK,KAAA;AAC9E,EAAA,OAAOC,SAAY,IAAA,EAAM,SAAA,EAAW,GAAA,EAAK,gBAAA,EAAkB,QAAQ,IAAI,CAAA;AACzE","file":"jsx-dev-runtime.js","sourcesContent":["import { useContext, type ElementType, type ReactNode } from 'react';\nimport { jsxDEV as reactJsxDEV, Fragment as ReactFragment } from 'react/jsx-dev-runtime';\nimport type { CSSProperties } from 'typestyles';\nimport { resolveCssPropClass } from './css-prop';\nimport { TypeStylesContext } from './context';\nimport { resolveHashClass } from './resolve-hash-class';\nimport type { WithCssProp } from './types';\n\nfunction processCssProp<P extends Record<string, unknown>>(\n props: WithCssProp<P>,\n hashClass: (properties: CSSProperties, label?: string) => string,\n): P {\n if (props.css == null) {\n return props as P;\n }\n\n const { css, className, ...rest } = props;\n const nextProps = {\n ...rest,\n className: resolveCssPropClass(hashClass, css, className),\n } as unknown as P;\n\n return nextProps;\n}\n\nexport const Fragment = ReactFragment;\n\nexport function jsxDEV<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key: React.Key | undefined,\n isStaticChildren: boolean,\n source: object | undefined,\n self: unknown,\n): React.ReactElement {\n const styles = useContext(TypeStylesContext);\n\n if (props.css != null && styles == null) {\n throw new Error(\n '[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. ' +\n 'Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props.',\n );\n }\n\n const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : (props as P);\n return reactJsxDEV(type, nextProps, key, isStaticChildren, source, self);\n}\n\nexport type { ReactNode };\n"]}
|
package/dist/jsx-runtime.cjs
CHANGED
|
@@ -13,15 +13,23 @@ function resolveCssPropClass(hashClass, css, className) {
|
|
|
13
13
|
}
|
|
14
14
|
var TypeStylesContext = react.createContext(null);
|
|
15
15
|
|
|
16
|
+
// src/resolve-hash-class.ts
|
|
17
|
+
function resolveHashClass(api) {
|
|
18
|
+
if ("hash" in api && typeof api.hash === "function") {
|
|
19
|
+
return (properties, label) => api.hash(properties, { label });
|
|
20
|
+
}
|
|
21
|
+
return api.hashClass;
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
// src/jsx-runtime.ts
|
|
17
|
-
function processCssProp(props,
|
|
25
|
+
function processCssProp(props, hashClass) {
|
|
18
26
|
if (props.css == null) {
|
|
19
27
|
return props;
|
|
20
28
|
}
|
|
21
29
|
const { css, className, ...rest } = props;
|
|
22
30
|
const nextProps = {
|
|
23
31
|
...rest,
|
|
24
|
-
className: resolveCssPropClass(
|
|
32
|
+
className: resolveCssPropClass(hashClass, css, className)
|
|
25
33
|
};
|
|
26
34
|
return nextProps;
|
|
27
35
|
}
|
|
@@ -29,10 +37,10 @@ function wrapJsx(factory, type, props, key) {
|
|
|
29
37
|
const styles = react.useContext(TypeStylesContext);
|
|
30
38
|
if (props.css != null && styles == null) {
|
|
31
39
|
throw new Error(
|
|
32
|
-
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a
|
|
40
|
+
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props."
|
|
33
41
|
);
|
|
34
42
|
}
|
|
35
|
-
const nextProps = styles ? processCssProp(props, styles) : props;
|
|
43
|
+
const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : props;
|
|
36
44
|
return factory(type, nextProps, key);
|
|
37
45
|
}
|
|
38
46
|
var Fragment = jsxRuntime.Fragment;
|
package/dist/jsx-runtime.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css-prop.ts","../src/context.tsx","../src/jsx-runtime.ts"],"names":["cx","createContext","useContext","ReactFragment","jsx","reactJsx","reactJsxs"],"mappings":";;;;;;;AAIO,SAAS,mBAAA,CACd,SAAA,EACA,GAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,OAAOA,aAAA,CAAG,SAAA,CAAU,GAAG,CAAA,EAAG,SAAS,CAAA;AAAA,EACrC;AACA,EAAA,OAAOA,cAAG,SAAS,CAAA;AACrB;ACVO,IAAM,iBAAA,GAAoBC,
|
|
1
|
+
{"version":3,"sources":["../src/css-prop.ts","../src/context.tsx","../src/resolve-hash-class.ts","../src/jsx-runtime.ts"],"names":["cx","createContext","useContext","ReactFragment","jsx","reactJsx","reactJsxs"],"mappings":";;;;;;;AAIO,SAAS,mBAAA,CACd,SAAA,EACA,GAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,OAAOA,aAAA,CAAG,SAAA,CAAU,GAAG,CAAA,EAAG,SAAS,CAAA;AAAA,EACrC;AACA,EAAA,OAAOA,cAAG,SAAS,CAAA;AACrB;ACVO,IAAM,iBAAA,GAAoBC,oBAAoC,IAAI,CAAA;;;ACKlE,SAAS,iBAAiB,GAAA,EAAiC;AAChE,EAAA,IAAI,MAAA,IAAU,GAAA,IAAO,OAAO,GAAA,CAAI,SAAS,UAAA,EAAY;AACnD,IAAA,OAAO,CAAC,YAAY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jsx-runtime.cjs","sourcesContent":["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","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, StylesApi, TypeStylesApi } from 'typestyles';\n\n/** Styles host for the css prop / TypeStylesProvider. */\nexport type CssStylesHost = Pick<TypeStylesApi, 'hash'> | StylesApi;\n\nexport type HashClassFn = (properties: CSSProperties, label?: string) => string;\n\n/** Normalize `hash` (createTypeStyles) and `hashClass` (createStyles). */\nexport function resolveHashClass(api: CssStylesHost): HashClassFn {\n if ('hash' in api && typeof api.hash === 'function') {\n return (properties, label) => api.hash(properties, { label });\n }\n return (api as StylesApi).hashClass;\n}\n","import { useContext, type ElementType, type ReactNode } from 'react';\nimport { jsx as reactJsx, jsxs as reactJsxs, Fragment as ReactFragment } from 'react/jsx-runtime';\nimport type { CSSProperties } from 'typestyles';\nimport { resolveCssPropClass } from './css-prop';\nimport { TypeStylesContext } from './context';\nimport { resolveHashClass } from './resolve-hash-class';\nimport type { WithCssProp } from './types';\n\nfunction processCssProp<P extends Record<string, unknown>>(\n props: WithCssProp<P>,\n hashClass: (properties: CSSProperties, label?: string) => string,\n): P {\n if (props.css == null) {\n return props as P;\n }\n\n const { css, className, ...rest } = props;\n const nextProps = {\n ...rest,\n className: resolveCssPropClass(hashClass, css, className),\n } as unknown as P;\n\n return nextProps;\n}\n\nfunction wrapJsx<P extends Record<string, unknown>>(\n factory: typeof reactJsx,\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n const styles = useContext(TypeStylesContext);\n\n if (props.css != null && styles == null) {\n throw new Error(\n '[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. ' +\n 'Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props.',\n );\n }\n\n const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : (props as P);\n return factory(type, nextProps, key);\n}\n\nexport const Fragment = ReactFragment;\n\nexport function jsx<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n return wrapJsx(reactJsx, type, props, key);\n}\n\nexport function jsxs<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n return wrapJsx(reactJsxs, type, props, key);\n}\n\nexport type { ReactNode };\n"]}
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { TypeStylesContext, resolveCssPropClass } from './chunk-
|
|
1
|
+
import { TypeStylesContext, resolveCssPropClass } from './chunk-IHZMLPG2.js';
|
|
2
|
+
import { resolveHashClass } from './chunk-KM65VQPZ.js';
|
|
2
3
|
import { useContext } from 'react';
|
|
3
4
|
import { Fragment as Fragment$1, jsx as jsx$1, jsxs as jsxs$1 } from 'react/jsx-runtime';
|
|
4
5
|
|
|
5
|
-
function processCssProp(props,
|
|
6
|
+
function processCssProp(props, hashClass) {
|
|
6
7
|
if (props.css == null) {
|
|
7
8
|
return props;
|
|
8
9
|
}
|
|
9
10
|
const { css, className, ...rest } = props;
|
|
10
11
|
const nextProps = {
|
|
11
12
|
...rest,
|
|
12
|
-
className: resolveCssPropClass(
|
|
13
|
+
className: resolveCssPropClass(hashClass, css, className)
|
|
13
14
|
};
|
|
14
15
|
return nextProps;
|
|
15
16
|
}
|
|
@@ -17,10 +18,10 @@ function wrapJsx(factory, type, props, key) {
|
|
|
17
18
|
const styles = useContext(TypeStylesContext);
|
|
18
19
|
if (props.css != null && styles == null) {
|
|
19
20
|
throw new Error(
|
|
20
|
-
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a
|
|
21
|
+
"[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props."
|
|
21
22
|
);
|
|
22
23
|
}
|
|
23
|
-
const nextProps = styles ? processCssProp(props, styles) : props;
|
|
24
|
+
const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : props;
|
|
24
25
|
return factory(type, nextProps, key);
|
|
25
26
|
}
|
|
26
27
|
var Fragment = Fragment$1;
|
package/dist/jsx-runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/jsx-runtime.ts"],"names":["ReactFragment","reactJsx","reactJsxs"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/jsx-runtime.ts"],"names":["ReactFragment","reactJsx","reactJsxs"],"mappings":";;;;;AAQA,SAAS,cAAA,CACP,OACA,SAAA,EACG;AACH,EAAA,IAAI,KAAA,CAAM,OAAO,IAAA,EAAM;AACrB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,GAAA,EAAK,SAAA,EAAW,GAAG,MAAK,GAAI,KAAA;AACpC,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,GAAG,IAAA;AAAA,IACH,SAAA,EAAW,mBAAA,CAAoB,SAAA,EAAW,GAAA,EAAK,SAAS;AAAA,GAC1D;AAEA,EAAA,OAAO,SAAA;AACT;AAEA,SAAS,OAAA,CACP,OAAA,EACA,IAAA,EACA,KAAA,EACA,GAAA,EACoB;AACpB,EAAA,MAAM,MAAA,GAAS,WAAW,iBAAiB,CAAA;AAE3C,EAAA,IAAI,KAAA,CAAM,GAAA,IAAO,IAAA,IAAQ,MAAA,IAAU,IAAA,EAAM;AACvC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AAEA,EAAA,MAAM,YAAY,MAAA,GAAS,cAAA,CAAe,OAAO,gBAAA,CAAiB,MAAM,CAAC,CAAA,GAAK,KAAA;AAC9E,EAAA,OAAO,OAAA,CAAQ,IAAA,EAAM,SAAA,EAAW,GAAG,CAAA;AACrC;AAEO,IAAM,QAAA,GAAWA;AAEjB,SAAS,GAAA,CACd,IAAA,EACA,KAAA,EACA,GAAA,EACoB;AACpB,EAAA,OAAO,OAAA,CAAQC,KAAA,EAAU,IAAA,EAAM,KAAA,EAAO,GAAG,CAAA;AAC3C;AAEO,SAAS,IAAA,CACd,IAAA,EACA,KAAA,EACA,GAAA,EACoB;AACpB,EAAA,OAAO,OAAA,CAAQC,MAAA,EAAW,IAAA,EAAM,KAAA,EAAO,GAAG,CAAA;AAC5C","file":"jsx-runtime.js","sourcesContent":["import { useContext, type ElementType, type ReactNode } from 'react';\nimport { jsx as reactJsx, jsxs as reactJsxs, Fragment as ReactFragment } from 'react/jsx-runtime';\nimport type { CSSProperties } from 'typestyles';\nimport { resolveCssPropClass } from './css-prop';\nimport { TypeStylesContext } from './context';\nimport { resolveHashClass } from './resolve-hash-class';\nimport type { WithCssProp } from './types';\n\nfunction processCssProp<P extends Record<string, unknown>>(\n props: WithCssProp<P>,\n hashClass: (properties: CSSProperties, label?: string) => string,\n): P {\n if (props.css == null) {\n return props as P;\n }\n\n const { css, className, ...rest } = props;\n const nextProps = {\n ...rest,\n className: resolveCssPropClass(hashClass, css, className),\n } as unknown as P;\n\n return nextProps;\n}\n\nfunction wrapJsx<P extends Record<string, unknown>>(\n factory: typeof reactJsx,\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n const styles = useContext(TypeStylesContext);\n\n if (props.css != null && styles == null) {\n throw new Error(\n '[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a styles instance. ' +\n 'Wrap your app in `<TypeStylesProvider styles={api}>` (from `createTypeStyles()`), or use the Babel plugin for zero-runtime css props.',\n );\n }\n\n const nextProps = styles ? processCssProp(props, resolveHashClass(styles)) : (props as P);\n return factory(type, nextProps, key);\n}\n\nexport const Fragment = ReactFragment;\n\nexport function jsx<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n return wrapJsx(reactJsx, type, props, key);\n}\n\nexport function jsxs<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n return wrapJsx(reactJsxs, type, props, key);\n}\n\nexport type { ReactNode };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React integration for typestyles — styled API and css prop",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -99,9 +99,9 @@
|
|
|
99
99
|
"react": "^18.0.0",
|
|
100
100
|
"react-dom": "^18.0.0",
|
|
101
101
|
"tsup": "^8.0.0",
|
|
102
|
-
"typestyles": "0.0.0-unstable.f96b13308930",
|
|
103
102
|
"typescript": "^5.4.0",
|
|
104
|
-
"vitest": "^3.0.0"
|
|
103
|
+
"vitest": "^3.0.0",
|
|
104
|
+
"typestyles": "1.0.0"
|
|
105
105
|
},
|
|
106
106
|
"scripts": {
|
|
107
107
|
"build": "tsup",
|
package/dist/chunk-3YCUQVCM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css-prop-runtime.ts"],"names":[],"mappings":";AAEO,SAAS,OAAA,CACd,QACA,UAAA,EACQ;AACR,EAAA,OAAO,MAAA,CAAO,UAAU,UAAU,CAAA;AACpC","file":"chunk-3YCUQVCM.js","sourcesContent":["import type { CSSProperties } from 'typestyles';\n\nexport function cssProp(\n styles: { hashClass: (properties: CSSProperties, label?: string) => string },\n properties: CSSProperties,\n): string {\n return styles.hashClass(properties);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context.tsx","../src/css-prop.ts"],"names":[],"mappings":";;;;;AAGO,IAAM,iBAAA,GAAoB,cAAgC,IAAI;AAE9D,SAAS,kBAAA,CAAmB;AAAA,EACjC,MAAA;AAAA,EACA;AACF,CAAA,EAGsB;AACpB,EAAA,2BAAQ,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,QAAS,QAAA,EAAS,CAAA;AAC9D;ACTO,SAAS,mBAAA,CACd,SAAA,EACA,GAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,OAAO,EAAA,CAAG,SAAA,CAAU,GAAG,CAAA,EAAG,SAAS,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,GAAG,SAAS,CAAA;AACrB","file":"chunk-4BYX2HZ7.js","sourcesContent":["import { createContext, type ReactNode } from 'react';\nimport type { StylesApi } from 'typestyles';\n\nexport const TypeStylesContext = createContext<StylesApi | null>(null);\n\nexport function TypeStylesProvider({\n styles,\n children,\n}: {\n styles: StylesApi;\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"]}
|