@typestyles/props 0.3.1 → 0.4.2
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/LICENSE +204 -0
- package/README.md +189 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
Copyright 2026 The TypeStyles Authors
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# @typestyles/props
|
|
2
|
+
|
|
3
|
+
Type-safe atomic CSS utilities for [typestyles](https://github.com/type-styles/typestyles) — Tailwind-style ergonomics with full TypeScript inference, readable class names, and CSS you can inspect in DevTools.
|
|
4
|
+
|
|
5
|
+
Define a design-system scale once; get autocomplete, compile-time errors on invalid combinations, and class strings like `atom-display-flex atom-padding-2` instead of hashed atoms.
|
|
6
|
+
|
|
7
|
+
Full guide: [Atomic CSS utilities](https://typestyles.dev/docs/atomic-css)
|
|
8
|
+
|
|
9
|
+
## Why this exists
|
|
10
|
+
|
|
11
|
+
| Approach | Tradeoff |
|
|
12
|
+
| ----------------------- | --------------------------------------------------------------------------------------------- |
|
|
13
|
+
| Tailwind | Fast authoring, no type safety, config-driven strings |
|
|
14
|
+
| Panda CSS | Build-time codegen, separate pipeline |
|
|
15
|
+
| **`@typestyles/props`** | Typed props API, runs with typestyles runtime or extraction, composes with `styles.component` |
|
|
16
|
+
|
|
17
|
+
Utility class naming is separate from `styles.component` / `styles.class` — see [Class naming](https://typestyles.dev/docs/class-naming).
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @typestyles/props typestyles
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { defineProperties, createProps } from '@typestyles/props';
|
|
29
|
+
|
|
30
|
+
const atoms = createProps(
|
|
31
|
+
'atom',
|
|
32
|
+
defineProperties({
|
|
33
|
+
properties: {
|
|
34
|
+
display: ['flex', 'block', 'grid', 'none'],
|
|
35
|
+
padding: { 0: '0', 1: '4px', 2: '8px', 3: '16px' },
|
|
36
|
+
gap: { 0: '0', 1: '4px', 2: '8px' },
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Full autocomplete — invalid values are type errors
|
|
42
|
+
atoms({ display: 'flex', padding: 2, gap: 1 });
|
|
43
|
+
// → "atom-display-flex atom-padding-2 atom-gap-1"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Use in JSX:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
<div className={atoms({ display: 'flex', padding: 3, gap: 2 })} />
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Defining properties
|
|
53
|
+
|
|
54
|
+
### Enumerated values (arrays)
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
defineProperties({
|
|
58
|
+
properties: {
|
|
59
|
+
display: ['flex', 'block', 'grid', 'inline-flex'],
|
|
60
|
+
alignItems: ['start', 'center', 'end', 'stretch'],
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Scales (objects)
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
defineProperties({
|
|
69
|
+
properties: {
|
|
70
|
+
padding: { 0: '0', 1: '0.25rem', 2: '0.5rem', 4: '1rem' },
|
|
71
|
+
fontSize: { sm: '0.875rem', base: '1rem', lg: '1.125rem' },
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Shorthands
|
|
77
|
+
|
|
78
|
+
Map one prop to several CSS properties:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
defineProperties({
|
|
82
|
+
properties: {
|
|
83
|
+
paddingTop: { 1: '4px', 2: '8px' },
|
|
84
|
+
paddingBottom: { 1: '4px', 2: '8px' },
|
|
85
|
+
},
|
|
86
|
+
shorthands: {
|
|
87
|
+
py: ['paddingTop', 'paddingBottom'],
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Responsive and conditional variants
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const responsive = defineProperties({
|
|
96
|
+
conditions: {
|
|
97
|
+
mobile: '@media (max-width: 768px)',
|
|
98
|
+
dark: '[data-theme="dark"] &',
|
|
99
|
+
},
|
|
100
|
+
properties: {
|
|
101
|
+
padding: { 1: '4px', 2: '8px', 4: '16px' },
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const props = createProps('ui', responsive);
|
|
106
|
+
|
|
107
|
+
props({ padding: { mobile: 2, default: 4 } });
|
|
108
|
+
// → "ui-padding-mobile-2 ui-padding-4"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Compose with component styles
|
|
112
|
+
|
|
113
|
+
Utilities and components work together via `cx`:
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { styles, cx } from 'typestyles';
|
|
117
|
+
import { createProps, defineProperties } from '@typestyles/props';
|
|
118
|
+
|
|
119
|
+
const atoms = createProps(
|
|
120
|
+
'atom',
|
|
121
|
+
defineProperties({
|
|
122
|
+
properties: { display: ['flex'], gap: { 2: '8px' } },
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const card = styles.component('card', {
|
|
127
|
+
base: { borderRadius: '8px', backgroundColor: 'white' },
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
<div className={cx(card(), atoms({ display: 'flex', gap: 2 }))} />;
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Split design-system modules
|
|
134
|
+
|
|
135
|
+
Define tokens per domain, merge at the app boundary:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
// spacing.ts
|
|
139
|
+
export const spacingProps = defineProperties({
|
|
140
|
+
properties: { padding: { 1: '4px', 2: '8px' } },
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// layout.ts
|
|
144
|
+
export const layoutProps = defineProperties({
|
|
145
|
+
properties: { display: ['flex', 'grid'] },
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// app/atoms.ts
|
|
149
|
+
import { createProps } from '@typestyles/props';
|
|
150
|
+
import { spacingProps } from './spacing';
|
|
151
|
+
import { layoutProps } from './layout';
|
|
152
|
+
|
|
153
|
+
export const atoms = createProps('atom', spacingProps, layoutProps);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## How it works
|
|
157
|
+
|
|
158
|
+
1. **`defineProperties`** describes allowed props, values, conditions, and shorthands
|
|
159
|
+
2. **`createProps(namespace, ...collections)`** generates all CSS rules upfront and injects them via typestyles
|
|
160
|
+
3. Calling the returned function resolves prop values to pre-generated class names — no runtime style parsing
|
|
161
|
+
|
|
162
|
+
CSS is included in zero-runtime extraction when your [convention entry](https://typestyles.dev/docs/zero-runtime) imports the module that calls `createProps`.
|
|
163
|
+
|
|
164
|
+
## API
|
|
165
|
+
|
|
166
|
+
| Export | Description |
|
|
167
|
+
| ---------------------------------------- | --------------------------------------------- |
|
|
168
|
+
| `defineProperties(config)` | Define a property collection |
|
|
169
|
+
| `createProps(namespace, ...collections)` | Merge collections into a typed props function |
|
|
170
|
+
|
|
171
|
+
The props function exposes `.properties` — a `Set` of all prop names for tooling and docs.
|
|
172
|
+
|
|
173
|
+
Types: `PropertyDefinitions`, `ConditionDefinitions`, `PropsFunction`, `ExtractProps`, and more from the package entry.
|
|
174
|
+
|
|
175
|
+
## Docs site example
|
|
176
|
+
|
|
177
|
+
The typestyles documentation site uses `@typestyles/props` for layout utilities — see [`docs/src/atoms.ts`](../../docs/src/atoms.ts).
|
|
178
|
+
|
|
179
|
+
## Related packages
|
|
180
|
+
|
|
181
|
+
| Package | Role |
|
|
182
|
+
| ----------------------------------------- | --------------------------------- |
|
|
183
|
+
| [`typestyles`](../typestyles) | Core `styles`, `tokens`, `cx` |
|
|
184
|
+
| [`@typestyles/open-props`](../open-props) | Pre-built Open Props token scales |
|
|
185
|
+
| [`@typestyles/vite`](../vite) | HMR + production extraction |
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
Apache-2.0
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"names":["insertRules"],"mappings":";;;;;AA6BO,SAAS,iBAId,MAAA,EAAsE;AACtE,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,gBAAA,GAAmB,OAAO,gBAAA,IAAoB,KAAA;AAEpD,EAAA,OAAO;AAAA,IACL,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,UAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF;AACF;;;ACxCO,SAAS,cAAc,KAAA,EAAgC;AAC5D,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAChB,OAAA,CAAQ,QAAQ,GAAG,CAAA,CACnB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAClC;AAKO,SAAS,YAAY,GAAA,EAAqB;AAE/C,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,IAAI,CA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,CAMd,cAAsB,WAAA,EAAsD;AAE5E,EAAA,MAAM,QAAA,GAAW,uBAAA,CAAwB,SAAA,EAAW,WAAW,CAAA;AAG/D,EAAAA,sBAAA,CAAY,QAAQ,CAAA;AAGpB,EAAA,MAAM,EAAE,WAAA,EAAa,aAAA,EAAe,YAAW,GAAI,cAAA,CAAe,WAAW,WAAW,CAAA;AAGxF,EAAA,MAAM,QAAA,GAAW,cAAA,CAAe,SAAA,EAAW,WAAA,EAAa,eAAe,UAAU,CAAA;AAGjF,EAAA,MAAM,UAAA,uBAAiB,GAAA,EAAY;AACnC,EAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AACpC,IAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,UAAU,CAAA,EAAG;AACrD,MAAA,UAAA,CAAW,IAAI,IAAI,CAAA;AAAA,IACrB;AACA,IAAA,KAAA,MAAW,SAAA,IAAa,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,UAAU,CAAA,EAAG;AAC1D,MAAA,UAAA,CAAW,IAAI,SAAS,CAAA;AAAA,IAC1B;AAAA,EACF;AAGA,EAAA,MAAM,gBAAgB,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,EAAE,YAAY,CAAA;AAE5D,EAAA,OAAO,aAAA;AACT","file":"index.cjs","sourcesContent":["import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n DefinePropertiesConfig,\n PropertyCollection,\n} from './types.js';\n\n/**\n * Define a collection of CSS properties with their allowed values and optional conditions.\n *\n * @example\n * ```ts\n * const responsiveProps = defineProperties({\n * conditions: {\n * mobile: { '@media': '(min-width: 768px)' },\n * desktop: { '@media': '(min-width: 1024px)' },\n * },\n * defaultCondition: false,\n * properties: {\n * display: ['flex', 'block', 'grid', 'none'],\n * paddingTop: { 0: '0', 1: '4px', 2: '8px', 3: '16px' },\n * },\n * shorthands: {\n * padding: ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],\n * },\n * });\n * ```\n */\nexport function defineProperties<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions = ConditionDefinitions,\n S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>,\n>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S> {\n const conditions = (config.conditions || {}) as C;\n const shorthands = (config.shorthands || {}) as S;\n const defaultCondition = config.defaultCondition ?? false;\n\n return {\n properties: config.properties,\n conditions,\n defaultCondition,\n shorthands,\n };\n}\n","/**\n * Sanitize a value for use in a class name.\n * Replaces spaces with hyphens and removes special characters.\n */\nexport function sanitizeValue(value: string | number): string {\n return String(value)\n .replace(/\\s+/g, '-')\n .replace(/[^a-zA-Z0-9-_]/g, '');\n}\n\n/**\n * Convert camelCase to kebab-case for CSS property names.\n */\nexport function toKebabCase(str: string): string {\n // Handle vendor prefixes (ms, webkit, moz)\n if (str.startsWith('ms')) {\n return '-' + str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n }\n return str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n}\n\n/**\n * Check if a value is a conditional object (has condition keys).\n */\nexport function isConditionalValue(\n value: unknown,\n conditionKeys: Set<string>,\n): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n // Check if any key is a known condition\n for (const key in value) {\n if (conditionKeys.has(key)) {\n return true;\n }\n }\n\n return false;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n PropertyCollection,\n ConditionDefinition,\n PropertyValues,\n ShorthandDefinitions,\n} from './types.js';\nimport { sanitizeValue, toKebabCase } from './utils.js';\n\n/**\n * Generate a single atomic CSS class.\n */\nfunction generateAtomicClass(\n namespace: string,\n property: string,\n valueKey: string,\n cssValue: string | number,\n condition?: ConditionDefinition & { name: string },\n): { key: string; css: string } {\n const sanitizedValue = sanitizeValue(valueKey);\n const className = condition\n ? `${namespace}-${property}-${condition.name}-${sanitizedValue}`\n : `${namespace}-${property}-${sanitizedValue}`;\n\n const kebabProp = toKebabCase(property);\n const declaration = `${kebabProp}: ${cssValue}`;\n\n if (!condition) {\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n }\n\n // Handle media queries\n if (condition['@media']) {\n const mediaQuery = `@media ${condition['@media']}`;\n return {\n key: `${mediaQuery}:.${className}`,\n css: `${mediaQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle container queries\n if (condition['@container']) {\n const containerQuery = `@container ${condition['@container']}`;\n return {\n key: `${containerQuery}:.${className}`,\n css: `${containerQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle @supports\n if (condition['@supports']) {\n const supportsQuery = `@supports ${condition['@supports']}`;\n return {\n key: `${supportsQuery}:.${className}`,\n css: `${supportsQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle custom selectors\n if (condition.selector) {\n const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);\n return {\n key: wrappedSelector,\n css: `${wrappedSelector} { ${declaration}; }`,\n };\n }\n\n // Fallback to no condition\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n}\n\n/**\n * Get CSS value entries from PropertyValues.\n */\nfunction getValueEntries(values: PropertyValues): Array<[string, string | number]> {\n if (Array.isArray(values)) {\n // Array format: ['flex', 'block'] -> [['flex', 'flex'], ['block', 'block']]\n return values.map((v) => [v, v]);\n } else {\n // Object format: { 0: '0', 1: '4px' } -> [['0', '0'], ['1', '4px']]\n return Object.entries(values);\n }\n}\n\n/**\n * Generate all atomic CSS classes for a property collection.\n */\nexport function generateAllAtomicClasses<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n>(\n namespace: string,\n properties: P,\n conditions: C,\n defaultCondition: keyof C | false,\n): Array<{ key: string; css: string }> {\n const rules: Array<{ key: string; css: string }> = [];\n\n for (const [property, values] of Object.entries(properties)) {\n const valueEntries = getValueEntries(values);\n\n for (const [valueKey, cssValue] of valueEntries) {\n // Generate base class (no condition or with default condition)\n if (defaultCondition === false) {\n rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));\n } else {\n const condition = conditions[defaultCondition as string];\n if (condition) {\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condition,\n name: defaultCondition as string,\n }),\n );\n }\n }\n\n // Generate conditional variants\n for (const [condName, condDef] of Object.entries(conditions)) {\n // Skip if this is the default condition and we already generated it\n if (defaultCondition !== false && condName === defaultCondition) {\n continue;\n }\n\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condDef,\n name: condName,\n }),\n );\n }\n }\n }\n\n return rules;\n}\n\n/**\n * Generate all atomic CSS classes from multiple property collections.\n */\nexport function generateFromCollections(\n namespace: string,\n collections: PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n): Array<{ key: string; css: string }> {\n const allRules: Array<{ key: string; css: string }> = [];\n\n for (const collection of collections) {\n const rules = generateAllAtomicClasses(\n namespace,\n collection.properties,\n collection.conditions,\n collection.defaultCondition,\n );\n allRules.push(...rules);\n }\n\n return allRules;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n PropertyCollection,\n} from './types.js';\nimport { sanitizeValue, isConditionalValue } from './utils.js';\n\n/**\n * Build a lookup map for runtime class name resolution.\n */\nexport function buildLookupMap<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n S extends ShorthandDefinitions<P>,\n>(\n _namespace: string,\n collections: PropertyCollection<P, C, S>[],\n): {\n propertyMap: Map<string, Set<string>>;\n conditionKeys: Set<string>;\n shorthands: Map<string, string[]>;\n} {\n const propertyMap = new Map<string, Set<string>>();\n const conditionKeys = new Set<string>();\n const shorthands = new Map<string, string[]>();\n\n for (const collection of collections) {\n // Collect properties\n for (const property of Object.keys(collection.properties)) {\n if (!propertyMap.has(property)) {\n propertyMap.set(property, new Set());\n }\n }\n\n // Collect conditions\n for (const condition of Object.keys(collection.conditions)) {\n conditionKeys.add(condition);\n }\n\n // Collect shorthands\n for (const [shorthand, props] of Object.entries(collection.shorthands)) {\n shorthands.set(shorthand, props as string[]);\n }\n }\n\n return { propertyMap, conditionKeys, shorthands };\n}\n\n/**\n * Expand shorthands in props object.\n */\nexport function expandShorthands(\n props: Record<string, unknown>,\n shorthands: Map<string, string[]>,\n): Record<string, unknown> {\n const expanded: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (shorthands.has(key)) {\n // Expand shorthand\n const properties = shorthands.get(key)!;\n for (const prop of properties) {\n expanded[prop] = value;\n }\n } else {\n // Regular property\n expanded[key] = value;\n }\n }\n\n return expanded;\n}\n\n/**\n * Resolve a single property value to class names.\n */\nfunction resolveValue(\n namespace: string,\n property: string,\n value: unknown,\n conditionKeys: Set<string>,\n): string[] {\n const classNames: string[] = [];\n\n if (isConditionalValue(value, conditionKeys)) {\n // Conditional value: { mobile: 'flex', desktop: 'block' }\n for (const [condition, condValue] of Object.entries(value)) {\n if (conditionKeys.has(condition)) {\n const sanitized = sanitizeValue(String(condValue));\n classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);\n }\n }\n } else {\n // Direct value: 'flex' or 2\n const sanitized = sanitizeValue(String(value));\n classNames.push(`${namespace}-${property}-${sanitized}`);\n }\n\n return classNames;\n}\n\n/**\n * Create a runtime resolver function.\n */\nexport function createResolver(\n namespace: string,\n _propertyMap: Map<string, Set<string>>,\n conditionKeys: Set<string>,\n shorthands: Map<string, string[]>,\n): (props: Record<string, unknown>) => string {\n return (props: Record<string, unknown>): string => {\n // Expand shorthands\n const expanded = expandShorthands(props, shorthands);\n\n const classNames: string[] = [];\n\n for (const [property, value] of Object.entries(expanded)) {\n if (value == null) continue;\n\n const resolved = resolveValue(namespace, property, value, conditionKeys);\n classNames.push(...resolved);\n }\n\n return classNames.join(' ');\n };\n}\n","import type {\n PropertyCollection,\n PropsFunction,\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n} from './types.js';\nimport { insertRules } from 'typestyles';\nimport { generateFromCollections } from './generate.js';\nimport { buildLookupMap, createResolver } from './runtime.js';\n\n/**\n * Combine property collections into a typed props function with pre-generated CSS.\n *\n * @example\n * ```ts\n * const props = createProps('atoms', responsiveProps, colorProps);\n *\n * // Type-safe usage\n * props({\n * display: 'flex',\n * padding: 2,\n * paddingTop: { mobile: 3 },\n * });\n * // Returns: \"atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3\"\n * ```\n */\nexport function createProps<\n Collections extends PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n>(namespace: string, ...collections: Collections): PropsFunction<Collections> {\n // Generate all CSS rules upfront\n const cssRules = generateFromCollections(namespace, collections);\n\n // Inject CSS\n insertRules(cssRules);\n\n // Build runtime lookup\n const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);\n\n // Create resolver function\n const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);\n\n // Create properties set for inspection\n const properties = new Set<string>();\n for (const collection of collections) {\n for (const prop of Object.keys(collection.properties)) {\n properties.add(prop);\n }\n for (const shorthand of Object.keys(collection.shorthands)) {\n properties.add(shorthand);\n }\n }\n\n // Attach properties to the function\n const propsFunction = Object.assign(resolver, { properties });\n\n return propsFunction as PropsFunction<Collections>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"names":["insertRules"],"mappings":";;;;;AA6BO,SAAS,iBAId,MAAA,EAAsE;AACtE,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,gBAAA,GAAmB,OAAO,gBAAA,IAAoB,KAAA;AAEpD,EAAA,OAAO;AAAA,IACL,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,UAA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Q,CAAA,EAAG;AACxD,MAAA,IAAI,SAAS,IAAA,EAAM;AAEnB,MAAA,MAAM,QAAA,GAAW,YAAA,CAAa,SAAA,EAAW,QAAA,EAAU,OAAO,aAAa,CAAA;AACvE,MAAA,UAAA,CAAW,IAAA,CAAK,GAAG,QAAQ,CAAA;AAAA,IAC7B;AAEA,IAAA,OAAO,UAAA,CAAW,KAAK,GAAG,CAAA;AAAA,EAC5B,CAAA;AACF;;;ACnGO,SAAS,WAAA,CAMd,cAAsB,WAAA,EAAsD;AAE5E,EAAA,MAAM,QAAA,GAAW,uBAAA,CAAwB,SAAA,EAAW,WAAW,CAAA;AAG/D,EAAAA,sBAAA,CAAY,QAAQ,CAAA;AAGpB,EAAA,MAAM,EAAE,WAAA,EAAa,aAAA,EAAe,YAAW,GAAI,cAAA,CAAe,WAAW,WAAW,CAAA;AAGxF,EAAA,MAAM,QAAA,GAAW,cAAA,CAAe,SAAA,EAAW,WAAA,EAAa,eAAe,UAAU,CAAA;AAGjF,EAAA,MAAM,UAAA,uBAAiB,GAAA,EAAY;AACnC,EAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AACpC,IAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,UAAU,CAAA,EAAG;AACrD,MAAA,UAAA,CAAW,IAAI,IAAI,CAAA;AAAA,IACrB;AACA,IAAA,KAAA,MAAW,SAAA,IAAa,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,UAAU,CAAA,EAAG;AAC1D,MAAA,UAAA,CAAW,IAAI,SAAS,CAAA;AAAA,IAC1B;AAAA,EACF;AAGA,EAAA,MAAM,gBAAgB,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,EAAE,YAAY,CAAA;AAE5D,EAAA,OAAO,aAAA;AACT","file":"index.cjs","sourcesContent":["import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n DefinePropertiesConfig,\n PropertyCollection,\n} from './types';\n\n/**\n * Define a collection of CSS properties with their allowed values and optional conditions.\n *\n * @example\n * ```ts\n * const responsiveProps = defineProperties({\n * conditions: {\n * mobile: { '@media': '(min-width: 768px)' },\n * desktop: { '@media': '(min-width: 1024px)' },\n * },\n * defaultCondition: false,\n * properties: {\n * display: ['flex', 'block', 'grid', 'none'],\n * paddingTop: { 0: '0', 1: '4px', 2: '8px', 3: '16px' },\n * },\n * shorthands: {\n * padding: ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],\n * },\n * });\n * ```\n */\nexport function defineProperties<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions = ConditionDefinitions,\n S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>,\n>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S> {\n const conditions = (config.conditions || {}) as C;\n const shorthands = (config.shorthands || {}) as S;\n const defaultCondition = config.defaultCondition ?? false;\n\n return {\n properties: config.properties,\n conditions,\n defaultCondition,\n shorthands,\n };\n}\n","/**\n * Sanitize a value for use in a class name.\n * Replaces spaces with hyphens and removes special characters.\n */\nexport function sanitizeValue(value: string | number): string {\n return String(value)\n .replace(/\\s+/g, '-')\n .replace(/[^a-zA-Z0-9-_]/g, '');\n}\n\n/**\n * Convert camelCase to kebab-case for CSS property names.\n */\nexport function toKebabCase(str: string): string {\n // Handle vendor prefixes (ms, webkit, moz)\n if (str.startsWith('ms')) {\n return '-' + str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n }\n return str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n}\n\n/**\n * Check if a value is a conditional object (has condition keys).\n */\nexport function isConditionalValue(\n value: unknown,\n conditionKeys: Set<string>,\n): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n // Check if any key is a known condition\n for (const key in value) {\n if (conditionKeys.has(key)) {\n return true;\n }\n }\n\n return false;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n PropertyCollection,\n ConditionDefinition,\n PropertyValues,\n ShorthandDefinitions,\n} from './types';\nimport { sanitizeValue, toKebabCase } from './utils';\n\n/**\n * Generate a single atomic CSS class.\n */\nfunction generateAtomicClass(\n namespace: string,\n property: string,\n valueKey: string,\n cssValue: string | number,\n condition?: ConditionDefinition & { name: string },\n): { key: string; css: string } {\n const sanitizedValue = sanitizeValue(valueKey);\n const className = condition\n ? `${namespace}-${property}-${condition.name}-${sanitizedValue}`\n : `${namespace}-${property}-${sanitizedValue}`;\n\n const kebabProp = toKebabCase(property);\n const declaration = `${kebabProp}: ${cssValue}`;\n\n if (!condition) {\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n }\n\n // Handle media queries\n if (condition['@media']) {\n const mediaQuery = `@media ${condition['@media']}`;\n return {\n key: `${mediaQuery}:.${className}`,\n css: `${mediaQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle container queries\n if (condition['@container']) {\n const containerQuery = `@container ${condition['@container']}`;\n return {\n key: `${containerQuery}:.${className}`,\n css: `${containerQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle @supports\n if (condition['@supports']) {\n const supportsQuery = `@supports ${condition['@supports']}`;\n return {\n key: `${supportsQuery}:.${className}`,\n css: `${supportsQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle custom selectors\n if (condition.selector) {\n const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);\n return {\n key: wrappedSelector,\n css: `${wrappedSelector} { ${declaration}; }`,\n };\n }\n\n // Fallback to no condition\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n}\n\n/**\n * Get CSS value entries from PropertyValues.\n */\nfunction getValueEntries(values: PropertyValues): Array<[string, string | number]> {\n if (Array.isArray(values)) {\n // Array format: ['flex', 'block'] -> [['flex', 'flex'], ['block', 'block']]\n return values.map((v) => [v, v]);\n } else {\n // Object format: { 0: '0', 1: '4px' } -> [['0', '0'], ['1', '4px']]\n return Object.entries(values);\n }\n}\n\n/**\n * Generate all atomic CSS classes for a property collection.\n */\nexport function generateAllAtomicClasses<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n>(\n namespace: string,\n properties: P,\n conditions: C,\n defaultCondition: keyof C | false,\n): Array<{ key: string; css: string }> {\n const rules: Array<{ key: string; css: string }> = [];\n\n for (const [property, values] of Object.entries(properties)) {\n const valueEntries = getValueEntries(values);\n\n for (const [valueKey, cssValue] of valueEntries) {\n // Generate base class (no condition or with default condition)\n if (defaultCondition === false) {\n rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));\n } else {\n const condition = conditions[defaultCondition as string];\n if (condition) {\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condition,\n name: defaultCondition as string,\n }),\n );\n }\n }\n\n // Generate conditional variants\n for (const [condName, condDef] of Object.entries(conditions)) {\n // Skip if this is the default condition and we already generated it\n if (defaultCondition !== false && condName === defaultCondition) {\n continue;\n }\n\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condDef,\n name: condName,\n }),\n );\n }\n }\n }\n\n return rules;\n}\n\n/**\n * Generate all atomic CSS classes from multiple property collections.\n */\nexport function generateFromCollections(\n namespace: string,\n collections: PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n): Array<{ key: string; css: string }> {\n const allRules: Array<{ key: string; css: string }> = [];\n\n for (const collection of collections) {\n const rules = generateAllAtomicClasses(\n namespace,\n collection.properties,\n collection.conditions,\n collection.defaultCondition,\n );\n allRules.push(...rules);\n }\n\n return allRules;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n PropertyCollection,\n} from './types';\nimport { sanitizeValue, isConditionalValue } from './utils';\n\n/**\n * Build a lookup map for runtime class name resolution.\n */\nexport function buildLookupMap<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n S extends ShorthandDefinitions<P>,\n>(\n _namespace: string,\n collections: PropertyCollection<P, C, S>[],\n): {\n propertyMap: Map<string, Set<string>>;\n conditionKeys: Set<string>;\n shorthands: Map<string, string[]>;\n} {\n const propertyMap = new Map<string, Set<string>>();\n const conditionKeys = new Set<string>();\n const shorthands = new Map<string, string[]>();\n\n for (const collection of collections) {\n // Collect properties\n for (const property of Object.keys(collection.properties)) {\n if (!propertyMap.has(property)) {\n propertyMap.set(property, new Set());\n }\n }\n\n // Collect conditions\n for (const condition of Object.keys(collection.conditions)) {\n conditionKeys.add(condition);\n }\n\n // Collect shorthands\n for (const [shorthand, props] of Object.entries(collection.shorthands)) {\n shorthands.set(shorthand, props as string[]);\n }\n }\n\n return { propertyMap, conditionKeys, shorthands };\n}\n\n/**\n * Expand shorthands in props object.\n */\nexport function expandShorthands(\n props: Record<string, unknown>,\n shorthands: Map<string, string[]>,\n): Record<string, unknown> {\n const expanded: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (shorthands.has(key)) {\n // Expand shorthand\n const properties = shorthands.get(key)!;\n for (const prop of properties) {\n expanded[prop] = value;\n }\n } else {\n // Regular property\n expanded[key] = value;\n }\n }\n\n return expanded;\n}\n\n/**\n * Resolve a single property value to class names.\n */\nfunction resolveValue(\n namespace: string,\n property: string,\n value: unknown,\n conditionKeys: Set<string>,\n): string[] {\n const classNames: string[] = [];\n\n if (isConditionalValue(value, conditionKeys)) {\n // Conditional value: { mobile: 'flex', desktop: 'block' }\n for (const [condition, condValue] of Object.entries(value)) {\n if (conditionKeys.has(condition)) {\n const sanitized = sanitizeValue(String(condValue));\n classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);\n }\n }\n } else {\n // Direct value: 'flex' or 2\n const sanitized = sanitizeValue(String(value));\n classNames.push(`${namespace}-${property}-${sanitized}`);\n }\n\n return classNames;\n}\n\n/**\n * Create a runtime resolver function.\n */\nexport function createResolver(\n namespace: string,\n _propertyMap: Map<string, Set<string>>,\n conditionKeys: Set<string>,\n shorthands: Map<string, string[]>,\n): (props: Record<string, unknown>) => string {\n return (props: Record<string, unknown>): string => {\n // Expand shorthands\n const expanded = expandShorthands(props, shorthands);\n\n const classNames: string[] = [];\n\n for (const [property, value] of Object.entries(expanded)) {\n if (value == null) continue;\n\n const resolved = resolveValue(namespace, property, value, conditionKeys);\n classNames.push(...resolved);\n }\n\n return classNames.join(' ');\n };\n}\n","import type {\n PropertyCollection,\n PropsFunction,\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n} from './types';\nimport { insertRules } from 'typestyles';\nimport { generateFromCollections } from './generate';\nimport { buildLookupMap, createResolver } from './runtime';\n\n/**\n * Combine property collections into a typed props function with pre-generated CSS.\n *\n * @example\n * ```ts\n * const props = createProps('atoms', responsiveProps, colorProps);\n *\n * // Type-safe usage\n * props({\n * display: 'flex',\n * padding: 2,\n * paddingTop: { mobile: 3 },\n * });\n * // Returns: \"atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3\"\n * ```\n */\nexport function createProps<\n Collections extends PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n>(namespace: string, ...collections: Collections): PropsFunction<Collections> {\n // Generate all CSS rules upfront\n const cssRules = generateFromCollections(namespace, collections);\n\n // Inject CSS\n insertRules(cssRules);\n\n // Build runtime lookup\n const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);\n\n // Create resolver function\n const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);\n\n // Create properties set for inspection\n const properties = new Set<string>();\n for (const collection of collections) {\n for (const prop of Object.keys(collection.properties)) {\n properties.add(prop);\n }\n for (const shorthand of Object.keys(collection.shorthands)) {\n properties.add(shorthand);\n }\n }\n\n // Attach properties to the function\n const propsFunction = Object.assign(resolver, { properties });\n\n return propsFunction as PropsFunction<Collections>;\n}\n"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","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U,CAAA,EAAG;AAC1D,MAAA,UAAA,CAAW,IAAI,SAAS,CAAA;AAAA,IAC1B;AAAA,EACF;AAGA,EAAA,MAAM,gBAAgB,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,EAAE,YAAY,CAAA;AAE5D,EAAA,OAAO,aAAA;AACT","file":"index.js","sourcesContent":["import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n DefinePropertiesConfig,\n PropertyCollection,\n} from './types.js';\n\n/**\n * Define a collection of CSS properties with their allowed values and optional conditions.\n *\n * @example\n * ```ts\n * const responsiveProps = defineProperties({\n * conditions: {\n * mobile: { '@media': '(min-width: 768px)' },\n * desktop: { '@media': '(min-width: 1024px)' },\n * },\n * defaultCondition: false,\n * properties: {\n * display: ['flex', 'block', 'grid', 'none'],\n * paddingTop: { 0: '0', 1: '4px', 2: '8px', 3: '16px' },\n * },\n * shorthands: {\n * padding: ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],\n * },\n * });\n * ```\n */\nexport function defineProperties<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions = ConditionDefinitions,\n S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>,\n>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S> {\n const conditions = (config.conditions || {}) as C;\n const shorthands = (config.shorthands || {}) as S;\n const defaultCondition = config.defaultCondition ?? false;\n\n return {\n properties: config.properties,\n conditions,\n defaultCondition,\n shorthands,\n };\n}\n","/**\n * Sanitize a value for use in a class name.\n * Replaces spaces with hyphens and removes special characters.\n */\nexport function sanitizeValue(value: string | number): string {\n return String(value)\n .replace(/\\s+/g, '-')\n .replace(/[^a-zA-Z0-9-_]/g, '');\n}\n\n/**\n * Convert camelCase to kebab-case for CSS property names.\n */\nexport function toKebabCase(str: string): string {\n // Handle vendor prefixes (ms, webkit, moz)\n if (str.startsWith('ms')) {\n return '-' + str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n }\n return str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n}\n\n/**\n * Check if a value is a conditional object (has condition keys).\n */\nexport function isConditionalValue(\n value: unknown,\n conditionKeys: Set<string>,\n): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n // Check if any key is a known condition\n for (const key in value) {\n if (conditionKeys.has(key)) {\n return true;\n }\n }\n\n return false;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n PropertyCollection,\n ConditionDefinition,\n PropertyValues,\n ShorthandDefinitions,\n} from './types.js';\nimport { sanitizeValue, toKebabCase } from './utils.js';\n\n/**\n * Generate a single atomic CSS class.\n */\nfunction generateAtomicClass(\n namespace: string,\n property: string,\n valueKey: string,\n cssValue: string | number,\n condition?: ConditionDefinition & { name: string },\n): { key: string; css: string } {\n const sanitizedValue = sanitizeValue(valueKey);\n const className = condition\n ? `${namespace}-${property}-${condition.name}-${sanitizedValue}`\n : `${namespace}-${property}-${sanitizedValue}`;\n\n const kebabProp = toKebabCase(property);\n const declaration = `${kebabProp}: ${cssValue}`;\n\n if (!condition) {\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n }\n\n // Handle media queries\n if (condition['@media']) {\n const mediaQuery = `@media ${condition['@media']}`;\n return {\n key: `${mediaQuery}:.${className}`,\n css: `${mediaQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle container queries\n if (condition['@container']) {\n const containerQuery = `@container ${condition['@container']}`;\n return {\n key: `${containerQuery}:.${className}`,\n css: `${containerQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle @supports\n if (condition['@supports']) {\n const supportsQuery = `@supports ${condition['@supports']}`;\n return {\n key: `${supportsQuery}:.${className}`,\n css: `${supportsQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle custom selectors\n if (condition.selector) {\n const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);\n return {\n key: wrappedSelector,\n css: `${wrappedSelector} { ${declaration}; }`,\n };\n }\n\n // Fallback to no condition\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n}\n\n/**\n * Get CSS value entries from PropertyValues.\n */\nfunction getValueEntries(values: PropertyValues): Array<[string, string | number]> {\n if (Array.isArray(values)) {\n // Array format: ['flex', 'block'] -> [['flex', 'flex'], ['block', 'block']]\n return values.map((v) => [v, v]);\n } else {\n // Object format: { 0: '0', 1: '4px' } -> [['0', '0'], ['1', '4px']]\n return Object.entries(values);\n }\n}\n\n/**\n * Generate all atomic CSS classes for a property collection.\n */\nexport function generateAllAtomicClasses<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n>(\n namespace: string,\n properties: P,\n conditions: C,\n defaultCondition: keyof C | false,\n): Array<{ key: string; css: string }> {\n const rules: Array<{ key: string; css: string }> = [];\n\n for (const [property, values] of Object.entries(properties)) {\n const valueEntries = getValueEntries(values);\n\n for (const [valueKey, cssValue] of valueEntries) {\n // Generate base class (no condition or with default condition)\n if (defaultCondition === false) {\n rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));\n } else {\n const condition = conditions[defaultCondition as string];\n if (condition) {\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condition,\n name: defaultCondition as string,\n }),\n );\n }\n }\n\n // Generate conditional variants\n for (const [condName, condDef] of Object.entries(conditions)) {\n // Skip if this is the default condition and we already generated it\n if (defaultCondition !== false && condName === defaultCondition) {\n continue;\n }\n\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condDef,\n name: condName,\n }),\n );\n }\n }\n }\n\n return rules;\n}\n\n/**\n * Generate all atomic CSS classes from multiple property collections.\n */\nexport function generateFromCollections(\n namespace: string,\n collections: PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n): Array<{ key: string; css: string }> {\n const allRules: Array<{ key: string; css: string }> = [];\n\n for (const collection of collections) {\n const rules = generateAllAtomicClasses(\n namespace,\n collection.properties,\n collection.conditions,\n collection.defaultCondition,\n );\n allRules.push(...rules);\n }\n\n return allRules;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n PropertyCollection,\n} from './types.js';\nimport { sanitizeValue, isConditionalValue } from './utils.js';\n\n/**\n * Build a lookup map for runtime class name resolution.\n */\nexport function buildLookupMap<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n S extends ShorthandDefinitions<P>,\n>(\n _namespace: string,\n collections: PropertyCollection<P, C, S>[],\n): {\n propertyMap: Map<string, Set<string>>;\n conditionKeys: Set<string>;\n shorthands: Map<string, string[]>;\n} {\n const propertyMap = new Map<string, Set<string>>();\n const conditionKeys = new Set<string>();\n const shorthands = new Map<string, string[]>();\n\n for (const collection of collections) {\n // Collect properties\n for (const property of Object.keys(collection.properties)) {\n if (!propertyMap.has(property)) {\n propertyMap.set(property, new Set());\n }\n }\n\n // Collect conditions\n for (const condition of Object.keys(collection.conditions)) {\n conditionKeys.add(condition);\n }\n\n // Collect shorthands\n for (const [shorthand, props] of Object.entries(collection.shorthands)) {\n shorthands.set(shorthand, props as string[]);\n }\n }\n\n return { propertyMap, conditionKeys, shorthands };\n}\n\n/**\n * Expand shorthands in props object.\n */\nexport function expandShorthands(\n props: Record<string, unknown>,\n shorthands: Map<string, string[]>,\n): Record<string, unknown> {\n const expanded: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (shorthands.has(key)) {\n // Expand shorthand\n const properties = shorthands.get(key)!;\n for (const prop of properties) {\n expanded[prop] = value;\n }\n } else {\n // Regular property\n expanded[key] = value;\n }\n }\n\n return expanded;\n}\n\n/**\n * Resolve a single property value to class names.\n */\nfunction resolveValue(\n namespace: string,\n property: string,\n value: unknown,\n conditionKeys: Set<string>,\n): string[] {\n const classNames: string[] = [];\n\n if (isConditionalValue(value, conditionKeys)) {\n // Conditional value: { mobile: 'flex', desktop: 'block' }\n for (const [condition, condValue] of Object.entries(value)) {\n if (conditionKeys.has(condition)) {\n const sanitized = sanitizeValue(String(condValue));\n classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);\n }\n }\n } else {\n // Direct value: 'flex' or 2\n const sanitized = sanitizeValue(String(value));\n classNames.push(`${namespace}-${property}-${sanitized}`);\n }\n\n return classNames;\n}\n\n/**\n * Create a runtime resolver function.\n */\nexport function createResolver(\n namespace: string,\n _propertyMap: Map<string, Set<string>>,\n conditionKeys: Set<string>,\n shorthands: Map<string, string[]>,\n): (props: Record<string, unknown>) => string {\n return (props: Record<string, unknown>): string => {\n // Expand shorthands\n const expanded = expandShorthands(props, shorthands);\n\n const classNames: string[] = [];\n\n for (const [property, value] of Object.entries(expanded)) {\n if (value == null) continue;\n\n const resolved = resolveValue(namespace, property, value, conditionKeys);\n classNames.push(...resolved);\n }\n\n return classNames.join(' ');\n };\n}\n","import type {\n PropertyCollection,\n PropsFunction,\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n} from './types.js';\nimport { insertRules } from 'typestyles';\nimport { generateFromCollections } from './generate.js';\nimport { buildLookupMap, createResolver } from './runtime.js';\n\n/**\n * Combine property collections into a typed props function with pre-generated CSS.\n *\n * @example\n * ```ts\n * const props = createProps('atoms', responsiveProps, colorProps);\n *\n * // Type-safe usage\n * props({\n * display: 'flex',\n * padding: 2,\n * paddingTop: { mobile: 3 },\n * });\n * // Returns: \"atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3\"\n * ```\n */\nexport function createProps<\n Collections extends PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n>(namespace: string, ...collections: Collections): PropsFunction<Collections> {\n // Generate all CSS rules upfront\n const cssRules = generateFromCollections(namespace, collections);\n\n // Inject CSS\n insertRules(cssRules);\n\n // Build runtime lookup\n const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);\n\n // Create resolver function\n const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);\n\n // Create properties set for inspection\n const properties = new Set<string>();\n for (const collection of collections) {\n for (const prop of Object.keys(collection.properties)) {\n properties.add(prop);\n }\n for (const shorthand of Object.keys(collection.shorthands)) {\n properties.add(shorthand);\n }\n }\n\n // Attach properties to the function\n const propsFunction = Object.assign(resolver, { properties });\n\n return propsFunction as PropsFunction<Collections>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"names":[],"mappings":";;;AA6BO,SAAS,iBAId,MAAA,EAAsE;AACtE,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,gBAAA,GAAmB,OAAO,gBAAA,IAAoB,KAAA;AAEpD,EAAA,OAAO;AAAA,IACL,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,UAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF;AACF;;;ACxCO,SAAS,cAAc,KAAA,EAAgC;AAC5D,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAChB,OAAA,CAAQ,QAAQ,GAAG,CAAA,CACnB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAClC;AAKO,SAAS,YAAY,GAAA,EAAqB;AAE/C,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACxB,IAAA,OAAO,GAAA,GAAM,IAAI,OAAA,CAAQ,QAAA,EAAU,CAAC,CAAA,KAAM,GAAA,GAAM,CAAA,CAAE,WAAA,EAAa,CAAA;AAAA,EACjE;AACA,EAAA,OAAO,GAAA,CAAI,QAAQ,QAAA,EAAU,CAAC,MAAM,GAAA,GAAM,CAAA,CAAE,aAAa,CAAA;AAC3D;AAKO,SAAS,kBAAA,CACd,OACA,aAAA,EACkC;AAClC,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,KAAA,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A,uBAAiB,GAAA,EAAY;AACnC,EAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AACpC,IAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,UAAU,CAAA,EAAG;AACrD,MAAA,UAAA,CAAW,IAAI,IAAI,CAAA;AAAA,IACrB;AACA,IAAA,KAAA,MAAW,SAAA,IAAa,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,UAAU,CAAA,EAAG;AAC1D,MAAA,UAAA,CAAW,IAAI,SAAS,CAAA;AAAA,IAC1B;AAAA,EACF;AAGA,EAAA,MAAM,gBAAgB,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,EAAE,YAAY,CAAA;AAE5D,EAAA,OAAO,aAAA;AACT","file":"index.js","sourcesContent":["import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n DefinePropertiesConfig,\n PropertyCollection,\n} from './types';\n\n/**\n * Define a collection of CSS properties with their allowed values and optional conditions.\n *\n * @example\n * ```ts\n * const responsiveProps = defineProperties({\n * conditions: {\n * mobile: { '@media': '(min-width: 768px)' },\n * desktop: { '@media': '(min-width: 1024px)' },\n * },\n * defaultCondition: false,\n * properties: {\n * display: ['flex', 'block', 'grid', 'none'],\n * paddingTop: { 0: '0', 1: '4px', 2: '8px', 3: '16px' },\n * },\n * shorthands: {\n * padding: ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],\n * },\n * });\n * ```\n */\nexport function defineProperties<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions = ConditionDefinitions,\n S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>,\n>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S> {\n const conditions = (config.conditions || {}) as C;\n const shorthands = (config.shorthands || {}) as S;\n const defaultCondition = config.defaultCondition ?? false;\n\n return {\n properties: config.properties,\n conditions,\n defaultCondition,\n shorthands,\n };\n}\n","/**\n * Sanitize a value for use in a class name.\n * Replaces spaces with hyphens and removes special characters.\n */\nexport function sanitizeValue(value: string | number): string {\n return String(value)\n .replace(/\\s+/g, '-')\n .replace(/[^a-zA-Z0-9-_]/g, '');\n}\n\n/**\n * Convert camelCase to kebab-case for CSS property names.\n */\nexport function toKebabCase(str: string): string {\n // Handle vendor prefixes (ms, webkit, moz)\n if (str.startsWith('ms')) {\n return '-' + str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n }\n return str.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n}\n\n/**\n * Check if a value is a conditional object (has condition keys).\n */\nexport function isConditionalValue(\n value: unknown,\n conditionKeys: Set<string>,\n): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n // Check if any key is a known condition\n for (const key in value) {\n if (conditionKeys.has(key)) {\n return true;\n }\n }\n\n return false;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n PropertyCollection,\n ConditionDefinition,\n PropertyValues,\n ShorthandDefinitions,\n} from './types';\nimport { sanitizeValue, toKebabCase } from './utils';\n\n/**\n * Generate a single atomic CSS class.\n */\nfunction generateAtomicClass(\n namespace: string,\n property: string,\n valueKey: string,\n cssValue: string | number,\n condition?: ConditionDefinition & { name: string },\n): { key: string; css: string } {\n const sanitizedValue = sanitizeValue(valueKey);\n const className = condition\n ? `${namespace}-${property}-${condition.name}-${sanitizedValue}`\n : `${namespace}-${property}-${sanitizedValue}`;\n\n const kebabProp = toKebabCase(property);\n const declaration = `${kebabProp}: ${cssValue}`;\n\n if (!condition) {\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n }\n\n // Handle media queries\n if (condition['@media']) {\n const mediaQuery = `@media ${condition['@media']}`;\n return {\n key: `${mediaQuery}:.${className}`,\n css: `${mediaQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle container queries\n if (condition['@container']) {\n const containerQuery = `@container ${condition['@container']}`;\n return {\n key: `${containerQuery}:.${className}`,\n css: `${containerQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle @supports\n if (condition['@supports']) {\n const supportsQuery = `@supports ${condition['@supports']}`;\n return {\n key: `${supportsQuery}:.${className}`,\n css: `${supportsQuery} { .${className} { ${declaration}; } }`,\n };\n }\n\n // Handle custom selectors\n if (condition.selector) {\n const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);\n return {\n key: wrappedSelector,\n css: `${wrappedSelector} { ${declaration}; }`,\n };\n }\n\n // Fallback to no condition\n return {\n key: `.${className}`,\n css: `.${className} { ${declaration}; }`,\n };\n}\n\n/**\n * Get CSS value entries from PropertyValues.\n */\nfunction getValueEntries(values: PropertyValues): Array<[string, string | number]> {\n if (Array.isArray(values)) {\n // Array format: ['flex', 'block'] -> [['flex', 'flex'], ['block', 'block']]\n return values.map((v) => [v, v]);\n } else {\n // Object format: { 0: '0', 1: '4px' } -> [['0', '0'], ['1', '4px']]\n return Object.entries(values);\n }\n}\n\n/**\n * Generate all atomic CSS classes for a property collection.\n */\nexport function generateAllAtomicClasses<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n>(\n namespace: string,\n properties: P,\n conditions: C,\n defaultCondition: keyof C | false,\n): Array<{ key: string; css: string }> {\n const rules: Array<{ key: string; css: string }> = [];\n\n for (const [property, values] of Object.entries(properties)) {\n const valueEntries = getValueEntries(values);\n\n for (const [valueKey, cssValue] of valueEntries) {\n // Generate base class (no condition or with default condition)\n if (defaultCondition === false) {\n rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));\n } else {\n const condition = conditions[defaultCondition as string];\n if (condition) {\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condition,\n name: defaultCondition as string,\n }),\n );\n }\n }\n\n // Generate conditional variants\n for (const [condName, condDef] of Object.entries(conditions)) {\n // Skip if this is the default condition and we already generated it\n if (defaultCondition !== false && condName === defaultCondition) {\n continue;\n }\n\n rules.push(\n generateAtomicClass(namespace, property, valueKey, cssValue, {\n ...condDef,\n name: condName,\n }),\n );\n }\n }\n }\n\n return rules;\n}\n\n/**\n * Generate all atomic CSS classes from multiple property collections.\n */\nexport function generateFromCollections(\n namespace: string,\n collections: PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n): Array<{ key: string; css: string }> {\n const allRules: Array<{ key: string; css: string }> = [];\n\n for (const collection of collections) {\n const rules = generateAllAtomicClasses(\n namespace,\n collection.properties,\n collection.conditions,\n collection.defaultCondition,\n );\n allRules.push(...rules);\n }\n\n return allRules;\n}\n","import type {\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n PropertyCollection,\n} from './types';\nimport { sanitizeValue, isConditionalValue } from './utils';\n\n/**\n * Build a lookup map for runtime class name resolution.\n */\nexport function buildLookupMap<\n P extends PropertyDefinitions,\n C extends ConditionDefinitions,\n S extends ShorthandDefinitions<P>,\n>(\n _namespace: string,\n collections: PropertyCollection<P, C, S>[],\n): {\n propertyMap: Map<string, Set<string>>;\n conditionKeys: Set<string>;\n shorthands: Map<string, string[]>;\n} {\n const propertyMap = new Map<string, Set<string>>();\n const conditionKeys = new Set<string>();\n const shorthands = new Map<string, string[]>();\n\n for (const collection of collections) {\n // Collect properties\n for (const property of Object.keys(collection.properties)) {\n if (!propertyMap.has(property)) {\n propertyMap.set(property, new Set());\n }\n }\n\n // Collect conditions\n for (const condition of Object.keys(collection.conditions)) {\n conditionKeys.add(condition);\n }\n\n // Collect shorthands\n for (const [shorthand, props] of Object.entries(collection.shorthands)) {\n shorthands.set(shorthand, props as string[]);\n }\n }\n\n return { propertyMap, conditionKeys, shorthands };\n}\n\n/**\n * Expand shorthands in props object.\n */\nexport function expandShorthands(\n props: Record<string, unknown>,\n shorthands: Map<string, string[]>,\n): Record<string, unknown> {\n const expanded: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (shorthands.has(key)) {\n // Expand shorthand\n const properties = shorthands.get(key)!;\n for (const prop of properties) {\n expanded[prop] = value;\n }\n } else {\n // Regular property\n expanded[key] = value;\n }\n }\n\n return expanded;\n}\n\n/**\n * Resolve a single property value to class names.\n */\nfunction resolveValue(\n namespace: string,\n property: string,\n value: unknown,\n conditionKeys: Set<string>,\n): string[] {\n const classNames: string[] = [];\n\n if (isConditionalValue(value, conditionKeys)) {\n // Conditional value: { mobile: 'flex', desktop: 'block' }\n for (const [condition, condValue] of Object.entries(value)) {\n if (conditionKeys.has(condition)) {\n const sanitized = sanitizeValue(String(condValue));\n classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);\n }\n }\n } else {\n // Direct value: 'flex' or 2\n const sanitized = sanitizeValue(String(value));\n classNames.push(`${namespace}-${property}-${sanitized}`);\n }\n\n return classNames;\n}\n\n/**\n * Create a runtime resolver function.\n */\nexport function createResolver(\n namespace: string,\n _propertyMap: Map<string, Set<string>>,\n conditionKeys: Set<string>,\n shorthands: Map<string, string[]>,\n): (props: Record<string, unknown>) => string {\n return (props: Record<string, unknown>): string => {\n // Expand shorthands\n const expanded = expandShorthands(props, shorthands);\n\n const classNames: string[] = [];\n\n for (const [property, value] of Object.entries(expanded)) {\n if (value == null) continue;\n\n const resolved = resolveValue(namespace, property, value, conditionKeys);\n classNames.push(...resolved);\n }\n\n return classNames.join(' ');\n };\n}\n","import type {\n PropertyCollection,\n PropsFunction,\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions,\n} from './types';\nimport { insertRules } from 'typestyles';\nimport { generateFromCollections } from './generate';\nimport { buildLookupMap, createResolver } from './runtime';\n\n/**\n * Combine property collections into a typed props function with pre-generated CSS.\n *\n * @example\n * ```ts\n * const props = createProps('atoms', responsiveProps, colorProps);\n *\n * // Type-safe usage\n * props({\n * display: 'flex',\n * padding: 2,\n * paddingTop: { mobile: 3 },\n * });\n * // Returns: \"atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3\"\n * ```\n */\nexport function createProps<\n Collections extends PropertyCollection<\n PropertyDefinitions,\n ConditionDefinitions,\n ShorthandDefinitions<PropertyDefinitions>\n >[],\n>(namespace: string, ...collections: Collections): PropsFunction<Collections> {\n // Generate all CSS rules upfront\n const cssRules = generateFromCollections(namespace, collections);\n\n // Inject CSS\n insertRules(cssRules);\n\n // Build runtime lookup\n const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);\n\n // Create resolver function\n const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);\n\n // Create properties set for inspection\n const properties = new Set<string>();\n for (const collection of collections) {\n for (const prop of Object.keys(collection.properties)) {\n properties.add(prop);\n }\n for (const shorthand of Object.keys(collection.shorthands)) {\n properties.add(shorthand);\n }\n }\n\n // Attach properties to the function\n const propsFunction = Object.assign(resolver, { properties });\n\n return propsFunction as PropsFunction<Collections>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/props",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Type-safe atomic CSS utility generator for typestyles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"typestyles": "0.
|
|
25
|
+
"typestyles": "0.7.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
+
"eslint": "^9.39.2",
|
|
28
29
|
"tsup": "^8.0.0",
|
|
29
30
|
"typescript": "^5.9.3",
|
|
30
31
|
"vitest": "^3.0.0"
|
|
@@ -32,12 +33,13 @@
|
|
|
32
33
|
"license": "Apache-2.0",
|
|
33
34
|
"repository": {
|
|
34
35
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/
|
|
36
|
+
"url": "https://github.com/type-styles/typestyles",
|
|
36
37
|
"directory": "packages/props"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"build": "tsup",
|
|
40
41
|
"test": "vitest run",
|
|
42
|
+
"lint": "eslint .",
|
|
41
43
|
"typecheck": "tsc --noEmit"
|
|
42
44
|
}
|
|
43
45
|
}
|