@udixio/theme 1.0.0-beta.2

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/dist/app.module.d.ts +2 -0
  4. package/dist/app.service.d.ts +7 -0
  5. package/dist/color/color-manager.service.d.ts +15 -0
  6. package/dist/color/color.interface.d.ts +9 -0
  7. package/dist/color/color.module.d.ts +2 -0
  8. package/dist/color/color.service.d.ts +13 -0
  9. package/dist/color/entities/color.entity.d.ts +37 -0
  10. package/dist/color/models/default-color.model.d.ts +4 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.js +8 -0
  13. package/dist/main.d.ts +2 -0
  14. package/dist/material-color-utilities/contrastCurve.d.ts +46 -0
  15. package/dist/material-color-utilities/dynamic_color.d.ts +171 -0
  16. package/dist/material-color-utilities/index.d.ts +2 -0
  17. package/dist/material-color-utilities/toneDeltaPair.d.ts +60 -0
  18. package/dist/theme/entities/scheme.entity.d.ts +15 -0
  19. package/dist/theme/entities/variant.entity.d.ts +6 -0
  20. package/dist/theme/models/variant.model.d.ts +8 -0
  21. package/dist/theme/services/scheme.service.d.ts +12 -0
  22. package/dist/theme/services/theme.service.d.ts +13 -0
  23. package/dist/theme/services/variant.service.d.ts +7 -0
  24. package/dist/theme/theme.module.d.ts +2 -0
  25. package/dist/theme.cjs.development.js +1310 -0
  26. package/dist/theme.cjs.development.js.map +1 -0
  27. package/dist/theme.cjs.production.min.js +2 -0
  28. package/dist/theme.cjs.production.min.js.map +1 -0
  29. package/dist/theme.esm.js +1306 -0
  30. package/dist/theme.esm.js.map +1 -0
  31. package/package.json +101 -0
  32. package/src/app.module.ts +10 -0
  33. package/src/app.service.spec.ts +15 -0
  34. package/src/app.service.ts +11 -0
  35. package/src/color/color-manager.service.ts +186 -0
  36. package/src/color/color.interface.ts +15 -0
  37. package/src/color/color.module.ts +11 -0
  38. package/src/color/color.service.spec.ts +28 -0
  39. package/src/color/color.service.ts +52 -0
  40. package/src/color/entities/color.entity.ts +60 -0
  41. package/src/color/models/default-color.model.ts +297 -0
  42. package/src/index.ts +1 -0
  43. package/src/main.ts +11 -0
  44. package/src/material-color-utilities/contrastCurve.ts +63 -0
  45. package/src/material-color-utilities/dynamic_color.ts +450 -0
  46. package/src/material-color-utilities/index.ts +2 -0
  47. package/src/material-color-utilities/toneDeltaPair.ts +64 -0
  48. package/src/theme/entities/scheme.entity.ts +44 -0
  49. package/src/theme/entities/variant.entity.ts +38 -0
  50. package/src/theme/models/variant.model.ts +56 -0
  51. package/src/theme/services/scheme.service.ts +52 -0
  52. package/src/theme/services/theme.service.ts +58 -0
  53. package/src/theme/services/variant.service.ts +17 -0
  54. package/src/theme/theme.module.ts +10 -0
