@udixio/theme 1.0.0-beta.6 → 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 (55) hide show
  1. package/dist/app.service.d.ts +6 -3
  2. package/dist/color/color.interface.d.ts +1 -2
  3. package/dist/color/entities/color.entity.d.ts +6 -1
  4. package/dist/color/index.d.ts +1 -2
  5. package/dist/color/models/default-color.model.d.ts +2 -3
  6. package/dist/color/services/color-manager.service.d.ts +18 -0
  7. package/dist/color/services/color.service.d.ts +21 -0
  8. package/dist/color/services/index.d.ts +2 -0
  9. package/dist/config/config.interface.d.ts +14 -0
  10. package/dist/config/config.module.d.ts +2 -0
  11. package/dist/config/config.service.d.ts +12 -0
  12. package/dist/config/index.d.ts +2 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/main.d.ts +2 -1
  15. package/dist/plugin/plugin.abstract.d.ts +6 -0
  16. package/dist/plugin/plugin.module.d.ts +2 -0
  17. package/dist/plugin/plugin.service.d.ts +9 -0
  18. package/dist/theme/entities/variant.entity.d.ts +2 -1
  19. package/dist/theme/services/scheme.service.d.ts +7 -2
  20. package/dist/theme/services/theme.service.d.ts +10 -4
  21. package/dist/theme/services/variant.service.d.ts +4 -0
  22. package/dist/theme.cjs.development.js +1077 -506
  23. package/dist/theme.cjs.development.js.map +1 -1
  24. package/dist/theme.cjs.production.min.js +1 -1
  25. package/dist/theme.cjs.production.min.js.map +1 -1
  26. package/dist/theme.esm.js +1073 -507
  27. package/dist/theme.esm.js.map +1 -1
  28. package/package.json +3 -5
  29. package/src/app.container.ts +9 -1
  30. package/src/app.service.ts +8 -2
  31. package/src/color/color.interface.ts +1 -3
  32. package/src/color/color.module.ts +2 -2
  33. package/src/color/entities/color.entity.ts +13 -1
  34. package/src/color/index.ts +1 -2
  35. package/src/color/models/default-color.model.ts +205 -202
  36. package/src/color/{color-manager.service.ts → services/color-manager.service.ts} +17 -10
  37. package/src/color/{color.service.spec.ts → services/color.service.spec.ts} +1 -1
  38. package/src/color/{color.service.ts → services/color.service.ts} +33 -21
  39. package/src/color/services/index.ts +2 -0
  40. package/src/config/config.interface.ts +15 -0
  41. package/src/config/config.module.ts +7 -0
  42. package/src/config/config.service.ts +68 -0
  43. package/src/config/index.ts +2 -0
  44. package/src/index.ts +3 -0
  45. package/src/main.ts +9 -1
  46. package/src/plugin/plugin.abstract.ts +7 -0
  47. package/src/plugin/plugin.module.ts +7 -0
  48. package/src/plugin/plugin.service.ts +26 -0
  49. package/src/theme/entities/variant.entity.ts +2 -1
  50. package/src/theme/models/variant.model.ts +7 -0
  51. package/src/theme/services/scheme.service.ts +39 -9
  52. package/src/theme/services/theme.service.ts +18 -8
  53. package/src/theme/services/variant.service.ts +36 -2
  54. package/dist/color/color-manager.service.d.ts +0 -17
  55. package/dist/color/color.service.d.ts +0 -16
package/dist/theme.esm.js CHANGED
@@ -1,6 +1,422 @@
1
1
  import { asClass, createContainer, InjectionMode } from 'awilix';
