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