diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18a57ce..15f2cbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Install just + uses: taiki-e/install-action@v2 + with: + tool: just + - name: Install tytanic (binary) if: ${{ !contains(matrix.typst-version.tytanic, '-rc') }} uses: taiki-e/install-action@v2 @@ -48,8 +53,7 @@ jobs: tool: tytanic@${{ matrix.typst-version.tytanic }} - name: Run test suite - id: run-suite - run: tt run --no-fail-fast --max-delta 1 + run: just test - name: Archive artifacts uses: actions/upload-artifact@v4 @@ -62,6 +66,26 @@ jobs: tests/**/ref/*.png retention-days: 5 + formatting: + name: Check formatting + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install just + uses: taiki-e/install-action@v2 + with: + tool: just + + - name: Install typstyle + uses: taiki-e/install-action@v2 + with: + tool: typstyle@0.13 + + - name: Check formatting + run: just check-format + assets: name: Check assets and documentation runs-on: ubuntu-latest @@ -77,7 +101,7 @@ jobs: - name: Install typst uses: typst-community/setup-typst@v3 with: - typst-version: 0.12 + typst-version: 0.13 - name: Check assets - run: just generate + run: just check-doc diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e5f04..de6f450 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ --- +# [v0.6.2](https://github.com/tingerrr/hydra/releases/tags/v0.6.2) +## Changed +- Bumped `oxifmt` from `0.2.1` to `1.0.0` +- Bumped `mantys` from `1.0.0` to `1.0.2` + +## Fixed + +--- + # [v0.6.1](https://github.com/tingerrr/hydra/releases/tags/v0.6.1) ## Fixed - Use the correct page length when calculating the top margin diff --git a/Justfile b/Justfile index f573a9b..e4f74ab 100644 --- a/Justfile +++ b/Justfile @@ -10,83 +10,129 @@ thumbnail := images / 'thumbnail' export TYPST_ROOT := justfile_directory() export TYPST_FONT_PATHS := fonts +prompt := BOLD + GREEN + ">>>" + NORMAL + +alias t := test +alias c := check +alias f := format +alias fmt := format +alias d := doc + # list recipes [private] default: @just --list --unsorted -# run tytanic with the correct assets -[positional-arguments] -tt *args: - @tt "$@" +# run all tests +test: && test-unit + @echo "{{prompt}} Running all tests" + +# run the Tytanic unit test suite +test-unit: + @echo "{{prompt}} Testing Tytanic suite (with max-delta: 1)" + @tt run --no-fail-fast --max-delta 1 --expression 'all()' + +# run all checks +check: && check-format check-doc + @echo "{{prompt}} Running all checks" + +# check the formatting +check-format: + @echo "{{prompt}} Checking Typst files for formatting" + @typstyle --diff {{ TYPST_ROOT }} + +# check the documentation assets generation +check-doc: && doc-generate + @echo "{{prompt}} Checking documentation assets generation for errors" + +# format all Typst files +format: + @echo "{{prompt}} Formatting Typst files in place" + @typstyle --inplace {{ TYPST_ROOT }} -# run the full test suite -test: - tt run --no-fail-fast --expression 'all()' +# generate the docs and thumbnail +doc: doc-generate -# update all persistent assets -update: update-manual update-thumbnail +# update persistent documentation assets +doc-update: && update-manual update-thumbnail + @echo "{{prompt}} Updating tracked manual and thumbnail" -# generate all non-persistent assets -generate: generate-manual generate-thumbnail +# generate non-persistent documentation assets +doc-generate: && generate-manual generate-thumbnail + @echo "{{prompt}} Generating local manual and thumbnail" # clean all output directories clean: - rm --recursive --force {{ manual / 'out' }} - rm --recursive --force {{ examples / 'book' / 'out' }} - rm --recursive --force {{ examples / 'skip' / 'out' }} - rm --recursive --force {{ thumbnail / 'out' }} - tt util clean + @echo "{{prompt}} Removing temporary directories" + @rm --recursive --force {{ manual / 'out' }} + @rm --recursive --force {{ examples / 'book' / 'out' }} + @rm --recursive --force {{ examples / 'skip' / 'out' }} + @rm --recursive --force {{ thumbnail / 'out' }} + @tt util clean + +# run Tytanic with the correct environment +[positional-arguments] +tt *args: + @tt "$@" # run the ci checks locally -ci: generate test +ci: test check # update the package thumbnail +[private] update-thumbnail: generate-thumbnail - oxipng --opt max {{ thumbnail / 'out' / 'thumbnail.png' }} - cp {{ thumbnail / 'out' / 'thumbnail.png' }} {{ images / 'thumbnail.png' }} + @echo "{{prompt}} Updating tracked thumbnail in {{ assets / 'thumbnail.png' }}" + @oxipng --opt max {{ thumbnail / 'out' / 'thumbnail.png' }} + @cp {{ thumbnail / 'out' / 'thumbnail.png' }} {{ images / 'thumbnail.png' }} # generate the package thumbnail +[private] generate-thumbnail: (clear-directory (thumbnail / 'out')) - typst compile \ + @typst compile \ --ppi 300 \ {{ thumbnail / 'pages.typ' }} \ {{ thumbnail / 'out' / '{n}.png' }} - typst compile \ + @typst compile \ {{ thumbnail / 'thumbnail.typ' }} \ {{ thumbnail / 'out' / 'thumbnail.png' }} # generate all docs examples +[private] generate-examples: (generate-example 'book') (generate-example 'skip') # generate a single docs example +[private] generate-example example: (clear-directory (examples / example / 'out')) - typst compile \ + @typst compile \ --ppi 300 \ {{ examples / example / 'a.typ' }} \ {{ examples / example / 'out' / 'a{n}.png' }} - typst compile \ + @typst compile \ --ppi 300 \ {{ examples / example / 'b.typ' }} \ {{ examples / example / 'out' / 'b{n}.png' }} # generate a new manual and update it +[private] update-manual: generate-manual - cp {{ manual / 'out' / 'manual.pdf' }} {{ assets / 'manual.pdf' }} + @echo "{{prompt}} Updating tracked manual in {{ assets / 'manual.pdf' }}" + @cp {{ manual / 'out' / 'manual.pdf' }} {{ assets / 'manual.pdf' }} # generate the manual +[private] generate-manual: (clear-directory (manual / 'out')) generate-examples - typst compile \ + @typst compile \ {{ manual / 'manual.typ' }} \ {{ manual / 'out' / 'manual.pdf' }} -# watch the manual +# watch the manual after generating its dependencies once +[private] watch-manual: (clear-directory (manual / 'out')) generate-examples - typst watch \ + @typst watch \ {{ manual / 'manual.typ' }} \ {{ manual / 'out' / 'manual.pdf' }} [private] clear-directory dir: - rm --recursive --force {{ dir }} - mkdir {{ dir }} + @rm --recursive --force {{ dir }} + @mkdir {{ dir }} diff --git a/assets/images/thumbnail/thumbnail.typ b/assets/images/thumbnail/thumbnail.typ index af8d356..242b875 100644 --- a/assets/images/thumbnail/thumbnail.typ +++ b/assets/images/thumbnail/thumbnail.typ @@ -1,15 +1,10 @@ -#page( - width: auto, - height: auto, - margin: 0pt, - block( - fill: gray, - inset: 1em, - radius: 1em, - grid( - columns: 4, - gutter: 1em, - ..range(1, 5).map(i => image("out/" + str(i) + ".png")) - ), +#page(width: auto, height: auto, margin: 0pt, block( + fill: gray, + inset: 1em, + radius: 1em, + grid( + columns: 4, + gutter: 1em, + ..range(1, 5).map(i => image("out/" + str(i) + ".png")) ), -) +)) diff --git a/assets/manual.pdf b/assets/manual.pdf index a66f6d0..9359a93 100644 Binary files a/assets/manual.pdf and b/assets/manual.pdf differ diff --git a/docs/manual/chapters/guide/faq.typ b/docs/manual/chapters/guide/faq.typ index 747f5c8..d8dfe49 100644 --- a/docs/manual/chapters/guide/faq.typ +++ b/docs/manual/chapters/guide/faq.typ @@ -1,4 +1,4 @@ -#import "/docs/manual/util.typ": issues, issue, mantys +#import "/docs/manual/util.typ": issue, issues, mantys #import mantys: * == Frequently Asked Questions diff --git a/docs/manual/chapters/guide/features.typ b/docs/manual/chapters/guide/features.typ index f9c4a55..8f50634 100644 --- a/docs/manual/chapters/guide/features.typ +++ b/docs/manual/chapters/guide/features.typ @@ -1,4 +1,4 @@ -#import "/docs/manual/util.typ": load-examples, show-examples, issue, mantys +#import "/docs/manual/util.typ": issue, load-examples, mantys, show-examples #import mantys: * == Features @@ -22,7 +22,11 @@ This is turned on by default. #let skip = load-examples("skip") #figure( - frame(grid(columns: 2, gutter: 1em, show-examples(skip.a), show-examples(skip.b))), + frame(grid( + columns: 2, + gutter: 1em, + show-examples(skip.a), show-examples(skip.b), + )), caption: [ Two example documents showing the difference between #arg(skip-starting: true) (left) and #arg(skip-starting: false) (right). ], @@ -58,7 +62,11 @@ This is turned off by default. #let book = load-examples("book") #figure( - frame(grid(columns: 2, gutter: 1em, show-examples(book.a), show-examples(book.b))), + frame(grid( + columns: 2, + gutter: 1em, + show-examples(book.a), show-examples(book.b), + )), caption: [ Two example documents showing the difference between #arg(book: false) (left) and #arg(book: true) (right). ], diff --git a/docs/manual/chapters/reference.typ b/docs/manual/chapters/reference.typ index 7a9fd10..ad5fc03 100644 --- a/docs/manual/chapters/reference.typ +++ b/docs/manual/chapters/reference.typ @@ -82,6 +82,7 @@ Defines the options passed to @cmd:hydra and resolved contextual information nee #pagebreak() +// @typstyle off #let mods = ( ("hydra", "/src/lib.typ", true, [ The package entry point. @@ -107,15 +108,11 @@ Defines the options passed to @cmd:hydra and resolved contextual information nee #let render-module(name, path, is-stable, description) = [ #heading(depth: 3, name) #label("sec:mod:" + name) - #place( - right, - dy: -2.4em, - if is-stable { - bbox(fill: green.lighten(50%), `stable`) - } else { - bbox(fill: yellow.lighten(50%), `unstable`) - }, - ) + #place(right, dy: -2.4em, if is-stable { + bbox(fill: green.lighten(50%), `stable`) + } else { + bbox(fill: yellow.lighten(50%), `unstable`) + }) #import "/docs/manual/util.typ": mantys #description diff --git a/docs/manual/manual.typ b/docs/manual/manual.typ index 603583c..b18d7e9 100644 --- a/docs/manual/manual.typ +++ b/docs/manual/manual.typ @@ -1,4 +1,4 @@ -#import "util.typ": package, mantys +#import "util.typ": mantys, package #show: mantys.mantys( ..package, @@ -9,10 +9,11 @@ Hydra provides a simple API to query for headings und section like elements and display them in your document's headers. It aids in creating headers and footers with navigational snippets. ], - theme: mantys.create-theme( + // TODO(tinger): This seems to be unaffected in typstyle `0.13.14`. + theme: /* @typstyle off */ mantys.create-theme( fonts: (sans: "TeX Gyre Heros"), heading: (font: "TeX Gyre Heros"), - ) + ), ) // replace the version in all examples with the current version @@ -34,7 +35,7 @@ [ ] numbering(it.numbering, ..counter(figure.where(kind: it.kind)).get()) }), - it.body + it.body, )) #include "chapters/guide.typ" diff --git a/docs/manual/util.typ b/docs/manual/util.typ index 5392860..aef3dd4 100644 --- a/docs/manual/util.typ +++ b/docs/manual/util.typ @@ -1,4 +1,4 @@ -#import "@preview/mantys:1.0.0" +#import "@preview/mantys:1.0.2" #let package = toml("/typst.toml").package @@ -17,11 +17,22 @@ radius: 0.25em, fill: theme.muted.bg, inset: 0.5em, - grid(columns: (1fr, 1fr), gutter: 0.5em, align(center + horizon)[Binding], ..examples), + grid( + columns: (1fr, 1fr), + gutter: 0.5em, + align( + center + horizon, + )[Binding], + ..examples, + ), ) -#let issue(num) = text(eastern, link(package.repository + "/issues/" + str(num))[hydra\##num]) +#let issue(num) = text(eastern, link( + package.repository + "/issues/" + str(num), +)[hydra\##num]) -#let issues = text(eastern, link(package.repository + "/issues/")[GitHub:tingerrr/hydra]) +#let issues = text(eastern, link( + package.repository + "/issues/", +)[GitHub:tingerrr/hydra]) #let bbox = box.with(inset: (x: 0.25em), outset: (y: 0.25em), radius: 0.25em) diff --git a/src/_pkgs.typ b/src/_pkgs.typ index 607cf95..9957627 100644 --- a/src/_pkgs.typ +++ b/src/_pkgs.typ @@ -1 +1 @@ -#import "@preview/oxifmt:0.2.1" +#import "@preview/oxifmt:1.0.0" diff --git a/src/core.typ b/src/core.typ index 95b811b..63a82cb 100644 --- a/src/core.typ +++ b/src/core.typ @@ -60,7 +60,7 @@ assert.eq( anchor.page(), here().page(), - message: "`anchor()` must be on every page before the first use of `hydra`" + message: "`anchor()` must be on every page before the first use of `hydra`", ) anchor @@ -94,12 +94,26 @@ let next-ancestor = none if ctx.ancestors != none { - let prev-ancestors = query(selector(ctx.ancestors.target).before(ctx.anchor-loc)) - let next-ancestors = query(selector(ctx.ancestors.target).after(ctx.anchor-loc)) + let prev-ancestors = query( + selector(ctx.ancestors.target).before( + ctx.anchor-loc, + ), + ) + let next-ancestors = query( + selector(ctx.ancestors.target).after( + ctx.anchor-loc, + ), + ) if ctx.ancestors.filter != none { - prev-ancestors = prev-ancestors.filter(x => (ctx.ancestors.filter)(ctx, x)) - next-ancestors = next-ancestors.filter(x => (ctx.ancestors.filter)(ctx, x)) + prev-ancestors = prev-ancestors.filter(x => (ctx.ancestors.filter)( + ctx, + x, + )) + next-ancestors = next-ancestors.filter(x => (ctx.ancestors.filter)( + ctx, + x, + )) } if scope-prev and prev-ancestors != () { @@ -122,8 +136,12 @@ next-targets = next-targets.filter(x => (ctx.primary.filter)(ctx, x)) last-targets = last-targets.filter(x => (ctx.primary.filter)(ctx, x)) } - next-targets = next-targets.filter(x => x.location().page() == ctx.anchor-loc.page()) - last-targets = last-targets.filter(x => x.location().page() == ctx.anchor-loc.page()) + next-targets = next-targets.filter(x => ( + x.location().page() == ctx.anchor-loc.page() + )) + last-targets = last-targets.filter(x => ( + x.location().page() == ctx.anchor-loc.page() + )) let prev = if prev-targets != () { prev-targets.last() } let next = if next-targets != () { next-targets.first() } @@ -151,8 +169,12 @@ /// -> candidates candidates, ) = { - let next = if candidates.primary.next != none { candidates.primary.next.location() } - let next-ancestor = if candidates.ancestor.next != none { candidates.ancestor.next.location() } + let next = if candidates.primary.next != none { + candidates.primary.next.location() + } + let next-ancestor = if candidates.ancestor.next != none { + candidates.ancestor.next.location() + } let next-starting = if next != none { next.page() == here().page() and next.position().y <= get-top-margin() @@ -161,7 +183,10 @@ } let next-ancestor-starting = if next-ancestor != none { - next-ancestor.page() == here().page() and next-ancestor.position().y <= get-top-margin() + ( + next-ancestor.page() == here().page() + and next-ancestor.position().y <= get-top-margin() + ) } else { false } @@ -185,7 +210,9 @@ candidates, ) = { let is-leading-page = calc.odd(here().page()) - let active-on-prev-page = candidates.primary.prev.location().page() == here().page() - 1 + let active-on-prev-page = ( + candidates.primary.prev.location().page() == here().page() - 1 + ) is-leading-page and active-on-prev-page } @@ -207,8 +234,8 @@ ) = { let active-visible = ( ctx.book - and candidates.primary.prev != none - and is-active-visible(ctx, candidates) + and candidates.primary.prev != none + and is-active-visible(ctx, candidates) ) let starting-page = is-on-starting-page(ctx, candidates) @@ -259,16 +286,24 @@ /// -> hydra-context ctx, ) = { - ctx.anchor-loc = if ctx.anchor != none and here().position().y > get-top-margin() { + ctx.anchor-loc = if ( + ctx.anchor != none and here().position().y > get-top-margin() + ) { locate-last-anchor(ctx) } else { here() } let candidates = get-candidates(ctx) - let prev-eligible = candidates.primary.prev != none and (ctx.prev-filter)(ctx, candidates) - let next-eligible = candidates.primary.next != none and (ctx.next-filter)(ctx, candidates) - let last-eligible = candidates.primary.last != none and (ctx.next-filter)(ctx, candidates) + let prev-eligible = ( + candidates.primary.prev != none and (ctx.prev-filter)(ctx, candidates) + ) + let next-eligible = ( + candidates.primary.next != none and (ctx.next-filter)(ctx, candidates) + ) + let last-eligible = ( + candidates.primary.last != none and (ctx.next-filter)(ctx, candidates) + ) let active-redundant = is-active-redundant(ctx, candidates) if active-redundant and ctx.skip-starting { diff --git a/src/lib.typ b/src/lib.typ index ae20f34..c775098 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -82,15 +82,14 @@ util.assert.types("anchor", anchor, label, none) let (named, pos) = (sel.named(), sel.pos()) - assert.eq( - named.len(), - 0, - message: util.fmt("Unexected named arguments: `{}`", named), - ) - assert( - pos.len() <= 1, - message: util.fmt("Unexpected positional arguments: `{}`", pos), - ) + assert.eq(named.len(), 0, message: util.fmt( + "Unexected named arguments: `{}`", + named, + )) + assert(pos.len() <= 1, message: util.fmt( + "Unexpected positional arguments: `{}`", + pos, + )) let sanitized = selectors.sanitize("sel", pos.at(0, default: heading)) diff --git a/src/selectors.typ b/src/selectors.typ index 05080d0..4f62e85 100644 --- a/src/selectors.typ +++ b/src/selectors.typ @@ -42,7 +42,9 @@ ( primary: (target: element, filter: filter), - ancestors: if ancestors != none { (target: ancestors, filter: ancestors-filter) }, + ancestors: if ancestors != none { + (target: ancestors, filter: ancestors-filter) + }, ) } @@ -64,14 +66,14 @@ ..exact, ) = { let (named, pos) = (exact.named(), exact.pos()) - assert.eq( - named.len(), 0, - message: util.fmt("Unexected named arguments: `{}`", named), - ) - assert( - pos.len() <= 1, - message: util.fmt("Unexpected positional arguments: `{}`", pos), - ) + assert.eq(named.len(), 0, message: util.fmt( + "Unexected named arguments: `{}`", + named, + )) + assert(pos.len() <= 1, message: util.fmt( + "Unexpected positional arguments: `{}`", + pos, + )) exact = pos.at(0, default: none) @@ -80,7 +82,9 @@ util.assert.types("exact", exact, int, none) if min == none and max == none and exact == none { - panic("Use `heading` directly if you have no `min`, `max` or `exact` level bound") + panic( + "Use `heading` directly if you have no `min`, `max` or `exact` level bound", + ) } if exact != none and (min != none or max != none) { @@ -105,7 +109,7 @@ let (ancestors, ancestors-filter) = if exact != none { (heading, (ctx, e) => e.level < exact) - } else if min != none and min > 1 { + } else if min != none and min > 1 { (heading, (ctx, e) => e.level < min) } else { (none, none) @@ -140,7 +144,9 @@ message: auto, ) = { let message = util.or-default(check: auto, message, () => util.fmt( - "`{}` must be a `selector`, a level, or a custom hydra-selector, was {}", name, sel, + "`{}` must be a `selector`, a level, or a custom hydra-selector, was {}", + name, + sel, )) if type(sel) == selector { @@ -148,17 +154,23 @@ // NOTE: because `repr(math.equation) == equation` we add it to the scope // NOTE: No, I don't like this either - let func = eval(if parts.len() == 1 { - parts.first() - } else { - parts.slice(0, -1).join(".") - }, scope: (equation: math.equation)) + let func = eval( + if parts.len() == 1 { + parts.first() + } else { + parts.slice(0, -1).join(".") + }, + scope: (equation: math.equation), + ) if func == heading { let fields = (:) if parts.len() > 1 { let args = parts.remove(-1) - for arg in args.trim("where").trim(regex("\(|\)"), repeat: false).split(",") { + for arg in args + .trim("where") + .trim(regex("\(|\)"), repeat: false) + .split(",") { let (name, val) = arg.split(":").map(str.trim) fields.insert(name, eval(val)) } @@ -174,7 +186,9 @@ by-level(sel) } else if type(sel) == function { custom(sel) - } else if type(sel) == dictionary and "primary" in sel and "ancestors" in sel { + } else if ( + type(sel) == dictionary and "primary" in sel and "ancestors" in sel + ) { sel } else { panic(message) diff --git a/src/util/assert.typ b/src/util/assert.typ index df1a9d7..934b013 100644 --- a/src/util/assert.typ +++ b/src/util/assert.typ @@ -23,16 +23,25 @@ message: auto, ) = { expected-values = expected-values.pos() - let message = _core.or-default(check: auto, message, () => if expected-values.len() == 1 { - _core.fmt("`{}` must be `{}`, was `{}`", name, expected-values.first(), value) - } else { - _core.fmt( - "`{}` must be one of {}, was `{}`", - name, - expected-values.map(_core.fmt.with("`{}`")).join(", ", last: " or "), - value, - ) - }) + let message = _core.or-default( + check: auto, + message, + () => if expected-values.len() == 1 { + _core.fmt( + "`{}` must be `{}`, was `{}`", + name, + expected-values.first(), + value, + ) + } else { + _core.fmt( + "`{}` must be one of {}, was `{}`", + name, + expected-values.map(_core.fmt.with("`{}`")).join(", ", last: " or "), + value, + ) + }, + ) assert(value in expected-values, message: message) } @@ -59,23 +68,34 @@ message: auto, ) = { let given-type = type(value) - expected-types = expected-types.pos().map(t => if t == none { - type(none) - } else if t == auto { - type(auto) - } else { - t - }) - let message = _core.or-default(check: auto, message, () => if expected-types.len() == 1 { - _core.fmt("`{}` must be a `{}`, was `{}`", name, expected-types.first(), given-type) - } else { - _core.fmt( - "`{}` must be one of a {}, was `{}`", - name, - expected-types.map(_core.fmt.with("`{}`")).join(", ", last: " or "), - given-type, - ) - }) + expected-types = expected-types + .pos() + .map(t => if t == none { + type(none) + } else if t == auto { + type(auto) + } else { + t + }) + let message = _core.or-default( + check: auto, + message, + () => if expected-types.len() == 1 { + _core.fmt( + "`{}` must be a `{}`, was `{}`", + name, + expected-types.first(), + given-type, + ) + } else { + _core.fmt( + "`{}` must be one of a {}, was `{}`", + name, + expected-types.map(_core.fmt.with("`{}`")).join(", ", last: " or "), + given-type, + ) + }, + ) assert(given-type in expected-types, message: message) } @@ -103,16 +123,25 @@ ) = { let given-func = element.func() expected-funcs = expected-funcs.pos() - let message = _core.or-default(check: auto, message, () => if expected-funcs.len() == 1 { - _core.fmt("`{}` must be a `{}`, was `{}`", name, expected-funcs.first(), given-func) - } else { - _core.fmt( - "`{}` must be one of a {}, was `{}`", - name, - expected-funcs.map(_core.fmt.with("`{}`")).join(", ", last: " or a"), - given-func, - ) - }) + let message = _core.or-default( + check: auto, + message, + () => if expected-funcs.len() == 1 { + _core.fmt( + "`{}` must be a `{}`, was `{}`", + name, + expected-funcs.first(), + given-func, + ) + } else { + _core.fmt( + "`{}` must be one of a {}, was `{}`", + name, + expected-funcs.map(_core.fmt.with("`{}`")).join(", ", last: " or a"), + given-func, + ) + }, + ) types(name, element, content, message: message) assert(given-func in expected-funcs, message: message) @@ -135,11 +164,15 @@ message: auto, ) = { let given-type = type(value) - let message = _core.or-default(check: auto, message, () => _core.fmt( - "`{}` must be queryable, such as an element function, selector or label, `{}` is not queryable", - name, - given-type, - )) + let message = _core.or-default( + check: auto, + message, + () => _core.fmt( + "`{}` must be queryable, such as an element function, selector or label, `{}` is not queryable", + name, + given-type, + ), + ) types(name, value, label, function, selector, message: message) diff --git a/src/util/core.typ b/src/util/core.typ index 3954732..71468c7 100644 --- a/src/util/core.typ +++ b/src/util/core.typ @@ -38,8 +38,21 @@ /// /// -> str lang, -) = if lang in ( - "ar", "dv", "fa", "he", "ks", "pa", "ps", "sd", "ug", "ur", "yi", +) = if ( + lang + in ( + "ar", + "dv", + "fa", + "he", + "ks", + "pa", + "ps", + "sd", + "ug", + "ur", + "yi", + ) ) { rtl } else { ltr } /// Returns the page binding for a text direction. diff --git a/tests/features/book-mode/ref.typ b/tests/features/book-mode/ref.typ index 1be14ad..09a024d 100644 --- a/tests/features/book-mode/ref.typ +++ b/tests/features/book-mode/ref.typ @@ -1,15 +1,12 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context ( - none, - none, - none, - [2.1 First Section], - none, - [2.2 Second Section], - ).at(counter(page).get().first() - 1), -) +#set page(paper: "a7", header: context ( + none, + none, + none, + [2.1 First Section], + none, + [2.2 Second Section], +).at(counter(page).get().first() - 1)) #include "document.typ" diff --git a/tests/features/book-mode/test.typ b/tests/features/book-mode/test.typ index efbc202..7ee9e66 100644 --- a/tests/features/book-mode/test.typ +++ b/tests/features/book-mode/test.typ @@ -4,9 +4,6 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context hydra(book: true), -) +#set page(paper: "a7", header: context hydra(book: true)) #include "document.typ" diff --git a/tests/features/fallback/ref.typ b/tests/features/fallback/ref.typ index d12f021..666f023 100644 --- a/tests/features/fallback/ref.typ +++ b/tests/features/fallback/ref.typ @@ -1,13 +1,10 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context ( - none, - [1.1 First Section], - [1.2 Second Section], - none, - ).at(counter(page).get().first() - 1), -) +#set page(paper: "a7", header: context ( + none, + [1.1 First Section], + [1.2 Second Section], + none, +).at(counter(page).get().first() - 1)) #include "document.typ" diff --git a/tests/features/fallback/test.typ b/tests/features/fallback/test.typ index 980c8b7..9e12794 100644 --- a/tests/features/fallback/test.typ +++ b/tests/features/fallback/test.typ @@ -4,9 +4,6 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context hydra(skip-starting: false, 2), -) +#set page(paper: "a7", header: context hydra(skip-starting: false, 2)) #include "document.typ" diff --git a/tests/features/footer/ref.typ b/tests/features/footer/ref.typ index 396d94c..5def592 100644 --- a/tests/features/footer/ref.typ +++ b/tests/features/footer/ref.typ @@ -1,15 +1,12 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - footer: context ( - none, - [1 Introduction], - [1 Introduction], - none, - none, - [2.2 Second Section], - ).at(counter(page).get().first() - 1), -) +#set page(paper: "a7", footer: context ( + none, + [1 Introduction], + [1 Introduction], + none, + none, + [2.2 Second Section], +).at(counter(page).get().first() - 1)) #include "document.typ" diff --git a/tests/features/footer/test.typ b/tests/features/footer/test.typ index ea01254..338ceb3 100644 --- a/tests/features/footer/test.typ +++ b/tests/features/footer/test.typ @@ -4,12 +4,8 @@ /// - Usage of an anchor ensures query results consistent with those in the /// header. -#import "/src/lib.typ": hydra, anchor +#import "/src/lib.typ": anchor, hydra -#set page( - paper: "a7", - header: anchor(), - footer: context hydra(), -) +#set page(paper: "a7", header: anchor(), footer: context hydra()) #include "document.typ" diff --git a/tests/features/use-last/basic/ref.typ b/tests/features/use-last/basic/ref.typ index 5a9d315..fc39de5 100644 --- a/tests/features/use-last/basic/ref.typ +++ b/tests/features/use-last/basic/ref.typ @@ -1,16 +1,13 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context ( - none, - [1 Introduction], - [1 Introduction], - none, - none, - [2.3 Third Section], - [2.3 Third Section], - ).at(counter(page).get().first() - 1), -) +#set page(paper: "a7", header: context ( + none, + [1 Introduction], + [1 Introduction], + none, + none, + [2.3 Third Section], + [2.3 Third Section], +).at(counter(page).get().first() - 1)) #include "document.typ" diff --git a/tests/features/use-last/basic/test.typ b/tests/features/use-last/basic/test.typ index 1e0f96e..48eceb9 100644 --- a/tests/features/use-last/basic/test.typ +++ b/tests/features/use-last/basic/test.typ @@ -4,9 +4,6 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context hydra(use-last: true), -) +#set page(paper: "a7", header: context hydra(use-last: true)) #include "document.typ" diff --git a/tests/features/use-last/multiple-ancestors/ref.typ b/tests/features/use-last/multiple-ancestors/ref.typ index a2ab912..8779dd3 100644 --- a/tests/features/use-last/multiple-ancestors/ref.typ +++ b/tests/features/use-last/multiple-ancestors/ref.typ @@ -1,13 +1,10 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context ( - none, - none, - [1.3 Third Section], - [3.1 Final Section], - ).at(counter(page).get().first() - 1), -) +#set page(paper: "a7", header: context ( + none, + none, + [1.3 Third Section], + [3.1 Final Section], +).at(counter(page).get().first() - 1)) #include "document.typ" diff --git a/tests/features/use-last/multiple-ancestors/test.typ b/tests/features/use-last/multiple-ancestors/test.typ index e3b0ad2..1c98f0e 100644 --- a/tests/features/use-last/multiple-ancestors/test.typ +++ b/tests/features/use-last/multiple-ancestors/test.typ @@ -4,9 +4,6 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context hydra(use-last: true, 2), -) +#set page(paper: "a7", header: context hydra(use-last: true, 2)) #include "document.typ" diff --git a/tests/regressions/fallback-to-future/test.typ b/tests/regressions/fallback-to-future/test.typ index 0812718..a053832 100644 --- a/tests/regressions/fallback-to-future/test.typ +++ b/tests/regressions/fallback-to-future/test.typ @@ -6,10 +6,7 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context hydra(), -) +#set page(paper: "a7", header: context hydra()) #set heading(numbering: "1.1") #show heading.where(level: 1): it => pagebreak(weak: true) + it #set par(justify: true) diff --git a/tests/regressions/precentage-margin/test.typ b/tests/regressions/precentage-margin/test.typ index 6055f86..40c971e 100644 --- a/tests/regressions/precentage-margin/test.typ +++ b/tests/regressions/precentage-margin/test.typ @@ -4,11 +4,10 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a4", - margin: (top: 10%), - header: context hydra(1, skip-starting: false), -) +#set page(paper: "a4", margin: (top: 10%), header: context hydra( + 1, + skip-starting: false, +)) #show heading.where(level: 1): it => pagebreak(weak: true) + it diff --git a/tests/regressions/scoped-search/test.typ b/tests/regressions/scoped-search/test.typ index f4cd3d3..872d652 100644 --- a/tests/regressions/scoped-search/test.typ +++ b/tests/regressions/scoped-search/test.typ @@ -9,16 +9,13 @@ #show heading.where(level: 1): it => pagebreak(weak: true) + it #set par(justify: true) -#set page( - paper: "a7", - header: context { - if calc.even(here().page()) { - align(left, hydra(1)) - } else { - align(right, hydra(2)) - } - }, -) +#set page(paper: "a7", header: context { + if calc.even(here().page()) { + align(left, hydra(1)) + } else { + align(right, hydra(2)) + } +}) = First Chapter == First section diff --git a/tests/regressions/zero-margin/test.typ b/tests/regressions/zero-margin/test.typ index 4ad3114..54fffa6 100644 --- a/tests/regressions/zero-margin/test.typ +++ b/tests/regressions/zero-margin/test.typ @@ -4,11 +4,7 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - margin: 0pt, - header: context hydra(), -) +#set page(paper: "a7", margin: 0pt, header: context hydra()) #set heading(numbering: "1.1") #show heading.where(level: 1): it => pagebreak(weak: true) + it #set par(justify: true) diff --git a/tests/template.typ b/tests/template.typ index 0681519..d9a0020 100644 --- a/tests/template.typ +++ b/tests/template.typ @@ -3,10 +3,7 @@ #import "/src/lib.typ": hydra -#set page( - paper: "a7", - header: context hydra(), -) +#set page(paper: "a7", header: context hydra()) #set heading(numbering: "1.1") #show heading.where(level: 1): it => pagebreak(weak: true) + it #set par(justify: true) diff --git a/typst.toml b/typst.toml index 637c604..06ff17c 100644 --- a/typst.toml +++ b/typst.toml @@ -1,7 +1,7 @@ [package] entrypoint = "src/lib.typ" name = "hydra" -version = "0.6.1" +version = "0.6.2" compiler = "0.12.0" authors = ["tinger "] repository = "https://github.com/tingerrr/hydra"