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
@@ -0,0 +1,298 @@
1
+ /*
2
+ * xbintsc GUI engine — implementation of the unsupported-feature diagnostics
3
+ * (see `warnings.h`).
4
+ */
5
+
6
+ #include "warnings.h"
7
+
8
+ #include <SDL3/SDL.h>
9
+
10
+ #include <cstdio>
11
+ #include <cstring>
12
+ #include <string>
13
+ #include <unordered_set>
14
+
15
+ namespace xtgui {
16
+
17
+ namespace {
18
+
19
+ struct SeenNames {
20
+ std::unordered_set<std::string> names;
21
+ };
22
+
23
+ /** Print one line per distinct name; repeated uses are dropped. */
24
+ bool firstUse(SeenNames *seen, const std::string &name) {
25
+ return seen->names.insert(name).second;
26
+ }
27
+
28
+ bool warningsSuppressed() {
29
+ static int suppressed = -1;
30
+ if (suppressed < 0) {
31
+ const char *value = SDL_getenv("XT_GUI_NO_WARNINGS");
32
+ suppressed = value != nullptr && value[0] != '\0' && std::strcmp(value, "0") != 0 ? 1 : 0;
33
+ }
34
+ return suppressed != 0;
35
+ }
36
+
37
+ /** The parser and `createElement` already lowercase the common case; only pay
38
+ * for a copy when the caller really passed mixed case. */
39
+ bool hasUpperAscii(const std::string &text) {
40
+ for (char c : text) {
41
+ if (c >= 'A' && c <= 'Z') return true;
42
+ }
43
+ return false;
44
+ }
45
+
46
+ std::string lowerAscii(const std::string &text) {
47
+ std::string out = text;
48
+ for (char &c : out) {
49
+ if (c >= 'A' && c <= 'Z') c = (char)(c - 'A' + 'a');
50
+ }
51
+ return out;
52
+ }
53
+
54
+ std::string truncated(const std::string &text, size_t limit) {
55
+ if (text.size() <= limit) return text;
56
+ return text.substr(0, limit) + "...";
57
+ }
58
+
59
+ /**
60
+ * HTML elements whose browser behaviour the engine does not implement.
61
+ *
62
+ * They still create a box (and their text descendants still render), but a page
63
+ * that relies on a table layout, a native form control, an embedded document or
64
+ * an interactive disclosure is not going to get it. Tags that render correctly
65
+ * as a generic inline/block box (`button`, `label`, custom elements, …) are
66
+ * intentionally absent, as are the tags the engine implements (`img`, `svg`,
67
+ * `canvas`, `video`, `audio`, …).
68
+ *
69
+ * Update this list when an element gains real support, and mirror the change in
70
+ * `doc/gui/dom.md` (and its Chinese translation).
71
+ */
72
+ const std::unordered_set<std::string> &unsupportedElements() {
73
+ static const std::unordered_set<std::string> names = {
74
+ "applet", "area", "basefont", "bgsound", "blink", "caption",
75
+ "col", "colgroup", "datalist", "details", "dialog", "embed",
76
+ "frame", "frameset", "iframe", "isindex", "keygen", "map",
77
+ "marquee", "math", "meter", "noembed", "noframes", "object",
78
+ "output", "param", "plaintext", "progress", "summary", "table",
79
+ "tbody", "td", "template", "tfoot", "th", "thead",
80
+ "tr", "track", "xmp",
81
+ };
82
+ return names;
83
+ }
84
+
85
+ /**
86
+ * SVG elements NanoSVG does not render.
87
+ *
88
+ * The list mirrors `doc/gui/known-issues.md`: text, `<use>`/symbols, filters,
89
+ * masks, clip paths, patterns, markers, embedded images and animation are not
90
+ * part of the rasteriser's subset.
91
+ */
92
+ const std::unordered_set<std::string> &unsupportedSvgElements() {
93
+ static const std::unordered_set<std::string> names = {
94
+ "altglyph", "altglyphdef", "altglyphitem", "animate",
95
+ "animatecolor", "animatemotion", "animatetransform", "clippath",
96
+ "color-profile", "cursor", "feblend", "fecolormatrix",
97
+ "fecomponenttransfer", "fecomposite", "feconvolvematrix", "fediffuselighting",
98
+ "fedisplacementmap", "fedistantlight", "fedropshadow", "feflood",
99
+ "fefunca", "fefuncb", "fefuncg", "fefuncr",
100
+ "fegaussianblur", "feimage", "femerge", "femergenode",
101
+ "femorphology", "feoffset", "fepointlight", "fespecularlighting",
102
+ "fespotlight", "fetile", "feturbulence", "filter",
103
+ "font", "font-face", "font-face-format", "font-face-name",
104
+ "font-face-src", "font-face-uri", "foreignobject", "glyph",
105
+ "glyphref", "hkern", "image", "marker",
106
+ "mask", "mpath", "pattern", "set",
107
+ "switch", "symbol", "text", "textpath",
108
+ "tref", "tspan", "use", "view",
109
+ "vkern",
110
+ };
111
+ return names;
112
+ }
113
+
114
+ /** Attributes that request browser behaviour the engine has no subsystem for. */
115
+ const std::unordered_set<std::string> &unsupportedAttributes() {
116
+ static const std::unordered_set<std::string> names = {
117
+ "autofocus", "clip-path", "contenteditable", "controls", "draggable",
118
+ "filter", "hidden", "href", "marker-end", "marker-mid",
119
+ "marker-start", "mask", "poster", "sizes", "srcset",
120
+ };
121
+ return names;
122
+ }
123
+
124
+ void warnElementOnce(const std::string &name) {
125
+ static SeenNames seen;
126
+ if (!firstUse(&seen, name)) return;
127
+ std::fprintf(stderr,
128
+ "xt_gui: warning: unsupported element <%s>; the engine has no browser "
129
+ "behaviour for it\n",
130
+ name.c_str());
131
+ }
132
+
133
+ void warnSvgElementOnce(const std::string &name) {
134
+ static SeenNames seen;
135
+ if (!firstUse(&seen, name)) return;
136
+ std::fprintf(stderr, "xt_gui: warning: unsupported SVG element <%s>; it is not rendered\n",
137
+ name.c_str());
138
+ }
139
+
140
+ void warnAttributeOnce(const std::string &tag, const std::string &attribute) {
141
+ static SeenNames seen;
142
+ std::string key = tag;
143
+ key += ':';
144
+ key += attribute;
145
+ if (!firstUse(&seen, key)) return;
146
+ std::fprintf(stderr,
147
+ "xt_gui: warning: unsupported attribute '%s' on <%s>; the engine has no "
148
+ "behaviour for it\n",
149
+ attribute.c_str(), tag.c_str());
150
+ }
151
+
152
+ void warnPropertyOnce(const std::string &name) {
153
+ static SeenNames seen;
154
+ if (!firstUse(&seen, name)) return;
155
+ std::fprintf(stderr, "xt_gui: warning: unsupported CSS property '%s'; it is ignored\n",
156
+ name.c_str());
157
+ }
158
+
159
+ void warnAtRuleOnce(const std::string &name) {
160
+ static SeenNames seen;
161
+ if (!firstUse(&seen, name)) return;
162
+ std::fprintf(stderr, "xt_gui: warning: unsupported at-rule '@%s'; its rule is ignored\n",
163
+ name.c_str());
164
+ }
165
+
166
+ void warnDescriptorOnce(const std::string &name) {
167
+ static SeenNames seen;
168
+ if (!firstUse(&seen, name)) return;
169
+ std::fprintf(stderr,
170
+ "xt_gui: warning: unsupported @font-face descriptor '%s'; it is ignored\n",
171
+ name.c_str());
172
+ }
173
+
174
+ void warnSelectorOnce(const std::string &selector) {
175
+ static SeenNames seen;
176
+ if (!firstUse(&seen, selector)) return;
177
+ std::fprintf(stderr, "xt_gui: warning: unsupported selector '%s'; the rule is ignored\n",
178
+ truncated(selector, 80).c_str());
179
+ }
180
+
181
+ void warnPseudoClassOnce(const std::string &name) {
182
+ static SeenNames seen;
183
+ if (!firstUse(&seen, name)) return;
184
+ std::fprintf(stderr, "xt_gui: warning: unsupported pseudo-class ':%s'; it never matches\n",
185
+ name.c_str());
186
+ }
187
+
188
+ void warnPseudoElementOnce(const std::string &name) {
189
+ static SeenNames seen;
190
+ if (!firstUse(&seen, name)) return;
191
+ std::fprintf(stderr, "xt_gui: warning: unsupported pseudo-element '::%s'; it is not generated\n",
192
+ name.c_str());
193
+ }
194
+
195
+ void warnMediaFeatureOnce(const std::string &name) {
196
+ static SeenNames seen;
197
+ if (!firstUse(&seen, name)) return;
198
+ std::fprintf(stderr,
199
+ "xt_gui: warning: unsupported media feature '%s'; the query is treated as "
200
+ "not matching\n",
201
+ name.c_str());
202
+ }
203
+
204
+ void warnFunctionOnce(const std::string &property, const std::string &function) {
205
+ static SeenNames seen;
206
+ std::string key = property;
207
+ key += ':';
208
+ key += function;
209
+ if (!firstUse(&seen, key)) return;
210
+ std::fprintf(stderr, "xt_gui: warning: unsupported function '%s()' in '%s'; it is ignored\n",
211
+ function.c_str(), property.c_str());
212
+ }
213
+
214
+ void warnUnitOnce(const std::string &unit) {
215
+ static SeenNames seen;
216
+ if (!firstUse(&seen, unit)) return;
217
+ std::fprintf(stderr, "xt_gui: warning: unsupported CSS unit '%s'; the value is ignored\n",
218
+ unit.c_str());
219
+ }
220
+
221
+ } // namespace
222
+
223
+ void xt_warn_unsupported_element(const std::string &tag) {
224
+ if (warningsSuppressed()) return;
225
+ if (!hasUpperAscii(tag)) {
226
+ if (unsupportedElements().count(tag) != 0) warnElementOnce(tag);
227
+ return;
228
+ }
229
+ const std::string name = lowerAscii(tag);
230
+ if (unsupportedElements().count(name) != 0) warnElementOnce(name);
231
+ }
232
+
233
+ void xt_warn_unsupported_svg_element(const std::string &tag) {
234
+ if (warningsSuppressed()) return;
235
+ const std::string name = hasUpperAscii(tag) ? lowerAscii(tag) : tag;
236
+ if (unsupportedSvgElements().count(name) != 0) warnSvgElementOnce(name);
237
+ }
238
+
239
+ void xt_warn_unsupported_attribute(const std::string &tag, const std::string &attribute) {
240
+ if (warningsSuppressed()) return;
241
+ const std::string name = hasUpperAscii(attribute) ? lowerAscii(attribute) : attribute;
242
+ if (unsupportedAttributes().count(name) == 0) return;
243
+ const std::string element = hasUpperAscii(tag) ? lowerAscii(tag) : tag;
244
+ warnAttributeOnce(element, name);
245
+ }
246
+
247
+ void xt_warn_unsupported_property(const std::string &property) {
248
+ if (warningsSuppressed()) return;
249
+ if (!hasUpperAscii(property)) {
250
+ warnPropertyOnce(property);
251
+ return;
252
+ }
253
+ warnPropertyOnce(lowerAscii(property));
254
+ }
255
+
256
+ void xt_warn_unsupported_at_rule(const std::string &name) {
257
+ if (warningsSuppressed() || name.empty()) return;
258
+ warnAtRuleOnce(hasUpperAscii(name) ? lowerAscii(name) : name);
259
+ }
260
+
261
+ void xt_warn_unsupported_descriptor(const std::string &name) {
262
+ if (warningsSuppressed() || name.empty()) return;
263
+ warnDescriptorOnce(hasUpperAscii(name) ? lowerAscii(name) : name);
264
+ }
265
+
266
+ void xt_warn_unsupported_selector(const std::string &selector) {
267
+ if (warningsSuppressed()) return;
268
+ const std::string text = selector;
269
+ if (text.empty()) return;
270
+ warnSelectorOnce(text);
271
+ }
272
+
273
+ void xt_warn_unsupported_pseudo_class(const std::string &name) {
274
+ if (warningsSuppressed() || name.empty()) return;
275
+ warnPseudoClassOnce(hasUpperAscii(name) ? lowerAscii(name) : name);
276
+ }
277
+
278
+ void xt_warn_unsupported_pseudo_element(const std::string &name) {
279
+ if (warningsSuppressed() || name.empty()) return;
280
+ warnPseudoElementOnce(hasUpperAscii(name) ? lowerAscii(name) : name);
281
+ }
282
+
283
+ void xt_warn_unsupported_media_feature(const std::string &name) {
284
+ if (warningsSuppressed() || name.empty()) return;
285
+ warnMediaFeatureOnce(hasUpperAscii(name) ? lowerAscii(name) : name);
286
+ }
287
+
288
+ void xt_warn_unsupported_function(const std::string &property, const std::string &function) {
289
+ if (warningsSuppressed() || function.empty()) return;
290
+ warnFunctionOnce(property, hasUpperAscii(function) ? lowerAscii(function) : function);
291
+ }
292
+
293
+ void xt_warn_unsupported_unit(const std::string &unit) {
294
+ if (warningsSuppressed() || unit.empty()) return;
295
+ warnUnitOnce(hasUpperAscii(unit) ? lowerAscii(unit) : unit);
296
+ }
297
+
298
+ } // namespace xtgui
@@ -0,0 +1,59 @@
1
+ /*
2
+ * xbintsc GUI engine — diagnostics for the features outside the supported
3
+ * HTML/CSS subset.
4
+ *
5
+ * The engine deliberately keeps rendering when a page uses an element or a
6
+ * declaration it does not implement; these helpers make that fallback visible
7
+ * instead of silent. Each name is reported once per process, so a property used
8
+ * by every rule (or a table cell repeated on every row) cannot flood stderr on
9
+ * every restyle.
10
+ *
11
+ * Set `XT_GUI_NO_WARNINGS=1` to silence the reports (they are development
12
+ * aids; a shipped application usually starts without a console on Windows).
13
+ */
14
+ #ifndef XT_GUI_WARNINGS_H
15
+ #define XT_GUI_WARNINGS_H
16
+
17
+ #include <string>
18
+
19
+ namespace xtgui {
20
+
21
+ /** Report an unsupported HTML element once per tag name. */
22
+ void xt_warn_unsupported_element(const std::string &tag);
23
+
24
+ /** Report an unsupported SVG child element once per tag name. */
25
+ void xt_warn_unsupported_svg_element(const std::string &tag);
26
+
27
+ /** Report an unsupported HTML attribute once per element/tag pair. */
28
+ void xt_warn_unsupported_attribute(const std::string &tag, const std::string &attribute);
29
+
30
+ /** Report an unsupported CSS property once per property name. */
31
+ void xt_warn_unsupported_property(const std::string &property);
32
+
33
+ /** Report an ignored at-rule once per at-rule name (`supports`, `layer`, …). */
34
+ void xt_warn_unsupported_at_rule(const std::string &name);
35
+
36
+ /** Report an ignored `@font-face` descriptor once per descriptor name. */
37
+ void xt_warn_unsupported_descriptor(const std::string &name);
38
+
39
+ /** Report a selector the parser had to drop. */
40
+ void xt_warn_unsupported_selector(const std::string &selector);
41
+
42
+ /** Report an unsupported pseudo-class (`:has`, `:nth-of-type`, …). */
43
+ void xt_warn_unsupported_pseudo_class(const std::string &name);
44
+
45
+ /** Report an unsupported pseudo-element (`::selection`, `::marker`, …). */
46
+ void xt_warn_unsupported_pseudo_element(const std::string &name);
47
+
48
+ /** Report an unsupported `@media` feature and why its query is treated as false. */
49
+ void xt_warn_unsupported_media_feature(const std::string &name);
50
+
51
+ /** Report an unsupported CSS function inside `property` (`transform`, `filter`, …). */
52
+ void xt_warn_unsupported_function(const std::string &property, const std::string &function);
53
+
54
+ /** Report an unsupported length unit (`vmin`, `ch`, `dvh`, …). */
55
+ void xt_warn_unsupported_unit(const std::string &unit);
56
+
57
+ } // namespace xtgui
58
+
59
+ #endif /* XT_GUI_WARNINGS_H */
@@ -20,6 +20,11 @@
20
20
 
