@melcanz85/chaincss 1.11.1 → 1.11.3
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/browser/rtt.js +137 -60
- package/node/strVal.js +2 -2
- package/package.json +1 -1
package/browser/rtt.js
CHANGED
|
@@ -1,48 +1,58 @@
|
|
|
1
1
|
import { tokens, createTokens, responsive } from '../shared/tokens.mjs';
|
|
2
|
+
|
|
2
3
|
let cssProperties = [];
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
|
|
5
|
+
const loadCSSProperties = async () => {
|
|
6
|
+
try {
|
|
7
|
+
const module = await import('../node/css-properties.json', {
|
|
8
|
+
assert: { type: 'json' }
|
|
9
|
+
});
|
|
10
|
+
return module.default;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.log('CSS properties file not found in package, will fetch from CDN');
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
12
17
|
const chain = {
|
|
13
18
|
cssOutput: undefined,
|
|
14
19
|
catcher: {},
|
|
15
20
|
cachedValidProperties: [],
|
|
16
|
-
async initializeProperties() {
|
|
17
|
-
if (
|
|
18
|
-
this.cachedValidProperties = cssProperties;
|
|
21
|
+
async initializeProperties() {
|
|
22
|
+
if (this.cachedValidProperties.length > 0) {
|
|
19
23
|
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const localProperties = await loadCSSProperties();
|
|
27
|
+
if (localProperties && localProperties.length > 0) {
|
|
28
|
+
this.cachedValidProperties = localProperties;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
console.log('Loading CSS properties from CDN...');
|
|
34
|
+
const response = await fetch('https://raw.githubusercontent.com/mdn/data/main/css/properties.json');
|
|
35
|
+
const data = await response.json();
|
|
36
|
+
const allProperties = Object.keys(data);
|
|
37
|
+
|
|
38
|
+
const baseProperties = new Set();
|
|
39
|
+
allProperties.forEach(prop => {
|
|
40
|
+
const baseProp = prop.replace(/^-(webkit|moz|ms|o)-/, '');
|
|
41
|
+
baseProperties.add(baseProp);
|
|
42
|
+
});
|
|
43
|
+
this.cachedValidProperties = Array.from(baseProperties).sort();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Error loading from CDN:', error);
|
|
46
|
+
this.cachedValidProperties = [];
|
|
39
47
|
}
|
|
40
48
|
},
|
|
41
49
|
getCachedProperties() {
|
|
42
50
|
return this.cachedValidProperties;
|
|
43
51
|
}
|
|
44
52
|
};
|
|
53
|
+
|
|
45
54
|
chain.initializeProperties();
|
|
55
|
+
|
|
46
56
|
const resolveToken = (value, useTokens) => {
|
|
47
57
|
if (!useTokens || typeof value !== 'string' || !value.startsWith('$')) {
|
|
48
58
|
return value;
|
|
@@ -54,39 +64,81 @@ const resolveToken = (value, useTokens) => {
|
|
|
54
64
|
}
|
|
55
65
|
return tokenValue;
|
|
56
66
|
};
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
|
|
68
|
+
function $(useTokens = true) {
|
|
69
|
+
const regularStyles = {};
|
|
70
|
+
const hoverStyles = {};
|
|
71
|
+
let isBuildingHover = false;
|
|
72
|
+
|
|
59
73
|
const validProperties = chain.cachedValidProperties;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
|
|
75
|
+
// Create the main proxy
|
|
76
|
+
const createProxy = () => {
|
|
77
|
+
const handler = {
|
|
78
|
+
get: (target, prop) => {
|
|
79
|
+
// Handle .block()
|
|
80
|
+
if (prop === 'block') {
|
|
81
|
+
return (...args) => {
|
|
82
|
+
const result = { ...regularStyles };
|
|
83
|
+
|
|
84
|
+
// Add hover styles if any exist
|
|
85
|
+
if (Object.keys(hoverStyles).length > 0) {
|
|
86
|
+
result.hover = { ...hoverStyles };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (args.length > 0) {
|
|
90
|
+
result.selectors = args;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Clear for next use
|
|
94
|
+
Object.keys(regularStyles).forEach(key => delete regularStyles[key]);
|
|
95
|
+
Object.keys(hoverStyles).forEach(key => delete hoverStyles[key]);
|
|
96
|
+
isBuildingHover = false;
|
|
97
|
+
|
|
67
98
|
return result;
|
|
68
|
-
}
|
|
69
|
-
const result = {
|
|
70
|
-
selectors: args,
|
|
71
|
-
...catcher
|
|
72
99
|
};
|
|
73
|
-
|
|
74
|
-
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Handle .hover()
|
|
103
|
+
if (prop === 'hover') {
|
|
104
|
+
return () => {
|
|
105
|
+
isBuildingHover = true;
|
|
106
|
+
return proxy; // Return the same proxy, just with hover mode on
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if(prop==='end'){
|
|
111
|
+
return () => {
|
|
112
|
+
isBuildingHover = false;
|
|
113
|
+
return proxy; // Return the same proxy, but end of hover mode
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Handle regular CSS properties
|
|
118
|
+
const cssProperty = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
119
|
+
if (validProperties && validProperties.length > 0 && !validProperties.includes(cssProperty)) {
|
|
120
|
+
console.warn(`Warning: '${cssProperty}' may not be a valid CSS property`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return (value) => {
|
|
124
|
+
console.log(`📦 ${prop} = ${value}, isBuildingHover = ${isBuildingHover}`);
|
|
125
|
+
if (isBuildingHover) {
|
|
126
|
+
hoverStyles[prop] = resolveToken(value, useTokens);
|
|
127
|
+
} else {
|
|
128
|
+
regularStyles[prop] = resolveToken(value, useTokens);
|
|
129
|
+
}
|
|
130
|
+
return proxy;
|
|
75
131
|
};
|
|
76
132
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
return function(value) {
|
|
82
|
-
catcher[prop] = resolveToken(value, useTokens);
|
|
83
|
-
return proxy;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return new Proxy({}, handler);
|
|
86
136
|
};
|
|
87
|
-
|
|
137
|
+
|
|
138
|
+
const proxy = createProxy();
|
|
88
139
|
return proxy;
|
|
89
140
|
}
|
|
141
|
+
|
|
90
142
|
const run = (...args) => {
|
|
91
143
|
let cssOutput = '';
|
|
92
144
|
args.forEach((value) => {
|
|
@@ -105,20 +157,45 @@ const run = (...args) => {
|
|
|
105
157
|
chain.cssOutput = cssOutput.trim();
|
|
106
158
|
return cssOutput.trim();
|
|
107
159
|
};
|
|
160
|
+
|
|
108
161
|
const compile = (obj) => {
|
|
109
162
|
let cssString = '';
|
|
110
163
|
for (const key in obj) {
|
|
111
164
|
if (obj.hasOwnProperty(key)) {
|
|
112
165
|
const element = obj[key];
|
|
113
166
|
let selectors = element.selectors || [];
|
|
114
|
-
|
|
167
|
+
|
|
168
|
+
// Generate normal styles
|
|
169
|
+
let normalCSS = '';
|
|
170
|
+
let hoverCSS = '';
|
|
171
|
+
|
|
115
172
|
for (let prop in element) {
|
|
116
|
-
if (element.hasOwnProperty(prop) && prop !== 'selectors') {
|
|
173
|
+
if (element.hasOwnProperty(prop) && prop !== 'selectors' && prop !== 'hover') {
|
|
117
174
|
const kebabKey = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
118
|
-
|
|
175
|
+
normalCSS += ` ${kebabKey}: ${element[prop]};\n`;
|
|
119
176
|
}
|
|
120
177
|
}
|
|
121
|
-
|
|
178
|
+
|
|
179
|
+
// Generate hover styles if present
|
|
180
|
+
if (element.hover && typeof element.hover === 'object') {
|
|
181
|
+
for (let prop in element.hover) {
|
|
182
|
+
if (element.hover.hasOwnProperty(prop)) {
|
|
183
|
+
const kebabKey = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
184
|
+
hoverCSS += ` ${kebabKey}: ${element.hover[prop]};\n`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Add normal styles
|
|
190
|
+
if (normalCSS) {
|
|
191
|
+
cssString += `${selectors.join(', ')} {\n${normalCSS}}\n`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Add hover styles as separate rule
|
|
195
|
+
if (hoverCSS) {
|
|
196
|
+
const hoverSelectors = selectors.map(s => `${s}:hover`);
|
|
197
|
+
cssString += `${hoverSelectors.join(', ')} {\n${hoverCSS}}\n`;
|
|
198
|
+
}
|
|
122
199
|
}
|
|
123
200
|
}
|
|
124
201
|
chain.cssOutput = cssString.trim();
|
package/node/strVal.js
CHANGED
|
@@ -2,7 +2,7 @@ const strVal = {
|
|
|
2
2
|
userConf: `// Project Configuration
|
|
3
3
|
module.exports = {
|
|
4
4
|
atomic: {
|
|
5
|
-
enabled:
|
|
5
|
+
enabled: true,
|
|
6
6
|
threshold: 3,
|
|
7
7
|
naming: 'hash',
|
|
8
8
|
cache: true,
|
|
@@ -13,7 +13,7 @@ module.exports = {
|
|
|
13
13
|
mode: 'auto',
|
|
14
14
|
browsers: ['> 0.5%', 'last 2 versions', 'not dead'],
|
|
15
15
|
enabled: true,
|
|
16
|
-
sourceMap:
|
|
16
|
+
sourceMap: true,
|
|
17
17
|
sourceMapInline: false
|
|
18
18
|
}
|
|
19
19
|
};
|