sass-embedded 1.0.0-beta.3 → 1.0.0-beta.8

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/.gitignore +1 -0
  3. package/dist/lib/index.js +36 -2
  4. package/dist/lib/index.js.map +1 -1
  5. package/dist/lib/src/{embedded-compiler/compiler.js → async-compiler.js} +13 -13
  6. package/dist/lib/src/async-compiler.js.map +1 -0
  7. package/dist/lib/src/compile.js +187 -85
  8. package/dist/lib/src/compile.js.map +1 -1
  9. package/dist/lib/src/compiler-path.js +18 -0
  10. package/dist/lib/src/compiler-path.js.map +1 -0
  11. package/dist/lib/src/deprotofy-span.js +51 -0
  12. package/dist/lib/src/deprotofy-span.js.map +1 -0
  13. package/dist/lib/src/{embedded-protocol/dispatcher.js → dispatcher.js} +47 -41
  14. package/dist/lib/src/dispatcher.js.map +1 -0
  15. package/dist/lib/src/exception.js +20 -0
  16. package/dist/lib/src/exception.js.map +1 -0
  17. package/dist/lib/src/function-registry.js +92 -0
  18. package/dist/lib/src/function-registry.js.map +1 -0
  19. package/dist/lib/src/importer-registry.js +127 -0
  20. package/dist/lib/src/importer-registry.js.map +1 -0
  21. package/dist/lib/src/legacy.js +133 -0
  22. package/dist/lib/src/legacy.js.map +1 -0
  23. package/dist/lib/src/{embedded-protocol/message-transformer.js → message-transformer.js} +11 -10
  24. package/dist/lib/src/message-transformer.js.map +1 -0
  25. package/dist/lib/src/{embedded-compiler/packet-transformer.js → packet-transformer.js} +2 -1
  26. package/dist/lib/src/packet-transformer.js.map +1 -0
  27. package/dist/lib/src/protofier.js +272 -0
  28. package/dist/lib/src/protofier.js.map +1 -0
  29. package/dist/lib/src/{embedded-protocol/request-tracker.js → request-tracker.js} +1 -0
  30. package/dist/lib/src/request-tracker.js.map +1 -0
  31. package/dist/lib/src/sync-compiler.js +52 -0
  32. package/dist/lib/src/sync-compiler.js.map +1 -0
  33. package/dist/lib/src/{exception/span.js → sync-process/event.js} +2 -2
  34. package/dist/lib/src/sync-process/event.js.map +1 -0
  35. package/dist/lib/src/sync-process/index.js +122 -0
  36. package/dist/lib/src/sync-process/index.js.map +1 -0
  37. package/dist/lib/src/sync-process/sync-message-port.js +128 -0
  38. package/dist/lib/src/sync-process/sync-message-port.js.map +1 -0
  39. package/dist/lib/src/sync-process/worker.js +51 -0
  40. package/dist/lib/src/sync-process/worker.js.map +1 -0
  41. package/dist/lib/src/utils.js +88 -0
  42. package/dist/lib/src/utils.js.map +1 -1
  43. package/dist/lib/src/value/argument-list.js +31 -0
  44. package/dist/lib/src/value/argument-list.js.map +1 -0
  45. package/dist/lib/src/value/boolean.js +40 -0
  46. package/dist/lib/src/value/boolean.js.map +1 -0
  47. package/dist/lib/src/value/color.js +258 -0
  48. package/dist/lib/src/value/color.js.map +1 -0
  49. package/dist/lib/src/value/function.js +34 -0
  50. package/dist/lib/src/value/function.js.map +1 -0
  51. package/dist/lib/src/value/{value.js → index.js} +28 -17
  52. package/dist/lib/src/value/index.js.map +1 -0
  53. package/dist/lib/src/value/list.js +99 -0
  54. package/dist/lib/src/value/list.js.map +1 -0
  55. package/dist/lib/src/value/map.js +91 -0
  56. package/dist/lib/src/value/map.js.map +1 -0
  57. package/dist/lib/src/value/null.js +10 -6
  58. package/dist/lib/src/value/null.js.map +1 -1
  59. package/dist/lib/src/value/number.js +579 -0
  60. package/dist/lib/src/value/number.js.map +1 -0
  61. package/dist/lib/src/value/string.js +117 -0
  62. package/dist/lib/src/value/string.js.map +1 -0
  63. package/dist/lib/src/value/utils.js +120 -0
  64. package/dist/lib/src/value/utils.js.map +1 -0
  65. package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.js +994 -8
  66. package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.js.map +1 -1
  67. package/dist/package.json +63 -0
  68. package/dist/tool/utils.js +85 -91
  69. package/dist/tool/utils.js.map +1 -1
  70. package/dist/types/compile.d.ts +152 -0
  71. package/dist/types/exception.d.ts +41 -0
  72. package/dist/types/importer.d.ts +294 -0
  73. package/dist/types/index.d.ts +76 -0
  74. package/dist/types/legacy/exception.d.ts +54 -0
  75. package/dist/types/legacy/function.d.ts +700 -0
  76. package/dist/types/legacy/importer.d.ts +168 -0
  77. package/dist/types/legacy/options.d.ts +642 -0
  78. package/dist/types/legacy/plugin_this.d.ts +73 -0
  79. package/dist/types/legacy/render.d.ts +139 -0
  80. package/dist/types/logger/index.d.ts +94 -0
  81. package/dist/types/logger/source_location.d.ts +21 -0
  82. package/dist/types/logger/source_span.d.ts +34 -0
  83. package/dist/types/options.d.ts +408 -0
  84. package/dist/types/util/promise_or.d.ts +17 -0
  85. package/dist/types/value/argument_list.d.ts +47 -0
  86. package/dist/types/value/boolean.d.ts +29 -0
  87. package/dist/types/value/color.d.ts +107 -0
  88. package/dist/types/value/function.d.ts +22 -0
  89. package/dist/types/value/index.d.ts +173 -0
  90. package/dist/types/value/list.d.ts +54 -0
  91. package/dist/types/value/map.d.ts +41 -0
  92. package/dist/types/value/number.d.ts +305 -0
  93. package/dist/types/value/string.d.ts +84 -0
  94. package/download-compiler-for-end-user.js +1 -6
  95. package/package.json +23 -19
  96. package/dist/lib/index.d.ts +0 -1
  97. package/dist/lib/src/compile.d.ts +0 -20
  98. package/dist/lib/src/embedded-compiler/compiler.d.ts +0 -19
  99. package/dist/lib/src/embedded-compiler/compiler.js.map +0 -1
  100. package/dist/lib/src/embedded-compiler/packet-transformer.d.ts +0 -34
  101. package/dist/lib/src/embedded-compiler/packet-transformer.js.map +0 -1
  102. package/dist/lib/src/embedded-protocol/dispatcher.d.ts +0 -60
  103. package/dist/lib/src/embedded-protocol/dispatcher.js.map +0 -1
  104. package/dist/lib/src/embedded-protocol/message-transformer.d.ts +0 -47
  105. package/dist/lib/src/embedded-protocol/message-transformer.js.map +0 -1
  106. package/dist/lib/src/embedded-protocol/request-tracker.d.ts +0 -20
  107. package/dist/lib/src/embedded-protocol/request-tracker.js.map +0 -1
  108. package/dist/lib/src/embedded-protocol/utils.d.ts +0 -7
  109. package/dist/lib/src/embedded-protocol/utils.js +0 -52
  110. package/dist/lib/src/embedded-protocol/utils.js.map +0 -1
  111. package/dist/lib/src/exception/exception.d.ts +0 -19
  112. package/dist/lib/src/exception/exception.js +0 -36
  113. package/dist/lib/src/exception/exception.js.map +0 -1
  114. package/dist/lib/src/exception/location.d.ts +0 -11
  115. package/dist/lib/src/exception/location.js +0 -6
  116. package/dist/lib/src/exception/location.js.map +0 -1
  117. package/dist/lib/src/exception/span.d.ts +0 -29
  118. package/dist/lib/src/exception/span.js.map +0 -1
  119. package/dist/lib/src/node-sass/render.d.ts +0 -60
  120. package/dist/lib/src/node-sass/render.js +0 -126
  121. package/dist/lib/src/node-sass/render.js.map +0 -1
  122. package/dist/lib/src/utils.d.ts +0 -9
  123. package/dist/lib/src/value/null.d.ts +0 -11
  124. package/dist/lib/src/value/value.d.ts +0 -98
  125. package/dist/lib/src/value/value.js.map +0 -1
  126. package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.d.ts +0 -1
  127. package/dist/tool/utils.d.ts +0 -29
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ // Copyright 2021 Google LLC. 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.SyncMessagePort = void 0;
7
+ const assert_1 = require("assert");
8
+ const events_1 = require("events");
9
+ const worker_threads_1 = require("worker_threads");
10
+ // TODO(nex3): Make this its own package.
11
+ /**
12
+ * An enum of possible states for the shared buffer that two `SyncMessagePort`s
13
+ * use to communicate.
14
+ */
15
+ var BufferState;
16
+ (function (BufferState) {
17
+ /**
18
+ * The initial state. When an endpoint is ready to receive messages, it'll set
19
+ * the buffer to this state so that it can use `Atomics.wait()` to be notified
20
+ * when it switches to `MessageSent`.
21
+ */
22
+ BufferState[BufferState["AwaitingMessage"] = 0] = "AwaitingMessage";
23
+ /**
24
+ * The state indicating that a message has been sent. Whenever an endpoint
25
+ * sends a message, it'll set the buffer to this state so that the other
26
+ * endpoint's `Atomics.wait()` call terminates.
27
+ */
28
+ BufferState[BufferState["MessageSent"] = 1] = "MessageSent";
29
+ /**
30
+ * The state indicating that the channel has been closed. This never
31
+ * transitions to any other states.
32
+ */
33
+ BufferState[BufferState["Closed"] = 2] = "Closed";
34
+ })(BufferState || (BufferState = {}));
35
+ /**
36
+ * A communication port that can receive messages synchronously from another
37
+ * `SyncMessagePort`.
38
+ *
39
+ * This also emits the same asynchronous events as `MessagePort`.
40
+ */
41
+ class SyncMessagePort extends events_1.EventEmitter {
42
+ /**
43
+ * Creates a new message port. The `port` must be created by
44
+ * `SyncMessagePort.createChannel()` and must connect to a port passed to
45
+ * another `SyncMessagePort` in another worker.
46
+ */
47
+ constructor(port) {
48
+ var _a;
49
+ super();
50
+ this.port = port;
51
+ const buffer = (_a = (0, worker_threads_1.receiveMessageOnPort)(this.port)) === null || _a === void 0 ? void 0 : _a.message;
52
+ if (!buffer) {
53
+ throw new Error('new SyncMessagePort() must be passed a port from ' +
54
+ 'SyncMessagePort.createChannel().');
55
+ }
56
+ this.buffer = new Int32Array(buffer);
57
+ this.on('newListener', (event, listener) => {
58
+ this.port.on(event, listener);
59
+ });
60
+ this.on('removeListener', (event, listener) => this.port.removeListener(event, listener));
61
+ }
62
+ /** Creates a channel whose ports can be passed to `new SyncMessagePort()`. */
63
+ static createChannel() {
64
+ const channel = new worker_threads_1.MessageChannel();
65
+ // Four bytes is the minimum necessary to use `Atomics.wait()`.
66
+ const buffer = new SharedArrayBuffer(4);
67
+ // Queue up messages on each port so the caller doesn't have to explicitly
68
+ // pass the buffer around along with them.
69
+ channel.port1.postMessage(buffer);
70
+ channel.port2.postMessage(buffer);
71
+ return channel;
72
+ }
73
+ /** See `MessagePort.postMesage()`. */
74
+ postMessage(value, transferList) {
75
+ this.port.postMessage(value, transferList);
76
+ // If the other port is waiting for a new message, notify it that the
77
+ // message is ready. Use `Atomics.compareExchange` so that we don't
78
+ // overwrite the "closed" state.
79
+ if (Atomics.compareExchange(this.buffer, 0, BufferState.AwaitingMessage, BufferState.MessageSent) === BufferState.AwaitingMessage) {
80
+ Atomics.notify(this.buffer, 0);
81
+ }
82
+ }
83
+ // TODO(nex3):
84
+ // * Add a non-blocking `receiveMessage()`
85
+ // * Add a timeout option to `receiveMessage()`
86
+ // * Add an option to `receiveMessage()` to return a special value if the
87
+ // channel is closed.
88
+ /**
89
+ * Blocks and returns the next message sent by the other port.
90
+ *
91
+ * This may not be called while this has a listener for the `'message'` event.
92
+ * Throws an error if the channel is closed, including if it closes while this
93
+ * is waiting for a message.
94
+ */
95
+ receiveMessage() {
96
+ if (this.listenerCount('message')) {
97
+ throw new Error('SyncMessageChannel.receiveMessage() may not be called while there ' +
98
+ 'are message listeners.');
99
+ }
100
+ // Set the "new message" indicator to zero before we check for new messages.
101
+ // That way if the other port sets it to 1 between the call to
102
+ // `receiveMessageOnPort` and the call to `Atomics.wait()`, we won't
103
+ // overwrite it. Use `Atomics.compareExchange` so that we don't overwrite
104
+ // the "closed" state.
105
+ if (Atomics.compareExchange(this.buffer, 0, BufferState.MessageSent, BufferState.AwaitingMessage) === BufferState.Closed) {
106
+ throw new Error("The SyncMessagePort's channel is closed.");
107
+ }
108
+ let message = (0, worker_threads_1.receiveMessageOnPort)(this.port);
109
+ if (message)
110
+ return message.message;
111
+ // If there's no new message, wait for the other port to flip the "new
112
+ // message" indicator to 1. If it's been set to 1 since we stored 0, this
113
+ // will terminate immediately.
114
+ Atomics.wait(this.buffer, 0, BufferState.AwaitingMessage);
115
+ message = (0, worker_threads_1.receiveMessageOnPort)(this.port);
116
+ if (message)
117
+ return message.message;
118
+ assert_1.strict.equal(Atomics.load(this.buffer, 0), BufferState.Closed);
119
+ throw new Error("The SyncMessagePort's channel is closed.");
120
+ }
121
+ /** See `MessagePort.close()`. */
122
+ close() {
123
+ Atomics.store(this.buffer, 0, BufferState.Closed);
124
+ this.port.close();
125
+ }
126
+ }
127
+ exports.SyncMessagePort = SyncMessagePort;
128
+ //# sourceMappingURL=sync-message-port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-message-port.js","sourceRoot":"","sources":["../../../../lib/src/sync-process/sync-message-port.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,mCAAwC;AACxC,mCAAoC;AACpC,mDAKwB;AAExB,yCAAyC;AAEzC;;;GAGG;AACH,IAAK,WAkBJ;AAlBD,WAAK,WAAW;IACd;;;;OAIG;IACH,mEAAe,CAAA;IACf;;;;OAIG;IACH,2DAAW,CAAA;IACX;;;OAGG;IACH,iDAAM,CAAA;AACR,CAAC,EAlBI,WAAW,KAAX,WAAW,QAkBf;AAED;;;;;GAKG;AACH,MAAa,eAAgB,SAAQ,qBAAY;IAwB/C;;;;OAIG;IACH,YAA6B,IAAiB;;QAC5C,KAAK,EAAE,CAAC;QADmB,SAAI,GAAJ,IAAI,CAAa;QAG5C,MAAM,MAAM,GAAG,MAAA,IAAA,qCAAoB,EAAC,IAAI,CAAC,IAAI,CAAC,0CAAE,OAAO,CAAC;QACxD,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CACb,mDAAmD;gBACjD,kCAAkC,CACrC,CAAC;SACH;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,MAA2B,CAAC,CAAC;QAE1D,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YACzC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAC5C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,C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,EACxB;YACA,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC7D;QAED,IAAI,OAAO,GAAG,IAAA,qCAAoB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC;QAEpC,sEAAsE;QACtE,yEAAyE;QACzE,8BAA8B;QAC9B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;QAC1D,OAAO,GAAG,IAAA,qCAAoB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC;QAEpC,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,iCAAiC;IACjC,KAAK;QACH,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACF;AA5HD,0CA4HC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ // Copyright 2021 Google LLC. 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
+ const worker_threads_1 = require("worker_threads");
7
+ const child_process_1 = require("child_process");
8
+ const assert_1 = require("assert");
9
+ const sync_message_port_1 = require("./sync-message-port");
10
+ const port = new sync_message_port_1.SyncMessagePort(worker_threads_1.workerData.port);
11
+ /** A more type-safe way to call `port.postMesage()` */
12
+ function emit(event, transferList) {
13
+ port.postMessage(event, transferList);
14
+ }
15
+ const process = (0, child_process_1.spawn)(worker_threads_1.workerData.command, worker_threads_1.workerData.args, worker_threads_1.workerData.options);
16
+ port.on('message', message => {
17
+ if (message.type === 'stdin') {
18
+ process.stdin.write(message.data);
19
+ }
20
+ else if (message.type === 'stdinClosed') {
21
+ process.stdin.end();
22
+ }
23
+ else {
24
+ assert_1.strict.equal(message.type, 'kill');
25
+ process.kill(message.signal);
26
+ }
27
+ });
28
+ process.stdout.on('data', data => {
29
+ emit({ type: 'stdout', data }, [data.buffer]);
30
+ });
31
+ process.stderr.on('data', data => {
32
+ emit({ type: 'stderr', data }, [data.buffer]);
33
+ });
34
+ process.on('error', error => {
35
+ emit({ type: 'error', error });
36
+ process.kill();
37
+ worker_threads_1.parentPort.close();
38
+ port.close();
39
+ });
40
+ process.on('exit', (code, signal) => {
41
+ if (code !== null) {
42
+ emit({ type: 'exit', code });
43
+ }
44
+ else {
45
+ (0, assert_1.strict)(signal);
46
+ emit({ type: 'exit', signal });
47
+ }
48
+ worker_threads_1.parentPort.close();
49
+ port.close();
50
+ });
51
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../../lib/src/sync-process/worker.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;AAEvC,mDAKwB;AACxB,iDAA8D;AAC9D,mCAAwC;AAExC,2DAAoD;AAGpD,MAAM,IAAI,GAAG,IAAI,mCAAe,CAAC,2BAAU,CAAC,IAAmB,CAAC,CAAC;AAEjE,uDAAuD;AACvD,SAAS,IAAI,CAAC,KAAoB,EAAE,YAAiC;IACnE,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,OAAO,GAAG,IAAA,qBAAK,EACnB,2BAAU,CAAC,OAAiB,EAC5B,2BAAU,CAAC,IAAgB,EAC3B,2BAAU,CAAC,OAA+C,CAC3D,CAAC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,IAAI,KAAK,IAAI,EAAE;QACjB,IAAI,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;KAC5B;SAAM;QACL,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC;QACf,IAAI,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC;KAC9B;IAED,2BAAW,CAAC,KAAK,EAAE,CAAC;IACpB,IAAI,CAAC,KAAK,EAAE,CAAC;AACf,CAAC,CAAC,CAAC"}
@@ -3,16 +3,60 @@
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
+ exports.putIfAbsent = exports.protofySyntax = 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
+ const proto = require("./vendor/embedded-protocol/embedded_sass_pb");
11
+ /**
12
+ * The equivalent of `Promise.then()`, except that if the first argument is a
13
+ * plain value it synchronously invokes `callback()` and returns its result.
14
+ */
15
+ function thenOr(promiseOrValue, callback) {
16
+ return promiseOrValue instanceof Promise
17
+ ? promiseOrValue.then(callback)
18
+ : callback(promiseOrValue);
19
+ }
20
+ exports.thenOr = thenOr;
21
+ /**
22
+ * The equivalent of `Promise.catch()`, except that if the first argument throws
23
+ * synchronously it synchronously invokes `callback()` and returns its result.
24
+ */
25
+ function catchOr(promiseOrValueCallback, callback) {
26
+ try {
27
+ const result = promiseOrValueCallback();
28
+ return result instanceof Promise
29
+ ? result.catch(callback)
30
+ : result;
31
+ }
32
+ catch (error) {
33
+ return callback(error);
34
+ }
35
+ }
36
+ exports.catchOr = catchOr;
6
37
  /** Checks for null or undefined. */
