xbintsc 0.3.15 → 0.3.16

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 (156) hide show
  1. package/dist/src/cli/main.js +4 -4
  2. package/dist/src/cli/main.js.map +1 -1
  3. package/dist/src/codegen/generator/state.js +8 -0
  4. package/dist/src/codegen/generator/state.js.map +1 -1
  5. package/dist/src/codegen/generator/tables.js +8 -0
  6. package/dist/src/codegen/generator/tables.js.map +1 -1
  7. package/dist/src/driver/bundler/graph.d.ts +8 -0
  8. package/dist/src/driver/bundler/graph.js +85 -0
  9. package/dist/src/driver/bundler/graph.js.map +1 -0
  10. package/dist/src/driver/bundler/merge.d.ts +11 -0
  11. package/dist/src/driver/bundler/merge.js +288 -0
  12. package/dist/src/driver/bundler/merge.js.map +1 -0
  13. package/dist/src/driver/bundler/resolve.d.ts +12 -0
  14. package/dist/src/driver/bundler/resolve.js +246 -0
  15. package/dist/src/driver/bundler/resolve.js.map +1 -0
  16. package/dist/src/driver/bundler/symbols.d.ts +15 -0
  17. package/dist/src/driver/bundler/symbols.js +51 -0
  18. package/dist/src/driver/bundler/symbols.js.map +1 -0
  19. package/dist/src/driver/bundler/types.d.ts +36 -0
  20. package/dist/src/driver/bundler/types.js +5 -0
  21. package/dist/src/driver/bundler/types.js.map +1 -0
  22. package/dist/src/driver/modules.d.ts +9 -16
  23. package/dist/src/driver/modules.js +8 -644
  24. package/dist/src/driver/modules.js.map +1 -1
  25. package/dist/src/extensions/catalog.js +2 -1
  26. package/dist/src/extensions/catalog.js.map +1 -1
  27. package/dist/src/extensions/gui/index.d.ts +24 -0
  28. package/dist/src/extensions/gui/index.js +101 -0
  29. package/dist/src/extensions/gui/index.js.map +1 -0
  30. package/dist/tests/e2e/compile-basics.test.d.ts +4 -0
  31. package/dist/tests/e2e/compile-basics.test.js +134 -0
  32. package/dist/tests/e2e/compile-basics.test.js.map +1 -0
  33. package/dist/tests/e2e/compile-builtins.test.d.ts +4 -0
  34. package/dist/tests/e2e/compile-builtins.test.js +191 -0
  35. package/dist/tests/e2e/compile-builtins.test.js.map +1 -0
  36. package/dist/tests/e2e/compile-control-flow.test.d.ts +4 -0
  37. package/dist/tests/e2e/compile-control-flow.test.js +190 -0
  38. package/dist/tests/e2e/compile-control-flow.test.js.map +1 -0
  39. package/dist/tests/e2e/compile-modules.test.d.ts +4 -0
  40. package/dist/tests/e2e/compile-modules.test.js +48 -0
  41. package/dist/tests/e2e/compile-modules.test.js.map +1 -0
  42. package/dist/tests/e2e/compile-objects-classes.test.d.ts +4 -0
  43. package/dist/tests/e2e/compile-objects-classes.test.js +362 -0
  44. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -0
  45. package/dist/tests/e2e/differential-helpers.d.ts +12 -0
  46. package/dist/tests/e2e/differential-helpers.js +16 -0
  47. package/dist/tests/e2e/differential-helpers.js.map +1 -0
  48. package/dist/tests/e2e/differential-language.test.d.ts +4 -0
  49. package/dist/tests/e2e/{differential.test.js → differential-language.test.js} +5 -287
  50. package/dist/tests/e2e/differential-language.test.js.map +1 -0
  51. package/dist/tests/e2e/differential-symbols.test.d.ts +4 -0
  52. package/dist/tests/e2e/differential-symbols.test.js +92 -0
  53. package/dist/tests/e2e/differential-symbols.test.js.map +1 -0
  54. package/dist/tests/e2e/differential-values.test.d.ts +4 -0
  55. package/dist/tests/e2e/differential-values.test.js +197 -0
  56. package/dist/tests/e2e/differential-values.test.js.map +1 -0
  57. package/dist/tests/e2e/gui.test.d.ts +12 -0
  58. package/dist/tests/e2e/gui.test.js +493 -0
  59. package/dist/tests/e2e/gui.test.js.map +1 -0
  60. package/dist/tests/e2e/runtime-coverage-buffer.test.d.ts +4 -0
  61. package/dist/tests/e2e/runtime-coverage-buffer.test.js +97 -0
  62. package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -0
  63. package/dist/tests/e2e/runtime-coverage-globals.test.d.ts +4 -0
  64. package/dist/tests/e2e/runtime-coverage-globals.test.js +149 -0
  65. package/dist/tests/e2e/runtime-coverage-globals.test.js.map +1 -0
  66. package/dist/tests/e2e/runtime-coverage-node-modules.test.d.ts +4 -0
  67. package/dist/tests/e2e/runtime-coverage-node-modules.test.js +177 -0
  68. package/dist/tests/e2e/runtime-coverage-node-modules.test.js.map +1 -0
  69. package/dist/tests/e2e/runtime-coverage-streams.test.d.ts +4 -0
  70. package/dist/tests/e2e/runtime-coverage-streams.test.js +161 -0
  71. package/dist/tests/e2e/runtime-coverage-streams.test.js.map +1 -0
  72. package/dist/tests/e2e/runtime-coverage-system.test.d.ts +4 -0
  73. package/dist/tests/e2e/runtime-coverage-system.test.js +91 -0
  74. package/dist/tests/e2e/runtime-coverage-system.test.js.map +1 -0
  75. package/dist/tests/e2e/timers.test.d.ts +7 -0
  76. package/dist/tests/e2e/timers.test.js +63 -0
  77. package/dist/tests/e2e/timers.test.js.map +1 -0
  78. package/package.json +2 -1
  79. package/runtime/ext_gui/css.cpp +743 -0
  80. package/runtime/ext_gui/css.h +98 -0
  81. package/runtime/ext_gui/document.cpp +264 -0
  82. package/runtime/ext_gui/document.h +89 -0
  83. package/runtime/ext_gui/dom.cpp +472 -0
  84. package/runtime/ext_gui/dom.h +71 -0
  85. package/runtime/ext_gui/gui.cpp +457 -0
  86. package/runtime/ext_gui/gui_engine.h +81 -0
  87. package/runtime/ext_gui/image.cpp +125 -0
  88. package/runtime/ext_gui/image.h +42 -0
  89. package/runtime/ext_gui/layout.cpp +748 -0
  90. package/runtime/ext_gui/layout.h +93 -0
  91. package/runtime/ext_gui/paint.cpp +137 -0
  92. package/runtime/ext_gui/paint.h +75 -0
  93. package/runtime/ext_gui/renderer.cpp +959 -0
  94. package/runtime/ext_gui/renderer.h +68 -0
  95. package/runtime/ext_gui/stb_image.h +7988 -0
  96. package/runtime/ext_gui/style.cpp +771 -0
  97. package/runtime/ext_gui/style.h +117 -0
  98. package/runtime/ext_gui/text.cpp +378 -0
  99. package/runtime/ext_gui/text.h +78 -0
  100. package/runtime/ext_gui/window.cpp +405 -0
  101. package/runtime/ext_node/fs/fs_common.h +13 -527
  102. package/runtime/ext_node/fs/parts/buffer-bridge.inc +6 -0
  103. package/runtime/ext_node/fs/parts/builtins.inc +69 -0
  104. package/runtime/ext_node/fs/parts/dir.inc +47 -0
  105. package/runtime/ext_node/fs/parts/encoding.inc +186 -0
  106. package/runtime/ext_node/fs/parts/errors.inc +66 -0
  107. package/runtime/ext_node/fs/parts/flags.inc +39 -0
  108. package/runtime/ext_node/fs/parts/platform.inc +86 -0
  109. package/runtime/ext_node/fs/parts/promisify.inc +15 -0
  110. package/runtime/ext_node/fs/parts/time.inc +9 -0
  111. package/runtime/rt.h +33 -0
  112. package/runtime/xt_builtins.c +4 -0
  113. package/runtime/xt_containers/access.inc +168 -0
  114. package/runtime/xt_containers/arrays.inc +108 -0
  115. package/runtime/xt_containers/boxes.inc +11 -0
  116. package/runtime/xt_containers/objects.inc +326 -0
  117. package/runtime/xt_containers.c +8 -618
  118. package/runtime/xt_io/base64.inc +87 -0
  119. package/runtime/xt_io/console.inc +119 -0
  120. package/runtime/xt_io/exception.inc +142 -0
  121. package/runtime/xt_io/inspect.inc +212 -0
  122. package/runtime/xt_io.c +8 -553
  123. package/runtime/xt_loop.c +262 -24
  124. package/runtime/xt_regex/api.inc +58 -0
  125. package/runtime/xt_regex/helpers.inc +68 -0
  126. package/runtime/xt_regex/matcher.inc +248 -0
  127. package/runtime/xt_regex/parser.inc +236 -0
  128. package/runtime/xt_regex/types.inc +58 -0
  129. package/runtime/xt_regex.h +9 -672
  130. package/runtime/xt_values/arithmetic.inc +150 -0
  131. package/runtime/xt_values/comparison.inc +112 -0
  132. package/runtime/xt_values/constructors.inc +41 -0
  133. package/runtime/xt_values/conversions.inc +115 -0
  134. package/runtime/xt_values/number-format.inc +180 -0
  135. package/runtime/xt_values/strings.inc +22 -0
  136. package/runtime/xt_values.c +10 -626
  137. package/scripts/build-gui.ts +317 -0
  138. package/src/cli/main.ts +4 -3
  139. package/src/codegen/generator/state.ts +8 -0
  140. package/src/codegen/generator/tables.ts +8 -0
  141. package/src/driver/bundler/graph.ts +95 -0
  142. package/src/driver/bundler/merge.ts +312 -0
  143. package/src/driver/bundler/resolve.ts +240 -0
  144. package/src/driver/bundler/symbols.ts +55 -0
  145. package/src/driver/bundler/types.ts +37 -0
  146. package/src/driver/modules.ts +9 -693
  147. package/src/extensions/catalog.ts +2 -1
  148. package/src/extensions/gui/index.ts +107 -0
  149. package/dist/tests/e2e/compile.test.d.ts +0 -8
  150. package/dist/tests/e2e/compile.test.js +0 -893
  151. package/dist/tests/e2e/compile.test.js.map +0 -1
  152. package/dist/tests/e2e/differential.test.d.ts +0 -7
  153. package/dist/tests/e2e/differential.test.js.map +0 -1
  154. package/dist/tests/e2e/runtime-coverage.test.d.ts +0 -11
  155. package/dist/tests/e2e/runtime-coverage.test.js +0 -646
  156. package/dist/tests/e2e/runtime-coverage.test.js.map +0 -1
