@tstdl/base 0.71.15 → 0.71.16

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.
@@ -0,0 +1,2 @@
1
+ export * from './theme.model';
2
+ export * from './theme.service';
@@ -0,0 +1,19 @@
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("./theme.model"), exports);
18
+ __exportStar(require("./theme.service"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/css/theme/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,kDAAgC"}
@@ -0,0 +1,8 @@
1
+ export declare type ThemeEntry = string | {
2
+ name?: string;
3
+ color: string;
4
+ };
5
+ export declare type Theme = {
6
+ isDark?: boolean;
7
+ colors: Record<string, ThemeEntry>;
8
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=theme.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.model.js","sourceRoot":"","sources":["../../../source/css/theme/theme.model.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
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
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThemeService = void 0;
4
+ const array_1 = require("../../utils/array/array");
5
+ const type_guards_1 = require("../../utils/type-guards");
6
+ const chroma = require("chroma-js");
7
+ const paletteNumbers = [50, ...(0, array_1.createArray)(9, (index) => (100 + (100 * index)))];
8
+ class ThemeService {
9
+ constructor(document) {
10
+ this.styleElement = document.createElement('style');
11
+ document.head.appendChild(this.styleElement);
12
+ }
13
+ setTheme(theme, darkTheme) {
14
+ const lightRules = buildThemeRules(theme);
15
+ const darkRules = (0, type_guards_1.isDefined)(darkTheme) ? buildThemeRules(darkTheme) : [];
16
+ const lightRulesString = lightRules.join('\n');
17
+ const darkRulesString = darkRules.join('\n');
18
+ this.styleElement.innerHTML = `
19
+ @media (prefers-color-scheme: light) {
20
+ :root, .light {
21
+ ${lightRulesString}
22
+ }
23
+
24
+ .dark {
25
+ ${darkRulesString}
26
+ }
27
+ }
28
+
29
+ @media (prefers-color-scheme: dark) {
30
+ :root, .dark {
31
+ ${darkRulesString}
32
+ }
33
+
34
+ .light {
35
+ ${lightRulesString}
36
+ }
37
+ }
38
+ `;
39
+ }
40
+ }
41
+ exports.ThemeService = ThemeService;
42
+ function buildThemeRules(theme) {
43
+ var _a, _b;
44
+ const rules = [];
45
+ for (const [colorName, value] of Object.entries(theme.colors)) {
46
+ const name = (0, type_guards_1.isString)(value) ? colorName : ((_a = value.name) !== null && _a !== void 0 ? _a : colorName);
47
+ const color = (0, type_guards_1.isString)(value) ? value : value.color;
48
+ const colorRules = generatePaletteVariableDeclarations(name, (_b = theme.isDark) !== null && _b !== void 0 ? _b : false, color);
49
+ rules.push(...colorRules);
50
+ }
51
+ return rules;
52
+ }
53
+ function generatePaletteVariableDeclarations(paletteName, isDark, color) {
54
+ const baseColor = isDark ? 'black' : 'white';
55
+ const colors = chroma.scale([baseColor, color]).colors(paletteNumbers.length);
56
+ const variables = [[`--color-${paletteName}`, color], ...paletteNumbers.map((number, index) => [`--color-${paletteName}-${number}`, colors[index]])];
57
+ const variableDeclarations = variables.map(([name, value]) => `${name}: ${value};`);
58
+ return variableDeclarations;
59
+ }
60
+ //# sourceMappingURL=theme.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.service.js","sourceRoot":"","sources":["../../../source/css/theme/theme.service.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,yDAA0D;AAC1D,oCAAoC;AAGpC,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,GAAG,IAAA,mBAAW,EAAC,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjF,MAAa,YAAY;IAGvB,YAAY,QAAkB;QAC5B,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;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CAAC,CAAC;IAC9J,MAAM,oBAAoB,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC;IAEpF,OAAO,oBAAoB,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.71.15",
3
+ "version": "0.71.16",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,6 +18,7 @@
18
18
  "rxjs": "^7"
19
19
  },
20
20
  "devDependencies": {
21
+ "@types/chroma-js": "^2.1.3",
21
22
  "@types/koa__router": "8.0",
22
23
  "@types/luxon": "2.3",
23
24
  "@types/minio": "7.0",
@@ -37,6 +38,7 @@
37
38
  "@elastic/elasticsearch": "^8.2",
38
39
  "@koa/router": "^10.1",
39
40
  "@tstdl/angular": "^0.10",
41
+ "chroma-js": "^2.4.2",
40
42
  "got": "^12.0",
41
43
  "handlebars": "^4.7",
42
44
  "koa": "^2.13",
@@ -14,7 +14,7 @@ export declare type ObjectSchemaDefinition<T extends StringMap<SchemaDefinition>
14
14
  /** Keep unknown properties instead of raising an error. This overwrites mask. */
15
15
  keepUnknown?: boolean;
16
16
  };
17
- export declare type ObjectAssign<A extends StringMap<SchemaDefinition>, B extends StringMap<SchemaDefinition>> = SimplifyObject<Omit<A, keyof B> & B>;
17
+ export declare type ObjectAssign<A extends StringMap<SchemaDefinition>, B extends StringMap<SchemaDefinition>> = SimplifyObject<B & Omit<A, keyof B>>;
18
18
  export declare class ObjectSchemaValidator<T extends StringMap<SchemaDefinition>> extends SchemaValidator<ObjectSchemaDefinition<T>> {
19
19
  private readonly validatorEntries;
20
20
  constructor(validators: ObjectSchemaValidatorEntries<T>, schema: ObjectSchemaDefinition<T>);
@@ -0,0 +1,16 @@
1
+ import type { Theme } from "../css/theme";
2
+ export declare type TailwindPalette = {
3
+ DEFAULT: string;
4
+ 50: string;
5
+ 100: string;
6
+ 200: string;
7
+ 300: string;
8
+ 400: string;
9
+ 500: string;
10
+ 600: string;
11
+ 700: string;
12
+ 800: string;
13
+ 900: string;
14
+ };
15
+ export declare function generateTailwindColors(theme: Theme): Record<string, TailwindPalette>;
16
+ export declare function generateTailwindPalette(name: string): TailwindPalette;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateTailwindPalette = exports.generateTailwindColors = void 0;
4
+ const type_guards_1 = require("../utils/type-guards");
5
+ function generateTailwindColors(theme) {
6
+ const entries = Object.entries(theme.colors)
7
+ .map(([colorName, value]) => {
8
+ var _a;
9
+ const name = (0, type_guards_1.isString)(value) ? colorName : ((_a = value.name) !== null && _a !== void 0 ? _a : colorName);
10
+ return [name, generateTailwindPalette(name)];
11
+ });
12
+ return Object.fromEntries(entries);
13
+ }
14
+ exports.generateTailwindColors = generateTailwindColors;
15
+ function generateTailwindPalette(name) {
16
+ return {
17
+ /* eslint-disable @typescript-eslint/naming-convention */
18
+ DEFAULT: `var(--color-${name})`,
19
+ 50: `var(--color-${name}-50)`,
20
+ 100: `var(--color-${name}-100)`,
21
+ 200: `var(--color-${name}-200)`,
22
+ 300: `var(--color-${name}-300)`,
23
+ 400: `var(--color-${name}-400)`,
24
+ 500: `var(--color-${name}-500)`,
25
+ 600: `var(--color-${name}-600)`,
26
+ 700: `var(--color-${name}-700)`,
27
+ 800: `var(--color-${name}-800)`,
28
+ 900: `var(--color-${name}-900)`
29
+ /* eslint-enable @typescript-eslint/naming-convention */
30
+ };
31
+ }
32
+ exports.generateTailwindPalette = generateTailwindPalette;
33
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.js","sourceRoot":"","sources":["../../source/tailwind/colors.ts"],"names":[],"mappings":";;;AACA,sDAA+C;AAkB/C,SAAgB,sBAAsB,CAAC,KAAY;IACjD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;SACzC,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,MAAA,KAAK,CAAC,IAAI,mCAAI,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"}
@@ -0,0 +1 @@
1
+ export * from './colors';
@@ -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("./colors"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/tailwind/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
package/types.d.ts CHANGED
@@ -43,12 +43,8 @@ export declare type Record<K extends keyof any = any, V = any> = {
43
43
  export declare type DeepRecord<K extends keyof any = any, V = any> = {
44
44
  [P in K]: V | DeepRecord<K, V>;
45
45
  };
46
- export declare type StringMap<T = any> = {
47
- [key: string]: T;
48
- };
49
- export declare type NumberMap<T = any> = {
50
- [key: number]: T;
51
- };
46
+ export declare type StringMap<T = any> = Record<string, T>;
47
+ export declare type NumberMap<T = any> = Record<number, T>;
52
48
  export declare type StringNumberMap<T = any> = {
53
49
  [key: string]: T;
54
50
  [key: number]: T;