<commit_before>export body!, content!, loadcss!, loadjs!, load!

content!(o, sel, html::AbstractString; fade = true) =
  fade ?
    @js_(o, Blink.fill($sel, $html)) :
    @js_ o document.querySelector($sel).innerHTML = $html

content!(o, sel, html; fade = true) =
  content!(o, sel, stringmime(MIME"text/html"(), html), fade = fade)

body!(w, html; fade = true) = content!(w, "body", html, fade = fade)

function loadcss!(w, url)
  @js_ w begin
    @var link = document.createElement("link")
    link.type = "text/css"
    link.rel = "stylesheet"
    link.href = $url
    document.head.appendChild(link)
  end
end

function loadjs!(w, url)
  id, cb = callback!()
  @js_ w begin
    @var script = document.createElement("script")
    script.src = $url
    script.onload = e -> Blink.cb($id)
    document.head.appendChild(script)
  end
  return wait(cb)
end

isurl(f) = ismatch(r"^https?://", f)

function load!(w, file)
  if !isurl(file)
    resource(file)
    file = basename(file)
  end
  ext = Mux.extension(file)
  if ext == "js"
    loadjs!(w, file)
  elseif ext == "css"
    loadcss!(w, file)
  else
    error("Blink: Unsupported file type")
  end
end
<commit_msg>Add support for HTML imports<commit_after>export body!, content!, loadcss!, loadjs!, load!, importhtml!

content!(o, sel, html::AbstractString; fade = true) =
  fade ?
    @js_(o, Blink.fill($sel, $html)) :
    @js_ o document.querySelector($sel).innerHTML = $html

content!(o, sel, html; fade = true) =
  content!(o, sel, stringmime(MIME"text/html"(), html), fade = fade)

body!(w, html; fade = true) = content!(w, "body", html, fade = fade)

function loadcss!(w, url)
  @js_ w begin
    @var link = document.createElement("link")
    link.type = "text/css"
    link.rel = "stylesheet"
    link.href = $url
    document.head.appendChild(link)
  end
end

function importhtml!(w, file)
  if !isurl(file)
    resource(file)
    file = basename(file)
  end
  @js_ w begin
    @var link = document.createElement("link")
    link.rel = "import"
    link.href = $file
    document.head.appendChild(link)
  end
end

function loadjs!(w, url)
  id, cb = callback!()
  @js_ w begin
    @var script = document.createElement("script")
    script.src = $url
    script.onload = e -> Blink.cb($id)
    document.head.appendChild(script)
  end
  return wait(cb)
end

isurl(f) = ismatch(r"^https?://", f)

function load!(w, file)
  if !isurl(file)
    resource(file)
    file = basename(file)
  end
  ext = Mux.extension(file)
  if ext == "js"
    loadjs!(w, file)
  elseif ext == "css"
    loadcss!(w, file)
  else
    error("Blink: Unsupported file type")
  end
end

{'fraction_non_alphanumeric': 0.1599236641221374, 'fraction_numerical': 0.0, 'mean_word_length': 3.488013698630137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5351837', 'n_tokens_mistral': 953, 'n_tokens_neox': 941, 'n_words': 247}