@tokenami/css 0.0.21 → 0.0.23

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 CHANGED
@@ -40,237 +40,75 @@ var import_config = require("@tokenami/config");
40
40
 
41
41
  // src/css.ts
42
42
  var Tokenami = __toESM(require("@tokenami/config"), 1);
43
-
44
- // src/shorthands.ts
45
- var mapShorthandToLonghands = {
46
- animation: [
47
- "animation-name",
48
- "animation-duration",
49
- "animation-timing-function",
50
- "animation-delay",
51
- "animation-iteration-count",
52
- "animation-direction",
53
- "animation-fill-mode",
54
- "animation-play-state",
55
- "animation-timeline"
56
- ],
57
- background: [
58
- "background-attachment",
59
- "background-clip",
60
- "background-color",
61
- "background-image",
62
- "background-position",
63
- "background-repeat",
64
- "background-size"
65
- ],
66
- border: ["border-style", "border-color", "border-width"],
67
- "border-top": ["border-top-width", "border-top-style", "border-top-color"],
68
- "border-right": ["border-right-width", "border-right-style", "border-right-color"],
69
- "border-bottom": ["border-bottom-width", "border-bottom-style", "border-bottom-color"],
70
- "border-left": ["border-left-width", "border-left-style", "border-left-color"],
71
- "border-color": [
72
- "border-top-color",
73
- "border-right-color",
74
- "border-bottom-color",
75
- "border-left-color"
76
- ],
77
- "border-style": [
78
- "border-top-style",
79
- "border-right-style",
80
- "border-bottom-style",
81
- "border-left-style"
82
- ],
83
- "border-width": [
84
- "border-top-width",
85
- "border-right-width",
86
- "border-bottom-width",
87
- "border-left-width"
88
- ],
89
- "border-image": [
90
- "border-image-source",
91
- "border-image-slice",
92
- "border-image-width",
93
- "border-image-outset",
94
- "border-image-repeat"
95
- ],
96
- "border-radius": [
97
- "border-top-left-radius",
98
- "border-top-right-radius",
99
- "border-bottom-right-radius",
100
- "border-bottom-left-radius"
101
- ],
102
- "border-block": ["border-block-width", "border-block-style", "border-block-color"],
103
- "border-block-width": ["border-block-start-width", "border-block-end-width"],
104
- "border-block-style": ["border-block-start-style", "border-block-end-style"],
105
- "border-block-color": ["border-block-start-color", "border-block-end-color"],
106
- "border-block-start": [
107
- "border-block-start-width",
108
- "border-block-start-style",
109
- "border-block-start-color"
110
- ],
111
- "border-block-end": [
112
- "border-block-end-width",
113
- "border-block-end-style",
114
- "border-block-end-color"
115
- ],
116
- "border-inline": ["border-inline-width", "border-inline-style", "border-inline-color"],
117
- "border-inline-width": ["border-inline-start-width", "border-inline-end-width"],
118
- "border-inline-style": ["border-inline-start-style", "border-inline-end-style"],
119
- "border-inline-color": ["border-inline-start-color", "border-inline-end-color"],
120
- "border-inline-start": [
121
- "border-inline-start-width",
122
- "border-inline-start-style",
123
- "border-inline-start-color"
124
- ],
125
- "border-inline-end": [
126
- "border-inline-end-width",
127
- "border-inline-end-style",
128
- "border-inline-end-color"
129
- ],
130
- "column-rule": ["column-rule-width", "column-rule-style", "column-rule-color"],
131
- columns: ["column-width", "column-count"],
132
- container: ["container-name", "container-type"],
133
- "contain-intrinsic-size": ["contain-intrinsic-width", "contain-intrinsic-height"],
134
- flex: ["flex-grow", "flex-shrink", "flex-basis"],
135
- "flex-flow": ["flex-direction", "flex-wrap"],
136
- font: [
137
- "font-style",
138
- "font-variant",
139
- "font-weight",
140
- "font-stretch",
141
- "font-size",
142
- "line-height",
143
- "font-family"
144
- ],
145
- "font-variant": [
146
- "font-variant-ligatures",
147
- "font-variant-caps",
148
- "font-variant-numeric",
149
- "font-variant-east-asian"
150
- ],
151
- gap: ["row-gap", "column-gap"],
152
- grid: [
153
- "grid-template-rows",
154
- "grid-template-columns",
155
- "grid-template-areas",
156
- "grid-auto-rows",
157
- "grid-auto-columns",
158
- "grid-auto-flow"
159
- ],
160
- "grid-area": ["grid-row-start", "grid-column-start", "grid-row-end", "grid-column-end"],
161
- "grid-column": ["grid-column-start", "grid-column-end"],
162
- "grid-row": ["grid-row-start", "grid-row-end"],
163
- "grid-template": ["grid-template-rows", "grid-template-columns", "grid-template-areas"],
164
- inset: ["top", "right", "bottom", "left"],
165
- "list-style": ["list-style-type", "list-style-position", "list-style-image"],
166
- "inset-block": ["inset-block-start", "inset-block-end"],
167
- "inset-inline": ["inset-inline-start", "inset-inline-end"],
168
- margin: ["margin-top", "margin-right", "margin-bottom", "margin-left"],
169
- "margin-block": ["margin-block-start", "margin-block-end"],
170
- "margin-inline": ["margin-inline-start", "margin-inline-end"],
171
- mask: [
172
- "mask-image",
173
- "mask-mode",
174
- "mask-position",
175
- "mask-size",
176
- "mask-repeat",
177
- "mask-origin",
178
- "mask-clip",
179
- "mask-composite",
180
- "mask-type"
181
- ],
182
- "mask-border": [
183
- "mask-border-mode",
184
- "mask-border-outset",
185
- "mask-border-repeat",
186
- "mask-border-slice",
187
- "mask-border-source",
188
- "mask-border-width"
189
- ],
190
- offset: ["offset-position", "offset-path", "offset-distance", "offset-anchor", "offset-rotate"],
191
- outline: ["outline-color", "outline-style", "outline-width"],
192
- overflow: ["overflow-x", "overflow-y"],
193
- padding: ["padding-top", "padding-right", "padding-bottom", "padding-left"],
194
- "padding-block": ["padding-block-start", "padding-block-end"],
195
- "padding-inline": ["padding-inline-start", "padding-inline-end"],
196
- "place-content": ["align-content", "justify-content"],
197
- "place-items": ["align-items", "justify-items"],
198
- "place-self": ["align-self", "justify-self"],
199
- "scroll-margin": [
200
- "scroll-margin-top",
201
- "scroll-margin-right",
202
- "scroll-margin-bottom",
203
- "scroll-margin-left"
204
- ],
205
- "scroll-margin-block": ["scroll-margin-block-start", "scroll-margin-block-end"],
206
- "scroll-margin-inline": ["scroll-margin-inline-start", "scroll-margin-inline-end"],
207
- "scroll-padding": [
208
- "scroll-padding-top",
209
- "scroll-padding-right",
210
- "scroll-padding-bottom",
211
- "scroll-padding-left"
212
- ],
213
- "scroll-padding-block": ["scroll-padding-block-start", "scroll-padding-block-end"],
214
- "scroll-padding-inline": ["scroll-padding-inline-start", "scroll-padding-inline-end"],
215
- "scroll-timeline": ["scroll-timeline-name", "scroll-timeline-axis"],
216
- "text-decoration": [
217
- "text-decoration-line",
218
- "text-decoration-style",
219
- "text-decoration-color",
220
- "text-decoration-thickness"
221
- ],
222
- "text-emphasis": ["text-emphasis-style", "text-emphasis-color"],
223
- transition: [
224
- "transition-property",
225
- "transition-duration",
226
- "transition-timing-function",
227
- "transition-delay"
228
- ]
43
+ var _LONGHANDS = Symbol();
44
+ var cache = {};
45
+ var css = (baseStyles, ...overrides) => {
46
+ const cacheId = JSON.stringify({ baseStyles, overrides });
47
+ const cached = cache[cacheId];
48
+ if (cached)
49
+ return cached;
50
+ let overriddenStyles = Object.assign({}, baseStyles);
51
+ overrides.forEach((overrideStyle) => {
52
+ if (!overrideStyle)
53
+ return;
54
+ for (let key in overrideStyle) {
55
+ const tokenProperty2 = key;
56
+ const property = Tokenami.getTokenPropertyName(tokenProperty2);
57
+ override(overriddenStyles, property);
58
+ }
59
+ Object.assign(overriddenStyles, overrideStyle);
60
+ });
61
+ Object.entries(overriddenStyles).forEach(([property, value]) => {
62
+ const tokenProperty2 = Tokenami.TokenProperty.safeParse(property);
63
+ if (tokenProperty2.success && typeof value === "number" && value > 0) {
64
+ const gridVar = Tokenami.gridProperty();
65
+ overriddenStyles[tokenProperty2.output] = `calc(var(${gridVar}) * ${value})`;
66
+ }
67
+ });
68
+ cache[cacheId] = overriddenStyles;
69
+ return overriddenStyles;
229
70
  };
230
-
231
- // src/css.ts
232
- var SHORTHANDS_TO_LONGHANDS = Symbol.for("tokenamiShorthandToLonghands");
233
- function css(baseStyles, variantsConfig, options) {
234
- const cache = {};
235
- return function generate(variants, ...overrides) {
236
- const cacheId = JSON.stringify({ variants, overrides });
71
+ css[_LONGHANDS] = Tokenami.mapShorthandToLonghands;
72
+ css.compose = (config) => {
73
+ const { variants, responsiveVariants, ...baseStyles } = config;
74
+ return function generate(selectedVariants, ...overrides) {
75
+ const cacheId = JSON.stringify({
76
+ baseStyles,
77
+ variants,
78
+ responsiveVariants,
79
+ selectedVariants,
80
+ overrides
81
+ });
237
82
  const cached = cache[cacheId];
238
83
  if (cached)
239
84
  return cached;
240
- const variantStyles = variants ? Object.entries(variants).flatMap(([key, variant]) => {
241
- var _a;
85
+ const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
86
+ var _a, _b, _c;
242
87
  if (!variant)
243
88
  return [];
244
89
  const [type, bp] = key.split("_").reverse();
245
- const styles = (_a = variantsConfig == null ? void 0 : variantsConfig[type]) == null ? void 0 : _a[variant];
246
- const responsive = options == null ? void 0 : options.responsive;
247
- const updated = responsive && bp && styles ? convertToMediaStyles(bp, styles) : styles;
248
- return updated ? [updated] : [];
249
- }) : [];
250
- const overrideStyles = [...variantStyles, ...overrides];
251
- let css2 = Object.assign({}, baseStyles);
252
- overrideStyles.forEach((overrideStyle) => {
253
- if (overrideStyle) {
254
- for (let tokenProperty2 in overrideStyle) {
255
- const property = Tokenami.getTokenPropertyName(tokenProperty2);
256
- override(css2, property);
257
- }
258
- Object.assign(css2, overrideStyle);
90
+ if (bp) {
91
+ const styles2 = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
92
+ return styles2 ? [convertToMediaStyles(bp, styles2)] : [];
93
+ } else {
94
+ const styles2 = (_c = (_b = variants || responsiveVariants) == null ? void 0 : _b[type]) == null ? void 0 : _c[variant];
95
+ return styles2 ? [styles2] : [];
259
96
  }
260
- });
261
- cache[cacheId] = css2;
262
- return css2;
97
+ }) : [];
98
+ const styles = css(baseStyles, ...variantStyles, ...overrides);
99
+ cache[cacheId] = styles;
100
+ return styles;
263
101
  };
264
- }
265
- css[SHORTHANDS_TO_LONGHANDS] = mapShorthandToLonghands;
102
+ };
103
+ css[_LONGHANDS] = Tokenami.mapShorthandToLonghands;
266
104
  function createCss(config) {
267
105
  if (!config.aliases)
268
106
  return css;
269
- css[SHORTHANDS_TO_LONGHANDS] = { ...css[SHORTHANDS_TO_LONGHANDS], ...config.aliases };
107
+ css[_LONGHANDS] = Object.assign({}, css[_LONGHANDS], config.aliases);
270
108
  return css;
271
109
  }
272
110
  function override(style, property) {
273
- const longhands = css[SHORTHANDS_TO_LONGHANDS][property];
111
+ const longhands = css[_LONGHANDS][property];
274
112
  if (!longhands)
275
113
  return;
276
114
  for (let longhand of longhands) {
package/dist/index.d.cts CHANGED
@@ -2,25 +2,31 @@ import * as Tokenami from '@tokenami/config';
2
2
  export { createConfig, defaultConfig } from '@tokenami/config';
3
3
  import { TokenamiProperties, TokenamiFinalConfig } from '@tokenami/dev';
4
4
 
5
+ declare const _LONGHANDS: unique symbol;
5
6
  type VariantsConfig = Record<string, Record<string, TokenamiProperties>>;
6
7
  type VariantValue<T> = T extends 'true' | 'false' ? boolean : T;
7
8
  type ReponsiveKey = Extract<keyof TokenamiFinalConfig['responsive'], string>;
8
9
  type ResponsiveValue<T> = T extends string ? `${ReponsiveKey}_${T}` : never;
9
10
  type Override = TokenamiProperties | false | undefined;
10
- type Variants$1<C> = {
11
+ type Variants$1<C> = undefined extends C ? {} : {
11
12
  [V in keyof C]?: VariantValue<keyof C[V]>;
12
13
  };
13
- type ResponsiveVariants<C> = {
14
+ type ResponsiveVariants<C> = undefined extends C ? {} : {
14
15
  [V in keyof C]: {
15
16
  [M in ResponsiveValue<V>]?: VariantValue<keyof C[V]>;
16
17
  };
17
18
  }[keyof C];
18
- type SelectedVariants<V, R> = undefined extends V ? null : Variants$1<V> & (R extends true ? ResponsiveVariants<V> : {});
19
- declare function css<V extends VariantsConfig | undefined, R>(baseStyles: TokenamiProperties, variantsConfig?: V & VariantsConfig, options?: undefined extends V ? never : {
20
- responsive: R & boolean;
21
- }): (variants?: SelectedVariants<V, R>, ...overrides: Override[]) => {};
22
- declare namespace css { }
23
- declare function createCss(config: Tokenami.Config): typeof css;
19
+ type ComposeCSS<V, R> = TokenamiProperties & {
20
+ variants?: V & VariantsConfig;
21
+ responsiveVariants?: R & VariantsConfig;
22
+ };
23
+ interface CSS {
24
+ [_LONGHANDS]?: typeof Tokenami.mapShorthandToLonghands;
25
+ (baseStyles: TokenamiProperties, ...overrides: Override[]): {};
26
+ compose: <V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(config: ComposeCSS<V, R>) => (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>, ...overrides: Override[]) => {};
27
+ }
28
+ declare const css: CSS;
29
+ declare function createCss(config: Tokenami.Config): CSS;
24
30
 
25
31
  type Variants<T extends () => {}> = Parameters<T>[0] extends undefined | null ? {} : NonNullable<Parameters<T>[0]>;
26
32
 
package/dist/index.d.ts CHANGED
@@ -2,25 +2,31 @@ import * as Tokenami from '@tokenami/config';
2
2
  export { createConfig, defaultConfig } from '@tokenami/config';
3
3
  import { TokenamiProperties, TokenamiFinalConfig } from '@tokenami/dev';
4
4
 
5
+ declare const _LONGHANDS: unique symbol;
5
6
  type VariantsConfig = Record<string, Record<string, TokenamiProperties>>;
6
7
  type VariantValue<T> = T extends 'true' | 'false' ? boolean : T;
7
8
  type ReponsiveKey = Extract<keyof TokenamiFinalConfig['responsive'], string>;
8
9
  type ResponsiveValue<T> = T extends string ? `${ReponsiveKey}_${T}` : never;
9
10
  type Override = TokenamiProperties | false | undefined;
10
- type Variants$1<C> = {
11
+ type Variants$1<C> = undefined extends C ? {} : {
11
12
  [V in keyof C]?: VariantValue<keyof C[V]>;
12
13
  };
13
- type ResponsiveVariants<C> = {
14
+ type ResponsiveVariants<C> = undefined extends C ? {} : {
14
15
  [V in keyof C]: {
15
16
  [M in ResponsiveValue<V>]?: VariantValue<keyof C[V]>;
16
17
  };
17
18
  }[keyof C];
18
- type SelectedVariants<V, R> = undefined extends V ? null : Variants$1<V> & (R extends true ? ResponsiveVariants<V> : {});
19
- declare function css<V extends VariantsConfig | undefined, R>(baseStyles: TokenamiProperties, variantsConfig?: V & VariantsConfig, options?: undefined extends V ? never : {
20
- responsive: R & boolean;
21
- }): (variants?: SelectedVariants<V, R>, ...overrides: Override[]) => {};
22
- declare namespace css { }
23
- declare function createCss(config: Tokenami.Config): typeof css;
19
+ type ComposeCSS<V, R> = TokenamiProperties & {
20
+ variants?: V & VariantsConfig;
21
+ responsiveVariants?: R & VariantsConfig;
22
+ };
23
+ interface CSS {
24
+ [_LONGHANDS]?: typeof Tokenami.mapShorthandToLonghands;
25
+ (baseStyles: TokenamiProperties, ...overrides: Override[]): {};
26
+ compose: <V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(config: ComposeCSS<V, R>) => (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>, ...overrides: Override[]) => {};
27
+ }
28
+ declare const css: CSS;
29
+ declare function createCss(config: Tokenami.Config): CSS;
24
30
 
25
31
  type Variants<T extends () => {}> = Parameters<T>[0] extends undefined | null ? {} : NonNullable<Parameters<T>[0]>;
26
32
 
package/dist/index.js CHANGED
@@ -3,237 +3,75 @@ import { createConfig, defaultConfig } from "@tokenami/config";
3
3
 
4
4
  // src/css.ts
5
5
  import * as Tokenami from "@tokenami/config";
6
-
7
- // src/shorthands.ts
8
- var mapShorthandToLonghands = {
9
- animation: [
10
- "animation-name",
11
- "animation-duration",
12
- "animation-timing-function",
13
- "animation-delay",
14
- "animation-iteration-count",
15
- "animation-direction",
16
- "animation-fill-mode",
17
- "animation-play-state",
18
- "animation-timeline"
19
- ],
20
- background: [
21
- "background-attachment",
22
- "background-clip",
23
- "background-color",
24
- "background-image",
25
- "background-position",
26
- "background-repeat",
27
- "background-size"
28
- ],
29
- border: ["border-style", "border-color", "border-width"],
30
- "border-top": ["border-top-width", "border-top-style", "border-top-color"],
31
- "border-right": ["border-right-width", "border-right-style", "border-right-color"],
32
- "border-bottom": ["border-bottom-width", "border-bottom-style", "border-bottom-color"],
33
- "border-left": ["border-left-width", "border-left-style", "border-left-color"],
34
- "border-color": [
35
- "border-top-color",
36
- "border-right-color",
37
- "border-bottom-color",
38
- "border-left-color"
39
- ],
40
- "border-style": [
41
- "border-top-style",
42
- "border-right-style",
43
- "border-bottom-style",
44
- "border-left-style"
45
- ],
46
- "border-width": [
47
- "border-top-width",
48
- "border-right-width",
49
- "border-bottom-width",
50
- "border-left-width"
51
- ],
52
- "border-image": [
53
- "border-image-source",
54
- "border-image-slice",
55
- "border-image-width",
56
- "border-image-outset",
57
- "border-image-repeat"
58
- ],
59
- "border-radius": [
60
- "border-top-left-radius",
61
- "border-top-right-radius",
62
- "border-bottom-right-radius",
63
- "border-bottom-left-radius"
64
- ],
65
- "border-block": ["border-block-width", "border-block-style", "border-block-color"],
66
- "border-block-width": ["border-block-start-width", "border-block-end-width"],
67
- "border-block-style": ["border-block-start-style", "border-block-end-style"],
68
- "border-block-color": ["border-block-start-color", "border-block-end-color"],
69
- "border-block-start": [
70
- "border-block-start-width",
71
- "border-block-start-style",
72
- "border-block-start-color"
73
- ],
74
- "border-block-end": [
75
- "border-block-end-width",
76
- "border-block-end-style",
77
- "border-block-end-color"
78
- ],
79
- "border-inline": ["border-inline-width", "border-inline-style", "border-inline-color"],
80
- "border-inline-width": ["border-inline-start-width", "border-inline-end-width"],
81
- "border-inline-style": ["border-inline-start-style", "border-inline-end-style"],
82
- "border-inline-color": ["border-inline-start-color", "border-inline-end-color"],
83
- "border-inline-start": [
84
- "border-inline-start-width",
85
- "border-inline-start-style",
86
- "border-inline-start-color"
87
- ],
88
- "border-inline-end": [
89
- "border-inline-end-width",
90
- "border-inline-end-style",
91
- "border-inline-end-color"
92
- ],
93
- "column-rule": ["column-rule-width", "column-rule-style", "column-rule-color"],
94
- columns: ["column-width", "column-count"],
95
- container: ["container-name", "container-type"],
96
- "contain-intrinsic-size": ["contain-intrinsic-width", "contain-intrinsic-height"],
97
- flex: ["flex-grow", "flex-shrink", "flex-basis"],
98
- "flex-flow": ["flex-direction", "flex-wrap"],
99
- font: [
100
- "font-style",
101
- "font-variant",
102
- "font-weight",
103
- "font-stretch",
104
- "font-size",
105
- "line-height",
106
- "font-family"
107
- ],
108
- "font-variant": [
109
- "font-variant-ligatures",
110
- "font-variant-caps",
111
- "font-variant-numeric",
112
- "font-variant-east-asian"
113
- ],
114
- gap: ["row-gap", "column-gap"],
115
- grid: [
116
- "grid-template-rows",
117
- "grid-template-columns",
118
- "grid-template-areas",
119
- "grid-auto-rows",
120
- "grid-auto-columns",
121
- "grid-auto-flow"
122
- ],
123
- "grid-area": ["grid-row-start", "grid-column-start", "grid-row-end", "grid-column-end"],
124
- "grid-column": ["grid-column-start", "grid-column-end"],
125
- "grid-row": ["grid-row-start", "grid-row-end"],
126
- "grid-template": ["grid-template-rows", "grid-template-columns", "grid-template-areas"],
127
- inset: ["top", "right", "bottom", "left"],
128
- "list-style": ["list-style-type", "list-style-position", "list-style-image"],
129
- "inset-block": ["inset-block-start", "inset-block-end"],
130
- "inset-inline": ["inset-inline-start", "inset-inline-end"],
131
- margin: ["margin-top", "margin-right", "margin-bottom", "margin-left"],
132
- "margin-block": ["margin-block-start", "margin-block-end"],
133
- "margin-inline": ["margin-inline-start", "margin-inline-end"],
134
- mask: [
135
- "mask-image",
136
- "mask-mode",
137
- "mask-position",
138
- "mask-size",
139
- "mask-repeat",
140
- "mask-origin",
141
- "mask-clip",
142
- "mask-composite",
143
- "mask-type"
144
- ],
145
- "mask-border": [
146
- "mask-border-mode",
147
- "mask-border-outset",
148
- "mask-border-repeat",
149
- "mask-border-slice",
150
- "mask-border-source",
151
- "mask-border-width"
152
- ],
153
- offset: ["offset-position", "offset-path", "offset-distance", "offset-anchor", "offset-rotate"],
154
- outline: ["outline-color", "outline-style", "outline-width"],
155
- overflow: ["overflow-x", "overflow-y"],
156
- padding: ["padding-top", "padding-right", "padding-bottom", "padding-left"],
157
- "padding-block": ["padding-block-start", "padding-block-end"],
158
- "padding-inline": ["padding-inline-start", "padding-inline-end"],
159
- "place-content": ["align-content", "justify-content"],
160
- "place-items": ["align-items", "justify-items"],
161
- "place-self": ["align-self", "justify-self"],
162
- "scroll-margin": [
163
- "scroll-margin-top",
164
- "scroll-margin-right",
165
- "scroll-margin-bottom",
166
- "scroll-margin-left"
167
- ],
168
- "scroll-margin-block": ["scroll-margin-block-start", "scroll-margin-block-end"],
169
- "scroll-margin-inline": ["scroll-margin-inline-start", "scroll-margin-inline-end"],
170
- "scroll-padding": [
171
- "scroll-padding-top",
172
- "scroll-padding-right",
173
- "scroll-padding-bottom",
174
- "scroll-padding-left"
175
- ],
176
- "scroll-padding-block": ["scroll-padding-block-start", "scroll-padding-block-end"],
177
- "scroll-padding-inline": ["scroll-padding-inline-start", "scroll-padding-inline-end"],
178
- "scroll-timeline": ["scroll-timeline-name", "scroll-timeline-axis"],
179
- "text-decoration": [
180
- "text-decoration-line",
181
- "text-decoration-style",
182
- "text-decoration-color",
183
- "text-decoration-thickness"
184
- ],
185
- "text-emphasis": ["text-emphasis-style", "text-emphasis-color"],
186
- transition: [
187
- "transition-property",
188
- "transition-duration",
189
- "transition-timing-function",
190
- "transition-delay"
191
- ]
6
+ var _LONGHANDS = Symbol();
7
+ var cache = {};
8
+ var css = (baseStyles, ...overrides) => {
9
+ const cacheId = JSON.stringify({ baseStyles, overrides });
10
+ const cached = cache[cacheId];
11
+ if (cached)
12
+ return cached;
13
+ let overriddenStyles = Object.assign({}, baseStyles);
14
+ overrides.forEach((overrideStyle) => {
15
+ if (!overrideStyle)
16
+ return;
17
+ for (let key in overrideStyle) {
18
+ const tokenProperty2 = key;
19
+ const property = Tokenami.getTokenPropertyName(tokenProperty2);
20
+ override(overriddenStyles, property);
21
+ }
22
+ Object.assign(overriddenStyles, overrideStyle);
23
+ });
24
+ Object.entries(overriddenStyles).forEach(([property, value]) => {
25
+ const tokenProperty2 = Tokenami.TokenProperty.safeParse(property);
26
+ if (tokenProperty2.success && typeof value === "number" && value > 0) {
27
+ const gridVar = Tokenami.gridProperty();
28
+ overriddenStyles[tokenProperty2.output] = `calc(var(${gridVar}) * ${value})`;
29
+ }
30
+ });
31
+ cache[cacheId] = overriddenStyles;
32
+ return overriddenStyles;
192
33
  };
193
-
194
- // src/css.ts
195
- var SHORTHANDS_TO_LONGHANDS = Symbol.for("tokenamiShorthandToLonghands");
196
- function css(baseStyles, variantsConfig, options) {
197
- const cache = {};
198
- return function generate(variants, ...overrides) {
199
- const cacheId = JSON.stringify({ variants, overrides });
34
+ css[_LONGHANDS] = Tokenami.mapShorthandToLonghands;
35
+ css.compose = (config) => {
36
+ const { variants, responsiveVariants, ...baseStyles } = config;
37
+ return function generate(selectedVariants, ...overrides) {
38
+ const cacheId = JSON.stringify({
39
+ baseStyles,
40
+ variants,
41
+ responsiveVariants,
42
+ selectedVariants,
43
+ overrides
44
+ });
200
45
  const cached = cache[cacheId];
201
46
  if (cached)
202
47
  return cached;
203
- const variantStyles = variants ? Object.entries(variants).flatMap(([key, variant]) => {
204
- var _a;
48
+ const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
49
+ var _a, _b, _c;
205
50
  if (!variant)
206
51
  return [];
207
52
  const [type, bp] = key.split("_").reverse();
208
- const styles = (_a = variantsConfig == null ? void 0 : variantsConfig[type]) == null ? void 0 : _a[variant];
209
- const responsive = options == null ? void 0 : options.responsive;
210
- const updated = responsive && bp && styles ? convertToMediaStyles(bp, styles) : styles;
211
- return updated ? [updated] : [];
212
- }) : [];
213
- const overrideStyles = [...variantStyles, ...overrides];
214
- let css2 = Object.assign({}, baseStyles);
215
- overrideStyles.forEach((overrideStyle) => {
216
- if (overrideStyle) {
217
- for (let tokenProperty2 in overrideStyle) {
218
- const property = Tokenami.getTokenPropertyName(tokenProperty2);
219
- override(css2, property);
220
- }
221
- Object.assign(css2, overrideStyle);
53
+ if (bp) {
54
+ const styles2 = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
55
+ return styles2 ? [convertToMediaStyles(bp, styles2)] : [];
56
+ } else {
57
+ const styles2 = (_c = (_b = variants || responsiveVariants) == null ? void 0 : _b[type]) == null ? void 0 : _c[variant];
58
+ return styles2 ? [styles2] : [];
222
59
  }
223
- });
224
- cache[cacheId] = css2;
225
- return css2;
60
+ }) : [];
61
+ const styles = css(baseStyles, ...variantStyles, ...overrides);
62
+ cache[cacheId] = styles;
63
+ return styles;
226
64
  };
227
- }
228
- css[SHORTHANDS_TO_LONGHANDS] = mapShorthandToLonghands;
65
+ };
66
+ css[_LONGHANDS] = Tokenami.mapShorthandToLonghands;
229
67
  function createCss(config) {
230
68
  if (!config.aliases)
231
69
  return css;
232
- css[SHORTHANDS_TO_LONGHANDS] = { ...css[SHORTHANDS_TO_LONGHANDS], ...config.aliases };
70
+ css[_LONGHANDS] = Object.assign({}, css[_LONGHANDS], config.aliases);
233
71
  return css;
234
72
  }
235
73
  function override(style, property) {
236
- const longhands = css[SHORTHANDS_TO_LONGHANDS][property];
74
+ const longhands = css[_LONGHANDS][property];
237
75
  if (!longhands)
238
76
  return;
239
77
  for (let longhand of longhands) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenami/css",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -12,17 +12,17 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@tokenami/config": "0.0.21"
15
+ "@tokenami/config": "0.0.23"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tsup": "^7.0.0",
19
19
  "typescript": "^5.1.3",
20
20
  "vitest": "^0.34.6",
21
- "@tokenami/dev": "0.0.21"
21
+ "@tokenami/dev": "0.0.23"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "typescript": ">= 5",
25
- "@tokenami/dev": "0.0.21"
25
+ "@tokenami/dev": "0.0.23"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsup",