@udixio/theme 1.0.0-beta.2 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/theme.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NestFactory } from '@nestjs/core';
2
2
  import { __decorate, __metadata } from 'tslib';
3
3
  import { Injectable, Module } from '@nestjs/common';
4
- import { lerp, Contrast, clampDouble, hexFromArgb, Hct, argbFromHex, TonalPalette } from '@material/material-color-utilities';
4
+ import { lerp, Contrast, clampDouble, hexFromArgb, Hct, argbFromHex, DislikeAnalyzer, TonalPalette } from '@material/material-color-utilities';
5
5
  import mergeDeep from 'merge-deep';
6
6
 
7
7
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
@@ -841,7 +841,7 @@ var ColorEntity = /*#__PURE__*/function () {
841
841
  var _proto = ColorEntity.prototype;
842
842
  _proto.update = function update(args) {
843
843
  this.dynamicColor = null;
844
- this.option = mergeDeep(this.option, args);
844
+ this.option = _extends({}, this.option, args);
845
845
  };
846
846
  _proto.getHex = function getHex() {
847
847
  return hexFromArgb(this.getArgb());
@@ -913,7 +913,7 @@ var SchemeService = /*#__PURE__*/function () {
913
913
  }
914
914
  var _proto = SchemeService.prototype;
915
915
  _proto.createOrUpdate = function createOrUpdate(options) {
916
- this.options = mergeDeep(this.options, options);
916
+ this.options = mergeDeep(options, this.options);
917
917
  var palettes = new Map();
918
918
  var sourceColorArgb = argbFromHex(this.options.sourceColorHex);
919
919
  var sourceColorHct = Hct.fromInt(sourceColorArgb);
@@ -1139,6 +1139,344 @@ var ColorManagerService = /*#__PURE__*/function () {
1139
1139
  }();
1140
1140
  ColorManagerService = /*#__PURE__*/__decorate([/*#__PURE__*/Injectable(), /*#__PURE__*/__metadata("design:paramtypes", [SchemeService])], ColorManagerService);
1141
1141
 
1142
+ function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
1143
+ var answer = tone;
1144
+ var closestToChroma = Hct.from(hue, chroma, tone);
1145
+ if (closestToChroma.chroma < chroma) {
1146
+ var chromaPeak = closestToChroma.chroma;
1147
+ while (closestToChroma.chroma < chroma) {
1148
+ answer += byDecreasingTone ? -1.0 : 1.0;
1149
+ var potentialSolution = Hct.from(hue, chroma, answer);
1150
+ if (chromaPeak > potentialSolution.chroma) {
1151
+ break;
1152
+ }
1153
+ if (Math.abs(potentialSolution.chroma - chroma) < 0.4) {
1154
+ break;
1155
+ }
1156
+ var potentialDelta = Math.abs(potentialSolution.chroma - chroma);
1157
+ var currentDelta = Math.abs(closestToChroma.chroma - chroma);
1158
+ if (potentialDelta < currentDelta) {
1159
+ closestToChroma = potentialSolution;
1160
+ }
1161
+ chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
1162
+ }
1163
+ }
1164
+ return answer;
1165
+ }
1166
+ var defaultColors = function defaultColors(colorManagerService) {
1167
+ return {
1168
+ background: {
1169
+ palette: function palette(s) {
1170
+ return s.getPalette('neutral');
1171
+ },
1172
+ tone: function tone(s) {
1173
+ return s.isDark ? 6 : 98;
1174
+ },
1175
+ isBackground: true
1176
+ },
1177
+ onBackground: {
1178
+ palette: function palette(s) {
1179
+ return s.getPalette('neutral');
1180
+ },
1181
+ tone: function tone(s) {
1182
+ return s.isDark ? 90 : 10;
1183
+ },
1184
+ background: function background(s) {
1185
+ return colorManagerService.get('background').getDynamicColor();
1186
+ },
1187
+ contrastCurve: new ContrastCurve(3, 3, 4.5, 7)
1188
+ },
1189
+ surface: {
1190
+ palette: function palette(s) {
1191
+ return s.getPalette('neutral');
1192
+ },
1193
+ tone: function tone(s) {
1194
+ return s.isDark ? 6 : 98;
1195
+ },
1196
+ isBackground: true
1197
+ },
1198
+ surfaceDim: {
1199
+ palette: function palette(s) {
1200
+ return s.getPalette('neutral');
1201
+ },
1202
+ tone: function tone(s) {
1203
+ return s.isDark ? 6 : 87;
1204
+ },
1205
+ isBackground: true
1206
+ },
1207
+ surfaceBright: {
1208
+ palette: function palette(s) {
1209
+ return s.getPalette('neutral');
1210
+ },
1211
+ tone: function tone(s) {
1212
+ return s.isDark ? 24 : 98;
1213
+ },
1214
+ isBackground: true
1215
+ },
1216
+ surfaceContainerLowest: {
1217
+ palette: function palette(s) {
1218
+ return s.getPalette('neutral');
1219
+ },
1220
+ tone: function tone(s) {
1221
+ return s.isDark ? 4 : 100;
1222
+ },
1223
+ isBackground: true
1224
+ },
1225
+ surfaceContainerLow: {
1226
+ palette: function palette(s) {
1227
+ return s.getPalette('neutral');
1228
+ },
1229
+ tone: function tone(s) {
1230
+ return s.isDark ? 10 : 96;
1231
+ },
1232
+ isBackground: true
1233
+ },
1234
+ surfaceContainer: {
1235
+ palette: function palette(s) {
1236
+ return s.getPalette('neutral');
1237
+ },
1238
+ tone: function tone(s) {
1239
+ return s.isDark ? 12 : 94;
1240
+ },
1241
+ isBackground: true
1242
+ },
1243
+ surfaceContainerHigh: {
1244
+ palette: function palette(s) {
1245
+ return s.getPalette('neutral');
1246
+ },
1247
+ tone: function tone(s) {
1248
+ return s.isDark ? 17 : 92;
1249
+ },
1250
+ isBackground: true
1251
+ },
1252
+ surfaceContainerHighest: {
1253
+ palette: function palette(s) {
1254
+ return s.getPalette('neutral');
1255
+ },
1256
+ tone: function tone(s) {
1257
+ return s.isDark ? 22 : 90;
1258
+ },
1259
+ isBackground: true
1260
+ },
1261
+ onSurface: {
1262
+ palette: function palette(s) {
1263
+ return s.getPalette('neutral');
1264
+ },
1265
+ tone: function tone(s) {
1266
+ return s.isDark ? 90 : 10;
1267
+ },
1268
+ background: function background(s) {
1269
+ return highestSurface(s, colorManagerService);
1270
+ },
1271
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1272
+ },
1273
+ surfaceVariant: {
1274
+ palette: function palette(s) {
1275
+ return s.getPalette('neutralVariant');
1276
+ },
1277
+ tone: function tone(s) {
1278
+ return s.isDark ? 30 : 90;
1279
+ },
1280
+ isBackground: true
1281
+ },
1282
+ onSurfaceVariant: {
1283
+ palette: function palette(s) {
1284
+ return s.getPalette('neutralVariant');
1285
+ },
1286
+ tone: function tone(s) {
1287
+ return s.isDark ? 80 : 30;
1288
+ },
1289
+ background: function background(s) {
1290
+ return highestSurface(s, colorManagerService);
1291
+ },
1292
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1293
+ },
1294
+ inverseSurface: {
1295
+ palette: function palette(s) {
1296
+ return s.getPalette('neutral');
1297
+ },
1298
+ tone: function tone(s) {
1299
+ return s.isDark ? 90 : 20;
1300
+ }
1301
+ },
1302
+ inverseOnSurface: {
1303
+ palette: function palette(s) {
1304
+ return s.getPalette('neutral');
1305
+ },
1306
+ tone: function tone(s) {
1307
+ return s.isDark ? 20 : 95;
1308
+ },
1309
+ background: function background(s) {
1310
+ return colorManagerService.get('inverseSurface').getDynamicColor();
1311
+ },
1312
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1313
+ },
1314
+ outline: {
1315
+ palette: function palette(s) {
1316
+ return s.getPalette('neutralVariant');
1317
+ },
1318
+ tone: function tone(s) {
1319
+ return s.isDark ? 60 : 50;
1320
+ },
1321
+ background: function background(s) {
1322
+ return highestSurface(s, colorManagerService);
1323
+ },
1324
+ contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7)
1325
+ },
1326
+ outlineVariant: {
1327
+ palette: function palette(s) {
1328
+ return s.getPalette('neutralVariant');
1329
+ },
1330
+ tone: function tone(s) {
1331
+ return s.isDark ? 30 : 80;
1332
+ },
1333
+ background: function background(s) {
1334
+ return highestSurface(s, colorManagerService);
1335
+ },
1336
+ contrastCurve: new ContrastCurve(1, 1, 3, 7)
1337
+ },
1338
+ shadow: {
1339
+ palette: function palette(s) {
1340
+ return s.getPalette('neutral');
1341
+ },
1342
+ tone: function tone(s) {
1343
+ return 0;
1344
+ }
1345
+ },
1346
+ scrim: {
1347
+ palette: function palette(s) {
1348
+ return s.getPalette('neutral');
1349
+ },
1350
+ tone: function tone(s) {
1351
+ return 0;
1352
+ }
1353
+ },
1354
+ surfaceTint: {
1355
+ palette: function palette(s) {
1356
+ return s.getPalette('neutral');
1357
+ },
1358
+ tone: function tone(s) {
1359
+ return s.isDark ? 80 : 40;
1360
+ },
1361
+ isBackground: true
1362
+ },
1363
+ secondaryContainer: {
1364
+ tone: function tone(s) {
1365
+ var initialTone = s.isDark ? 30 : 90;
1366
+ return findDesiredChromaByTone(s.getPalette('secondary').hue, s.getPalette('secondary').chroma, initialTone, !s.isDark);
1367
+ }
1368
+ },
1369
+ onSecondaryContainer: {
1370
+ tone: function tone(s) {
1371
+ return DynamicColor.foregroundTone(colorManagerService.get('secondaryContainer').getDynamicColor().tone(s), 4.5);
1372
+ }
1373
+ },
1374
+ tertiaryContainer: {
1375
+ palette: function palette(s) {
1376
+ return s.getPalette('tertiary');
1377
+ },
1378
+ tone: function tone(s) {
1379
+ var proposedHct = s.getPalette('tertiary').getHct(s.sourceColorHct.tone);
1380
+ return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
1381
+ }
1382
+ },
1383
+ onTertiaryContainer: {
1384
+ palette: function palette(s) {
1385
+ return s.getPalette('tertiary');
1386
+ },
1387
+ tone: function tone(s) {
1388
+ return DynamicColor.foregroundTone(colorManagerService.get('tertiaryContainer').getDynamicColor().tone(s), 4.5);
1389
+ }
1390
+ },
1391
+ error: {
1392
+ palette: function palette(s) {
1393
+ return s.getPalette('error');
1394
+ },
1395
+ tone: function tone(s) {
1396
+ return s.isDark ? 80 : 40;
1397
+ },
1398
+ isBackground: true,
1399
+ background: function background(s) {
1400
+ return highestSurface(s, colorManagerService);
1401
+ },
1402
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
1403
+ toneDeltaPair: function toneDeltaPair(s) {
1404
+ return new ToneDeltaPair(colorManagerService.get('errorContainer').getDynamicColor(), colorManagerService.get('error').getDynamicColor(), 15, 'nearer', false);
1405
+ }
1406
+ },
1407
+ onError: {
1408
+ palette: function palette(s) {
1409
+ return s.getPalette('error');
1410
+ },
1411
+ tone: function tone(s) {
1412
+ return s.isDark ? 20 : 100;
1413
+ },
1414
+ background: function background(s) {
1415
+ return colorManagerService.get('error').getDynamicColor();
1416
+ },
1417
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1418
+ },
1419
+ errorContainer: {
1420
+ palette: function palette(s) {
1421
+ return s.getPalette('error');
1422
+ },
1423
+ tone: function tone(s) {
1424
+ return s.isDark ? 30 : 90;
1425
+ },
1426
+ isBackground: true,
1427
+ background: function background(s) {
1428
+ return highestSurface(s, colorManagerService);
1429
+ },
1430
+ contrastCurve: new ContrastCurve(1, 1, 3, 7),
1431
+ toneDeltaPair: function toneDeltaPair(s) {
1432
+ return new ToneDeltaPair(colorManagerService.get('errorContainer').getDynamicColor(), colorManagerService.get('error').getDynamicColor(), 15, 'nearer', false);
1433
+ }
1434
+ },
1435
+ onErrorContainer: {
1436
+ palette: function palette(s) {
1437
+ return s.getPalette('error');
1438
+ },
1439
+ tone: function tone(s) {
1440
+ return s.isDark ? 90 : 10;
1441
+ },
1442
+ background: function background(s) {
1443
+ return colorManagerService.get('errorContainer').getDynamicColor();
1444
+ },
1445
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1446
+ },
1447
+ onTertiaryFixed: {
1448
+ palette: function palette(s) {
1449
+ return s.getPalette('tertiary');
1450
+ },
1451
+ tone: function tone(s) {
1452
+ return 10.0;
1453
+ },
1454
+ background: function background(s) {
1455
+ return colorManagerService.get('tertiaryFixedDim').getDynamicColor();
1456
+ },
1457
+ secondBackground: function secondBackground(s) {
1458
+ return colorManagerService.get('tertiaryFixed').getDynamicColor();
1459
+ },
1460
+ contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
1461
+ },
1462
+ onTertiaryFixedVariant: {
1463
+ palette: function palette(s) {
1464
+ return s.getPalette('tertiary');
1465
+ },
1466
+ tone: function tone(s) {
1467
+ return 30.0;
1468
+ },
1469
+ background: function background(s) {
1470
+ return colorManagerService.get('tertiaryFixedDim').getDynamicColor();
1471
+ },
1472
+ secondBackground: function secondBackground(s) {
1473
+ return colorManagerService.get('tertiaryFixed').getDynamicColor();
1474
+ },
1475
+ contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
1476
+ }
1477
+ };
1478
+ };
1479
+
1142
1480
  var ColorService = /*#__PURE__*/function () {
1143
1481
  function ColorService(colorManagerService) {
1144
1482
  this.colorManagerService = void 0;
@@ -1157,23 +1495,26 @@ var ColorService = /*#__PURE__*/function () {
1157
1495
  //
1158
1496
  // return colors;
1159
1497
  // }
1160
- //
1161
- // addBaseColors() {
1162
- // this.colorManagerService.addFromPalette('primary');
1163
- // this.colorManagerService.addFromPalette('secondary');
1164
- // this.colorManagerService.addFromPalette('tertiary');
1165
- // for (const [key, value] of Object.entries(this.defaultColorModel.colors)) {
1166
- // this.colorManagerService.createOrUpdate(key, value as any);
1167
- // }
1168
- // }
1169
1498
  ;
1499
+ _proto.addBaseColors = function addBaseColors() {
1500
+ var _this = this;
1501
+ this.colorManagerService.addFromPalette('primary');
1502
+ this.colorManagerService.addFromPalette('secondary');
1503
+ this.colorManagerService.addFromPalette('tertiary');
1504
+ var colors = defaultColors(this.colorManagerService);
1505
+ Object.keys(colors).map(function (key) {
1506
+ var color = colors[key];
1507
+ if (!color) return;
1508
+ return _this.colorManagerService.createOrUpdate(key, color);
1509
+ });
1510
+ };
1170
1511
  _proto.addColor = function addColor(key, color) {
1171
1512
  return this.colorManagerService.createOrUpdate(key, color);
1172
1513
  };
1173
1514
  _proto.addColors = function addColors(colors) {
1174
- var _this = this;
1515
+ var _this2 = this;
1175
1516
  return Object.keys(colors).map(function (key) {
1176
- return _this.addColor(key, colors[key]);
1517
+ return _this2.addColor(key, colors[key]);
1177
1518
  });
1178
1519
  };
1179
1520
  _proto.getColor = function getColor(key) {