Clone in a terminal:
Commit 8e08a53
Johan Mattsson - 2026-06-28T11:17:23+00:00
8e08a5374ed6aae5a6db53b22a41d37dcd1e3ba5johan.mattsson.m@gmail.com

Init functon from annotated struct

Changed files (5)

Diff

diff --git a/.gitignore b/.gitignorenew file mode 100644index 0000000..ea8c4bf--- /dev/null+++ b/.gitignore@@ -0,0 +1 @@+/targetdiff --git a/Cargo.lock b/Cargo.locknew file mode 100644index 0000000..7fe3f47--- /dev/null+++ b/Cargo.lock@@ -0,0 +1,720 @@+# This file is automatically @generated by Cargo.+# It is not intended for manual editing.+version = 4++[[package]]+name = "bincode"+version = "1.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"+dependencies = [+ "serde",+]++[[package]]+name = "bumpalo"+version = "3.20.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"++[[package]]+name = "bytes"+version = "1.12.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593"++[[package]]+name = "cfg-if"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"++[[package]]+name = "equivalent"+version = "1.0.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"++[[package]]+name = "form_urlencoded"+version = "1.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"+dependencies = [+ "percent-encoding",+]++[[package]]+name = "futures"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-io",+ "futures-sink",+ "futures-task",+ "futures-util",+]++[[package]]+name = "futures-channel"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"+dependencies = [+ "futures-core",+ "futures-sink",+]++[[package]]+name = "futures-core"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"++[[package]]+name = "futures-io"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"++[[package]]+name = "futures-macro"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "futures-sink"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"++[[package]]+name = "futures-task"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"++[[package]]+name = "futures-util"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-io",+ "futures-macro",+ "futures-sink",+ "futures-task",+ "memchr",+ "pin-project-lite",+ "slab",+]++[[package]]+name = "getrandom"+version = "0.2.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"+dependencies = [+ "cfg-if",+ "js-sys",+ "libc",+ "wasi",+ "wasm-bindgen",+]++[[package]]+name = "gloo"+version = "0.12.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dc13cc21c3835347855fd83900414d94716adc1e332f09f7fba56f21be127214"+dependencies = [+ "gloo-console",+ "gloo-dialogs",+ "gloo-events",+ "gloo-file",+ "gloo-history",+ "gloo-net",+ "gloo-render",+ "gloo-storage",+ "gloo-timers",+ "gloo-utils 0.3.0",+ "gloo-worker",+]++[[package]]+name = "gloo-console"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9f1d5cec0b97edb53f21221f799c659cef3764ad5a00eca52950eb9b902028ba"+dependencies = [+ "gloo-utils 0.3.0",+ "js-sys",+ "serde",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-dialogs"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "45618929b7022bb49903b958b5b7af1d4fb58fbd99712926d91641fe582f3d55"+dependencies = [+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-events"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8c6a94fa8cd88bea0babf8a27fe9abbcdece831fd1c3c84dd5c231fab4685ec7"+dependencies = [+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-file"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "544a15ff6a3d5976bebc97380c8471ae14283bc71f4bb198d6c8cae64f411ab7"+dependencies = [+ "gloo-events",+ "js-sys",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-history"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f07f3d446931414cc92f4a1b6e631dfa233db2f96c887d5f72beeecd1b5db39c"+dependencies = [+ "getrandom",+ "gloo-events",+ "gloo-utils 0.3.0",+ "serde",+ "serde-wasm-bindgen",+ "serde_urlencoded",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-net"+version = "0.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a6420f887c48417e9e86c6cf61274eb231830cccc100e49613f7952e269a1fe1"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-sink",+ "gloo-utils 0.3.0",+ "http",+ "js-sys",+ "pin-project",+ "serde",+ "serde_json",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "wasm-bindgen-futures",+ "web-sys",+]++[[package]]+name = "gloo-render"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3f609333b9e38e43e74224410d6616e3ad773ed6fe14f53cd8a006d1bb25e108"+dependencies = [+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-storage"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e82ce7d41c6d821640a43726f6ff33c924795cc151b62e5a84d0c988c151c980"+dependencies = [+ "gloo-utils 0.3.0",+ "js-sys",+ "serde",+ "serde_json",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-timers"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "482ce8a491a501da4cd806bd190275363d674f2845005c6ddbd5d3e1dd54495d"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "gloo-utils"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa"+dependencies = [+ "js-sys",+ "serde",+ "serde_json",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-utils"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4202275d95a142fa209a1e35e91c250a710c5600731372cd3464a39ed01573d6"+dependencies = [+ "js-sys",+ "serde",+ "serde_json",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-worker"+version = "0.6.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "142478655c5d764e5168d3019510ea0c0885687a72ba74e90548bd74ae160a41"+dependencies = [+ "bincode",+ "futures",+ "gloo-utils 0.2.0",+ "gloo-worker-macros",+ "js-sys",+ "pinned",+ "serde",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "wasm-bindgen-futures",+ "web-sys",+]++[[package]]+name = "gloo-worker-macros"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f3bf5ede96b06406bd74351a026f708ae196b7dc262077aee56e6ad7223e7466"+dependencies = [+ "proc-macro-crate",+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "hashbrown"+version = "0.17.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"++[[package]]+name = "http"+version = "1.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425"+dependencies = [+ "bytes",+ "itoa",+]++[[package]]+name = "indexmap"+version = "2.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"+dependencies = [+ "equivalent",+ "hashbrown",+]++[[package]]+name = "itoa"+version = "1.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"++[[package]]+name = "js-sys"+version = "0.3.103"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102"+dependencies = [+ "cfg-if",+ "futures-util",+ "wasm-bindgen",+]++[[package]]+name = "kaja-web-component"+version = "0.1.0"+dependencies = [+ "gloo",+ "js-sys",+ "proc-macro2",+ "quote",+ "syn",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "libc"+version = "0.2.186"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"++[[package]]+name = "memchr"+version = "2.8.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"++[[package]]+name = "once_cell"+version = "1.21.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"++[[package]]+name = "percent-encoding"+version = "2.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"++[[package]]+name = "pin-project"+version = "1.1.13"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924"+dependencies = [+ "pin-project-internal",+]++[[package]]+name = "pin-project-internal"+version = "1.1.13"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "pin-project-lite"+version = "0.2.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"++[[package]]+name = "pinned"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a829027bd95e54cfe13e3e258a1ae7b645960553fb82b75ff852c29688ee595b"+dependencies = [+ "futures",+ "rustversion",+ "thiserror 1.0.69",+]++[[package]]+name = "proc-macro-crate"+version = "3.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"+dependencies = [+ "toml_edit",+]++[[package]]+name = "proc-macro2"+version = "1.0.106"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "quote"+version = "1.0.46"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"+dependencies = [+ "proc-macro2",+]++[[package]]+name = "rustversion"+version = "1.0.22"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"++[[package]]+name = "ryu"+version = "1.0.23"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"++[[package]]+name = "serde"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"+dependencies = [+ "serde_core",+ "serde_derive",+]++[[package]]+name = "serde-wasm-bindgen"+version = "0.6.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"+dependencies = [+ "js-sys",+ "serde",+ "wasm-bindgen",+]++[[package]]+name = "serde_core"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"+dependencies = [+ "serde_derive",+]++[[package]]+name = "serde_derive"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "serde_json"+version = "1.0.150"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"+dependencies = [+ "itoa",+ "memchr",+ "serde",+ "serde_core",+ "zmij",+]++[[package]]+name = "serde_urlencoded"+version = "0.7.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"+dependencies = [+ "form_urlencoded",+ "itoa",+ "ryu",+ "serde",+]++[[package]]+name = "slab"+version = "0.4.12"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"++[[package]]+name = "syn"+version = "2.0.118"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]++[[package]]+name = "thiserror"+version = "1.0.69"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"+dependencies = [+ "thiserror-impl 1.0.69",+]++[[package]]+name = "thiserror"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"+dependencies = [+ "thiserror-impl 2.0.18",+]++[[package]]+name = "thiserror-impl"+version = "1.0.69"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "thiserror-impl"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "toml_datetime"+version = "0.6.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"++[[package]]+name = "toml_edit"+version = "0.22.27"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"+dependencies = [+ "indexmap",+ "toml_datetime",+ "winnow",+]++[[package]]+name = "unicode-ident"+version = "1.0.24"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"++[[package]]+name = "wasi"+version = "0.11.1+wasi-snapshot-preview1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"++[[package]]+name = "wasm-bindgen"+version = "0.2.126"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4"+dependencies = [+ "cfg-if",+ "once_cell",+ "rustversion",+ "wasm-bindgen-macro",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-futures"+version = "0.4.76"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c62df1340f32221cb9c54d6a27b030e3dba64361d4a95bed55f9aacb44da291d"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "wasm-bindgen-macro"+version = "0.2.126"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1"+dependencies = [+ "quote",+ "wasm-bindgen-macro-support",+]++[[package]]+name = "wasm-bindgen-macro-support"+version = "0.2.126"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e"+dependencies = [+ "bumpalo",+ "proc-macro2",+ "quote",+ "syn",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-shared"+version = "0.2.126"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "web-sys"+version = "0.3.103"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "winnow"+version = "0.7.15"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"+dependencies = [+ "memchr",+]++[[package]]+name = "zmij"+version = "1.0.21"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"++[[patch.unused]]+name = "kaja-callback-macro"+version = "1.0.0"diff --git a/Cargo.toml b/Cargo.tomlnew file mode 100644index 0000000..2a1f080--- /dev/null+++ b/Cargo.toml@@ -0,0 +1,19 @@+[package]+name = "kaja-web-component"+version = "0.1.0"+edition = "2024"++[lib]+proc-macro = true++[dependencies]+syn = { version = "2", features = ["full"] }+quote = "1"+proc-macro2 = "1"+gloo = "0.12.0"+wasm-bindgen = "0.2.122"+js-sys = "0.3"+web-sys = { version = "0.3.99", features = ["Window", "HtmlElement", "CustomElementRegistry", "ElementDefinitionOptions"] }++[patch.crates-io]+kaja-callback-macro = { path = "../kaja-callback-macro" }diff --git a/src/lib.rs b/src/lib.rsnew file mode 100644index 0000000..a07249e--- /dev/null+++ b/src/lib.rs@@ -0,0 +1,106 @@+use proc_macro2::Span;+use proc_macro2::TokenStream;+use quote::quote;+use syn::parse2;+use syn::{Ident, ItemStruct, LitStr};++#[proc_macro_attribute]+pub fn component(+    attr: proc_macro::TokenStream,+    item: proc_macro::TokenStream,+) -> proc_macro::TokenStream {+    let html_tag_name = proc_macro2::TokenStream::from(attr.clone());+    let tag_value = parse2::<LitStr>(html_tag_name.clone());++    if tag_value.is_empty() {+        return syn::Error::new_spanned(+            tag_value,+            "expected a tag name or component: #[component(example-component-tag)]",+        )+        .to_compile_error()+        .into();+    }++    let component_struct_name = proc_macro2::TokenStream::from(item.clone());+    let component_struct_item = match syn::parse2::<ItemStruct>(component_struct_name.clone()) {+        Ok(s) => s,+        Err(_) => {+            return syn::Error::new_spanned(+                component_struct_name,+                "the #[component] attribute can only be applied to structs",+            )+            .to_compile_error()+            .into();+        }+    };++    let struct_name_ident = &component_struct_item.ident;+    let create_html_component_fn_name = format!("createComponent{}", struct_name_ident);+    let fn_create_ident = Ident::new(&create_html_component_fn_name, Span::call_site());+    let html_tag = LitStr::new(&tag_value, Span::call_site());++    let create_fn = generate_create_component_fn(fn_create_ident);++    let expanded = quote! {+        #component_struct_item+        #create_fn+    };++    TokenStream::from(expanded)+}++fn generate_create_component_fn(name: Ident) -> TokenStream {+    let expanded = quote! {+        #[allow(non_snake_case)]+        pub fn #name() { // createComponentTheStructName++            let wasm_id = 0;++            let component = Function::new_no_args(+                r#"+                let componentId = -1;++                return class extends HTMLElement {+                    connectedCallback() {+                        if (componentId == -1) {+                            componentId = counterInit();+                        }++                        counterComponentConnect(this, componentId);+                    }++                    disconnectedCallback() {+                        counterComponentDisconnect(this, componentId);+                    }++                    attributeChangedCallback(name, oldValue, newValue) {+                        //callbacks.attributeChanged(this, name, oldValue, newValue);+                    }++                    static get observedAttributes() {+                        return [];+                    }+                }+            "#,+            );++            let class = component.call0(&JsValue::NULL);++            if class.is_err() {+                error!("Failed to register class for", tag_name);+                return;+            }++            let class_fn = class.unwrap();+            let registry = web_sys::window().unwrap().custom_elements();++            let result = registry.define(tag_name, &class_fn.unchecked_into());++            if result.is_err() {+                error!("Failed to register component", tag_name);+            }+        }+    };++    expanded+}diff --git a/src/prelude.rs b/src/prelude.rsnew file mode 100644index 0000000..e69de29--- /dev/null+++ b/src/prelude.rs

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112