@@ -0,0 +1,93 @@
1
+ /*
2
+ * xbintsc GUI engine — layout (box tree + geometry).
3
+ *
4
+ * `LayoutTree::compute` turns the styled DOM into a tree of `LayoutBox`es with
5
+ * absolute (viewport-relative) geometry. It implements the slice a UI needs:
6
+ * block flow, a simple inline formatting context with greedy line breaking
7
+ * (text metrics come from the HarfBuzz/FreeType stack) and single-line
8
+ * Flexbox. `<img>` is a replaced element sized from its intrinsic dimensions.
9
+ *
10
+ * Coordinates are absolute: `x`/`y` is the border-box origin measured from the
11
+ * viewport's top-left corner.
12
+ */
13
+ #ifndef XT_GUI_LAYOUT_H
14
+ #define XT_GUI_LAYOUT_H
15
+
16
+ #include <memory>
17
+ #include <string>
18
+ #include <unordered_map>
19
+ #include <vector>
20
+
21
+ #include "dom.h"
22
+ #include "style.h"
23
+
24
+ namespace xtgui {
25
+
26
+ /** A positioned text fragment (a wrapped text box can span several lines).
27
+ * `text` holds the run this fragment covers (a word or a run of spaces). */
28
+ struct TextFragment {
29
+ float x = 0;
30
+ float y = 0;
31
+ float width = 0;
32
+ float height = 0;
33
+ std::string text;
34
+ };
35
+
36
+ struct LayoutBox {
37
+ const Node *node = nullptr;
38
+ const XtStyle *style = nullptr;
39
+
40
+ bool is_text = false;
41
+ std::string text; // only for text boxes
42
+ std::vector<TextFragment> fragments;
43
+
44
+ /* Replaced element (currently `<img>`): source + intrinsic pixel size. */
45
+ bool is_image = false;
46
+ std::string image_src;
47
+ float intrinsic_width = 0;
48
+ float intrinsic_height = 0;
49
+
50
+ Display display = Display::Inline;
51
+
52
+ /* Resolved (px) box edges. */
53
+ float margin_top = 0, margin_right = 0, margin_bottom = 0, margin_left = 0;
54
+ float padding_top = 0, padding_right = 0, padding_bottom = 0, padding_left = 0;
55
+ float border_top = 0, border_right = 0, border_bottom = 0, border_left = 0;
56
+
57
+ /* Absolute geometry; `x`/`y`/`width`/`height` are the border box. */
58
+ float x = 0, y = 0, width = 0, height = 0;
59
+ float content_x = 0, content_y = 0, content_width = 0, content_height = 0;
60
+ float baseline = 0;
61
+
62
+ LayoutBox *parent = nullptr;
63
+ std::vector<std::unique_ptr<LayoutBox>> children;
64
+ };
65
+
66
+ class LayoutTree {
67
+ public:
68
+ void compute(const Node *root, const std::unordered_map<const Node *, XtStyle> &styles,
69
+ float viewportWidth, float viewportHeight);
70
+ void clear() {
71
+ root_.reset();
72
+ index_.clear();
73
+ }
74
+
75
+ const LayoutBox *root() const { return root_.get(); }
76
+ const LayoutBox *find(const Node *node) const;
77
+ /** Deepest box whose border box contains the viewport-relative point. */
78
+ const LayoutBox *hitTest(float x, float y) const;
79
+ /** Human-readable geometry dump, for diagnostics/tests. */
80
+ std::string dump() const;
81
+
82
+ private:
83
+ std::unique_ptr<LayoutBox> root_;
84
+ std::unordered_map<const Node *, const LayoutBox *> index_;
85
+ XtStyle root_style_;
86
+ };
87
+
88
+ /** Text width under `style` (shaped with the HarfBuzz/FreeType stack). */
89
+ float xt_layout_text_width(const std::string &text, const XtStyle &style);
90
+
91
+ } // namespace xtgui
92
+
93
+ #endif /* XT_GUI_LAYOUT_H */
@@ -0,0 +1,137 @@
1
+ /*
2
+ * xbintsc GUI engine — display list construction.
3
+ */
4
+
5
+ #include "paint.h"
6
+
7
+ #include <cstdio>
8
+ #include <utility>
9
+
10
+ #include "style.h"
11
+
12
+ namespace xtgui {
13
+
14
+ namespace {
15
+
16
+ std::string formatColor(const Color &color) {
17
+ char buffer[32];
18
+ std::snprintf(buffer, sizeof(buffer), "#%02x%02x%02x%02x", (int)(color.r * 255.0f + 0.5f),
19
+ (int)(color.g * 255.0f + 0.5f), (int)(color.b * 255.0f + 0.5f),
20
+ (int)(color.a * 255.0f + 0.5f));
21
+ return buffer;
22
+ }
23
+
24
+ FontSpec specOf(const XtStyle &style) {
25
+ FontSpec spec;
26
+ spec.family = style.font_family;
27
+ spec.pixel_size = style.font_size;
28
+ spec.weight = style.font_weight;
29
+ spec.italic = style.font_style == FontStyle::Italic;
30
+ return spec;
31
+ }
32
+
33
+ void addRect(DisplayList &out, float x, float y, float width, float height, float radius,
34
+ const Color &color) {
35
+ if (width <= 0.0f || height <= 0.0f || color.a <= 0.0f) return;
36
+ PaintRect rect;
37
+ rect.x = x;
38
+ rect.y = y;
39
+ rect.width = width;
40
+ rect.height = height;
41
+ rect.radius = radius;
42
+ rect.color = color;
43
+ out.rects.push_back(rect);
44
+ }
45
+
46
+ void addTextRuns(const LayoutBox *box, const XtStyle &style, DisplayList &out) {
47
+ if (box->fragments.empty() || style.color.a <= 0.0f) return;
48
+ FontSpec spec = specOf(style);
49
+ float ascent = 0;
50
+ xt_text_metrics(spec, &ascent, nullptr, nullptr);
51
+ if (ascent <= 0.0f) ascent = style.font_size * 0.8f;
52
+ for (const TextFragment &fragment : box->fragments) {
53
+ if (fragment.text.empty()) continue;
54
+ PaintText run;
55
+ run.x = fragment.x;
56
+ run.baseline = fragment.y + ascent;
57
+ run.width = fragment.width;
58
+ run.height = fragment.height;
59
+ run.color = style.color;
60
+ run.text = fragment.text;
61
+ run.font = spec;
62
+ out.texts.push_back(std::move(run));
63
+ }
64
+ }
65
+
66
+ void paintBox(const LayoutBox *box, DisplayList &out) {
67
+ if (box == nullptr) return;
68
+ const XtStyle *style = box->style;
69
+
70
+ if (style != nullptr && box->display != Display::None) {
71
+ if (box->is_text) {
72
+ addTextRuns(box, *style, out);
73
+ } else {
74
+ /* Background first, then the (sharp-cornered) border ring on top, then the
75
+ * children, so their content paints over the padding. */
76
+ if (style->has_background) {
77
+ addRect(out, box->x, box->y, box->width, box->height, style->border_radius,
78
+ style->background);
79
+ }
80
+ if (style->border_style != BorderStyle::None && style->has_border_color) {
81
+ const Color bc = style->border_color;
82
+ float top = box->border_top;
83
+ float right = box->border_right;
84
+ float bottom = box->border_bottom;
85
+ float left = box->border_left;
86
+ float inner_height = box->height - top - bottom;
87
+ /* Top/bottom span the whole width and overlap the side edges, which is
88
+ * harmless (same colour) and avoids seams from float rounding. */
89
+ addRect(out, box->x, box->y, box->width, top, 0.0f, bc);
90
+ addRect(out, box->x, box->y + box->height - bottom, box->width, bottom, 0.0f, bc);
91
+ addRect(out, box->x, box->y + top, left, inner_height, 0.0f, bc);
92
+ addRect(out, box->x + box->width - right, box->y + top, right, inner_height, 0.0f, bc);
93
+ }
94
+ if (box->is_image && !box->image_src.empty() && box->content_width > 0.0f &&
95
+ box->content_height > 0.0f) {
96
+ PaintImage image;
97
+ image.x = box->content_x;
98
+ image.y = box->content_y;
99
+ image.width = box->content_width;
100
+ image.height = box->content_height;
101
+ image.src = box->image_src;
102
+ out.images.push_back(std::move(image));
103
+ }
104
+ }
105
+ }
106
+
107
+ for (const std::unique_ptr<LayoutBox> &child : box->children) paintBox(child.get(), out);
108
+ }
109
+
110
+ } // namespace
111
+
112
+ void xt_paint_build(const LayoutBox *root, DisplayList &out) { paintBox(root, out); }
113
+
114
+ std::string DisplayList::dump() const {
115
+ std::string text;
116
+ char buffer[192];
117
+ for (const PaintRect &rect : rects) {
118
+ std::snprintf(buffer, sizeof(buffer), "rect x=%.1f y=%.1f w=%.1f h=%.1f r=%.1f color=%s\n",
119
+ rect.x, rect.y, rect.width, rect.height, rect.radius,
120
+ formatColor(rect.color).c_str());
121
+ text += buffer;
122
+ }
123
+ for (const PaintText &run : texts) {
124
+ std::snprintf(buffer, sizeof(buffer),
125
+ "text x=%.1f baseline=%.1f size=%.1f color=%s \"%s\"\n", run.x, run.baseline,
126
+ run.font.pixel_size, formatColor(run.color).c_str(), run.text.c_str());
127
+ text += buffer;
128
+ }
129
+ for (const PaintImage &image : images) {
130
+ std::snprintf(buffer, sizeof(buffer), "image x=%.1f y=%.1f w=%.1f h=%.1f src=%s\n", image.x,
131
+ image.y, image.width, image.height, image.src.c_str());
132
+ text += buffer;
133
+ }
134
+ return text;
135
+ }
136
+
137
+ } // namespace xtgui
@@ -0,0 +1,75 @@
1
+ /*
2
+ * xbintsc GUI engine — display list (paint).
3
+ *
4
+ * `xt_paint_build` walks the laid-out box tree and produces a painter's-order
5
+ * list of shapes. It is deliberately backend-agnostic: the GPU renderer turns
6
+ * the same list into triangles (rectangles) and glyph quads (text), and
7
+ * diagnostics/tests can inspect it without a GPU.
8
+ *
9
+ * Rectangles and text are kept in separate lists: backgrounds/borders are drawn
10
+ * first, then all text on top. That matches almost every static UI and lets the
11
+ * renderer use one draw call per list instead of switching pipelines per shape.
12
+ */
13
+ #ifndef XT_GUI_PAINT_H
14
+ #define XT_GUI_PAINT_H
15
+
16
+ #include <string>
17
+ #include <vector>
18
+
19
+ #include "css.h"
20
+ #include "layout.h"
21
+ #include "text.h"
22
+
23
+ namespace xtgui {
24
+
25
+ /** A solid, optionally rounded, rectangle. Coordinates are viewport-relative. */
26
+ struct PaintRect {
27
+ float x = 0;
28
+ float y = 0;
29
+ float width = 0;
30
+ float height = 0;
31
+ float radius = 0;
32
+ Color color;
33
+ };
34
+
35
+ /** A run of text to draw at `x`/`baseline` (viewport-relative). */
36
+ struct PaintText {
37
+ float x = 0;
38
+ float baseline = 0;
39
+ float width = 0;
40
+ float height = 0;
41
+ Color color;
42
+ std::string text;
43
+ FontSpec font;
44
+ };
45
+
46
+ /** An image to draw, scaled into the given rectangle (viewport-relative). */
47
+ struct PaintImage {
48
+ float x = 0;
49
+ float y = 0;
50
+ float width = 0;
51
+ float height = 0;
52
+ std::string src;
53
+ };
54
+
55
+ struct DisplayList {
56
+ std::vector<PaintRect> rects;
57
+ std::vector<PaintText> texts;
58
+ std::vector<PaintImage> images;
59
+
60
+ void clear() {
61
+ rects.clear();
62
+ texts.clear();
63
+ images.clear();
64
+ }
65
+ bool empty() const { return rects.empty() && texts.empty() && images.empty(); }
66
+ /** Human-readable dump, one shape per line (for diagnostics/tests). */
67
+ std::string dump() const;
68
+ };
69
+
70
+ /** Build the display list for a laid-out tree and append it to `out`. */
71
+ void xt_paint_build(const LayoutBox *root, DisplayList &out);
72
+
73
+ } // namespace xtgui
74
+
75
+ #endif /* XT_GUI_PAINT_H */