xbintsc 0.6.12 → 0.6.17

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 (189) hide show
  1. package/dist/src/ast/expressions.d.ts +6 -0
  2. package/dist/src/checker/type-infer.js +1 -1
  3. package/dist/src/checker/type-infer.js.map +1 -1
  4. package/dist/src/cli/help.d.ts +1 -1
  5. package/dist/src/codegen/generator/calls/literals.js +4 -1
  6. package/dist/src/codegen/generator/calls/literals.js.map +1 -1
  7. package/dist/src/codegen/generator/expressions/assignment.js +3 -1
  8. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  9. package/dist/src/codegen/generator/expressions/operators.js +2 -6
  10. package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
  11. package/dist/src/codegen/generator/expressions/primary.d.ts +9 -0
  12. package/dist/src/codegen/generator/expressions/primary.js +44 -7
  13. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  14. package/dist/src/driver/bundler/commonjs.js +1 -1
  15. package/dist/src/driver/bundler/commonjs.js.map +1 -1
  16. package/dist/src/driver/bundler/symbols.js +6 -0
  17. package/dist/src/driver/bundler/symbols.js.map +1 -1
  18. package/dist/src/driver/version.d.ts +1 -1
  19. package/dist/src/driver/version.js +1 -1
  20. package/dist/src/extensions/gui/features.d.ts +2 -0
  21. package/dist/src/extensions/gui/features.js +24 -0
  22. package/dist/src/extensions/gui/features.js.map +1 -1
  23. package/dist/src/extensions/gui/index.js +39 -0
  24. package/dist/src/extensions/gui/index.js.map +1 -1
  25. package/dist/src/extensions/node/index.js +2 -0
  26. package/dist/src/extensions/node/index.js.map +1 -1
  27. package/dist/src/extensions/node/readline/index.d.ts +12 -0
  28. package/dist/src/extensions/node/readline/index.js +27 -0
  29. package/dist/src/extensions/node/readline/index.js.map +1 -0
  30. package/dist/src/parser/declarations/functions.js +6 -0
  31. package/dist/src/parser/declarations/functions.js.map +1 -1
  32. package/dist/src/parser/literals.js +1 -1
  33. package/dist/src/parser/literals.js.map +1 -1
  34. package/dist/tests/e2e/compile-modules.test.js +22 -0
  35. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  36. package/dist/tests/e2e/date-parse.test.js +17 -0
  37. package/dist/tests/e2e/date-parse.test.js.map +1 -1
  38. package/dist/tests/e2e/gui-browser.test.js +61 -0
  39. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  40. package/dist/tests/e2e/gui-css-coverage.test.js +39 -0
  41. package/dist/tests/e2e/gui-css-coverage.test.js.map +1 -1
  42. package/dist/tests/e2e/gui-css-features.test.js +100 -0
  43. package/dist/tests/e2e/gui-css-features.test.js.map +1 -1
  44. package/dist/tests/e2e/gui-dom.test.js +34 -0
  45. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  46. package/dist/tests/e2e/gui-errors.test.d.ts +11 -0
  47. package/dist/tests/e2e/gui-errors.test.js +68 -0
  48. package/dist/tests/e2e/gui-errors.test.js.map +1 -0
  49. package/dist/tests/e2e/gui-example-pelican3d.test.d.ts +6 -4
  50. package/dist/tests/e2e/gui-example-pelican3d.test.js +103 -44
  51. package/dist/tests/e2e/gui-example-pelican3d.test.js.map +1 -1
  52. package/dist/tests/e2e/gui-example-webgpu.test.d.ts +9 -0
  53. package/dist/tests/e2e/gui-example-webgpu.test.js +59 -0
  54. package/dist/tests/e2e/gui-example-webgpu.test.js.map +1 -0
  55. package/dist/tests/e2e/gui-helpers.d.ts +1 -1
  56. package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js +7 -1
  57. package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js.map +1 -1
  58. package/dist/tests/e2e/gui-webgpu.test.d.ts +11 -0
  59. package/dist/tests/e2e/gui-webgpu.test.js +402 -0
  60. package/dist/tests/e2e/gui-webgpu.test.js.map +1 -0
  61. package/dist/tests/e2e/harness.d.ts +4 -0
  62. package/dist/tests/e2e/harness.js +2 -0
  63. package/dist/tests/e2e/harness.js.map +1 -1
  64. package/dist/tests/e2e/readline.test.d.ts +7 -0
  65. package/dist/tests/e2e/readline.test.js +73 -0
  66. package/dist/tests/e2e/readline.test.js.map +1 -0
  67. package/dist/tests/extensions/gui-features.test.js +18 -1
  68. package/dist/tests/extensions/gui-features.test.js.map +1 -1
  69. package/doc/ai/extensions.md +7 -1
  70. package/doc/ai/zh-CN/extensions.md +6 -1
  71. package/doc/gui/api.md +15 -0
  72. package/doc/gui/dom.md +7 -2
  73. package/doc/gui/known-issues.md +2 -1
  74. package/doc/gui/layout.md +5 -1
  75. package/doc/gui/webgpu.md +121 -0
  76. package/doc/gui.md +12 -1
  77. package/doc/implemented/node/readline.md +34 -0
  78. package/doc/implemented/node.md +1 -0
  79. package/doc/unimplemented/node/modules.md +2 -3
  80. package/doc/unimplemented/node.md +2 -2
  81. package/doc/zh-CN/gui/api.md +11 -0
  82. package/doc/zh-CN/gui/dom.md +6 -2
  83. package/doc/zh-CN/gui/known-issues.md +2 -1
  84. package/doc/zh-CN/gui/layout.md +4 -1
  85. package/doc/zh-CN/gui/webgpu.md +111 -0
  86. package/doc/zh-CN/gui.md +10 -1
  87. package/doc/zh-CN/implemented/node/readline.md +33 -0
  88. package/doc/zh-CN/implemented/node.md +1 -0
  89. package/doc/zh-CN/unimplemented/node/modules.md +1 -2
  90. package/doc/zh-CN/unimplemented/node.md +2 -2
  91. package/llms.txt +1 -0
  92. package/package.json +7 -7
  93. package/runtime/ext_gui/browser.cpp +10 -0
  94. package/runtime/ext_gui/browser_abort.cpp +2 -2
  95. package/runtime/ext_gui/browser_loop.cpp +1 -0
  96. package/runtime/ext_gui/browser_media.cpp +1 -1
  97. package/runtime/ext_gui/dom_api_canvas.cpp +21 -0
  98. package/runtime/ext_gui/dom_api_canvas_extra.cpp +61 -0
  99. package/runtime/ext_gui/dom_api_canvas_image.cpp +2 -1
  100. package/runtime/ext_gui/dom_api_events.cpp +1 -1
  101. package/runtime/ext_gui/dom_api_internal.h +2 -0
  102. package/runtime/ext_gui/dom_api_node.cpp +18 -12
  103. package/runtime/ext_gui/dom_api_node_read.cpp +27 -0
  104. package/runtime/ext_gui/dom_api_proto.cpp +2 -0
  105. package/runtime/ext_gui/error_report.cpp +166 -0
  106. package/runtime/ext_gui/gpu_feature.cpp +2 -0
  107. package/runtime/ext_gui/gpu_shader_api.h +6 -0
  108. package/runtime/ext_gui/gui.cpp +16 -0
  109. package/runtime/ext_gui/gui_canvas.cpp +18 -0
  110. package/runtime/ext_gui/gui_engine.h +13 -0
  111. package/runtime/ext_gui/gui_events.cpp +4 -1
  112. package/runtime/ext_gui/layout_inline.cpp +46 -14
  113. package/runtime/ext_gui/paint.cpp +22 -0
  114. package/runtime/ext_gui/renderer_image.cpp +6 -0
  115. package/runtime/ext_gui/script.cpp +1 -1
  116. package/runtime/ext_gui/style.cpp +1 -0
  117. package/runtime/ext_gui/style.h +13 -0
  118. package/runtime/ext_gui/style_print.cpp +99 -0
  119. package/runtime/ext_gui/style_text.cpp +79 -0
  120. package/runtime/ext_gui/webgl_glsl.h +8 -0
  121. package/runtime/ext_gui/webgl_glsl_compile.cpp +11 -5
  122. package/runtime/ext_gui/webgl_msl.cpp +20 -9
  123. package/runtime/ext_gui/webgl_msl.h +4 -0
  124. package/runtime/ext_gui/webgl_texture.cpp +0 -8
  125. package/runtime/ext_gui/webgpu.h +371 -0
  126. package/runtime/ext_gui/webgpu_api.h +42 -0
  127. package/runtime/ext_gui/webgpu_bindings.cpp +364 -0
  128. package/runtime/ext_gui/webgpu_bindings.h +59 -0
  129. package/runtime/ext_gui/webgpu_bridge.c +21 -0
  130. package/runtime/ext_gui/webgpu_buffer.cpp +293 -0
  131. package/runtime/ext_gui/webgpu_canvas.cpp +305 -0
  132. package/runtime/ext_gui/webgpu_command.cpp +510 -0
  133. package/runtime/ext_gui/webgpu_compute_pass.cpp +138 -0
  134. package/runtime/ext_gui/webgpu_convert.cpp +309 -0
  135. package/runtime/ext_gui/webgpu_device.cpp +370 -0
  136. package/runtime/ext_gui/webgpu_feature.cpp +74 -0
  137. package/runtime/ext_gui/webgpu_objects.cpp +125 -0
  138. package/runtime/ext_gui/webgpu_pass.cpp +295 -0
  139. package/runtime/ext_gui/webgpu_pass.h +33 -0
  140. package/runtime/ext_gui/webgpu_pipeline.cpp +463 -0
  141. package/runtime/ext_gui/webgpu_queue.cpp +222 -0
  142. package/runtime/ext_gui/webgpu_render_pass.cpp +417 -0
  143. package/runtime/ext_gui/webgpu_resources.cpp +315 -0
  144. package/runtime/ext_gui/webgpu_shader.cpp +242 -0
  145. package/runtime/ext_gui/wgsl.h +99 -0
  146. package/runtime/ext_gui/wgsl_api.cpp +137 -0
  147. package/runtime/ext_gui/wgsl_ast.h +233 -0
  148. package/runtime/ext_gui/wgsl_emit.cpp +452 -0
  149. package/runtime/ext_gui/wgsl_emit.h +128 -0
  150. package/runtime/ext_gui/wgsl_emit_call.cpp +281 -0
  151. package/runtime/ext_gui/wgsl_emit_expr.cpp +192 -0
  152. package/runtime/ext_gui/wgsl_emit_stmt.cpp +209 -0
  153. package/runtime/ext_gui/wgsl_entry.cpp +189 -0
  154. package/runtime/ext_gui/wgsl_infer.cpp +171 -0
  155. package/runtime/ext_gui/wgsl_lexer.cpp +179 -0
  156. package/runtime/ext_gui/wgsl_lexer.h +32 -0
  157. package/runtime/ext_gui/wgsl_parse_expr.cpp +215 -0
  158. package/runtime/ext_gui/wgsl_parse_stmt.cpp +259 -0
  159. package/runtime/ext_gui/wgsl_parser.cpp +457 -0
  160. package/runtime/ext_gui/wgsl_parser.h +77 -0
  161. package/runtime/ext_gui/wgsl_type.cpp +232 -0
  162. package/runtime/ext_gui/window.cpp +22 -8
  163. package/runtime/ext_gui/window_emit.cpp +1 -1
  164. package/runtime/ext_node/fs/parts/platform.inc +2 -0
  165. package/runtime/ext_node/readline/readline.c +572 -0
  166. package/runtime/rt.h +15 -0
  167. package/runtime/rt_internal.h +3 -2
  168. package/runtime/xt_io/exception.inc +29 -6
  169. package/runtime/xt_loop.c +36 -1
  170. package/runtime/xt_promise.c +26 -2
  171. package/runtime/xt_stdlib2/date.inc +2 -2
  172. package/runtime/xt_typed_array/elements.inc +0 -9
  173. package/runtime/xt_url.c +0 -6
  174. package/runtime/xt_url_object.c +1 -1
  175. package/src/ast/expressions.ts +6 -0
  176. package/src/checker/type-infer.ts +1 -1
  177. package/src/codegen/generator/calls/literals.ts +4 -1
  178. package/src/codegen/generator/expressions/assignment.ts +3 -1
  179. package/src/codegen/generator/expressions/operators.ts +2 -6
  180. package/src/codegen/generator/expressions/primary.ts +58 -6
  181. package/src/driver/bundler/commonjs.ts +1 -1
  182. package/src/driver/bundler/symbols.ts +6 -0
  183. package/src/driver/version.ts +1 -1
  184. package/src/extensions/gui/features.ts +24 -0
  185. package/src/extensions/gui/index.ts +39 -0
  186. package/src/extensions/node/index.ts +2 -0
  187. package/src/extensions/node/readline/index.ts +31 -0
  188. package/src/parser/declarations/functions.ts +6 -0
  189. package/src/parser/literals.ts +1 -1
