@typestyles/props 0.0.0-unstable.5b7138167233

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/dist/index.cjs ADDED
@@ -0,0 +1,223 @@
1
+ 'use strict';
2
+
3
+ var typestyles = require('typestyles');
4
+
5
+ // src/defineProperties.ts
6
+ function defineProperties(config) {
7
+ const conditions = config.conditions || {};
8
+ const shorthands = config.shorthands || {};
9
+ const defaultCondition = config.defaultCondition ?? false;
10
+ return {
11
+ properties: config.properties,
12
+ conditions,
13
+ defaultCondition,
14
+ shorthands
15
+ };
16
+ }
17
+
18
+ // src/utils.ts
19
+ function sanitizeValue(value) {
20
+ return String(value).replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-_]/g, "");
21
+ }
22
+ function toKebabCase(str) {
23
+ if (str.startsWith("ms")) {
24
+ return "-" + str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
25
+ }
26
+ return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
27
+ }
28
+ function isConditionalValue(value, conditionKeys) {
29
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
30
+ return false;
31
+ }
32
+ for (const key in value) {
33
+ if (conditionKeys.has(key)) {
34
+ return true;
35
+ }
36
+ }
37
+ return false;
38
+ }
39
+
40
+ // src/generate.ts
41
+ function generateAtomicClass(namespace, property, valueKey, cssValue, condition) {
42
+ const sanitizedValue = sanitizeValue(valueKey);
43
+ const className = condition ? `${namespace}-${property}-${condition.name}-${sanitizedValue}` : `${namespace}-${property}-${sanitizedValue}`;
44
+ const kebabProp = toKebabCase(property);
45
+ const declaration = `${kebabProp}: ${cssValue}`;
46
+ if (!condition) {
47
+ return {
48
+ key: `.${className}`,
49
+ css: `.${className} { ${declaration}; }`
50
+ };
51
+ }
52
+ if (condition["@media"]) {
53
+ const mediaQuery = `@media ${condition["@media"]}`;
54
+ return {
55
+ key: `${mediaQuery}:.${className}`,
56
+ css: `${mediaQuery} { .${className} { ${declaration}; } }`
57
+ };
58
+ }
59
+ if (condition["@container"]) {
60
+ const containerQuery = `@container ${condition["@container"]}`;
61
+ return {
62
+ key: `${containerQuery}:.${className}`,
63
+ css: `${containerQuery} { .${className} { ${declaration}; } }`
64
+ };
65
+ }
66
+ if (condition["@supports"]) {
67
+ const supportsQuery = `@supports ${condition["@supports"]}`;
68
+ return {
69
+ key: `${supportsQuery}:.${className}`,
70
+ css: `${supportsQuery} { .${className} { ${declaration}; } }`
71
+ };
72
+ }
73
+ if (condition.selector) {
74
+ const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);
75
+ return {
76
+ key: wrappedSelector,
77
+ css: `${wrappedSelector} { ${declaration}; }`
78
+ };
79
+ }
80
+ return {
81
+ key: `.${className}`,
82
+ css: `.${className} { ${declaration}; }`
83
+ };
84
+ }
85
+ function getValueEntries(values) {
86
+ if (Array.isArray(values)) {
87
+ return values.map((v) => [v, v]);
88
+ } else {
89
+ return Object.entries(values);
90
+ }
91
+ }
92
+ function generateAllAtomicClasses(namespace, properties, conditions, defaultCondition) {
93
+ const rules = [];
94
+ for (const [property, values] of Object.entries(properties)) {
95
+ const valueEntries = getValueEntries(values);
96
+ for (const [valueKey, cssValue] of valueEntries) {
97
+ if (defaultCondition === false) {
98
+ rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));
99
+ } else {
100
+ const condition = conditions[defaultCondition];
101
+ if (condition) {
102
+ rules.push(
103
+ generateAtomicClass(namespace, property, valueKey, cssValue, {
104
+ ...condition,
105
+ name: defaultCondition
106
+ })
107
+ );
108
+ }
109
+ }
110
+ for (const [condName, condDef] of Object.entries(conditions)) {
111
+ if (defaultCondition !== false && condName === defaultCondition) {
112
+ continue;
113
+ }
114
+ rules.push(
115
+ generateAtomicClass(namespace, property, valueKey, cssValue, {
116
+ ...condDef,
117
+ name: condName
118
+ })
119
+ );
120
+ }
121
+ }
122
+ }
123
+ return rules;
124
+ }
125
+ function generateFromCollections(namespace, collections) {
126
+ const allRules = [];
127
+ for (const collection of collections) {
128
+ const rules = generateAllAtomicClasses(
129
+ namespace,
130
+ collection.properties,
131
+ collection.conditions,
132
+ collection.defaultCondition
133
+ );
134
+ allRules.push(...rules);
135
+ }
136
+ return allRules;
137
+ }
138
+
139
+ // src/runtime.ts
140
+ function buildLookupMap(_namespace, collections) {
141
+ const propertyMap = /* @__PURE__ */ new Map();
142
+ const conditionKeys = /* @__PURE__ */ new Set();
143
+ const shorthands = /* @__PURE__ */ new Map();
144
+ for (const collection of collections) {
145
+ for (const property of Object.keys(collection.properties)) {
146
+ if (!propertyMap.has(property)) {
147
+ propertyMap.set(property, /* @__PURE__ */ new Set());
148
+ }
149
+ }
150
+ for (const condition of Object.keys(collection.conditions)) {
151
+ conditionKeys.add(condition);
152
+ }
153
+ for (const [shorthand, props] of Object.entries(collection.shorthands)) {
154
+ shorthands.set(shorthand, props);
155
+ }
156
+ }
157
+ return { propertyMap, conditionKeys, shorthands };
158
+ }
159
+ function expandShorthands(props, shorthands) {
160
+ const expanded = {};
161
+ for (const [key, value] of Object.entries(props)) {
162
+ if (shorthands.has(key)) {
163
+ const properties = shorthands.get(key);
164
+ for (const prop of properties) {
165
+ expanded[prop] = value;
166
+ }
167
+ } else {
168
+ expanded[key] = value;
169
+ }
170
+ }
171
+ return expanded;
172
+ }
173
+ function resolveValue(namespace, property, value, conditionKeys) {
174
+ const classNames = [];
175
+ if (isConditionalValue(value, conditionKeys)) {
176
+ for (const [condition, condValue] of Object.entries(value)) {
177
+ if (conditionKeys.has(condition)) {
178
+ const sanitized = sanitizeValue(String(condValue));
179
+ classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);
180
+ }
181
+ }
182
+ } else {
183
+ const sanitized = sanitizeValue(String(value));
184
+ classNames.push(`${namespace}-${property}-${sanitized}`);
185
+ }
186
+ return classNames;
187
+ }
188
+ function createResolver(namespace, _propertyMap, conditionKeys, shorthands) {
189
+ return (props) => {
190
+ const expanded = expandShorthands(props, shorthands);
191
+ const classNames = [];
192
+ for (const [property, value] of Object.entries(expanded)) {
193
+ if (value == null) continue;
194
+ const resolved = resolveValue(namespace, property, value, conditionKeys);
195
+ classNames.push(...resolved);
196
+ }
197
+ return classNames.join(" ");
198
+ };
199
+ }
200
+
201
+ // src/createProps.ts
202
+ function createProps(namespace, ...collections) {
203
+ const cssRules = generateFromCollections(namespace, collections);
204
+ typestyles.insertRules(cssRules);
205
+ const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);
206
+ const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);
207
+ const properties = /* @__PURE__ */ new Set();
208
+ for (const collection of collections) {
209
+ for (const prop of Object.keys(collection.properties)) {
210
+ properties.add(prop);
211
+ }
212
+ for (const shorthand of Object.keys(collection.shorthands)) {
213
+ properties.add(shorthand);
214
+ }
215
+ }
216
+ const propsFunction = Object.assign(resolver, { properties });
217
+ return propsFunction;
218
+ }
219
+
220
+ exports.createProps = createProps;
221
+ exports.defineProperties = defineProperties;
222
+ //# sourceMappingURL=index.cjs.map
223
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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,O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K,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.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"]}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * A single condition definition (e.g., media query, selector, container query).
3
+ */
4
+ interface ConditionDefinition {
5
+ name?: string;
6
+ '@media'?: string;
7
+ '@container'?: string;
8
+ '@supports'?: string;
9
+ selector?: string;
10
+ }
11
+ /**
12
+ * A map of condition names to their definitions.
13
+ */
14
+ type ConditionDefinitions = Record<string, ConditionDefinition>;
15
+ /**
16
+ * Property value definitions - either an array of strings or a map of keys to CSS values.
17
+ */
18
+ type PropertyValues = string[] | Record<string, string | number>;
19
+ /**
20
+ * A map of CSS property names to their allowed values.
21
+ */
22
+ type PropertyDefinitions = Record<string, PropertyValues>;
23
+ /**
24
+ * Shorthand definitions - map shorthand names to arrays of property names.
25
+ */
26
+ type ShorthandDefinitions<P extends PropertyDefinitions> = Record<string, Array<keyof P>>;
27
+ /**
28
+ * The configuration object passed to defineProperties().
29
+ */
30
+ interface DefinePropertiesConfig<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
31
+ properties: P;
32
+ conditions?: C;
33
+ defaultCondition?: keyof C | false;
34
+ shorthands?: S;
35
+ }
36
+ /**
37
+ * A property collection returned by defineProperties().
38
+ */
39
+ interface PropertyCollection<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
40
+ readonly properties: P;
41
+ readonly conditions: C;
42
+ readonly defaultCondition: keyof C | false;
43
+ readonly shorthands: S;
44
+ }
45
+ /**
46
+ * Extract value type from PropertyValues.
47
+ */
48
+ type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string, unknown> ? keyof T : never;
49
+ /**
50
+ * Create a prop value type that can be a direct value or a conditional object.
51
+ */
52
+ type PropValue<V, C extends ConditionDefinitions> = V | {
53
+ [K in keyof C]?: V;
54
+ };
55
+ /**
56
+ * Extract prop types from a property collection.
57
+ */
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
+ };
61
+ /**
62
+ * The props function signature.
63
+ */
64
+ type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{
65
+ [I in keyof Collections]: Collections[I] extends PropertyCollection<infer P, infer C, infer S> ? ExtractProps<P, C, S> : never;
66
+ }[number]>) => string) & {
67
+ properties: Set<string>;
68
+ };
69
+ /**
70
+ * Convert a union type to an intersection type.
71
+ */
72
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
73
+
74
+ /**
75
+ * Define a collection of CSS properties with their allowed values and optional conditions.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const responsiveProps = defineProperties({
80
+ * conditions: {
81
+ * mobile: { '@media': '(min-width: 768px)' },
82
+ * desktop: { '@media': '(min-width: 1024px)' },
83
+ * },
84
+ * defaultCondition: false,
85
+ * properties: {
86
+ * display: ['flex', 'block', 'grid', 'none'],
87
+ * paddingTop: { 0: '0', 1: '4px', 2: '8px', 3: '16px' },
88
+ * },
89
+ * shorthands: {
90
+ * padding: ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],
91
+ * },
92
+ * });
93
+ * ```
94
+ */
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
+
97
+ /**
98
+ * Combine property collections into a typed props function with pre-generated CSS.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const props = createProps('atoms', responsiveProps, colorProps);
103
+ *
104
+ * // Type-safe usage
105
+ * props({
106
+ * display: 'flex',
107
+ * padding: 2,
108
+ * paddingTop: { mobile: 3 },
109
+ * });
110
+ * // Returns: "atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3"
111
+ * ```
112
+ */
113
+ declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
114
+
115
+ export { type ConditionDefinition, type ConditionDefinitions, type DefinePropertiesConfig, type ExtractProps, type PropertyCollection, type PropertyDefinitions, type PropertyValues, type PropsFunction, type ShorthandDefinitions, createProps, defineProperties };
@@ -0,0 +1,115 @@
1
+ /**
2
+ * A single condition definition (e.g., media query, selector, container query).
3
+ */
4
+ interface ConditionDefinition {
5
+ name?: string;
6
+ '@media'?: string;
7
+ '@container'?: string;
8
+ '@supports'?: string;
9
+ selector?: string;
10
+ }
11
+ /**
12
+ * A map of condition names to their definitions.
13
+ */
14
+ type ConditionDefinitions = Record<string, ConditionDefinition>;
15
+ /**
16
+ * Property value definitions - either an array of strings or a map of keys to CSS values.
17
+ */
18
+ type PropertyValues = string[] | Record<string, string | number>;
19
+ /**
20
+ * A map of CSS property names to their allowed values.
21
+ */
22
+ type PropertyDefinitions = Record<string, PropertyValues>;
23
+ /**
24
+ * Shorthand definitions - map shorthand names to arrays of property names.
25
+ */
26
+ type ShorthandDefinitions<P extends PropertyDefinitions> = Record<string, Array<keyof P>>;
27
+ /**
28
+ * The configuration object passed to defineProperties().
29
+ */
30
+ interface DefinePropertiesConfig<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
31
+ properties: P;
32
+ conditions?: C;
33
+ defaultCondition?: keyof C | false;
34
+ shorthands?: S;
35
+ }
36
+ /**
37
+ * A property collection returned by defineProperties().
38
+ */
39
+ interface PropertyCollection<P extends PropertyDefinitions, C extends ConditionDefinitions, S extends ShorthandDefinitions<P>> {
40
+ readonly properties: P;
41
+ readonly conditions: C;
42
+ readonly defaultCondition: keyof C | false;
43
+ readonly shorthands: S;
44
+ }
45
+ /**
46
+ * Extract value type from PropertyValues.
47
+ */
48
+ type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string, unknown> ? keyof T : never;
49
+ /**
50
+ * Create a prop value type that can be a direct value or a conditional object.
51
+ */
52
+ type PropValue<V, C extends ConditionDefinitions> = V | {
53
+ [K in keyof C]?: V;
54
+ };
55
+ /**
56
+ * Extract prop types from a property collection.
57
+ */
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
+ };
61
+ /**
62
+ * The props function signature.
63
+ */
64
+ type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{
65
+ [I in keyof Collections]: Collections[I] extends PropertyCollection<infer P, infer C, infer S> ? ExtractProps<P, C, S> : never;
66
+ }[number]>) => string) & {
67
+ properties: Set<string>;
68
+ };
69
+ /**
70
+ * Convert a union type to an intersection type.
71
+ */
72
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
73
+
74
+ /**
75
+ * Define a collection of CSS properties with their allowed values and optional conditions.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const responsiveProps = defineProperties({
80
+ * conditions: {
81
+ * mobile: { '@media': '(min-width: 768px)' },
82
+ * desktop: { '@media': '(min-width: 1024px)' },
83
+ * },
84
+ * defaultCondition: false,
85
+ * properties: {
86
+ * display: ['flex', 'block', 'grid', 'none'],
87
+ * paddingTop: { 0: '0', 1: '4px', 2: '8px', 3: '16px' },
88
+ * },
89
+ * shorthands: {
90
+ * padding: ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],
91
+ * },
92
+ * });
93
+ * ```
94
+ */
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
+
97
+ /**
98
+ * Combine property collections into a typed props function with pre-generated CSS.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const props = createProps('atoms', responsiveProps, colorProps);
103
+ *
104
+ * // Type-safe usage
105
+ * props({
106
+ * display: 'flex',
107
+ * padding: 2,
108
+ * paddingTop: { mobile: 3 },
109
+ * });
110
+ * // Returns: "atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3"
111
+ * ```
112
+ */
113
+ declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
114
+
115
+ export { type ConditionDefinition, type ConditionDefinitions, type DefinePropertiesConfig, type ExtractProps, type PropertyCollection, type PropertyDefinitions, type PropertyValues, type PropsFunction, type ShorthandDefinitions, createProps, defineProperties };
package/dist/index.js ADDED
@@ -0,0 +1,220 @@
1
+ import { insertRules } from 'typestyles';
2
+
3
+ // src/defineProperties.ts
4
+ function defineProperties(config) {
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
+ };
14
+ }
15
+
16
+ // src/utils.ts
17
+ function sanitizeValue(value) {
18
+ return String(value).replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-_]/g, "");
19
+ }
20
+ function toKebabCase(str) {
21
+ if (str.startsWith("ms")) {
22
+ return "-" + str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
23
+ }
24
+ return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
25
+ }
26
+ function isConditionalValue(value, conditionKeys) {
27
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
28
+ return false;
29
+ }
30
+ for (const key in value) {
31
+ if (conditionKeys.has(key)) {
32
+ return true;
33
+ }
34
+ }
35
+ return false;
36
+ }
37
+
38
+ // src/generate.ts
39
+ function generateAtomicClass(namespace, property, valueKey, cssValue, condition) {
40
+ const sanitizedValue = sanitizeValue(valueKey);
41
+ const className = condition ? `${namespace}-${property}-${condition.name}-${sanitizedValue}` : `${namespace}-${property}-${sanitizedValue}`;
42
+ const kebabProp = toKebabCase(property);
43
+ const declaration = `${kebabProp}: ${cssValue}`;
44
+ if (!condition) {
45
+ return {
46
+ key: `.${className}`,
47
+ css: `.${className} { ${declaration}; }`
48
+ };
49
+ }
50
+ if (condition["@media"]) {
51
+ const mediaQuery = `@media ${condition["@media"]}`;
52
+ return {
53
+ key: `${mediaQuery}:.${className}`,
54
+ css: `${mediaQuery} { .${className} { ${declaration}; } }`
55
+ };
56
+ }
57
+ if (condition["@container"]) {
58
+ const containerQuery = `@container ${condition["@container"]}`;
59
+ return {
60
+ key: `${containerQuery}:.${className}`,
61
+ css: `${containerQuery} { .${className} { ${declaration}; } }`
62
+ };
63
+ }
64
+ if (condition["@supports"]) {
65
+ const supportsQuery = `@supports ${condition["@supports"]}`;
66
+ return {
67
+ key: `${supportsQuery}:.${className}`,
68
+ css: `${supportsQuery} { .${className} { ${declaration}; } }`
69
+ };
70
+ }
71
+ if (condition.selector) {
72
+ const wrappedSelector = condition.selector.replace(/&/g, `.${className}`);
73
+ return {
74
+ key: wrappedSelector,
75
+ css: `${wrappedSelector} { ${declaration}; }`
76
+ };
77
+ }
78
+ return {
79
+ key: `.${className}`,
80
+ css: `.${className} { ${declaration}; }`
81
+ };
82
+ }
83
+ function getValueEntries(values) {
84
+ if (Array.isArray(values)) {
85
+ return values.map((v) => [v, v]);
86
+ } else {
87
+ return Object.entries(values);
88
+ }
89
+ }
90
+ function generateAllAtomicClasses(namespace, properties, conditions, defaultCondition) {
91
+ const rules = [];
92
+ for (const [property, values] of Object.entries(properties)) {
93
+ const valueEntries = getValueEntries(values);
94
+ for (const [valueKey, cssValue] of valueEntries) {
95
+ if (defaultCondition === false) {
96
+ rules.push(generateAtomicClass(namespace, property, valueKey, cssValue));
97
+ } else {
98
+ const condition = conditions[defaultCondition];
99
+ if (condition) {
100
+ rules.push(
101
+ generateAtomicClass(namespace, property, valueKey, cssValue, {
102
+ ...condition,
103
+ name: defaultCondition
104
+ })
105
+ );
106
+ }
107
+ }
108
+ for (const [condName, condDef] of Object.entries(conditions)) {
109
+ if (defaultCondition !== false && condName === defaultCondition) {
110
+ continue;
111
+ }
112
+ rules.push(
113
+ generateAtomicClass(namespace, property, valueKey, cssValue, {
114
+ ...condDef,
115
+ name: condName
116
+ })
117
+ );
118
+ }
119
+ }
120
+ }
121
+ return rules;
122
+ }
123
+ function generateFromCollections(namespace, collections) {
124
+ const allRules = [];
125
+ for (const collection of collections) {
126
+ const rules = generateAllAtomicClasses(
127
+ namespace,
128
+ collection.properties,
129
+ collection.conditions,
130
+ collection.defaultCondition
131
+ );
132
+ allRules.push(...rules);
133
+ }
134
+ return allRules;
135
+ }
136
+
137
+ // src/runtime.ts
138
+ function buildLookupMap(_namespace, collections) {
139
+ const propertyMap = /* @__PURE__ */ new Map();
140
+ const conditionKeys = /* @__PURE__ */ new Set();
141
+ const shorthands = /* @__PURE__ */ new Map();
142
+ for (const collection of collections) {
143
+ for (const property of Object.keys(collection.properties)) {
144
+ if (!propertyMap.has(property)) {
145
+ propertyMap.set(property, /* @__PURE__ */ new Set());
146
+ }
147
+ }
148
+ for (const condition of Object.keys(collection.conditions)) {
149
+ conditionKeys.add(condition);
150
+ }
151
+ for (const [shorthand, props] of Object.entries(collection.shorthands)) {
152
+ shorthands.set(shorthand, props);
153
+ }
154
+ }
155
+ return { propertyMap, conditionKeys, shorthands };
156
+ }
157
+ function expandShorthands(props, shorthands) {
158
+ const expanded = {};
159
+ for (const [key, value] of Object.entries(props)) {
160
+ if (shorthands.has(key)) {
161
+ const properties = shorthands.get(key);
162
+ for (const prop of properties) {
163
+ expanded[prop] = value;
164
+ }
165
+ } else {
166
+ expanded[key] = value;
167
+ }
168
+ }
169
+ return expanded;
170
+ }
171
+ function resolveValue(namespace, property, value, conditionKeys) {
172
+ const classNames = [];
173
+ if (isConditionalValue(value, conditionKeys)) {
174
+ for (const [condition, condValue] of Object.entries(value)) {
175
+ if (conditionKeys.has(condition)) {
176
+ const sanitized = sanitizeValue(String(condValue));
177
+ classNames.push(`${namespace}-${property}-${condition}-${sanitized}`);
178
+ }
179
+ }
180
+ } else {
181
+ const sanitized = sanitizeValue(String(value));
182
+ classNames.push(`${namespace}-${property}-${sanitized}`);
183
+ }
184
+ return classNames;
185
+ }
186
+ function createResolver(namespace, _propertyMap, conditionKeys, shorthands) {
187
+ return (props) => {
188
+ const expanded = expandShorthands(props, shorthands);
189
+ const classNames = [];
190
+ for (const [property, value] of Object.entries(expanded)) {
191
+ if (value == null) continue;
192
+ const resolved = resolveValue(namespace, property, value, conditionKeys);
193
+ classNames.push(...resolved);
194
+ }
195
+ return classNames.join(" ");
196
+ };
197
+ }
198
+
199
+ // src/createProps.ts
200
+ function createProps(namespace, ...collections) {
201
+ const cssRules = generateFromCollections(namespace, collections);
202
+ insertRules(cssRules);
203
+ const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);
204
+ const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);
205
+ const properties = /* @__PURE__ */ new Set();
206
+ for (const collection of collections) {
207
+ for (const prop of Object.keys(collection.properties)) {
208
+ properties.add(prop);
209
+ }
210
+ for (const shorthand of Object.keys(collection.shorthands)) {
211
+ properties.add(shorthand);
212
+ }
213
+ }
214
+ const propsFunction = Object.assign(resolver, { properties });
215
+ return propsFunction;
216
+ }
217
+
218
+ export { createProps, defineProperties };
219
+ //# sourceMappingURL=index.js.map
220
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,IACnB,UAAA;AAAA,IACA,gBA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ACxD,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.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"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@typestyles/props",
3
+ "version": "0.0.0-unstable.5b7138167233",
4
+ "description": "Type-safe atomic CSS utility generator for typestyles",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "typestyles": "0.0.0-unstable.5b7138167233"
26
+ },
27
+ "devDependencies": {
28
+ "tsup": "^8.0.0",
29
+ "typescript": "^5.9.3",
30
+ "vitest": "^3.0.0"
31
+ },
32
+ "license": "Apache-2.0",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/dbanksdesign/typestyles",
36
+ "directory": "packages/props"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "test": "vitest run",
41
+ "typecheck": "tsc --noEmit"
42
+ }
43
+ }