@molecule/app-styling 1.0.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/LICENSE +115 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/theme.d.ts +33 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +43 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +66 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +132 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styling interface and utilities for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic class-name merging ({@link cn}), variant generation
|
|
5
|
+
* ({@link cva}), and theme→CSS-variable conversion ({@link themeToCSS}) — the
|
|
6
|
+
* low-level plumbing that styling bonds (e.g. `@molecule/app-styling-tailwind`)
|
|
7
|
+
* and ClassMap bonds build on.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { cn, cva } from '@molecule/app-styling'
|
|
12
|
+
*
|
|
13
|
+
* // inside a ClassMap bond / shared-component plumbing:
|
|
14
|
+
* cn('base', isActive && 'active', { disabled: isDisabled })
|
|
15
|
+
* const button = cva('btn', { variants: { size: { sm: 'btn-sm', lg: 'btn-lg' } } })
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* - **This package does NOT license raw class names in app code.** CSS class
|
|
20
|
+
* STRINGS still live only inside ClassMap bond packages — application
|
|
21
|
+
* components style via `getClassMap()` / `cm.*` from `@molecule/app-ui`
|
|
22
|
+
* (compose with `cm.cn`). Reach for this package's `cn`/`cva` only when
|
|
23
|
+
* building a styling bond or shared-component infrastructure.
|
|
24
|
+
* - **Conflict resolution requires a registered merger.** Bare {@link cn} just
|
|
25
|
+
* joins strings — two conflicting utilities (e.g. two `gap-*` classes) both
|
|
26
|
+
* survive. A styling bond registers its merger via {@link setClassMerger} at
|
|
27
|
+
* startup (the Tailwind bond registers `tailwind-merge`); without one, never
|
|
28
|
+
* rely on "last class wins".
|
|
29
|
+
* - {@link themeToCSS} converts a theme object into CSS-variable pairs — pair
|
|
30
|
+
* it with `@molecule/app-theme` bonds instead of hand-writing variable maps.
|
|
31
|
+
*
|
|
32
|
+
* @module
|
|
33
|
+
*/
|
|
34
|
+
export * from './theme.js';
|
|
35
|
+
export * from './types.js';
|
|
36
|
+
export * from './utilities.js';
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styling interface and utilities for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic class-name merging ({@link cn}), variant generation
|
|
5
|
+
* ({@link cva}), and theme→CSS-variable conversion ({@link themeToCSS}) — the
|
|
6
|
+
* low-level plumbing that styling bonds (e.g. `@molecule/app-styling-tailwind`)
|
|
7
|
+
* and ClassMap bonds build on.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { cn, cva } from '@molecule/app-styling'
|
|
12
|
+
*
|
|
13
|
+
* // inside a ClassMap bond / shared-component plumbing:
|
|
14
|
+
* cn('base', isActive && 'active', { disabled: isDisabled })
|
|
15
|
+
* const button = cva('btn', { variants: { size: { sm: 'btn-sm', lg: 'btn-lg' } } })
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* - **This package does NOT license raw class names in app code.** CSS class
|
|
20
|
+
* STRINGS still live only inside ClassMap bond packages — application
|
|
21
|
+
* components style via `getClassMap()` / `cm.*` from `@molecule/app-ui`
|
|
22
|
+
* (compose with `cm.cn`). Reach for this package's `cn`/`cva` only when
|
|
23
|
+
* building a styling bond or shared-component infrastructure.
|
|
24
|
+
* - **Conflict resolution requires a registered merger.** Bare {@link cn} just
|
|
25
|
+
* joins strings — two conflicting utilities (e.g. two `gap-*` classes) both
|
|
26
|
+
* survive. A styling bond registers its merger via {@link setClassMerger} at
|
|
27
|
+
* startup (the Tailwind bond registers `tailwind-merge`); without one, never
|
|
28
|
+
* rely on "last class wins".
|
|
29
|
+
* - {@link themeToCSS} converts a theme object into CSS-variable pairs — pair
|
|
30
|
+
* it with `@molecule/app-theme` bonds instead of hand-writing variable maps.
|
|
31
|
+
*
|
|
32
|
+
* @module
|
|
33
|
+
*/
|
|
34
|
+
export * from './theme.js';
|
|
35
|
+
export * from './types.js';
|
|
36
|
+
export * from './utilities.js';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme-to-CSS conversion utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Minimal theme shape required by themeToCSS().
|
|
8
|
+
* Structurally compatible with Theme from `@molecule/app-theme`.
|
|
9
|
+
*/
|
|
10
|
+
interface ThemeLike {
|
|
11
|
+
colors: Record<string, string | number>;
|
|
12
|
+
spacing: Record<string, string | number>;
|
|
13
|
+
typography: {
|
|
14
|
+
fontSize: Record<string, string | number>;
|
|
15
|
+
};
|
|
16
|
+
borderRadius: Record<string, string | number>;
|
|
17
|
+
shadows: Record<string, string | number>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Maps a molecule theme to CSS custom properties.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const cssVars = themeToCSS(theme)
|
|
25
|
+
* // Use in style attribute or inject into :root
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param theme - A theme object with colors, spacing, typography, borderRadius, and shadows.
|
|
29
|
+
* @returns A flat record of CSS custom properties (e.g. `{ '--color-primary': '#3b82f6' }`).
|
|
30
|
+
*/
|
|
31
|
+
export declare const themeToCSS: (theme: ThemeLike) => Record<string, string>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IACvC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IACxC,UAAU,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;KAAE,CAAA;IACzD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IAC7C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CACzC;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CA6BlE,CAAA"}
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme-to-CSS conversion utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { camelToKebab } from './utilities.js';
|
|
7
|
+
/**
|
|
8
|
+
* Maps a molecule theme to CSS custom properties.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const cssVars = themeToCSS(theme)
|
|
13
|
+
* // Use in style attribute or inject into :root
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param theme - A theme object with colors, spacing, typography, borderRadius, and shadows.
|
|
17
|
+
* @returns A flat record of CSS custom properties (e.g. `{ '--color-primary': '#3b82f6' }`).
|
|
18
|
+
*/
|
|
19
|
+
export const themeToCSS = (theme) => {
|
|
20
|
+
const vars = {};
|
|
21
|
+
// Colors
|
|
22
|
+
for (const [key, value] of Object.entries(theme.colors)) {
|
|
23
|
+
vars[`--color-${camelToKebab(key)}`] = String(value);
|
|
24
|
+
}
|
|
25
|
+
// Spacing
|
|
26
|
+
for (const [key, value] of Object.entries(theme.spacing)) {
|
|
27
|
+
vars[`--spacing-${key}`] = String(value);
|
|
28
|
+
}
|
|
29
|
+
// Typography
|
|
30
|
+
for (const [key, value] of Object.entries(theme.typography.fontSize)) {
|
|
31
|
+
vars[`--font-size-${key}`] = String(value);
|
|
32
|
+
}
|
|
33
|
+
// Border radius
|
|
34
|
+
for (const [key, value] of Object.entries(theme.borderRadius)) {
|
|
35
|
+
vars[`--radius-${key}`] = String(value);
|
|
36
|
+
}
|
|
37
|
+
// Shadows
|
|
38
|
+
for (const [key, value] of Object.entries(theme.shadows)) {
|
|
39
|
+
vars[`--shadow-${key}`] = String(value);
|
|
40
|
+
}
|
|
41
|
+
return vars;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,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GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACzC,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styling type definitions for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Class name value types accepted by {@link cn}.
|
|
8
|
+
*/
|
|
9
|
+
export type ClassValue = string | number | boolean | undefined | null | ClassValue[] | Record<string, boolean | undefined | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for class variance authority ({@link cva}).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* A class-name merger: post-processes the joined class string produced by
|
|
15
|
+
* `cn()` to resolve conflicts (e.g. `tailwind-merge`). Registered by a styling
|
|
16
|
+
* bond via `setClassMerger` so the styling core stays framework-agnostic.
|
|
17
|
+
*/
|
|
18
|
+
export type ClassMerger = (className: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for a class-variance-authority (`cva`) function: the variant
|
|
21
|
+
* definitions, default selections, and compound variants used to resolve a
|
|
22
|
+
* component's final class string from its props.
|
|
23
|
+
*/
|
|
24
|
+
export interface CVAConfig<T extends Record<string, Record<string, string>>> {
|
|
25
|
+
variants?: T;
|
|
26
|
+
defaultVariants?: {
|
|
27
|
+
[K in keyof T]?: keyof T[K];
|
|
28
|
+
};
|
|
29
|
+
compoundVariants?: Array<{
|
|
30
|
+
[K in keyof T]?: keyof T[K];
|
|
31
|
+
} & {
|
|
32
|
+
class: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,IAAI,GACJ,UAAU,EAAE,GACZ,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,CAAA;AAE9C;;GAEG;AACH;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;AAEvD;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzE,QAAQ,CAAC,EAAE,CAAC,CAAA;IACZ,eAAe,CAAC,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;KAAE,CAAA;IACjD,gBAAgB,CAAC,EAAE,KAAK,CAAC;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC9E"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic styling utility functions.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { ClassMerger, ClassValue, CVAConfig } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Registers the class-name merger used by {@link cn} to resolve conflicting
|
|
9
|
+
* classes. Styling bonds call this at startup; pass `null` to clear it.
|
|
10
|
+
*
|
|
11
|
+
* @param merger - Post-processes the joined class string, or `null` to disable merging.
|
|
12
|
+
*/
|
|
13
|
+
export declare const setClassMerger: (merger: ClassMerger | null) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Merges class names, filtering out falsy values. Supports strings,
|
|
16
|
+
* numbers, conditional objects, and nested arrays.
|
|
17
|
+
*
|
|
18
|
+
* When a class merger is registered via {@link setClassMerger} (e.g. the
|
|
19
|
+
* Tailwind bond registers `tailwind-merge`), conflicting utilities such as two
|
|
20
|
+
* `gap-*` classes are resolved by it; otherwise the joined string is returned
|
|
21
|
+
* as-is.
|
|
22
|
+
*
|
|
23
|
+
* @param classes - Class values to merge (strings, booleans, objects, arrays).
|
|
24
|
+
* @returns A single space-separated class string.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* cn('btn', 'btn-primary', isActive && 'active')
|
|
29
|
+
* // => 'btn btn-primary active' (if isActive is true)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const cn: (...classes: ClassValue[]) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a class variance authority (CVA) function for component variants.
|
|
35
|
+
* Given a base class and variant configuration, returns a function that
|
|
36
|
+
* resolves the final class string based on selected variants.
|
|
37
|
+
*
|
|
38
|
+
* @param base - The base class that is always included.
|
|
39
|
+
* @param config - Variant definitions, defaults, and compound variants.
|
|
40
|
+
* @returns A function that accepts variant props and returns the resolved class string.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const button = cva('btn', {
|
|
45
|
+
* variants: {
|
|
46
|
+
* size: { sm: 'btn-sm', md: 'btn-md', lg: 'btn-lg' },
|
|
47
|
+
* variant: { primary: 'btn-primary', secondary: 'btn-secondary' }
|
|
48
|
+
* },
|
|
49
|
+
* defaultVariants: { size: 'md', variant: 'primary' }
|
|
50
|
+
* })
|
|
51
|
+
*
|
|
52
|
+
* button({ size: 'lg', variant: 'secondary' })
|
|
53
|
+
* // => 'btn btn-lg btn-secondary'
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const cva: <T extends Record<string, Record<string, string>>>(base: string, config?: CVAConfig<T>) => (props?: { [K in keyof T]?: keyof T[K]; } & {
|
|
57
|
+
class?: string;
|
|
58
|
+
}) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Converts a camelCase string to kebab-case.
|
|
61
|
+
*
|
|
62
|
+
* @param str - The camelCase string to convert.
|
|
63
|
+
* @returns The kebab-case version (e.g. `'borderRadius'` → `'border-radius'`).
|
|
64
|
+
*/
|
|
65
|
+
export declare const camelToKebab: (str: string) => string;
|
|
66
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAWpE;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,WAAW,GAAG,IAAI,KAAG,IAE3D,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,EAAE,GAAI,GAAG,SAAS,UAAU,EAAE,KAAG,MAqB7C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAClE,MAAM,MAAM,EACZ,SAAS,SAAS,CAAC,CAAC,CAAC,MAEb,QAAQ,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,GAAE,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,MAwCxE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAE1C,CAAA"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic styling utility functions.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The active class-name merger, injected by a styling bond. This core is
|
|
8
|
+
* framework-agnostic and carries no styling-library dependency; a bond such as
|
|
9
|
+
* `@molecule/app-styling-tailwind` registers `tailwind-merge` here at startup
|
|
10
|
+
* (via `setupAppStylingTailwind()` in the default bond wiring). When none is
|
|
11
|
+
* registered, {@link cn} returns the plain joined string.
|
|
12
|
+
*/
|
|
13
|
+
let classMerger = null;
|
|
14
|
+
/**
|
|
15
|
+
* Registers the class-name merger used by {@link cn} to resolve conflicting
|
|
16
|
+
* classes. Styling bonds call this at startup; pass `null` to clear it.
|
|
17
|
+
*
|
|
18
|
+
* @param merger - Post-processes the joined class string, or `null` to disable merging.
|
|
19
|
+
*/
|
|
20
|
+
export const setClassMerger = (merger) => {
|
|
21
|
+
classMerger = merger;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Merges class names, filtering out falsy values. Supports strings,
|
|
25
|
+
* numbers, conditional objects, and nested arrays.
|
|
26
|
+
*
|
|
27
|
+
* When a class merger is registered via {@link setClassMerger} (e.g. the
|
|
28
|
+
* Tailwind bond registers `tailwind-merge`), conflicting utilities such as two
|
|
29
|
+
* `gap-*` classes are resolved by it; otherwise the joined string is returned
|
|
30
|
+
* as-is.
|
|
31
|
+
*
|
|
32
|
+
* @param classes - Class values to merge (strings, booleans, objects, arrays).
|
|
33
|
+
* @returns A single space-separated class string.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* cn('btn', 'btn-primary', isActive && 'active')
|
|
38
|
+
* // => 'btn btn-primary active' (if isActive is true)
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const cn = (...classes) => {
|
|
42
|
+
const joined = classes
|
|
43
|
+
.flat()
|
|
44
|
+
.filter((c) => {
|
|
45
|
+
if (c === null || c === undefined || c === false || c === '')
|
|
46
|
+
return false;
|
|
47
|
+
return true;
|
|
48
|
+
})
|
|
49
|
+
.map((c) => {
|
|
50
|
+
if (typeof c === 'string' || typeof c === 'number')
|
|
51
|
+
return String(c);
|
|
52
|
+
if (typeof c === 'object') {
|
|
53
|
+
return Object.entries(c)
|
|
54
|
+
.filter(([, value]) => Boolean(value))
|
|
55
|
+
.map(([key]) => key)
|
|
56
|
+
.join(' ');
|
|
57
|
+
}
|
|
58
|
+
return '';
|
|
59
|
+
})
|
|
60
|
+
.join(' ')
|
|
61
|
+
.trim();
|
|
62
|
+
if (joined === '')
|
|
63
|
+
return '';
|
|
64
|
+
return classMerger ? classMerger(joined) : joined;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Creates a class variance authority (CVA) function for component variants.
|
|
68
|
+
* Given a base class and variant configuration, returns a function that
|
|
69
|
+
* resolves the final class string based on selected variants.
|
|
70
|
+
*
|
|
71
|
+
* @param base - The base class that is always included.
|
|
72
|
+
* @param config - Variant definitions, defaults, and compound variants.
|
|
73
|
+
* @returns A function that accepts variant props and returns the resolved class string.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const button = cva('btn', {
|
|
78
|
+
* variants: {
|
|
79
|
+
* size: { sm: 'btn-sm', md: 'btn-md', lg: 'btn-lg' },
|
|
80
|
+
* variant: { primary: 'btn-primary', secondary: 'btn-secondary' }
|
|
81
|
+
* },
|
|
82
|
+
* defaultVariants: { size: 'md', variant: 'primary' }
|
|
83
|
+
* })
|
|
84
|
+
*
|
|
85
|
+
* button({ size: 'lg', variant: 'secondary' })
|
|
86
|
+
* // => 'btn btn-lg btn-secondary'
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export const cva = (base, config) => {
|
|
90
|
+
return (props) => {
|
|
91
|
+
const classes = [base];
|
|
92
|
+
const { variants, defaultVariants, compoundVariants } = config ?? {};
|
|
93
|
+
if (variants) {
|
|
94
|
+
for (const [variantKey, variantOptions] of Object.entries(variants)) {
|
|
95
|
+
const selectedVariant = props?.[variantKey] ??
|
|
96
|
+
defaultVariants?.[variantKey];
|
|
97
|
+
if (selectedVariant &&
|
|
98
|
+
typeof selectedVariant === 'string' &&
|
|
99
|
+
variantOptions[selectedVariant]) {
|
|
100
|
+
classes.push(variantOptions[selectedVariant]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (compoundVariants && props) {
|
|
105
|
+
for (const compound of compoundVariants) {
|
|
106
|
+
const { class: compoundClass, ...conditions } = compound;
|
|
107
|
+
const conditionEntries = Object.entries(conditions);
|
|
108
|
+
const matches = conditionEntries.every(([key, value]) => {
|
|
109
|
+
const propValue = props[key] ?? defaultVariants?.[key];
|
|
110
|
+
return propValue === value;
|
|
111
|
+
});
|
|
112
|
+
if (matches) {
|
|
113
|
+
classes.push(compoundClass);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (props?.class) {
|
|
118
|
+
classes.push(props.class);
|
|
119
|
+
}
|
|
120
|
+
return cn(...classes);
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Converts a camelCase string to kebab-case.
|
|
125
|
+
*
|
|
126
|
+
* @param str - The camelCase string to convert.
|
|
127
|
+
* @returns The kebab-case version (e.g. `'borderRadius'` → `'border-radius'`).
|
|
128
|
+
*/
|
|
129
|
+
export const camelToKebab = (str) => {
|
|
130
|
+
return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;GAMG;AACH,IAAI,WAAW,GAAuB,IAAI,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,M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ACH,CAAC;QACH,CAAC;QAED,IAAI,KAAK,EAAE,KAAK,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAA;IACvB,CAAC,CAAA;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE;IAClD,OAAO,GAAG,CAAC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA;AACjE,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-styling",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Styling interface and utilities for molecule.dev",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"styling",
|
|
25
|
+
"css",
|
|
26
|
+
"classnames",
|
|
27
|
+
"cva"
|
|
28
|
+
],
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "26.1.2",
|
|
32
|
+
"typescript": "6.0.3",
|
|
33
|
+
"vitest": "4.1.10"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
38
|
+
"directory": "packages/app/core/styling"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/app/core/styling",
|
|
41
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|