aliascss 1.4.7 → 1.5.1
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/CHANGELOG.md +51 -0
- package/bin/aliascss.js +118 -1
- package/dist/aliascss.js +1 -1
- package/jestconfig.json +1 -3
- package/lib/build/index.js +136 -19
- package/lib/classPrinter.d.ts +1 -1
- package/lib/classPrinter.js +351 -23
- package/lib/compilers/border.js +106 -27
- package/lib/compilers/clipPath.js +79 -6
- package/lib/compilers/color.js +150 -21
- package/lib/compilers/filter.js +90 -3
- package/lib/compilers/font.js +39 -11
- package/lib/compilers/gradient.js +43 -27
- package/lib/compilers/length.js +34 -9
- package/lib/compilers/shadow.js +60 -26
- package/lib/compilers/stringAndContent.js +39 -2
- package/lib/compilers/timingFunction.js +57 -6
- package/lib/compilers/transform.js +118 -48
- package/lib/compilers/transition.js +79 -11
- package/lib/compilers/url.js +53 -3
- package/lib/config.d.ts +1 -0
- package/lib/config.js +1 -0
- package/lib/custom-css-compilers.js +1 -68
- package/lib/index.d.ts +9 -9
- package/lib/node/compileFile-BK-291026.d.ts +27 -0
- package/lib/node/compileFile-BK-291026.js +309 -0
- package/lib/node/compileFile-bk.d.ts +14 -12
- package/lib/node/compileFile-bk.js +263 -252
- package/lib/node/compileFile.js +1 -1
- package/lib/node/extractClassNamesFromFile.js +208 -86
- package/lib/prebuild.d.ts +26 -0
- package/lib/prebuild.js +0 -6
- package/lib/prefix/element-selector.js +93 -20
- package/lib/prefix/extractPrefix.d.ts +1 -1
- package/lib/prefix/extractPrefix.js +113 -70
- package/lib/returnPropertyAndValue-bk-301026.d.ts +30 -0
- package/lib/returnPropertyAndValue-bk-301026.js +219 -0
- package/lib/returnPropertyAndValue.js +26 -25
- package/lib/returnStatement-bk-291026.d.ts +5 -0
- package/lib/returnStatement-bk-291026.js +470 -0
- package/lib/returnStatement.d.ts +1 -0
- package/lib/returnStatement.js +120 -29
- package/lib/utils/helper.js +16 -2
- package/lib/x-classes/x-bundle.d.ts +26 -0
- package/lib/x-classes/x-bundle.js +2 -1
- package/lib/x-classes/x-extras.js +1 -1
- package/lib/x-classes/x-form-components.js +2 -1
- package/lib/x-classes/x-row-col.d.ts +29 -0
- package/lib/x-classes/x-row-col.js +52 -0
- package/llms.txt +326 -0
- package/package.json +3 -1
- package/tsconfig.json +1 -0
- package/tsconfig.test.json +10 -0
package/lib/returnStatement.js
CHANGED
|
@@ -11,13 +11,82 @@ import { createCompilerObj, extractProperty } from "./utils/createCompilerObj.js
|
|
|
11
11
|
import config from "./config.js";
|
|
12
12
|
import cssProps from "./css-properties-all.js";
|
|
13
13
|
import { staticClassNamesAlias } from "./static/staticClassNamesAlias.js";
|
|
14
|
-
import postcss from "postcss";
|
|
15
14
|
import { splitByCommaOutsideParens, matchTrailingGroup, splitTopLevel, joinGroupItem } from "./utils/helper.js";
|
|
16
15
|
import cssCustomCompilers from "./custom-css-compilers.js";
|
|
17
16
|
// import customGroups from './prebuild.js';
|
|
18
17
|
const [staticClassNamesWithAlias, cssPropsWithAlias] = createCompilerObj(cssProps, config.globalValues);
|
|
19
18
|
const NAME = '[a-zA-Z_][\\w-]*(?:\\/[a-zA-Z_][\\w-]*)*';
|
|
20
19
|
const AS_EXPORT = new RegExp(`--as-(?<names>${NAME}|\\[${NAME}(?:,${NAME})*\\])$`);
|
|
20
|
+
// Built once per prefix value instead of on every class
|
|
21
|
+
let prefixCache = null;
|
|
22
|
+
const prefixRegex = (prefix) => {
|
|
23
|
+
if (!prefixCache || prefixCache.prefix !== prefix) {
|
|
24
|
+
prefixCache = { prefix, re: new RegExp('^' + prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '-') };
|
|
25
|
+
}
|
|
26
|
+
return prefixCache.re;
|
|
27
|
+
};
|
|
28
|
+
// Classes that clearly tried to be AliasCSS (used for warnings only)
|
|
29
|
+
const ACSS_SYNTAX = /^[@_\[]|^--|--as-|\[.*\]$/;
|
|
30
|
+
// Safety check for a generated statement before it is emitted.
|
|
31
|
+
// A single bad statement must never damage the CSS that comes after it, so we reject:
|
|
32
|
+
// - unbalanced (), [], {} → would swallow or close the following rules / layers
|
|
33
|
+
// - an unclosed quote → the rest of the stylesheet becomes part of a string
|
|
34
|
+
// - "/*" outside quotes → opens a comment that hides everything after it
|
|
35
|
+
// - "</style" anywhere → ends an inline <style> tag in server-rendered HTML
|
|
36
|
+
// - no "property:value" in {} → empty or meaningless rule
|
|
37
|
+
// Escaped characters (\( \[ \{ …) in selectors are skipped.
|
|
38
|
+
// (postcss.parse checked only syntax too, but put the whole parser in the browser bundle.)
|
|
39
|
+
export function isSafeCss(css) {
|
|
40
|
+
if (/<\/style/i.test(css))
|
|
41
|
+
return false;
|
|
42
|
+
const stack = [];
|
|
43
|
+
const pairs = { ')': '(', ']': '[', '}': '{' };
|
|
44
|
+
let quote = '';
|
|
45
|
+
for (let i = 0; i < css.length; i++) {
|
|
46
|
+
const c = css[i];
|
|
47
|
+
if (c === '\\') {
|
|
48
|
+
i++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (quote) {
|
|
52
|
+
if (c === quote)
|
|
53
|
+
quote = '';
|
|
54
|
+
else if (c === '\n')
|
|
55
|
+
return false; // CSS strings can't span lines
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (c === '"' || c === "'") {
|
|
59
|
+
quote = c;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (c === '/' && css[i + 1] === '*')
|
|
63
|
+
return false;
|
|
64
|
+
if (c === '(' || c === '[' || c === '{')
|
|
65
|
+
stack.push(c);
|
|
66
|
+
else if (c in pairs && stack.pop() !== pairs[c])
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return !quote && stack.length === 0 && /\{[^{}]*:[^{}]*\}/.test(css);
|
|
70
|
+
}
|
|
71
|
+
// ---- Authoring warnings (the CSS is still emitted; these point at likely mistakes) ----
|
|
72
|
+
// "+" or "-" without spaces inside calc()/min()/max()/clamp(): calc(100%-32px) is invalid CSS.
|
|
73
|
+
// var(...) is removed first so names like --space-2-5 don't trigger it.
|
|
74
|
+
const CALC_FN = /\b(?:calc|min|max|clamp)\(/;
|
|
75
|
+
const NO_SPACE_MATH = /(?:\d(?:%|[a-z]+)?|\))[+-](?=[\d.(]|var\b)/i;
|
|
76
|
+
function calcSpacingProblem(declaration) {
|
|
77
|
+
if (!CALC_FN.test(declaration))
|
|
78
|
+
return false;
|
|
79
|
+
let d = declaration;
|
|
80
|
+
let prev = '';
|
|
81
|
+
while (d !== prev) {
|
|
82
|
+
prev = d;
|
|
83
|
+
d = d.replace(/var\([^()]*\)/g, '0');
|
|
84
|
+
} // innermost var() first, kept as a number
|
|
85
|
+
return NO_SPACE_MATH.test(d);
|
|
86
|
+
}
|
|
87
|
+
// A pseudo-class after these pseudo-elements never matches (::before:hover).
|
|
88
|
+
// Not included on purpose: ::file-selector-button, ::-webkit-scrollbar*, ::part() — those allow it.
|
|
89
|
+
const PSEUDO_ELEMENT_THEN_CLASS = /::(?:before|after|placeholder|marker|selection|first-line|first-letter|backdrop)(?=:[a-z])/;
|
|
21
90
|
export const compiler = {
|
|
22
91
|
// cache will cache propertyAndValue
|
|
23
92
|
cache: { propertyAndValue: Object.assign({}, customStaticClassNames) },
|
|
@@ -62,11 +131,12 @@ export const compiler = {
|
|
|
62
131
|
}
|
|
63
132
|
}
|
|
64
133
|
// Budle atomice class name in new
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
134
|
+
// --as-name or --as-[name1,name2,…]: compile the group once per name
|
|
135
|
+
const asMatch = className.match(AS_EXPORT);
|
|
136
|
+
if ((_a = asMatch === null || asMatch === void 0 ? void 0 : asMatch.groups) === null || _a === void 0 ? void 0 : _a.names) {
|
|
137
|
+
const body = className.slice(0, asMatch.index);
|
|
138
|
+
const names = asMatch.groups.names.replace(/^\[|\]$/g, '').split(',');
|
|
139
|
+
return names.map((name) => this.group(body, name)).join('');
|
|
70
140
|
}
|
|
71
141
|
let unPrefixedClassName = className;
|
|
72
142
|
// check for [group-acss,]
|
|
@@ -88,11 +158,11 @@ export const compiler = {
|
|
|
88
158
|
}
|
|
89
159
|
// EONEW
|
|
90
160
|
let beforeClassNameSelector = '';
|
|
91
|
-
if (this.prefix
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
unPrefixedClassName = className.replace(
|
|
161
|
+
if (this.prefix) {
|
|
162
|
+
const re = prefixRegex(this.prefix);
|
|
163
|
+
if (!re.test(className))
|
|
164
|
+
return null;
|
|
165
|
+
unPrefixedClassName = className.replace(re, '');
|
|
96
166
|
}
|
|
97
167
|
if (!this.mediaTest)
|
|
98
168
|
this.mediaTest = createRegexForMedia(this.mediaSelector);
|
|
@@ -166,6 +236,15 @@ export const compiler = {
|
|
|
166
236
|
// ------------PostCSSParse
|
|
167
237
|
if (result) {
|
|
168
238
|
let stm = '';
|
|
239
|
+
if (bool !== true) {
|
|
240
|
+
const shown = as ? `${as} (${className})` : className;
|
|
241
|
+
if (calcSpacingProblem(result)) {
|
|
242
|
+
console.warn(`AliasCSS: "${shown}": "+" and "-" need spaces in calc(), write _-_ e.g. calc(100%_-_32px)`);
|
|
243
|
+
}
|
|
244
|
+
if (PSEUDO_ELEMENT_THEN_CLASS.test(elementAndPseudo)) {
|
|
245
|
+
console.warn(`AliasCSS: "${shown}": "${elementAndPseudo.trim()}" never matches; put the state first, e.g. --hover--before`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
169
248
|
className = (as ? as : className).replace(/([$.&%=\]\[@~,:*#+\(\)\/^/</>\\|])/g, '\\$1');
|
|
170
249
|
if (bool === true)
|
|
171
250
|
return result;
|
|
@@ -189,16 +268,17 @@ export const compiler = {
|
|
|
189
268
|
else {
|
|
190
269
|
stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
|
|
191
270
|
}
|
|
192
|
-
|
|
193
|
-
postcss.parse(stm);
|
|
271
|
+
if (isSafeCss(stm))
|
|
194
272
|
return stm;
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
console.log('Not a Valid CSS Statement, PostCSS Parse:', stm);
|
|
198
|
-
}
|
|
273
|
+
console.warn(`AliasCSS: "${as ? as : className}" produced invalid CSS:`, stm);
|
|
199
274
|
}
|
|
200
275
|
else {
|
|
201
|
-
|
|
276
|
+
// extractProperty returns [property, key] even when nothing matched, so test the property itself
|
|
277
|
+
const looksLikeAcss = ACSS_SYNTAX.test(className) || !!extractProperty(pnv, this.cssProps)[0];
|
|
278
|
+
if (!this.groupDepth && (looksLikeAcss || config.debug)) {
|
|
279
|
+
console.warn(`AliasCSS: can't compile "${className}"`);
|
|
280
|
+
}
|
|
281
|
+
// console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`)
|
|
202
282
|
}
|
|
203
283
|
},
|
|
204
284
|
makeNested(className, as, bool) {
|
|
@@ -332,13 +412,9 @@ export const compiler = {
|
|
|
332
412
|
else {
|
|
333
413
|
stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
|
|
334
414
|
}
|
|
335
|
-
|
|
336
|
-
postcss.parse(stm);
|
|
415
|
+
if (isSafeCss(stm))
|
|
337
416
|
return stm;
|
|
338
|
-
|
|
339
|
-
catch (error) {
|
|
340
|
-
console.log('Not a Valid CSS Statement, PostCSS Parse:', stm);
|
|
341
|
-
}
|
|
417
|
+
console.log('Not a Valid CSS Statement:', stm);
|
|
342
418
|
}
|
|
343
419
|
else {
|
|
344
420
|
console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`);
|
|
@@ -349,11 +425,26 @@ export const compiler = {
|
|
|
349
425
|
// },
|
|
350
426
|
group(str, as) {
|
|
351
427
|
let statement = '';
|
|
352
|
-
[
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
428
|
+
const failed = [];
|
|
429
|
+
this.groupDepth = (this.groupDepth || 0) + 1;
|
|
430
|
+
try {
|
|
431
|
+
[...str.trim().split(/\s+/)].forEach((e) => {
|
|
432
|
+
if (!e)
|
|
433
|
+
return;
|
|
434
|
+
const getEachClassNameCompiled = this.make(e, as);
|
|
435
|
+
if (getEachClassNameCompiled)
|
|
436
|
+
statement += getEachClassNameCompiled + ' \n';
|
|
437
|
+
else
|
|
438
|
+
failed.push(e);
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
this.groupDepth--;
|
|
443
|
+
}
|
|
444
|
+
// Items inside a group or statement are always meant as AliasCSS, so always report them
|
|
445
|
+
if (failed.length) {
|
|
446
|
+
console.warn(`AliasCSS: in "${as}", could not compile: ${failed.join(', ')}`);
|
|
447
|
+
}
|
|
357
448
|
return statement;
|
|
358
449
|
},
|
|
359
450
|
groupMulti(str, as) {
|
package/lib/utils/helper.js
CHANGED
|
@@ -4,8 +4,22 @@ export function splitByCommaOutsideParens(str) {
|
|
|
4
4
|
const result = [];
|
|
5
5
|
let current = '';
|
|
6
6
|
let depth = 0;
|
|
7
|
-
for (let i = 0; i < str.length; i++) {
|
|
8
|
-
|
|
7
|
+
// for (let i = 0; i < str.length; i++) {
|
|
8
|
+
// const char = str[i];
|
|
9
|
+
// if (char === '(') {
|
|
10
|
+
// depth++;
|
|
11
|
+
// current += char;
|
|
12
|
+
// } else if (char === ')') {
|
|
13
|
+
// depth = Math.max(0, depth - 1);
|
|
14
|
+
// current += char;
|
|
15
|
+
// } else if (char === ',' && depth === 0) {
|
|
16
|
+
// result.push(current.trim());
|
|
17
|
+
// current = '';
|
|
18
|
+
// } else {
|
|
19
|
+
// current += char;
|
|
20
|
+
// }
|
|
21
|
+
// }
|
|
22
|
+
for (const char of str) {
|
|
9
23
|
if (char === '(') {
|
|
10
24
|
depth++;
|
|
11
25
|
current += char;
|
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
declare const xComponents: {
|
|
2
|
+
'x-row': {
|
|
3
|
+
type: string;
|
|
4
|
+
compiler: (value: string) => string;
|
|
5
|
+
groups: {
|
|
6
|
+
'': string;
|
|
7
|
+
xs: string;
|
|
8
|
+
sm: string;
|
|
9
|
+
md: string;
|
|
10
|
+
lg: string;
|
|
11
|
+
xl: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
'x-col': {
|
|
15
|
+
type: string;
|
|
16
|
+
compiler: (value: string) => string;
|
|
17
|
+
groups: {
|
|
18
|
+
[k: string]: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
'x-col-offset': {
|
|
22
|
+
type: string;
|
|
23
|
+
compiler: (value: string) => string;
|
|
24
|
+
groups: {
|
|
25
|
+
[k: string]: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
2
28
|
'x-absolute-0': {
|
|
3
29
|
type: string;
|
|
4
30
|
statement: string;
|
|
@@ -7,5 +7,6 @@ import moreComponents from "./x-comps.js";
|
|
|
7
7
|
import layout from "./x-layout-components.js";
|
|
8
8
|
import menuComponents from "./x-menu.js";
|
|
9
9
|
import absoluteComponents from "./x-helper-components.js";
|
|
10
|
-
|
|
10
|
+
import xRowCol from "./x-row-col.js";
|
|
11
|
+
const xComponents = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, components), formComponents), moreComponents), navContent), themeComponents), tableComponents), layout), menuComponents), absoluteComponents), xRowCol);
|
|
11
12
|
export default xComponents;
|
|
@@ -52,7 +52,7 @@ const components = {
|
|
|
52
52
|
},
|
|
53
53
|
'x-card-elevated': {
|
|
54
54
|
type: 'statement',
|
|
55
|
-
statement: `--x-card-border-color:transparent --x-card-shadow:(0_1px_3px_rgb(16_24_40_/_0.1),0_1px_2px_rgb(16_24_40_/_0.06))`
|
|
55
|
+
statement: `--x-card-border-color:(light-dark(transparent,rgb(255_255_255_/_0.08))) --x-card-shadow:(0_1px_3px_rgb(16_24_40_/_0.1),0_1px_2px_rgb(16_24_40_/_0.06))`
|
|
56
56
|
},
|
|
57
57
|
'x-card-flat': {
|
|
58
58
|
type: 'statement',
|
|
@@ -60,6 +60,7 @@ const formComponents = {
|
|
|
60
60
|
@components[d-inline-flex,aic,jcc,g-8px,box-sizing-border-box,h--x-form-height:40px,padding-inline--x-button-padding:16px,br--x-form-radius:8px,border-width-1px,border-style-solid,border-color--x-button-border-color:transparent,bgc--x-button-bg:accentRA1000,c--x-button-color:white,fs--x-button-font-size:15px,fw-600,lh-1,white-space-nowrap,user-select-none,cursor-pointer,transition-property-background-color__border-color__color__transform,transition-duration-0.15s]
|
|
61
61
|
@components--enabled--hover-bgc--x-button-hover-bg:accentRA1100
|
|
62
62
|
@components--enabled--active-tf-scale-0.98
|
|
63
|
+
@components__svg-flex-shrink-0
|
|
63
64
|
${focusVisible}
|
|
64
65
|
@components--disabled[o-0.5,cursor-not-allowed]
|
|
65
66
|
@components-[aria-disabled=true][o-0.5,cursor-not-allowed,pointer-events-none]
|
|
@@ -88,7 +89,7 @@ const formComponents = {
|
|
|
88
89
|
'x-button-icon': {
|
|
89
90
|
// square icon-only button: <button class="x-button x-button-icon" aria-label="Close">…</button>
|
|
90
91
|
type: 'statement',
|
|
91
|
-
statement: `--x-button-padding:0px w--x-form-height:40px`
|
|
92
|
+
statement: `--x-button-padding:0px @components-[class][padding-inline-0,w--x-form-height:40px,flex-shrink-0]`
|
|
92
93
|
},
|
|
93
94
|
// ---------------- Text fields ----------------
|
|
94
95
|
// <input class="x-input" type="email">
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
'x-row': {
|
|
3
|
+
type: string;
|
|
4
|
+
compiler: (value: string) => string;
|
|
5
|
+
groups: {
|
|
6
|
+
'': string;
|
|
7
|
+
xs: string;
|
|
8
|
+
sm: string;
|
|
9
|
+
md: string;
|
|
10
|
+
lg: string;
|
|
11
|
+
xl: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
'x-col': {
|
|
15
|
+
type: string;
|
|
16
|
+
compiler: (value: string) => string;
|
|
17
|
+
groups: {
|
|
18
|
+
[k: string]: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
'x-col-offset': {
|
|
22
|
+
type: string;
|
|
23
|
+
compiler: (value: string) => string;
|
|
24
|
+
groups: {
|
|
25
|
+
[k: string]: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ------------------------------------------------------------------
|
|
2
|
+
// x-row / x-col: 12-column grid (Bootstrap-style), built on flex + gap.
|
|
3
|
+
//
|
|
4
|
+
// <div class="x-row"> gap 16px (default)
|
|
5
|
+
// <div class="x-row-lg"> gap 24px (xs 4, sm 8, md 16, lg 24, xl 32)
|
|
6
|
+
// <div class="x-row-20px"> any gap
|
|
7
|
+
// <div class="x-col-4">…</div> 4 of 12 columns
|
|
8
|
+
// <div class="x-col">…</div> fill the remaining space (equal share)
|
|
9
|
+
// <div class="x-col-auto">…</div> as wide as its content
|
|
10
|
+
// <div class="x-col-240px">…</div> fixed width
|
|
11
|
+
// <div class="x-col-offset-2 x-col-8">…</div> skip 2 columns
|
|
12
|
+
//
|
|
13
|
+
// Responsive: write every breakpoint explicitly (plain classes beat breakpoint classes):
|
|
14
|
+
// <div class="@xs-x-col-12 @sm-x-col-6 @lg-x-col-4">
|
|
15
|
+
//
|
|
16
|
+
// vars: --x-row-gap (16px), --x-row-gap-y (vertical gap, defaults to --x-row-gap)
|
|
17
|
+
// ------------------------------------------------------------------
|
|
18
|
+
const GAP = 'var(--x-row-gap,16px)';
|
|
19
|
+
const clean = (v) => v.trim().replace(/^-/, '');
|
|
20
|
+
// Width of N columns out of 12, with (12 - 1) gaps shared exactly
|
|
21
|
+
const spanWidth = (n) => `calc((100% - 11 * ${GAP}) / 12 * ${n} + (${n} - 1) * ${GAP})`;
|
|
22
|
+
const row = (gap) => `--x-row-gap:${gap};display:flex;flex-wrap:wrap;gap:var(--x-row-gap-y,var(--x-row-gap)) var(--x-row-gap);box-sizing:border-box;`;
|
|
23
|
+
const col = (v) => {
|
|
24
|
+
if (v === '' || v === 'fill')
|
|
25
|
+
return 'flex:1 1 0%;min-width:0;box-sizing:border-box;';
|
|
26
|
+
if (v === 'auto')
|
|
27
|
+
return 'flex:0 0 auto;width:auto;max-width:100%;box-sizing:border-box;';
|
|
28
|
+
if (/^([1-9]|1[0-2])$/.test(v))
|
|
29
|
+
return `flex:0 0 ${spanWidth(v)};max-width:100%;min-width:0;box-sizing:border-box;`;
|
|
30
|
+
return `flex:0 0 ${v};max-width:100%;min-width:0;box-sizing:border-box;`; // 240px, 30%, 20rem…
|
|
31
|
+
};
|
|
32
|
+
const offset = (v) => /^([0-9]|1[01])$/.test(v)
|
|
33
|
+
? `margin-inline-start:${v === '0' ? '0' : `calc((100% - 11 * ${GAP}) / 12 * ${v} + ${v} * ${GAP})`};`
|
|
34
|
+
: `margin-inline-start:${v};`;
|
|
35
|
+
const range12 = Array.from({ length: 12 }, (_, i) => String(i + 1));
|
|
36
|
+
export default {
|
|
37
|
+
'x-row': {
|
|
38
|
+
type: 'group',
|
|
39
|
+
compiler: (value) => row(clean(value) || '16px'),
|
|
40
|
+
groups: { '': row('16px'), xs: row('4px'), sm: row('8px'), md: row('16px'), lg: row('24px'), xl: row('32px') },
|
|
41
|
+
},
|
|
42
|
+
'x-col': {
|
|
43
|
+
type: 'group',
|
|
44
|
+
compiler: (value) => col(clean(value)),
|
|
45
|
+
groups: Object.fromEntries([...range12, '', 'fill', 'auto'].map(k => [k, col(k)])),
|
|
46
|
+
},
|
|
47
|
+
'x-col-offset': {
|
|
48
|
+
type: 'group',
|
|
49
|
+
compiler: (value) => offset(clean(value)),
|
|
50
|
+
groups: Object.fromEntries(['0', ...range12.slice(0, 11)].map(k => [k, offset(k)])),
|
|
51
|
+
},
|
|
52
|
+
};
|