@opendaw/lib-dom 0.0.62 → 0.0.63

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dragging.d.ts","sourceRoot":"","sources":["../src/dragging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAkB,MAAM,EAAY,UAAU,EAAa,MAAM,kBAAkB,CAAA;AAG1G,OAAO,EAAS,oBAAoB,EAAC,MAAM,UAAU,CAAA;AAGrD,yBAAiB,QAAQ,CAAC;IACtB,UAAiB,OAAO;QACpB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;QAC1B,MAAM,CAAC,IAAI,IAAI,CAAA;QACf,OAAO,CAAC,IAAI,IAAI,CAAA;QAChB,OAAO,CAAC,IAAI,IAAI,CAAA;QAChB,WAAW,CAAC,EAAE,WAAW,CAAA;KAC5B;IAED,UAAiB,KAAK;QAClB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;QACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;QAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAC5B;IAED,UAAiB,cAAc;QAC3B,UAAU,CAAC,EAAE,OAAO,CAAA;QACpB,SAAS,CAAC,EAAE,OAAO,CAAA;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;QAC1B,WAAW,CAAC,EAAE,OAAO,CAAA;QACrB,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAChC;IAEM,IAAI,cAAc,SAAQ,CAAA;IAE1B,MAAM,MAAM,GAAI,CAAC,SAAS,oBAAoB,EAAE,QAAQ,CAAC,EACT,SAAS,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,EAC5C,UAAU,cAAc,KAAG,UAoIjF,CAAA;CACJ"}
1
+ {"version":3,"file":"dragging.d.ts","sourceRoot":"","sources":["../src/dragging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAkB,MAAM,EAAY,UAAU,EAAa,MAAM,kBAAkB,CAAA;AAG1G,OAAO,EAAS,oBAAoB,EAAC,MAAM,UAAU,CAAA;AAGrD,yBAAiB,QAAQ,CAAC;IACtB,UAAiB,OAAO;QACpB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;QAC1B,MAAM,CAAC,IAAI,IAAI,CAAA;QACf,OAAO,CAAC,IAAI,IAAI,CAAA;QAChB,OAAO,CAAC,IAAI,IAAI,CAAA;QAChB,WAAW,CAAC,EAAE,WAAW,CAAA;KAC5B;IAED,UAAiB,KAAK;QAClB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;QACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;QAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAC5B;IAED,UAAiB,cAAc;QAC3B,UAAU,CAAC,EAAE,OAAO,CAAA;QACpB,SAAS,CAAC,EAAE,OAAO,CAAA;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;QAC1B,WAAW,CAAC,EAAE,OAAO,CAAA;QACrB,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAChC;IAEM,IAAI,cAAc,SAAQ,CAAA;IAE1B,MAAM,MAAM,GAAI,CAAC,SAAS,oBAAoB,EAAE,QAAQ,CAAC,EACT,SAAS,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,EAC5C,UAAU,cAAc,KAAG,UAsIjF,CAAA;CACJ"}
package/dist/dragging.js CHANGED
@@ -23,7 +23,12 @@ export var Dragging;
23
23
  const pointerId = event.pointerId;
24
24
  event.stopPropagation();
25
25
  event.stopImmediatePropagation();
26
- target.setPointerCapture(pointerId);
26
+ try {
27
+ target.setPointerCapture(pointerId);
28
+ }
29
+ catch (_) {
30
+ return;
31
+ }
27
32
  // Pointer lock configuration
28
33
  const usePointerLock = options?.pointerLock === true && Dragging.usePointerLock;
29
34
  const threshold = options?.pointerLockThreshold ?? 16;
package/dist/fonts.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type FontFaceProperties = {
2
2
  "font-family": string;
3
3
  "font-style": "normal" | "italic" | "oblique";
4
- "font-weight": 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 | "normal" | "bold" | "bolder" | "lighter";
4
+ "font-weight": 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 | "normal" | "bold" | "bolder" | "lighter" | `${number} ${number}`;
5
5
  "src": string;
6
6
  };
7
7
  export declare const loadFont: (properties: FontFaceProperties) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"fonts.d.ts","sourceRoot":"","sources":["../src/fonts.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC7B,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC7C,aAAa,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IACpH,KAAK,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,YAAY,kBAAkB,kBAe5D,CAAA;AAGD,eAAO,MAAM,oBAAoB,GAAI,SAAS,wBAAwB,EACjC,YAAY,MAAM,EAClB,UAAU,MAAM,KAAG,MAKvD,CAAA"}
1
+ {"version":3,"file":"fonts.d.ts","sourceRoot":"","sources":["../src/fonts.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC7B,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC7C,aAAa,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAA;IAC5I,KAAK,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,YAAY,kBAAkB,kBAe5D,CAAA;AAGD,eAAO,MAAM,oBAAoB,GAAI,SAAS,wBAAwB,EACjC,YAAY,MAAM,EAClB,UAAU,MAAM,KAAG,MAKvD,CAAA"}
package/dist/fonts.js CHANGED
@@ -9,7 +9,7 @@ export const loadFont = async (properties) => {
9
9
  });
10
10
  await fontFace.load();
11
11
  document.fonts.add(fontFace);
12
- console.debug(`font-family: '${fontFace.family}'`);
12
+ console.debug(`font loaded '${fontFace.family} ${fontFace.style} ${fontFace.weight}'`);
13
13
  }
