@unsass/selector 1.1.0 → 1.3.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
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
+ ## [1.3.0](https://github.com/unsass/selector/compare/v1.2.0...v1.3.0) (2023-09-11)
6
+
7
+
8
+ ### Features
9
+
10
+ * **create:** add list option for `$scope` parameter ([ebd78c1](https://github.com/unsass/selector/commit/ebd78c1705a2271b4d8bad8b2441936abc928284))
11
+
12
+
13
+ ### Build System
14
+
15
+ * **deps:** bump to `sass` 1.66.1 ([b9ff3d5](https://github.com/unsass/selector/commit/b9ff3d5ccad6ab1a5fba427cfdc753a09f50418d))
16
+ * **deps:** prevent dependencies vulnerabilities ([610177d](https://github.com/unsass/selector/commit/610177d035c8d255e836846fe4a5b7c9be932c08))
17
+
18
+ ## [1.2.0](https://github.com/unsass/selector/compare/v1.1.0...v1.2.0) (2023-03-20)
19
+
20
+
21
+ ### Features
22
+
23
+ * allow `&` nesting selector ([20d12a2](https://github.com/unsass/selector/commit/20d12a2302e8a8c31a60e19094bbeb2aa16af1b1))
24
+
25
+
26
+ ### Code Refactoring
27
+
28
+ * add better error messages ([6ae5295](https://github.com/unsass/selector/commit/6ae529558dc230a0cdf7677b7fa226e2270e5436))
29
+ * removed unneeded sass import ([b817859](https://github.com/unsass/selector/commit/b817859233c967a78f0fba7752cbaedda112abff))
30
+
5
31
  ## [1.1.0](https://github.com/unsass/selector/compare/v1.0.0...v1.1.0) (2023-03-20)
6
32
 
7
33
 
package/README.md CHANGED
@@ -19,7 +19,7 @@ npm install @unsass/selector
19
19
  ```scss
20
20
  @use "@unsass/selector";
21
21
 
22
- @include selector.create("foo") {
22
+ @include selector.create("foo", "md") {
23
23
  color: darkcyan;
24
24
  }
25
25
  ```
@@ -27,15 +27,117 @@ npm install @unsass/selector
27
27
  ### Result
28
28
 
29
29
  ```css
30
- .foo {
30
+ .md\:foo {
31
31
  color: darkcyan;
32
32
  }
33
33
  ```
34
34
 
35
35
  ## API
36
36
 
37
- ### Sass mixins
37
+ | Mixin | Description |
38
+ |-----------------------------------------------------------------------------------------|------------------------------------------------------------|
39
+ | `create($selector, $scope, $separator, $suffix, $pseudo-class, $pseudo-element, $root)` | Sets new CSS selector with class scope and pseudo options. |
40
+
41
+ ### `$separator`
42
+
43
+ Define your own scope separator character.
44
+
45
+ ```scss
46
+ @use "@unsass/selector";
47
+
48
+ @include selector.create("foo", "md", "@") {
49
+ color: darkcyan;
50
+ }
51
+ ```
52
+
53
+ ### Result
54
+
55
+ ```css
56
+ .md\@foo {
57
+ color: darkcyan;
58
+ }
59
+ ```
60
+
61
+ ### `$suffix`
62
+
63
+ Define the scope value has a prefix on selector.
64
+
65
+ ```scss
66
+ @use "@unsass/selector";
67
+
68
+ @include selector.create("foo", "md", $suffix: true) {
69
+ color: darkcyan;
70
+ }
71
+ ```
72
+
73
+ ### Result
74
+
75
+ ```css
76
+ .foo\:md {
77
+ color: darkcyan;
78
+ }
79
+ ```
80
+
81
+ ### `$pseudo-class`
82
+
83
+ Define the pseudo class suffix.
84
+
85
+ ```scss
86
+ @use "@unsass/selector";
87
+
88
+ @include selector.create("foo", "hover", $pseudo-class: "hover") {
89
+ color: darkcyan;
90
+ }
91
+ ```
92
+
93
+ ### Result
94
+
95
+ ```css
96
+ .hover\:foo:hover {
97
+ color: darkcyan;
98
+ }
99
+ ```
100
+
101
+ ### `$pseudo-element`
102
+
103
+ Define the pseudo element suffix.
104
+
105
+ ```scss
106
+ @use "@unsass/selector";
107
+
108
+ @include selector.create("foo", "before", $pseudo-element: "before") {
109
+ color: darkcyan;
110
+ }
111
+ ```
112
+
113
+ ### Result
114
+
115
+ ```css
116
+ .before\:foo::before {
117
+ color: darkcyan;
118
+ }
119
+ ```
120
+
121
+ ### `$root`
122
+
123
+ Wrap the selector with `@at-root` rule before code output.
124
+
125
+ ```scss
126
+ @use "@unsass/selector";
127
+
128
+ .foo {
129
+ .bar {
130
+ @include selector.create(&, "md", $root: true) {
131
+ color: darkcyan;
132
+ }
133
+ }
134
+ }
135
+ ```
136
+
137
+ ### Result
38
138
 
39
- | Mixin | Description |
40
- |----------------------------------------------------------------------------------|------------------------------------------------------------|
41
- | `create($selector, $scope, $separator, $suffix, $pseudo-class, $pseudo-element)` | Sets new CSS selector with class scope and pseudo options. |
139
+ ```css
140
+ .md\:foo .bar {
141
+ color: darkcyan;
142
+ }
143
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsass/selector",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Sass functions and mixins to manage CSS selectors.",
5
5
  "scripts": {
6
6
  "lint:css": "stylelint --fix \"**/*.scss\"",
@@ -15,9 +15,9 @@
15
15
  },
16
16
  "sass": "index.scss",
17
17
  "devDependencies": {
18
- "@commitlint/cli": "^17.4.4",
19
- "@commitlint/config-conventional": "^17.4.4",
20
- "@semantic-release/changelog": "^6.0.2",
18
+ "@commitlint/cli": "^17.7.1",
19
+ "@commitlint/config-conventional": "^17.7.0",
20
+ "@semantic-release/changelog": "^6.0.3",
21
21
  "@semantic-release/git": "^10.0.1",
22
22
  "glob": "^7.2.0",
23
23
  "husky": "^8.0.3",
@@ -26,14 +26,14 @@
26
26
  "jest-junit": "^15.0.0",
27
27
  "npm-run-all": "^4.1.5",
28
28
  "sass-true": "^7.0.0",
29
- "semantic-release": "^20.1.3",
29
+ "semantic-release": "^21.1.1",
30
30
  "stylelint": "^15.3.0",
31
31
  "stylelint-config-unsass": "^1.0.1"
32
32
  },
33
33
  "dependencies": {
34
34
  "@unsass/string": "^1.4.2",
35
35
  "@unsass/types": "^1.0.2",
36
- "sass": "^1.53.0"
36
+ "sass": "^1.66.1"
37
37
  },
38
38
  "keywords": [
39
39
  "sass",
package/src/_mixins.scss CHANGED
@@ -2,7 +2,7 @@
2
2
  // MIXINS //
3
3
  // ============================================================================================= //
4
4
 
5
- @use "sass:meta";
5
+ @use "sass:list";
6
6
  @use "sass:selector";
7
7
  @use "@unsass/string";
8
8
  @use "@unsass/types" as type;
@@ -50,7 +50,7 @@
50
50
  /// }
51
51
  ///
52
52
  /// @param {string} $selector - Selector name.
53
- /// @param {string} $scope - Selector affix value.
53
+ /// @param {string, list} $scope - Selector affix value.
54
54
  /// @param {string} $separator - Selector affix separator.
55
55
  /// @param {string} $pseudo-class - Selector pseudo-class.
56
56
  /// @param {string} $pseudo-element - Selector pseudo-element.
@@ -61,11 +61,14 @@
61
61
  ///
62
62
  /// @access public
63
63
  ///
64
- @mixin create($selector, $scope: null, $separator: ":", $suffix: false, $pseudo-class: null, $pseudo-element: null) {
65
- @if ($pseudo-class and $suffix) or ($pseudo-element and $suffix) {
66
- @error "You cannot add a suffix with a selector that already has a pseudo-class or a pseudo-element."
64
+ @mixin create($selector, $scope: null, $separator: ":", $suffix: false, $pseudo-class: null, $pseudo-element: null, $root: false) {
65
+ @if $pseudo-class and $suffix {
66
+ @error "You cannot add a suffix with a selector that already has a pseudo-class."
67
+ } @else if $pseudo-element and $suffix {
68
+ @error "You cannot add a suffix with a selector that already has a pseudo-element."
67
69
  }
68
70
 
71
+ $selector: if(type.is-list($selector), "#{list.nth($selector, 1)}", $selector);
69
72
  $class-selector: string.slice($selector, 1, 1) == ".";
70
73
 
71
74
  @if $class-selector {
@@ -78,9 +81,7 @@
78
81
 
79
82
  @if $pseudo-class {
80
83
  $selector: functions.pseudo-class($selector, $pseudo-class);
81
- }
82
-
83
- @if $pseudo-element {
84
+ } @else if $pseudo-element {
84
85
  $selector: functions.pseudo-element($selector, $pseudo-element);
85
86
  }
86
87
 
@@ -89,23 +90,55 @@
89
90
  ///
90
91
 
91
92
  @if $scope and not $suffix {
92
- @if type.is-number(string.to-number(string.slice($scope, 1, $end-at: 1))) {
93
- $scope: string.replace(\3 #{string.unquote($scope)}, " ");
93
+ $class: "";
94
+
95
+ @if type.is-list($scope) {
96
+ @each $key in $scope {
97
+ @if type.is-number(string.to-number(string.slice($key, 1, $end-at: 1))) {
98
+ $key: string.replace(\3 #{string.unquote($key)}, " ");
99
+ }
100
+
101
+ $class: $class + "#{$key}\\#{$separator}";
102
+ }
103
+ } @else {
104
+ @if type.is-number(string.to-number(string.slice($scope, 1, $end-at: 1))) {
105
+ $scope: string.replace(\3 #{string.unquote($scope)}, " ");
106
+ }
107
+
108
+ $class: "#{$scope}\\#{$separator}";
94
109
  }
95
110
 
96
- $selector: selector.append("#{$scope}\\#{$separator}", $selector);
111
+ $selector: selector.append($class, $selector);
97
112
  }
98
113
 
99
114
  @if $scope and $suffix {
100
- $selector: selector.append($selector, "\\#{$separator}#{$scope}");
115
+ $class: "";
116
+
117
+ @if type.is-list($scope) {
118
+ @each $key in $scope {
119
+ $class: $class + "\\#{$separator}#{$key}";
120
+ }
121
+ } @else {
122
+ $class: "\\#{$separator}#{$scope}";
123
+ }
124
+
125
+ $selector: selector.append($selector, $class);
101
126
  }
102
127
 
103
128
  ///
104
129
  /// Set selector.
105
130
  ///
106
131
 
107
- #{functions.to-class($selector)} {
108
- @content;
132
+ $selector: functions.to-class($selector);
133
+
134
+ @if $root {
135
+ @at-root #{$selector} {
136
+ @content;
137
+ }
138
+ } @else {
139
+ #{$selector} {
140
+ @content;
141
+ }
109
142
  }
110
143
  }
111
144