@3mo/theme 0.0.2 → 0.0.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/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Theme
2
-
1
+ # Theme
2
+
3
3
  Tools & tokens for theming 3MO components & applications.
package/dist/Accent.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { css, unsafeCSS } from '@a11d/lit';
2
- import { RootCssInjector } from '@a11d/lit-application';
2
+ import { RootCssInjector } from '@a11d/root-css-injector';
3
3
  import { LocalStorage } from '@a11d/local-storage';
4
4
  import { Color } from '@3mo/color';
5
5
  import { ColorSet } from './ColorSet.js';
@@ -42,15 +42,15 @@ export class AccentStorage extends LocalStorage {
42
42
  const firstColor = value instanceof ColorSet ? value.colors[0] : value;
43
43
  const secondColor = value instanceof ColorSet ? value.colors[1] : value;
44
44
  const thirdColor = value instanceof ColorSet ? value.colors[2] : value;
45
- this.styleElement = RootCssInjector.inject(css `
46
- [application] {
47
- --mo-color-accent-base-r:${unsafeCSS(medianColor === null || medianColor === void 0 ? void 0 : medianColor.r)};
48
- --mo-color-accent-base-g:${unsafeCSS(medianColor === null || medianColor === void 0 ? void 0 : medianColor.g)};
49
- --mo-color-accent-base-b:${unsafeCSS(medianColor === null || medianColor === void 0 ? void 0 : medianColor.b)};
50
- --mo-color-accent-gradient-1: ${unsafeCSS(firstColor === null || firstColor === void 0 ? void 0 : firstColor.rgb)};
51
- --mo-color-accent-gradient-2: ${unsafeCSS(secondColor === null || secondColor === void 0 ? void 0 : secondColor.rgb)};
52
- --mo-color-accent-gradient-3: ${unsafeCSS(thirdColor === null || thirdColor === void 0 ? void 0 : thirdColor.rgb)};
53
- }
45
+ this.styleElement = RootCssInjector.inject(css `
46
+ :root {
47
+ --mo-color-accent-base-r:${unsafeCSS(medianColor === null || medianColor === void 0 ? void 0 : medianColor.r)};
48
+ --mo-color-accent-base-g:${unsafeCSS(medianColor === null || medianColor === void 0 ? void 0 : medianColor.g)};
49
+ --mo-color-accent-base-b:${unsafeCSS(medianColor === null || medianColor === void 0 ? void 0 : medianColor.b)};
50
+ --mo-color-accent-gradient-1: ${unsafeCSS(firstColor === null || firstColor === void 0 ? void 0 : firstColor.rgb)};
51
+ --mo-color-accent-gradient-2: ${unsafeCSS(secondColor === null || secondColor === void 0 ? void 0 : secondColor.rgb)};
52
+ --mo-color-accent-gradient-3: ${unsafeCSS(thirdColor === null || thirdColor === void 0 ? void 0 : thirdColor.rgb)};
53
+ }
54
54
  `, this.styleElement);
55
55
  }
56
56
  }
@@ -5,7 +5,6 @@ export declare const enum Background {
5
5
  Dark = "dark"
6
6
  }
7
7
  export declare class BackgroundStorage extends LocalStorage<Background> {
8
- private application?;
9
8
  constructor();
10
9
  get calculatedValue(): Background.Light | Background.Dark;
11
10
  private updateAttributeValue;
@@ -1 +1 @@
1
- {"version":3,"file":"Background.d.ts","sourceRoot":"","sources":["../Background.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,0BAAkB,UAAU;IAC3B,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;CACb;AAED,qBAAa,iBAAkB,SAAQ,YAAY,CAAC,UAAU,CAAC;IAC9D,OAAO,CAAC,WAAW,CAAC,CAAa;;IAajC,IAAI,eAAe,uCAMlB;IAED,OAAO,CAAC,oBAAoB;CAG5B"}
1
+ {"version":3,"file":"Background.d.ts","sourceRoot":"","sources":["../Background.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,0BAAkB,UAAU;IAC3B,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;CACb;AAED,qBAAa,iBAAkB,SAAQ,YAAY,CAAC,UAAU,CAAC;;IAS9D,IAAI,eAAe,uCAMlB;IAED,OAAO,CAAC,oBAAoB;CAG5B"}
@@ -1,15 +1,11 @@
1
- import { Application } from '@a11d/lit-application';
2
1
  import { LocalStorage } from '@a11d/local-storage';
3
2
  export class BackgroundStorage extends LocalStorage {
4
3
  constructor() {
5
4
  super('Theme.Background', "system" /* Background.System */);
6
5
  window.matchMedia('(prefers-color-scheme: dark)').onchange = () => this.updateAttributeValue();
7
6
  window.matchMedia('(prefers-color-scheme: light)').onchange = () => this.updateAttributeValue();
8
- Application.addInitializer(application => {
9
- this.application = application;
10
- this.updateAttributeValue();
11
- this.changed.subscribe(() => this.updateAttributeValue());
12
- });
7
+ this.updateAttributeValue();
8
+ this.changed.subscribe(() => this.updateAttributeValue());
13
9
  }
14
10
  get calculatedValue() {
15
11
  return this.value !== "system" /* Background.System */
@@ -19,7 +15,6 @@ export class BackgroundStorage extends LocalStorage {
19
15
  : "light" /* Background.Light */;
20
16
  }
21
17
  updateAttributeValue() {
22
- var _a;
23
- (_a = this.application) === null || _a === void 0 ? void 0 : _a.setAttribute('data-theme', this.calculatedValue);
18
+ document.documentElement.setAttribute('data-theme', this.calculatedValue);
24
19
  }
25
20
  }
@@ -5,7 +5,6 @@ export declare const enum Background {
5
5
  Dark = "dark"
6
6
  }
7
7
  export declare class BackgroundStorage extends LocalStorage<Background> {
8
- private application?;
9
8
  constructor();
10
9
  get calculatedValue(): Background.Light | Background.Dark;
11
10
  private updateAttributeValue;
@@ -1 +1 @@
1
- {"version":3,"file":"Background.d.ts","sourceRoot":"","sources":["../../Background.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,0BAAkB,UAAU;IAC3B,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;CACb;AAED,qBAAa,iBAAkB,SAAQ,YAAY,CAAC,UAAU,CAAC;IAC9D,OAAO,CAAC,WAAW,CAAC,CAAa;;IAajC,IAAI,eAAe,uCAMlB;IAED,OAAO,CAAC,oBAAoB;CAG5B"}
1
+ {"version":3,"file":"Background.d.ts","sourceRoot":"","sources":["../../Background.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,0BAAkB,UAAU;IAC3B,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;CACb;AAED,qBAAa,iBAAkB,SAAQ,YAAY,CAAC,UAAU,CAAC;;IAS9D,IAAI,eAAe,uCAMlB;IAED,OAAO,CAAC,oBAAoB;CAG5B"}
@@ -0,0 +1,10 @@
1
+ import { Controller, ReactiveElement } from '@a11d/lit';
2
+ export declare class ThemeController extends Controller {
3
+ readonly host: ReactiveElement;
4
+ constructor(host: ReactiveElement);
5
+ hostConnected(): void;
6
+ hostDisconnected(): void;
7
+ private handleChange;
8
+ private setAttribute;
9
+ }
10
+ //# sourceMappingURL=ThemeController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeController.d.ts","sourceRoot":"","sources":["../../ThemeController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAGvD,qBAAa,eAAgB,SAAQ,UAAU;aAChB,IAAI,EAAE,eAAe;gBAArB,IAAI,EAAE,eAAe;IAI1C,aAAa;IAMb,gBAAgB;IAKzB,OAAO,CAAC,YAAY,CAGnB;IAED,OAAO,CAAC,YAAY;CAGpB"}
@@ -3,4 +3,5 @@ export * from './Background.js';
3
3
  export * from './Accent.js';
4
4
  export * from './Theme.js';
5
5
  export * from './styles.css.js';
6
+ export * from './ThemeController.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { Controller, ReactiveElement } from '@a11d/lit';
2
+ export declare class ThemeController extends Controller {
3
+ readonly host: ReactiveElement;
4
+ constructor(host: ReactiveElement);
5
+ hostConnected(): void;
6
+ hostDisconnected(): void;
7
+ private handleChange;
8
+ private setAttribute;
9
+ }
10
+ //# sourceMappingURL=ThemeController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeController.d.ts","sourceRoot":"","sources":["../ThemeController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAGvD,qBAAa,eAAgB,SAAQ,UAAU;aAChB,IAAI,EAAE,eAAe;gBAArB,IAAI,EAAE,eAAe;IAI1C,aAAa;IAMb,gBAAgB;IAKzB,OAAO,CAAC,YAAY,CAGnB;IAED,OAAO,CAAC,YAAY;CAGpB"}
@@ -0,0 +1,24 @@
1
+ import { Controller } from '@a11d/lit';
2
+ import { Theme } from './Theme.js';
3
+ export class ThemeController extends Controller {
4
+ constructor(host) {
5
+ super(host);
6
+ this.host = host;
7
+ this.handleChange = () => {
8
+ this.setAttribute();
9
+ this.host.requestUpdate();
10
+ };
11
+ }
12
+ hostConnected() {
13
+ this.setAttribute();
14
+ Theme.accent.changed.subscribe(this.handleChange);
15
+ Theme.background.changed.subscribe(this.handleChange);
16
+ }
17
+ hostDisconnected() {
18
+ Theme.accent.changed.unsubscribe(this.handleChange);
19
+ Theme.background.changed.unsubscribe(this.handleChange);
20
+ }
21
+ setAttribute() {
22
+ this.host.setAttribute('data-theme', Theme.background.calculatedValue);
23
+ }
24
+ }