@seelen-ui/lib 2.4.8 → 2.4.10

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.
Files changed (187) hide show
  1. package/esm/gen/types/BluetoothDevice.d.ts +1 -0
  2. package/esm/gen/types/BluetoothDevice.d.ts.map +1 -1
  3. package/esm/gen/types/DevicePairingAnswer.d.ts +8 -0
  4. package/esm/gen/types/DevicePairingAnswer.d.ts.map +1 -0
  5. package/esm/gen/types/DevicePairingNeededAction.d.ts +18 -0
  6. package/esm/gen/types/DevicePairingNeededAction.d.ts.map +1 -0
  7. package/esm/gen/types/RadioDevice.d.ts +14 -0
  8. package/esm/gen/types/RadioDevice.d.ts.map +1 -0
  9. package/esm/gen/types/RadioDevice.js +1 -0
  10. package/esm/gen/types/RadioDeviceKind.d.ts +8 -0
  11. package/esm/gen/types/RadioDeviceKind.d.ts.map +1 -0
  12. package/esm/gen/types/RadioDeviceKind.js +9 -0
  13. package/esm/gen/types/ResourceMetadata.d.ts +6 -0
  14. package/esm/gen/types/ResourceMetadata.d.ts.map +1 -1
  15. package/esm/gen/types/SeelenCommandArgument.d.ts +25 -14
  16. package/esm/gen/types/SeelenCommandArgument.d.ts.map +1 -1
  17. package/esm/gen/types/SeelenCommandConfirmBluetoothDevicePairingArgs.d.ts +6 -0
  18. package/esm/gen/types/SeelenCommandConfirmBluetoothDevicePairingArgs.d.ts.map +1 -0
  19. package/esm/gen/types/SeelenCommandConfirmBluetoothDevicePairingArgs.js +1 -0
  20. package/esm/gen/types/SeelenCommandDisconnectBluetoothDeviceArgs.d.ts +4 -0
  21. package/esm/gen/types/SeelenCommandDisconnectBluetoothDeviceArgs.d.ts.map +1 -0
  22. package/esm/gen/types/SeelenCommandDisconnectBluetoothDeviceArgs.js +2 -0
  23. package/esm/gen/types/SeelenCommandRequestPairBluetoothDeviceArgs.d.ts +4 -0
  24. package/esm/gen/types/SeelenCommandRequestPairBluetoothDeviceArgs.d.ts.map +1 -0
  25. package/esm/gen/types/SeelenCommandRequestPairBluetoothDeviceArgs.js +2 -0
  26. package/esm/gen/types/SeelenCommandReturn.d.ts +22 -12
  27. package/esm/gen/types/SeelenCommandReturn.d.ts.map +1 -1
  28. package/esm/gen/types/SeelenCommandSetCurrentWidgetStatusArgs.d.ts +5 -0
  29. package/esm/gen/types/SeelenCommandSetCurrentWidgetStatusArgs.d.ts.map +1 -0
  30. package/esm/gen/types/SeelenCommandSetCurrentWidgetStatusArgs.js +1 -0
  31. package/esm/gen/types/SeelenCommandSetRadioStateArgs.d.ts +6 -0
  32. package/esm/gen/types/SeelenCommandSetRadioStateArgs.d.ts.map +1 -0
  33. package/esm/gen/types/SeelenCommandSetRadioStateArgs.js +1 -0
  34. package/esm/gen/types/SeelenEventPayload.d.ts +7 -9
  35. package/esm/gen/types/SeelenEventPayload.d.ts.map +1 -1
  36. package/esm/gen/types/ThemeVariable.d.ts +18 -4
  37. package/esm/gen/types/ThemeVariable.d.ts.map +1 -1
  38. package/esm/gen/types/ThemeVariableDefinition.d.ts +1 -1
  39. package/esm/gen/types/ThemeVariableDefinition.d.ts.map +1 -1
  40. package/esm/gen/types/ThemeVariableWithUnit.d.ts +22 -6
  41. package/esm/gen/types/ThemeVariableWithUnit.d.ts.map +1 -1
  42. package/esm/gen/types/Wallpaper.d.ts +9 -2
  43. package/esm/gen/types/Wallpaper.d.ts.map +1 -1
  44. package/esm/gen/types/WallpaperKind.d.ts +7 -0
  45. package/esm/gen/types/WallpaperKind.d.ts.map +1 -0
  46. package/esm/gen/types/WallpaperKind.js +8 -0
  47. package/esm/gen/types/Widget.d.ts +4 -0
  48. package/esm/gen/types/Widget.d.ts.map +1 -1
  49. package/esm/gen/types/WidgetStatus.d.ts +8 -0
  50. package/esm/gen/types/WidgetStatus.d.ts.map +1 -0
  51. package/esm/gen/types/WidgetStatus.js +9 -0
  52. package/esm/gen/types/mod.d.ts +11 -2
  53. package/esm/gen/types/mod.d.ts.map +1 -1
  54. package/esm/gen/types/mod.js +11 -2
  55. package/esm/src/handlers/commands.d.ts +11 -7
  56. package/esm/src/handlers/commands.d.ts.map +1 -1
  57. package/esm/src/handlers/commands.js +10 -6
  58. package/esm/src/handlers/events.d.ts +4 -5
  59. package/esm/src/handlers/events.d.ts.map +1 -1
  60. package/esm/src/handlers/events.js +3 -4
  61. package/esm/src/state/theme/mod.d.ts +0 -6
  62. package/esm/src/state/theme/mod.d.ts.map +1 -1
  63. package/esm/src/state/theme/mod.js +12 -28
  64. package/esm/src/state/theme/theming.d.ts +7 -0
  65. package/esm/src/state/theme/theming.d.ts.map +1 -0
  66. package/esm/src/state/theme/theming.js +56 -0
  67. package/esm/src/state/wallpaper/mod.d.ts +4 -2
  68. package/esm/src/state/wallpaper/mod.d.ts.map +1 -1
  69. package/esm/src/state/wallpaper/mod.js +4 -2
  70. package/esm/src/state/widget/mod.d.ts +31 -8
  71. package/esm/src/state/widget/mod.d.ts.map +1 -1
  72. package/esm/src/state/widget/mod.js +69 -31
  73. package/esm/src/state/widget/sizing.d.ts +7 -2
  74. package/esm/src/state/widget/sizing.d.ts.map +1 -1
  75. package/esm/src/state/widget/sizing.js +39 -36
  76. package/esm/src/system_state/bluetooth/mod.d.ts +1 -7
  77. package/esm/src/system_state/bluetooth/mod.d.ts.map +1 -1
  78. package/esm/src/system_state/bluetooth/mod.js +1 -26
  79. package/esm/src/system_state/ui_colors.d.ts +6 -3
  80. package/esm/src/system_state/ui_colors.d.ts.map +1 -1
  81. package/esm/src/system_state/ui_colors.js +63 -32
  82. package/esm/src/utils/DOM.d.ts +9 -0
  83. package/esm/src/utils/DOM.d.ts.map +1 -0
  84. package/esm/src/utils/DOM.js +29 -0
  85. package/package.json +1 -1
  86. package/script/gen/types/BluetoothDevice.d.ts +1 -0
  87. package/script/gen/types/BluetoothDevice.d.ts.map +1 -1
  88. package/script/gen/types/DevicePairingAnswer.d.ts +8 -0
  89. package/script/gen/types/DevicePairingAnswer.d.ts.map +1 -0
  90. package/script/gen/types/DevicePairingNeededAction.d.ts +18 -0
  91. package/script/gen/types/DevicePairingNeededAction.d.ts.map +1 -0
  92. package/script/gen/types/RadioDevice.d.ts +14 -0
  93. package/script/gen/types/RadioDevice.d.ts.map +1 -0
  94. package/script/gen/types/RadioDevice.js +2 -0
  95. package/script/gen/types/RadioDeviceKind.d.ts +8 -0
  96. package/script/gen/types/RadioDeviceKind.d.ts.map +1 -0
  97. package/script/gen/types/RadioDeviceKind.js +12 -0
  98. package/script/gen/types/ResourceMetadata.d.ts +6 -0
  99. package/script/gen/types/ResourceMetadata.d.ts.map +1 -1
  100. package/script/gen/types/SeelenCommandArgument.d.ts +25 -14
  101. package/script/gen/types/SeelenCommandArgument.d.ts.map +1 -1
  102. package/script/gen/types/SeelenCommandConfirmBluetoothDevicePairingArgs.d.ts +6 -0
  103. package/script/gen/types/SeelenCommandConfirmBluetoothDevicePairingArgs.d.ts.map +1 -0
  104. package/script/gen/types/SeelenCommandConfirmBluetoothDevicePairingArgs.js +2 -0
  105. package/script/gen/types/SeelenCommandDisconnectBluetoothDeviceArgs.d.ts +4 -0
  106. package/script/gen/types/SeelenCommandDisconnectBluetoothDeviceArgs.d.ts.map +1 -0
  107. package/script/gen/types/SeelenCommandDisconnectBluetoothDeviceArgs.js +3 -0
  108. package/script/gen/types/SeelenCommandRequestPairBluetoothDeviceArgs.d.ts +4 -0
  109. package/script/gen/types/SeelenCommandRequestPairBluetoothDeviceArgs.d.ts.map +1 -0
  110. package/script/gen/types/SeelenCommandRequestPairBluetoothDeviceArgs.js +3 -0
  111. package/script/gen/types/SeelenCommandReturn.d.ts +22 -12
  112. package/script/gen/types/SeelenCommandReturn.d.ts.map +1 -1
  113. package/script/gen/types/SeelenCommandSetCurrentWidgetStatusArgs.d.ts +5 -0
  114. package/script/gen/types/SeelenCommandSetCurrentWidgetStatusArgs.d.ts.map +1 -0
  115. package/script/gen/types/SeelenCommandSetCurrentWidgetStatusArgs.js +2 -0
  116. package/script/gen/types/SeelenCommandSetRadioStateArgs.d.ts +6 -0
  117. package/script/gen/types/SeelenCommandSetRadioStateArgs.d.ts.map +1 -0
  118. package/script/gen/types/SeelenCommandSetRadioStateArgs.js +2 -0
  119. package/script/gen/types/SeelenEventPayload.d.ts +7 -9
  120. package/script/gen/types/SeelenEventPayload.d.ts.map +1 -1
  121. package/script/gen/types/ThemeVariable.d.ts +18 -4
  122. package/script/gen/types/ThemeVariable.d.ts.map +1 -1
  123. package/script/gen/types/ThemeVariableDefinition.d.ts +1 -1
  124. package/script/gen/types/ThemeVariableDefinition.d.ts.map +1 -1
  125. package/script/gen/types/ThemeVariableWithUnit.d.ts +22 -6
  126. package/script/gen/types/ThemeVariableWithUnit.d.ts.map +1 -1
  127. package/script/gen/types/Wallpaper.d.ts +9 -2
  128. package/script/gen/types/Wallpaper.d.ts.map +1 -1
  129. package/script/gen/types/WallpaperKind.d.ts +7 -0
  130. package/script/gen/types/WallpaperKind.d.ts.map +1 -0
  131. package/script/gen/types/WallpaperKind.js +11 -0
  132. package/script/gen/types/Widget.d.ts +4 -0
  133. package/script/gen/types/Widget.d.ts.map +1 -1
  134. package/script/gen/types/WidgetStatus.d.ts +8 -0
  135. package/script/gen/types/WidgetStatus.d.ts.map +1 -0
  136. package/script/gen/types/WidgetStatus.js +12 -0
  137. package/script/gen/types/mod.d.ts +11 -2
  138. package/script/gen/types/mod.d.ts.map +1 -1
  139. package/script/gen/types/mod.js +11 -2
  140. package/script/src/handlers/commands.d.ts +11 -7
  141. package/script/src/handlers/commands.d.ts.map +1 -1
  142. package/script/src/handlers/commands.js +10 -6
  143. package/script/src/handlers/events.d.ts +4 -5
  144. package/script/src/handlers/events.d.ts.map +1 -1
  145. package/script/src/handlers/events.js +3 -4
  146. package/script/src/state/theme/mod.d.ts +0 -6
  147. package/script/src/state/theme/mod.d.ts.map +1 -1
  148. package/script/src/state/theme/mod.js +11 -29
  149. package/script/src/state/theme/theming.d.ts +7 -0
  150. package/script/src/state/theme/theming.d.ts.map +1 -0
  151. package/script/src/state/theme/theming.js +60 -0
  152. package/script/src/state/wallpaper/mod.d.ts +4 -2
  153. package/script/src/state/wallpaper/mod.d.ts.map +1 -1
  154. package/script/src/state/wallpaper/mod.js +4 -2
  155. package/script/src/state/widget/mod.d.ts +31 -8
  156. package/script/src/state/widget/mod.d.ts.map +1 -1
  157. package/script/src/state/widget/mod.js +66 -28
  158. package/script/src/state/widget/sizing.d.ts +7 -2
  159. package/script/src/state/widget/sizing.d.ts.map +1 -1
  160. package/script/src/state/widget/sizing.js +41 -37
  161. package/script/src/system_state/bluetooth/mod.d.ts +1 -7
  162. package/script/src/system_state/bluetooth/mod.d.ts.map +1 -1
  163. package/script/src/system_state/bluetooth/mod.js +1 -26
  164. package/script/src/system_state/ui_colors.d.ts +6 -3
  165. package/script/src/system_state/ui_colors.d.ts.map +1 -1
  166. package/script/src/system_state/ui_colors.js +63 -32
  167. package/script/src/utils/DOM.d.ts +9 -0
  168. package/script/src/utils/DOM.d.ts.map +1 -0
  169. package/script/src/utils/DOM.js +33 -0
  170. package/esm/gen/types/SeelenCommandConfirmBluetoothDevicePairArgs.d.ts +0 -5
  171. package/esm/gen/types/SeelenCommandConfirmBluetoothDevicePairArgs.d.ts.map +0 -1
  172. package/esm/gen/types/SeelenCommandPairBluetoothDeviceArgs.d.ts +0 -4
  173. package/esm/gen/types/SeelenCommandPairBluetoothDeviceArgs.d.ts.map +0 -1
  174. package/esm/src/utils/Wrapper.d.ts +0 -3
  175. package/esm/src/utils/Wrapper.d.ts.map +0 -1
  176. package/esm/src/utils/Wrapper.js +0 -5
  177. package/script/gen/types/SeelenCommandConfirmBluetoothDevicePairArgs.d.ts +0 -5
  178. package/script/gen/types/SeelenCommandConfirmBluetoothDevicePairArgs.d.ts.map +0 -1
  179. package/script/gen/types/SeelenCommandPairBluetoothDeviceArgs.d.ts +0 -4
  180. package/script/gen/types/SeelenCommandPairBluetoothDeviceArgs.d.ts.map +0 -1
  181. package/script/src/utils/Wrapper.d.ts +0 -3
  182. package/script/src/utils/Wrapper.d.ts.map +0 -1
  183. package/script/src/utils/Wrapper.js +0 -8
  184. /package/esm/gen/types/{SeelenCommandConfirmBluetoothDevicePairArgs.js → DevicePairingAnswer.js} +0 -0
  185. /package/esm/gen/types/{SeelenCommandPairBluetoothDeviceArgs.js → DevicePairingNeededAction.js} +0 -0
  186. /package/script/gen/types/{SeelenCommandConfirmBluetoothDevicePairArgs.js → DevicePairingAnswer.js} +0 -0
  187. /package/script/gen/types/{SeelenCommandPairBluetoothDeviceArgs.js → DevicePairingNeededAction.js} +0 -0
