hokusai-zero 0.1.1
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.
- checksums.yaml +7 -0
- data/Dockerfile +26 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +91 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/ast/genheader +3 -0
- data/ast/include/hashmap.c +1151 -0
- data/ast/include/hashmap.c.license +20 -0
- data/ast/include/hashmap.h +54 -0
- data/ast/src/core/ast.c +448 -0
- data/ast/src/core/ast.h +259 -0
- data/ast/src/core/common.h +24 -0
- data/ast/src/core/component.c +85 -0
- data/ast/src/core/component.h +35 -0
- data/ast/src/core/hml.c +665 -0
- data/ast/src/core/hml.h +11 -0
- data/ast/src/core/input.c +458 -0
- data/ast/src/core/input.h +118 -0
- data/ast/src/core/style.c +101 -0
- data/ast/src/core/style.h +41 -0
- data/ast/src/core/text.c +784 -0
- data/ast/src/core/text.h +93 -0
- data/ast/src/core/util.c +140 -0
- data/ast/src/core/util.h +48 -0
- data/ast/src/hokusai.c +6 -0
- data/ast/src/hokusai.h +6 -0
- data/ast/test/fixtures/test.ui +13 -0
- data/ast/test/greatest.h +1266 -0
- data/ast/test/hokusai.c +14 -0
- data/ast/test/parser.c +234 -0
- data/ast/test/text.c +116 -0
- data/ext/extconf.rb +27 -0
- data/grammar/Cargo.lock +80 -0
- data/grammar/Cargo.toml +26 -0
- data/grammar/binding.gyp +20 -0
- data/grammar/bindings/node/binding.cc +28 -0
- data/grammar/bindings/node/index.js +19 -0
- data/grammar/bindings/rust/build.rs +40 -0
- data/grammar/bindings/rust/lib.rs +52 -0
- data/grammar/corpus/1_document.txt +131 -0
- data/grammar/corpus/2_selectors.txt +58 -0
- data/grammar/corpus/3_spaces.txt +69 -0
- data/grammar/corpus/4_errors.txt +10 -0
- data/grammar/corpus/5_macros.txt +175 -0
- data/grammar/corpus/6_styles.txt +81 -0
- data/grammar/grammar.js +275 -0
- data/grammar/package-lock.json +34 -0
- data/grammar/package.json +33 -0
- data/grammar/src/grammar.json +1269 -0
- data/grammar/src/node-types.json +474 -0
- data/grammar/src/parser.c +5772 -0
- data/grammar/src/scanner.c +258 -0
- data/grammar/src/tree_sitter/parser.h +230 -0
- data/grammar/src/tree_sitter/scanner.h +12 -0
- data/grammar/test.nml +10 -0
- data/hokusai.gemspec +19 -0
- data/ui/examples/assets/DigitalDisplay.ttf +0 -0
- data/ui/examples/assets/OpenSans-Regular.ttf +0 -0
- data/ui/examples/assets/addy.png +0 -0
- data/ui/examples/assets/baby_sean.png +0 -0
- data/ui/examples/assets/football-troll.png +0 -0
- data/ui/examples/assets/gear.png +0 -0
- data/ui/examples/assets/icecold.ttf +0 -0
- data/ui/examples/assets/science-troll.png +0 -0
- data/ui/examples/buddy.rb +31 -0
- data/ui/examples/clock.rb +58 -0
- data/ui/examples/counter.rb +123 -0
- data/ui/examples/dynamic.rb +147 -0
- data/ui/examples/foobar.rb +236 -0
- data/ui/examples/stock.rb +115 -0
- data/ui/examples/stock_decider/option.rb +74 -0
- data/ui/examples/tic_tac_toe.rb +246 -0
- data/ui/lib/lib_hokusai.rb +425 -0
- data/ui/spec/hokusai/ast_spec.rb +88 -0
- data/ui/spec/hokusai/automation/keys_transcoder_spec.rb +50 -0
- data/ui/spec/hokusai/automation/selector_spec.rb +68 -0
- data/ui/spec/hokusai/block_spec.rb +126 -0
- data/ui/spec/hokusai/directives_spec.rb +327 -0
- data/ui/spec/hokusai/e2e/client_spec.rb +58 -0
- data/ui/spec/hokusai/e2e/meta_spec.rb +42 -0
- data/ui/spec/hokusai/publisher_spec.rb +38 -0
- data/ui/spec/hokusai/slots_spec.rb +150 -0
- data/ui/spec/hokusai/util/piece_table_spec.rb +90 -0
- data/ui/spec/hokusai_spec.rb +0 -0
- data/ui/spec/spec_helper.rb +30 -0
- data/ui/src/hokusai/ast.rb +446 -0
- data/ui/src/hokusai/automation/client.rb +167 -0
- data/ui/src/hokusai/automation/constants.rb +98 -0
- data/ui/src/hokusai/automation/converters/selector_converter.rb +61 -0
- data/ui/src/hokusai/automation/driver.rb +54 -0
- data/ui/src/hokusai/automation/driver_command_queue.rb +50 -0
- data/ui/src/hokusai/automation/driver_commands/base.rb +79 -0
- data/ui/src/hokusai/automation/driver_commands/get_attribute.rb +41 -0
- data/ui/src/hokusai/automation/driver_commands/invoke.rb +33 -0
- data/ui/src/hokusai/automation/driver_commands/locate.rb +48 -0
- data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +94 -0
- data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +213 -0
- data/ui/src/hokusai/automation/keys_transcoder.rb +128 -0
- data/ui/src/hokusai/automation/selector.rb +39 -0
- data/ui/src/hokusai/automation/server.rb +114 -0
- data/ui/src/hokusai/automation.rb +3 -0
- data/ui/src/hokusai/backends/raylib/config.rb +47 -0
- data/ui/src/hokusai/backends/raylib/font.rb +113 -0
- data/ui/src/hokusai/backends/raylib/keys.rb +124 -0
- data/ui/src/hokusai/backends/raylib.rb +449 -0
- data/ui/src/hokusai/backends/sdl2/Monaco.ttf +0 -0
- data/ui/src/hokusai/backends/sdl2/color.rb +12 -0
- data/ui/src/hokusai/backends/sdl2/config.rb +31 -0
- data/ui/src/hokusai/backends/sdl2/font.rb +127 -0
- data/ui/src/hokusai/backends/sdl2/keys.rb +119 -0
- data/ui/src/hokusai/backends/sdl2.rb +529 -0
- data/ui/src/hokusai/block.rb +237 -0
- data/ui/src/hokusai/blocks/button.rb +100 -0
- data/ui/src/hokusai/blocks/checkbox.rb +51 -0
- data/ui/src/hokusai/blocks/circle.rb +28 -0
- data/ui/src/hokusai/blocks/clipped.rb +23 -0
- data/ui/src/hokusai/blocks/cursor.rb +49 -0
- data/ui/src/hokusai/blocks/dynamic.rb +37 -0
- data/ui/src/hokusai/blocks/empty.rb +10 -0
- data/ui/src/hokusai/blocks/hblock.rb +35 -0
- data/ui/src/hokusai/blocks/image.rb +18 -0
- data/ui/src/hokusai/blocks/input.rb +200 -0
- data/ui/src/hokusai/blocks/label.rb +39 -0
- data/ui/src/hokusai/blocks/panel.rb +126 -0
- data/ui/src/hokusai/blocks/rect.rb +24 -0
- data/ui/src/hokusai/blocks/scissor_begin.rb +18 -0
- data/ui/src/hokusai/blocks/scissor_end.rb +12 -0
- data/ui/src/hokusai/blocks/scrollbar.rb +103 -0
- data/ui/src/hokusai/blocks/selectable.rb +77 -0
- data/ui/src/hokusai/blocks/svg.rb +20 -0
- data/ui/src/hokusai/blocks/text.rb +214 -0
- data/ui/src/hokusai/blocks/titlebar/osx.rb +145 -0
- data/ui/src/hokusai/blocks/toggle.rb +55 -0
- data/ui/src/hokusai/blocks/vblock.rb +35 -0
- data/ui/src/hokusai/commands/base.rb +22 -0
- data/ui/src/hokusai/commands/circle.rb +47 -0
- data/ui/src/hokusai/commands/image.rb +45 -0
- data/ui/src/hokusai/commands/rect.rb +158 -0
- data/ui/src/hokusai/commands/scissor.rb +22 -0
- data/ui/src/hokusai/commands/text.rb +92 -0
- data/ui/src/hokusai/commands.rb +87 -0
- data/ui/src/hokusai/diff.rb +124 -0
- data/ui/src/hokusai/error.rb +3 -0
- data/ui/src/hokusai/event.rb +54 -0
- data/ui/src/hokusai/events/keyboard.rb +84 -0
- data/ui/src/hokusai/events/mouse.rb +172 -0
- data/ui/src/hokusai/font.rb +280 -0
- data/ui/src/hokusai/meta.rb +152 -0
- data/ui/src/hokusai/mounting/loop_entry.rb +230 -0
- data/ui/src/hokusai/mounting/mount_entry.rb +74 -0
- data/ui/src/hokusai/mounting/update_entry.rb +101 -0
- data/ui/src/hokusai/node.rb +98 -0
- data/ui/src/hokusai/node_mounter.rb +102 -0
- data/ui/src/hokusai/painter.rb +214 -0
- data/ui/src/hokusai/publisher.rb +32 -0
- data/ui/src/hokusai/style.rb +72 -0
- data/ui/src/hokusai/types.rb +266 -0
- data/ui/src/hokusai/util/clamping_iterator.rb +202 -0
- data/ui/src/hokusai/util/piece_table.rb +111 -0
- data/ui/src/hokusai/util/selection.rb +145 -0
- data/ui/src/hokusai.rb +120 -0
- data/ui/vendor/.gitkeep +0 -0
- data/vendor/.gitkeep +0 -0
- data/xmake.lua +192 -0
- metadata +222 -0
data/ast/src/core/text.h
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
#ifndef HOKU_TEXT_H
|
2
|
+
#define HOKU_TEXT_H
|
3
|
+
|
4
|
+
#include <string.h>
|
5
|
+
#include <stdbool.h>
|
6
|
+
#include <stdlib.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <md4c.h>
|
9
|
+
|
10
|
+
typedef struct HokuChar
|
11
|
+
{
|
12
|
+
int offset;
|
13
|
+
int width;
|
14
|
+
struct HokuChar* next_char;
|
15
|
+
} hoku_char;
|
16
|
+
|
17
|
+
enum HOKU_GROUP_TYPE
|
18
|
+
{
|
19
|
+
HOKU_GROUP_NORMAL = 1 << 0,
|
20
|
+
HOKU_GROUP_BOLD = 1 << 1,
|
21
|
+
HOKU_GROUP_ITALICS = 1 << 2,
|
22
|
+
HOKU_GROUP_LINK = 1 << 3,
|
23
|
+
HOKU_GROUP_IMAGE = 1 << 4,
|
24
|
+
HOKU_GROUP_CODE = 1 << 5,
|
25
|
+
HOKU_GROUP_LIST_ITEM = 1 << 6
|
26
|
+
};
|
27
|
+
|
28
|
+
typedef struct HokuGroupLink
|
29
|
+
{
|
30
|
+
char* url;
|
31
|
+
} hoku_group_link;
|
32
|
+
|
33
|
+
typedef struct HokuGroupImage
|
34
|
+
{
|
35
|
+
char* src;
|
36
|
+
} hoku_group_image;
|
37
|
+
|
38
|
+
typedef struct HokuGroupCode
|
39
|
+
{
|
40
|
+
char* language;
|
41
|
+
} hoku_group_code;
|
42
|
+
|
43
|
+
typedef struct HokuGroupListItem
|
44
|
+
{
|
45
|
+
int level;
|
46
|
+
} hoku_group_list_item;
|
47
|
+
|
48
|
+
typedef struct HokuGroup
|
49
|
+
{
|
50
|
+
int offset;
|
51
|
+
int size;
|
52
|
+
enum HOKU_GROUP_TYPE type;
|
53
|
+
void* payload;
|
54
|
+
hoku_char* chars;
|
55
|
+
struct HokuGroup* next_group;
|
56
|
+
} hoku_group;
|
57
|
+
|
58
|
+
typedef struct HokuSegment
|
59
|
+
{
|
60
|
+
int offset;
|
61
|
+
int size;
|
62
|
+
int select_begin;
|
63
|
+
int select_end;
|
64
|
+
hoku_char* chars;
|
65
|
+
hoku_group* groups;
|
66
|
+
struct HokuSegment* next_segment;
|
67
|
+
} hoku_segment;
|
68
|
+
|
69
|
+
|
70
|
+
typedef int (*hoku_char_width_cb)(char character, void* payload);
|
71
|
+
|
72
|
+
typedef struct HokuClamping
|
73
|
+
{
|
74
|
+
char* text;
|
75
|
+
float width;
|
76
|
+
hoku_segment* segments;
|
77
|
+
} hoku_clamping;
|
78
|
+
|
79
|
+
int hoku_text_char_init(hoku_char** character, int offset, int width);
|
80
|
+
int hoku_text_group_init(hoku_group** group, int offset, enum HOKU_GROUP_TYPE type, void* payload);
|
81
|
+
int hoku_text_segment_init(hoku_segment** segment, int offset);
|
82
|
+
int hoku_text_clamping_init(hoku_clamping** clamping, char* text, float width);
|
83
|
+
hoku_char* hoku_text_segment_split(hoku_segment* segment, int at);
|
84
|
+
float hoku_text_char_sum(hoku_char* character);
|
85
|
+
void hoku_text_group_append_char(hoku_group* group, hoku_char* character);
|
86
|
+
int hoku_text_md_clamp(hoku_clamping** out, char* text, float width, float initial, void* payload, hoku_char_width_cb cb);
|
87
|
+
int hoku_text_clamp(hoku_clamping** out, char* text, float width, float initial, void* payload, hoku_char_width_cb cb);
|
88
|
+
void hoku_text_char_free(hoku_char* chars);
|
89
|
+
void hoku_text_segment_free(hoku_segment* segment);
|
90
|
+
void hoku_text_clamping_free(hoku_clamping* clamping);
|
91
|
+
|
92
|
+
|
93
|
+
#endif
|
data/ast/src/core/util.c
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
#ifndef HOKU_UTIL
|
2
|
+
#define HOKU_UTIL
|
3
|
+
|
4
|
+
#include "util.h"
|
5
|
+
|
6
|
+
bool hoku_rect_includes_y(hoku_rect rect, float y)
|
7
|
+
{
|
8
|
+
return y > rect.y && y <= (rect.y + rect.h);
|
9
|
+
}
|
10
|
+
|
11
|
+
bool hoku_rect_includes_x(hoku_rect rect, float x)
|
12
|
+
{
|
13
|
+
return x > rect.x && x <= (rect.x + rect.w);
|
14
|
+
}
|
15
|
+
|
16
|
+
float hoku_rect_x_left(hoku_rect rect, int times)
|
17
|
+
{
|
18
|
+
return (rect.x - ((rect.w / 2) * times));
|
19
|
+
}
|
20
|
+
float hoku_rect_x_right(hoku_rect rect, int times)
|
21
|
+
{
|
22
|
+
return (rect.x + ((rect.w / 2) * times));
|
23
|
+
}
|
24
|
+
|
25
|
+
float hoku_rect_y_up(hoku_rect rect, int times)
|
26
|
+
{
|
27
|
+
return (rect.y - ((rect.h / 2) * times));
|
28
|
+
}
|
29
|
+
|
30
|
+
float hoku_rect_y_down(hoku_rect rect, int times)
|
31
|
+
{
|
32
|
+
return (rect.y + ((rect.h / 2) * times));
|
33
|
+
}
|
34
|
+
|
35
|
+
int hoku_selection_init(hoku_selection** selection)
|
36
|
+
{
|
37
|
+
hoku_selection* init = malloc(sizeof(hoku_selection));
|
38
|
+
if (init == NULL)
|
39
|
+
{
|
40
|
+
return -1;
|
41
|
+
}
|
42
|
+
|
43
|
+
init->type = HOKU_SELECT_NONE;
|
44
|
+
init->start_x = 0.0;
|
45
|
+
init->start_y = 0.0;
|
46
|
+
init->stop_x = 0.0;
|
47
|
+
init->stop_y = 0.0;
|
48
|
+
init->offset_y = 0.0;
|
49
|
+
|
50
|
+
init->cursor = NULL;
|
51
|
+
|
52
|
+
*selection = init;
|
53
|
+
return 0;
|
54
|
+
}
|
55
|
+
|
56
|
+
bool hoku_selection_selected(hoku_selection* selection, float x, float y, float width, float height)
|
57
|
+
{
|
58
|
+
if (selection->type == HOKU_SELECT_NONE) return false;
|
59
|
+
|
60
|
+
float sx = selection->start_x;
|
61
|
+
float sy = selection->start_y;
|
62
|
+
float ex = selection->stop_x;
|
63
|
+
float ey = selection->stop_y;
|
64
|
+
|
65
|
+
bool down = selection->start_y <= selection->stop_y;
|
66
|
+
bool up = selection->stop_y < selection->start_y;
|
67
|
+
bool left = selection->stop_x < selection->start_x;
|
68
|
+
bool right = selection->start_x <= selection->stop_x;
|
69
|
+
|
70
|
+
hoku_rect hit_box = (hoku_rect){.x=x, .y=y, .w=width, .h=height};
|
71
|
+
float x_shifted_right = hoku_rect_x_right(hit_box, 1);
|
72
|
+
float y_shifted_up = hoku_rect_y_up(hit_box, 2);
|
73
|
+
float y_shifted_down = hoku_rect_y_down(hit_box, 2);
|
74
|
+
float end_y = y + height;
|
75
|
+
|
76
|
+
return (
|
77
|
+
(down &&
|
78
|
+
// first line of multiline selection
|
79
|
+
((x_shifted_right > sx && end_y < ey && hoku_rect_includes_y(hit_box, sy)) ||
|
80
|
+
// last line of multiline selection
|
81
|
+
(x_shifted_right <= ex && y_shifted_up + hit_box.h < ey && hit_box.y > sy) ||
|
82
|
+
// middle line (all selected)
|
83
|
+
(hit_box.y > sy && end_y < ey))) ||
|
84
|
+
(up &&
|
85
|
+
// first line of multiline selection
|
86
|
+
((x_shifted_right <= sx && hit_box.y > ey && hoku_rect_includes_y(hit_box, sy)) ||
|
87
|
+
// last line of multiline selection
|
88
|
+
(x_shifted_right >= ex && y_shifted_down > ey && end_y < sy) ||
|
89
|
+
// middle line (all selected)
|
90
|
+
(hit_box.y > ey && hit_box.y + hit_box.h < sy))) ||
|
91
|
+
// single line selection
|
92
|
+
((hoku_rect_includes_y(hit_box, sy) && hoku_rect_includes_y(hit_box, ey)) &&
|
93
|
+
((left && x_shifted_right < sx && x_shifted_right > ex) || (right && x_shifted_right > sx && x_shifted_right < ex)))
|
94
|
+
);
|
95
|
+
}
|
96
|
+
|
97
|
+
hoku_cursor_position hoku_selection_cursor_get(hoku_selection* selection)
|
98
|
+
{
|
99
|
+
if (selection->cursor == NULL) return (hoku_cursor_position){.x=0.0, .y=0.0, .w=0.0, .h=0.0 };
|
100
|
+
hoku_cursor_position pos = (hoku_cursor_position){ .x=selection->cursor->x, .y=selection->cursor->y, .w=selection->cursor->w, .h=selection->cursor->h };
|
101
|
+
|
102
|
+
if (selection->type == HOKU_SELECT_FROZEN)
|
103
|
+
{
|
104
|
+
pos.y = selection->offset_y;
|
105
|
+
return pos;
|
106
|
+
}
|
107
|
+
|
108
|
+
return pos;
|
109
|
+
}
|
110
|
+
|
111
|
+
int hoku_selection_cursor_set(hoku_selection* selection, hoku_cursor_position cursor)
|
112
|
+
{
|
113
|
+
if (selection->cursor == NULL)
|
114
|
+
{
|
115
|
+
selection->cursor = malloc(sizeof(hoku_cursor_position));
|
116
|
+
|
117
|
+
if (selection->cursor == NULL) return -1;
|
118
|
+
}
|
119
|
+
|
120
|
+
selection->cursor->x = cursor.x;
|
121
|
+
selection->cursor->y = cursor.y;
|
122
|
+
selection->cursor->w = cursor.w;
|
123
|
+
selection->cursor->h = cursor.h;
|
124
|
+
|
125
|
+
return 0;
|
126
|
+
}
|
127
|
+
|
128
|
+
void hoku_selection_cursor_free(hoku_selection* selection)
|
129
|
+
{
|
130
|
+
if (selection->cursor != NULL) free(selection->cursor);
|
131
|
+
selection->cursor = NULL;
|
132
|
+
}
|
133
|
+
|
134
|
+
void hoku_selection_free(hoku_selection* selection)
|
135
|
+
{
|
136
|
+
hoku_selection_cursor_free(selection);
|
137
|
+
free(selection);
|
138
|
+
}
|
139
|
+
|
140
|
+
#endif
|
data/ast/src/core/util.h
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#ifndef HOKU_UTIL_H
|
2
|
+
#define HOKU_UTIL_H
|
3
|
+
|
4
|
+
#include "common.h"
|
5
|
+
#include <stdbool.h>
|
6
|
+
#include <stdlib.h>
|
7
|
+
|
8
|
+
typedef enum HokuSelectType {
|
9
|
+
HOKU_SELECT_ACTIVE = 1 << 1,
|
10
|
+
HOKU_SELECT_FROZEN = 1 << 2,
|
11
|
+
HOKU_SELECT_NONE = 1 << 3
|
12
|
+
} hoku_select_type;
|
13
|
+
|
14
|
+
typedef struct HokuSelectionCursorPosition
|
15
|
+
{
|
16
|
+
float x;
|
17
|
+
float y;
|
18
|
+
float w;
|
19
|
+
float h;
|
20
|
+
} hoku_cursor_position;
|
21
|
+
|
22
|
+
typedef struct HokuSelection
|
23
|
+
{
|
24
|
+
hoku_select_type type;
|
25
|
+
float start_x;
|
26
|
+
float start_y;
|
27
|
+
float stop_x;
|
28
|
+
float stop_y;
|
29
|
+
float offset_y;
|
30
|
+
hoku_cursor_position* cursor;
|
31
|
+
} hoku_selection;
|
32
|
+
|
33
|
+
bool hoku_rect_includes_y(hoku_rect rect, float y);
|
34
|
+
bool hoku_rect_includes_x(hoku_rect rect, float x);
|
35
|
+
float hoku_rect_x_left(hoku_rect rect, int times);
|
36
|
+
float hoku_rect_x_right(hoku_rect rect, int times);
|
37
|
+
float hoku_rect_y_up(hoku_rect rect, int times);
|
38
|
+
float hoku_rect_y_down(hoku_rect rect, int times);
|
39
|
+
|
40
|
+
int hoku_selection_init(hoku_selection** selection);
|
41
|
+
bool hoku_selection_selected(hoku_selection* selection, float x, float y, float width, float height);
|
42
|
+
int hoku_selection_cursor_set(hoku_selection* selection, hoku_cursor_position cursor);
|
43
|
+
void hoku_selection_cursor_free(hoku_selection* selection);
|
44
|
+
void hoku_selection_free(hoku_selection* selection);
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
#endif
|
data/ast/src/hokusai.c
ADDED
data/ast/src/hokusai.h
ADDED