<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-book/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-book

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-book>` web component shows a book as a physical object, from the image of its front cover alone: front cover, spine and page block drawn in CSS 3D, turned a little so the spine shows. It is the catalogue and product-page counterpart of `<mds-img>`, for publications rather than pictures.

#### Semantic Behavior

- **One image of the book**: The host is a single `role="img"` named by `alt`, or by `name` and `author` ("Title by Author", localised in el/en/es/it), or by a generic "Book" when there is neither. An empty `alt` marks the book as decorative (`role="presentation"`). The text printed on the spine and on a drawn cover is hidden from assistive technologies, since it repeats that name.
- **The sides come from the cover**: The spine continues the left edge of the cover image and the board edges its top and right edges, as a wraparound cover prints its design on, so no spine or back cover image is needed. Without an image they take the colour of the drawn cover.
- **A drawn cover instead of a broken image**: Without `src`, or when the image fails to load, the front shows the author, the title and the publisher, or its mark, on `--mds-book-color`, which paints the drawn cover only. A new `src` tries again.
- **Printed on paper**: A book with `src` is bound in the colour of paper, the same in light and dark mode, as the image is: a blank book until its image arrives, then the paper wherever the image does not reach (its transparent parts, the spine and the edges until they paint it). So neither a lazy catalogue nor a cover that has just arrived flashes in the colour of drawn covers, and one library can mix books with and without a cover image with no setting.
- **Light and shadow**: The book is seen a little from above. Each face takes the light by how it turns toward it, in a light touch that shows the volume without drawing the eye. Its shadow falls on the surface it rests on, under its tail when it stands and under its back cover when it lies, darkest where it touches and soon gone; around its outline only a halo faint enough to part a light cover from a light page.
- **Movement**: The book rests in its `pose`. On hover it rises off the surface, its shadow fading there, and leans a little toward the pointer, with a faint sheen on the cover. A drag (mouse, pen or finger) turns it further, within limits, to show the spine or the pages, never the back, or spins a lying book on its surface; it settles back when released, or when the pointer leaves the window or the frame of the page, where its release could not reach the book. A vertical swipe still scrolls the page.
- **Not a control**: The book has no action of its own. To make it a link, wrap it: the click that ends a drag does not follow the link, a plain click does.
- **Reduced motion**: With the animation preference set to reduce (or the system asking for it, when there is no controller), the book keeps its resting pose: no lean, no lift, no drag.
- **Consumption**: The consumption preference sets how much the book costs to draw. At `high` (the default, and on a page without the controller) it does everything; at `medium` it moves without the sheen and without the halo, a filter computed again on every frame; at `low` it is drawn once, in its pose, and never animated. While it moves, only opacities and transforms change, which the compositor applies without painting the faces again.

#### Properties & Visual Configurations

- **`pose`**: how the book is shown, after the usual shots of product photography. A drag turns it from there, and it goes back to it when released.
  - `'spine'`: standing, turned to show its spine; the default, and the one for a catalogue.
  - `'fore-edge'`: standing, turned the other way to show its pages.
  - `'front'`: facing the reader, flat, the cover as it is; the light still shows the binding when it moves.
  - `'lying'`: lying on its back, seen from above, its tail toward the reader: a book on a desk.
  - `'lying-turned'`: lying, spun on the surface to show its spine and its tail.

- **`format`**: the proportions of the book, in one field that also carries the orientation.
  - `'auto'`: the proportions of the image, read once it has loaded (a square cover gives a square book); before that, and without an image, 17x24. Pick it when the image already has the true proportions.
  - `'a4'`, `'a5'`, `'b5'`: the ISO formats, portrait. Any other format is `WxH` in centimetres, the order of the two numbers being the orientation: `'17x24'` portrait, `'24x17'` landscape, `'21x21'` square. A fixed format keeps its shape before the image loads and crops small differences of the image.
- **`pages`**: the number of pages, from the catalogue record, which sets how deep the book is against the width of its format (17 cm for `'auto'`). A short book is printed on bulky paper and a long volume on thin paper, so a page goes from 0.1 mm at 1 page to 0.05 mm at 1000 pages and beyond, in proportion: 64 pages make 6 mm, 300 pages 2.5 cm, 1000 pages 5 cm, and an A4 of the same pages looks thinner than a 17x24. A spine under 5 mm carries no text.
- **`binding`**: how the book is built, which shows on its head, its fore edge and its spine.
  - `'paperback'`: cut flush, the cover a hairline on the same edge as the pages, a flat spine.
  - `'hardcover'`: rigid boards about 2.5 mm thick, overhanging a page block set in from them by about 3 mm, the endpapers showing in the gap, a headband, a rounded spine and a hinge groove on the front.
  - `'none'`: not bound, a stack of loose sheets cut flush, as a document is. The cover, image or drawn (author, title, publisher and its colour), is only the sheet on top, with no fold and no gloss; the pages show on all four sides, the side of the spine too, which carries no text.
- **`name`**, **`author`**, **`publisher`**: the same names as on `<mds-bibliography>`, so one catalogue record feeds both.
- **The spine**: the title, then the author, at the head, and the publisher at the foot. Where the spine has room for two lines, at least 13.5% as deep as the book is wide (about 23 mm on a 17x24, some 270 pages in paperback), the author goes under the title, smaller, as on a thick volume.
- **`publisher-logo`**: the mark of the publisher, printed instead of its name at the foot of the spine and of a drawn cover (a cover image carries its own). Only its shape is printed, as a mask, in `--mds-book-publisher-color`, which is the colour of the text unless set, so a mark of any colour prints in the ink of the book. Give an svg, or a png on a transparent ground; an image from another origin needs CORS headers, as any mask does. The place stays empty while the mark loads, and the name of the publisher is printed if it fails.
- **Size**: the book is sized as an image is, in the proportions of its format: give it a width, and its height follows; give it a height, and its width follows. With neither, it fills the width of its container, as a block does; where nothing gives it a width (a row of a flex layout) it is 200 px wide. Its box is the front cover at rest: the turned book reaches a little beyond it, by a few percent of its width on each side standing, by up to a third lying spun round, so leave it some room inside a container that clips.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-book--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `alt` | `alt` | `string \| undefined` | - | The accessible name of the book. Without it the name is built from `name` and `author`; an empty `alt` marks the book as decorative, left out by assistive technologies |
| `author` | `author` | `string \| undefined` | - | The author, printed on the cover drawn when there is no image, above the title, and on the spine after the title, or under it where the spine has room for two lines |
| `binding` | `binding` | `"hardcover" \| "none" \| "paperback"` | `'paperback'` | How the book is bound: a thin flexible cover flush with the pages, rigid boards a little larger than the page block, with a rounded spine, or not at all (`none`), a stack of loose sheets, a document: its cover is only the sheet on top, and the pages show on every side, the side of the spine too, where nothing is printed |
| `format` | `format` | `"a4" \| "a5" \| "auto" \| "b5" \| '${number}x${number}'` | `'auto'` | The proportions of the book. `auto` takes them from the image; a named format (`a4`, `a5`, `b5`) is portrait; any other one is `WxH` in centimetres, the order of the two numbers being the orientation (`17x24` portrait, `24x17` landscape, `21x21` square) |
| `loading` | `loading` | `"eager" \| "lazy" \| undefined` | `'lazy'` | Specifies whether a browser should load the cover immediately or defer it until it is near the viewport |
| `name` | `name` | `string \| undefined` | - | The title of the book, printed on the spine and on the cover drawn when there is no image |
| `pages` | `pages` | `number` | `300` | The number of pages, which sets how deep the book is, against the width of its format (17 cm for `auto`). A page is as thick as `--mds-book-page-weight-min` at 1 page, going to `--mds-book-page-weight-max` at 1000 pages and more, in proportion: by default from 0.1 mm, the bulky paper of a short book, to 0.05 mm, the thin paper of a volume, so 64 pages make 6 mm, 300 pages 2.5 cm and 1000 pages 5 cm. A spine under 5 mm deep carries no text |
| `pose` | `pose` | `"fore-edge" \| "front" \| "lying" \| "lying-turned" \| "spine"` | `'spine'` | How the book is shown: standing, turned to show its spine (`spine`) or its pages (`fore-edge`), or facing the reader (`front`); lying on its back, seen from above, its tail toward the reader (`lying`) or spun on the surface (`lying-turned`). A drag turns it from there, and it goes back when released |
| `publisher` | `publisher` | `string \| undefined` | - | The publisher, printed at the foot of the spine and of the cover drawn when there is no image, unless its `publisher-logo` is printed there instead |
| `publisherLogo` | `publisher-logo` | `string \| undefined` | - | The mark of the publisher, printed instead of its name at the foot of the spine and of the cover drawn when there is no image: the path to an svg, or a png on a transparent ground. Its shape is printed, not its colours, in `--mds-book-publisher-color`. An image from another origin needs CORS headers, as any mask does; one that does not load leaves the name |
| `src` | `src` | `string \| undefined` | - | Specifies the path to the image of the front cover |

## Parts

| Part | Description |
| --- | --- |
| `cover` | The native `<img>` that shows the front cover |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-book-color` | **Static**: a value of its own, not a token or a role. The colour of the cover drawn when there is no image (no src, or one that fails), with its spine and board edges. A book with an image does not take it: it is printed on paper. |
| `--mds-book-publisher-color` | **Static**: a value of its own, not a token or a role. The colour of the publisher at the foot of the spine and of the cover drawn when there is no image, its mark or its name. Unset, the colour of the text. |
| `--mds-book-spine-color` | **Static**: a value of its own, not a token or a role. A solid colour for the spine and the board edges. Unset, they continue the edges of the cover image. |
| `--mds-book-text-color` | **Static**: a value of its own, not a token or a role. The colour of the text on the spine and on the cover drawn when there is no image. |

Only these are public. Its other 3 are internal: they may change in any release, do not set them.
