Fidus Writer Toolkit — reusable TypeScript utilities, UI helpers and styles originally written for Fidus Writer but usable in any browser project.
import {escapeText, addAlert} from "fwtoolkit"
import {convertDataURIToBlob} from "fwtoolkit/blob.js"The source is written in TypeScript and ships with declaration files:
import {Dialog} from "fwtoolkit/dialog.js"The package ships the styles for its UI components under fwtoolkit/css/.
Load colors.css and tokens.css first (they define the design tokens), then
the component styles you need. If the host page has not already applied a CSS
reset, load reset.css before the component styles:
<link rel="stylesheet" href="node_modules/fwtoolkit/css/reset.css" />
<link rel="stylesheet" href="node_modules/fwtoolkit/css/colors.css" />
<link rel="stylesheet" href="node_modules/fwtoolkit/css/tokens.css" />
<link rel="stylesheet" href="node_modules/fwtoolkit/css/dialog.css" />
<link rel="stylesheet" href="node_modules/fwtoolkit/css/buttons.css" />css/tokens.css defines the semantic Design 5 layer (--fw-*): typography
(Poppins UI typeface, size/weight/line-height scales), colours, radii, sizing,
spacing, motion and z-index. New component code should use these tokens.
The legacy token names in css/colors.css (--main-*, --cs-*,
--overview-*, --input-*, --tabs-*, …) are retained and now alias the
semantic layer, so existing host stylesheets keep working unchanged.
Contrast rules are enforced by test/contrast.test.ts:
--fw-brand(#50c95f) is a fill only — it never reaches 4.5:1 on white. Text on green uses--fw-text-on-brand(#292929, ~6.8:1).--fw-accent(blue) is safe for text and for white-on-accent.- Non-text control strokes use
--fw-border-control(#8c8c8c, ≥3:1). --fw-text-secondaryis darkened to#656565so secondary text still passes AA on--fw-surface-2; the mock's lighter#848383is available as--fw-text-tertiaryfor large/decorative text only.
Wrap a labelled field in .fw-floating-field to get a Material-style text
field: the label sits inside the field while it is empty and unfocused, and
rises above it on focus or once the field has content.
<div class="fw-floating-field">
<label for="title">Title of publication</label>
<input type="text" id="title" placeholder=" " />
</div>
<script type="module">
import {initFloatingLabels} from "fwtoolkit"
initFloatingLabels() // call again for fields added later, e.g. dialogs
</script>- The input needs a placeholder — a single space is enough.
- Focus is handled entirely in CSS (
:focus-within);initFloatingLabels()only tracks the "has content" state (.fw-filled) and the disabled state. - Call
initFloatingLabels(dialog.dialogEl)after opening a dialog, since the dialog body does not exist until then. - Motion is disabled under
prefers-reduced-motion.
All interactive components use a single :focus-visible ring
(--fw-focus), keep their keyboard operability and ARIA semantics, and honour
prefers-reduced-motion. The file dialog is a Finder-style column browser with
role="tree"/role="treeitem", roving tabindex, arrow-key navigation and a
clickable breadcrumb.
In Fidus Writer the CSS is copied automatically to the static files directory
by the copy_fwtoolkit_css postinstall step.
Live demos are published on Forgejo Pages:
https://fiduswriter.pages.fiduswriter.org/fwtoolkit/
To build and deploy the demos yourself, run:
npm run build
./scripts/deploy-pages.shYou will also need to configure a Forgejo webhook in the repository settings
with the target URL https://fiduswriter.pages.fiduswriter.org/fwtoolkit and branch
filter pages.
npm install
npm run build
npm testsrc/— TypeScript sourcedist/— compiled JavaScript and declaration files (generated bynpm run build)css/— component styles and a minimalcolors.cssdemo/— Forgejo Pages demo sitetest/— Jest tests
"Fidus Writer" is a registered EU trademark of Lund Info AB. This repository's license covers the code, not the name and logo — see TRADEMARK.md and the Fidus Writer trademark policy.