xbintsc 0.7.6 → 0.7.7

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 (53) hide show
  1. package/dist/src/binder/references.js +13 -7
  2. package/dist/src/binder/references.js.map +1 -1
  3. package/dist/src/cli/help.d.ts +1 -1
  4. package/dist/src/driver/version.d.ts +1 -1
  5. package/dist/src/driver/version.js +1 -1
  6. package/dist/src/extensions/gui/index.js +5 -0
  7. package/dist/src/extensions/gui/index.js.map +1 -1
  8. package/dist/tests/binder/binder.test.js +26 -4
  9. package/dist/tests/binder/binder.test.js.map +1 -1
  10. package/dist/tests/checker/checker.test.js +16 -0
  11. package/dist/tests/checker/checker.test.js.map +1 -1
  12. package/dist/tests/e2e/gui-browser.test.js +31 -0
  13. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  14. package/dist/tests/e2e/gui-events.test.js +89 -0
  15. package/dist/tests/e2e/gui-events.test.js.map +1 -1
  16. package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
  17. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
  18. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
  19. package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
  20. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
  21. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
  22. package/doc/gui/api.md +9 -0
  23. package/doc/gui/input.md +8 -0
  24. package/doc/gui/known-issues.md +8 -0
  25. package/doc/implemented/binder.md +1 -1
  26. package/doc/zh-CN/gui/api.md +8 -0
  27. package/doc/zh-CN/gui/input.md +7 -0
  28. package/doc/zh-CN/gui/known-issues.md +6 -0
  29. package/doc/zh-CN/implemented/binder.md +1 -1
  30. package/package.json +7 -7
  31. package/runtime/ext_gui/browser.cpp +2 -0
  32. package/runtime/ext_gui/dom_api.cpp +4 -0
  33. package/runtime/ext_gui/dom_api_events.cpp +2 -1
  34. package/runtime/ext_gui/dom_api_internal.h +8 -0
  35. package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
  36. package/runtime/ext_gui/dom_api_proto.cpp +3 -0
  37. package/runtime/ext_gui/dom_api_webgl_state.cpp +7 -0
  38. package/runtime/ext_gui/gui.cpp +2 -0
  39. package/runtime/ext_gui/gui_engine.h +18 -2
  40. package/runtime/ext_gui/gui_events.cpp +18 -118
  41. package/runtime/ext_gui/gui_input.cpp +148 -0
  42. package/runtime/ext_gui/pointer_lock.cpp +137 -0
  43. package/runtime/ext_gui/webgl_buffer.cpp +6 -0
  44. package/runtime/ext_gui/webgl_context.cpp +2 -0
  45. package/runtime/ext_gui/webgl_glsl.h +4 -0
  46. package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
  47. package/runtime/ext_gui/webgl_objects.h +2 -0
  48. package/runtime/ext_gui/webgl_shader.cpp +1 -1
  49. package/runtime/ext_gui/window.cpp +3 -83
  50. package/runtime/ext_gui/window_diagnostics.cpp +94 -1
  51. package/src/binder/references.ts +13 -7
  52. package/src/driver/version.ts +1 -1
  53. package/src/extensions/gui/index.ts +5 -0
@@ -24,6 +24,7 @@ static xt_value g_window_proto = XT_UNDEFINED;
24
24
  xt_value xt_gui_window_set_background(xt_value self, xt_value env, int32_t argc, xt_value *argv);
25
25
  xt_value xt_gui_window_paint_list(xt_value self, xt_value env, int32_t argc, xt_value *argv);
26
26
  xt_value xt_gui_window_paint_count(xt_value self, xt_value env, int32_t argc, xt_value *argv);
27
+ xt_value xt_gui_window_send_event(xt_value self, xt_value env, int32_t argc, xt_value *argv);
27
28
 
28
29
  /* -- methods -------------------------------------------------------------- */
29
30
 
