@tokenami/css 0.0.11
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 +21 -0
- package/README.md +3 -0
- package/dist/index.cjs +299 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +261 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 @jjenzz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
createConfig: () => import_config.createConfig,
|
|
34
|
+
createCss: () => createCss,
|
|
35
|
+
css: () => css,
|
|
36
|
+
defaultConfig: () => import_config.defaultConfig
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(src_exports);
|
|
39
|
+
var import_config = require("@tokenami/config");
|
|
40
|
+
|
|
41
|
+
// src/css.ts
|
|
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
|
+
]
|
|
229
|
+
};
|
|
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 });
|
|
237
|
+
const cached = cache[cacheId];
|
|
238
|
+
if (cached)
|
|
239
|
+
return cached;
|
|
240
|
+
const variantStyles = variants ? Object.entries(variants).flatMap(([key, variant]) => {
|
|
241
|
+
var _a;
|
|
242
|
+
if (!variant)
|
|
243
|
+
return [];
|
|
244
|
+
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
|
+
}
|
|
259
|
+
Object.assign(css2, overrideStyle);
|
|
260
|
+
});
|
|
261
|
+
cache[cacheId] = css2;
|
|
262
|
+
return css2;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
css[SHORTHANDS_TO_LONGHANDS] = mapShorthandToLonghands;
|
|
266
|
+
function createCss(config) {
|
|
267
|
+
if (!config.aliases)
|
|
268
|
+
return css;
|
|
269
|
+
css[SHORTHANDS_TO_LONGHANDS] = { ...css[SHORTHANDS_TO_LONGHANDS], ...config.aliases };
|
|
270
|
+
return css;
|
|
271
|
+
}
|
|
272
|
+
function override(style, property) {
|
|
273
|
+
const longhands = css[SHORTHANDS_TO_LONGHANDS][property];
|
|
274
|
+
if (!longhands)
|
|
275
|
+
return;
|
|
276
|
+
for (let longhand of longhands) {
|
|
277
|
+
const tokenProperty2 = Tokenami.tokenProperty(longhand);
|
|
278
|
+
if (style[tokenProperty2]) {
|
|
279
|
+
delete style[tokenProperty2];
|
|
280
|
+
}
|
|
281
|
+
override(style, longhand);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function convertToMediaStyles(bp, styles) {
|
|
285
|
+
const updatedEntries = Object.entries(styles).map(([property, value]) => {
|
|
286
|
+
const tokenPrefix = Tokenami.tokenProperty("");
|
|
287
|
+
const bpPrefix = Tokenami.variantProperty(bp, "");
|
|
288
|
+
const bpProperty = property.replace(tokenPrefix, bpPrefix);
|
|
289
|
+
return [bpProperty, value];
|
|
290
|
+
});
|
|
291
|
+
return Object.fromEntries(updatedEntries);
|
|
292
|
+
}
|
|
293
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
294
|
+
0 && (module.exports = {
|
|
295
|
+
createConfig,
|
|
296
|
+
createCss,
|
|
297
|
+
css,
|
|
298
|
+
defaultConfig
|
|
299
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as Tokenami from '@tokenami/config';
|
|
2
|
+
export { createConfig, defaultConfig } from '@tokenami/config';
|
|
3
|
+
import { TokenamiProperties, ResponsiveKey } from '@tokenami/dev';
|
|
4
|
+
|
|
5
|
+
type VariantsConfig = Record<string, Record<string, TokenamiProperties>>;
|
|
6
|
+
type VariantValue<T> = T extends 'true' | 'false' ? boolean : T;
|
|
7
|
+
type ResponsiveValue<T> = T extends string ? ResponsiveKey extends `${infer R}` ? `${R}_${T}` : never : never;
|
|
8
|
+
type Override = TokenamiProperties | false | undefined;
|
|
9
|
+
type Variants$1<C> = {
|
|
10
|
+
[V in keyof C]?: VariantValue<keyof C[V]>;
|
|
11
|
+
};
|
|
12
|
+
type ResponsiveVariants<C> = {
|
|
13
|
+
[V in keyof C]: {
|
|
14
|
+
[M in ResponsiveValue<V>]?: VariantValue<keyof C[V]>;
|
|
15
|
+
};
|
|
16
|
+
}[keyof C];
|
|
17
|
+
type SelectedVariants<V, R> = undefined extends V ? null : Variants$1<V> & (R extends true ? ResponsiveVariants<V> : {});
|
|
18
|
+
declare function css<V extends VariantsConfig | undefined, R>(baseStyles: TokenamiProperties, variantsConfig?: V & VariantsConfig, options?: undefined extends V ? never : {
|
|
19
|
+
responsive: R & boolean;
|
|
20
|
+
}): (variants?: SelectedVariants<V, R>, ...overrides: Override[]) => {};
|
|
21
|
+
declare function createCss(config: Tokenami.Config): typeof css;
|
|
22
|
+
|
|
23
|
+
type Variants<T extends () => {}> = Parameters<T>[0] extends undefined | null ? {} : NonNullable<Parameters<T>[0]>;
|
|
24
|
+
|
|
25
|
+
export { Variants, createCss, css };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createConfig, defaultConfig } from "@tokenami/config";
|
|
3
|
+
|
|
4
|
+
// src/css.ts
|
|
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
|
+
]
|
|
192
|
+
};
|
|
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 });
|
|
200
|
+
const cached = cache[cacheId];
|
|
201
|
+
if (cached)
|
|
202
|
+
return cached;
|
|
203
|
+
const variantStyles = variants ? Object.entries(variants).flatMap(([key, variant]) => {
|
|
204
|
+
var _a;
|
|
205
|
+
if (!variant)
|
|
206
|
+
return [];
|
|
207
|
+
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
|
+
}
|
|
222
|
+
Object.assign(css2, overrideStyle);
|
|
223
|
+
});
|
|
224
|
+
cache[cacheId] = css2;
|
|
225
|
+
return css2;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
css[SHORTHANDS_TO_LONGHANDS] = mapShorthandToLonghands;
|
|
229
|
+
function createCss(config) {
|
|
230
|
+
if (!config.aliases)
|
|
231
|
+
return css;
|
|
232
|
+
css[SHORTHANDS_TO_LONGHANDS] = { ...css[SHORTHANDS_TO_LONGHANDS], ...config.aliases };
|
|
233
|
+
return css;
|
|
234
|
+
}
|
|
235
|
+
function override(style, property) {
|
|
236
|
+
const longhands = css[SHORTHANDS_TO_LONGHANDS][property];
|
|
237
|
+
if (!longhands)
|
|
238
|
+
return;
|
|
239
|
+
for (let longhand of longhands) {
|
|
240
|
+
const tokenProperty2 = Tokenami.tokenProperty(longhand);
|
|
241
|
+
if (style[tokenProperty2]) {
|
|
242
|
+
delete style[tokenProperty2];
|
|
243
|
+
}
|
|
244
|
+
override(style, longhand);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function convertToMediaStyles(bp, styles) {
|
|
248
|
+
const updatedEntries = Object.entries(styles).map(([property, value]) => {
|
|
249
|
+
const tokenPrefix = Tokenami.tokenProperty("");
|
|
250
|
+
const bpPrefix = Tokenami.variantProperty(bp, "");
|
|
251
|
+
const bpProperty = property.replace(tokenPrefix, bpPrefix);
|
|
252
|
+
return [bpProperty, value];
|
|
253
|
+
});
|
|
254
|
+
return Object.fromEntries(updatedEntries);
|
|
255
|
+
}
|
|
256
|
+
export {
|
|
257
|
+
createConfig,
|
|
258
|
+
createCss,
|
|
259
|
+
css,
|
|
260
|
+
defaultConfig
|
|
261
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokenami/css",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"repository": "https://github.com/tokenami/tokenami",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@tokenami/config": "0.0.11"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"tsup": "^7.0.0",
|
|
19
|
+
"typescript": "^5.1.3",
|
|
20
|
+
"vitest": "^0.34.6",
|
|
21
|
+
"@tokenami/dev": "0.0.11"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"typescript": ">= 5",
|
|
25
|
+
"@tokenami/dev": "0.0.11"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"dev": "pnpm build --watch src",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"typecheck:ci": "pnpm typecheck",
|
|
32
|
+
"test": "vitest --run",
|
|
33
|
+
"test:watch": "vitest"
|
|
34
|
+
}
|
|
35
|
+
}
|