21
21
  static xt_value g_window_proto = XT_UNDEFINED;
22
22
 
23
+ /* Defined in `window_diagnostics.cpp`. */
24
+ xt_value xt_gui_window_set_background(xt_value self, xt_value env, int32_t argc, xt_value *argv);
25
+ xt_value xt_gui_window_paint_list(xt_value self, xt_value env, int32_t argc, xt_value *argv);
26
+ xt_value xt_gui_window_paint_count(xt_value self, xt_value env, int32_t argc, xt_value *argv);
27
+
23
28
  /** String value of a runtime value, as `std::string` ("" for null/undefined). */
24
29
  static std::string window_string(xt_value value) {
25
30
  const char *data = xt_string_data(xt_to_string(value));
@@ -192,56 +197,8 @@ static xt_value win_layout_tree(xt_value self, xt_value env, int32_t argc, xt_va
192
197
  return xt_string_from_cstr(text.c_str());
193
198
  }
194
199
 
195
- static xt_value win_set_background(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
196
- (void)env;
197
- XtGuiWindow *win = xt_gui_window_from_this(self);
198
- if (win != NULL && argc >= 1) {
199
- xt_value text = xt_to_string(xt_arg(argc, argv, 0));
200
- const char *data = xt_string_data(text);
201
- if (data != nullptr) {
202
- xtgui::Color color = xtgui::xt_css_parse_color(data);
203
- if (color.valid) {
204
- win->background[0] = color.r;
205
- win->background[1] = color.g;
206
- win->background[2] = color.b;
207
- win->background[3] = color.a;
208
- win->present_dirty = 1;
209
- }
210
- }
211
- xt_object_set(self, xt_string_from_cstr("__xt_gui_background"), text);
212
- }
213
- return XT_UNDEFINED;
214
- }
215
-
216
- /** Diagnostic/test hook: the display list built from the current layout. */
217
- static xt_value win_paint_list(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
218
- (void)env;
219
- (void)argc;
220
- (void)argv;
221
- XtGuiWindow *win = xt_gui_window_from_this(self);
222
- if (win == nullptr || win->document == nullptr) return xt_string_from_cstr("");
223
- xt_gui_flush_dom(win);
224
- xtgui::DisplayList list;
225
- xtgui::xt_paint_build(win->document->layout().root(), list);
226
- std::string text = list.dump();
227
- return xt_string_from_cstr(text.c_str());
228
- }
229
-
230
- /** Diagnostic/test hook: number of shapes in the display list. */
231
- static xt_value win_paint_count(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
232
- (void)env;
233
- (void)argc;
234
- (void)argv;
235
- XtGuiWindow *win = xt_gui_window_from_this(self);
236
- if (win == nullptr || win->document == nullptr) return xt_number(0);
237
- xt_gui_flush_dom(win);
238
- xtgui::DisplayList list;
239
- xtgui::xt_paint_build(win->document->layout().root(), list);
240
- return xt_number((double)list.rects.size());
241
- }
242
-
243
- /** Diagnostic/test hook: the serialized SVG document of the first `<svg>`
244
- * element matching `selector`, plus the intrinsic size and shape count the
200
+ /** Diagnostic/test hook: the serialized inline `<svg>` document of the first
201
+ * element matching `selector`, plus the intrinsic size and shape count a
245
202
  * NanoSVG parse yields. Returns `undefined` when there is no such element. */
246
203
  static xt_value win_inline_svg(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
247
204
  (void)env;
@@ -429,6 +386,24 @@ static xt_value win_send_event(xt_value self, xt_value env, int32_t argc, xt_val
429
386
  y = xt_gui_number_or(xt_object_get_cstr(options, "y"), 0);
430
387
  }
431
388
  std::string name(type);
389
+ if (name == "textInput") {
390
+ std::string text;
391
+ if (XT_IS_OBJECT(options)) {
392
+ xt_value value = xt_object_get_cstr(options, "text");
393
+ if (XT_IS_STRING(value)) text = std::string(xt_string_data(value));
394
+ }
395
+ xt_gui_text_input(win, text.c_str());
396
+ return XT_TRUE;
397
+ }
398
+ if (name == "compositionstart" || name == "compositionupdate" || name == "compositionend") {
399
+ std::string data;
400
+ if (XT_IS_OBJECT(options)) {
401
+ xt_value value = xt_object_get_cstr(options, "data");
402
+ if (XT_IS_STRING(value)) data = std::string(xt_string_data(value));
403
+ }
404
+ xt_gui_composition_event(win, name.c_str(), data.c_str());
405
+ return XT_TRUE;
406
+ }
432
407
  if (name == "wheel") {
433
408
  double delta_x = 0;
434
409
  double delta_y = 0;
@@ -440,10 +415,10 @@ static xt_value win_send_event(xt_value self, xt_value env, int32_t argc, xt_val
440
415
  return XT_TRUE;
441
416
  }
442
417
  if (name == "keydown" || name == "keyup") {
418
+ auto flag = [options](const char *key) { return xt_truthy(xt_object_get_cstr(options, key)); };
443
419
  if (XT_IS_OBJECT(options) && XT_IS_NUMBER(xt_object_get_cstr(options, "scancode"))) {
444
420
  int scancode = (int)xt_gui_number_or(xt_object_get_cstr(options, "scancode"), 0);
445
421
  int keycode = (int)xt_gui_number_or(xt_object_get_cstr(options, "keycode"), 0);
446
- auto flag = [options](const char *key) { return xt_truthy(xt_object_get_cstr(options, key)); };
447
422
  xt_gui_dispatch_physical_key(win, type, scancode, keycode, flag("repeat"), flag("ctrl"),
448
423
  flag("shift"), flag("alt"), flag("meta"), flag("caps"));
449
424
  return XT_TRUE;
@@ -456,7 +431,8 @@ static xt_value win_send_event(xt_value self, xt_value env, int32_t argc, xt_val
456
431
  if (XT_IS_STRING(key_value)) key = xt_string_data(key_value);
457
432
  if (XT_IS_STRING(code_value)) code = xt_string_data(code_value);
458
433
  }
459
- xt_gui_dispatch_key(win, type, key, code);
434
+ xt_gui_dispatch_key_with_modifiers(win, type, key, code, flag("repeat"), flag("ctrl"),
435
+ flag("shift"), flag("alt"), flag("meta"));
460
436
  return XT_TRUE;
461
437
  }
462
438
  int button = -1;
@@ -572,9 +548,9 @@ xt_value xt_gui_window_proto(void) {
572
548
  define_method(proto, "queryCount", (void *)win_query_count);
573
549
  define_method(proto, "getBoundingClientRect", (void *)win_get_bounding_rect);
574
550
  define_method(proto, "layoutTree", (void *)win_layout_tree);
575
- define_method(proto, "setBackground", (void *)win_set_background);
576
- define_method(proto, "paintList", (void *)win_paint_list);
577
- define_method(proto, "paintCount", (void *)win_paint_count);
551
+ define_method(proto, "setBackground", (void *)xt_gui_window_set_background);
552
+ define_method(proto, "paintList", (void *)xt_gui_window_paint_list);
553
+ define_method(proto, "paintCount", (void *)xt_gui_window_paint_count);
578
554
  define_method(proto, "inlineSvg", (void *)win_inline_svg);
579
555
  define_method(proto, "advance", (void *)win_advance);
580
556
  define_method(proto, "measureText", (void *)win_measure_text);
@@ -0,0 +1,58 @@
1
+ /*
2
+ * xbintsc GUI engine — window diagnostics and background painting exposed as
3
+ * test/debug hooks (`setBackground`, `paintList`, `paintCount`).
4
+ */
5
+
6
+ #include "gui_internal.h"
7
+
8
+ #include "paint.h"
9
+
10
+ #include <string>
11
+
12
+ xt_value xt_gui_window_set_background(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
13
+ (void)env;
14
+ XtGuiWindow *win = xt_gui_window_from_this(self);
15
+ if (win != NULL && argc >= 1) {
16
+ xt_value text = xt_to_string(xt_arg(argc, argv, 0));
17
+ const char *data = xt_string_data(text);
18
+ if (data != nullptr) {
19
+ xtgui::Color color = xtgui::xt_css_parse_color(data);
20
+ if (color.valid) {
21
+ win->background[0] = color.r;
22
+ win->background[1] = color.g;
23
+ win->background[2] = color.b;
24
+ win->background[3] = color.a;
25
+ win->present_dirty = 1;
26
+ }
27
+ }
28
+ xt_object_set(self, xt_string_from_cstr("__xt_gui_background"), text);
29
+ }
30
+ return XT_UNDEFINED;
31
+ }
32
+
33
+ /** Diagnostic/test hook: the display list built from the current layout. */
34
+ xt_value xt_gui_window_paint_list(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
35
+ (void)env;
36
+ (void)argc;
37
+ (void)argv;
38
+ XtGuiWindow *win = xt_gui_window_from_this(self);
39
+ if (win == nullptr || win->document == nullptr) return xt_string_from_cstr("");
40
+ xt_gui_flush_dom(win);
41
+ xtgui::DisplayList list;
42
+ xtgui::xt_paint_build(win->document->layout().root(), list);
43
+ std::string text = list.dump();
44
+ return xt_string_from_cstr(text.c_str());
45
+ }
46
+
47
+ /** Diagnostic/test hook: number of shapes in the display list. */
48
+ xt_value xt_gui_window_paint_count(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
49
+ (void)env;
50
+ (void)argc;
51
+ (void)argv;
52
+ XtGuiWindow *win = xt_gui_window_from_this(self);
53
+ if (win == nullptr || win->document == nullptr) return xt_number(0);
54
+ xt_gui_flush_dom(win);
55
+ xtgui::DisplayList list;
56
+ xtgui::xt_paint_build(win->document->layout().root(), list);
57
+ return xt_number((double)list.rects.size());
58
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * xbintsc GUI engine — window-level event listeners (`window.on` /
3
+ * `window.addEventListener`) live here so the input/rendering unit stays focused.
4
+ */
5
+
6
+ #include "gui_internal.h"
7
+ #include "listener_options.h"
8
+
9
+ #include <vector>
10
+
11
+ /* -- window events -------------------------------------------------------- */
12
+
13
+ void xt_gui_emit(XtGuiWindow *win, const char *event) {
14
+ xt_gui_emit_payload(win, event, XT_UNDEFINED);
15
+ }
16
+
17
+ /** Drop one window listener (by identity: type + fn + capture). */
18
+ static void remove_window_listener(XtGuiWindow *win, const XtGuiWindowListener &listener) {
19
+ std::vector<XtGuiWindowListener> &listeners = win->window_listeners;
20
+ for (auto it = listeners.begin(); it != listeners.end(); ++it) {
21
+ if (it->type == listener.type && it->capture == listener.capture &&
22
+ xt_truthy(xt_seq(it->fn, listener.fn))) {
23
+ listeners.erase(it);
24
+ return;
25
+ }
26
+ }
27
+ }
28
+
29
+ void xt_gui_emit_payload(XtGuiWindow *win, const char *event, xt_value payload) {
30
+ if (win == NULL || !XT_IS_OBJECT(win->object)) return;
31
+ xt_value args[1];
32
+ int32_t count = 0;
33
+ if (!XT_IS_UNDEFINED(payload)) {
34
+ args[0] = payload;
35
+ count = 1;
36
+ }
37
+ /* Snapshot the list: a handler may register or remove listeners while it
38
+ * runs, and the DOM runs the batch as it stood when dispatch started. */
39
+ std::vector<XtGuiWindowListener> snapshot = win->window_listeners;
40
+ for (const XtGuiWindowListener &listener : snapshot) {
41
+ if (listener.type != event) continue;
42
+ /* `{ signal }` removes the listener at abort time (checked here, so no
43
+ * callback plumbing is needed inside the signal). */
44
+ if (xt_gui_signal_aborted(listener.signal)) {
45
+ remove_window_listener(win, listener);
46
+ continue;
47
+ }
48
+ if (listener.once) remove_window_listener(win, listener);
49
+ if (XT_IS_FUNCTION(listener.fn)) xt_call_with_this(listener.fn, win->object, count, args);
50
+ }
51
+ }
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  #include "rt.h"
14
+ #include "crypto_hash.h"
14
15
 
15
16
  #include <stdint.h>
16
17
  #include <stdio.h>
@@ -223,7 +224,7 @@ static void sha1_final(sha1_ctx *ctx, uint8_t *out) {
223
224
 
224
225
  /* Compute `algorithm` over `data`; returns the digest length, or 0 when the
225
226
  * algorithm is unsupported. */
226
- static size_t xt_hash_compute(const char *algorithm, const uint8_t *data, size_t length, uint8_t *out) {
227
+ size_t xt_crypto_hash_compute(const char *algorithm, const uint8_t *data, size_t length, uint8_t *out) {
227
228
  if (algorithm && (strcmp(algorithm, "sha1") == 0 || strcmp(algorithm, "sha-1") == 0)) {
228
229
  sha1_ctx ctx;
229
230
  sha1_init(&ctx);
@@ -317,7 +318,7 @@ static xt_value hash_finish(xt_value hash, int argc, xt_value *argv) {
317
318
  const char *text = xt_string_data(xt_to_string(data));
318
319
  if (!text) text = "";
319
320
  uint8_t digest[64];
320
- size_t length = xt_hash_compute(hash_algorithm(hash), (const uint8_t *)text, strlen(text), digest);
321
+ size_t length = xt_crypto_hash_compute(hash_algorithm(hash), (const uint8_t *)text, strlen(text), digest);
321
322
  if (length == 0) return xt_string_from_cstr("");
322
323
  return hash_encode(digest, length, hash_encoding(hash, argc, argv));
323
324
  }
@@ -0,0 +1,13 @@
1
+ #ifndef XT_CRYPTO_HASH_H
2
+ #define XT_CRYPTO_HASH_H
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ /* SHA-1 / SHA-256 over one buffer. Returns the digest length, or 0 for an
8
+ * unsupported algorithm. Shared by `crypto.c` (createHash) and
9
+ * `crypto_random.c` (PBKDF2). */
10
+ size_t xt_crypto_hash_compute(const char *algorithm, const uint8_t *data, size_t length,
11
+ uint8_t *out);
12
+
13
+ #endif /* XT_CRYPTO_HASH_H */