@asyra/system-context 0.2.0

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 (150) hide show
  1. package/.turbo/turbo-test$colon$ci.log +77 -0
  2. package/.turbo/turbo-test$colon$local.log +23 -0
  3. package/.turbo/turbo-test.log +359 -0
  4. package/README.md +1 -0
  5. package/coverage/base.css +224 -0
  6. package/coverage/block-navigation.js +87 -0
  7. package/coverage/clover.xml +345 -0
  8. package/coverage/coverage-final.json +5831 -0
  9. package/coverage/favicon.png +0 -0
  10. package/coverage/index.html +176 -0
  11. package/coverage/prettify.css +1 -0
  12. package/coverage/prettify.js +2 -0
  13. package/coverage/sort-arrow-sprite.png +0 -0
  14. package/coverage/sorter.js +196 -0
  15. package/coverage/src/apis/index.html +206 -0
  16. package/coverage/src/apis/index.ts.html +133 -0
  17. package/coverage/src/apis/key-state.ts.html +124 -0
  18. package/coverage/src/apis/mouse-state.ts.html +124 -0
  19. package/coverage/src/apis/primary-tool-state.ts.html +124 -0
  20. package/coverage/src/apis/root.ts.html +139 -0
  21. package/coverage/src/apis/system-state.ts.html +112 -0
  22. package/coverage/src/apis/target-state.ts.html +121 -0
  23. package/coverage/src/index.html +131 -0
  24. package/coverage/src/index.ts.html +97 -0
  25. package/coverage/src/states/index.html +191 -0
  26. package/coverage/src/states/index.ts.html +139 -0
  27. package/coverage/src/states/key-state.ts.html +148 -0
  28. package/coverage/src/states/mouse-state.ts.html +184 -0
  29. package/coverage/src/states/primary-tool-state.ts.html +130 -0
  30. package/coverage/src/states/system-state.ts.html +130 -0
  31. package/coverage/src/states/target-state.ts.html +154 -0
  32. package/coverage/src/subscribe/index.html +191 -0
  33. package/coverage/src/subscribe/index.ts.html +187 -0
  34. package/coverage/src/subscribe/key-state.ts.html +109 -0
  35. package/coverage/src/subscribe/mouse-state.ts.html +109 -0
  36. package/coverage/src/subscribe/primary-tool-state.ts.html +136 -0
  37. package/coverage/src/subscribe/system-state.ts.html +94 -0
  38. package/coverage/src/subscribe/target-state.ts.html +109 -0
  39. package/coverage/src/system-context.ts.html +247 -0
  40. package/coverage/src/types/deps.ts.html +145 -0
  41. package/coverage/src/types/index.html +221 -0
  42. package/coverage/src/types/index.ts.html +157 -0
  43. package/coverage/src/types/key-state.ts.html +118 -0
  44. package/coverage/src/types/mouse-state.ts.html +118 -0
  45. package/coverage/src/types/primary-tool-state.ts.html +121 -0
  46. package/coverage/src/types/root.ts.html +106 -0
  47. package/coverage/src/types/system-state.ts.html +106 -0
  48. package/coverage/src/types/target-state.ts.html +118 -0
  49. package/dist/__tests__/system-context.test.d.ts +1 -0
  50. package/dist/__tests__/system-context.test.js +63 -0
  51. package/dist/apis/index.d.ts +13 -0
  52. package/dist/apis/index.js +14 -0
  53. package/dist/apis/key-state.d.ts +2 -0
  54. package/dist/apis/key-state.js +8 -0
  55. package/dist/apis/mouse-state copy.d.ts +2 -0
  56. package/dist/apis/mouse-state copy.js +8 -0
  57. package/dist/apis/mouse-state.d.ts +2 -0
  58. package/dist/apis/mouse-state.js +8 -0
  59. package/dist/apis/primary-tool-state.d.ts +2 -0
  60. package/dist/apis/primary-tool-state.js +8 -0
  61. package/dist/apis/root.d.ts +2 -0
  62. package/dist/apis/root.js +15 -0
  63. package/dist/apis/system-state.d.ts +2 -0
  64. package/dist/apis/system-state.js +5 -0
  65. package/dist/apis/target-state.d.ts +2 -0
  66. package/dist/apis/target-state.js +8 -0
  67. package/dist/index.d.ts +3 -0
  68. package/dist/index.js +3 -0
  69. package/dist/states/index.d.ts +6 -0
  70. package/dist/states/index.js +6 -0
  71. package/dist/states/key-state.d.ts +9 -0
  72. package/dist/states/key-state.js +16 -0
  73. package/dist/states/mouse-state copy.d.ts +9 -0
  74. package/dist/states/mouse-state copy.js +28 -0
  75. package/dist/states/mouse-state.d.ts +9 -0
  76. package/dist/states/mouse-state.js +28 -0
  77. package/dist/states/primary-tool-state.d.ts +8 -0
  78. package/dist/states/primary-tool-state.js +11 -0
  79. package/dist/states/system-state.d.ts +8 -0
  80. package/dist/states/system-state.js +11 -0
  81. package/dist/states/target-state.d.ts +9 -0
  82. package/dist/states/target-state.js +17 -0
  83. package/dist/subscribe/index.d.ts +2 -0
  84. package/dist/subscribe/index.js +24 -0
  85. package/dist/subscribe/key-state.d.ts +2 -0
  86. package/dist/subscribe/key-state.js +6 -0
  87. package/dist/subscribe/mouse-state copy.d.ts +2 -0
  88. package/dist/subscribe/mouse-state copy.js +6 -0
  89. package/dist/subscribe/mouse-state.d.ts +2 -0
  90. package/dist/subscribe/mouse-state.js +6 -0
  91. package/dist/subscribe/primary-tool-state.d.ts +2 -0
  92. package/dist/subscribe/primary-tool-state.js +10 -0
  93. package/dist/subscribe/root.d.ts +2 -0
  94. package/dist/subscribe/root.js +7 -0
  95. package/dist/subscribe/system-state.d.ts +1 -0
  96. package/dist/subscribe/system-state.js +3 -0
  97. package/dist/subscribe/target-state.d.ts +2 -0
  98. package/dist/subscribe/target-state.js +6 -0
  99. package/dist/system-context.d.ts +17 -0
  100. package/dist/system-context.js +30 -0
  101. package/dist/types/deps.d.ts +12 -0
  102. package/dist/types/deps.js +1 -0
  103. package/dist/types/index.d.ts +9 -0
  104. package/dist/types/index.js +1 -0
  105. package/dist/types/key-state.d.ts +8 -0
  106. package/dist/types/key-state.js +1 -0
  107. package/dist/types/mouse-state copy.d.ts +8 -0
  108. package/dist/types/mouse-state copy.js +1 -0
  109. package/dist/types/mouse-state.d.ts +8 -0
  110. package/dist/types/mouse-state.js +1 -0
  111. package/dist/types/primary-tool-state.d.ts +8 -0
  112. package/dist/types/primary-tool-state.js +1 -0
  113. package/dist/types/root.d.ts +5 -0
  114. package/dist/types/root.js +1 -0
  115. package/dist/types/system-state.d.ts +5 -0
  116. package/dist/types/system-state.js +1 -0
  117. package/dist/types/target-state.d.ts +8 -0
  118. package/dist/types/target-state.js +1 -0
  119. package/package.json +28 -0
  120. package/src/__tests__/system-context.test.ts +79 -0
  121. package/src/apis/index.ts +16 -0
  122. package/src/apis/key-state.ts +13 -0
  123. package/src/apis/mouse-state.ts +13 -0
  124. package/src/apis/primary-tool-state.ts +13 -0
  125. package/src/apis/root.ts +18 -0
  126. package/src/apis/system-state.ts +9 -0
  127. package/src/apis/target-state.ts +12 -0
  128. package/src/index.ts +4 -0
  129. package/src/states/index.ts +18 -0
  130. package/src/states/key-state.ts +21 -0
  131. package/src/states/mouse-state.ts +33 -0
  132. package/src/states/primary-tool-state.ts +15 -0
  133. package/src/states/system-state.ts +15 -0
  134. package/src/states/target-state.ts +23 -0
  135. package/src/subscribe/index.ts +34 -0
  136. package/src/subscribe/key-state.ts +8 -0
  137. package/src/subscribe/mouse-state.ts +8 -0
  138. package/src/subscribe/primary-tool-state.ts +17 -0
  139. package/src/subscribe/system-state.ts +3 -0
  140. package/src/subscribe/target-state.ts +8 -0
  141. package/src/system-context.ts +54 -0
  142. package/src/types/deps.ts +20 -0
  143. package/src/types/index.ts +24 -0
  144. package/src/types/key-state.ts +11 -0
  145. package/src/types/mouse-state.ts +11 -0
  146. package/src/types/primary-tool-state.ts +12 -0
  147. package/src/types/root.ts +7 -0
  148. package/src/types/system-state.ts +7 -0
  149. package/src/types/target-state.ts +11 -0
  150. package/tsconfig.json +17 -0
