[6a3a178] | 1 | import autoprefixer from 'autoprefixer';
|
---|
| 2 | import browserslist from 'browserslist';
|
---|
| 3 | import cssdb from 'cssdb';
|
---|
| 4 | import postcss$1 from 'postcss';
|
---|
| 5 | import postcssAttributeCaseInsensitive from 'postcss-attribute-case-insensitive';
|
---|
| 6 | import postcssBlankPseudo from 'css-blank-pseudo/postcss';
|
---|
| 7 | import postcssColorFunctionalNotation from 'postcss-color-functional-notation';
|
---|
| 8 | import postcssColorGray from 'postcss-color-gray';
|
---|
| 9 | import postcssColorHexAlpha from 'postcss-color-hex-alpha';
|
---|
| 10 | import postcssColorModFunction from 'postcss-color-mod-function';
|
---|
| 11 | import postcssColorRebeccapurple from 'postcss-color-rebeccapurple';
|
---|
| 12 | import postcssCustomMedia from 'postcss-custom-media';
|
---|
| 13 | import postcssCustomProperties from 'postcss-custom-properties';
|
---|
| 14 | import postcssCustomSelectors from 'postcss-custom-selectors';
|
---|
| 15 | import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
|
---|
| 16 | import postcssDoublePositionGradients from 'postcss-double-position-gradients';
|
---|
| 17 | import postcssEnvFunction from 'postcss-env-function';
|
---|
| 18 | import postcssFocusVisible from 'postcss-focus-visible';
|
---|
| 19 | import postcssFocusWithin from 'postcss-focus-within';
|
---|
| 20 | import postcssFontVariant from 'postcss-font-variant';
|
---|
| 21 | import postcssGapProperties from 'postcss-gap-properties';
|
---|
| 22 | import postcssHasPseudo from 'css-has-pseudo/postcss';
|
---|
| 23 | import postcssImageSetPolyfill from 'postcss-image-set-function';
|
---|
| 24 | import postcssInitial from 'postcss-initial';
|
---|
| 25 | import postcssLabFunction from 'postcss-lab-function';
|
---|
| 26 | import postcssLogical from 'postcss-logical';
|
---|
| 27 | import postcssMediaMinmax from 'postcss-media-minmax';
|
---|
| 28 | import postcssNesting from 'postcss-nesting';
|
---|
| 29 | import postcssOverflowShorthand from 'postcss-overflow-shorthand';
|
---|
| 30 | import postcssPageBreak from 'postcss-page-break';
|
---|
| 31 | import postcssPlace from 'postcss-place';
|
---|
| 32 | import postcssPrefersColorScheme from 'css-prefers-color-scheme/postcss';
|
---|
| 33 | import postcssPseudoClassAnyLink from 'postcss-pseudo-class-any-link';
|
---|
| 34 | import postcssReplaceOverflowWrap from 'postcss-replace-overflow-wrap';
|
---|
| 35 | import postcssSelectorMatches from 'postcss-selector-matches';
|
---|
| 36 | import postcssSelectorNot from 'postcss-selector-not';
|
---|
| 37 | import { features, feature } from 'caniuse-lite';
|
---|
| 38 | import fs from 'fs';
|
---|
| 39 | import path from 'path';
|
---|
| 40 |
|
---|
| 41 | var postcssFontFamilySystemUi = postcss$1.plugin('postcss-system-ui-font', () => root => {
|
---|
| 42 | root.walkDecls(propertyRegExp, decl => {
|
---|
| 43 | decl.value = decl.value.replace(systemUiMatch, systemUiReplace);
|
---|
| 44 | });
|
---|
| 45 | });
|
---|
| 46 | const propertyRegExp = /(?:^(?:-|\\002d){2})|(?:^font(?:-family)?$)/i;
|
---|
| 47 | const whitespace = '[\\f\\n\\r\\x09\\x20]';
|
---|
| 48 | const systemUiFamily = ['system-ui',
|
---|
| 49 | /* macOS 10.11-10.12 */
|
---|
| 50 | '-apple-system',
|
---|
| 51 | /* Windows 6+ */
|
---|
| 52 | 'Segoe UI',
|
---|
| 53 | /* Android 4+ */
|
---|
| 54 | 'Roboto',
|
---|
| 55 | /* Ubuntu 10.10+ */
|
---|
| 56 | 'Ubuntu',
|
---|
| 57 | /* Gnome 3+ */
|
---|
| 58 | 'Cantarell',
|
---|
| 59 | /* KDE Plasma 5+ */
|
---|
| 60 | 'Noto Sans',
|
---|
| 61 | /* fallback */
|
---|
| 62 | 'sans-serif'];
|
---|
| 63 | const systemUiMatch = new RegExp(`(^|,|${whitespace}+)(?:system-ui${whitespace}*)(?:,${whitespace}*(?:${systemUiFamily.join('|')})${whitespace}*)?(,|$)`, 'i');
|
---|
| 64 | const systemUiReplace = `$1${systemUiFamily.join(', ')}$2`;
|
---|
| 65 |
|
---|
| 66 | var plugins = {
|
---|
| 67 | 'all-property': postcssInitial,
|
---|
| 68 | 'any-link-pseudo-class': postcssPseudoClassAnyLink,
|
---|
| 69 | 'blank-pseudo-class': postcssBlankPseudo,
|
---|
| 70 | 'break-properties': postcssPageBreak,
|
---|
| 71 | 'case-insensitive-attributes': postcssAttributeCaseInsensitive,
|
---|
| 72 | 'color-functional-notation': postcssColorFunctionalNotation,
|
---|
| 73 | 'color-mod-function': postcssColorModFunction,
|
---|
| 74 | 'custom-media-queries': postcssCustomMedia,
|
---|
| 75 | 'custom-properties': postcssCustomProperties,
|
---|
| 76 | 'custom-selectors': postcssCustomSelectors,
|
---|
| 77 | 'dir-pseudo-class': postcssDirPseudoClass,
|
---|
| 78 | 'double-position-gradients': postcssDoublePositionGradients,
|
---|
| 79 | 'environment-variables': postcssEnvFunction,
|
---|
| 80 | 'focus-visible-pseudo-class': postcssFocusVisible,
|
---|
| 81 | 'focus-within-pseudo-class': postcssFocusWithin,
|
---|
| 82 | 'font-variant-property': postcssFontVariant,
|
---|
| 83 | 'gap-properties': postcssGapProperties,
|
---|
| 84 | 'gray-function': postcssColorGray,
|
---|
| 85 | 'has-pseudo-class': postcssHasPseudo,
|
---|
| 86 | 'hexadecimal-alpha-notation': postcssColorHexAlpha,
|
---|
| 87 | 'image-set-function': postcssImageSetPolyfill,
|
---|
| 88 | 'lab-function': postcssLabFunction,
|
---|
| 89 | 'logical-properties-and-values': postcssLogical,
|
---|
| 90 | 'matches-pseudo-class': postcssSelectorMatches,
|
---|
| 91 | 'media-query-ranges': postcssMediaMinmax,
|
---|
| 92 | 'nesting-rules': postcssNesting,
|
---|
| 93 | 'not-pseudo-class': postcssSelectorNot,
|
---|
| 94 | 'overflow-property': postcssOverflowShorthand,
|
---|
| 95 | 'overflow-wrap-property': postcssReplaceOverflowWrap,
|
---|
| 96 | 'place-properties': postcssPlace,
|
---|
| 97 | 'prefers-color-scheme-query': postcssPrefersColorScheme,
|
---|
| 98 | 'rebeccapurple-color': postcssColorRebeccapurple,
|
---|
| 99 | 'system-ui-font-family': postcssFontFamilySystemUi
|
---|
| 100 | };
|
---|
| 101 |
|
---|
| 102 | // return a list of features to be inserted before or after cssdb features
|
---|
| 103 | function getTransformedInsertions(insertions, placement) {
|
---|
| 104 | return Object.keys(insertions).map(id => [].concat(insertions[id]).map(plugin => ({
|
---|
| 105 | [placement]: true,
|
---|
| 106 | plugin,
|
---|
| 107 | id
|
---|
| 108 | }))).reduce((array, feature) => array.concat(feature), []);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | function getUnsupportedBrowsersByFeature(feature$1) {
|
---|
| 112 | const caniuseFeature = features[feature$1]; // if feature support can be determined
|
---|
| 113 |
|
---|
| 114 | if (caniuseFeature) {
|
---|
| 115 | const stats = feature(caniuseFeature).stats; // return an array of browsers and versions that do not support the feature
|
---|
| 116 |
|
---|
| 117 | const results = Object.keys(stats).reduce((browsers, browser) => browsers.concat(Object.keys(stats[browser]).filter(version => stats[browser][version].indexOf('y') !== 0).map(version => `${browser} ${version}`)), []);
|
---|
| 118 | return results;
|
---|
| 119 | } else {
|
---|
| 120 | // otherwise, return that the feature does not work in any browser
|
---|
| 121 | return ['> 0%'];
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | // ids ordered by required execution, then alphabetically
|
---|
| 126 | var idsByExecutionOrder = ['custom-media-queries', 'custom-properties', 'environment-variables', // run environment-variables here to access transpiled custom media params and properties
|
---|
| 127 | 'image-set-function', // run images-set-function before nesting-rules so that it may fix nested media
|
---|
| 128 | 'media-query-ranges', // run media-query-range and
|
---|
| 129 | 'prefers-color-scheme-query', // run prefers-color-scheme-query here to prevent duplicate transpilation after nesting-rules
|
---|
| 130 | 'nesting-rules', 'custom-selectors', // run custom-selectors after nesting-rules to correctly transpile &:--custom-selector
|
---|
| 131 | 'any-link-pseudo-class', 'case-insensitive-attributes', 'focus-visible-pseudo-class', 'focus-within-pseudo-class', 'matches-pseudo-class', // run matches-pseudo-class and
|
---|
| 132 | 'not-pseudo-class', // run not-pseudo-class after other selectors have been transpiled
|
---|
| 133 | 'logical-properties-and-values', // run logical-properties-and-values before dir-pseudo-class
|
---|
| 134 | 'dir-pseudo-class', 'all-property', // run all-property before other property polyfills
|
---|
| 135 | 'color-functional-notation', 'double-position-gradients', 'gray-function', 'hexadecimal-alpha-notation', 'lab-function', 'rebeccapurple-color', 'color-mod-function', // run color-mod after other color modifications have finished
|
---|
| 136 | 'blank-pseudo-class', 'break-properties', 'font-variant-property', 'has-pseudo-class', 'gap-properties', 'overflow-property', 'overflow-wrap-property', 'place-properties', 'system-ui-font-family'];
|
---|
| 137 |
|
---|
| 138 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
---|
| 139 | try {
|
---|
| 140 | var info = gen[key](arg);
|
---|
| 141 | var value = info.value;
|
---|
| 142 | } catch (error) {
|
---|
| 143 | reject(error);
|
---|
| 144 | return;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | if (info.done) {
|
---|
| 148 | resolve(value);
|
---|
| 149 | } else {
|
---|
| 150 | Promise.resolve(value).then(_next, _throw);
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | function _asyncToGenerator(fn) {
|
---|
| 155 | return function () {
|
---|
| 156 | var self = this,
|
---|
| 157 | args = arguments;
|
---|
| 158 | return new Promise(function (resolve, reject) {
|
---|
| 159 | var gen = fn.apply(self, args);
|
---|
| 160 |
|
---|
| 161 | function _next(value) {
|
---|
| 162 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | function _throw(err) {
|
---|
| 166 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | _next(undefined);
|
---|
| 170 | });
|
---|
| 171 | };
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | /* Write Exports to CSS File
|
---|
| 175 | /* ========================================================================== */
|
---|
| 176 |
|
---|
| 177 | function getCustomMediaAsCss(customMedia) {
|
---|
| 178 | const cssContent = Object.keys(customMedia).reduce((cssLines, name) => {
|
---|
| 179 | cssLines.push(`@custom-media ${name} ${customMedia[name]};`);
|
---|
| 180 | return cssLines;
|
---|
| 181 | }, []).join('\n');
|
---|
| 182 | const css = `${cssContent}\n`;
|
---|
| 183 | return css;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | function getCustomPropertiesAsCss(customProperties) {
|
---|
| 187 | const cssContent = Object.keys(customProperties).reduce((cssLines, name) => {
|
---|
| 188 | cssLines.push(`\t${name}: ${customProperties[name]};`);
|
---|
| 189 | return cssLines;
|
---|
| 190 | }, []).join('\n');
|
---|
| 191 | const css = `:root {\n${cssContent}\n}\n`;
|
---|
| 192 | return css;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | function getCustomSelectorsAsCss(customSelectors) {
|
---|
| 196 | const cssContent = Object.keys(customSelectors).reduce((cssLines, name) => {
|
---|
| 197 | cssLines.push(`@custom-selector ${name} ${customSelectors[name]};`);
|
---|
| 198 | return cssLines;
|
---|
| 199 | }, []).join('\n');
|
---|
| 200 | const css = `${cssContent}\n`;
|
---|
| 201 | return css;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | function writeExportsToCssFile(_x, _x2, _x3, _x4) {
|
---|
| 205 | return _writeExportsToCssFile.apply(this, arguments);
|
---|
| 206 | }
|
---|
| 207 | /* Write Exports to JSON file
|
---|
| 208 | /* ========================================================================== */
|
---|
| 209 |
|
---|
| 210 |
|
---|
| 211 | function _writeExportsToCssFile() {
|
---|
| 212 | _writeExportsToCssFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) {
|
---|
| 213 | const customPropertiesAsCss = getCustomPropertiesAsCss(customProperties);
|
---|
| 214 | const customMediaAsCss = getCustomMediaAsCss(customMedia);
|
---|
| 215 | const customSelectorsAsCss = getCustomSelectorsAsCss(customSelectors);
|
---|
| 216 | const css = `${customMediaAsCss}\n${customSelectorsAsCss}\n${customPropertiesAsCss}`;
|
---|
| 217 | yield writeFile(to, css);
|
---|
| 218 | });
|
---|
| 219 | return _writeExportsToCssFile.apply(this, arguments);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | function writeExportsToJsonFile(_x5, _x6, _x7, _x8) {
|
---|
| 223 | return _writeExportsToJsonFile.apply(this, arguments);
|
---|
| 224 | }
|
---|
| 225 | /* Write Exports to Common JS file
|
---|
| 226 | /* ========================================================================== */
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 | function _writeExportsToJsonFile() {
|
---|
| 230 | _writeExportsToJsonFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) {
|
---|
| 231 | const jsonContent = JSON.stringify({
|
---|
| 232 | 'custom-media': customMedia,
|
---|
| 233 | 'custom-properties': customProperties,
|
---|
| 234 | 'custom-selectors': customSelectors
|
---|
| 235 | }, null, ' ');
|
---|
| 236 | const json = `${jsonContent}\n`;
|
---|
| 237 | yield writeFile(to, json);
|
---|
| 238 | });
|
---|
| 239 | return _writeExportsToJsonFile.apply(this, arguments);
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | function getObjectWithKeyAsCjs(key, object) {
|
---|
| 243 | const jsContents = Object.keys(object).reduce((jsLines, name) => {
|
---|
| 244 | jsLines.push(`\t\t'${escapeForJS(name)}': '${escapeForJS(object[name])}'`);
|
---|
| 245 | return jsLines;
|
---|
| 246 | }, []).join(',\n');
|
---|
| 247 | const cjs = `\n\t${key}: {\n${jsContents}\n\t}`;
|
---|
| 248 | return cjs;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | function writeExportsToCjsFile(_x9, _x10, _x11, _x12) {
|
---|
| 252 | return _writeExportsToCjsFile.apply(this, arguments);
|
---|
| 253 | }
|
---|
| 254 | /* Write Exports to Module JS file
|
---|
| 255 | /* ========================================================================== */
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 | function _writeExportsToCjsFile() {
|
---|
| 259 | _writeExportsToCjsFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) {
|
---|
| 260 | const customMediaAsCjs = getObjectWithKeyAsCjs('customMedia', customMedia);
|
---|
| 261 | const customPropertiesAsCjs = getObjectWithKeyAsCjs('customProperties', customProperties);
|
---|
| 262 | const customSelectorsAsCjs = getObjectWithKeyAsCjs('customSelectors', customSelectors);
|
---|
| 263 | const cjs = `module.exports = {${customMediaAsCjs},${customPropertiesAsCjs},${customSelectorsAsCjs}\n};\n`;
|
---|
| 264 | yield writeFile(to, cjs);
|
---|
| 265 | });
|
---|
| 266 | return _writeExportsToCjsFile.apply(this, arguments);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | function getObjectWithKeyAsMjs(key, object) {
|
---|
| 270 | const mjsContents = Object.keys(object).reduce((mjsLines, name) => {
|
---|
| 271 | mjsLines.push(`\t'${escapeForJS(name)}': '${escapeForJS(object[name])}'`);
|
---|
| 272 | return mjsLines;
|
---|
| 273 | }, []).join(',\n');
|
---|
| 274 | const mjs = `export const ${key} = {\n${mjsContents}\n};\n`;
|
---|
| 275 | return mjs;
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | function writeExportsToMjsFile(_x13, _x14, _x15, _x16) {
|
---|
| 279 | return _writeExportsToMjsFile.apply(this, arguments);
|
---|
| 280 | }
|
---|
| 281 | /* Write Exports to Exports
|
---|
| 282 | /* ========================================================================== */
|
---|
| 283 |
|
---|
| 284 |
|
---|
| 285 | function _writeExportsToMjsFile() {
|
---|
| 286 | _writeExportsToMjsFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) {
|
---|
| 287 | const customMediaAsMjs = getObjectWithKeyAsMjs('customMedia', customMedia);
|
---|
| 288 | const customPropertiesAsMjs = getObjectWithKeyAsMjs('customProperties', customProperties);
|
---|
| 289 | const customSelectorsAsMjs = getObjectWithKeyAsMjs('customSelectors', customSelectors);
|
---|
| 290 | const mjs = `${customMediaAsMjs}\n${customPropertiesAsMjs}\n${customSelectorsAsMjs}`;
|
---|
| 291 | yield writeFile(to, mjs);
|
---|
| 292 | });
|
---|
| 293 | return _writeExportsToMjsFile.apply(this, arguments);
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | function writeToExports(customExports, destinations) {
|
---|
| 297 | return Promise.all([].concat(destinations).map(
|
---|
| 298 | /*#__PURE__*/
|
---|
| 299 | function () {
|
---|
| 300 | var _ref = _asyncToGenerator(function* (destination) {
|
---|
| 301 | if (destination instanceof Function) {
|
---|
| 302 | yield destination({
|
---|
| 303 | customMedia: getObjectWithStringifiedKeys(customExports.customMedia),
|
---|
| 304 | customProperties: getObjectWithStringifiedKeys(customExports.customProperties),
|
---|
| 305 | customSelectors: getObjectWithStringifiedKeys(customExports.customSelectors)
|
---|
| 306 | });
|
---|
| 307 | } else {
|
---|
| 308 | // read the destination as an object
|
---|
| 309 | const opts = destination === Object(destination) ? destination : {
|
---|
| 310 | to: String(destination)
|
---|
| 311 | }; // transformer for Exports into a JSON-compatible object
|
---|
| 312 |
|
---|
| 313 | const toJSON = opts.toJSON || getObjectWithStringifiedKeys;
|
---|
| 314 |
|
---|
| 315 | if ('customMedia' in opts || 'customProperties' in opts || 'customSelectors' in opts) {
|
---|
| 316 | // write directly to an object as customProperties
|
---|
| 317 | opts.customMedia = toJSON(customExports.customMedia);
|
---|
| 318 | opts.customProperties = toJSON(customExports.customProperties);
|
---|
| 319 | opts.customSelectors = toJSON(customExports.customSelectors);
|
---|
| 320 | } else if ('custom-media' in opts || 'custom-properties' in opts || 'custom-selectors' in opts) {
|
---|
| 321 | // write directly to an object as custom-properties
|
---|
| 322 | opts['custom-media'] = toJSON(customExports.customMedia);
|
---|
| 323 | opts['custom-properties'] = toJSON(customExports.customProperties);
|
---|
| 324 | opts['custom-selectors'] = toJSON(customExports.customSelectors);
|
---|
| 325 | } else {
|
---|
| 326 | // destination pathname
|
---|
| 327 | const to = String(opts.to || ''); // type of file being written to
|
---|
| 328 |
|
---|
| 329 | const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase(); // transformed Exports
|
---|
| 330 |
|
---|
| 331 | const customMediaJSON = toJSON(customExports.customMedia);
|
---|
| 332 | const customPropertiesJSON = toJSON(customExports.customProperties);
|
---|
| 333 | const customSelectorsJSON = toJSON(customExports.customSelectors);
|
---|
| 334 |
|
---|
| 335 | if (type === 'css') {
|
---|
| 336 | yield writeExportsToCssFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON);
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | if (type === 'js') {
|
---|
| 340 | yield writeExportsToCjsFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | if (type === 'json') {
|
---|
| 344 | yield writeExportsToJsonFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON);
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | if (type === 'mjs') {
|
---|
| 348 | yield writeExportsToMjsFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON);
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 | });
|
---|
| 353 |
|
---|
| 354 | return function (_x17) {
|
---|
| 355 | return _ref.apply(this, arguments);
|
---|
| 356 | };
|
---|
| 357 | }()));
|
---|
| 358 | }
|
---|
| 359 | /* Helper utilities
|
---|
| 360 | /* ========================================================================== */
|
---|
| 361 |
|
---|
| 362 | function getObjectWithStringifiedKeys(object) {
|
---|
| 363 | return Object.keys(object).reduce((objectJSON, key) => {
|
---|
| 364 | objectJSON[key] = String(object[key]);
|
---|
| 365 | return objectJSON;
|
---|
| 366 | }, {});
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | function writeFile(to, text) {
|
---|
| 370 | return new Promise((resolve, reject) => {
|
---|
| 371 | fs.writeFile(to, text, error => {
|
---|
| 372 | if (error) {
|
---|
| 373 | reject(error);
|
---|
| 374 | } else {
|
---|
| 375 | resolve();
|
---|
| 376 | }
|
---|
| 377 | });
|
---|
| 378 | });
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | function escapeForJS(string) {
|
---|
| 382 | return string.replace(/\\([\s\S])|(')/g, '\\$1$2').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | var postcss = postcss$1.plugin('postcss-preset-env', opts => {
|
---|
| 386 | // initialize options
|
---|
| 387 | const features = Object(Object(opts).features);
|
---|
| 388 | const insertBefore = Object(Object(opts).insertBefore);
|
---|
| 389 | const insertAfter = Object(Object(opts).insertAfter);
|
---|
| 390 | const browsers = Object(opts).browsers;
|
---|
| 391 | const stage = 'stage' in Object(opts) ? opts.stage === false ? 5 : parseInt(opts.stage) || 0 : 2;
|
---|
| 392 | const autoprefixerOptions = Object(opts).autoprefixer;
|
---|
| 393 | const sharedOpts = initializeSharedOpts(Object(opts));
|
---|
| 394 | const stagedAutoprefixer = autoprefixerOptions === false ? () => {} : autoprefixer(Object.assign({
|
---|
| 395 | overrideBrowserslist: browsers
|
---|
| 396 | }, autoprefixerOptions)); // polyfillable features (those with an available postcss plugin)
|
---|
| 397 |
|
---|
| 398 | const polyfillableFeatures = cssdb.concat( // additional features to be inserted before cssdb features
|
---|
| 399 | getTransformedInsertions(insertBefore, 'insertBefore'), // additional features to be inserted after cssdb features
|
---|
| 400 | getTransformedInsertions(insertAfter, 'insertAfter')).filter( // inserted features or features with an available postcss plugin
|
---|
| 401 | feature => feature.insertBefore || feature.id in plugins).sort( // features sorted by execution order and then insertion order
|
---|
| 402 | (a, b) => idsByExecutionOrder.indexOf(a.id) - idsByExecutionOrder.indexOf(b.id) || (a.insertBefore ? -1 : b.insertBefore ? 1 : 0) || (a.insertAfter ? 1 : b.insertAfter ? -1 : 0)).map( // polyfillable features as an object
|
---|
| 403 | feature => {
|
---|
| 404 | // target browsers for the polyfill
|
---|
| 405 | const unsupportedBrowsers = getUnsupportedBrowsersByFeature(feature.caniuse);
|
---|
| 406 | return feature.insertBefore || feature.insertAfter ? {
|
---|
| 407 | browsers: unsupportedBrowsers,
|
---|
| 408 | plugin: feature.plugin,
|
---|
| 409 | id: `${feature.insertBefore ? 'before' : 'after'}-${feature.id}`,
|
---|
| 410 | stage: 6
|
---|
| 411 | } : {
|
---|
| 412 | browsers: unsupportedBrowsers,
|
---|
| 413 | plugin: plugins[feature.id],
|
---|
| 414 | id: feature.id,
|
---|
| 415 | stage: feature.stage
|
---|
| 416 | };
|
---|
| 417 | }); // staged features (those at or above the selected stage)
|
---|
| 418 |
|
---|
| 419 | const stagedFeatures = polyfillableFeatures.filter(feature => feature.id in features ? features[feature.id] : feature.stage >= stage).map(feature => ({
|
---|
| 420 | browsers: feature.browsers,
|
---|
| 421 | plugin: typeof feature.plugin.process === 'function' ? features[feature.id] === true ? sharedOpts // if the plugin is enabled and has shared options
|
---|
| 422 | ? feature.plugin(Object.assign({}, sharedOpts)) // otherwise, if the plugin is enabled
|
---|
| 423 | : feature.plugin() : sharedOpts // if the plugin has shared options and individual options
|
---|
| 424 | ? feature.plugin(Object.assign({}, sharedOpts, features[feature.id])) // if the plugin has individual options
|
---|
| 425 | : feature.plugin(Object.assign({}, features[feature.id])) // if the plugin is already initialized
|
---|
| 426 | : feature.plugin,
|
---|
| 427 | id: feature.id
|
---|
| 428 | })); // browsers supported by the configuration
|
---|
| 429 |
|
---|
| 430 | const supportedBrowsers = browserslist(browsers, {
|
---|
| 431 | ignoreUnknownVersions: true
|
---|
| 432 | }); // features supported by the stage and browsers
|
---|
| 433 |
|
---|
| 434 | const supportedFeatures = stagedFeatures.filter(feature => supportedBrowsers.some(supportedBrowser => browserslist(feature.browsers, {
|
---|
| 435 | ignoreUnknownVersions: true
|
---|
| 436 | }).some(polyfillBrowser => polyfillBrowser === supportedBrowser)));
|
---|
| 437 | return (root, result) => {
|
---|
| 438 | // polyfills run in execution order
|
---|
| 439 | const polyfills = supportedFeatures.reduce((promise, feature) => promise.then(() => feature.plugin(result.root, result)), Promise.resolve()).then(() => stagedAutoprefixer(result.root, result)).then(() => {
|
---|
| 440 | if (Object(opts).exportTo) {
|
---|
| 441 | writeToExports(sharedOpts.exportTo, opts.exportTo);
|
---|
| 442 | }
|
---|
| 443 | });
|
---|
| 444 | return polyfills;
|
---|
| 445 | };
|
---|
| 446 | });
|
---|
| 447 |
|
---|
| 448 | const initializeSharedOpts = opts => {
|
---|
| 449 | if ('importFrom' in opts || 'exportTo' in opts || 'preserve' in opts) {
|
---|
| 450 | const sharedOpts = {};
|
---|
| 451 |
|
---|
| 452 | if ('importFrom' in opts) {
|
---|
| 453 | sharedOpts.importFrom = opts.importFrom;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | if ('exportTo' in opts) {
|
---|
| 457 | sharedOpts.exportTo = {
|
---|
| 458 | customMedia: {},
|
---|
| 459 | customProperties: {},
|
---|
| 460 | customSelectors: {}
|
---|
| 461 | };
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | if ('preserve' in opts) {
|
---|
| 465 | sharedOpts.preserve = opts.preserve;
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | return sharedOpts;
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | return false;
|
---|
| 472 | };
|
---|
| 473 |
|
---|
| 474 | export default postcss;
|
---|
| 475 | //# sourceMappingURL=index.mjs.map
|
---|