@tokenami/css 0.0.77 → 0.0.78--canary.391.13467326933.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 +105 -63
- package/dist/index.d.cts +15 -10
- package/dist/index.d.ts +15 -10
- package/dist/index.js +105 -63
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -24,101 +24,143 @@ var Tokenami__namespace = /*#__PURE__*/_interopNamespace(Tokenami);
|
|
|
24
24
|
|
|
25
25
|
// src/index.ts
|
|
26
26
|
var _TOKENAMI_CSS = Symbol.for("@tokenami/css");
|
|
27
|
-
var
|
|
28
|
-
limit: 500,
|
|
29
|
-
cache: /* @__PURE__ */ new Map(),
|
|
30
|
-
get(key) {
|
|
31
|
-
const value = this.cache.get(key);
|
|
32
|
-
if (!value)
|
|
33
|
-
return;
|
|
34
|
-
this.cache.delete(key);
|
|
35
|
-
this.cache.set(key, value);
|
|
36
|
-
return value;
|
|
37
|
-
},
|
|
38
|
-
set(key, value) {
|
|
39
|
-
this.cache.delete(key);
|
|
40
|
-
if (this.cache.size === this.limit)
|
|
41
|
-
this.cache.delete(this.cache.keys().next().value);
|
|
42
|
-
this.cache.set(key, value);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
27
|
+
var _COMPOSE = Symbol();
|
|
45
28
|
function createCss(config, options = { escapeSpecialChars: true }) {
|
|
46
29
|
globalThis[_TOKENAMI_CSS] = options;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const cacheId = JSON.stringify({ baseStyles, overrides });
|
|
51
|
-
const cached = cache.get(cacheId);
|
|
30
|
+
function css2(...allStyles) {
|
|
31
|
+
const cacheId = generateCacheId(allStyles);
|
|
32
|
+
const cached = lruCache.get(cacheId);
|
|
52
33
|
if (cached)
|
|
53
34
|
return cached;
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
const opts = globalThis[_TOKENAMI_CSS];
|
|
36
|
+
const overriddenStyles = { [_COMPOSE]: {} };
|
|
37
|
+
for (const styles of allStyles) {
|
|
38
|
+
if (!styles)
|
|
57
39
|
continue;
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
const composeEntries = Object.entries(styles[_COMPOSE] ?? {});
|
|
41
|
+
const entries = [...composeEntries, ...Object.entries(styles)];
|
|
42
|
+
const aliasProperties = Tokenami__namespace.iterateAliasProperties(entries, config);
|
|
43
|
+
for (const [key, value, propertyConfig] of aliasProperties) {
|
|
44
|
+
const tokenProperty2 = Tokenami__namespace.TokenProperty.safeParse(key);
|
|
45
|
+
const isComposedProperty = styles[_COMPOSE]?.[key] != null;
|
|
46
|
+
if (!tokenProperty2.success) {
|
|
60
47
|
overriddenStyles[key] = value;
|
|
61
48
|
continue;
|
|
62
49
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const longProperty = createLonghandProperty(tokenProperty2, cssProperty);
|
|
68
|
-
const isNumber = typeof value === "number" && value !== 0;
|
|
69
|
-
const parsedProperty = Tokenami__namespace.parseProperty(longProperty, globalOptions);
|
|
50
|
+
for (const cssProperty of propertyConfig.cssProperties) {
|
|
51
|
+
const longProperty = Tokenami__namespace.createLonghandProperty(tokenProperty2.output, cssProperty);
|
|
52
|
+
const parsedProperty = Tokenami__namespace.parseProperty(longProperty, opts);
|
|
53
|
+
const calcToggle = Tokenami__namespace.calcProperty(parsedProperty);
|
|
70
54
|
overrideLonghands(overriddenStyles, parsedProperty);
|
|
71
|
-
overriddenStyles[parsedProperty]
|
|
72
|
-
|
|
55
|
+
const target = isComposedProperty && !overriddenStyles[_COMPOSE][parsedProperty] ? overriddenStyles[_COMPOSE] : overriddenStyles;
|
|
56
|
+
target[parsedProperty] = value;
|
|
57
|
+
if (isComposedProperty)
|
|
58
|
+
continue;
|
|
59
|
+
if (propertyConfig.isCalc)
|
|
60
|
+
overriddenStyles[calcToggle] = "/*on*/";
|
|
61
|
+
else
|
|
62
|
+
delete overriddenStyles[calcToggle];
|
|
73
63
|
}
|
|
74
64
|
}
|
|
75
65
|
}
|
|
76
|
-
|
|
66
|
+
lruCache.set(cacheId, overriddenStyles);
|
|
77
67
|
return overriddenStyles;
|
|
78
|
-
}
|
|
79
|
-
css2.compose = (
|
|
80
|
-
const { variants, responsiveVariants, ...baseStyles } =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
68
|
+
}
|
|
69
|
+
css2.compose = (styleConfig) => {
|
|
70
|
+
const { includes = [], variants, responsiveVariants, ...baseStyles } = styleConfig;
|
|
71
|
+
const className = Tokenami__namespace.generateClassName(baseStyles);
|
|
72
|
+
return function generate(selectedVariants = {}) {
|
|
73
|
+
const cacheId = generateCacheId({ styleConfig, selectedVariants });
|
|
74
|
+
const cached = lruCache.get(cacheId);
|
|
84
75
|
if (cached)
|
|
85
76
|
return cached;
|
|
77
|
+
const variantEntries = Object.entries(selectedVariants);
|
|
86
78
|
let variantStyles = [];
|
|
87
|
-
|
|
79
|
+
let includeStyles = [];
|
|
80
|
+
let includeClassNames = [];
|
|
81
|
+
for (const include of includes) {
|
|
82
|
+
if (typeof include === "function") {
|
|
83
|
+
const [cn2, styles] = include(selectedVariants);
|
|
84
|
+
includeClassNames.push(cn2());
|
|
85
|
+
includeStyles.push(styles());
|
|
86
|
+
} else {
|
|
87
|
+
includeStyles.push(include);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const [key, variant] of variantEntries) {
|
|
88
91
|
if (!variant)
|
|
89
92
|
continue;
|
|
90
93
|
const [type, bp] = key.split("_").reverse();
|
|
91
94
|
const responsive = responsiveVariants?.[type]?.[variant];
|
|
95
|
+
const variantValue = variants?.[type]?.[variant] ?? responsive;
|
|
92
96
|
if (bp && responsive) {
|
|
93
97
|
variantStyles.push(convertToMediaStyles(bp, responsive));
|
|
94
|
-
} else {
|
|
95
|
-
variantStyles.push(
|
|
98
|
+
} else if (variantValue) {
|
|
99
|
+
variantStyles.push(variantValue);
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
const result = [
|
|
103
|
+
cn.bind(null, ...includeClassNames, className),
|
|
104
|
+
(...overrides) => {
|
|
105
|
+
const styles = { [_COMPOSE]: baseStyles };
|
|
106
|
+
const base = css2(styles, ...variantStyles, ...overrides);
|
|
107
|
+
return css2.apply(null, [...includeStyles, base]);
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
lruCache.set(cacheId, result);
|
|
111
|
+
return result;
|
|
101
112
|
};
|
|
102
113
|
};
|
|
103
114
|
return css2;
|
|
104
115
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
function generateCacheId(obj) {
|
|
117
|
+
return JSON.stringify(obj, (_, value) => {
|
|
118
|
+
if (typeof value === "object" && value !== null) {
|
|
119
|
+
const newValue = { ...value };
|
|
120
|
+
const symbols = Object.getOwnPropertySymbols(value);
|
|
121
|
+
for (const sym of symbols) {
|
|
122
|
+
newValue[sym.toString()] = value[sym];
|
|
123
|
+
}
|
|
124
|
+
return newValue;
|
|
113
125
|
}
|
|
114
|
-
|
|
126
|
+
return value;
|
|
115
127
|
});
|
|
116
128
|
}
|
|
117
|
-
var
|
|
118
|
-
|
|
129
|
+
var lruCache = {
|
|
130
|
+
limit: 1500,
|
|
131
|
+
cache: /* @__PURE__ */ new Map(),
|
|
132
|
+
get(key) {
|
|
133
|
+
const value = this.cache.get(key);
|
|
134
|
+
if (!value)
|
|
135
|
+
return;
|
|
136
|
+
this.cache.delete(key);
|
|
137
|
+
this.cache.set(key, value);
|
|
138
|
+
return value;
|
|
139
|
+
},
|
|
140
|
+
set(key, value) {
|
|
141
|
+
this.cache.delete(key);
|
|
142
|
+
if (this.cache.size === this.limit)
|
|
143
|
+
this.cache.delete(this.cache.keys().next().value);
|
|
144
|
+
this.cache.set(key, value);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
function cn(...classNames) {
|
|
148
|
+
return classNames.filter(Boolean).join(" ");
|
|
149
|
+
}
|
|
150
|
+
function overrideLonghands(style, tokenProperty2) {
|
|
119
151
|
const parts = Tokenami__namespace.getTokenPropertySplit(tokenProperty2);
|
|
120
|
-
const
|
|
121
|
-
|
|
152
|
+
const longhands = Tokenami__namespace.mapShorthandToLonghands.get(parts.alias) || [];
|
|
153
|
+
for (const longhand of longhands) {
|
|
154
|
+
const tokenPropertyLong = Tokenami__namespace.createLonghandProperty(tokenProperty2, longhand);
|
|
155
|
+
const calcProp = Tokenami__namespace.calcProperty(tokenPropertyLong);
|
|
156
|
+
const composedValue = style[_COMPOSE]?.[tokenPropertyLong];
|
|
157
|
+
const value = composedValue ?? style[tokenPropertyLong];
|
|
158
|
+
const isNumber = typeof value === "number";
|
|
159
|
+
composedValue ? style[tokenPropertyLong] = "initial" : delete style[tokenPropertyLong];
|
|
160
|
+
if (isNumber)
|
|
161
|
+
composedValue ? style[calcProp] = "initial" : delete style[calcProp];
|
|
162
|
+
overrideLonghands(style, tokenPropertyLong);
|
|
163
|
+
}
|
|
122
164
|
}
|
|
123
165
|
function convertToMediaStyles(bp, styles) {
|
|
124
166
|
const updatedEntries = Object.entries(styles).map(([property, value]) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -4,13 +4,14 @@ import * as Tokenami from '@tokenami/config';
|
|
|
4
4
|
export { Config, createConfig } from '@tokenami/config';
|
|
5
5
|
|
|
6
6
|
type TokenamiCSS = {
|
|
7
|
-
[_: symbol]:
|
|
7
|
+
[_: symbol]: TokenamiProperties;
|
|
8
8
|
};
|
|
9
9
|
type VariantsConfig = Record<string, Record<string, TokenamiProperties>>;
|
|
10
10
|
type VariantValue<T> = T extends 'true' | 'false' ? boolean : T;
|
|
11
11
|
type ReponsiveKey = Extract<keyof NonNullable<TokenamiFinalConfig['responsive']>, string>;
|
|
12
12
|
type ResponsiveValue<T> = T extends string ? `${ReponsiveKey}_${T}` : never;
|
|
13
13
|
type Override = TokenamiProperties | TokenamiCSS | false | undefined;
|
|
14
|
+
type ClassName = string | undefined | null | false;
|
|
14
15
|
type Variants$1<C> = undefined extends C ? {} : {
|
|
15
16
|
[V in keyof C]?: VariantValue<keyof C[V]>;
|
|
16
17
|
};
|
|
@@ -19,30 +20,34 @@ type ResponsiveVariants<C> = undefined extends C ? {} : {
|
|
|
19
20
|
[M in ResponsiveValue<V>]?: VariantValue<keyof C[V]>;
|
|
20
21
|
};
|
|
21
22
|
}[keyof C];
|
|
22
|
-
type
|
|
23
|
+
type TokenamiComposeInput<V, R> = TokenamiProperties & {
|
|
24
|
+
includes?: (TokenamiComposeResult<any, any> | TokenamiCSS)[];
|
|
23
25
|
variants?: V & VariantsConfig;
|
|
24
26
|
responsiveVariants?: R & VariantsConfig;
|
|
25
27
|
};
|
|
26
|
-
|
|
27
|
-
(baseStyles: TokenamiProperties, ...overrides: Override[]): TokenamiCSS;
|
|
28
|
-
compose: <V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(config: ComposeCSS<V, R>) => (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>, ...overrides: Override[]) => TokenamiCSS;
|
|
29
|
-
}
|
|
28
|
+
type TokenamiComposeResult<V, R> = (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>) => [cn: (...classNames: ClassName[]) => string, style: (...overrides: Override[]) => TokenamiCSS];
|
|
30
29
|
type CreateCssOptions = {
|
|
31
30
|
/**
|
|
32
31
|
* When using arbitrary values, Tokenami will escape special characters. Some frameworks
|
|
33
32
|
* automatically escape so this would result in double-escaping. In that case, switch this
|
|
34
|
-
* off to hand
|
|
33
|
+
* off to hand over to your framework.
|
|
35
34
|
*
|
|
36
35
|
* @default true
|
|
37
36
|
*/
|
|
38
37
|
escapeSpecialChars?: boolean;
|
|
39
38
|
};
|
|
40
|
-
declare function createCss(config: Pick<Tokenami.Config, 'aliases'>, options?: CreateCssOptions):
|
|
41
|
-
|
|
39
|
+
declare function createCss(config: Pick<Tokenami.Config, 'aliases'>, options?: CreateCssOptions): {
|
|
40
|
+
(allStyles_0: TokenamiProperties, ...allStyles_1: Override[]): TokenamiCSS;
|
|
41
|
+
compose<V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(styleConfig: TokenamiComposeInput<V, R>): TokenamiComposeResult<V, R>;
|
|
42
|
+
};
|
|
43
|
+
declare const css: {
|
|
44
|
+
(allStyles_0: TokenamiProperties, ...allStyles_1: Override[]): TokenamiCSS;
|
|
45
|
+
compose<V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(styleConfig: TokenamiComposeInput<V, R>): TokenamiComposeResult<V, R>;
|
|
46
|
+
};
|
|
42
47
|
|
|
43
48
|
type TokenamiStyle<P> = Omit<P, 'style'> & {
|
|
44
49
|
style?: (TokenamiProperties | TokenamiCSS) & ('style' extends keyof P ? P['style'] : {});
|
|
45
50
|
};
|
|
46
51
|
type Variants<T extends (...args: any) => any> = Parameters<T>[0] extends undefined | null ? {} : NonNullable<Parameters<T>[0]>;
|
|
47
52
|
|
|
48
|
-
export { type
|
|
53
|
+
export { type TokenamiCSS, type TokenamiStyle, type Variants, createCss, css };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ import * as Tokenami from '@tokenami/config';
|
|
|
4
4
|
export { Config, createConfig } from '@tokenami/config';
|
|
5
5
|
|
|
6
6
|
type TokenamiCSS = {
|
|
7
|
-
[_: symbol]:
|
|
7
|
+
[_: symbol]: TokenamiProperties;
|
|
8
8
|
};
|
|
9
9
|
type VariantsConfig = Record<string, Record<string, TokenamiProperties>>;
|
|
10
10
|
type VariantValue<T> = T extends 'true' | 'false' ? boolean : T;
|
|
11
11
|
type ReponsiveKey = Extract<keyof NonNullable<TokenamiFinalConfig['responsive']>, string>;
|
|
12
12
|
type ResponsiveValue<T> = T extends string ? `${ReponsiveKey}_${T}` : never;
|
|
13
13
|
type Override = TokenamiProperties | TokenamiCSS | false | undefined;
|
|
14
|
+
type ClassName = string | undefined | null | false;
|
|
14
15
|
type Variants$1<C> = undefined extends C ? {} : {
|
|
15
16
|
[V in keyof C]?: VariantValue<keyof C[V]>;
|
|
16
17
|
};
|
|
@@ -19,30 +20,34 @@ type ResponsiveVariants<C> = undefined extends C ? {} : {
|
|
|
19
20
|
[M in ResponsiveValue<V>]?: VariantValue<keyof C[V]>;
|
|
20
21
|
};
|
|
21
22
|
}[keyof C];
|
|
22
|
-
type
|
|
23
|
+
type TokenamiComposeInput<V, R> = TokenamiProperties & {
|
|
24
|
+
includes?: (TokenamiComposeResult<any, any> | TokenamiCSS)[];
|
|
23
25
|
variants?: V & VariantsConfig;
|
|
24
26
|
responsiveVariants?: R & VariantsConfig;
|
|
25
27
|
};
|
|
26
|
-
|
|
27
|
-
(baseStyles: TokenamiProperties, ...overrides: Override[]): TokenamiCSS;
|
|
28
|
-
compose: <V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(config: ComposeCSS<V, R>) => (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>, ...overrides: Override[]) => TokenamiCSS;
|
|
29
|
-
}
|
|
28
|
+
type TokenamiComposeResult<V, R> = (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>) => [cn: (...classNames: ClassName[]) => string, style: (...overrides: Override[]) => TokenamiCSS];
|
|
30
29
|
type CreateCssOptions = {
|
|
31
30
|
/**
|
|
32
31
|
* When using arbitrary values, Tokenami will escape special characters. Some frameworks
|
|
33
32
|
* automatically escape so this would result in double-escaping. In that case, switch this
|
|
34
|
-
* off to hand
|
|
33
|
+
* off to hand over to your framework.
|
|
35
34
|
*
|
|
36
35
|
* @default true
|
|
37
36
|
*/
|
|
38
37
|
escapeSpecialChars?: boolean;
|
|
39
38
|
};
|
|
40
|
-
declare function createCss(config: Pick<Tokenami.Config, 'aliases'>, options?: CreateCssOptions):
|
|
41
|
-
|
|
39
|
+
declare function createCss(config: Pick<Tokenami.Config, 'aliases'>, options?: CreateCssOptions): {
|
|
40
|
+
(allStyles_0: TokenamiProperties, ...allStyles_1: Override[]): TokenamiCSS;
|
|
41
|
+
compose<V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(styleConfig: TokenamiComposeInput<V, R>): TokenamiComposeResult<V, R>;
|
|
42
|
+
};
|
|
43
|
+
declare const css: {
|
|
44
|
+
(allStyles_0: TokenamiProperties, ...allStyles_1: Override[]): TokenamiCSS;
|
|
45
|
+
compose<V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(styleConfig: TokenamiComposeInput<V, R>): TokenamiComposeResult<V, R>;
|
|
46
|
+
};
|
|
42
47
|
|
|
43
48
|
type TokenamiStyle<P> = Omit<P, 'style'> & {
|
|
44
49
|
style?: (TokenamiProperties | TokenamiCSS) & ('style' extends keyof P ? P['style'] : {});
|
|
45
50
|
};
|
|
46
51
|
type Variants<T extends (...args: any) => any> = Parameters<T>[0] extends undefined | null ? {} : NonNullable<Parameters<T>[0]>;
|
|
47
52
|
|
|
48
|
-
export { type
|
|
53
|
+
export { type TokenamiCSS, type TokenamiStyle, type Variants, createCss, css };
|
package/dist/index.js
CHANGED
|
@@ -3,101 +3,143 @@ export { createConfig } from '@tokenami/config';
|
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
var _TOKENAMI_CSS = Symbol.for("@tokenami/css");
|
|
6
|
-
var
|
|
7
|
-
limit: 500,
|
|
8
|
-
cache: /* @__PURE__ */ new Map(),
|
|
9
|
-
get(key) {
|
|
10
|
-
const value = this.cache.get(key);
|
|
11
|
-
if (!value)
|
|
12
|
-
return;
|
|
13
|
-
this.cache.delete(key);
|
|
14
|
-
this.cache.set(key, value);
|
|
15
|
-
return value;
|
|
16
|
-
},
|
|
17
|
-
set(key, value) {
|
|
18
|
-
this.cache.delete(key);
|
|
19
|
-
if (this.cache.size === this.limit)
|
|
20
|
-
this.cache.delete(this.cache.keys().next().value);
|
|
21
|
-
this.cache.set(key, value);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
6
|
+
var _COMPOSE = Symbol();
|
|
24
7
|
function createCss(config, options = { escapeSpecialChars: true }) {
|
|
25
8
|
globalThis[_TOKENAMI_CSS] = options;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const cacheId = JSON.stringify({ baseStyles, overrides });
|
|
30
|
-
const cached = cache.get(cacheId);
|
|
9
|
+
function css2(...allStyles) {
|
|
10
|
+
const cacheId = generateCacheId(allStyles);
|
|
11
|
+
const cached = lruCache.get(cacheId);
|
|
31
12
|
if (cached)
|
|
32
13
|
return cached;
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
const opts = globalThis[_TOKENAMI_CSS];
|
|
15
|
+
const overriddenStyles = { [_COMPOSE]: {} };
|
|
16
|
+
for (const styles of allStyles) {
|
|
17
|
+
if (!styles)
|
|
36
18
|
continue;
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
const composeEntries = Object.entries(styles[_COMPOSE] ?? {});
|
|
20
|
+
const entries = [...composeEntries, ...Object.entries(styles)];
|
|
21
|
+
const aliasProperties = Tokenami.iterateAliasProperties(entries, config);
|
|
22
|
+
for (const [key, value, propertyConfig] of aliasProperties) {
|
|
23
|
+
const tokenProperty2 = Tokenami.TokenProperty.safeParse(key);
|
|
24
|
+
const isComposedProperty = styles[_COMPOSE]?.[key] != null;
|
|
25
|
+
if (!tokenProperty2.success) {
|
|
39
26
|
overriddenStyles[key] = value;
|
|
40
27
|
continue;
|
|
41
28
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const longProperty = createLonghandProperty(tokenProperty2, cssProperty);
|
|
47
|
-
const isNumber = typeof value === "number" && value !== 0;
|
|
48
|
-
const parsedProperty = Tokenami.parseProperty(longProperty, globalOptions);
|
|
29
|
+
for (const cssProperty of propertyConfig.cssProperties) {
|
|
30
|
+
const longProperty = Tokenami.createLonghandProperty(tokenProperty2.output, cssProperty);
|
|
31
|
+
const parsedProperty = Tokenami.parseProperty(longProperty, opts);
|
|
32
|
+
const calcToggle = Tokenami.calcProperty(parsedProperty);
|
|
49
33
|
overrideLonghands(overriddenStyles, parsedProperty);
|
|
50
|
-
overriddenStyles[parsedProperty]
|
|
51
|
-
|
|
34
|
+
const target = isComposedProperty && !overriddenStyles[_COMPOSE][parsedProperty] ? overriddenStyles[_COMPOSE] : overriddenStyles;
|
|
35
|
+
target[parsedProperty] = value;
|
|
36
|
+
if (isComposedProperty)
|
|
37
|
+
continue;
|
|
38
|
+
if (propertyConfig.isCalc)
|
|
39
|
+
overriddenStyles[calcToggle] = "/*on*/";
|
|
40
|
+
else
|
|
41
|
+
delete overriddenStyles[calcToggle];
|
|
52
42
|
}
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
|
-
|
|
45
|
+
lruCache.set(cacheId, overriddenStyles);
|
|
56
46
|
return overriddenStyles;
|
|
57
|
-
}
|
|
58
|
-
css2.compose = (
|
|
59
|
-
const { variants, responsiveVariants, ...baseStyles } =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
47
|
+
}
|
|
48
|
+
css2.compose = (styleConfig) => {
|
|
49
|
+
const { includes = [], variants, responsiveVariants, ...baseStyles } = styleConfig;
|
|
50
|
+
const className = Tokenami.generateClassName(baseStyles);
|
|
51
|
+
return function generate(selectedVariants = {}) {
|
|
52
|
+
const cacheId = generateCacheId({ styleConfig, selectedVariants });
|
|
53
|
+
const cached = lruCache.get(cacheId);
|
|
63
54
|
if (cached)
|
|
64
55
|
return cached;
|
|
56
|
+
const variantEntries = Object.entries(selectedVariants);
|
|
65
57
|
let variantStyles = [];
|
|
66
|
-
|
|
58
|
+
let includeStyles = [];
|
|
59
|
+
let includeClassNames = [];
|
|
60
|
+
for (const include of includes) {
|
|
61
|
+
if (typeof include === "function") {
|
|
62
|
+
const [cn2, styles] = include(selectedVariants);
|
|
63
|
+
includeClassNames.push(cn2());
|
|
64
|
+
includeStyles.push(styles());
|
|
65
|
+
} else {
|
|
66
|
+
includeStyles.push(include);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const [key, variant] of variantEntries) {
|
|
67
70
|
if (!variant)
|
|
68
71
|
continue;
|
|
69
72
|
const [type, bp] = key.split("_").reverse();
|
|
70
73
|
const responsive = responsiveVariants?.[type]?.[variant];
|
|
74
|
+
const variantValue = variants?.[type]?.[variant] ?? responsive;
|
|
71
75
|
if (bp && responsive) {
|
|
72
76
|
variantStyles.push(convertToMediaStyles(bp, responsive));
|
|
73
|
-
} else {
|
|
74
|
-
variantStyles.push(
|
|
77
|
+
} else if (variantValue) {
|
|
78
|
+
variantStyles.push(variantValue);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
const result = [
|
|
82
|
+
cn.bind(null, ...includeClassNames, className),
|
|
83
|
+
(...overrides) => {
|
|
84
|
+
const styles = { [_COMPOSE]: baseStyles };
|
|
85
|
+
const base = css2(styles, ...variantStyles, ...overrides);
|
|
86
|
+
return css2.apply(null, [...includeStyles, base]);
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
lruCache.set(cacheId, result);
|
|
90
|
+
return result;
|
|
80
91
|
};
|
|
81
92
|
};
|
|
82
93
|
return css2;
|
|
83
94
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
function generateCacheId(obj) {
|
|
96
|
+
return JSON.stringify(obj, (_, value) => {
|
|
97
|
+
if (typeof value === "object" && value !== null) {
|
|
98
|
+
const newValue = { ...value };
|
|
99
|
+
const symbols = Object.getOwnPropertySymbols(value);
|
|
100
|
+
for (const sym of symbols) {
|
|
101
|
+
newValue[sym.toString()] = value[sym];
|
|
102
|
+
}
|
|
103
|
+
return newValue;
|
|
92
104
|
}
|
|
93
|
-
|
|
105
|
+
return value;
|
|
94
106
|
});
|
|
95
107
|
}
|
|
96
|
-
var
|
|
97
|
-
|
|
108
|
+
var lruCache = {
|
|
109
|
+
limit: 1500,
|
|
110
|
+
cache: /* @__PURE__ */ new Map(),
|
|
111
|
+
get(key) {
|
|
112
|
+
const value = this.cache.get(key);
|
|
113
|
+
if (!value)
|
|
114
|
+
return;
|
|
115
|
+
this.cache.delete(key);
|
|
116
|
+
this.cache.set(key, value);
|
|
117
|
+
return value;
|
|
118
|
+
},
|
|
119
|
+
set(key, value) {
|
|
120
|
+
this.cache.delete(key);
|
|
121
|
+
if (this.cache.size === this.limit)
|
|
122
|
+
this.cache.delete(this.cache.keys().next().value);
|
|
123
|
+
this.cache.set(key, value);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function cn(...classNames) {
|
|
127
|
+
return classNames.filter(Boolean).join(" ");
|
|
128
|
+
}
|
|
129
|
+
function overrideLonghands(style, tokenProperty2) {
|
|
98
130
|
const parts = Tokenami.getTokenPropertySplit(tokenProperty2);
|
|
99
|
-
const
|
|
100
|
-
|
|
131
|
+
const longhands = Tokenami.mapShorthandToLonghands.get(parts.alias) || [];
|
|
132
|
+
for (const longhand of longhands) {
|
|
133
|
+
const tokenPropertyLong = Tokenami.createLonghandProperty(tokenProperty2, longhand);
|
|
134
|
+
const calcProp = Tokenami.calcProperty(tokenPropertyLong);
|
|
135
|
+
const composedValue = style[_COMPOSE]?.[tokenPropertyLong];
|
|
136
|
+
const value = composedValue ?? style[tokenPropertyLong];
|
|
137
|
+
const isNumber = typeof value === "number";
|
|
138
|
+
composedValue ? style[tokenPropertyLong] = "initial" : delete style[tokenPropertyLong];
|
|
139
|
+
if (isNumber)
|
|
140
|
+
composedValue ? style[calcProp] = "initial" : delete style[calcProp];
|
|
141
|
+
overrideLonghands(style, tokenPropertyLong);
|
|
142
|
+
}
|
|
101
143
|
}
|
|
102
144
|
function convertToMediaStyles(bp, styles) {
|
|
103
145
|
const updatedEntries = Object.entries(styles).map(([property, value]) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenami/css",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.78--canary.391.13467326933.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"test:watch": "vitest"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@tokenami/config": "0.0.
|
|
37
|
+
"@tokenami/config": "0.0.78--canary.391.13467326933.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"tokenami": "0.0.
|
|
40
|
+
"tokenami": "0.0.78--canary.391.13467326933.0",
|
|
41
41
|
"tsup": "^7.0.0",
|
|
42
42
|
"typescript": "^5.1.3",
|
|
43
43
|
"vitest": "^0.34.6"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"tokenami": ">= 0",
|
|
47
47
|
"typescript": ">= 5"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3a94df9615df16ae83234c3cc9d153255167c5f2"
|
|
50
50
|
}
|