@@ -14,7 +14,7 @@ export declare class WidgetList extends List<IWidget> {
14
14
  static onChange(cb: (payload: WidgetList) => void): Promise<UnSubscriber>;
15
15
  findById(id: WidgetId): IWidget | undefined;
16
16
  }
17
- interface WidgetInformation {
17
+ export interface WidgetInformation {
18
18
  /** decoded webview label */
19
19
  label: string;
20
20
  /** Will be present if the widget replicas is set to by monitor */
@@ -26,6 +26,20 @@ interface WidgetInformation {
26
26
  readonly [key in string]?: string;
27
27
  };
28
28
  }
29
+ export interface InitWidgetOptions {
30
+ /**
31
+ * @default !widget.lazy
32
+ */
33
+ show?: boolean;
34
+ /**
35
+ * Will auto size the widget to the content size of the element
36
+ * @example
37
+ * autoSizeByContent: document.body,
38
+ * autoSizeByContent: document.getElementById("root"),
39
+ * @default undefined
40
+ */
41
+ autoSizeByContent?: HTMLElement | null;
42
+ }
29
43
  /**
30
44
  * Represents the widget instance running in the current webview
31
45
  */
@@ -38,6 +52,9 @@ export declare class Widget {
38
52
  readonly decoded: WidgetInformation;
39
53
  /** current webview window */
40
54
  readonly webview: WebviewWindow;
55
+ private autoSizer?;
56
+ private initOptions;
57
+ private runtimeState;
41
58
  private constructor();
42
59
  private static getDecodedWebviewLabel;
43
60
  /** Will throw if the library is being used on a non Seelen UI environment */
@@ -55,17 +72,23 @@ export declare class Widget {
55
72
  /** Will apply the recommended settings for a popup widget */
56
73
  private applyPopupPreset;
57
74
  /**
58
- * Will restore the saved position and size of the widget after that
59
- * will store the position and size of the widget on change.
75
+ * Will restore the saved position and size of the widget on start,
76
+ * after that will store the position and size of the widget on change.
60
77
  */
61
78
  persistPositionAndSize(): Promise<void>;
62
- autoSizeWebviewByElement(element?: HTMLElement): void;
63
79
  /**
64
- * Will initialize the widget based on the preset, this function won't show the widget.
65
- * You need to call `webview.show()` to show the widget.
80
+ * Will initialize the widget based on the preset and mark it as `pending`, this function won't show the widget.
81
+ * This should be called before any other action on the widget. After this you should call
82
+ * `ready` to mark the widget as ready and show it.
83
+ */
84
+ init(options?: InitWidgetOptions): Promise<void>;
85
+ /**
86
+ * Will mark the widget as `ready` and pool pending triggers.
87
+ *
88
+ * If the widget is not lazy this will inmediately show the widget.
89
+ * Lazy widget should be shown on trigger action.
66
90
  */
67
- init(): Promise<void>;
91
+ ready(): Promise<void>;
68
92
  onTrigger(cb: (args: WidgetTriggerPayload) => void): void;
69
93
  }
70
- export {};
71
94
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/state/widget/mod.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,QAAQ,EAEb,KAAK,oBAAoB,EAE1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAyC,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAS5F,eAAO,MAAM,sBAAsB,EAAE,QAAyC,CAAC;AAC/E,eAAO,MAAM,mBAAmB,EAAE,QAAsC,CAAC;AACzE,eAAO,MAAM,iBAAiB,EAAE,QAAoC,CAAC;AACrE,eAAO,MAAM,qBAAqB,EAAE,QAA8C,CAAC;AACnF,eAAO,MAAM,2BAA2B,EAAE,QAA+C,CAAC;AAC1F,eAAO,M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AGG;IACU,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAuCpD;;;;OAIG;IACU,IAAI,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BjE;;;;;OAKG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB5B,SAAS,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,IAAI,GAAG,IAAI;CAOjE"}
@@ -1,6 +1,6 @@
1
1
  import * as dntShim from "../../../_dnt.shims.js";
2
- import { WidgetPreset, } from "../../../gen/types/mod.js";
3
- import { SeelenCommand, SeelenEvent, subscribe } from "../../handlers/mod.js";
2
+ import { WidgetPreset, WidgetStatus, } from "../../../gen/types/mod.js";
3
+ import { invoke, SeelenCommand, SeelenEvent } from "../../handlers/mod.js";
4
4
  import { List } from "../../utils/List.js";
5
5
  import { newFromInvoke, newOnEvent } from "../../utils/State.js";
6
6
  import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
@@ -8,8 +8,9 @@ import { decodeBase64Url } from "../../../deps/jsr.io/@std/encoding/1.0.10/mod.j
8
8
  import { PhysicalPosition, PhysicalSize } from "@tauri-apps/api/dpi";
9
9
  import { monitorFromPoint } from "@tauri-apps/api/window";
10
10
  import { debounce } from "../../utils/async.js";
11
- import { autoSizeWebviewBasedOnContent } from "./sizing.js";
11
+ import { WidgetAutoSizer } from "./sizing.js";
12
12
  import { adjustPostionByPlacement } from "./positioning.js";
13
+ import { startThemingTool } from "../theme/theming.js";
13
14
  export const SeelenSettingsWidgetId = "@seelen/settings";
14
15
  export const SeelenPopupWidgetId = "@seelen/popup";
15
16
  export const SeelenWegWidgetId = "@seelen/weg";
@@ -40,6 +41,12 @@ export class Widget {
40
41
  decoded;
41
42
  /** current webview window */
42
43
  webview;
44
+ autoSizer;
45
+ initOptions = {};
46
+ runtimeState = {
47
+ initialized: false,
48
+ ready: false,
49
+ };
43
50
  constructor(widget) {
44
51
  this.def = widget;
45
52
  this.webview = getCurrentWebviewWindow();
@@ -112,8 +119,8 @@ export class Widget {
112
119
  ...this.applyInvisiblePreset(),
113
120
  // Desktop widgets are always on bottom
114
121
  this.webview.setAlwaysOnBottom(true),
122
+ this.persistPositionAndSize(),
115
123
  ]);
116
- await this.persistPositionAndSize();
117
124
  }
118
125
  /** Will apply the recommended settings for an overlay widget */
119
126
  async applyOverlayPreset() {
@@ -121,25 +128,31 @@ export class Widget {
121
128
  ...this.applyInvisiblePreset(),
122
129
  // Overlay widgets are always on top
123
130
  this.webview.setAlwaysOnTop(true),
131
+ this.persistPositionAndSize(),
124
132
  ]);
125
133
  }
126
134
  /** Will apply the recommended settings for a popup widget */
127
135
  async applyPopupPreset() {
128
- await Promise.all([...this.applyInvisiblePreset(), this.webview.setResizable(false)]);
129
- // auto close on focus lost
136
+ await Promise.all([...this.applyInvisiblePreset()]);
137
+ // auto close after 1 minute when not in use to save resources
130
138
  const closeOnTimeout = debounce(() => {
131
- // this.webview.close(); todo
132
- }, 5000);
133
- this.webview.onFocusChanged((e) => {
134
- if (e.payload) {
135
- closeOnTimeout.cancel();
139
+ this.webview.close();
140
+ }, 60_000);
141
+ const hideWebview = debounce(() => {
142
+ this.webview.hide();
143
+ closeOnTimeout();
144
+ }, 100);
145
+ this.webview.onFocusChanged(({ payload: focused }) => {
146
+ if (focused) {
147
+ hideWebview.cancel();
136
148
  }
137
149
  else {
138
- this.webview.hide();
139
- closeOnTimeout();
150
+ hideWebview();
140
151
  }
141
152
  });
142
153
  this.onTrigger(async ({ desiredPosition, alignX, alignY }) => {
154
+ // avoid flickering when clicking a button that triggers the widget
155
+ hideWebview.cancel();
143
156
  if (desiredPosition) {
144
157
  const { width, height } = await this.webview.outerSize();
145
158
  const pos = await adjustPostionByPlacement({
@@ -153,11 +166,12 @@ export class Widget {
153
166
  await this.webview.setPosition(new PhysicalPosition(pos.x, pos.y));
154
167
  }
155
168
  await this.webview.show();
169
+ await this.webview.setFocus();
156
170
  });
157
171
  }
158
172
  /**
159
- * Will restore the saved position and size of the widget after that
160
- * will store the position and size of the widget on change.
173
+ * Will restore the saved position and size of the widget on start,
174
+ * after that will store the position and size of the widget on change.
161
175
  */
162
176
  async persistPositionAndSize() {
163
177
  const storage = globalThis.window.localStorage;
@@ -188,15 +202,18 @@ export class Widget {
188
202
  console.info(`Widget size saved: ${width} ${height}`);
189
203
  }, 500));
190
204
  }
191
- // this will monitor the element and resize the webview accordingly
192
- autoSizeWebviewByElement(element = document.body) {
193
- autoSizeWebviewBasedOnContent(this.webview, element);
194
- }
195
205
  /**
196
- * Will initialize the widget based on the preset, this function won't show the widget.
197
- * You need to call `webview.show()` to show the widget.
206
+ * Will initialize the widget based on the preset and mark it as `pending`, this function won't show the widget.
207
+ * This should be called before any other action on the widget. After this you should call
208
+ * `ready` to mark the widget as ready and show it.
198
209
  */
199
- async init() {
210
+ async init(options = {}) {
211
+ if (this.runtimeState.initialized) {
212
+ console.warn(`Widget already initialized`);
213
+ return;
214
+ }
215
+ this.runtimeState.initialized = true;
216
+ this.initOptions = options;
200
217
  switch (this.def.preset) {
201
218
  case WidgetPreset.None:
202
219
  break;
@@ -210,17 +227,38 @@ export class Widget {
210
227
  await this.applyPopupPreset();
211
228
  break;
212
229
  }
230
+ await startThemingTool();
231
+ if (options.autoSizeByContent) {
232
+ this.autoSizer = new WidgetAutoSizer(this.webview, options.autoSizeByContent);
233
+ }
234
+ }
235
+ /**
236
+ * Will mark the widget as `ready` and pool pending triggers.
237
+ *
238
+ * If the widget is not lazy this will inmediately show the widget.
239
+ * Lazy widget should be shown on trigger action.
240
+ */
241
+ async ready() {
242
+ if (!this.runtimeState.initialized) {
243
+ throw new Error(`Widget was not initialized before ready`);
244
+ }
245
+ if (this.runtimeState.ready) {
246
+ console.warn(`Widget is already ready`);
247
+ return;
248
+ }
249
+ this.runtimeState.ready = true;
250
+ await this.autoSizer?.execute();
251
+ if (this.initOptions.show ?? !this.def.lazy) {
252
+ await this.webview.show();
253
+ }
254
+ // this will mark the widget as ready, and send pending trigger event if exists
255
+ await invoke(SeelenCommand.SetCurrentWidgetStatus, { status: WidgetStatus.Ready });
213
256
  }
214
257
  onTrigger(cb) {
215
- const fn = ({ payload }) => {
216
- const { id, monitorId, instanceId } = payload;
217
- if (id !== this.id ||
218
- (monitorId && monitorId !== this.decoded.monitorId) ||
219
- (instanceId && instanceId !== this.decoded.instanceId)) {
220
- return;
221
- }
258
+ this.webview.listen(SeelenEvent.WidgetTriggered, ({ payload }) => {
259
+ // fix for cutted popups, ensure correct size on trigger.
260
+ // await this.autoSizer?.execute();
222
261
  cb(payload);
223
- };
224
- subscribe(SeelenEvent.WidgetTriggered, fn.bind(this));
262
+ });
225
263
  }
226
264
  }
@@ -2,6 +2,11 @@ import type { WebviewWindow } from "@tauri-apps/api/webviewWindow";
2
2
  export interface AutoSizeOptions {
3
3
  onResize?: () => void;
4
4
  }
5
- /** This function will update the size of the webview/window based on the size of the root element */
6
- export declare function autoSizeWebviewBasedOnContent(webview: WebviewWindow, element: HTMLElement, options?: AutoSizeOptions): () => void;
5
+ export declare class WidgetAutoSizer {
6
+ private webview;
7
+ private element;
8
+ constructor(webview: WebviewWindow, element: HTMLElement);
9
+ private setup;
10
+ execute(): Promise<void>;
11
+ }
7
12
  //# sourceMappingURL=sizing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sizing.d.ts","sourceRoot":"","sources":["../../../../src/src/state/widget/sizing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,qGAAqG;AACrG,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,eAAoB,GAC5B,MAAM,IAAI,CA6CZ"}
1
+ {"version":3,"file":"sizing.d.ts","sourceRoot":"","sources":["../../../../src/src/state/widget/sizing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,qBAAa,eAAe;IACd,OAAO,CAAC,OAAO;IAAiB,OAAO,CAAC,OAAO;gBAAvC,OAAO,EAAE,aAAa,EAAU,OAAO,EAAE,WAAW;IAKxE,OAAO,CAAC,KAAK;IAmBP,OAAO;CAkBd"}
@@ -1,39 +1,42 @@
1
1
  import { LogicalSize } from "@tauri-apps/api/dpi";
2
- /** This function will update the size of the webview/window based on the size of the root element */
3
- export function autoSizeWebviewBasedOnContent(webview, element, options = {}) {
4
- const { onResize } = options;
5
- const updateSize = async () => {
6
- const contentWidth = Math.floor(element.scrollWidth);
7
- const contentHeight = Math.floor(element.scrollHeight);
8
- if (contentWidth > 0 && contentHeight > 0) {
9
- const { width: currentWidth, height: currentHeight } = await webview.outerSize();
10
- const currentWidthFloored = Math.floor(currentWidth);
11
- const currentHeightFloored = Math.floor(currentHeight);
12
- // Only update if the difference is more than 1px (avoid infinite loops from decimal differences)
13
- if (Math.abs(contentWidth - currentWidthFloored) > 1 ||
14
- Math.abs(contentHeight - currentHeightFloored) > 1) {
15
- const size = new LogicalSize(contentWidth, contentHeight);
16
- webview.setSize(size).catch((err) => {
17
- console.error("Failed to update webview size:", err);
18
- });
19
- onResize?.();
20
- }
2
+ export class WidgetAutoSizer {
3
+ webview;
4
+ element;
5
+ constructor(webview, element) {
6
+ this.webview = webview;
7
+ this.element = element;
8
+ this.execute = this.execute.bind(this);
9
+ this.setup();
10
+ }
11
+ setup() {
12
+ // Disable resizing by the user
13
+ this.webview.setResizable(false);
14
+ // Update size when content changes
15
+ const observer = new MutationObserver(this.execute);
16
+ observer.observe(this.element, {
17
+ childList: true,
18
+ subtree: true,
19
+ attributes: true,
20
+ characterData: true,
21
+ });
22
+ // Cleanup function
23
+ return () => {
24
+ observer.disconnect();
25
+ };
26
+ }
27
+ async execute() {
28
+ const contentWidth = this.element.scrollWidth;
29
+ const contentHeight = this.element.scrollHeight;
30
+ if (contentWidth < 1 || contentHeight < 1) {
31
+ return;
21
32
  }
22
- };
23
- // Initial size update
24
- updateSize();
25
- // Update size when content changes
26
- const observer = new MutationObserver(() => {
27
- updateSize();
28
- });
29
- observer.observe(element, {
30
- childList: true,
31
- subtree: true,
32
- attributes: true,
33
- characterData: true,
34
- });
35
- // Cleanup function
36
- return () => {
37
- observer.disconnect();
38
- };
33
+ const { width: physicalWidth, height: physicalHeight } = await this.webview.outerSize();
34
+ const logicalWidth = physicalWidth * globalThis.window.devicePixelRatio;
35
+ const logicalHeight = physicalHeight * globalThis.window.devicePixelRatio;
36
+ // Only update if the difference is more than 1px (avoid infinite loops from decimal differences)
37
+ if (Math.abs(contentWidth - logicalWidth) > 1 || Math.abs(contentHeight - logicalHeight) > 1) {
38
+ const size = new LogicalSize(contentWidth, contentHeight);
39
+ await this.webview.setSize(size);
40
+ }
41
+ }
39
42
  }
@@ -1,17 +1,11 @@
1
1
  import { type UnSubscriber } from "../../handlers/mod.js";
2
2
  import { List } from "../../utils/List.js";
3
- import type { BluetoothDevice, BluetoothDevicePairShowPinRequest } from "../../../gen/types/mod.js";
4
- import type { UnlistenFn } from "@tauri-apps/api/event";
3
+ import type { BluetoothDevice } from "../../../gen/types/mod.js";
5
4
  export declare class BluetoothDevices extends List<BluetoothDevice> {
6
5
  static getAsync(): Promise<BluetoothDevices>;
7
6
  static onChange(cb: (payload: BluetoothDevices) => void): Promise<UnSubscriber>;
8
- static onDiscoveredDevicesChange(cb: (payload: BluetoothDevices) => void): Promise<UnSubscriber>;
9
7
  static discover(): Promise<void>;
10
8
  static stopDiscovery(): Promise<void>;
11
- static pairDevice(address: bigint): Promise<void>;
12
- static forgetDevice(id: string): Promise<void>;
13
- static confirmPair(accept: boolean, passphrase: string): Promise<void>;
14
- static onPairRequest(cb: (param: BluetoothDevicePairShowPinRequest | null) => void): Promise<UnlistenFn>;
15
9
  static default(): BluetoothDevices;
16
10
  }
17
11
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/system_state/bluetooth/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,iCAAiC,EAAE,MAAM,2BAA2B,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,qBAAa,gBAAiB,SAAQ,IAAI,CAAC,eAAe,CAAC;IACzD,MAAM,CAAC,QAAQ,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAI5C,MAAM,CAAC,QAAQ,CACb,EAAE,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,GACtC,OAAO,CAAC,YAAY,CAAC;IAIxB,MAAM,CAAC,yBAAyB,CAC9B,EAAE,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,GACtC,OAAO,CAAC,YAAY,CAAC;WAIX,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;WAGzB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;WAI9B,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAG1C,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAGvC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAO/D,aAAa,CACxB,EAAE,EAAE,CAAC,KAAK,EAAE,iCAAiC,GAAG,IAAI,KAAK,IAAI,GAC5D,OAAO,CAAC,UAAU,CAAC;IAiBtB,MAAM,CAAC,OAAO,IAAI,gBAAgB;CAGnC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/system_state/bluetooth/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAGjE,qBAAa,gBAAiB,SAAQ,IAAI,CAAC,eAAe,CAAC;IACzD,MAAM,CAAC,QAAQ,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAI5C,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC;WAIlE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;WAIzB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C,MAAM,CAAC,OAAO,IAAI,gBAAgB;CAGnC"}
@@ -1,44 +1,19 @@
1
1
  import { invoke, SeelenCommand, SeelenEvent } from "../../handlers/mod.js";
2
2
  import { List } from "../../utils/List.js";
3
- import { subscribe } from "../../handlers/mod.js";
4
3
  import { newFromInvoke, newOnEvent } from "../../utils/State.js";
5
4
  export class BluetoothDevices extends List {
6
5
  static getAsync() {
7
- return newFromInvoke(this, SeelenCommand.GetConnectedBluetoothDevices);
6
+ return newFromInvoke(this, SeelenCommand.GetBluetoothDevices);
8
7
  }
9
8
  static onChange(cb) {
10
9
  return newOnEvent(cb, this, SeelenEvent.BluetoothDevicesChanged);
11
10
  }
12
- static onDiscoveredDevicesChange(cb) {
13
- return newOnEvent(cb, this, SeelenEvent.BluetoothDiscoveredDevicesChanged);
14
- }
15
11
  static async discover() {
16
12
  return await invoke(SeelenCommand.StartBluetoothScanning);
17
13
  }
18
14
  static async stopDiscovery() {
19
15
  return await invoke(SeelenCommand.StopBluetoothScanning);
20
16
  }
21
- static async pairDevice(address) {
22
- return await invoke(SeelenCommand.PairBluetoothDevice, { address });
23
- }
24
- static async forgetDevice(id) {
25
- return await invoke(SeelenCommand.ForgetBluetoothDevice, { id });
26
- }
27
- static async confirmPair(accept, passphrase) {
28
- return await invoke(SeelenCommand.ConfirmBluetoothDevicePair, {
29
- accept,
30
- passphrase,
31
- });
32
- }
33
- static async onPairRequest(cb) {
34
- //TODO(Eythaan): from here the process does not continues
35
- const unlistenShowPin = await subscribe(SeelenEvent.BluetoothPairShowPin, (param) => cb(param.payload));
36
- const unlistenRequestPin = await subscribe(SeelenEvent.BluetoothPairRequestPin, (param) => cb(param.payload));
37
- return () => {
38
- unlistenRequestPin();
39
- unlistenShowPin();
40
- };
41
- }
42
17
  static default() {
43
18
  return new this([]);
44
19
  }
@@ -8,14 +8,16 @@ export declare class UIColors {
8
8
  static default(): UIColors;
9
9
  setAsCssVariables(): void;
10
10
  }
11
+ export interface Color extends IColor {
12
+ }
11
13
  export declare class Color {
12
- inner: IColor;
13
- constructor(inner: IColor);
14
+ constructor(obj: IColor);
14
15
  /** generates a random solid color */
15
16
  static random(): Color;
17
+ static fromHex(hex: string): Color;
18
+ toHexString(): string;
16
19
  private getRuntimeStyleSheet;
17
20
  private insertIntoStyleSheet;
18
- toHexString(): string;
19
21
  /**
20
22
  * @param name the name of the color
21
23
  * the name will be parsed to lower kebab case and remove non-alphanumeric characters
@@ -32,5 +34,6 @@ export declare class Color {
32
34
  * @returns a number between 0 and 255
33
35
  */
34
36
  calcLuminance(accuracy?: boolean): number;
37
+ complementary(): Color;
35
38
  }
36
39
  //# sourceMappingURL=ui_colors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ui_colors.d.ts","sourceRoot":"","sources":["../../../src/src/system_state/ui_colors.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEnF,OAAO,KAAK,EAAE,KAAK,IAAI,MAAM,EAAE,QAAQ,IAAI,SAAS,EAAE,MAA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AED,MAAM,WAAW,KAAM,SAAQ,MAAM;CAAG;AAExC,qBAAa,KAAK;gBACJ,GAAG,EAAE,MAAM;IAOvB,qCAAqC;IACrC,MAAM,CAAC,MAAM,IAAI,KAAK;IAStB,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAyBlC,WAAW,IAAI,MAAM;IAUrB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,oBAAoB;IAkB5B;;;;;;;OAOG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAapC;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM;IAYzC,aAAa,IAAI,KAAK;CAQvB"}
@@ -1,4 +1,5 @@
1
1
  import { SeelenCommand, SeelenEvent } from "../handlers/mod.js";
2
+ import { RuntimeStyleSheet } from "../utils/DOM.js";
2
3
  import { newFromInvoke, newOnEvent } from "../utils/State.js";
3
4
  export class UIColors {
4
5
  inner;
@@ -26,35 +27,37 @@ export class UIColors {
26
27
  });
27
28
  }
28
29
  setAsCssVariables() {
29
- const id = "system-ui-color-variables";
30
- document.getElementById(id)?.remove();
31
- const element = document.createElement("style");
32
- element.id = id;
33
- element.textContent = ":root {\n";
30
+ const oldStyles = new RuntimeStyleSheet("@deprecated/system-colors");
31
+ const newStyles = new RuntimeStyleSheet("@runtime/system-colors");
34
32
  for (const [key, value] of Object.entries(this.inner)) {
35
33
  if (typeof value !== "string") {
36
34
  continue;
37
35
  }
38
- const hex = value.replace("#", "").slice(0, 6);
39
- const color = parseInt(hex, 16);
40
- const r = (color >> 16) & 255;
41
- const g = (color >> 8) & 255;
42
- const b = color & 255;
36
+ const color = Color.fromHex(value);
37
+ const { r, g, b } = color;
43
38
  // replace rust snake case with kebab case
44
39
  const name = key.replace("_", "-");
45
- element.textContent += `--system-${name}-color: ${value.slice(0, 7)};\n`;
46
- element.textContent += `--system-${name}-color-rgb: ${r}, ${g}, ${b};\n`;
47
40
  // @deprecated old names
48
- element.textContent += `--config-${name}-color: ${value.slice(0, 7)};\n`;
49
- element.textContent += `--config-${name}-color-rgb: ${r}, ${g}, ${b};\n`;
41
+ oldStyles.addVariable(`--config-${name}-color`, value.slice(0, 7));
42
+ oldStyles.addVariable(`--config-${name}-color-rgb`, `${r}, ${g}, ${b}`);
43
+ if (name.startsWith("accent")) {
44
+ newStyles.addVariable(`--system-${name}-color`, value.slice(0, 7));
45
+ newStyles.addVariable(`--system-${name}-color-rgb`, `${r}, ${g}, ${b}`);
46
+ const complement = color.complementary();
47
+ newStyles.addVariable(`--system-${name}-complementary-color`, complement.toHexString());
48
+ newStyles.addVariable(`--system-${name}-complementary-color-rgb`, `${complement.r}, ${complement.g}, ${complement.b}`);
49
+ }
50
50
  }
51
- document.head.appendChild(element);
51
+ oldStyles.applyToDocument();
52
+ newStyles.applyToDocument();
52
53
  }
53
54
  }
54
55
  export class Color {
55
- inner;
56
- constructor(inner) {
57
- this.inner = inner;
56
+ constructor(obj) {
57
+ this.r = obj.r;
58
+ this.g = obj.g;
59
+ this.b = obj.b;
60
+ this.a = obj.a;
58
61
  }
59
62
  /** generates a random solid color */
60
63
  static random() {
@@ -65,6 +68,34 @@ export class Color {
65
68
  a: 255,
66
69
  });
67
70
  }
71
+ static fromHex(hex) {
72
+ if (hex.startsWith("#")) {
73
+ hex = hex.slice(1);
74
+ }
75
+ if (hex.length === 3) {
76
+ hex = hex
77
+ .split("")
78
+ .map((char) => `${char}${char}`)
79
+ .join("");
80
+ }
81
+ if (hex.length === 6) {
82
+ hex = hex.padStart(8, "f");
83
+ }
84
+ const color = parseInt(hex.replace("#", ""), 16);
85
+ return new Color({
86
+ r: (color >> 24) & 255,
87
+ g: (color >> 16) & 255,
88
+ b: (color >> 8) & 255,
89
+ a: color & 255,
90
+ });
91
+ }
92
+ toHexString() {
93
+ return ("#" +
94
+ this.r.toString(16).padStart(2, "0") +
95
+ this.g.toString(16).padStart(2, "0") +
96
+ this.b.toString(16).padStart(2, "0") +
97
+ (this.a === 255 ? "" : this.a.toString(16).padStart(2, "0")));
98
+ }
68
99
  getRuntimeStyleSheet() {
69
100
  const styleId = "slu-lib-runtime-color-variables";
70
101
  let styleElement = document.getElementById(styleId);
@@ -92,13 +123,6 @@ export class Color {
92
123
  lines.push("}");
93
124
  sheet.textContent = lines.join("\n");
94
125
  }
95
- toHexString() {
96
- return ("#" +
97
- this.inner.r.toString(16).padStart(2, "0") +
98
- this.inner.g.toString(16).padStart(2, "0") +
99
- this.inner.b.toString(16).padStart(2, "0") +
100
- this.inner.a.toString(16).padStart(2, "0"));
101
- }
102
126
  /**
103
127
  * @param name the name of the color
104
128
  * the name will be parsed to lower kebab case and remove non-alphanumeric characters
@@ -114,8 +138,8 @@ export class Color {
114
138
  .toLowerCase();
115
139
  this.insertIntoStyleSheet({
116
140
  [`--color-${parsedName}`]: this.toHexString(),
117
- [`--color-${parsedName}-rgb`]: `${this.inner.r}, ${this.inner.g}, ${this.inner.b}`,
118
- [`--color-${parsedName}-rgba`]: `${this.inner.r}, ${this.inner.g}, ${this.inner.b}, ${this.inner.a}`,
141
+ [`--color-${parsedName}-rgb`]: `${this.r}, ${this.g}, ${this.b}`,
142
+ [`--color-${parsedName}-rgba`]: `${this.r}, ${this.g}, ${this.b}, ${this.a}`,
119
143
  });
120
144
  }
121
145
  /**
@@ -125,15 +149,22 @@ export class Color {
125
149
  * @returns a number between 0 and 255
126
150
  */
127
151
  calcLuminance(accuracy) {
128
- const { r, g, b } = this.inner;
129
152
  if (accuracy) {
130
153
  // gamma correction
131
- const gR = r ** 2.2;
132
- const gG = g ** 2.2;
133
- const gB = b ** 2.2;
154
+ const gR = this.r ** 2.2;
155
+ const gG = this.g ** 2.2;
156
+ const gB = this.b ** 2.2;
134
157
  return (0.299 * gR + 0.587 * gG + 0.114 * gB) ** (1 / 2.2);
135
158
  }
136
159
  // standard algorithm
137
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
160
+ return 0.2126 * this.r + 0.7152 * this.g + 0.0722 * this.b;
161
+ }
162
+ complementary() {
163
+ return new Color({
164
+ r: 255 - this.r,
165
+ g: 255 - this.g,
166
+ b: 255 - this.b,
167
+ a: this.a,
168
+ });
138
169
  }
139
170
  }
@@ -0,0 +1,9 @@
1
+ export declare class RuntimeStyleSheet {
2
+ #private;
3
+ constructor(styleId: string);
4
+ addVariable(key: string, value: string): void;
5
+ addStyle(style: string): void;
6
+ clear(): void;
7
+ applyToDocument(): void;
8
+ }
9
+ //# sourceMappingURL=DOM.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DOM.d.ts","sourceRoot":"","sources":["../../../src/src/utils/DOM.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAiB;;gBAKhB,OAAO,EAAE,MAAM;IAU3B,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,KAAK,IAAI,IAAI;IAKb,eAAe,IAAI,IAAI;CAKxB"}