@zohodesk/react-cli 0.0.1-beta.17 → 0.0.1-beta.170
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/.eslintignore +1 -0
- package/.eslintrc.js +49 -10
- package/.prettierrc +6 -0
- package/CHANGELOG.md +5 -0
- package/README.md +855 -0
- package/bin/cli.js +215 -46
- package/cert/Tsicsezwild-22-23.crt +37 -0
- package/cert/Tsicsezwild-22-23.key +27 -0
- package/docs/CustomChunks.md +26 -0
- package/docs/DevStart.md +18 -0
- package/docs/HoverActive.md +12 -0
- package/docs/InstallNode.md +28 -0
- package/docs/TODOS.md +10 -0
- package/docs/ValueReplacer.md +60 -0
- package/docs/warnings_while_install.txt +35 -0
- package/files/eslintrc.js +62 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +24 -0
- package/lib/babel/es-plugins-presets.js +34 -0
- package/lib/common/getEntries.js +33 -46
- package/lib/common/getPublicPathConfig.js +40 -0
- package/lib/common/index.js +24 -19
- package/lib/common/splitChunks.js +110 -25
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/templateParameters.js +25 -0
- package/lib/common/testPattern.js +69 -0
- package/lib/common/valueReplacer.js +55 -0
- package/lib/configs/jest.config.js +31 -27
- package/lib/configs/libAlias.js +31 -0
- package/lib/configs/webpack.component.umd.config.js +46 -53
- package/lib/configs/webpack.css.umd.config.js +47 -46
- package/lib/configs/webpack.dev.config.js +98 -84
- package/lib/configs/webpack.docs.config.js +64 -57
- package/lib/configs/webpack.impact.config.js +108 -0
- package/lib/configs/webpack.prod.config.js +146 -104
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +144 -71
- package/lib/jest/coverageCollector.js +68 -35
- package/lib/jest/jsonMaker.js +54 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +92 -42
- package/lib/jest/run.js +75 -28
- package/lib/jest/setup.js +103 -102
- package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
- package/lib/loaderUtils/getCSSLoaders.js +113 -0
- package/lib/loaderUtils/getDevJsLoaders.js +35 -23
- package/lib/loaderUtils/index.js +14 -7
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileBountryLoader.js +17 -0
- package/lib/loaders/fileLoader.js +47 -38
- package/lib/loaders/scriptInstrumentLoader.js +23 -20
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +90 -72
- package/lib/middlewares/SSTMiddleware.js +21 -0
- package/lib/pluginUtils/getDevPlugins.js +177 -30
- package/lib/pluginUtils/getDocsPlugins.js +36 -15
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +244 -37
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +14 -18
- package/lib/pluginUtils/getUMDComponentPlugins.js +14 -9
- package/lib/pluginUtils/index.js +36 -43
- package/lib/plugins/CdnChangePlugin.js +77 -0
- package/lib/plugins/CleanupStatsPlugin.js +28 -0
- package/lib/plugins/EFCPlugin.js +241 -0
- package/lib/plugins/EFCPlugin.md +6 -0
- package/lib/plugins/EFCTemplatePlugin.js +151 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -0
- package/lib/plugins/I18nSplitPlugin/README.md +25 -0
- package/lib/plugins/I18nSplitPlugin/index.js +185 -0
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
- package/lib/plugins/ManifestPlugin.js +86 -0
- package/lib/plugins/ModuleStatsPlugin.js +98 -97
- package/lib/plugins/OptimizeJSPlugin.js +41 -0
- package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
- package/lib/plugins/PublicPathChangePlugin.js +226 -0
- package/lib/plugins/ReportGeneratePlugin.js +181 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +67 -0
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +107 -0
- package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
- package/lib/plugins/SourceMapHookPlugin.js +25 -59
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +39 -0
- package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
- package/lib/plugins/index.js +127 -37
- package/lib/plugins/libraryImpactPlugin.js +190 -0
- package/lib/plugins/webpackwatchrunplugin.js +26 -0
- package/lib/postcss-plugins/ExcludePlugin.js +23 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
- package/lib/postcss-plugins/ValueReplacer.js +46 -0
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +22 -0
- package/lib/postcss-plugins/__test__/test1Input.css +39 -0
- package/lib/postcss-plugins/__test__/test1Output.css +39 -0
- package/lib/postcss-plugins/hoverActivePlugin.js +365 -0
- package/lib/postcss-plugins/variableModifier.js +243 -0
- package/lib/schemas/index.js +534 -66
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/devBuild.js +102 -0
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +94 -79
- package/lib/servers/getCliPath.js +28 -0
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/httpsOptions.js +18 -0
- package/lib/servers/impactServer.js +123 -115
- package/lib/servers/mockserver.js +44 -0
- package/lib/servers/nowatchserver.js +200 -0
- package/lib/servers/scrServer.js +147 -0
- package/lib/servers/server.js +134 -132
- package/lib/servers/ssServer.js +106 -70
- package/lib/sh/reportPublish.sh +16 -10
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +10 -0
- package/lib/utils/babelPresets.js +12 -4
- package/lib/utils/buildstats.html +148 -0
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +16 -109
- package/lib/utils/copyTimezones.js +21 -0
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +77 -0
- package/lib/utils/cssURLReplacer.js +136 -0
- package/lib/utils/dependencyPostPublish.js +42 -0
- package/lib/utils/fileUtils.js +125 -0
- package/lib/utils/folderIterator.js +47 -0
- package/lib/utils/getComponents.js +126 -0
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +151 -0
- package/lib/utils/getHash.js +26 -0
- package/lib/utils/getIp.js +20 -0
- package/lib/utils/getOptions.js +113 -28
- package/lib/utils/getServerURL.js +25 -8
- package/lib/utils/index.js +283 -68
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +47 -27
- package/lib/utils/jsonHelper.js +106 -0
- package/lib/utils/libraryImpactConfig.js +63 -0
- package/lib/utils/lint/addScripts.js +27 -0
- package/lib/utils/lint/checkExistingConfig.js +67 -0
- package/lib/utils/lint/copyConfigs.js +24 -0
- package/lib/utils/lint/index.js +54 -0
- package/lib/utils/lint/lintScripts.js +11 -0
- package/lib/utils/lint/lintSetup.js +31 -0
- package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
- package/lib/utils/lint/question.js +30 -0
- package/lib/utils/lintReporter.js +142 -0
- package/lib/utils/mailSender.js +16 -25
- package/lib/utils/pullOrigin.js +28 -0
- package/lib/utils/reinstallDependencies.js +133 -0
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +59 -63
- package/lib/utils/request.js +64 -77
- package/lib/utils/resultSchema.json +73 -0
- package/lib/utils/rtl.js +59 -0
- package/lib/utils/setEnvVariables.js +13 -0
- package/lib/utils/ssTestHack.js +48 -0
- package/lib/utils/switchBranch.js +28 -0
- package/lib/utils/urlConcat.js +22 -0
- package/lib/utils/useExitCleanup.js +55 -0
- package/npm8.md +9 -0
- package/package.json +96 -64
- package/postpublish.js +6 -0
- package/templates/app/.eslintrc.js +140 -0
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -8
- package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
- package/templates/app/app/properties/i18nkeys.json +3 -3
- package/templates/app/docs/all.html +69 -69
- package/templates/app/mockapi/index.js +18 -13
- package/templates/app/package.json +37 -17
- package/templates/app/src/actions/SampleActions/index.js +37 -0
- package/templates/app/src/actions/index.js +65 -0
- package/templates/app/src/appUrls.js +19 -0
- package/templates/app/src/components/Alert/Alert.js +134 -0
- package/templates/app/src/components/Alert/Alert.module.css +79 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
- package/templates/app/src/components/Sample/Sample.module.css +11 -0
- package/templates/app/src/components/Sample/SampleList.js +61 -0
- package/templates/app/src/components/Slider/Slider.css +41 -0
- package/templates/app/src/components/Slider/Slider.js +55 -0
- package/templates/app/src/containers/AlertContainer/index.js +15 -0
- package/templates/app/src/containers/AppContainer/index.js +96 -0
- package/templates/app/src/containers/AppContainer/index.module.css +27 -0
- package/templates/app/src/containers/CustomMatch/index.js +65 -0
- package/templates/app/src/containers/DevTools/index.js +10 -0
- package/templates/app/src/containers/Header/index.js +67 -0
- package/templates/app/src/containers/Header/index.module.css +43 -0
- package/templates/app/src/containers/Redirect/index.js +63 -0
- package/templates/app/src/containers/Redirector/index.js +47 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
- package/templates/app/src/historyChange.js +5 -0
- package/templates/app/src/index.html +10 -0
- package/templates/app/src/index.js +24 -0
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
- package/templates/app/src/reducers/alertData.js +11 -0
- package/templates/app/src/reducers/index.js +6 -0
- package/templates/app/src/reducers/samples.js +19 -0
- package/templates/app/src/store/configureStore.dev.js +51 -0
- package/templates/app/src/store/configureStore.js +5 -0
- package/templates/app/src/store/configureStore.prod.js +26 -0
- package/templates/app/src/util/Common.js +5 -0
- package/templates/app/src/util/RequestAPI.js +132 -0
- package/templates/appold/README.md +12 -0
- package/templates/appold/app/index.html +8 -0
- package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
- package/templates/appold/app/properties/i18nkeys.json +3 -0
- package/templates/appold/docs/all.html +69 -0
- package/templates/appold/mockapi/index.js +13 -0
- package/templates/{app → appold}/mockapi/tickets.json +0 -0
- package/templates/appold/package.json +17 -0
- package/templates/appold/src/components/Text/Text.css +0 -0
- package/templates/appold/src/components/Text/Text.js +23 -0
- package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
- package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
- package/templates/appold/src/components/docs.js +1 -0
- package/templates/appold/src/components/index.js +5 -0
- package/templates/appold/src/index.js +13 -0
- package/templates/docs/all.html +1 -1
- package/templates/docs/component.html +110 -69
- package/templates/docs/components.html +221 -0
- package/templates/docs/css/component.css +12 -14
- package/templates/docs/css/componentTest.css +7 -0
- package/templates/docs/css/style.css +150 -206
- package/templates/docs/impactReportTemplate.html +154 -0
- package/templates/docs/index.html +1482 -1336
- package/templates/library/src/index.js +0 -0
- package/.npmignore +0 -3
- package/cert/cert.pem +0 -129
- package/cert/key.pem +0 -27
- package/lib/common/getInsertAt.js +0 -36
- package/lib/common/getInsertIntoFunction.js +0 -13
- package/lib/configs/webpack.server.config.js +0 -93
- package/lib/plugins/ChunkManifestReplacePlugin.js +0 -94
- package/lib/plugins/RuntimePublicPathPlugin.js +0 -46
- package/lib/rmcntrlm.sh +0 -14
- package/lib/servers/nodeServer.js +0 -238
- package/lib/templates/HMRTemplate.js +0 -256
- package/lib/templates/publicPathTemplate.js +0 -16
- package/lib/utils/setConfig.js +0 -14
- package/node_modules/history/CHANGES.md +0 -395
- package/node_modules/history/DOMUtils.js +0 -3
- package/node_modules/history/ExecutionEnvironment.js +0 -3
- package/node_modules/history/LICENSE +0 -21
- package/node_modules/history/LocationUtils.js +0 -3
- package/node_modules/history/PathUtils.js +0 -3
- package/node_modules/history/README.md +0 -282
- package/node_modules/history/cjs/history.js +0 -933
- package/node_modules/history/cjs/history.min.js +0 -1
- package/node_modules/history/createBrowserHistory.js +0 -3
- package/node_modules/history/createHashHistory.js +0 -3
- package/node_modules/history/createMemoryHistory.js +0 -3
- package/node_modules/history/createTransitionManager.js +0 -3
- package/node_modules/history/es/DOMUtils.js +0 -7
- package/node_modules/history/es/ExecutionEnvironment.js +0 -7
- package/node_modules/history/es/LocationUtils.js +0 -7
- package/node_modules/history/es/PathUtils.js +0 -7
- package/node_modules/history/es/createBrowserHistory.js +0 -7
- package/node_modules/history/es/createHashHistory.js +0 -7
- package/node_modules/history/es/createMemoryHistory.js +0 -7
- package/node_modules/history/es/createTransitionManager.js +0 -7
- package/node_modules/history/es/warnAboutDeprecatedESMImport.js +0 -35
- package/node_modules/history/esm/history.js +0 -904
- package/node_modules/history/index.js +0 -7
- package/node_modules/history/package.json +0 -134
- package/node_modules/history/umd/history.js +0 -1059
- package/node_modules/history/umd/history.min.js +0 -1
- package/node_modules/history/warnAboutDeprecatedCJSRequire.js +0 -35
- package/templates/app/.npmignore +0 -9
- package/templates/library/.npmignore +0 -9
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _utils = require("../utils");
|
9
|
+
|
10
|
+
class WebpackWatchRunPlugin {
|
11
|
+
apply(compiler) {
|
12
|
+
compiler.hooks.watchRun.tap('WatchRun', comp => {
|
13
|
+
const changedTimes = comp.watchFileSystem.watcher.mtimes;
|
14
|
+
const changedFiles = Object.keys(changedTimes).map(file => `\n ${file}`).join('');
|
15
|
+
|
16
|
+
if (changedFiles.length) {
|
17
|
+
(0, _utils.log)('====================================');
|
18
|
+
(0, _utils.log)('NEW BUILD FILES CHANGED:', changedFiles);
|
19
|
+
(0, _utils.log)('====================================');
|
20
|
+
}
|
21
|
+
});
|
22
|
+
}
|
23
|
+
|
24
|
+
}
|
25
|
+
|
26
|
+
exports.default = WebpackWatchRunPlugin;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
module.exports = _postcss.default.plugin('postcss-exclude-files', opts => {
|
8
|
+
const {
|
9
|
+
plugins
|
10
|
+
} = opts;
|
11
|
+
return (root, result) => {
|
12
|
+
const inputFile = root.source.input.file;
|
13
|
+
let isIgnoredFile = opts.ignore.some(file => inputFile.indexOf(file) !== -1);
|
14
|
+
|
15
|
+
if (!isIgnoredFile) {
|
16
|
+
const handler = response => response.messages.forEach(msg => result.messages.push(msg));
|
17
|
+
|
18
|
+
return (0, _postcss.default)(plugins).process(root, {
|
19
|
+
from: undefined
|
20
|
+
}).then(handler);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
});
|
@@ -0,0 +1,138 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.separateRtlAndLtr = separateRtlAndLtr;
|
7
|
+
exports.separateSingleDir = separateSingleDir;
|
8
|
+
|
9
|
+
var postcss = _interopRequireWildcard(require("postcss"));
|
10
|
+
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
12
|
+
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
14
|
+
|
15
|
+
const oppositeDir = {
|
16
|
+
ltr: 'rtl',
|
17
|
+
rtl: 'ltr'
|
18
|
+
};
|
19
|
+
|
20
|
+
function compareSelector(selector1, selector2) {
|
21
|
+
// console.log({ selector1, selector2 }, selector1 === selector2);
|
22
|
+
return selector1 === selector2;
|
23
|
+
}
|
24
|
+
|
25
|
+
const directionRegexs = {
|
26
|
+
ltr: /\[dir=ltr\]/,
|
27
|
+
rtl: /\[dir=rtl\]/
|
28
|
+
};
|
29
|
+
|
30
|
+
const getRegex = dir => directionRegexs[dir];
|
31
|
+
|
32
|
+
const getOppositeRegex = dir => getRegex(oppositeDir[dir]);
|
33
|
+
|
34
|
+
function selectorMinifySameDir(selector, direction) {
|
35
|
+
// NOTE: if this rule is same dir as current need
|
36
|
+
// then we can just remove that [dir=ltr] or [dir=rtl]
|
37
|
+
// it just for minimaze selector
|
38
|
+
const regex = getRegex(direction);
|
39
|
+
return selector.replace(regex, '').trim();
|
40
|
+
}
|
41
|
+
/**
|
42
|
+
* this funtion will remove given rule,
|
43
|
+
* if given selector and it's previous sibiling rule selector are same
|
44
|
+
* current rule properties will move to previous sibiling rule.
|
45
|
+
* @param {Rule} rule current rule
|
46
|
+
*/
|
47
|
+
|
48
|
+
|
49
|
+
function mergeIfSameSelector(rule) {
|
50
|
+
// NOTE: to merge dublicate selector rules
|
51
|
+
const prev = rule.prev();
|
52
|
+
|
53
|
+
if (prev && compareSelector(prev.selector, rule.selector)) {
|
54
|
+
rule.each(decl => {
|
55
|
+
prev.append(decl);
|
56
|
+
});
|
57
|
+
rule.remove();
|
58
|
+
}
|
59
|
+
}
|
60
|
+
/**
|
61
|
+
* this funtion will remove given rule,
|
62
|
+
* if given selector and it's previous sibiling rule selector are same
|
63
|
+
* current rule properties will move to previous sibiling rule.
|
64
|
+
* @param {Rule} rule current rule
|
65
|
+
*/
|
66
|
+
|
67
|
+
|
68
|
+
function removeIfOppsiteDirRule(rule, direction, rootOptions) {
|
69
|
+
// console.log({ rule, type: rule.type });
|
70
|
+
const selectors = rule.selector.split(/\s*,\s*/); // NOTE: if we use opposite dir selector as custom override reason,
|
71
|
+
// and compain normal selector with it, In this case
|
72
|
+
// we just a have to remove that selector only not full rule
|
73
|
+
|
74
|
+
const oppositeDirRegex = getOppositeRegex(direction);
|
75
|
+
let remainingSelectors = selectors.filter(selector => !oppositeDirRegex.test(selector));
|
76
|
+
|
77
|
+
if (!rootOptions.disableMiniFiySelector) {
|
78
|
+
remainingSelectors = remainingSelectors.map(selector => selectorMinifySameDir(selector, direction));
|
79
|
+
}
|
80
|
+
|
81
|
+
if (remainingSelectors.length) {
|
82
|
+
rule.selector = remainingSelectors.join(', ');
|
83
|
+
} else {
|
84
|
+
// NOTE: every selector is opposite dir then we have to remove the rule
|
85
|
+
rule.remove();
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
function removeIfOppsiteDirKeyframe(rule, direction) {
|
90
|
+
let name = rule.params;
|
91
|
+
let keyFrameDirName = name.slice(name.lastIndexOf('-') + 1);
|
92
|
+
|
93
|
+
if (keyFrameDirName === oppositeDir[direction]) {
|
94
|
+
// console.log({ m: 'removed', keyFrameName: rule.params });
|
95
|
+
rule.remove();
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
function separateSingleDir(root, direction, rootOptions) {
|
100
|
+
root.walkRules(rule => {
|
101
|
+
removeIfOppsiteDirRule(rule, direction, rootOptions);
|
102
|
+
mergeIfSameSelector(rule);
|
103
|
+
});
|
104
|
+
root.walkAtRules(rule => {
|
105
|
+
removeIfOppsiteDirKeyframe(rule, direction);
|
106
|
+
});
|
107
|
+
return root;
|
108
|
+
}
|
109
|
+
|
110
|
+
function separateRtlAndLtr(css, rootOptions) {
|
111
|
+
// let processor = postcss([]).process(css);
|
112
|
+
let root = postcss.parse(css); // let { root } = processor;
|
113
|
+
// console.log(processor, root);
|
114
|
+
// NOTE: I did first rtl then ltr , Because for ltr I use original root ref
|
115
|
+
|
116
|
+
const rtlRoot = separateSingleDir(root.clone(), 'rtl', rootOptions); // console.log('############################');
|
117
|
+
|
118
|
+
const ltrRoot = separateSingleDir(root, 'ltr', rootOptions);
|
119
|
+
return {
|
120
|
+
ltrRoot,
|
121
|
+
rtlRoot,
|
122
|
+
ltr: ltrRoot.toString(),
|
123
|
+
rtl: rtlRoot.toString()
|
124
|
+
};
|
125
|
+
} // NOTE: to test in https://astexplorer.net/
|
126
|
+
// you can test with sample input https://astexplorer.net/#/gist/a892a509eb585099355ef53ef094f836/1ca70d5f7af3b88ca4910296e12f118e9712c874
|
127
|
+
// export default postcss.plugin('postcss-rtl-remove', (options = {}) =>
|
128
|
+
// // Work with options here
|
129
|
+
// root => {
|
130
|
+
// const rtlRoot = separateSingleDir(root.clone(), 'rtl');
|
131
|
+
// const ltrRoot = separateSingleDir(root, 'ltr');
|
132
|
+
// // root.append(postcss.comment({ text: 'comment' }));
|
133
|
+
// root.append(postcss.comment({ text: 'this is spliting part ' }));
|
134
|
+
// root.append(rtlRoot);
|
135
|
+
// //console.log({root, roots:root+""}, root+"")
|
136
|
+
// // Transform CSS AST here
|
137
|
+
// }
|
138
|
+
// );
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
// module.exports = postcss.plugin('postcss-value-replacer', opts => {
|
8
|
+
// const { plugins } = opts;
|
9
|
+
// return (root, result) => {
|
10
|
+
// const inputFile = root.source.input.file;
|
11
|
+
// let isIgnoredFile= opts.ignore.some(file => inputFile.indexOf(file)!==-1);
|
12
|
+
// if (!isIgnoredFile) {
|
13
|
+
// const handler = response =>
|
14
|
+
// response.messages.forEach(msg => result.messages.push(msg));
|
15
|
+
// return postcss(plugins)
|
16
|
+
// .process(root, { from: undefined })
|
17
|
+
// .then(handler);
|
18
|
+
// }
|
19
|
+
// };
|
20
|
+
// });
|
21
|
+
// export default
|
22
|
+
module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
|
23
|
+
root => {
|
24
|
+
root.walkDecls(decl => {
|
25
|
+
valueReplacer.forEach(obj => {
|
26
|
+
if (obj.props.indexOf(decl.prop) !== -1) {
|
27
|
+
let ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
|
28
|
+
ks.forEach(k => {
|
29
|
+
decl.value = decl.value.replace(k, obj.values[k]);
|
30
|
+
}); //decl.value = obj.values[decl.value];
|
31
|
+
}
|
32
|
+
}); //console.log({root, roots:root+""}, root+"")
|
33
|
+
// Transform CSS AST here
|
34
|
+
}); // root.walkDecls(decl => {
|
35
|
+
// valueReplacer.forEach(obj => {
|
36
|
+
// if (
|
37
|
+
// obj.props.indexOf(decl.prop) !== -1 &&
|
38
|
+
// obj.values[decl.value] !== undefined
|
39
|
+
// ) {
|
40
|
+
// decl.value = obj.values[decl.value];
|
41
|
+
// }
|
42
|
+
// });
|
43
|
+
// //console.log({root, roots:root+""}, root+"")
|
44
|
+
// // Transform CSS AST here
|
45
|
+
// });
|
46
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const fs = require('fs');
|
4
|
+
|
5
|
+
const postcss = require('postcss');
|
6
|
+
|
7
|
+
function expectRunPostCss(inputFile, outputfile, cb) {
|
8
|
+
const inputStr = fs.readFileSync(inputFile, 'utf-8');
|
9
|
+
postcss(plugins).process(inputStr, {
|
10
|
+
from,
|
11
|
+
to
|
12
|
+
}).then(result => {
|
13
|
+
expect(result.css).toBe(fs.readFileSync(outputfile, 'utf-8'));
|
14
|
+
cb();
|
15
|
+
});
|
16
|
+
}
|
17
|
+
|
18
|
+
describe('To Check Hover active postcss Plugin ', () => {
|
19
|
+
test('should handle normal rule hover', cb => {
|
20
|
+
expectRunPostCss('test1Input.css', 'test1Output.css', cb);
|
21
|
+
});
|
22
|
+
});
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/*Hover_active:ignore*/
|
2
|
+
g,a:hover{
|
3
|
+
color : red
|
4
|
+
}
|
5
|
+
/*Hover:ignore*/
|
6
|
+
h:hover{
|
7
|
+
background : yellow
|
8
|
+
}
|
9
|
+
|
10
|
+
/* Hover_active:ignore */
|
11
|
+
g,d+e:hover{
|
12
|
+
color : black
|
13
|
+
}
|
14
|
+
|
15
|
+
g,d e:hover{
|
16
|
+
color : black
|
17
|
+
}
|
18
|
+
|
19
|
+
@media screen and (max-width:61.25em){
|
20
|
+
/* Hover_active:ignore */
|
21
|
+
a,b,a:hover, b:hover{
|
22
|
+
background-color : blue
|
23
|
+
}
|
24
|
+
a + b,a:hover + b:hover{
|
25
|
+
background-color : blue
|
26
|
+
}
|
27
|
+
a b:hover{
|
28
|
+
background-color : blue
|
29
|
+
}
|
30
|
+
|
31
|
+
.cc:hover {
|
32
|
+
color: red;
|
33
|
+
}
|
34
|
+
|
35
|
+
c:hover{
|
36
|
+
color : red
|
37
|
+
}
|
38
|
+
|
39
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/*Hover_active:ignore*/
|
2
|
+
g,a:hover{
|
3
|
+
color : red
|
4
|
+
}
|
5
|
+
/*Hover:ignore*/
|
6
|
+
h:hover{
|
7
|
+
background : yellow
|
8
|
+
}
|
9
|
+
|
10
|
+
/* Hover_active:ignore */
|
11
|
+
g,d+e:hover{
|
12
|
+
color : black
|
13
|
+
}
|
14
|
+
|
15
|
+
g,d e:hover{
|
16
|
+
color : black
|
17
|
+
}
|
18
|
+
|
19
|
+
@media screen and (max-width:61.25em){
|
20
|
+
/* Hover_active:ignore */
|
21
|
+
a,b,a:hover, b:hover{
|
22
|
+
background-color : blue
|
23
|
+
}
|
24
|
+
a + b,a:hover + b:hover{
|
25
|
+
background-color : blue
|
26
|
+
}
|
27
|
+
a b:hover{
|
28
|
+
background-color : blue
|
29
|
+
}
|
30
|
+
|
31
|
+
.cc:hover {
|
32
|
+
color: red;
|
33
|
+
}
|
34
|
+
|
35
|
+
c:hover{
|
36
|
+
color : red
|
37
|
+
}
|
38
|
+
|
39
|
+
}
|
@@ -0,0 +1,365 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
/**
|
8
|
+
* we have give support for ignore(exclude) comments
|
9
|
+
* These are the comments' keyword
|
10
|
+
*/
|
11
|
+
const hoverIgnoreQuery = 'Hover:ignore',
|
12
|
+
activeIgnoreQuery = 'Active:ignore',
|
13
|
+
hoverActiveIgnoreQuery = 'HoverActive:ignore';
|
14
|
+
const medHoverIgnoreQuery = 'MedHover:ignore',
|
15
|
+
medActiveIgnoreQuery = 'MedActive:ignore',
|
16
|
+
medHoverActiveIgnoreQuery = 'MedHoverActive:ignore';
|
17
|
+
const hoverMedQuerySuffix = '(min--moz-device-pixel-ratio:0) and (hover: hover), (hover: hover)';
|
18
|
+
const ruleIgnoreCommentRegex = /(Hover:ignore|Active:ignore|HoverActive:ignore)/g;
|
19
|
+
const mediaQueryIgnoreCommentRegex = /(MedHover:ignore|MedActive:ignore|MedHoverActive:ignore)/g;
|
20
|
+
|
21
|
+
function isComment(node) {
|
22
|
+
return node && node.type === 'comment' && node.text !== undefined;
|
23
|
+
}
|
24
|
+
|
25
|
+
function isHoverPresent(atrule) {
|
26
|
+
let hoverPresent = false;
|
27
|
+
atrule.walkRules(rule => {
|
28
|
+
if (rule.selector.includes('hover')) {
|
29
|
+
hoverPresent = true;
|
30
|
+
}
|
31
|
+
});
|
32
|
+
return hoverPresent;
|
33
|
+
}
|
34
|
+
|
35
|
+
module.exports = _postcss.default.plugin('postcss-mobile-hover', () => rootOriginal => {
|
36
|
+
const hoverRules = [];
|
37
|
+
let positionsObj = {};
|
38
|
+
|
39
|
+
function isRuleHasIgnoreComment(index, type) {
|
40
|
+
const prevNode = rootOriginal.nodes[index - 1];
|
41
|
+
|
42
|
+
if (isComment(prevNode)) {
|
43
|
+
return prevNode.text === type;
|
44
|
+
}
|
45
|
+
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
|
49
|
+
function isMediaQueryHasIgnoreComment(node, type) {
|
50
|
+
if (isComment(node)) {
|
51
|
+
return node.text === type;
|
52
|
+
}
|
53
|
+
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
|
57
|
+
function hasIgnoreComment({
|
58
|
+
index,
|
59
|
+
atrule,
|
60
|
+
type
|
61
|
+
}) {
|
62
|
+
if (type.match(mediaQueryIgnoreCommentRegex)) {
|
63
|
+
return isMediaQueryHasIgnoreComment(atrule.nodes[index - 1], type.slice(3));
|
64
|
+
}
|
65
|
+
|
66
|
+
if (type.match(ruleIgnoreCommentRegex)) {
|
67
|
+
return isRuleHasIgnoreComment(index, type);
|
68
|
+
}
|
69
|
+
|
70
|
+
return false;
|
71
|
+
}
|
72
|
+
|
73
|
+
function getPositionsOfHoverAndActiveMedQueries(parent) {
|
74
|
+
const allNodes = rootOriginal.nodes;
|
75
|
+
const hoverMediaQuery = `${parent.params} and all and ${hoverMedQuerySuffix}`;
|
76
|
+
const hoverNoneMediaQuery = `${parent.params} and (hover: none)`;
|
77
|
+
const positions = {
|
78
|
+
hovMed: allNodes[positionsObj[hoverMediaQuery]],
|
79
|
+
actMed: allNodes[positionsObj[hoverNoneMediaQuery]]
|
80
|
+
};
|
81
|
+
return positions;
|
82
|
+
}
|
83
|
+
|
84
|
+
function handleMedHoverAndHoverActiveIgnore(atrule, index) {
|
85
|
+
return !hasIgnoreComment({
|
86
|
+
atrule,
|
87
|
+
index,
|
88
|
+
type: medHoverIgnoreQuery
|
89
|
+
}) && !hasIgnoreComment({
|
90
|
+
atrule,
|
91
|
+
index,
|
92
|
+
type: medHoverActiveIgnoreQuery
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
function handleMedActiveAndHoverActiveIgnore(atrule, index) {
|
97
|
+
return !hasIgnoreComment({
|
98
|
+
atrule,
|
99
|
+
index,
|
100
|
+
type: medActiveIgnoreQuery
|
101
|
+
}) && !hasIgnoreComment({
|
102
|
+
atrule,
|
103
|
+
index,
|
104
|
+
type: medHoverActiveIgnoreQuery
|
105
|
+
});
|
106
|
+
}
|
107
|
+
|
108
|
+
function handleHoverAndHoverActiveIgnore(index) {
|
109
|
+
return !hasIgnoreComment({
|
110
|
+
index,
|
111
|
+
type: hoverIgnoreQuery
|
112
|
+
}) && !hasIgnoreComment({
|
113
|
+
index,
|
114
|
+
type: hoverActiveIgnoreQuery
|
115
|
+
});
|
116
|
+
}
|
117
|
+
|
118
|
+
function handleActiveAndHoverActiveIgnore(index) {
|
119
|
+
return !hasIgnoreComment({
|
120
|
+
index,
|
121
|
+
type: activeIgnoreQuery
|
122
|
+
}) && !hasIgnoreComment({
|
123
|
+
index,
|
124
|
+
type: hoverActiveIgnoreQuery
|
125
|
+
});
|
126
|
+
}
|
127
|
+
|
128
|
+
function handleAllIgnoreCases(index) {
|
129
|
+
return !hasIgnoreComment({
|
130
|
+
index,
|
131
|
+
type: activeIgnoreQuery
|
132
|
+
}) && !hasIgnoreComment({
|
133
|
+
index,
|
134
|
+
type: hoverIgnoreQuery
|
135
|
+
}) && !hasIgnoreComment({
|
136
|
+
index,
|
137
|
+
type: hoverActiveIgnoreQuery
|
138
|
+
});
|
139
|
+
}
|
140
|
+
|
141
|
+
function mediaCommaQuery(rule, index) {
|
142
|
+
if (rule.parent.params !== undefined && !rule.parent.params.includes('hover')) {
|
143
|
+
//console.log(hovMed, actMed);
|
144
|
+
let newSelector = '';
|
145
|
+
let {
|
146
|
+
hovMed,
|
147
|
+
actMed
|
148
|
+
} = getPositionsOfHoverAndActiveMedQueries(rule.parent);
|
149
|
+
let hovQueries = [];
|
150
|
+
let actQueries = [];
|
151
|
+
rule.selector.split(/\s*,\s*/).forEach(_subrule => {
|
152
|
+
let subrule = _subrule.trim();
|
153
|
+
|
154
|
+
let clone = rule.clone();
|
155
|
+
|
156
|
+
if (subrule.includes('hover')) {
|
157
|
+
clone.selector = subrule;
|
158
|
+
|
159
|
+
if (handleMedHoverAndHoverActiveIgnore(rule.parent, index)) {
|
160
|
+
hovQueries.push(subrule);
|
161
|
+
}
|
162
|
+
|
163
|
+
if (handleMedActiveAndHoverActiveIgnore(rule.parent, index)) {
|
164
|
+
actQueries.push(subrule);
|
165
|
+
}
|
166
|
+
} else {
|
167
|
+
newSelector += `${subrule}, `;
|
168
|
+
}
|
169
|
+
});
|
170
|
+
|
171
|
+
if (hovQueries.length > 0) {
|
172
|
+
let clone = rule.clone();
|
173
|
+
clone.selector = hovQueries.join(',');
|
174
|
+
hovMed.append(clone);
|
175
|
+
}
|
176
|
+
|
177
|
+
if (actQueries.length > 0) {
|
178
|
+
let clone = rule.clone();
|
179
|
+
clone.selector = actQueries.join(',');
|
180
|
+
actMed.append(clone.clone({
|
181
|
+
selector: clone.selector.replace(/:hover/gi, ':active')
|
182
|
+
}));
|
183
|
+
}
|
184
|
+
|
185
|
+
if (handleMedHoverAndHoverActiveIgnore(rule.parent, index)) {
|
186
|
+
rule.selector = newSelector.substring(0, newSelector.length - 2);
|
187
|
+
}
|
188
|
+
|
189
|
+
if (rule.selector === '') {
|
190
|
+
rule.remove();
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
function mediaQuery(rule, index) {
|
196
|
+
if (rule.parent.params !== undefined && !rule.parent.params.includes('hover')) {
|
197
|
+
let {
|
198
|
+
hovMed,
|
199
|
+
actMed
|
200
|
+
} = getPositionsOfHoverAndActiveMedQueries(rule.parent);
|
201
|
+
|
202
|
+
if (rule.selector.includes('hover') && hovMed !== undefined && rule.parent.type === 'atrule') {
|
203
|
+
if (handleMedHoverAndHoverActiveIgnore(rule.parent, index)) {
|
204
|
+
hovMed.append(rule);
|
205
|
+
}
|
206
|
+
|
207
|
+
if (handleMedActiveAndHoverActiveIgnore(rule.parent, index)) {
|
208
|
+
actMed.append(rule.clone({
|
209
|
+
selector: rule.selector.replace(/:hover/gi, ':active')
|
210
|
+
}));
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
function commaQuery(rule, index) {
|
217
|
+
//console.log("comma" , rule.selector.split('\n'));
|
218
|
+
let newSelector = '';
|
219
|
+
let hovQueries = [];
|
220
|
+
rule.selector.split(/\s*,\s*/).forEach(_subrule => {
|
221
|
+
let subrule = _subrule.trim();
|
222
|
+
|
223
|
+
if (subrule.includes('hover')) {
|
224
|
+
// hoverRules.push({ rule: clone, index });
|
225
|
+
hovQueries.push(subrule);
|
226
|
+
} else {
|
227
|
+
newSelector += `${subrule}, `;
|
228
|
+
}
|
229
|
+
});
|
230
|
+
|
231
|
+
if (hovQueries.length > 0) {
|
232
|
+
let clone = rule.clone();
|
233
|
+
clone.selector = hovQueries.join(',');
|
234
|
+
hoverRules.push({
|
235
|
+
rule: clone,
|
236
|
+
index
|
237
|
+
});
|
238
|
+
}
|
239
|
+
|
240
|
+
if (handleHoverAndHoverActiveIgnore(index)) {
|
241
|
+
rule.selector = newSelector.substring(0, newSelector.length - 2).trim();
|
242
|
+
}
|
243
|
+
|
244
|
+
if (rule.selector === '') {
|
245
|
+
rule.remove();
|
246
|
+
}
|
247
|
+
} // Start by identifying all :hover rules
|
248
|
+
|
249
|
+
|
250
|
+
rootOriginal.walkAtRules(atrule => {
|
251
|
+
const hoverQuery = `${atrule.params} and all and ${hoverMedQuerySuffix}`;
|
252
|
+
const activeQuery = `${atrule.params} and (hover: none)`;
|
253
|
+
|
254
|
+
if (isHoverPresent(atrule)) {
|
255
|
+
if (!positionsObj[hoverQuery] && !positionsObj[activeQuery]) {
|
256
|
+
rootOriginal.append({
|
257
|
+
name: 'media',
|
258
|
+
params: hoverQuery
|
259
|
+
});
|
260
|
+
positionsObj[hoverQuery] = rootOriginal.nodes.length - 1;
|
261
|
+
rootOriginal.append({
|
262
|
+
name: 'media',
|
263
|
+
params: activeQuery
|
264
|
+
});
|
265
|
+
positionsObj[activeQuery] = rootOriginal.nodes.length - 1;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
});
|
269
|
+
rootOriginal.walkRules(/:hover/i, (rule, index) => {
|
270
|
+
// media hover query with ',' ' ' '+'
|
271
|
+
// console.log("media query" , rule.selector)
|
272
|
+
if (rule.parent.type === 'atrule' && rule.selector.includes(',')) {
|
273
|
+
//console.log("media comma", rule.selector)
|
274
|
+
mediaCommaQuery(rule, index);
|
275
|
+
} else {
|
276
|
+
// plus, space and other media queries
|
277
|
+
//console.log("media", rule.selector)
|
278
|
+
mediaQuery(rule, index);
|
279
|
+
} // usual hover query
|
280
|
+
|
281
|
+
|
282
|
+
if (!rule.selector.match(/,+| +|\++/g) && rule.parent !== undefined && rule.parent.name === undefined) {
|
283
|
+
hoverRules.push({
|
284
|
+
rule,
|
285
|
+
index
|
286
|
+
});
|
287
|
+
} //usual hover query with ',' ' ' '+'
|
288
|
+
|
289
|
+
|
290
|
+
if (rule.selector.match(/,+| +|\++/g) && rule.parent.name === undefined) {
|
291
|
+
if (rule.selector.includes(',')) {
|
292
|
+
commaQuery(rule, index);
|
293
|
+
} else if (rule.selector.match(/ +|\++/g)) {
|
294
|
+
//console.log("plus or space" , rule.selector);
|
295
|
+
if (rule.selector.includes('hover')) {
|
296
|
+
hoverRules.push({
|
297
|
+
rule,
|
298
|
+
index
|
299
|
+
}); //rule.remove();
|
300
|
+
}
|
301
|
+
}
|
302
|
+
}
|
303
|
+
}); // If there are any :hover rules in the input, then create media queries
|
304
|
+
// to automatically translate it into :active on touch-based devices
|
305
|
+
|
306
|
+
if (hoverRules.length > 0) {
|
307
|
+
// Create a media query targetting devices that actually support
|
308
|
+
// hover
|
309
|
+
const hoverQuery = rootOriginal.append({
|
310
|
+
name: 'media',
|
311
|
+
params: `all and ${hoverMedQuerySuffix}`
|
312
|
+
}).last; // Create a media query targetting devices that don't support hover
|
313
|
+
// (ie. devices where we should fall back to :active instead)
|
314
|
+
|
315
|
+
const activeQuery = rootOriginal.append({
|
316
|
+
name: 'media',
|
317
|
+
params: '(hover: none)'
|
318
|
+
}).last; // Loop through the hover rules and apply them to each of the media
|
319
|
+
// queries
|
320
|
+
// eslint-disable-next-line no-labels
|
321
|
+
|
322
|
+
outerLoop: for (const hoverRule of hoverRules) {
|
323
|
+
// determine if the rule has been nested inside another media
|
324
|
+
// query; in that case bail out as we have no way of reliably
|
325
|
+
// nesting these queries
|
326
|
+
let parentRule = hoverRule.rule.parent;
|
327
|
+
|
328
|
+
while (parentRule) {
|
329
|
+
if (parentRule.type === 'atrule' && parentRule.name === 'media') {
|
330
|
+
// eslint-disable-next-line no-labels
|
331
|
+
continue outerLoop;
|
332
|
+
}
|
333
|
+
|
334
|
+
parentRule = parentRule.parent;
|
335
|
+
} // Push a clone of the :hover rule 'as is' to queries where we
|
336
|
+
// expect the user's device to support hover
|
337
|
+
// ieQuery.append(hoverRule.clone());
|
338
|
+
|
339
|
+
|
340
|
+
if (handleHoverAndHoverActiveIgnore(hoverRule.index)) {
|
341
|
+
hoverQuery.append(hoverRule.rule.clone());
|
342
|
+
} // Push a clone of the :hover rule, where we transform the
|
343
|
+
// selector to :active to the query targetting devices that
|
344
|
+
// don't support hover
|
345
|
+
|
346
|
+
|
347
|
+
if (handleActiveAndHoverActiveIgnore(hoverRule.index)) {
|
348
|
+
activeQuery.append(hoverRule.rule.clone({
|
349
|
+
selector: hoverRule.rule.selector.replace(/:hover/gi, ':active')
|
350
|
+
}));
|
351
|
+
} // remove legacy rule from output
|
352
|
+
|
353
|
+
|
354
|
+
if (handleAllIgnoreCases(hoverRule.index)) {
|
355
|
+
hoverRule.rule.remove();
|
356
|
+
}
|
357
|
+
}
|
358
|
+
}
|
359
|
+
|
360
|
+
rootOriginal.walkAtRules(atrule => {
|
361
|
+
if (atrule !== undefined && atrule.nodes !== undefined && atrule.nodes.length === 0 || atrule.nodes === undefined) {
|
362
|
+
atrule.remove();
|
363
|
+
}
|
364
|
+
});
|
365
|
+
});
|