update(autoprefixer): add browsers and prefixes modules (#43462)

As already used in the stylelint project:
https://github.com/stylelint/stylelint/blob/master/types/autoprefixer/index.d.ts

- add `lib/browsers` and `lib/prefixes`
- update tests

https://github.com/postcss/autoprefixer/blob/master/lib/browsers.js
https://github.com/postcss/autoprefixer/blob/master/lib/prefixes.js

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-03-31 00:11:21 +02:00 committed by GitHub
parent 21b410c313
commit 8d8f42c838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 0 deletions

View File

@ -1,4 +1,6 @@
import autoprefixer = require('autoprefixer');
import Browsers = require('autoprefixer/lib/browsers');
import Prefixes = require('autoprefixer/lib/prefixes');
import { Transformer } from 'postcss';
// No options
@ -36,3 +38,31 @@ const ap3: Transformer = autoprefixer({
ssr: ['node 12'],
},
});
const prefixes = new Prefixes(autoprefixer.data.prefixes, new Browsers(autoprefixer.data.browsers, []));
const autoprefixerApiTest = {
atRuleName(identifier: string) {
return Boolean(prefixes.remove[`@${identifier.toLowerCase()}`]);
},
selector(identifier: string) {
return prefixes.remove.selectors.some((selectorObj: { prefixed: string }) => {
return identifier.toLowerCase() === selectorObj.prefixed;
});
},
mediaFeatureName(identifier: string) {
return identifier.toLowerCase().includes('device-pixel-ratio');
},
property(identifier: string) {
return Boolean(autoprefixer.data.prefixes[prefixes.unprefixed(identifier.toLowerCase())]);
},
propertyValue(prop: string, value: string) {
const possiblePrefixableValues =
(prefixes.remove[prop.toLowerCase()] && prefixes.remove[prop.toLowerCase()].values) || false;
return (
possiblePrefixableValues &&
possiblePrefixableValues.some((valueObj: { prefixed: string }) => {
return value.toLowerCase() === valueObj.prefixed;
})
);
},
};

25
types/autoprefixer/lib/browsers.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
import browserslist = require('browserslist');
type Queries = string | ReadonlyArray<string>;
interface Browsers {
parse(queries: Queries): string[];
prefix(browser: string): string;
isSelected(browser: string): boolean;
}
declare class BrowsersImpl implements Browsers {
constructor(data: { [k: string]: any }, options?: any, browserslistOpts?: browserslist.Options);
isSelected(browser: string): boolean;
parse(queries: string | ReadonlyArray<string>): string[];
prefix(browser: string): string;
prefixes(): string[];
withPrefix(value: string): boolean;
}
export = BrowsersImpl;

17
types/autoprefixer/lib/prefixes.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
import Browsers = require('./browsers');
interface Prefixes {
remove: { [k: string]: any };
unprefixed(value: string): string;
}
declare class PrefixesImpl implements Prefixes {
constructor(data: string[], browsers: Browsers, options?: any);
remove: { [p: string]: any };
unprefixed(value: string): string;
}
export = PrefixesImpl;