14
14
  catch (error) {
15
15
  console.error(error);
package/dist/index.d.ts CHANGED
@@ -10,8 +10,11 @@ export * from "./files";
10
10
  export * from "./fonts";
11
11
  export * from "./frames";
12
12
  export * from "./html";
13
+ export * from "./key";
13
14
  export * from "./keyboard";
14
15
  export * from "./modfier-keys";
16
+ export * from "./shortcut-definitions";
17
+ export * from "./shortcut-manager";
15
18
  export * from "./stream";
16
19
  export * from "./svg";
17
20
  export * from "./terminable";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA;AACrB,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -18,8 +18,11 @@ export * from "./files";
18
18
  export * from "./fonts";
19
19
  export * from "./frames";
20
20
  export * from "./html";
21
+ export * from "./key";
21
22
  export * from "./keyboard";
22
23
  export * from "./modfier-keys";
24
+ export * from "./shortcut-definitions";
25
+ export * from "./shortcut-manager";
23
26
  export * from "./stream";
24
27
  export * from "./svg";
25
28
  export * from "./terminable";
package/dist/key.d.ts ADDED
@@ -0,0 +1,102 @@
1
+ export declare namespace Key {
2
+ const KeyA = "KeyA";
3
+ const KeyB = "KeyB";
4
+ const KeyC = "KeyC";
5
+ const KeyD = "KeyD";
6
+ const KeyE = "KeyE";
7
+ const KeyF = "KeyF";
8
+ const KeyG = "KeyG";
9
+ const KeyH = "KeyH";
10
+ const KeyI = "KeyI";
11
+ const KeyJ = "KeyJ";
12
+ const KeyK = "KeyK";
13
+ const KeyL = "KeyL";
14
+ const KeyM = "KeyM";
15
+ const KeyN = "KeyN";
16
+ const KeyO = "KeyO";
17
+ const KeyP = "KeyP";
18
+ const KeyQ = "KeyQ";
19
+ const KeyR = "KeyR";
20
+ const KeyS = "KeyS";
21
+ const KeyT = "KeyT";
22
+ const KeyU = "KeyU";
23
+ const KeyV = "KeyV";
24
+ const KeyW = "KeyW";
25
+ const KeyX = "KeyX";
26
+ const KeyY = "KeyY";
27
+ const KeyZ = "KeyZ";
28
+ const Digit0 = "Digit0";
29
+ const Digit1 = "Digit1";
30
+ const Digit2 = "Digit2";
31
+ const Digit3 = "Digit3";
32
+ const Digit4 = "Digit4";
33
+ const Digit5 = "Digit5";
34
+ const Digit6 = "Digit6";
35
+ const Digit7 = "Digit7";
36
+ const Digit8 = "Digit8";
37
+ const Digit9 = "Digit9";
38
+ const F1 = "F1";
39
+ const F2 = "F2";
40
+ const F3 = "F3";
41
+ const F4 = "F4";
42
+ const F5 = "F5";
43
+ const F6 = "F6";
44
+ const F7 = "F7";
45
+ const F8 = "F8";
46
+ const F9 = "F9";
47
+ const F10 = "F10";
48
+ const F11 = "F11";
49
+ const F12 = "F12";
50
+ const ArrowUp = "ArrowUp";
51
+ const ArrowDown = "ArrowDown";
52
+ const ArrowLeft = "ArrowLeft";
53
+ const ArrowRight = "ArrowRight";
54
+ const Enter = "Enter";
55
+ const Space = "Space";
56
+ const Tab = "Tab";
57
+ const Escape = "Escape";
58
+ const Backspace = "Backspace";
59
+ const Delete = "Delete";
60
+ const DeleteAction = "DeleteAction";
61
+ const Insert = "Insert";
62
+ const Home = "Home";
63
+ const End = "End";
64
+ const PageUp = "PageUp";
65
+ const PageDown = "PageDown";
66
+ const ShiftLeft = "ShiftLeft";
67
+ const ShiftRight = "ShiftRight";
68
+ const ControlLeft = "ControlLeft";
69
+ const ControlRight = "ControlRight";
70
+ const AltLeft = "AltLeft";
71
+ const AltRight = "AltRight";
72
+ const MetaLeft = "MetaLeft";
73
+ const MetaRight = "MetaRight";
74
+ const Minus = "Minus";
75
+ const Equal = "Equal";
76
+ const BracketLeft = "BracketLeft";
77
+ const BracketRight = "BracketRight";
78
+ const Backslash = "Backslash";
79
+ const Semicolon = "Semicolon";
80
+ const Quote = "Quote";
81
+ const Backquote = "Backquote";
82
+ const Comma = "Comma";
83
+ const Period = "Period";
84
+ const Slash = "Slash";
85
+ const Numpad0 = "Numpad0";
86
+ const Numpad1 = "Numpad1";
87
+ const Numpad2 = "Numpad2";
88
+ const Numpad3 = "Numpad3";
89
+ const Numpad4 = "Numpad4";
90
+ const Numpad5 = "Numpad5";
91
+ const Numpad6 = "Numpad6";
92
+ const Numpad7 = "Numpad7";
93
+ const Numpad8 = "Numpad8";
94
+ const Numpad9 = "Numpad9";
95
+ const NumpadAdd = "NumpadAdd";
96
+ const NumpadSubtract = "NumpadSubtract";
97
+ const NumpadMultiply = "NumpadMultiply";
98
+ const NumpadDivide = "NumpadDivide";
99
+ const NumpadDecimal = "NumpadDecimal";
100
+ const NumpadEnter = "NumpadEnter";
101
+ }
102
+ //# sourceMappingURL=key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../src/key.ts"],"names":[],"mappings":"AAAA,yBAAiB,GAAG,CAAC;IACV,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IACnB,MAAM,IAAI,SAAS,CAAA;IAC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B,MAAM,OAAO,YAAY,CAAA;IACzB,MAAM,OAAO,YAAY,CAAA;IACzB,MAAM,OAAO,YAAY,CAAA;IACzB,MAAM,SAAS,cAAc,CAAA;IAC7B,MAAM,cAAc,mBAAmB,CAAA;IACvC,MAAM,cAAc,mBAAmB,CAAA;IACvC,MAAM,YAAY,iBAAiB,CAAA;IACnC,MAAM,aAAa,kBAAkB,CAAA;IACrC,MAAM,WAAW,gBAAgB,CAAA;CAC3C"}
package/dist/key.js ADDED
@@ -0,0 +1,102 @@
1
+ export var Key;
2
+ (function (Key) {
3
+ Key.KeyA = "KeyA";
4
+ Key.KeyB = "KeyB";
5
+ Key.KeyC = "KeyC";
6
+ Key.KeyD = "KeyD";
7
+ Key.KeyE = "KeyE";
8
+ Key.KeyF = "KeyF";
9
+ Key.KeyG = "KeyG";
10
+ Key.KeyH = "KeyH";
11
+ Key.KeyI = "KeyI";
12
+ Key.KeyJ = "KeyJ";
13
+ Key.KeyK = "KeyK";
14
+ Key.KeyL = "KeyL";
15
+ Key.KeyM = "KeyM";
16
+ Key.KeyN = "KeyN";
17
+ Key.KeyO = "KeyO";
18
+ Key.KeyP = "KeyP";
19
+ Key.KeyQ = "KeyQ";
20
+ Key.KeyR = "KeyR";
21
+ Key.KeyS = "KeyS";
22
+ Key.KeyT = "KeyT";
23
+ Key.KeyU = "KeyU";
24
+ Key.KeyV = "KeyV";
25
+ Key.KeyW = "KeyW";
26
+ Key.KeyX = "KeyX";
27
+ Key.KeyY = "KeyY";
28
+ Key.KeyZ = "KeyZ";
29
+ Key.Digit0 = "Digit0";
30
+ Key.Digit1 = "Digit1";
31
+ Key.Digit2 = "Digit2";
32
+ Key.Digit3 = "Digit3";
33
+ Key.Digit4 = "Digit4";
34
+ Key.Digit5 = "Digit5";
35
+ Key.Digit6 = "Digit6";
36
+ Key.Digit7 = "Digit7";
37
+ Key.Digit8 = "Digit8";
38
+ Key.Digit9 = "Digit9";
39
+ Key.F1 = "F1";
40
+ Key.F2 = "F2";
41
+ Key.F3 = "F3";
42
+ Key.F4 = "F4";
43
+ Key.F5 = "F5";
44
+ Key.F6 = "F6";
45
+ Key.F7 = "F7";
46
+ Key.F8 = "F8";
47
+ Key.F9 = "F9";
48
+ Key.F10 = "F10";
49
+ Key.F11 = "F11";
50
+ Key.F12 = "F12";
51
+ Key.ArrowUp = "ArrowUp";
52
+ Key.ArrowDown = "ArrowDown";
53
+ Key.ArrowLeft = "ArrowLeft";
54
+ Key.ArrowRight = "ArrowRight";
55
+ Key.Enter = "Enter";
56
+ Key.Space = "Space";
57
+ Key.Tab = "Tab";
58
+ Key.Escape = "Escape";
59
+ Key.Backspace = "Backspace";
60
+ Key.Delete = "Delete";
61
+ Key.DeleteAction = "DeleteAction";
62
+ Key.Insert = "Insert";
63
+ Key.Home = "Home";
64
+ Key.End = "End";
65
+ Key.PageUp = "PageUp";
66
+ Key.PageDown = "PageDown";
67
+ Key.ShiftLeft = "ShiftLeft";
68
+ Key.ShiftRight = "ShiftRight";
69
+ Key.ControlLeft = "ControlLeft";
70
+ Key.ControlRight = "ControlRight";
71
+ Key.AltLeft = "AltLeft";
72
+ Key.AltRight = "AltRight";
73
+ Key.MetaLeft = "MetaLeft";
74
+ Key.MetaRight = "MetaRight";
75
+ Key.Minus = "Minus";
76
+ Key.Equal = "Equal";
77
+ Key.BracketLeft = "BracketLeft";
78
+ Key.BracketRight = "BracketRight";
79
+ Key.Backslash = "Backslash";
80
+ Key.Semicolon = "Semicolon";
81
+ Key.Quote = "Quote";
82
+ Key.Backquote = "Backquote";
83
+ Key.Comma = "Comma";
84
+ Key.Period = "Period";
85
+ Key.Slash = "Slash";
86
+ Key.Numpad0 = "Numpad0";
87
+ Key.Numpad1 = "Numpad1";
88
+ Key.Numpad2 = "Numpad2";
89
+ Key.Numpad3 = "Numpad3";
90
+ Key.Numpad4 = "Numpad4";
91
+ Key.Numpad5 = "Numpad5";
92
+ Key.Numpad6 = "Numpad6";
93
+ Key.Numpad7 = "Numpad7";
94
+ Key.Numpad8 = "Numpad8";
95
+ Key.Numpad9 = "Numpad9";
96
+ Key.NumpadAdd = "NumpadAdd";
97
+ Key.NumpadSubtract = "NumpadSubtract";
98
+ Key.NumpadMultiply = "NumpadMultiply";
99
+ Key.NumpadDivide = "NumpadDivide";
100
+ Key.NumpadDecimal = "NumpadDecimal";
101
+ Key.NumpadEnter = "NumpadEnter";
102
+ })(Key || (Key = {}));
@@ -1 +1 @@
1
- {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"AAGA,yBAAiB,QAAQ,CAAC;IACf,MAAM,YAAY,GAAI,sBAAoB;QAC7C,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAA;KACnB,YAA0C,CAAA;IACpC,MAAM,SAAS,GAAI,YAAU;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,YAAW,CAAA;IAC3D,MAAM,QAAQ,GAAI,OAAO,aAAa,YAAiG,CAAA;IACvI,MAAM,WAAW,GAAI,OAAO,aAAa,YAAoE,CAAA;IAC7G,MAAM,aAAa,GAAI,OAAO,aAAa,YAAmE,CAAA;CACxH"}
1
+ {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"AAEA,yBAAiB,QAAQ,CAAC;IACf,MAAM,YAAY,GAAI,sBAAoB;QAC7C,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAA;KACnB,YAA0C,CAAA;IACpC,MAAM,SAAS,GAAI,YAAU;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,YAAW,CAAA;IAC3D,MAAM,QAAQ,GAAI,OAAO,aAAa,YAA0D,CAAA;IAChG,MAAM,WAAW,GAAI,OAAO,aAAa,YAAoE,CAAA;IAC7G,MAAM,aAAa,GAAI,OAAO,aAAa,YAAmE,CAAA;CACxH"}
package/dist/keyboard.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { Browser } from "./browser";
2
- import { Events } from "./events";
3
2
  export var Keyboard;
4
3
  (function (Keyboard) {
5
4
  Keyboard.isControlKey = ({ ctrlKey, metaKey }) => Browser.isMacOS() ? metaKey : ctrlKey;
6
5
  Keyboard.isCopyKey = ({ altKey }) => altKey;
7
- Keyboard.isDelete = (event) => !Events.isTextInput(event.target) && (event.code === "Delete" || event.code === "Backspace");
6
+ Keyboard.isDelete = (event) => event.code === "Delete" || event.code === "Backspace";
8
7
  Keyboard.isSelectAll = (event) => Keyboard.isControlKey(event) && !event.shiftKey && event.code === "KeyA";
9
8
  Keyboard.isDeselectAll = (event) => Keyboard.isControlKey(event) && event.shiftKey && event.code === "KeyA";
10
9
  })(Keyboard || (Keyboard = {}));
@@ -0,0 +1,17 @@
1
+ import { Shortcut } from "./shortcut-manager";
2
+ import { JSONValue } from "@opendaw/lib-std";
3
+ export type ShortcutDefinition = {
4
+ shortcut: Shortcut;
5
+ description: string;
6
+ };
7
+ export type ShortcutDefinitions = Record<string, ShortcutDefinition>;
8
+ export declare namespace ShortcutDefinitions {
9
+ const copy: <T extends ShortcutDefinitions>(defs: T) => T;
10
+ const copyInto: (source: ShortcutDefinitions, target: ShortcutDefinitions) => void;
11
+ const toJSON: (defs: ShortcutDefinitions) => JSONValue;
12
+ const fromJSON: (defs: ShortcutDefinitions, values: JSONValue) => void;
13
+ }
14
+ export declare namespace ShortcutValidator {
15
+ const validate: <T extends ShortcutDefinitions>(actions: T) => T;
16
+ }
17
+ //# sourceMappingURL=shortcut-definitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortcut-definitions.d.ts","sourceRoot":"","sources":["../src/shortcut-definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAW,SAAS,EAAC,MAAM,kBAAkB,CAAA;AAEpD,MAAM,MAAM,kBAAkB,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5E,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;AAEpE,yBAAiB,mBAAmB,CAAC;IAC1B,MAAM,IAAI,GAAI,CAAC,SAAS,mBAAmB,EAAE,MAAM,CAAC,KAAG,CAM7D,CAAA;IAEM,MAAM,QAAQ,GAAI,QAAQ,mBAAmB,EAAE,QAAQ,mBAAmB,KAAG,IAInF,CAAA;IAEM,MAAM,MAAM,GAAI,MAAM,mBAAmB,KAAG,SAMlD,CAAA;IAEM,MAAM,QAAQ,GAAI,MAAM,mBAAmB,EAAE,QAAQ,SAAS,KAAG,IAOvE,CAAA;CACJ;AAED,yBAAiB,iBAAiB,CAAC;IACxB,MAAM,QAAQ,GAAI,CAAC,SAAS,mBAAmB,EAAE,SAAS,CAAC,KAAG,CAUpE,CAAA;CACJ"}
@@ -0,0 +1,50 @@
1
+ import { Shortcut } from "./shortcut-manager";
2
+ import { isAbsent } from "@opendaw/lib-std";
3
+ export var ShortcutDefinitions;
4
+ (function (ShortcutDefinitions) {
5
+ ShortcutDefinitions.copy = (defs) => {
6
+ const result = {};
7
+ for (const [key, { shortcut, description }] of Object.entries(defs)) {
8
+ result[key] = { shortcut: shortcut.copy(), description };
9
+ }
10
+ return result;
11
+ };
12
+ ShortcutDefinitions.copyInto = (source, target) => {
13
+ for (const [key, { shortcut }] of Object.entries(source)) {
14
+ target[key].shortcut.overrideWith(shortcut.copy());
15
+ }
16
+ };
17
+ ShortcutDefinitions.toJSON = (defs) => {
18
+ const result = {};
19
+ for (const [key, { shortcut }] of Object.entries(defs)) {
20
+ result[key] = shortcut.toJSON();
21
+ }
22
+ return result;
23
+ };
24
+ ShortcutDefinitions.fromJSON = (defs, values) => {
25
+ if (typeof values !== "object" || values === null || Array.isArray(values)) {
26
+ return;
27
+ }
28
+ for (const [key, value] of Object.entries(values)) {
29
+ const def = defs[key];
30
+ if (isAbsent(def)) {
31
+ continue;
32
+ }
33
+ Shortcut.fromJSON(value).ifSome(keys => def.shortcut.overrideWith(keys));
34
+ }
35
+ };
36
+ })(ShortcutDefinitions || (ShortcutDefinitions = {}));
37
+ export var ShortcutValidator;
38
+ (function (ShortcutValidator) {
39
+ ShortcutValidator.validate = (actions) => {
40
+ const entries = Object.entries(actions);
41
+ for (let i = 0; i < entries.length; i++) {
42
+ for (let j = i + 1; j < entries.length; j++) {
43
+ if (entries[i][1].shortcut.equals(entries[j][1].shortcut)) {
44
+ alert(`Shortcut conflict: '${entries[i][0]}' and '${entries[j][0]}' both use ${entries[i][1].shortcut.format()}`);
45
+ }
46
+ }
47
+ }
48
+ return actions;
49
+ };
50
+ })(ShortcutValidator || (ShortcutValidator = {}));
@@ -0,0 +1,61 @@
1
+ import { int, JSONValue, Maybe, Observer, Option, Predicate, Provider, Subscription, Terminable } from "@opendaw/lib-std";
2
+ export declare class ShortcutManager {
3
+ #private;
4
+ static get(): ShortcutManager;
5
+ readonly global: ShortcutContext;
6
+ private constructor();
7
+ createContext(activation: Predicate<void> | Element, name: string, priority?: int): ShortcutContext;
8
+ hasConflict(shortcut: Shortcut): boolean;
9
+ handleEvent(event: KeyboardEvent): void;
10
+ }
11
+ export declare class ShortcutContext implements Terminable {
12
+ #private;
13
+ constructor(isActive: Predicate<void>, name: string, priority: int);
14
+ get active(): boolean;
15
+ get name(): string;
16
+ get priority(): int;
17
+ get entries(): ReadonlyArray<ShortcutEntry>;
18
+ register(shortcut: Shortcut, consume: Provider<Maybe<boolean> | unknown>, options?: ShortcutOptions): Subscription;
19
+ hasConflict(shortcut: Shortcut): boolean;
20
+ own<T extends Terminable>(terminable: T): T;
21
+ terminate(): void;
22
+ }
23
+ export declare class Shortcut {
24
+ #private;
25
+ static of(code: string, modifiers?: {
26
+ ctrl?: boolean;
27
+ shift?: boolean;
28
+ alt?: boolean;
29
+ }): Shortcut;
30
+ static fromJSON(value: JSONValue): Option<Shortcut>;
31
+ static fromEvent(event: KeyboardEvent): Option<Shortcut>;
32
+ private constructor();
33
+ get code(): string;
34
+ get ctrl(): boolean;
35
+ get shift(): boolean;
36
+ get alt(): boolean;
37
+ equals(other: Shortcut): boolean;
38
+ matches(event: KeyboardEvent): boolean;
39
+ format(): ReadonlyArray<string>;
40
+ overrideWith(shortcut: Shortcut): void;
41
+ subscribe(observer: Observer<void>): Subscription;
42
+ toJSON(): JSONValue;
43
+ copy(): Shortcut;
44
+ toString(): string;
45
+ }
46
+ export type ShortcutOptions = {
47
+ readonly preventDefault?: boolean;
48
+ readonly allowRepeat?: boolean;
49
+ readonly activeInTextField?: boolean;
50
+ readonly priority?: number;
51
+ };
52
+ export declare namespace ShortcutOptions {
53
+ const Default: ShortcutOptions;
54
+ }
55
+ type ShortcutEntry = {
56
+ readonly shortcut: Shortcut;
57
+ readonly consume: Provider<Maybe<boolean> | unknown>;
58
+ readonly options: ShortcutOptions;
59
+ };
60
+ export {};
61
+ //# sourceMappingURL=shortcut-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortcut-manager.d.ts","sourceRoot":"","sources":["../src/shortcut-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,GAAG,EAEH,SAAS,EAET,KAAK,EAGL,QAAQ,EACR,MAAM,EACN,SAAS,EAET,QAAQ,EACR,YAAY,EACZ,UAAU,EAEb,MAAM,kBAAkB,CAAA;AAMzB,qBAAa,eAAe;;IAExB,MAAM,CAAC,GAAG,IAAI,eAAe;IAE7B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAIhC,OAAO;IAKP,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,eAAe;IAanG,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IAIxC,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;CAoB1C;AAED,qBAAa,eAAgB,YAAW,UAAU;;gBAOlC,QAAQ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CAAC,MAAM,CAAC;IAiB/B,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAYtC,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,YAAY;IAEjD,MAAM,IAAI,SAAS;IAEnB,IAAI,IAAI,QAAQ;IAEhB,QAAQ,IAAI,MAAM;CACrB;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAA;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,yBAAiB,eAAe,CAAC;IACtB,MAAM,OAAO,EAAE,eAKrB,CAAA;CACJ;AAED,KAAK,aAAa,GAAG;IACjB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAA;IACpD,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;CACpC,CAAA"}
@@ -0,0 +1,254 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Arrays, BinarySearch, isAbsent, Lazy, Notifier, NumberComparator, Option, Predicates, Terminable, Terminator } from "@opendaw/lib-std";
11
+ import { Browser } from "./browser";
12
+ import { Events } from "./events";
13
+ import { Key } from "./key";
14
+ import { Keyboard } from "./keyboard";
15
+ export class ShortcutManager {
16
+ static get() { return new ShortcutManager(); }
17
+ global;
18
+ #contexts = [];
19
+ constructor() {
20
+ this.global = this.createContext(Predicates.alwaysTrue, "Global");
21
+ console.debug("ShortcutManager installed");
22
+ }
23
+ createContext(activation, name, priority) {
24
+ const isActive = typeof activation === "function"
25
+ ? activation :
26
+ () => activation.contains(document.activeElement);
27
+ const context = new ShortcutContext(isActive, name, priority ?? 0);
28
+ const index = BinarySearch.leftMostMapped(this.#contexts, context.priority, (a, b) => b - a, ({ priority }) => priority);
29
+ this.#contexts.splice(index, 0, context);
30
+ console.debug(this.#contexts.map(({ name, priority }) => `${name} (${priority})`).join(", "));
31
+ context.own(Terminable.create(() => Arrays.remove(this.#contexts, context)));
32
+ return context;
33
+ }
34
+ hasConflict(shortcut) {
35
+ return this.#contexts.some(context => context.hasConflict(shortcut));
36
+ }
37
+ handleEvent(event) {
38
+ for (const context of this.#contexts) {
39
+ if (context.active && this.#tryHandle(event, context)) {
40
+ console.debug("consumed by", context.name);
41
+ return;
42
+ }
43
+ }
44
+ }
45
+ #tryHandle(event, context) {
46
+ for (const { shortcut, consume, options } of context.entries) {
47
+ if (!options.activeInTextField && Events.isTextInput(event.target)) {
48
+ continue;
49
+ }
50
+ if (!options.allowRepeat && event.repeat) {
51
+ continue;
52
+ }
53
+ if (!shortcut.matches(event)) {
54
+ continue;
55
+ }
56
+ if (options.preventDefault ?? true) {
57
+ event.preventDefault();
58
+ }
59
+ const returnValue = consume();
60
+ return returnValue !== false; // everything counts as consumed unless one specifically returns false
61
+ }
62
+ return false;
63
+ }
64
+ }
65
+ __decorate([
66
+ Lazy,
67
+ __metadata("design:type", Function),
68
+ __metadata("design:paramtypes", []),
69
+ __metadata("design:returntype", ShortcutManager)
70
+ ], ShortcutManager, "get", null);
71
+ export class ShortcutContext {
72
+ #terminator = new Terminator();
73
+ #isActive;
74
+ #name;
75
+ #priority;
76
+ #entries = [];
77
+ constructor(isActive, name, priority) {
78
+ this.#isActive = isActive;
79
+ this.#name = name;
80
+ this.#priority = priority;
81
+ }
82
+ get active() { return this.#isActive(); }
83
+ get name() { return this.#name; }
84
+ get priority() { return this.#priority; }
85
+ get entries() { return this.#entries; }
86
+ register(shortcut, consume, options) {
87
+ const entry = { shortcut, consume, options: options ?? ShortcutOptions.Default };
88
+ const index = BinarySearch.leftMostMapped(this.#entries, entry.options.priority ?? 0, NumberComparator, ({ options: { priority } }) => priority ?? 0);
89
+ this.#entries.splice(index, 0, entry);
90
+ return this.#terminator.own({ terminate: () => this.#entries.splice(this.#entries.indexOf(entry), 1) });
91
+ }
92
+ hasConflict(shortcut) { return this.#entries.some(entry => entry.shortcut.equals(shortcut)); }
93
+ own(terminable) { return this.#terminator.own(terminable); }
94
+ terminate() { this.#terminator.terminate(); }
95
+ }
96
+ export class Shortcut {
97
+ static of(code, modifiers) {
98
+ return new Shortcut(code, modifiers?.ctrl, modifiers?.shift, modifiers?.alt);
99
+ }
100
+ static fromJSON(value) {
101
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
102
+ return Option.None;
103
+ }
104
+ const { code, ctrl, shift, alt } = value;
105
+ if (typeof code !== "string") {
106
+ return Option.None;
107
+ }
108
+ if (typeof ctrl !== "boolean") {
109
+ return Option.None;
110
+ }
111
+ if (typeof shift !== "boolean") {
112
+ return Option.None;
113
+ }
114
+ if (typeof alt !== "boolean") {
115
+ return Option.None;
116
+ }
117
+ return Option.wrap(new Shortcut(code, ctrl, shift, alt));
118
+ }
119
+ static fromEvent(event) {
120
+ const code = event.code;
121
+ if (code.startsWith("Shift")
122
+ || code.startsWith("Control")
123
+ || code.startsWith("Alt")
124
+ || code.startsWith("Meta")
125
+ || code === Key.Escape
126
+ || code === Key.Delete
127
+ || code === Key.Backspace
128
+ || code === Key.Enter) {
129
+ return Option.None;
130
+ }
131
+ return Option.wrap(new Shortcut(code, Keyboard.isControlKey(event), event.shiftKey, event.altKey));
132
+ }
133
+ static #keyNames = {
134
+ [Key.Escape]: ["⎋", "Esc"],
135
+ [Key.Enter]: ["↩", "Enter"],
136
+ [Key.Backspace]: ["⌫", "Backspace"],
137
+ [Key.Delete]: ["⌦", "Del"],
138
+ [Key.DeleteAction]: ["⌫", "Del"],
139
+ [Key.Home]: ["↖", "Home"],
140
+ [Key.End]: ["↘", "End"],
141
+ [Key.PageUp]: ["⇞", "PgUp"],
142
+ [Key.PageDown]: ["⇟", "PgDn"],
143
+ [Key.ArrowUp]: "↑",
144
+ [Key.ArrowDown]: "↓",
145
+ [Key.ArrowLeft]: "←",
146
+ [Key.ArrowRight]: "→",
147
+ [Key.Comma]: ",",
148
+ [Key.Period]: ".",
149
+ [Key.Semicolon]: ";",
150
+ [Key.Quote]: "'",
151
+ [Key.Backquote]: "`",
152
+ [Key.Slash]: "/",
153
+ [Key.Backslash]: "\\",
154
+ [Key.BracketLeft]: "[",
155
+ [Key.BracketRight]: "]",
156
+ [Key.Minus]: "-",
157
+ [Key.Equal]: "="
158
+ };
159
+ static #formatKey(code) {
160
+ if (code.startsWith("Key")) {
161
+ return code.slice(3);
162
+ }
163
+ if (code.startsWith("Digit")) {
164
+ return `#${code.slice(5)}`;
165
+ }
166
+ const mapped = this.#keyNames[code];
167
+ if (isAbsent(mapped)) {
168
+ return code;
169
+ }
170
+ if (typeof mapped === "string") {
171
+ return mapped;
172
+ }
173
+ return Browser.isMacOS() ? mapped[0] : mapped[1];
174
+ }
175
+ #notifier = new Notifier();
176
+ #code;
177
+ #ctrl;
178
+ #shift;
179
+ #alt;
180
+ constructor(code, ctrl = false, shift = false, alt = false) {
181
+ this.#code = code;
182
+ this.#ctrl = ctrl;
183
+ this.#shift = shift;
184
+ this.#alt = alt;
185
+ }
186
+ get code() { return this.#code; }
187
+ get ctrl() { return this.#ctrl; }
188
+ get shift() { return this.#shift; }
189
+ get alt() { return this.#alt; }
190
+ equals(other) {
191
+ return this.#code === other.#code
192
+ && this.#ctrl === other.#ctrl
193
+ && this.#shift === other.#shift
194
+ && this.#alt === other.#alt;
195
+ }
196
+ matches(event) {
197
+ const codeMatches = event.code === this.#code
198
+ || (this.#code === Key.DeleteAction && Keyboard.isDelete(event));
199
+ return codeMatches
200
+ && this.#ctrl === Keyboard.isControlKey(event)
201
+ && this.#shift === event.shiftKey
202
+ && this.#alt === event.altKey;
203
+ }
204
+ format() {
205
+ const parts = [];
206
+ if (this.#shift) {
207
+ parts.push(Browser.isMacOS() ? "⇧" : "Shift");
208
+ }
209
+ if (this.#alt) {
210
+ parts.push(Browser.isMacOS() ? "⌥" : "Alt");
211
+ }
212
+ if (this.#ctrl) {
213
+ parts.push(Browser.isMacOS() ? "⌘" : "Ctrl");
214
+ }
215
+ parts.push(Shortcut.#formatKey(this.#code));
216
+ if (!Browser.isMacOS()) {
217
+ const result = [];
218
+ for (let i = 0; i < parts.length; i++) {
219
+ if (i > 0) {
220
+ result.push("+");
221
+ }
222
+ result.push(parts[i]);
223
+ }
224
+ return result;
225
+ }
226
+ return parts;
227
+ }
228
+ overrideWith(shortcut) {
229
+ if (this.#code === shortcut.#code
230
+ && this.#ctrl === shortcut.#ctrl
231
+ && this.#shift === shortcut.#shift
232
+ && this.#alt === shortcut.#alt) {
233
+ return;
234
+ }
235
+ this.#code = shortcut.#code;
236
+ this.#ctrl = shortcut.#ctrl;
237
+ this.#shift = shortcut.#shift;
238
+ this.#alt = shortcut.#alt;
239
+ this.#notifier.notify();
240
+ }
241
+ subscribe(observer) { return this.#notifier.subscribe(observer); }
242
+ toJSON() { return { code: this.#code, ctrl: this.#ctrl, shift: this.#shift, alt: this.#alt }; }
243
+ copy() { return new Shortcut(this.#code, this.#ctrl, this.#shift, this.#alt); }
244
+ toString() { return `{ShortcutKeys ${this.format().join("")}}`; }
245
+ }
246
+ export var ShortcutOptions;
247
+ (function (ShortcutOptions) {
248
+ ShortcutOptions.Default = {
249
+ preventDefault: true,
250
+ allowRepeat: false,
251
+ activeInTextField: false,
252
+ priority: 0
253
+ };
254
+ })(ShortcutOptions || (ShortcutOptions = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendaw/lib-dom",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "sideEffects": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -23,13 +23,13 @@
23
23
  "test": "vitest run"
24
24
  },
25
25
  "dependencies": {
26
- "@opendaw/lib-runtime": "^0.0.61",
27
- "@opendaw/lib-std": "^0.0.61",
26
+ "@opendaw/lib-runtime": "^0.0.62",
27
+ "@opendaw/lib-std": "^0.0.62",
28
28
  "@types/wicg-file-system-access": "^2023.10.6"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@opendaw/eslint-config": "^0.0.27",
32
- "@opendaw/typescript-config": "^0.0.27"
32
+ "@opendaw/typescript-config": "^0.0.28"
33
33
  },
34
- "gitHead": "b33275f0f9dbfc525fe517560b484514bdae3dad"
34
+ "gitHead": "100e759378d7150e6eb7165232d8c4a1fbb77bbc"
35
35
  }