function $(selector, el = document) {
    return el.querySelector(selector);
}

function $$(selector, el = document) {
    return [].slice.call(el.querySelectorAll(selector));
}

function replace(el_old, el_new) {
    el_old.parentNode.replaceChild(el_new, el_old);
    return el_new;
}

function component(name, init) {
    function parse_conf(el) {
        const default_conf = {};

        try {
            const conf = JSON.parse(el.getAttribute("data-component-conf"));
            return conf || default_conf;
        } catch(e) {
            return default_conf;
        }
    }

    return $$(`[data-component~="${name}"]`)
        .map((el, index) => {
            const def = el.getAttribute("data-component").split(" ");

            const options = {
                index,
                conf: parse_conf(el),
                is_type(type) {
                    return def.indexOf(`${name}-${type}`) !== -1;
                }
            };

            return init(el, options);
        });
}

export { $, $$, component, replace };

@@ -310,16 +310,27 @@
 me, init
+, opts = %7B%7D
 ) %7B%0A    
@@ -595,52 +595,210 @@
   %7D%0A
-%0A    return $$(%60%5Bdata-component~=%22$%7Bname%7D%22%5D%60
+    %0A    opts = opts instanceof HTMLElement ? %7B root: opts %7D : opts;%0A%0A    return $$(%60%5Bdata-component~=%22$%7Bname%7D%22%5D%60, opts.root %7C%7C document)%0A        .filter((el) =%3E !el.hasAttribute(%22data-component-ready%22)
 )%0A  
@@ -895,17 +895,16 @@
 t(%22 %22);%0A
-%0A
         
@@ -917,79 +917,146 @@
 nst 
-options = %7B%0A                index,%0A                conf: parse_conf(el)
+conf = Object.assign(%7B%7D, init.DEFAULTS %7C%7C %7B%7D, opts.conf %7C%7C %7B%7D, parse_conf(el));%0A%0A            const options = %7B%0A                index, conf
 ,%0A  
@@ -1197,22 +1197,33 @@
         
-return
+const component =
  init(el
@@ -1234,16 +1234,103 @@
 tions);%0A
+            el.setAttribute(%22data-component-ready%22, %22%22);%0A            return component;%0A
         

improve component helper function