@pixel-forge/sass-utils 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Itay "Cipher" Leybovich
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
13
+ all 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
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @pixel-forge/sass-utils
2
+
3
+ Sass shorthands, mixins, and functions. No runtime JavaScript — this package
4
+ ships source partials that you `@use` from your own stylesheets.
5
+
6
+ Function docs live on the SCSS as SassDoc (`///` comments), the Sass equivalent
7
+ of JSDoc. A later docs site can generate pages from those comments. `/* */` is
8
+ not used — Sass would copy those into the consumer's CSS.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm i @pixel-forge/sass-utils
14
+ ```
15
+
16
+ Requires a Dart Sass compiler (`sass` or `sass-embedded`, 1.71+ for the `pkg:`
17
+ importer).
18
+
19
+ ## Import surface
20
+
21
+ There is no compiled CSS and no `dist/`. npm publishes `src/`. The public
22
+ surface is the `exports` map in `package.json` — one subpath per domain, each
23
+ pointing at that domain's `_index.scss`. Extra files in the folder (for example
24
+ `_number.scss`) are for `@forward` from `_index.scss`; they are not importable as
25
+ their own subpaths.
26
+
27
+ ```scss
28
+ @use 'pkg:@pixel-forge/sass-utils/assertion' as Assert;
29
+ @use 'pkg:@pixel-forge/sass-utils/color' as Color;
30
+ @use 'pkg:@pixel-forge/sass-utils/palette' as Palette;
31
+ ```
32
+
33
+ | Subpath | Exposes |
34
+ | ----------- | ---------------------------------------------- |
35
+ | `assertion` | `assertColor`, `assertNumber`, `assertInteger` |
36
+ | `color` | `colorWithAlpha` |
37
+ | `palette` | `paletteBuilder` |
38
+
39
+ ## License
40
+
41
+ MIT
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@pixel-forge/sass-utils",
3
+ "version": "0.1.0",
4
+ "description": "Sass shorthands, mixins, and functions for Pixel Forge.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/pixel-forge/Pixel-Forge.git",
11
+ "directory": "packages/sass-utils"
12
+ },
13
+ "homepage": "https://github.com/pixel-forge/Pixel-Forge/tree/main/packages/sass-utils#readme",
14
+ "bugs": "https://github.com/pixel-forge/Pixel-Forge/issues",
15
+ "keywords": [
16
+ "sass",
17
+ "scss",
18
+ "mixins",
19
+ "functions",
20
+ "shorthands"
21
+ ],
22
+ "files": [
23
+ "src"
24
+ ],
25
+ "exports": {
26
+ "./assertion": {
27
+ "sass": "./src/assertion/_index.scss",
28
+ "default": "./src/assertion/_index.scss"
29
+ },
30
+ "./color": {
31
+ "sass": "./src/color/_index.scss",
32
+ "default": "./src/color/_index.scss"
33
+ },
34
+ "./palette": {
35
+ "sass": "./src/palette/_index.scss",
36
+ "default": "./src/palette/_index.scss"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "engines": {
44
+ "node": ">=22.12.0"
45
+ },
46
+ "devDependencies": {
47
+ "sass": "^1.103.1"
48
+ },
49
+ "scripts": {
50
+ "clean": "rimraf dist",
51
+ "typecheck": "tsc -p tsconfig.json --noEmit",
52
+ "test": "vitest run",
53
+ "test:watch": "vitest"
54
+ }
55
+ }
@@ -0,0 +1,73 @@
1
+ @use 'sass:meta';
2
+ @use 'sass:math';
3
+
4
+ /// Returns `$value` if it is a color.
5
+ ///
6
+ /// CSS named colors like `red` are colors. A quoted string or a number is not.
7
+ ///
8
+ /// @param {*} $value - Candidate to check
9
+ /// @return {Color} `$value` unchanged
10
+ /// @throw if `meta.type-of($value)` is not `color`
11
+ @function assertColor($value) {
12
+ @if meta.type-of($value) != 'color' {
13
+ @error 'Expected a color, got #{meta.type-of($value)}: #{$value}';
14
+ }
15
+ @return $value;
16
+ }
17
+
18
+ /// Returns `$value` if it is a number. `$min` and `$max` are inclusive bounds;
19
+ /// omit a bound (or pass `null`) to leave that side open.
20
+ ///
21
+ /// @param {*} $value - Candidate to check
22
+ /// @param {Number | null} $min [null] - Inclusive lower bound
23
+ /// @param {Number | null} $max [null] - Inclusive upper bound
24
+ /// @return {Number} `$value` unchanged
25
+ /// @throw if `$value` is not a number
26
+ /// @throw if a provided bound is not a number
27
+ /// @throw if `$value < $min` or `$value > $max`
28
+ ///
29
+ /// @example scss
30
+ /// assertNumber($n, $min: 0);
31
+ /// assertNumber($n, $max: 100);
32
+ /// assertNumber($alpha, 0, 1);
33
+ @function assertNumber($value, $min: null, $max: null) {
34
+ @if meta.type-of($value) != 'number' {
35
+ @error 'Expected a number, got #{meta.type-of($value)}: #{$value}';
36
+ }
37
+
38
+ @if $min != null {
39
+ @if meta.type-of($min) != 'number' {
40
+ @error 'Expected minimum to be a number, got #{meta.type-of($min)}: #{$min}';
41
+ }
42
+
43
+ @if $value < $min {
44
+ @error 'Expected at least #{$min}, got #{$value}';
45
+ }
46
+ }
47
+
48
+ @if $max != null {
49
+ @if meta.type-of($max) != 'number' {
50
+ @error 'Expected maximum to be a number, got #{meta.type-of($max)}: #{$max}';
51
+ }
52
+
53
+ @if $value > $max {
54
+ @error 'Expected at most #{$max}, got #{$value}';
55
+ }
56
+ }
57
+
58
+ @return $value;
59
+ }
60
+
61
+ /// Returns `$value` if it is an integer. Non-numbers fail through `assertNumber`.
62
+ ///
63
+ /// @param {*} $value - Candidate to check
64
+ /// @return {Number} `$value` unchanged
65
+ /// @throw if `$value` is not a number
66
+ /// @throw if `$value` is not an integer
67
+ @function assertInteger($value) {
68
+ $value: assertNumber($value);
69
+ @if $value != math.round($value) {
70
+ @error 'Expected an integer, got #{$value}';
71
+ }
72
+ @return $value;
73
+ }
@@ -0,0 +1,22 @@
1
+ @use 'sass:color';
2
+ @use '../assertion' as Assert;
3
+
4
+ /// Returns `$color` with its alpha set to `$alpha`. Channels are read in `rgb`
5
+ /// space, so HSL (and other) inputs still produce an RGB result.
6
+ ///
7
+ /// @param {Color} $color - Any Sass color
8
+ /// @param {Number} $alpha [1] - Opacity in the inclusive `0–1` range
9
+ /// @return {Color}
10
+ /// @throw if `$color` is not a color
11
+ /// @throw if `$alpha` is not a number in `0–1`
12
+ ///
13
+ /// @example scss
14
+ /// .overlay { color: colorWithAlpha(#000, 0.5); }
15
+ @function colorWithAlpha($color, $alpha: 1) {
16
+ $color: Assert.assertColor($color);
17
+ $alpha: Assert.assertNumber($alpha, 0, 1);
18
+ $r: color.channel($color, 'red', $space: rgb);
19
+ $g: color.channel($color, 'green', $space: rgb);
20
+ $b: color.channel($color, 'blue', $space: rgb);
21
+ @return rgba($r, $g, $b, $alpha);
22
+ }
@@ -0,0 +1,32 @@
1
+ @use 'sass:math';
2
+ @use 'sass:color';
3
+ @use 'sass:list';
4
+ @use '../assertion' as Assert;
5
+
6
+ /// Builds a list of successively lighter tints of `$baseColor`.
7
+ ///
8
+ /// Index `0` is `$baseColor` unchanged. Each later index scales lightness by
9
+ /// `i / $steps` toward white. The loop is `0` to `$steps` exclusive, so the
10
+ /// list never includes a fully white step.
11
+ ///
12
+ /// @param {Color} $baseColor - Color to tint
13
+ /// @param {Number} $steps - Length of the list; integer `>= 1`
14
+ /// @return {List} `$steps` colors
15
+ /// @throw if `$baseColor` is not a color
16
+ /// @throw if `$steps` is not an integer `>= 1`
17
+ ///
18
+ /// @example scss
19
+ /// $tints: paletteBuilder(#f00, 4);
20
+ /// // red, rgb(100%, 25%, 25%), rgb(100%, 50%, 50%), rgb(100%, 75%, 75%)
21
+ @function paletteBuilder($baseColor, $steps) {
22
+ $baseColor: Assert.assertColor($baseColor);
23
+ $steps: Assert.assertInteger($steps);
24
+ $steps: Assert.assertNumber($steps, $min: 1);
25
+ $colorList: ();
26
+ @for $i from 0 to $steps {
27
+ $lightness: math.percentage(math.div($i, $steps));
28
+ $newColor: color.scale($baseColor, $lightness: $lightness);
29
+ $colorList: list.append($colorList, $newColor);
30
+ }
31
+ @return $colorList;
32
+ }