@udixio/theme 1.0.0-beta.8 → 1.0.0

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 (199) hide show
  1. package/.eslintrc.mjs +22 -0
  2. package/CHANGELOG.md +174 -0
  3. package/README.md +6 -68
  4. package/dist/API.d.ts +14 -0
  5. package/dist/API.d.ts.map +1 -0
  6. package/dist/LICENSE +202 -0
  7. package/dist/adapter/adapter.abstract.d.ts +10 -0
  8. package/dist/adapter/adapter.abstract.d.ts.map +1 -0
  9. package/dist/adapter/config.interface.d.ts +14 -0
  10. package/dist/adapter/config.interface.d.ts.map +1 -0
  11. package/dist/adapter/define-config.d.ts +3 -0
  12. package/dist/adapter/define-config.d.ts.map +1 -0
  13. package/dist/adapter/file-adapter.mixin.d.ts +18 -0
  14. package/dist/adapter/file-adapter.mixin.d.ts.map +1 -0
  15. package/dist/adapter/index.d.ts +4 -0
  16. package/dist/adapter/index.d.ts.map +1 -0
  17. package/dist/adapters/index.d.ts +3 -0
  18. package/dist/adapters/index.d.ts.map +1 -0
  19. package/dist/adapters/node.adapter.d.ts +7 -0
  20. package/dist/adapters/node.adapter.d.ts.map +1 -0
  21. package/dist/adapters/vite.adapter.d.ts +3 -0
  22. package/dist/adapters/vite.adapter.d.ts.map +1 -0
  23. package/dist/app.container.d.ts +5 -5
  24. package/dist/app.container.d.ts.map +1 -0
  25. package/dist/app.module.d.ts +1 -0
  26. package/dist/app.module.d.ts.map +1 -0
  27. package/dist/bootstrap.d.ts +3 -0
  28. package/dist/bootstrap.d.ts.map +1 -0
  29. package/dist/color/color.api.d.ts +39 -0
  30. package/dist/color/color.api.d.ts.map +1 -0
  31. package/dist/color/color.manager.d.ts +24 -0
  32. package/dist/color/color.manager.d.ts.map +1 -0
  33. package/dist/color/color.module.d.ts +1 -0
  34. package/dist/color/color.module.d.ts.map +1 -0
  35. package/dist/color/color.utils.d.ts +8 -0
  36. package/dist/color/color.utils.d.ts.map +1 -0
  37. package/dist/color/configurable-color.d.ts +31 -0
  38. package/dist/color/configurable-color.d.ts.map +1 -0
  39. package/dist/color/default-color.d.ts +3 -0
  40. package/dist/color/default-color.d.ts.map +1 -0
  41. package/dist/color/index.d.ts +5 -4
  42. package/dist/color/index.d.ts.map +1 -0
  43. package/dist/index.cjs +3215 -0
  44. package/dist/index.d.ts +7 -4
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +3175 -7
  47. package/dist/material-color-utilities/contrastCurve.d.ts +1 -0
  48. package/dist/material-color-utilities/contrastCurve.d.ts.map +1 -0
  49. package/dist/material-color-utilities/dynamic_color.d.ts +89 -76
  50. package/dist/material-color-utilities/dynamic_color.d.ts.map +1 -0
  51. package/dist/material-color-utilities/hct_solver.d.ts +131 -0
  52. package/dist/material-color-utilities/hct_solver.d.ts.map +1 -0
  53. package/dist/material-color-utilities/htc.d.ts +77 -0
  54. package/dist/material-color-utilities/htc.d.ts.map +1 -0
  55. package/dist/material-color-utilities/index.d.ts +1 -0
  56. package/dist/material-color-utilities/index.d.ts.map +1 -0
  57. package/dist/material-color-utilities/toneDeltaPair.d.ts +19 -25
  58. package/dist/material-color-utilities/toneDeltaPair.d.ts.map +1 -0
  59. package/dist/plugin/index.d.ts +4 -0
  60. package/dist/plugin/index.d.ts.map +1 -0
  61. package/dist/plugin/plugin.abstract.d.ts +19 -5
  62. package/dist/plugin/plugin.abstract.d.ts.map +1 -0
  63. package/dist/plugin/plugin.api.d.ts +10 -0
  64. package/dist/plugin/plugin.api.d.ts.map +1 -0
  65. package/dist/plugin/plugin.module.d.ts +1 -0
  66. package/dist/plugin/plugin.module.d.ts.map +1 -0
  67. package/dist/plugins/font/font.plugin.d.ts +50 -0
  68. package/dist/plugins/font/font.plugin.d.ts.map +1 -0
  69. package/dist/plugins/font/index.d.ts +2 -0
  70. package/dist/plugins/font/index.d.ts.map +1 -0
  71. package/dist/plugins/index.d.ts +2 -0
  72. package/dist/plugins/index.d.ts.map +1 -0
  73. package/dist/theme/index.d.ts +7 -3
  74. package/dist/theme/index.d.ts.map +1 -0
  75. package/dist/theme/scheme.d.ts +20 -0
  76. package/dist/theme/scheme.d.ts.map +1 -0
  77. package/dist/theme/scheme.manager.d.ts +31 -0
  78. package/dist/theme/scheme.manager.d.ts.map +1 -0
  79. package/dist/theme/theme.api.d.ts +23 -0
  80. package/dist/theme/theme.api.d.ts.map +1 -0
  81. package/dist/theme/theme.module.d.ts +1 -0
  82. package/dist/theme/theme.module.d.ts.map +1 -0
  83. package/dist/theme/variant.d.ts +36 -0
  84. package/dist/theme/variant.d.ts.map +1 -0
  85. package/dist/theme/variant.manager.d.ts +14 -0
  86. package/dist/theme/variant.manager.d.ts.map +1 -0
  87. package/dist/theme/variants/expressive.variant.d.ts +3 -0
  88. package/dist/theme/variants/expressive.variant.d.ts.map +1 -0
  89. package/dist/theme/variants/index.d.ts +11 -0
  90. package/dist/theme/variants/index.d.ts.map +1 -0
  91. package/dist/theme/variants/neutral.variant.d.ts +3 -0
  92. package/dist/theme/variants/neutral.variant.d.ts.map +1 -0
  93. package/dist/theme/variants/tonal-spot.variant.d.ts +3 -0
  94. package/dist/theme/variants/tonal-spot.variant.d.ts.map +1 -0
  95. package/dist/theme/variants/vibrant.variant.d.ts +3 -0
  96. package/dist/theme/variants/vibrant.variant.d.ts.map +1 -0
  97. package/package.json +24 -86
  98. package/src/API.ts +23 -0
  99. package/src/adapter/adapter.abstract.ts +64 -0
  100. package/src/adapter/config.interface.ts +14 -0
  101. package/src/adapter/define-config.ts +11 -0
  102. package/src/adapter/file-adapter.mixin.ts +72 -0
  103. package/src/adapter/index.ts +3 -0
  104. package/src/adapters/index.ts +2 -0
  105. package/src/adapters/node.adapter.ts +49 -0
  106. package/src/adapters/vite.adapter.ts +79 -0
  107. package/src/app.container.ts +12 -36
  108. package/src/app.module.ts +2 -2
  109. package/src/bootstrap.ts +6 -0
  110. package/src/color/color.api.ts +75 -0
  111. package/src/color/color.manager.ts +213 -0
  112. package/src/color/color.module.ts +4 -4
  113. package/src/color/color.utils.ts +126 -0
  114. package/src/color/configurable-color.ts +67 -0
  115. package/src/color/default-color.ts +832 -0
  116. package/src/color/index.ts +4 -4
  117. package/src/index.test.ts +5 -0
  118. package/src/index.ts +6 -4
  119. package/src/material-color-utilities/dynamic_color.ts +286 -222
  120. package/src/material-color-utilities/hct_solver.ts +536 -0
  121. package/src/material-color-utilities/htc.ts +198 -0
  122. package/src/material-color-utilities/toneDeltaPair.ts +29 -11
  123. package/src/plugin/index.ts +3 -0
  124. package/src/plugin/plugin.abstract.ts +45 -4
  125. package/src/plugin/plugin.api.ts +51 -0
  126. package/src/plugin/plugin.module.ts +2 -2
  127. package/src/plugins/font/font.plugin.ts +203 -0
  128. package/src/plugins/font/index.ts +1 -0
  129. package/src/plugins/index.ts +1 -0
  130. package/src/theme/index.ts +6 -3
  131. package/src/theme/{services/scheme.service.ts → scheme.manager.ts} +39 -19
  132. package/src/theme/{entities/scheme.entity.ts → scheme.ts} +20 -4
  133. package/src/theme/{services/theme.service.ts → theme.api.ts} +23 -19
  134. package/src/theme/theme.module.ts +6 -4
  135. package/src/theme/variant.manager.ts +58 -0
  136. package/src/theme/variant.ts +53 -0
  137. package/src/theme/variants/expressive.variant.ts +81 -0
  138. package/src/theme/variants/index.ts +16 -0
  139. package/src/theme/variants/neutral.variant.ts +45 -0
  140. package/src/theme/variants/tonal-spot.variant.ts +35 -0
  141. package/src/theme/variants/vibrant.variant.ts +72 -0
  142. package/tsconfig.json +13 -0
  143. package/tsconfig.lib.json +33 -0
  144. package/tsconfig.spec.json +36 -0
  145. package/vite.config.ts +54 -0
  146. package/LICENSE +0 -21
  147. package/dist/app.service.d.ts +0 -13
  148. package/dist/color/color.interface.d.ts +0 -8
  149. package/dist/color/entities/color.entity.d.ts +0 -42
  150. package/dist/color/entities/index.d.ts +0 -1
  151. package/dist/color/models/default-color.model.d.ts +0 -3
  152. package/dist/color/models/index.d.ts +0 -1
  153. package/dist/color/services/color-manager.service.d.ts +0 -18
  154. package/dist/color/services/color.service.d.ts +0 -21
  155. package/dist/color/services/index.d.ts +0 -2
  156. package/dist/config/config.interface.d.ts +0 -14
  157. package/dist/config/config.module.d.ts +0 -2
  158. package/dist/config/config.service.d.ts +0 -12
  159. package/dist/config/index.d.ts +0 -2
  160. package/dist/main.d.ts +0 -3
  161. package/dist/plugin/plugin.service.d.ts +0 -9
  162. package/dist/theme/entities/index.d.ts +0 -2
  163. package/dist/theme/entities/scheme.entity.d.ts +0 -15
  164. package/dist/theme/entities/variant.entity.d.ts +0 -7
  165. package/dist/theme/models/index.d.ts +0 -1
  166. package/dist/theme/models/variant.model.d.ts +0 -8
  167. package/dist/theme/services/index.d.ts +0 -3
  168. package/dist/theme/services/scheme.service.d.ts +0 -17
  169. package/dist/theme/services/theme.service.d.ts +0 -22
  170. package/dist/theme/services/variant.service.d.ts +0 -13
  171. package/dist/theme.cjs.development.js +0 -1975
  172. package/dist/theme.cjs.development.js.map +0 -1
  173. package/dist/theme.cjs.production.min.js +0 -2
  174. package/dist/theme.cjs.production.min.js.map +0 -1
  175. package/dist/theme.esm.js +0 -1947
  176. package/dist/theme.esm.js.map +0 -1
  177. package/src/app.service.spec.ts +0 -15
  178. package/src/app.service.ts +0 -23
  179. package/src/color/color.interface.ts +0 -13
  180. package/src/color/entities/color.entity.ts +0 -71
  181. package/src/color/entities/index.ts +0 -1
  182. package/src/color/models/default-color.model.ts +0 -300
  183. package/src/color/models/index.ts +0 -1
  184. package/src/color/services/color-manager.service.ts +0 -191
  185. package/src/color/services/color.service.spec.ts +0 -28
  186. package/src/color/services/color.service.ts +0 -75
  187. package/src/color/services/index.ts +0 -2
  188. package/src/config/config.interface.ts +0 -15
  189. package/src/config/config.module.ts +0 -7
  190. package/src/config/config.service.ts +0 -68
  191. package/src/config/index.ts +0 -2
  192. package/src/main.ts +0 -14
  193. package/src/plugin/plugin.service.ts +0 -26
  194. package/src/theme/entities/index.ts +0 -2
  195. package/src/theme/entities/variant.entity.ts +0 -39
  196. package/src/theme/models/index.ts +0 -1
  197. package/src/theme/models/variant.model.ts +0 -63
  198. package/src/theme/services/index.ts +0 -3
  199. package/src/theme/services/variant.service.ts +0 -52
