<commit_before>package visceljs.render

import viscel.shared.{ChapterPos, Contents, Gallery, ImageRef}
import visceljs.Definitions.{class_chapters, class_dead, class_preview, link_asset, link_index}
import visceljs.{Actions, Body, Data, Make}

import scala.Predef.{$conforms, ArrowAssoc}
import scala.annotation.tailrec
import scalatags.JsDom.Frag
import scalatags.JsDom.all.Tag
import scalatags.JsDom.implicits.stringFrag
import scalatags.JsDom.tags.{SeqFrag, div, fieldset, header, legend, span}
import scalatags.JsDom.tags2.{article, section}
import rescala._
import rescalatags._

object Front {


	def gen(dataS: Signal[Data]): Body = {

		val fragS = dataS.map { data =>
			val Data(narration, Contents(gallery, chapters), bookmark, _) = data



				val top = header(s"${narration.name} ($bookmark/${narration.size})")

				val navigation = Make.navigation(
					link_index("index"),
					Make.fullscreenToggle("TFS"),
					link_asset(data.move(_.first))("first"),
					Make.postBookmark(0, data, _ => Actions.gotoFront(narration, scrolltop = false), "remove"),
					Make.postForceHint(narration, "force"))

				val preview = {
					val preview1 = data.move(_.next(bookmark - 1).prev(2))
					val preview2 = preview1.next
					val preview3 = preview2.next
					section(class_preview)(
						List(preview1, preview2, preview3).map(p => p -> p.gallery.get)
							.collect { case (p, Some(a)) => link_asset(p)(article(Make.asset(a, data): _*)) })
				}

				def chapterlist: Tag = {
					val assets = gallery.end

					def makeChapField(chap: String, size: Int, gallery: Gallery[ImageRef]): Frag = {
						val (remaining, links) = Range(size, 0, -1).foldLeft((gallery, List[Frag]())) { case ((gal, acc), i) =>
							val next = gal.prev(1)
							(next, link_asset(data.move(_ => next))(s"$i") :: stringFrag(" ") :: acc)
						}

						article(fieldset(legend(chap), links))
					}


					@tailrec
					def build(apos: Int, assets: Gallery[ImageRef], chapters: List[ChapterPos], acc: List[Frag]): List[Frag] = chapters match {
						case ChapterPos(name, cpos) :: ctail =>
							build(cpos, assets.prev(apos - cpos), ctail, makeChapField(name, apos - cpos, assets) :: acc)
						case Nil => acc
					}

					section(class_chapters)(build(assets.pos, assets, chapters, Nil))

				}
				div(top, navigation, preview, chapterlist)
		}.withDefault(() => span("loading please wait"))


		Body(id = "front", title = "TODO:",
			frag = fragS.asFrag)

	}
}<commit_msg>update for newer rescala snapshot<commit_after>package visceljs.render

import viscel.shared.{ChapterPos, Contents, Gallery, ImageRef}
import visceljs.Definitions.{class_chapters, class_dead, class_preview, link_asset, link_index}
import visceljs.{Actions, Body, Data, Make}

import scala.Predef.{$conforms, ArrowAssoc}
import scala.annotation.tailrec
import scalatags.JsDom.Frag
import scalatags.JsDom.all.Tag
import scalatags.JsDom.implicits.stringFrag
import scalatags.JsDom.tags.{SeqFrag, div, fieldset, header, legend, span}
import scalatags.JsDom.tags2.{article, section}
import rescala._
import rescalatags._

object Front {


	def gen(dataS: Signal[Data]): Body = {

		val fragS: Signal[Tag] = dataS.map { data =>
			val Data(narration, Contents(gallery, chapters), bookmark, _) = data



				val top = header(s"${narration.name} ($bookmark/${narration.size})")

				val navigation = Make.navigation(
					link_index("index"),
					Make.fullscreenToggle("TFS"),
					link_asset(data.move(_.first))("first"),
					Make.postBookmark(0, data, _ => Actions.gotoFront(narration, scrolltop = false), "remove"),
					Make.postForceHint(narration, "force"))

				val preview = {
					val preview1 = data.move(_.next(bookmark - 1).prev(2))
					val preview2 = preview1.next
					val preview3 = preview2.next
					section(class_preview)(
						List(preview1, preview2, preview3).map(p => p -> p.gallery.get)
							.collect { case (p, Some(a)) => link_asset(p)(article(Make.asset(a, data): _*)) })
				}

				def chapterlist: Tag = {
					val assets = gallery.end

					def makeChapField(chap: String, size: Int, gallery: Gallery[ImageRef]): Frag = {
						val (remaining, links) = Range(size, 0, -1).foldLeft((gallery, List[Frag]())) { case ((gal, acc), i) =>
							val next = gal.prev(1)
							(next, link_asset(data.move(_ => next))(s"$i") :: stringFrag(" ") :: acc)
						}

						article(fieldset(legend(chap), links))
					}


					@tailrec
					def build(apos: Int, assets: Gallery[ImageRef], chapters: List[ChapterPos], acc: List[Frag]): List[Frag] = chapters match {
						case ChapterPos(name, cpos) :: ctail =>
							build(cpos, assets.prev(apos - cpos), ctail, makeChapField(name, apos - cpos, assets) :: acc)
						case Nil => acc
					}

					section(class_chapters)(build(assets.pos, assets, chapters, Nil))

				}
				div(top, navigation, preview, chapterlist)
		}.withDefault(span("loading please wait"))


		Body(id = "front", title = "TODO:",
			frag = fragS.asFrag)

	}
}
{'fraction_non_alphanumeric': 0.15109945531571514, 'fraction_numerical': 0.006052047609441194, 'mean_word_length': 3.87992125984252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '4545967', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1646, 'n_words': 370}