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/dist/index.cjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkIROCUBI4cjs = require('./chunk-IROCUBI4.cjs');
|
|
11
|
+
|
|
12
|
+
// src/index.ts
|
|
13
|
+
var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
|
|
14
|
+
var _postcssselectorparser = require('postcss-selector-parser'); var _postcssselectorparser2 = _interopRequireDefault(_postcssselectorparser);
|
|
15
|
+
var PLUGIN_NAME = "postcss-kazaksha";
|
|
16
|
+
var KAZAKH_LETTER = /[а-яёәіңғүұқөһ]/i;
|
|
17
|
+
var IMPORTANT_RE = new RegExp(`\\s*!\\s*${_chunkIROCUBI4cjs.IMPORTANT}\\s*$`, "iu");
|
|
18
|
+
var CONDITIONAL_AT_RULES = /* @__PURE__ */ new Set(["media", "supports", "container", "custom-media"]);
|
|
19
|
+
var table = (base, extra) => new Map(Object.entries({ ...base, ...extra }));
|
|
20
|
+
var lookup = (word, order) => {
|
|
21
|
+
for (const t of order) {
|
|
22
|
+
const translated = t.get(word);
|
|
23
|
+
if (translated !== void 0) return translated;
|
|
24
|
+
}
|
|
25
|
+
return void 0;
|
|
26
|
+
};
|
|
27
|
+
var kazaksha = (opts = {}) => {
|
|
28
|
+
const { extend = {}, strict = false } = opts;
|
|
29
|
+
const tables = {
|
|
30
|
+
properties: table(_chunkIROCUBI4cjs.properties, extend.properties),
|
|
31
|
+
values: table(_chunkIROCUBI4cjs.values, extend.values),
|
|
32
|
+
functions: table(_chunkIROCUBI4cjs.functions, extend.functions),
|
|
33
|
+
selectors: table(_chunkIROCUBI4cjs.selectors, extend.selectors),
|
|
34
|
+
atRules: table(_chunkIROCUBI4cjs.atRules, extend.atRules),
|
|
35
|
+
mediaWords: table(_chunkIROCUBI4cjs.mediaWords, extend.mediaWords),
|
|
36
|
+
keyframes: table(_chunkIROCUBI4cjs.keyframeSelectors)
|
|
37
|
+
};
|
|
38
|
+
const warnUnknown = (word, node, result) => {
|
|
39
|
+
if (strict && KAZAKH_LETTER.test(word)) {
|
|
40
|
+
node.warn(result, `"${word}" \u0441\u04E9\u0437\u0456 \u0441\u04E9\u0437\u0434\u0456\u043A\u0442\u0435 \u0436\u043E\u049B, \u0430\u0443\u0434\u0430\u0440\u044B\u043B\u043C\u0430\u0434\u044B`, { word });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
let keyframeNames = /* @__PURE__ */ new Set();
|
|
44
|
+
const collectKeyframeNames = (root) => {
|
|
45
|
+
const names = /* @__PURE__ */ new Set();
|
|
46
|
+
root.walkAtRules((atRule) => {
|
|
47
|
+
const name = _nullishCoalesce(lookup(atRule.name.toLowerCase(), [tables.atRules]), () => ( atRule.name));
|
|
48
|
+
if (/keyframes$/i.test(name) && atRule.params) names.add(atRule.params.trim());
|
|
49
|
+
});
|
|
50
|
+
return names;
|
|
51
|
+
};
|
|
52
|
+
const valueOrder = [tables.values, tables.properties];
|
|
53
|
+
const mediaOrder = [tables.mediaWords, tables.properties, tables.values];
|
|
54
|
+
const translateCustomProperty = (name) => {
|
|
55
|
+
const translated = lookup(name.slice(2), valueOrder);
|
|
56
|
+
return translated ? `--${translated}` : name;
|
|
57
|
+
};
|
|
58
|
+
const translateValue = (value, order, node, result) => {
|
|
59
|
+
const parsed = _postcssvalueparser2.default.call(void 0, value);
|
|
60
|
+
parsed.walk((n) => {
|
|
61
|
+
if (n.type === "function") {
|
|
62
|
+
if (n.value.toLowerCase() === "url") return false;
|
|
63
|
+
const fn = lookup(n.value, [tables.functions]);
|
|
64
|
+
if (fn) n.value = fn;
|
|
65
|
+
else if (n.value) warnUnknown(n.value, node, result);
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
if (n.type === "word") {
|
|
69
|
+
if (n.value.startsWith("--")) {
|
|
70
|
+
n.value = translateCustomProperty(n.value);
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
if (keyframeNames.has(n.value)) return void 0;
|
|
74
|
+
const translated = lookup(n.value, order);
|
|
75
|
+
if (translated) n.value = translated;
|
|
76
|
+
else warnUnknown(n.value, node, result);
|
|
77
|
+
}
|
|
78
|
+
return void 0;
|
|
79
|
+
});
|
|
80
|
+
return parsed.toString();
|
|
81
|
+
};
|
|
82
|
+
const processDecl = (decl, result) => {
|
|
83
|
+
if (decl.prop.startsWith("--")) {
|
|
84
|
+
decl.prop = translateCustomProperty(decl.prop);
|
|
85
|
+
} else {
|
|
86
|
+
const prop = decl.prop.toLowerCase();
|
|
87
|
+
const translated = lookup(prop, [tables.properties]);
|
|
88
|
+
if (translated) decl.prop = translated;
|
|
89
|
+
else warnUnknown(decl.prop, decl, result);
|
|
90
|
+
}
|
|
91
|
+
let value = decl.value;
|
|
92
|
+
if (IMPORTANT_RE.test(value)) {
|
|
93
|
+
value = value.replace(IMPORTANT_RE, "");
|
|
94
|
+
decl.important = true;
|
|
95
|
+
}
|
|
96
|
+
decl.value = translateValue(value, valueOrder, decl, result);
|
|
97
|
+
};
|
|
98
|
+
const processAtRule = (atRule, result) => {
|
|
99
|
+
const name = lookup(atRule.name.toLowerCase(), [tables.atRules]);
|
|
100
|
+
if (name) atRule.name = name;
|
|
101
|
+
if (atRule.params && CONDITIONAL_AT_RULES.has(atRule.name.toLowerCase())) {
|
|
102
|
+
atRule.params = translateValue(atRule.params, mediaOrder, atRule, result);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const isInsideKeyframes = (rule) => {
|
|
106
|
+
const parent = rule.parent;
|
|
107
|
+
return _optionalChain([parent, 'optionalAccess', _ => _.type]) === "atrule" && /keyframes$/i.test(parent.name);
|
|
108
|
+
};
|
|
109
|
+
const processRule = (rule, result) => {
|
|
110
|
+
if (isInsideKeyframes(rule)) {
|
|
111
|
+
rule.selectors = rule.selectors.map(
|
|
112
|
+
(s) => _nullishCoalesce(lookup(s.trim(), [tables.keyframes]), () => ( s))
|
|
113
|
+
);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!rule.selector.includes(":")) return;
|
|
117
|
+
rule.selector = _postcssselectorparser2.default.call(void 0, (selectors2) => {
|
|
118
|
+
selectors2.walkPseudos((pseudo) => {
|
|
119
|
+
const colons = pseudo.value.startsWith("::") ? "::" : ":";
|
|
120
|
+
const name = pseudo.value.slice(colons.length);
|
|
121
|
+
const translated = lookup(name.toLowerCase(), [tables.selectors]);
|
|
122
|
+
if (translated) pseudo.value = colons + translated;
|
|
123
|
+
else warnUnknown(name, rule, result);
|
|
124
|
+
});
|
|
125
|
+
}).processSync(rule.selector);
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
postcssPlugin: PLUGIN_NAME,
|
|
129
|
+
Once(root, { result }) {
|
|
130
|
+
keyframeNames = collectKeyframeNames(root);
|
|
131
|
+
root.walk((node) => {
|
|
132
|
+
if (node.type === "atrule") processAtRule(node, result);
|
|
133
|
+
else if (node.type === "rule") processRule(node, result);
|
|
134
|
+
else if (node.type === "decl") processDecl(node, result);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
kazaksha.postcss = true;
|
|
140
|
+
var index_default = kazaksha;
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
exports.default = index_default;
|
|
144
|
+
|
|
145
|
+
module.exports = exports.default;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PluginCreator } from 'postcss';
|
|
2
|
+
import { O as Options } from './types-DdnEYsVC.cjs';
|
|
3
|
+
export { D as Dictionary, a as DictionaryKind } from './types-DdnEYsVC.cjs';
|
|
4
|
+
|
|
5
|
+
declare const kazaksha: PluginCreator<Options>;
|
|
6
|
+
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
export = kazaksha;
|
|
9
|
+
export { Options };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PluginCreator } from 'postcss';
|
|
2
|
+
import { O as Options } from './types-DdnEYsVC.js';
|
|
3
|
+
export { D as Dictionary, a as DictionaryKind } from './types-DdnEYsVC.js';
|
|
4
|
+
|
|
5
|
+
declare const kazaksha: PluginCreator<Options>;
|
|
6
|
+
|
|
7
|
+
export { Options, kazaksha as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IMPORTANT,
|
|
3
|
+
atRules,
|
|
4
|
+
functions,
|
|
5
|
+
keyframeSelectors,
|
|
6
|
+
mediaWords,
|
|
7
|
+
properties,
|
|
8
|
+
selectors,
|
|
9
|
+
values
|
|
10
|
+
} from "./chunk-GI2CVDY3.js";
|
|
11
|
+
|
|
12
|
+
// src/index.ts
|
|
13
|
+
import valueParser from "postcss-value-parser";
|
|
14
|
+
import selectorParser from "postcss-selector-parser";
|
|
15
|
+
var PLUGIN_NAME = "postcss-kazaksha";
|
|
16
|
+
var KAZAKH_LETTER = /[а-яёәіңғүұқөһ]/i;
|
|
17
|
+
var IMPORTANT_RE = new RegExp(`\\s*!\\s*${IMPORTANT}\\s*$`, "iu");
|
|
18
|
+
var CONDITIONAL_AT_RULES = /* @__PURE__ */ new Set(["media", "supports", "container", "custom-media"]);
|
|
19
|
+
var table = (base, extra) => new Map(Object.entries({ ...base, ...extra }));
|
|
20
|
+
var lookup = (word, order) => {
|
|
21
|
+
for (const t of order) {
|
|
22
|
+
const translated = t.get(word);
|
|
23
|
+
if (translated !== void 0) return translated;
|
|
24
|
+
}
|
|
25
|
+
return void 0;
|
|
26
|
+
};
|
|
27
|
+
var kazaksha = (opts = {}) => {
|
|
28
|
+
const { extend = {}, strict = false } = opts;
|
|
29
|
+
const tables = {
|
|
30
|
+
properties: table(properties, extend.properties),
|
|
31
|
+
values: table(values, extend.values),
|
|
32
|
+
functions: table(functions, extend.functions),
|
|
33
|
+
selectors: table(selectors, extend.selectors),
|
|
34
|
+
atRules: table(atRules, extend.atRules),
|
|
35
|
+
mediaWords: table(mediaWords, extend.mediaWords),
|
|
36
|
+
keyframes: table(keyframeSelectors)
|
|
37
|
+
};
|
|
38
|
+
const warnUnknown = (word, node, result) => {
|
|
39
|
+
if (strict && KAZAKH_LETTER.test(word)) {
|
|
40
|
+
node.warn(result, `"${word}" \u0441\u04E9\u0437\u0456 \u0441\u04E9\u0437\u0434\u0456\u043A\u0442\u0435 \u0436\u043E\u049B, \u0430\u0443\u0434\u0430\u0440\u044B\u043B\u043C\u0430\u0434\u044B`, { word });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
let keyframeNames = /* @__PURE__ */ new Set();
|
|
44
|
+
const collectKeyframeNames = (root) => {
|
|
45
|
+
const names = /* @__PURE__ */ new Set();
|
|
46
|
+
root.walkAtRules((atRule) => {
|
|
47
|
+
const name = lookup(atRule.name.toLowerCase(), [tables.atRules]) ?? atRule.name;
|
|
48
|
+
if (/keyframes$/i.test(name) && atRule.params) names.add(atRule.params.trim());
|
|
49
|
+
});
|
|
50
|
+
return names;
|
|
51
|
+
};
|
|
52
|
+
const valueOrder = [tables.values, tables.properties];
|
|
53
|
+
const mediaOrder = [tables.mediaWords, tables.properties, tables.values];
|
|
54
|
+
const translateCustomProperty = (name) => {
|
|
55
|
+
const translated = lookup(name.slice(2), valueOrder);
|
|
56
|
+
return translated ? `--${translated}` : name;
|
|
57
|
+
};
|
|
58
|
+
const translateValue = (value, order, node, result) => {
|
|
59
|
+
const parsed = valueParser(value);
|
|
60
|
+
parsed.walk((n) => {
|
|
61
|
+
if (n.type === "function") {
|
|
62
|
+
if (n.value.toLowerCase() === "url") return false;
|
|
63
|
+
const fn = lookup(n.value, [tables.functions]);
|
|
64
|
+
if (fn) n.value = fn;
|
|
65
|
+
else if (n.value) warnUnknown(n.value, node, result);
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
if (n.type === "word") {
|
|
69
|
+
if (n.value.startsWith("--")) {
|
|
70
|
+
n.value = translateCustomProperty(n.value);
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
if (keyframeNames.has(n.value)) return void 0;
|
|
74
|
+
const translated = lookup(n.value, order);
|
|
75
|
+
if (translated) n.value = translated;
|
|
76
|
+
else warnUnknown(n.value, node, result);
|
|
77
|
+
}
|
|
78
|
+
return void 0;
|
|
79
|
+
});
|
|
80
|
+
return parsed.toString();
|
|
81
|
+
};
|
|
82
|
+
const processDecl = (decl, result) => {
|
|
83
|
+
if (decl.prop.startsWith("--")) {
|
|
84
|
+
decl.prop = translateCustomProperty(decl.prop);
|
|
85
|
+
} else {
|
|
86
|
+
const prop = decl.prop.toLowerCase();
|
|
87
|
+
const translated = lookup(prop, [tables.properties]);
|
|
88
|
+
if (translated) decl.prop = translated;
|
|
89
|
+
else warnUnknown(decl.prop, decl, result);
|
|
90
|
+
}
|
|
91
|
+
let value = decl.value;
|
|
92
|
+
if (IMPORTANT_RE.test(value)) {
|
|
93
|
+
value = value.replace(IMPORTANT_RE, "");
|
|
94
|
+
decl.important = true;
|
|
95
|
+
}
|
|
96
|
+
decl.value = translateValue(value, valueOrder, decl, result);
|
|
97
|
+
};
|
|
98
|
+
const processAtRule = (atRule, result) => {
|
|
99
|
+
const name = lookup(atRule.name.toLowerCase(), [tables.atRules]);
|
|
100
|
+
if (name) atRule.name = name;
|
|
101
|
+
if (atRule.params && CONDITIONAL_AT_RULES.has(atRule.name.toLowerCase())) {
|
|
102
|
+
atRule.params = translateValue(atRule.params, mediaOrder, atRule, result);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const isInsideKeyframes = (rule) => {
|
|
106
|
+
const parent = rule.parent;
|
|
107
|
+
return parent?.type === "atrule" && /keyframes$/i.test(parent.name);
|
|
108
|
+
};
|
|
109
|
+
const processRule = (rule, result) => {
|
|
110
|
+
if (isInsideKeyframes(rule)) {
|
|
111
|
+
rule.selectors = rule.selectors.map(
|
|
112
|
+
(s) => lookup(s.trim(), [tables.keyframes]) ?? s
|
|
113
|
+
);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!rule.selector.includes(":")) return;
|
|
117
|
+
rule.selector = selectorParser((selectors2) => {
|
|
118
|
+
selectors2.walkPseudos((pseudo) => {
|
|
119
|
+
const colons = pseudo.value.startsWith("::") ? "::" : ":";
|
|
120
|
+
const name = pseudo.value.slice(colons.length);
|
|
121
|
+
const translated = lookup(name.toLowerCase(), [tables.selectors]);
|
|
122
|
+
if (translated) pseudo.value = colons + translated;
|
|
123
|
+
else warnUnknown(name, rule, result);
|
|
124
|
+
});
|
|
125
|
+
}).processSync(rule.selector);
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
postcssPlugin: PLUGIN_NAME,
|
|
129
|
+
Once(root, { result }) {
|
|
130
|
+
keyframeNames = collectKeyframeNames(root);
|
|
131
|
+
root.walk((node) => {
|
|
132
|
+
if (node.type === "atrule") processAtRule(node, result);
|
|
133
|
+
else if (node.type === "rule") processRule(node, result);
|
|
134
|
+
else if (node.type === "decl") processDecl(node, result);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
kazaksha.postcss = true;
|
|
140
|
+
var index_default = kazaksha;
|
|
141
|
+
export {
|
|
142
|
+
index_default as default
|
|
143
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Қазақша атау → CSS атауы */
|
|
2
|
+
type Dictionary = Readonly<Record<string, string>>;
|
|
3
|
+
type DictionaryKind = 'properties' | 'values' | 'functions' | 'selectors' | 'atRules' | 'mediaWords';
|
|
4
|
+
interface Options {
|
|
5
|
+
/**
|
|
6
|
+
* Өз сөздеріңізді қосу немесе бар сөздерді қайта анықтау.
|
|
7
|
+
* @example { values: { 'теңіз': '#1e90ff' } }
|
|
8
|
+
*/
|
|
9
|
+
extend?: Partial<Record<DictionaryKind, Dictionary>>;
|
|
10
|
+
/** Аударылмаған қазақша сөздерге ескерту шығару. Әдепкі: `false` */
|
|
11
|
+
strict?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { Dictionary as D, Options as O, DictionaryKind as a };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Қазақша атау → CSS атауы */
|
|
2
|
+
type Dictionary = Readonly<Record<string, string>>;
|
|
3
|
+
type DictionaryKind = 'properties' | 'values' | 'functions' | 'selectors' | 'atRules' | 'mediaWords';
|
|
4
|
+
interface Options {
|
|
5
|
+
/**
|
|
6
|
+
* Өз сөздеріңізді қосу немесе бар сөздерді қайта анықтау.
|
|
7
|
+
* @example { values: { 'теңіз': '#1e90ff' } }
|
|
8
|
+
*/
|
|
9
|
+
extend?: Partial<Record<DictionaryKind, Dictionary>>;
|
|
10
|
+
/** Аударылмаған қазақша сөздерге ескерту шығару. Әдепкі: `false` */
|
|
11
|
+
strict?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { Dictionary as D, Options as O, DictionaryKind as a };
|