@asdf-overlay/electron 0.9.0 → 0.9.1

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,6 +1,4 @@
1
1
  import type { Overlay } from '@asdf-overlay/core';
2
- export * from './input/index.js';
3
- export * from './surface.js';
4
2
  export type OverlayWindow = {
5
3
  overlay: Overlay;
6
4
  id: number;
package/lib/index.js CHANGED
@@ -1,2 +1 @@
1
- export * from './input/index.js';
2
- export * from './surface.js';
1
+ export {};
@@ -1,3 +1,3 @@
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
+ export declare function mapCssCursor(cursor: string): Cursor | undefined;
3
+ export declare function mapKeycode(code: number): string | undefined;
package/lib/input/conv.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Cursor } from '@asdf-overlay/core';
2
2
  // https://www.electronjs.org/docs/latest/api/web-contents
3
3
  // https://developer.mozilla.org/ko/docs/Web/CSS/cursor
4
- export function toCursor(cursor) {
4
+ export function mapCssCursor(cursor) {
5
5
  switch (cursor) {
6
6
  case 'pointer': return Cursor.Default;
7
7
  case 'crosshair': return Cursor.Crosshair;
@@ -50,9 +50,12 @@ export function toCursor(cursor) {
50
50
  default: return Cursor.Default;
51
51
  }
52
52
  }
53
+ export function mapKeycode(code) {
54
+ return KEYS[code];
55
+ }
53
56
  // As per https://www.electronjs.org/docs/latest/api/accelerator
54
57
  // and https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
55
- export const KEYS = {
58
+ const KEYS = {
56
59
  8: 'Backspace',
57
60
  9: 'Tab',
58
61
  13: 'Enter',
@@ -111,6 +114,21 @@ export const KEYS = {
111
114
  91: 'Super',
112
115
  92: 'Super',
113
116
  93: 'Meta',
117
+ 96: 'num0',
118
+ 97: 'num1',
119
+ 98: 'num2',
120
+ 99: 'num3',
121
+ 100: 'num4',
122
+ 101: 'num5',
123
+ 102: 'num6',
124
+ 103: 'num7',
125
+ 104: 'num8',
126
+ 105: 'num9',
127
+ 106: 'nummult',
128
+ 108: 'numsub',
129
+ 109: 'numsub',
130
+ 110: 'numdec',
131
+ 111: 'numdiv',
114
132
  112: 'F1',
115
133
  113: 'F2',
116
134
  114: 'F3',
@@ -1,5 +1,5 @@
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
4
  export declare class ElectronOverlayInput {
5
5
  private readonly window;
@@ -7,7 +7,6 @@ export declare class ElectronOverlayInput {
7
7
  private readonly cursorInputHandler;
8
8
  private readonly keyboardInputHandler;
9
9
  private readonly cursorChangedHandler;
10
- forwardInput: boolean;
11
10
  private constructor();
12
11
  static connect(window: OverlayWindow, contents: WebContents): ElectronOverlayInput;
13
12
  disconnect(): Promise<void>;
@@ -20,5 +19,4 @@ export declare class ElectronOverlayInput {
20
19
  private updateModifiers;
21
20
  sendKeyboardInput(input: KeyboardInput): void;
22
21
  private processIme;
23
- private sendInput;
24
22
  }
@@ -1,4 +1,4 @@
1
- import { KEYS, toCursor } from './conv.js';
1
+ import { mapCssCursor, mapKeycode } from './input/conv.js';
2
2
  import { Cursor } from '@asdf-overlay/core';
3
3
  export class ElectronOverlayInput {
4
4
  window;
@@ -6,7 +6,6 @@ export class ElectronOverlayInput {
6
6
  cursorInputHandler;
7
7
  keyboardInputHandler;
8
8
  cursorChangedHandler;
9
- forwardInput = false;
10
9
  constructor(window, contents) {
11
10
  this.window = window;
12
11
  this.contents = contents;
@@ -24,7 +23,7 @@ export class ElectronOverlayInput {
24
23
  this.sendKeyboardInput(input);
25
24
  });
26
25
  this.contents.on('cursor-changed', this.cursorChangedHandler = (_, type) => {
27
- void this.window.overlay.setBlockingCursor(this.window.id, toCursor(type));
26
+ void this.window.overlay.setBlockingCursor(this.window.id, mapCssCursor(type));
28
27
  });
29
28
  }
30
29
  static connect(window, contents) {
@@ -69,7 +68,7 @@ export class ElectronOverlayInput {
69
68
  if (input.state === 'Pressed') {
70
69
  const clickCount = 1 + ~~input.doubleClick;
71
70
  this.clickCounts.push(clickCount);
72
- this.sendInput({
71
+ this.contents.sendInputEvent({
73
72
  type: 'mouseDown',
74
73
  button,
75
74
  clickCount,
@@ -84,7 +83,7 @@ export class ElectronOverlayInput {
84
83
  }
85
84
  else {
86
85
  const clickCount = this.clickCounts.pop() ?? 1;
87
- this.sendInput({
86
+ this.contents.sendInputEvent({
88
87
  type: 'mouseUp',
89
88
  button,
90
89
  clickCount,
@@ -107,7 +106,7 @@ export class ElectronOverlayInput {
107
106
  const movementY = input.windowY - this.lastWindowCursor.y;
108
107
  switch (input.kind) {
109
108
  case 'Enter': {
110
- this.sendInput({
109
+ this.contents.sendInputEvent({
111
110
  type: 'mouseEnter',
112
111
  x: input.clientX,
113
112
  y: input.clientY,
@@ -120,7 +119,7 @@ export class ElectronOverlayInput {
120
119
  break;
121
120
  }
122
121
  case 'Leave': {
123
- this.sendInput({
122
+ this.contents.sendInputEvent({
124
123
  type: 'mouseLeave',
125
124
  x: input.clientX,
126
125
  y: input.clientY,
@@ -133,7 +132,7 @@ export class ElectronOverlayInput {
133
132
  break;
134
133
  }
135
134
  case 'Move': {
136
- this.sendInput({
135
+ this.contents.sendInputEvent({
137
136
  type: 'mouseMove',
138
137
  x: input.clientX,
139
138
  y: input.clientY,
@@ -173,7 +172,7 @@ export class ElectronOverlayInput {
173
172
  modifiers: this.modifiers,
174
173
  };
175
174
  }
176
- this.sendInput(scroll);
175
+ this.contents.sendInputEvent(scroll);
177
176
  break;
178
177
  }
179
178
  case 'Action': {
@@ -238,13 +237,13 @@ export class ElectronOverlayInput {
238
237
  sendKeyboardInput(input) {
239
238
  switch (input.kind) {
240
239
  case 'Key': {
241
- const keyCode = KEYS[input.key.code];
240
+ const keyCode = mapKeycode(input.key.code);
242
241
  if (!keyCode) {
243
242
  return;
244
243
  }
245
244
  const pressed = input.state === 'Pressed';
246
245
  this.updateModifiers(keyCode, pressed);
247
- this.sendInput({
246
+ this.contents.sendInputEvent({
248
247
  type: pressed ? 'keyDown' : 'keyUp',
249
248
  keyCode,
250
249
  modifiers: this.modifiers,
@@ -252,7 +251,7 @@ export class ElectronOverlayInput {
252
251
  return;
253
252
  }
254
253
  case 'Char': {
255
- this.sendInput({
254
+ this.contents.sendInputEvent({
256
255
  type: 'char',
257
256
  keyCode: input.ch,
258
257
  modifiers: this.modifiers,
@@ -270,17 +269,11 @@ export class ElectronOverlayInput {
270
269
  return;
271
270
  }
272
271
  for (const ch of input.ime.text) {
273
- this.sendInput({
272
+ this.contents.sendInputEvent({
274
273
  type: 'char',
275
274
  keyCode: ch,
276
275
  modifiers: this.modifiers,
277
276
  });
278
277
  }
279
278
  }
280
- sendInput(e) {
281
- if (!this.forwardInput) {
282
- return;
283
- }
284
- this.contents.sendInputEvent(e);
285
- }
286
279
  }
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.1",
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
  ],