Skip to content

CSS tokens ​

The tokens are CSS custom properties that change the look of the component without overriding its rules. Set them on :root, on an ancestor of the viewer or on .paperpic:

css
:root {
  --paperpic-color-accent: #c2410c;
  --paperpic-radius: 0;
}
TokenLightDarkDescription
--paperpic-color-accent#0a84ff#5cb5ffAccent of the interface
--paperpic-color-dimrgb(0 0 0 / 50%)rgb(0 0 0 / 50%)Darkens the image around a selection
--paperpic-color-line#fff#fffLines over the image: the outline of a selection, the corner handles and the cross of the magnifier
--paperpic-color-line-shadowrgb(0 0 0 / 60%)rgb(0 0 0 / 60%)The shadow under each line, so it shows on any image
--paperpic-color-surface#fff#151e2eBackground of the interface
--paperpic-color-text#1a263c#f2f5f9Text of the interface
--paperpic-radius6px6pxCorner radius of the interface
--paperpic-transition-duration0.2s0.2sDuration of the interface transitions

Dark mode ​

The color tokens take their light or dark value with light-dark(), from the color-scheme of the page. Without color-scheme they are light. With color-scheme: dark they are dark, and with color-scheme: light dark they are dark when the system prefers a dark color scheme. Styling shows how to set it.

To choose both values of a token, use light-dark() too:

css
:root {
  --paperpic-color-accent: light-dark(#c2410c, #fb923c);
}

The colors that paint over the image, --paperpic-color-dim, --paperpic-color-line and --paperpic-color-line-shadow, have one value for both, because they sit on the photo and not on the interface. A line and its shadow go in pairs: with a dark line, choose a light shadow.

Stylesheet ​

Each package ships one stylesheet. Import it once in your app:

ts
import '@paperpic/core/style.css'

Its rules live in the paperpic cascade layer, so any CSS of yours outside a layer overrides them, whatever its specificity. This includes global resets, such as a rule on button. With Tailwind CSS, name the order of the layers, as Styling shows.

Classes ​

These classes are public: their names, and the elements they mark, stay stable between releases. The other classes of the component hold its layout together and can change in any release.

ClassElement
paperpicThe root of the viewer
paperpic-buttonEvery button of the toolbar and the edit bar
paperpic-button-dangerDiscard, in the question before discarding the changes
paperpic-button-primaryApply, and Done in every tool
paperpic-button-textThe buttons of the question before discarding the changes
paperpic-edit-barThe edit bar, a card at the bottom while editing
paperpic-editingThe root, while editing
paperpic-handleA corner handle of Crop and Straighten
paperpic-hostThe element that the Vue and React components render around the viewer
paperpic-iconThe icon of a button
paperpic-statusThe message that shows, and that screen readers hear, while the image loads or the changes apply, and on failure
paperpic-status-visibleThe message, while it shows in the middle of the viewer
paperpic-toolbarThe toolbar at the right, hidden while editing
paperpic-viewportThe area that shows the image and takes the keyboard focus

Buttons show their state with ARIA attributes, which you can select too:

AttributeState
[aria-disabled='true']The button cannot act now. It keeps the keyboard focus, so it is not disabled
[aria-pressed='true']The fit in effect, Fit to width or Fit to height, or the choice of Adjust that the ruler changes

The hover and these states paint with box-shadow, which global resets of buttons leave alone. To restyle them, override box-shadow too.

States ​

The root, .paperpic, carries the state of the viewer in data attributes, so CSS can follow it:

AttributeValues
data-paperpic-statusempty, loading, ready or error, as status in the state
data-paperpic-modeview or edit
data-paperpic-toolThe id of the open tool, such as crop. It is missing while no tool is open
css
.paperpic[data-paperpic-status='error'] .paperpic-status-visible {
  color: #b91c1c;
}

Controls ​

Every button, ruler and corner handle carries data-paperpic-control, with the key of its label. Select it to style one control:

css
.paperpic-button[data-paperpic-control='edit'] {
  color: var(--paperpic-color-accent);
}
PlaceValues
Toolbaredit, zoomIn, zoomOut, fitWidth, fitHeight, rotateLeft, rotateRight, download
Edit barcancel, crop, perspective, rotateLeft, flip, adjust, finish, redact, undo, redo, apply
Adjust and Clean upbrightness and contrast, the choices and their rulers, finishOriginal, finishGray and finishMono, the finishes, and finishSensitivity, its ruler
Every toolcancelTool, confirm
Crop, Straighten and RedactzoomIn, zoomOut, cornerTopLeft, cornerTopRight, cornerBottomRight, cornerBottomLeft
StraightenpaperAuto, paperA4, paperLetter, paperCard
RedactredactArea, redactTurn, redactBlack, redactWhite
Question before discardingkeepEditing, discard

rotateLeft names two buttons that never show at the same time: the one of a read-only viewer, which turns the display, and the one of the edit bar, which turns the image. So do zoomIn and zoomOut, in the toolbar and in a panel. brightness and contrast name a choice and its ruler, which show together: add button or input to the selector to tell them apart.

Released under the MIT License.