@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,264 @@
1
+ import { Callback1, Handler1 } from "./Callbacks";
2
+ import { Disposable } from "./Disposable";
3
+ import { throwNullArgument } from "./Errors";
4
+ import { fui_fetch_cancel, fui_fetch_start } from "./FetchFfi";
5
+ import { bind1 } from "./bind";
6
+
7
+ const FUNCTION_FETCH_REQUEST = "Fetch.request";
8
+ const FUNCTION_FETCH_METHOD = "FetchRequest.method";
9
+ const FUNCTION_FETCH_HEADER = "FetchRequest.header";
10
+ const FUNCTION_FETCH_BODY_BYTES = "FetchRequest.bodyBytes";
11
+ const FUNCTION_FETCH_BODY_TEXT = "FetchRequest.bodyText";
12
+
13
+ let nextFetchRequestId: u32 = 1;
14
+ const pendingFetchRequests = new Map<u32, FetchRequest>();
15
+
16
+ function encodeUtf8(text: string): Uint8Array {
17
+ return Uint8Array.wrap(String.UTF8.encode(text, false));
18
+ }
19
+
20
+ function encodeTextParts(values: Array<string>): Uint8Array {
21
+ const encodedValues = new Array<Uint8Array>(values.length);
22
+ let totalBytes: usize = sizeof<u32>();
23
+ for (let index = 0; index < values.length; index += 1) {
24
+ const encoded = encodeUtf8(unchecked(values[index]));
25
+ encodedValues[index] = encoded;
26
+ totalBytes += sizeof<u32>() + <usize>encoded.length;
27
+ }
28
+ const bytes = new Uint8Array(<i32>totalBytes);
29
+ let cursor = bytes.dataStart;
30
+ store<u32>(cursor, <u32>values.length);
31
+ cursor += sizeof<u32>();
32
+ for (let index = 0; index < encodedValues.length; index += 1) {
33
+ const encoded = unchecked(encodedValues[index]);
34
+ store<u32>(cursor, <u32>encoded.length);
35
+ cursor += sizeof<u32>();
36
+ if (encoded.length > 0) {
37
+ memory.copy(cursor, encoded.dataStart, <usize>encoded.length);
38
+ cursor += <usize>encoded.length;
39
+ }
40
+ }
41
+ return bytes;
42
+ }
43
+
44
+ function registerPendingFetchRequest(request: FetchRequest): u32 {
45
+ const requestId = nextFetchRequestId++;
46
+ pendingFetchRequests.set(requestId, request);
47
+ return requestId;
48
+ }
49
+
50
+ function findPendingFetchRequest(requestId: u32): FetchRequest | null {
51
+ return pendingFetchRequests.has(requestId) ? unchecked(pendingFetchRequests.get(requestId)) : null;
52
+ }
53
+
54
+ export class FetchResponse {
55
+ readonly ok: bool;
56
+ readonly status: i32;
57
+ readonly statusText: string;
58
+ readonly url: string;
59
+
60
+ constructor(ok: bool, status: i32, statusText: string, url: string) {
61
+ this.ok = ok;
62
+ this.status = status;
63
+ this.statusText = statusText;
64
+ this.url = url;
65
+ }
66
+ }
67
+
68
+ export class FetchRequest implements Disposable {
69
+ private urlValue: string;
70
+ private methodValue: string = "GET";
71
+ private headerParts: Array<string> = new Array<string>();
72
+ private bodyBytesValue: Uint8Array | null = null;
73
+ private completeBinding: Callback1<FetchResponse> | null = null;
74
+ private errorBinding: Callback1<string> | null = null;
75
+ private requestId: u32 = 0;
76
+ private started: bool = false;
77
+ private finished: bool = false;
78
+
79
+ constructor(url: string) {
80
+ this.urlValue = url;
81
+ }
82
+
83
+ method(value: string): this {
84
+ if (changetype<usize>(value) == 0) {
85
+ throwNullArgument(FUNCTION_FETCH_METHOD, "value");
86
+ }
87
+ this.methodValue = value;
88
+ return this;
89
+ }
90
+
91
+ header(name: string, value: string): this {
92
+ if (changetype<usize>(name) == 0) {
93
+ throwNullArgument(FUNCTION_FETCH_HEADER, "name");
94
+ }
95
+ if (changetype<usize>(value) == 0) {
96
+ throwNullArgument(FUNCTION_FETCH_HEADER, "value");
97
+ }
98
+ this.headerParts.push(name);
99
+ this.headerParts.push(value);
100
+ return this;
101
+ }
102
+
103
+ bodyBytes(value: Uint8Array): this {
104
+ if (changetype<usize>(value) == 0) {
105
+ throwNullArgument(FUNCTION_FETCH_BODY_BYTES, "value");
106
+ }
107
+ this.bodyBytesValue = value;
108
+ return this;
109
+ }
110
+
111
+ bodyText(value: string): this {
112
+ if (changetype<usize>(value) == 0) {
113
+ throwNullArgument(FUNCTION_FETCH_BODY_TEXT, "value");
114
+ }
115
+ this.bodyBytesValue = encodeUtf8(value);
116
+ return this;
117
+ }
118
+
119
+ onComplete<Owner>(owner: Owner, handler: Handler1<Owner, FetchResponse>): this {
120
+ if (changetype<usize>(handler) == 0) {
121
+ throwNullArgument("FetchRequest.onComplete", "handler");
122
+ }
123
+ this.completeBinding = bind1<Owner, FetchResponse>(owner, handler);
124
+ return this;
125
+ }
126
+
127
+ onCompleteWith<Owner>(owner: Owner, handler: Handler1<Owner, FetchResponse>): this {
128
+ return this.onComplete<Owner>(owner, handler);
129
+ }
130
+
131
+ onError<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
132
+ if (changetype<usize>(handler) == 0) {
133
+ throwNullArgument("FetchRequest.onError", "handler");
134
+ }
135
+ this.errorBinding = bind1<Owner, string>(owner, handler);
136
+ return this;
137
+ }
138
+
139
+ onErrorWith<Owner>(owner: Owner, handler: Handler1<Owner, string>): this {
140
+ return this.onError<Owner>(owner, handler);
141
+ }
142
+
143
+ start(): this {
144
+ if (this.finished || this.started) {
145
+ return this;
146
+ }
147
+ if (this.urlValue.length == 0) {
148
+ const binding = this.errorBinding;
149
+ if (binding !== null) {
150
+ binding.invoke("FetchRequest.start: url must not be empty.");
151
+ }
152
+ return this;
153
+ }
154
+ const requestId = registerPendingFetchRequest(this);
155
+ const methodBytes = encodeUtf8(this.methodValue);
156
+ const urlBytes = encodeUtf8(this.urlValue);
157
+ const headerBytes = encodeTextParts(this.headerParts);
158
+ const bodyBytes = this.bodyBytesValue;
159
+ this.requestId = requestId;
160
+ this.started = true;
161
+ fui_fetch_start(
162
+ requestId,
163
+ methodBytes.length > 0 ? methodBytes.dataStart : 0,
164
+ <u32>methodBytes.length,
165
+ urlBytes.length > 0 ? urlBytes.dataStart : 0,
166
+ <u32>urlBytes.length,
167
+ headerBytes.length > 0 ? headerBytes.dataStart : 0,
168
+ <u32>headerBytes.length,
169
+ bodyBytes !== null && bodyBytes.length > 0 ? bodyBytes.dataStart : 0,
170
+ bodyBytes === null ? 0 : <u32>bodyBytes.length,
171
+ );
172
+ return this;
173
+ }
174
+
175
+ cancel(): void {
176
+ if (!this.started || this.finished) {
177
+ return;
178
+ }
179
+ fui_fetch_cancel(this.requestId);
180
+ this.finish();
181
+ }
182
+
183
+ dispose(): void {
184
+ this.cancel();
185
+ }
186
+
187
+ private finish(): void {
188
+ if (this.finished) {
189
+ return;
190
+ }
191
+ if (this.requestId != 0) {
192
+ pendingFetchRequests.delete(this.requestId);
193
+ this.requestId = 0;
194
+ }
195
+ this.finished = true;
196
+ this.completeBinding = null;
197
+ this.errorBinding = null;
198
+ }
199
+
200
+ dispatchComplete(response: FetchResponse): void {
201
+ if (this.finished) {
202
+ return;
203
+ }
204
+ const binding = this.completeBinding;
205
+ this.finish();
206
+ if (binding !== null) {
207
+ binding.invoke(response);
208
+ }
209
+ }
210
+
211
+ dispatchError(message: string): void {
212
+ if (this.finished) {
213
+ return;
214
+ }
215
+ const binding = this.errorBinding;
216
+ this.finish();
217
+ if (binding !== null) {
218
+ binding.invoke(message);
219
+ }
220
+ }
221
+ }
222
+
223
+ export class Fetch {
224
+ static request(url: string): FetchRequest {
225
+ if (changetype<usize>(url) == 0) {
226
+ throwNullArgument(FUNCTION_FETCH_REQUEST, "url");
227
+ }
228
+ return new FetchRequest(url);
229
+ }
230
+ }
231
+
232
+ export function handleFetchComplete(
233
+ requestId: u32,
234
+ ok: bool,
235
+ status: i32,
236
+ statusText: string,
237
+ url: string,
238
+ ): void {
239
+ const request = findPendingFetchRequest(requestId);
240
+ if (request === null) {
241
+ return;
242
+ }
243
+ request.dispatchComplete(new FetchResponse(ok, status, statusText, url));
244
+ }
245
+
246
+ export function handleFetchError(requestId: u32, message: string | null): void {
247
+ const request = findPendingFetchRequest(requestId);
248
+ if (request === null) {
249
+ return;
250
+ }
251
+ request.dispatchError(message === null ? "Fetch request failed." : message);
252
+ }
253
+
254
+ export function disposeAllFetchRequests(): void {
255
+ const requests = pendingFetchRequests.values();
256
+ for (let index = 0; index < requests.length; index += 1) {
257
+ unchecked(requests[index]).dispose();
258
+ }
259
+ }
260
+
261
+ export function __resetFetchForTests(): void {
262
+ disposeAllFetchRequests();
263
+ nextFetchRequestId = 1;
264
+ }
@@ -0,0 +1,15 @@
1
+ @external("fui_fetch_host", "fui_fetch_start")
2
+ export declare function fui_fetch_start(
3
+ requestId: u32,
4
+ methodPtr: usize,
5
+ methodLen: u32,
6
+ urlPtr: usize,
7
+ urlLen: u32,
8
+ headersPtr: usize,
9
+ headersLen: u32,
10
+ bodyPtr: usize,
11
+ bodyLen: u32,
12
+ ): void;
13
+
14
+ @external("fui_fetch_host", "fui_fetch_cancel")
15
+ export declare function fui_fetch_cancel(requestId: u32): void;