@@ -0,0 +1,3 @@
1
+ import systemContext, { SystemContext } from './system-context';
2
+ export { SystemContext };
3
+ export default systemContext;
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import systemContext, { SystemContext } from './system-context';
2
+ export { SystemContext };
3
+ export default systemContext;
@@ -0,0 +1,6 @@
1
+ import systemState, { SystemState } from './system-state';
2
+ import primaryToolState, { PrimaryToolState } from './primary-tool-state';
3
+ import mouseState, { MouseState } from './mouse-state';
4
+ import keyState, { KeyState } from './key-state';
5
+ import targetState, { TargetState } from './target-state';
6
+ export { systemState, SystemState, primaryToolState, PrimaryToolState, mouseState, MouseState, keyState, KeyState, targetState, TargetState };
@@ -0,0 +1,6 @@
1
+ import systemState, { SystemState } from './system-state';
2
+ import primaryToolState, { PrimaryToolState } from './primary-tool-state';
3
+ import mouseState, { MouseState } from './mouse-state';
4
+ import keyState, { KeyState } from './key-state';
5
+ import targetState, { TargetState } from './target-state';
6
+ export { systemState, SystemState, primaryToolState, PrimaryToolState, mouseState, MouseState, keyState, KeyState, targetState, TargetState };
@@ -0,0 +1,9 @@
1
+ import { KeySnapshot } from '@asyra/utils';
2
+ export declare class KeyState {
3
+ private _state;
4
+ constructor();
5
+ set(keySnapshot: KeySnapshot): void;
6
+ get current(): import("@asyra/utils").ModifierKeys;
7
+ }
8
+ declare const _default: KeyState;
9
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { DefaultKeySnapshot } from '@asyra/utils';
2
+ export class KeyState {
3
+ _state;
4
+ constructor() {
5
+ this._state = {
6
+ ...DefaultKeySnapshot
7
+ };
8
+ }
9
+ set(keySnapshot) {
10
+ this._state = { ...keySnapshot };
11
+ }
12
+ get current() {
13
+ return this._state;
14
+ }
15
+ }
16
+ export default new KeyState();
@@ -0,0 +1,9 @@
1
+ import { MouseSnapshot } from '@asyra/utils';
2
+ export declare class MouseState {
3
+ private _state;
4
+ constructor();
5
+ set(mouseSnapshot: MouseSnapshot): void;
6
+ get current(): MouseSnapshot;
7
+ }
8
+ declare const _default: MouseState;
9
+ export default _default;
@@ -0,0 +1,28 @@
1
+ import { DefaultPosition, MouseButton } from '@asyra/utils';
2
+ export class MouseState {
3
+ _state;
4
+ constructor() {
5
+ this._state = {
6
+ dragStart: DefaultPosition,
7
+ position: DefaultPosition,
8
+ delta: DefaultPosition,
9
+ button: MouseButton.NONE,
10
+ down: false,
11
+ dragging: false
12
+ };
13
+ }
14
+ set(mouseSnapshot) {
15
+ if (mouseSnapshot.dragStart) {
16
+ this._state.dragStart = { ...mouseSnapshot.dragStart };
17
+ }
18
+ this._state.position = { ...mouseSnapshot.position };
19
+ this._state.delta = { ...mouseSnapshot.delta };
20
+ this._state.button = mouseSnapshot.button;
21
+ this._state.down = mouseSnapshot.down;
22
+ this._state.dragging = mouseSnapshot.dragging;
23
+ }
24
+ get current() {
25
+ return this._state;
26
+ }
27
+ }
28
+ export default new MouseState();
@@ -0,0 +1,9 @@
1
+ import { MouseSnapshot } from '@asyra/utils';
2
+ export declare class MouseState {
3
+ private _state;
4
+ constructor();
5
+ set(mouseSnapshot: MouseSnapshot): void;
6
+ get current(): MouseSnapshot;
7
+ }
8
+ declare const _default: MouseState;
9
+ export default _default;
@@ -0,0 +1,28 @@
1
+ import { DefaultPosition, MouseButton } from '@asyra/utils';
2
+ export class MouseState {
3
+ _state;
4
+ constructor() {
5
+ this._state = {
6
+ dragStart: DefaultPosition,
7
+ position: DefaultPosition,
8
+ delta: DefaultPosition,
9
+ button: MouseButton.NONE,
10
+ down: false,
11
+ dragging: false
12
+ };
13
+ }
14
+ set(mouseSnapshot) {
15
+ if (mouseSnapshot.dragStart) {
16
+ this._state.dragStart = { ...mouseSnapshot.dragStart };
17
+ }
18
+ this._state.position = { ...mouseSnapshot.position };
19
+ this._state.delta = { ...mouseSnapshot.delta };
20
+ this._state.button = mouseSnapshot.button;
21
+ this._state.down = mouseSnapshot.down;
22
+ this._state.dragging = mouseSnapshot.dragging;
23
+ }
24
+ get current() {
25
+ return this._state;
26
+ }
27
+ }
28
+ export default new MouseState();
@@ -0,0 +1,8 @@
1
+ import { PrimaryToolType } from '@asyra/utils';
2
+ export declare class PrimaryToolState {
3
+ private _state;
4
+ set(tool: PrimaryToolType): void;
5
+ get current(): PrimaryToolType;
6
+ }
7
+ declare const _default: PrimaryToolState;
8
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { DefaultPrimaryTool } from '@asyra/utils';
2
+ export class PrimaryToolState {
3
+ _state = DefaultPrimaryTool;
4
+ set(tool) {
5
+ this._state = tool;
6
+ }
7
+ get current() {
8
+ return this._state;
9
+ }
10
+ }
11
+ export default new PrimaryToolState();
@@ -0,0 +1,8 @@
1
+ import { SystemMode } from '@asyra/utils';
2
+ export declare class SystemState {
3
+ private _mode;
4
+ set(mode: SystemMode): void;
5
+ get mode(): SystemMode;
6
+ }
7
+ declare const _default: SystemState;
8
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { DefaultSystemSnapshot } from '@asyra/utils';
2
+ export class SystemState {
3
+ _mode = DefaultSystemSnapshot.mode;
4
+ set(mode) {
5
+ this._mode = mode;
6
+ }
7
+ get mode() {
8
+ return this._mode;
9
+ }
10
+ }
11
+ export default new SystemState();
@@ -0,0 +1,9 @@
1
+ import { TargetSnapshot } from '@asyra/utils';
2
+ export declare class TargetState {
3
+ private _state;
4
+ constructor();
5
+ updateHoveredElementId(elementId: string | null): void;
6
+ get current(): TargetSnapshot;
7
+ }
8
+ declare const _default: TargetState;
9
+ export default _default;
@@ -0,0 +1,17 @@
1
+ export class TargetState {
2
+ _state;
3
+ constructor() {
4
+ this._state = {
5
+ hoveredElementId: null,
6
+ selectedElementIds: [],
7
+ activeElementId: null
8
+ };
9
+ }
10
+ updateHoveredElementId(elementId) {
11
+ this._state.hoveredElementId = elementId;
12
+ }
13
+ get current() {
14
+ return this._state;
15
+ }
16
+ }
17
+ export default new TargetState();
@@ -0,0 +1,2 @@
1
+ import { SystemContextAPIs } from '../types';
2
+ export declare const initSystemContextSubscribe: (apis: SystemContextAPIs) => void;
@@ -0,0 +1,24 @@
1
+ import { initPrimaryToolStateSubscribe } from './primary-tool-state';
2
+ import { initMouseStateSubscribe } from './mouse-state';
3
+ import { initSystemStateSubscribe } from './system-state';
4
+ import { initKeyStateSubscribe } from './key-state';
5
+ import { initTargetStateSubscribe } from './target-state';
6
+ export const initSystemContextSubscribe = (apis) => {
7
+ initSystemStateSubscribe();
8
+ initPrimaryToolStateSubscribe({
9
+ getCurrentPrimaryTool: () => apis.getCurrentPrimaryTool(),
10
+ switchPrimaryTool: (tool) => apis.switchPrimaryTool(tool)
11
+ });
12
+ initMouseStateSubscribe({
13
+ getMouseState: () => apis.getMouseState(),
14
+ updateMouseState: (mouseSnapshot) => apis.updateMouseState(mouseSnapshot)
15
+ });
16
+ initKeyStateSubscribe({
17
+ getKeyState: () => apis.getKeyState(),
18
+ updateKeyState: (keySnapshot) => apis.updateKeyState(keySnapshot)
19
+ });
20
+ initTargetStateSubscribe({
21
+ getTargetState: () => apis.getTargetState(),
22
+ updateHoveredElementId: (elementId) => apis.updateHoveredElementId(elementId)
23
+ });
24
+ };
@@ -0,0 +1,2 @@
1
+ import { KeyStateAPIs } from '../types';
2
+ export declare const initKeyStateSubscribe: (apis: KeyStateAPIs) => void;
@@ -0,0 +1,6 @@
1
+ import { subscribeToUpdateKeyState } from '@asyra/reactive-events';
2
+ export const initKeyStateSubscribe = (apis) => {
3
+ subscribeToUpdateKeyState(({ payload }) => {
4
+ apis.updateKeyState(payload);
5
+ });
6
+ };
@@ -0,0 +1,2 @@
1
+ import { MouseStateAPIs } from '../types';
2
+ export declare const initMouseStateSubscribe: (apis: MouseStateAPIs) => void;
@@ -0,0 +1,6 @@
1
+ import { subscribeToUpdateMouseState } from '@asyra/reactive-events';
2
+ export const initMouseStateSubscribe = (apis) => {
3
+ subscribeToUpdateMouseState(({ payload }) => {
4
+ apis.updateMouseState(payload);
5
+ });
6
+ };
@@ -0,0 +1,2 @@
1
+ import { MouseStateAPIs } from '../types';
2
+ export declare const initMouseStateSubscribe: (apis: MouseStateAPIs) => void;
@@ -0,0 +1,6 @@
1
+ import { subscribeToUpdateMouseState } from '@asyra/reactive-events';
2
+ export const initMouseStateSubscribe = (apis) => {
3
+ subscribeToUpdateMouseState(({ payload }) => {
4
+ apis.updateMouseState(payload);
5
+ });
6
+ };
@@ -0,0 +1,2 @@
1
+ import { PrimaryToolStateAPIs } from '../types';
2
+ export declare const initPrimaryToolStateSubscribe: (apis: PrimaryToolStateAPIs) => void;
@@ -0,0 +1,10 @@
1
+ import { finishRequestCurrentPrimaryTool, subscribeToRequestCurrentPrimaryTool, subscribeToSwitchPrimaryTool } from '@asyra/reactive-events';
2
+ export const initPrimaryToolStateSubscribe = (apis) => {
3
+ subscribeToSwitchPrimaryTool(({ payload }) => {
4
+ apis.switchPrimaryTool(payload.tool);
5
+ });
6
+ subscribeToRequestCurrentPrimaryTool(({ payload }) => {
7
+ const primaryTool = apis.getCurrentPrimaryTool();
8
+ finishRequestCurrentPrimaryTool(payload.requestId, primaryTool);
9
+ });
10
+ };
@@ -0,0 +1,2 @@
1
+ import { RootAPIs } from '../types';
2
+ export declare const initRootSubscribe: (apis: RootAPIs) => void;
@@ -0,0 +1,7 @@
1
+ import { finishRequestSystemContextSnapshot, subscribeToRequestSystemContextSnapshot } from '@asyra/reactive-events';
2
+ export const initRootSubscribe = (apis) => {
3
+ subscribeToRequestSystemContextSnapshot(({ payload }) => {
4
+ const systemContextSnapshot = apis.getSystemContextSnapshot();
5
+ finishRequestSystemContextSnapshot(payload.requestId, systemContextSnapshot);
6
+ });
7
+ };
@@ -0,0 +1 @@
1
+ export declare const initSystemStateSubscribe: () => void;
@@ -0,0 +1,3 @@
1
+ export const initSystemStateSubscribe = () => {
2
+ // TODO: add SystemMode and FeatureFlags
3
+ };
@@ -0,0 +1,2 @@
1
+ import { TargetStateAPIs } from '../types';
2
+ export declare const initTargetStateSubscribe: (apis: TargetStateAPIs) => void;
@@ -0,0 +1,6 @@
1
+ import { subscribeToUpdateHoveredElementId } from '@asyra/reactive-events';
2
+ export const initTargetStateSubscribe = (apis) => {
3
+ subscribeToUpdateHoveredElementId(({ payload }) => {
4
+ apis.updateHoveredElementId(payload.elementId);
5
+ });
6
+ };
@@ -0,0 +1,17 @@
1
+ import { HandlerDeps, PrimaryToolStateAPIs, MouseStateAPIs, SystemStateAPIs, SystemContextAPIs, RootAPIs, KeyStateAPIs, TargetStateAPIs } from './types';
2
+ export declare class SystemContext implements SystemContextAPIs {
3
+ private deps;
4
+ getSystemMode: SystemStateAPIs['getSystemMode'];
5
+ getCurrentPrimaryTool: PrimaryToolStateAPIs['getCurrentPrimaryTool'];
6
+ switchPrimaryTool: PrimaryToolStateAPIs['switchPrimaryTool'];
7
+ getMouseState: MouseStateAPIs['getMouseState'];
8
+ updateMouseState: MouseStateAPIs['updateMouseState'];
9
+ getKeyState: KeyStateAPIs['getKeyState'];
10
+ updateKeyState: KeyStateAPIs['updateKeyState'];
11
+ getTargetState: TargetStateAPIs['getTargetState'];
12
+ updateHoveredElementId: TargetStateAPIs['updateHoveredElementId'];
13
+ getSystemContextSnapshot: RootAPIs['getSystemContextSnapshot'];
14
+ constructor(deps: HandlerDeps);
15
+ }
16
+ declare const systemContext: SystemContext;
17
+ export default systemContext;
@@ -0,0 +1,30 @@
1
+ import { createAllAPIs } from './apis';
2
+ import { systemState, primaryToolState, mouseState, keyState, targetState } from './states';
3
+ import { initSystemContextSubscribe } from './subscribe';
4
+ export class SystemContext {
5
+ deps;
6
+ getSystemMode;
7
+ getCurrentPrimaryTool;
8
+ switchPrimaryTool;
9
+ getMouseState;
10
+ updateMouseState;
11
+ getKeyState;
12
+ updateKeyState;
13
+ getTargetState;
14
+ updateHoveredElementId;
15
+ getSystemContextSnapshot;
16
+ constructor(deps) {
17
+ this.deps = deps;
18
+ const apis = createAllAPIs(deps);
19
+ initSystemContextSubscribe(apis);
20
+ Object.assign(this, apis);
21
+ }
22
+ }
23
+ const systemContext = new SystemContext({
24
+ systemState,
25
+ primaryToolState,
26
+ mouseState,
27
+ keyState,
28
+ targetState
29
+ });
30
+ export default systemContext;
@@ -0,0 +1,12 @@
1
+ import type { SystemState, PrimaryToolState, MouseState, KeyState, TargetState } from '../states';
2
+ export interface HandlerDeps {
3
+ systemState: SystemState;
4
+ primaryToolState: PrimaryToolState;
5
+ mouseState: MouseState;
6
+ keyState: KeyState;
7
+ targetState: TargetState;
8
+ }
9
+ export interface SystemDeps {
10
+ primaryToolState: PrimaryToolState;
11
+ mouseState: MouseState;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { RootAPIs } from './root';
2
+ import { SystemStateAPIs } from './system-state';
3
+ import { PrimaryToolStateAPIs } from './primary-tool-state';
4
+ import { MouseStateAPIs } from './mouse-state';
5
+ import { KeyStateAPIs } from './key-state';
6
+ import { TargetStateAPIs } from './target-state';
7
+ export { RootAPIs, SystemStateAPIs, PrimaryToolStateAPIs, MouseStateAPIs, KeyStateAPIs, TargetStateAPIs };
8
+ export type SystemContextAPIs = RootAPIs & SystemStateAPIs & PrimaryToolStateAPIs & MouseStateAPIs & KeyStateAPIs & TargetStateAPIs;
9
+ export * from './deps';
@@ -0,0 +1 @@
1
+ export * from './deps';
@@ -0,0 +1,8 @@
1
+ import { KeySnapshot } from '@asyra/utils';
2
+ export interface KeyStateRawAPIs {
3
+ getKeyState: () => KeySnapshot;
4
+ }
5
+ export interface KeyStateActionAPIs {
6
+ updateKeyState: (keySnapshot: KeySnapshot) => void;
7
+ }
8
+ export type KeyStateAPIs = KeyStateActionAPIs & KeyStateRawAPIs;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { MouseSnapshot } from '@asyra/utils';
2
+ export interface MouseStateRawAPIs {
3
+ getMouseState: () => MouseSnapshot;
4
+ }
5
+ export interface MouseStateActionAPIs {
6
+ updateMouseState: (mouseSnapshot: MouseSnapshot) => void;
7
+ }
8
+ export type MouseStateAPIs = MouseStateActionAPIs & MouseStateRawAPIs;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { MouseSnapshot } from '@asyra/utils';
2
+ export interface MouseStateRawAPIs {
3
+ getMouseState: () => MouseSnapshot;
4
+ }
5
+ export interface MouseStateActionAPIs {
6
+ updateMouseState: (mouseSnapshot: MouseSnapshot) => void;
7
+ }
8
+ export type MouseStateAPIs = MouseStateActionAPIs & MouseStateRawAPIs;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { PrimaryToolType } from '@asyra/utils';
2
+ export interface PrimaryToolStateRawAPIs {
3
+ getCurrentPrimaryTool: () => PrimaryToolType;
4
+ }
5
+ export interface PrimaryToolStateActionAPIs {
6
+ switchPrimaryTool: (tool: PrimaryToolType) => void;
7
+ }
8
+ export type PrimaryToolStateAPIs = PrimaryToolStateRawAPIs & PrimaryToolStateActionAPIs;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SystemContextSnapshot } from '@asyra/utils';
2
+ export interface RootRawAPIs {
3
+ getSystemContextSnapshot: () => SystemContextSnapshot;
4
+ }
5
+ export type RootAPIs = RootRawAPIs;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SystemMode } from '@asyra/utils';
2
+ export interface SystemStateRawAPIs {
3
+ getSystemMode: () => SystemMode;
4
+ }
5
+ export type SystemStateAPIs = SystemStateRawAPIs;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { TargetSnapshot } from '@asyra/utils';
2
+ export interface TargetStateRawAPIs {
3
+ getTargetState: () => TargetSnapshot;
4
+ }
5
+ export interface TargetStateActionAPIs {
6
+ updateHoveredElementId: (elementId: string | null) => void;
7
+ }
8
+ export type TargetStateAPIs = TargetStateActionAPIs & TargetStateRawAPIs;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@asyra/system-context",
3
+ "version": "0.2.0",
4
+ "description": "Provides reactive system parameters, tool states, and feature access control for the core application.",
5
+ "author": "Asa Tsai",
6
+ "license": "MIT",
7
+ "packageManager": "yarn@4.3.1",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "scripts": {
11
+ "dev": "tsc --watch --preserveWatchOutput",
12
+ "build:system-context": "tsc",
13
+ "clean": "rm -rf dist",
14
+ "has:test": "find . -type f \\( -name \"*.test.ts\" -o -name \"*.test.tsx\" \\) | grep -q .",
15
+ "test": "yarn has:test && vitest || echo 'No test files found. Skipping test.'",
16
+ "test:local": "yarn has:test && vitest run || echo 'No test files found. Skipping test:local.'",
17
+ "test:ci": "yarn has:test && vitest run --coverage --reporter=default --reporter=junit || echo 'No test files found. Skipping test:ci.'"
18
+ },
19
+ "devDependencies": {
20
+ "@vitest/coverage-v8": "^2.1.8",
21
+ "typescript": "^5.7.2",
22
+ "vitest": "^2.1.8"
23
+ },
24
+ "dependencies": {
25
+ "@asyra/reactive-events": "workspace:*",
26
+ "@asyra/utils": "workspace:*"
27
+ }
28
+ }
@@ -0,0 +1,79 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest'
2
+ import { SystemContext } from '../system-context'
3
+ import { KeyState } from '../states/key-state'
4
+ import { MouseState } from '../states/mouse-state'
5
+ import { PrimaryToolState } from '../states/primary-tool-state'
6
+ import { SystemState } from '../states/system-state'
7
+ import { TargetState } from '../states/target-state'
8
+ import {
9
+ DefaultKeySnapshot,
10
+ DefaultPosition,
11
+ MouseButton,
12
+ PrimaryToolType
13
+ } from '@asyra/utils'
14
+
15
+ describe('SystemContext', () => {
16
+ let systemContext: SystemContext
17
+ let keyState: KeyState
18
+ let mouseState: MouseState
19
+ let primaryToolState: PrimaryToolState
20
+ let systemState: SystemState
21
+ let targetState: TargetState
22
+
23
+ beforeEach(() => {
24
+ keyState = new KeyState()
25
+ mouseState = new MouseState()
26
+ primaryToolState = new PrimaryToolState()
27
+ systemState = new SystemState()
28
+ targetState = new TargetState()
29
+
30
+ systemContext = new SystemContext({
31
+ keyState,
32
+ mouseState,
33
+ primaryToolState,
34
+ systemState,
35
+ targetState
36
+ })
37
+ })
38
+
39
+ it('should initialize with the correct default state', () => {
40
+ expect(systemContext.getKeyState()).toEqual(DefaultKeySnapshot)
41
+ expect(systemContext.getMouseState()).toEqual({
42
+ dragStart: DefaultPosition,
43
+ position: DefaultPosition,
44
+ delta: DefaultPosition,
45
+ button: MouseButton.NONE,
46
+ down: false,
47
+ dragging: false
48
+ })
49
+ expect(systemContext.getCurrentPrimaryTool()).toEqual(
50
+ PrimaryToolType.SELECT
51
+ )
52
+ })
53
+
54
+ it('should update mouse state correctly', () => {
55
+ const newMouseSnapshot = {
56
+ position: { x: 100, y: 200 },
57
+ delta: { x: 1, y: 1 },
58
+ button: MouseButton.LEFT,
59
+ down: true,
60
+ dragging: true,
61
+ dragStart: { x: 99, y: 199 }
62
+ }
63
+ systemContext.updateMouseState(newMouseSnapshot)
64
+ expect(systemContext.getMouseState()).toEqual(newMouseSnapshot)
65
+ })
66
+
67
+ it('should update tool state correctly', () => {
68
+ systemContext.switchPrimaryTool(PrimaryToolType.RECTANGLE)
69
+ expect(systemContext.getCurrentPrimaryTool()).toEqual(
70
+ PrimaryToolType.RECTANGLE
71
+ )
72
+ })
73
+
74
+ it('should update key state correctly', () => {
75
+ const newKeySnapshot = { ...DefaultKeySnapshot, shift: true }
76
+ systemContext.updateKeyState(newKeySnapshot)
77
+ expect(systemContext.getKeyState()).toEqual(newKeySnapshot)
78
+ })
79
+ })
@@ -0,0 +1,16 @@
1
+ import { createRootAPIs } from './root'
2
+ import { createMouseStateAPIs } from './mouse-state'
3
+ import { createPrimaryToolStateAPIs } from './primary-tool-state'
4
+ import { createSystemAPIs } from './system-state'
5
+ import { createKeyStateAPIs } from './key-state'
6
+ import { createTargetStateAPIs } from './target-state'
7
+ import { HandlerDeps } from '../types'
8
+
9
+ export const createAllAPIs = (deps: HandlerDeps) => ({
10
+ ...createRootAPIs(deps),
11
+ ...createPrimaryToolStateAPIs(deps.primaryToolState),
12
+ ...createMouseStateAPIs(deps.mouseState),
13
+ ...createSystemAPIs(deps.systemState),
14
+ ...createKeyStateAPIs(deps.keyState),
15
+ ...createTargetStateAPIs(deps.targetState)
16
+ })
@@ -0,0 +1,13 @@
1
+ import { KeySnapshot } from '@asyra/utils'
2
+ import { HandlerDeps, KeyStateAPIs } from '../types'
3
+
4
+ export const createKeyStateAPIs = (
5
+ keyState: HandlerDeps['keyState']
6
+ ): KeyStateAPIs => ({
7
+ updateKeyState(keySnapshot: KeySnapshot) {
8
+ keyState.set(keySnapshot)
9
+ },
10
+ getKeyState() {
11
+ return keyState.current
12
+ }
13
+ })