Compare commits

...

29 Commits

Author SHA1 Message Date
Anton Smirnov a4165465ae Kinda fix highlighting (scss highlighting crashes) 2022-12-19 18:58:36 +02:00
Anton Smirnov fea1f58102 Ignore build dir 2022-12-19 18:57:57 +02:00
Anton Smirnov e584d9c2b6 Useless param 2022-06-23 06:52:17 +03:00
Anton Smirnov c59eca22d7 Importer needs some adaptation 2022-06-23 06:45:34 +03:00
Anton Smirnov 8d7dc75796 Upgrade mocha 2022-06-23 06:12:47 +03:00
Anton Smirnov 7374479bfd RGB definition 2022-06-23 06:07:59 +03:00
Anton Smirnov a22810fbc8 loadPaths is required 2022-06-23 06:05:31 +03:00
Anton Smirnov beea262e6f Convert tests to TypeScript 2022-06-23 06:02:02 +03:00
Anton Smirnov 2d92d1ec16 Rename to ts 2022-06-23 06:00:05 +03:00
Anton Smirnov 3991142c0d Fix project name 2022-06-02 01:56:30 +03:00
Anton Smirnov 8bc1b2c1d4 Use furo for docs 2022-06-02 01:55:14 +03:00
Anton Smirnov 09e16c7d1d Use scss fields in package.json 2021-08-30 09:13:07 +03:00
Anton Smirnov 35f3120776 formatting 2021-08-29 18:36:04 +03:00
Anton Smirnov 7832f53709 typo 2021-08-29 18:31:20 +03:00
Anton Smirnov 4cb177683d Release as 1.0.2 2021-08-29 18:23:15 +03:00
Anton Smirnov fecbb2bc6c Do not include ci in build 2021-08-29 18:22:40 +03:00
Anton Smirnov f8e4c69d7b Build status 2021-08-29 18:20:57 +03:00
Anton Smirnov cfb52712c3 Run tests in CI 2021-08-29 18:17:40 +03:00
Anton Smirnov fa0a8988e8 Check all hue branches 2021-08-29 18:07:29 +03:00
Anton Smirnov d3587aa2e4 Test fraction units 2021-08-29 17:51:52 +03:00
Anton Smirnov d170efaa38 Test angle units 2021-08-29 17:44:58 +03:00
Anton Smirnov ac6b0bdb42 Test aliases 2021-08-29 17:25:54 +03:00
Anton Smirnov a6abccc1eb libsass support 2021-08-29 17:02:37 +03:00
Anton Smirnov 55529768fd Install mocha 2021-08-29 16:17:20 +03:00
Anton Smirnov 5321839814 Installation test launcher 2021-08-29 16:16:30 +03:00
Anton Smirnov 4b42392eeb Test installation with node-sass-package-importer 2021-08-29 15:38:24 +03:00
Anton Smirnov dd4ccb3ad2 Add description and keywords 2021-08-28 04:00:26 +03:00
Anton Smirnov a6c1451258 Fix issues path 2021-08-28 03:52:03 +03:00
Anton Smirnov 75ed6c810b Changelog 2021-08-28 03:34:38 +03:00
49 changed files with 702 additions and 7 deletions

10
.gitignore vendored
View File

@ -1,5 +1,11 @@
# idea
/.idea
/node_modules
/package-lock.json
# npm. ignore names everywhere
node_modules
package-lock.json
# project specific
/demo.*
/docs/index.html
/docs/build

7
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,7 @@
test:
image: node:current
before_script:
- npm install
script:
- npm test
- tests/installation/installation.sh

8
.mocharc.js Normal file
View File

@ -0,0 +1,8 @@
'use strict';
module.exports = {
spec: [
"tests/spec/**/*.spec.ts"
],
"require": "ts-node/register",
}

12
.npmignore Normal file
View File

@ -0,0 +1,12 @@
# gitignore
/.idea
/node_modules
/package-lock.json
/demo.*
# no needed in node package
/docs
/tests
/.mocharc.js
/.gitlab-ci.yml
/tsconfig.json

20
CHANGELOG.md Normal file
View File

@ -0,0 +1,20 @@
# Changelog
## 1.0.2
*Aug 29, 2021*
* Added a way to bypass libsass incompatibility
* Added tests
## 1.0.1
*Aug 28, 2021*
First published version (1.0.0 was published by mistake and was yanked)
## 1.0.0
*Aug 28, 2021*
First public release

View File

