@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.
- package/LICENSE.md +7 -0
- package/browser/src/common-harness/host-imports.ts +430 -0
- package/browser/src/common-harness/interop.ts +39 -0
- package/browser/src/common-harness/managed-harness-bitmap-host.ts +92 -0
- package/browser/src/common-harness/managed-harness-fetch-host.ts +201 -0
- package/browser/src/common-harness/managed-harness-file-host.ts +1101 -0
- package/browser/src/common-harness/managed-harness-file-payloads.ts +143 -0
- package/browser/src/common-harness/managed-harness-file-types.ts +106 -0
- package/browser/src/common-harness/managed-harness-session.ts +15 -0
- package/browser/src/common-harness/managed-harness.ts +1323 -0
- package/browser/src/common-harness/managed-history.ts +168 -0
- package/browser/src/common-harness/persisted-restore-policy.ts +50 -0
- package/browser/src/common-harness/persisted-ui-state-controller.ts +309 -0
- package/browser/src/common-harness/text-session-bridge.ts +452 -0
- package/browser/src/common-harness/types.ts +205 -0
- package/browser/src/common-harness/ui-chrome.ts +191 -0
- package/browser/src/common-harness/ui-imports.ts +529 -0
- package/browser/src/common-harness/wasm-module-cache.ts +47 -0
- package/browser/src/common-harness.ts +27 -0
- package/browser/src/file-processing-worker.ts +89 -0
- package/browser/src/host-events.ts +97 -0
- package/browser/src/host-services.ts +203 -0
- package/browser/src/index.ts +62 -0
- package/browser/src/persisted-ui-state.ts +206 -0
- package/browser/src/routed-harness.ts +198 -0
- package/browser/src/worker-bootstrap.ts +483 -0
- package/browser/src/worker-manager.ts +230 -0
- package/browser/src/worker-types.ts +50 -0
- package/package.json +89 -0
- package/scripts/build-demo-as.sh +91 -0
- package/scripts/build.sh +325 -0
- package/scripts/generate-host-events.ts +175 -0
- package/scripts/generate-host-services.ts +157 -0
- package/src/Fui.ts +205 -0
- package/src/FuiExports.ts +55 -0
- package/src/FuiPrimitives.ts +15 -0
- package/src/FuiWorker.ts +3 -0
- package/src/FuiWorkerExports.ts +6 -0
- package/src/bindings/ui.ts +531 -0
- package/src/color.ts +86 -0
- package/src/controls/AntiSelectionArea.ts +23 -0
- package/src/controls/Button.ts +750 -0
- package/src/controls/Checkbox.ts +181 -0
- package/src/controls/ContextMenu.ts +885 -0
- package/src/controls/ControlTemplateSet.ts +37 -0
- package/src/controls/Dialog.ts +355 -0
- package/src/controls/Dropdown.ts +856 -0
- package/src/controls/Form.ts +110 -0
- package/src/controls/NavLink.ts +211 -0
- package/src/controls/Popup.ts +129 -0
- package/src/controls/ProgressBar.ts +180 -0
- package/src/controls/RadioButton.ts +135 -0
- package/src/controls/RadioGroup.ts +244 -0
- package/src/controls/SelectionArea.ts +75 -0
- package/src/controls/Slider.ts +471 -0
- package/src/controls/Switch.ts +132 -0
- package/src/controls/TextArea.ts +20 -0
- package/src/controls/TextInput.ts +7 -0
- package/src/controls/index.ts +18 -0
- package/src/controls/internal/ButtonPresenter.ts +95 -0
- package/src/controls/internal/CheckboxIndicatorPresenter.ts +93 -0
- package/src/controls/internal/DropdownChevronPresenter.ts +67 -0
- package/src/controls/internal/DropdownFieldPresenter.ts +110 -0
- package/src/controls/internal/DropdownOptionRowPresenter.ts +82 -0
- package/src/controls/internal/PopupPresenter.ts +198 -0
- package/src/controls/internal/PressableIndicatorPresenter.ts +32 -0
- package/src/controls/internal/PressableLabeledControl.ts +221 -0
- package/src/controls/internal/RadioIndicatorPresenter.ts +73 -0
- package/src/controls/internal/SliderPresenter.ts +157 -0
- package/src/controls/internal/SwitchIndicatorPresenter.ts +72 -0
- package/src/controls/internal/TextInputCore.ts +695 -0
- package/src/controls/internal/TextInputPresenter.ts +72 -0
- package/src/controls/templating.ts +54 -0
- package/src/core/Action.ts +94 -0
- package/src/core/Actions.ts +37 -0
- package/src/core/Animation.ts +412 -0
- package/src/core/Application.ts +328 -0
- package/src/core/Assets.ts +264 -0
- package/src/core/AttachedProperties.ts +32 -0
- package/src/core/Bitmap.ts +70 -0
- package/src/core/BoundCallback.ts +104 -0
- package/src/core/Callbacks.ts +17 -0
- package/src/core/ContextMenuManager.ts +466 -0
- package/src/core/DebugApi.ts +30 -0
- package/src/core/Disposable.ts +10 -0
- package/src/core/DragDropManager.ts +179 -0
- package/src/core/DragGesture.ts +184 -0
- package/src/core/DynamicAssetIds.ts +24 -0
- package/src/core/Errors.ts +48 -0
- package/src/core/EventRouter.ts +408 -0
- package/src/core/ExternalDropManager.ts +122 -0
- package/src/core/Fetch.ts +264 -0
- package/src/core/FetchFfi.ts +15 -0
- package/src/core/File.ts +1002 -0
- package/src/core/FocusAdornerManager.ts +263 -0
- package/src/core/FocusVisibility.ts +36 -0
- package/src/core/FrameScheduler.ts +28 -0
- package/src/core/KeyboardScroll.ts +161 -0
- package/src/core/KeyboardScrollTracker.ts +386 -0
- package/src/core/Logger.ts +80 -0
- package/src/core/Navigation.ts +13 -0
- package/src/core/Node.ts +1708 -0
- package/src/core/PersistedState.ts +102 -0
- package/src/core/PersistedUiState.ts +142 -0
- package/src/core/Platform.ts +219 -0
- package/src/core/Signal.ts +89 -0
- package/src/core/Theme.ts +365 -0
- package/src/core/Timers.ts +129 -0
- package/src/core/ToolTip.ts +122 -0
- package/src/core/ToolTipManager.ts +459 -0
- package/src/core/Transitions.ts +34 -0
- package/src/core/Typography.ts +204 -0
- package/src/core/Worker.ts +196 -0
- package/src/core/bind.ts +37 -0
- package/src/core/event_exports.ts +596 -0
- package/src/core/ffi.ts +728 -0
- package/src/host-services/runtime.ts +25 -0
- package/src/nodes/FlexBox.ts +789 -0
- package/src/nodes/GradientStop.ts +9 -0
- package/src/nodes/Grid.ts +183 -0
- package/src/nodes/Image.ts +189 -0
- package/src/nodes/Portal.ts +14 -0
- package/src/nodes/RichText.ts +312 -0
- package/src/nodes/ScrollBar.ts +570 -0
- package/src/nodes/ScrollBox.ts +415 -0
- package/src/nodes/ScrollState.ts +10 -0
- package/src/nodes/ScrollView.ts +511 -0
- package/src/nodes/Svg.ts +142 -0
- package/src/nodes/Text.ts +145 -0
- package/src/nodes/TextCore.ts +558 -0
- package/src/nodes/VirtualList.ts +431 -0
- package/src/nodes/helpers.ts +25 -0
- package/src/nodes/index.ts +14 -0
- package/src/tsconfig.json +7 -0
- package/src/worker/Worker.ts +169 -0
- package/src/worker/WorkerJob.ts +65 -0
- package/src/worker/ffi.ts +23 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Callback1, Handler1 } from "./Callbacks";
|
|
2
|
+
import { Disposable } from "./Disposable";
|
|
3
|
+
import { throwNullArgument } from "./Errors";
|
|
4
|
+
import { fui_worker_cancel, fui_worker_start_string } from "./ffi";
|
|
5
|
+
import { warn } from "./Logger";
|
|
6
|
+
import { bind1 } from "./bind";
|
|
7
|
+
|
|
8
|
+
const FUNCTION_START = "Worker.start";
|
|
9
|
+
const FUNCTION_SEND_STRING = "Worker.sendString";
|
|
10
|
+
|
|
11
|
+
const activeWorkers = new Map<u32, Worker>();
|
|
12
|
+
let nextWorkerId: u32 = 1;
|
|
13
|
+
|
|
14
|
+
function encodeUtf8(text: string): Uint8Array {
|
|
15
|
+
return Uint8Array.wrap(String.UTF8.encode(text, false));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function unregisterWorker(workerId: u32): void {
|
|
19
|
+
activeWorkers.delete(workerId);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function findWorker(workerId: u32): Worker | null {
|
|
23
|
+
return activeWorkers.has(workerId) ? unchecked(activeWorkers.get(workerId)) : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Worker implements Disposable {
|
|
27
|
+
private readonly workerId: u32;
|
|
28
|
+
private readonly entryName: string;
|
|
29
|
+
private progressBinding: Callback1<string> | null = null;
|
|
30
|
+
private completeBinding: Callback1<string> | null = null;
|
|
31
|
+
private errorBinding: Callback1<string> | null = null;
|
|
32
|
+
private started: bool = false;
|
|
33
|
+
private finished: bool = false;
|
|
34
|
+
private cancelRequested: bool = false;
|
|
35
|
+
|
|
36
|
+
private constructor(workerId: u32, entryName: string) {
|
|
37
|
+
this.workerId = workerId;
|
|
38
|
+
this.entryName = entryName;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static start(entryName: string): Worker {
|
|
42
|
+
if (changetype<usize>(entryName) == 0) {
|
|
43
|
+
throwNullArgument(FUNCTION_START, "entryName");
|
|
44
|
+
}
|
|
45
|
+
const workerId = nextWorkerId++;
|
|
46
|
+
const worker = new Worker(workerId, entryName);
|
|
47
|
+
activeWorkers.set(workerId, worker);
|
|
48
|
+
return worker;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onProgress<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
|
|
52
|
+
this.progressBinding = bind1<Owner, string>(owner, handler);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
onProgressWith<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
|
|
57
|
+
return this.onProgress<Owner>(owner, handler);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
onComplete<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
|
|
61
|
+
this.completeBinding = bind1<Owner, string>(owner, handler);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onCompleteWith<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
|
|
66
|
+
return this.onComplete<Owner>(owner, handler);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onError<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
|
|
70
|
+
this.errorBinding = bind1<Owner, string>(owner, handler);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
onErrorWith<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
|
|
75
|
+
return this.onError<Owner>(owner, handler);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
sendString(input: string): this {
|
|
79
|
+
if (changetype<usize>(input) == 0) {
|
|
80
|
+
throwNullArgument(FUNCTION_SEND_STRING, "input");
|
|
81
|
+
}
|
|
82
|
+
if (this.finished) {
|
|
83
|
+
warn("Worker", "sendString ignored after the worker already finished.");
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
if (this.started) {
|
|
87
|
+
warn("Worker", "sendString ignored because one-shot workers only accept one input.");
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
this.started = true;
|
|
91
|
+
const entryBytes = encodeUtf8(this.entryName);
|
|
92
|
+
const inputBytes = encodeUtf8(input);
|
|
93
|
+
fui_worker_start_string(
|
|
94
|
+
this.workerId,
|
|
95
|
+
entryBytes.length > 0 ? entryBytes.dataStart : 0,
|
|
96
|
+
<u32>entryBytes.length,
|
|
97
|
+
inputBytes.length > 0 ? inputBytes.dataStart : 0,
|
|
98
|
+
<u32>inputBytes.length,
|
|
99
|
+
);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
cancel(): void {
|
|
104
|
+
if (!this.started || this.finished || this.cancelRequested) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.cancelRequested = true;
|
|
108
|
+
fui_worker_cancel(this.workerId);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
dispose(): void {
|
|
112
|
+
if (!this.finished && this.started) {
|
|
113
|
+
fui_worker_cancel(this.workerId);
|
|
114
|
+
}
|
|
115
|
+
this.finish();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private dispatchProgress(message: string): void {
|
|
119
|
+
if (this.finished || this.cancelRequested) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const binding = this.progressBinding;
|
|
123
|
+
if (binding !== null) {
|
|
124
|
+
binding.invoke(message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private dispatchComplete(result: string): void {
|
|
129
|
+
if (this.finished) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const binding = this.completeBinding;
|
|
133
|
+
this.finish();
|
|
134
|
+
if (binding !== null) {
|
|
135
|
+
binding.invoke(result);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private dispatchError(message: string): void {
|
|
140
|
+
if (this.finished) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const binding = this.errorBinding;
|
|
144
|
+
this.finish();
|
|
145
|
+
if (binding !== null) {
|
|
146
|
+
binding.invoke(message);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private finish(): void {
|
|
151
|
+
if (this.finished) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this.finished = true;
|
|
155
|
+
this.progressBinding = null;
|
|
156
|
+
this.completeBinding = null;
|
|
157
|
+
this.errorBinding = null;
|
|
158
|
+
unregisterWorker(this.workerId);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function handleWorkerProgress(workerId: u32, message: string): void {
|
|
163
|
+
const worker = findWorker(workerId);
|
|
164
|
+
if (worker === null) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
worker.dispatchProgress(message);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function handleWorkerComplete(workerId: u32, result: string): void {
|
|
171
|
+
const worker = findWorker(workerId);
|
|
172
|
+
if (worker === null) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
worker.dispatchComplete(result);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function handleWorkerError(workerId: u32, message: string): void {
|
|
179
|
+
const worker = findWorker(workerId);
|
|
180
|
+
if (worker === null) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
worker.dispatchError(message);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function disposeAllWorkers(): void {
|
|
187
|
+
const workers = activeWorkers.values();
|
|
188
|
+
for (let index = 0; index < workers.length; ++index) {
|
|
189
|
+
unchecked(workers[index]).dispose();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function __resetWorkerControllersForTests(): void {
|
|
194
|
+
disposeAllWorkers();
|
|
195
|
+
nextWorkerId = 1;
|
|
196
|
+
}
|
package/src/core/bind.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BoundCallback0,
|
|
3
|
+
BoundCallback1,
|
|
4
|
+
BoundCallback2,
|
|
5
|
+
BoundResultCallback0,
|
|
6
|
+
BoundResultCallback1,
|
|
7
|
+
Callback0,
|
|
8
|
+
Callback1,
|
|
9
|
+
Callback2,
|
|
10
|
+
Handler0,
|
|
11
|
+
Handler1,
|
|
12
|
+
Handler2,
|
|
13
|
+
ResultCallback0,
|
|
14
|
+
ResultCallback1,
|
|
15
|
+
ResultHandler0,
|
|
16
|
+
ResultHandler1,
|
|
17
|
+
} from "./Callbacks";
|
|
18
|
+
|
|
19
|
+
export function bind0<Owner>(owner: Owner, handler: Handler0<Owner>): Callback0 {
|
|
20
|
+
return new BoundCallback0<Owner>(owner, handler);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function bind1<Owner, T>(owner: Owner, handler: Handler1<Owner, T>): Callback1<T> {
|
|
24
|
+
return new BoundCallback1<Owner, T>(owner, handler);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function bind2<Owner, T1, T2>(owner: Owner, handler: Handler2<Owner, T1, T2>): Callback2<T1, T2> {
|
|
28
|
+
return new BoundCallback2<Owner, T1, T2>(owner, handler);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function bindResult0<Owner, R>(owner: Owner, handler: ResultHandler0<Owner, R>): ResultCallback0<R> {
|
|
32
|
+
return new BoundResultCallback0<Owner, R>(owner, handler);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function bindResult1<Owner, T, R>(owner: Owner, handler: ResultHandler1<Owner, T, R>): ResultCallback1<T, R> {
|
|
36
|
+
return new BoundResultCallback1<Owner, T, R>(owner, handler);
|
|
37
|
+
}
|