12Object 12 · Players
Cassette
A clear cassette as a progress bar. The right pack grows as the work goes on and the hubs turn while it runs, the emptier one faster. Your finger winds the tape.
- Version
- 0.1.0
- Size
- 17.8 KB gzipped
- Access
- With a Pass
- Needs
- cassette.mjs + cassette.css
- Tests
- 13 tests · 13 states
Use it
A progress display people read at a glance and want to touch. Given a number it is the progress of an upload, a render or export, a migration, an agent's run: the hubs turning while it works and stopping when it waits. Bound to an <audio> or <video> element it is a player's position for a podcast, a voice memo or a call recording, speaking "2:14 of 5:30" and seeking when wound. It is a real slider (0–100 %, or seconds), keyboard-operable, with a read-only mode for pure readouts.
Copy the cassette folder from its package next to your page, link its stylesheet and construct it on an element. Every option has a default; the lab’s Code tab writes the same example at any settings, and for React, Vue, Svelte or a custom element (Using a framework).
<link rel="stylesheet" href="cassette/cassette.css">
<div id="cassette" style="width: min(90vw, 640px)"></div>
<script type="module">
import Cassette from './cassette/cassette.mjs';
const cassette = new Cassette(document.getElementById('cassette'), {
progress: 0.32,
playing: true,
speed: 1,
});
// cassette.update({ … }); change any option in place
// cassette.destroy(); and take it away again
</script>Options
| Option | Type | Default | What it does |
|---|---|---|---|
| progress | number, 0 to 100 | 32 | How far the work has gone: the tape on the right. Turn a hub in the preview to wind it. |
| playing | boolean | true | The hubs turn: work in progress, or playing. |
| speed | number, 0.5 to 16 | 1 | How fast the hubs turn while it runs. 1 is real tape speed, 4.76 cm/s. |
| shell | smoke · clear · black · white | 'smoke' | Smoke and clear show everything inside; black and white only through the window. Clear prints in black, for light pages. |
| hubs | white · brass · black | 'white' | The screws follow the hubs. |
| tape | ferric · chrome | 'ferric' | Brown ferric oxide, or near-black chrome. |
| length | c46 · c60 · c90 | 'c60' | How big a full pack is: its tape’s length times its thickness. |
| paper | boolean | false | A paper label round the window, or print straight on the shell. |
| title | text | 'Nightly build' | What is on the tape: the job, the file, the run. |
| side | text | 'A' | One letter in the box, or empty. |
| note | text | 'Run 412' | A second, smaller line. |
| scale | boolean | true | Printed under the window, where the right pack’s edge crosses at 0, 25, 50, 75 and 100 %. |
| light | number, 0 to 345 | 315 | 0 is from above, clockwise. The tape’s sheen points at it and stays there while the packs turn. |
| size | number, 0 to 1200 | 0 | 0 fits its frame; any other value is its width, shrunk only to fit. |
| readonly | boolean | false | A readout: values from code only, not the hand. |
| label | text | 'Progress' | Accessible name |
Methods
new Cassette(element, options)- Builds it inside the element with these options.
value- Progress, 0…1.
playingupdate(opts = {})- Change options in place.
setProgress(p, { instant = false } = {})- Set the progress (0…1).
play()pause()destroy()- Stops it and cleans up after it.
Events it fires, which bubble from the element: input, change.
States
- At restThe packs show the progress; the scale under the window reads the right pack's edge; the loop is asleep.
- RunningThe hubs turn at tape speed (4.76 cm/s × speed): the near-empty hub fast, the full one slowly.
- New valuesetProgress() or a media seek: the packs roll to the value and the hubs spin up as in fast-forward, then stop.
- Turning a hubPress on a pack and turn: the hub follows the finger exactly and the other follows the tape; input fires on every change, change when it lifts.
- Dragging acrossPress anywhere off the packs and drag sideways: one cassette width winds the whole tape.
- KeyboardArrows step 1 % (5 s with media), Page keys ten times that, Home and End go to the ends; Space plays and pauses bound media.
- MediaBound to an audio or video element it follows timeupdate, play, pause, seeked and ratechange, and scrubbing sets currentTime.
- Read-onlyValues from code only; the hand does nothing and aria-readonly says so.
- Smoke and clearEverything inside shows through: the packs, the tape path round the corner rollers, the pressure pad; the hub bores and the holes show the page.
- Black and whiteAn opaque shell, clear only in a wide window across both hubs.
- Paper labelA paper label with a stadium cut-out round the window, the title and note printed on it.
- Off screen or hiddenThe loop pauses; off screen the packs land on the value; a returning tab advances one clamped frame.
- Reduced motionThe packs jump to the value and the hubs stand still; no frame is requested.
How it works
Made of: Conserved tape area, Tape driven hubs, Solved tape path, Hub locked scrub, Anisotropic bow tie sheen, Room fixed sheen, Embossed clear moulding, True printed scale, Media binding, Sleeping loop, Fit to host.
Original. Canvas 2D, drawn in millimetres. The far half, the near half, a hub, the hub's fixed sheen and a full pack are baked once per size and style; a frame is the far half, two pack shadows, the solved tape path, two packs clipped to their annuli, two turned hubs with unturned sheen, and the near half. The Walkman (spring door, latching keys) is the next piece built on it.