@@ -0,0 +1,1310 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@nestjs/core');
6
+ var tslib = require('tslib');
7
+ var common = require('@nestjs/common');
8
+ var materialColorUtilities = require('@material/material-color-utilities');
9
+ var mergeDeep = require('merge-deep');
10
+
11
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
12
+ try {
13
+ var i = n[a](c),
14
+ u = i.value;
15
+ } catch (n) {
16
+ return void e(n);
17
+ }
18
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
19
+ }
20
+ function _asyncToGenerator(n) {
21
+ return function () {
22
+ var t = this,
23
+ e = arguments;
24
+ return new Promise(function (r, o) {
25
+ var a = n.apply(t, e);
26
+ function _next(n) {
27
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
28
+ }
29
+ function _throw(n) {
30
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
31
+ }
32
+ _next(void 0);
33
+ });
34
+ };
35
+ }
36
+ function _defineProperties(e, r) {
37
+ for (var t = 0; t < r.length; t++) {
38
+ var o = r[t];
39
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
40
+ }
41
+ }
42
+ function _createClass(e, r, t) {
43
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
44
+ writable: !1
45
+ }), e;
46
+ }
47
+ function _extends() {
48
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
49
+ for (var e = 1; e < arguments.length; e++) {
50
+ var t = arguments[e];
51
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
52
+ }
53
+ return n;
54
+ }, _extends.apply(null, arguments);
55
+ }
56
+ function _regeneratorRuntime() {
57
+ _regeneratorRuntime = function () {
58
+ return e;
59
+ };
60
+ var t,
61
+ e = {},
62
+ r = Object.prototype,
63
+ n = r.hasOwnProperty,
64
+ o = Object.defineProperty || function (t, e, r) {
65
+ t[e] = r.value;
66
+ },
67
+ i = "function" == typeof Symbol ? Symbol : {},
68
+ a = i.iterator || "@@iterator",
69
+ c = i.asyncIterator || "@@asyncIterator",
70
+ u = i.toStringTag || "@@toStringTag";
71
+ function define(t, e, r) {
72
+ return Object.defineProperty(t, e, {
73
+ value: r,
74
+ enumerable: !0,
75
+ configurable: !0,
76
+ writable: !0
77
+ }), t[e];
78
+ }
79
+ try {
80
+ define({}, "");
81
+ } catch (t) {
82
+ define = function (t, e, r) {
83
+ return t[e] = r;
84
+ };
85
+ }
86
+ function wrap(t, e, r, n) {
87
+ var i = e && e.prototype instanceof Generator ? e : Generator,
88
+ a = Object.create(i.prototype),
89
+ c = new Context(n || []);
90
+ return o(a, "_invoke", {
91
+ value: makeInvokeMethod(t, r, c)
92
+ }), a;
93
+ }
94
+ function tryCatch(t, e, r) {
95
+ try {
96
+ return {
97
+ type: "normal",
98
+ arg: t.call(e, r)
99
+ };
100
+ } catch (t) {
101
+ return {
102
+ type: "throw",
103
+ arg: t
104
+ };
105
+ }
106
+ }
107
+ e.wrap = wrap;
108
+ var h = "suspendedStart",
109
+ l = "suspendedYield",
110
+ f = "executing",
111
+ s = "completed",
112
+ y = {};
113
+ function Generator() {}
114
+ function GeneratorFunction() {}
115
+ function GeneratorFunctionPrototype() {}
116
+ var p = {};
117
+ define(p, a, function () {
118
+ return this;
119
+ });
120
+ var d = Object.getPrototypeOf,
121
+ v = d && d(d(values([])));
122
+ v && v !== r && n.call(v, a) && (p = v);
123
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
124
+ function defineIteratorMethods(t) {
125
+ ["next", "throw", "return"].forEach(function (e) {
126
+ define(t, e, function (t) {
127
+ return this._invoke(e, t);
128
+ });
129
+ });
130
+ }
131
+ function AsyncIterator(t, e) {
132
+ function invoke(r, o, i, a) {
133
+ var c = tryCatch(t[r], t, o);
134
+ if ("throw" !== c.type) {
135
+ var u = c.arg,
136
+ h = u.value;
137
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
138
+ invoke("next", t, i, a);
139
+ }, function (t) {
140
+ invoke("throw", t, i, a);
141
+ }) : e.resolve(h).then(function (t) {
142
+ u.value = t, i(u);
143
+ }, function (t) {
144
+ return invoke("throw", t, i, a);
145
+ });
146
+ }
147
+ a(c.arg);
148
+ }
149
+ var r;
150
+ o(this, "_invoke", {
151
+ value: function (t, n) {
152
+ function callInvokeWithMethodAndArg() {
153
+ return new e(function (e, r) {
154
+ invoke(t, n, e, r);
155
+ });
156
+ }
157
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
158
+ }
159
+ });
160
+ }
161
+ function makeInvokeMethod(e, r, n) {
162
+ var o = h;
163
+ return function (i, a) {
164
+ if (o === f) throw Error("Generator is already running");
165
+ if (o === s) {
166
+ if ("throw" === i) throw a;
167
+ return {
168
+ value: t,
169
+ done: !0
170
+ };
171
+ }
172
+ for (n.method = i, n.arg = a;;) {
173
+ var c = n.delegate;
174
+ if (c) {
175
+ var u = maybeInvokeDelegate(c, n);
176
+ if (u) {
177
+ if (u === y) continue;
178
+ return u;
179
+ }
180
+ }
181
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
182
+ if (o === h) throw o = s, n.arg;
183
+ n.dispatchException(n.arg);
184
+ } else "return" === n.method && n.abrupt("return", n.arg);
185
+ o = f;
186
+ var p = tryCatch(e, r, n);
187
+ if ("normal" === p.type) {
188
+ if (o = n.done ? s : l, p.arg === y) continue;
189
+ return {
190
+ value: p.arg,
191
+ done: n.done
192
+ };
193
+ }
194
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
195
+ }
196
+ };
197
+ }
198
+ function maybeInvokeDelegate(e, r) {
199
+ var n = r.method,
200
+ o = e.iterator[n];
201
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
202
+ var i = tryCatch(o, e.iterator, r.arg);
203
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
204
+ var a = i.arg;
205
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
206
+ }
207
+ function pushTryEntry(t) {
208
+ var e = {
209
+ tryLoc: t[0]
210
+ };
211
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
212
+ }
213
+ function resetTryEntry(t) {
214
+ var e = t.completion || {};
215
+ e.type = "normal", delete e.arg, t.completion = e;
216
+ }
217
+ function Context(t) {
218
+ this.tryEntries = [{
219
+ tryLoc: "root"
220
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
221
+ }
222
+ function values(e) {
223
+ if (e || "" === e) {
224
+ var r = e[a];
225
+ if (r) return r.call(e);
226
+ if ("function" == typeof e.next) return e;
227
+ if (!isNaN(e.length)) {
228
+ var o = -1,
229
+ i = function next() {
230
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
231
+ return next.value = t, next.done = !0, next;
232
+ };
233
+ return i.next = i;
234
+ }
235
+ }
236
+ throw new TypeError(typeof e + " is not iterable");
237
+ }
238
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
239
+ value: GeneratorFunctionPrototype,
240
+ configurable: !0
241
+ }), o(GeneratorFunctionPrototype, "constructor", {
242
+ value: GeneratorFunction,
243
+ configurable: !0
244
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
245
+ var e = "function" == typeof t && t.constructor;
246
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
247
+ }, e.mark = function (t) {
248
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
249
+ }, e.awrap = function (t) {
250
+ return {
251
+ __await: t
252
+ };
253
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
254
+ return this;
255
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
256
+ void 0 === i && (i = Promise);
257
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
258
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
259
+ return t.done ? t.value : a.next();
260
+ });
261
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
262
+ return this;
263
+ }), define(g, "toString", function () {
264
+ return "[object Generator]";
265
+ }), e.keys = function (t) {
266
+ var e = Object(t),
267
+ r = [];
268
+ for (var n in e) r.push(n);
269
+ return r.reverse(), function next() {
270
+ for (; r.length;) {
271
+ var t = r.pop();
272
+ if (t in e) return next.value = t, next.done = !1, next;
273
+ }
274
+ return next.done = !0, next;
275
+ };
276
+ }, e.values = values, Context.prototype = {
277
+ constructor: Context,
278
+ reset: function (e) {
279
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
280
+ },
281
+ stop: function () {
282
+ this.done = !0;
283
+ var t = this.tryEntries[0].completion;
284
+ if ("throw" === t.type) throw t.arg;
285
+ return this.rval;
286
+ },
287
+ dispatchException: function (e) {
288
+ if (this.done) throw e;
289
+ var r = this;
290
+ function handle(n, o) {
291
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
292
+ }
293
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
294
+ var i = this.tryEntries[o],
295
+ a = i.completion;
296
+ if ("root" === i.tryLoc) return handle("end");
297
+ if (i.tryLoc <= this.prev) {
298
+ var c = n.call(i, "catchLoc"),
299
+ u = n.call(i, "finallyLoc");
300
+ if (c && u) {
301
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
302
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
303
+ } else if (c) {
304
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
305
+ } else {
306
+ if (!u) throw Error("try statement without catch or finally");
307
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
308
+ }
309
+ }
310
+ }
311
+ },
312
+ abrupt: function (t, e) {
313
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
314
+ var o = this.tryEntries[r];
315
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
316
+ var i = o;
317
+ break;
318
+ }
319
+ }
320
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
321
+ var a = i ? i.completion : {};
322
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
323
+ },
324
+ complete: function (t, e) {
325
+ if ("throw" === t.type) throw t.arg;
326
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
327
+ },
328
+ finish: function (t) {
329
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
330
+ var r = this.tryEntries[e];
331
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
332
+ }
333
+ },
334
+ catch: function (t) {
335
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
336
+ var r = this.tryEntries[e];
337
+ if (r.tryLoc === t) {
338
+ var n = r.completion;
339
+ if ("throw" === n.type) {
340
+ var o = n.arg;
341
+ resetTryEntry(r);
342
+ }
343
+ return o;
344
+ }
345
+ }
346
+ throw Error("illegal catch attempt");
347
+ },
348
+ delegateYield: function (e, r, n) {
349
+ return this.delegate = {
350
+ iterator: values(e),
351
+ resultName: r,
352
+ nextLoc: n
353
+ }, "next" === this.method && (this.arg = t), y;
354
+ }
355
+ }, e;
356
+ }
357
+ function _toPrimitive(t, r) {
358
+ if ("object" != typeof t || !t) return t;
359
+ var e = t[Symbol.toPrimitive];
360
+ if (void 0 !== e) {
361
+ var i = e.call(t, r || "default");
362
+ if ("object" != typeof i) return i;
363
+ throw new TypeError("@@toPrimitive must return a primitive value.");
364
+ }
365
+ return ("string" === r ? String : Number)(t);
366
+ }
367
+ function _toPropertyKey(t) {
368
+ var i = _toPrimitive(t, "string");
369
+ return "symbol" == typeof i ? i : i + "";
370
+ }
371
+
372
+ /**
373
+ * @license
374
+ * Copyright 2023 Google LLC
375
+ *
376
+ * Licensed under the Apache License, Version 2.0 (the "License");
377
+ * you may not use this file except in compliance with the License.
378
+ * You may obtain a copy of the License at
379
+ *
380
+ * http://www.apache.org/licenses/LICENSE-2.0
381
+ *
382
+ * Unless required by applicable law or agreed to in writing, software
383
+ * distributed under the License is distributed on an "AS IS" BASIS,
384
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
385
+ * See the License for the specific language governing permissions and
386
+ * limitations under the License.
387
+ */
388
+ /**
389
+ * A class containing a value that changes with the contrast level.
390
+ *
391
+ * Usually represents the contrast requirements for a dynamic color on its
392
+ * background. The four values correspond to values for contrast levels -1.0,
393
+ * 0.0, 0.5, and 1.0, respectively.
394
+ */
395
+ var ContrastCurve = /*#__PURE__*/function () {
396
+ /**
397
+ * Creates a `ContrastCurve` object.
398
+ *
399
+ * @param low Value for contrast level -1.0
400
+ * @param normal Value for contrast level 0.0
401
+ * @param medium Value for contrast level 0.5
402
+ * @param high Value for contrast level 1.0
403
+ */
404
+ function ContrastCurve(low, normal, medium, high) {
405
+ this.low = void 0;
406
+ this.normal = void 0;
407
+ this.medium = void 0;
408
+ this.high = void 0;
409
+ this.low = low;
410
+ this.normal = normal;
411
+ this.medium = medium;
412
+ this.high = high;
413
+ }
414
+ /**
415
+ * Returns the value at a given contrast level.
416
+ *
417
+ * @param contrastLevel The contrast level. 0.0 is the default (normal); -1.0
418
+ * is the lowest; 1.0 is the highest.
419
+ * @return The value. For contrast ratios, a number between 1.0 and 21.0.
420
+ */
421
+ var _proto = ContrastCurve.prototype;
422
+ _proto.get = function get(contrastLevel) {
423
+ if (contrastLevel <= -1.0) {
424
+ return this.low;
425
+ } else if (contrastLevel < 0.0) {
426
+ return materialColorUtilities.lerp(this.low, this.normal, (contrastLevel - -1) / 1);
427
+ } else if (contrastLevel < 0.5) {
428
+ return materialColorUtilities.lerp(this.normal, this.medium, (contrastLevel - 0) / 0.5);
429
+ } else if (contrastLevel < 1.0) {
430
+ return materialColorUtilities.lerp(this.medium, this.high, (contrastLevel - 0.5) / 0.5);
431
+ } else {
432
+ return this.high;
433
+ }
434
+ };
435
+ return ContrastCurve;
436
+ }();
437
+
438
+ /**
439
+ * @license
440
+ * Copyright 2023 Google LLC
441
+ *
442
+ * Licensed under the Apache License, Version 2.0 (the "License");
443
+ * you may not use this file except in compliance with the License.
444
+ * You may obtain a copy of the License at
445
+ *
446
+ * http://www.apache.org/licenses/LICENSE-2.0
447
+ *
448
+ * Unless required by applicable law or agreed to in writing, software
449
+ * distributed under the License is distributed on an "AS IS" BASIS,
450
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
451
+ * See the License for the specific language governing permissions and
452
+ * limitations under the License.
453
+ */
454
+ /**
455
+ * Documents a constraint between two DynamicColors, in which their tones must
456
+ * have a certain distance from each other.
457
+ *
458
+ * Prefer a DynamicColor with a background, this is for special cases when
459
+ * designers want tonal distance, literally contrast, between two colors that
460
+ * don't have a background / foreground relationship or a contrast guarantee.
461
+ */
462
+ var ToneDeltaPair =
463
+ /**
464
+ * Documents a constraint in tone distance between two DynamicColors.
465
+ *
466
+ * The polarity is an adjective that describes "A", compared to "B".
467
+ *
468
+ * For instance, ToneDeltaPair(A, B, 15, 'darker', stayTogether) states that
469
+ * A's tone should be at least 15 darker than B's.
470
+ *
471
+ * 'nearer' and 'farther' describes closeness to the surface roles. For
472
+ * instance, ToneDeltaPair(A, B, 10, 'nearer', stayTogether) states that A
473
+ * should be 10 lighter than B in light mode, and 10 darker than B in dark
474
+ * mode.
475
+ *
476
+ * @param roleA The first role in a pair.
477
+ * @param roleB The second role in a pair.
478
+ * @param delta Required difference between tones. Absolute value, negative
479
+ * values have undefined behavior.
480
+ * @param polarity The relative relation between tones of roleA and roleB,
481
+ * as described above.
482
+ * @param stayTogether Whether these two roles should stay on the same side of
483
+ * the "awkward zone" (T50-59). This is necessary for certain cases where
484
+ * one role has two backgrounds.
485
+ */
486
+ function ToneDeltaPair(roleA, roleB, delta, polarity, stayTogether) {
487
+ this.roleA = void 0;
488
+ this.roleB = void 0;
489
+ this.delta = void 0;
490
+ this.polarity = void 0;
491
+ this.stayTogether = void 0;
492
+ this.roleA = roleA;
493
+ this.roleB = roleB;
494
+ this.delta = delta;
495
+ this.polarity = polarity;
496
+ this.stayTogether = stayTogether;
497
+ };
498
+
499
+ /**
500
+ * @license
501
+ * Copyright 2022 Google LLC
502
+ *
503
+ * Licensed under the Apache License, Version 2.0 (the "License");
504
+ * you may not use this file except in compliance with the License.
505
+ * You may obtain a copy of the License at
506
+ *
507
+ * http://www.apache.org/licenses/LICENSE-2.0
508
+ *
509
+ * Unless required by applicable law or agreed to in writing, software
510
+ * distributed under the License is distributed on an "AS IS" BASIS,
511
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
512
+ * See the License for the specific language governing permissions and
513
+ * limitations under the License.
514
+ */
515
+ /**
516
+ * A color that adjusts itself based on UI state provided by SchemeEntity.
517
+ *
518
+ * Colors without backgrounds do not change tone when contrast changes. Colors
519
+ * with backgrounds become closer to their background as contrast lowers, and
520
+ * further when contrast increases.
521
+ *
522
+ * Prefer static constructors. They require either a hexcode, a palette and
523
+ * tone, or a hue and chroma. Optionally, they can provide a background
524
+ * DynamicColor.
525
+ */
526
+ var DynamicColor = /*#__PURE__*/function () {
527
+ /**
528
+ * The base constructor for DynamicColor.
529
+ *
530
+ * _Strongly_ prefer using one of the convenience constructors. This class is
531
+ * arguably too flexible to ensure it can support any scenario. Functional
532
+ * arguments allow overriding without risks that come with subclasses.
533
+ *
534
+ * For example, the default behavior of adjust tone at max contrast
535
+ * to be at a 7.0 ratio with its background is principled and
536
+ * matches accessibility guidance. That does not mean it's the desired
537
+ * approach for _every_ design system, and every color pairing,
538
+ * always, in every case.
539
+ *
540
+ * @param name The name of the dynamic color. Defaults to empty.
541
+ * @param palette Function that provides a TonalPalette given
542
+ * SchemeEntity. A TonalPalette is defined by a hue and chroma, so this
543
+ * replaces the need to specify hue/chroma. By providing a tonal palette, when
544
+ * contrast adjustments are made, intended chroma can be preserved.
545
+ * @param tone Function that provides a tone, given a SchemeEntity.
546
+ * @param isBackground Whether this dynamic color is a background, with
547
+ * some other color as the foreground. Defaults to false.
548
+ * @param background The background of the dynamic color (as a function of a
549
+ * `SchemeEntity`), if it exists.
550
+ * @param secondBackground A second background of the dynamic color (as a
551
+ * function of a `SchemeEntity`), if it
552
+ * exists.
553
+ * @param contrastCurve A `ContrastCurve` object specifying how its contrast
554
+ * against its background should behave in various contrast levels options.
555
+ * @param toneDeltaPair A `ToneDeltaPair` object specifying a tone delta
556
+ * constraint between two colors. One of them must be the color being
557
+ * constructed.
558
+ */
559
+ function DynamicColor(name, palette, tone, isBackground, background, secondBackground, contrastCurve, toneDeltaPair) {
560
+ this.name = void 0;
561
+ this.palette = void 0;
562
+ this.tone = void 0;
563
+ this.isBackground = void 0;
564
+ this.background = void 0;
565
+ this.secondBackground = void 0;
566
+ this.contrastCurve = void 0;
567
+ this.toneDeltaPair = void 0;
568
+ this.hctCache = new Map();
569
+ this.name = name;
570
+ this.palette = palette;
571
+ this.tone = tone;
572
+ this.isBackground = isBackground;
573
+ this.background = background;
574
+ this.secondBackground = secondBackground;
575
+ this.contrastCurve = contrastCurve;
576
+ this.toneDeltaPair = toneDeltaPair;
577
+ if (!background && secondBackground) {
578
+ throw new Error("Color " + name + " has secondBackground" + "defined, but background is not defined.");
579
+ }
580
+ if (!background && contrastCurve) {
581
+ throw new Error("Color " + name + " has contrastCurve" + "defined, but background is not defined.");
582
+ }
583
+ if (background && !contrastCurve) {
584
+ throw new Error("Color " + name + " has background" + "defined, but contrastCurve is not defined.");
585
+ }
586
+ }
587
+ /**
588
+ * Create a DynamicColor defined by a TonalPalette and HCT tone.
589
+ *
590
+ * @param args Functions with SchemeEntity as input. Must provide a palette
591
+ * and tone. May provide a background DynamicColor and ToneDeltaConstraint.
592
+ */
593
+ DynamicColor.fromPalette = function fromPalette(args) {
594
+ var _args$name, _args$isBackground;
595
+ return new DynamicColor((_args$name = args.name) != null ? _args$name : '', args.palette, args.tone, (_args$isBackground = args.isBackground) != null ? _args$isBackground : false, args.background, args.secondBackground, args.contrastCurve, args.toneDeltaPair);
596
+ }
597
+ /**
598
+ * Given a background tone, find a foreground tone, while ensuring they reach
599
+ * a contrast ratio that is as close to [ratio] as possible.
600
+ *
601
+ * @param bgTone Tone in HCT. Range is 0 to 100, undefined behavior when it
602
+ * falls outside that range.
603
+ * @param ratio The contrast ratio desired between bgTone and the return
604
+ * value.
605
+ */;
606
+ DynamicColor.foregroundTone = function foregroundTone(bgTone, ratio) {
607
+ var lighterTone = materialColorUtilities.Contrast.lighterUnsafe(bgTone, ratio);
608
+ var darkerTone = materialColorUtilities.Contrast.darkerUnsafe(bgTone, ratio);
609
+ var lighterRatio = materialColorUtilities.Contrast.ratioOfTones(lighterTone, bgTone);
610
+ var darkerRatio = materialColorUtilities.Contrast.ratioOfTones(darkerTone, bgTone);
611
+ var preferLighter = DynamicColor.tonePrefersLightForeground(bgTone);
612
+ if (preferLighter) {
613
+ // This handles an edge case where the initial contrast ratio is high
614
+ // (ex. 13.0), and the ratio passed to the function is that high
615
+ // ratio, and both the lighter and darker ratio fails to pass that
616
+ // ratio.
617
+ //
618
+ // This was observed with Tonal Spot's On Primary Container turning
619
+ // black momentarily between high and max contrast in light mode. PC's
620
+ // standard tone was T90, OPC's was T10, it was light mode, and the
621
+ // contrast value was 0.6568521221032331.
622
+ var negligibleDifference = Math.abs(lighterRatio - darkerRatio) < 0.1 && lighterRatio < ratio && darkerRatio < ratio;
623
+ return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
624
+ } else {
625
+ return darkerRatio >= ratio || darkerRatio >= lighterRatio ? darkerTone : lighterTone;
626
+ }
627
+ }
628
+ /**
629
+ * Returns whether [tone] prefers a light foreground.
630
+ *
631
+ * People prefer white foregrounds on ~T60-70. Observed over time, and also
632
+ * by Andrew Somers during research for APCA.
633
+ *
634
+ * T60 used as to create the smallest discontinuity possible when skipping
635
+ * down to T49 in order to ensure light foregrounds.
636
+ * Since `tertiaryContainer` in dark monochrome scheme requires a tone of
637
+ * 60, it should not be adjusted. Therefore, 60 is excluded here.
638
+ */;
639
+ DynamicColor.tonePrefersLightForeground = function tonePrefersLightForeground(tone) {
640
+ return Math.round(tone) < 60.0;
641
+ }
642
+ /**
643
+ * Returns whether [tone] can reach a contrast ratio of 4.5 with a lighter
644
+ * color.
645
+ */;
646
+ DynamicColor.toneAllowsLightForeground = function toneAllowsLightForeground(tone) {
647
+ return Math.round(tone) <= 49.0;
648
+ }
649
+ /**
650
+ * Adjust a tone such that white has 4.5 contrast, if the tone is
651
+ * reasonably close to supporting it.
652
+ */;
653
+ DynamicColor.enableLightForeground = function enableLightForeground(tone) {
654
+ if (DynamicColor.tonePrefersLightForeground(tone) && !DynamicColor.toneAllowsLightForeground(tone)) {
655
+ return 49.0;
656
+ }
657
+ return tone;
658
+ }
659
+ /**
660
+ * Return a ARGB integer (i.e. a hex code).
661
+ *
662
+ * @param scheme Defines the conditions of the user interface, for example,
663
+ * whether or not it is dark mode or light mode, and what the desired
664
+ * contrast level is.
665
+ */;
666
+ var _proto = DynamicColor.prototype;
667
+ _proto.getArgb = function getArgb(scheme) {
668
+ return this.getHct(scheme).toInt();
669
+ }
670
+ /**
671
+ * Return a color, expressed in the HCT color space, that this
672
+ * DynamicColor is under the conditions in scheme.
673
+ *
674
+ * @param scheme Defines the conditions of the user interface, for example,
675
+ * whether or not it is dark mode or light mode, and what the desired
676
+ * contrast level is.
677
+ */;
678
+ _proto.getHct = function getHct(scheme) {
679
+ var cachedAnswer = this.hctCache.get(scheme);
680
+ if (cachedAnswer != null) {
681
+ return cachedAnswer;
682
+ }
683
+ var tone = this.getTone(scheme);
684
+ var answer = this.palette(scheme).getHct(tone);
685
+ if (this.hctCache.size > 4) {
686
+ this.hctCache.clear();
687
+ }
688
+ this.hctCache.set(scheme, answer);
689
+ return answer;
690
+ }
691
+ /**
692
+ * Return a tone, T in the HCT color space, that this DynamicColor is under
693
+ * the conditions in scheme.
694
+ *
695
+ * @param scheme Defines the conditions of the user interface, for example,
696
+ * whether or not it is dark mode or light mode, and what the desired
697
+ * contrast level is.
698
+ */;
699
+ _proto.getTone = function getTone(scheme) {
700
+ var decreasingContrast = scheme.contrastLevel < 0;
701
+ // Case 1: dual foreground, pair of colors with delta constraint.
702
+ if (this.toneDeltaPair) {
703
+ var toneDeltaPair = this.toneDeltaPair(scheme);
704
+ var roleA = toneDeltaPair.roleA;
705
+ var roleB = toneDeltaPair.roleB;
706
+ var delta = toneDeltaPair.delta;
707
+ var polarity = toneDeltaPair.polarity;
708
+ var stayTogether = toneDeltaPair.stayTogether;
709
+ var bg = this.background(scheme);
710
+ var bgTone = bg.getTone(scheme);
711
+ var aIsNearer = polarity === 'nearer' || polarity === 'lighter' && !scheme.isDark || polarity === 'darker' && scheme.isDark;
712
+ var nearer = aIsNearer ? roleA : roleB;
713
+ var farther = aIsNearer ? roleB : roleA;
714
+ var amNearer = this.name === nearer.name;
715
+ var expansionDir = scheme.isDark ? 1 : -1;
716
+ // 1st round: solve to min, each
717
+ var nContrast = nearer.contrastCurve.get(scheme.contrastLevel);
718
+ var fContrast = farther.contrastCurve.get(scheme.contrastLevel);
719
+ // If a color is good enough, it is not adjusted.
720
+ // Initial and adjusted tones for `nearer`
721
+ var nInitialTone = nearer.tone(scheme);
722
+ var nTone = materialColorUtilities.Contrast.ratioOfTones(bgTone, nInitialTone) >= nContrast ? nInitialTone : DynamicColor.foregroundTone(bgTone, nContrast);
723
+ // Initial and adjusted tones for `farther`
724
+ var fInitialTone = farther.tone(scheme);
725
+ var fTone = materialColorUtilities.Contrast.ratioOfTones(bgTone, fInitialTone) >= fContrast ? fInitialTone : DynamicColor.foregroundTone(bgTone, fContrast);
726
+ if (decreasingContrast) {
727
+ // If decreasing contrast, adjust color to the "bare minimum"
728
+ // that satisfies contrast.
729
+ nTone = DynamicColor.foregroundTone(bgTone, nContrast);
730
+ fTone = DynamicColor.foregroundTone(bgTone, fContrast);
731
+ }
732
+ if ((fTone - nTone) * expansionDir >= delta) ; else {
733
+ // 2nd round: expand farther to match delta.
734
+ fTone = materialColorUtilities.clampDouble(0, 100, nTone + delta * expansionDir);
735
+ if ((fTone - nTone) * expansionDir >= delta) ; else {
736
+ // 3rd round: contract nearer to match delta.
737
+ nTone = materialColorUtilities.clampDouble(0, 100, fTone - delta * expansionDir);
738
+ }
739
+ }
740
+ // Avoids the 50-59 awkward zone.
741
+ if (50 <= nTone && nTone < 60) {
742
+ // If `nearer` is in the awkward zone, move it away, together with
743
+ // `farther`.
744
+ if (expansionDir > 0) {
745
+ nTone = 60;
746
+ fTone = Math.max(fTone, nTone + delta * expansionDir);
747
+ } else {
748
+ nTone = 49;
749
+ fTone = Math.min(fTone, nTone + delta * expansionDir);
750
+ }
751
+ } else if (50 <= fTone && fTone < 60) {
752
+ if (stayTogether) {
753
+ // Fixes both, to avoid two colors on opposite sides of the "awkward
754
+ // zone".
755
+ if (expansionDir > 0) {
756
+ nTone = 60;
757
+ fTone = Math.max(fTone, nTone + delta * expansionDir);
758
+ } else {
759
+ nTone = 49;
760
+ fTone = Math.min(fTone, nTone + delta * expansionDir);
761
+ }
762
+ } else {
763
+ // Not required to stay together; fixes just one.
764
+ if (expansionDir > 0) {
765
+ fTone = 60;
766
+ } else {
767
+ fTone = 49;
768
+ }
769
+ }
770
+ }
771
+ // Returns `nTone` if this color is `nearer`, otherwise `fTone`.
772
+ return amNearer ? nTone : fTone;
773
+ } else {
774
+ // Case 2: No contrast pair; just solve for itself.
775
+ var answer = this.tone(scheme);
776
+ if (this.background == null) {
777
+ return answer; // No adjustment for colors with no background.
778
+ }
779
+ var _bgTone = this.background(scheme).getTone(scheme);
780
+ var desiredRatio = this.contrastCurve.get(scheme.contrastLevel);
781
+ if (materialColorUtilities.Contrast.ratioOfTones(_bgTone, answer) >= desiredRatio) ; else {
782
+ // Rough improvement.
783
+ answer = DynamicColor.foregroundTone(_bgTone, desiredRatio);
784
+ }
785
+ if (decreasingContrast) {
786
+ answer = DynamicColor.foregroundTone(_bgTone, desiredRatio);
787
+ }
788
+ if (this.isBackground && 50 <= answer && answer < 60) {
789
+ // Must adjust
790
+ if (materialColorUtilities.Contrast.ratioOfTones(49, _bgTone) >= desiredRatio) {
791
+ answer = 49;
792
+ } else {
793
+ answer = 60;
794
+ }
795
+ }
796
+ if (this.secondBackground) {
797
+ // Case 3: Adjust for dual backgrounds.
798
+ var _ref = [this.background, this.secondBackground],
799
+ bg1 = _ref[0],
800
+ bg2 = _ref[1];
801
+ var _ref2 = [bg1(scheme).getTone(scheme), bg2(scheme).getTone(scheme)],
802
+ bgTone1 = _ref2[0],
803
+ bgTone2 = _ref2[1];
804
+ var _ref3 = [Math.max(bgTone1, bgTone2), Math.min(bgTone1, bgTone2)],
805
+ upper = _ref3[0],
806
+ lower = _ref3[1];
807
+ if (materialColorUtilities.Contrast.ratioOfTones(upper, answer) >= desiredRatio && materialColorUtilities.Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
808
+ return answer;
809
+ }
810
+ // The darkest light tone that satisfies the desired ratio,
811
+ // or -1 if such ratio cannot be reached.
812
+ var lightOption = materialColorUtilities.Contrast.lighter(upper, desiredRatio);
813
+ // The lightest dark tone that satisfies the desired ratio,
814
+ // or -1 if such ratio cannot be reached.
815
+ var darkOption = materialColorUtilities.Contrast.darker(lower, desiredRatio);
816
+ // Tones suitable for the foreground.
817
+ var availables = [];
818
+ if (lightOption !== -1) availables.push(lightOption);
819
+ if (darkOption !== -1) availables.push(darkOption);
820
+ var prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
821
+ if (prefersLight) {
822
+ return lightOption < 0 ? 100 : lightOption;
823
+ }
824
+ if (availables.length === 1) {
825
+ return availables[0];
826
+ }
827
+ return darkOption < 0 ? 0 : darkOption;
828
+ }
829
+ return answer;
830
+ }
831
+ };
832
+ return DynamicColor;
833
+ }();
834
+
835
+ var ColorEntity = /*#__PURE__*/function () {
836
+ function ColorEntity(option, schemeService, colorService) {
837
+ this.option = void 0;
838
+ this.schemeService = void 0;
839
+ this.colorService = void 0;
840
+ this.dynamicColor = null;
841
+ this.option = option;
842
+ this.schemeService = schemeService;
843
+ this.colorService = colorService;
844
+ }
845
+ var _proto = ColorEntity.prototype;
846
+ _proto.update = function update(args) {
847
+ this.dynamicColor = null;
848
+ this.option = mergeDeep(this.option, args);
849
+ };
850
+ _proto.getHex = function getHex() {
851
+ return materialColorUtilities.hexFromArgb(this.getArgb());
852
+ };
853
+ _proto.getArgb = function getArgb() {
854
+ return this.getDynamicColor().getArgb(this.schemeService.get());
855
+ };
856
+ _proto.getName = function getName() {
857
+ return this.option.name.replace(/([A-Z])/g, '_$1').toLowerCase();
858
+ };
859
+ _proto.getDynamicColor = function getDynamicColor() {
860
+ if (!this.dynamicColor) {
861
+ this.dynamicColor = DynamicColor.fromPalette(_extends({}, this.option, {
862
+ name: this.getName()
863
+ }));
864
+ }
865
+ return this.dynamicColor;
866
+ };
867
+ return ColorEntity;
868
+ }();
869
+
870
+ var SchemeEntity = /*#__PURE__*/function () {
871
+ function SchemeEntity(options) {
872
+ this.options = void 0;
873
+ this.options = options;
874
+ }
875
+ var _proto = SchemeEntity.prototype;
876
+ _proto.getPalette = function getPalette(key) {
877
+ if (!this.options) {
878
+ throw new Error('Scheme options is not set');
879
+ }
880
+ var palette = this.options.palettes.get(key);
881
+ if (!palette) {
882
+ throw new Error("Palette " + key + " not found");
883
+ }
884
+ return palette;
885
+ };
886
+ return _createClass(SchemeEntity, [{
887
+ key: "contrastLevel",
888
+ get: function get() {
889
+ if (!this.options) {
890
+ throw new Error('Scheme options is not set');
891
+ }
892
+ return this.options.contrastLevel;
893
+ }
894
+ }, {
895
+ key: "isDark",
896
+ get: function get() {
897
+ if (!this.options) {
898
+ throw new Error('Scheme options is not set');
899
+ }
900
+ return this.options.isDark;
901
+ }
902
+ }, {
903
+ key: "sourceColorHct",
904
+ get: function get() {
905
+ if (!this.options) {
906
+ throw new Error('Scheme options is not set');
907
+ }
908
+ return materialColorUtilities.Hct.fromInt(this.options.sourceColorArgb);
909
+ }
910
+ }]);
911
+ }();
912
+
913
+ var SchemeService = /*#__PURE__*/function () {
914
+ function SchemeService() {
915
+ this.schemeEntity = void 0;
916
+ this.options = void 0;
917
+ }
918
+ var _proto = SchemeService.prototype;
919
+ _proto.createOrUpdate = function createOrUpdate(options) {
920
+ this.options = mergeDeep(this.options, options);
921
+ var palettes = new Map();
922
+ var sourceColorArgb = materialColorUtilities.argbFromHex(this.options.sourceColorHex);
923
+ var sourceColorHct = materialColorUtilities.Hct.fromInt(sourceColorArgb);
924
+ if (!this.options.palettes) {
925
+ return;
926
+ }
927
+ for (var _i = 0, _Object$entries = Object.entries(this.options.palettes); _i < _Object$entries.length; _i++) {
928
+ var _Object$entries$_i = _Object$entries[_i],
929
+ key = _Object$entries$_i[0],
930
+ paletteFunction = _Object$entries$_i[1];
931
+ var palette = paletteFunction(sourceColorHct);
932
+ palettes.set(key, palette);
933
+ }
934
+ this.schemeEntity = new SchemeEntity(_extends({}, this.options, {
935
+ palettes: palettes,
936
+ sourceColorArgb: sourceColorArgb
937
+ }));
938
+ };
939
+ _proto.get = function get() {
940
+ if (!this.schemeEntity) {
941
+ throw new Error('Scheme is not created');
942
+ }
943
+ return this.schemeEntity;
944
+ };
945
+ return SchemeService;
946
+ }();
947
+ SchemeService = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Injectable()], SchemeService);
948
+
949
+ function capitalizeFirstLetter(string) {
950
+ return string.charAt(0).toUpperCase() + string.slice(1);
951
+ }
952
+ var highestSurface = function highestSurface(s, colorManagerService) {
953
+ return s.isDark ? colorManagerService.get('surfaceBright').getDynamicColor() : colorManagerService.get('surfaceDim').getDynamicColor();
954
+ };
955
+ var ColorManagerService = /*#__PURE__*/function () {
956
+ function ColorManagerService(schemeService) {
957
+ this.schemeService = void 0;
958
+ this.colorMap = new Map();
959
+ this.schemeService = schemeService;
960
+ }
961
+ var _proto = ColorManagerService.prototype;
962
+ _proto.createOrUpdate = function createOrUpdate(key, args) {
963
+ var colorEntity = this.colorMap.get(key);
964
+ if (!colorEntity) {
965
+ var palette = args.palette,
966
+ tone = args.tone;
967
+ if (palette && tone) {
968
+ colorEntity = new ColorEntity(_extends({}, args, {
969
+ palette: palette,
970
+ tone: tone,
971
+ name: key
972
+ }), this.schemeService, this);
973
+ this.colorMap.set(key, colorEntity);
974
+ } else {
975
+ throw new Error("Palette " + key + " does not exist");
976
+ }
977
+ } else {
978
+ colorEntity.update(_extends({}, args, {
979
+ name: key
980
+ }));
981
+ this.colorMap.set(key, colorEntity);
982
+ }
983
+ return colorEntity;
984
+ };
985
+ _proto.remove = function remove(key) {
986
+ return this.colorMap["delete"](key);
987
+ };
988
+ _proto.get = function get(key) {
989
+ var colorEntity = this.colorMap.get(key);
990
+ if (colorEntity) {
991
+ return colorEntity;
992
+ } else {
993
+ throw new Error("Color " + key + " does not exist");
994
+ }
995
+ };
996
+ _proto.getAll = function getAll() {
997
+ return this.colorMap;
998
+ };
999
+ _proto.addFromPalette = function addFromPalette(key) {
1000
+ var _this = this;
1001
+ var colorKey = key;
1002
+ var ColorKey = capitalizeFirstLetter(key);
1003
+ var onColorKey = 'on' + ColorKey;
1004
+ var colorKeyContainer = colorKey + 'Container';
1005
+ var onColorKeyContainer = 'on' + ColorKey + 'Container';
1006
+ var inverseColorKey = 'inverse' + ColorKey;
1007
+ var colorKeyFixed = colorKey + 'Fixed';
1008
+ var colorKeyFixedDim = colorKey + 'FixedDim';
1009
+ var onColorKeyFixed = 'on' + ColorKey + 'Fixed';
1010
+ var onColorKeyFixedVariant = 'on' + ColorKey + 'FixedVariant';
1011
+ this.createOrUpdate(colorKey, {
1012
+ palette: function palette(s) {
1013
+ return s.getPalette(key);
1014
+ },
1015
+ tone: function tone(s) {
1016
+ return s.isDark ? 80 : 40;
1017
+ },
1018
+ isBackground: true,
1019
+ background: function background(s) {
1020
+ return highestSurface(s, _this);
1021
+ },
1022
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
1023
+ toneDeltaPair: function toneDeltaPair(s) {
1024
+ return new ToneDeltaPair(_this.get(colorKeyContainer).getDynamicColor(), _this.get(colorKey).getDynamicColor(), 15, 'nearer', false);
1025
+ }
1026
+ });
1027
+ this.createOrUpdate(onColorKey, {
1028
+ palette: function palette(s) {
1029
+ return s.getPalette(key);
1030
+ },
1031
+ tone: function tone(s) {
1032
+ return s.isDark ? 20 : 100;
1033
+ },
1034
+ background: function background(s) {
1035
+ return _this.get(colorKey).getDynamicColor();
1036
+ },
1037
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1038
+ });
1039
+ this.createOrUpdate(colorKeyContainer, {
1040
+ palette: function palette(s) {
1041
+ return s.getPalette(key);
1042
+ },
1043
+ tone: function tone(s) {
1044
+ return s.isDark ? 30 : 90;
1045
+ },
1046
+ isBackground: true,
1047
+ background: function background(s) {
1048
+ return highestSurface(s, _this);
1049
+ },
1050
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
1051
+ toneDeltaPair: function toneDeltaPair(s) {
1052
+ return new ToneDeltaPair(_this.get(colorKeyContainer).getDynamicColor(), _this.get(colorKey).getDynamicColor(), 15, 'nearer', false);
1053
+ }
1054
+ });
1055
+ this.createOrUpdate(onColorKeyContainer, {
1056
+ palette: function palette(s) {
1057
+ return s.getPalette(key);
1058
+ },
1059
+ tone: function tone(s) {
1060
+ return s.isDark ? 90 : 10;
1061
+ },
1062
+ background: function background(s) {
1063
+ return _this.get(colorKeyContainer).getDynamicColor();
1064
+ },
1065
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1066
+ });
1067
+ this.createOrUpdate(inverseColorKey, {
1068
+ palette: function palette(s) {
1069
+ return s.getPalette(key);
1070
+ },
1071
+ tone: function tone(s) {
1072
+ return s.isDark ? 40 : 80;
1073
+ },
1074
+ background: function background(s) {
1075
+ return _this.get('inverseSurface').getDynamicColor();
1076
+ },
1077
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1078
+ });
1079
+ this.createOrUpdate(colorKeyFixed, {
1080
+ palette: function palette(s) {
1081
+ return s.getPalette(key);
1082
+ },
1083
+ tone: function tone(s) {
1084
+ return 90.0;
1085
+ },
1086
+ isBackground: true,
1087
+ background: function background(s) {
1088
+ return highestSurface(s, _this);
1089
+ },
1090
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
1091
+ toneDeltaPair: function toneDeltaPair(s) {
1092
+ return new ToneDeltaPair(_this.get(colorKeyFixed).getDynamicColor(), _this.get(colorKeyFixedDim).getDynamicColor(), 10, 'lighter', true);
1093
+ }
1094
+ });
1095
+ this.createOrUpdate(colorKeyFixedDim, {
1096
+ palette: function palette(s) {
1097
+ return s.getPalette(key);
1098
+ },
1099
+ tone: function tone(s) {
1100
+ return 80.0;
1101
+ },
1102
+ isBackground: true,
1103
+ background: function background(s) {
1104
+ return highestSurface(s, _this);
1105
+ },
1106
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
1107
+ toneDeltaPair: function toneDeltaPair(s) {
1108
+ return new ToneDeltaPair(_this.get(colorKeyFixed).getDynamicColor(), _this.get(colorKeyFixedDim).getDynamicColor(), 10, 'lighter', true);
1109
+ }
1110
+ });
1111
+ this.createOrUpdate(onColorKeyFixed, {
1112
+ palette: function palette(s) {
1113
+ return s.getPalette(key);
1114
+ },
1115
+ tone: function tone(s) {
1116
+ return 10.0;
1117
+ },
1118
+ background: function background(s) {
1119
+ return _this.get(colorKeyFixedDim).getDynamicColor();
1120
+ },
1121
+ secondBackground: function secondBackground(s) {
1122
+ return _this.get(colorKeyFixed).getDynamicColor();
1123
+ },
1124
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1125
+ });
1126
+ this.createOrUpdate(onColorKeyFixedVariant, {
1127
+ palette: function palette(s) {
1128
+ return s.getPalette(key);
1129
+ },
1130
+ tone: function tone(s) {
1131
+ return 30.0;
1132
+ },
1133
+ background: function background(s) {
1134
+ return _this.get(colorKeyFixedDim).getDynamicColor();
1135
+ },
1136
+ secondBackground: function secondBackground(s) {
1137
+ return _this.get(colorKeyFixed).getDynamicColor();
1138
+ },
1139
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1140
+ });
1141
+ };
1142
+ return ColorManagerService;
1143
+ }();
1144
+ ColorManagerService = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Injectable(), /*#__PURE__*/tslib.__metadata("design:paramtypes", [SchemeService])], ColorManagerService);
1145
+
1146
+ var ColorService = /*#__PURE__*/function () {
1147
+ function ColorService(colorManagerService) {
1148
+ this.colorManagerService = void 0;
1149
+ this.colorManagerService = colorManagerService;
1150
+ }
1151
+ var _proto = ColorService.prototype;
1152
+ _proto.getAllColors = function getAllColors() {
1153
+ return this.colorManagerService.getAll();
1154
+ }
1155
+ // getColors() {
1156
+ // const colors: Record<string, string> = {};
1157
+ //
1158
+ // for (const [key, value] of this.colorManagerService.getAll()) {
1159
+ // colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
1160
+ // }
1161
+ //
1162
+ // return colors;
1163
+ // }
1164
+ //
1165
+ // addBaseColors() {
1166
+ // this.colorManagerService.addFromPalette('primary');
1167
+ // this.colorManagerService.addFromPalette('secondary');
1168
+ // this.colorManagerService.addFromPalette('tertiary');
1169
+ // for (const [key, value] of Object.entries(this.defaultColorModel.colors)) {
1170
+ // this.colorManagerService.createOrUpdate(key, value as any);
1171
+ // }
1172
+ // }
1173
+ ;
1174
+ _proto.addColor = function addColor(key, color) {
1175
+ return this.colorManagerService.createOrUpdate(key, color);
1176
+ };
1177
+ _proto.addColors = function addColors(colors) {
1178
+ var _this = this;
1179
+ return Object.keys(colors).map(function (key) {
1180
+ return _this.addColor(key, colors[key]);
1181
+ });
1182
+ };
1183
+ _proto.getColor = function getColor(key) {
1184
+ return this.colorManagerService.get(key);
1185
+ };
1186
+ _proto.removeColor = function removeColor(key) {
1187
+ return this.colorManagerService.remove(key);
1188
+ };
1189
+ _proto.updateColor = function updateColor(key, newColor) {
1190
+ return this.colorManagerService.createOrUpdate(key, newColor);
1191
+ };
1192
+ return ColorService;
1193
+ }();
1194
+ ColorService = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Injectable(), /*#__PURE__*/tslib.__metadata("design:paramtypes", [ColorManagerService])], ColorService);
1195
+
1196
+ var VariantService = /*#__PURE__*/function () {
1197
+ function VariantService(schemeService) {
1198
+ this.schemeService = void 0;
1199
+ this.schemeService = schemeService;
1200
+ }
1201
+ var _proto = VariantService.prototype;
1202
+ _proto.set = function set(variantEntity) {
1203
+ if (!variantEntity.palettes.error) {
1204
+ variantEntity.palettes.error = function () {
1205
+ return materialColorUtilities.TonalPalette.fromHueAndChroma(25.0, 84.0);
1206
+ };
1207
+ }
1208
+ this.schemeService.createOrUpdate(variantEntity);
1209
+ };
1210
+ return VariantService;
1211
+ }();
1212
+ VariantService = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Injectable(), /*#__PURE__*/tslib.__metadata("design:paramtypes", [SchemeService])], VariantService);
1213
+
1214
+ var ThemeService = /*#__PURE__*/function () {
1215
+ function ThemeService(schemeService, variantService) {
1216
+ this.schemeService = void 0;
1217
+ this.variantService = void 0;
1218
+ this.schemeService = schemeService;
1219
+ this.variantService = variantService;
1220
+ // this.addPalette({key: "primary", addDefaultColors: true})
1221
+ // this.addPalette({key: "secondary", addDefaultColors: true})
1222
+ // this.addPalette({key: "tertiary", addDefaultColors: true})
1223
+ // this.addPalette({key: "error", palette: TonalPalette.fromHueAndChroma(25.0, 84.0)})
1224
+ // this.addPalette({key: "neutral"})
1225
+ // this.addPalette({key: "neutralVariant"})
1226
+ }
1227
+ // addPalette({key, palette, addDefaultColors}: {key: string; palette: TonalPalette; addDefaultColors: boolean}) {
1228
+ // this.themeOptions.palettes.set(key, palette);
1229
+ // if (addDefaultColors){
1230
+ // this.colorService.addPalette(key)
1231
+ // }
1232
+ // }
1233
+ // create(args: ThemeOptions): SchemeService {
1234
+ // return new SchemeService(args, this.colorService)
1235
+ // }
1236
+ //
1237
+ // update(options: Partial<ThemeOptions>): SchemeService {
1238
+ // Object.assign(this.themeOptions, options);
1239
+ // return this.theme();
1240
+ // }
1241
+ var _proto = ThemeService.prototype;
1242
+ _proto.create = function create(options) {
1243
+ this.schemeService.createOrUpdate(options);
1244
+ };
1245
+ _proto.addVariant = function addVariant(variant) {
1246
+ this.variantService.set(variant);
1247
+ };
1248
+ _proto.update = function update(options) {
1249
+ this.schemeService.createOrUpdate(options);
1250
+ };
1251
+ return ThemeService;
1252
+ }();
1253
+ ThemeService = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Injectable(), /*#__PURE__*/tslib.__metadata("design:paramtypes", [SchemeService, VariantService])], ThemeService);
1254
+
1255
+ var AppService = function AppService(colorService, themeService) {
1256
+ this.colorService = void 0;
1257
+ this.themeService = void 0;
1258
+ this.colorService = colorService;
1259
+ this.themeService = themeService;
1260
+ };
1261
+ AppService = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Injectable(), /*#__PURE__*/tslib.__metadata("design:paramtypes", [ColorService, ThemeService])], AppService);
1262
+
1263
+ var ThemeModule = function ThemeModule() {};
1264
+ ThemeModule = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Module({
1265
+ providers: [SchemeService, ThemeService, VariantService],
1266
+ exports: [ThemeService, SchemeService]
1267
+ })], ThemeModule);
1268
+
1269
+ var ColorModule = function ColorModule() {};
1270
+ ColorModule = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Module({
1271
+ imports: [ThemeModule],
1272
+ providers: [ColorService, ColorManagerService],
1273
+ exports: [ColorService]
1274
+ })], ColorModule);
1275
+
1276
+ var AppModule = function AppModule() {};
1277
+ AppModule = /*#__PURE__*/tslib.__decorate([/*#__PURE__*/common.Module({
1278
+ imports: [ColorModule, ThemeModule],
1279
+ providers: [AppService]
1280
+ })], AppModule);
1281
+
1282
+ function main() {
1283
+ return _main.apply(this, arguments);
1284
+ }
1285
+ function _main() {
1286
+ _main = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1287
+ var app, appService, close;
1288
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1289
+ while (1) switch (_context.prev = _context.next) {
1290
+ case 0:
1291
+ _context.next = 2;
1292
+ return core.NestFactory.create(AppModule);
1293
+ case 2:
1294
+ app = _context.sent;
1295
+ appService = app.get(AppService);
1296
+ close = function close() {
1297
+ return app.close();
1298
+ };
1299
+ return _context.abrupt("return", [appService, close]);
1300
+ case 6:
1301
+ case "end":
1302
+ return _context.stop();
1303
+ }
1304
+ }, _callee);
1305
+ }));
1306
+ return _main.apply(this, arguments);
1307
+ }
1308
+
1309
+ exports.main = main;
1310
+ //# sourceMappingURL=theme.cjs.development.js.map