@ngcorex/css 0.1.6 → 0.2.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/constraints/constraint-error.d.ts.map +1 -1
- package/dist/constraints/constraint-error.js +2 -2
- package/dist/engine/build-css.js +2 -2
- package/dist/errors/ngcorex-error.d.ts +68 -1
- package/dist/errors/ngcorex-error.d.ts.map +1 -1
- package/dist/errors/ngcorex-error.js +135 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/tokens/normalize-colors.js +2 -2
- package/dist/tokens/normalize.d.ts.map +1 -1
- package/dist/tokens/normalize.js +2 -2
- package/dist/validation/color-format.d.ts +22 -0
- package/dist/validation/color-format.d.ts.map +1 -0
- package/dist/validation/color-format.js +249 -0
- package/dist/validation/index.d.ts +42 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +206 -0
- package/dist/validation/scale-consistency.d.ts +14 -0
- package/dist/validation/scale-consistency.d.ts.map +1 -0
- package/dist/validation/scale-consistency.js +215 -0
- package/dist/validation/shadow-format.d.ts +14 -0
- package/dist/validation/shadow-format.d.ts.map +1 -0
- package/dist/validation/shadow-format.js +217 -0
- package/dist/validation/spacing-format.d.ts +14 -0
- package/dist/validation/spacing-format.d.ts.map +1 -0
- package/dist/validation/spacing-format.js +173 -0
- package/dist/validation/token-duplicates.d.ts +24 -0
- package/dist/validation/token-duplicates.d.ts.map +1 -0
- package/dist/validation/token-duplicates.js +149 -0
- package/dist/validation/types.d.ts +160 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/types.js +4 -0
- package/dist/validation/z-index-logic.d.ts +14 -0
- package/dist/validation/z-index-logic.d.ts.map +1 -0
- package/dist/validation/z-index-logic.js +230 -0
- package/package.json +6 -6
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z-index logic validation
|
|
3
|
+
* Checks for logical layering and value consistency
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Validation code for z-index logic
|
|
7
|
+
*/
|
|
8
|
+
const ZINDEX_LOGIC_CODE = 'ZINDEX_LOGIC';
|
|
9
|
+
/**
|
|
10
|
+
* Common z-index layer order (from bottom to top)
|
|
11
|
+
*/
|
|
12
|
+
const COMMON_ZINDEX_LAYERS = [
|
|
13
|
+
'base', // 0 or 1
|
|
14
|
+
'dropdown', // 1000
|
|
15
|
+
'sticky', // 1020
|
|
16
|
+
'fixed', // 1030
|
|
17
|
+
'modal', // 1040
|
|
18
|
+
'popover', // 1050
|
|
19
|
+
'tooltip', // 1060
|
|
20
|
+
'toast' // 1070
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Default z-index values for common layers
|
|
24
|
+
*/
|
|
25
|
+
const DEFAULT_ZINDEX_VALUES = {
|
|
26
|
+
base: 0,
|
|
27
|
+
dropdown: 1000,
|
|
28
|
+
sticky: 1020,
|
|
29
|
+
fixed: 1030,
|
|
30
|
+
modal: 1040,
|
|
31
|
+
popover: 1050,
|
|
32
|
+
tooltip: 1060,
|
|
33
|
+
toast: 1070
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Parse a z-index value to extract numeric value
|
|
37
|
+
*/
|
|
38
|
+
function parseZIndexValue(value) {
|
|
39
|
+
let raw;
|
|
40
|
+
let numericValue;
|
|
41
|
+
if (typeof value === 'number') {
|
|
42
|
+
raw = value.toString();
|
|
43
|
+
numericValue = value;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
raw = value;
|
|
47
|
+
const match = value.match(/^(-?\d+)$/);
|
|
48
|
+
if (!match)
|
|
49
|
+
return null;
|
|
50
|
+
numericValue = parseInt(match[1], 10);
|
|
51
|
+
}
|
|
52
|
+
return { value: numericValue, raw };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validate a single z-index value
|
|
56
|
+
*/
|
|
57
|
+
function validateZIndexValue(path, value, severity = 'warning') {
|
|
58
|
+
const parsed = parseZIndexValue(value);
|
|
59
|
+
if (!parsed) {
|
|
60
|
+
return {
|
|
61
|
+
severity: 'error',
|
|
62
|
+
code: ZINDEX_LOGIC_CODE,
|
|
63
|
+
message: `Invalid z-index value: "${value}"`,
|
|
64
|
+
path,
|
|
65
|
+
suggestion: 'Z-index values must be integers.',
|
|
66
|
+
example: `// Examples:\n// "${path}": "1000"\n// "${path}": 1000`
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const { value: numericValue } = parsed;
|
|
70
|
+
// Check for negative values (not typically valid for z-index)
|
|
71
|
+
if (numericValue < 0) {
|
|
72
|
+
return {
|
|
73
|
+
severity: 'warning',
|
|
74
|
+
code: ZINDEX_LOGIC_CODE,
|
|
75
|
+
message: `Negative z-index value: "${value}"`,
|
|
76
|
+
path,
|
|
77
|
+
suggestion: 'Z-index values should typically be non-negative. Use negative values only for specific use cases.',
|
|
78
|
+
example: `// Change from:\n// "${path}": "${value}"\n// To:\n// "${path}": "0"`
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Check for very large values (may cause issues)
|
|
82
|
+
if (numericValue > 2147483647) {
|
|
83
|
+
return {
|
|
84
|
+
severity: 'warning',
|
|
85
|
+
code: ZINDEX_LOGIC_CODE,
|
|
86
|
+
message: `Very large z-index value: "${value}"`,
|
|
87
|
+
path,
|
|
88
|
+
suggestion: 'Z-index values should be reasonable. Consider using a smaller value.',
|
|
89
|
+
example: `// Change from:\n// "${path}": "${value}"\n// To:\n// "${path}": "9999"`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check for overlapping z-index values
|
|
96
|
+
*/
|
|
97
|
+
function checkOverlappingZIndexValues(zIndex, severity = 'warning') {
|
|
98
|
+
const results = [];
|
|
99
|
+
const valueMap = new Map();
|
|
100
|
+
// Group keys by value
|
|
101
|
+
for (const [key, value] of Object.entries(zIndex)) {
|
|
102
|
+
const parsed = parseZIndexValue(value);
|
|
103
|
+
if (parsed) {
|
|
104
|
+
const { value: numericValue } = parsed;
|
|
105
|
+
if (!valueMap.has(numericValue)) {
|
|
106
|
+
valueMap.set(numericValue, []);
|
|
107
|
+
}
|
|
108
|
+
valueMap.get(numericValue).push(key);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Check for duplicate values
|
|
112
|
+
for (const [value, keys] of valueMap.entries()) {
|
|
113
|
+
if (keys.length > 1) {
|
|
114
|
+
results.push({
|
|
115
|
+
severity,
|
|
116
|
+
code: ZINDEX_LOGIC_CODE,
|
|
117
|
+
message: `Multiple z-index layers have the same value: ${value}`,
|
|
118
|
+
path: 'zIndex',
|
|
119
|
+
suggestion: `Consider using different values for each layer. Keys: ${keys.join(', ')}.`,
|
|
120
|
+
example: `// Example:\n// "zIndex.${keys[0]}": "${value}"\n// "zIndex.${keys[1]}": "${value + 10}"`
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return results;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Check for inconsistent layering order
|
|
128
|
+
*/
|
|
129
|
+
function checkLayeringOrder(zIndex, severity = 'warning') {
|
|
130
|
+
const results = [];
|
|
131
|
+
// Get keys that match common layers
|
|
132
|
+
const commonLayersPresent = COMMON_ZINDEX_LAYERS.filter(layer => layer in zIndex);
|
|
133
|
+
if (commonLayersPresent.length < 2) {
|
|
134
|
+
return results;
|
|
135
|
+
}
|
|
136
|
+
// Sort by expected order
|
|
137
|
+
const sortedByExpected = [...commonLayersPresent].sort((a, b) => {
|
|
138
|
+
return COMMON_ZINDEX_LAYERS.indexOf(a) - COMMON_ZINDEX_LAYERS.indexOf(b);
|
|
139
|
+
});
|
|
140
|
+
// Check if values are in increasing order
|
|
141
|
+
const values = [];
|
|
142
|
+
for (const key of sortedByExpected) {
|
|
143
|
+
const parsed = parseZIndexValue(zIndex[key]);
|
|
144
|
+
if (parsed) {
|
|
145
|
+
values.push({ key, value: parsed.value });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Check for non-monotonic progression
|
|
149
|
+
for (let i = 1; i < values.length; i++) {
|
|
150
|
+
const prev = values[i - 1];
|
|
151
|
+
const curr = values[i];
|
|
152
|
+
if (curr.value <= prev.value) {
|
|
153
|
+
const prevLayer = COMMON_ZINDEX_LAYERS.indexOf(prev.key);
|
|
154
|
+
const currLayer = COMMON_ZINDEX_LAYERS.indexOf(curr.key);
|
|
155
|
+
results.push({
|
|
156
|
+
severity,
|
|
157
|
+
code: ZINDEX_LOGIC_CODE,
|
|
158
|
+
message: `Inconsistent layering: "${curr.key}" (${curr.value}) should be greater than "${prev.key}" (${prev.value})`,
|
|
159
|
+
path: `zIndex.${curr.key}`,
|
|
160
|
+
suggestion: `Z-index values should increase with layer depth. ${curr.key} should be above ${prev.key}.`,
|
|
161
|
+
example: `// Example:\n// "zIndex.${prev.key}": "${prev.value}"\n// "zIndex.${curr.key}": "${prev.value + 10}"`
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return results;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Check for gaps in z-index scale
|
|
169
|
+
*/
|
|
170
|
+
function checkZIndexGaps(zIndex, severity = 'warning') {
|
|
171
|
+
const results = [];
|
|
172
|
+
// Get common layers that are present
|
|
173
|
+
const commonLayersPresent = COMMON_ZINDEX_LAYERS.filter(layer => layer in zIndex);
|
|
174
|
+
if (commonLayersPresent.length < 2) {
|
|
175
|
+
return results;
|
|
176
|
+
}
|
|
177
|
+
// Check for missing common layers
|
|
178
|
+
const missingLayers = COMMON_ZINDEX_LAYERS.filter(layer => !(layer in zIndex));
|
|
179
|
+
if (missingLayers.length > 0) {
|
|
180
|
+
results.push({
|
|
181
|
+
severity: 'info',
|
|
182
|
+
code: ZINDEX_LOGIC_CODE,
|
|
183
|
+
message: `Potential gaps in z-index scale: missing layers ${missingLayers.map(l => `"${l}"`).join(', ')}`,
|
|
184
|
+
path: 'zIndex',
|
|
185
|
+
suggestion: 'Consider adding missing z-index layers for a complete layering system.',
|
|
186
|
+
example: `// Example:\n// "zIndex.${missingLayers[0]}": "${DEFAULT_ZINDEX_VALUES[missingLayers[0]]}"`
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return results;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Validate all z-index logic
|
|
193
|
+
*/
|
|
194
|
+
export function validateZIndexLogic(tokens, severity = 'warning') {
|
|
195
|
+
const results = [];
|
|
196
|
+
if (!tokens.zIndex) {
|
|
197
|
+
return results;
|
|
198
|
+
}
|
|
199
|
+
const zIndex = tokens.zIndex;
|
|
200
|
+
// Validate each z-index value
|
|
201
|
+
for (const [key, value] of Object.entries(zIndex)) {
|
|
202
|
+
const result = validateZIndexValue(`zIndex.${key}`, value, severity);
|
|
203
|
+
if (result) {
|
|
204
|
+
results.push(result);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Check for overlapping values
|
|
208
|
+
results.push(...checkOverlappingZIndexValues(zIndex, severity));
|
|
209
|
+
// Check for layering order
|
|
210
|
+
results.push(...checkLayeringOrder(zIndex, severity));
|
|
211
|
+
// Check for gaps
|
|
212
|
+
results.push(...checkZIndexGaps(zIndex, severity));
|
|
213
|
+
return results;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get a summary of z-index logic issues
|
|
217
|
+
*/
|
|
218
|
+
export function getZIndexLogicSummary(issues) {
|
|
219
|
+
if (issues.length === 0) {
|
|
220
|
+
return 'No z-index logic issues found.';
|
|
221
|
+
}
|
|
222
|
+
const summary = [];
|
|
223
|
+
summary.push(`Found ${issues.length} z-index logic issue${issues.length > 1 ? 's' : ''}:`);
|
|
224
|
+
for (const issue of issues) {
|
|
225
|
+
summary.push(` • ${issue.path}: ${issue.issue}`);
|
|
226
|
+
summary.push(` ${issue.details}`);
|
|
227
|
+
summary.push(` 💡 ${issue.suggestion}`);
|
|
228
|
+
}
|
|
229
|
+
return summary.join('\n');
|
|
230
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngcorex/css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Angular-native design token and utility CSS engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-tokens",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"build": "tsc -p tsconfig.json"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/arkdezin/ngCorex.git",
|
|
38
|
+
"directory": "packages/css"
|
|
39
|
+
},
|
|
40
40
|
|
|
41
|
-
"homepage": "https://github.com/arkdezin/ngCorex"
|
|
41
|
+
"homepage": "https://github.com/arkdezin/ngCorex/blob/main/README.md"
|
|
42
42
|
}
|