@asdf-overlay/electron 0.9.0 → 0.9.2

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/lib/index.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import type { Overlay } from '@asdf-overlay/core';
2
- export * from './input/index.js';
3
- export * from './surface.js';
2
+ /**
3
+ * Describe a window in `Overlay`.
4
+ */
4
5
  export type OverlayWindow = {
6
+ /**
7
+ * Associated `Overlay` instance.
8
+ */
5
9
  overlay: Overlay;
10
+ /**
11
+ * Window id.
12
+ */
6
13
  id: number;
7
14
  };
package/lib/index.js CHANGED
@@ -1,2 +1 @@
1
- export * from './input/index.js';
2
- export * from './surface.js';
1
+ export {};
@@ -1,3 +1,17 @@
1
1
  import { Cursor } from '@asdf-overlay/core';
2
- export declare function toCursor(cursor: string): Cursor | undefined;
3
- export declare const KEYS: Record<number, string | undefined>;
2
+ /**
3
+ * Map CSS cursor into overlay `Cursor`.
4
+ *
5
+ * Invalid CSS cursors will be mapped to `Default`.
6
+ *
7
+ * @see https://developer.mozilla.org/ko/docs/Web/CSS/cursor
8
+ * @see https://www.electronjs.org/docs/latest/api/web-contents
9
+ */
10
+ export declare function mapCssCursor(cursor: string): Cursor | undefined;
11
+ /**
12
+ * Map Windows virtual key code into Electron accelerator keycode.
13
+ *
14
+ * @see https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
15
+ * @see https://www.electronjs.org/docs/latest/api/accelerator
16
+ */
17
+ export declare function mapKeycode(code: number): string | undefined;
package/lib/input/conv.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import { Cursor } from '@asdf-overlay/core';
2
- // https://www.electronjs.org/docs/latest/api/web-contents
3
- // https://developer.mozilla.org/ko/docs/Web/CSS/cursor
4
- export function toCursor(cursor) {
2
+ /**
3
+ * Map CSS cursor into overlay `Cursor`.
4
+ *
5
+ * Invalid CSS cursors will be mapped to `Default`.
6
+ *
7
+ * @see https://developer.mozilla.org/ko/docs/Web/CSS/cursor
8
+ * @see https://www.electronjs.org/docs/latest/api/web-contents
9
+ */
10
+ export function mapCssCursor(cursor) {
5
11
  switch (cursor) {
6
12
  case 'pointer': return Cursor.Default;
7
13
  case 'crosshair': return Cursor.Crosshair;
@@ -50,9 +56,19 @@ export function toCursor(cursor) {
50
56
  default: return Cursor.Default;
51
57
  }
52
58
  }
53
- // As per https://www.electronjs.org/docs/latest/api/accelerator
54
- // and https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
55
- export const KEYS = {
59
+ /**
60
+ * Map Windows virtual key code into Electron accelerator keycode.
61
+ *
62
+ * @see https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
63
+ * @see https://www.electronjs.org/docs/latest/api/accelerator
64
+ */
65
+ export function mapKeycode(code) {
66
+ return KEYS[code];
67
+ }
68
+ /**
69
+ * Conversion map from windows keycode to Electron accelerator keycode.
70
+ */
71
+ const KEYS = {
56
72
  8: 'Backspace',
57
73
  9: 'Tab',
58
74
  13: 'Enter',
@@ -111,6 +127,21 @@ export const KEYS = {
111
127
  91: 'Super',
112
128
  92: 'Super',
113
129
  93: 'Meta',
130
+ 96: 'num0',
131
+ 97: 'num1',
132
+ 98: 'num2',
133
+ 99: 'num3',
134
+ 100: 'num4',
135
+ 101: 'num5',
136
+ 102: 'num6',
137
+ 103: 'num7',
138
+ 104: 'num8',
139
+ 105: 'num9',
140
+ 106: 'nummult',
141
+ 108: 'numsub',
142
+ 109: 'numsub',
143
+ 110: 'numdec',
144
+ 111: 'numdiv',
114
145
  112: 'F1',
115
146
  113: 'F2',
116
147
  114: 'F3',
@@ -1,15 +1,23 @@
1
1
  import type { WebContents } from 'electron';
2
- import type { OverlayWindow } from '../index.js';
2
+ import type { OverlayWindow } from './index.js';
3
3
  import type { CursorInput, KeyboardInput } from '@asdf-overlay/core/input';
4
+ /**
5
+ * Connection from a overlay window to a Electron window.
6
+ */
4
7
  export declare class ElectronOverlayInput {
5
8
  private readonly window;
6
9
  private readonly contents;
7
10
  private readonly cursorInputHandler;
8
11
  private readonly keyboardInputHandler;
9
12
  private readonly cursorChangedHandler;
10
- forwardInput: boolean;
11
13
  private constructor();
14
+ /**
15
+ * Connect overlay inputs to a Electron `WebContents`.
16
+ */
12
17
  static connect(window: OverlayWindow, contents: WebContents): ElectronOverlayInput;
18
+ /**
19
+ * Disconnect overlay inputs.
20
+ */
13
21
  disconnect(): Promise<void>;
14
22
  private readonly clickCounts;
15
23
  private processCursorAction;
@@ -20,5 +28,4 @@ export declare class ElectronOverlayInput {
20
28
  private updateModifiers;
21
29
  sendKeyboardInput(input: KeyboardInput): void;
22
30
  private processIme;
23
- private sendInput;
24
31
  }
@@ -1,12 +1,14 @@
1
- import { KEYS, toCursor } from './conv.js';
1
+ import { mapCssCursor, mapKeycode } from './input/conv.js';
2
2
  import { Cursor } from '@asdf-overlay/core';
3
+ /**
4
+ * Connection from a overlay window to a Electron window.
5
+ */
3
6
  export class ElectronOverlayInput {
4
7
  window;
5
8
  contents;
6
9
  cursorInputHandler;
7
10
  keyboardInputHandler;
8
11
  cursorChangedHandler;
9
- forwardInput = false;
10
12
  constructor(window, contents) {
11
13
  this.window = window;
12
14
  this.contents = contents;
@@ -24,12 +26,18 @@ export class ElectronOverlayInput {
24
26
  this.sendKeyboardInput(input);
25
27
  });
26
28
  this.contents.on('cursor-changed', this.cursorChangedHandler = (_, type) => {
27
- void this.window.overlay.setBlockingCursor(this.window.id, toCursor(type));
29
+ void this.window.overlay.setBlockingCursor(this.window.id, mapCssCursor(type));
28
30
  });
29
31
  }
32
+ /**
33
+ * Connect overlay inputs to a Electron `WebContents`.
34
+ */
30
35
  static connect(window, contents) {
31
36
  return new ElectronOverlayInput({ ...window }, contents);
32
37
  }
38
+ /**
39
+ * Disconnect overlay inputs.
40
+ */
33
41
  async disconnect() {
34
42
  this.window.overlay.event.off('cursor_input', this.cursorInputHandler);
35
43
  this.window.overlay.event.off('keyboard_input', this.keyboardInputHandler);
@@ -69,7 +77,7 @@ export class ElectronOverlayInput {
69
77
  if (input.state === 'Pressed') {
70
78
  const clickCount = 1 + ~~input.doubleClick;
71
79
  this.clickCounts.push(clickCount);
72
- this.sendInput({
80
+ this.contents.sendInputEvent({
73
81
  type: 'mouseDown',
74
82
  button,
75
83
  clickCount,
@@ -84,7 +92,7 @@ export class ElectronOverlayInput {
84
92
  }
85
93
  else {
86
94
  const clickCount = this.clickCounts.pop() ?? 1;
87
- this.sendInput({
95
+ this.contents.sendInputEvent({
88
96
  type: 'mouseUp',
89
97
  button,
90
98
  clickCount,
@@ -107,7 +115,7 @@ export class ElectronOverlayInput {
107
115
  const movementY = input.windowY - this.lastWindowCursor.y;
108
116
  switch (input.kind) {
109
117
  case 'Enter': {
110
- this.sendInput({
118
+ this.contents.sendInputEvent({
111
119
  type: 'mouseEnter',
112
120
  x: input.clientX,
113
121
  y: input.clientY,
@@ -120,7 +128,7 @@ export class ElectronOverlayInput {
120
128
  break;
121
129
  }
122
130
  case 'Leave': {
123
- this.sendInput({
131
+ this.contents.sendInputEvent({
124
132
  type: 'mouseLeave',
125
133
  x: input.clientX,
126
134
  y: input.clientY,
@@ -133,7 +141,7 @@ export class ElectronOverlayInput {
133
141
  break;
134
142
  }
135
143
  case 'Move': {
136
- this.sendInput({
144
+ this.contents.sendInputEvent({
137
145
  type: 'mouseMove',
138
146
  x: input.clientX,
139
147
  y: input.clientY,
@@ -173,7 +181,7 @@ export class ElectronOverlayInput {
173
181
  modifiers: this.modifiers,
174
182
  };
175
183
  }
176
- this.sendInput(scroll);
184
+ this.contents.sendInputEvent(scroll);
177
185
  break;
178
186
  }
179
187
  case 'Action': {
@@ -238,13 +246,13 @@ export class ElectronOverlayInput {
238
246
  sendKeyboardInput(input) {
239
247
  switch (input.kind) {
240
248
  case 'Key': {
241
- const keyCode = KEYS[input.key.code];
249
+ const keyCode = mapKeycode(input.key.code);
242
250
  if (!keyCode) {
243
251
  return;
244
252
  }
245
253
  const pressed = input.state === 'Pressed';
246
254
  this.updateModifiers(keyCode, pressed);
247
- this.sendInput({
255
+ this.contents.sendInputEvent({
248
256
  type: pressed ? 'keyDown' : 'keyUp',
249
257
  keyCode,
250
258
  modifiers: this.modifiers,
@@ -252,7 +260,7 @@ export class ElectronOverlayInput {
252
260
  return;
253
261
  }
254
262
  case 'Char': {
255
- this.sendInput({
263
+ this.contents.sendInputEvent({
256
264
  type: 'char',
257
265
  keyCode: input.ch,
258
266
  modifiers: this.modifiers,
@@ -270,17 +278,11 @@ export class ElectronOverlayInput {
270
278
  return;
271
279
  }
272
280
  for (const ch of input.ime.text) {
273
- this.sendInput({
281
+ this.contents.sendInputEvent({
274
282
  type: 'char',
275
283
  keyCode: ch,
276
284
  modifiers: this.modifiers,
277
285
  });
278
286
  }
279
287
  }
280
- sendInput(e) {
281
- if (!this.forwardInput) {
282
- return;
283
- }
284
- this.contents.sendInputEvent(e);
285
- }
286
288
  }
package/lib/surface.d.ts CHANGED
@@ -2,17 +2,38 @@ import type { WebContents } from 'electron';
2
2
  import type { OverlayWindow } from './index.js';
3
3
  import EventEmitter from 'node:events';
4
4
  type Emitter = EventEmitter<{
5
+ /**
6
+ * An error has been occured while copying to overlay surface.
7
+ */
5
8
  error: [e: unknown];
6
9
  }>;
10
+ /**
11
+ * Connection from a Electron offscreen window to a overlay surface.
12
+ */
7
13
  export declare class ElectronOverlaySurface {
8
14
  private readonly window;
9
15
  private readonly contents;
16
+ /**
17
+ * Events during paints.
18
+ */
10
19
  readonly events: Emitter;
11
20
  private handler;
12
21
  private constructor();
22
+ /**
23
+ * Connect Electron `WebContents` surface to target overlay window.
24
+ */
13
25
  static connect(window: OverlayWindow, contents: WebContents): ElectronOverlaySurface;
26
+ /**
27
+ * Disconnect surface from Electron window and clear overlay surface.
28
+ */
14
29
  disconnect(): Promise<void>;
30
+ /**
31
+ * Copy overlay texture in gpu accelerated shared texture mode.
32
+ */
15
33
  private paintAccelerated;
34
+ /**
35
+ * Copy overlay texture from bitmap surface.
36
+ */
16
37
  private paintSoftware;
17
38
  private emitError;
18
39
  }
package/lib/surface.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import EventEmitter from 'node:events';
2
+ /**
3
+ * Connection from a Electron offscreen window to a overlay surface.
4
+ */
2
5
  export class ElectronOverlaySurface {
3
6
  window;
4
7
  contents;
8
+ /**
9
+ * Events during paints.
10
+ */
5
11
  events = new EventEmitter();
6
12
  handler;
7
13
  constructor(window, contents) {
@@ -26,13 +32,22 @@ export class ElectronOverlaySurface {
26
32
  contents.on('paint', this.handler);
27
33
  contents.invalidate();
28
34
  }
35
+ /**
36
+ * Connect Electron `WebContents` surface to target overlay window.
37
+ */
29
38
  static connect(window, contents) {
30
39
  return new ElectronOverlaySurface({ ...window }, contents);
31
40
  }
41
+ /**
42
+ * Disconnect surface from Electron window and clear overlay surface.
43
+ */
32
44
  async disconnect() {
33
45
  this.contents.off('paint', this.handler);
34
46
  await this.window.overlay.clearSurface(this.window.id);
35
47
  }
48
+ /**
49
+ * Copy overlay texture in gpu accelerated shared texture mode.
50
+ */
36
51
  async paintAccelerated(texture) {
37
52
  const rect = texture.metadata.captureUpdateRect ?? texture.contentRect;
38
53
  // update only changed part
@@ -47,6 +62,9 @@ export class ElectronOverlaySurface {
47
62
  this.emitError(e);
48
63
  }
49
64
  }
65
+ /**
66
+ * Copy overlay texture from bitmap surface.
67
+ */
50
68
  async paintSoftware(_dirtyRect, image) {
51
69
  // TODO:: update only changed part
52
70
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asdf-overlay/electron",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Asdf overlay Electron integration",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -15,6 +15,16 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/storycraft/asdf-overlay"
17
17
  },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./lib/index.d.ts",
21
+ "default": "./lib/index.js"
22
+ },
23
+ "./*": {
24
+ "types": "./lib/*.d.ts",
25
+ "default": "./lib/*.js"
26
+ }
27
+ },
18
28
  "files": [
19
29
  "lib/**/*"
20
30
  ],
@@ -24,7 +34,7 @@
24
34
  },
25
35
  "peerDependencies": {
26
36
  "electron": "^37.3.1",
27
- "@asdf-overlay/core": "0.9.0"
37
+ "@asdf-overlay/core": "0.9.2"
28
38
  },
29
39
  "scripts": {
30
40
  "build:dist": "tsc",