postcss-kazaksha 1.0.0 → 1.0.2

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,4 +1,4 @@
1
- export const dictionary = {
1
+ module.exports = {
2
2
  // === ТҮСТЕР ===
3
3
  'түс': 'color',
4
4
  'артқы-түс': 'background-color',
package/index.js CHANGED
@@ -3,45 +3,45 @@ const postcss = require('postcss');
3
3
  const dictionary = require('./dictionary');
4
4
 
5
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 translateValues = (value) =>
20
+ Object.keys(dictionary).reduce((acc, kazakh) => {
21
+ const regex = new RegExp(`\\b${kazakh}\\b`, 'gi');
22
+ return acc.replace(regex, dictionary[kazakh]);
23
+ }, value);
24
+
25
+ const translateProperty = (prop) =>
26
+ dictionary[prop.toLowerCase()] || prop;
27
+
6
28
  module.exports = postcss.plugin('postcss-kazaksha', () => {
7
29
  return (root) => {
8
30
  root.walkDecls((decl) => {
9
- if (decl.prop.startsWith('--')) {
10
- const varName = decl.prop.substring(2);
11
- const translatedVar = dictionary[varName];
12
- if (translatedVar) {
13
- decl.prop = `--${translatedVar}`;
14
- }
15
- }
16
-
17
- const translatedProp = dictionary[decl.prop.toLowerCase()];
18
- if (translatedProp) {
19
- decl.prop = translatedProp;
20
- }
21
-
22
- let value = decl.value;
23
-
24
- value = value.replace(/var\(\s*--([^)]+)\s*\)/g, (match, varName) => {
25
- const translatedVar = dictionary[varName.trim()];
26
- return translatedVar ? `var(--${translatedVar})` : match;
27
- });
31
+ const translatedValue = [translateCSSVariables, translateValues]
32
+ .reduce((value, transform) => transform(value), decl.value);
28
33
 
29
- Object.keys(dictionary).forEach((kazakh) => {
30
- const regex = new RegExp(`\\b${kazakh}\\b`, 'gi');
31
- value = value.replace(regex, dictionary[kazakh]);
32
- });
34
+ const translatedProp = decl.prop.startsWith('--')
35
+ ? translateCustomProperty(decl.prop)
36
+ : translateProperty(decl.prop);
33
37
 
34
- decl.value = value;
38
+ decl.value = translatedValue;
39
+ decl.prop = translatedProp;
35
40
  });
36
41
 
37
42
  root.walkAtRules((atRule) => {
38
43
  if (atRule.params) {
39
- let params = atRule.params;
40
- Object.keys(dictionary).forEach((kazakh) => {
41
- const regex = new RegExp(`\\b${kazakh}\\b`, 'gi');
42
- params = params.replace(regex, dictionary[kazakh]);
43
- });
44
- atRule.params = params;
44
+ atRule.params = translateValues(atRule.params);
45
45
  }
46
46
  });
47
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-kazaksha",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "PostCSS плагині - қазақша CSS жазып, стандартты CSS-ке аударыңыз",
5
5
  "main": "index.js",
6
6
  "keywords": [