From 22b8286ea5b28532a1cacd4a49a4aff2a886e9ee Mon Sep 17 00:00:00 2001 From: spring-raining Date: Sun, 8 Sep 2024 17:16:55 +0900 Subject: [PATCH 1/3] fix: Fix cases where both the chapter and part page counters are set --- .changeset/clean-socks-think.md | 5 +++ .../theme-base/css/common/meta-properties.css | 9 +++++ .../theme-base/css/partial/page.css | 37 ++++++++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 .changeset/clean-socks-think.md diff --git a/.changeset/clean-socks-think.md b/.changeset/clean-socks-think.md new file mode 100644 index 0000000..a48efb5 --- /dev/null +++ b/.changeset/clean-socks-think.md @@ -0,0 +1,5 @@ +--- +"@vivliostyle/theme-base": patch +--- + +Fix cases where both the chapter and part page counters are set diff --git a/packages/@vivliostyle/theme-base/css/common/meta-properties.css b/packages/@vivliostyle/theme-base/css/common/meta-properties.css index 7a75f10..95a8eb1 100644 --- a/packages/@vivliostyle/theme-base/css/common/meta-properties.css +++ b/packages/@vivliostyle/theme-base/css/common/meta-properties.css @@ -68,4 +68,13 @@ */ --vs-document-root-counter-reset: ; --vs-first-page-counter-reset: ; + + /** + * Counter increments + * It is used for incrementing CSS counters on a first page of a document + * Caution: Don't set counter-reset directly otherwise all other counters will be ignored. + * OK: :root { --vs-document-first-page-counter-increment: foo bar; } + * NG: @page :nth(1) { counter-increment: foo bar; } + */ + --vs-document-first-page-counter-increment: ; } diff --git a/packages/@vivliostyle/theme-base/css/partial/page.css b/packages/@vivliostyle/theme-base/css/partial/page.css index 8393f66..1faaa7f 100644 --- a/packages/@vivliostyle/theme-base/css/partial/page.css +++ b/packages/@vivliostyle/theme-base/css/partial/page.css @@ -426,22 +426,37 @@ * document counters */ +html.chapter, +body.chapter { + page: chapter-document; +} + html.part, -body.part, -[role='doc-part'] { - page: part; +body.part { + page: part-document; +} + +html.part.chapter, +body.part.chapter { + page: part-chapter-document; } @page :nth(1) { - counter-increment: vs-counter-doc; + counter-increment: var(--vs-page--doc-counter-increment, vs-counter-doc) + var(--vs-document-first-page-counter-increment,); } -@page part:nth(1) { - counter-increment: vs-counter-doc vs-counter-part; +@page chapter-document { + --vs-page--doc-counter-increment: vs-counter-doc vs-counter-chapter; } -@page chapter:nth(1) { - counter-increment: vs-counter-doc vs-counter-chapter; +@page part-document { + --vs-page--doc-counter-increment: vs-counter-doc vs-counter-part; +} + +@page part-chapter-document { + --vs-page--doc-counter-increment: vs-counter-doc vs-counter-part + vs-counter-chapter; } /* @@ -489,12 +504,6 @@ body.bibliography, page: bibliography; } -html.chapter, -body.chapter, -[role='doc-chapter'] { - page: chapter; -} - html.conclusion, body.conclusion, [role='doc-conclusion'] { From fc5f428477a74e52614e9201148df2046ddc8d8b Mon Sep 17 00:00:00 2001 From: spring-raining Date: Sun, 8 Sep 2024 17:19:35 +0900 Subject: [PATCH 2/3] fix: Don't increment vs-counter-doc for ToC/cover documents --- .changeset/hip-parrots-rush.md | 5 +++++ .../theme-base/css/partial/page.css | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .changeset/hip-parrots-rush.md diff --git a/.changeset/hip-parrots-rush.md b/.changeset/hip-parrots-rush.md new file mode 100644 index 0000000..7c08a75 --- /dev/null +++ b/.changeset/hip-parrots-rush.md @@ -0,0 +1,5 @@ +--- +"@vivliostyle/theme-base": patch +--- + +Don't increment `vs-counter-doc` for ToC/cover documents diff --git a/packages/@vivliostyle/theme-base/css/partial/page.css b/packages/@vivliostyle/theme-base/css/partial/page.css index 1faaa7f..9783206 100644 --- a/packages/@vivliostyle/theme-base/css/partial/page.css +++ b/packages/@vivliostyle/theme-base/css/partial/page.css @@ -441,6 +441,14 @@ body.part.chapter { page: part-chapter-document; } +body:has([role='doc-toc']) { + page: toc-document; +} + +body:has([role='doc-cover']) { + page: cover-document; +} + @page :nth(1) { counter-increment: var(--vs-page--doc-counter-increment, vs-counter-doc) var(--vs-document-first-page-counter-increment,); @@ -459,6 +467,16 @@ body.part.chapter { vs-counter-chapter; } +@page toc-document { + /* Don't increment vs-counter-doc for ToC documents */ + --vs-page--doc-counter-increment: vs-counter-doc 0; +} + +@page cover-document { + /* Don't increment vs-counter-doc for cover documents */ + --vs-page--doc-counter-increment: vs-counter-doc 0; +} + /* * cover pages */ From 18ed51aea1248c440d1d77b2fab46450844dbbfd Mon Sep 17 00:00:00 2001 From: spring-raining Date: Sun, 8 Sep 2024 18:40:20 +0900 Subject: [PATCH 3/3] feat: Add variables to override the initial counter value at the document root see #129 --- .changeset/neat-windows-exist.md | 11 +++++++++++ packages/@vivliostyle/theme-base/css/common/basic.css | 1 + .../@vivliostyle/theme-base/css/partial/crossref.css | 6 ++++-- .../@vivliostyle/theme-base/css/partial/footnote.css | 3 ++- .../@vivliostyle/theme-base/css/partial/section.css | 8 ++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .changeset/neat-windows-exist.md diff --git a/.changeset/neat-windows-exist.md b/.changeset/neat-windows-exist.md new file mode 100644 index 0000000..6595e60 --- /dev/null +++ b/.changeset/neat-windows-exist.md @@ -0,0 +1,11 @@ +--- +"@vivliostyle/theme-base": minor +--- + +Add variables to override the initial counter value at the document root. + +The following CSS variables are supported: + +- `--vs-crossref--root-counter-{fig|tbl|cite}` +- `--vs-footnote--root-counter-footnote` +- `--vs-section--root-counter-{sections|sec-h1|sec-h2|sec-h3|sec-h4|sec-h5|sec-h6}` diff --git a/packages/@vivliostyle/theme-base/css/common/basic.css b/packages/@vivliostyle/theme-base/css/common/basic.css index 896446d..931ae53 100644 --- a/packages/@vivliostyle/theme-base/css/common/basic.css +++ b/packages/@vivliostyle/theme-base/css/common/basic.css @@ -178,6 +178,7 @@ html { body { counter-reset: var(--vs-crossref--root-counter-reset,) var(--vs-footnote--root-counter-reset,) + var(--vs-section--root-counter-reset,) var(--vs-document-root-counter-reset,); } diff --git a/packages/@vivliostyle/theme-base/css/partial/crossref.css b/packages/@vivliostyle/theme-base/css/partial/crossref.css index b6e79db..d714d3f 100644 --- a/packages/@vivliostyle/theme-base/css/partial/crossref.css +++ b/packages/@vivliostyle/theme-base/css/partial/crossref.css @@ -25,8 +25,10 @@ counter(vs-counter-tbl, var(--vs-crossref--counter-style)) ': '; --vs-crossref--marker-cite-content: '[' counter(vs-counter-cite) ']'; --vs-crossref--marker-margin-inline: 0; - --vs-crossref--root-counter-reset: vs-counter-fig vs-counter-tbl - vs-counter-cite; + --vs-crossref--root-counter-reset: vs-counter-fig + var(--vs-crossref--root-counter-fig,) vs-counter-tbl + var(--vs-crossref--root-counter-tbl,) vs-counter-cite + var(--vs-crossref--root-counter-cite,); /* displays dummy content on screen media that doesn't support target-counter() */ --vs-crossref--call-fig-content-on-screen: 'Figure ???'; diff --git a/packages/@vivliostyle/theme-base/css/partial/footnote.css b/packages/@vivliostyle/theme-base/css/partial/footnote.css index 8c41d50..1d08141 100644 --- a/packages/@vivliostyle/theme-base/css/partial/footnote.css +++ b/packages/@vivliostyle/theme-base/css/partial/footnote.css @@ -17,7 +17,8 @@ --vs-footnote--area-before-margin-inline: var(--vs--hr-margin-inline); --vs-footnote--item-margin-block: 0; --vs-footnote--item-margin-inline: 0; - --vs-footnote--root-counter-reset: vs-counter-footnote; + --vs-footnote--root-counter-reset: vs-counter-footnote + var(--vs-footnote--root-counter-footnote,); } .footnote, diff --git a/packages/@vivliostyle/theme-base/css/partial/section.css b/packages/@vivliostyle/theme-base/css/partial/section.css index 55b6c0f..a9f3077 100644 --- a/packages/@vivliostyle/theme-base/css/partial/section.css +++ b/packages/@vivliostyle/theme-base/css/partial/section.css @@ -19,6 +19,14 @@ var(--vs-section--counter-style) ); --vs-section--marker-margin-inline: 1ch; + --vs-section--root-counter-reset: vs-counter-sections + var(--vs-section--root-counter-sections,) vs-counter-sec-h1 + var(--vs-section--root-counter-sec-h1,) vs-counter-sec-h2 + var(--vs-section--root-counter-sec-h2,) vs-counter-sec-h3 + var(--vs-section--root-counter-sec-h3,) vs-counter-sec-h4 + var(--vs-section--root-counter-sec-h4,) vs-counter-sec-h5 + var(--vs-section--root-counter-sec-h5,) vs-counter-sec-h6 + var(--vs-section--root-counter-sec-h6,); } :lang(ja) {