<commit_before>package visceljs

import org.scalajs.dom.html
import viscel.shared.{Article, Description}
import visceljs.Actions._
import visceljs.Definitions._

import scala.Predef.{$conforms, ArrowAssoc}
import scalatags.JsDom.all._
import scalatags.JsDom.attrs.{onclick, style}
import scalatags.JsDom.tags.a
import scalatags.JsDom.tags2.{aside, nav, section}

object Make {


	def postBookmark(nar: Description, bm: Int, data: Data, handler: Data => Unit, ts: Frag*): HtmlTag = a(class_post)(ts)(onclick := { () =>
		Viscel.postBookmark(nar, bm)
		handler(data.copy(bookmark = bm))
	})

	def postForceHint(nar: Description, ts: Frag*): HtmlTag = a(class_post)(ts)(onclick := { () =>
		Viscel.hint(nar, force = true)
	})

	def searchArea(narrations: List[Description]): HtmlTag = aside {
		val results = ol.render
		var filtered = narrations
		filtered.sortBy(_.name).foreach(nar => results.appendChild(li(link_front(nar, nar.name)).render))
		lazy val inputField: html.Input = input(`type` := "textfield", onkeyup := { () =>
			results.innerHTML = ""
			val query = inputField.value.toString.toLowerCase
			filtered = SearchUtil.search(query, narrations.map(n => n.name -> n))
			filtered.foreach(nar => results.appendChild(li(link_front(nar, nar.name)).render))
		}).render

		form(fieldset(legend("Search"), inputField, results), action := "", onsubmit := { () => filtered.headOption.foreach(gotoFront(_)); false })
	}

	def imageStyle(data: Data): Modifier = {
		def s(mw: Boolean = false, mh: Boolean = false, w: Boolean = false, h: Boolean = false) =
			s"max-height: ${if (mh) "100vh" else "none"}; max-width: ${if (mw) "100vw" else "none"}; height: ${if (h) "100vh" else "auto"}; width: ${if (w) "100vw" else "auto"}"
		style := (data.fitType % 8 match {
			case 0 => ""
			case 1 => s()
			case 2 => s(mw = true)
			case 3 => s(mh = true)
			case 4 => s(mw = true, mh = true)
			case 5 => s(w = true)
			case 6 => s(h = true)
			case 7 => s(w = true, h = true)
		})
	}

	def asset(asset: Article, data: Data): List[Modifier] = {
		asset.blob.fold[List[Modifier]](List(class_placeholder, "placeholder"))(blob =>
			img(src := path_blob(blob), title := asset.data.getOrElse("title", ""), alt := asset.data.getOrElse("alt",""))(imageStyle(data)) :: Nil)
	}

	def fullscreenToggle(stuff: Frag*): Tag = a(onclick := (() => Viscel.toggleFullscreen()))(stuff)

	def group(name: String, entries: Seq[Frag]): Tag = section(fieldset(legend(name), ul(entries.map(li(_)))))

	def navigation(links: Tag*): Tag =
		nav(links)
}
<commit_msg>fix search tabindex<commit_after>package visceljs

import org.scalajs.dom.html
import viscel.shared.{Article, Description}
import visceljs.Actions._
import visceljs.Definitions._

import scala.Predef.{$conforms, ArrowAssoc}
import scalatags.JsDom.all._
import scalatags.JsDom.attrs.{onclick, style}
import scalatags.JsDom.tags.a
import scalatags.JsDom.tags2.{aside, nav, section}

object Make {


	def postBookmark(nar: Description, bm: Int, data: Data, handler: Data => Unit, ts: Frag*): HtmlTag = a(class_post)(ts)(onclick := { () =>
		Viscel.postBookmark(nar, bm)
		handler(data.copy(bookmark = bm))
	})

	def postForceHint(nar: Description, ts: Frag*): HtmlTag = a(class_post)(ts)(onclick := { () =>
		Viscel.hint(nar, force = true)
	})

	def searchArea(narrations: List[Description]): HtmlTag = aside {
		val results = ol.render
		var filtered = narrations
		filtered.sortBy(_.name).foreach(nar => results.appendChild(li(link_front(nar, nar.name)).render))
		lazy val inputField: html.Input = input(`type` := "textfield", tabindex := "1", onkeyup := { () =>
			results.innerHTML = ""
			val query = inputField.value.toString.toLowerCase
			filtered = SearchUtil.search(query, narrations.map(n => n.name -> n))
			filtered.foreach(nar => results.appendChild(li(link_front(nar, nar.name)).render))
		}).render

		form(fieldset(legend("Search"), inputField, results), action := "", onsubmit := { () => filtered.headOption.foreach(gotoFront(_)); false })
	}

	def imageStyle(data: Data): Modifier = {
		def s(mw: Boolean = false, mh: Boolean = false, w: Boolean = false, h: Boolean = false) =
			s"max-height: ${if (mh) "100vh" else "none"}; max-width: ${if (mw) "100vw" else "none"}; height: ${if (h) "100vh" else "auto"}; width: ${if (w) "100vw" else "auto"}"
		style := (data.fitType % 8 match {
			case 0 => ""
			case 1 => s()
			case 2 => s(mw = true)
			case 3 => s(mh = true)
			case 4 => s(mw = true, mh = true)
			case 5 => s(w = true)
			case 6 => s(h = true)
			case 7 => s(w = true, h = true)
		})
	}

	def asset(asset: Article, data: Data): List[Modifier] = {
		asset.blob.fold[List[Modifier]](List(class_placeholder, "placeholder"))(blob =>
			img(src := path_blob(blob), title := asset.data.getOrElse("title", ""), alt := asset.data.getOrElse("alt",""))(imageStyle(data)) :: Nil)
	}

	def fullscreenToggle(stuff: Frag*): Tag = a(onclick := (() => Viscel.toggleFullscreen()))(stuff)

	def group(name: String, entries: Seq[Frag]): Tag = section(fieldset(legend(name), ul(entries.map(li(_)))))

	def navigation(links: Tag*): Tag =
		nav(links)
}

{'fraction_non_alphanumeric': 0.1822640769079851, 'fraction_numerical': 0.008828722778104767, 'mean_word_length': 4.61453744493392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '233470', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1793, 'n_words': 420}