storybook-addon-pseudo-states 1.15.0 → 1.15.2--canary.45.07abc1b.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v1.15.1 (Wed Jun 22 2022)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Update react and react-dom peer dependencies level [#35](https://github.com/chromaui/storybook-addon-pseudo-states/pull/35) ([@dsueltenfuss](https://github.com/dsueltenfuss))
6
+
7
+ #### Authors: 1
8
+
9
+ - Dave Sueltenfuss ([@dsueltenfuss](https://github.com/dsueltenfuss))
10
+
11
+ ---
12
+
1
13
  # v1.15.0 (Thu Jun 16 2022)
2
14
 
3
15
  #### 🚀 Enhancement
@@ -1,53 +1,28 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.PseudoStateTool = void 0;
9
-
10
7
  var _react = _interopRequireWildcard(require("react"));
11
-
12
8
  var _api = require("@storybook/api");
13
-
14
9
  var _components = require("@storybook/components");
15
-
16
10
  var _theming = require("@storybook/theming");
17
-
18
11
  var _constants = require("./constants");
19
-
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
-
22
- 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; }
23
-
24
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
-
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
27
-
28
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
-
30
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
31
-
32
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
33
-
34
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
35
-
36
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
37
-
38
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
39
-
40
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
41
-
42
- var LinkTitle = _theming.styled.span(function (_ref) {
43
- var active = _ref.active;
12
+ 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); }
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
+ const LinkTitle = _theming.styled.span(_ref => {
15
+ let {
16
+ active
17
+ } = _ref;
44
18
  return {
45
19
  color: active ? _theming.color.secondary : "inherit"
46
20
  };
47
21
  });
48
-
49
- var LinkIcon = (0, _theming.styled)(_components.Icons)(function (_ref2) {
50
- var active = _ref2.active;
22
+ const LinkIcon = (0, _theming.styled)(_components.Icons)(_ref2 => {
23
+ let {
24
+ active
25
+ } = _ref2;
51
26
  return {
52
27
  opacity: active ? 1 : 0,
53
28
  path: {
@@ -55,47 +30,37 @@ var LinkIcon = (0, _theming.styled)(_components.Icons)(function (_ref2) {
55
30
  }
56
31
  };
57
32
  });
58
- var options = Object.keys(_constants.PSEUDO_STATES).sort();
59
-
60
- var PseudoStateTool = function PseudoStateTool() {
61
- var _useGlobals = (0, _api.useGlobals)(),
62
- _useGlobals2 = _slicedToArray(_useGlobals, 2),
63
- pseudo = _useGlobals2[0].pseudo,
64
- updateGlobals = _useGlobals2[1];
65
-
66
- var isActive = (0, _react.useCallback)(function (option) {
67
- return (pseudo === null || pseudo === void 0 ? void 0 : pseudo[option]) === true;
68
- }, [pseudo]);
69
- var toggleOption = (0, _react.useCallback)(function (option) {
70
- return function () {
71
- return updateGlobals({
72
- pseudo: _objectSpread(_objectSpread({}, pseudo), {}, _defineProperty({}, option, !isActive(option)))
73
- });
74
- };
75
- }, [pseudo]);
33
+ const options = Object.keys(_constants.PSEUDO_STATES).sort();
34
+ const PseudoStateTool = () => {
35
+ const [{
36
+ pseudo
37
+ }, updateGlobals] = (0, _api.useGlobals)();
38
+ const isActive = (0, _react.useCallback)(option => pseudo?.[option] === true, [pseudo]);
39
+ const toggleOption = (0, _react.useCallback)(option => () => updateGlobals({
40
+ pseudo: {
41
+ ...pseudo,
42
+ [option]: !isActive(option)
43
+ }
44
+ }), [pseudo]);
76
45
  return /*#__PURE__*/_react.default.createElement(_components.WithTooltip, {
77
46
  placement: "top",
78
47
  trigger: "click",
79
- tooltip: function tooltip() {
80
- return /*#__PURE__*/_react.default.createElement(_components.TooltipLinkList, {
81
- links: options.map(function (option) {
82
- return {
83
- id: option,
84
- title: /*#__PURE__*/_react.default.createElement(LinkTitle, {
85
- active: isActive(option)
86
- }, ":", _constants.PSEUDO_STATES[option]),
87
- right: /*#__PURE__*/_react.default.createElement(LinkIcon, {
88
- icon: "check",
89
- width: 12,
90
- height: 12,
91
- active: isActive(option)
92
- }),
93
- onClick: toggleOption(option),
94
- active: isActive(option)
95
- };
96
- })
97
- });
98
- }
48
+ tooltip: () => /*#__PURE__*/_react.default.createElement(_components.TooltipLinkList, {
49
+ links: options.map(option => ({
50
+ id: option,
51
+ title: /*#__PURE__*/_react.default.createElement(LinkTitle, {
52
+ active: isActive(option)
53
+ }, ":", _constants.PSEUDO_STATES[option]),
54
+ right: /*#__PURE__*/_react.default.createElement(LinkIcon, {
55
+ icon: "check",
56
+ width: 12,
57
+ height: 12,
58
+ active: isActive(option)
59
+ }),
60
+ onClick: toggleOption(option),
61
+ active: isActive(option)
62
+ }))
63
+ })
99
64
  }, /*#__PURE__*/_react.default.createElement(_components.IconButton, {
100
65
  key: "pseudo-state",
101
66
  title: "Select CSS pseudo states",
@@ -104,5 +69,4 @@ var PseudoStateTool = function PseudoStateTool() {
104
69
  icon: "button"
105
70
  })));
106
71
  };
107
-
108
72
  exports.PseudoStateTool = PseudoStateTool;
@@ -3,14 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TOOL_ID = exports.PSEUDO_STATES = exports.ADDON_ID = void 0;
7
- var ADDON_ID = "storybook/pseudo-states";
6
+ exports.TOOL_ID = exports.PSEUDO_STATES = exports.EXCLUDED_PSEUDO_ELEMENTS = exports.ADDON_ID = void 0;
7
+ const ADDON_ID = "storybook/pseudo-states";
8
8
  exports.ADDON_ID = ADDON_ID;
9
- var TOOL_ID = "".concat(ADDON_ID, "/tool"); // Dynamic pseudo-classes
10
- // @see https://www.w3.org/TR/2018/REC-selectors-3-20181106/#dynamic-pseudos
9
+ const TOOL_ID = `${ADDON_ID}/tool`;
11
10
 
11
+ // Pseudo-classes, which are not allowed to have classes applied on
12
+ // e.g. ::-webkit-scrollbar-thumb.pseudo-hover is not a valid selector
12
13
  exports.TOOL_ID = TOOL_ID;
13
- var PSEUDO_STATES = {
14
+ const EXCLUDED_PSEUDO_ELEMENTS = ["::-webkit-scrollbar-thumb"];
15
+
16
+ // Dynamic pseudo-classes
17
+ // @see https://www.w3.org/TR/2018/REC-selectors-3-20181106/#dynamic-pseudos
18
+ exports.EXCLUDED_PSEUDO_ELEMENTS = EXCLUDED_PSEUDO_ELEMENTS;
19
+ const PSEUDO_STATES = {
14
20
  hover: "hover",
15
21
  active: "active",
16
22
  focusVisible: "focus-visible",
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _addons = require("@storybook/addons");
4
-
5
4
  var _constants = require("../constants");
6
-
7
5
  var _PseudoStateTool = require("../PseudoStateTool");
8
-
9
- _addons.addons.register(_constants.ADDON_ID, function () {
6
+ _addons.addons.register(_constants.ADDON_ID, () => {
10
7
  _addons.addons.add(_constants.TOOL_ID, {
11
8
  type: _addons.types.TOOL,
12
9
  title: "CSS pseudo states",
13
- match: function match(_ref) {
14
- var viewMode = _ref.viewMode;
10
+ match: _ref => {
11
+ let {
12
+ viewMode
13
+ } = _ref;
15
14
  return viewMode === "story";
16
15
  },
17
16
  render: _PseudoStateTool.PseudoStateTool
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.decorators = void 0;
7
-
8
7
  var _withPseudoState = require("../withPseudoState");
9
-
10
- var decorators = [_withPseudoState.withPseudoState];
8
+ const decorators = [_withPseudoState.withPseudoState];
11
9
  exports.decorators = decorators;
@@ -4,108 +4,78 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.rewriteStyleSheet = void 0;
7
-
8
7
  var _constants = require("./constants");
9
-
10
8
  var _splitSelectors = require("./splitSelectors");
11
-
12
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
-
14
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
-
16
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
17
-
18
- var pseudoStates = Object.values(_constants.PSEUDO_STATES);
19
- var matchOne = new RegExp(":(".concat(pseudoStates.join("|"), ")"));
20
- var matchAll = new RegExp(":(".concat(pseudoStates.join("|"), ")"), "g");
21
- var warnings = new Set();
22
-
23
- var warnOnce = function warnOnce(message) {
24
- if (warnings.has(message)) return; // eslint-disable-next-line no-console
25
-
9
+ const pseudoStates = Object.values(_constants.PSEUDO_STATES);
10
+ const matchOne = new RegExp(`:(${pseudoStates.join("|")})`);
11
+ const matchAll = new RegExp(`:(${pseudoStates.join("|")})`, "g");
12
+ const warnings = new Set();
13
+ const warnOnce = message => {
14
+ if (warnings.has(message)) return;
15
+ // eslint-disable-next-line no-console
26
16
  console.warn(message);
27
17
  warnings.add(message);
28
18
  };
29
-
30
- var rewriteRule = function rewriteRule(cssText, selectorText, shadowRoot) {
31
- return cssText.replace(selectorText, (0, _splitSelectors.splitSelectors)(selectorText).flatMap(function (selector) {
19
+ const rewriteRule = (cssText, selectorText, shadowRoot) => {
20
+ return cssText.replace(selectorText, (0, _splitSelectors.splitSelectors)(selectorText).flatMap(selector => {
32
21
  if (selector.includes(".pseudo-")) {
33
22
  return [];
34
23
  }
35
-
36
24
  if (!matchOne.test(selector)) {
37
25
  return [selector];
38
26
  }
39
-
40
- var states = [];
41
- var plainSelector = selector.replace(matchAll, function (_, state) {
27
+ const states = [];
28
+ const plainSelector = selector.replace(matchAll, (_, state) => {
42
29
  states.push(state);
43
30
  return "";
44
31
  });
45
- var classSelector = states.reduce(function (acc, state) {
46
- return acc.replace(new RegExp(":".concat(state), "g"), ".pseudo-".concat(state));
32
+ const getDoesSelectorEndsWithExcludedPseudoElement = pseudo => _constants.EXCLUDED_PSEUDO_ELEMENTS.some(element => {
33
+ return selector.endsWith(`${element}:${pseudo}`);
34
+ });
35
+ const classSelector = states.reduce((acc, state) => {
36
+ if (getDoesSelectorEndsWithExcludedPseudoElement(state)) {
37
+ return undefined;
38
+ }
39
+ return acc.replace(new RegExp(`(?<!Y):${state}`, "g"), `.pseudo-${state}`);
47
40
  }, selector);
48
-
49
41
  if (selector.startsWith(":host(") || selector.startsWith("::slotted(")) {
50
42
  return [selector, classSelector];
51
43
  }
52
-
53
- var ancestorSelector = shadowRoot ? ":host(".concat(states.map(function (s) {
54
- return ".pseudo-".concat(s);
55
- }).join(""), ") ").concat(plainSelector) : "".concat(states.map(function (s) {
56
- return ".pseudo-".concat(s);
57
- }).join(""), " ").concat(plainSelector);
58
- return [selector, classSelector, ancestorSelector].filter(function (selector) {
59
- return !selector.includes(":not()");
60
- });
44
+ const ancestorSelector = shadowRoot ? `:host(${states.map(s => `.pseudo-${s}`).join("")}) ${plainSelector}` : `${states.map(s => `.pseudo-${s}`).join("")} ${plainSelector}`;
45
+ return [selector, classSelector, ancestorSelector].filter(selector => !selector?.includes(":not()")).filter(Boolean);
61
46
  }).join(", "));
62
- }; // Rewrites the style sheet to add alternative selectors for any rule that targets a pseudo state.
63
- // A sheet can only be rewritten once, and may carry over between stories.
64
-
47
+ };
65
48
 
66
- var rewriteStyleSheet = function rewriteStyleSheet(sheet, shadowRoot, shadowHosts) {
49
+ // Rewrites the style sheet to add alternative selectors for any rule that targets a pseudo state.
50
+ // A sheet can only be rewritten once, and may carry over between stories.
51
+ const rewriteStyleSheet = (sheet, shadowRoot, shadowHosts) => {
67
52
  if (sheet.__pseudoStatesRewritten) return;
68
53
  sheet.__pseudoStatesRewritten = true;
69
-
70
54
  try {
71
- var index = 0;
72
-
73
- var _iterator = _createForOfIteratorHelper(sheet.cssRules),
74
- _step;
75
-
76
- try {
77
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
78
- var _step$value = _step.value,
79
- cssText = _step$value.cssText,
80
- selectorText = _step$value.selectorText;
81
-
82
- if (matchOne.test(selectorText)) {
83
- var newRule = rewriteRule(cssText, selectorText, shadowRoot);
84
- sheet.deleteRule(index);
85
- sheet.insertRule(newRule, index);
86
- if (shadowRoot) shadowHosts.add(shadowRoot.host);
87
- }
88
-
89
- index++;
90
-
91
- if (index > 1000) {
92
- warnOnce("Reached maximum of 1000 pseudo selectors per sheet, skipping the rest.");
93
- break;
94
- }
55
+ let index = 0;
56
+ for (const {
57
+ cssText,
58
+ selectorText
59
+ } of sheet.cssRules) {
60
+ if (matchOne.test(selectorText)) {
61
+ const newRule = rewriteRule(cssText, selectorText, shadowRoot);
62
+ sheet.deleteRule(index);
63
+ sheet.insertRule(newRule, index);
64
+ if (shadowRoot) shadowHosts.add(shadowRoot.host);
65
+ }
66
+ index++;
67
+ if (index > 1000) {
68
+ warnOnce("Reached maximum of 1000 pseudo selectors per sheet, skipping the rest.");
69
+ break;
95
70
  }
96
- } catch (err) {
97
- _iterator.e(err);
98
- } finally {
99
- _iterator.f();
100
71
  }
101
72
  } catch (e) {
102
73
  if (e.toString().includes("cssRules")) {
103
- warnOnce("Can't access cssRules, likely due to CORS restrictions: ".concat(sheet.href));
74
+ warnOnce(`Can't access cssRules, likely due to CORS restrictions: ${sheet.href}`);
104
75
  } else {
105
76
  // eslint-disable-next-line no-console
106
77
  console.error(e, sheet.href);
107
78
  }
108
79
  }
109
80
  };
110
-
111
81
  exports.rewriteStyleSheet = rewriteStyleSheet;
@@ -1,84 +1,68 @@
1
1
  "use strict";
2
2
 
3
3
  var _rewriteStyleSheet = require("./rewriteStyleSheet");
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
7
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
8
-
9
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
-
11
- var Sheet = /*#__PURE__*/function () {
12
- function Sheet() {
13
- _classCallCheck(this, Sheet);
14
-
4
+ class Sheet {
5
+ constructor() {
15
6
  this.__pseudoStatesRewritten = false;
16
-
17
7
  for (var _len = arguments.length, rules = new Array(_len), _key = 0; _key < _len; _key++) {
18
8
  rules[_key] = arguments[_key];
19
9
  }
20
-
21
- this.cssRules = rules.map(function (cssText) {
22
- return {
23
- cssText: cssText,
24
- selectorText: cssText.slice(0, cssText.indexOf(" {"))
25
- };
26
- });
10
+ this.cssRules = rules.map(cssText => ({
11
+ cssText,
12
+ selectorText: cssText.slice(0, cssText.indexOf(" {"))
13
+ }));
27
14
  }
28
-
29
- _createClass(Sheet, [{
30
- key: "deleteRule",
31
- value: function deleteRule(index) {
32
- this.cssRules.splice(index, 1);
33
- }
34
- }, {
35
- key: "insertRule",
36
- value: function insertRule(cssText, index) {
37
- this.cssRules.splice(index, 0, cssText);
38
- }
39
- }]);
40
-
41
- return Sheet;
42
- }();
43
-
44
- describe("rewriteStyleSheet", function () {
45
- it("adds alternative selector targeting the element directly", function () {
46
- var sheet = new Sheet("a:hover { color: red }");
15
+ deleteRule(index) {
16
+ this.cssRules.splice(index, 1);
17
+ }
18
+ insertRule(cssText, index) {
19
+ this.cssRules.splice(index, 0, cssText);
20
+ }
21
+ }
22
+ describe("rewriteStyleSheet", () => {
23
+ it("adds alternative selector targeting the element directly", () => {
24
+ const sheet = new Sheet("a:hover { color: red }");
47
25
  (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
48
26
  expect(sheet.cssRules[0]).toContain("a.pseudo-hover");
49
27
  });
50
- it("adds alternative selector targeting an ancestor", function () {
51
- var sheet = new Sheet("a:hover { color: red }");
28
+ it("adds alternative selector targeting an ancestor", () => {
29
+ const sheet = new Sheet("a:hover { color: red }");
52
30
  (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
53
31
  expect(sheet.cssRules[0]).toContain(".pseudo-hover a");
54
32
  });
55
- it("adds alternative selector for each pseudo selector", function () {
56
- var sheet = new Sheet("a:hover, a:focus { color: red }");
33
+ it("does not add .pseudo-<class> to pseudo-class, which does not support classes", () => {
34
+ const sheet = new Sheet("::-webkit-scrollbar-thumb:hover { border-color: transparent; }");
35
+ (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
36
+ console.log(sheet.cssRules[0]);
37
+ expect(sheet.cssRules[0]).not.toContain("::-webkit-scrollbar-thumb.pseudo-hover");
38
+ });
39
+ it("adds alternative selector for each pseudo selector", () => {
40
+ const sheet = new Sheet("a:hover, a:focus { color: red }");
57
41
  (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
58
42
  expect(sheet.cssRules[0]).toContain("a.pseudo-hover");
59
43
  expect(sheet.cssRules[0]).toContain("a.pseudo-focus");
60
44
  expect(sheet.cssRules[0]).toContain(".pseudo-hover a");
61
45
  expect(sheet.cssRules[0]).toContain(".pseudo-focus a");
62
46
  });
63
- it("keeps non-pseudo selectors as-is", function () {
64
- var sheet = new Sheet("a.class, a:hover, a:focus, a#id { color: red }");
47
+ it("keeps non-pseudo selectors as-is", () => {
48
+ const sheet = new Sheet("a.class, a:hover, a:focus, a#id { color: red }");
65
49
  (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
66
50
  expect(sheet.cssRules[0]).toContain("a.class");
67
51
  expect(sheet.cssRules[0]).toContain("a#id");
68
52
  });
69
- it("supports combined pseudo selectors", function () {
70
- var sheet = new Sheet("a:hover:focus { color: red }");
53
+ it("supports combined pseudo selectors", () => {
54
+ const sheet = new Sheet("a:hover:focus { color: red }");
71
55
  (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
72
56
  expect(sheet.cssRules[0]).toContain("a.pseudo-hover.pseudo-focus");
73
57
  expect(sheet.cssRules[0]).toContain(".pseudo-hover.pseudo-focus a");
74
58
  });
75
- it('supports ":host"', function () {
76
- var sheet = new Sheet(":host(:hover) { color: red }");
59
+ it('supports ":host"', () => {
60
+ const sheet = new Sheet(":host(:hover) { color: red }");
77
61
  (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
78
62
  expect(sheet.cssRules[0]).toEqual(":host(:hover), :host(.pseudo-hover) { color: red }");
79
63
  });
80
- it('supports ":not"', function () {
81
- var sheet = new Sheet(":not(:hover) { color: red }");
64
+ it('supports ":not"', () => {
65
+ const sheet = new Sheet(":not(:hover) { color: red }");
82
66
  (0, _rewriteStyleSheet.rewriteStyleSheet)(sheet);
83
67
  expect(sheet.cssRules[0]).toEqual(":not(:hover), :not(.pseudo-hover) { color: red }");
84
68
  });
@@ -4,21 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.splitSelectors = void 0;
7
-
8
- var isAtRule = function isAtRule(selector) {
9
- return selector.indexOf("@") === 0;
10
- };
11
-
12
- var splitSelectors = function splitSelectors(selectors) {
7
+ const isAtRule = selector => selector.indexOf("@") === 0;
8
+ const splitSelectors = selectors => {
13
9
  if (isAtRule(selectors)) return [selectors];
14
- var result = [];
15
- var parentheses = 0;
16
- var brackets = 0;
17
- var selector = "";
18
-
19
- for (var i = 0, len = selectors.length; i < len; i++) {
20
- var char = selectors[i];
21
-
10
+ let result = [];
11
+ let parentheses = 0;
12
+ let brackets = 0;
13
+ let selector = "";
14
+ for (let i = 0, len = selectors.length; i < len; i++) {
15
+ const char = selectors[i];
22
16
  if (char === "(") {
23
17
  parentheses += 1;
24
18
  } else if (char === ")") {
@@ -34,12 +28,9 @@ var splitSelectors = function splitSelectors(selectors) {
34
28
  continue;
35
29
  }
36
30
  }
37
-
38
31
  selector += char;
39
32
  }
40
-
41
33
  result.push(selector.trim());
42
34
  return result;
43
35
  };
44
-
45
36
  exports.splitSelectors = splitSelectors;
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _splitSelectors = require("./splitSelectors");
4
-
5
- describe("splitSelectors", function () {
6
- test("handles basic selectors", function () {
4
+ describe("splitSelectors", () => {
5
+ test("handles basic selectors", () => {
7
6
  expect((0, _splitSelectors.splitSelectors)(".a")).toEqual([".a"]);
8
7
  expect((0, _splitSelectors.splitSelectors)(".a, .b")).toEqual([".a", ".b"]);
9
8
  });
10
- test("supports ::slotted and :is", function () {
9
+ test("supports ::slotted and :is", () => {
11
10
  expect((0, _splitSelectors.splitSelectors)("::slotted(:is(button, a):active)")).toEqual(["::slotted(:is(button, a):active)"]);
12
11
  expect((0, _splitSelectors.splitSelectors)("::slotted(:is(button, a):active), ::slotted(:is(button, a):hover)")).toEqual(["::slotted(:is(button, a):active)", "::slotted(:is(button, a):hover)"]);
13
12
  });
14
- test("supports :host", function () {
13
+ test("supports :host", () => {
15
14
  expect((0, _splitSelectors.splitSelectors)(":host([type='secondary']) ::slotted(:is(button, a)), :host([type='primary']) ::slotted(:is(button, a):active)")).toEqual([":host([type='secondary']) ::slotted(:is(button, a))", ":host([type='primary']) ::slotted(:is(button, a):active)"]);
16
15
  expect((0, _splitSelectors.splitSelectors)(":host([outline]) ::slotted(:is(button, a):focus-within:focus-visible:not(:active))")).toEqual([":host([outline]) ::slotted(:is(button, a):focus-within:focus-visible:not(:active))"]);
17
16
  });