Skip to content

Commit a642a8d

Browse files
committed
+ tagmap feature
1 parent 680e9b6 commit a642a8d

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

packages/web-platform/web-core-wasm/src/constants.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License Version 2.0 that can be found in the
33
// LICENSE file in the root directory of this source tree.
44

5+
use fnv::FnvHashMap;
6+
57
pub const LYNX_UNIQUE_ID_ATTRIBUTE: &str = "l-uid";
68
pub const CSS_ID_ATTRIBUTE: &str = "l-css-id";
79
pub const LYNX_ENTRY_NAME_ATTRIBUTE: &str = "l-e-name";
@@ -225,3 +227,15 @@ pub(crate) const STYLE_PROPERTY_MAP: &[&str] = &[
225227
"offset-path",
226228
"offset-distance",
227229
];
230+
231+
lazy_static::lazy_static! {
232+
pub static ref TAG_NAME_TO_HTML_TAG_MAP: FnvHashMap<String, String> = FnvHashMap::from_iter(vec![
233+
("view".to_string(), "x-view".to_string()),
234+
("text".to_string(), "x-text".to_string()),
235+
("image".to_string(), "x-image".to_string()),
236+
("raw-text".to_string(), "raw-text".to_string()),
237+
("scroll-view".to_string(), "x-scroll-view".to_string()),
238+
("wrapper".to_string(), "lynx-wrapper".to_string()),
239+
("list".to_string(), "x-list".to_string()),
240+
]);
241+
}

packages/web-platform/web-core-wasm/src/main_thread/element_apis/element_template_apis.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ impl MainThreadWasmContext {
118118
LEOAsmOpcode::CreateElement => {
119119
let tag_name = &operation.operands_str[0];
120120
let dom = document
121-
.create_element(tag_name)
121+
.create_element(
122+
self
123+
.tag_name_to_html_tag_map
124+
.get(tag_name)
125+
.map(|s| s.as_str())
126+
.unwrap_or(tag_name),
127+
)
122128
.map_err(|e| JsError::new(&format!("Failed to create element {tag_name}: {e:?}")))?;
123129
let element_id = operation.operands_num[0];
124130
let _ = dom.set_attribute(constants::LYNX_TAG_ATTRIBUTE, tag_name);

packages/web-platform/web-core-wasm/src/main_thread/main_thread_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl MainThreadWasmContext {
6666
unique_id_to_element_map: vec![None],
6767
unique_id_symbol,
6868
enabled_events: FnvHashSet::default(),
69-
tag_name_to_html_tag_map: FnvHashMap::default(),
69+
tag_name_to_html_tag_map: constants::TAG_NAME_TO_HTML_TAG_MAP.clone(),
7070
timing_flags: vec![],
7171
exposure_changed_elements: vec![],
7272
// document,

packages/web-platform/web-core-wasm/ts/client/mainthread/elementAPIs/createElementAPI.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
lynxEntryNameAttribute,
1010
lynxTagAttribute,
1111
uniqueIdSymbol,
12+
defaultTagMap,
1213
} from '@constants';
1314
import {
1415
__SwapElement,
@@ -51,6 +52,7 @@ export function createElementAPI(
5152
config_enable_css_selector: boolean,
5253
config_default_display_linear: boolean,
5354
config_default_overflow_visible: boolean,
55+
tagMap: Record<string, string> = defaultTagMap,
5456
): ElementPAPIs {
5557
// let uniqueIdCounter = 1;
5658
const wasmContext = new MainThreadWasmContext(
@@ -107,7 +109,9 @@ export function createElementAPI(
107109
return dom;
108110
},
109111
__CreateElement(tagName, parentComponentUniqueId) {
110-
const dom = document.createElement(tagName) as DecoratedHTMLElement;
112+
const dom = document.createElement(
113+
tagMap[tagName] ?? tagName,
114+
) as DecoratedHTMLElement;
111115
dom[uniqueIdSymbol] = wasmContext.__CreateElementCommon(
112116
parentComponentUniqueId,
113117
dom,

packages/web-platform/web-core-wasm/ts/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,8 @@ export const enum ErrorCode {
9191
SELECTOR_NOT_SUPPORTED = 5,
9292
NO_UI_FOR_NODE = 6,
9393
}
94+
95+
export const defaultTagMap = {
96+
'input': 'x-input',
97+
'x-input-ng': 'x-input',
98+
};

0 commit comments

Comments
 (0)