sass-embedded 1.0.0-beta.1 → 1.0.0-beta.7
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 +49 -1
- package/README.md +3 -3
- package/dist/.gitignore +2 -1
- package/dist/lib/index.js +29 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/src/{embedded/compiler.js → async-compiler.js} +13 -13
- package/dist/lib/src/async-compiler.js.map +1 -0
- package/dist/lib/src/compile.js +170 -69
- package/dist/lib/src/compile.js.map +1 -1
- package/dist/lib/src/compiler-path.js +18 -0
- package/dist/lib/src/compiler-path.js.map +1 -0
- package/dist/lib/src/deprotofy-span.js +51 -0
- package/dist/lib/src/deprotofy-span.js.map +1 -0
- package/dist/lib/src/{embedded/dispatcher.js → dispatcher.js} +63 -57
- package/dist/lib/src/dispatcher.js.map +1 -0
- package/dist/lib/src/exception.js +20 -0
- package/dist/lib/src/exception.js.map +1 -0
- package/dist/lib/src/function-registry.js +81 -0
- package/dist/lib/src/function-registry.js.map +1 -0
- package/dist/lib/src/legacy.js +133 -0
- package/dist/lib/src/legacy.js.map +1 -0
- package/dist/lib/src/{embedded/message-transformer.js → message-transformer.js} +35 -34
- package/dist/lib/src/message-transformer.js.map +1 -0
- package/dist/lib/src/{embedded/packet-transformer.js → packet-transformer.js} +2 -1
- package/dist/lib/src/packet-transformer.js.map +1 -0
- package/dist/lib/src/protofier.js +205 -0
- package/dist/lib/src/protofier.js.map +1 -0
- package/dist/lib/src/{embedded/request-tracker.js → request-tracker.js} +1 -0
- package/dist/lib/src/request-tracker.js.map +1 -0
- package/dist/lib/src/sync-compiler.js +52 -0
- package/dist/lib/src/sync-compiler.js.map +1 -0
- package/dist/lib/src/{exception/span.js → sync-process/event.js} +2 -2
- package/dist/lib/src/sync-process/event.js.map +1 -0
- package/dist/lib/src/sync-process/index.js +122 -0
- package/dist/lib/src/sync-process/index.js.map +1 -0
- package/dist/lib/src/sync-process/sync-message-port.js +128 -0
- package/dist/lib/src/sync-process/sync-message-port.js.map +1 -0
- package/dist/lib/src/sync-process/worker.js +51 -0
- package/dist/lib/src/sync-process/worker.js.map +1 -0
- package/dist/lib/src/utils.js +64 -42
- package/dist/lib/src/utils.js.map +1 -1
- package/dist/lib/src/value/boolean.js +40 -0
- package/dist/lib/src/value/boolean.js.map +1 -0
- package/dist/lib/src/value/color.js +258 -0
- package/dist/lib/src/value/color.js.map +1 -0
- package/dist/lib/src/value/index.js +147 -0
- package/dist/lib/src/value/index.js.map +1 -0
- package/dist/lib/src/value/list.js +99 -0
- package/dist/lib/src/value/list.js.map +1 -0
- package/dist/lib/src/value/map.js +91 -0
- package/dist/lib/src/value/map.js.map +1 -0
- package/dist/lib/src/value/null.js +35 -0
- package/dist/lib/src/value/null.js.map +1 -0
- package/dist/lib/src/value/number.js +579 -0
- package/dist/lib/src/value/number.js.map +1 -0
- package/dist/lib/src/value/string.js +117 -0
- package/dist/lib/src/value/string.js.map +1 -0
- package/dist/lib/src/value/utils.js +120 -0
- package/dist/lib/src/value/utils.js.map +1 -0
- package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.js +1738 -261
- package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.js.map +1 -1
- package/dist/package.json +63 -0
- package/dist/tool/utils.js +78 -90
- package/dist/tool/utils.js.map +1 -1
- package/dist/types/compile.d.ts +152 -0
- package/dist/types/exception.d.ts +41 -0
- package/dist/types/importer.d.ts +294 -0
- package/dist/types/index.d.ts +76 -0
- package/dist/types/legacy/exception.d.ts +54 -0
- package/dist/types/legacy/function.d.ts +652 -0
- package/dist/types/legacy/importer.d.ts +168 -0
- package/dist/types/legacy/options.d.ts +642 -0
- package/dist/types/legacy/plugin_this.d.ts +70 -0
- package/dist/types/legacy/render.d.ts +139 -0
- package/dist/types/logger/index.d.ts +94 -0
- package/dist/types/logger/source_location.d.ts +21 -0
- package/dist/types/logger/source_span.d.ts +34 -0
- package/dist/types/options.d.ts +408 -0
- package/dist/types/util/promise_or.d.ts +17 -0
- package/dist/types/value/argument_list.d.ts +47 -0
- package/dist/types/value/boolean.d.ts +29 -0
- package/dist/types/value/color.d.ts +107 -0
- package/dist/types/value/function.d.ts +22 -0
- package/dist/types/value/index.d.ts +173 -0
- package/dist/types/value/list.d.ts +54 -0
- package/dist/types/value/map.d.ts +41 -0
- package/dist/types/value/number.d.ts +305 -0
- package/dist/types/value/string.d.ts +84 -0
- package/download-compiler-for-end-user.js +1 -6
- package/package.json +25 -21
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/src/compile.d.ts +0 -20
- package/dist/lib/src/embedded/compiler.d.ts +0 -19
- package/dist/lib/src/embedded/compiler.js.map +0 -1
- package/dist/lib/src/embedded/dispatcher.d.ts +0 -60
- package/dist/lib/src/embedded/dispatcher.js.map +0 -1
- package/dist/lib/src/embedded/message-transformer.d.ts +0 -47
- package/dist/lib/src/embedded/message-transformer.js.map +0 -1
- package/dist/lib/src/embedded/packet-transformer.d.ts +0 -34
- package/dist/lib/src/embedded/packet-transformer.js.map +0 -1
- package/dist/lib/src/embedded/request-tracker.d.ts +0 -20
- package/dist/lib/src/embedded/request-tracker.js.map +0 -1
- package/dist/lib/src/exception/exception.d.ts +0 -19
- package/dist/lib/src/exception/exception.js +0 -36
- package/dist/lib/src/exception/exception.js.map +0 -1
- package/dist/lib/src/exception/location.d.ts +0 -11
- package/dist/lib/src/exception/location.js +0 -6
- package/dist/lib/src/exception/location.js.map +0 -1
- package/dist/lib/src/exception/span.d.ts +0 -29
- package/dist/lib/src/exception/span.js.map +0 -1
- package/dist/lib/src/node-sass/render.d.ts +0 -60
- package/dist/lib/src/node-sass/render.js +0 -125
- package/dist/lib/src/node-sass/render.js.map +0 -1
- package/dist/lib/src/utils.d.ts +0 -14
- package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.d.ts +0 -1
- package/dist/tool/utils.d.ts +0 -29
package/dist/lib/src/utils.js
CHANGED
|
@@ -3,67 +3,89 @@
|
|
|
3
3
|
// MIT-style license that can be found in the LICENSE file or at
|
|
4
4
|
// https://opensource.org/licenses/MIT.
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
exports.putIfAbsent = exports.withoutExtension = exports.pathToUrlString = exports.valueError = exports.hostError = exports.mandatoryError = exports.compilerError = exports.asImmutableList = exports.isNullOrUndefined = exports.catchOr = exports.thenOr = void 0;
|
|
7
|
+
const immutable_1 = require("immutable");
|
|
8
|
+
const p = require("path");
|
|
9
|
+
const url = require("url");
|
|
10
|
+
function thenOr(promiseOrValue, callback) {
|
|
11
|
+
return promiseOrValue instanceof Promise
|
|
12
|
+
? promiseOrValue.then(callback)
|
|
13
|
+
: callback(promiseOrValue);
|
|
14
|
+
}
|
|
15
|
+
exports.thenOr = thenOr;
|
|
16
|
+
function catchOr(promiseOrValueCallback, callback) {
|
|
17
|
+
try {
|
|
18
|
+
const result = promiseOrValueCallback();
|
|
19
|
+
return result instanceof Promise
|
|
20
|
+
? result.catch(callback)
|
|
21
|
+
: result;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return callback(error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.catchOr = catchOr;
|
|
7
28
|
/** Checks for null or undefined. */
|
|
8
29
|
function isNullOrUndefined(object) {
|
|
9
30
|
return object === null || object === undefined;
|
|
10
31
|
}
|
|
11
32
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|
33
|
+
/** Returns `collection` as an immutable List. */
|
|
34
|
+
function asImmutableList(collection) {
|
|
35
|
+
return immutable_1.List.isList(collection) ? collection : (0, immutable_1.List)(collection);
|
|
36
|
+
}
|
|
37
|
+
exports.asImmutableList = asImmutableList;
|
|
12
38
|
/** Constructs a compiler-caused Error. */
|
|
13
39
|
function compilerError(message) {
|
|
14
40
|
return Error(`Compiler caused error: ${message}.`);
|
|
15
41
|
}
|
|
16
42
|
exports.compilerError = compilerError;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a `compilerError()` indicating that the given `field` should have
|
|
45
|
+
* been included but was not.
|
|
46
|
+
*/
|
|
47
|
+
function mandatoryError(field) {
|
|
48
|
+
return compilerError(`Missing mandatory field ${field}`);
|
|
49
|
+
}
|
|
50
|
+
exports.mandatoryError = mandatoryError;
|
|
17
51
|
/** Constructs a host-caused Error. */
|
|
18
52
|
function hostError(message) {
|
|
19
53
|
return Error(`Compiler reported error: ${message}.`);
|
|
20
54
|
}
|
|
21
55
|
exports.hostError = hostError;
|
|
56
|
+
/** Constructs an error caused by an invalid value type. */
|
|
57
|
+
function valueError(message, name) {
|
|
58
|
+
return Error(name ? `$${name}: ${message}.` : `${message}.`);
|
|
59
|
+
}
|
|
60
|
+
exports.valueError = valueError;
|
|
61
|
+
/** Converts a (possibly relative) path on the local filesystem to a URL. */
|
|
62
|
+
function pathToUrlString(path) {
|
|
63
|
+
if (p.isAbsolute(path))
|
|
64
|
+
return url.pathToFileURL(path).toString();
|
|
65
|
+
const components = p.sep === '\\' ? path.split(/[/\\]/) : path.split('/');
|
|
66
|
+
return components.map(encodeURIComponent).join('/');
|
|
67
|
+
}
|
|
68
|
+
exports.pathToUrlString = pathToUrlString;
|
|
69
|
+
/** Returns `path` without an extension, if it had one. */
|
|
70
|
+
function withoutExtension(path) {
|
|
71
|
+
const extension = p.extname(path);
|
|
72
|
+
return path.substring(0, path.length - extension.length);
|
|
73
|
+
}
|
|
74
|
+
exports.withoutExtension = withoutExtension;
|
|
22
75
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
76
|
+
* Dart-style utility. See
|
|
77
|
+
* http://go/dart-api/stable/2.8.4/dart-core/Map/putIfAbsent.html.
|
|
25
78
|
*/
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
exports.deprotifyException = deprotifyException;
|
|
31
|
-
// Creates a SourceSpan from the given protocol `buffer`. Throws if the buffer
|
|
32
|
-
// has invalid fields.
|
|
33
|
-
function deprotifySourceSpan(buffer) {
|
|
34
|
-
const text = buffer.getText();
|
|
35
|
-
if (buffer.getStart() === undefined) {
|
|
36
|
-
throw compilerError('Expected SourceSpan to have start.');
|
|
37
|
-
}
|
|
38
|
-
const start = deprotifySourceLocation(buffer.getStart());
|
|
39
|
-
let end;
|
|
40
|
-
if (buffer.getEnd() === undefined) {
|
|
41
|
-
if (text !== '') {
|
|
42
|
-
throw compilerError('Expected SourceSpan text to be empty.');
|
|
43
|
-
}
|
|
79
|
+
function putIfAbsent(map, key, provider) {
|
|
80
|
+
const val = map.get(key);
|
|
81
|
+
if (val !== undefined) {
|
|
82
|
+
return val;
|
|
44
83
|
}
|
|
45
84
|
else {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
85
|
+
const newVal = provider();
|
|
86
|
+
map.set(key, newVal);
|
|
87
|
+
return newVal;
|
|
50
88
|
}
|
|
51
|
-
const url = buffer.getUrl() === '' ? undefined : buffer.getUrl();
|
|
52
|
-
const context = buffer.getContext() === '' ? undefined : buffer.getContext();
|
|
53
|
-
return {
|
|
54
|
-
text,
|
|
55
|
-
start,
|
|
56
|
-
end,
|
|
57
|
-
url,
|
|
58
|
-
context,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
// Creates a SourceLocation from the given protocol `buffer`.
|
|
62
|
-
function deprotifySourceLocation(buffer) {
|
|
63
|
-
return {
|
|
64
|
-
offset: buffer.getOffset(),
|
|
65
|
-
line: buffer.getLine(),
|
|
66
|
-
column: buffer.getColumn(),
|
|
67
|
-
};
|
|
68
89
|
}
|
|
90
|
+
exports.putIfAbsent = putIfAbsent;
|
|
69
91
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/src/utils.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources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,GAAG,CAAC;KACZ;SAAM;QACL,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACrB,OAAO,MAAM,CAAC;KACf;AACH,CAAC;AAbD,kCAaC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 Google Inc. Use of this source code is governed by an
|
|
3
|
+
// MIT-style license that can be found in the LICENSE file or at
|
|
4
|
+
// https://opensource.org/licenses/MIT.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sassFalse = exports.sassTrue = void 0;
|
|
7
|
+
const immutable_1 = require("immutable");
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const trueHash = (0, immutable_1.hash)(true);
|
|
10
|
+
const falseHash = (0, immutable_1.hash)(false);
|
|
11
|
+
class SassBooleanInternal extends index_1.Value {
|
|
12
|
+
constructor(valueInternal) {
|
|
13
|
+
super();
|
|
14
|
+
this.valueInternal = valueInternal;
|
|
15
|
+
Object.freeze(this);
|
|
16
|
+
}
|
|
17
|
+
get value() {
|
|
18
|
+
return this.valueInternal;
|
|
19
|
+
}
|
|
20
|
+
get isTruthy() {
|
|
21
|
+
return this.value;
|
|
22
|
+
}
|
|
23
|
+
assertBoolean() {
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
equals(other) {
|
|
27
|
+
return this === other;
|
|
28
|
+
}
|
|
29
|
+
hashCode() {
|
|
30
|
+
return this.value ? trueHash : falseHash;
|
|
31
|
+
}
|
|
32
|
+
toString() {
|
|
33
|
+
return this.value ? 'sassTrue' : 'sassFalse';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The singleton instance of SassScript true. */
|
|
37
|
+
exports.sassTrue = new SassBooleanInternal(true);
|
|
38
|
+
/** The singleton instance of SassScript false. */
|
|
39
|
+
exports.sassFalse = new SassBooleanInternal(false);
|
|
40
|
+
//# sourceMappingURL=boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../../lib/src/value/boolean.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,yCAA+B;AAE/B,mCAA8B;AAY9B,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,CAAC;AAC5B,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,KAAK,CAAC,CAAC;AAE9B,MAAM,mBAAoB,SAAQ,aAAK;IACrC,YAA6B,aAAsB;QACjD,KAAK,EAAE,CAAC;QADmB,kBAAa,GAAb,aAAa,CAAS;QAEjD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,KAAY;QACjB,OAAO,IAAI,KAAK,KAAK,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3C,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IAC/C,CAAC;CACF;AAED,iDAAiD;AACpC,QAAA,QAAQ,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;AAEtD,kDAAkD;AACrC,QAAA,SAAS,GAAG,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 Google Inc. Use of this source code is governed by an
|
|
3
|
+
// MIT-style license that can be found in the LICENSE file or at
|
|
4
|
+
// https://opensource.org/licenses/MIT.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SassColor = void 0;
|
|
7
|
+
const index_1 = require("./index");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const immutable_1 = require("immutable");
|
|
10
|
+
/** A SassScript color. */
|
|
11
|
+
class SassColor extends index_1.Value {
|
|
12
|
+
constructor(color) {
|
|
13
|
+
super();
|
|
14
|
+
if ('red' in color) {
|
|
15
|
+
this.redInternal = (0, utils_1.fuzzyAssertInRange)(Math.round(color.red), 0, 255, 'red');
|
|
16
|
+
this.greenInternal = (0, utils_1.fuzzyAssertInRange)(Math.round(color.green), 0, 255, 'green');
|
|
17
|
+
this.blueInternal = (0, utils_1.fuzzyAssertInRange)(Math.round(color.blue), 0, 255, 'blue');
|
|
18
|
+
}
|
|
19
|
+
else if ('saturation' in color) {
|
|
20
|
+
this.hueInternal = (0, utils_1.positiveMod)(color.hue, 360);
|
|
21
|
+
this.saturationInternal = (0, utils_1.fuzzyAssertInRange)(color.saturation, 0, 100, 'saturation');
|
|
22
|
+
this.lightnessInternal = (0, utils_1.fuzzyAssertInRange)(color.lightness, 0, 100, 'lightness');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// From https://www.w3.org/TR/css-color-4/#hwb-to-rgb
|
|
26
|
+
const scaledHue = (0, utils_1.positiveMod)(color.hue, 360) / 360;
|
|
27
|
+
let scaledWhiteness = (0, utils_1.fuzzyAssertInRange)(color.whiteness, 0, 100, 'whiteness') / 100;
|
|
28
|
+
let scaledBlackness = (0, utils_1.fuzzyAssertInRange)(color.blackness, 0, 100, 'blackness') / 100;
|
|
29
|
+
const sum = scaledWhiteness + scaledBlackness;
|
|
30
|
+
if (sum > 1) {
|
|
31
|
+
scaledWhiteness /= sum;
|
|
32
|
+
scaledBlackness /= sum;
|
|
33
|
+
}
|
|
34
|
+
// Because HWB is (currently) used much less frequently than HSL or RGB, we
|
|
35
|
+
// don't cache its values because we expect the memory overhead of doing so
|
|
36
|
+
// to outweigh the cost of recalculating it on access. Instead, we eagerly
|
|
37
|
+
// convert it to RGB and then convert back if necessary.
|
|
38
|
+
this.redInternal = hwbToRgb(scaledHue + 1 / 3, scaledWhiteness, scaledBlackness);
|
|
39
|
+
this.greenInternal = hwbToRgb(scaledHue, scaledWhiteness, scaledBlackness);
|
|
40
|
+
this.blueInternal = hwbToRgb(scaledHue - 1 / 3, scaledWhiteness, scaledBlackness);
|
|
41
|
+
}
|
|
42
|
+
this.alphaInternal =
|
|
43
|
+
color.alpha === undefined
|
|
44
|
+
? 1
|
|
45
|
+
: (0, utils_1.fuzzyAssertInRange)(color.alpha, 0, 1, 'alpha');
|
|
46
|
+
}
|
|
47
|
+
/** `this`'s red channel. */
|
|
48
|
+
get red() {
|
|
49
|
+
if (this.redInternal === undefined) {
|
|
50
|
+
this.hslToRgb();
|
|
51
|
+
}
|
|
52
|
+
return this.redInternal;
|
|
53
|
+
}
|
|
54
|
+
/** `this`'s blue channel. */
|
|
55
|
+
get blue() {
|
|
56
|
+
if (this.blueInternal === undefined) {
|
|
57
|
+
this.hslToRgb();
|
|
58
|
+
}
|
|
59
|
+
return this.blueInternal;
|
|
60
|
+
}
|
|
61
|
+
/** `this`'s green channel. */
|
|
62
|
+
get green() {
|
|
63
|
+
if (this.greenInternal === undefined) {
|
|
64
|
+
this.hslToRgb();
|
|
65
|
+
}
|
|
66
|
+
return this.greenInternal;
|
|
67
|
+
}
|
|
68
|
+
/** `this`'s hue value. */
|
|
69
|
+
get hue() {
|
|
70
|
+
if (this.hueInternal === undefined) {
|
|
71
|
+
this.rgbToHsl();
|
|
72
|
+
}
|
|
73
|
+
return this.hueInternal;
|
|
74
|
+
}
|
|
75
|
+
/** `this`'s saturation value. */
|
|
76
|
+
get saturation() {
|
|
77
|
+
if (this.saturationInternal === undefined) {
|
|
78
|
+
this.rgbToHsl();
|
|
79
|
+
}
|
|
80
|
+
return this.saturationInternal;
|
|
81
|
+
}
|
|
82
|
+
/** `this`'s hue value. */
|
|
83
|
+
get lightness() {
|
|
84
|
+
if (this.lightnessInternal === undefined) {
|
|
85
|
+
this.rgbToHsl();
|
|
86
|
+
}
|
|
87
|
+
return this.lightnessInternal;
|
|
88
|
+
}
|
|
89
|
+
/** `this`'s whiteness value. */
|
|
90
|
+
get whiteness() {
|
|
91
|
+
// Because HWB is (currently) used much less frequently than HSL or RGB, we
|
|
92
|
+
// don't cache its values because we expect the memory overhead of doing so
|
|
93
|
+
// to outweigh the cost of recalculating it on access.
|
|
94
|
+
return (Math.min(this.red, this.green, this.blue) / 255) * 100;
|
|
95
|
+
}
|
|
96
|
+
/** `this`'s blackness value. */
|
|
97
|
+
get blackness() {
|
|
98
|
+
// Because HWB is (currently) used much less frequently than HSL or RGB, we
|
|
99
|
+
// don't cache its values because we expect the memory overhead of doing so
|
|
100
|
+
// to outweigh the cost of recalculating it on access.
|
|
101
|
+
return 100 - (Math.max(this.red, this.green, this.blue) / 255) * 100;
|
|
102
|
+
}
|
|
103
|
+
/** `this`'s alpha channel. */
|
|
104
|
+
get alpha() {
|
|
105
|
+
return this.alphaInternal;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether `this` has already calculated the HSL components for the color.
|
|
109
|
+
*
|
|
110
|
+
* This is an internal property that's not an official part of Sass's JS API,
|
|
111
|
+
* and may be broken at any time.
|
|
112
|
+
*/
|
|
113
|
+
get hasCalculatedHsl() {
|
|
114
|
+
return !!this.hueInternal;
|
|
115
|
+
}
|
|
116
|
+
assertColor() {
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
change(color) {
|
|
120
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
121
|
+
if ('whiteness' in color || 'blackness' in color) {
|
|
122
|
+
return new SassColor({
|
|
123
|
+
hue: (_a = color.hue) !== null && _a !== void 0 ? _a : this.hue,
|
|
124
|
+
whiteness: (_b = color.whiteness) !== null && _b !== void 0 ? _b : this.whiteness,
|
|
125
|
+
blackness: (_c = color.blackness) !== null && _c !== void 0 ? _c : this.blackness,
|
|
126
|
+
alpha: (_d = color.alpha) !== null && _d !== void 0 ? _d : this.alpha,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else if ('hue' in color ||
|
|
130
|
+
'saturation' in color ||
|
|
131
|
+
'lightness' in color) {
|
|
132
|
+
// Tell TypeScript this isn't a Partial<HwbColor>.
|
|
133
|
+
const hsl = color;
|
|
134
|
+
return new SassColor({
|
|
135
|
+
hue: (_e = hsl.hue) !== null && _e !== void 0 ? _e : this.hue,
|
|
136
|
+
saturation: (_f = hsl.saturation) !== null && _f !== void 0 ? _f : this.saturation,
|
|
137
|
+
lightness: (_g = hsl.lightness) !== null && _g !== void 0 ? _g : this.lightness,
|
|
138
|
+
alpha: (_h = hsl.alpha) !== null && _h !== void 0 ? _h : this.alpha,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if ('red' in color ||
|
|
142
|
+
'green' in color ||
|
|
143
|
+
'blue' in color ||
|
|
144
|
+
this.redInternal) {
|
|
145
|
+
const rgb = color;
|
|
146
|
+
return new SassColor({
|
|
147
|
+
red: (_j = rgb.red) !== null && _j !== void 0 ? _j : this.red,
|
|
148
|
+
green: (_k = rgb.green) !== null && _k !== void 0 ? _k : this.green,
|
|
149
|
+
blue: (_l = rgb.blue) !== null && _l !== void 0 ? _l : this.blue,
|
|
150
|
+
alpha: (_m = rgb.alpha) !== null && _m !== void 0 ? _m : this.alpha,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
return new SassColor({
|
|
155
|
+
hue: this.hue,
|
|
156
|
+
saturation: this.saturation,
|
|
157
|
+
lightness: this.lightness,
|
|
158
|
+
alpha: (_o = color.alpha) !== null && _o !== void 0 ? _o : this.alpha,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
equals(other) {
|
|
163
|
+
return (other instanceof SassColor &&
|
|
164
|
+
(0, utils_1.fuzzyEquals)(this.red, other.red) &&
|
|
165
|
+
(0, utils_1.fuzzyEquals)(this.green, other.green) &&
|
|
166
|
+
(0, utils_1.fuzzyEquals)(this.blue, other.blue) &&
|
|
167
|
+
(0, utils_1.fuzzyEquals)(this.alpha, other.alpha));
|
|
168
|
+
}
|
|
169
|
+
hashCode() {
|
|
170
|
+
return (0, immutable_1.hash)(this.red ^ this.green ^ this.blue ^ this.alpha);
|
|
171
|
+
}
|
|
172
|
+
toString() {
|
|
173
|
+
const isOpaque = (0, utils_1.fuzzyEquals)(this.alpha, 1);
|
|
174
|
+
let string = isOpaque ? 'rgb(' : 'rgba(';
|
|
175
|
+
string += `${this.red}, ${this.green}, ${this.blue}`;
|
|
176
|
+
string += isOpaque ? ')' : `, ${this.alpha})`;
|
|
177
|
+
return string;
|
|
178
|
+
}
|
|
179
|
+
// Computes `this`'s `hue`, `saturation`, and `lightness` values based on
|
|
180
|
+
// `red`, `green`, and `blue`.
|
|
181
|
+
//
|
|
182
|
+
// Algorithm from https://en.wikipedia.org/wiki/HSL_and_HSV#RGB_to_HSL_and_HSV
|
|
183
|
+
rgbToHsl() {
|
|
184
|
+
const scaledRed = this.red / 255;
|
|
185
|
+
const scaledGreen = this.green / 255;
|
|
186
|
+
const scaledBlue = this.blue / 255;
|
|
187
|
+
const max = Math.max(scaledRed, scaledGreen, scaledBlue);
|
|
188
|
+
const min = Math.min(scaledRed, scaledGreen, scaledBlue);
|
|
189
|
+
const delta = max - min;
|
|
190
|
+
if (max === min) {
|
|
191
|
+
this.hueInternal = 0;
|
|
192
|
+
}
|
|
193
|
+
else if (max === scaledRed) {
|
|
194
|
+
this.hueInternal = (0, utils_1.positiveMod)((60 * (scaledGreen - scaledBlue)) / delta, 360);
|
|
195
|
+
}
|
|
196
|
+
else if (max === scaledGreen) {
|
|
197
|
+
this.hueInternal = (0, utils_1.positiveMod)(120 + (60 * (scaledBlue - scaledRed)) / delta, 360);
|
|
198
|
+
}
|
|
199
|
+
else if (max === scaledBlue) {
|
|
200
|
+
this.hueInternal = (0, utils_1.positiveMod)(240 + (60 * (scaledRed - scaledGreen)) / delta, 360);
|
|
201
|
+
}
|
|
202
|
+
this.lightnessInternal = 50 * (max + min);
|
|
203
|
+
if (max === min) {
|
|
204
|
+
this.saturationInternal = 0;
|
|
205
|
+
}
|
|
206
|
+
else if (this.lightnessInternal < 50) {
|
|
207
|
+
this.saturationInternal = (100 * delta) / (max + min);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
this.saturationInternal = (100 * delta) / (2 - max - min);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Computes `this`'s red`, `green`, and `blue` channels based on `hue`,
|
|
214
|
+
// `saturation`, and `value`.
|
|
215
|
+
//
|
|
216
|
+
// Algorithm from the CSS3 spec: https://www.w3.org/TR/css3-color/#hsl-color.
|
|
217
|
+
hslToRgb() {
|
|
218
|
+
const scaledHue = this.hue / 360;
|
|
219
|
+
const scaledSaturation = this.saturation / 100;
|
|
220
|
+
const scaledLightness = this.lightness / 100;
|
|
221
|
+
const m2 = scaledLightness <= 0.5
|
|
222
|
+
? scaledLightness * (scaledSaturation + 1)
|
|
223
|
+
: scaledLightness +
|
|
224
|
+
scaledSaturation -
|
|
225
|
+
scaledLightness * scaledSaturation;
|
|
226
|
+
const m1 = scaledLightness * 2 - m2;
|
|
227
|
+
this.redInternal = (0, utils_1.fuzzyRound)(hueToRgb(m1, m2, scaledHue + 1 / 3) * 255);
|
|
228
|
+
this.greenInternal = (0, utils_1.fuzzyRound)(hueToRgb(m1, m2, scaledHue) * 255);
|
|
229
|
+
this.blueInternal = (0, utils_1.fuzzyRound)(hueToRgb(m1, m2, scaledHue - 1 / 3) * 255);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
exports.SassColor = SassColor;
|
|
233
|
+
// A helper for converting HWB colors to RGB.
|
|
234
|
+
function hwbToRgb(hue, scaledWhiteness, scaledBlackness) {
|
|
235
|
+
const factor = 1 - scaledWhiteness - scaledBlackness;
|
|
236
|
+
const channel = hueToRgb(0, 1, hue) * factor + scaledWhiteness;
|
|
237
|
+
return (0, utils_1.fuzzyRound)(channel * 255);
|
|
238
|
+
}
|
|
239
|
+
// An algorithm from the CSS3 spec: http://www.w3.org/TR/css3-color/#hsl-color.
|
|
240
|
+
function hueToRgb(m1, m2, hue) {
|
|
241
|
+
if (hue < 0)
|
|
242
|
+
hue += 1;
|
|
243
|
+
if (hue > 1)
|
|
244
|
+
hue -= 1;
|
|
245
|
+
if (hue < 1 / 6) {
|
|
246
|
+
return m1 + (m2 - m1) * hue * 6;
|
|
247
|
+
}
|
|
248
|
+
else if (hue < 1 / 2) {
|
|
249
|
+
return m2;
|
|
250
|
+
}
|
|
251
|
+
else if (hue < 2 / 3) {
|
|
252
|
+
return m1 + (m2 - m1) * (2 / 3 - hue) * 6;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
return m1;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../../../lib/src/value/color.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,mCAA8B;AAC9B,mCAKiB;AACjB,yCAA+B;AAuB/B,0BAA0B;AAC1B,MAAa,SAAU,SAAQ,aAAK;IAYlC,YAAY,KAAqC;QAC/C,KAAK,EAAE,CAAC;QAER,IAAI,KAAK,IAAI,KAAK,EAAE;YAClB,IAAI,CAAC,WAAW,GAAG,IAAA,0BAAkB,EACnC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EACrB,CAAC,EACD,GAAG,EACH,KAAK,CACN,CAAC;YACF,IAAI,CAAC,aAAa,GAAG,IAAA,0BAAkB,EACrC,IAAI,CAAC,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AC,GAAG,eAAe,GAAG,eAAe,CAAC;IACrD,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,GAAG,eAAe,CAAC;IAC/D,OAAO,IAAA,kBAAU,EAAC,OAAO,GAAG,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,+EAA+E;AAC/E,SAAS,QAAQ,CAAC,EAAU,EAAE,EAAU,EAAE,GAAW;IACnD,IAAI,GAAG,GAAG,CAAC;QAAE,GAAG,IAAI,CAAC,CAAC;IACtB,IAAI,GAAG,GAAG,CAAC;QAAE,GAAG,IAAI,CAAC,CAAC;IAEtB,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,EAAE;QACf,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;KACjC;SAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,EAAE,CAAC;KACX;SAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;KAC3C;SAAM;QACL,OAAO,EAAE,CAAC;KACX;AACH,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 Google Inc. Use of this source code is governed by an
|
|
3
|
+
// MIT-style license that can be found in the LICENSE file or at
|
|
4
|
+
// https://opensource.org/licenses/MIT.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Value = void 0;
|
|
7
|
+
const immutable_1 = require("immutable");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
/**
|
|
10
|
+
* A SassScript value.
|
|
11
|
+
*
|
|
12
|
+
* All SassScript values are immutable.
|
|
13
|
+
*
|
|
14
|
+
* Concrete values (such as `SassColor`) are implemented as subclasses and get
|
|
15
|
+
* instantiated as normal JS classes.
|
|
16
|
+
*
|
|
17
|
+
* Untyped values can be cast to particular types using `assert*()` functions,
|
|
18
|
+
* which throw user-friendly error messages if they fail.
|
|
19
|
+
*
|
|
20
|
+
* All values, except `false` and `null`, count as `true`.
|
|
21
|
+
*
|
|
22
|
+
* All values can be used as lists. Maps count as lists of pairs, while all
|
|
23
|
+
* other values count as single-value lists. Empty maps are equal to empty
|
|
24
|
+
* lists.
|
|
25
|
+
*/
|
|
26
|
+
class Value {
|
|
27
|
+
/** Whether `this` counts as `true`. */
|
|
28
|
+
get isTruthy() {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
/** Returns JS null if `this` is `sassNull`. Otherwise, returns `this`. */
|
|
32
|
+
get realNull() {
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
/** `this` as a list. */
|
|
36
|
+
get asList() {
|
|
37
|
+
return (0, immutable_1.List)([this]);
|
|
38
|
+
}
|
|
39
|
+
/** The separator for `this` as a list. */
|
|
40
|
+
get separator() {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/** Whether `this`, as a list, has brackets. */
|
|
44
|
+
get hasBrackets() {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// Subclasses can override this to change the behavior of
|
|
48
|
+
// `sassIndexToListIndex`.
|
|
49
|
+
get lengthAsList() {
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Converts `sassIndex` to a JS index into the array returned by `asList`.
|
|
54
|
+
*
|
|
55
|
+
* Sass indices start counting at 1, and may be negative in order to index
|
|
56
|
+
* from the end of the list.
|
|
57
|
+
*
|
|
58
|
+
* `sassIndex` must be...
|
|
59
|
+
* - a number, and
|
|
60
|
+
* - an integer, and
|
|
61
|
+
* - a valid index into `asList`.
|
|
62
|
+
*
|
|
63
|
+
* Otherwise, this throws an error.
|
|
64
|
+
*
|
|
65
|
+
* If `this` came from a function argument, `name` is the argument name
|
|
66
|
+
* (without the `$`) and is used for error reporting.
|
|
67
|
+
*/
|
|
68
|
+
sassIndexToListIndex(sassIndex, name) {
|
|
69
|
+
const index = sassIndex.assertNumber().assertInt();
|
|
70
|
+
if (index === 0) {
|
|
71
|
+
throw Error('List index may not be 0.');
|
|
72
|
+
}
|
|
73
|
+
if (Math.abs(index) > this.lengthAsList) {
|
|
74
|
+
throw (0, utils_1.valueError)(`Invalid index ${sassIndex} for a list with ${this.lengthAsList} elements.`, name);
|
|
75
|
+
}
|
|
76
|
+
return index < 0 ? this.lengthAsList + index : index - 1;
|
|
77
|
+
}
|
|
78
|
+
/** Returns `this.asList.get(index)`. */
|
|
79
|
+
get(index) {
|
|
80
|
+
return index < 1 && index >= -1 ? this : undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Casts `this` to `SassBoolean`; throws if `this` isn't a boolean.
|
|
84
|
+
*
|
|
85
|
+
* If `this` came from a function argument, `name` is the argument name
|
|
86
|
+
* (without the `$`) and is used for error reporting.
|
|
87
|
+
*/
|
|
88
|
+
assertBoolean(name) {
|
|
89
|
+
throw (0, utils_1.valueError)(`${this} is not a boolean`, name);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Casts `this` to `SassColor`; throws if `this` isn't a color.
|
|
93
|
+
*
|
|
94
|
+
* If `this` came from a function argument, `name` is the argument name
|
|
95
|
+
* (without the `$`) and is used for error reporting.
|
|
96
|
+
*/
|
|
97
|
+
assertColor(name) {
|
|
98
|
+
throw (0, utils_1.valueError)(`${this} is not a color`, name);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Casts `this` to `SassFunction`; throws if `this` isn't a function
|
|
102
|
+
* reference.
|
|
103
|
+
*
|
|
104
|
+
* If `this` came from a function argument, `name` is the argument name
|
|
105
|
+
* (without the `$`) and is used for error reporting.
|
|
106
|
+
*/
|
|
107
|
+
assertFunction(name) {
|
|
108
|
+
throw (0, utils_1.valueError)(`${this} is not a function reference`, name);
|
|
109
|
+
// TODO(awjin): Narrow the return type to SassFunction.
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Casts `this` to `SassMap`; throws if `this` isn't a map.
|
|
113
|
+
*
|
|
114
|
+
* If `this` came from a function argument, `name` is the argument name
|
|
115
|
+
* (without the `$`) and is used for error reporting.
|
|
116
|
+
*/
|
|
117
|
+
assertMap(name) {
|
|
118
|
+
throw (0, utils_1.valueError)(`${this} is not a map`, name);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns `this` as a `SassMap` if it counts as one (including empty lists),
|
|
122
|
+
* or `null` if it does not.
|
|
123
|
+
*/
|
|
124
|
+
tryMap() {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Casts `this` to `SassString`; throws if `this` isn't a string.
|
|
129
|
+
*
|
|
130
|
+
* If `this` came from a function argument, `name` is the argument name
|
|
131
|
+
* (without the `$`) and is used for error reporting.
|
|
132
|
+
*/
|
|
133
|
+
assertNumber(name) {
|
|
134
|
+
throw (0, utils_1.valueError)(`${this} is not a number`, name);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Casts `this` to `SassString`; throws if `this` isn't a string.
|
|
138
|
+
*
|
|
139
|
+
* If `this` came from a function argument, `name` is the argument name
|
|
140
|
+
* (without the `$`) and is used for error reporting.
|
|
141
|
+
*/
|
|
142
|
+
assertString(name) {
|
|
143
|
+
throw (0, utils_1.valueError)(`${this} is not a string`, name);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.Value = Value;
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/src/value/index.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,yCAA4C;AAQ5C,o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