@ -2,6 +2,7 @@
[![npm](https://img.shields.io/npm/v/sass-hsv?style=flat-square)](https://www.npmjs.com/package/sass-hsv)
[![NPM](https://img.shields.io/npm/l/sass-hsv?style=flat-square)](https://www.npmjs.com/package/sass-hsv)
[![Gitlab pipeline status](https://img.shields.io/gitlab/pipeline/sandfox/sass-hsv/master.svg?style=flat-square)](https://gitlab.com/sandfox/sass-hsv/-/pipelines)
A simple helper to introduce [HSV/HSB] model support to SASS.
@ -38,7 +39,7 @@ Also on Read the Docs: <https://sass-hsv.readthedocs.io/>
## Support
Please file issues on our main repo at GitLab: <https://gitlab.com/sandfox/bencode/-/issues>
Please file issues on our main repo at GitLab: <https://gitlab.com/sandfox/sass-hsv/-/issues>
## License

56
_legacy.scss Normal file
View File

@ -0,0 +1,56 @@
@function hsv($h, $s, $v, $a: 1) {
// normalize h to degrees
$h: (0deg + $h) / 1deg;
$h: $h % 360;
// normalize s to fractions
@if (not unitless($s)) {
$s: $s / 100%;
}
// normalize v to fractions
@if (not unitless($v)) {
$v: $v / 100%;
}
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
$c: $s * $v;
$h1: $h / 60;
$x: $c * (1 - abs($h1 % 2 - 1));
$r1: none; $g1: none; $b1: none;
@if ($h1 < 1) {
$r1: $c; $g1: $x; $b1: 0;
} @else if($h1 < 2) {
$r1: $x; $g1: $c; $b1: 0;
} @else if($h1 < 3) {
$r1: 0; $g1: $c; $b1: $x;
} @else if($h1 < 4) {
$r1: 0; $g1: $x; $b1: $c;
} @else if($h1 < 5) {
$r1: $x; $g1: 0; $b1: $c;
} @else {
$r1: $c; $g1: 0; $b1: $x;
}
$m: $v - $c;
$r: floor(($r1 + $m) * 255);
$g: floor(($g1 + $m) * 255);
$b: floor(($b1 + $m) * 255);
@return rgba($r, $g, $b, $a);
}
// some aliases
@function hsva($h, $s, $v, $a) {
@return hsv($h, $s, $v, $a);
}
@function hsb($h, $s, $b, $a: 1) {
@return hsv($h, $s, $b, $a);
}
@function hsba($h, $s, $b, $a) {
@return hsv($h, $s, $b, $a);
}

22
docs/_templates/sidebar/brand.html vendored Normal file
View File

@ -0,0 +1,22 @@
<a class="sidebar-brand{% if logo %} centered{% endif %}" href="{{ pathto(master_doc) }}">
{% block brand_content %}
{%- if logo_url %}
<div class="sidebar-logo-container">
<img class="sidebar-logo" src="{{ logo_url }}" alt="Logo"/>
</div>
{%- endif %}
{%- if theme_light_logo and theme_dark_logo %}
<div class="sidebar-logo-container">
<img class="sidebar-logo only-light" src="{{ pathto('_static/' + theme_light_logo, 1) }}" alt="Light Logo"/>
<img class="sidebar-logo only-dark" src="{{ pathto('_static/' + theme_dark_logo, 1) }}" alt="Dark Logo"/>
</div>
{%- endif %}
{% if not theme_sidebar_hide_name %}
<span class="sidebar-brand-text">{{ docstitle if docstitle else project }}</span>
{%- endif %}
{% endblock brand_content %}
</a>
{%- if current_version -%}
<div class="sidebar-brand">{{ current_version }}</div>
{%- endif -%}

10
docs/conf.py Normal file
View File

@ -0,0 +1,10 @@
from datetime import datetime
project = 'sass-hsv'
author = 'Anton Smirnov'
copyright = '{} {}'.format(datetime.now().year, author)
language = 'en'
html_title = project
html_theme = 'furo'
templates_path = ["_templates"]

View File

@ -12,7 +12,14 @@ The helper tries to mimic ``hsl()`` syntax from css.
The easiest way to import the helper is to use node-sass-package-importer_.
.. code-block:: scss
Dart Sass
---------
Just import the module:
.. don't ask why scilab, it just works
.. code-block:: scilab
// node-sass-package-importer path syntax, adjust for your favorite importer
@use "~sass-hsv" as *;
@ -31,6 +38,21 @@ The easiest way to import the helper is to use node-sass-package-importer_.
color: hsba(270, 50%, 100%, 1); // same as hsva()
}
libsass
-------
The package is designed for ``sass`` / Dart Sass with modules but it has support of ``node-sass`` / ``libsass``.
You need to import the legacy module explicitly:
.. code-block:: scilab
// node-sass-package-importer path syntax, adjust for your favorite importer
@import "~sass-hsv/legacy"
a {
color: hsv(270, 50%, 100%); // #bf7fff
}
License
=======

1
docs/requirements.txt Normal file
View File

@ -0,0 +1 @@
furo

View File

@ -1,7 +1,13 @@
{
"name": "sass-hsv",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"description": "A simple helper to introduce HSV/HSB model support to SASS",
"keywords": [
"sass",
"hsv",
"hsl"
],
"repository": {
"type": "git",
"url": "https://gitlab.com/sandfox/sass-hsv"
@ -12,8 +18,19 @@
"email": "sandfox@sandfox.me",
"url": "https://sandfox.me/"
},
"sass": "_hsv.scss",
"scss": "_hsv.scss",
"main.scss": "_hsv.scss",
"scripts": {
"test": "mocha"
},
"devDependencies": {
"sass": "^1.38.1"
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node-sass": "^4.11.2",
"chai": "^4.3.4",
"mocha": "^10.0.0",
"node-sass": "*",
"sass": "*",
"ts-node": "^10.8.1"
}
}

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
cd `dirname $0`
# do clean installations
find . -type d -name node_modules -exec rm -rf {} \;
find . -type f -name package-lock.json -exec rm -f {} \;
cd node-sass-package-importer && \
npm install && node index.js && \
echo "All installation scripts successful"
exit $?

View File

@ -0,0 +1,26 @@
'use strict';
const sass = require('sass');
const packageImporter = require('node-sass-package-importer')();
const fs = require('fs');
const process = require('process');
const css = sass.compile('test.scss', {
style: 'compressed',
importers: [{
findFileUrl(url) {
return new URL('file://' + packageImporter(url).file)
}
}],
})
const data = fs.readFileSync('../test_result.css').toString();
if (css.css !== data) {
console.log('css content is different');
console.log(`expected: "${data}"`);
console.log(`actual: "${css.css}"`);
process.exit(1);
}
console.log('import is successful');

View File

@ -0,0 +1,7 @@
{
"dependencies": {
"node-sass-package-importer": "^5.3.2",
"sass": "^1.45.0",
"sass-hsv": "file:../../.."
}
}

View File

@ -0,0 +1,2 @@
@use "~sass-hsv" as *;
@import "../test";

View File

@ -0,0 +1,3 @@
a {
color: hsv(270, 50%, 100%);
}

View File

@ -0,0 +1 @@
a{color:#bf7fff}

View File

@ -0,0 +1,52 @@
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
import { Options } from 'sass/types/options';
const expected = readFileSync(__dirname + '/sass/aliases/expected.css').toString().trim();
const expectedAlpha = readFileSync(__dirname + '/sass/aliases/expected-alpha.css').toString().trim();
const options: Options<'sync'> = {
style: 'compressed',
loadPaths: [__dirname + '/../..']
}
describe('hsv()', function () {
it('works', function () {
const actual = compile(__dirname + '/sass/aliases/hsv-test.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
});
describe('hsb()', function () {
it('works', function () {
const actual = compile(__dirname + '/sass/aliases/hsb.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
});
describe('hsva()', function () {
it('works', function () {
const actual = compile(__dirname + '/sass/aliases/hsva.scss', options).css.toString().trim();
assert.equal(actual, expectedAlpha);
});
it('requires alpha param', function () {
assert.throws(function () {
compile(__dirname + '/sass/aliases/hsva-error.scss', options);
});
});
});
describe('hsba()', function () {
it('works', function () {
const actual = compile(__dirname + '/sass/aliases/hsba.scss', options).css.toString().trim();
assert.equal(actual, expectedAlpha);
});
it('requires alpha param', function () {
assert.throws(function () {
compile(__dirname + '/sass/aliases/hsba-error.scss', options);
});
});
});

50
tests/spec/angles.spec.ts Normal file
View File

@ -0,0 +1,50 @@
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
import { Options } from 'sass/types/options';
const expected = readFileSync(__dirname + '/sass/angles/expected.css').toString().trim();
const options: Options<'sync'> = {
style: 'compressed',
loadPaths: [__dirname + '/../..']
}
describe('angle units', function () {
it('accepts unitless as degrees', function () {
const actual = compile(__dirname + '/sass/angles/unitless.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts degrees', function () {
const actual = compile(__dirname + '/sass/angles/deg.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts radians', function () {
const actual = compile(__dirname + '/sass/angles/rad.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts turns', function () {
const actual = compile(__dirname + '/sass/angles/turn.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts grads', function () {
const actual = compile(__dirname + '/sass/angles/grad.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('does not allow incompatible units: %', function () {
assert.throws(function () {
compile(__dirname + '/sass/angles/percent.scss', options);
});
});
it('does not allow incompatible units: pt', function () {
assert.throws(function () {
compile(__dirname + '/sass/angles/pt.scss', options);
});
});
});

35
tests/spec/frac.spec.ts Normal file
View File

@ -0,0 +1,35 @@
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
import { Options } from 'sass/types/options';
const expected = readFileSync(__dirname + '/sass/frac/expected.css').toString().trim();
const options: Options<'sync'> = {
style: 'compressed',
loadPaths: [__dirname + '/../..']
}
describe('fraction units', function () {
it('accepts unitless as fractions', function () {
const actual = compile(__dirname + '/sass/frac/fraction.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts percent', function () {
const actual = compile(__dirname + '/sass/frac/percent.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('does not allow incompatible units: deg', function () {
assert.throws(function () {
compile(__dirname + '/sass/frac/deg.scss', options);
});
});
it('does not allow incompatible units: pt', function () {
assert.throws(function () {
compile(__dirname + '/sass/frac/pt.scss', options);
});
});
});

15
tests/spec/hue.spec.ts Normal file
View File

@ -0,0 +1,15 @@
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
describe('check all hue values with 10 degree step to verify all h1 branches', function () {
it('is valid', function () {
const actual = compile(__dirname + '/sass/hue/all-degrees.scss', {
style: 'expanded',
loadPaths: [__dirname + '/../..']
}).css.toString().trim();
const expected = readFileSync(__dirname + '/sass/hue/expected.css').toString().trim();
assert.equal(actual, expected);
});
});

View File

@ -0,0 +1,15 @@
import { assert } from 'chai';
import { renderSync } from 'node-sass';
import { readFileSync } from 'fs';
describe('legacy libsass support' , function () {
it('works with node-sass', function () {
const actual = renderSync({
file: __dirname + '/sass/node-sass/node-sass.scss',
outputStyle: 'compressed',
}).css;
const expected = readFileSync(__dirname + '/sass/node-sass/expected.css');
assert.equal(actual.toString(), expected.toString());
});
});

View File

@ -0,0 +1 @@
b{color:rgba(191,127,255,.5)}

View File

@ -0,0 +1 @@
a{color:#bf7fff}b{color:rgba(191,127,255,.5)}

View File

@ -0,0 +1,9 @@
@use "hsv" as *;
a {
color: hsb(270, 50%, 100%);
}
b {
color: hsb(270, 50%, 100%, 0.5);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsba(270, 50%, 100%);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
b {
color: hsba(270, 50%, 100%, 0.5);
}

View File

@ -0,0 +1,9 @@
@use "hsv" as *;
a {
color: hsv(270, 50%, 100%);
}
b {
color: hsv(270, 50%, 100%, 0.5);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsva(270, 50%, 100%);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
b {
color: hsva(270, 50%, 100%, 0.5);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(45deg, 75%, 75%);
}

View File

@ -0,0 +1 @@
a{color:#bf9b2f}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(50grad, 75%, 75%);
}

View File

@ -0,0 +1,6 @@
@use "hsv" as *;
@use "sass:math";
a {
color: hsv(50%, 75%, 75%);
}

View File

@ -0,0 +1,6 @@
@use "hsv" as *;
@use "sass:math";
a {
color: hsv(15pt, 75%, 75%);
}

View File

@ -0,0 +1,6 @@
@use "hsv" as *;
@use "sass:math";
a {
color: hsv(math.$pi * 0.25rad, 75%, 75%);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(0.125turn, 75%, 75%);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(45, 75%, 75%);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(135, 0.33deg, 0.66deg);
}

View File

@ -0,0 +1 @@
a{color:#70a87e}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(135, 0.33, 0.66);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(135, 33%, 66%);
}

View File

@ -0,0 +1,5 @@
@use "hsv" as *;
a {
color: hsv(135, 33pt, 66pt);
}

View File

@ -0,0 +1,39 @@
@use "hsv" as *;
.h0 { color: hsv(00, 100%, 100%) }
.h1 { color: hsv(10, 100%, 100%) }
.h2 { color: hsv(20, 100%, 100%) }
.h3 { color: hsv(30, 100%, 100%) }
.h4 { color: hsv(40, 100%, 100%) }
.h5 { color: hsv(50, 100%, 100%) }
.h6 { color: hsv(60, 100%, 100%) }
.h7 { color: hsv(70, 100%, 100%) }
.h8 { color: hsv(80, 100%, 100%) }
.h9 { color: hsv(90, 100%, 100%) }
.h10 { color: hsv(100, 100%, 100%) }
.h11 { color: hsv(110, 100%, 100%) }
.h12 { color: hsv(120, 100%, 100%) }
.h13 { color: hsv(130, 100%, 100%) }
.h14 { color: hsv(140, 100%, 100%) }
.h15 { color: hsv(150, 100%, 100%) }
.h16 { color: hsv(160, 100%, 100%) }
.h17 { color: hsv(170, 100%, 100%) }
.h18 { color: hsv(180, 100%, 100%) }
.h19 { color: hsv(190, 100%, 100%) }
.h20 { color: hsv(200, 100%, 100%) }
.h21 { color: hsv(210, 100%, 100%) }
.h22 { color: hsv(220, 100%, 100%) }
.h23 { color: hsv(230, 100%, 100%) }
.h24 { color: hsv(240, 100%, 100%) }
.h25 { color: hsv(250, 100%, 100%) }
.h26 { color: hsv(260, 100%, 100%) }
.h27 { color: hsv(270, 100%, 100%) }
.h28 { color: hsv(280, 100%, 100%) }
.h29 { color: hsv(290, 100%, 100%) }
.h30 { color: hsv(300, 100%, 100%) }
.h31 { color: hsv(310, 100%, 100%) }
.h32 { color: hsv(320, 100%, 100%) }
.h33 { color: hsv(330, 100%, 100%) }
.h34 { color: hsv(340, 100%, 100%) }
.h35 { color: hsv(350, 100%, 100%) }
.h36 { color: hsv(360, 100%, 100%) }

View File

@ -0,0 +1,147 @@
.h0 {
color: rgb(255, 0, 0);
}
.h1 {
color: rgb(255, 42, 0);
}
.h2 {
color: rgb(255, 84, 0);
}
.h3 {
color: rgb(255, 127, 0);
}
.h4 {
color: rgb(255, 170, 0);
}
.h5 {
color: rgb(255, 212, 0);
}
.h6 {
color: rgb(255, 255, 0);
}
.h7 {
color: rgb(212, 255, 0);
}
.h8 {
color: rgb(170, 255, 0);
}
.h9 {
color: rgb(127, 255, 0);
}
.h10 {
color: rgb(84, 255, 0);
}
.h11 {
color: rgb(42, 255, 0);
}
.h12 {
color: rgb(0, 255, 0);
}
.h13 {
color: rgb(0, 255, 42);
}
.h14 {
color: rgb(0, 255, 85);
}
.h15 {
color: rgb(0, 255, 127);
}
.h16 {
color: rgb(0, 255, 169);
}
.h17 {
color: rgb(0, 255, 212);
}
.h18 {
color: rgb(0, 255, 255);
}
.h19 {
color: rgb(0, 212, 255);
}
.h20 {
color: rgb(0, 169, 255);
}
.h21 {
color: rgb(0, 127, 255);
}
.h22 {
color: rgb(0, 85, 255);
}
.h23 {
color: rgb(0, 42, 255);
}
.h24 {
color: rgb(0, 0, 255);
}
.h25 {
color: rgb(42, 0, 255);
}
.h26 {
color: rgb(84, 0, 255);
}
.h27 {
color: rgb(127, 0, 255);
}
.h28 {
color: rgb(170, 0, 255);
}
.h29 {
color: rgb(212, 0, 255);
}
.h30 {
color: rgb(255, 0, 255);
}
.h31 {
color: rgb(255, 0, 212);
}
.h32 {
color: rgb(255, 0, 170);
}
.h33 {
color: rgb(255, 0, 127);
}
.h34 {
color: rgb(255, 0, 84);
}
.h35 {
color: rgb(255, 0, 42);
}
.h36 {
color: rgb(255, 0, 0);
}

View File

@ -0,0 +1 @@
a{color:#bf7fff}

View File

@ -0,0 +1,5 @@
@import "legacy";
a {
color: hsv(270, 50%, 100%);
}

2
tsconfig.json Normal file
View File

@ -0,0 +1,2 @@
{
}