@typestyles/props 0.4.38 → 0.4.40
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 +1 -1
- package/dist/index.cjs +147 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -30
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +28 -30
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +146 -192
- package/dist/index.js.map +1 -1
- package/package.json +8 -10
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @typestyles/props
|
|
2
2
|
|
|
3
|
-
Type-safe atomic CSS utilities for [typestyles](https://github.com/
|
|
3
|
+
Type-safe atomic CSS utilities for [typestyles](https://github.com/phthalo-dev/typestyles) — Tailwind-style ergonomics with full TypeScript inference, readable class names, and CSS you can inspect in DevTools.
|
|
4
4
|
|
|
5
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
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,223 +1,176 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// src/defineProperties.ts
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let typestyles = require("typestyles");
|
|
3
|
+
//#region src/defineProperties.ts
|
|
6
4
|
function defineProperties(config) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const conditions = config.conditions || {};
|
|
6
|
+
const shorthands = config.shorthands || {};
|
|
7
|
+
const defaultCondition = config.defaultCondition ?? false;
|
|
8
|
+
return {
|
|
9
|
+
properties: config.properties,
|
|
10
|
+
conditions,
|
|
11
|
+
defaultCondition,
|
|
12
|
+
shorthands
|
|
13
|
+
};
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/utils.ts
|
|
19
17
|
function sanitizeValue(value) {
|
|
20
|
-
|
|
18
|
+
return String(value).replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-_]/g, "");
|
|
21
19
|
}
|
|
22
20
|
function toKebabCase(str) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
21
|
+
if (str.startsWith("ms")) return "-" + str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
22
|
+
return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
27
23
|
}
|
|
28
24
|
function isConditionalValue(value, conditionKeys) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for (const key in value) {
|
|
33
|
-
if (conditionKeys.has(key)) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
25
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
26
|
+
for (const key in value) if (conditionKeys.has(key)) return true;
|
|
27
|
+
return false;
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/generate.ts
|
|
41
31
|
function generateAtomicClass(namespace, property, valueKey, cssValue, condition) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
key: `.${className}`,
|
|
82
|
-
css: `.${className} { ${declaration}; }`
|
|
83
|
-
};
|
|
32
|
+
const sanitizedValue = sanitizeValue(valueKey);
|
|
33
|
+
const className = condition ? `${namespace}-${property}-${condition.name}-${sanitizedValue}` : `${namespace}-${property}-${sanitizedValue}`;
|
|
34
|
+
const declaration = `${toKebabCase(property)}: ${cssValue}`;
|
|
35
|
+
if (!condition) return {
|
|
36
|
+
key: `.${className}`,
|
|
37
|
+
css: `.${className} { ${declaration}; }`
|
|
38
|
+
};
|
|
39
|
+
if (condition["@media"]) {
|
|
40
|
+
const mediaQuery = `@media ${condition["@media"]}`;
|
|
41
|
+
return {
|
|
42
|
+
key: `${mediaQuery}:.${className}`,
|
|
43
|
+
css: `${mediaQuery} { .${className} { ${declaration}; } }`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (condition["@container"]) {
|
|
47
|
+
const containerQuery = `@container ${condition["@container"]}`;
|
|
48
|
+
return {
|
|
49
|
+
key: `${containerQuery}:.${className}`,
|
|
50
|
+
css: `${containerQuery} { .${className} { ${declaration}; } }`
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (condition["@supports"]) {
|
|
54
|
+
const supportsQuery = `@supports ${condition["@supports"]}`;
|
|
55
|
+
return {
|
|
56
|
+
key: `${supportsQuery}:.${className}`,
|
|
57
|
+
css: `${supportsQuery} { .${className} { ${declaration}; } }`
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (condition.selector) {
|
|
61
|
+
const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);
|
|
62
|
+
return {
|
|
63
|
+
key: wrappedSelector,
|
|
64
|
+
css: `${wrappedSelector} { ${declaration}; }`
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
key: `.${className}`,
|
|
69
|
+
css: `.${className} { ${declaration}; }`
|
|
70
|
+
};
|
|
84
71
|
}
|
|
85
72
|
function getValueEntries(values) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} else {
|
|
89
|
-
return Object.entries(values);
|
|
90
|
-
}
|
|
73
|
+
if (Array.isArray(values)) return values.map((v) => [v, v]);
|
|
74
|
+
else return Object.entries(values);
|
|
91
75
|
}
|
|
92
76
|
function generateAllAtomicClasses(namespace, properties, conditions, defaultCondition) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
generateAtomicClass(namespace, property, valueKey, cssValue, {
|
|
116
|
-
...condDef,
|
|
117
|
-
name: condName
|
|
118
|
-
})
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return rules;
|
|
77
|
+
const rules = [];
|
|
78
|
+
for (const [property, values] of Object.entries(properties)) {
|
|
79
|
+
const valueEntries = getValueEntries(values);
|
|
80
|
+
for (const [valueKey, cssValue] of valueEntries) {
|
|
81
|
+
if (defaultCondition === false) rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));
|
|
82
|
+
else {
|
|
83
|
+
const condition = conditions[defaultCondition];
|
|
84
|
+
if (condition) rules.push(generateAtomicClass(namespace, property, valueKey, cssValue, {
|
|
85
|
+
...condition,
|
|
86
|
+
name: defaultCondition
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
for (const [condName, condDef] of Object.entries(conditions)) {
|
|
90
|
+
if (defaultCondition !== false && condName === defaultCondition) continue;
|
|
91
|
+
rules.push(generateAtomicClass(namespace, property, valueKey, cssValue, {
|
|
92
|
+
...condDef,
|
|
93
|
+
name: condName
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return rules;
|
|
124
99
|
}
|
|
125
100
|
function generateFromCollections(namespace, collections) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
collection.defaultCondition
|
|
133
|
-
);
|
|
134
|
-
allRules.push(...rules);
|
|
135
|
-
}
|
|
136
|
-
return allRules;
|
|
101
|
+
const allRules = [];
|
|
102
|
+
for (const collection of collections) {
|
|
103
|
+
const rules = generateAllAtomicClasses(namespace, collection.properties, collection.conditions, collection.defaultCondition);
|
|
104
|
+
allRules.push(...rules);
|
|
105
|
+
}
|
|
106
|
+
return allRules;
|
|
137
107
|
}
|
|
138
|
-
|
|
139
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/runtime.ts
|
|
140
110
|
function buildLookupMap(_namespace, collections) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
shorthands.set(shorthand, props);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return { propertyMap, conditionKeys, shorthands };
|
|
111
|
+
const propertyMap = new Map();
|
|
112
|
+
const conditionKeys = new Set();
|
|
113
|
+
const shorthands = new Map();
|
|
114
|
+
for (const collection of collections) {
|
|
115
|
+
for (const property of Object.keys(collection.properties)) if (!propertyMap.has(property)) propertyMap.set(property, new Set());
|
|
116
|
+
for (const condition of Object.keys(collection.conditions)) conditionKeys.add(condition);
|
|
117
|
+
for (const [shorthand, props] of Object.entries(collection.shorthands)) shorthands.set(shorthand, props);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
propertyMap,
|
|
121
|
+
conditionKeys,
|
|
122
|
+
shorthands
|
|
123
|
+
};
|
|
158
124
|
}
|
|
159
125
|
function expandShorthands(props, shorthands) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
expanded[key] = value;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return expanded;
|
|
126
|
+
const expanded = {};
|
|
127
|
+
for (const [key, value] of Object.entries(props)) if (shorthands.has(key)) {
|
|
128
|
+
const properties = shorthands.get(key);
|
|
129
|
+
for (const prop of properties) expanded[prop] = value;
|
|
130
|
+
} else expanded[key] = value;
|
|
131
|
+
return expanded;
|
|
172
132
|
}
|
|
173
133
|
function resolveValue(namespace, property, value, conditionKeys) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
return classNames;
|
|
134
|
+
const classNames = [];
|
|
135
|
+
if (isConditionalValue(value, conditionKeys)) {
|
|
136
|
+
for (const [condition, condValue] of Object.entries(value)) if (conditionKeys.has(condition)) {
|
|
137
|
+
const sanitized = sanitizeValue(String(condValue));
|
|
138
|
+
classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
const sanitized = sanitizeValue(String(value));
|
|
142
|
+
classNames.push(`${namespace}-${property}-${sanitized}`);
|
|
143
|
+
}
|
|
144
|
+
return classNames;
|
|
187
145
|
}
|
|
188
146
|
function createResolver(namespace, _propertyMap, conditionKeys, shorthands) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
147
|
+
return (props) => {
|
|
148
|
+
const expanded = expandShorthands(props, shorthands);
|
|
149
|
+
const classNames = [];
|
|
150
|
+
for (const [property, value] of Object.entries(expanded)) {
|
|
151
|
+
if (value == null) continue;
|
|
152
|
+
const resolved = resolveValue(namespace, property, value, conditionKeys);
|
|
153
|
+
classNames.push(...resolved);
|
|
154
|
+
}
|
|
155
|
+
return classNames.join(" ");
|
|
156
|
+
};
|
|
199
157
|
}
|
|
200
|
-
|
|
201
|
-
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/createProps.ts
|
|
202
160
|
function createProps(namespace, ...collections) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
properties.add(shorthand);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const propsFunction = Object.assign(resolver, { properties });
|
|
217
|
-
return propsFunction;
|
|
161
|
+
const cssRules = generateFromCollections(namespace, collections);
|
|
162
|
+
(0, typestyles.insertRules)(cssRules);
|
|
163
|
+
const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);
|
|
164
|
+
const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);
|
|
165
|
+
const properties = new Set();
|
|
166
|
+
for (const collection of collections) {
|
|
167
|
+
for (const prop of Object.keys(collection.properties)) properties.add(prop);
|
|
168
|
+
for (const shorthand of Object.keys(collection.shorthands)) properties.add(shorthand);
|
|
169
|
+
}
|
|
170
|
+
return Object.assign(resolver, { properties });
|
|
218
171
|
}
|
|
219
|
-
|
|
172
|
+
//#endregion
|
|
220
173
|
exports.createProps = createProps;
|
|
221
174
|
exports.defineProperties = defineProperties;
|
|
222
|
-
|
|
175
|
+
|
|
223
176
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defineProperties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AA,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"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"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"],"mappings":";;;AA6BA,SAAgB,iBAId,QAAsE;CACtE,MAAM,aAAc,OAAO,cAAc,CAAC;CAC1C,MAAM,aAAc,OAAO,cAAc,CAAC;CAC1C,MAAM,mBAAmB,OAAO,oBAAoB;CAEpD,OAAO;EACL,YAAY,OAAO;EACnB;EACA;EACA;CACF;AACF;;;ACxCA,SAAgB,cAAc,OAAgC;CAC5D,OAAO,OAAO,KAAK,CAAC,CACjB,QAAQ,QAAQ,GAAG,CAAC,CACpB,QAAQ,mBAAmB,EAAE;AAClC;AAKA,SAAgB,YAAY,KAAqB;CAE/C,IAAI,IAAI,WAAW,IAAI,GACrB,OAAO,MAAM,IAAI,QAAQ,WAAW,MAAM,MAAM,EAAE,YAAY,CAAC;CAEjE,OAAO,IAAI,QAAQ,WAAW,MAAM,MAAM,EAAE,YAAY,CAAC;AAC3D;AAKA,SAAgB,mBACd,OACA,eACkC;CAClC,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,OAAO;CAIT,KAAK,MAAM,OAAO,OAChB,IAAI,cAAc,IAAI,GAAG,GACvB,OAAO;CAIX,OAAO;AACT;;;AC3BA,SAAS,oBACP,WACA,UACA,UACA,UACA,WAC8B;CAC9B,MAAM,iBAAiB,cAAc,QAAQ;CAC7C,MAAM,YAAY,YACd,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,KAAK,GAAG,mBAC9C,GAAG,UAAU,GAAG,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AAa;EACpC,KAAK,MAAM,QAAQ,OAAO,KAAK,WAAW,UAAU,GAClD,WAAW,IAAI,IAAI;EAErB,KAAK,MAAM,aAAa,OAAO,KAAK,WAAW,UAAU,GACvD,WAAW,IAAI,SAAS;CAE5B;CAKA,OAFsB,OAAO,OAAO,UAAU,EAAE,WAAW,CAExC;AACrB"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* A single condition definition (e.g., media query, selector, container query).
|
|
3
4
|
*/
|
|
4
5
|
interface ConditionDefinition {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
name?: string;
|
|
7
|
+
'@media'?: string;
|
|
8
|
+
'@container'?: string;
|
|
9
|
+
'@supports'?: string;
|
|
10
|
+
selector?: string;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* A map of condition names to their definitions.
|
|
@@ -28,19 +29,19 @@ type ShorthandDefinitions<P extends PropertyDefinitions> = Record<string, Array<
|
|
|
28
29
|
* The configuration object passed to defineProperties().
|
|
29
30
|
*/
|
|
30
31
|
interface DefinePropertiesConfig<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
properties: P;
|
|
33
|
+
conditions?: C;
|
|
34
|
+
defaultCondition?: keyof C | false;
|
|
35
|
+
shorthands?: S;
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* A property collection returned by defineProperties().
|
|
38
39
|
*/
|
|
39
40
|
interface PropertyCollection<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
readonly properties: P;
|
|
42
|
+
readonly conditions: C;
|
|
43
|
+
readonly defaultCondition: keyof C | false;
|
|
44
|
+
readonly shorthands: S;
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Extract value type from PropertyValues.
|
|
@@ -49,28 +50,23 @@ type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string, unkn
|
|
|
49
50
|
/**
|
|
50
51
|
* Create a prop value type that can be a direct value or a conditional object.
|
|
51
52
|
*/
|
|
52
|
-
type PropValue<V, C extends ConditionDefinitions> = V | {
|
|
53
|
-
[K in keyof C]?: V;
|
|
54
|
-
};
|
|
53
|
+
type PropValue<V, C extends ConditionDefinitions> = V | { [K in keyof C]?: V; };
|
|
55
54
|
/**
|
|
56
55
|
* Extract prop types from a property collection.
|
|
57
56
|
*/
|
|
58
|
-
type ExtractProps<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> = {
|
|
59
|
-
[K in keyof P | keyof S]?: K extends keyof S ? PropValue<ExtractValue<P[S[K][number]]>, C> : K extends keyof P ? PropValue<ExtractValue<P[K]>, C> : never;
|
|
60
|
-
};
|
|
57
|
+
type ExtractProps<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> = { [K in keyof P | keyof S]?: K extends keyof S ? PropValue<ExtractValue<P[S[K][number]]>, C> : K extends keyof P ? PropValue<ExtractValue<P[K]>, C> : never; };
|
|
61
58
|
/**
|
|
62
59
|
* The props function signature.
|
|
63
60
|
*/
|
|
64
|
-
type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{
|
|
65
|
-
|
|
66
|
-
}[number]>) => string) & {
|
|
67
|
-
properties: Set<string>;
|
|
61
|
+
type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{ [I in keyof Collections]: Collections[I] extends PropertyCollection<infer P, infer C, infer S> ? ExtractProps<P, C, S> : never; }[number]>) => string) & {
|
|
62
|
+
properties: Set<string>;
|
|
68
63
|
};
|
|
69
64
|
/**
|
|
70
65
|
* Convert a union type to an intersection type.
|
|
71
66
|
*/
|
|
72
|
-
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
73
|
-
|
|
67
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/defineProperties.d.ts
|
|
74
70
|
/**
|
|
75
71
|
* Define a collection of CSS properties with their allowed values and optional conditions.
|
|
76
72
|
*
|
|
@@ -92,8 +88,9 @@ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) exten
|
|
|
92
88
|
* });
|
|
93
89
|
* ```
|
|
94
90
|
*/
|
|
95
|
-
declare function defineProperties<P extends PropertyDefinitions, C extends ConditionDefinitions = ConditionDefinitions, S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S>;
|
|
96
|
-
|
|
91
|
+
export declare function defineProperties<P extends PropertyDefinitions, C extends ConditionDefinitions = ConditionDefinitions, S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S>;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/createProps.d.ts
|
|
97
94
|
/**
|
|
98
95
|
* Combine property collections into a typed props function with pre-generated CSS.
|
|
99
96
|
*
|
|
@@ -110,6 +107,7 @@ declare function defineProperties<P extends PropertyDefinitions, C extends Condi
|
|
|
110
107
|
* // Returns: "atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3"
|
|
111
108
|
* ```
|
|
112
109
|
*/
|
|
113
|
-
declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
|
|
114
|
-
|
|
115
|
-
export {
|
|
110
|
+
export declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
|
|
111
|
+
//#endregion
|
|
112
|
+
export type { ConditionDefinition, ConditionDefinitions, DefinePropertiesConfig, ExtractProps, PropertyCollection, PropertyDefinitions, PropertyValues, PropsFunction, ShorthandDefinitions };
|
|
113
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/defineProperties.ts","../src/createProps.ts"],"mappings":";;;;UAGiB;EACf;EACA;EACA;EACA;EACA;;;;;KAMU,uBAAuB,eAAe;;;;KAKtC,4BAA4B;;;;KAK5B,sBAAsB,eAAe;;;;KAKrC,qBAAqB,UAAU,uBAAuB,eAAe,YAAY;;;;UAK5E,uBACf,UAAU,qBACV,UAAU,sBACV,UAAU,qBAAqB;EAE/B,YAAY;EACZ,aAAa;EACb,yBAAyB;EACzB,aAAa;;;;;UAME,mBACf,UAAU,qBACV,UAAU,sBACV,UAAU,qBAAqB;WAEtB,YAAY;WACZ,YAAY;WACZ,wBAAwB;WACxB,YAAY;;;;;KAMlB,aAAa,KAAK,iBAAiB,OACpC,IACA,UAAU,gCACF;;;;KAMP,UAAU,GAAG,UAAU,wBACxB,OAEG,WAAW,KAAK;;;;KAMX,aACV,UAAU,qBACV,UAAU,sBACV,UAAU,qBAAqB,SAE9B,WAAW,UAAU,KAAK,gBAAgB,IACvC,UAAU,aAAa,EAAE,EAAE,cAAc,KACzC,gBAAgB,IACd,UAAU,aAAa,EAAE,KAAK;;;;KAO1B,cACV,oBAAoB,mBAClB,qBACA,sBACA,qBAAqB,6BAGvB,OAAO,uBAEF,WAAW,cAAc,YAAY,WAAW,yBAAyB,SAAS,SAAS,KACxF,aAAa,GAAG,GAAG;EAK3B,YAAY;;;;;KAMT,oBAAoB,MAAM,qBAAqB,GAAG,8BACrD,SAAS,cAEP;;;;;;;;;;;;;;;;;;;;;;;;wBC1FY,iBACd,UAAU,qBACV,UAAU,uBAAuB,sBACjC,UAAU,qBAAqB,KAAK,eAAe,YAAY,KAC/D,QAAQ,uBAAuB,GAAG,GAAG,KAAK,mBAAmB,GAAG,GAAG;;;;;;;;;;;;;;;;;;;wBCNrD,YACd,oBAAoB,mBAClB,qBACA,sBACA,qBAAqB,yBAEvB,sBAAsB,aAAa,cAAc,cAAc"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* A single condition definition (e.g., media query, selector, container query).
|
|
3
4
|
*/
|
|
4
5
|
interface ConditionDefinition {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
name?: string;
|
|
7
|
+
'@media'?: string;
|
|
8
|
+
'@container'?: string;
|
|
9
|
+
'@supports'?: string;
|
|
10
|
+
selector?: string;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* A map of condition names to their definitions.
|
|
@@ -28,19 +29,19 @@ type ShorthandDefinitions<P extends PropertyDefinitions> = Record<string, Array<
|
|
|
28
29
|
* The configuration object passed to defineProperties().
|
|
29
30
|
*/
|
|
30
31
|
interface DefinePropertiesConfig<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
properties: P;
|
|
33
|
+
conditions?: C;
|
|
34
|
+
defaultCondition?: keyof C | false;
|
|
35
|
+
shorthands?: S;
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* A property collection returned by defineProperties().
|
|
38
39
|
*/
|
|
39
40
|
interface PropertyCollection<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
readonly properties: P;
|
|
42
|
+
readonly conditions: C;
|
|
43
|
+
readonly defaultCondition: keyof C | false;
|
|
44
|
+
readonly shorthands: S;
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Extract value type from PropertyValues.
|
|
@@ -49,28 +50,23 @@ type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string, unkn
|
|
|
49
50
|
/**
|
|
50
51
|
* Create a prop value type that can be a direct value or a conditional object.
|
|
51
52
|
*/
|
|
52
|
-
type PropValue<V, C extends ConditionDefinitions> = V | {
|
|
53
|
-
[K in keyof C]?: V;
|
|
54
|
-
};
|
|
53
|
+
type PropValue<V, C extends ConditionDefinitions> = V | { [K in keyof C]?: V; };
|
|
55
54
|
/**
|
|
56
55
|
* Extract prop types from a property collection.
|
|
57
56
|
*/
|
|
58
|
-
type ExtractProps<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> = {
|
|
59
|
-
[K in keyof P | keyof S]?: K extends keyof S ? PropValue<ExtractValue<P[S[K][number]]>, C> : K extends keyof P ? PropValue<ExtractValue<P[K]>, C> : never;
|
|
60
|
-
};
|
|
57
|
+
type ExtractProps<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> = { [K in keyof P | keyof S]?: K extends keyof S ? PropValue<ExtractValue<P[S[K][number]]>, C> : K extends keyof P ? PropValue<ExtractValue<P[K]>, C> : never; };
|
|
61
58
|
/**
|
|
62
59
|
* The props function signature.
|
|
63
60
|
*/
|
|
64
|
-
type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{
|
|
65
|
-
|
|
66
|
-
}[number]>) => string) & {
|
|
67
|
-
properties: Set<string>;
|
|
61
|
+
type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{ [I in keyof Collections]: Collections[I] extends PropertyCollection<infer P, infer C, infer S> ? ExtractProps<P, C, S> : never; }[number]>) => string) & {
|
|
62
|
+
properties: Set<string>;
|
|
68
63
|
};
|
|
69
64
|
/**
|
|
70
65
|
* Convert a union type to an intersection type.
|
|
71
66
|
*/
|
|
72
|
-
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
73
|
-
|
|
67
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/defineProperties.d.ts
|
|
74
70
|
/**
|
|
75
71
|
* Define a collection of CSS properties with their allowed values and optional conditions.
|
|
76
72
|
*
|
|
@@ -92,8 +88,9 @@ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) exten
|
|
|
92
88
|
* });
|
|
93
89
|
* ```
|
|
94
90
|
*/
|
|
95
|
-
declare function defineProperties<P extends PropertyDefinitions, C extends ConditionDefinitions = ConditionDefinitions, S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S>;
|
|
96
|
-
|
|
91
|
+
export declare function defineProperties<P extends PropertyDefinitions, C extends ConditionDefinitions = ConditionDefinitions, S extends ShorthandDefinitions<P> = Record<string, Array<keyof P>>>(config: DefinePropertiesConfig<P, C, S>): PropertyCollection<P, C, S>;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/createProps.d.ts
|
|
97
94
|
/**
|
|
98
95
|
* Combine property collections into a typed props function with pre-generated CSS.
|
|
99
96
|
*
|
|
@@ -110,6 +107,7 @@ declare function defineProperties<P extends PropertyDefinitions, C extends Condi
|
|
|
110
107
|
* // Returns: "atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3"
|
|
111
108
|
* ```
|
|
112
109
|
*/
|
|
113
|
-
declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
|
|
114
|
-
|
|
115
|
-
export {
|
|
110
|
+
export declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
|
|
111
|
+
//#endregion
|
|
112
|
+
export type { ConditionDefinition, ConditionDefinitions, DefinePropertiesConfig, ExtractProps, PropertyCollection, PropertyDefinitions, PropertyValues, PropsFunction, ShorthandDefinitions };
|
|
113
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/defineProperties.ts","../src/createProps.ts"],"mappings":";;;;UAGiB;EACf;EACA;EACA;EACA;EACA;;;;;KAMU,uBAAuB,eAAe;;;;KAKtC,4BAA4B;;;;KAK5B,sBAAsB,eAAe;;;;KAKrC,qBAAqB,UAAU,uBAAuB,eAAe,YAAY;;;;UAK5E,uBACf,UAAU,qBACV,UAAU,sBACV,UAAU,qBAAqB;EAE/B,YAAY;EACZ,aAAa;EACb,yBAAyB;EACzB,aAAa;;;;;UAME,mBACf,UAAU,qBACV,UAAU,sBACV,UAAU,qBAAqB;WAEtB,YAAY;WACZ,YAAY;WACZ,wBAAwB;WACxB,YAAY;;;;;KAMlB,aAAa,KAAK,iBAAiB,OACpC,IACA,UAAU,gCACF;;;;KAMP,UAAU,GAAG,UAAU,wBACxB,OAEG,WAAW,KAAK;;;;KAMX,aACV,UAAU,qBACV,UAAU,sBACV,UAAU,qBAAqB,SAE9B,WAAW,UAAU,KAAK,gBAAgB,IACvC,UAAU,aAAa,EAAE,EAAE,cAAc,KACzC,gBAAgB,IACd,UAAU,aAAa,EAAE,KAAK;;;;KAO1B,cACV,oBAAoB,mBAClB,qBACA,sBACA,qBAAqB,6BAGvB,OAAO,uBAEF,WAAW,cAAc,YAAY,WAAW,yBAAyB,SAAS,SAAS,KACxF,aAAa,GAAG,GAAG;EAK3B,YAAY;;;;;KAMT,oBAAoB,MAAM,qBAAqB,GAAG,8BACrD,SAAS,cAEP;;;;;;;;;;;;;;;;;;;;;;;;wBC1FY,iBACd,UAAU,qBACV,UAAU,uBAAuB,sBACjC,UAAU,qBAAqB,KAAK,eAAe,YAAY,KAC/D,QAAQ,uBAAuB,GAAG,GAAG,KAAK,mBAAmB,GAAG,GAAG;;;;;;;;;;;;;;;;;;;wBCNrD,YACd,oBAAoB,mBAClB,qBACA,sBACA,qBAAqB,yBAEvB,sBAAsB,aAAa,cAAc,cAAc"}
|
package/dist/index.js
CHANGED
|
@@ -1,220 +1,174 @@
|
|
|
1
|
-
import { insertRules } from
|
|
2
|
-
|
|
3
|
-
// src/defineProperties.ts
|
|
1
|
+
import { insertRules } from "typestyles";
|
|
2
|
+
//#region src/defineProperties.ts
|
|
4
3
|
function defineProperties(config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const conditions = config.conditions || {};
|
|
5
|
+
const shorthands = config.shorthands || {};
|
|
6
|
+
const defaultCondition = config.defaultCondition ?? false;
|
|
7
|
+
return {
|
|
8
|
+
properties: config.properties,
|
|
9
|
+
conditions,
|
|
10
|
+
defaultCondition,
|
|
11
|
+
shorthands
|
|
12
|
+
};
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/utils.ts
|
|
17
16
|
function sanitizeValue(value) {
|
|
18
|
-
|
|
17
|
+
return String(value).replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-_]/g, "");
|
|
19
18
|
}
|
|
20
19
|
function toKebabCase(str) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
20
|
+
if (str.startsWith("ms")) return "-" + str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
21
|
+
return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
25
22
|
}
|
|
26
23
|
function isConditionalValue(value, conditionKeys) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (const key in value) {
|
|
31
|
-
if (conditionKeys.has(key)) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
24
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
25
|
+
for (const key in value) if (conditionKeys.has(key)) return true;
|
|
26
|
+
return false;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/generate.ts
|
|
39
30
|
function generateAtomicClass(namespace, property, valueKey, cssValue, condition) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
key: `.${className}`,
|
|
80
|
-
css: `.${className} { ${declaration}; }`
|
|
81
|
-
};
|
|
31
|
+
const sanitizedValue = sanitizeValue(valueKey);
|
|
32
|
+
const className = condition ? `${namespace}-${property}-${condition.name}-${sanitizedValue}` : `${namespace}-${property}-${sanitizedValue}`;
|
|
33
|
+
const declaration = `${toKebabCase(property)}: ${cssValue}`;
|
|
34
|
+
if (!condition) return {
|
|
35
|
+
key: `.${className}`,
|
|
36
|
+
css: `.${className} { ${declaration}; }`
|
|
37
|
+
};
|
|
38
|
+
if (condition["@media"]) {
|
|
39
|
+
const mediaQuery = `@media ${condition["@media"]}`;
|
|
40
|
+
return {
|
|
41
|
+
key: `${mediaQuery}:.${className}`,
|
|
42
|
+
css: `${mediaQuery} { .${className} { ${declaration}; } }`
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (condition["@container"]) {
|
|
46
|
+
const containerQuery = `@container ${condition["@container"]}`;
|
|
47
|
+
return {
|
|
48
|
+
key: `${containerQuery}:.${className}`,
|
|
49
|
+
css: `${containerQuery} { .${className} { ${declaration}; } }`
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (condition["@supports"]) {
|
|
53
|
+
const supportsQuery = `@supports ${condition["@supports"]}`;
|
|
54
|
+
return {
|
|
55
|
+
key: `${supportsQuery}:.${className}`,
|
|
56
|
+
css: `${supportsQuery} { .${className} { ${declaration}; } }`
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (condition.selector) {
|
|
60
|
+
const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);
|
|
61
|
+
return {
|
|
62
|
+
key: wrappedSelector,
|
|
63
|
+
css: `${wrappedSelector} { ${declaration}; }`
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
key: `.${className}`,
|
|
68
|
+
css: `.${className} { ${declaration}; }`
|
|
69
|
+
};
|
|
82
70
|
}
|
|
83
71
|
function getValueEntries(values) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} else {
|
|
87
|
-
return Object.entries(values);
|
|
88
|
-
}
|
|
72
|
+
if (Array.isArray(values)) return values.map((v) => [v, v]);
|
|
73
|
+
else return Object.entries(values);
|
|
89
74
|
}
|
|
90
75
|
function generateAllAtomicClasses(namespace, properties, conditions, defaultCondition) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
generateAtomicClass(namespace, property, valueKey, cssValue, {
|
|
114
|
-
...condDef,
|
|
115
|
-
name: condName
|
|
116
|
-
})
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return rules;
|
|
76
|
+
const rules = [];
|
|
77
|
+
for (const [property, values] of Object.entries(properties)) {
|
|
78
|
+
const valueEntries = getValueEntries(values);
|
|
79
|
+
for (const [valueKey, cssValue] of valueEntries) {
|
|
80
|
+
if (defaultCondition === false) rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));
|
|
81
|
+
else {
|
|
82
|
+
const condition = conditions[defaultCondition];
|
|
83
|
+
if (condition) rules.push(generateAtomicClass(namespace, property, valueKey, cssValue, {
|
|
84
|
+
...condition,
|
|
85
|
+
name: defaultCondition
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
for (const [condName, condDef] of Object.entries(conditions)) {
|
|
89
|
+
if (defaultCondition !== false && condName === defaultCondition) continue;
|
|
90
|
+
rules.push(generateAtomicClass(namespace, property, valueKey, cssValue, {
|
|
91
|
+
...condDef,
|
|
92
|
+
name: condName
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return rules;
|
|
122
98
|
}
|
|
123
99
|
function generateFromCollections(namespace, collections) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
collection.defaultCondition
|
|
131
|
-
);
|
|
132
|
-
allRules.push(...rules);
|
|
133
|
-
}
|
|
134
|
-
return allRules;
|
|
100
|
+
const allRules = [];
|
|
101
|
+
for (const collection of collections) {
|
|
102
|
+
const rules = generateAllAtomicClasses(namespace, collection.properties, collection.conditions, collection.defaultCondition);
|
|
103
|
+
allRules.push(...rules);
|
|
104
|
+
}
|
|
105
|
+
return allRules;
|
|
135
106
|
}
|
|
136
|
-
|
|
137
|
-
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/runtime.ts
|
|
138
109
|
function buildLookupMap(_namespace, collections) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
shorthands.set(shorthand, props);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return { propertyMap, conditionKeys, shorthands };
|
|
110
|
+
const propertyMap = new Map();
|
|
111
|
+
const conditionKeys = new Set();
|
|
112
|
+
const shorthands = new Map();
|
|
113
|
+
for (const collection of collections) {
|
|
114
|
+
for (const property of Object.keys(collection.properties)) if (!propertyMap.has(property)) propertyMap.set(property, new Set());
|
|
115
|
+
for (const condition of Object.keys(collection.conditions)) conditionKeys.add(condition);
|
|
116
|
+
for (const [shorthand, props] of Object.entries(collection.shorthands)) shorthands.set(shorthand, props);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
propertyMap,
|
|
120
|
+
conditionKeys,
|
|
121
|
+
shorthands
|
|
122
|
+
};
|
|
156
123
|
}
|
|
157
124
|
function expandShorthands(props, shorthands) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
expanded[key] = value;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return expanded;
|
|
125
|
+
const expanded = {};
|
|
126
|
+
for (const [key, value] of Object.entries(props)) if (shorthands.has(key)) {
|
|
127
|
+
const properties = shorthands.get(key);
|
|
128
|
+
for (const prop of properties) expanded[prop] = value;
|
|
129
|
+
} else expanded[key] = value;
|
|
130
|
+
return expanded;
|
|
170
131
|
}
|
|
171
132
|
function resolveValue(namespace, property, value, conditionKeys) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
return classNames;
|
|
133
|
+
const classNames = [];
|
|
134
|
+
if (isConditionalValue(value, conditionKeys)) {
|
|
135
|
+
for (const [condition, condValue] of Object.entries(value)) if (conditionKeys.has(condition)) {
|
|
136
|
+
const sanitized = sanitizeValue(String(condValue));
|
|
137
|
+
classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
const sanitized = sanitizeValue(String(value));
|
|
141
|
+
classNames.push(`${namespace}-${property}-${sanitized}`);
|
|
142
|
+
}
|
|
143
|
+
return classNames;
|
|
185
144
|
}
|
|
186
145
|
function createResolver(namespace, _propertyMap, conditionKeys, shorthands) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
146
|
+
return (props) => {
|
|
147
|
+
const expanded = expandShorthands(props, shorthands);
|
|
148
|
+
const classNames = [];
|
|
149
|
+
for (const [property, value] of Object.entries(expanded)) {
|
|
150
|
+
if (value == null) continue;
|
|
151
|
+
const resolved = resolveValue(namespace, property, value, conditionKeys);
|
|
152
|
+
classNames.push(...resolved);
|
|
153
|
+
}
|
|
154
|
+
return classNames.join(" ");
|
|
155
|
+
};
|
|
197
156
|
}
|
|
198
|
-
|
|
199
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/createProps.ts
|
|
200
159
|
function createProps(namespace, ...collections) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
properties.add(shorthand);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
const propsFunction = Object.assign(resolver, { properties });
|
|
215
|
-
return propsFunction;
|
|
160
|
+
const cssRules = generateFromCollections(namespace, collections);
|
|
161
|
+
insertRules(cssRules);
|
|
162
|
+
const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);
|
|
163
|
+
const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);
|
|
164
|
+
const properties = new Set();
|
|
165
|
+
for (const collection of collections) {
|
|
166
|
+
for (const prop of Object.keys(collection.properties)) properties.add(prop);
|
|
167
|
+
for (const shorthand of Object.keys(collection.shorthands)) properties.add(shorthand);
|
|
168
|
+
}
|
|
169
|
+
return Object.assign(resolver, { properties });
|
|
216
170
|
}
|
|
217
|
-
|
|
171
|
+
//#endregion
|
|
218
172
|
export { createProps, defineProperties };
|
|
219
|
-
|
|
173
|
+
|
|
220
174
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,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AAQ,QAAQ,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,EAAA,WAAA,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.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"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"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"],"mappings":";;AA6BA,SAA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typestyles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,24 +22,22 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"typestyles": "0.32.
|
|
25
|
+
"typestyles": "0.32.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"vitest": "^3.0.0"
|
|
28
|
+
"typescript": "^6.0.0",
|
|
29
|
+
"vitest": "5.0.5",
|
|
30
|
+
"vite-plus": "1.3.0"
|
|
32
31
|
},
|
|
33
32
|
"license": "Apache-2.0",
|
|
34
33
|
"repository": {
|
|
35
34
|
"type": "git",
|
|
36
|
-
"url": "https://github.com/
|
|
35
|
+
"url": "https://github.com/phthalo-dev/typestyles",
|
|
37
36
|
"directory": "packages/props"
|
|
38
37
|
},
|
|
39
38
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"test": "
|
|
42
|
-
"lint": "eslint .",
|
|
39
|
+
"build": "vp pack",
|
|
40
|
+
"test": "vp test run",
|
|
43
41
|
"typecheck": "tsc --noEmit"
|
|
44
42
|
}
|
|
45
43
|
}
|