@tstdl/base 0.81.22 → 0.81.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.81.22",
3
+ "version": "0.81.23",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "luxon": "^3.1",
19
19
  "reflect-metadata": "^0.1",
20
- "rxjs": "^7.6",
20
+ "rxjs": "^7.8",
21
21
  "type-fest": "^2.19"
22
22
  },
23
23
  "devDependencies": {
@@ -47,7 +47,7 @@
47
47
  "koa": "^2.14",
48
48
  "minio": "^7.0",
49
49
  "mjml": "^4.13",
50
- "mongodb": "4.12",
50
+ "mongodb": "4.13",
51
51
  "nodemailer": "^6.8",
52
52
  "puppeteer": "^19.4",
53
53
  "undici": "^5.14",
package/rxjs/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './cast';
2
2
  export * from './intersection-observer';
3
+ export * from './media-query';
3
4
  export * from './mutation-observer';
4
5
  export * from './noop';
5
6
  export * from './performance-observer';
package/rxjs/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./cast"), exports);
18
18
  __exportStar(require("./intersection-observer"), exports);
19
+ __exportStar(require("./media-query"), exports);
19
20
  __exportStar(require("./mutation-observer"), exports);
20
21
  __exportStar(require("./noop"), exports);
21
22
  __exportStar(require("./performance-observer"), exports);
package/rxjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/rxjs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0DAAwC;AACxC,sDAAoC;AACpC,yCAAuB;AACvB,yDAAuC;AACvC,oDAAkC;AAClC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/rxjs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0DAAwC;AACxC,gDAA8B;AAC9B,sDAAoC;AACpC,yCAAuB;AACvB,yDAAuC;AACvC,oDAAkC;AAClC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB"}
@@ -0,0 +1,6 @@
1
+ import type { Observable } from 'rxjs';
2
+ /**
3
+ * creates an observable that emits whether the query matches
4
+ * @param query query to watch
5
+ */
6
+ export declare function observeMediaQuery(query: string): Observable<boolean>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.observeMediaQuery = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ /**
6
+ * creates an observable that emits whether the query matches
7
+ * @param query query to watch
8
+ */
9
+ function observeMediaQuery(query) {
10
+ const mediaQueryList = window.matchMedia(query);
11
+ return (0, rxjs_1.fromEvent)(mediaQueryList, 'change').pipe((0, rxjs_1.map)(() => mediaQueryList.matches));
12
+ }
13
+ exports.observeMediaQuery = observeMediaQuery;
14
+ //# sourceMappingURL=media-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-query.js","sourceRoot":"","sources":["../../source/rxjs/media-query.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AAEtC;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAChD,OAAO,IAAA,gBAAS,EAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAA,UAAG,EAAC,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;AACrF,CAAC;AAHD,8CAGC"}
@@ -1,4 +1,4 @@
1
- import type { Theme } from "../css/theme";
1
+ import type { Theme } from "../theme";
2
2
  export declare type TailwindPalette = {
3
3
  DEFAULT: string;
4
4
  50: string;
@@ -12,5 +12,6 @@ export declare type TailwindPalette = {
12
12
  800: string;
13
13
  900: string;
14
14
  };
15
- export declare function generateTailwindColors(theme: Theme): Record<string, TailwindPalette>;
15
+ export declare function generateTailwindColorsFromTheme(theme: Theme): Record<string, TailwindPalette>;
16
+ export declare function generateTailwindColorsFromThemeColors(colors: string[]): Record<string, TailwindPalette>;
16
17
  export declare function generateTailwindPalette(name: string): TailwindPalette;
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateTailwindPalette = exports.generateTailwindColors = void 0;
3
+ exports.generateTailwindPalette = exports.generateTailwindColorsFromThemeColors = exports.generateTailwindColorsFromTheme = void 0;
4
4
  const object_1 = require("../utils/object/object");
5
- const type_guards_1 = require("../utils/type-guards");
6
- function generateTailwindColors(theme) {
7
- const entries = (0, object_1.objectEntries)(theme.colors)
8
- .map(([colorName, value]) => {
9
- const name = (0, type_guards_1.isString)(value) ? colorName : (value.name ?? colorName);
10
- return [name, generateTailwindPalette(name)];
11
- });
5
+ function generateTailwindColorsFromTheme(theme) {
6
+ const colors = (0, object_1.objectKeys)(theme.palette);
7
+ return generateTailwindColorsFromThemeColors(colors);
8
+ }
9
+ exports.generateTailwindColorsFromTheme = generateTailwindColorsFromTheme;
10
+ function generateTailwindColorsFromThemeColors(colors) {
11
+ const entries = colors
12
+ .flatMap((color) => [[color, generateTailwindPalette(color)], [`${color}-contrast`, generateTailwindPalette(color)]]);
12
13
  return Object.fromEntries(entries);
13
14
  }
14
- exports.generateTailwindColors = generateTailwindColors;
15
+ exports.generateTailwindColorsFromThemeColors = generateTailwindColorsFromThemeColors;
15
16
  function generateTailwindPalette(name) {
16
17
  return {
17
18
  /* eslint-disable @typescript-eslint/naming-convention */
@@ -1 +1 @@
1
- {"version":3,"file":"colors.js","sourceRoot":"","sources":["../../source/tailwind/colors.ts"],"names":[],"mappings":";;;AACA,mDAAsD;AACtD,sDAA+C;AAkB/C,SAAgB,sBAAsB,CAAC,KAAY;IACjD,MAAM,OAAO,GAAG,IAAA,sBAAa,EAAC,KAAK,CAAC,MAAM,CAAC;SACxC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1B,MAAM,IAAI,GAAG,IAAA,sBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;QACrE,OAAO,CAAC,IAAI,EAAE,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEL,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAoC,CAAC;AACxE,CAAC;AARD,wDAQC;AAED,SAAgB,uBAAuB,CAAC,IAAY;IAClD,OAAO;QACL,yDAAyD;QACzD,OAAO,EAAE,eAAe,IAAI,GAAG;QAC/B,EAAE,EAAE,eAAe,IAAI,MAAM;QAC7B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,wDAAwD;KACzD,CAAC;AACJ,CAAC;AAhBD,0DAgBC"}
1
+ {"version":3,"file":"colors.js","sourceRoot":"","sources":["../../source/tailwind/colors.ts"],"names":[],"mappings":";;;AACA,mDAAmD;AAkBnD,SAAgB,+BAA+B,CAAC,KAAY;IAC1D,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,qCAAqC,CAAC,MAAM,CAAC,CAAC;AACvD,CAAC;AAHD,0EAGC;AAED,SAAgB,qCAAqC,CAAC,MAAgB;IACpE,MAAM,OAAO,GAAG,MAAM;SACnB,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,uBAAuB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,WAAW,EAAE,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAExH,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAoC,CAAC;AACxE,CAAC;AALD,sFAKC;AAED,SAAgB,uBAAuB,CAAC,IAAY;IAClD,OAAO;QACL,yDAAyD;QACzD,OAAO,EAAE,eAAe,IAAI,GAAG;QAC/B,EAAE,EAAE,eAAe,IAAI,MAAM;QAC7B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,GAAG,EAAE,eAAe,IAAI,OAAO;QAC/B,wDAAwD;KACzD,CAAC;AACJ,CAAC;AAhBD,0DAgBC"}
@@ -0,0 +1,5 @@
1
+ import type { ThemeService } from '../theme-service';
2
+ export interface CssThemeAdapter {
3
+ destroy(): void;
4
+ }
5
+ export declare function cssThemeAdapter(themeService: ThemeService<any>): CssThemeAdapter;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cssThemeAdapter = void 0;
4
+ const object_1 = require("../../utils/object");
5
+ const string_1 = require("../../utils/string");
6
+ const theme_service_1 = require("../theme-service");
7
+ function cssThemeAdapter(themeService) {
8
+ const variablesStyleElement = document.createElement('style');
9
+ const classesStyleElement = document.createElement('style');
10
+ const classes = generateClasses(themeService.colors);
11
+ classesStyleElement.innerHTML = classes.join('\n');
12
+ themeService.calculatedTheme$.subscribe((theme) => {
13
+ const variables = generateVariables(theme.palette);
14
+ variablesStyleElement.innerHTML = `:root {
15
+ ${variables.join('\n')}
16
+ }`;
17
+ });
18
+ document.head.appendChild(variablesStyleElement);
19
+ document.head.appendChild(classesStyleElement);
20
+ return {
21
+ destroy() {
22
+ variablesStyleElement.remove();
23
+ classesStyleElement.remove();
24
+ }
25
+ };
26
+ }
27
+ exports.cssThemeAdapter = cssThemeAdapter;
28
+ function generateVariables(palette) {
29
+ const entries = (0, object_1.objectEntries)(palette);
30
+ return entries.flatMap(([color, { main, contrast }]) => [
31
+ `--color-${(0, string_1.hyphenate)(color)}: ${main.base};`,
32
+ ...theme_service_1.themeColorTones.map((tone) => `--color-${(0, string_1.hyphenate)(color)}-${tone}: ${main[tone]};`),
33
+ `--color-${(0, string_1.hyphenate)(color)}-contrast: ${contrast.base};`,
34
+ ...theme_service_1.themeColorTones.map((tone) => `--color-${(0, string_1.hyphenate)(color)}-contrast-${tone}: ${contrast[tone]};`)
35
+ ]);
36
+ }
37
+ function generateClasses(colors) {
38
+ const classes = [];
39
+ for (const color of colors) {
40
+ classes.push(`.theme-color-${color} {
41
+ background-color: var(--color-${(0, string_1.hyphenate)(color)});
42
+ color: var(--color-${(0, string_1.hyphenate)(color)}-contrast);
43
+ }`);
44
+ for (const tone of theme_service_1.themeColorTones) {
45
+ classes.push(`.theme-color-${color}-${tone} {
46
+ background-color: var(--color-${(0, string_1.hyphenate)(color)}-${tone});
47
+ color: var(--color-${(0, string_1.hyphenate)(color)}-contrast-${tone});
48
+ }`);
49
+ }
50
+ }
51
+ return classes;
52
+ }
53
+ //# sourceMappingURL=css-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-adapter.js","sourceRoot":"","sources":["../../../source/theme/adapters/css-adapter.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAC/C,+CAA2C;AAE3C,oDAAmD;AAMnD,SAAgB,eAAe,CAAC,YAA+B;IAC7D,MAAM,qBAAqB,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9D,MAAM,mBAAmB,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAE5D,MAAM,OAAO,GAAG,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACrD,mBAAmB,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnD,YAAY,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QAChD,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEnD,qBAAqB,CAAC,SAAS,GAAG;IAClC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;EACtB,CAAC;IACD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IACjD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;IAE/C,OAAO;QACL,OAAO;YACL,qBAAqB,CAAC,MAAM,EAAE,CAAC;YAC/B,mBAAmB,CAAC,MAAM,EAAE,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC;AAxBD,0CAwBC;AAED,SAAS,iBAAiB,CAAC,OAA0B;IACnD,MAAM,OAAO,GAAG,IAAA,sBAAa,EAAC,OAAO,CAAC,CAAC;IAEvC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QACtD,WAAW,IAAA,kBAAS,EAAC,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,GAAG;QAC5C,GAAG,+BAAe,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,IAAA,kBAAS,EAAC,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QAEvF,WAAW,IAAA,kBAAS,EAAC,KAAK,CAAC,cAAc,QAAQ,CAAC,IAAI,GAAG;QACzD,GAAG,+BAAe,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,IAAA,kBAAS,EAAC,KAAK,CAAC,aAAa,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;KACrG,CAAC,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAC,MAAgB;IACvC,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,OAAO,CAAC,IAAI,CACV,gBAAgB,KAAK;kCACO,IAAA,kBAAS,EAAC,KAAK,CAAC;uBAC3B,IAAA,kBAAS,EAAC,KAAK,CAAC;EACrC,CACG,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,+BAAe,EAAE;YAClC,OAAO,CAAC,IAAI,CACV,gBAAgB,KAAK,IAAI,IAAI;kCACH,IAAA,kBAAS,EAAC,KAAK,CAAC,IAAI,IAAI;uBACnC,IAAA,kBAAS,EAAC,KAAK,CAAC,aAAa,IAAI;EACtD,CACK,CAAC;SACH;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './theme-service';
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./theme.model"), exports);
18
- __exportStar(require("./theme.service"), exports);
17
+ __exportStar(require("./theme-service"), exports);
19
18
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/theme/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
@@ -0,0 +1,49 @@
1
+ import type { UnionToTuple } from "../types";
2
+ import type { Observable } from 'rxjs';
3
+ export declare type CalculatedPalette<Colors extends string = string> = {
4
+ [Color in Colors]: {
5
+ main: ColorTones;
6
+ contrast: ColorTones;
7
+ };
8
+ };
9
+ export declare type CalculatedTheme<Colors extends string = string> = {
10
+ name: string;
11
+ palette: CalculatedPalette<Colors>;
12
+ };
13
+ export declare type PaletteColor = string | {
14
+ main: string;
15
+ contrast?: string;
16
+ };
17
+ export declare type Theme<Colors extends string = string> = {
18
+ name: string;
19
+ palette: Palette<Colors>;
20
+ };
21
+ export declare type Palette<Colors extends string = string> = {
22
+ [Color in Colors]: PaletteColor;
23
+ };
24
+ export declare type ColorTones = {
25
+ base: string;
26
+ 50: string;
27
+ 100: string;
28
+ 200: string;
29
+ 300: string;
30
+ 400: string;
31
+ 500: string;
32
+ 600: string;
33
+ 700: string;
34
+ 800: string;
35
+ 900: string;
36
+ };
37
+ export declare const themeColorTones: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
38
+ export declare class ThemeService<Colors extends string = string> {
39
+ private readonly themeSubject;
40
+ private readonly calculatedThemeSubject;
41
+ private readonly defaultTheme;
42
+ readonly colors: UnionToTuple<Colors>;
43
+ readonly theme$: Observable<Theme<Colors>>;
44
+ readonly calculatedTheme$: Observable<CalculatedTheme<Colors>>;
45
+ get theme(): Theme<Colors>;
46
+ get calculatedTheme(): CalculatedTheme<Colors>;
47
+ constructor(defaultTheme: Theme<Colors>);
48
+ setTheme(theme: Theme<Colors> | undefined): void;
49
+ }
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ThemeService = exports.themeColorTones = void 0;
13
+ const container_1 = require("../container");
14
+ const array_1 = require("../utils/array/array");
15
+ const object_1 = require("../utils/object/object");
16
+ const type_guards_1 = require("../utils/type-guards");
17
+ const chroma = require("chroma-js");
18
+ const rxjs_1 = require("rxjs");
19
+ const white = chroma('white');
20
+ const black = chroma('black');
21
+ exports.themeColorTones = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
22
+ let ThemeService = class ThemeService {
23
+ themeSubject;
24
+ calculatedThemeSubject;
25
+ defaultTheme;
26
+ colors;
27
+ theme$;
28
+ calculatedTheme$;
29
+ get theme() {
30
+ return this.themeSubject.value;
31
+ }
32
+ get calculatedTheme() {
33
+ return this.calculatedThemeSubject.value;
34
+ }
35
+ constructor(defaultTheme) {
36
+ this.defaultTheme = defaultTheme;
37
+ this.colors = (0, object_1.objectKeys)(defaultTheme.palette);
38
+ this.themeSubject = new rxjs_1.BehaviorSubject(undefined);
39
+ this.calculatedThemeSubject = new rxjs_1.BehaviorSubject(undefined);
40
+ this.theme$ = this.themeSubject.asObservable();
41
+ this.calculatedTheme$ = this.calculatedThemeSubject.asObservable();
42
+ this.setTheme(undefined);
43
+ }
44
+ setTheme(theme) {
45
+ const newTheme = theme ?? this.defaultTheme;
46
+ const calculatedTheme = calculateTheme(newTheme);
47
+ this.themeSubject.next(newTheme);
48
+ this.calculatedThemeSubject.next(calculatedTheme);
49
+ }
50
+ };
51
+ ThemeService = __decorate([
52
+ (0, container_1.singleton)(),
53
+ __metadata("design:paramtypes", [Object])
54
+ ], ThemeService);
55
+ exports.ThemeService = ThemeService;
56
+ function getContrastColor(color) {
57
+ const contrastWhite = chroma.contrast(color, white);
58
+ const contrastBlack = chroma.contrast(color, black);
59
+ return (contrastWhite > contrastBlack) ? '#ffffff' : '#000000';
60
+ }
61
+ function calculateTheme(theme) {
62
+ const entries = (0, object_1.objectEntries)(theme.palette);
63
+ const calculatedTheme = {
64
+ name: theme.name,
65
+ palette: {}
66
+ };
67
+ for (const [color, palette] of entries) {
68
+ const mainBase = (0, type_guards_1.isString)(palette) ? palette : palette.main;
69
+ const contrastBase = ((0, type_guards_1.isObject)(palette) ? palette.contrast : undefined) ?? getContrastColor(mainBase);
70
+ const mainTones = generateColorTones(mainBase);
71
+ calculatedTheme.palette[color] = {
72
+ main: mainTones,
73
+ contrast: generateContrastColorTones(contrastBase, mainTones)
74
+ };
75
+ }
76
+ return calculatedTheme;
77
+ }
78
+ function generateColorTones(base) {
79
+ const colors = generateColors([base], undefined, 10, true, true);
80
+ return {
81
+ base: (0, type_guards_1.isString)(base) ? base : base.hex(),
82
+ 50: colors[0],
83
+ 100: colors[1],
84
+ 200: colors[2],
85
+ 300: colors[3],
86
+ 400: colors[4],
87
+ 500: colors[5],
88
+ 600: colors[6],
89
+ 700: colors[7],
90
+ 800: colors[8],
91
+ 900: colors[9]
92
+ };
93
+ }
94
+ function generateContrastColorTones(base, tones) {
95
+ return {
96
+ base: (0, type_guards_1.isString)(base) ? base : base.hex(),
97
+ 50: getContrastColor(tones[50]),
98
+ 100: getContrastColor(tones[100]),
99
+ 200: getContrastColor(tones[200]),
100
+ 300: getContrastColor(tones[300]),
101
+ 400: getContrastColor(tones[400]),
102
+ 500: getContrastColor(tones[500]),
103
+ 600: getContrastColor(tones[600]),
104
+ 700: getContrastColor(tones[700]),
105
+ 800: getContrastColor(tones[800]),
106
+ 900: getContrastColor(tones[900])
107
+ };
108
+ }
109
+ /**
110
+ * stolen from <https://github.com/gka/palettes/blob/master/src/PalettePreview.svelte>
111
+ */
112
+ function generateColors(baseColors, divergingColors, colorCount, bezier, correctLightness) {
113
+ const diverging = (0, type_guards_1.isDefined)(divergingColors) && (divergingColors.length > 0);
114
+ const even = (colorCount % 2) == 0;
115
+ const numColorsLeft = diverging ? Math.ceil(colorCount / 2) + (even ? 1 : 0) : colorCount;
116
+ const numColorsRight = diverging ? Math.ceil(colorCount / 2) + (even ? 1 : 0) : 0;
117
+ const genColors = (baseColors.length > 0)
118
+ ? (baseColors.length > 1)
119
+ ? baseColors
120
+ : autoColors(baseColors[0], numColorsLeft, diverging)
121
+ : [];
122
+ const genColors2 = diverging
123
+ ? (divergingColors.length > 1)
124
+ ? divergingColors
125
+ : autoColors(divergingColors[0], numColorsRight, diverging, true)
126
+ : [];
127
+ const stepsLeft = (baseColors.length > 0)
128
+ ? (bezier ? chroma.bezier(genColors).scale() : chroma.scale(genColors))
129
+ .correctLightness(correctLightness)
130
+ .colors(numColorsLeft)
131
+ : [];
132
+ const stepsRight = diverging
133
+ ? ((bezier && (divergingColors.length > 1)) ? chroma.bezier(genColors2).scale() : chroma.scale(genColors2))
134
+ .correctLightness(correctLightness)
135
+ .colors(numColorsRight)
136
+ : [];
137
+ const steps = (even && diverging ? stepsLeft.slice(0, stepsLeft.length - 1) : stepsLeft).concat(stepsRight.slice(1));
138
+ return steps;
139
+ }
140
+ function autoColors(color, numColors, diverging, reverse = false) {
141
+ if (diverging) {
142
+ const colors = autoGradient(color, 3, diverging).concat(chroma('#f5f5f5'));
143
+ if (reverse) {
144
+ return colors.reverse();
145
+ }
146
+ return colors;
147
+ }
148
+ return autoGradient(color, numColors, diverging);
149
+ }
150
+ function autoGradient(color, numColors, diverging) {
151
+ const lab = chroma(color).lab();
152
+ const lRange = 100 * ((0.95 - 1) / numColors);
153
+ const lStep = lRange / (numColors - 1);
154
+ const lStart = (100 - lRange) * 0.5;
155
+ const range = (0, array_1.createArray)(numColors, (i) => lStart + (i * lStep));
156
+ let offset = 0;
157
+ if (!diverging) {
158
+ offset = 9999;
159
+ for (let i = 0; i < numColors; i++) {
160
+ const diff = lab[0] - range[i];
161
+ if (Math.abs(diff) < Math.abs(offset)) {
162
+ offset = diff;
163
+ }
164
+ }
165
+ }
166
+ return range.map((l) => chroma.lab(l + offset, lab[1], lab[2]));
167
+ }
168
+ //# sourceMappingURL=theme-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-service.js","sourceRoot":"","sources":["../../source/theme/theme-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwC;AAExC,gDAAkD;AAClD,mDAAkE;AAClE,sDAAoE;AACpE,oCAAoC;AAEpC,+BAAuC;AA0CvC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAEjB,QAAA,eAAe,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAGnF,IAAM,YAAY,GAAlB,MAAM,YAAY;IACN,YAAY,CAAiC;IAC7C,sBAAsB,CAA2C;IACjE,YAAY,CAAgB;IAEpC,MAAM,CAAuB;IAC7B,MAAM,CAA4B;IAClC,gBAAgB,CAAsC;IAE/D,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;IAC3C,CAAC;IAED,YAAY,YAA2B;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI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C,CAAC,GAAG,SAAS,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC;IACpC,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IAElE,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,GAAG,IAAI,CAAC;QAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE;YAClC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;YAEhC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gBACrC,MAAM,GAAG,IAAI,CAAC;aACf;SACF;KACF;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function hyphenate(value: string): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hyphenate = void 0;
4
+ function hyphenate(value) {
5
+ return value.replace(/[A-Z]|[0-9]+/ug, (match) => `-${match}`);
6
+ }
7
+ exports.hyphenate = hyphenate;
8
+ //# sourceMappingURL=hypenate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hypenate.js","sourceRoot":"","sources":["../../../source/utils/string/hypenate.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;AACjE,CAAC;AAFD,8BAEC"}
@@ -0,0 +1 @@
1
+ export * from './hypenate';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hypenate"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/utils/string/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B"}
@@ -1,2 +0,0 @@
1
- export * from './theme.model';
2
- export * from './theme.service';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/css/theme/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,kDAAgC"}
@@ -1,8 +0,0 @@
1
- export declare type ThemeEntry<Name extends string = string> = string | {
2
- name?: Name;
3
- color: string;
4
- };
5
- export declare type Theme<T extends Record<string, ThemeEntry> = Record<string, ThemeEntry>> = {
6
- colors: T;
7
- };
8
- export declare function createTheme<T extends Theme>(theme: T): T;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTheme = void 0;
4
- function createTheme(theme) {
5
- return theme;
6
- }
7
- exports.createTheme = createTheme;
8
- //# sourceMappingURL=theme.model.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme.model.js","sourceRoot":"","sources":["../../../source/css/theme/theme.model.ts"],"names":[],"mappings":";;;AASA,SAAgB,WAAW,CAAkB,KAAQ;IACnD,OAAO,KAAK,CAAC;AACf,CAAC;AAFD,kCAEC"}
@@ -1,6 +0,0 @@
1
- import type { Theme } from './theme.model';
2
- export declare class ThemeService {
3
- private readonly styleElement;
4
- constructor(document: Document);
5
- setTheme(theme: Theme, darkTheme?: Theme): void;
6
- }
@@ -1,91 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ThemeService = void 0;
16
- const container_1 = require("../../container");
17
- const tokens_1 = require("../../tokens");
18
- const object_1 = require("../../utils/object/object");
19
- const type_guards_1 = require("../../utils/type-guards");
20
- const chroma = require("chroma-js");
21
- let ThemeService = class ThemeService {
22
- styleElement;
23
- constructor(document) {
24
- this.styleElement = document.createElement('style');
25
- document.head.appendChild(this.styleElement);
26
- }
27
- setTheme(theme, darkTheme) {
28
- const lightRules = buildThemeRules(theme);
29
- const darkRules = (0, type_guards_1.isDefined)(darkTheme) ? buildThemeRules(darkTheme) : [];
30
- const lightRulesString = lightRules.join('\n');
31
- const darkRulesString = darkRules.join('\n');
32
- this.styleElement.innerHTML = `
33
- @media (prefers-color-scheme: light) {
34
- :root, .light {
35
- ${lightRulesString}
36
- }
37
-
38
- .dark {
39
- ${darkRulesString}
40
- }
41
- }
42
-
43
- @media (prefers-color-scheme: dark) {
44
- :root, .dark {
45
- ${darkRulesString}
46
- }
47
-
48
- .light {
49
- ${lightRulesString}
50
- }
51
- }
52
- `;
53
- }
54
- };
55
- ThemeService = __decorate([
56
- (0, container_1.singleton)(),
57
- __param(0, (0, container_1.inject)(tokens_1.DOCUMENT)),
58
- __metadata("design:paramtypes", [Document])
59
- ], ThemeService);
60
- exports.ThemeService = ThemeService;
61
- function buildThemeRules(theme) {
62
- const rules = [];
63
- for (const [colorName, value] of (0, object_1.objectEntries)(theme.colors)) {
64
- const name = (0, type_guards_1.isString)(value) ? colorName : (value.name ?? colorName);
65
- const color = (0, type_guards_1.isString)(value) ? value : value.color;
66
- const colorRules = generatePaletteVariableDeclarations(name, color);
67
- rules.push(...colorRules);
68
- }
69
- return rules;
70
- }
71
- function generatePaletteVariableDeclarations(paletteName, color) {
72
- const chromaColor = chroma(color);
73
- const [hue, saturation, lightness] = chromaColor.hsl();
74
- const colors = {
75
- 50: chroma.hsl(hue, saturation, lightness + 0.50).css(),
76
- 100: chroma.hsl(hue, saturation, lightness + 0.40).css(),
77
- 200: chroma.hsl(hue, saturation, lightness + 0.30).css(),
78
- 300: chroma.hsl(hue, saturation, lightness + 0.20).css(),
79
- 400: chroma.hsl(hue, saturation, lightness + 0.10).css(),
80
- 500: chromaColor.css(),
81
- 600: chroma.hsl(hue, saturation, lightness - 0.10).css(),
82
- 700: chroma.hsl(hue, saturation, lightness - 0.20).css(),
83
- 800: chroma.hsl(hue, saturation, lightness - 0.30).css(),
84
- 900: chroma.hsl(hue, saturation, lightness - 0.40).css()
85
- };
86
- const colorEntries = (0, object_1.objectEntries)(colors);
87
- const variables = [[`--color-${paletteName}`, colors[500]], ...colorEntries.map(([number, numberColor]) => [`--color-${paletteName}-${number}`, numberColor])];
88
- const variableDeclarations = variables.map(([name, value]) => `${name}: ${value};`);
89
- return variableDeclarations;
90
- }
91
- //# sourceMappingURL=theme.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme.service.js","sourceRoot":"","sources":["../../../source/css/theme/theme.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAgD;AAChD,yCAAoC;AACpC,sDAAsD;AACtD,yDAA0D;AAC1D,oCAAoC;AAI7B,IAAM,YAAY,GAAlB,MAAM,YAAY;IACN,YAAY,CAAmB;IAEhD,YAA8B,QAAkB;QAC9C,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACpD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,QAAQ,CAAC,KAAY,EAAE,SAAiB;QACtC,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,IAAA,uBAAS,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,MAAM,gBAAgB,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,eAAe,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE7C,IAAI,CAAC,YAAY,CAAC,SAAS,GAAG;;;MAG5B,gBAAgB;;;;MAIhB,eAAe;;;;;;MAMf,eAAe;;;;MAIf,gBAA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