postcss-kazaksha 1.2.0 → 2.0.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/LICENSE +21 -0
- package/dist/chunk-GI2CVDY3.js +436 -0
- package/dist/chunk-IROCUBI4.cjs +436 -0
- package/dist/dictionary/index.cjs +20 -0
- package/dist/dictionary/index.d.cts +23 -0
- package/dist/dictionary/index.d.ts +23 -0
- package/dist/dictionary/index.js +20 -0
- package/dist/index.cjs +145 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +143 -0
- package/dist/types-DdnEYsVC.d.cts +14 -0
- package/dist/types-DdnEYsVC.d.ts +14 -0
- package/dist/vscode/kazaksha.css-data.json +1 -0
- package/package.json +68 -4
- package/readme.md +137 -24
- package/dictionary/index.js +0 -325
- package/index.js +0 -82
package/index.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// postcss-kazaksha/index.js
|
|
2
|
-
const postcss = require('postcss');
|
|
3
|
-
const dictionary = require('./dictionary');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const translateCustomProperty = (prop) => {
|
|
7
|
-
if (!prop.startsWith('--')) return prop;
|
|
8
|
-
const varName = prop.substring(2);
|
|
9
|
-
const translated = dictionary[varName];
|
|
10
|
-
return translated ? `--${translated}` : prop;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const translateCSSVariables = (value) =>
|
|
14
|
-
value.replace(/var\(\s*--([^)]+)\s*\)/g, (match, varName) => {
|
|
15
|
-
const translated = dictionary[varName.trim()];
|
|
16
|
-
return translated ? `var(--${translated})` : match;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const isWordChar = (char) => {
|
|
20
|
-
if (!char) return false;
|
|
21
|
-
return /[a-zA-Zа-яА-ЯәіңғүұқөһӘІҢҒҮҰҚӨҺ0-9_-]/.test(char);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const isWordBoundary = (str, startPos, endPos) => {
|
|
25
|
-
const before = startPos > 0 ? str[startPos - 1] : '';
|
|
26
|
-
const after = endPos < str.length ? str[endPos] : '';
|
|
27
|
-
return !isWordChar(before) && !isWordChar(after);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const translateValues = (value) => {
|
|
31
|
-
const sortedKeys = Object.keys(dictionary).sort((a, b) => b.length - a.length);
|
|
32
|
-
|
|
33
|
-
return sortedKeys.reduce((acc, kazakh) => {
|
|
34
|
-
let result = acc;
|
|
35
|
-
let searchFrom = 0;
|
|
36
|
-
|
|
37
|
-
while (true) {
|
|
38
|
-
const index = result.indexOf(kazakh, searchFrom);
|
|
39
|
-
if (index === -1) break;
|
|
40
|
-
|
|
41
|
-
const endIndex = index + kazakh.length;
|
|
42
|
-
if (isWordBoundary(result, index, endIndex)) {
|
|
43
|
-
result = result.substring(0, index) + dictionary[kazakh] + result.substring(endIndex);
|
|
44
|
-
searchFrom = index + dictionary[kazakh].length;
|
|
45
|
-
} else {
|
|
46
|
-
searchFrom = index + 1;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return result;
|
|
51
|
-
}, value);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const translateProperty = (prop) =>
|
|
55
|
-
dictionary[prop.toLowerCase()] || prop;
|
|
56
|
-
|
|
57
|
-
const processRoot = (root) => {
|
|
58
|
-
root.walkDecls((decl) => {
|
|
59
|
-
const translatedValue = [translateCSSVariables, translateValues]
|
|
60
|
-
.reduce((value, transform) => transform(value), decl.value);
|
|
61
|
-
|
|
62
|
-
const translatedProp = decl.prop.startsWith('--')
|
|
63
|
-
? translateCustomProperty(decl.prop)
|
|
64
|
-
: translateProperty(decl.prop);
|
|
65
|
-
|
|
66
|
-
decl.value = translatedValue;
|
|
67
|
-
decl.prop = translatedProp;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
root.walkAtRules((atRule) => {
|
|
71
|
-
if (atRule.params) {
|
|
72
|
-
atRule.params = translateValues(atRule.params);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
module.exports = () => ({
|
|
78
|
-
postcssPlugin: 'postcss-kazaksha',
|
|
79
|
-
Once: processRoot
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
module.exports.postcss = true;
|