@unsass/selector 1.0.0-beta.1

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 ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
+
5
+ ## 1.0.0-beta.1 (2022-08-26)
6
+
7
+
8
+ ### Features
9
+
10
+ * add mixins and functions ([729e708](https://github.com/unsass/selector/commit/729e70868e8688656b89ec2ff9bf3b5fe598510b))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 unsass
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Selector
2
+
3
+ [![Version](https://flat.badgen.net/npm/v/@unsass/selector)](https://www.npmjs.com/package/@unsass/selector)
4
+ [![Downloads](https://flat.badgen.net/npm/dt/@unsass/selector)](https://www.npmjs.com/package/@unsass/selector)
5
+ [![License](https://flat.badgen.net/npm/license/@unsass/selector)](https://www.npmjs.com/package/@unsass/selector)
6
+
7
+ ## Introduction
8
+
9
+ Sass functions and mixins to manage CSS selectors.
10
+
11
+ ## Installing
12
+
13
+ ```shell
14
+ npm install @unsass/selector
15
+ ```
package/index.scss ADDED
@@ -0,0 +1,6 @@
1
+ // ============================================================================================= //
2
+ // SELECTOR //
3
+ // ============================================================================================= //
4
+
5
+ @forward "./src/mixins";
6
+ @forward "./src/functions";
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@unsass/selector",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Sass functions and mixins to manage CSS selectors.",
5
+ "scripts": {
6
+ "lint:css": "stylelint --fix \"**/*.scss\"",
7
+ "lint": "npm-run-all --parallel lint:*",
8
+ "test": "jest",
9
+ "prepare": "husky install",
10
+ "release": "semantic-release"
11
+ },
12
+ "engines": {
13
+ "node": ">=14.0.0",
14
+ "npm": ">=8.0.0"
15
+ },
16
+ "sass": "index.scss",
17
+ "devDependencies": {
18
+ "@commitlint/cli": "^17.0.3",
19
+ "@commitlint/config-conventional": "^17.0.3",
20
+ "@semantic-release/changelog": "^6.0.1",
21
+ "@semantic-release/git": "^10.0.1",
22
+ "glob": "^7.2.0",
23
+ "husky": "^8.0.1",
24
+ "jest": "^28.1.3",
25
+ "npm-run-all": "^4.1.5",
26
+ "sass-true": "^6.1.0",
27
+ "semantic-release": "^19.0.3",
28
+ "stylelint": "^14.10.0",
29
+ "stylelint-config-unsass": "^1.0.0"
30
+ },
31
+ "dependencies": {
32
+ "@unsass/utilities": "^1.3.1",
33
+ "sass": "^1.53.0"
34
+ },
35
+ "keywords": [
36
+ "sass",
37
+ "selector",
38
+ "class",
39
+ "unsass",
40
+ "front-end"
41
+ ],
42
+ "license": "MIT",
43
+ "homepage": "https://github.com/unsass/selector#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/unsass/selector/issues"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/unsass/selector.git"
50
+ },
51
+ "files": [
52
+ "src/**/*",
53
+ "*.scss",
54
+ "CHANGELOG.md"
55
+ ],
56
+ "publishConfig": {
57
+ "access": "public"
58
+ }
59
+ }
@@ -0,0 +1,59 @@
1
+ // ============================================================================================= //
2
+ // MIXINS //
3
+ // ============================================================================================= //
4
+
5
+ @use "sass:map";
6
+ @use "sass:meta";
7
+ @use "sass:selector";
8
+
9
+ // ------------------------------------------------------------------------- //
10
+ // Privates functions
11
+ // ------------------------------------------------------------------------- //
12
+
13
+ // ...
14
+
15
+ // ------------------------------------------------------------------------- //
16
+ // Public functions
17
+ // ------------------------------------------------------------------------- //
18
+
19
+ @function pseudo-class($selector, $pseudo-class) {
20
+ @return selector.append($selector, ":#{$pseudo-class}");
21
+ }
22
+
23
+ @function pseudo-element($selector, $pseudo-element) {
24
+ @return selector.append($selector, "::#{$pseudo-element}");
25
+ }
26
+
27
+ @function to-id($selector) {
28
+ @return "##{$selector}";
29
+ }
30
+
31
+ @function to-class($selector) {
32
+ @return ".#{$selector}";
33
+ }
34
+
35
+ ///
36
+ /// Number.
37
+ ///
38
+ @function number($value) {
39
+ @if meta.type-of($value) == "number" {
40
+ @return $value;
41
+ } @else if meta.type-of($value) != "string" {
42
+ @error "Invalid string type for `#{$value}` value. Use string type instead.";
43
+ }
44
+
45
+ $numbers: (
46
+ "0": 0,
47
+ "1": 1,
48
+ "2": 2,
49
+ "3": 3,
50
+ "4": 4,
51
+ "5": 5,
52
+ "6": 6,
53
+ "7": 7,
54
+ "8": 8,
55
+ "9": 9
56
+ );
57
+
58
+ @return map.get($numbers, $value);
59
+ }
@@ -0,0 +1,113 @@
1
+ // ============================================================================================= //
2
+ // MIXINS //
3
+ // ============================================================================================= //
4
+
5
+ @use "sass:meta";
6
+ @use "sass:selector";
7
+ @use "sass:string";
8
+ @use "@unsass/utilities";
9
+ @use "./functions";
10
+
11
+ ///
12
+ /// @example - scss
13
+ /// @include create("foo") {
14
+ /// color: darkcyan;
15
+ /// }
16
+ ///
17
+ /// @example - css
18
+ /// .foo {
19
+ /// color: darkcyan;
20
+ /// }
21
+ ///
22
+ /// @example - scss
23
+ /// @include create("foo", "md") {
24
+ /// color: darkcyan;
25
+ /// }
26
+ ///
27
+ /// @example - css
28
+ /// .md:foo {
29
+ /// color: darkcyan;
30
+ /// }
31
+ ///
32
+ /// @example - scss
33
+ /// @include create("foo", $pseudo-class: "hover") {
34
+ /// color: darkcyan;
35
+ /// }
36
+ ///
37
+ /// @example - css
38
+ /// .foo:hover {
39
+ /// color: darkcyan;
40
+ /// }
41
+ ///
42
+ /// @example - scss
43
+ /// @include create("foo", $pseudo-element: "before") {
44
+ /// color: darkcyan;
45
+ /// }
46
+ ///
47
+ /// @example - css
48
+ /// .foo::before {
49
+ /// color: darkcyan;
50
+ /// }
51
+ ///
52
+ /// @param {string} $selector - Selector name.
53
+ /// @param {string} $scope - Selector affix value.
54
+ /// @param {string} $separator - Selector affix separator.
55
+ /// @param {string} $pseudo-class - Selector pseudo-class.
56
+ /// @param {string} $pseudo-element - Selector pseudo-element.
57
+ /// @param {boolean} $suffix - Use suffix instead of prefix.
58
+ ///
59
+ /// @see {function} functions.pseudo-class
60
+ /// @see {function} functions.pseudo-element
61
+ /// @see {function} functions.number
62
+ /// @see {function} utilities.string-replace
63
+ ///
64
+ /// @access public
65
+ ///
66
+ @mixin create($selector, $scope: null, $separator: ":", $suffix: false, $pseudo-class: null, $pseudo-element: null) {
67
+ @if ($pseudo-class and $suffix) or ($pseudo-element and $suffix) {
68
+ @error "You cannot add a suffix with a selector that already has a pseudo-class or a pseudo-element."
69
+ }
70
+
71
+ $class-selector: string.slice($selector, 1, 1) == ".";
72
+
73
+ @if $class-selector {
74
+ $selector: string.slice($selector, 2);
75
+ }
76
+
77
+ ///
78
+ /// Set pseudo-{classes, elements}.
79
+ ///
80
+
81
+ @if $pseudo-class {
82
+ $selector: functions.pseudo-class($selector, $pseudo-class);
83
+ }
84
+
85
+ @if $pseudo-element {
86
+ $selector: functions.pseudo-element($selector, $pseudo-element);
87
+ }
88
+
89
+ ///
90
+ /// Set scope.
91
+ ///
92
+
93
+ @if $scope and not $suffix {
94
+ @if meta.type-of(functions.number(string.slice($scope, 1, $end-at: 1))) == "number" {
95
+ $scope: utilities.string-replace(\3 #{string.unquote($scope)}, " ");
96
+ }
97
+
98
+ $selector: selector.append("#{$scope}\\#{$separator}", $selector);
99
+ }
100
+
101
+ @if $scope and $suffix {
102
+ $selector: selector.append($selector, "\\#{$separator}#{$scope}");
103
+ }
104
+
105
+ ///
106
+ /// Set selector.
107
+ ///
108
+
109
+ #{functions.to-class($selector)} {
110
+ @content;
111
+ }
112
+ }
113
+