xbintsc 0.6.9 → 0.6.12

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 (164) hide show
  1. package/dist/src/checker/globals.js +2 -1
  2. package/dist/src/checker/globals.js.map +1 -1
  3. package/dist/src/cli/help.d.ts +1 -1
  4. package/dist/src/cli/main.js +1 -0
  5. package/dist/src/cli/main.js.map +1 -1
  6. package/dist/src/codegen/generator/state.js +3 -0
  7. package/dist/src/codegen/generator/state.js.map +1 -1
  8. package/dist/src/codegen/generator/tables.js +3 -0
  9. package/dist/src/codegen/generator/tables.js.map +1 -1
  10. package/dist/src/driver/compiler.js +1 -1
  11. package/dist/src/driver/compiler.js.map +1 -1
  12. package/dist/src/driver/config.js +1 -0
  13. package/dist/src/driver/config.js.map +1 -1
  14. package/dist/src/driver/runtime-objects.d.ts +1 -1
  15. package/dist/src/driver/runtime-objects.js +2 -0
  16. package/dist/src/driver/runtime-objects.js.map +1 -1
  17. package/dist/src/driver/version.d.ts +1 -1
  18. package/dist/src/driver/version.js +1 -1
  19. package/dist/src/driver/version.js.map +1 -1
  20. package/dist/src/extensions/node/crypto/index.js +12 -1
  21. package/dist/src/extensions/node/crypto/index.js.map +1 -1
  22. package/dist/tests/driver/config.test.js +15 -2
  23. package/dist/tests/driver/config.test.js.map +1 -1
  24. package/dist/tests/e2e/compile-builtins.test.js +26 -0
  25. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  26. package/dist/tests/e2e/compile-node.test.js +37 -1
  27. package/dist/tests/e2e/compile-node.test.js.map +1 -1
  28. package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
  29. package/dist/tests/e2e/crypto-random.test.js +63 -0
  30. package/dist/tests/e2e/crypto-random.test.js.map +1 -0
  31. package/dist/tests/e2e/date-parse.test.js +27 -1
  32. package/dist/tests/e2e/date-parse.test.js.map +1 -1
  33. package/dist/tests/e2e/gui-css-coverage.test.js +1 -1
  34. package/dist/tests/e2e/gui-dom.test.js +29 -0
  35. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  36. package/dist/tests/e2e/gui-form.test.d.ts +9 -0
  37. package/dist/tests/e2e/gui-form.test.js +359 -0
  38. package/dist/tests/e2e/gui-form.test.js.map +1 -0
  39. package/dist/tests/e2e/gui-helpers.d.ts +2 -0
  40. package/dist/tests/e2e/gui-helpers.js +1 -0
  41. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  42. package/dist/tests/e2e/gui-layout.test.js +47 -0
  43. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  44. package/dist/tests/e2e/gui-paint.test.js +108 -0
  45. package/dist/tests/e2e/gui-paint.test.js.map +1 -1
  46. package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
  47. package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
  48. package/dist/tests/e2e/gui-style.test.js +82 -0
  49. package/dist/tests/e2e/gui-style.test.js.map +1 -1
  50. package/dist/tests/e2e/gui-unsupported.test.d.ts +6 -0
  51. package/dist/tests/e2e/gui-unsupported.test.js +124 -0
  52. package/dist/tests/e2e/gui-unsupported.test.js.map +1 -0
  53. package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
  54. package/dist/tests/e2e/json-parse-errors.test.js +48 -0
  55. package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
  56. package/doc/ai/extensions.md +7 -4
  57. package/doc/ai/language-support.md +2 -1
  58. package/doc/ai/zh-CN/extensions.md +6 -3
  59. package/doc/ai/zh-CN/language-support.md +2 -1
  60. package/doc/gui/api.md +8 -2
  61. package/doc/gui/dom.md +81 -4
  62. package/doc/gui/input.md +74 -3
  63. package/doc/gui/known-issues.md +12 -5
  64. package/doc/gui/layout.md +19 -6
  65. package/doc/gui/rendering.md +16 -9
  66. package/doc/implemented/node/crypto.md +8 -0
  67. package/doc/implemented/node/fs.md +1 -1
  68. package/doc/implemented/stdlib.md +10 -2
  69. package/doc/zh-CN/gui/api.md +8 -2
  70. package/doc/zh-CN/gui/dom.md +70 -4
  71. package/doc/zh-CN/gui/input.md +65 -4
  72. package/doc/zh-CN/gui/known-issues.md +11 -4
  73. package/doc/zh-CN/gui/layout.md +14 -4
  74. package/doc/zh-CN/gui/rendering.md +13 -10
  75. package/doc/zh-CN/implemented/node/crypto.md +6 -0
  76. package/doc/zh-CN/implemented/node/fs.md +1 -1
  77. package/doc/zh-CN/implemented/stdlib.md +10 -2
  78. package/package.json +7 -7
  79. package/runtime/ext_gui/clip_values.cpp +11 -0
  80. package/runtime/ext_gui/css.cpp +27 -2
  81. package/runtime/ext_gui/css_match.cpp +21 -1
  82. package/runtime/ext_gui/css_selector.cpp +23 -0
  83. package/runtime/ext_gui/css_sheet.cpp +7 -0
  84. package/runtime/ext_gui/document.cpp +15 -0
  85. package/runtime/ext_gui/document_animation.cpp +4 -1
  86. package/runtime/ext_gui/dom.h +41 -2
  87. package/runtime/ext_gui/dom_api.cpp +3 -0
  88. package/runtime/ext_gui/dom_api_document.cpp +28 -0
  89. package/runtime/ext_gui/dom_api_events.cpp +17 -14
  90. package/runtime/ext_gui/dom_api_form.cpp +567 -0
  91. package/runtime/ext_gui/dom_api_internal.h +46 -214
  92. package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
  93. package/runtime/ext_gui/dom_api_node.cpp +10 -3
  94. package/runtime/ext_gui/dom_api_node_read.cpp +1 -1
  95. package/runtime/ext_gui/dom_api_proto.cpp +45 -0
  96. package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
  97. package/runtime/ext_gui/dom_parse.cpp +118 -1
  98. package/runtime/ext_gui/effect_values.cpp +28 -7
  99. package/runtime/ext_gui/form_focus.cpp +293 -0
  100. package/runtime/ext_gui/form_input.cpp +448 -0
  101. package/runtime/ext_gui/form_internal.h +30 -0
  102. package/runtime/ext_gui/form_shared.cpp +126 -0
  103. package/runtime/ext_gui/form_state.cpp +536 -0
  104. package/runtime/ext_gui/form_state.h +97 -0
  105. package/runtime/ext_gui/gradient_values.cpp +25 -5
  106. package/runtime/ext_gui/gui_engine.h +40 -4
  107. package/runtime/ext_gui/gui_events.cpp +63 -48
  108. package/runtime/ext_gui/inline_svg.cpp +3 -0
  109. package/runtime/ext_gui/layout.cpp +6 -0
  110. package/runtime/ext_gui/layout.h +4 -0
  111. package/runtime/ext_gui/layout_flow.cpp +35 -3
  112. package/runtime/ext_gui/layout_inline.cpp +80 -7
  113. package/runtime/ext_gui/media_query.cpp +7 -1
  114. package/runtime/ext_gui/paint.cpp +62 -24
  115. package/runtime/ext_gui/paint.h +7 -4
  116. package/runtime/ext_gui/paint_clip.cpp +74 -19
  117. package/runtime/ext_gui/paint_form.cpp +389 -0
  118. package/runtime/ext_gui/paint_internal.h +13 -1
  119. package/runtime/ext_gui/renderer_clip.cpp +19 -17
  120. package/runtime/ext_gui/style.cpp +5 -1
  121. package/runtime/ext_gui/style.h +5 -0
  122. package/runtime/ext_gui/style_cascade.cpp +2 -0
  123. package/runtime/ext_gui/style_internal.h +7 -2
  124. package/runtime/ext_gui/style_print.cpp +33 -0
  125. package/runtime/ext_gui/style_text.cpp +11 -0
  126. package/runtime/ext_gui/style_ua.cpp +42 -0
  127. package/runtime/ext_gui/style_values.cpp +89 -90
  128. package/runtime/ext_gui/transform.cpp +2 -0
  129. package/runtime/ext_gui/warnings.cpp +298 -0
  130. package/runtime/ext_gui/warnings.h +59 -0
  131. package/runtime/ext_gui/window.cpp +31 -55
  132. package/runtime/ext_gui/window_diagnostics.cpp +58 -0
  133. package/runtime/ext_gui/window_emit.cpp +51 -0
  134. package/runtime/ext_node/crypto/crypto.c +3 -2
  135. package/runtime/ext_node/crypto/crypto_hash.h +13 -0
  136. package/runtime/ext_node/crypto/crypto_random.c +339 -0
  137. package/runtime/ext_node/fs/async_worker.c +1 -1
  138. package/runtime/ext_node/fs/fs_ops.c +1 -1
  139. package/runtime/ext_node/fs/parts/platform.inc +65 -0
  140. package/runtime/rt.h +27 -0
  141. package/runtime/xt_crypto.c +132 -0
  142. package/runtime/xt_random.c +143 -0
  143. package/runtime/xt_regex/matcher.inc +9 -28
  144. package/runtime/xt_regex/parser.inc +65 -2
  145. package/runtime/xt_regex/types.inc +11 -1
  146. package/runtime/xt_regex.h +6 -2
  147. package/runtime/xt_stdlib/dispatch.inc +2 -0
  148. package/runtime/xt_stdlib/math.inc +1 -1
  149. package/runtime/xt_stdlib2/date.inc +204 -4
  150. package/runtime/xt_stdlib2/json.inc +4 -546
  151. package/runtime/xt_stdlib2/json_parse.inc +347 -0
  152. package/runtime/xt_stdlib2/json_stringify.inc +368 -0
  153. package/runtime/xt_stdlib2/regexp-match.inc +6 -11
  154. package/runtime/xt_stdlib2.c +0 -4
  155. package/runtime/xt_typed_array/elements.inc +6 -1
  156. package/src/checker/globals.ts +2 -0
  157. package/src/cli/main.ts +1 -0
  158. package/src/codegen/generator/state.ts +3 -0
  159. package/src/codegen/generator/tables.ts +3 -0
  160. package/src/driver/compiler.ts +1 -1
  161. package/src/driver/config.ts +1 -0
  162. package/src/driver/runtime-objects.ts +2 -0
  163. package/src/driver/version.ts +1 -1
  164. package/src/extensions/node/crypto/index.ts +12 -1
