@effindomv2/fui-as 0.1.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 (137) hide show
  1. package/LICENSE.md +7 -0
  2. package/browser/src/common-harness/host-imports.ts +430 -0
  3. package/browser/src/common-harness/interop.ts +39 -0
  4. package/browser/src/common-harness/managed-harness-bitmap-host.ts +92 -0
  5. package/browser/src/common-harness/managed-harness-fetch-host.ts +201 -0
  6. package/browser/src/common-harness/managed-harness-file-host.ts +1101 -0
  7. package/browser/src/common-harness/managed-harness-file-payloads.ts +143 -0
  8. package/browser/src/common-harness/managed-harness-file-types.ts +106 -0
  9. package/browser/src/common-harness/managed-harness-session.ts +15 -0
  10. package/browser/src/common-harness/managed-harness.ts +1323 -0
  11. package/browser/src/common-harness/managed-history.ts +168 -0
  12. package/browser/src/common-harness/persisted-restore-policy.ts +50 -0
  13. package/browser/src/common-harness/persisted-ui-state-controller.ts +309 -0
  14. package/browser/src/common-harness/text-session-bridge.ts +452 -0
  15. package/browser/src/common-harness/types.ts +205 -0
  16. package/browser/src/common-harness/ui-chrome.ts +191 -0
  17. package/browser/src/common-harness/ui-imports.ts +529 -0
  18. package/browser/src/common-harness/wasm-module-cache.ts +47 -0
  19. package/browser/src/common-harness.ts +27 -0
  20. package/browser/src/file-processing-worker.ts +89 -0
  21. package/browser/src/host-events.ts +97 -0
  22. package/browser/src/host-services.ts +203 -0
  23. package/browser/src/index.ts +62 -0
  24. package/browser/src/persisted-ui-state.ts +206 -0
  25. package/browser/src/routed-harness.ts +198 -0
  26. package/browser/src/worker-bootstrap.ts +483 -0
  27. package/browser/src/worker-manager.ts +230 -0
  28. package/browser/src/worker-types.ts +50 -0
  29. package/package.json +89 -0
  30. package/scripts/build-demo-as.sh +91 -0
  31. package/scripts/build.sh +325 -0
  32. package/scripts/generate-host-events.ts +175 -0
  33. package/scripts/generate-host-services.ts +157 -0
  34. package/src/Fui.ts +205 -0
  35. package/src/FuiExports.ts +55 -0
  36. package/src/FuiPrimitives.ts +15 -0
  37. package/src/FuiWorker.ts +3 -0
  38. package/src/FuiWorkerExports.ts +6 -0
  39. package/src/bindings/ui.ts +531 -0
  40. package/src/color.ts +86 -0
  41. package/src/controls/AntiSelectionArea.ts +23 -0
  42. package/src/controls/Button.ts +750 -0
  43. package/src/controls/Checkbox.ts +181 -0
  44. package/src/controls/ContextMenu.ts +885 -0
  45. package/src/controls/ControlTemplateSet.ts +37 -0
  46. package/src/controls/Dialog.ts +355 -0
  47. package/src/controls/Dropdown.ts +856 -0
  48. package/src/controls/Form.ts +110 -0
  49. package/src/controls/NavLink.ts +211 -0
  50. package/src/controls/Popup.ts +129 -0
  51. package/src/controls/ProgressBar.ts +180 -0
  52. package/src/controls/RadioButton.ts +135 -0
  53. package/src/controls/RadioGroup.ts +244 -0
  54. package/src/controls/SelectionArea.ts +75 -0
  55. package/src/controls/Slider.ts +471 -0
  56. package/src/controls/Switch.ts +132 -0
  57. package/src/controls/TextArea.ts +20 -0
  58. package/src/controls/TextInput.ts +7 -0
  59. package/src/controls/index.ts +18 -0
  60. package/src/controls/internal/ButtonPresenter.ts +95 -0
  61. package/src/controls/internal/CheckboxIndicatorPresenter.ts +93 -0
  62. package/src/controls/internal/DropdownChevronPresenter.ts +67 -0
  63. package/src/controls/internal/DropdownFieldPresenter.ts +110 -0
  64. package/src/controls/internal/DropdownOptionRowPresenter.ts +82 -0
  65. package/src/controls/internal/PopupPresenter.ts +198 -0
  66. package/src/controls/internal/PressableIndicatorPresenter.ts +32 -0
  67. package/src/controls/internal/PressableLabeledControl.ts +221 -0
  68. package/src/controls/internal/RadioIndicatorPresenter.ts +73 -0
  69. package/src/controls/internal/SliderPresenter.ts +157 -0
  70. package/src/controls/internal/SwitchIndicatorPresenter.ts +72 -0
  71. package/src/controls/internal/TextInputCore.ts +695 -0
  72. package/src/controls/internal/TextInputPresenter.ts +72 -0
  73. package/src/controls/templating.ts +54 -0
  74. package/src/core/Action.ts +94 -0
  75. package/src/core/Actions.ts +37 -0
  76. package/src/core/Animation.ts +412 -0
  77. package/src/core/Application.ts +328 -0
  78. package/src/core/Assets.ts +264 -0
  79. package/src/core/AttachedProperties.ts +32 -0
  80. package/src/core/Bitmap.ts +70 -0
  81. package/src/core/BoundCallback.ts +104 -0
  82. package/src/core/Callbacks.ts +17 -0
  83. package/src/core/ContextMenuManager.ts +466 -0
  84. package/src/core/DebugApi.ts +30 -0
  85. package/src/core/Disposable.ts +10 -0
  86. package/src/core/DragDropManager.ts +179 -0
  87. package/src/core/DragGesture.ts +184 -0
  88. package/src/core/DynamicAssetIds.ts +24 -0
  89. package/src/core/Errors.ts +48 -0
  90. package/src/core/EventRouter.ts +408 -0
  91. package/src/core/ExternalDropManager.ts +122 -0
  92. package/src/core/Fetch.ts +264 -0
  93. package/src/core/FetchFfi.ts +15 -0
  94. package/src/core/File.ts +1002 -0
  95. package/src/core/FocusAdornerManager.ts +263 -0
  96. package/src/core/FocusVisibility.ts +36 -0
  97. package/src/core/FrameScheduler.ts +28 -0
  98. package/src/core/KeyboardScroll.ts +161 -0
  99. package/src/core/KeyboardScrollTracker.ts +386 -0
  100. package/src/core/Logger.ts +80 -0
  101. package/src/core/Navigation.ts +13 -0
  102. package/src/core/Node.ts +1708 -0
  103. package/src/core/PersistedState.ts +102 -0
  104. package/src/core/PersistedUiState.ts +142 -0
  105. package/src/core/Platform.ts +219 -0
  106. package/src/core/Signal.ts +89 -0
  107. package/src/core/Theme.ts +365 -0
  108. package/src/core/Timers.ts +129 -0
  109. package/src/core/ToolTip.ts +122 -0
  110. package/src/core/ToolTipManager.ts +459 -0
  111. package/src/core/Transitions.ts +34 -0
  112. package/src/core/Typography.ts +204 -0
  113. package/src/core/Worker.ts +196 -0
  114. package/src/core/bind.ts +37 -0
  115. package/src/core/event_exports.ts +596 -0
  116. package/src/core/ffi.ts +728 -0
  117. package/src/host-services/runtime.ts +25 -0
  118. package/src/nodes/FlexBox.ts +789 -0
  119. package/src/nodes/GradientStop.ts +9 -0
  120. package/src/nodes/Grid.ts +183 -0
  121. package/src/nodes/Image.ts +189 -0
  122. package/src/nodes/Portal.ts +14 -0
  123. package/src/nodes/RichText.ts +312 -0
  124. package/src/nodes/ScrollBar.ts +570 -0
  125. package/src/nodes/ScrollBox.ts +415 -0
  126. package/src/nodes/ScrollState.ts +10 -0
  127. package/src/nodes/ScrollView.ts +511 -0
  128. package/src/nodes/Svg.ts +142 -0
  129. package/src/nodes/Text.ts +145 -0
  130. package/src/nodes/TextCore.ts +558 -0
  131. package/src/nodes/VirtualList.ts +431 -0
  132. package/src/nodes/helpers.ts +25 -0
  133. package/src/nodes/index.ts +14 -0
  134. package/src/tsconfig.json +7 -0
  135. package/src/worker/Worker.ts +169 -0
  136. package/src/worker/WorkerJob.ts +65 -0
  137. package/src/worker/ffi.ts +23 -0