@@ -83,6 +84,7 @@ static xt_value win_load_html(xt_value self, xt_value env, int32_t argc, xt_valu
83
84
  win->scroll_y = 0.0f;
84
85
  /* Fresh document: invalidate every previously handed-out handle, and drop
85
86
  * the decoders that belonged to the old tree. */
87
+ xt_gui_pointer_lock_release(win);
86
88
  xt_gui_handles_reset(win);
87
89
  xt_gui_media_shutdown(win);
88
90
  xt_gui_canvas_shutdown(win);
@@ -373,10 +375,6 @@ static xt_value win_cancel_animation_frame(xt_value self, xt_value env, int32_t
373
375
 
374
376
  /* -- input diagnostics ---------------------------------------------------- */
375
377
 
376
- static double xt_gui_number_or(xt_value value, double fallback) {
377
- return XT_IS_NUMBER(value) ? xt_to_number(value) : fallback;
378
- }
379
-
380
378
  /** Test/debug hook: CSS-like descriptor of the deepest element at (x, y). */
381
379
  static xt_value win_hit_test(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
382
380
  (void)env;
@@ -389,84 +387,6 @@ static xt_value win_hit_test(xt_value self, xt_value env, int32_t argc, xt_value
389
387
  return xt_string_from_cstr(target.c_str());
390
388
  }
391
389
 
392
- /** Test/debug hook: synthesise an input event and deliver it to handlers.
393
- * `win.sendEvent("click", { x, y, button, clicks })`,
394
- * `win.sendEvent("wheel", { x, y, deltaX, deltaY })` or
395
- * `win.sendEvent("keydown", { key, code })`. A key event may instead name the
396
- * SDL `scancode`/`keycode` plus modifiers to exercise a real-keyboard path. */
397
- static xt_value win_send_event(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
398
- (void)env;
399
- XtGuiWindow *win = xt_gui_window_from_this(self);
400
- if (win == nullptr || argc < 1) return XT_FALSE;
401
- const char *type = xt_string_data(xt_to_string(xt_arg(argc, argv, 0)));
402
- if (type == nullptr) return XT_FALSE;
403
- xt_value options = xt_arg(argc, argv, 1);
404
- double x = 0;
405
- double y = 0;
406
- if (XT_IS_OBJECT(options)) {
407
- x = xt_gui_number_or(xt_object_get_cstr(options, "x"), 0);
408
- y = xt_gui_number_or(xt_object_get_cstr(options, "y"), 0);
409
- }
410
- std::string name(type);
411
- if (name == "textInput") {
412
- std::string text;
413
- if (XT_IS_OBJECT(options)) {
414
- xt_value value = xt_object_get_cstr(options, "text");
415
- if (XT_IS_STRING(value)) text = std::string(xt_string_data(value));
416
- }
417
- xt_gui_text_input(win, text.c_str());
418
- return XT_TRUE;
419
- }
420
- if (name == "compositionstart" || name == "compositionupdate" || name == "compositionend") {
421
- std::string data;
422
- if (XT_IS_OBJECT(options)) {
423
- xt_value value = xt_object_get_cstr(options, "data");
424
- if (XT_IS_STRING(value)) data = std::string(xt_string_data(value));
425
- }
426
- xt_gui_composition_event(win, name.c_str(), data.c_str());
427
- return XT_TRUE;
428
- }
429
- if (name == "wheel") {
430
- double delta_x = 0;
431
- double delta_y = 0;
432
- if (XT_IS_OBJECT(options)) {
433
- delta_x = xt_gui_number_or(xt_object_get_cstr(options, "deltaX"), 0);
434
- delta_y = xt_gui_number_or(xt_object_get_cstr(options, "deltaY"), 0);
435
- }
436
- xt_gui_dispatch_wheel(win, (float)x, (float)y, (float)delta_x, (float)delta_y);
437
- return XT_TRUE;
438
- }
439
- if (name == "keydown" || name == "keyup") {
440
- auto flag = [options](const char *key) { return xt_truthy(xt_object_get_cstr(options, key)); };
441
- if (XT_IS_OBJECT(options) && XT_IS_NUMBER(xt_object_get_cstr(options, "scancode"))) {
442
- int scancode = (int)xt_gui_number_or(xt_object_get_cstr(options, "scancode"), 0);
443
- int keycode = (int)xt_gui_number_or(xt_object_get_cstr(options, "keycode"), 0);
444
- xt_gui_dispatch_physical_key(win, type, scancode, keycode, flag("repeat"), flag("ctrl"),
445
- flag("shift"), flag("alt"), flag("meta"), flag("caps"));
446
- return XT_TRUE;
447
- }
448
- const char *key = "";
449
- const char *code = "";
450
- if (XT_IS_OBJECT(options)) {
451
- xt_value key_value = xt_object_get_cstr(options, "key");
452
- xt_value code_value = xt_object_get_cstr(options, "code");
453
- if (XT_IS_STRING(key_value)) key = xt_string_data(key_value);
454
- if (XT_IS_STRING(code_value)) code = xt_string_data(code_value);
455
- }
456
- xt_gui_dispatch_key_with_modifiers(win, type, key, code, flag("repeat"), flag("ctrl"),
457
- flag("shift"), flag("alt"), flag("meta"));
458
- return XT_TRUE;
459
- }
460
- int button = -1;
461
- int clicks = 0;
462
- if (XT_IS_OBJECT(options)) {
463
- button = (int)xt_gui_number_or(xt_object_get_cstr(options, "button"), -1);
464
- clicks = (int)xt_gui_number_or(xt_object_get_cstr(options, "clicks"), 0);
465
- }
466
- xt_gui_dispatch_pointer(win, type, (float)x, (float)y, button, clicks);
467
- return XT_TRUE;
468
- }
469
-
470
390
  /** Diagnostic/test hook: engine counters as one object. `heapBytes` and
471
391
  * `heapAllocations` are the live runtime heap, `treeNodes`/`detachedNodes` the
472
392
  * DOM tree and the detached pool, and `handles`/`listeners` the element-handle
@@ -588,7 +508,7 @@ xt_value xt_gui_window_proto(void) {
588
508
  * `window_events.cpp`. */
589
509
  xt_gui_install_window_events(proto);
590
510
  define_method(proto, "hitTest", (void *)win_hit_test);
591
- define_method(proto, "sendEvent", (void *)win_send_event);
511
+ define_method(proto, "sendEvent", (void *)xt_gui_window_send_event);
592
512
  define_method(proto, "stats", (void *)win_stats);
593
513
  /* The browser surface a page written for a real page expects (`innerWidth`,
594
514
  * `setTimeout`, `navigator`, `matchMedia`, …) lives in `browser.cpp`. */
@@ -1,6 +1,11 @@
1
1
  /*
2
2
  * xbintsc GUI engine — window diagnostics and background painting exposed as
3
- * test/debug hooks (`setBackground`, `paintList`, `paintCount`).
3
+ * test/debug hooks (`setBackground`, `paintList`, `paintCount`, `sendEvent`).
4
+ *
5
+ * `sendEvent` synthesises the same input payloads a real SDL event produces, so
6
+ * the whole hit-test/listener path is testable without a mouse. The SDL event
7
+ * switch lives in `gui_input.cpp`; the single-window record and its prototype
8
+ * stay in `window.cpp`.
4
9
  */
5
10
 
6
11
  #include "gui_internal.h"
@@ -56,3 +61,91 @@ xt_value xt_gui_window_paint_count(xt_value self, xt_value env, int32_t argc, xt
56
61
  xtgui::xt_paint_build(win->document->layout().root(), list);
57
62
  return xt_number((double)list.rects.size());
58
63
  }
64
+
65
+ static double xt_gui_number_or(xt_value value, double fallback) {
66
+ return XT_IS_NUMBER(value) ? xt_to_number(value) : fallback;
67
+ }
68
+
69
+ /** Test/debug hook: synthesise an input event and deliver it to handlers.
70
+ * `win.sendEvent("click", { x, y, button, clicks })`,
71
+ * `win.sendEvent("wheel", { x, y, deltaX, deltaY })`,
72
+ * `win.sendEvent("mousemove", { x, y, movementX, movementY })` or
73
+ * `win.sendEvent("keydown", { key, code })`. A key event may instead name the
74
+ * SDL `scancode`/`keycode` plus modifiers to exercise a real-keyboard path. */
75
+ xt_value xt_gui_window_send_event(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
76
+ (void)env;
77
+ XtGuiWindow *win = xt_gui_window_from_this(self);
78
+ if (win == nullptr || argc < 1) return XT_FALSE;
79
+ const char *type = xt_string_data(xt_to_string(xt_arg(argc, argv, 0)));
80
+ if (type == nullptr) return XT_FALSE;
81
+ xt_value options = xt_arg(argc, argv, 1);
82
+ double x = 0;
83
+ double y = 0;
84
+ double movement_x = 0;
85
+ double movement_y = 0;
86
+ if (XT_IS_OBJECT(options)) {
87
+ x = xt_gui_number_or(xt_object_get_cstr(options, "x"), 0);
88
+ y = xt_gui_number_or(xt_object_get_cstr(options, "y"), 0);
89
+ movement_x = xt_gui_number_or(xt_object_get_cstr(options, "movementX"), 0);
90
+ movement_y = xt_gui_number_or(xt_object_get_cstr(options, "movementY"), 0);
91
+ }
92
+ std::string name(type);
93
+ if (name == "textInput") {
94
+ std::string text;
95
+ if (XT_IS_OBJECT(options)) {
96
+ xt_value value = xt_object_get_cstr(options, "text");
97
+ if (XT_IS_STRING(value)) text = std::string(xt_string_data(value));
98
+ }
99
+ xt_gui_text_input(win, text.c_str());
100
+ return XT_TRUE;
101
+ }
102
+ if (name == "compositionstart" || name == "compositionupdate" || name == "compositionend") {
103
+ std::string data;
104
+ if (XT_IS_OBJECT(options)) {
105
+ xt_value value = xt_object_get_cstr(options, "data");
106
+ if (XT_IS_STRING(value)) data = std::string(xt_string_data(value));
107
+ }
108
+ xt_gui_composition_event(win, name.c_str(), data.c_str());
109
+ return XT_TRUE;
110
+ }
111
+ if (name == "wheel") {
112
+ double delta_x = 0;
113
+ double delta_y = 0;
114
+ if (XT_IS_OBJECT(options)) {
115
+ delta_x = xt_gui_number_or(xt_object_get_cstr(options, "deltaX"), 0);
116
+ delta_y = xt_gui_number_or(xt_object_get_cstr(options, "deltaY"), 0);
117
+ }
118
+ xt_gui_dispatch_wheel(win, (float)x, (float)y, (float)delta_x, (float)delta_y);
119
+ return XT_TRUE;
120
+ }
121
+ if (name == "keydown" || name == "keyup") {
122
+ auto flag = [options](const char *key) { return xt_truthy(xt_object_get_cstr(options, key)); };
123
+ if (XT_IS_OBJECT(options) && XT_IS_NUMBER(xt_object_get_cstr(options, "scancode"))) {
124
+ int scancode = (int)xt_gui_number_or(xt_object_get_cstr(options, "scancode"), 0);
125
+ int keycode = (int)xt_gui_number_or(xt_object_get_cstr(options, "keycode"), 0);
126
+ xt_gui_dispatch_physical_key(win, type, scancode, keycode, flag("repeat"), flag("ctrl"),
127
+ flag("shift"), flag("alt"), flag("meta"), flag("caps"));
128
+ return XT_TRUE;
129
+ }
130
+ const char *key = "";
131
+ const char *code = "";
132
+ if (XT_IS_OBJECT(options)) {
133
+ xt_value key_value = xt_object_get_cstr(options, "key");
134
+ xt_value code_value = xt_object_get_cstr(options, "code");
135
+ if (XT_IS_STRING(key_value)) key = xt_string_data(key_value);
136
+ if (XT_IS_STRING(code_value)) code = xt_string_data(code_value);
137
+ }
138
+ xt_gui_dispatch_key_with_modifiers(win, type, key, code, flag("repeat"), flag("ctrl"),
139
+ flag("shift"), flag("alt"), flag("meta"));
140
+ return XT_TRUE;
141
+ }
142
+ int button = -1;
143
+ int clicks = 0;
144
+ if (XT_IS_OBJECT(options)) {
145
+ button = (int)xt_gui_number_or(xt_object_get_cstr(options, "button"), -1);
146
+ clicks = (int)xt_gui_number_or(xt_object_get_cstr(options, "clicks"), 0);
147
+ }
148
+ xt_gui_dispatch_pointer(win, type, (float)x, (float)y, button, clicks, (float)movement_x,
149
+ (float)movement_y);
150
+ return XT_TRUE;
151
+ }
@@ -144,15 +144,21 @@ export const referenceMethods: ReferenceMethods = {
144
144
  clauses: { expression?: Expression; statements: Statement[] }[];
145
145
  };
146
146
  this.bindNode(statement.expression, scope);
147
- /* Every `case` body shares the switch's block scope, so the
148
- * declarations they contain have to be pre-declared before any clause
149
- * is bound. Without this a `const` declared directly in a `case`
150
- * clause had no symbol and later phases crashed on it. */
147
+ /* A switch body is a block scope of its own, so all `case` bodies
148
+ * share one scope *below* the enclosing one: a `let`/`const` written
149
+ * directly in a clause shadows an outer binding
150
+ * (`function f(t) { switch (…) { case 1: let t = … } }` is legal, and
151
+ * minified output relies on it) while two clauses declaring the same
152
+ * name still collide. The declarations have to be pre-declared before
153
+ * any clause is bound; without that a `const` declared directly in a
154
+ * `case` clause had no symbol and later phases crashed on it. */
155
+ const switchScope = this.createScope(ScopeKind.Block, node, scope);
156
+ this.scopes.set(node, switchScope);
151
157
  for (const clause of statement.clauses) {
152
- this.bindNode(clause.expression, scope);
153
- this.predeclareStatements(clause.statements, scope);
158
+ this.bindNode(clause.expression, switchScope);
159
+ this.predeclareStatements(clause.statements, switchScope);
154
160
  }
155
- for (const clause of statement.clauses) this.bindStatements(clause.statements, scope);
161
+ for (const clause of statement.clauses) this.bindStatements(clause.statements, switchScope);
156
162
  return;
157
163
  }
158
164
  case SyntaxKind.BreakStatement:
@@ -9,4 +9,4 @@
9
9
  * `main`/`master` only (see `.githooks/pre-commit`), so feature branches never
10
10
  * change this line and merging two of them cannot conflict here.
11
11
  */
12
- export const COMPILER_VERSION = "0.7.6";
12
+ export const COMPILER_VERSION = "0.7.7";
@@ -89,6 +89,11 @@ const hostTypes = [
89
89
  "AbortController",
90
90
  "AbortSignal",
91
91
  "EventTarget",
92
+ /* An inert observer: bundlers build one unconditionally (Vite's
93
+ * `modulepreload` polyfill calls `new MutationObserver(…).observe(…)` at
94
+ * startup), so the name has to resolve and the methods have to exist. No
95
+ * callback ever fires — see `runtime/ext_gui/dom_api_mutation.cpp`. */
96
+ "MutationObserver",
92
97
  "DOMParser",
93
98
  "Request",
94
99
  "Headers",