2
- import { lerp, Contrast, clampDouble, hexFromArgb, DislikeAnalyzer, Hct, argbFromHex, TonalPalette, sanitizeDegreesDouble } from '@material/material-color-utilities';
3
- import mergeDeep from 'merge-deep';
2
+ import { lerp, Contrast, clampDouble, hexFromArgb, Hct, argbFromHex, TonalPalette, DislikeAnalyzer, sanitizeDegreesDouble } from '@material/material-color-utilities';
3
+ import { resolve } from 'path';
4
+
5
+ var ColorService = /*#__PURE__*/function () {
6
+ function ColorService(_ref) {
7
+ var colorManagerService = _ref.colorManagerService;
8
+ this.colorManagerService = void 0;
9
+ this.colorManagerService = colorManagerService;
10
+ }
11
+ var _proto = ColorService.prototype;
12
+ _proto.getColors = function getColors() {
13
+ return this.colorManagerService.getAll();
14
+ }
15
+ // getColors() {
16
+ // const colors: Record<string, string> = {};
17
+ //
18
+ // for (const [key, value] of this.colorManagerService.getAll()) {
19
+ // colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
20
+ // }
21
+ //
22
+ // return colors;
23
+ // }
24
+ ;
25
+ _proto.addColor = function addColor(key, color) {
26
+ return this.colorManagerService.createOrUpdate(key, color);
27
+ };
28
+ _proto.addColors = function addColors(args) {
29
+ var _this = this;
30
+ if (!Array.isArray(args)) args = [args];
31
+ args.forEach(function (args) {
32
+ if (typeof args === 'function') {
33
+ args = args(_this);
34
+ }
35
+ if (args.fromPalettes) {
36
+ if (!Array.isArray(args.fromPalettes)) args.fromPalettes = [args.fromPalettes];
37
+ args.fromPalettes.map(function (paletteKey) {
38
+ _this.colorManagerService.addFromPalette(paletteKey);
39
+ });
40
+ }
41
+ if (args.colors) {
42
+ Object.keys(args.colors).map(function (key) {
43
+ return _this.addColor(key, args.colors[key]);
44
+ });
45
+ }
46
+ });
47
+ };
48
+ _proto.getColor = function getColor(key) {
49
+ return this.colorManagerService.get(key);
50
+ };
51
+ _proto.removeColor = function removeColor(key) {
52
+ return this.colorManagerService.remove(key);
53
+ };
54
+ _proto.updateColor = function updateColor(key, newColor) {
55
+ return this.colorManagerService.createOrUpdate(key, newColor);
56
+ };
57
+ return ColorService;
58
+ }();
59
+
60
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
61
+ try {
62
+ var i = n[a](c),
63
+ u = i.value;
64
+ } catch (n) {
65
+ return void e(n);
66
+ }
67
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
68
+ }
69
+ function _asyncToGenerator(n) {
70
+ return function () {
71
+ var t = this,
72
+ e = arguments;
73
+ return new Promise(function (r, o) {
74
+ var a = n.apply(t, e);
75
+ function _next(n) {
76
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
77
+ }
78
+ function _throw(n) {
79
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
80
+ }
81
+ _next(void 0);
82
+ });
83
+ };
84
+ }
85
+ function _defineProperties(e, r) {
86
+ for (var t = 0; t < r.length; t++) {
87
+ var o = r[t];
88
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
89
+ }
90
+ }
91
+ function _createClass(e, r, t) {
92
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
93
+ writable: !1
94
+ }), e;
95
+ }
96
+ function _extends() {
97
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
98
+ for (var e = 1; e < arguments.length; e++) {
99
+ var t = arguments[e];
100
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
101
+ }
102
+ return n;
103
+ }, _extends.apply(null, arguments);
104
+ }
105
+ function _regeneratorRuntime() {
106
+ _regeneratorRuntime = function () {
107
+ return e;
108
+ };
109
+ var t,
110
+ e = {},
111
+ r = Object.prototype,
112
+ n = r.hasOwnProperty,
113
+ o = Object.defineProperty || function (t, e, r) {
114
+ t[e] = r.value;
115
+ },
116
+ i = "function" == typeof Symbol ? Symbol : {},
117
+ a = i.iterator || "@@iterator",
118
+ c = i.asyncIterator || "@@asyncIterator",
119
+ u = i.toStringTag || "@@toStringTag";
120
+ function define(t, e, r) {
121
+ return Object.defineProperty(t, e, {
122
+ value: r,
123
+ enumerable: !0,
124
+ configurable: !0,
125
+ writable: !0
126
+ }), t[e];
127
+ }
128
+ try {
129
+ define({}, "");
130
+ } catch (t) {
131
+ define = function (t, e, r) {
132
+ return t[e] = r;
133
+ };
134
+ }
135
+ function wrap(t, e, r, n) {
136
+ var i = e && e.prototype instanceof Generator ? e : Generator,
137
+ a = Object.create(i.prototype),
138
+ c = new Context(n || []);
139
+ return o(a, "_invoke", {
140
+ value: makeInvokeMethod(t, r, c)
141
+ }), a;
142
+ }
143
+ function tryCatch(t, e, r) {
144
+ try {
145
+ return {
146
+ type: "normal",
147
+ arg: t.call(e, r)
148
+ };
149
+ } catch (t) {
150
+ return {
151
+ type: "throw",
152
+ arg: t
153
+ };
154
+ }
155
+ }
156
+ e.wrap = wrap;
157
+ var h = "suspendedStart",
158
+ l = "suspendedYield",
159
+ f = "executing",
160
+ s = "completed",
161
+ y = {};
162
+ function Generator() {}
163
+ function GeneratorFunction() {}
164
+ function GeneratorFunctionPrototype() {}
165
+ var p = {};
166
+ define(p, a, function () {
167
+ return this;
168
+ });
169
+ var d = Object.getPrototypeOf,
170
+ v = d && d(d(values([])));
171
+ v && v !== r && n.call(v, a) && (p = v);
172
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
173
+ function defineIteratorMethods(t) {
174
+ ["next", "throw", "return"].forEach(function (e) {
175
+ define(t, e, function (t) {
176
+ return this._invoke(e, t);
177
+ });
178
+ });
179
+ }
180
+ function AsyncIterator(t, e) {
181
+ function invoke(r, o, i, a) {
182
+ var c = tryCatch(t[r], t, o);
183
+ if ("throw" !== c.type) {
184
+ var u = c.arg,
185
+ h = u.value;
186
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
187
+ invoke("next", t, i, a);
188
+ }, function (t) {
189
+ invoke("throw", t, i, a);
190
+ }) : e.resolve(h).then(function (t) {
191
+ u.value = t, i(u);
192
+ }, function (t) {
193
+ return invoke("throw", t, i, a);
194
+ });
195
+ }
196
+ a(c.arg);
197
+ }
198
+ var r;
199
+ o(this, "_invoke", {
200
+ value: function (t, n) {
201
+ function callInvokeWithMethodAndArg() {
202
+ return new e(function (e, r) {
203
+ invoke(t, n, e, r);
204
+ });
205
+ }
206
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
207
+ }
208
+ });
209
+ }
210
+ function makeInvokeMethod(e, r, n) {
211
+ var o = h;
212
+ return function (i, a) {
213
+ if (o === f) throw Error("Generator is already running");
214
+ if (o === s) {
215
+ if ("throw" === i) throw a;
216
+ return {
217
+ value: t,
218
+ done: !0
219
+ };
220
+ }
221
+ for (n.method = i, n.arg = a;;) {
222
+ var c = n.delegate;
223
+ if (c) {
224
+ var u = maybeInvokeDelegate(c, n);
225
+ if (u) {
226
+ if (u === y) continue;
227
+ return u;
228
+ }
229
+ }
230
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
231
+ if (o === h) throw o = s, n.arg;
232
+ n.dispatchException(n.arg);
233
+ } else "return" === n.method && n.abrupt("return", n.arg);
234
+ o = f;
235
+ var p = tryCatch(e, r, n);
236
+ if ("normal" === p.type) {
237
+ if (o = n.done ? s : l, p.arg === y) continue;
238
+ return {
239
+ value: p.arg,
240
+ done: n.done
241
+ };
242
+ }
243
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
244
+ }
245
+ };
246
+ }
247
+ function maybeInvokeDelegate(e, r) {
248
+ var n = r.method,
249
+ o = e.iterator[n];
250
+ 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;
251
+ var i = tryCatch(o, e.iterator, r.arg);
252
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
253
+ var a = i.arg;
254
+ 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);
255
+ }
256
+ function pushTryEntry(t) {
257
+ var e = {
258
+ tryLoc: t[0]
259
+ };
260
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
261
+ }
262
+ function resetTryEntry(t) {
263
+ var e = t.completion || {};
264
+ e.type = "normal", delete e.arg, t.completion = e;
265
+ }
266
+ function Context(t) {
267
+ this.tryEntries = [{
268
+ tryLoc: "root"
269
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
270
+ }
271
+ function values(e) {
272
+ if (e || "" === e) {
273
+ var r = e[a];
274
+ if (r) return r.call(e);
275
+ if ("function" == typeof e.next) return e;
276
+ if (!isNaN(e.length)) {
277
+ var o = -1,
278
+ i = function next() {
279
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
280
+ return next.value = t, next.done = !0, next;
281
+ };
282
+ return i.next = i;
283
+ }
284
+ }
285
+ throw new TypeError(typeof e + " is not iterable");
286
+ }
287
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
288
+ value: GeneratorFunctionPrototype,
289
+ configurable: !0
290
+ }), o(GeneratorFunctionPrototype, "constructor", {
291
+ value: GeneratorFunction,
292
+ configurable: !0
293
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
294
+ var e = "function" == typeof t && t.constructor;
295
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
296
+ }, e.mark = function (t) {
297
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
298
+ }, e.awrap = function (t) {
299
+ return {
300
+ __await: t
301
+ };
302
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
303
+ return this;
304
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
305
+ void 0 === i && (i = Promise);
306
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
307
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
308
+ return t.done ? t.value : a.next();
309
+ });
310
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
311
+ return this;
312
+ }), define(g, "toString", function () {
313
+ return "[object Generator]";
314
+ }), e.keys = function (t) {
315
+ var e = Object(t),
316
+ r = [];
317
+ for (var n in e) r.push(n);
318
+ return r.reverse(), function next() {
319
+ for (; r.length;) {
320
+ var t = r.pop();
321
+ if (t in e) return next.value = t, next.done = !1, next;
322
+ }
323
+ return next.done = !0, next;
324
+ };
325
+ }, e.values = values, Context.prototype = {
326
+ constructor: Context,
327
+ reset: function (e) {
328
+ 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);
329
+ },
330
+ stop: function () {
331
+ this.done = !0;
332
+ var t = this.tryEntries[0].completion;
333
+ if ("throw" === t.type) throw t.arg;
334
+ return this.rval;
335
+ },
336
+ dispatchException: function (e) {
337
+ if (this.done) throw e;
338
+ var r = this;
339
+ function handle(n, o) {
340
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
341
+ }
342
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
343
+ var i = this.tryEntries[o],
344
+ a = i.completion;
345
+ if ("root" === i.tryLoc) return handle("end");
346
+ if (i.tryLoc <= this.prev) {
347
+ var c = n.call(i, "catchLoc"),
348
+ u = n.call(i, "finallyLoc");
349
+ if (c && u) {
350
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
351
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
352
+ } else if (c) {
353
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
354
+ } else {
355
+ if (!u) throw Error("try statement without catch or finally");
356
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
357
+ }
358
+ }
359
+ }
360
+ },
361
+ abrupt: function (t, e) {
362
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
363
+ var o = this.tryEntries[r];
364
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
365
+ var i = o;
366
+ break;
367
+ }
368
+ }
369
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
370
+ var a = i ? i.completion : {};
371
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
372
+ },
373
+ complete: function (t, e) {
374
+ if ("throw" === t.type) throw t.arg;
375
+ 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;
376
+ },
377
+ finish: function (t) {
378
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
379
+ var r = this.tryEntries[e];
380
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
381
+ }
382
+ },
383
+ catch: function (t) {
384
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
385
+ var r = this.tryEntries[e];
386
+ if (r.tryLoc === t) {
387
+ var n = r.completion;
388
+ if ("throw" === n.type) {
389
+ var o = n.arg;
390
+ resetTryEntry(r);
391
+ }
392
+ return o;
393
+ }
394
+ }
395
+ throw Error("illegal catch attempt");
396
+ },
397
+ delegateYield: function (e, r, n) {
398
+ return this.delegate = {
399
+ iterator: values(e),
400
+ resultName: r,
401
+ nextLoc: n
402
+ }, "next" === this.method && (this.arg = t), y;
403
+ }
404
+ }, e;
405
+ }
406
+ function _toPrimitive(t, r) {
407
+ if ("object" != typeof t || !t) return t;
408
+ var e = t[Symbol.toPrimitive];
409
+ if (void 0 !== e) {
410
+ var i = e.call(t, r || "default");
411
+ if ("object" != typeof i) return i;
412
+ throw new TypeError("@@toPrimitive must return a primitive value.");
413
+ }
414
+ return ("string" === r ? String : Number)(t);
415
+ }
416
+ function _toPropertyKey(t) {
417
+ var i = _toPrimitive(t, "string");
418
+ return "symbol" == typeof i ? i : i + "";
419
+ }
4
420
 