@@ -10,10 +10,11 @@
10
10
  `DisplayList`:一个按画家顺序排列的 `ops` 列表,包含**矩形**(背景与四条实心
11
11
  边框,带 `border-radius`)、**文本 run**(每个携带其文本、颜色与已解析的
12
12
  `FontSpec`)与**图像**,背后由并列的负载数组支撑。每个 op 还携带当前生效的裁剪
13
- 矩形(最近的 `overflow: hidden` 祖先的 padding box)以及最多两个指向显示列表
14
- 三角化 `clip-path` 多边形的下标,因此 `overflow`/`clip-path` 裁剪与 `z-index`
15
- 顺序都能保留到渲染器。`DisplayList::dump()` 为 `paintList()`/`paintCount()`
16
- 提供数据。
13
+ 矩形(最近的 `overflow: hidden` 祖先的 padding box)以及最多四个指向显示列表
14
+ 裁剪多边形的下标——CSS `clip-path` 形状,加上带 `border-radius` 的 `overflow`
15
+ 祖先的圆角 padding box——因此 `overflow`/`clip-path` 裁剪与 `z-index`
16
+ 顺序都能保留到渲染器,圆形头像框也真的是圆的。`DisplayList::dump()` 为
17
+ `paintList()`/`paintCount()` 提供数据。
17
18
 