@@ -31,12 +31,18 @@ struct GpuShaderApi {
31
31
  const GlslLinkLayout &layout, const GlslShaderInfo &info);
32
32
  bool (*compile_glsl)(const std::string &source, bool fragment,
33
33
  std::vector<uint32_t> *spirv, std::string *log);
34
+ /** Stage-explicit compile (0 vertex, 1 fragment, 2 compute) for WebGPU. */
35
+ bool (*compile_glsl_stage)(const std::string &source, int stage,
36
+ std::vector<uint32_t> *spirv, std::string *log);
34
37
  bool (*reflect_uniform_block)(const std::vector<uint32_t> &spirv,
35
38
  std::vector<GlslBlockMember> *out);
36
39
  bool (*reflect_attributes)(const std::vector<uint32_t> &spirv,
37
40
  std::unordered_map<std::string, int> *out);
38
41
  bool (*cross_compile_msl)(const std::vector<uint32_t> &spirv, bool fragment,
39
42
  std::string *source, std::string *entry, std::string *log);
43
+ /** Stage-explicit MSL cross-compile for WebGPU compute. */
44
+ bool (*cross_compile_msl_stage)(const std::vector<uint32_t> &spirv, int stage,
45
+ std::string *source, std::string *entry, std::string *log);
40
46
  };
