xbintsc 0.6.10 → 0.6.13
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.
- package/dist/src/ast/expressions.d.ts +6 -0
- package/dist/src/checker/globals.js +2 -1
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-infer.js +1 -1
- package/dist/src/checker/type-infer.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/codegen/generator/calls/literals.js +4 -1
- package/dist/src/codegen/generator/calls/literals.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +3 -1
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/operators.js +2 -6
- package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.d.ts +9 -0
- package/dist/src/codegen/generator/expressions/primary.js +44 -7
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/state.js +3 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +3 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.js +1 -1
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/symbols.js +6 -0
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/compiler.js +1 -1
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +2 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/node/crypto/index.js +12 -1
- package/dist/src/extensions/node/crypto/index.js.map +1 -1
- package/dist/src/extensions/node/index.js +2 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/readline/index.d.ts +12 -0
- package/dist/src/extensions/node/readline/index.js +27 -0
- package/dist/src/extensions/node/readline/index.js.map +1 -0
- package/dist/src/parser/declarations/functions.js +6 -0
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/literals.js +1 -1
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +26 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +22 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-node.test.js +37 -1
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
- package/dist/tests/e2e/crypto-random.test.js +63 -0
- package/dist/tests/e2e/crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/date-parse.test.js +44 -1
- package/dist/tests/e2e/date-parse.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +61 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-coverage.test.js +40 -1
- package/dist/tests/e2e/gui-css-coverage.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-features.test.js +100 -0
- package/dist/tests/e2e/gui-css-features.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +63 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-errors.test.d.ts +11 -0
- package/dist/tests/e2e/gui-errors.test.js +68 -0
- package/dist/tests/e2e/gui-errors.test.js.map +1 -0
- package/dist/tests/e2e/gui-form.test.d.ts +9 -0
- package/dist/tests/e2e/gui-form.test.js +359 -0
- package/dist/tests/e2e/gui-form.test.js.map +1 -0
- package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
- package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
- package/dist/tests/e2e/gui-style.test.js +82 -0
- package/dist/tests/e2e/gui-style.test.js.map +1 -1
- package/dist/tests/e2e/gui-unsupported.test.js +4 -3
- package/dist/tests/e2e/gui-unsupported.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js +7 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +4 -0
- package/dist/tests/e2e/harness.js +2 -0
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
- package/dist/tests/e2e/json-parse-errors.test.js +48 -0
- package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
- package/dist/tests/e2e/readline.test.d.ts +7 -0
- package/dist/tests/e2e/readline.test.js +73 -0
- package/dist/tests/e2e/readline.test.js.map +1 -0
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/gui/api.md +24 -3
- package/doc/gui/dom.md +28 -14
- package/doc/gui/input.md +74 -3
- package/doc/gui/known-issues.md +2 -1
- package/doc/gui/layout.md +5 -1
- package/doc/implemented/node/crypto.md +8 -0
- package/doc/implemented/node/fs.md +1 -1
- package/doc/implemented/node/readline.md +34 -0
- package/doc/implemented/node.md +1 -0
- package/doc/implemented/stdlib.md +10 -2
- package/doc/unimplemented/node/modules.md +2 -3
- package/doc/unimplemented/node.md +2 -2
- package/doc/zh-CN/gui/api.md +20 -3
- package/doc/zh-CN/gui/dom.md +23 -13
- package/doc/zh-CN/gui/input.md +65 -4
- package/doc/zh-CN/gui/known-issues.md +2 -1
- package/doc/zh-CN/gui/layout.md +4 -1
- package/doc/zh-CN/implemented/node/crypto.md +6 -0
- package/doc/zh-CN/implemented/node/fs.md +1 -1
- package/doc/zh-CN/implemented/node/readline.md +33 -0
- package/doc/zh-CN/implemented/node.md +1 -0
- package/doc/zh-CN/implemented/stdlib.md +10 -2
- package/doc/zh-CN/unimplemented/node/modules.md +1 -2
- package/doc/zh-CN/unimplemented/node.md +2 -2
- package/package.json +7 -7
- package/runtime/ext_gui/browser_abort.cpp +2 -2
- package/runtime/ext_gui/browser_loop.cpp +1 -0
- package/runtime/ext_gui/browser_media.cpp +1 -1
- package/runtime/ext_gui/css_match.cpp +21 -1
- package/runtime/ext_gui/css_selector.cpp +2 -2
- package/runtime/ext_gui/document.cpp +12 -0
- package/runtime/ext_gui/dom.h +41 -2
- package/runtime/ext_gui/dom_api_canvas_image.cpp +2 -1
- package/runtime/ext_gui/dom_api_document.cpp +28 -0
- package/runtime/ext_gui/dom_api_events.cpp +18 -15
- package/runtime/ext_gui/dom_api_form.cpp +567 -0
- package/runtime/ext_gui/dom_api_internal.h +48 -214
- package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
- package/runtime/ext_gui/dom_api_node.cpp +28 -15
- package/runtime/ext_gui/dom_api_node_read.cpp +28 -1
- package/runtime/ext_gui/dom_api_proto.cpp +47 -0
- package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
- package/runtime/ext_gui/dom_parse.cpp +114 -1
- package/runtime/ext_gui/error_report.cpp +166 -0
- package/runtime/ext_gui/form_focus.cpp +293 -0
- package/runtime/ext_gui/form_input.cpp +448 -0
- package/runtime/ext_gui/form_internal.h +30 -0
- package/runtime/ext_gui/form_shared.cpp +126 -0
- package/runtime/ext_gui/form_state.cpp +536 -0
- package/runtime/ext_gui/form_state.h +97 -0
- package/runtime/ext_gui/gui.cpp +16 -0
- package/runtime/ext_gui/gui_engine.h +53 -4
- package/runtime/ext_gui/gui_events.cpp +67 -49
- package/runtime/ext_gui/layout.cpp +6 -0
- package/runtime/ext_gui/layout.h +4 -0
- package/runtime/ext_gui/layout_flow.cpp +23 -1
- package/runtime/ext_gui/layout_inline.cpp +46 -14
- package/runtime/ext_gui/paint.cpp +26 -1
- package/runtime/ext_gui/paint_form.cpp +389 -0
- package/runtime/ext_gui/paint_internal.h +6 -0
- package/runtime/ext_gui/script.cpp +1 -1
- package/runtime/ext_gui/style.cpp +1 -0
- package/runtime/ext_gui/style.h +13 -0
- package/runtime/ext_gui/style_print.cpp +129 -0
- package/runtime/ext_gui/style_text.cpp +79 -0
- package/runtime/ext_gui/style_ua.cpp +42 -0
- package/runtime/ext_gui/warnings.cpp +5 -7
- package/runtime/ext_gui/webgl_texture.cpp +0 -8
- package/runtime/ext_gui/window.cpp +52 -62
- package/runtime/ext_gui/window_diagnostics.cpp +58 -0
- package/runtime/ext_gui/window_emit.cpp +51 -0
- package/runtime/ext_node/crypto/crypto.c +3 -2
- package/runtime/ext_node/crypto/crypto_hash.h +13 -0
- package/runtime/ext_node/crypto/crypto_random.c +339 -0
- package/runtime/ext_node/fs/async_worker.c +1 -1
- package/runtime/ext_node/fs/fs_ops.c +1 -1
- package/runtime/ext_node/fs/parts/platform.inc +67 -0
- package/runtime/ext_node/readline/readline.c +572 -0
- package/runtime/rt.h +42 -0
- package/runtime/rt_internal.h +3 -2
- package/runtime/xt_crypto.c +132 -0
- package/runtime/xt_io/exception.inc +29 -6
- package/runtime/xt_loop.c +36 -1
- package/runtime/xt_promise.c +26 -2
- package/runtime/xt_random.c +143 -0
- package/runtime/xt_regex/matcher.inc +9 -28
- package/runtime/xt_regex/parser.inc +65 -2
- package/runtime/xt_regex/types.inc +11 -1
- package/runtime/xt_regex.h +6 -2
- package/runtime/xt_stdlib/dispatch.inc +2 -0
- package/runtime/xt_stdlib/math.inc +1 -1
- package/runtime/xt_stdlib2/date.inc +206 -6
- package/runtime/xt_stdlib2/json.inc +4 -546
- package/runtime/xt_stdlib2/json_parse.inc +347 -0
- package/runtime/xt_stdlib2/json_stringify.inc +368 -0
- package/runtime/xt_stdlib2/regexp-match.inc +6 -11
- package/runtime/xt_stdlib2.c +0 -4
- package/runtime/xt_typed_array/elements.inc +2 -6
- package/runtime/xt_url.c +0 -6
- package/runtime/xt_url_object.c +1 -1
- package/src/ast/expressions.ts +6 -0
- package/src/checker/globals.ts +2 -0
- package/src/checker/type-infer.ts +1 -1
- package/src/codegen/generator/calls/literals.ts +4 -1
- package/src/codegen/generator/expressions/assignment.ts +3 -1
- package/src/codegen/generator/expressions/operators.ts +2 -6
- package/src/codegen/generator/expressions/primary.ts +58 -6
- package/src/codegen/generator/state.ts +3 -0
- package/src/codegen/generator/tables.ts +3 -0
- package/src/driver/bundler/commonjs.ts +1 -1
- package/src/driver/bundler/symbols.ts +6 -0
- package/src/driver/compiler.ts +1 -1
- package/src/driver/runtime-objects.ts +2 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/node/crypto/index.ts +12 -1
- package/src/extensions/node/index.ts +2 -0
- package/src/extensions/node/readline/index.ts +31 -0
- package/src/parser/declarations/functions.ts +6 -0
- package/src/parser/literals.ts +1 -1
|
@@ -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
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
#include "style_internal.h"
|
|
6
6
|
|
|
7
|
+
#include <cctype>
|
|
7
8
|
#include <unordered_map>
|
|
8
9
|
|
|
9
10
|
namespace xtgui {
|
|
@@ -38,6 +39,47 @@ void xt_style_apply_user_agent(const Node *node, XtStyle *style) {
|
|
|
38
39
|
if (tag == "br") style->display = Display::Block;
|
|
39
40
|
if (tag == "button" || tag == "input" || tag == "select" || tag == "textarea") {
|
|
40
41
|
style->display = Display::InlineBlock;
|
|
42
|
+
/* The browser's form-control look: a 1px border, a white field background
|
|
43
|
+
* and the inherited font. The value/caret are painted by `paint_form.cpp`. */
|
|
44
|
+
style->border_style = BorderStyle::Solid;
|
|
45
|
+
style->border_width.set({1.0f, Unit::Px});
|
|
46
|
+
style->border_color = {0.46f, 0.46f, 0.46f, 1.0f};
|
|
47
|
+
style->has_border_color = true;
|
|
48
|
+
style->background = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
49
|
+
style->has_background = true;
|
|
50
|
+
style->color = {0.1f, 0.1f, 0.1f, 1.0f};
|
|
51
|
+
style->padding.set({1.0f, Unit::Px});
|
|
52
|
+
style->padding.left = style->padding.right = {2.0f, Unit::Px};
|
|
53
|
+
}
|
|
54
|
+
if (tag == "input") {
|
|
55
|
+
const std::string *type = node->attr("type");
|
|
56
|
+
std::string kind;
|
|
57
|
+
if (type != nullptr) {
|
|
58
|
+
kind = *type;
|
|
59
|
+
for (char &c : kind) c = (char)std::tolower((unsigned char)c);
|
|
60
|
+
}
|
|
61
|
+
if (kind == "hidden") style->display = Display::None;
|
|
62
|
+
if (kind == "checkbox" || kind == "radio" || kind == "range") {
|
|
63
|
+
style->border_style = BorderStyle::None;
|
|
64
|
+
style->padding.set({0.0f, Unit::Px});
|
|
65
|
+
style->background = Color{0.0f, 0.0f, 0.0f, 0.0f};
|
|
66
|
+
style->has_background = false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (tag == "textarea") {
|
|
70
|
+
style->white_space = WhiteSpace::PreWrap;
|
|
71
|
+
}
|
|
72
|
+
if (tag == "button") {
|
|
73
|
+
style->background = {0.93f, 0.93f, 0.93f, 1.0f};
|
|
74
|
+
style->has_background = true;
|
|
75
|
+
style->padding.set({1.0f, Unit::Px});
|
|
76
|
+
style->padding.left = style->padding.right = {6.0f, Unit::Px};
|
|
77
|
+
}
|
|
78
|
+
if ((tag == "input" || tag == "textarea" || tag == "select" || tag == "button") &&
|
|
79
|
+
node->attr("disabled") != nullptr) {
|
|
80
|
+
style->color = {0.55f, 0.55f, 0.55f, 1.0f};
|
|
81
|
+
style->background = {0.95f, 0.95f, 0.95f, 1.0f};
|
|
82
|
+
style->has_background = true;
|
|
41
83
|
}
|
|
42
84
|
if (tag == "img") style->display = Display::InlineBlock;
|
|
43
85
|
/* An inline `<svg>` is a replaced inline-block too: its intrinsic size comes
|
|
@@ -73,12 +73,11 @@ const std::unordered_set<std::string> &unsupportedElements() {
|
|
|
73
73
|
static const std::unordered_set<std::string> names = {
|
|
74
74
|
"applet", "area", "basefont", "bgsound", "blink", "caption",
|
|
75
75
|
"col", "colgroup", "datalist", "details", "dialog", "embed",
|
|
76
|
-
"frame", "frameset", "iframe", "
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"track", "xmp",
|
|
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",
|
|
82
81
|
};
|
|
83
82
|
return names;
|
|
84
83
|
}
|
|
@@ -118,7 +117,6 @@ const std::unordered_set<std::string> &unsupportedAttributes() {
|
|
|
118
117
|
"autofocus", "clip-path", "contenteditable", "controls", "draggable",
|
|
119
118
|
"filter", "hidden", "href", "marker-end", "marker-mid",
|
|
120
119
|
"marker-start", "mask", "poster", "sizes", "srcset",
|
|
121
|
-
"tabindex",
|
|
122
120
|
};
|
|
123
121
|
return names;
|
|
124
122
|
}
|
|
@@ -12,14 +12,6 @@
|
|
|
12
12
|
namespace xtgui {
|
|
13
13
|
namespace {
|
|
14
14
|
|
|
15
|
-
bool depth_texture_format(SDL_GPUTextureFormat format) {
|
|
16
|
-
return format == SDL_GPU_TEXTUREFORMAT_D16_UNORM ||
|
|
17
|
-
format == SDL_GPU_TEXTUREFORMAT_D24_UNORM ||
|
|
18
|
-
format == SDL_GPU_TEXTUREFORMAT_D32_FLOAT ||
|
|
19
|
-
format == SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT ||
|
|
20
|
-
format == SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
15
|
int texel_bytes(SDL_GPUTextureFormat format) {
|
|
24
16
|
if (format == SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT) return 8;
|
|
25
17
|
if (format == SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT) return 16;
|
|
@@ -20,11 +20,10 @@
|
|
|
20
20
|
|
|
21
21
|
static xt_value g_window_proto = XT_UNDEFINED;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
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);
|
|
28
27
|
|
|
29
28
|
/* -- methods -------------------------------------------------------------- */
|
|
30
29
|
|
|
@@ -42,8 +41,28 @@ static xt_value win_set_size(xt_value self, xt_value env, int32_t argc, xt_value
|
|
|
42
41
|
(void)env;
|
|
43
42
|
XtGuiWindow *win = xt_gui_window_from_this(self);
|
|
44
43
|
if (win != NULL && win->window != NULL && argc >= 2) {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
int width = (int)xt_to_number(xt_arg(argc, argv, 0));
|
|
45
|
+
int height = (int)xt_to_number(xt_arg(argc, argv, 1));
|
|
46
|
+
SDL_SetWindowSize(win->window, width, height);
|
|
47
|
+
/* Settle the request with the window system (bounded by the backend's own
|
|
48
|
+
* timeout). `innerWidth` already reads the live size, so a host that does
|
|
49
|
+
* not pump SDL events — a page driven only by timers — otherwise never
|
|
50
|
+
* observes the matching `resize` event. */
|
|
51
|
+
SDL_SyncWindow(win->window);
|
|
52
|
+
int actualWidth = width;
|
|
53
|
+
int actualHeight = height;
|
|
54
|
+
SDL_GetWindowSize(win->window, &actualWidth, &actualHeight);
|
|
55
|
+
if (actualWidth != win->width || actualHeight != win->height) {
|
|
56
|
+
win->width = actualWidth;
|
|
57
|
+
win->height = actualHeight;
|
|
58
|
+
if (win->document != NULL) {
|
|
59
|
+
win->document->restyle((float)win->width, (float)win->height);
|
|
60
|
+
}
|
|
61
|
+
win->geometry.dirty = 1;
|
|
62
|
+
win->present_dirty = 1;
|
|
63
|
+
xt_gui_emit(win, "resize");
|
|
64
|
+
xt_gui_media_lists_notify(win);
|
|
65
|
+
}
|
|
47
66
|
}
|
|
48
67
|
return XT_UNDEFINED;
|
|
49
68
|
}
|
|
@@ -192,56 +211,8 @@ static xt_value win_layout_tree(xt_value self, xt_value env, int32_t argc, xt_va
|
|
|
192
211
|
return xt_string_from_cstr(text.c_str());
|
|
193
212
|
}
|
|
194
213
|
|
|
195
|
-
|
|
196
|
-
|
|
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
|
|
214
|
+
/** Diagnostic/test hook: the serialized inline `<svg>` document of the first
|
|
215
|
+
* element matching `selector`, plus the intrinsic size and shape count a
|
|
245
216
|
* NanoSVG parse yields. Returns `undefined` when there is no such element. */
|
|
246
217
|
static xt_value win_inline_svg(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
247
218
|
(void)env;
|
|
@@ -429,6 +400,24 @@ static xt_value win_send_event(xt_value self, xt_value env, int32_t argc, xt_val
|
|
|
429
400
|
y = xt_gui_number_or(xt_object_get_cstr(options, "y"), 0);
|
|
430
401
|
}
|
|
431
402
|
std::string name(type);
|
|
403
|
+
if (name == "textInput") {
|
|
404
|
+
std::string text;
|
|
405
|
+
if (XT_IS_OBJECT(options)) {
|
|
406
|
+
xt_value value = xt_object_get_cstr(options, "text");
|
|
407
|
+
if (XT_IS_STRING(value)) text = std::string(xt_string_data(value));
|
|
408
|
+
}
|
|
409
|
+
xt_gui_text_input(win, text.c_str());
|
|
410
|
+
return XT_TRUE;
|
|
411
|
+
}
|
|
412
|
+
if (name == "compositionstart" || name == "compositionupdate" || name == "compositionend") {
|
|
413
|
+
std::string data;
|
|
414
|
+
if (XT_IS_OBJECT(options)) {
|
|
415
|
+
xt_value value = xt_object_get_cstr(options, "data");
|
|
416
|
+
if (XT_IS_STRING(value)) data = std::string(xt_string_data(value));
|
|
417
|
+
}
|
|
418
|
+
xt_gui_composition_event(win, name.c_str(), data.c_str());
|
|
419
|
+
return XT_TRUE;
|
|
420
|
+
}
|
|
432
421
|
if (name == "wheel") {
|
|
433
422
|
double delta_x = 0;
|
|
434
423
|
double delta_y = 0;
|
|
@@ -440,10 +429,10 @@ static xt_value win_send_event(xt_value self, xt_value env, int32_t argc, xt_val
|
|
|
440
429
|
return XT_TRUE;
|
|
441
430
|
}
|
|
442
431
|
if (name == "keydown" || name == "keyup") {
|
|
432
|
+
auto flag = [options](const char *key) { return xt_truthy(xt_object_get_cstr(options, key)); };
|
|
443
433
|
if (XT_IS_OBJECT(options) && XT_IS_NUMBER(xt_object_get_cstr(options, "scancode"))) {
|
|
444
434
|
int scancode = (int)xt_gui_number_or(xt_object_get_cstr(options, "scancode"), 0);
|
|
445
435
|
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
436
|
xt_gui_dispatch_physical_key(win, type, scancode, keycode, flag("repeat"), flag("ctrl"),
|
|
448
437
|
flag("shift"), flag("alt"), flag("meta"), flag("caps"));
|
|
449
438
|
return XT_TRUE;
|
|
@@ -456,7 +445,8 @@ static xt_value win_send_event(xt_value self, xt_value env, int32_t argc, xt_val
|
|
|
456
445
|
if (XT_IS_STRING(key_value)) key = xt_string_data(key_value);
|
|
457
446
|
if (XT_IS_STRING(code_value)) code = xt_string_data(code_value);
|
|
458
447
|
}
|
|
459
|
-
|
|
448
|
+
xt_gui_dispatch_key_with_modifiers(win, type, key, code, flag("repeat"), flag("ctrl"),
|
|
449
|
+
flag("shift"), flag("alt"), flag("meta"));
|
|
460
450
|
return XT_TRUE;
|
|
461
451
|
}
|
|
462
452
|
int button = -1;
|
|
@@ -572,9 +562,9 @@ xt_value xt_gui_window_proto(void) {
|
|
|
572
562
|
define_method(proto, "queryCount", (void *)win_query_count);
|
|
573
563
|
define_method(proto, "getBoundingClientRect", (void *)win_get_bounding_rect);
|
|
574
564
|
define_method(proto, "layoutTree", (void *)win_layout_tree);
|
|
575
|
-
define_method(proto, "setBackground", (void *)
|
|
576
|
-
define_method(proto, "paintList", (void *)
|
|
577
|
-
define_method(proto, "paintCount", (void *)
|
|
565
|
+
define_method(proto, "setBackground", (void *)xt_gui_window_set_background);
|
|
566
|
+
define_method(proto, "paintList", (void *)xt_gui_window_paint_list);
|
|
567
|
+
define_method(proto, "paintCount", (void *)xt_gui_window_paint_count);
|
|
578
568
|
define_method(proto, "inlineSvg", (void *)win_inline_svg);
|
|
579
569
|
define_method(proto, "advance", (void *)win_advance);
|
|
580
570
|
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_gui_invoke(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
|
-
|
|
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 =
|
|
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 */
|