stylehacks 9.0.0 → 9.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.
- package/package.json +5 -2
- package/src/index.js +46 -5
- package/src/plugins/index.js +21 -1
- package/types/index.d.ts.map +1 -1
- package/types/plugins/index.d.ts +9 -2
- package/types/plugins/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylehacks",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.2",
|
|
4
4
|
"description": "Detect/remove browser hacks from CSS files.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
8
8
|
"default": "./src/index.js"
|
|
9
|
-
}
|
|
9
|
+
},
|
|
10
|
+
"./package.json": "./package.json"
|
|
10
11
|
},
|
|
12
|
+
"main": "./src/index.js",
|
|
13
|
+
"types": "./types/index.d.ts",
|
|
11
14
|
"imports": {
|
|
12
15
|
"#getBrowsersList": {
|
|
13
16
|
"node": "./src/lib/computeBrowsersToSupport.js",
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import getBrowsersList from '#getBrowsersList';
|
|
2
|
-
import plugins from './plugins/index.js';
|
|
2
|
+
import plugins, { pluginsByNodeType } from './plugins/index.js';
|
|
3
|
+
|
|
4
|
+
/** @import {Declaration} from 'postcss'; */
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @import browserslist from 'browserslist'
|
|
@@ -56,14 +58,53 @@ function pluginCreator(opts = {}) {
|
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
/** @type {
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
/** @type {WeakMap<Declaration, {before: string | undefined, prop: string, value: string, detected: boolean}>} */
|
|
62
|
+
const declarationDetections = new WeakMap();
|
|
63
|
+
|
|
64
|
+
/** @param {import('postcss').Node} node */
|
|
65
|
+
function detect(node) {
|
|
66
|
+
if (node.type === 'decl') {
|
|
67
|
+
const declaration = /** @type {Declaration} */ (node);
|
|
68
|
+
const { before } = declaration.raws;
|
|
69
|
+
const cached = declarationDetections.get(declaration);
|
|
70
|
+
|
|
71
|
+
if (
|
|
72
|
+
cached &&
|
|
73
|
+
cached.before === before &&
|
|
74
|
+
cached.prop === declaration.prop &&
|
|
75
|
+
cached.value === declaration.value
|
|
76
|
+
) {
|
|
77
|
+
return cached.detected;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const detected = pluginsByNodeType.decl.some((Plugin) => {
|
|
81
|
+
const hack = new Plugin();
|
|
82
|
+
|
|
83
|
+
return hack.any(node);
|
|
84
|
+
});
|
|
85
|
+
declarationDetections.set(declaration, {
|
|
86
|
+
before,
|
|
87
|
+
prop: declaration.prop,
|
|
88
|
+
value: declaration.value,
|
|
89
|
+
detected,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return detected;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const nodePlugins = pluginsByNodeType[node.type];
|
|
96
|
+
if (!nodePlugins) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return nodePlugins.some((Plugin) => {
|
|
62
101
|
const hack = new Plugin();
|
|
63
102
|
|
|
64
103
|
return hack.any(node);
|
|
65
104
|
});
|
|
66
|
-
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pluginCreator.detect = detect;
|
|
67
108
|
|
|
68
109
|
pluginCreator.postcss = true;
|
|
69
110
|
const moduleExports =
|
package/src/plugins/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import slash9 from './slash9.js';
|
|
|
11
11
|
import starHtml from './starHtml.js';
|
|
12
12
|
import trailingSlashComma from './trailingSlashComma.js';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const plugins = [
|
|
15
15
|
bodyEmpty,
|
|
16
16
|
htmlCombinatorCommentBody,
|
|
17
17
|
htmlFirstChild,
|
|
@@ -25,3 +25,23 @@ export default [
|
|
|
25
25
|
starHtml,
|
|
26
26
|
trailingSlashComma,
|
|
27
27
|
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Detectors grouped by the PostCSS node types they accept. `detect()` uses
|
|
31
|
+
* this to avoid constructing detectors that cannot inspect the given node.
|
|
32
|
+
*
|
|
33
|
+
* @type {Record<string, (typeof plugins)[number][]>}
|
|
34
|
+
*/
|
|
35
|
+
export const pluginsByNodeType = {
|
|
36
|
+
atrule: [leadingStar, mediaSlash0, mediaSlash0Slash9, mediaSlash9],
|
|
37
|
+
decl: [important, leadingStar, leadingUnderscore, slash9],
|
|
38
|
+
rule: [
|
|
39
|
+
bodyEmpty,
|
|
40
|
+
htmlCombinatorCommentBody,
|
|
41
|
+
htmlFirstChild,
|
|
42
|
+
starHtml,
|
|
43
|
+
trailingSlashComma,
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default plugins;
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAMG,OAAQ,KAAA,YAAY,MAAM,cAAc,CACxC;AAAA,YAAwD,mBAAmB,GAAjE;IAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAqB;AAC3E,YAAgE,mBAAmB,GAAzE,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC,CAAqB;AACnF,YAAwE,OAAO,GAArE;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAC,GAAG,mBAAmB,GAAG,mBAAmB,CAAS;AAoGlF,QAAA,MAAM,aAAa,EACN,OAAO,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG;IAAC,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,SAAS,EAAE,IAAI,KAAK,OAAO,CAAA;CAEvG,CAAC;AAEJ,OAAO,EAAE,aAAa,IAAI,OAAO,EAAE,aAAa,IAAI,gBAAgB,EAAE,CAAC"}
|
package/types/plugins/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const
|
|
1
|
+
declare const plugins: ({
|
|
2
2
|
new (result?: import('postcss').Result | undefined): {
|
|
3
3
|
detect(decl: import('postcss').Declaration): void;
|
|
4
4
|
nodes: import("../plugin.js").NodeWithInfo[];
|
|
@@ -33,5 +33,12 @@ declare const _default: ({
|
|
|
33
33
|
warn(): void;
|
|
34
34
|
};
|
|
35
35
|
})[];
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Detectors grouped by the PostCSS node types they accept. `detect()` uses
|
|
38
|
+
* this to avoid constructing detectors that cannot inspect the given node.
|
|
39
|
+
*
|
|
40
|
+
* @type {Record<string, (typeof plugins)[number][]>}
|
|
41
|
+
*/
|
|
42
|
+
export declare const pluginsByNodeType: Record<string, (typeof plugins)[number][]>;
|
|
43
|
+
export default plugins;
|
|
37
44
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.js"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.js"],"names":[],"mappings":"AAaA,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAaZ,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAFpB,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,CAYlD,CAAC;eAEa,OAAO"}
|