@@ -0,0 +1,181 @@
1
+ import { Callback1, Handler1 } from "../core/BoundCallback";
2
+ import { SemanticCheckedState, SemanticRole } from "../core/ffi";
3
+ import { PersistedInt32Codec, PersistedValueState } from "../core/PersistedState";
4
+ import { bind1 } from "../core/bind";
5
+ import { getControlTemplates } from "./ControlTemplateSet";
6
+ import { activeTheme } from "../core/Theme";
7
+ import { PressableLabeledControl } from "./internal/PressableLabeledControl";
8
+ import {
9
+ CheckboxIndicatorPresenter,
10
+ CheckboxIndicatorTemplate,
11
+ CheckboxIndicatorVisualState,
12
+ defaultCheckboxIndicatorTemplate,
13
+ } from "./internal/CheckboxIndicatorPresenter";
14
+ const CHECKBOX_PERSISTED_CODEC = new PersistedInt32Codec();
15
+
16
+ function clampPersistedCheckedState(value: i32): SemanticCheckedState {
17
+ if (value == <i32>SemanticCheckedState.True) {
18
+ return SemanticCheckedState.True;
19
+ }
20
+ if (value == <i32>SemanticCheckedState.Mixed) {
21
+ return SemanticCheckedState.Mixed;
22
+ }
23
+ return SemanticCheckedState.False;
24
+ }
25
+
26
+ class PersistedCheckboxState extends PersistedValueState<Checkbox, i32> {
27
+ constructor() {
28
+ super("checkbox-checked-state", CHECKBOX_PERSISTED_CODEC, 1);
29
+ }
30
+
31
+ protected captureValue(node: Checkbox): i32 {
32
+ return <i32>node.checkedState;
33
+ }
34
+
35
+ protected restoreValue(node: Checkbox, value: i32): void {
36
+ node._applyPersistedCheckedState(clampPersistedCheckedState(value));
37
+ }
38
+ }
39
+
40
+ const CHECKBOX_PERSISTED_STATE = new PersistedCheckboxState();
41
+
42
+ function createIndicatorPresenter(template: CheckboxIndicatorTemplate | null): CheckboxIndicatorPresenter {
43
+ if (template !== null) {
44
+ return template.create();
45
+ }
46
+ const templateSet = getControlTemplates();
47
+ const appTemplate = templateSet !== null ? templateSet.checkboxIndicator : null;
48
+ return (appTemplate === null ? defaultCheckboxIndicatorTemplate : appTemplate).create();
49
+ }
50
+
51
+ export class Checkbox extends PressableLabeledControl {
52
+ private indicatorPresenter: CheckboxIndicatorPresenter;
53
+ private templateOverride: CheckboxIndicatorTemplate | null = null;
54
+ private checkedStateValue: SemanticCheckedState = SemanticCheckedState.False;
55
+ private triStateEnabled: bool = false;
56
+ private changedCallback: ((state: SemanticCheckedState) => void) | null = null;
57
+ private changedBinding: Callback1<SemanticCheckedState> | null = null;
58
+
59
+ constructor(label: string) {
60
+ const indicatorPresenter = createIndicatorPresenter(null);
61
+ super(SemanticRole.Checkbox, label, indicatorPresenter.root);
62
+ this.indicatorPresenter = indicatorPresenter;
63
+ this.semanticChecked(this.checkedStateValue);
64
+ this.syncVisualState();
65
+ this.persistState(CHECKBOX_PERSISTED_STATE);
66
+ }
67
+
68
+ get checkedState(): SemanticCheckedState {
69
+ return this.checkedStateValue;
70
+ }
71
+
72
+ get checked(): bool {
73
+ return this.checkedStateValue == SemanticCheckedState.True;
74
+ }
75
+
76
+ triState(flag: bool = true): this {
77
+ this.triStateEnabled = flag;
78
+ if (!flag && this.checkedStateValue == SemanticCheckedState.Mixed) {
79
+ this.setCheckedState(SemanticCheckedState.False, false);
80
+ }
81
+ return this;
82
+ }
83
+
84
+ check(flag: bool): this {
85
+ this.setCheckedState(flag ? SemanticCheckedState.True : SemanticCheckedState.False, false);
86
+ return this;
87
+ }
88
+
89
+ mixed(flag: bool): this {
90
+ if (!this.triStateEnabled) {
91
+ return this;
92
+ }
93
+ this.setCheckedState(flag ? SemanticCheckedState.Mixed : SemanticCheckedState.False, false);
94
+ return this;
95
+ }
96
+
97
+ template(template: CheckboxIndicatorTemplate | null): this {
98
+ this.templateOverride = template;
99
+ this.indicatorPresenter = createIndicatorPresenter(this.templateOverride);
100
+ this.replaceIndicatorRoot(this.indicatorPresenter.root);
101
+ this.syncVisualState();
102
+ return this;
103
+ }
104
+
105
+ onChanged(callback: ((state: SemanticCheckedState) => void) | null): this {
106
+ this.changedCallback = callback;
107
+ this.changedBinding = null;
108
+ return this;
109
+ }
110
+
111
+ bindChanged<Owner>(owner: Owner, handler: Handler1<Owner, SemanticCheckedState>): this {
112
+ this.changedCallback = null;
113
+ this.changedBinding = bind1<Owner, SemanticCheckedState>(owner, handler);
114
+ return this;
115
+ }
116
+
117
+ onChangedWith<Owner>(owner: Owner, handler: Handler1<Owner, SemanticCheckedState>): this {
118
+ this.bindChanged(owner, handler);
119
+ return this;
120
+ }
121
+
122
+ protected handleActivated(): void {
123
+ if (this.triStateEnabled) {
124
+ if (this.checkedStateValue == SemanticCheckedState.False) {
125
+ this.setCheckedState(SemanticCheckedState.True, true);
126
+ return;
127
+ }
128
+ if (this.checkedStateValue == SemanticCheckedState.True) {
129
+ this.setCheckedState(SemanticCheckedState.Mixed, true);
130
+ return;
131
+ }
132
+ this.setCheckedState(SemanticCheckedState.False, true);
133
+ return;
134
+ }
135
+ this.setCheckedState(
136
+ this.checkedStateValue == SemanticCheckedState.True ? SemanticCheckedState.False : SemanticCheckedState.True,
137
+ true,
138
+ );
139
+ }
140
+
141
+ protected syncVisualState(): void {
142
+ this.indicatorPresenter.apply(
143
+ activeTheme.value,
144
+ new CheckboxIndicatorVisualState(
145
+ this.checkedStateValue,
146
+ this.hoveredState,
147
+ this.pressedState,
148
+ this.focusedState,
149
+ this.isEnabled,
150
+ ),
151
+ );
152
+ }
153
+
154
+ _applyPersistedCheckedState(next: SemanticCheckedState): void {
155
+ this.setCheckedState(next, true);
156
+ }
157
+
158
+ private setCheckedState(next: SemanticCheckedState, emit: bool): void {
159
+ if (!this.triStateEnabled && next == SemanticCheckedState.Mixed) {
160
+ next = SemanticCheckedState.False;
161
+ }
162
+ if (this.checkedStateValue == next) {
163
+ return;
164
+ }
165
+ this.checkedStateValue = next;
166
+ this.semanticChecked(next);
167
+ this.syncVisualState();
168
+ if (emit) {
169
+ this.requestSemanticAnnouncement();
170
+ const callback = this.changedCallback;
171
+ if (callback !== null) {
172
+ callback(next);
173
+ }
174
+ const binding = this.changedBinding;
175
+ if (binding !== null) {
176
+ binding.invoke(next);
177
+ }
178
+ }
179
+ }
180
+
181
+ }