41
47
 
42
48
  /** Install the table. Called by the `gpu` feature bridge before `main`. */
@@ -122,6 +122,7 @@ static void ensure_init(void) {
122
122
  /* Registered only once a window can exist: a failed init has nothing to
123
123
  * mark, and a caller that cannot retry never needs a second provider. */
124
124
  xt_gc_register_root_provider(xt_gui_gc_scan_roots);
125
+ xt_gui_install_error_handlers();
125
126
  g_sdl_initialized = 1;
126
127
  }
127
128
 
@@ -149,6 +150,13 @@ XtGuiWindow *xt_gui_window_from_this(xt_value thisValue) {
149
150
  return window_by_object(thisValue);
150
151
  }
151
152
 
153
+ XtGuiWindow *xt_gui_primary_window(void) {
154
+ for (int i = g_window_count - 1; i >= 0; i--) {
155
+ if (g_windows[i].open) return &g_windows[i];
156
+ }
157
+ return NULL;
158
+ }
159
+
152
160
  void xt_gui_quit_window(XtGuiWindow *win) {
153
161
  if (win == NULL || !win->open) return;
154
162
  win->open = 0;
@@ -253,6 +261,11 @@ static XtGuiWindow *create_window_record(const char *title, int width, int heigh
253
261
  xt_object_set(object, xt_string_from_cstr("__xt_gui_index"), xt_number((double)index));
254
262
  xt_object_set(object, xt_string_from_cstr("__xt_gui_html"), xt_string_from_cstr(""));
255
263
  xt_object_set(object, xt_string_from_cstr("__xt_gui_events"), xt_object_new());
264
+ /* Present-but-null handler properties, like a browser window: a feature
265
+ * probe gets "object" instead of "undefined", and assigning a function is a
266
+ * plain property write. */
267
+ xt_object_set(object, xt_string_from_cstr("onerror"), XT_NULL);
268
+ xt_object_set(object, xt_string_from_cstr("onunhandledrejection"), XT_NULL);
256
269
  /* The engine owns a graph of values on the window's behalf — element
257
270
  * handles (`node_handles`), their event listeners and the queued animation
258
271
  * frame closures. Most of them are referenced from TypeScript too, but not
@@ -413,6 +426,9 @@ extern "C" xt_value xt_gui_run(int32_t argc, xt_value *argv) {
413
426
  * frames. `xt_loop_poll(0)` is non-blocking. */
414
427
  xt_loop_poll(0);
415
428
  xt_drain_microtasks();
429
+ /* Rejections nobody observed become window `unhandledrejection` events;
430
+ * the installed handler suppresses the process-killing default. */
431
+ xt_promise_report_unhandled();
416
432
 
417
433
  if (deadline != 0 && SDL_GetTicks() >= deadline) break;
418
434
  if (!had_event) SDL_Delay(1);
@@ -14,6 +14,7 @@
14
14
  #include "canvas.h"
15
15
  #include "document.h"
16
16
  #include "gui_engine.h"
17
+ #include "webgpu_api.h"
17
18
  #include "gui_internal.h"
18
19
  #include "perf.h"
19
20
 
@@ -90,6 +91,7 @@ void xt_gui_canvas_sync(XtGuiWindow *win) {
90
91
  std::vector<const xtgui::Node *> nodes;
91
92
  collectCanvases(win->document->root(), &nodes);
92
93
  const XtWebglApi *webgl = xt_webgl_api();
94
+ const XtWebgpuApi *webgpu = xt_webgpu_api();
93
95
  for (const xtgui::Node *node : nodes) {
94
96
  if (webgl != nullptr) {
95
97
  if (void *context = webgl->find(win, node)) {
@@ -101,6 +103,20 @@ void xt_gui_canvas_sync(XtGuiWindow *win) {
101
103
  continue;
102
104
  }
103
105
  }
106
+ /* A WebGPU context publishes its colour texture through the same canvas
107
+ * table: the paint pipeline samples that texture directly, so it needs a
108
+ * non-zero canvas id exactly like a WebGL or 2D canvas. */
109
+ if (webgpu != nullptr) {
110
+ uint32_t context = 0;
111
+ if (webgpu->canvas_find(win, node, &context)) {
112
+ float width = 0.0f;
113
+ float height = 0.0f;
114
+ uint64_t id = 0;
115
+ webgpu->info(context, &width, &height, &id);
116
+ win->document->setCanvasInfo(node, width, height, id);
117
+ continue;
118
+ }
119
+ }
104
120
  xtgui::Canvas2D *canvas = xt_gui_canvas_find(win, node);
105
121
  if (canvas != nullptr) {
106
122
  win->document->setCanvasInfo(node, (float)canvas->width(), (float)canvas->height(),
@@ -145,6 +161,8 @@ void xt_gui_canvas_shutdown(XtGuiWindow *win) {
145
161
  if (win == nullptr) return;
146
162
  const XtWebglApi *webgl = xt_webgl_api();
147
163
  if (webgl != nullptr) webgl->shutdown(win);
164
+ const XtWebgpuApi *webgpu = xt_webgpu_api();
165
+ if (webgpu != nullptr) webgpu->shutdown(win);
148
166
  for (auto &entry : win->canvases) releaseCanvasTexture(entry.second.get());
149
167
  win->canvases.clear();
150
168
  for (auto &entry : win->offscreen_canvases) releaseCanvasTexture(entry.second.get());
@@ -70,6 +70,14 @@ void xt_browser_schedule_frame(void);
70
70
  /** Whether `run()` currently owns the frame loop (the pump then stays idle). */
71
71
  int xt_gui_run_active(void);
72
72
 
73
+ /* Page-level error reporting (error_report.cpp). `xt_gui_invoke` runs one
74
+ * host-invoked callback under a `try` boundary so a throw reaches the window's
75
+ * `error`/`unhandledrejection` surfaces instead of terminating the process. */
76
+ void xt_gui_install_error_handlers(void);
77
+ void xt_gui_report_uncaught(xt_value error);
78
+ int xt_gui_unhandled_rejection(xt_value reason, xt_value promise);
79
+ int xt_gui_invoke(xt_value fn, xt_value thisValue, int32_t argc, xt_value *argv);
80
+
73
81
  /* Web Audio objects (`audio.cpp`).
74
82
  * `AudioContext.prototype` — also the `instanceof AudioContext` target. */
75
83
  xt_value xt_gui_audio_proto(void);
@@ -244,6 +252,11 @@ struct XtGuiWindow {
244
252
  /** Resolve a window handle (`this`) to its record, or NULL for a foreign value. */
245
253
  XtGuiWindow *xt_gui_window_from_this(xt_value thisValue);
246
254
 
255
+ /** The most recently created live window, or NULL when none is open. Error
256
+ * reporting uses it because a throw can escape a callback with no window
257
+ * argument. */
258
+ XtGuiWindow *xt_gui_primary_window(void);
259
+
247
260
 
248
261
  /** The `document` handle for `win` (created on first use). */
249
262
  xt_value xt_gui_document_handle(XtGuiWindow *win);
@@ -304,6 +304,9 @@ void handle_event(const SDL_Event *event) {
304
304
  if (event->type == SDL_EVENT_WINDOW_RESIZED) {
305
305
  XtGuiWindow *win = xt_gui_find_by_window_id(event->window.windowID);
306
306
  if (win == NULL || !win->open) return;
307
+ /* `setSize` already applied and emitted the change synchronously; the
308
+ * queued backend event must not deliver the same resize twice. */
309
+ if (win->width == event->window.data1 && win->height == event->window.data2) return;
307
310
  win->width = event->window.data1;
308
311
  win->height = event->window.data2;
309
312
  if (win->document != NULL) win->document->restyle((float)win->width, (float)win->height);
@@ -401,7 +404,7 @@ void xt_gui_run_animation_frames(XtGuiWindow *win, double timestamp_ms) {
401
404
  for (const XtGuiAnimationFrame &frame : frames) {
402
405
  if (!win->open) break;
403
406
  xt_value arg = xt_number(timestamp_ms);
404
- xt_call_with_this(frame.fn, win->object, 1, &arg);
407
+ xt_gui_invoke(frame.fn, win->object, 1, &arg);
405
408
  }
406
409
  frames.clear();
407
410
  }
@@ -67,7 +67,10 @@ void Layouter::flattenInline(LayoutBox *box, float contentWidth,
67
67
  float available = contentWidth;
68
68
  float intrinsic = preferredContentWidth(box, available);
69
69
  setContainingBlock(box, containingBlockAncestor(box));
70
- layoutBlock(box, 0, 0, available, -1, intrinsic);
70
+ /* An explicit width must go through the normal used-width path so
71
+ * `box-sizing: border-box` can subtract padding and borders. Only an `auto`
72
+ * width needs the shrink-to-fit content width forced here. */
73
+ layoutBlock(box, 0, 0, available, -1, isAuto(style.width) ? intrinsic : -1.0f);
71
74
  InlineItem item;
72
75
  item.box = box;
73
76
  item.style = &style;
@@ -274,24 +277,53 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
274
277
  lineDescent = 0;
275
278
  };
276
279
 
277
- for (InlineItem &item : items) {
280
+ for (size_t index = 0; index < items.size(); index++) {
281
+ InlineItem &item = items[index];
278
282
  if (item.force_break) {
279
283
  finalize();
280
284
  continue;
281
285
  }
282
286
  if (item.is_space && line.empty()) continue; // no leading space on a line
283
- /* Break against the band the line would occupy, then place it. */
284
- float pendingHeight = std::max(lineAscent + lineDescent, item.height);
285
- float x0 = 0;
286
- float x1 = 0;
287
- band(cursorY, pendingHeight, &x0, &x1);
288
- float available = x1 - x0;
289
- if (wrap && lineWidth + item.width > available && !line.empty()) finalize();
290
- if (item.is_space && line.empty()) continue;
291
- line.push_back(&item);
292
- lineWidth += item.width;
293
- lineAscent = std::max(lineAscent, item.ascent);
294
- lineDescent = std::max(lineDescent, item.height - item.ascent);
287
+ /* A `break-word`/`anywhere` word that does not fit is split at the
288
+ * largest prefix the remaining line can hold; the remainder is processed
289
+ * again on the next line. Without this a long token overflowed the box. */
290
+ for (;;) {
291
+ /* Break against the band the line would occupy, then place it. */
292
+ float pendingHeight = std::max(lineAscent + lineDescent, item.height);
293
+ float x0 = 0;
294
+ float x1 = 0;
295
+ band(cursorY, pendingHeight, &x0, &x1);
296
+ float available = x1 - x0;
297
+ bool overflows = lineWidth + item.width > available + 0.001f;
298
+ if (wrap && overflows) {
299
+ bool breakWord = item.style != nullptr &&
300
+ item.style->overflow_wrap != OverflowWrap::Normal;
301
+ if (breakWord && !item.atomic && !item.is_space && item.text.size() > 1) {
302
+ float room = available - lineWidth;
303
+ size_t prefix = fittingPrefix(item.text, *item.style, room);
304
+ if (prefix > 0 && prefix < item.text.size()) {
305
+ InlineItem head = item;
306
+ head.text = item.text.substr(0, prefix);
307
+ head.width = textWidth(head.text, *item.style);
308
+ line.push_back(&head);
309
+ lineWidth += head.width;
310
+ lineAscent = std::max(lineAscent, head.ascent);
311
+ lineDescent = std::max(lineDescent, head.height - head.ascent);
312
+ finalize();
313
+ item.text = item.text.substr(prefix);
314
+ item.width = textWidth(item.text, *item.style);
315
+ continue;
316
+ }
317
+ }
318
+ if (!line.empty()) finalize();
319
+ }
320
+ if (item.is_space && line.empty()) break;
321
+ line.push_back(&item);
322
+ lineWidth += item.width;
323
+ lineAscent = std::max(lineAscent, item.ascent);
324
+ lineDescent = std::max(lineDescent, item.height - item.ascent);
325
+ break;
326
+ }
295
327
  }
296
328
  finalize();
297
329
 
@@ -173,6 +173,28 @@ void addTextRuns(const LayoutBox *box, const XtStyle &style, DisplayList &out,
173
173
  paint_detail::addTextRun(out, fragment.x, fragment.y + ascent, fragment.width,
174
174
  fragment.height, fragment.text, spec, base, box->world, clip, style,
175
175
  chain, viewportWidth, viewportHeight);
176
+ if (style.text_decoration_line != 0) {
177
+ /* The decoration uses the element's text colour unless the shorthand
178
+ * named one. Dashed/dotted/wavy are currently painted solid; the style
179
+ * is still retained for `getComputedStyle`. */
180
+ Color rule = paint_detail::filterColor(
181
+ chain, style.has_text_decoration_color ? style.text_decoration_color : style.color);
182
+ float thickness = std::max(1.0f, style.font_size / 14.0f);
183
+ float baseline = fragment.y + ascent;
184
+ if (style.text_decoration_line & (uint8_t)TextDecorationLine::Underline) {
185
+ paint_detail::addRect(out, fragment.x, baseline + thickness, fragment.width, thickness,
186
+ 0.0f, rule, clip, box->world);
187
+ }
188
+ if (style.text_decoration_line & (uint8_t)TextDecorationLine::Overline) {
189
+ paint_detail::addRect(out, fragment.x, fragment.y, fragment.width, thickness, 0.0f, rule,
190
+ clip, box->world);
191
+ }
192
+ if (style.text_decoration_line & (uint8_t)TextDecorationLine::LineThrough) {
193
+ paint_detail::addRect(out, fragment.x,
194
+ fragment.y + fragment.height * 0.55f - thickness / 2.0f,
195
+ fragment.width, thickness, 0.0f, rule, clip, box->world);
196
+ }
197
+ }
176
198
  continue;
177
199
  }
178
200
  if (fragment.upright) {
@@ -16,6 +16,7 @@
16
16
  #include "perf.h"
17
17
  #include "svg.h"
18
18
  #include "webgl_api.h"
19
+ #include "webgpu_api.h"
19
20
 
20
21
  #include "renderer_shaders.h"
21
22
 
@@ -158,6 +159,11 @@ static SDL_GPUTexture *ensureMediaTexture(SDL_GPUDevice *device, uint64_t media_
158
159
  * directly and nothing is copied through the CPU. */
159
160
  static SDL_GPUTexture *ensureCanvasTexture(SDL_GPUDevice *device, uint64_t canvas_id,
160
161
  XtGuiUploadBatch *batch) {
162
+ if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
163
+ if (void *texture = webgpu->color_texture(canvas_id)) {
164
+ return static_cast<SDL_GPUTexture *>(texture);
165
+ }
166
+ }
161
167
  if (const XtWebglApi *webgl = xt_webgl_api()) {
162
168
  if (void *texture = webgl->color_texture(canvas_id)) {
163
169
  return static_cast<SDL_GPUTexture *>(texture);
@@ -99,6 +99,6 @@ void xt_gui_run_scripts(XtGuiWindow *win) {
99
99
  auto it = script_registry().find(id);
100
100
  if (it == script_registry().end()) continue;
101
101
  xt_value args[2] = {window_handle, document_handle};
102
- xt_call_with_this(it->second, XT_UNDEFINED, 2, args);
102
+ xt_gui_invoke(it->second, XT_UNDEFINED, 2, args);
103
103
  }
104
104
  }
@@ -187,6 +187,7 @@ void inheritFrom(XtStyle *style, const XtStyle *parent) {
187
187
  style->white_space = parent->white_space;
188
188
  style->text_shadow = parent->text_shadow;
189
189
  style->text_transform = parent->text_transform;
190
+ style->overflow_wrap = parent->overflow_wrap;
190
191
  style->letter_spacing = parent->letter_spacing;
191
192
  style->font_variant_numeric = parent->font_variant_numeric;
192
193
  style->writing_mode = parent->writing_mode;
@@ -10,6 +10,7 @@
10
10
  #ifndef XT_GUI_STYLE_H
11
11
  #define XT_GUI_STYLE_H
12
12
 
13
+ #include <cstdint>
13
14
  #include <map>
14
15
  #include <memory>
15
16
  #include <string>
@@ -37,6 +38,11 @@ enum class TextAlign { Start, Center, End, Justify };
37
38
  enum class TextOverflow { Clip, Ellipsis };
38
39
  enum class WhiteSpace { Normal, NoWrap, Pre, PreWrap, PreLine };
39
40
  enum class Overflow { Visible, Hidden, Scroll, Auto };
41
+ /** `text-decoration-line` is a bit set; `None` is zero. */
42
+ enum class TextDecorationLine : uint8_t { None = 0, Underline = 1, Overline = 2, LineThrough = 4 };
43
+ enum class TextDecorationStyle { Solid, Double, Dotted, Dashed, Wavy };
44
+ /** `overflow-wrap` (and its legacy `word-wrap` spelling). */
45
+ enum class OverflowWrap { Normal, BreakWord, Anywhere };
40
46
  enum class BorderStyle { None, Solid, Dashed, Dotted };
41
47
  enum class FontStyle { Normal, Italic };
42
48
 
@@ -311,6 +317,13 @@ struct XtStyle {
311
317
  TextOverflow text_overflow = TextOverflow::Clip;
312
318
  WhiteSpace white_space = WhiteSpace::Normal; // inherited
313
319
  TextTransform text_transform = TextTransform::None; // inherited
320
+ /** `text-decoration` shorthand (line/style/color); not inherited, but it
321
+ * propagates visually to in-flow descendants. */
322
+ uint8_t text_decoration_line = 0;
323
+ TextDecorationStyle text_decoration_style = TextDecorationStyle::Solid;
324
+ Color text_decoration_color{0.0f, 0.0f, 0.0f, 1.0f};
325
+ bool has_text_decoration_color = false;
326
+ OverflowWrap overflow_wrap = OverflowWrap::Normal; // inherited
314
327
  /** Resolved to pixels in the cascade (em is the element's own font size). */
315
328
  Length letter_spacing{0.0f, Unit::Px}; // inherited
316
329
  bool font_variant_numeric = false; // inherited; accepted, no OpenType features
@@ -234,6 +234,8 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
234
234
  static const char *const clearNames[] = {"none", "left", "right", "both"};
235
235
  static const char *const alignTextNames[] = {"start", "center", "end", "justify"};
236
236
  static const char *const textTransformNames[] = {"none", "uppercase", "lowercase", "capitalize"};
237
+ static const char *const decorationStyleNames[] = {"solid", "double", "dotted", "dashed", "wavy"};
238
+ static const char *const overflowWrapNames[] = {"normal", "break-word", "anywhere"};
237
239
  static const char *const writingModeNames[] = {"horizontal-tb", "vertical-rl", "vertical-lr"};
238
240
  static const char *const cursorNames[] = {"auto", "default", "pointer", "text", "move",
239
241
  "wait", "help", "not-allowed", "crosshair"};
@@ -252,6 +254,9 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
252
254
  if (style.inline_level) return style.display == Display::Grid ? "inline-grid" : "inline-flex";
253
255
  return displayNames[(int)style.display];
254
256
  }
257
+ if (property == "box-sizing") {
258
+ return style.box_sizing == BoxSizing::BorderBox ? "border-box" : "content-box";
259
+ }
255
260
  if (property == "position") return positionNames[(int)style.position];
256
261
  if (property == "color") return formatColor(style.color);
257
262
  if (property == "background-color" || property == "background") {
@@ -278,11 +283,44 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
278
283
  if (property == "font-size") return formatNumber(style.font_size) + "px";
279
284
  if (property == "font-weight") return formatNumber((float)style.font_weight);
280
285
  if (property == "font-family") return style.font_family;
286
+ if (property == "font-style") return style.font_style == FontStyle::Italic ? "italic" : "normal";
287
+ if (property == "font-variant") return style.font_variant_numeric ? "tabular-nums" : "normal";
288
+ if (property == "font-stretch") return "100%";
289
+ if (property == "font-kerning") return "auto";
290
+ if (property == "overflow" || property == "overflow-x" || property == "overflow-y") {
291
+ static const char *const overflowNames[] = {"visible", "hidden", "scroll", "auto"};
292
+ return overflowNames[(int)style.overflow];
293
+ }
294
+ if (property == "transition") return style.transitions.empty() ? "none" : "";
295
+ if (property == "animation") return style.animations.empty() ? "none" : "";
281
296
  if (property == "line-height") {
282
297
  return style.line_height.unit == Unit::Auto ? "normal" : formatLength(style.line_height);
283
298
  }
284
299
  if (property == "text-align") return alignTextNames[(int)style.text_align];
285
300
  if (property == "text-transform") return textTransformNames[(int)style.text_transform];
301
+ if (property == "text-decoration" || property == "text-decoration-line") {
302
+ if (style.text_decoration_line == 0) return "none";
303
+ std::string out;
304
+ if (style.text_decoration_line & (uint8_t)TextDecorationLine::Underline) out = "underline";
305
+ if (style.text_decoration_line & (uint8_t)TextDecorationLine::Overline) {
306
+ if (!out.empty()) out += " ";
307
+ out += "overline";
308
+ }
309
+ if (style.text_decoration_line & (uint8_t)TextDecorationLine::LineThrough) {
310
+ if (!out.empty()) out += " ";
311
+ out += "line-through";
312
+ }
313
+ return out;
314
+ }
315
+ if (property == "text-decoration-style") {
316
+ return decorationStyleNames[(int)style.text_decoration_style];
317
+ }
318
+ if (property == "text-decoration-color") {
319
+ return formatColor(style.has_text_decoration_color ? style.text_decoration_color : style.color);
320
+ }
321
+ if (property == "overflow-wrap" || property == "word-wrap") {
322
+ return overflowWrapNames[(int)style.overflow_wrap];
323
+ }
286
324
  if (property == "text-overflow") {
287
325
  return style.text_overflow == TextOverflow::Ellipsis ? "ellipsis" : "clip";
288
326
  }
@@ -383,6 +421,67 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
383
421
  if (property == "transform-origin") {
384
422
  return formatLength(style.transform_origin_x) + " " + formatLength(style.transform_origin_y);
385
423
  }
424
+
425
+ /* Standard properties the engine does not model still answer with their
426
+ * CSS initial value. Returning "" made the usual "read the current style"
427
+ * pattern (`getComputedStyle(el).wordBreak`, `.objectFit`, …) see a value no
428
+ * browser produces. Modelled properties are handled above; this table is
429
+ * only the computed default. */
430
+ struct InitialValue {
431
+ const char *name;
432
+ const char *value;
433
+ };
434
+ static const InitialValue kInitialValues[] = {
435
+ {"box-sizing", "content-box"},
436
+ {"text-decoration", "none"},
437
+ {"text-decoration-line", "none"},
438
+ {"text-decoration-style", "solid"},
439
+ {"text-decoration-color", "rgb(0, 0, 0)"},
440
+ {"overflow-wrap", "normal"},
441
+ {"word-wrap", "normal"},
442
+ {"text-indent", "0px"},
443
+ {"word-spacing", "0px"},
444
+ {"word-break", "normal"},
445
+ {"hyphens", "manual"},
446
+ {"tab-size", "8"},
447
+ {"direction", "ltr"},
448
+ {"unicode-bidi", "normal"},
449
+ {"text-rendering", "auto"},
450
+ {"text-justify", "auto"},
451
+ {"background-repeat", "repeat"},
452
+ {"background-position", "0% 0%"},
453
+ {"background-attachment", "scroll"},
454
+ {"background-clip", "border-box"},
455
+ {"background-origin", "padding-box"},
456
+ {"border-collapse", "separate"},
457
+ {"border-spacing", "0px"},
458
+ {"table-layout", "auto"},
459
+ {"caption-side", "top"},
460
+ {"empty-cells", "show"},
461
+ {"list-style-type", "disc"},
462
+ {"list-style-position", "outside"},
463
+ {"list-style-image", "none"},
464
+ {"object-fit", "fill"},
465
+ {"object-position", "50% 50%"},
466
+ {"resize", "none"},
467
+ {"user-select", "auto"},
468
+ {"touch-action", "auto"},
469
+ {"scroll-behavior", "auto"},
470
+ {"overscroll-behavior", "auto"},
471
+ {"will-change", "auto"},
472
+ {"contain", "none"},
473
+ {"isolation", "auto"},
474
+ {"appearance", "none"},
475
+ {"columns", "auto"},
476
+ {"column-count", "auto"},
477
+ {"column-rule", "none"},
478
+ {"caret-color", "auto"},
479
+ {"accent-color", "auto"},
480
+ {"color-scheme", "normal"},
481
+ };
482
+ for (const InitialValue &entry : kInitialValues) {
483
+ if (property == entry.name) return entry.value;
484
+ }
386
485
  return "";
387
486
  }
388
487
 
@@ -123,6 +123,38 @@ bool isFontWeightKeyword(const std::string &token) {
123
123
  return token == "bold" || token == "bolder" || token == "lighter" || token == "normal";
124
124
  }
125
125
 
126
+ /** One token of `text-decoration-line` (`none` clears the set). */
127
+ bool applyDecorationLineToken(const std::string &token, uint8_t *out) {
128
+ if (token == "none") {
129
+ *out = 0;
130
+ return true;
131
+ }
132
+ if (token == "underline") *out |= (uint8_t)TextDecorationLine::Underline;
133
+ else if (token == "overline") *out |= (uint8_t)TextDecorationLine::Overline;
134
+ else if (token == "line-through") *out |= (uint8_t)TextDecorationLine::LineThrough;
135
+ else if (token == "blink") return true; // accepted, no animation
136
+ else return false;
137
+ return true;
138
+ }
139
+
140
+ bool parseDecorationStyle(const std::string &token, TextDecorationStyle *out) {
141
+ if (token == "solid") *out = TextDecorationStyle::Solid;
142
+ else if (token == "double") *out = TextDecorationStyle::Double;
143
+ else if (token == "dotted") *out = TextDecorationStyle::Dotted;
144
+ else if (token == "dashed") *out = TextDecorationStyle::Dashed;
145
+ else if (token == "wavy") *out = TextDecorationStyle::Wavy;
146
+ else return false;
147
+ return true;
148
+ }
149
+
150
+ bool parseOverflowWrap(const std::string &text, OverflowWrap *out) {
151
+ if (text == "normal") *out = OverflowWrap::Normal;
152
+ else if (text == "break-word") *out = OverflowWrap::BreakWord;
153
+ else if (text == "anywhere") *out = OverflowWrap::Anywhere;
154
+ else return false;
155
+ return true;
156
+ }
157
+
126
158
  } // namespace
127
159
 
128
160
  std::string xt_apply_text_transform(const std::string &text, TextTransform transform) {
@@ -167,6 +199,53 @@ bool xt_style_apply_text_property(XtStyle *style, const std::string &property,
167
199
  parseTextTransform(value, &style->text_transform);
168
200
  return true;
169
201
  }
202
+ if (property == "text-decoration" || property == "text-decoration-line") {
203
+ std::vector<std::string> tokens = splitTokens(lowerTrim(value));
204
+ uint8_t line = 0;
205
+ bool sawLine = false;
206
+ for (const std::string &token : tokens) {
207
+ if (applyDecorationLineToken(token, &line)) {
208
+ sawLine = true;
209
+ continue;
210
+ }
211
+ if (property == "text-decoration" && parseDecorationStyle(token, &style->text_decoration_style)) {
212
+ continue;
213
+ }
214
+ if (property == "text-decoration") {
215
+ Color color = xt_css_parse_color(token);
216
+ if (color.valid) {
217
+ style->text_decoration_color = color;
218
+ style->has_text_decoration_color = true;
219
+ }
220
+ }
221
+ }
222
+ /* `text-decoration: <style> <color>` without a line keeps the current
223
+ * line; the shorthand's `none` already cleared it. */
224
+ if (sawLine || property == "text-decoration-line") style->text_decoration_line = line;
225
+ return true;
226
+ }
227
+ if (property == "text-decoration-style") {
228
+ parseDecorationStyle(lowerTrim(value), &style->text_decoration_style);
229
+ return true;
230
+ }
231
+ if (property == "text-decoration-color") {
232
+ Color color = xt_css_parse_color(value);
233
+ if (color.valid) {
234
+ style->text_decoration_color = color;
235
+ style->has_text_decoration_color = true;
236
+ }
237
+ return true;
238
+ }
239
+ if (property == "text-decoration-thickness" || property == "text-underline-offset" ||
240
+ property == "text-decoration-skip-ink") {
241
+ /* Accepted: the painter uses a fixed one-pixel rule and does not skip
242
+ * descenders yet. */
243
+ return true;
244
+ }
245
+ if (property == "overflow-wrap" || property == "word-wrap") {
246
+ parseOverflowWrap(lowerTrim(value), &style->overflow_wrap);
247
+ return true;
248
+ }
170
249
  if (property == "text-overflow") {
171
250
  /* `clip | ellipsis` (the two-value `start end` form collapses to one
172
251
  * behaviour here). A custom string is accepted as `clip`, which is still
@@ -140,6 +140,14 @@ std::string rewrite_glsl(const std::string &source, bool fragment, const GlslLin
140
140
  bool compile_glsl(const std::string &source, bool fragment, std::vector<uint32_t> *spirv,
141
141
  std::string *log);
142
142
 
143
+ /**
144
+ * The same compiler for an explicit stage: 0 = vertex, 1 = fragment,
145
+ * 2 = compute. WebGL always passes vertex/fragment; WebGPU compute pipelines
146
+ * need the third.
147
+ */
148
+ bool compile_glsl_stage(const std::string &source, int stage, std::vector<uint32_t> *spirv,
149
+ std::string *log);
150
+
143
151
  /** One std140 block member, reflected from SPIR-V. */
144
152
  struct GlslBlockMember {
145
153
  std::string name;
@@ -340,18 +340,19 @@ void reflect_struct_members(const Module &module, uint32_t struct_id, int base,
340
340
 
341
341
  } // namespace
342
342
 
343
- bool compile_glsl(const std::string &source, bool fragment, std::vector<uint32_t> *spirv,
344
- std::string *log) {
343
+ bool compile_glsl_stage(const std::string &source, int stage_index, std::vector<uint32_t> *spirv,
344
+ std::string *log) {
345
345
  static const bool initialized = glslang::InitializeProcess();
346
346
  if (!initialized) {
347
347
  *log = "glslang initialization failed";
348
348
  return false;
349
349
  }
350
- const EShLanguage stage = fragment ? EShLangFragment : EShLangVertex;
350
+ EShLanguage stage = EShLangVertex;
351
+ if (stage_index == 1) stage = EShLangFragment;
352
+ else if (stage_index == 2) stage = EShLangCompute;
351
353
  glslang::TShader shader(stage);
352
354
  if (getenv("XT_WEBGL_DUMP_GLSL") != nullptr) {
353
- fprintf(stderr, "--- GLSL %s ---\n%s\n---\n", fragment ? "fragment" : "vertex",
354
- source.c_str());
355
+ fprintf(stderr, "--- GLSL stage %d ---\n%s\n---\n", stage_index, source.c_str());
355
356
  }
356
357
  const char *text = source.c_str();
357
358
  shader.setStrings(&text, 1);
@@ -376,6 +377,11 @@ bool compile_glsl(const std::string &source, bool fragment, std::vector<uint32_t
376
377
  return !spirv->empty();
377
378
  }
378
379
 
380
+ bool compile_glsl(const std::string &source, bool fragment, std::vector<uint32_t> *spirv,
381
+ std::string *log) {
382
+ return compile_glsl_stage(source, fragment ? 1 : 0, spirv, log);
383
+ }
384
+
379
385
  bool reflect_uniform_block(const std::vector<uint32_t> &spirv, std::vector<GlslBlockMember> *out) {
380
386
  out->clear();
381
387
  Module module;