7
38
  function isNullOrUndefined(object) {
8
39
  return object === null || object === undefined;
9
40
  }
10
41
  exports.isNullOrUndefined = isNullOrUndefined;
42
+ /** Returns `collection` as an immutable List. */
43
+ function asImmutableList(collection) {
44
+ return immutable_1.List.isList(collection) ? collection : (0, immutable_1.List)(collection);
45
+ }
46
+ exports.asImmutableList = asImmutableList;
11
47
  /** Constructs a compiler-caused Error. */
12
48
  function compilerError(message) {
13
49
  return Error(`Compiler caused error: ${message}.`);
14
50
  }
15
51
  exports.compilerError = compilerError;
52
+ /**
53
+ * Returns a `compilerError()` indicating that the given `field` should have
54
+ * been included but was not.
55
+ */
56
+ function mandatoryError(field) {
57
+ return compilerError(`Missing mandatory field ${field}`);
58
+ }
59
+ exports.mandatoryError = mandatoryError;
16
60
  /** Constructs a host-caused Error. */
17
61
  function hostError(message) {
18
62
  return Error(`Compiler reported error: ${message}.`);
@@ -23,4 +67,48 @@ function valueError(message, name) {
23
67
  return Error(name ? `$${name}: ${message}.` : `${message}.`);
24
68
  }
25
69
  exports.valueError = valueError;
70
+ /** Converts a (possibly relative) path on the local filesystem to a URL. */
71
+ function pathToUrlString(path) {
72
+ if (p.isAbsolute(path))
73
+ return url.pathToFileURL(path).toString();
74
+ const components = p.sep === '\\' ? path.split(/[/\\]/) : path.split('/');
75
+ return components.map(encodeURIComponent).join('/');
76
+ }
77
+ exports.pathToUrlString = pathToUrlString;
78
+ /** Returns `path` without an extension, if it had one. */
79
+ function withoutExtension(path) {
80
+ const extension = p.extname(path);
81
+ return path.substring(0, path.length - extension.length);
82
+ }
83
+ exports.withoutExtension = withoutExtension;
84
+ /** Converts a JS syntax string into a protobuf syntax enum. */
85
+ function protofySyntax(syntax) {
86
+ switch (syntax) {
87
+ case 'scss':
88
+ return proto.Syntax.SCSS;
89
+ case 'indented':
90
+ return proto.Syntax.INDENTED;
91
+ case 'css':
92
+ return proto.Syntax.CSS;
93
+ default:
94
+ throw new Error(`Unknown syntax: "${syntax}"`);
95
+ }
96
+ }
97
+ exports.protofySyntax = protofySyntax;
98
+ /**
99
+ * Dart-style utility. See
100
+ * http://go/dart-api/stable/2.8.4/dart-core/Map/putIfAbsent.html.
101
+ */
102
+ function putIfAbsent(map, key, provider) {
103
+ const val = map.get(key);
104
+ if (val !== undefined) {
105
+ return val;
106
+ }
107
+ else {
108
+ const newVal = provider();
109
+ map.set(key, newVal);
110
+ return newVal;
111
+ }
112
+ }
113
+ exports.putIfAbsent = putIfAbsent;
26
114
  //# 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;;AAIvC,oCAAoC;AACpC,SAAgB,iBAAiB,CAAI,MAAS;IAC5C,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC;AACjD,CAAC;AAFD,8CAEC;AAED,0CAA0C;AAC1C,SAAgB,aAAa,CAAC,OAAe;IAC3C,OAAO,KAAK,CAAC,0BAA0B,OAAO,GAAG,CAAC,CAAC;AACrD,CAAC;AAFD,sCAEC;AAED,sCAAsC;AACtC,SAAgB,SAAS,CAAC,OAAe;IACvC,OAAO,KAAK,CAAC,4BAA4B,OAAO,GAAG,CAAC,CAAC;AACvD,CAAC;AAFD,8BAEC;AAED,2DAA2D;AAC3D,SAAgB,UAAU,CAAC,OAAe,EAAE,IAAa;IACvD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,KAAK,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC;AAC/D,CAAC;AAFD,gCAEC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/src/utils.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,yCAA+B;AAC/B,0BAA0B;AAC1B,2BAA2B;AAE3B,qEAAqE;AAQrE;;;GAGG;AACH,SAAgB,MAAM,CACpB,cAAkC,EAClC,QAA0C;IAE1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ACH,CAAC;AAhBD,sCAgBC;AAED;;;GAGG;AACH,SAAgB,WAAW,CACzB,GAAc,EACd,GAAM,EACN,QAAiB;IAEjB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,OAAO,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,31 @@
1
+ "use strict";
2
+ // Copyright 2021 Google LLC. 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.SassArgumentList = void 0;
7
+ const immutable_1 = require("immutable");
8
+ const list_1 = require("./list");
9
+ class SassArgumentList extends list_1.SassList {
10
+ constructor(contents, keywords, separator, id) {
11
+ super(contents, { separator });
12
+ /**
13
+ * Whether the `keywords` getter has been accessed.
14
+ *
15
+ * This is marked as public so that the protofier can access it, but it's not
16
+ * part of the package's public API and should not be accessed by user code.
17
+ * It may be renamed or removed without warning in the future.
18
+ */
19
+ this.keywordsAccessed = false;
20
+ this.keywordsInternal = (0, immutable_1.isOrderedMap)(keywords)
21
+ ? keywords
22
+ : (0, immutable_1.OrderedMap)(keywords);
23
+ this.id = id !== null && id !== void 0 ? id : 0;
24
+ }
25
+ get keywords() {
26
+ this.keywordsAccessed = true;
27
+ return this.keywordsInternal;
28
+ }
29
+ }
30
+ exports.SassArgumentList = SassArgumentList;
31
+ //# sourceMappingURL=argument-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argument-list.js","sourceRoot":"","sources":["../../../../lib/src/value/argument-list.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,yCAAyD;AAEzD,iCAA+C;AAG/C,MAAa,gBAAiB,SAAQ,eAAQ;IAsC5C,YACE,QAA+B,EAC/B,QAA2D,EAC3D,SAAyB,EACzB,EAAW;QAEX,KAAK,CAAC,QAAQ,EAAE,EAAC,SAAS,EAAC,CAAC,CAAC;QApB/B;;;;;;WAMG;QACH,qBAAgB,GAAG,KAAK,CAAC;QAcvB,IAAI,CAAC,gBAAgB,GAAG,IAAA,wBAAY,EAAC,QAAQ,CAAC;YAC5C,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,IAAA,sBAAU,EAAC,QAAQ,CAAC,CAAC;QACzB,IAAI,CAAC,EAAE,GAAG,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,CAAC,CAAC;IACpB,CAAC;IAhBD,IAAI,QAAQ;QACV,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CAcF;AAlDD,4CAkDC"}
@@ -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