stylehacks 5.0.1 → 5.1.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.
Files changed (66) hide show
  1. package/README.md +5 -8
  2. package/package.json +8 -11
  3. package/src/dictionary/browsers.js +9 -0
  4. package/src/dictionary/identifiers.js +7 -0
  5. package/src/dictionary/postcss.js +6 -0
  6. package/src/dictionary/tags.js +5 -0
  7. package/src/exists.js +13 -0
  8. package/src/index.js +60 -0
  9. package/src/isMixin.js +15 -0
  10. package/src/plugin.js +108 -0
  11. package/src/plugins/bodyEmpty.js +49 -0
  12. package/src/plugins/htmlCombinatorCommentBody.js +54 -0
  13. package/src/plugins/htmlFirstChild.js +50 -0
  14. package/src/plugins/important.js +25 -0
  15. package/src/plugins/index.js +28 -0
  16. package/src/plugins/leadingStar.js +55 -0
  17. package/src/plugins/leadingUnderscore.js +51 -0
  18. package/src/plugins/mediaSlash0.js +26 -0
  19. package/src/plugins/mediaSlash0Slash9.js +27 -0
  20. package/src/plugins/mediaSlash9.js +27 -0
  21. package/src/plugins/slash9.js +26 -0
  22. package/src/plugins/starHtml.js +50 -0
  23. package/src/plugins/trailingSlashComma.js +36 -0
  24. package/types/dictionary/browsers.d.ts +6 -0
  25. package/types/dictionary/identifiers.d.ts +4 -0
  26. package/types/dictionary/postcss.d.ts +3 -0
  27. package/types/dictionary/tags.d.ts +2 -0
  28. package/types/exists.d.ts +2 -0
  29. package/types/index.d.ts +16 -0
  30. package/types/isMixin.d.ts +2 -0
  31. package/types/plugin.d.ts +60 -0
  32. package/types/plugins/bodyEmpty.d.ts +17 -0
  33. package/types/plugins/htmlCombinatorCommentBody.d.ts +16 -0
  34. package/types/plugins/htmlFirstChild.d.ts +17 -0
  35. package/types/plugins/important.d.ts +11 -0
  36. package/types/plugins/index.d.ts +365 -0
  37. package/types/plugins/leadingStar.d.ts +11 -0
  38. package/types/plugins/leadingUnderscore.d.ts +11 -0
  39. package/types/plugins/mediaSlash0.d.ts +11 -0
  40. package/types/plugins/mediaSlash0Slash9.d.ts +11 -0
  41. package/types/plugins/mediaSlash9.d.ts +11 -0
  42. package/types/plugins/slash9.d.ts +11 -0
  43. package/types/plugins/starHtml.d.ts +17 -0
  44. package/types/plugins/trailingSlashComma.d.ts +11 -0
  45. package/CHANGELOG.md +0 -81
  46. package/dist/dictionary/browsers.js +0 -18
  47. package/dist/dictionary/identifiers.js +0 -14
  48. package/dist/dictionary/postcss.js +0 -12
  49. package/dist/dictionary/tags.js +0 -10
  50. package/dist/exists.js +0 -13
  51. package/dist/index.js +0 -69
  52. package/dist/isMixin.js +0 -20
  53. package/dist/plugin.js +0 -71
  54. package/dist/plugins/bodyEmpty.js +0 -48
  55. package/dist/plugins/htmlCombinatorCommentBody.js +0 -50
  56. package/dist/plugins/htmlFirstChild.js +0 -48
  57. package/dist/plugins/important.js +0 -29
  58. package/dist/plugins/index.js +0 -36
  59. package/dist/plugins/leadingStar.js +0 -67
  60. package/dist/plugins/leadingUnderscore.js +0 -49
  61. package/dist/plugins/mediaSlash0.js +0 -30
  62. package/dist/plugins/mediaSlash0Slash9.js +0 -30
  63. package/dist/plugins/mediaSlash9.js +0 -30
  64. package/dist/plugins/slash9.js +0 -30
  65. package/dist/plugins/starHtml.js +0 -48
  66. package/dist/plugins/trailingSlashComma.js +0 -39
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+ const BasePlugin = require('../plugin');
3
+ const { IE_5_5, IE_6, IE_7 } = require('../dictionary/browsers');
4
+ const { MEDIA_QUERY } = require('../dictionary/identifiers');
5
+ const { ATRULE } = require('../dictionary/postcss');
6
+
7
+ module.exports = class MediaSlash9 extends BasePlugin {
8
+ /** @param {import('postcss').Result} result */
9
+ constructor(result) {
10
+ super([IE_5_5, IE_6, IE_7], [ATRULE], result);
11
+ }
12
+
13
+ /**
14
+ * @param {import('postcss').AtRule} rule
15
+ * @return {void}
16
+ */
17
+ detect(rule) {
18
+ const params = rule.params.trim();
19
+
20
+ if (params.toLowerCase() === 'screen\\9') {
21
+ this.push(rule, {
22
+ identifier: MEDIA_QUERY,
23
+ hack: params,
24
+ });
25
+ }
26
+ }
27
+ };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+ const BasePlugin = require('../plugin.js');
3
+ const { IE_6, IE_7, IE_8 } = require('../dictionary/browsers');
4
+ const { VALUE } = require('../dictionary/identifiers');
5
+ const { DECL } = require('../dictionary/postcss');
6
+
7
+ module.exports = class Slash9 extends BasePlugin {
8
+ /** @param {import('postcss').Result=} result */
9
+ constructor(result) {
10
+ super([IE_6, IE_7, IE_8], [DECL], result);
11
+ }
12
+
13
+ /**
14
+ * @param {import('postcss').Declaration} decl
15
+ * @return {void}
16
+ */
17
+ detect(decl) {
18
+ let v = decl.value;
19
+ if (v && v.length > 2 && v.indexOf('\\9') === v.length - 2) {
20
+ this.push(decl, {
21
+ identifier: VALUE,
22
+ hack: v,
23
+ });
24
+ }
25
+ }
26
+ };
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+ const parser = require('postcss-selector-parser');
3
+ const exists = require('../exists');
4
+ const isMixin = require('../isMixin');
5
+ const BasePlugin = require('../plugin');
6
+ const { IE_5_5, IE_6 } = require('../dictionary/browsers');
7
+ const { SELECTOR } = require('../dictionary/identifiers');
8
+ const { RULE } = require('../dictionary/postcss');
9
+ const { HTML } = require('../dictionary/tags');
10
+
11
+ module.exports = class StarHtml extends BasePlugin {
12
+ /** @param {import('postcss').Result=} result */
13
+ constructor(result) {
14
+ super([IE_5_5, IE_6], [RULE], result);
15
+ }
16
+
17
+ /**
18
+ * @param {import('postcss').Rule} rule
19
+ * @return {void}
20
+ */
21
+ detect(rule) {
22
+ if (isMixin(rule)) {
23
+ return;
24
+ }
25
+ parser(this.analyse(rule)).processSync(rule.selector);
26
+ }
27
+
28
+ /**
29
+ * @param {import('postcss').Rule} rule
30
+ * @return {parser.SyncProcessor<void>}
31
+ */
32
+ analyse(rule) {
33
+ return (selectors) => {
34
+ selectors.each((selector) => {
35
+ if (
36
+ exists(selector, 0, '*') &&
37
+ exists(selector, 1, ' ') &&
38
+ exists(selector, 2, HTML) &&
39
+ exists(selector, 3, ' ') &&
40
+ selector.at(4)
41
+ ) {
42
+ this.push(rule, {
43
+ identifier: SELECTOR,
44
+ hack: selector.toString(),
45
+ });
46
+ }
47
+ });
48
+ };
49
+ }
50
+ };
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+ const BasePlugin = require('../plugin');
3
+ const isMixin = require('../isMixin');
4
+ const { IE_5_5, IE_6, IE_7 } = require('../dictionary/browsers');
5
+ const { SELECTOR } = require('../dictionary/identifiers');
6
+ const { RULE } = require('../dictionary/postcss');
7
+
8
+ module.exports = class TrailingSlashComma extends BasePlugin {
9
+ /** @param {import('postcss').Result=} result */
10
+ constructor(result) {
11
+ super([IE_5_5, IE_6, IE_7], [RULE], result);
12
+ }
13
+
14
+ /**
15
+ * @param {import('postcss').Rule} rule
16
+ * @return {void}
17
+ */
18
+ detect(rule) {
19
+ if (isMixin(rule)) {
20
+ return;
21
+ }
22
+
23
+ const { selector } = rule;
24
+ const trim = selector.trim();
25
+
26
+ if (
27
+ trim.lastIndexOf(',') === selector.length - 1 ||
28
+ trim.lastIndexOf('\\') === selector.length - 1
29
+ ) {
30
+ this.push(rule, {
31
+ identifier: SELECTOR,
32
+ hack: selector,
33
+ });
34
+ }
35
+ }
36
+ };
@@ -0,0 +1,6 @@
1
+ export const FF_2: "firefox 2";
2
+ export const IE_5_5: "ie 5.5";
3
+ export const IE_6: "ie 6";
4
+ export const IE_7: "ie 7";
5
+ export const IE_8: "ie 8";
6
+ export const OP_9: "opera 9";
@@ -0,0 +1,4 @@
1
+ export const MEDIA_QUERY: "media query";
2
+ export const PROPERTY: "property";
3
+ export const SELECTOR: "selector";
4
+ export const VALUE: "value";
@@ -0,0 +1,3 @@
1
+ export const ATRULE: "atrule";
2
+ export const DECL: "decl";
3
+ export const RULE: "rule";
@@ -0,0 +1,2 @@
1
+ export const BODY: "body";
2
+ export const HTML: "html";
@@ -0,0 +1,2 @@
1
+ declare function _exports(selector: import('postcss-selector-parser').Selector, index: number, value: string): boolean | undefined | '';
2
+ export = _exports;
@@ -0,0 +1,16 @@
1
+ export = pluginCreator;
2
+ /** @typedef {{lint?: boolean}} Options */
3
+ /**
4
+ * @type {import('postcss').PluginCreator<Options>}
5
+ * @param {Options} opts
6
+ * @return {import('postcss').Plugin}
7
+ */
8
+ declare function pluginCreator(opts?: Options): import('postcss').Plugin;
9
+ declare namespace pluginCreator {
10
+ export { detect, postcss, Options };
11
+ }
12
+ type Options = {
13
+ lint?: boolean;
14
+ };
15
+ declare function detect(node: import('postcss').Node): boolean;
16
+ declare var postcss: true;
@@ -0,0 +1,2 @@
1
+ declare function _exports(node: import('postcss').Rule): boolean;
2
+ export = _exports;
@@ -0,0 +1,60 @@
1
+ export = BasePlugin;
2
+ declare class BasePlugin {
3
+ /**
4
+ * @param {string[]} targets
5
+ * @param {string[]} nodeTypes
6
+ * @param {import('postcss').Result=} result
7
+ */
8
+ constructor(targets: string[], nodeTypes: string[], result?: import('postcss').Result | undefined);
9
+ /** @type {NodeWithInfo[]} */
10
+ nodes: NodeWithInfo[];
11
+ targets: Set<string>;
12
+ nodeTypes: Set<string>;
13
+ result: import("postcss").Result | undefined;
14
+ /**
15
+ * @param {import('postcss').Node} node
16
+ * @param {{identifier: string, hack: string}} metadata
17
+ * @return {void}
18
+ */
19
+ push(node: import('postcss').Node, metadata: {
20
+ identifier: string;
21
+ hack: string;
22
+ }): void;
23
+ /**
24
+ * @param {import('postcss').Node} node
25
+ * @return {boolean}
26
+ */
27
+ any(node: import('postcss').Node): boolean;
28
+ /**
29
+ * @param {import('postcss').Node} node
30
+ * @return {void}
31
+ */
32
+ detectAndResolve(node: import('postcss').Node): void;
33
+ /**
34
+ * @param {import('postcss').Node} node
35
+ * @return {void}
36
+ */
37
+ detectAndWarn(node: import('postcss').Node): void;
38
+ /** @param {import('postcss').Node} node */
39
+ detect(node: import('postcss').Node): void;
40
+ /** @return {void} */
41
+ resolve(): void;
42
+ warn(): void;
43
+ }
44
+ declare namespace BasePlugin {
45
+ export { Plugin, NodeWithInfo };
46
+ }
47
+ type NodeWithInfo = import('postcss').Node & {
48
+ _stylehacks: {
49
+ message: string;
50
+ browsers: Set<string>;
51
+ identifier: string;
52
+ hack: string;
53
+ };
54
+ };
55
+ type Plugin = {
56
+ targets: Set<string>;
57
+ nodeTypes: Set<string>;
58
+ detectAndResolve: (node: import('postcss').Node) => void;
59
+ detectAndWarn: (node: import('postcss').Node) => void;
60
+ };
@@ -0,0 +1,17 @@
1
+ export = BodyEmpty;
2
+ declare class BodyEmpty extends BasePlugin {
3
+ /** @param {import('postcss').Result} result */
4
+ constructor(result: import('postcss').Result);
5
+ /**
6
+ * @param {import('postcss').Rule} rule
7
+ * @return {void}
8
+ */
9
+ detect(rule: import('postcss').Rule): void;
10
+ /**
11
+ * @param {import('postcss').Rule} rule
12
+ * @return {parser.SyncProcessor<void>}
13
+ */
14
+ analyse(rule: import('postcss').Rule): parser.SyncProcessor<void>;
15
+ }
16
+ import BasePlugin = require("../plugin");
17
+ import parser = require("postcss-selector-parser");
@@ -0,0 +1,16 @@
1
+ export = HtmlCombinatorCommentBody;
2
+ declare class HtmlCombinatorCommentBody extends BasePlugin {
3
+ /** @param {import('postcss').Result} result */
4
+ constructor(result: import('postcss').Result);
5
+ /**
6
+ * @param {import('postcss').Rule} rule
7
+ * @return {void}
8
+ */
9
+ detect(rule: import('postcss').Rule): void;
10
+ /** @param {import('postcss').Rule} rule
11
+ * @return {parser.SyncProcessor<void>}
12
+ */
13
+ analyse(rule: import('postcss').Rule): parser.SyncProcessor<void>;
14
+ }
15
+ import BasePlugin = require("../plugin");
16
+ import parser = require("postcss-selector-parser");
@@ -0,0 +1,17 @@
1
+ export = HtmlFirstChild;
2
+ declare class HtmlFirstChild extends BasePlugin {
3
+ /** @param {import('postcss').Result} result */
4
+ constructor(result: import('postcss').Result);
5
+ /**
6
+ * @param {import('postcss').Rule} rule
7
+ * @return {void}
8
+ */
9
+ detect(rule: import('postcss').Rule): void;
10
+ /**
11
+ * @param {import('postcss').Rule} rule
12
+ * @return {parser.SyncProcessor<void>}
13
+ */
14
+ analyse(rule: import('postcss').Rule): parser.SyncProcessor<void>;
15
+ }
16
+ import BasePlugin = require("../plugin");
17
+ import parser = require("postcss-selector-parser");
@@ -0,0 +1,11 @@
1
+ export = Important;
2
+ declare class Important extends BasePlugin {
3
+ /** @param {import('postcss').Result=} result */
4
+ constructor(result?: import('postcss').Result | undefined);
5
+ /**
6
+ * @param {import('postcss').Declaration} decl
7
+ * @return {void}
8
+ */
9
+ detect(decl: import('postcss').Declaration): void;
10
+ }
11
+ import BasePlugin = require("../plugin");