@udixio/theme 1.0.0-beta.5 → 1.0.0-beta.7

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/src/app.module.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { Module } from '@nestjs/common';
1
+ import { asClass } from 'awilix';
2
2
  import { AppService } from './app.service';
3
- import { ColorModule } from './color/color.module';
4
- import { ThemeModule } from './theme/theme.module';
3
+ import { Module } from './app.container';
5
4
 
6
- @Module({
7
- imports: [ColorModule, ThemeModule],
8
- providers: [AppService],
9
- })
10
- export class AppModule {}
5
+ export const AppModule: Module = {
6
+ appService: asClass(AppService).singleton(),
7
+ };
@@ -1,6 +1,6 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
2
  import { AppService } from '../src/app.service';
3
- import { AppModule } from '../src/app.module';
3
+ import { AppModule } from './app.container';
4
4
 
5
5
  describe('AppController (e2e)', () => {
6
6
  let appService: AppService;
@@ -1,11 +1,17 @@
1
- import { Injectable } from '@nestjs/common';
2
1
  import { ColorService } from './color/color.service';
3
2
  import { ThemeService } from './theme/services/theme.service';
4
3
 
5
- @Injectable()
6
4
  export class AppService {
7
- constructor(
8
- public colorService: ColorService,
9
- public themeService: ThemeService
10
- ) {}
5
+ public colorService: ColorService;
6
+ public themeService: ThemeService;
7
+ constructor({
8
+ colorService,
9
+ themeService,
10
+ }: {
11
+ colorService: ColorService;
12
+ themeService: ThemeService;
13
+ }) {
14
+ this.colorService = colorService;
15
+ this.themeService = themeService;
16
+ }
11
17
  }
@@ -1,4 +1,3 @@
1
- import { Injectable } from '@nestjs/common';
2
1
  import { ContrastCurve, ToneDeltaPair } from '../material-color-utilities';
3
2
  import { DynamicColor } from '../material-color-utilities/dynamic_color';
4
3
  import { SchemeEntity } from '../theme/entities/scheme.entity';
@@ -20,10 +19,12 @@ export const highestSurface = (
20
19
  : colorManagerService.get('surfaceDim').getDynamicColor();
21
20
  };
22
21
 
23
- @Injectable()
24
22
  export class ColorManagerService {
25
23
  private colorMap = new Map<string, ColorEntity>();
26
- constructor(private schemeService: SchemeService) {}
24
+ private readonly schemeService: SchemeService;
25
+ constructor({ schemeService }: { schemeService: SchemeService }) {
26
+ this.schemeService = schemeService;
27
+ }
27
28
 
28
29
  createOrUpdate(key: string, args: Partial<ColorOptions>): ColorEntity {
29
30
  let colorEntity = this.colorMap.get(key);
@@ -1,11 +1,9 @@
1
1
  import { ColorService } from './color.service';
2
- import { Module } from '@nestjs/common';
3
2
  import { ColorManagerService } from './color-manager.service';
4
- import { ThemeModule } from '../theme/theme.module';
3
+ import { asClass } from 'awilix';
4
+ import { Module } from '../app.container';
5
5
 
6
- @Module({
7
- imports: [ThemeModule],
8
- providers: [ColorService, ColorManagerService],
9
- exports: [ColorService],
10
- })
11
- export class ColorModule {}
6
+ export const ColorModule: Module = {
7
+ colorManagerService: asClass(ColorManagerService).singleton(),
8
+ colorService: asClass(ColorService).singleton(),
9
+ };
@@ -1,12 +1,17 @@
1
- import { Injectable } from '@nestjs/common';
2
1
  import { ColorManagerService } from './color-manager.service';
3
2
  import { ColorInterface } from './color.interface';
4
3
  import { ColorEntity, ColorOptions } from './entities/color.entity';
5
4
  import { defaultColors, DynamicColorKey } from './models/default-color.model';
6
5
 
7
- @Injectable()
8
6
  export class ColorService implements ColorInterface {
9
- constructor(private colorManagerService: ColorManagerService) {}
7
+ private readonly colorManagerService: ColorManagerService;
8
+ constructor({
9
+ colorManagerService,
10
+ }: {
11
+ colorManagerService: ColorManagerService;
12
+ }) {
13
+ this.colorManagerService = colorManagerService;
14
+ }
10
15
 
11
16
  getAllColors() {
12
17
  return this.colorManagerService.getAll();
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { default as AppContainer } from './app.container';
2
+ export * from './app.container';
1
3
  export * from './app.module';
2
4
  export * from './app.service';
3
5
  export * from './color';
package/src/main.ts CHANGED
@@ -1,11 +1,6 @@
1
- import { NestFactory } from '@nestjs/core';
2
- import { AppModule } from './app.module';
1
+ import AppContainer from './app.container';
3
2
  import { AppService } from './app.service';
4
3
 
5
- export async function main(): Promise<[AppService, () => Promise<void>]> {
6
- const app = await NestFactory.create(AppModule);
7
- const appService = app.get(AppService);
8
-
9
- const close = () => app.close();
10
- return [appService, close];
4
+ export function main(): AppService {
5
+ return AppContainer.resolve<AppService>('appService');
11
6
  }
@@ -1,11 +1,9 @@
1
- import { Injectable } from '@nestjs/common';
2
1
  import { SchemeEntity, SchemeOptions } from '../entities/scheme.entity';
3
2
  import {
4
3
  argbFromHex,
5
4
  Hct,
6
5
  TonalPalette,
7
6
  } from '@material/material-color-utilities';
8
- import mergeDeep from 'merge-deep';
9
7
 
10
8
  export type SchemeServiceOptions = Omit<
11
9
  SchemeOptions,
@@ -15,13 +13,19 @@ export type SchemeServiceOptions = Omit<
15
13
  palettes: Record<string, (sourceColorHct: Hct) => TonalPalette>;
16
14
  };
17
15
 
18
- @Injectable()
19
16
  export class SchemeService {
20
17
  private schemeEntity?: SchemeEntity;
21
18
  private options?: SchemeServiceOptions;
22
19
 
23
20
  createOrUpdate(options: Partial<SchemeServiceOptions>) {
24
- this.options = mergeDeep(options, this.options);
21
+ this.options = {
22
+ ...this.options,
23
+ ...options,
24
+ palettes: {
25
+ ...this.options?.palettes,
26
+ ...options.palettes,
27
+ },
28
+ } as SchemeServiceOptions;
25
29
  const palettes = new Map<string, TonalPalette>();
26
30
 
27
31
  const sourceColorArgb = argbFromHex(this.options.sourceColorHex);
@@ -1,5 +1,4 @@
1
1
  import { DynamicColor } from '@material/material-color-utilities';
2
- import { Injectable } from '@nestjs/common';
3
2
  import { SchemeService, SchemeServiceOptions } from './scheme.service';
4
3
  import { VariantService } from './variant.service';
5
4
  import { VariantEntity } from '../entities/variant.entity';
@@ -12,12 +11,19 @@ const colorPaletteKeyColor = DynamicColor.fromPalette({
12
11
  tone: (s) => s.primaryPalette.keyColor.tone,
13
12
  });
14
13
 
15
- @Injectable()
16
14
  export class ThemeService {
17
- constructor(
18
- private schemeService: SchemeService,
19
- private variantService: VariantService
20
- ) {
15
+ private readonly schemeService: SchemeService;
16
+ private readonly variantService: VariantService;
17
+ constructor({
18
+ schemeService,
19
+ variantService,
20
+ }: {
21
+ schemeService: SchemeService;
22
+ variantService: VariantService;
23
+ }) {
24
+ this.schemeService = schemeService;
25
+ this.variantService = variantService;
26
+
21
27
  // this.addPalette({key: "primary", addDefaultColors: true})
22
28
  // this.addPalette({key: "secondary", addDefaultColors: true})
23
29
  // this.addPalette({key: "tertiary", addDefaultColors: true})
@@ -1,11 +1,12 @@
1
1
  import { SchemeService } from './scheme.service';
2
2
  import { VariantEntity } from '../entities/variant.entity';
3
- import { Injectable } from '@nestjs/common';
4
3
  import { TonalPalette } from '@material/material-color-utilities';
5
4
 
6
- @Injectable()
7
5
  export class VariantService {
8
- constructor(private schemeService: SchemeService) {}
6
+ private readonly schemeService: SchemeService;
7
+ constructor({ schemeService }: { schemeService: SchemeService }) {
8
+ this.schemeService = schemeService;
9
+ }
9
10
 
10
11
  set(variantEntity: VariantEntity) {
11
12
  if (!variantEntity.palettes.error) {
@@ -1,10 +1,9 @@
1
- import { Module } from '@nestjs/common';
2
- import { SchemeService } from './services/scheme.service';
3
- import { ThemeService } from './services/theme.service';
4
- import { VariantService } from './services/variant.service';
1
+ import { SchemeService, ThemeService, VariantService } from './services';
2
+ import { asClass } from 'awilix';
3
+ import { Module } from '../app.container';
5
4
 
6
- @Module({
7
- providers: [SchemeService, ThemeService, VariantService],
8
- exports: [ThemeService, SchemeService],
9
- })
10
- export class ThemeModule {}
5
+ export const ThemeModule: Module = {
6
+ schemeService: asClass(SchemeService).singleton(),
7
+ variantService: asClass(VariantService).singleton(),
8
+ themeService: asClass(ThemeService).singleton(),
9
+ };