show(), hide(), visible. font-light, normal, medium, semibold, bold, extrabold, black. protocol connection pooling. fetch() with GURT. DNS from HTTP to GURT.
This commit is contained in:
@@ -14,9 +14,14 @@ static func apply_flex_container_properties(node, styles: Dictionary) -> void:
|
||||
# Flex wrap
|
||||
if styles.has("flex-wrap"):
|
||||
match styles["flex-wrap"]:
|
||||
"nowrap": node.flex_wrap = FlexContainer.FlexWrap.NoWrap
|
||||
"wrap": node.flex_wrap = FlexContainer.FlexWrap.Wrap
|
||||
"wrap-reverse": node.flex_wrap = FlexContainer.FlexWrap.WrapReverse
|
||||
"nowrap":
|
||||
node.flex_wrap = FlexContainer.FlexWrap.NoWrap
|
||||
"wrap":
|
||||
node.flex_wrap = FlexContainer.FlexWrap.Wrap
|
||||
# this is probably not needed but i dont feel like testing it
|
||||
node.flex_property_changed("flex_wrap", FlexContainer.FlexWrap.Wrap)
|
||||
"wrap-reverse":
|
||||
node.flex_wrap = FlexContainer.FlexWrap.WrapReverse
|
||||
# Justify content
|
||||
if styles.has("justify-content"):
|
||||
match styles["justify-content"]:
|
||||
|
||||
@@ -195,6 +195,13 @@ static func trigger_element_restyle(element: HTMLParser.HTMLElement, dom_parser:
|
||||
var dom_node = dom_parser.parse_result.dom_nodes.get(element_id, null)
|
||||
if not dom_node:
|
||||
return
|
||||
|
||||
# Check if element has the "hidden" class before styling
|
||||
var has_hidden_class = false
|
||||
var current_style = element.get_attribute("style", "")
|
||||
if current_style.length() > 0:
|
||||
var style_classes = CSSParser.smart_split_utility_classes(current_style)
|
||||
has_hidden_class = "hidden" in style_classes
|
||||
|
||||
# margins, wrappers, etc.
|
||||
var updated_dom_node = StyleManager.apply_element_styles(dom_node, element, dom_parser)
|
||||
@@ -204,9 +211,15 @@ static func trigger_element_restyle(element: HTMLParser.HTMLElement, dom_parser:
|
||||
dom_parser.parse_result.dom_nodes[element_id] = updated_dom_node
|
||||
dom_node = updated_dom_node
|
||||
|
||||
# Apply visibility state to the correct node (wrapper or content)
|
||||
if has_hidden_class:
|
||||
dom_node.visible = false
|
||||
else:
|
||||
dom_node.visible = true
|
||||
|
||||
# Find node
|
||||
var actual_element_node = dom_node
|
||||
if dom_node is MarginContainer and dom_node.name.begins_with("MarginWrapper_"):
|
||||
if dom_node is MarginContainer and dom_node.has_meta("is_margin_wrapper"):
|
||||
if dom_node.get_child_count() > 0:
|
||||
actual_element_node = dom_node.get_child(0)
|
||||
|
||||
@@ -223,7 +236,7 @@ static func trigger_element_restyle(element: HTMLParser.HTMLElement, dom_parser:
|
||||
static func update_element_text_content(dom_node: Control, element: HTMLParser.HTMLElement, dom_parser: HTMLParser) -> void:
|
||||
# Get node
|
||||
var content_node = dom_node
|
||||
if dom_node is MarginContainer and dom_node.name.begins_with("MarginWrapper_"):
|
||||
if dom_node is MarginContainer and dom_node.has_meta("is_margin_wrapper"):
|
||||
if dom_node.get_child_count() > 0:
|
||||
content_node = dom_node.get_child(0)
|
||||
|
||||
|
||||
@@ -515,6 +515,12 @@ static func add_element_methods(vm: LuauVM, lua_api: LuaAPI) -> void:
|
||||
vm.lua_pushcallable(LuaDOMUtils._element_create_tween_wrapper, "element.createTween")
|
||||
vm.lua_setfield(-2, "createTween")
|
||||
|
||||
vm.lua_pushcallable(LuaDOMUtils._element_show_wrapper, "element.show")
|
||||
vm.lua_setfield(-2, "show")
|
||||
|
||||
vm.lua_pushcallable(LuaDOMUtils._element_hide_wrapper, "element.hide")
|
||||
vm.lua_setfield(-2, "hide")
|
||||
|
||||
_add_classlist_support(vm, lua_api)
|
||||
|
||||
vm.lua_newtable()
|
||||
@@ -881,6 +887,24 @@ static func _element_index_wrapper(vm: LuauVM) -> int:
|
||||
# Fallback to empty array
|
||||
vm.lua_newtable()
|
||||
return 1
|
||||
"visible":
|
||||
if lua_api:
|
||||
# Get element ID and find the element
|
||||
vm.lua_getfield(1, "_element_id")
|
||||
var element_id: String = vm.lua_tostring(-1)
|
||||
vm.lua_pop(1)
|
||||
|
||||
var element = lua_api.dom_parser.find_by_id(element_id) if element_id != "body" else lua_api.dom_parser.find_first("body")
|
||||
if element:
|
||||
# Check if element has display: none (hidden class)
|
||||
var class_attr = element.get_attribute("class")
|
||||
var is_hidden = "hidden" in class_attr or element.get_attribute("style").contains("display:none") or element.get_attribute("style").contains("display: none")
|
||||
vm.lua_pushboolean(not is_hidden)
|
||||
return 1
|
||||
|
||||
# Fallback to true (visible by default)
|
||||
vm.lua_pushboolean(true)
|
||||
return 1
|
||||
_:
|
||||
# Check for DOM traversal properties first
|
||||
if lua_api:
|
||||
@@ -1034,6 +1058,48 @@ static func _element_newindex_wrapper(vm: LuauVM) -> int:
|
||||
|
||||
emit_dom_operation(lua_api, operation)
|
||||
return 0
|
||||
"visible":
|
||||
var is_visible: bool = vm.lua_toboolean(3)
|
||||
|
||||
vm.lua_getfield(1, "_element_id")
|
||||
var element_id: String = vm.lua_tostring(-1)
|
||||
vm.lua_pop(1)
|
||||
|
||||
var element = lua_api.dom_parser.find_by_id(element_id) if element_id != "body" else lua_api.dom_parser.find_first("body")
|
||||
if element:
|
||||
var class_attr = element.get_attribute("class")
|
||||
var classes = class_attr.split(" ") if not class_attr.is_empty() else []
|
||||
|
||||
if is_visible:
|
||||
# Remove hidden class if present
|
||||
var hidden_index = classes.find("hidden")
|
||||
if hidden_index >= 0:
|
||||
classes.remove_at(hidden_index)
|
||||
var new_class_attr = " ".join(classes).strip_edges()
|
||||
element.set_attribute("class", new_class_attr)
|
||||
|
||||
# Update visual element
|
||||
var operation = {
|
||||
"type": "remove_class",
|
||||
"element_id": element_id,
|
||||
"class_name": "hidden"
|
||||
}
|
||||
emit_dom_operation(lua_api, operation)
|
||||
else:
|
||||
# Add hidden class if not present
|
||||
if not "hidden" in classes:
|
||||
classes.append("hidden")
|
||||
var new_class_attr = " ".join(classes).strip_edges()
|
||||
element.set_attribute("class", new_class_attr)
|
||||
|
||||
# Update visual element
|
||||
var operation = {
|
||||
"type": "add_class",
|
||||
"element_id": element_id,
|
||||
"class_name": "hidden"
|
||||
}
|
||||
emit_dom_operation(lua_api, operation)
|
||||
return 0
|
||||
_:
|
||||
# Store in table normally
|
||||
vm.lua_pushvalue(2)
|
||||
@@ -1041,6 +1107,71 @@ static func _element_newindex_wrapper(vm: LuauVM) -> int:
|
||||
vm.lua_rawset(1)
|
||||
return 0
|
||||
|
||||
static func _element_show_wrapper(vm: LuauVM) -> int:
|
||||
var lua_api = vm.get_meta("lua_api") as LuaAPI
|
||||
if not lua_api:
|
||||
return 0
|
||||
|
||||
vm.luaL_checktype(1, vm.LUA_TTABLE)
|
||||
|
||||
vm.lua_getfield(1, "_element_id")
|
||||
var element_id: String = vm.lua_tostring(-1)
|
||||
vm.lua_pop(1)
|
||||
|
||||
var element = lua_api.dom_parser.find_by_id(element_id) if element_id != "body" else lua_api.dom_parser.find_first("body")
|
||||
if element:
|
||||
var class_attr = element.get_attribute("class")
|
||||
var classes = class_attr.split(" ") if not class_attr.is_empty() else []
|
||||
|
||||
# Remove hidden class if present
|
||||
var hidden_index = classes.find("hidden")
|
||||
if hidden_index >= 0:
|
||||
classes.remove_at(hidden_index)
|
||||
var new_class_attr = " ".join(classes).strip_edges()
|
||||
element.set_attribute("class", new_class_attr)
|
||||
|
||||
# Update visual element
|
||||
var operation = {
|
||||
"type": "remove_class",
|
||||
"element_id": element_id,
|
||||
"class_name": "hidden"
|
||||
}
|
||||
emit_dom_operation(lua_api, operation)
|
||||
|
||||
return 0
|
||||
|
||||
static func _element_hide_wrapper(vm: LuauVM) -> int:
|
||||
var lua_api = vm.get_meta("lua_api") as LuaAPI
|
||||
if not lua_api:
|
||||
return 0
|
||||
|
||||
vm.luaL_checktype(1, vm.LUA_TTABLE)
|
||||
|
||||
vm.lua_getfield(1, "_element_id")
|
||||
var element_id: String = vm.lua_tostring(-1)
|
||||
vm.lua_pop(1)
|
||||
|
||||
var element = lua_api.dom_parser.find_by_id(element_id) if element_id != "body" else lua_api.dom_parser.find_first("body")
|
||||
if element:
|
||||
var class_attr = element.get_attribute("class")
|
||||
var classes = class_attr.split(" ") if not class_attr.is_empty() else []
|
||||
|
||||
# Add hidden class if not present
|
||||
if not "hidden" in classes:
|
||||
classes.append("hidden")
|
||||
var new_class_attr = " ".join(classes).strip_edges()
|
||||
element.set_attribute("class", new_class_attr)
|
||||
|
||||
# Update visual element
|
||||
var operation = {
|
||||
"type": "add_class",
|
||||
"element_id": element_id,
|
||||
"class_name": "hidden"
|
||||
}
|
||||
emit_dom_operation(lua_api, operation)
|
||||
|
||||
return 0
|
||||
|
||||
static func _element_create_tween_wrapper(vm: LuauVM) -> int:
|
||||
var lua_api = vm.get_meta("lua_api") as LuaAPI
|
||||
if not lua_api:
|
||||
|
||||
@@ -126,6 +126,8 @@ static func _response_ok_handler(vm: LuauVM) -> int:
|
||||
return 1
|
||||
|
||||
static func make_http_request(url: String, method: String, headers: PackedStringArray, body: String) -> Dictionary:
|
||||
if url.begins_with("gurt://"):
|
||||
return make_gurt_request(url, method, headers, body)
|
||||
var http_client = HTTPClient.new()
|
||||
var response_data = {
|
||||
"status": 0,
|
||||
@@ -269,3 +271,63 @@ static func make_http_request(url: String, method: String, headers: PackedString
|
||||
|
||||
http_client.close()
|
||||
return response_data
|
||||
|
||||
static var _gurt_client: GurtProtocolClient = null
|
||||
|
||||
static func make_gurt_request(url: String, method: String, headers: PackedStringArray, body: String) -> Dictionary:
|
||||
var response_data = {
|
||||
"status": 0,
|
||||
"status_text": "Network Error",
|
||||
"headers": {},
|
||||
"body": ""
|
||||
}
|
||||
|
||||
# Reuse existing client or create new one
|
||||
if _gurt_client == null:
|
||||
_gurt_client = GurtProtocolClient.new()
|
||||
if not _gurt_client.create_client(10):
|
||||
response_data.status = 0
|
||||
response_data.status_text = "Connection Failed"
|
||||
return response_data
|
||||
|
||||
var client = _gurt_client
|
||||
|
||||
# Convert headers array to dictionary
|
||||
var headers_dict = {}
|
||||
for header in headers:
|
||||
var parts = header.split(":", 1)
|
||||
if parts.size() == 2:
|
||||
headers_dict[parts[0].strip_edges()] = parts[1].strip_edges()
|
||||
|
||||
# Prepare request options
|
||||
var options = {
|
||||
"method": method
|
||||
}
|
||||
|
||||
if not headers_dict.is_empty():
|
||||
options["headers"] = headers_dict
|
||||
|
||||
if not body.is_empty():
|
||||
options["body"] = body
|
||||
|
||||
var response = client.request(url, options)
|
||||
|
||||
# Keep connection alive for reuse instead of disconnecting after every request
|
||||
# client.disconnect()
|
||||
|
||||
if not response:
|
||||
response_data.status = 0
|
||||
response_data.status_text = "No Response"
|
||||
return response_data
|
||||
|
||||
response_data.status = response.status_code
|
||||
response_data.status_text = response.status_message if response.status_message else "OK"
|
||||
response_data.headers = response.headers if response.headers else {}
|
||||
|
||||
var body_content = response.body if response.body else ""
|
||||
if body_content is PackedByteArray:
|
||||
response_data.body = body_content.get_string_from_utf8()
|
||||
else:
|
||||
response_data.body = str(body_content)
|
||||
|
||||
return response_data
|
||||
|
||||
Reference in New Issue
Block a user