1use once_cell::sync::Lazy;
2use rustc_hash::FxHashMap;
3use serde::{Deserialize, Serialize};
4use swc_atoms::Atom;
5
6#[derive(Serialize, Deserialize, Debug)]
7pub struct Entity {
8 pub characters: String,
9}
10
11pub static HTML_ENTITIES: Lazy<FxHashMap<String, Entity>> = Lazy::new(|| {
12 let entities: FxHashMap<String, Entity> =
13 serde_json::from_str(include_str!("../data/entities.json"))
14 .expect("failed to parse entities.json for html entities");
15
16 entities
17});
18
19#[derive(Serialize, Deserialize, Debug, Clone)]
20#[serde(rename_all = "camelCase")]
21pub struct AttributeInfo {
22 #[serde(default)]
23 pub initial: Option<String>,
24 #[serde(default)]
25 pub inherited: Option<bool>,
26 #[serde(default)]
27 pub boolean: Option<bool>,
28 #[serde(default)]
29 pub deprecated: Option<bool>,
30}
31
32#[derive(Serialize, Deserialize, Debug)]
33pub struct Element {
34 _extends: Option<Vec<Atom>>,
35 #[serde(flatten)]
36 pub other: FxHashMap<Atom, AttributeInfo>,
37}
38
39pub static HTML_ELEMENTS_AND_ATTRIBUTES: Lazy<FxHashMap<Atom, Element>> = Lazy::new(|| {
40 let default_attributes: FxHashMap<Atom, Element> =
41 serde_json::from_str(include_str!("../data/html_elements_and_attributes.json"))
42 .expect("failed to parse html_elements_and_attributes.json for default attributes");
43
44 default_attributes
45});
46
47pub static SVG_ELEMENTS_AND_ATTRIBUTES: Lazy<FxHashMap<Atom, Element>> = Lazy::new(|| {
48 let svg_elements_and_attributes: FxHashMap<Atom, Element> =
49 serde_json::from_str(include_str!("../data/svg_elements_and_attributes.json"))
50 .expect("failed to parse svg_elements_and_attributes.json for default attributes");
51
52 svg_elements_and_attributes
53});