Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 | const charset = 'charset'; // eslint-disable-next-line no-control-regex
|
---|
8 |
|
---|
9 | const nonAscii = /[^\x00-\x7F]/;
|
---|
10 |
|
---|
11 | function pluginCreator(opts = {}) {
|
---|
12 | return {
|
---|
13 | postcssPlugin: 'postcss-normalize-' + charset,
|
---|
14 |
|
---|
15 | OnceExit(css, {
|
---|
16 | AtRule
|
---|
17 | }) {
|
---|
18 | let charsetRule;
|
---|
19 | let nonAsciiNode;
|
---|
20 | css.walk(node => {
|
---|
21 | if (node.type === 'atrule' && node.name === charset) {
|
---|
22 | if (!charsetRule) {
|
---|
23 | charsetRule = node;
|
---|
24 | }
|
---|
25 |
|
---|
26 | node.remove();
|
---|
27 | } else if (!nonAsciiNode && node.parent === css && nonAscii.test(node.toString())) {
|
---|
28 | nonAsciiNode = node;
|
---|
29 | }
|
---|
30 | });
|
---|
31 |
|
---|
32 | if (nonAsciiNode) {
|
---|
33 | if (!charsetRule && opts.add !== false) {
|
---|
34 | charsetRule = new AtRule({
|
---|
35 | name: charset,
|
---|
36 | params: '"utf-8"'
|
---|
37 | });
|
---|
38 | }
|
---|
39 |
|
---|
40 | if (charsetRule) {
|
---|
41 | charsetRule.source = nonAsciiNode.source;
|
---|
42 | css.prepend(charsetRule);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | };
|
---|
48 | }
|
---|
49 |
|
---|
50 | pluginCreator.postcss = true;
|
---|
51 | var _default = pluginCreator;
|
---|
52 | exports.default = _default;
|
---|
53 | module.exports = exports.default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.