@@ -1,1975 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var awilix = require('awilix');
6
- var materialColorUtilities = require('@material/material-color-utilities');
7
- var path = require('path');
8
-
9
- var ColorService = /*#__PURE__*/function () {
10
- function ColorService(_ref) {
11
- var colorManagerService = _ref.colorManagerService;
12
- this.colorManagerService = void 0;
13
- this.colorManagerService = colorManagerService;
14
- }
15
- var _proto = ColorService.prototype;
16
- _proto.getColors = function getColors() {
17
- return this.colorManagerService.getAll();
18
- }
19
- // getColors() {
20
- // const colors: Record<string, string> = {};
21
- //
22
- // for (const [key, value] of this.colorManagerService.getAll()) {
23
- // colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
24
- // }
25
- //
26
- // return colors;
27
- // }
28
- ;
29
- _proto.addColor = function addColor(key, color) {
30
- return this.colorManagerService.createOrUpdate(key, color);
31
- };
32
- _proto.addColors = function addColors(args) {
33
- var _this = this;
34
- if (!Array.isArray(args)) args = [args];
35
- args.forEach(function (args) {
36
- if (typeof args === 'function') {
37
- args = args(_this);
38
- }
39
- if (args.fromPalettes) {
40
- if (!Array.isArray(args.fromPalettes)) args.fromPalettes = [args.fromPalettes];
41
- args.fromPalettes.map(function (paletteKey) {
42
- _this.colorManagerService.addFromPalette(paletteKey);
43
- });
44
- }
45
- if (args.colors) {
46
- Object.keys(args.colors).map(function (key) {
47
- return _this.addColor(key, args.colors[key]);
48
- });
49
- }
50
- });
51
- };
52
- _proto.getColor = function getColor(key) {
53
- return this.colorManagerService.get(key);
54
- };
55
- _proto.removeColor = function removeColor(key) {
56
- return this.colorManagerService.remove(key);
57
- };
58
- _proto.updateColor = function updateColor(key, newColor) {
59
- return this.colorManagerService.createOrUpdate(key, newColor);
60
- };
61
- return ColorService;
62
- }();
63
-
64
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
65
- try {
66
- var i = n[a](c),
67
- u = i.value;
68
- } catch (n) {
69
- return void e(n);
70
- }
71
- i.done ? t(u) : Promise.resolve(u).then(r, o);
72
- }
73
- function _asyncToGenerator(n) {
74
- return function () {
75
- var t = this,
76
- e = arguments;
77
- return new Promise(function (r, o) {
78
- var a = n.apply(t, e);
79
- function _next(n) {
80
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
81
- }
82
- function _throw(n) {
83
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
84
- }
85
- _next(void 0);
86
- });
87
- };
88
- }
89
- function _defineProperties(e, r) {
90
- for (var t = 0; t < r.length; t++) {
91
- var o = r[t];
92
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
93
- }
94
- }
95
- function _createClass(e, r, t) {
96
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
97
- writable: !1
98
- }), e;
99
- }
100
- function _extends() {
101
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
102
- for (var e = 1; e < arguments.length; e++) {
103
- var t = arguments[e];
104
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
105
- }
106
- return n;
107
- }, _extends.apply(null, arguments);
108
- }
109
- function _regeneratorRuntime() {
110
- _regeneratorRuntime = function () {
111
- return e;
112
- };
113
- var t,
114
- e = {},
115
- r = Object.prototype,
116
- n = r.hasOwnProperty,
117
- o = Object.defineProperty || function (t, e, r) {
118
- t[e] = r.value;
119
- },
120
- i = "function" == typeof Symbol ? Symbol : {},
121
- a = i.iterator || "@@iterator",
122
- c = i.asyncIterator || "@@asyncIterator",
123
- u = i.toStringTag || "@@toStringTag";
124
- function define(t, e, r) {
125
- return Object.defineProperty(t, e, {
126
- value: r,
127
- enumerable: !0,
128
- configurable: !0,
129
- writable: !0
130
- }), t[e];
131
- }
132
- try {
133
- define({}, "");
134
- } catch (t) {
135
- define = function (t, e, r) {
136
- return t[e] = r;
137
- };
138
- }
139
- function wrap(t, e, r, n) {
140
- var i = e && e.prototype instanceof Generator ? e : Generator,
141
- a = Object.create(i.prototype),
142
- c = new Context(n || []);
143
- return o(a, "_invoke", {
144
- value: makeInvokeMethod(t, r, c)
145
- }), a;
146
- }
147
- function tryCatch(t, e, r) {
148
- try {
149
- return {
150
- type: "normal",
151
- arg: t.call(e, r)
152
- };
153
- } catch (t) {
154
- return {
155
- type: "throw",
156
- arg: t
157
- };
158
- }
159
- }
160
- e.wrap = wrap;
161
- var h = "suspendedStart",
162
- l = "suspendedYield",
163
- f = "executing",
164
- s = "completed",
165
- y = {};
166
- function Generator() {}
167
- function GeneratorFunction() {}
168
- function GeneratorFunctionPrototype() {}
169
- var p = {};
170
- define(p, a, function () {
171
- return this;
172
- });
173
- var d = Object.getPrototypeOf,
174
- v = d && d(d(values([])));
175
- v && v !== r && n.call(v, a) && (p = v);
176
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
177
- function defineIteratorMethods(t) {
178
- ["next", "throw", "return"].forEach(function (e) {
179
- define(t, e, function (t) {
180
- return this._invoke(e, t);
181
- });
182
- });
183
- }
184
- function AsyncIterator(t, e) {
185
- function invoke(r, o, i, a) {
186
- var c = tryCatch(t[r], t, o);
187
- if ("throw" !== c.type) {
188
- var u = c.arg,
189
- h = u.value;
190
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
191
- invoke("next", t, i, a);
192
- }, function (t) {
193
- invoke("throw", t, i, a);
194
- }) : e.resolve(h).then(function (t) {
195
- u.value = t, i(u);
196
- }, function (t) {
197
- return invoke("throw", t, i, a);
198
- });
199
- }
200
- a(c.arg);
201
- }
202
- var r;
203
- o(this, "_invoke", {
204
- value: function (t, n) {
205
- function callInvokeWithMethodAndArg() {
206
- return new e(function (e, r) {
207
- invoke(t, n, e, r);
208
- });
209
- }
210
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
211
- }
212
- });
213
- }
214
- function makeInvokeMethod(e, r, n) {
215
- var o = h;
216
- return function (i, a) {
217
- if (o === f) throw Error("Generator is already running");
218
- if (o === s) {
219
- if ("throw" === i) throw a;
220
- return {
221
- value: t,
222
- done: !0
223
- };
224
- }
225
- for (n.method = i, n.arg = a;;) {
226
- var c = n.delegate;
227
- if (c) {
228
- var u = maybeInvokeDelegate(c, n);
229
- if (u) {
230
- if (u === y) continue;
231
- return u;
232
- }
233
- }
234
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
235
- if (o === h) throw o = s, n.arg;
236
- n.dispatchException(n.arg);
237
- } else "return" === n.method && n.abrupt("return", n.arg);
238
- o = f;
239
- var p = tryCatch(e, r, n);
240
- if ("normal" === p.type) {
241
- if (o = n.done ? s : l, p.arg === y) continue;
242
- return {
243
- value: p.arg,
244
- done: n.done
245
- };
246
- }
247
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
248
- }
249
- };
250
- }
251
- function maybeInvokeDelegate(e, r) {
252
- var n = r.method,
253
- o = e.iterator[n];
254
- 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;
255
- var i = tryCatch(o, e.iterator, r.arg);
256
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
257
- var a = i.arg;
258
- 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);
259
- }
260
- function pushTryEntry(t) {
261
- var e = {
262
- tryLoc: t[0]
263
- };
264
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
265
- }
266
- function resetTryEntry(t) {
267
- var e = t.completion || {};
268
- e.type = "normal", delete e.arg, t.completion = e;
269
- }
270
- function Context(t) {
271
- this.tryEntries = [{
272
- tryLoc: "root"
273
- }], t.forEach(pushTryEntry, this), this.reset(!0);
274
- }
275
- function values(e) {
276
- if (e || "" === e) {
277
- var r = e[a];
278
- if (r) return r.call(e);
279
- if ("function" == typeof e.next) return e;
280
- if (!isNaN(e.length)) {
281
- var o = -1,
282
- i = function next() {
283
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
284
- return next.value = t, next.done = !0, next;
285
- };
286
- return i.next = i;
287
- }
288
- }
289
- throw new TypeError(typeof e + " is not iterable");
290
- }
291
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
292
- value: GeneratorFunctionPrototype,
293
- configurable: !0
294
- }), o(GeneratorFunctionPrototype, "constructor", {
295
- value: GeneratorFunction,
296
- configurable: !0
297
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
298
- var e = "function" == typeof t && t.constructor;
299
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
300
- }, e.mark = function (t) {
301
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
302
- }, e.awrap = function (t) {
303
- return {
304
- __await: t
305
- };
306
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
307
- return this;
308
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
309
- void 0 === i && (i = Promise);
310
- var a = new AsyncIterator(wrap(t, r, n, o), i);
311
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
312
- return t.done ? t.value : a.next();
313
- });
314
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
315
- return this;
316
- }), define(g, "toString", function () {
317
- return "[object Generator]";
318
- }), e.keys = function (t) {
319
- var e = Object(t),
320
- r = [];
321
- for (var n in e) r.push(n);
322
- return r.reverse(), function next() {
323
- for (; r.length;) {
324
- var t = r.pop();
325
- if (t in e) return next.value = t, next.done = !1, next;
326
- }
327
- return next.done = !0, next;
328
- };
329
- }, e.values = values, Context.prototype = {
330
- constructor: Context,
331
- reset: function (e) {
332
- 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);
333
- },
334
- stop: function () {
335
- this.done = !0;
336
- var t = this.tryEntries[0].completion;
337
- if ("throw" === t.type) throw t.arg;
338
- return this.rval;
339
- },
340
- dispatchException: function (e) {
341
- if (this.done) throw e;
342
- var r = this;
343
- function handle(n, o) {
344
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
345
- }
346
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
347
- var i = this.tryEntries[o],
348
- a = i.completion;
349
- if ("root" === i.tryLoc) return handle("end");
350
- if (i.tryLoc <= this.prev) {
351
- var c = n.call(i, "catchLoc"),
352
- u = n.call(i, "finallyLoc");
353
- if (c && u) {
354
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
355
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
356
- } else if (c) {
357
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
358
- } else {
359
- if (!u) throw Error("try statement without catch or finally");
360
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
361
- }
362
- }
363
- }
364
- },
365
- abrupt: function (t, e) {
366
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
367
- var o = this.tryEntries[r];
368
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
369
- var i = o;
370
- break;
371
- }
372
- }
373
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
374
- var a = i ? i.completion : {};
375
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
376
- },
377
- complete: function (t, e) {
378
- if ("throw" === t.type) throw t.arg;
379
- 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;
380
- },
381
- finish: function (t) {
382
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
383
- var r = this.tryEntries[e];
384
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
385
- }
386
- },
387
- catch: function (t) {
388
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
389
- var r = this.tryEntries[e];
390
- if (r.tryLoc === t) {
391
- var n = r.completion;
392
- if ("throw" === n.type) {
393
- var o = n.arg;
394
- resetTryEntry(r);
395
- }
396
- return o;
397
- }
398
- }
399
- throw Error("illegal catch attempt");
400
- },
401
- delegateYield: function (e, r, n) {
402
- return this.delegate = {
403
- iterator: values(e),
404
- resultName: r,
405
- nextLoc: n
406
- }, "next" === this.method && (this.arg = t), y;
407
- }
408
- }, e;
409
- }
410
- function _toPrimitive(t, r) {
411
- if ("object" != typeof t || !t) return t;
412
- var e = t[Symbol.toPrimitive];
413
- if (void 0 !== e) {
414
- var i = e.call(t, r || "default");
415
- if ("object" != typeof i) return i;
416
- throw new TypeError("@@toPrimitive must return a primitive value.");
417
- }
418
- return ("string" === r ? String : Number)(t);
419
- }
420
- function _toPropertyKey(t) {
421
- var i = _toPrimitive(t, "string");
422
- return "symbol" == typeof i ? i : i + "";
423
- }
424
-
425
- /**
426
- * @license
427
- * Copyright 2023 Google LLC
428
- *
429
- * Licensed under the Apache License, Version 2.0 (the "License");
430
- * you may not use this file except in compliance with the License.
431
- * You may obtain a copy of the License at
432
- *
433
- * http://www.apache.org/licenses/LICENSE-2.0
434
- *
435
- * Unless required by applicable law or agreed to in writing, software
436
- * distributed under the License is distributed on an "AS IS" BASIS,
437
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
438
- * See the License for the specific language governing permissions and
439
- * limitations under the License.
440
- */
441
- /**
442
- * A class containing a value that changes with the contrast level.
443
- *
444
- * Usually represents the contrast requirements for a dynamic color on its
445
- * background. The four values correspond to values for contrast levels -1.0,
446
- * 0.0, 0.5, and 1.0, respectively.
447
- */
448
- var ContrastCurve = /*#__PURE__*/function () {
449
- /**
450
- * Creates a `ContrastCurve` object.
451
- *
452
- * @param low Value for contrast level -1.0
453
- * @param normal Value for contrast level 0.0
454
- * @param medium Value for contrast level 0.5
455
- * @param high Value for contrast level 1.0
456
- */
457
- function ContrastCurve(low, normal, medium, high) {
458
- this.low = void 0;
459
- this.normal = void 0;
460
- this.medium = void 0;
461
- this.high = void 0;
462
- this.low = low;
463
- this.normal = normal;
464
- this.medium = medium;
465
- this.high = high;
466
- }
467
- /**
468
- * Returns the value at a given contrast level.
469
- *
470
- * @param contrastLevel The contrast level. 0.0 is the default (normal); -1.0
471
- * is the lowest; 1.0 is the highest.
472
- * @return The value. For contrast ratios, a number between 1.0 and 21.0.
473
- */
474
- var _proto = ContrastCurve.prototype;
475
- _proto.get = function get(contrastLevel) {
476
- if (contrastLevel <= -1.0) {
477
- return this.low;
478
- } else if (contrastLevel < 0.0) {
479
- return materialColorUtilities.lerp(this.low, this.normal, (contrastLevel - -1) / 1);
480
- } else if (contrastLevel < 0.5) {
481
- return materialColorUtilities.lerp(this.normal, this.medium, (contrastLevel - 0) / 0.5);
482
- } else if (contrastLevel < 1.0) {
483
- return materialColorUtilities.lerp(this.medium, this.high, (contrastLevel - 0.5) / 0.5);
484
- } else {
485
- return this.high;
486
- }
487
- };
488
- return ContrastCurve;
489
- }();
490
-
491
- /**
492
- * @license
493
- * Copyright 2022 Google LLC
494
- *
495
- * Licensed under the Apache License, Version 2.0 (the "License");
496
- * you may not use this file except in compliance with the License.
497
- * You may obtain a copy of the License at
498
- *
499
- * http://www.apache.org/licenses/LICENSE-2.0
500
- *
501
- * Unless required by applicable law or agreed to in writing, software
502
- * distributed under the License is distributed on an "AS IS" BASIS,
503
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
504
- * See the License for the specific language governing permissions and
505
- * limitations under the License.
506
- */
507
- /**
508
- * A color that adjusts itself based on UI state provided by SchemeEntity.
509
- *
510
- * Colors without backgrounds do not change tone when contrast changes. Colors
511
- * with backgrounds become closer to their background as contrast lowers, and
512
- * further when contrast increases.
513
- *
514
- * Prefer static constructors. They require either a hexcode, a palette and
515
- * tone, or a hue and chroma. Optionally, they can provide a background
516
- * DynamicColor.
517
- */
518
- var DynamicColor = /*#__PURE__*/function () {
519
- /**
520
- * The base constructor for DynamicColor.
521
- *
522
- * _Strongly_ prefer using one of the convenience constructors. This class is
523
- * arguably too flexible to ensure it can support any scenario. Functional
524
- * arguments allow overriding without risks that come with subclasses.
525
- *
526
- * For example, the default behavior of adjust tone at max contrast
527
- * to be at a 7.0 ratio with its background is principled and
528
- * matches accessibility guidance. That does not mean it's the desired
529
- * approach for _every_ design system, and every color pairing,
530
- * always, in every case.
531
- *
532
- * @param name The name of the dynamic color. Defaults to empty.
533
- * @param palette Function that provides a TonalPalette given
534
- * SchemeEntity. A TonalPalette is defined by a hue and chroma, so this
535
- * replaces the need to specify hue/chroma. By providing a tonal palette, when
536
- * contrast adjustments are made, intended chroma can be preserved.
537
- * @param tone Function that provides a tone, given a SchemeEntity.
538
- * @param isBackground Whether this dynamic color is a background, with
539
- * some other color as the foreground. Defaults to false.
540
- * @param background The background of the dynamic color (as a function of a
541
- * `SchemeEntity`), if it exists.
542
- * @param secondBackground A second background of the dynamic color (as a
543
- * function of a `SchemeEntity`), if it
544
- * exists.
545
- * @param contrastCurve A `ContrastCurve` object specifying how its contrast
546
- * against its background should behave in various contrast levels options.
547
- * @param toneDeltaPair A `ToneDeltaPair` object specifying a tone delta
548
- * constraint between two colors. One of them must be the color being
549
- * constructed.
550
- */
551
- function DynamicColor(name, palette, tone, isBackground, background, secondBackground, contrastCurve, toneDeltaPair) {
552
- this.name = void 0;
553
- this.palette = void 0;
554
- this.tone = void 0;
555
- this.isBackground = void 0;
556
- this.background = void 0;
557
- this.secondBackground = void 0;
558
- this.contrastCurve = void 0;
559
- this.toneDeltaPair = void 0;
560
- this.hctCache = new Map();
561
- this.name = name;
562
- this.palette = palette;
563
- this.tone = tone;
564
- this.isBackground = isBackground;
565
- this.background = background;
566
- this.secondBackground = secondBackground;
567
- this.contrastCurve = contrastCurve;
568
- this.toneDeltaPair = toneDeltaPair;
569
- if (!background && secondBackground) {
570
- throw new Error("Color " + name + " has secondBackground" + "defined, but background is not defined.");
571
- }
572
- if (!background && contrastCurve) {
573
- throw new Error("Color " + name + " has contrastCurve" + "defined, but background is not defined.");
574
- }
575
- if (background && !contrastCurve) {
576
- throw new Error("Color " + name + " has background" + "defined, but contrastCurve is not defined.");
577
- }
578
- }
579
- /**
580
- * Create a DynamicColor defined by a TonalPalette and HCT tone.
581
- *
582
- * @param args Functions with SchemeEntity as input. Must provide a palette
583
- * and tone. May provide a background DynamicColor and ToneDeltaConstraint.
584
- */
585
- DynamicColor.fromPalette = function fromPalette(args) {
586
- var _args$name, _args$isBackground;
587
- 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);
588
- }
589
- /**
590
- * Given a background tone, find a foreground tone, while ensuring they reach
591
- * a contrast ratio that is as close to [ratio] as possible.
592
- *
593
- * @param bgTone Tone in HCT. Range is 0 to 100, undefined behavior when it
594
- * falls outside that range.
595
- * @param ratio The contrast ratio desired between bgTone and the return
596
- * value.
597
- */;
598
- DynamicColor.foregroundTone = function foregroundTone(bgTone, ratio) {
599
- var lighterTone = materialColorUtilities.Contrast.lighterUnsafe(bgTone, ratio);
600
- var darkerTone = materialColorUtilities.Contrast.darkerUnsafe(bgTone, ratio);
601
- var lighterRatio = materialColorUtilities.Contrast.ratioOfTones(lighterTone, bgTone);
602
- var darkerRatio = materialColorUtilities.Contrast.ratioOfTones(darkerTone, bgTone);
603
- var preferLighter = DynamicColor.tonePrefersLightForeground(bgTone);
604
- if (preferLighter) {
605
- // This handles an edge case where the initial contrast ratio is high
606
- // (ex. 13.0), and the ratio passed to the function is that high
607
- // ratio, and both the lighter and darker ratio fails to pass that
608
- // ratio.
609
- //
610
- // This was observed with Tonal Spot's On Primary Container turning
611
- // black momentarily between high and max contrast in light mode. PC's
612
- // standard tone was T90, OPC's was T10, it was light mode, and the
613
- // contrast value was 0.6568521221032331.
614
- var negligibleDifference = Math.abs(lighterRatio - darkerRatio) < 0.1 && lighterRatio < ratio && darkerRatio < ratio;
615
- return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
616
- } else {
617
- return darkerRatio >= ratio || darkerRatio >= lighterRatio ? darkerTone : lighterTone;
618
- }
619
- }
620
- /**
621
- * Returns whether [tone] prefers a light foreground.
622
- *
623
- * People prefer white foregrounds on ~T60-70. Observed over time, and also
624
- * by Andrew Somers during research for APCA.
625
- *
626
- * T60 used as to create the smallest discontinuity possible when skipping
627
- * down to T49 in order to ensure light foregrounds.
628
- * Since `tertiaryContainer` in dark monochrome scheme requires a tone of
629
- * 60, it should not be adjusted. Therefore, 60 is excluded here.
630
- */;
631
- DynamicColor.tonePrefersLightForeground = function tonePrefersLightForeground(tone) {
632
- return Math.round(tone) < 60.0;
633
- }
634
- /**
635
- * Returns whether [tone] can reach a contrast ratio of 4.5 with a lighter
636
- * color.
637
- */;
638
- DynamicColor.toneAllowsLightForeground = function toneAllowsLightForeground(tone) {
639
- return Math.round(tone) <= 49.0;
640
- }
641
- /**
642
- * Adjust a tone such that white has 4.5 contrast, if the tone is
643
- * reasonably close to supporting it.
644
- */;
645
- DynamicColor.enableLightForeground = function enableLightForeground(tone) {
646
- if (DynamicColor.tonePrefersLightForeground(tone) && !DynamicColor.toneAllowsLightForeground(tone)) {
647
- return 49.0;
648
- }
649
- return tone;
650
- }
651
- /**
652
- * Return a ARGB integer (i.e. a hex code).
653
- *
654
- * @param scheme Defines the conditions of the user interface, for example,
655
- * whether or not it is dark mode or light mode, and what the desired
656
- * contrast level is.
657
- */;
658
- var _proto = DynamicColor.prototype;
659
- _proto.getArgb = function getArgb(scheme) {
660
- return this.getHct(scheme).toInt();
661
- }
662
- /**
663
- * Return a color, expressed in the HCT color space, that this
664
- * DynamicColor is under the conditions in scheme.
665
- *
666
- * @param scheme Defines the conditions of the user interface, for example,
667
- * whether or not it is dark mode or light mode, and what the desired
668
- * contrast level is.
669
- */;
670
- _proto.getHct = function getHct(scheme) {
671
- var cachedAnswer = this.hctCache.get(scheme);
672
- if (cachedAnswer != null) {
673
- return cachedAnswer;
674
- }
675
- var tone = this.getTone(scheme);
676
- var answer = this.palette(scheme).getHct(tone);
677
- if (this.hctCache.size > 4) {
678
- this.hctCache.clear();
679
- }
680
- this.hctCache.set(scheme, answer);
681
- return answer;
682
- }
683
- /**
684
- * Return a tone, T in the HCT color space, that this DynamicColor is under
685
- * the conditions in scheme.
686
- *
687
- * @param scheme Defines the conditions of the user interface, for example,
688
- * whether or not it is dark mode or light mode, and what the desired
689
- * contrast level is.
690
- */;
691
- _proto.getTone = function getTone(scheme) {
692
- var decreasingContrast = scheme.contrastLevel < 0;
693
- // Case 1: dual foreground, pair of colors with delta constraint.
694
- if (this.toneDeltaPair) {
695
- var toneDeltaPair = this.toneDeltaPair(scheme);
696
- var roleA = toneDeltaPair.roleA;
697
- var roleB = toneDeltaPair.roleB;
698
- var delta = toneDeltaPair.delta;
699
- var polarity = toneDeltaPair.polarity;
700
- var stayTogether = toneDeltaPair.stayTogether;
701
- var bg = this.background(scheme);
702
- var bgTone = bg.getTone(scheme);
703
- var aIsNearer = polarity === 'nearer' || polarity === 'lighter' && !scheme.isDark || polarity === 'darker' && scheme.isDark;
704
- var nearer = aIsNearer ? roleA : roleB;
705
- var farther = aIsNearer ? roleB : roleA;
706
- var amNearer = this.name === nearer.name;
707
- var expansionDir = scheme.isDark ? 1 : -1;
708
- // 1st round: solve to min, each
709
- var nContrast = nearer.contrastCurve.get(scheme.contrastLevel);
710
- var fContrast = farther.contrastCurve.get(scheme.contrastLevel);
711
- // If a color is good enough, it is not adjusted.
712
- // Initial and adjusted tones for `nearer`
713
- var nInitialTone = nearer.tone(scheme);
714
- var nTone = materialColorUtilities.Contrast.ratioOfTones(bgTone, nInitialTone) >= nContrast ? nInitialTone : DynamicColor.foregroundTone(bgTone, nContrast);
715
- // Initial and adjusted tones for `farther`
716
- var fInitialTone = farther.tone(scheme);
717
- var fTone = materialColorUtilities.Contrast.ratioOfTones(bgTone, fInitialTone) >= fContrast ? fInitialTone : DynamicColor.foregroundTone(bgTone, fContrast);
718
- if (decreasingContrast) {
719
- // If decreasing contrast, adjust color to the "bare minimum"
720
- // that satisfies contrast.
721
- nTone = DynamicColor.foregroundTone(bgTone, nContrast);
722
- fTone = DynamicColor.foregroundTone(bgTone, fContrast);
723
- }
724
- if ((fTone - nTone) * expansionDir >= delta) ; else {
725
- // 2nd round: expand farther to match delta.
726
- fTone = materialColorUtilities.clampDouble(0, 100, nTone + delta * expansionDir);
727
- if ((fTone - nTone) * expansionDir >= delta) ; else {
728
- // 3rd round: contract nearer to match delta.
729
- nTone = materialColorUtilities.clampDouble(0, 100, fTone - delta * expansionDir);
730
- }
731
- }
732
- // Avoids the 50-59 awkward zone.
733
- if (50 <= nTone && nTone < 60) {
734
- // If `nearer` is in the awkward zone, move it away, together with
735
- // `farther`.
736
- if (expansionDir > 0) {
737
- nTone = 60;
738
- fTone = Math.max(fTone, nTone + delta * expansionDir);
739
- } else {
740
- nTone = 49;
741
- fTone = Math.min(fTone, nTone + delta * expansionDir);
742
- }
743
- } else if (50 <= fTone && fTone < 60) {
744
- if (stayTogether) {
745
- // Fixes both, to avoid two colors on opposite sides of the "awkward
746
- // zone".
747
- if (expansionDir > 0) {
748
- nTone = 60;
749
- fTone = Math.max(fTone, nTone + delta * expansionDir);
750
- } else {
751
- nTone = 49;
752
- fTone = Math.min(fTone, nTone + delta * expansionDir);
753
- }
754
- } else {
755
- // Not required to stay together; fixes just one.
756
- if (expansionDir > 0) {
757
- fTone = 60;
758
- } else {
759
- fTone = 49;
760
- }
761
- }
762
- }
763
- // Returns `nTone` if this color is `nearer`, otherwise `fTone`.
764
- return amNearer ? nTone : fTone;
765
- } else {
766
- // Case 2: No contrast pair; just solve for itself.
767
- var answer = this.tone(scheme);
768
- if (this.background == null) {
769
- return answer; // No adjustment for colors with no background.
770
- }
771
- var _bgTone = this.background(scheme).getTone(scheme);
772
- var desiredRatio = this.contrastCurve.get(scheme.contrastLevel);
773
- if (materialColorUtilities.Contrast.ratioOfTones(_bgTone, answer) >= desiredRatio) ; else {
774
- // Rough improvement.
775
- answer = DynamicColor.foregroundTone(_bgTone, desiredRatio);
776
- }
777
- if (decreasingContrast) {
778
- answer = DynamicColor.foregroundTone(_bgTone, desiredRatio);
779
- }
780
- if (this.isBackground && 50 <= answer && answer < 60) {
781
- // Must adjust
782
- if (materialColorUtilities.Contrast.ratioOfTones(49, _bgTone) >= desiredRatio) {
783
- answer = 49;
784
- } else {
785
- answer = 60;
786
- }
787
- }
788
- if (this.secondBackground) {
789
- // Case 3: Adjust for dual backgrounds.
790
- var _ref = [this.background, this.secondBackground],
791
- bg1 = _ref[0],
792
- bg2 = _ref[1];
793
- var _ref2 = [bg1(scheme).getTone(scheme), bg2(scheme).getTone(scheme)],
794
- bgTone1 = _ref2[0],
795
- bgTone2 = _ref2[1];
796
- var _ref3 = [Math.max(bgTone1, bgTone2), Math.min(bgTone1, bgTone2)],
797
- upper = _ref3[0],
798
- lower = _ref3[1];
799
- if (materialColorUtilities.Contrast.ratioOfTones(upper, answer) >= desiredRatio && materialColorUtilities.Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
800
- return answer;
801
- }
802
- // The darkest light tone that satisfies the desired ratio,
803
- // or -1 if such ratio cannot be reached.
804
- var lightOption = materialColorUtilities.Contrast.lighter(upper, desiredRatio);
805
- // The lightest dark tone that satisfies the desired ratio,
806
- // or -1 if such ratio cannot be reached.
807
- var darkOption = materialColorUtilities.Contrast.darker(lower, desiredRatio);
808
- // Tones suitable for the foreground.
809
- var availables = [];
810
- if (lightOption !== -1) availables.push(lightOption);
811
- if (darkOption !== -1) availables.push(darkOption);
812
- var prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
813
- if (prefersLight) {
814
- return lightOption < 0 ? 100 : lightOption;
815
- }
816
- if (availables.length === 1) {
817
- return availables[0];
818
- }
819
- return darkOption < 0 ? 0 : darkOption;
820
- }
821
- return answer;
822
- }
823
- };
824
- return DynamicColor;
825
- }();
826
-
827
- /**
828
- * @license
829
- * Copyright 2023 Google LLC
830
- *
831
- * Licensed under the Apache License, Version 2.0 (the "License");
832
- * you may not use this file except in compliance with the License.
833
- * You may obtain a copy of the License at
834
- *
835
- * http://www.apache.org/licenses/LICENSE-2.0
836
- *
837
- * Unless required by applicable law or agreed to in writing, software
838
- * distributed under the License is distributed on an "AS IS" BASIS,
839
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
840
- * See the License for the specific language governing permissions and
841
- * limitations under the License.
842
- */
843
- /**
844
- * Documents a constraint between two DynamicColors, in which their tones must
845
- * have a certain distance from each other.
846
- *
847
- * Prefer a DynamicColor with a background, this is for special cases when
848
- * designers want tonal distance, literally contrast, between two colors that
849
- * don't have a background / foreground relationship or a contrast guarantee.
850
- */
851
- var ToneDeltaPair =
852
- /**
853
- * Documents a constraint in tone distance between two DynamicColors.
854
- *
855
- * The polarity is an adjective that describes "A", compared to "B".
856
- *
857
- * For instance, ToneDeltaPair(A, B, 15, 'darker', stayTogether) states that
858
- * A's tone should be at least 15 darker than B's.
859
- *
860
- * 'nearer' and 'farther' describes closeness to the surface roles. For
861
- * instance, ToneDeltaPair(A, B, 10, 'nearer', stayTogether) states that A
862
- * should be 10 lighter than B in light mode, and 10 darker than B in dark
863
- * mode.
864
- *
865
- * @param roleA The first role in a pair.
866
- * @param roleB The second role in a pair.
867
- * @param delta Required difference between tones. Absolute value, negative
868
- * values have undefined behavior.
869
- * @param polarity The relative relation between tones of roleA and roleB,
870
- * as described above.
871
- * @param stayTogether Whether these two roles should stay on the same side of
872
- * the "awkward zone" (T50-59). This is necessary for certain cases where
873
- * one role has two backgrounds.
874
- */
875
- function ToneDeltaPair(roleA, roleB, delta, polarity, stayTogether) {
876
- this.roleA = void 0;
877
- this.roleB = void 0;
878
- this.delta = void 0;
879
- this.polarity = void 0;
880
- this.stayTogether = void 0;
881
- this.roleA = roleA;
882
- this.roleB = roleB;
883
- this.delta = delta;
884
- this.polarity = polarity;
885
- this.stayTogether = stayTogether;
886
- };
887
-
888
- function argbToRgb(argb) {
889
- return {
890
- r: argb >> 16 & 0xff,
891
- g: argb >> 8 & 0xff,
892
- b: argb & 0xff
893
- };
894
- }
895
- var ColorEntity = /*#__PURE__*/function () {
896
- function ColorEntity(option, schemeService, colorService) {
897
- this.option = void 0;
898
- this.schemeService = void 0;
899
- this.colorService = void 0;
900
- this.dynamicColor = null;
901
- this.option = option;
902
- this.schemeService = schemeService;
903
- this.colorService = colorService;
904
- }
905
- var _proto = ColorEntity.prototype;
906
- _proto.update = function update(args) {
907
- this.dynamicColor = null;
908
- this.option = _extends({}, this.option, args);
909
- };
910
- _proto.getHex = function getHex() {
911
- return materialColorUtilities.hexFromArgb(this.getArgb());
912
- };
913
- _proto.getArgb = function getArgb() {
914
- return this.getDynamicColor().getArgb(this.schemeService.get());
915
- };
916
- _proto.getRgb = function getRgb() {
917
- return argbToRgb(this.getArgb());
918
- };
919
- _proto.getName = function getName() {
920
- return this.option.name.replace(/([A-Z])/g, '_$1').toLowerCase();
921
- };
922
- _proto.getDynamicColor = function getDynamicColor() {
923
- if (!this.dynamicColor) {
924
- this.dynamicColor = DynamicColor.fromPalette(_extends({}, this.option, {
925
- name: this.getName()
926
- }));
927
- }
928
- return this.dynamicColor;
929
- };
930
- return ColorEntity;
931
- }();
932
-
933
- function capitalizeFirstLetter(string) {
934
- return string.charAt(0).toUpperCase() + string.slice(1);
935
- }
936
- var highestSurface = function highestSurface(s, colorService) {
937
- if (colorService instanceof ColorService) {
938
- return s.isDark ? colorService.getColor('surfaceBright').getDynamicColor() : colorService.getColor('surfaceDim').getDynamicColor();
939
- } else {
940
- return s.isDark ? colorService.get('surfaceBright').getDynamicColor() : colorService.get('surfaceDim').getDynamicColor();
941
- }
942
- };
943
- var ColorManagerService = /*#__PURE__*/function () {
944
- function ColorManagerService(_ref) {
945
- var schemeService = _ref.schemeService;
946
- this.colorMap = new Map();
947
- this.schemeService = void 0;
948
- this.schemeService = schemeService;
949
- }
950
- var _proto = ColorManagerService.prototype;
951
- _proto.createOrUpdate = function createOrUpdate(key, args) {
952
- var colorEntity = this.colorMap.get(key);
953
- if (!colorEntity) {
954
- var palette = args.palette,
955
- tone = args.tone;
956
- if (palette && tone) {
957
- colorEntity = new ColorEntity(_extends({}, args, {
958
- palette: palette,
959
- tone: tone,
960
- name: key
961
- }), this.schemeService, this);
962
- this.colorMap.set(key, colorEntity);
963
- } else {
964
- throw new Error("Palette " + key + " does not exist");
965
- }
966
- } else {
967
- colorEntity.update(_extends({}, args, {
968
- name: key
969
- }));
970
- this.colorMap.set(key, colorEntity);
971
- }
972
- return colorEntity;
973
- };
974
- _proto.remove = function remove(key) {
975
- return this.colorMap["delete"](key);
976
- };
977
- _proto.get = function get(key) {
978
- var colorEntity = this.colorMap.get(key);
979
- if (colorEntity) {
980
- return colorEntity;
981
- } else {
982
- throw new Error("Color " + key + " does not exist");
983
- }
984
- };
985
- _proto.getAll = function getAll() {
986
- return this.colorMap;
987
- };
988
- _proto.addFromPalette = function addFromPalette(key) {
989
- var _this = this;
990
- var colorKey = key;
991
- var ColorKey = capitalizeFirstLetter(key);
992
- var onColorKey = 'on' + ColorKey;
993
- var colorKeyContainer = colorKey + 'Container';
994
- var onColorKeyContainer = 'on' + ColorKey + 'Container';
995
- var inverseColorKey = 'inverse' + ColorKey;
996
- var colorKeyFixed = colorKey + 'Fixed';
997
- var colorKeyFixedDim = colorKey + 'FixedDim';
998
- var onColorKeyFixed = 'on' + ColorKey + 'Fixed';
999
- var onColorKeyFixedVariant = 'on' + ColorKey + 'FixedVariant';
1000
- this.createOrUpdate(colorKey, {
1001
- palette: function palette(s) {
1002
- return s.getPalette(key);
1003
- },
1004
- tone: function tone(s) {
1005
- return s.isDark ? 80 : 40;
1006
- },
1007
- isBackground: true,
1008
- background: function background(s) {
1009
- return highestSurface(s, _this);
1010
- },
1011
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
1012
- toneDeltaPair: function toneDeltaPair(s) {
1013
- return new ToneDeltaPair(_this.get(colorKeyContainer).getDynamicColor(), _this.get(colorKey).getDynamicColor(), 15, 'nearer', false);
1014
- }
1015
- });
1016
- this.createOrUpdate(onColorKey, {
1017
- palette: function palette(s) {
1018
- return s.getPalette(key);
1019
- },
1020
- tone: function tone(s) {
1021
- return s.isDark ? 20 : 100;
1022
- },
1023
- background: function background(s) {
1024
- return _this.get(colorKey).getDynamicColor();
1025
- },
1026
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1027
- });
1028
- this.createOrUpdate(colorKeyContainer, {
1029
- palette: function palette(s) {
1030
- return s.getPalette(key);
1031
- },
1032
- tone: function tone(s) {
1033
- return s.isDark ? 30 : 90;
1034
- },
1035
- isBackground: true,
1036
- background: function background(s) {
1037
- return highestSurface(s, _this);
1038
- },
1039
- contrastCurve: new ContrastCurve(1, 1, 3, 7),
1040
- toneDeltaPair: function toneDeltaPair(s) {
1041
- return new ToneDeltaPair(_this.get(colorKeyContainer).getDynamicColor(), _this.get(colorKey).getDynamicColor(), 15, 'nearer', false);
1042
- }
1043
- });
1044
- this.createOrUpdate(onColorKeyContainer, {
1045
- palette: function palette(s) {
1046
- return s.getPalette(key);
1047
- },
1048
- tone: function tone(s) {
1049
- return s.isDark ? 90 : 10;
1050
- },
1051
- background: function background(s) {
1052
- return _this.get(colorKeyContainer).getDynamicColor();
1053
- },
1054
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1055
- });
1056
- this.createOrUpdate(inverseColorKey, {
1057
- palette: function palette(s) {
1058
- return s.getPalette(key);
1059
- },
1060
- tone: function tone(s) {
1061
- return s.isDark ? 40 : 80;
1062
- },
1063
- background: function background(s) {
1064
- return _this.get('inverseSurface').getDynamicColor();
1065
- },
1066
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1067
- });
1068
- this.createOrUpdate(colorKeyFixed, {
1069
- palette: function palette(s) {
1070
- return s.getPalette(key);
1071
- },
1072
- tone: function tone(s) {
1073
- return 90.0;
1074
- },
1075
- isBackground: true,
1076
- background: function background(s) {
1077
- return highestSurface(s, _this);
1078
- },
1079
- contrastCurve: new ContrastCurve(1, 1, 3, 7),
1080
- toneDeltaPair: function toneDeltaPair(s) {
1081
- return new ToneDeltaPair(_this.get(colorKeyFixed).getDynamicColor(), _this.get(colorKeyFixedDim).getDynamicColor(), 10, 'lighter', true);
1082
- }
1083
- });
1084
- this.createOrUpdate(colorKeyFixedDim, {
1085
- palette: function palette(s) {
1086
- return s.getPalette(key);
1087
- },
1088
- tone: function tone(s) {
1089
- return 80.0;
1090
- },
1091
- isBackground: true,
1092
- background: function background(s) {
1093
- return highestSurface(s, _this);
1094
- },
1095
- contrastCurve: new ContrastCurve(1, 1, 3, 7),
1096
- toneDeltaPair: function toneDeltaPair(s) {
1097
- return new ToneDeltaPair(_this.get(colorKeyFixed).getDynamicColor(), _this.get(colorKeyFixedDim).getDynamicColor(), 10, 'lighter', true);
1098
- }
1099
- });
1100
- this.createOrUpdate(onColorKeyFixed, {
1101
- palette: function palette(s) {
1102
- return s.getPalette(key);
1103
- },
1104
- tone: function tone(s) {
1105
- return 10.0;
1106
- },
1107
- background: function background(s) {
1108
- return _this.get(colorKeyFixedDim).getDynamicColor();
1109
- },
1110
- secondBackground: function secondBackground(s) {
1111
- return _this.get(colorKeyFixed).getDynamicColor();
1112
- },
1113
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1114
- });
1115
- this.createOrUpdate(onColorKeyFixedVariant, {
1116
- palette: function palette(s) {
1117
- return s.getPalette(key);
1118
- },
1119
- tone: function tone(s) {
1120
- return 30.0;
1121
- },
1122
- background: function background(s) {
1123
- return _this.get(colorKeyFixedDim).getDynamicColor();
1124
- },
1125
- secondBackground: function secondBackground(s) {
1126
- return _this.get(colorKeyFixed).getDynamicColor();
1127
- },
1128
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1129
- });
1130
- };
1131
- return ColorManagerService;
1132
- }();
1133
-
1134
- var ColorModule = {
1135
- colorManagerService: /*#__PURE__*/awilix.asClass(ColorManagerService).singleton(),
1136
- colorService: /*#__PURE__*/awilix.asClass(ColorService).singleton()
1137
- };
1138
-
1139
- var SchemeEntity = /*#__PURE__*/function () {
1140
- function SchemeEntity(options) {
1141
- this.options = void 0;
1142
- this.options = options;
1143
- }
1144
- var _proto = SchemeEntity.prototype;
1145
- _proto.getPalette = function getPalette(key) {
1146
- if (!this.options) {
1147
- throw new Error('Scheme options is not set');
1148
- }
1149
- var palette = this.options.palettes.get(key);
1150
- if (!palette) {
1151
- throw new Error("Palette " + key + " not found");
1152
- }
1153
- return palette;
1154
- };
1155
- return _createClass(SchemeEntity, [{
1156
- key: "contrastLevel",
1157
- get: function get() {
1158
- if (!this.options) {
1159
- throw new Error('Scheme options is not set');
1160
- }
1161
- return this.options.contrastLevel;
1162
- }
1163
- }, {
1164
- key: "isDark",
1165
- get: function get() {
1166
- if (!this.options) {
1167
- throw new Error('Scheme options is not set');
1168
- }
1169
- return this.options.isDark;
1170
- }
1171
- }, {
1172
- key: "sourceColorHct",
1173
- get: function get() {
1174
- if (!this.options) {
1175
- throw new Error('Scheme options is not set');
1176
- }
1177
- return materialColorUtilities.Hct.fromInt(this.options.sourceColorArgb);
1178
- }
1179
- }]);
1180
- }();
1181
-
1182
- var SchemeService = /*#__PURE__*/function () {
1183
- function SchemeService() {
1184
- this.schemeEntity = void 0;
1185
- this.options = void 0;
1186
- }
1187
- var _proto = SchemeService.prototype;
1188
- _proto.createOrUpdate = function createOrUpdate(options) {
1189
- var _this$options, _this$options2;
1190
- this.options = _extends({}, this.options, options, {
1191
- sourcesColorHex: _extends({}, (_this$options = this.options) == null ? void 0 : _this$options.sourcesColorHex, options.sourcesColorHex),
1192
- palettes: _extends({}, (_this$options2 = this.options) == null ? void 0 : _this$options2.palettes, options.palettes)
1193
- });
1194
- var palettes = new Map();
1195
- if (!this.options.sourcesColorHex.primary) {
1196
- throw new Error('Primary source color is not set');
1197
- }
1198
- var sourceColorArgb = materialColorUtilities.argbFromHex(this.options.sourcesColorHex.primary);
1199
- var sourceColorHct = materialColorUtilities.Hct.fromInt(sourceColorArgb);
1200
- if (!this.options.palettes) {
1201
- return;
1202
- }
1203
- for (var _i = 0, _Object$entries = Object.entries(this.options.palettes); _i < _Object$entries.length; _i++) {
1204
- var _Object$entries$_i = _Object$entries[_i],
1205
- key = _Object$entries$_i[0],
1206
- _Object$entries$_i$ = _Object$entries$_i[1],
1207
- sourceColorkey = _Object$entries$_i$.sourceColorkey,
1208
- paletteFunction = _Object$entries$_i$.tonalPalette;
1209
- var palette = void 0;
1210
- if (!sourceColorkey) {
1211
- palette = paletteFunction(sourceColorHct);
1212
- } else {
1213
- var _sourceColorArgb = materialColorUtilities.argbFromHex(this.options.sourcesColorHex[sourceColorkey]);
1214
- var _sourceColorHct = materialColorUtilities.Hct.fromInt(_sourceColorArgb);
1215
- palette = paletteFunction(_sourceColorHct);
1216
- }
1217
- palettes.set(key, palette);
1218
- }
1219
- this.schemeEntity = new SchemeEntity(_extends({}, this.options, {
1220
- palettes: palettes,
1221
- sourceColorArgb: sourceColorArgb
1222
- }));
1223
- };
1224
- _proto.get = function get() {
1225
- if (!this.schemeEntity) {
1226
- throw new Error('Scheme is not created');
1227
- }
1228
- return this.schemeEntity;
1229
- };
1230
- return SchemeService;
1231
- }();
1232
-
1233
- var ThemeService = /*#__PURE__*/function () {
1234
- function ThemeService(_ref) {
1235
- var schemeService = _ref.schemeService,
1236
- variantService = _ref.variantService;
1237
- this.schemeService = void 0;
1238
- this.variantService = void 0;
1239
- this.schemeService = schemeService;
1240
- this.variantService = variantService;
1241
- // this.addPalette({key: "primary", addDefaultColors: true})
1242
- // this.addPalette({key: "secondary", addDefaultColors: true})
1243
- // this.addPalette({key: "tertiary", addDefaultColors: true})
1244
- // this.addPalette({key: "error", palette: TonalPalette.fromHueAndChroma(25.0, 84.0)})
1245
- // this.addPalette({key: "neutral"})
1246
- // this.addPalette({key: "neutralVariant"})
1247
- }
1248
- // addPalette({key, palette, addDefaultColors}: {key: string; palette: TonalPalette; addDefaultColors: boolean}) {
1249
- // this.themeOptions.palettes.set(key, palette);
1250
- // if (addDefaultColors){
1251
- // this.colorService.addPalette(key)
1252
- // }
1253
- // }
1254
- // create(args: ThemeOptions): SchemeService {
1255
- // return new SchemeService(args, this.colorService)
1256
- // }
1257
- //
1258
- // update(options: Partial<ThemeOptions>): SchemeService {
1259
- // Object.assign(this.themeOptions, options);
1260
- // return this.theme();
1261
- // }
1262
- var _proto = ThemeService.prototype;
1263
- _proto.create = function create(options) {
1264
- this.schemeService.createOrUpdate(_extends({}, options, {
1265
- sourcesColorHex: {
1266
- primary: options.sourceColorHex
1267
- }
1268
- }));
1269
- this.variantService.set(options.variant);
1270
- };
1271
- _proto.update = function update(options) {
1272
- var themeOptions = _extends({}, options);
1273
- if (options.sourceColorHex) themeOptions.sourcesColorHex = {
1274
- primary: options.sourceColorHex
1275
- };
1276
- this.schemeService.createOrUpdate(themeOptions);
1277
- if (options.variant) this.variantService.set(options.variant);
1278
- };
1279
- _proto.addCustomPalette = function addCustomPalette(key, colorHex) {
1280
- this.variantService.addCustomPalette(key, colorHex);
1281
- };
1282
- return ThemeService;
1283
- }();
1284
-
1285
- var VariantService = /*#__PURE__*/function () {
1286
- function VariantService(_ref) {
1287
- var schemeService = _ref.schemeService;
1288
- this.customPalettes = {};
1289
- this.variantEntity = void 0;
1290
- this.schemeService = void 0;
1291
- this.schemeService = schemeService;
1292
- }
1293
- var _proto = VariantService.prototype;
1294
- _proto.addCustomPalette = function addCustomPalette(key, colorHex) {
1295
- this.customPalettes[key] = colorHex;
1296
- this.update();
1297
- };
1298
- _proto.set = function set(variantEntity) {
1299
- this.variantEntity = variantEntity;
1300
- if (!variantEntity.palettes.error) {
1301
- variantEntity.palettes.error = function () {
1302
- return materialColorUtilities.TonalPalette.fromHueAndChroma(25.0, 84.0);
1303
- };
1304
- }
1305
- this.update();
1306
- };
1307
- _proto.update = function update() {
1308
- var _this = this;
1309
- if (!this.variantEntity) return;
1310
- var palettes = {};
1311
- Object.keys(this.variantEntity.palettes).forEach(function (key) {
1312
- palettes[key] = {
1313
- tonalPalette: _this.variantEntity.palettes[key]
1314
- };
1315
- });
1316
- if (this.variantEntity.customPalettes) {
1317
- Object.keys(this.customPalettes).forEach(function (key) {
1318
- palettes[key] = {
1319
- sourceColorkey: key,
1320
- tonalPalette: _this.variantEntity.customPalettes
1321
- };
1322
- });
1323
- }
1324
- this.schemeService.createOrUpdate({
1325
- sourcesColorHex: this.customPalettes,
1326
- palettes: palettes
1327
- });
1328
- };
1329
- return VariantService;
1330
- }();
1331
-
1332
- var ThemeModule = {
1333
- schemeService: /*#__PURE__*/awilix.asClass(SchemeService).singleton(),
1334
- variantService: /*#__PURE__*/awilix.asClass(VariantService).singleton(),
1335
- themeService: /*#__PURE__*/awilix.asClass(ThemeService).singleton()
1336
- };
1337
-
1338
- var AppService = function AppService(_ref) {
1339
- var colorService = _ref.colorService,
1340
- themeService = _ref.themeService,
1341
- pluginService = _ref.pluginService;
1342
- this.colorService = void 0;
1343
- this.themeService = void 0;
1344
- this.pluginService = void 0;
1345
- this.pluginService = pluginService;
1346
- this.colorService = colorService;
1347
- this.themeService = themeService;
1348
- };
1349
-
1350
- var AppModule = {
1351
- appService: /*#__PURE__*/awilix.asClass(AppService).singleton()
1352
- };
1353
-
1354
- function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
1355
- var answer = tone;
1356
- var closestToChroma = materialColorUtilities.Hct.from(hue, chroma, tone);
1357
- if (closestToChroma.chroma < chroma) {
1358
- var chromaPeak = closestToChroma.chroma;
1359
- while (closestToChroma.chroma < chroma) {
1360
- answer += byDecreasingTone ? -1.0 : 1.0;
1361
- var potentialSolution = materialColorUtilities.Hct.from(hue, chroma, answer);
1362
- if (chromaPeak > potentialSolution.chroma) {
1363
- break;
1364
- }
1365
- if (Math.abs(potentialSolution.chroma - chroma) < 0.4) {
1366
- break;
1367
- }
1368
- var potentialDelta = Math.abs(potentialSolution.chroma - chroma);
1369
- var currentDelta = Math.abs(closestToChroma.chroma - chroma);
1370
- if (potentialDelta < currentDelta) {
1371
- closestToChroma = potentialSolution;
1372
- }
1373
- chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
1374
- }
1375
- }
1376
- return answer;
1377
- }
1378
- var defaultColors = function defaultColors(colorService) {
1379
- return {
1380
- fromPalettes: ['primary', 'secondary', 'tertiary'],
1381
- colors: {
1382
- background: {
1383
- palette: function palette(s) {
1384
- return s.getPalette('neutral');
1385
- },
1386
- tone: function tone(s) {
1387
- return s.isDark ? 6 : 98;
1388
- },
1389
- isBackground: true
1390
- },
1391
- onBackground: {
1392
- palette: function palette(s) {
1393
- return s.getPalette('neutral');
1394
- },
1395
- tone: function tone(s) {
1396
- return s.isDark ? 90 : 10;
1397
- },
1398
- background: function background(s) {
1399
- return colorService.getColor('background').getDynamicColor();
1400
- },
1401
- contrastCurve: new ContrastCurve(3, 3, 4.5, 7)
1402
- },
1403
- surface: {
1404
- palette: function palette(s) {
1405
- return s.getPalette('neutral');
1406
- },
1407
- tone: function tone(s) {
1408
- return s.isDark ? 6 : 98;
1409
- },
1410
- isBackground: true
1411
- },
1412
- surfaceDim: {
1413
- palette: function palette(s) {
1414
- return s.getPalette('neutral');
1415
- },
1416
- tone: function tone(s) {
1417
- return s.isDark ? 6 : 87;
1418
- },
1419
- isBackground: true
1420
- },
1421
- surfaceBright: {
1422
- palette: function palette(s) {
1423
- return s.getPalette('neutral');
1424
- },
1425
- tone: function tone(s) {
1426
- return s.isDark ? 24 : 98;
1427
- },
1428
- isBackground: true
1429
- },
1430
- surfaceContainerLowest: {
1431
- palette: function palette(s) {
1432
- return s.getPalette('neutral');
1433
- },
1434
- tone: function tone(s) {
1435
- return s.isDark ? 4 : 100;
1436
- },
1437
- isBackground: true
1438
- },
1439
- surfaceContainerLow: {
1440
- palette: function palette(s) {
1441
- return s.getPalette('neutral');
1442
- },
1443
- tone: function tone(s) {
1444
- return s.isDark ? 10 : 96;
1445
- },
1446
- isBackground: true
1447
- },
1448
- surfaceContainer: {
1449
- palette: function palette(s) {
1450
- return s.getPalette('neutral');
1451
- },
1452
- tone: function tone(s) {
1453
- return s.isDark ? 12 : 94;
1454
- },
1455
- isBackground: true
1456
- },
1457
- surfaceContainerHigh: {
1458
- palette: function palette(s) {
1459
- return s.getPalette('neutral');
1460
- },
1461
- tone: function tone(s) {
1462
- return s.isDark ? 17 : 92;
1463
- },
1464
- isBackground: true
1465
- },
1466
- surfaceContainerHighest: {
1467
- palette: function palette(s) {
1468
- return s.getPalette('neutral');
1469
- },
1470
- tone: function tone(s) {
1471
- return s.isDark ? 22 : 90;
1472
- },
1473
- isBackground: true
1474
- },
1475
- onSurface: {
1476
- palette: function palette(s) {
1477
- return s.getPalette('neutral');
1478
- },
1479
- tone: function tone(s) {
1480
- return s.isDark ? 90 : 10;
1481
- },
1482
- background: function background(s) {
1483
- return highestSurface(s, colorService);
1484
- },
1485
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1486
- },
1487
- surfaceVariant: {
1488
- palette: function palette(s) {
1489
- return s.getPalette('neutralVariant');
1490
- },
1491
- tone: function tone(s) {
1492
- return s.isDark ? 30 : 90;
1493
- },
1494
- isBackground: true
1495
- },
1496
- onSurfaceVariant: {
1497
- palette: function palette(s) {
1498
- return s.getPalette('neutralVariant');
1499
- },
1500
- tone: function tone(s) {
1501
- return s.isDark ? 80 : 30;
1502
- },
1503
- background: function background(s) {
1504
- return highestSurface(s, colorService);
1505
- },
1506
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1507
- },
1508
- inverseSurface: {
1509
- palette: function palette(s) {
1510
- return s.getPalette('neutral');
1511
- },
1512
- tone: function tone(s) {
1513
- return s.isDark ? 90 : 20;
1514
- }
1515
- },
1516
- inverseOnSurface: {
1517
- palette: function palette(s) {
1518
- return s.getPalette('neutral');
1519
- },
1520
- tone: function tone(s) {
1521
- return s.isDark ? 20 : 95;
1522
- },
1523
- background: function background(s) {
1524
- return colorService.getColor('inverseSurface').getDynamicColor();
1525
- },
1526
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1527
- },
1528
- outline: {
1529
- palette: function palette(s) {
1530
- return s.getPalette('neutralVariant');
1531
- },
1532
- tone: function tone(s) {
1533
- return s.isDark ? 60 : 50;
1534
- },
1535
- background: function background(s) {
1536
- return highestSurface(s, colorService);
1537
- },
1538
- contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7)
1539
- },
1540
- outlineVariant: {
1541
- palette: function palette(s) {
1542
- return s.getPalette('neutralVariant');
1543
- },
1544
- tone: function tone(s) {
1545
- return s.isDark ? 30 : 80;
1546
- },
1547
- background: function background(s) {
1548
- return highestSurface(s, colorService);
1549
- },
1550
- contrastCurve: new ContrastCurve(1, 1, 3, 7)
1551
- },
1552
- shadow: {
1553
- palette: function palette(s) {
1554
- return s.getPalette('neutral');
1555
- },
1556
- tone: function tone(s) {
1557
- return 0;
1558
- }
1559
- },
1560
- scrim: {
1561
- palette: function palette(s) {
1562
- return s.getPalette('neutral');
1563
- },
1564
- tone: function tone(s) {
1565
- return 0;
1566
- }
1567
- },
1568
- surfaceTint: {
1569
- palette: function palette(s) {
1570
- return s.getPalette('neutral');
1571
- },
1572
- tone: function tone(s) {
1573
- return s.isDark ? 80 : 40;
1574
- },
1575
- isBackground: true
1576
- },
1577
- secondaryContainer: {
1578
- tone: function tone(s) {
1579
- var initialTone = s.isDark ? 30 : 90;
1580
- return findDesiredChromaByTone(s.getPalette('secondary').hue, s.getPalette('secondary').chroma, initialTone, !s.isDark);
1581
- }
1582
- },
1583
- onSecondaryContainer: {
1584
- tone: function tone(s) {
1585
- return DynamicColor.foregroundTone(colorService.getColor('secondaryContainer').getDynamicColor().tone(s), 4.5);
1586
- }
1587
- },
1588
- tertiaryContainer: {
1589
- palette: function palette(s) {
1590
- return s.getPalette('tertiary');
1591
- },
1592
- tone: function tone(s) {
1593
- var proposedHct = s.getPalette('tertiary').getHct(s.sourceColorHct.tone);
1594
- return materialColorUtilities.DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
1595
- }
1596
- },
1597
- onTertiaryContainer: {
1598
- palette: function palette(s) {
1599
- return s.getPalette('tertiary');
1600
- },
1601
- tone: function tone(s) {
1602
- return DynamicColor.foregroundTone(colorService.getColor('tertiaryContainer').getDynamicColor().tone(s), 4.5);
1603
- }
1604
- },
1605
- error: {
1606
- palette: function palette(s) {
1607
- return s.getPalette('error');
1608
- },
1609
- tone: function tone(s) {
1610
- return s.isDark ? 80 : 40;
1611
- },
1612
- isBackground: true,
1613
- background: function background(s) {
1614
- return highestSurface(s, colorService);
1615
- },
1616
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
1617
- toneDeltaPair: function toneDeltaPair(s) {
1618
- return new ToneDeltaPair(colorService.getColor('errorContainer').getDynamicColor(), colorService.getColor('error').getDynamicColor(), 15, 'nearer', false);
1619
- }
1620
- },
1621
- onError: {
1622
- palette: function palette(s) {
1623
- return s.getPalette('error');
1624
- },
1625
- tone: function tone(s) {
1626
- return s.isDark ? 20 : 100;
1627
- },
1628
- background: function background(s) {
1629
- return colorService.getColor('error').getDynamicColor();
1630
- },
1631
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1632
- },
1633
- errorContainer: {
1634
- palette: function palette(s) {
1635
- return s.getPalette('error');
1636
- },
1637
- tone: function tone(s) {
1638
- return s.isDark ? 30 : 90;
1639
- },
1640
- isBackground: true,
1641
- background: function background(s) {
1642
- return highestSurface(s, colorService);
1643
- },
1644
- contrastCurve: new ContrastCurve(1, 1, 3, 7),
1645
- toneDeltaPair: function toneDeltaPair(s) {
1646
- return new ToneDeltaPair(colorService.getColor('errorContainer').getDynamicColor(), colorService.getColor('error').getDynamicColor(), 15, 'nearer', false);
1647
- }
1648
- },
1649
- onErrorContainer: {
1650
- palette: function palette(s) {
1651
- return s.getPalette('error');
1652
- },
1653
- tone: function tone(s) {
1654
- return s.isDark ? 90 : 10;
1655
- },
1656
- background: function background(s) {
1657
- return colorService.getColor('errorContainer').getDynamicColor();
1658
- },
1659
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1660
- },
1661
- onTertiaryFixed: {
1662
- palette: function palette(s) {
1663
- return s.getPalette('tertiary');
1664
- },
1665
- tone: function tone(s) {
1666
- return 10.0;
1667
- },
1668
- background: function background(s) {
1669
- return colorService.getColor('tertiaryFixedDim').getDynamicColor();
1670
- },
1671
- secondBackground: function secondBackground(s) {
1672
- return colorService.getColor('tertiaryFixed').getDynamicColor();
1673
- },
1674
- contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1675
- },
1676
- onTertiaryFixedVariant: {
1677
- palette: function palette(s) {
1678
- return s.getPalette('tertiary');
1679
- },
1680
- tone: function tone(s) {
1681
- return 30.0;
1682
- },
1683
- background: function background(s) {
1684
- return colorService.getColor('tertiaryFixedDim').getDynamicColor();
1685
- },
1686
- secondBackground: function secondBackground(s) {
1687
- return colorService.getColor('tertiaryFixed').getDynamicColor();
1688
- },
1689
- contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1690
- }
1691
- }
1692
- };
1693
- };
1694
-
1695
- var getRotatedHue = function getRotatedHue(sourceColor, hues, rotations) {
1696
- var sourceHue = sourceColor.hue;
1697
- if (hues.length !== rotations.length) {
1698
- throw new Error("mismatch between hue length " + hues.length + " & rotations " + rotations.length);
1699
- }
1700
- if (rotations.length === 1) {
1701
- return materialColorUtilities.sanitizeDegreesDouble(sourceColor.hue + rotations[0]);
1702
- }
1703
- var size = hues.length;
1704
- for (var i = 0; i <= size - 2; i++) {
1705
- var thisHue = hues[i];
1706
- var nextHue = hues[i + 1];
1707
- if (thisHue < sourceHue && sourceHue < nextHue) {
1708
- return materialColorUtilities.sanitizeDegreesDouble(sourceHue + rotations[i]);
1709
- }
1710
- }
1711
- // If this statement executes, something is wrong, there should have been a
1712
- // rotation found using the arrays.
1713
- return sourceHue;
1714
- };
1715
- var VariantEntity = function VariantEntity(palettes, customPalettes) {
1716
- if (palettes === void 0) {
1717
- palettes = {};
1718
- }
1719
- this.palettes = void 0;
1720
- this.customPalettes = void 0;
1721
- this.palettes = palettes;
1722
- this.customPalettes = customPalettes;
1723
- };
1724
-
1725
- var _VariantModel;
1726
- var VariantModel = function VariantModel() {};
1727
- _VariantModel = VariantModel;
1728
- VariantModel.tonalSpot = {
1729
- palettes: {
1730
- primary: function primary(sourceColorHct) {
1731
- return materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 36.0);
1732
- },
1733
- secondary: function secondary(sourceColorHct) {
1734
- return materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16.0);
1735
- },
1736
- tertiary: function tertiary(sourceColorHct) {
1737
- return materialColorUtilities.TonalPalette.fromHueAndChroma(materialColorUtilities.sanitizeDegreesDouble(sourceColorHct.hue + 60.0), 24.0);
1738
- },
1739
- neutral: function neutral(sourceColorHct) {
1740
- return materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 6.0);
1741
- },
1742
- neutralVariant: function neutralVariant(sourceColorHct) {
1743
- return materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0);
1744
- }
1745
- },
1746
- customPalettes: function customPalettes(colorHct) {
1747
- return materialColorUtilities.TonalPalette.fromHueAndChroma(colorHct.hue, 16);
1748
- }
1749
- };
1750
- VariantModel.vibrant = {
1751
- palettes: {
1752
- primary: function primary(sourceColorHct) {
1753
- return materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 200.0);
1754
- },
1755
- secondary: function secondary(sourceColorHct) {
1756
- return materialColorUtilities.TonalPalette.fromHueAndChroma(getRotatedHue(sourceColorHct, _VariantModel.hues, _VariantModel.secondaryRotations), 24.0);
1757
- },
1758
- tertiary: function tertiary(sourceColorHct) {
1759
- return materialColorUtilities.TonalPalette.fromHueAndChroma(getRotatedHue(sourceColorHct, _VariantModel.hues, _VariantModel.tertiaryRotations), 32.0);
1760
- },
1761
- neutral: function neutral(sourceColorHct) {
1762
- return materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 6.0);
1763
- },
1764
- neutralVariant: function neutralVariant(sourceColorHct) {
1765
- return materialColorUtilities.TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0);
1766
- }
1767
- },
1768
- customPalettes: function customPalettes(colorHct) {
1769
- return materialColorUtilities.TonalPalette.fromHueAndChroma(getRotatedHue(colorHct, _VariantModel.hues, _VariantModel.secondaryRotations), 24.0);
1770
- }
1771
- };
1772
- VariantModel.hues = [0.0, 41.0, 61.0, 101.0, 131.0, 181.0, 251.0, 301.0, 360.0];
1773
- VariantModel.secondaryRotations = [18.0, 15.0, 10.0, 12.0, 15.0, 18.0, 15.0, 12.0, 12.0];
1774
- VariantModel.tertiaryRotations = [35.0, 30.0, 20.0, 25.0, 30.0, 35.0, 30.0, 25.0, 25.0];
1775
-
1776
- function defineConfig(configObject) {
1777
- if (!configObject || typeof configObject !== 'object') {
1778
- throw new Error('The configuration is missing or not an object');
1779
- }
1780
- if (!('sourceColor' in configObject)) {
1781
- throw new Error('Invalid configuration');
1782
- }
1783
- return configObject;
1784
- }
1785
- var ConfigService = /*#__PURE__*/function () {
1786
- function ConfigService(_ref) {
1787
- var appService = _ref.appService;
1788
- this.configPath = './theme.config.ts';
1789
- this.appService = void 0;
1790
- this.appService = appService;
1791
- }
1792
- var _proto = ConfigService.prototype;
1793
- _proto.loadConfig = /*#__PURE__*/function () {
1794
- var _loadConfig = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1795
- 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;
1796
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1797
- while (1) switch (_context.prev = _context.next) {
1798
- case 0:
1799
- _this$appService = this.appService, themeService = _this$appService.themeService, colorService = _this$appService.colorService, pluginService = _this$appService.pluginService;
1800
- _context.next = 3;
1801
- return this.getConfig();
1802
- case 3:
1803
- _yield$this$getConfig = _context.sent;
1804
- sourceColor = _yield$this$getConfig.sourceColor;
1805
- _yield$this$getConfig2 = _yield$this$getConfig.contrastLevel;
1806
- contrastLevel = _yield$this$getConfig2 === void 0 ? 0 : _yield$this$getConfig2;
1807
- _yield$this$getConfig3 = _yield$this$getConfig.isDark;
1808
- isDark = _yield$this$getConfig3 === void 0 ? false : _yield$this$getConfig3;
1809
- _yield$this$getConfig4 = _yield$this$getConfig.variant;
1810
- variant = _yield$this$getConfig4 === void 0 ? VariantModel.tonalSpot : _yield$this$getConfig4;
1811
- palettes = _yield$this$getConfig.palettes;
1812
- colors = _yield$this$getConfig.colors;
1813
- _yield$this$getConfig5 = _yield$this$getConfig.useDefaultColors;
1814
- useDefaultColors = _yield$this$getConfig5 === void 0 ? true : _yield$this$getConfig5;
1815
- plugins = _yield$this$getConfig.plugins;
1816
- themeService.create({
1817
- contrastLevel: contrastLevel,
1818
- isDark: isDark,
1819
- sourceColorHex: sourceColor,
1820
- variant: variant
1821
- });
1822
- if (palettes) {
1823
- Object.entries(palettes).forEach(function (_ref2) {
1824
- var key = _ref2[0],
1825
- value = _ref2[1];
1826
- return themeService.addCustomPalette(key, value);
1827
- });
1828
- }
1829
- if (useDefaultColors) {
1830
- colorService.addColors(defaultColors);
1831
- }
1832
- if (colors) {
1833
- colorService.addColors(colors);
1834
- }
1835
- if (plugins) {
1836
- plugins.forEach(function (plugin) {
1837
- return pluginService.addPlugin(plugin);
1838
- });
1839
- pluginService.loadPlugins(this.appService);
1840
- }
1841
- case 21:
1842
- case "end":
1843
- return _context.stop();
1844
- }
1845
- }, _callee, this);
1846
- }));
1847
- function loadConfig() {
1848
- return _loadConfig.apply(this, arguments);
1849
- }
1850
- return loadConfig;
1851
- }();
1852
- _proto.getConfig = /*#__PURE__*/function () {
1853
- var _getConfig = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1854
- var path$1, configImport, config;
1855
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1856
- while (1) switch (_context2.prev = _context2.next) {
1857
- case 0:
1858
- path$1 = path.resolve(this.configPath);
1859
- _context2.next = 3;
1860
- return import(path$1);
1861
- case 3:
1862
- configImport = _context2.sent;
1863
- config = configImport["default"];
1864
- return _context2.abrupt("return", config);
1865
- case 6:
1866
- case "end":
1867
- return _context2.stop();
1868
- }
1869
- }, _callee2, this);
1870
- }));
1871
- function getConfig() {
1872
- return _getConfig.apply(this, arguments);
1873
- }
1874
- return getConfig;
1875
- }();
1876
- return ConfigService;
1877
- }();
1878
-
1879
- var ConfigModule = {
1880
- configService: /*#__PURE__*/awilix.asClass(ConfigService).singleton()
1881
- };
1882
-
1883
- var PluginService = /*#__PURE__*/function () {
1884
- function PluginService() {
1885
- this.pluginInstances = new Map();
1886
- this.pluginConstructors = new Map();
1887
- }
1888
- var _proto = PluginService.prototype;
1889
- _proto.addPlugin = function addPlugin(plugin) {
1890
- this.pluginConstructors.set(plugin.name, plugin);
1891
- };
1892
- _proto.loadPlugins = function loadPlugins(appService) {
1893
- var _this = this;
1894
- this.pluginConstructors.forEach(function (plugin) {
1895
- _this.pluginInstances.set(plugin.name, new plugin(appService));
1896
- });
1897
- };
1898
- _proto.getPlugin = function getPlugin(plugin) {
1899
- return this.pluginInstances.get(plugin.name);
1900
- };
1901
- return PluginService;
1902
- }();
1903
-
1904
- var PluginModule = {
1905
- pluginService: /*#__PURE__*/awilix.asClass(PluginService).singleton()
1906
- };
1907
-
1908
- function importContainer(container, services) {
1909
- services.forEach(function (service) {
1910
- Object.entries(service).forEach(function (_ref) {
1911
- var name = _ref[0],
1912
- serviceClass = _ref[1];
1913
- container.register(name, serviceClass);
1914
- });
1915
- });
1916
- return container;
1917
- }
1918
- var AppContainer = /*#__PURE__*/awilix.createContainer({
1919
- injectionMode: awilix.InjectionMode.PROXY
1920
- });
1921
- importContainer(AppContainer, [ConfigModule, AppModule, PluginModule, ColorModule, ThemeModule]);
1922
-
1923
- function bootstrap() {
1924
- return AppContainer.resolve('appService');
1925
- }
1926
- function bootstrapFromConfig(_x) {
1927
- return _bootstrapFromConfig.apply(this, arguments);
1928
- }
1929
- function _bootstrapFromConfig() {
1930
- _bootstrapFromConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(path) {
1931
- var configService;
1932
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1933
- while (1) switch (_context.prev = _context.next) {
1934
- case 0:
1935
- configService = AppContainer.resolve('configService');
1936
- if (path) configService.configPath = path;
1937
- _context.next = 4;
1938
- return configService.loadConfig();
1939
- case 4:
1940
- return _context.abrupt("return", AppContainer.resolve('appService'));
1941
- case 5:
1942
- case "end":
1943
- return _context.stop();
1944
- }
1945
- }, _callee);
1946
- }));
1947
- return _bootstrapFromConfig.apply(this, arguments);
1948
- }
1949
-
1950
- exports.AppContainer = AppContainer;
1951
- exports.AppModule = AppModule;
1952
- exports.AppService = AppService;
1953
- exports.ColorEntity = ColorEntity;
1954
- exports.ColorManagerService = ColorManagerService;
1955
- exports.ColorModule = ColorModule;
1956
- exports.ColorService = ColorService;
1957
- exports.ConfigService = ConfigService;
1958
- exports.ContrastCurve = ContrastCurve;
1959
- exports.DynamicColor = DynamicColor;
1960
- exports.SchemeEntity = SchemeEntity;
1961
- exports.SchemeService = SchemeService;
1962
- exports.ThemeModule = ThemeModule;
1963
- exports.ThemeService = ThemeService;
1964
- exports.ToneDeltaPair = ToneDeltaPair;
1965
- exports.VariantEntity = VariantEntity;
1966
- exports.VariantModel = VariantModel;
1967
- exports.VariantService = VariantService;
1968
- exports.bootstrap = bootstrap;
1969
- exports.bootstrapFromConfig = bootstrapFromConfig;
1970
- exports.defaultColors = defaultColors;
1971
- exports.defineConfig = defineConfig;
1972
- exports.getRotatedHue = getRotatedHue;
1973
- exports.highestSurface = highestSurface;
1974
- exports.importContainer = importContainer;
1975
- //# sourceMappingURL=theme.cjs.development.js.map