5
421
  /**
6
422
  * @license
@@ -465,41 +881,13 @@ function ToneDeltaPair(roleA, roleB, delta, polarity, stayTogether) {
465
881
  this.stayTogether = stayTogether;
466
882
  };
467
883
 
468
- function _defineProperties(e, r) {
469
- for (var t = 0; t < r.length; t++) {
470
- var o = r[t];
471
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
472
- }
473
- }
474
- function _createClass(e, r, t) {
475
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
476
- writable: !1
477
- }), e;
478
- }
479
- function _extends() {
480
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
481
- for (var e = 1; e < arguments.length; e++) {
482
- var t = arguments[e];
483
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
484
- }
485
- return n;
486
- }, _extends.apply(null, arguments);
487
- }
488
- function _toPrimitive(t, r) {
489
- if ("object" != typeof t || !t) return t;
490
- var e = t[Symbol.toPrimitive];
491
- if (void 0 !== e) {
492
- var i = e.call(t, r || "default");
493
- if ("object" != typeof i) return i;
494
- throw new TypeError("@@toPrimitive must return a primitive value.");
495
- }
496
- return ("string" === r ? String : Number)(t);
497
- }
498
- function _toPropertyKey(t) {
499
- var i = _toPrimitive(t, "string");
500
- return "symbol" == typeof i ? i : i + "";
884
+ function argbToRgb(argb) {
885
+ return {
886
+ r: argb >> 16 & 0xff,
887
+ g: argb >> 8 & 0xff,
888
+ b: argb & 0xff
889
+ };
501
890
  }
502
-
503
891
  var ColorEntity = /*#__PURE__*/function () {
504
892
  function ColorEntity(option, schemeService, colorService) {
505
893
  this.option = void 0;
@@ -521,6 +909,9 @@ var ColorEntity = /*#__PURE__*/function () {
521
909
  _proto.getArgb = function getArgb() {
522
910
  return this.getDynamicColor().getArgb(this.schemeService.get());
523
911
  };
912
+ _proto.getRgb = function getRgb() {
913
+ return argbToRgb(this.getArgb());
914
+ };
524
915
  _proto.getName = function getName() {
525
916
  return this.option.name.replace(/([A-Z])/g, '_$1').toLowerCase();
526
917
  };
@@ -538,8 +929,12 @@ var ColorEntity = /*#__PURE__*/function () {
538
929
  function capitalizeFirstLetter(string) {
539
930
  return string.charAt(0).toUpperCase() + string.slice(1);
540
931
  }
541
- var highestSurface = function highestSurface(s, colorManagerService) {
542
- return s.isDark ? colorManagerService.get('surfaceBright').getDynamicColor() : colorManagerService.get('surfaceDim').getDynamicColor();
932
+ var highestSurface = function highestSurface(s, colorService) {
933
+ if (colorService instanceof ColorService) {
934
+ return s.isDark ? colorService.getColor('surfaceBright').getDynamicColor() : colorService.getColor('surfaceDim').getDynamicColor();
935
+ } else {
936
+ return s.isDark ? colorService.get('surfaceBright').getDynamicColor() : colorService.get('surfaceDim').getDynamicColor();
937
+ }
543
938
  };
544
939
  var ColorManagerService = /*#__PURE__*/function () {
545
940
  function ColorManagerService(_ref) {
@@ -732,455 +1127,71 @@ var ColorManagerService = /*#__PURE__*/function () {
732
1127
  return ColorManagerService;
733
1128
  }();
734
1129
 
735
- function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
736
- var answer = tone;
737
- var closestToChroma = Hct.from(hue, chroma, tone);
738
- if (closestToChroma.chroma < chroma) {
739
- var chromaPeak = closestToChroma.chroma;
740
- while (closestToChroma.chroma < chroma) {
741
- answer += byDecreasingTone ? -1.0 : 1.0;
742
- var potentialSolution = Hct.from(hue, chroma, answer);
743
- if (chromaPeak > potentialSolution.chroma) {
744
- break;
1130
+ var ColorModule = {
1131
+ colorManagerService: /*#__PURE__*/asClass(ColorManagerService).singleton(),
1132
+ colorService: /*#__PURE__*/asClass(ColorService).singleton()
1133
+ };
1134
+
1135
+ var SchemeEntity = /*#__PURE__*/function () {
1136
+ function SchemeEntity(options) {
1137
+ this.options = void 0;
1138
+ this.options = options;
1139
+ }
1140
+ var _proto = SchemeEntity.prototype;
1141
+ _proto.getPalette = function getPalette(key) {
1142
+ if (!this.options) {
1143
+ throw new Error('Scheme options is not set');
1144
+ }
1145
+ var palette = this.options.palettes.get(key);
1146
+ if (!palette) {
1147
+ throw new Error("Palette " + key + " not found");
1148
+ }
1149
+ return palette;
1150
+ };
1151
+ return _createClass(SchemeEntity, [{
1152
+ key: "contrastLevel",
1153
+ get: function get() {
1154
+ if (!this.options) {
1155
+ throw new Error('Scheme options is not set');
745
1156
  }
746
- if (Math.abs(potentialSolution.chroma - chroma) < 0.4) {
747
- break;
1157
+ return this.options.contrastLevel;
1158
+ }
1159
+ }, {
1160
+ key: "isDark",
1161
+ get: function get() {
1162
+ if (!this.options) {
1163
+ throw new Error('Scheme options is not set');
748
1164
  }
749
- var potentialDelta = Math.abs(potentialSolution.chroma - chroma);
750
- var currentDelta = Math.abs(closestToChroma.chroma - chroma);
751
- if (potentialDelta < currentDelta) {
752
- closestToChroma = potentialSolution;
1165
+ return this.options.isDark;
1166
+ }
1167
+ }, {
1168
+ key: "sourceColorHct",
1169
+ get: function get() {
1170
+ if (!this.options) {
1171
+ throw new Error('Scheme options is not set');
753
1172
  }
754
- chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
1173
+ return Hct.fromInt(this.options.sourceColorArgb);
755
1174
  }
756
- }
757
- return answer;
758
- }
759
- var defaultColors = function defaultColors(colorManagerService) {
760
- return {
761
- background: {
762
- palette: function palette(s) {
763
- return s.getPalette('neutral');
764
- },
765
- tone: function tone(s) {
766
- return s.isDark ? 6 : 98;
767
- },
768
- isBackground: true
769
- },
770
- onBackground: {
771
- palette: function palette(s) {
772
- return s.getPalette('neutral');
773
- },
774
- tone: function tone(s) {
775
- return s.isDark ? 90 : 10;
776
- },
777
- background: function background(s) {
778
- return colorManagerService.get('background').getDynamicColor();
779
- },
780
- contrastCurve: new ContrastCurve(3, 3, 4.5, 7)
781
- },
782
- surface: {
783
- palette: function palette(s) {
784
- return s.getPalette('neutral');
785
- },
786
- tone: function tone(s) {
787
- return s.isDark ? 6 : 98;
788
- },
789
- isBackground: true
790
- },
791
- surfaceDim: {
792
- palette: function palette(s) {
793
- return s.getPalette('neutral');
794
- },
795
- tone: function tone(s) {
796
- return s.isDark ? 6 : 87;
797
- },
798
- isBackground: true
799
- },
800
- surfaceBright: {
801
- palette: function palette(s) {
802
- return s.getPalette('neutral');
803
- },
804
- tone: function tone(s) {
805
- return s.isDark ? 24 : 98;
806
- },
807
- isBackground: true
808
- },
809
- surfaceContainerLowest: {
810
- palette: function palette(s) {
811
- return s.getPalette('neutral');
812
- },
813
- tone: function tone(s) {
814
- return s.isDark ? 4 : 100;
815
- },
816
- isBackground: true
817
- },
818
- surfaceContainerLow: {
819
- palette: function palette(s) {
820
- return s.getPalette('neutral');
821
- },
822
- tone: function tone(s) {
823
- return s.isDark ? 10 : 96;
824
- },
825
- isBackground: true
826
- },
827
- surfaceContainer: {
828
- palette: function palette(s) {
829
- return s.getPalette('neutral');
830
- },
831
- tone: function tone(s) {
832
- return s.isDark ? 12 : 94;
833
- },
834
- isBackground: true
835
- },
836
- surfaceContainerHigh: {
837
- palette: function palette(s) {
838
- return s.getPalette('neutral');
839
- },
840
- tone: function tone(s) {
841
- return s.isDark ? 17 : 92;
842
- },
843
- isBackground: true
844
- },
845
- surfaceContainerHighest: {
846
- palette: function palette(s) {
847
- return s.getPalette('neutral');
848
- },
849
- tone: function tone(s) {
850
- return s.isDark ? 22 : 90;
851
- },
852
- isBackground: true
853
- },
854
- onSurface: {
855
- palette: function palette(s) {
856
- return s.getPalette('neutral');
857
- },
858
- tone: function tone(s) {
859
- return s.isDark ? 90 : 10;
860
- },
861
- background: function background(s) {
862
- return highestSurface(s, colorManagerService);
863
- },
864
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
865
- },
866
- surfaceVariant: {
867
- palette: function palette(s) {
868
- return s.getPalette('neutralVariant');
869
- },
870
- tone: function tone(s) {
871
- return s.isDark ? 30 : 90;
872
- },
873
- isBackground: true
874
- },
875
- onSurfaceVariant: {
876
- palette: function palette(s) {
877
- return s.getPalette('neutralVariant');
878
- },
879
- tone: function tone(s) {
880
- return s.isDark ? 80 : 30;
881
- },
882
- background: function background(s) {
883
- return highestSurface(s, colorManagerService);
884
- },
885
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
886
- },
887
- inverseSurface: {
888
- palette: function palette(s) {
889
- return s.getPalette('neutral');
890
- },
891
- tone: function tone(s) {
892
- return s.isDark ? 90 : 20;
893
- }
894
- },
895
- inverseOnSurface: {
896
- palette: function palette(s) {
897
- return s.getPalette('neutral');
898
- },
899
- tone: function tone(s) {
900
- return s.isDark ? 20 : 95;
901
- },
902
- background: function background(s) {
903
- return colorManagerService.get('inverseSurface').getDynamicColor();
904
- },
905
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
906
- },
907
- outline: {
908
- palette: function palette(s) {
909
- return s.getPalette('neutralVariant');
910
- },
911
- tone: function tone(s) {
912
- return s.isDark ? 60 : 50;
913
- },
914
- background: function background(s) {
915
- return highestSurface(s, colorManagerService);
916
- },
917
- contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7)
918
- },
919
- outlineVariant: {
920
- palette: function palette(s) {
921
- return s.getPalette('neutralVariant');
922
- },
923
- tone: function tone(s) {
924
- return s.isDark ? 30 : 80;
925
- },
926
- background: function background(s) {
927
- return highestSurface(s, colorManagerService);
928
- },
929
- contrastCurve: new ContrastCurve(1, 1, 3, 7)
930
- },
931
- shadow: {
932
- palette: function palette(s) {
933
- return s.getPalette('neutral');
934
- },
935
- tone: function tone(s) {
936
- return 0;
937
- }
938
- },
939
- scrim: {
940
- palette: function palette(s) {
941
- return s.getPalette('neutral');
942
- },
943
- tone: function tone(s) {
944
- return 0;
945
- }
946
- },
947
- surfaceTint: {
948
- palette: function palette(s) {
949
- return s.getPalette('neutral');
950
- },
951
- tone: function tone(s) {
952
- return s.isDark ? 80 : 40;
953
- },
954
- isBackground: true
955
- },
956
- secondaryContainer: {
957
- tone: function tone(s) {
958
- var initialTone = s.isDark ? 30 : 90;
959
- return findDesiredChromaByTone(s.getPalette('secondary').hue, s.getPalette('secondary').chroma, initialTone, !s.isDark);
960
- }
961
- },
962
- onSecondaryContainer: {
963
- tone: function tone(s) {
964
- return DynamicColor.foregroundTone(colorManagerService.get('secondaryContainer').getDynamicColor().tone(s), 4.5);
965
- }
966
- },
967
- tertiaryContainer: {
968
- palette: function palette(s) {
969
- return s.getPalette('tertiary');
970
- },
971
- tone: function tone(s) {
972
- var proposedHct = s.getPalette('tertiary').getHct(s.sourceColorHct.tone);
973
- return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
974
- }
975
- },
976
- onTertiaryContainer: {
977
- palette: function palette(s) {
978
- return s.getPalette('tertiary');
979
- },
980
- tone: function tone(s) {
981
- return DynamicColor.foregroundTone(colorManagerService.get('tertiaryContainer').getDynamicColor().tone(s), 4.5);
982
- }
983
- },
984
- error: {
985
- palette: function palette(s) {
986
- return s.getPalette('error');
987
- },
988
- tone: function tone(s) {
989
- return s.isDark ? 80 : 40;
990
- },
991
- isBackground: true,
992
- background: function background(s) {
993
- return highestSurface(s, colorManagerService);
994
- },
995
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
996
- toneDeltaPair: function toneDeltaPair(s) {
997
- return new ToneDeltaPair(colorManagerService.get('errorContainer').getDynamicColor(), colorManagerService.get('error').getDynamicColor(), 15, 'nearer', false);
998
- }
999
- },
1000
- onError: {
1001
- palette: function palette(s) {
1002
- return s.getPalette('error');
1003
- },
1004
- tone: function tone(s) {
1005
- return s.isDark ? 20 : 100;
1006
- },
1007
- background: function background(s) {
1008
- return colorManagerService.get('error').getDynamicColor();
1009
- },
1010
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1011
- },
1012
- errorContainer: {
1013
- palette: function palette(s) {
1014
- return s.getPalette('error');
1015
- },
1016
- tone: function tone(s) {
1017
- return s.isDark ? 30 : 90;
1018
- },
1019
- isBackground: true,
1020
- background: function background(s) {
1021
- return highestSurface(s, colorManagerService);
1022
- },
1023
- contrastCurve: new ContrastCurve(1, 1, 3, 7),
1024
- toneDeltaPair: function toneDeltaPair(s) {
1025
- return new ToneDeltaPair(colorManagerService.get('errorContainer').getDynamicColor(), colorManagerService.get('error').getDynamicColor(), 15, 'nearer', false);
1026
- }
1027
- },
1028
- onErrorContainer: {
1029
- palette: function palette(s) {
1030
- return s.getPalette('error');
1031
- },
1032
- tone: function tone(s) {
1033
- return s.isDark ? 90 : 10;
1034
- },
1035
- background: function background(s) {
1036
- return colorManagerService.get('errorContainer').getDynamicColor();
1037
- },
1038
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1039
- },
1040
- onTertiaryFixed: {
1041
- palette: function palette(s) {
1042
- return s.getPalette('tertiary');
1043
- },
1044
- tone: function tone(s) {
1045
- return 10.0;
1046
- },
1047
- background: function background(s) {
1048
- return colorManagerService.get('tertiaryFixedDim').getDynamicColor();
1049
- },
1050
- secondBackground: function secondBackground(s) {
1051
- return colorManagerService.get('tertiaryFixed').getDynamicColor();
1052
- },
1053
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1054
- },
1055
- onTertiaryFixedVariant: {
1056
- palette: function palette(s) {
1057
- return s.getPalette('tertiary');
1058
- },
1059
- tone: function tone(s) {
1060
- return 30.0;
1061
- },
1062
- background: function background(s) {
1063
- return colorManagerService.get('tertiaryFixedDim').getDynamicColor();
1064
- },
1065
- secondBackground: function secondBackground(s) {
1066
- return colorManagerService.get('tertiaryFixed').getDynamicColor();
1067
- },
1068
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1069
- }
1070
- };
1071
- };
1072
-
1073
- var ColorService = /*#__PURE__*/function () {
1074
- function ColorService(_ref) {
1075
- var colorManagerService = _ref.colorManagerService;
1076
- this.colorManagerService = void 0;
1077
- this.colorManagerService = colorManagerService;
1078
- }
1079
- var _proto = ColorService.prototype;
1080
- _proto.getAllColors = function getAllColors() {
1081
- return this.colorManagerService.getAll();
1082
- }
1083
- // getColors() {
1084
- // const colors: Record<string, string> = {};
1085
- //
1086
- // for (const [key, value] of this.colorManagerService.getAll()) {
1087
- // colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
1088
- // }
1089
- //
1090
- // return colors;
1091
- // }
1092
- ;
1093
- _proto.addBaseColors = function addBaseColors() {
1094
- var _this = this;
1095
- this.colorManagerService.addFromPalette('primary');
1096
- this.colorManagerService.addFromPalette('secondary');
1097
- this.colorManagerService.addFromPalette('tertiary');
1098
- var colors = defaultColors(this.colorManagerService);
1099
- Object.keys(colors).map(function (key) {
1100
- var color = colors[key];
1101
- if (!color) return;
1102
- return _this.colorManagerService.createOrUpdate(key, color);
1103
- });
1104
- };
1105
- _proto.addColor = function addColor(key, color) {
1106
- return this.colorManagerService.createOrUpdate(key, color);
1107
- };
1108
- _proto.addColors = function addColors(colors) {
1109
- var _this2 = this;
1110
- return Object.keys(colors).map(function (key) {
1111
- return _this2.addColor(key, colors[key]);
1112
- });
1113
- };
1114
- _proto.getColor = function getColor(key) {
1115
- return this.colorManagerService.get(key);
1116
- };
1117
- _proto.removeColor = function removeColor(key) {
1118
- return this.colorManagerService.remove(key);
1119
- };
1120
- _proto.updateColor = function updateColor(key, newColor) {
1121
- return this.colorManagerService.createOrUpdate(key, newColor);
1122
- };
1123
- return ColorService;
1124
- }();
1125
-
1126
- var ColorModule = {
1127
- colorManagerService: /*#__PURE__*/asClass(ColorManagerService).singleton(),
1128
- colorService: /*#__PURE__*/asClass(ColorService).singleton()
1129
- };
1130
-
1131
- var SchemeEntity = /*#__PURE__*/function () {
1132
- function SchemeEntity(options) {
1133
- this.options = void 0;
1134
- this.options = options;
1135
- }
1136
- var _proto = SchemeEntity.prototype;
1137
- _proto.getPalette = function getPalette(key) {
1138
- if (!this.options) {
1139
- throw new Error('Scheme options is not set');
1140
- }
1141
- var palette = this.options.palettes.get(key);
1142
- if (!palette) {
1143
- throw new Error("Palette " + key + " not found");
1144
- }
1145
- return palette;
1146
- };
1147
- return _createClass(SchemeEntity, [{
1148
- key: "contrastLevel",
1149
- get: function get() {
1150
- if (!this.options) {
1151
- throw new Error('Scheme options is not set');
1152
- }
1153
- return this.options.contrastLevel;
1154
- }
1155
- }, {
1156
- key: "isDark",
1157
- get: function get() {
1158
- if (!this.options) {
1159
- throw new Error('Scheme options is not set');
1160
- }
1161
- return this.options.isDark;
1162
- }
1163
- }, {
1164
- key: "sourceColorHct",
1165
- get: function get() {
1166
- if (!this.options) {
1167
- throw new Error('Scheme options is not set');
1168
- }
1169
- return Hct.fromInt(this.options.sourceColorArgb);
1170
- }
1171
- }]);
1172
- }();
1173
-
1174
- var SchemeService = /*#__PURE__*/function () {
1175
- function SchemeService() {
1176
- this.schemeEntity = void 0;
1177
- this.options = void 0;
1175
+ }]);
1176
+ }();
1177
+
1178
+ var SchemeService = /*#__PURE__*/function () {
1179
+ function SchemeService() {
1180
+ this.schemeEntity = void 0;
1181
+ this.options = void 0;
1178
1182
  }
1179
1183
  var _proto = SchemeService.prototype;
1180
1184
  _proto.createOrUpdate = function createOrUpdate(options) {
1181
- this.options = mergeDeep(options, this.options);
1185
+ var _this$options, _this$options2;
1186
+ this.options = _extends({}, this.options, options, {
1187
+ sourcesColorHex: _extends({}, (_this$options = this.options) == null ? void 0 : _this$options.sourcesColorHex, options.sourcesColorHex),
1188
+ palettes: _extends({}, (_this$options2 = this.options) == null ? void 0 : _this$options2.palettes, options.palettes)
1189
+ });
1182
1190
  var palettes = new Map();
1183
- var sourceColorArgb = argbFromHex(this.options.sourceColorHex);
1191
+ if (!this.options.sourcesColorHex.primary) {
1192
+ throw new Error('Primary source color is not set');
1193
+ }
1194
+ var sourceColorArgb = argbFromHex(this.options.sourcesColorHex.primary);
1184
1195
  var sourceColorHct = Hct.fromInt(sourceColorArgb);
1185
1196
  if (!this.options.palettes) {
1186
1197
  return;
@@ -1188,8 +1199,17 @@ var SchemeService = /*#__PURE__*/function () {
1188
1199
  for (var _i = 0, _Object$entries = Object.entries(this.options.palettes); _i < _Object$entries.length; _i++) {
1189
1200
  var _Object$entries$_i = _Object$entries[_i],
1190
1201
  key = _Object$entries$_i[0],
1191
- paletteFunction = _Object$entries$_i[1];
1192
- var palette = paletteFunction(sourceColorHct);
1202
+ _Object$entries$_i$ = _Object$entries$_i[1],
1203
+ sourceColorkey = _Object$entries$_i$.sourceColorkey,
1204
+ paletteFunction = _Object$entries$_i$.tonalPalette;
1205
+ var palette = void 0;
1206
+ if (!sourceColorkey) {
1207
+ palette = paletteFunction(sourceColorHct);
1208
+ } else {
1209
+ var _sourceColorArgb = argbFromHex(this.options.sourcesColorHex[sourceColorkey]);
1210
+ var _sourceColorHct = Hct.fromInt(_sourceColorArgb);
1211
+ palette = paletteFunction(_sourceColorHct);
1212
+ }
1193
1213
  palettes.set(key, palette);
1194
1214
  }
1195
1215
  this.schemeEntity = new SchemeEntity(_extends({}, this.options, {
@@ -1237,13 +1257,23 @@ var ThemeService = /*#__PURE__*/function () {
1237
1257
  // }
1238
1258
  var _proto = ThemeService.prototype;
1239
1259
  _proto.create = function create(options) {
1240
- this.schemeService.createOrUpdate(options);
1241
- };
1242
- _proto.addVariant = function addVariant(variant) {
1243
- this.variantService.set(variant);
1260
+ this.schemeService.createOrUpdate(_extends({}, options, {
1261
+ sourcesColorHex: {
1262
+ primary: options.sourceColorHex
1263
+ }
1264
+ }));
1265
+ this.variantService.set(options.variant);
1244
1266
  };
1245
1267
  _proto.update = function update(options) {
1246
- this.schemeService.createOrUpdate(options);
1268
+ var themeOptions = _extends({}, options);
1269
+ if (options.sourceColorHex) themeOptions.sourcesColorHex = {
1270
+ primary: options.sourceColorHex
1271
+ };
1272
+ this.schemeService.createOrUpdate(themeOptions);
1273
+ if (options.variant) this.variantService.set(options.variant);
1274
+ };
1275
+ _proto.addCustomPalette = function addCustomPalette(key, colorHex) {
1276
+ this.variantService.addCustomPalette(key, colorHex);
1247
1277
  };
1248
1278
  return ThemeService;
1249
1279
  }();
@@ -1251,17 +1281,46 @@ var ThemeService = /*#__PURE__*/function () {
1251
1281
  var VariantService = /*#__PURE__*/function () {
1252
1282
  function VariantService(_ref) {
1253
1283
  var schemeService = _ref.schemeService;
1284
+ this.customPalettes = {};
1285
+ this.variantEntity = void 0;
1254
1286
  this.schemeService = void 0;
1255
1287
  this.schemeService = schemeService;
1256
1288
  }
1257
1289
  var _proto = VariantService.prototype;
1290
+ _proto.addCustomPalette = function addCustomPalette(key, colorHex) {
1291
+ this.customPalettes[key] = colorHex;
1292
+ this.update();
1293
+ };
1258
1294
  _proto.set = function set(variantEntity) {
1295
+ this.variantEntity = variantEntity;
1259
1296
  if (!variantEntity.palettes.error) {
1260
1297
  variantEntity.palettes.error = function () {
1261
1298
  return TonalPalette.fromHueAndChroma(25.0, 84.0);
1262
1299
  };
1263
1300
  }
1264
- this.schemeService.createOrUpdate(variantEntity);
1301
+ this.update();
1302
+ };
1303
+ _proto.update = function update() {
1304
+ var _this = this;
1305
+ if (!this.variantEntity) return;
1306
+ var palettes = {};
1307
+ Object.keys(this.variantEntity.palettes).forEach(function (key) {
1308
+ palettes[key] = {
1309
+ tonalPalette: _this.variantEntity.palettes[key]
1310
+ };
1311
+ });
1312
+ if (this.variantEntity.customPalettes) {
1313
+ Object.keys(this.customPalettes).forEach(function (key) {
1314
+ palettes[key] = {
1315
+ sourceColorkey: key,
1316
+ tonalPalette: _this.variantEntity.customPalettes
1317
+ };
1318
+ });
1319
+ }
1320
+ this.schemeService.createOrUpdate({
1321
+ sourcesColorHex: this.customPalettes,
1322
+ palettes: palettes
1323
+ });
1265
1324
  };
1266
1325
  return VariantService;
1267
1326
  }();
@@ -1274,9 +1333,12 @@ var ThemeModule = {
1274
1333
 
1275
1334
  var AppService = function AppService(_ref) {
1276
1335
  var colorService = _ref.colorService,
1277
- themeService = _ref.themeService;
1336
+ themeService = _ref.themeService,
1337
+ pluginService = _ref.pluginService;
1278
1338
  this.colorService = void 0;
1279
1339
  this.themeService = void 0;
1340
+ this.pluginService = void 0;
1341
+ this.pluginService = pluginService;
1280
1342
  this.colorService = colorService;
1281
1343
  this.themeService = themeService;
1282
1344
  };
@@ -1285,24 +1347,346 @@ var AppModule = {
1285
1347
  appService: /*#__PURE__*/asClass(AppService).singleton()
1286
1348
  };
1287
1349
 
1288
- function importContainer(container, services) {
1289
- services.forEach(function (service) {
1290
- Object.entries(service).forEach(function (_ref) {
1291
- var name = _ref[0],
1292
- serviceClass = _ref[1];
1293
- container.register(name, serviceClass);
1294
- });
1295
- });
1296
- return container;
1297
- }
1298
- var AppContainer = /*#__PURE__*/createContainer({
1299
- injectionMode: InjectionMode.PROXY
1300
- });
1301
- importContainer(AppContainer, [AppModule, ColorModule, ThemeModule]);
1302
-
1303
- function main() {
1304
- return AppContainer.resolve('appService');
1350
+ function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
1351
+ var answer = tone;
1352
+ var closestToChroma = Hct.from(hue, chroma, tone);
1353
+ if (closestToChroma.chroma < chroma) {
1354
+ var chromaPeak = closestToChroma.chroma;
1355
+ while (closestToChroma.chroma < chroma) {
1356
+ answer += byDecreasingTone ? -1.0 : 1.0;
1357
+ var potentialSolution = Hct.from(hue, chroma, answer);
1358
+ if (chromaPeak > potentialSolution.chroma) {
1359
+ break;
1360
+ }
1361
+ if (Math.abs(potentialSolution.chroma - chroma) < 0.4) {
1362
+ break;
1363
+ }
1364
+ var potentialDelta = Math.abs(potentialSolution.chroma - chroma);
1365
+ var currentDelta = Math.abs(closestToChroma.chroma - chroma);
1366
+ if (potentialDelta < currentDelta) {
1367
+ closestToChroma = potentialSolution;
1368
+ }
1369
+ chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
1370
+ }
1371
+ }
1372
+ return answer;
1305
1373
  }
1374
+ var defaultColors = function defaultColors(colorService) {
1375
+ return {
1376
+ fromPalettes: ['primary', 'secondary', 'tertiary'],
1377
+ colors: {
1378
+ background: {
1379
+ palette: function palette(s) {
1380
+ return s.getPalette('neutral');
1381
+ },
1382
+ tone: function tone(s) {
1383
+ return s.isDark ? 6 : 98;
1384
+ },
1385
+ isBackground: true
1386
+ },
1387
+ onBackground: {
1388
+ palette: function palette(s) {
1389
+ return s.getPalette('neutral');
1390
+ },
1391
+ tone: function tone(s) {
1392
+ return s.isDark ? 90 : 10;
1393
+ },
1394
+ background: function background(s) {
1395
+ return colorService.getColor('background').getDynamicColor();
1396
+ },
1397
+ contrastCurve: new ContrastCurve(3, 3, 4.5, 7)
1398
+ },
1399
+ surface: {
1400
+ palette: function palette(s) {
1401
+ return s.getPalette('neutral');
1402
+ },
1403
+ tone: function tone(s) {
1404
+ return s.isDark ? 6 : 98;
1405
+ },
1406
+ isBackground: true
1407
+ },
1408
+ surfaceDim: {
1409
+ palette: function palette(s) {
1410
+ return s.getPalette('neutral');
1411
+ },
1412
+ tone: function tone(s) {
1413
+ return s.isDark ? 6 : 87;
1414
+ },
1415
+ isBackground: true
1416
+ },
1417
+ surfaceBright: {
1418
+ palette: function palette(s) {
1419
+ return s.getPalette('neutral');
1420
+ },
1421
+ tone: function tone(s) {
1422
+ return s.isDark ? 24 : 98;
1423
+ },
1424
+ isBackground: true
1425
+ },
1426
+ surfaceContainerLowest: {
1427
+ palette: function palette(s) {
1428
+ return s.getPalette('neutral');
1429
+ },
1430
+ tone: function tone(s) {
1431
+ return s.isDark ? 4 : 100;
1432
+ },
1433
+ isBackground: true
1434
+ },
1435
+ surfaceContainerLow: {
1436
+ palette: function palette(s) {
1437
+ return s.getPalette('neutral');
1438
+ },
1439
+ tone: function tone(s) {
1440
+ return s.isDark ? 10 : 96;
1441
+ },
1442
+ isBackground: true
1443
+ },
1444
+ surfaceContainer: {
1445
+ palette: function palette(s) {
1446
+ return s.getPalette('neutral');
1447
+ },
1448
+ tone: function tone(s) {
1449
+ return s.isDark ? 12 : 94;
1450
+ },
1451
+ isBackground: true
1452
+ },
1453
+ surfaceContainerHigh: {
1454
+ palette: function palette(s) {
1455
+ return s.getPalette('neutral');
1456
+ },
1457
+ tone: function tone(s) {
1458
+ return s.isDark ? 17 : 92;
1459
+ },
1460
+ isBackground: true
1461
+ },
1462
+ surfaceContainerHighest: {
1463
+ palette: function palette(s) {
1464
+ return s.getPalette('neutral');
1465
+ },
1466
+ tone: function tone(s) {
1467
+ return s.isDark ? 22 : 90;
1468
+ },
1469
+ isBackground: true
1470
+ },
1471
+ onSurface: {
1472
+ palette: function palette(s) {
1473
+ return s.getPalette('neutral');
1474
+ },
1475
+ tone: function tone(s) {
1476
+ return s.isDark ? 90 : 10;
1477
+ },
1478
+ background: function background(s) {
1479
+ return highestSurface(s, colorService);
1480
+ },
1481
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1482
+ },
1483
+ surfaceVariant: {
1484
+ palette: function palette(s) {
1485
+ return s.getPalette('neutralVariant');
1486
+ },
1487
+ tone: function tone(s) {
1488
+ return s.isDark ? 30 : 90;
1489
+ },
1490
+ isBackground: true
1491
+ },
1492
+ onSurfaceVariant: {
1493
+ palette: function palette(s) {
1494
+ return s.getPalette('neutralVariant');
1495
+ },
1496
+ tone: function tone(s) {
1497
+ return s.isDark ? 80 : 30;
1498
+ },
1499
+ background: function background(s) {
1500
+ return highestSurface(s, colorService);
1501
+ },
1502
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1503
+ },
1504
+ inverseSurface: {
1505
+ palette: function palette(s) {
1506
+ return s.getPalette('neutral');
1507
+ },
1508
+ tone: function tone(s) {
1509
+ return s.isDark ? 90 : 20;
1510
+ }
1511
+ },
1512
+ inverseOnSurface: {
1513
+ palette: function palette(s) {
1514
+ return s.getPalette('neutral');
1515
+ },
1516
+ tone: function tone(s) {
1517
+ return s.isDark ? 20 : 95;
1518
+ },
1519
+ background: function background(s) {
1520
+ return colorService.getColor('inverseSurface').getDynamicColor();
1521
+ },
1522
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1523
+ },
1524
+ outline: {
1525
+ palette: function palette(s) {
1526
+ return s.getPalette('neutralVariant');
1527
+ },
1528
+ tone: function tone(s) {
1529
+ return s.isDark ? 60 : 50;
1530
+ },
1531
+ background: function background(s) {
1532
+ return highestSurface(s, colorService);
1533
+ },
1534
+ contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7)
1535
+ },
1536
+ outlineVariant: {
1537
+ palette: function palette(s) {
1538
+ return s.getPalette('neutralVariant');
1539
+ },
1540
+ tone: function tone(s) {
1541
+ return s.isDark ? 30 : 80;
1542
+ },
1543
+ background: function background(s) {
1544
+ return highestSurface(s, colorService);
1545
+ },
1546
+ contrastCurve: new ContrastCurve(1, 1, 3, 7)
1547
+ },
1548
+ shadow: {
1549
+ palette: function palette(s) {
1550
+ return s.getPalette('neutral');
1551
+ },
1552
+ tone: function tone(s) {
1553
+ return 0;
1554
+ }
1555
+ },
1556
+ scrim: {
1557
+ palette: function palette(s) {
1558
+ return s.getPalette('neutral');
1559
+ },
1560
+ tone: function tone(s) {
1561
+ return 0;
1562
+ }
1563
+ },
1564
+ surfaceTint: {
1565
+ palette: function palette(s) {
1566
+ return s.getPalette('neutral');
1567
+ },
1568
+ tone: function tone(s) {
1569
+ return s.isDark ? 80 : 40;
1570
+ },
1571
+ isBackground: true
1572
+ },
1573
+ secondaryContainer: {
1574
+ tone: function tone(s) {
1575
+ var initialTone = s.isDark ? 30 : 90;
1576
+ return findDesiredChromaByTone(s.getPalette('secondary').hue, s.getPalette('secondary').chroma, initialTone, !s.isDark);
1577
+ }
1578
+ },
1579
+ onSecondaryContainer: {
1580
+ tone: function tone(s) {
1581
+ return DynamicColor.foregroundTone(colorService.getColor('secondaryContainer').getDynamicColor().tone(s), 4.5);
1582
+ }
1583
+ },
1584
+ tertiaryContainer: {
1585
+ palette: function palette(s) {
1586
+ return s.getPalette('tertiary');
1587
+ },
1588
+ tone: function tone(s) {
1589
+ var proposedHct = s.getPalette('tertiary').getHct(s.sourceColorHct.tone);
1590
+ return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
1591
+ }
1592
+ },
1593
+ onTertiaryContainer: {
1594
+ palette: function palette(s) {
1595
+ return s.getPalette('tertiary');
1596
+ },
1597
+ tone: function tone(s) {
1598
+ return DynamicColor.foregroundTone(colorService.getColor('tertiaryContainer').getDynamicColor().tone(s), 4.5);
1599
+ }
1600
+ },
1601
+ error: {
1602
+ palette: function palette(s) {
1603
+ return s.getPalette('error');
1604
+ },
1605
+ tone: function tone(s) {
1606
+ return s.isDark ? 80 : 40;
1607
+ },
1608
+ isBackground: true,
1609
+ background: function background(s) {
1610
+ return highestSurface(s, colorService);
1611
+ },
1612
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
1613
+ toneDeltaPair: function toneDeltaPair(s) {
1614
+ return new ToneDeltaPair(colorService.getColor('errorContainer').getDynamicColor(), colorService.getColor('error').getDynamicColor(), 15, 'nearer', false);
1615
+ }
1616
+ },
1617
+ onError: {
1618
+ palette: function palette(s) {
1619
+ return s.getPalette('error');
1620
+ },
1621
+ tone: function tone(s) {
1622
+ return s.isDark ? 20 : 100;
1623
+ },
1624
+ background: function background(s) {
1625
+ return colorService.getColor('error').getDynamicColor();
1626
+ },
1627
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1628
+ },
1629
+ errorContainer: {
1630
+ palette: function palette(s) {
1631
+ return s.getPalette('error');
1632
+ },
1633
+ tone: function tone(s) {
1634
+ return s.isDark ? 30 : 90;
1635
+ },
1636
+ isBackground: true,
1637
+ background: function background(s) {
1638
+ return highestSurface(s, colorService);
1639
+ },
1640
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
1641
+ toneDeltaPair: function toneDeltaPair(s) {
1642
+ return new ToneDeltaPair(colorService.getColor('errorContainer').getDynamicColor(), colorService.getColor('error').getDynamicColor(), 15, 'nearer', false);
1643
+ }
1644
+ },
1645
+ onErrorContainer: {
1646
+ palette: function palette(s) {
1647
+ return s.getPalette('error');
1648
+ },
1649
+ tone: function tone(s) {
1650
+ return s.isDark ? 90 : 10;
1651
+ },
1652
+ background: function background(s) {
1653
+ return colorService.getColor('errorContainer').getDynamicColor();
1654
+ },
1655
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1656
+ },
1657
+ onTertiaryFixed: {
1658
+ palette: function palette(s) {
1659
+ return s.getPalette('tertiary');
1660
+ },
1661
+ tone: function tone(s) {
1662
+ return 10.0;
1663
+ },
1664
+ background: function background(s) {
1665
+ return colorService.getColor('tertiaryFixedDim').getDynamicColor();
1666
+ },
1667
+ secondBackground: function secondBackground(s) {
1668
+ return colorService.getColor('tertiaryFixed').getDynamicColor();
1669
+ },
1670
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1671
+ },
1672
+ onTertiaryFixedVariant: {
1673
+ palette: function palette(s) {
1674
+ return s.getPalette('tertiary');
1675
+ },
1676
+ tone: function tone(s) {
1677
+ return 30.0;
1678
+ },
1679
+ background: function background(s) {
1680
+ return colorService.getColor('tertiaryFixedDim').getDynamicColor();
1681
+ },
1682
+ secondBackground: function secondBackground(s) {
1683
+ return colorService.getColor('tertiaryFixed').getDynamicColor();
1684
+ },
1685
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1686
+ }
1687
+ }
1688
+ };
1689
+ };
1306
1690
 
1307
1691
  var getRotatedHue = function getRotatedHue(sourceColor, hues, rotations) {
1308
1692
  var sourceHue = sourceColor.hue;
@@ -1324,12 +1708,14 @@ var getRotatedHue = function getRotatedHue(sourceColor, hues, rotations) {
1324
1708
  // rotation found using the arrays.
1325
1709
  return sourceHue;
1326
1710
  };
1327
- var VariantEntity = function VariantEntity(palettes) {
1711
+ var VariantEntity = function VariantEntity(palettes, customPalettes) {
1328
1712
  if (palettes === void 0) {
1329
1713
  palettes = {};
1330
1714
  }
1331
1715
  this.palettes = void 0;
1716
+ this.customPalettes = void 0;
1332
1717
  this.palettes = palettes;
1718
+ this.customPalettes = customPalettes;
1333
1719
  };
1334
1720
 
1335
1721
  var _VariantModel;
@@ -1352,6 +1738,9 @@ VariantModel.tonalSpot = {
1352
1738
  neutralVariant: function neutralVariant(sourceColorHct) {
1353
1739
  return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0);
1354
1740
  }
1741
+ },
1742
+ customPalettes: function customPalettes(colorHct) {
1743
+ return TonalPalette.fromHueAndChroma(colorHct.hue, 16);
1355
1744
  }
1356
1745
  };
1357
1746
  VariantModel.vibrant = {
@@ -1371,11 +1760,188 @@ VariantModel.vibrant = {
1371
1760
  neutralVariant: function neutralVariant(sourceColorHct) {
1372
1761
  return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0);
1373
1762
  }
1763
+ },
1764
+ customPalettes: function customPalettes(colorHct) {
1765
+ return TonalPalette.fromHueAndChroma(getRotatedHue(colorHct, _VariantModel.hues, _VariantModel.secondaryRotations), 24.0);
1374
1766
  }
1375
1767
  };
1376
1768
  VariantModel.hues = [0.0, 41.0, 61.0, 101.0, 131.0, 181.0, 251.0, 301.0, 360.0];
1377
1769
  VariantModel.secondaryRotations = [18.0, 15.0, 10.0, 12.0, 15.0, 18.0, 15.0, 12.0, 12.0];
1378
1770
  VariantModel.tertiaryRotations = [35.0, 30.0, 20.0, 25.0, 30.0, 35.0, 30.0, 25.0, 25.0];
1379
1771
 
1380
- export { AppService, ColorEntity, ColorManagerService, ColorModule, ColorService, ContrastCurve, DynamicColor, SchemeEntity, SchemeService, ThemeModule, ThemeService, ToneDeltaPair, VariantEntity, VariantModel, VariantService, defaultColors, getRotatedHue, highestSurface, importContainer, main };
1772
+ function defineConfig(configObject) {
1773
+ if (!configObject || typeof configObject !== 'object') {
1774
+ throw new Error('The configuration is missing or not an object');
1775
+ }
1776
+ if (!('sourceColor' in configObject)) {
1777
+ throw new Error('Invalid configuration');
1778
+ }
1779
+ return configObject;
1780
+ }
1781
+ var ConfigService = /*#__PURE__*/function () {
1782
+ function ConfigService(_ref) {
1783
+ var appService = _ref.appService;
1784
+ this.configPath = './theme.config.ts';
1785
+ this.appService = void 0;
1786
+ this.appService = appService;
1787
+ }
1788
+ var _proto = ConfigService.prototype;
1789
+ _proto.loadConfig = /*#__PURE__*/function () {
1790
+ var _loadConfig = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1791
+ var _this$appService, themeService, colorService, pluginService, _yield$this$getConfig, sourceColor, _yield$this$getConfig2, contrastLevel, _yield$this$getConfig3, isDark, _yield$this$getConfig4, variant, palettes, colors, _yield$this$getConfig5, useDefaultColors, plugins;
1792
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1793
+ while (1) switch (_context.prev = _context.next) {
1794
+ case 0:
1795
+ _this$appService = this.appService, themeService = _this$appService.themeService, colorService = _this$appService.colorService, pluginService = _this$appService.pluginService;
1796
+ _context.next = 3;
1797
+ return this.getConfig();
1798
+ case 3:
1799
+ _yield$this$getConfig = _context.sent;
1800
+ sourceColor = _yield$this$getConfig.sourceColor;
1801
+ _yield$this$getConfig2 = _yield$this$getConfig.contrastLevel;
1802
+ contrastLevel = _yield$this$getConfig2 === void 0 ? 0 : _yield$this$getConfig2;
1803
+ _yield$this$getConfig3 = _yield$this$getConfig.isDark;
1804
+ isDark = _yield$this$getConfig3 === void 0 ? false : _yield$this$getConfig3;
1805
+ _yield$this$getConfig4 = _yield$this$getConfig.variant;
1806
+ variant = _yield$this$getConfig4 === void 0 ? VariantModel.tonalSpot : _yield$this$getConfig4;
1807
+ palettes = _yield$this$getConfig.palettes;
1808
+ colors = _yield$this$getConfig.colors;
1809
+ _yield$this$getConfig5 = _yield$this$getConfig.useDefaultColors;
1810
+ useDefaultColors = _yield$this$getConfig5 === void 0 ? true : _yield$this$getConfig5;
1811
+ plugins = _yield$this$getConfig.plugins;
1812
+ themeService.create({
1813
+ contrastLevel: contrastLevel,
1814
+ isDark: isDark,
1815
+ sourceColorHex: sourceColor,
1816
+ variant: variant
1817
+ });
1818
+ if (palettes) {
1819
+ Object.entries(palettes).forEach(function (_ref2) {
1820
+ var key = _ref2[0],
1821
+ value = _ref2[1];
1822
+ return themeService.addCustomPalette(key, value);
1823
+ });
1824
+ }
1825
+ if (useDefaultColors) {
1826
+ colorService.addColors(defaultColors);
1827
+ }
1828
+ if (colors) {
1829
+ colorService.addColors(colors);
1830
+ }
1831
+ if (plugins) {
1832
+ plugins.forEach(function (plugin) {
1833
+ return pluginService.addPlugin(plugin);
1834
+ });
1835
+ pluginService.loadPlugins(this.appService);
1836
+ }
1837
+ case 21:
1838
+ case "end":
1839
+ return _context.stop();
1840
+ }
1841
+ }, _callee, this);
1842
+ }));
1843
+ function loadConfig() {
1844
+ return _loadConfig.apply(this, arguments);
1845
+ }
1846
+ return loadConfig;
1847
+ }();
1848
+ _proto.getConfig = /*#__PURE__*/function () {
1849
+ var _getConfig = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1850
+ var path, configImport, config;
1851
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1852
+ while (1) switch (_context2.prev = _context2.next) {
1853
+ case 0:
1854
+ path = resolve(this.configPath);
1855
+ _context2.next = 3;
1856
+ return import(path);
1857
+ case 3:
1858
+ configImport = _context2.sent;
1859
+ config = configImport["default"];
1860
+ return _context2.abrupt("return", config);
1861
+ case 6:
1862
+ case "end":
1863
+ return _context2.stop();
1864
+ }
1865
+ }, _callee2, this);
1866
+ }));
1867
+ function getConfig() {
1868
+ return _getConfig.apply(this, arguments);
1869
+ }
1870
+ return getConfig;
1871
+ }();
1872
+ return ConfigService;
1873
+ }();
1874
+
1875
+ var ConfigModule = {
1876
+ configService: /*#__PURE__*/asClass(ConfigService).singleton()
1877
+ };
1878
+
1879
+ var PluginService = /*#__PURE__*/function () {
1880
+ function PluginService() {
1881
+ this.pluginInstances = new Map();
1882
+ this.pluginConstructors = new Map();
1883
+ }
1884
+ var _proto = PluginService.prototype;
1885
+ _proto.addPlugin = function addPlugin(plugin) {
1886
+ this.pluginConstructors.set(plugin.name, plugin);
1887
+ };
1888
+ _proto.loadPlugins = function loadPlugins(appService) {
1889
+ var _this = this;
1890
+ this.pluginConstructors.forEach(function (plugin) {
1891
+ _this.pluginInstances.set(plugin.name, new plugin(appService));
1892
+ });
1893
+ };
1894
+ _proto.getPlugin = function getPlugin(plugin) {
1895
+ return this.pluginInstances.get(plugin.name);
1896
+ };
1897
+ return PluginService;
1898
+ }();
1899
+
1900
+ var PluginModule = {
1901
+ pluginService: /*#__PURE__*/asClass(PluginService).singleton()
1902
+ };
1903
+
1904
+ function importContainer(container, services) {
1905
+ services.forEach(function (service) {
1906
+ Object.entries(service).forEach(function (_ref) {
1907
+ var name = _ref[0],
1908
+ serviceClass = _ref[1];
1909
+ container.register(name, serviceClass);
1910
+ });
1911
+ });
1912
+ return container;
1913
+ }
1914
+ var AppContainer = /*#__PURE__*/createContainer({
1915
+ injectionMode: InjectionMode.PROXY
1916
+ });
1917
+ importContainer(AppContainer, [ConfigModule, AppModule, PluginModule, ColorModule, ThemeModule]);
1918
+
1919
+ function bootstrap() {
1920
+ return AppContainer.resolve('appService');
1921
+ }
1922
+ function bootstrapFromConfig(_x) {
1923
+ return _bootstrapFromConfig.apply(this, arguments);
1924
+ }
1925
+ function _bootstrapFromConfig() {
1926
+ _bootstrapFromConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(path) {
1927
+ var configService;
1928
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1929
+ while (1) switch (_context.prev = _context.next) {
1930
+ case 0:
1931
+ configService = AppContainer.resolve('configService');
1932
+ if (path) configService.configPath = path;
1933
+ _context.next = 4;
1934
+ return configService.loadConfig();
1935
+ case 4:
1936
+ return _context.abrupt("return", AppContainer.resolve('appService'));
1937
+ case 5:
1938
+ case "end":
1939
+ return _context.stop();
1940
+ }
1941
+ }, _callee);
1942
+ }));
1943
+ return _bootstrapFromConfig.apply(this, arguments);
1944
+ }
1945
+
1946
+ export { AppContainer, AppModule, AppService, ColorEntity, ColorManagerService, ColorModule, ColorService, ConfigService, ContrastCurve, DynamicColor, SchemeEntity, SchemeService, ThemeModule, ThemeService, ToneDeltaPair, VariantEntity, VariantModel, VariantService, bootstrap, bootstrapFromConfig, defaultColors, defineConfig, getRotatedHue, highestSurface, importContainer };
1381
1947
  //# sourceMappingURL=theme.esm.js.map