const tr = t => ({ translation: { id: t, params: [] } }) const plain = t => ({ text: t }) const span_raw = (s, th, bold) => ({ t: "text", s, color: th ? "#ffffff" : "#000000", size: 15, bold, font: "FreeSans" }) const par_raw = (s, th, bold) => ({ t: "par", es: [span_raw(s, th, bold)] }) const par = (t, th, bold) => par_raw(tr(t), th, bold) const h2 = (t, th) => ({ t: "text", s: tr(t), color: th ? "#ffffff" : "#000000", size: 40, font: "Great Vibes" }) const emph = (t, th) => ({ t: "text", s: tr(t), color: th ? "#95bd51" : "#2e4900", size: 20, font: "Gluten" }) const label = (id, e) => ({ t: "label", id, e }) const ref = (id, e) => ({ t: "ref", id, e }) const title = () => ({ t: "page", background: "cover", es: [ { t: "text", s: tr("b.title"), size: 70, color: "#000000", font: "Great Vibes" } ] }) const toc = (pages) => ({ t: "page", background: "toc", es: [ h2("b.toc"), { t: "list", es: pages.map(p => ref(p.ref, ({ t: "par", es: [ span_raw(tr(p.title)), { t: "align", dir: "flow_end", e: par_raw(plain(`${p.page}`)) } ] }))) }, ] }) const about = () => ({ t: "page", es: [ { t: "text", s: tr("b.about"), color: "#000000", size: 30, font: "FreeSans" }, par("b.about.name"), { t: "conditional", cond: "image_attribution", value: true, e: { t: "text", s: tr("b.about.image_attrib"), color: "#000000", size: 20, font: "FreeSans" } }, { t: "conditional", cond: "image_attribution", value: true, e: { t: "table", es: [ [par("b.about.image_attrib.name", false, true), par("b.about.image_attrib.author", false, true)], [par("b.nigiri"), par_raw(plain("Ahtziri Lagarde (unsplash)"))], [par("b.icecream"), par_raw(plain("Markus Spiske (unsplash), adapted"))], [par("b.curry"), par_raw(plain("Andy Hay (unsplash), adapted"))], [par("b.mochi"), par_raw(plain("blackieshoot (unsplash)"))], [par("b.burger"), par_raw(plain("Pablo Merchán Montes (unsplash), adapted"))], [par("b.tomato_soup"), par_raw(plain("Julia Kicova (unsplash), adapted"))], ] } } ] }) const recipe = (n, i, th = false, extra = []) => ({ t: "page", background: n, es: [ h2(`b.${n}`, th), par(`b.${n}.desc`, th), { t: "list", es: i.map(e => emph(`b.ingred.${e}`, th)) }, par(`b.${n}.steps`, th), ...extra ] }) const toc_pages = [ recipe("tomato_soup", ["leek", "tomato"]), recipe("bun", ["flour"], true), recipe("burger", ["lettuce", "tomato", "cheese", "steak", "bun"], true, [par("b.burger.variation", true)]), recipe("mochi", ["rice", "strawberry"], true), recipe("curry", ["coconut", "tomato", "leek", "rice"], true), recipe("icecream", ["strawberry", "coconut"]), recipe("nigiri", ["fish", "rice"]), { t: "page", background: "drinks", es: [ { t: "text", s: tr(`b.water`), color: "#ffffff", size: 30, font: "Great Vibes" }, par("b.water.steps", true), { t: "text", s: tr(`b.strawberry_shake`), color: "#ffffff", size: 30, font: "Great Vibes" }, par("b.strawberry_shake.steps", true), ] }, about() ] console.log(JSON.stringify({ t: "document", es: [ title(), toc(toc_pages.map((p, i) => ({ page: i + 3, title: p.es[0].s.translation.id, ref: `page.${i}` }))), ...toc_pages.map((p, i) => label(`page.${i}`, p)) ] }))