18
19
  `opacity` 会乘到该盒子及其后代绘制的每个颜色 alpha 上(沿绘制链逐层相乘),
19
20
  因此小数 opacity 以及 CSS 解析器接受的 `opacity` 过渡都能看到效果。这是按图形
@@ -24,7 +25,8 @@
24
25
  `runtime/ext_gui/renderer.{h,cpp}` 把该列表转换为每个窗口的批处理顶点缓冲
25
26
  (图形、字形四边形与图像),并把管线、裁剪与纹理都相同的连续 op 合并为
26
27
  **绘制 run**。每个 run 用各自的 GPU scissor 矩形(按设备像素缩放)绘制,因此
27
- 画家顺序与 `overflow` 裁剪按 op 生效,并通过 SDL_GPU 图形管线完成:
28
+ 画家顺序与 `overflow` 裁剪按 op 生效,并通过 SDL_GPU 图形管线完成;scissor 只是
29
+ 包围矩形,圆角 `overflow` 裁剪与 `clip-path` 形状会切进下面描述的顶点几何:
28
30
 
29
31
  - 共享管线会依据设备支持的着色器格式延迟创建。SDL_GPU 的三个后端各自只接受一种
30
32
  二进制格式,且都不会在运行时编译 GLSL/HLSL,因此引擎三种都随包提供,由
