aliascss 1.5.4 → 1.5.6

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.
@@ -1,131 +0,0 @@
1
- import {getCompiler,main} from './lib/index.js'
2
- import { compilers } from './custom-compilers.js';
3
- import prebuild from './lib/prebuild.js';
4
- const config={
5
- // input:['ui-dev/**/*.html','experiments/**/*.html'],
6
- input:['ui-dev/**/css-nono-test.html'],
7
- output:{
8
- location:'demo/css/css/style/acss.css',
9
- "--file":true
10
- },
11
- '--module':true,
12
- prefix:'',
13
- importModuleAs:'x',
14
- minify:true,
15
- extractorFunction:"x|@",
16
- //reg:new RegExp('x' + "(`|\\(["+`"'])`+ "(.+)" + "(`|" + `["']` + "\\))") ,
17
- media:{
18
- prefix:{
19
- xs:'@media (max-width : 24px)'
20
- }
21
- },
22
- extend:{
23
- // Note property cannot include uppercase/number character but first character uppercase allowed
24
- ...compilers,
25
- 'txt-shadow':{
26
- property:'--webkit-text-shadow',
27
- compiler:(value)=>{
28
- console.log(value);
29
- return value
30
- },
31
- },
32
- 'text':{
33
- property:'color',
34
- extend:'color',
35
- // compiler:(value)=>this.compiler(value)
36
- },
37
- $color:{extend:'color'},
38
- text:{
39
- property:'color',
40
- compiler:(value,custom)=>{
41
- return config.extend.$color.compiler(value,custom);
42
- },
43
- values:['red:danger']
44
- },
45
- // 'font-size':{
46
- // alias:'fs',
47
- // values:["2rem:xl"],
48
- // compiler:(value)=>{
49
- // return value;
50
- // }
51
- // },
52
- $padding:{extend:'padding'},
53
- // 'padding':{
54
- // alias:'p',
55
- // compiler:getCompiler('padding').compiler,
56
- // values:[...getCompiler('padding').values,'var(--padding-xs,4px):xs','8px:sm','12px:md','14px:lg','16px:xl','20px:xxl']
57
- // },
58
-
59
- 'shadows':{
60
- property:'box-shadow',
61
- //alias:'sdo',
62
- compiler:(value)=>{
63
- value=value.slice(1);
64
- const values={
65
- '3xl': ' 0px 32px 64px -12px var(--shadow-color)',
66
- '2xl': ' 0px 24px 48px -12px var(--shadow-color)',
67
- 'xl': ' 0px 20px 24px -4px var(--shadow-color)',
68
- 'lg': ' 0px 12px 16px -4px var(--shadow-color)',
69
- 'md': ' 0px 4px 8px -2px var(--shadow-color)',
70
- 'sm': ' 0px 1px 3px var(--shadow-color)',
71
- 'xs': ' 0px 1px 2px var(--shadow-color)',
72
- };
73
- if(values.hasOwnProperty(value)) return values[value];
74
- }
75
-
76
- }
77
- },
78
- //statement:``,
79
- custom:{
80
- colors:{
81
- white:'#e3e3e3',
82
- 'whiter':'#f3f3f3',
83
- whitest:'#ffffff',
84
- "primary":"#4E60FF",
85
- "primary-lightest":"#F8F9FF",
86
- "primary-light":"#F3F4FF",
87
- "primary-30":"#CACFFF",
88
- "primary-hover":"#697BFF",
89
- "primary-dark":"#3A4CEB",
90
-
91
- "black":"#2B2B43",
92
- "gray-dark":"#545563",
93
- "gray":"#83859C",
94
- "gray-light":"#C7C8D2",
95
- "gray-lightest":"#EDEEF2",
96
- "main-bg-color":"#F7F7F9",
97
-
98
- "error":"#FF5C60",
99
- "error-lightest":"#FFF6F6",
100
- "error-light":"#FFEAEA",
101
- "error-hover":"#FF6B6F",
102
- "error-dark":"#E13E42",
103
- "success":'#1ABF70',
104
- "success-light":'#E8F9F1',
105
- "secondary":"#FD6D22",
106
- "secondary-light":"#FFF3ED",
107
- "tertiary":"#8C3EEE",
108
- "tertiary-light":"#F6F0FE",
109
- }
110
- },
111
- prebuild:{
112
- 'colorize-dark':'background:#0f0f0f;color:#e3e3e3',
113
- //'x-clip-menu':'clip-path: polygon(0% 10%,100% 10%,100% 20%,0% 20%,0% 45%,100% 45%,100% 55%,0% 55%,0% 80%,100% 80%,100% 90%,0% 90%);',
114
-
115
- },
116
- group:{
117
- //...prebuild,
118
- //'x-card':"w-256px h-120px [class~=shadow]-bxs-0px-12px-24px-rgba-43-43-67-0d16 bgc-fff b-1px-s-gray-lightest br-16px --hover-bgc-primary-lightest --hover-b-1px-s-primary-hover --active[b-1px-s-primary,bgc-primary-light]",
119
- 'x-responsive':'xs-w-100p sm-w-540px md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
120
- 'x-responsive-sm':'xs-w-100p sm-w-540px md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
121
- 'x-responsive-md':'xs-w-100p sm-w-100p md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
122
- 'x-responsive-lg':'xs-w-100p sm-w-100p md-w-100p lg-w-960px xl-w-1140px 2xl-w-1320px',
123
- 'x-responsive-xl':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-w-1140px 2xl-w-1320px',
124
- 'x-responsive-2xl':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-w-100p 2xl-w-1320px',
125
- 'x-responsive-fluid':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-100p 2xl-100p',
126
- },
127
- statement:`.color{color:red}`,
128
- ignore:['bgc-red']
129
- }
130
- export default config;
131
-
@@ -1,50 +0,0 @@
1
- import {getCompiler,main} from './lib/index.js'
2
- import { compilers } from './custom-compilers.js';
3
- import prebuild from './lib/prebuild.js';
4
- const config={
5
- // input:['ui-dev/**/*.html','experiments/**/*.html'],
6
- input:['demo/**/*.html'],
7
- output:{
8
- location:'demo/acss.css',
9
- "--file":true
10
- },
11
- // '--module':true,
12
- // prefix:'',
13
- // importModuleAs:'x',
14
- // // minify:true,
15
- // extractorFunction:"String",
16
- // //reg:new RegExp('x' + "(`|\\(["+`"'])`+ "(.+)" + "(`|" + `["']` + "\\))") ,
17
- // media:{
18
- // prefix:{
19
- // xs:'@media (max-width : 24px)'
20
- // }
21
- // },
22
- // prebuild:{
23
- // 'colorize-dark':'background:#0f0f0f;color:#e3e3e3',
24
- // //'x-clip-menu':'clip-path: polygon(0% 10%,100% 10%,100% 20%,0% 20%,0% 45%,100% 45%,100% 55%,0% 55%,0% 80%,100% 80%,100% 90%,0% 90%);',
25
-
26
- // },
27
- // group:{
28
- // //...prebuild,
29
- // //'x-card':"w-256px h-120px [class~=shadow]-bxs-0px-12px-24px-rgba-43-43-67-0d16 bgc-fff b-1px-s-gray-lightest br-16px --hover-bgc-primary-lightest --hover-b-1px-s-primary-hover --active[b-1px-s-primary,bgc-primary-light]",
30
- // 'x-responsive':'xs-w-100p sm-w-540px md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
31
- // 'x-responsive-sm':'xs-w-100p sm-w-540px md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
32
- // 'x-responsive-md':'xs-w-100p sm-w-100p md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
33
- // 'x-responsive-lg':'xs-w-100p sm-w-100p md-w-100p lg-w-960px xl-w-1140px 2xl-w-1320px',
34
- // 'x-responsive-xl':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-w-1140px 2xl-w-1320px',
35
- // 'x-responsive-2xl':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-w-100p 2xl-w-1320px',
36
- // 'x-responsive-fluid':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-100p 2xl-100p',
37
- // 'btn':`\
38
- // [bgc-red,c-yellow]
39
- // --hover[c-blue,bgc-yellow]
40
- // `,
41
-
42
- // },
43
- // statement:`.color{color:red}`,
44
-
45
-
46
-
47
- // ignore:['bgc-red']
48
- }
49
- export default config;
50
-
@@ -1,61 +0,0 @@
1
- import {getCompiler} from './lib/index.js'
2
- export const compilers={
3
- 'x-square':{
4
- type:'group',
5
- compiler:(value)=>{
6
- const v=value.replace(/-([\d])/g,'$1');
7
- return `width:calc(${v} + var(--x-square-grow,0px) - var(--x-square-shrink,0px)); flex-basis:calc(${v} + var(--x-square-grow,0px) - var(--x-square-shrink,0px)); flex-shrink:0;flex-grow:0;height:calc(${v} + var(--x-square-grow,0px) - var(--x-square-shrink,0px))`;
8
- },
9
- },
10
- 'x-circle':{
11
- type:'group',
12
- compiler:(value)=>{
13
- const v=value.replace(/-([\d])/g,'$1');
14
- return `width:calc(${v} + var(--x-circle-grow,0px) - var(--x-circle-shrink,0px)); height:calc(${v} + var(--x-circle-grow,0px) - var(--x-circle-shrink,0px)); border-radius:50%;`;
15
- },
16
- },
17
- 'x-box':{
18
- type:'group',
19
- compiler:(value)=>{
20
- const property=['width','height','padding','margin'];
21
- let result='display:block; ';
22
- const match=/-([-]?[\w\.]+)/;
23
- value.match(new RegExp(match,'g')).forEach((e,i)=>{
24
- if(i<property.length){
25
- result+=`${property[i]}:${e.replace(match,'$1').replace(/(\d)d(\d)/,'$1.$2').replace(/([\d])p([\s]|$)/,'$1%$2')};`;
26
- }else{
27
- result=result.replace(/;$/,` ${e.replace(match,'$1').replace(/(\d)d(\d)/,'$1.$2').replace(/([\d])p([\s]|$)/,'$1%$2')};`)
28
- }
29
- })
30
- return result;
31
- },
32
- },
33
- 'Flex-box':{
34
- type:'group',
35
- compiler:(value)=>{
36
- const property=['flex-direction','justify-content','align-items','margin'];
37
- let result='display:flex; ';
38
- const match=/-([-]?[\w\.]+)/;
39
- value.match(new RegExp(match,'g')).forEach((e,i)=>{
40
- if(i<property.length){
41
- result+=`${property[i]}:${e.replace(match,'$1').replace(/(\d)d(\d)/,'$1.$2').replace(/([\d])p([\s]|$)/,'$1%$2')};`;
42
- }else{
43
- result=result.replace(/;$/,` ${e.replace(match,'$1').replace(/(\d)d(\d)/,'$1.$2').replace(/([\d])p([\s]|$)/,'$1%$2')};`)
44
- }
45
- })
46
- return result;
47
- },
48
- },
49
-
50
- }
51
-
52
- //Grid-box
53
- //Flex-child
54
- //Grid-child
55
- //Color
56
- //Container
57
- //Section
58
- //Text-size-lineHeight-letterSpacing-decoration
59
- //Border-borderWidth-borderStyle-Border-color-borderRadius
60
- //List
61
- //Table
@@ -1,216 +0,0 @@
1
- diff --git a/src/__tests__/dashedIdentTest.ts b/src/__tests__/dashedIdentTest.ts
2
- new file mode 100644
3
- index 0000000..25bb3bd
4
- --- /dev/null
5
- +++ b/src/__tests__/dashedIdentTest.ts
6
- @@ -0,0 +1,52 @@
7
- +import {describe, test, expect} from '@jest/globals';
8
- +import compileDashedIdent from '../compilers/dashedIdent.js';
9
- +import {createCompilerObj, extractProperty} from "../utils/createCompilerObj.js";
10
- +import cssProps from '../css-properties-all.js';
11
- +import cssCustomCompilers from "../custom-css-compilers.js";
12
- +import getPropertyAndValue from '../returnPropertyAndValue.js'
13
- +import config from "../config.js";
14
- +
15
- +const [staticClassNames, compilerObj] = createCompilerObj({...cssCustomCompilers, ...cssProps}, config.globalValues);
16
- +const pv = (c: string) => getPropertyAndValue(c, compilerObj, staticClassNames, {}, extractProperty);
17
- +
18
- +describe('Dashed-ident properties (anchor-name, timelines, position-try)', () => {
19
- + test('a bare word becomes a --name', () => {
20
- + expect(compileDashedIdent('anchor-name', '-menu')).toBe('--menu');
21
- + expect(compileDashedIdent('position-anchor', '-x-menu')).toBe('--x-menu');
22
- + });
23
- + test('names already written with dashes are not doubled', () => {
24
- + expect(compileDashedIdent('anchor-name', '--menu')).toBe('--menu');
25
- + expect(compileDashedIdent('anchor-name', '---menu')).toBe('--menu');
26
- + });
27
- + test('__ separates names', () => {
28
- + expect(compileDashedIdent('timeline-scope', '-a__b')).toBe('--a, --b');
29
- + });
30
- + test('keywords stay keywords', () => {
31
- + expect(compileDashedIdent('position-anchor', '-auto')).toBe('auto');
32
- + expect(compileDashedIdent('timeline-scope', '-all')).toBe('all');
33
- + expect(compileDashedIdent('anchor-name', '-inherit')).toBe('inherit');
34
- + });
35
- + test('function form: names are not wrapped in var()', () => {
36
- + expect(compileDashedIdent('anchor-name', '(--a,--b)')).toBe('--a, --b');
37
- + expect(compileDashedIdent('scroll-timeline', '(--hero_y)')).toBe('--hero y');
38
- + expect(compileDashedIdent('view-timeline', '(--card_block_auto_20%)')).toBe('--card block auto 20%');
39
- + expect(compileDashedIdent('position-try-fallbacks', '(--below,flip-block)')).toBe('--below, flip-block');
40
- + expect(compileDashedIdent('animation-timeline', '(scroll(root_block))')).toBe('scroll(root block)');
41
- + });
42
- + test('keep-mode properties never add dashes', () => {
43
- + expect(compileDashedIdent('position-try-fallbacks', '-flip-block')).toBe('flip-block');
44
- + expect(compileDashedIdent('font-palette', '-dark')).toBe('dark');
45
- + });
46
- + test('explicit variables are left to the variable handling', () => {
47
- + expect(compileDashedIdent('anchor-name', '--var--x')).toBeNull();
48
- + expect(compileDashedIdent('anchor-name', '--x:--y')).toBeNull();
49
- + expect(compileDashedIdent('width', '-10px')).toBeNull();
50
- + });
51
- + test('wired into getPropertyAndValue', () => {
52
- + expect(pv('anchor-name-menu')).toBe('anchor-name:--menu');
53
- + expect(pv('anchor-name--menu')).toBe('anchor-name:--menu');
54
- + expect(pv('position-anchor-auto')).toBe('position-anchor:auto');
55
- + expect(pv('scroll-timeline(--hero_y)')).toBe('scroll-timeline:--hero y');
56
- + expect(pv('anchor-name--var--x')).toBe('anchor-name: var(--x)');
57
- + });
58
- +});
59
- diff --git a/src/compilers/dashedIdent.ts b/src/compilers/dashedIdent.ts
60
- new file mode 100644
61
- index 0000000..702193d
62
- --- /dev/null
63
- +++ b/src/compilers/dashedIdent.ts
64
- @@ -0,0 +1,130 @@
65
- +/**
66
- + * Properties whose values are names written with two leading dashes (CSS
67
- + * "dashed idents"): anchor names, scroll/view timeline names, custom
68
- + * @position-try rules, custom font palettes.
69
- + *
70
- + * In these properties `--name` is a name, never a CSS variable, so the usual
71
- + * `--x` → `var(--x)` rule must not apply. This compiler runs after static class
72
- + * names and before the variable handling in getPropertyAndValue.
73
- + *
74
- + * anchor-name-menu anchor-name: --menu
75
- + * anchor-name--menu anchor-name: --menu (was var(--menu))
76
- + * anchor-name---menu anchor-name: --menu (was ----menu)
77
- + * anchor-name-menu__card anchor-name: --menu, --card
78
- + * anchor-name(--menu,--card) anchor-name: --menu, --card (was var(--menu), var(--card))
79
- + * position-anchor-auto position-anchor: auto (was --auto)
80
- + * timeline-scope-all timeline-scope: all (was --all)
81
- + * animation-timeline(scroll(root_block)) animation-timeline: scroll(root block)
82
- + * scroll-timeline(--hero_y) scroll-timeline: --hero y (was var(--hero y))
83
- + * scroll-timeline-hero_y scroll-timeline: --hero y
84
- + * position-try-fallbacks(--below,flip-block) position-try-fallbacks: --below, flip-block
85
- + *
86
- + * A real variable is still possible with the explicit forms, which this
87
- + * compiler leaves alone: anchor-name--var--x → anchor-name: var(--x),
88
- + * and var(...) written inside a value.
89
- + */
90
- +
91
- +type Mode =
92
- + /** Every item is one name: bare words get "--" added (anchor-name-menu → --menu) */
93
- + | 'name'
94
- + /** Each item is a name followed by other values (scroll-timeline: --hero y) */
95
- + | 'shorthand'
96
- + /** Values are written as they are; "--x" stays a name, nothing is added */
97
- + | 'keep';
98
- +
99
- +interface Rule {
100
- + mode: Mode;
101
- + /** Words that are keywords, not names */
102
- + keywords: string[];
103
- +}
104
- +
105
- +const GLOBAL = ['inherit', 'initial', 'unset', 'revert', 'revert-layer'];
106
- +
107
- +export const DASHED_IDENT_PROPERTIES: { [property: string]: Rule } = {
108
- + 'anchor-name': { mode: 'name', keywords: ['none'] },
109
- + 'anchor-scope': { mode: 'name', keywords: ['none', 'all'] },
110
- + 'position-anchor': { mode: 'name', keywords: ['auto', 'none'] },
111
- + 'animation-timeline': { mode: 'name', keywords: ['auto', 'none'] },
112
- + 'scroll-timeline-name': { mode: 'name', keywords: ['none'] },
113
- + 'view-timeline-name': { mode: 'name', keywords: ['none'] },
114
- + 'timeline-scope': { mode: 'name', keywords: ['none', 'all'] },
115
- + 'scroll-timeline': { mode: 'shorthand', keywords: ['none'] },
116
- + 'view-timeline': { mode: 'shorthand', keywords: ['none'] },
117
- + 'position-try-fallbacks': { mode: 'keep', keywords: [] },
118
- + 'position-try': { mode: 'keep', keywords: [] },
119
- + 'font-palette': { mode: 'keep', keywords: [] },
120
- +};
121
- +
122
- +export function isDashedIdentProperty(property: string): boolean {
123
- + return Object.prototype.hasOwnProperty.call(DASHED_IDENT_PROPERTIES, property);
124
- +}
125
- +
126
- +/** `_` is a space; `\_` stays an underscore (same rule as other function values). */
127
- +const spaces = (s: string) => s.replace(/\\_|_/g, (m) => (m === '_' ? ' ' : '_'));
128
- +
129
- +/** Splits on commas that aren't inside parentheses. */
130
- +function splitTopLevel(s: string, sep: string): string[] {
131
- + const out: string[] = [];
132
- + let depth = 0;
133
- + let start = 0;
134
- + for (let i = 0; i < s.length; i++) {
135
- + const ch = s[i];
136
- + if (ch === '(') depth++;
137
- + else if (ch === ')') depth--;
138
- + else if (depth === 0 && s.startsWith(sep, i)) {
139
- + out.push(s.slice(start, i));
140
- + start = i + sep.length;
141
- + i += sep.length - 1;
142
- + }
143
- + }
144
- + out.push(s.slice(start));
145
- + return out.map((x) => x.trim()).filter(Boolean);
146
- +}
147
- +
148
- +/** One name: keywords, functions and var() stay as written; anything else gets exactly two leading dashes. */
149
- +function asName(word: string, rule: Rule): string {
150
- + if (rule.keywords.indexOf(word) !== -1 || GLOBAL.indexOf(word) !== -1) return word;
151
- + if (/^[a-z-]*\(/i.test(word)) return word; // scroll(), view(), var(), palette-mix()…
152
- + return '--' + word.replace(/^-+/, '');
153
- +}
154
- +
155
- +function compileItem(item: string, rule: Rule): string {
156
- + if (rule.mode === 'keep') return item;
157
- + if (rule.mode === 'name') return asName(item, rule);
158
- + // shorthand: the first word is the name, the rest (axis, inset) as written
159
- + const [first, ...rest] = splitTopLevel(item, ' ');
160
- + return [asName(first, rule), ...rest].join(' ');
161
- +}
162
- +
163
- +/**
164
- + * @param property the full CSS property name (after alias lookup), e.g. "anchor-name"
165
- + * @param valuePortion the class name minus the property key, as getPropertyAndValue has it:
166
- + * "-menu", "--menu", "-menu__card", "(--menu,--card)", "(scroll(root_block))"
167
- + * @returns the CSS value, or null to let the normal processing continue
168
- + */
169
- +export default function compileDashedIdent(property: string, valuePortion: string): string | null {
170
- + const rule = DASHED_IDENT_PROPERTIES[property];
171
- + if (!rule || !valuePortion) return null;
172
- +
173
- + // Explicit variables keep their existing meaning
174
- + if (/^--var--/.test(valuePortion)) return null;
175
- + // A fallback-style variable (anchor-name--x:value) is a variable too
176
- + if (/^--[a-zA-Z][\w-]*:/.test(valuePortion)) return null;
177
- +
178
- + // Function form: property(value) — commas separate items, _ is a space
179
- + const fn = valuePortion.match(/^\((.+)\)$/);
180
- + if (fn) {
181
- + const items = splitTopLevel(spaces(fn[1]), ',');
182
- + return items.map((item) => compileItem(item, rule)).join(', ') || null;
183
- + }
184
- +
185
- + // Class form: the leading dash is the separator; __ separates items, _ is a space
186
- + const raw = valuePortion.replace(/^-/, '');
187
- + if (!raw) return null;
188
- + const items = raw.split('__').map((x) => spaces(x).trim()).filter(Boolean);
189
- + if (rule.mode === 'keep') {
190
- + // Hyphens belong to the value here (flip-block, --my-try); only __ and _ are separators
191
- + return items.join(', ');
192
- + }
193
- + return items.map((item) => compileItem(item, rule)).join(', ');
194
- +}
195
- diff --git a/src/returnPropertyAndValue.ts b/src/returnPropertyAndValue.ts
196
- index 383c577..2661e87 100644
197
- --- a/src/returnPropertyAndValue.ts
198
- +++ b/src/returnPropertyAndValue.ts
199
- @@ -1,3 +1,4 @@
200
- +import compileDashedIdent, { isDashedIdentProperty } from './compilers/dashedIdent.js';
201
- type Property = {
202
- alias?:string,
203
- property?: string,
204
- @@ -148,6 +149,12 @@ export default function getPropertyAndValue(
205
- // --End of Group type
206
- const prop=property.property?property.property:propertyKey;
207
-
208
- + // Properties whose values are --names, not CSS variables (anchor-name, timelines, …)
209
- + if(isDashedIdentProperty(prop)){
210
- + const value=compileDashedIdent(prop, className.replace(propertyKey,''));
211
- + if(value) return bool?[prop,value]:prop+":"+value;
212
- + }
213
- +
214
- // Case 2: CSS Variables
215
- if (/--var--/.test(className)) {
216
- const splits: string[] = className.split(/--var--/);