@typestyles/props 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -137,7 +137,7 @@ function generateFromCollections(namespace, collections) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// src/runtime.ts
|
|
140
|
-
function buildLookupMap(
|
|
140
|
+
function buildLookupMap(_namespace, collections) {
|
|
141
141
|
const propertyMap = /* @__PURE__ */ new Map();
|
|
142
142
|
const conditionKeys = /* @__PURE__ */ new Set();
|
|
143
143
|
const shorthands = /* @__PURE__ */ new Map();
|
|
@@ -185,7 +185,7 @@ function resolveValue(namespace, property, value, conditionKeys) {
|
|
|
185
185
|
}
|
|
186
186
|
return classNames;
|
|
187
187
|
}
|
|
188
|
-
function createResolver(namespace,
|
|
188
|
+
function createResolver(namespace, _propertyMap, conditionKeys, shorthands) {
|
|
189
189
|
return (props) => {
|
|
190
190
|
const expanded = expandShorthands(props, shorthands);
|
|
191
191
|
const classNames = [];
|
|
@@ -202,10 +202,7 @@ function createResolver(namespace, propertyMap, conditionKeys, shorthands) {
|
|
|
202
202
|
function createProps(namespace, ...collections) {
|
|
203
203
|
const cssRules = generateFromCollections(namespace, collections);
|
|
204
204
|
typestyles.insertRules(cssRules);
|
|
205
|
-
const { propertyMap, conditionKeys, shorthands } = buildLookupMap(
|
|
206
|
-
namespace,
|
|
207
|
-
collections
|
|
208
|
-
);
|
|
205
|
+
const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);
|
|
209
206
|
const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);
|
|
210
207
|
const properties = /* @__PURE__ */ new Set();
|
|
211
208
|
for (const collection of collections) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"names":["insertRules"],"mappings":";;;;;AA6BO,SAAS,iBAKd,MAAA,EAC6B;AAC7B,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;;;AC1CO,SAAS,cAAc,KAAA,EAAgC;AAC5D,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAChB,OAAA,CAAQ,QAAQ,GAAG,CAAA,CACnB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAClC;AAKO,SAAS,YAAY,GAAA,EAAqB;AAE/C,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACxB,IAAA,OAAO,GAAA,GAAM,IAAI,OAAA,CAAQ,QAAA,EAAU,CAAC,CAAA,KAAM,GAAA,GAAM,CAAA,CAAE,WAAA,EAAa,CAAA;AAAA,EACjE;AACA,EAAA,OAAO,GAAA,CAAI,QAAQ,QAAA,EAAU,CAAC,MAAM,GAAA,GAAM,CAAA,CAAE,aAAa,CAAA;AAC3D;AAKO,SAAS,kBAAA,CACd,OACA,aAAA,EAC8B;AAC9B,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACvE,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,KAAA,MAAW,OAAO,KAAA,EAAO;AACvB,IAAA,IAAI,aAAA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U,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 = {},\n S extends ShorthandDefinitions<P> = {}\n>(\n config: DefinePropertiesConfig<P, C, S>\n): 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: any,\n conditionKeys: Set<string>\n): value is Record<string, any> {\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} 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<any, any, any>[]\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, any>,\n shorthands: Map<string, string[]>\n): Record<string, any> {\n const expanded: Record<string, any> = {};\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: any,\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, any>) => string {\n return (props: Record<string, any>): 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 { PropertyCollection, PropsFunction } 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<Collections extends PropertyCollection<any, any, any>[]>(\n namespace: string,\n ...collections: Collections\n): 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(\n namespace,\n collections\n );\n\n // Create resolver function\n const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);\n\n // Create properties set for inspection\n const properties = new Set<string>();\n for (const collection of collections) {\n for (const prop of Object.keys(collection.properties)) {\n properties.add(prop);\n }\n for (const shorthand of Object.keys(collection.shorthands)) {\n properties.add(shorthand);\n }\n }\n\n // Attach properties to the function\n const propsFunction = Object.assign(resolver, { properties });\n\n return propsFunction as PropsFunction<Collections>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"names":["insertRules"],"mappings":";;;;;AA6BO,SAAS,iBAId,MAAA,EAAsE;AACtE,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,gBAAA,GAAmB,OAAO,gBAAA,IAAoB,KAAA;AAEpD,EAAA,OAAO;AAAA,IACL,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,UAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF;AACF;;;ACxCO,SAAS,cAAc,KAAA,EAAgC;AAC5D,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAChB,OAAA,CAAQ,QAAQ,GAAG,CAAA,CACnB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAClC;AAKO,SAAS,YAAY,GAAA,EAAqB;AAE/C,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACxB,IAAA,OAAO,GAAA,GAAM,IAAI,OAAA,CAAQ,QAAA,EAAU,CAAC,CAAA,KAAM,GAAA,GAAM,CAAA,CAAE,WAAA,EAAa,CAAA;AAAA,EACjE;AACA,EAAA,OAAO,GAAA,CAAI,QAAQ,QAAA,EAAU,CAAC,MAAM,GAAA,GAAM,CAAA,CAAE,aAAa,CAAA;AAC3D;AAKO,SAAS,kBAAA,CACd,OACA,aAAA,EACkC;AAClC,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACvE,IA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a;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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -45,7 +45,7 @@ interface PropertyCollection<P extends PropertyDefinitions, C extends ConditionD
|
|
|
45
45
|
/**
|
|
46
46
|
* Extract value type from PropertyValues.
|
|
47
47
|
*/
|
|
48
|
-
type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string,
|
|
48
|
+
type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string, unknown> ? keyof T : never;
|
|
49
49
|
/**
|
|
50
50
|
* Create a prop value type that can be a direct value or a conditional object.
|
|
51
51
|
*/
|
|
@@ -61,7 +61,7 @@ type ExtractProps<P extends PropertyDefinitions, C extends ConditionDefinitions,
|
|
|
61
61
|
/**
|
|
62
62
|
* The props function signature.
|
|
63
63
|
*/
|
|
64
|
-
type PropsFunction<Collections extends PropertyCollection<
|
|
64
|
+
type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{
|
|
65
65
|
[I in keyof Collections]: Collections[I] extends PropertyCollection<infer P, infer C, infer S> ? ExtractProps<P, C, S> : never;
|
|
66
66
|
}[number]>) => string) & {
|
|
67
67
|
properties: Set<string>;
|
|
@@ -69,7 +69,7 @@ type PropsFunction<Collections extends PropertyCollection<any, any, any>[]> = ((
|
|
|
69
69
|
/**
|
|
70
70
|
* Convert a union type to an intersection type.
|
|
71
71
|
*/
|
|
72
|
-
type UnionToIntersection<U> = (U extends
|
|
72
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Define a collection of CSS properties with their allowed values and optional conditions.
|
|
@@ -92,7 +92,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
92
92
|
* });
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
|
-
declare function defineProperties<P extends PropertyDefinitions, C extends ConditionDefinitions =
|
|
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
96
|
|
|
97
97
|
/**
|
|
98
98
|
* Combine property collections into a typed props function with pre-generated CSS.
|
|
@@ -110,6 +110,6 @@ declare function defineProperties<P extends PropertyDefinitions, C extends Condi
|
|
|
110
110
|
* // Returns: "atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3"
|
|
111
111
|
* ```
|
|
112
112
|
*/
|
|
113
|
-
declare function createProps<Collections extends PropertyCollection<
|
|
113
|
+
declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
|
|
114
114
|
|
|
115
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.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ interface PropertyCollection<P extends PropertyDefinitions, C extends ConditionD
|
|
|
45
45
|
/**
|
|
46
46
|
* Extract value type from PropertyValues.
|
|
47
47
|
*/
|
|
48
|
-
type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string,
|
|
48
|
+
type ExtractValue<T> = T extends (infer U)[] ? U : T extends Record<string, unknown> ? keyof T : never;
|
|
49
49
|
/**
|
|
50
50
|
* Create a prop value type that can be a direct value or a conditional object.
|
|
51
51
|
*/
|
|
@@ -61,7 +61,7 @@ type ExtractProps<P extends PropertyDefinitions, C extends ConditionDefinitions,
|
|
|
61
61
|
/**
|
|
62
62
|
* The props function signature.
|
|
63
63
|
*/
|
|
64
|
-
type PropsFunction<Collections extends PropertyCollection<
|
|
64
|
+
type PropsFunction<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]> = ((props: UnionToIntersection<{
|
|
65
65
|
[I in keyof Collections]: Collections[I] extends PropertyCollection<infer P, infer C, infer S> ? ExtractProps<P, C, S> : never;
|
|
66
66
|
}[number]>) => string) & {
|
|
67
67
|
properties: Set<string>;
|
|
@@ -69,7 +69,7 @@ type PropsFunction<Collections extends PropertyCollection<any, any, any>[]> = ((
|
|
|
69
69
|
/**
|
|
70
70
|
* Convert a union type to an intersection type.
|
|
71
71
|
*/
|
|
72
|
-
type UnionToIntersection<U> = (U extends
|
|
72
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Define a collection of CSS properties with their allowed values and optional conditions.
|
|
@@ -92,7 +92,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
92
92
|
* });
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
|
-
declare function defineProperties<P extends PropertyDefinitions, C extends ConditionDefinitions =
|
|
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
96
|
|
|
97
97
|
/**
|
|
98
98
|
* Combine property collections into a typed props function with pre-generated CSS.
|
|
@@ -110,6 +110,6 @@ declare function defineProperties<P extends PropertyDefinitions, C extends Condi
|
|
|
110
110
|
* // Returns: "atoms-display-flex atoms-padding-2 atoms-paddingTop-mobile-3"
|
|
111
111
|
* ```
|
|
112
112
|
*/
|
|
113
|
-
declare function createProps<Collections extends PropertyCollection<
|
|
113
|
+
declare function createProps<Collections extends PropertyCollection<PropertyDefinitions, ConditionDefinitions, ShorthandDefinitions<PropertyDefinitions>>[]>(namespace: string, ...collections: Collections): PropsFunction<Collections>;
|
|
114
114
|
|
|
115
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
CHANGED
|
@@ -135,7 +135,7 @@ function generateFromCollections(namespace, collections) {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
// src/runtime.ts
|
|
138
|
-
function buildLookupMap(
|
|
138
|
+
function buildLookupMap(_namespace, collections) {
|
|
139
139
|
const propertyMap = /* @__PURE__ */ new Map();
|
|
140
140
|
const conditionKeys = /* @__PURE__ */ new Set();
|
|
141
141
|
const shorthands = /* @__PURE__ */ new Map();
|
|
@@ -183,7 +183,7 @@ function resolveValue(namespace, property, value, conditionKeys) {
|
|
|
183
183
|
}
|
|
184
184
|
return classNames;
|
|
185
185
|
}
|
|
186
|
-
function createResolver(namespace,
|
|
186
|
+
function createResolver(namespace, _propertyMap, conditionKeys, shorthands) {
|
|
187
187
|
return (props) => {
|
|
188
188
|
const expanded = expandShorthands(props, shorthands);
|
|
189
189
|
const classNames = [];
|
|
@@ -200,10 +200,7 @@ function createResolver(namespace, propertyMap, conditionKeys, shorthands) {
|
|
|
200
200
|
function createProps(namespace, ...collections) {
|
|
201
201
|
const cssRules = generateFromCollections(namespace, collections);
|
|
202
202
|
insertRules(cssRules);
|
|
203
|
-
const { propertyMap, conditionKeys, shorthands } = buildLookupMap(
|
|
204
|
-
namespace,
|
|
205
|
-
collections
|
|
206
|
-
);
|
|
203
|
+
const { propertyMap, conditionKeys, shorthands } = buildLookupMap(namespace, collections);
|
|
207
204
|
const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);
|
|
208
205
|
const properties = /* @__PURE__ */ new Set();
|
|
209
206
|
for (const collection of collections) {
|
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,iBAKd,MAAA,EAC6B;AAC7B,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;;;AC1CO,SAAS,cAAc,KAAA,EAAgC;AAC5D,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAChB,OAAA,CAAQ,QAAQ,GAAG,CAAA,CACnB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAClC;AAKO,SAAS,YAAY,GAAA,EAAqB;AAE/C,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACxB,IAAA,OAAO,GAAA,GAAM,IAAI,OAAA,CAAQ,QAAA,EAAU,CAAC,CAAA,KAAM,GAAA,GAAM,CAAA,CAAE,WAAA,EAAa,CAAA;AAAA,EACjE;AACA,EAAA,OAAO,GAAA,CAAI,QAAQ,QAAA,EAAU,CAAC,MAAM,GAAA,G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ACjD,SAAA;AAAA,IACA;AAAA,GACF;AAGA,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 = {},\n S extends ShorthandDefinitions<P> = {}\n>(\n config: DefinePropertiesConfig<P, C, S>\n): 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: any,\n conditionKeys: Set<string>\n): value is Record<string, any> {\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} 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<any, any, any>[]\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, any>,\n shorthands: Map<string, string[]>\n): Record<string, any> {\n const expanded: Record<string, any> = {};\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: any,\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, any>) => string {\n return (props: Record<string, any>): 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 { PropertyCollection, PropsFunction } 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<Collections extends PropertyCollection<any, any, any>[]>(\n namespace: string,\n ...collections: Collections\n): 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(\n namespace,\n collections\n );\n\n // Create resolver function\n const resolver = createResolver(namespace, propertyMap, conditionKeys, shorthands);\n\n // Create properties set for inspection\n const properties = new Set<string>();\n for (const collection of collections) {\n for (const prop of Object.keys(collection.properties)) {\n properties.add(prop);\n }\n for (const shorthand of Object.keys(collection.shorthands)) {\n properties.add(shorthand);\n }\n }\n\n // Attach properties to the function\n const propsFunction = Object.assign(resolver, { properties });\n\n return propsFunction as PropsFunction<Collections>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/defineProperties.ts","../src/utils.ts","../src/generate.ts","../src/runtime.ts","../src/createProps.ts"],"names":[],"mappings":";;;AA6BO,SAAS,iBAId,MAAA,EAAsE;AACtE,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,UAAA,GAAc,MAAA,CAAO,UAAA,IAAc,EAAC;AAC1C,EAAA,MAAM,gBAAA,GAAmB,OAAO,gBAAA,IAAoB,KAAA;AAEpD,EAAA,OAAO;AAAA,IACL,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,UAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF;AACF;;;ACxCO,SAAS,cAAc,KAAA,EAAgC;AAC5D,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAChB,OAAA,CAAQ,QAAQ,GAAG,CAAA,CACnB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAClC;AAKO,SAAS,YAAY,GAAA,EAAqB;AAE/C,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACxB,IAAA,OAAO,GAAA,GAAM,IAAI,OAAA,CAAQ,QAAA,EAAU,CAAC,CAAA,KAAM,GAAA,GAAM,CAAA,CAAE,WAAA,EAAa,CAAA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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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/props",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Type-safe atomic CSS utility generator for typestyles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"typestyles": "0.
|
|
25
|
+
"typestyles": "0.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "^8.0.0",
|