@@ -122,11 +124,12 @@ rgba(…) calc(100% - 1px)` 这样的 1px 分割线要么落在两次采样之
122
124
  显示为 `backdrop …` op。
123
125
 
124
126
  **`clip-path`** 在 `paint_clip.cpp` 中解析为设备空间多边形(每个点都应用盒子的
125
- transform),用耳切法三角化,并存入 `DisplayList::clip_paths`。每个 op 的
126
- `PaintClip` 最多携带两个路径下标;`renderer_clip.cpp` 在上传时把每个凸的图形/
127
- 字形/图像四边形与这些三角形求交。即使 `polygon()` 是凹多边形也正确,无需模板或
128
- shader 改动,但边缘是硬边(没有解析抗锯齿)。支持两层嵌套路径求交;更深时保留
129
- 最外两层。
127
+ transform),用耳切法三角化,并存入 `DisplayList::clip_paths`。圆角 `overflow`
128
+ 裁剪使用同一表示:每个角用短弦近似,因此多边形是凸的,scissor 矩形只是它的
129
+ 包围盒。每个 op 的 `PaintClip` 最多携带四个路径下标;`renderer_clip.cpp` 在上传
130
+ 时把每个凸的图形/字形/图像四边形与这些三角形求交(先按一条路径裁剪,再把得到的
131
+ 每块交给下一条)。即使 `polygon()` 是凹多边形也正确,无需模板或 shader 改动,
132
+ 但边缘是硬边(没有解析抗锯齿)。嵌套超过四层时保留最外四层。
130
133
 
131
134
  **`filter`** 的颜色函数(`brightness`、`contrast`、`grayscale`、`sepia`、
132
135
  `invert`、`saturate`、`hue-rotate`、`opacity`)会折进每个绘制颜色,因此盒子与
@@ -7,3 +7,9 @@
7
7
  - `createHash(algorithm)` 返回带 `update(...)` 与 `digest([encoding])` 的哈希对象。
8
8
  - 支持流式形式(`setEncoding` / `write` / `end` / `read`)。
9
9
  - 提供 SHA-1 与 SHA-256。
10
+ - `randomBytes(size[, callback])`、`randomUUID()`、`randomInt([min, ]max[, callback])`、
11
+ `randomFillSync(buffer[, offset[, size]])` 与 `randomFill(...)` 读取操作系统
12
+ CSPRNG(Windows 上的 `BCryptGenRandom`,其它平台的 `/dev/urandom`)。
13
+ `webcrypto` 暴露与全局 `crypto` 相同的 `getRandomValues` / `randomUUID` 对象。
14
+ - `pbkdf2Sync(password, salt, iterations, keylen[, digest])` 与 `pbkdf2(...)`
15
+ 实现 PBKDF2-HMAC-SHA1/SHA-256(异步形式会立即调用回调,计算本身是同步的)。
@@ -18,7 +18,7 @@
18
18
  | `rmSync(path[, options])` | `xt_node_rm` | 删除文件/目录,`{ recursive: true }` 递归删除 |
19
19
  | `unlinkSync(path)` | `xt_node_unlink` | 删除文件 |
20
20
  | `rmdirSync(path)` | `xt_node_rmdir` | 删除空目录 |
21
- | `renameSync(oldPath, newPath)` | `xt_node_rename` | 重命名 / 移动 |
21
+ | `renameSync(oldPath, newPath)` | `xt_node_rename` | 重命名 / 移动;原子替换已存在的目标(Windows 使用 `MoveFileExW` + `MOVEFILE_REPLACE_EXISTING`) |
22
22
  | `copyFileSync(src, dest[, flags])` | `xt_node_copy_file` | 复制文件;支持 `COPYFILE_EXCL` |
23
23
  | `cpSync(src, dest[, options])` | `xt_node_cp` | 递归复制;`recursive` / `force` / `errorOnExist` / `dereference` / `preserveTimestamps` |
24
24
  | `realpathSync(path)` | `xt_node_realpath` | 解析为绝对路径 |
@@ -35,17 +35,19 @@
35
35
 
36
36
  ## JSON
37
37
 
38
- - `JSON.parse` 支持 `reviver`。
38
+ - `JSON.parse` 支持 `reviver`;畸形输入(错误数字/字符串、尾随内容、缺少分隔符)会抛出可捕获的 `SyntaxError`,而不是返回 `undefined`。
39
39
  - `JSON.stringify` 支持函数或数组 `replacer`、`toJSON`,以及 `space`(数字或字符串,最多 10 个单位)。`undefined` / 函数 / symbol 值遵循标准省略规则。
40
40
  - 对象键按插入序输出,整数键按数值排序;循环引用抛错。
41
41
 
42
42
  ## Date
43
43
 
44
44
  - `Date` 基于 `gmtime_r`;`Date.parse` / `new Date(string)` 支持 ISO 8601 解析。
45
+ - `toLocaleDateString` / `toLocaleTimeString` / `toLocaleString` 按本地时间格式化(`M/D/YYYY`、`h:mm:ss AM`);支持少量 options(`weekday`/`year`/`month`/`day`/`hour`/`minute`/`second`/`hour12`)。另有 `toDateString` / `toTimeString` / `toUTCString`;无效日期格式化为 `Invalid Date`。
45
46
 
46
47
  ## RegExp
47
48
 
48
- - `RegExp` 使用 POSIX ERE(`regcomp` / `regexec`)实现 `test` / `exec`;捕获组可经 `exec` / `match` / `replace` / `split` / `search` 使用。
49
+ - `RegExp` 在所有宿主上都使用运行时自带的 POSIX ERE 兼容匹配器(`regcomp` / `regexec` 风格),因此结果不依赖平台 libc。捕获组可经 `exec` / `match` / `replace` / `split` / `search` 使用。
50
+ - 量词支持 `*`、`+`、`?` 以及计数形式 `{n}`、`{n,}`、`{n,m}`(可带惰性 `?` 后缀)。`{x}`、`{,2}` 这类畸形花括号组保持字面量,与 JavaScript 一致;`{2,1}` 这类倒置范围同样按字面量处理,而不是报错。
49
51
  - 匹配按字节进行,且 `/g` / `/y` 的 `lastIndex` 不被读取 —— 见[运行时偏差](../unimplemented/deviations.md)。
50
52
 
51
53
  ## Symbol
@@ -90,3 +92,9 @@
90
92
  - `btoa` / `atob` base64 编解码(核心全局函数,并非 Node 扩展专属)。
91
93
  - `structuredClone`:数组、对象、`Map`、`Set`、`Date`、`RegExp` 与类型化数组,保留循环引用与共享引用;函数、symbol、Promise、生成器会被拒绝。
92
94
  - 定时器、`queueMicrotask` 与 `performance.now` 见[异步、Promise 与生成器](./async.md);`fetch` 见 [fetch](./fetch.md)。
95
+
96
+ ## 全局 crypto
97
+
98
+ - `crypto.getRandomValues(typedArray)` 从操作系统 CSPRNG 填充整数类型化数组(最多 65 536 字节)并返回;`crypto.randomUUID()` 返回 v4 UUID 字符串。`crypto` 也是一等对象,方法可脱离对象使用(`const uuid = crypto.randomUUID`)。
99
+ - `Math.random` 使用由操作系统 CSPRNG 播种的 xoshiro256** 流(53 位随机性),不再使用 C `rand()`。
100
+ - Node 的 `crypto.randomBytes` / `randomInt` / `randomFillSync` / `pbkdf2Sync` 见 [node/crypto](../implemented/node/crypto.md)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xbintsc",
3
- "version": "0.6.9",
3
+ "version": "0.6.12",
4
4
  "description": "xbintsc - a TypeScript binary compiler (TypeScript -> LLVM IR -> native binary)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -72,12 +72,12 @@
72
72
  "vitest": "^2.1.8"
73
73
  },
74
74
  "optionalDependencies": {
75
- "@xbintsc/linux-x64": "0.6.9",
76
- "@xbintsc/linux-arm64": "0.6.9",
77
- "@xbintsc/darwin-x64": "0.6.9",
78
- "@xbintsc/darwin-arm64": "0.6.9",
79
- "@xbintsc/win32-x64": "0.6.9",
80
- "@xbintsc/win32-arm64": "0.6.9"
75
+ "@xbintsc/linux-x64": "0.6.12",
76
+ "@xbintsc/linux-arm64": "0.6.12",
77
+ "@xbintsc/darwin-x64": "0.6.12",
78
+ "@xbintsc/darwin-arm64": "0.6.12",
79
+ "@xbintsc/win32-x64": "0.6.12",
80
+ "@xbintsc/win32-arm64": "0.6.12"
81
81
  },
82
82
  "engines": {
83
83
  "node": ">=22"
@@ -13,6 +13,7 @@
13
13
  #include "css_internal.h"
14
14
  #include "style_internal.h"
15
15
  #include "style_values_internal.h"
16
+ #include "warnings.h"
16
17
 
17
18
  namespace xtgui {
18
19
 
@@ -219,6 +220,10 @@ bool xt_style_apply_clip_path(XtStyle *style, const std::string &property,
219
220
  return true;
220
221
  }
221
222
  if (text.size() < 8 || text.back() != ')') {
223
+ const size_t open = lower.find('(');
224
+ if (open != std::string::npos) {
225
+ xt_warn_unsupported_function("clip-path", xt_css_trim(lower.substr(0, open)));
226
+ }
222
227
  style->clip_path = spec;
223
228
  return true;
224
229
  }
@@ -239,6 +244,12 @@ bool xt_style_apply_clip_path(XtStyle *style, const std::string &property,
239
244
  return true;
240
245
  }
241
246
  /* `url(#…)`, `path()` and other shapes are not part of the subset. */
247
+ {
248
+ const size_t open = lower.find('(');
249
+ if (open != std::string::npos) {
250
+ xt_warn_unsupported_function("clip-path", xt_css_trim(lower.substr(0, open)));
251
+ }
252
+ }
242
253
  style->clip_path = spec;
243
254
  return true;
244
255
  }
