xbintsc 0.5.31 → 0.5.32
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/README.md +16 -10
- package/dist/src/binder/references.js +14 -1
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/codegen/generator/module.d.ts +1 -0
- package/dist/src/codegen/generator/module.js +54 -0
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/statements/variables.js +6 -4
- package/dist/src/codegen/generator/statements/variables.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/gui/css.d.ts +26 -0
- package/dist/src/extensions/gui/css.js +100 -0
- package/dist/src/extensions/gui/css.js.map +1 -0
- package/dist/src/extensions/gui/html.js +9 -2
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +16 -2
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/gui/three.d.ts +16 -0
- package/dist/src/extensions/gui/three.js +22 -0
- package/dist/src/extensions/gui/three.js.map +1 -0
- package/dist/src/extensions/media/index.d.ts +6 -5
- package/dist/src/extensions/media/index.js +12 -14
- package/dist/src/extensions/media/index.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +24 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js +23 -0
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +1 -1
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-effects.test.d.ts +6 -0
- package/dist/tests/e2e/gui-effects.test.js +262 -0
- package/dist/tests/e2e/gui-effects.test.js.map +1 -0
- package/dist/tests/e2e/gui-example-webgl.test.d.ts +10 -0
- package/dist/tests/e2e/gui-example-webgl.test.js +75 -0
- package/dist/tests/e2e/gui-example-webgl.test.js.map +1 -0
- package/dist/tests/e2e/gui-example-webgl2.test.d.ts +8 -0
- package/dist/tests/e2e/gui-example-webgl2.test.js +72 -0
- package/dist/tests/e2e/gui-example-webgl2.test.js.map +1 -0
- package/dist/tests/e2e/gui-layout.test.js +48 -0
- package/dist/tests/e2e/gui-layout.test.js.map +1 -1
- package/dist/tests/e2e/gui-media.test.js +5 -4
- package/dist/tests/e2e/gui-media.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl.test.js +179 -0
- package/dist/tests/e2e/gui-webgl.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2.test.js +238 -0
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -0
- package/dist/tests/extensions/gui.test.js +41 -0
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/extensions/media.test.js +7 -3
- package/dist/tests/extensions/media.test.js.map +1 -1
- package/doc/ai/extensions.md +29 -9
- package/doc/ai/troubleshooting.md +12 -8
- package/doc/ai/zh-CN/extensions.md +26 -8
- package/doc/ai/zh-CN/troubleshooting.md +10 -6
- package/doc/gui/api.md +3 -2
- package/doc/gui/build.md +72 -16
- package/doc/gui/canvas.md +11 -3
- package/doc/gui/dom.md +33 -18
- package/doc/gui/known-issues.md +57 -24
- package/doc/gui/layout.md +18 -0
- package/doc/gui/media.md +17 -13
- package/doc/gui/rendering.md +50 -3
- package/doc/gui/webgl.md +256 -0
- package/doc/gui.md +108 -17
- package/doc/npm-package.md +6 -4
- package/doc/requirements.md +18 -9
- package/doc/zh-CN/gui/api.md +3 -2
- package/doc/zh-CN/gui/build.md +64 -15
- package/doc/zh-CN/gui/canvas.md +9 -2
- package/doc/zh-CN/gui/dom.md +20 -7
- package/doc/zh-CN/gui/known-issues.md +45 -19
- package/doc/zh-CN/gui/layout.md +14 -0
- package/doc/zh-CN/gui/media.md +15 -11
- package/doc/zh-CN/gui/rendering.md +41 -4
- package/doc/zh-CN/gui/webgl.md +115 -0
- package/doc/zh-CN/gui.md +89 -14
- package/doc/zh-CN/npm-package.md +9 -6
- package/doc/zh-CN/requirements.md +12 -6
- package/llms.txt +2 -0
- package/package.json +1 -1
- package/runtime/ext_gui/browser.cpp +39 -13
- package/runtime/ext_gui/canvas.cpp +3 -18
- package/runtime/ext_gui/canvas_internal.h +10 -0
- package/runtime/ext_gui/canvas_raster.cpp +60 -0
- package/runtime/ext_gui/clip_values.cpp +246 -0
- package/runtime/ext_gui/css.cpp +94 -0
- package/runtime/ext_gui/css.h +22 -1
- package/runtime/ext_gui/css_match.cpp +3 -0
- package/runtime/ext_gui/css_selector.cpp +9 -0
- package/runtime/ext_gui/css_sheet.cpp +89 -45
- package/runtime/ext_gui/document.cpp +4 -1
- package/runtime/ext_gui/document.h +2 -0
- package/runtime/ext_gui/dom.h +16 -0
- package/runtime/ext_gui/dom_api.cpp +1 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +17 -80
- package/runtime/ext_gui/dom_api_canvas_extra.cpp +130 -1
- package/runtime/ext_gui/dom_api_canvas_pending.cpp +41 -0
- package/runtime/ext_gui/dom_api_internal.h +259 -0
- package/runtime/ext_gui/dom_api_webgl.cpp +376 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +434 -0
- package/runtime/ext_gui/dom_api_webgl2_draw.cpp +269 -0
- package/runtime/ext_gui/dom_api_webgl_buffer.cpp +212 -0
- package/runtime/ext_gui/dom_api_webgl_rt.h +30 -0
- package/runtime/ext_gui/dom_api_webgl_shader.cpp +443 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +444 -0
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +445 -0
- package/runtime/ext_gui/effect_values.cpp +312 -0
- package/runtime/ext_gui/gradient_values.cpp +476 -0
- package/runtime/ext_gui/grid_values.cpp +230 -0
- package/runtime/ext_gui/gui_canvas.cpp +50 -2
- package/runtime/ext_gui/gui_engine.h +27 -0
- package/runtime/ext_gui/gui_events.cpp +4 -1
- package/runtime/ext_gui/gui_media.cpp +1 -1
- package/runtime/ext_gui/gui_webgl.cpp +83 -0
- package/runtime/ext_gui/layout.cpp +21 -0
- package/runtime/ext_gui/layout_flow.cpp +81 -4
- package/runtime/ext_gui/layout_flow_internal.h +31 -0
- package/runtime/ext_gui/layout_grid.cpp +374 -0
- package/runtime/ext_gui/media.h +1 -1
- package/runtime/ext_gui/media_api.h +2 -2
- package/runtime/ext_gui/media_query.cpp +211 -0
- package/runtime/ext_gui/paint.cpp +111 -77
- package/runtime/ext_gui/paint.h +33 -3
- package/runtime/ext_gui/paint_background.cpp +229 -0
- package/runtime/ext_gui/paint_clip.cpp +268 -0
- package/runtime/ext_gui/paint_effects.cpp +324 -0
- package/runtime/ext_gui/paint_internal.h +85 -0
- package/runtime/ext_gui/renderer.cpp +8 -31
- package/runtime/ext_gui/renderer_clip.cpp +196 -0
- package/runtime/ext_gui/renderer_image.cpp +13 -8
- package/runtime/ext_gui/renderer_internal.h +15 -8
- package/runtime/ext_gui/renderer_text.cpp +6 -31
- package/runtime/ext_gui/style.cpp +343 -20
- package/runtime/ext_gui/style.h +144 -3
- package/runtime/ext_gui/style_print.cpp +134 -1
- package/runtime/ext_gui/style_values.cpp +152 -126
- package/runtime/ext_gui/style_values_internal.h +35 -0
- package/runtime/ext_gui/webgl.h +466 -0
- package/runtime/ext_gui/webgl2_constants.h +274 -0
- package/runtime/ext_gui/webgl_buffer.cpp +565 -0
- package/runtime/ext_gui/webgl_constants.h +317 -0
- package/runtime/ext_gui/webgl_context.cpp +466 -0
- package/runtime/ext_gui/webgl_draw.cpp +495 -0
- package/runtime/ext_gui/webgl_glsl.h +125 -0
- package/runtime/ext_gui/webgl_glsl_compile.cpp +431 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +349 -0
- package/runtime/ext_gui/webgl_glsl_scan.cpp +581 -0
- package/runtime/ext_gui/webgl_msl.cpp +62 -0
- package/runtime/ext_gui/webgl_msl.h +33 -0
- package/runtime/ext_gui/webgl_pipeline.cpp +274 -0
- package/runtime/ext_gui/webgl_program_internal.h +18 -0
- package/runtime/ext_gui/webgl_shader.cpp +582 -0
- package/runtime/ext_gui/webgl_texture.cpp +293 -0
- package/runtime/ext_gui/webgl_uniform.cpp +167 -0
- package/runtime/ext_gui/webgl_webgl2.cpp +224 -0
- package/runtime/ext_media/media.cpp +1 -1
- package/runtime/ext_media/media_bridge.c +9 -3
- package/runtime/rt_internal.h +1 -0
- package/runtime/xt_containers/access.inc +8 -0
- package/runtime/xt_regex/api.inc +2 -0
- package/runtime/xt_regex/matcher.inc +16 -3
- package/runtime/xt_regex/parser.inc +8 -2
- package/runtime/xt_regex/types.inc +3 -0
- package/runtime/xt_stdlib2/regexp-match.inc +60 -21
- package/runtime/xt_stdlib2/regexp.inc +1 -0
- package/runtime/xt_typed_array.c +1 -1
- package/scripts/build-gui.ts +90 -3
- package/scripts/build-media.ts +323 -58
- package/scripts/setup-vs-toolchain.ps1 +152 -0
- package/src/binder/references.ts +13 -1
- package/src/codegen/generator/module.ts +50 -0
- package/src/codegen/generator/statements/variables.ts +6 -3
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/css.ts +113 -0
- package/src/extensions/gui/html.ts +9 -2
- package/src/extensions/gui/index.ts +16 -2
- package/src/extensions/gui/three.ts +25 -0
- package/src/extensions/media/index.ts +13 -16
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — CSS transition declarations.
|
|
3
|
+
*
|
|
4
|
+
* Kept apart from `style_values.cpp` so the declaration dispatcher stays under
|
|
5
|
+
* the repository's per-file line budget.
|
|
6
|
+
*/
|
|
7
|
+
#include <cctype>
|
|
8
|
+
#include <cmath>
|
|
9
|
+
#include <cstdlib>
|
|
10
|
+
#include <cstring>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
#include "css_internal.h"
|
|
15
|
+
#include "style_internal.h"
|
|
16
|
+
#include "style_values_internal.h"
|
|
17
|
+
|
|
18
|
+
namespace xtgui {
|
|
19
|
+
|
|
20
|
+
/* -- transitions ---------------------------------------------------------- */
|
|
21
|
+
|
|
22
|
+
static bool parseTimeSeconds(const std::string &text, float *out) {
|
|
23
|
+
std::string token = xt_css_trim(text);
|
|
24
|
+
if (token.empty()) return false;
|
|
25
|
+
const char *begin = token.c_str();
|
|
26
|
+
char *end = nullptr;
|
|
27
|
+
double value = std::strtod(begin, &end);
|
|
28
|
+
if (end == begin) return false;
|
|
29
|
+
std::string unit = xt_css_lower(xt_css_trim(std::string(end)));
|
|
30
|
+
if (unit == "ms") {
|
|
31
|
+
*out = (float)(value / 1000.0);
|
|
32
|
+
} else if (unit.empty() || unit == "s") {
|
|
33
|
+
*out = (float)value;
|
|
34
|
+
} else {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static bool parseTimingFunction(const std::string &text, TimingFunction *out) {
|
|
41
|
+
std::string token = xt_css_lower(xt_css_trim(text));
|
|
42
|
+
if (token == "linear") {
|
|
43
|
+
*out = TimingFunction::Linear;
|
|
44
|
+
} else if (token == "ease") {
|
|
45
|
+
*out = TimingFunction::Ease;
|
|
46
|
+
} else if (token == "ease-in") {
|
|
47
|
+
*out = TimingFunction::EaseIn;
|
|
48
|
+
} else if (token == "ease-out") {
|
|
49
|
+
*out = TimingFunction::EaseOut;
|
|
50
|
+
} else if (token == "ease-in-out") {
|
|
51
|
+
*out = TimingFunction::EaseInOut;
|
|
52
|
+
} else {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static std::vector<std::string> splitCommas(const std::string &text) {
|
|
59
|
+
std::vector<std::string> parts;
|
|
60
|
+
size_t start = 0;
|
|
61
|
+
for (size_t i = 0; i <= text.size(); i++) {
|
|
62
|
+
if (i == text.size() || text[i] == ',') {
|
|
63
|
+
std::string part = xt_css_trim(text.substr(start, i - start));
|
|
64
|
+
if (!part.empty()) parts.push_back(part);
|
|
65
|
+
start = i + 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return parts;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static void parseTransitionShorthand(const std::string &value, std::vector<TransitionSpec> *out) {
|
|
72
|
+
out->clear();
|
|
73
|
+
for (const std::string &group : splitCommas(value)) {
|
|
74
|
+
std::vector<std::string> tokens = xt_css_split_whitespace(group);
|
|
75
|
+
if (tokens.empty()) continue;
|
|
76
|
+
TransitionSpec spec;
|
|
77
|
+
int time_seen = 0;
|
|
78
|
+
for (const std::string &token : tokens) {
|
|
79
|
+
float seconds = 0;
|
|
80
|
+
TimingFunction timing = TimingFunction::Ease;
|
|
81
|
+
if (parseTimeSeconds(token, &seconds)) {
|
|
82
|
+
if (time_seen == 0) {
|
|
83
|
+
spec.duration = seconds;
|
|
84
|
+
} else {
|
|
85
|
+
spec.delay = seconds;
|
|
86
|
+
}
|
|
87
|
+
time_seen++;
|
|
88
|
+
} else if (parseTimingFunction(token, &timing)) {
|
|
89
|
+
spec.timing = timing;
|
|
90
|
+
} else {
|
|
91
|
+
spec.property = xt_css_lower(token);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
out->push_back(spec);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
/* -- filters, shadows and generated content -------------------------------- */
|
|
100
|
+
|
|
101
|
+
/** Split on whitespace outside function parentheses (`rgb(1, 2, 3)` stays one). */
|
|
102
|
+
static std::vector<std::string> splitShadowTokens(const std::string &text) {
|
|
103
|
+
std::vector<std::string> parts;
|
|
104
|
+
std::string current;
|
|
105
|
+
int depth = 0;
|
|
106
|
+
for (char c : text) {
|
|
107
|
+
if (c == '(') depth++;
|
|
108
|
+
if (c == ')') depth--;
|
|
109
|
+
if ((c == ' ' || c == '\t' || c == '\n' || c == '\r') && depth == 0) {
|
|
110
|
+
if (!current.empty()) {
|
|
111
|
+
parts.push_back(current);
|
|
112
|
+
current.clear();
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
current.push_back(c);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!current.empty()) parts.push_back(current);
|
|
119
|
+
return parts;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static bool parseFilterAmount(const std::string &raw, float *out) {
|
|
123
|
+
std::string text = xt_css_trim(raw);
|
|
124
|
+
bool percent = !text.empty() && text.back() == '%';
|
|
125
|
+
if (percent) text.pop_back();
|
|
126
|
+
float number = 0;
|
|
127
|
+
if (!xt_css_parse_number(text, &number)) return false;
|
|
128
|
+
*out = percent ? number / 100.0f : number;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static bool parseAngleDegrees(const std::string &raw, float *out) {
|
|
133
|
+
std::string text = xt_css_lower(xt_css_trim(raw));
|
|
134
|
+
struct Unit {
|
|
135
|
+
const char *suffix;
|
|
136
|
+
float scale;
|
|
137
|
+
};
|
|
138
|
+
static const Unit units[] = {{"deg", 1.0f}, {"grad", 0.9f}, {"rad", 57.2957795f},
|
|
139
|
+
{"turn", 360.0f}};
|
|
140
|
+
for (const Unit &unit : units) {
|
|
141
|
+
size_t length = std::strlen(unit.suffix);
|
|
142
|
+
if (text.size() <= length || text.compare(text.size() - length, length, unit.suffix) != 0)
|
|
143
|
+
continue;
|
|
144
|
+
float number = 0;
|
|
145
|
+
if (!xt_css_parse_number(text.substr(0, text.size() - length), &number)) return false;
|
|
146
|
+
*out = number * unit.scale;
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (xt_css_parse_number(text, out)) return true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static bool parseShadowLengths(const std::string &value, Length *dx, Length *dy, Length *blur,
|
|
154
|
+
Color *color, bool *hasColor) {
|
|
155
|
+
std::vector<std::string> tokens = splitShadowTokens(value);
|
|
156
|
+
Length lengths[3];
|
|
157
|
+
size_t count = 0;
|
|
158
|
+
for (const std::string &token : tokens) {
|
|
159
|
+
Length length = xt_css_parse_length(token);
|
|
160
|
+
if (length.unit != Unit::Invalid && length.unit != Unit::Auto && length.unit != Unit::None) {
|
|
161
|
+
if (count < 3) lengths[count++] = length;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
Color parsed = xt_css_parse_color(token);
|
|
165
|
+
if (parsed.valid) {
|
|
166
|
+
*color = parsed;
|
|
167
|
+
*hasColor = true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (count < 2) return false;
|
|
171
|
+
*dx = lengths[0];
|
|
172
|
+
*dy = lengths[1];
|
|
173
|
+
*blur = count > 2 ? lengths[2] : Length{0.0f, Unit::Px};
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static bool parseFilterList(const std::string &value, std::vector<FilterOp> *out) {
|
|
178
|
+
std::string text = xt_css_trim(value);
|
|
179
|
+
std::string lower = xt_css_lower(text);
|
|
180
|
+
if (lower == "none" || text.empty()) {
|
|
181
|
+
out->clear();
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
out->clear();
|
|
185
|
+
size_t i = 0;
|
|
186
|
+
while (i < text.size()) {
|
|
187
|
+
while (i < text.size() &&
|
|
188
|
+
(xt_is_css_space(text[i]) || text[i] == ','))
|
|
189
|
+
i++;
|
|
190
|
+
size_t nameStart = i;
|
|
191
|
+
while (i < text.size() && (std::isalpha((unsigned char)text[i]) || text[i] == '-')) i++;
|
|
192
|
+
if (i == nameStart) break;
|
|
193
|
+
std::string name = xt_css_lower(text.substr(nameStart, i - nameStart));
|
|
194
|
+
while (i < text.size() && xt_is_css_space(text[i])) i++;
|
|
195
|
+
if (i >= text.size() || text[i] != '(') break;
|
|
196
|
+
int depth = 0;
|
|
197
|
+
size_t open = i;
|
|
198
|
+
size_t close = std::string::npos;
|
|
199
|
+
for (; i < text.size(); i++) {
|
|
200
|
+
if (text[i] == '(') depth++;
|
|
201
|
+
else if (text[i] == ')') {
|
|
202
|
+
depth--;
|
|
203
|
+
if (depth == 0) {
|
|
204
|
+
close = i;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (close == std::string::npos) break;
|
|
210
|
+
std::string args = xt_css_trim(text.substr(open + 1, close - open - 1));
|
|
211
|
+
i = close + 1;
|
|
212
|
+
|
|
213
|
+
FilterOp op;
|
|
214
|
+
bool known = true;
|
|
215
|
+
if (name == "blur") {
|
|
216
|
+
op.kind = FilterKind::Blur;
|
|
217
|
+
Length length = xt_css_parse_length(args);
|
|
218
|
+
if (length.unit == Unit::Invalid) known = false;
|
|
219
|
+
else op.blur = length;
|
|
220
|
+
} else if (name == "drop-shadow") {
|
|
221
|
+
op.kind = FilterKind::DropShadow;
|
|
222
|
+
if (!parseShadowLengths(args, &op.dx, &op.dy, &op.blur, &op.color, &op.has_color))
|
|
223
|
+
known = false;
|
|
224
|
+
} else if (name == "hue-rotate") {
|
|
225
|
+
op.kind = FilterKind::HueRotate;
|
|
226
|
+
if (!parseAngleDegrees(args, &op.amount)) known = false;
|
|
227
|
+
} else {
|
|
228
|
+
if (name == "brightness") op.kind = FilterKind::Brightness;
|
|
229
|
+
else if (name == "contrast") op.kind = FilterKind::Contrast;
|
|
230
|
+
else if (name == "grayscale") op.kind = FilterKind::Grayscale;
|
|
231
|
+
else if (name == "sepia") op.kind = FilterKind::Sepia;
|
|
232
|
+
else if (name == "invert") op.kind = FilterKind::Invert;
|
|
233
|
+
else if (name == "saturate") op.kind = FilterKind::Saturate;
|
|
234
|
+
else if (name == "opacity") op.kind = FilterKind::Opacity;
|
|
235
|
+
else known = false;
|
|
236
|
+
if (known && !parseFilterAmount(args, &op.amount)) known = false;
|
|
237
|
+
}
|
|
238
|
+
if (known) out->push_back(op);
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static bool parseTextShadow(const std::string &value, std::vector<TextShadow> *out) {
|
|
244
|
+
std::string text = xt_css_trim(value);
|
|
245
|
+
std::string lower = xt_css_lower(text);
|
|
246
|
+
out->clear();
|
|
247
|
+
if (lower == "none" || text.empty()) return true;
|
|
248
|
+
for (const std::string &part : splitCommas(value)) {
|
|
249
|
+
TextShadow shadow;
|
|
250
|
+
if (!parseShadowLengths(part, &shadow.dx, &shadow.dy, &shadow.blur, &shadow.color,
|
|
251
|
+
&shadow.has_color))
|
|
252
|
+
return false;
|
|
253
|
+
out->push_back(shadow);
|
|
254
|
+
}
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
bool xt_style_apply_effect(XtStyle *style, const std::string &property,
|
|
259
|
+
const std::string &value) {
|
|
260
|
+
if (property == "filter") return parseFilterList(value, &style->filters);
|
|
261
|
+
if (property == "backdrop-filter") return parseFilterList(value, &style->backdrop_filters);
|
|
262
|
+
if (property == "text-shadow") return parseTextShadow(value, &style->text_shadow);
|
|
263
|
+
if (property == "content") {
|
|
264
|
+
std::string text = xt_css_lower(xt_css_trim(value));
|
|
265
|
+
if (text == "none" || text == "normal") {
|
|
266
|
+
style->has_content = false;
|
|
267
|
+
style->content.clear();
|
|
268
|
+
} else {
|
|
269
|
+
style->has_content = true;
|
|
270
|
+
style->content = xt_css_trim(value);
|
|
271
|
+
}
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
bool xt_style_apply_transition(XtStyle *style, const std::string &property,
|
|
278
|
+
const std::string &value) {
|
|
279
|
+
if (property == "transition") {
|
|
280
|
+
parseTransitionShorthand(value, &style->transitions);
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
if (property == "transition-property") {
|
|
284
|
+
std::vector<std::string> parts = splitCommas(value);
|
|
285
|
+
style->transitions.resize(parts.size());
|
|
286
|
+
for (size_t i = 0; i < parts.size(); i++) style->transitions[i].property = xt_css_lower(parts[i]);
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
if (property == "transition-duration" || property == "transition-delay") {
|
|
290
|
+
std::vector<std::string> parts = splitCommas(value);
|
|
291
|
+
style->transitions.resize(parts.size());
|
|
292
|
+
for (size_t i = 0; i < parts.size(); i++) {
|
|
293
|
+
float seconds = 0;
|
|
294
|
+
if (!parseTimeSeconds(parts[i], &seconds)) continue;
|
|
295
|
+
if (property == "transition-duration") style->transitions[i].duration = seconds;
|
|
296
|
+
else style->transitions[i].delay = seconds;
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
if (property == "transition-timing-function") {
|
|
301
|
+
std::vector<std::string> parts = splitCommas(value);
|
|
302
|
+
style->transitions.resize(parts.size());
|
|
303
|
+
for (size_t i = 0; i < parts.size(); i++) {
|
|
304
|
+
TimingFunction timing = TimingFunction::Ease;
|
|
305
|
+
if (parseTimingFunction(parts[i], &timing)) style->transitions[i].timing = timing;
|
|
306
|
+
}
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
} // namespace xtgui
|