@@ -6,10 +6,13 @@
6
6
 
7
7
  #include "css_internal.h"
8
8
 
9
+ #include "warnings.h"
10
+
9
11
  #include <cmath>
10
12
  #include <cstdlib>
11
13
  #include <cstring>
12
14
  #include <unordered_map>
15
+ #include <unordered_set>
13
16
 
14
17
  namespace xtgui {
15
18
 
@@ -131,7 +134,10 @@ static Length makeScalarLength(double number, const std::string &rawUnit) {
131
134
  else if (unit == "cm") { length.value = (float)number * (96.0f / 2.54f); length.unit = Unit::Px; }
132
135
  else if (unit == "mm") { length.value = (float)number * (96.0f / 25.4f); length.unit = Unit::Px; }
133
136
  else if (unit == "q") { length.value = (float)number * (96.0f / 101.6f); length.unit = Unit::Px; }
134
- else length.unit = Unit::Invalid;
137
+ else {
138
+ length.unit = Unit::Invalid;
139
+ if (!unit.empty()) xt_warn_unsupported_unit(unit);
140
+ }
135
141
  return length;
136
142
  }
137
143
 
@@ -404,7 +410,10 @@ bool parseFunctionColor(const std::string &text, Color *color) {
404
410
  for (size_t i = 0; i < parts.size() && i < 4; i++) {
405
411
  const std::string &part = parts[i];
406
412
  if (i < 3) {
407
- if (name == "hsl" || name == "hsla") return false; // hsl not supported yet
413
+ if (name == "hsl" || name == "hsla") {
414
+ xt_warn_unsupported_function("color", name);
415
+ return false;
416
+ }
408
417
  if (!part.empty() && part.back() == '%') {
409
418
  values[i] = strtof(part.c_str(), nullptr) / 100.0f;
410
419
  } else {
@@ -447,6 +456,14 @@ const std::unordered_map<std::string, unsigned int> &namedColors() {
447
456
 
448
457
  } // namespace
449
458
 
459
+ /** CSS Color 4 functions the engine does not implement (beyond hsl). */
460
+ static bool isUnsupportedColorFunction(const std::string &name) {
461
+ static const std::unordered_set<std::string> names = {
462
+ "color", "color-mix", "hwb", "lab", "lch", "light-dark", "oklab", "oklch",
463
+ };
464
+ return names.count(name) != 0;
465
+ }
466
+
450
467
  Color xt_css_parse_color(const std::string &value) {
451
468
  Color color;
452
469
  std::string text = xt_css_lower(xt_css_trim(value));
@@ -460,6 +477,14 @@ Color xt_css_parse_color(const std::string &value) {
460
477
  parseFunctionColor(text, &color);
461
478
  return color;
462
479
  }
480
+ const size_t open = text.find('(');
481
+ if (open != std::string::npos) {
482
+ const std::string name = xt_css_trim(text.substr(0, open));
483
+ if (isUnsupportedColorFunction(name)) {
484
+ xt_warn_unsupported_function("color", name);
485
+ return color;
486
+ }
487
+ }
463
488
  auto it = namedColors().find(text);
464
489
  if (it != namedColors().end()) {
465
490
  unsigned int rgba = it->second;
@@ -7,6 +7,8 @@
7
7
  #include <cstdlib>
8
8
  #include <memory>
9
9
 
10
+ #include "form_state.h"
11
+
10
12
  namespace xtgui {
11
13
 
12
14
  namespace {
@@ -96,6 +98,9 @@ bool matchPseudo(const Node *node, const std::string &pseudo, const MatchState &
96
98
  /* The engine has no keyboard modality tracking, so focus-visible is the same
97
99
  * as focus (a mouse click also shows the focus ring). */
98
100
  if (pseudo == "focus-visible") return node == state.focus;
101
+ /* `:focus-within` matches the focused element and every ancestor, which is
102
+ * what lets a form card highlight while one of its fields has focus. */
103
+ if (pseudo == "focus-within") return isHoverTarget(node, state.focus);
99
104
  if (pseudo == "active") return isHoverTarget(node, state.active);
100
105
  if (pseudo == "empty") {
101
106
  for (const std::unique_ptr<Node> &child : node->children) {
@@ -105,7 +110,22 @@ bool matchPseudo(const Node *node, const std::string &pseudo, const MatchState &
105
110
  return true;
106
111
  }
107
112
  if (pseudo == "disabled") return node->attr("disabled") != nullptr;
108
- if (pseudo == "checked") return node->attr("checked") != nullptr;
113
+ if (pseudo == "checked") {
114
+ /* The live state, not the default `checked` attribute: a checkbox toggled
115
+ * by a click must match `:checked` immediately. */
116
+ if (node->isTag("input") && (xt_form_type(node) == "checkbox" ||
117
+ xt_form_type(node) == "radio")) {
118
+ return xt_form_checked(node);
119
+ }
120
+ if (node->isTag("option")) {
121
+ const Node *select = node->parent;
122
+ while (select != nullptr && !(select->isElement() && select->isTag("select"))) {
123
+ select = select->parent;
124
+ }
125
+ if (select != nullptr) return xt_form_selected_option(select) == node;
126
+ }
127
+ return node->attr("checked") != nullptr;
128
+ }
109
129
  if (pseudo.rfind("nth-child(", 0) == 0) {
110
130
  return matchesNth(node->elementIndex() + 1, pseudo.substr(10, pseudo.size() - 11));
111
131
  }
@@ -4,10 +4,27 @@
4
4
 
5
5
  #include "css_internal.h"
6
6
 
7
+ #include "warnings.h"
8
+
9
+ #include <string>
10
+ #include <unordered_set>
11
+
7
12
  namespace xtgui {
8
13
 
9
14
  namespace {
10
15
 
16
+ /** Pseudo-classes `css_match.cpp` can evaluate. `:not(...)` and
17
+ * `:nth-child(...)` are stored with their argument text, so the base name is
18
+ * what this set holds. */
19
+ const std::unordered_set<std::string> &supportedPseudoClasses() {
20
+ static const std::unordered_set<std::string> names = {
21
+ "active", "checked", "disabled", "empty", "first-child", "focus",
22
+ "focus-visible", "focus-within", "hover", "last-child", "not",
23
+ "nth-child", "only-child", "root",
24
+ };
25
+ return names;
26
+ }
27
+
11
28
  class SelectorParser {
12
29
  public:
13
30
  explicit SelectorParser(const std::string &text) : text_(text) {}
@@ -43,6 +60,9 @@ class SelectorParser {
43
60
  ComplexSelector selector;
44
61
  if (parseComplex(part, &selector) && !selector.compounds.empty()) {
45
62
  selectors.push_back(std::move(selector));
63
+ } else {
64
+ const std::string trimmed = xt_css_trim(part);
65
+ if (!trimmed.empty()) xt_warn_unsupported_selector(trimmed);
46
66
  }
47
67
  start = i + 1;
48
68
  }
@@ -93,10 +113,12 @@ class SelectorParser {
93
113
  /* `::before`/`::after` are generated-content elements, not states. The
94
114
  * single-colon spellings (`:before`) are the legacy equivalent. */
95
115
  if (pseudoElement || name == "before" || name == "after") {
116
+ if (name != "before" && name != "after") xt_warn_unsupported_pseudo_element(name);
96
117
  compound->pseudo_element = name;
97
118
  any = true;
98
119
  continue;
99
120
  }
121
+ const std::string base = name;
100
122
  if (!pseudoElement && *index < text.size() && text[*index] == '(') {
101
123
  int depth = 0;
102
124
  size_t start = *index;
@@ -113,6 +135,7 @@ class SelectorParser {
113
135
  }
114
136
  name += text.substr(start, *index - start);
115
137
  }
138
+ if (supportedPseudoClasses().count(base) == 0) xt_warn_unsupported_pseudo_class(base);
116
139
  compound->pseudoClasses.push_back(name);
117
140
  any = true;
118
141
  } else if (xt_css_is_ident_start(c)) {
@@ -8,6 +8,8 @@
8
8
 
9
9
  #include "css_internal.h"
10
10
 
11
+ #include "warnings.h"
12
+
11
13
  #include <algorithm>
12
14
  #include <cctype>
13
15
  #include <cstring>
@@ -287,6 +289,8 @@ void parseFontFaceBlock(const std::string &block, StyleSheet *sheet) {
287
289
  rule.has_italic = true;
288
290
  rule.italic = true;
289
291
  }
292
+ } else {
293
+ xt_warn_unsupported_descriptor(declaration.property);
290
294
  }
291
295
  }
292
296
  if (rule.family.empty() || rule.sources.empty()) return;
@@ -308,6 +312,9 @@ void parseRules(const std::string &text, const std::string &media, int *order,
308
312
  (std::isalnum((unsigned char)text[nameEnd]) || text[nameEnd] == '-'))
309
313
  nameEnd++;
310
314
  std::string name = xt_css_lower(text.substr(nameStart, nameEnd - nameStart));
315
+ const bool supported = name == "media" || name == "font-face" ||
316
+ (name.size() >= 9 && name.compare(name.size() - 9, 9, "keyframes") == 0);
317
+ if (!supported) xt_warn_unsupported_at_rule(name);
311
318
  size_t brace = text.find('{', nameEnd);
312
319
  size_t semi = text.find(';', nameEnd);
313
320
  if (brace != std::string::npos && (semi == std::string::npos || brace < semi)) {
@@ -4,6 +4,9 @@
4
4
 
5
5
  #include "document.h"
6
6
 
7
+ #include "form_state.h"
8
+ #include "warnings.h"
9
+
7
10
  #include <cmath>
8
11
  #include <string>
9
12
  #include <utility>
@@ -71,10 +74,21 @@ void XtDocument::load(const std::string &html, float viewportWidth, float viewpo
71
74
  restyle(viewportWidth, viewportHeight);
72
75
  }
73
76
 
77
+ namespace {
78
+ void initialiseFormControls(Node *node) {
79
+ if (node == nullptr) return;
80
+ if (node->isElement() && xt_form_is_control(node)) xt_form_init(node);
81
+ for (const std::unique_ptr<Node> &child : node->children) {
82
+ initialiseFormControls(child.get());
83
+ }
84
+ }
85
+ } // namespace
86
+
74
87
  void XtDocument::restyle(float viewportWidth, float viewportHeight) {
75
88
  viewportWidth_ = viewportWidth;
76
89
  viewportHeight_ = viewportHeight;
77
90
  g_perf_frame.restyles += 1;
91
+ if (root_ != nullptr) initialiseFormControls(root_.get());
78
92
  if (root_ != nullptr) {
79
93
  MatchState state;
80
94
  state.hover = hover_;
@@ -184,6 +198,7 @@ std::string XtDocument::toDebugString() const {
184
198
  /* -- DOM mutation --------------------------------------------------------- */
185
199
 
186
200
  Node *XtDocument::createElement(const std::string &tag) {
201
+ xt_warn_unsupported_element(tag);
187
202
  auto node = std::make_unique<Node>(NodeType::Element);
188
203
  node->tag = tag;
189
204
  Node *raw = node.get();
@@ -15,6 +15,7 @@
15
15
  #include <vector>
16
16
 
17
17
  #include "style_internal.h"
18
+ #include "warnings.h"
18
19
 
19
20
  namespace xtgui {
20
21
 
@@ -171,7 +172,9 @@ void applyKeyframeDeclarations(XtStyle *style, const std::vector<Declaration> &d
171
172
  declaration.property[1] == '-')
172
173
  continue;
173
174
  if (declaration.property.compare(0, 9, "animation") == 0) continue;
174
- xt_style_apply_declaration(style, declaration.property, declaration.value, context);
175
+ if (!xt_style_apply_declaration(style, declaration.property, declaration.value, context)) {
176
+ xt_warn_unsupported_property(declaration.property);
177
+ }
175
178
  }
176
179
  }
177
180
 
@@ -26,6 +26,40 @@ struct Attr {
26
26
  std::string value;
27
27
  };
28
28
 
29
+ /** Editable/checkable state of a form control (`<input>`, `<textarea>`,
30
+ * `<select>`). The browser keeps this in the element's internal value, separate
31
+ * from the `value`/`checked` *attributes*; the engine does the same so
32
+ * `<input value="a">` (the default) and `el.value = "b"` (the live value) do not
33
+ * overwrite each other. */
34
+ struct FormState {
35
+ std::string value;
36
+ bool initialized = false;
37
+ /** `checkbox`/`radio` state (the `checked` attribute is only the default). */
38
+ bool checked = false;
39
+ bool checked_initialized = false;
40
+ /** Selection in UTF-16 code units, like the DOM's `selectionStart`/`End`. */
41
+ int selection_start = 0;
42
+ int selection_end = 0;
43
+ /** 0 = none, 1 = forward, -1 = backward (`selectionDirection`). */
44
+ int selection_direction = 0;
45
+ bool focused = false;
46
+ /** Text value when focus arrived, so `change` fires only if it changed. */
47
+ std::string focus_value;
48
+ bool focus_value_valid = false;
49
+ /** IME composition: `composition` is displayed at the selection until the
50
+ * `compositionend` commit inserts it into `value`. */
51
+ bool composing = false;
52
+ std::string composition;
53
+ int composition_start = 0;
54
+ int composition_end = 0;
55
+ /** `<select>`: index of the selected `<option>`, or -1 when it has none. */
56
+ int selected_index = -1;
57
+ /** Range drag in progress (paint and pointer dispatch share it). */
58
+ bool dragging = false;
59
+ /** `<textarea>` first visible line (reserved; the engine paints from line 0). */
60
+ int scroll_top = 0;
61
+ };
62
+
29
63
  /** A DOM node. Element/text/document are one type to keep the tree simple. */
30
64
  struct Node {
31
65
  NodeType type = NodeType::Element;
@@ -38,6 +72,8 @@ struct Node {
38
72
  std::vector<Attr> attrs;
39
73
  Node *parent = nullptr;
40
74
  std::vector<std::unique_ptr<Node>> children;
75
+ /** Form-control state, allocated only for `<input>`/`<textarea>`/`<select>`. */
76
+ std::unique_ptr<FormState> form;
41
77
 
42
78
  /* -- generated content (`::before` / `::after`) -------------------------
43
79
  * A pseudo-element is a synthetic node owned by the document's per-restyle
@@ -83,8 +119,11 @@ struct Node {
83
119
  int elementSiblingCount() const;
84
120
  };
85
121
 
86
- /** Parse an HTML document/fragment. Returns a Document node (never NULL). */
87
- std::unique_ptr<Node> xt_html_parse(const std::string &html);
122
+ /** Parse an HTML document/fragment. Returns a Document node (never NULL).
123
+ * `synthesize_structure` wraps a fragment in the implicit `<html>`/`<head>`/
124
+ * `<body>`; `innerHTML`/`insertAdjacentHTML` pass false because their result is
125
+ * inserted under an existing element. */
126
+ std::unique_ptr<Node> xt_html_parse(const std::string &html, bool synthesize_structure = true);
88
127
 
89
128
  /** Serialize a subtree; used by diagnostics and tests. */
90
129
  std::string xt_dom_to_string(const Node *node);
@@ -21,6 +21,8 @@
21
21
 
22
22
  #include "dom_api_internal.h"
23
23
 
24
+ #include "warnings.h"
25
+
24
26
  #include <cctype>
25
27
  #include <string>
26
28
  #include <vector>
@@ -132,6 +134,7 @@ void remove_attribute_raw(xtgui::Node *node, const std::string &name) {
132
134
 
133
135
  void set_attribute(XtGuiWindow *win, xtgui::Node *node, const std::string &name,
134
136
  const std::string &value) {
137
+ if (node != nullptr) xtgui::xt_warn_unsupported_attribute(node->tag, name);
135
138
  set_attribute_raw(node, name, value);
136
139
  mark_dirty(win);
137
140
  }
@@ -226,6 +226,15 @@ METHOD(doc_body_get) {
226
226
  return xt_gui_node_handle(win, find_by_tag(win->document->root(), "body"));
227
227
  }
228
228
 
229
+ METHOD(doc_head_get) {
230
+ (void)env;
231
+ (void)argc;
232
+ (void)argv;
233
+ XtGuiWindow *win = resolve_window(self);
234
+ if (win == nullptr || win->document == nullptr) return XT_UNDEFINED;
235
+ return xt_gui_node_handle(win, find_by_tag(win->document->root(), "head"));
236
+ }
237
+
229
238
  METHOD(doc_document_element_get) {
230
239
  (void)env;
231
240
  (void)argc;
@@ -235,6 +244,25 @@ METHOD(doc_document_element_get) {
235
244
  return xt_gui_node_handle(win, find_by_tag(win->document->root(), "html"));
236
245
  }
237
246
 
247
+ /** `document.activeElement`: the focused element, or `<body>` when nothing is
248
+ * focused (a browser never answers "none" for a parsed document). A focus
249
+ * pointer left on a detached node falls back to the body too. */
250
+ METHOD(doc_active_element_get) {
251
+ (void)env;
252
+ (void)argc;
253
+ (void)argv;
254
+ XtGuiWindow *win = resolve_window(self);
255
+ if (win == nullptr || win->document == nullptr) return XT_NULL;
256
+ const xtgui::Node *root = win->document->root();
257
+ const xtgui::Node *focus = win->document->focus();
258
+ if (focus != nullptr && root != nullptr && root->contains(focus)) {
259
+ return xt_gui_node_handle(win, focus);
260
+ }
261
+ if (const xtgui::Node *body = find_by_tag(root, "body")) return xt_gui_node_handle(win, body);
262
+ if (const xtgui::Node *html = find_by_tag(root, "html")) return xt_gui_node_handle(win, html);
263
+ return XT_NULL;
264
+ }
265
+
238
266
  #undef METHOD
239
267
 
240
268
  } // namespace domapi
@@ -26,10 +26,11 @@ static xt_value make_dom_event(XtGuiWindow *win, const char *type, const xtgui::
26
26
  xt_object_set(event, xt_string_from_cstr("timeStamp"), xt_number((double)SDL_GetTicks()));
27
27
  if (XT_IS_OBJECT(legacy)) {
28
28
  static const char *const fields[] = {
29
- "x", "y", "clientX", "clientY", "button", "clicks",
30
- "deltaX", "deltaY", "key", "code", "repeat", "ctrl",
31
- "shift", "alt", "meta", "ctrlKey", "shiftKey", "altKey",
32
- "metaKey",
29
+ "x", "y", "clientX", "clientY", "button", "clicks",
30
+ "deltaX", "deltaY", "key", "code", "repeat", "ctrl",
31
+ "shift", "alt", "meta", "ctrlKey", "shiftKey", "altKey",
32
+ "metaKey", "data", "inputType", "isComposing", "value", "charCode",
33
+ "keyCode", "relatedTarget", "detail", "submitter",
33
34
  };
34
35
  for (const char *field : fields) {
35
36
  xt_value value = xt_object_get_cstr(legacy, field);
@@ -174,11 +175,11 @@ METHOD(event_composed_path) {
174
175
 
175
176
  } // namespace domapi
176
177
 
177
- void xt_gui_emit_dom_event(XtGuiWindow *win, const char *type, const xtgui::Node *target,
178
+ bool xt_gui_emit_dom_event(XtGuiWindow *win, const char *type, const xtgui::Node *target,
178
179
  xt_value legacy) {
179
180
  using namespace domapi;
180
- if (win == nullptr || win->document == nullptr || target == nullptr) return;
181
- if (win->node_listeners.empty()) return;
181
+ if (win == nullptr || win->document == nullptr || target == nullptr) return false;
182
+ if (win->node_listeners.empty()) return false;
182
183
  std::vector<xtgui::Node *> path;
183
184
  for (xtgui::Node *node = const_cast<xtgui::Node *>(target); node != nullptr; node = node->parent) {
184
185
  path.push_back(node);
@@ -196,25 +197,27 @@ void xt_gui_emit_dom_event(XtGuiWindow *win, const char *type, const xtgui::Node
196
197
  for (xtgui::Node *node : path) xt_array_push(handlePath, xt_gui_node_handle(win, node));
197
198
  xt_object_set(event, xt_string_from_cstr("__xt_gui_path"), handlePath);
198
199
  bool bubbles = value_truthy(xt_object_get_cstr(event, "bubbles"));
200
+ bool stopped = false;
199
201
  /* Capture phase: root -> target. */
200
- for (auto it = path.rbegin(); it != path.rend(); ++it) {
202
+ for (auto it = path.rbegin(); it != path.rend() && !stopped; ++it) {
201
203
  int32_t phase = *it == target ? 2 : 1;
202
- if (call_node_listeners(win, *it, type, event, true, phase)) return;
204
+ if (call_node_listeners(win, *it, type, event, true, phase)) stopped = true;
203
205
  }
204
206
  /* Bubble phase: target -> root; a non-bubbling event stops after the target
205
207
  * (its non-capture listeners still run there). */
206
- for (auto it = path.begin(); it != path.end(); ++it) {
208
+ for (auto it = path.begin(); it != path.end() && !stopped; ++it) {
207
209
  if (!bubbles && *it != target) break;
208
210
  int32_t phase = *it == target ? 2 : 3;
209
- if (call_node_listeners(win, *it, type, event, false, phase)) return;
211
+ if (call_node_listeners(win, *it, type, event, false, phase)) stopped = true;
210
212
  }
213
+ return value_truthy(xt_object_get_cstr(event, "defaultPrevented"));
211
214
  }
212
215
 
213
- void xt_gui_dispatch_to_node(XtGuiWindow *win, const xtgui::Node *target, const char *type) {
214
- if (win == nullptr || target == nullptr) return;
216
+ bool xt_gui_dispatch_to_node(XtGuiWindow *win, const xtgui::Node *target, const char *type) {
217
+ if (win == nullptr || target == nullptr) return false;
215
218
  xt_value legacy = xt_object_new();
216
219
  xt_object_set(legacy, xt_string_from_cstr("type"), xt_string_from_cstr(type));
217
220
  std::string describe = xtgui::xt_dom_describe(target);
218
221
  xt_object_set(legacy, xt_string_from_cstr("target"), xt_string_from_cstr(describe.c_str()));
219
- xt_gui_emit_dom_event(win, type, target, legacy);
222
+ return xt_gui_emit_dom_event(win, type, target, legacy);
220
223
  }