import { VisQuill, Circles, Pins, Points } from "@visquill/visquill-gdk";
import "./styles.css";

// Part 3: the numbers.
export function run(div: HTMLDivElement) {
  const rvg = VisQuill.create(div, "clock-");
  const canvas = rvg.canvas;

  const face = canvas.visuals.circle("face");
  Circles.circleAt([280, 170], 130, face);

  // A pin at the center that points to 12, and turned copies of it.
  const twelve = Pins.withOrientation([280, 170], [0, -1]);
  const at = (fraction: number) => Pins.rotateBy(twelve, fraction * 2 * Math.PI);

  for (let i = 0; i < 60; i++) {
    const long = i % 5 === 0;
    const pin = at(i / 60);
    canvas.visuals.segment(long ? "tick long" : "tick", Pins.moveForward(pin, long ? 116 : 123), Pins.moveForward(pin, 130));
  }

  // Each number is a label, placed 100 pixels from the center in the
  // direction of its hour.
  for (let h = 1; h <= 12; h++) {
    const label = canvas.text.label(String(h), "number region-numbers");
    Points.copy(Pins.moveForward(at(h / 12), 100), label);
  }
}
/* Each class is the prefix "clock-" plus the name used in demo.ts. */

.clock-face {
  fill: #faf6ef;
  stroke: #1c1a17;
  stroke-width: 3px;
}

/* All ticks are thin; the class "long" makes every fifth one thicker. */
.clock-tick { stroke: #1c1a17; stroke-width: 1px; }
.clock-long { stroke-width: 3px; }

.clock-number {
  fill: #1c1a17;
  font: 500 16px Inter, system-ui, sans-serif;
  text-anchor: middle;
  dominant-baseline: middle;
  user-select: none;
}

.clock-hand { stroke: #1c1a17; stroke-linecap: round; }
.clock-hour { stroke-width: 6px; }
.clock-minute { stroke-width: 4px; }
.clock-second { stroke: #c0503f; stroke-width: 2px; }
.clock-cap { r: 5px; fill: #1c1a17; }

/* Part 6: the timer. The arc is a thick, light line just inside the rim. */
.clock-timer-arc {
  fill: none;
  stroke: #e9c48f;
  stroke-width: 14px;
}

.clock-knob {
  r: 10px;
  fill: #d8913a;
  stroke: #faf6ef;
  stroke-width: 2px;
  cursor: grab;
}
.clock-knob:active { cursor: grabbing; }

.clock-readout {
  fill: #1c1a17;
  font: 500 14px "JetBrains Mono", ui-monospace, monospace;
  text-anchor: middle;
  dominant-baseline: middle;
  user-select: none;
}

Build a clock · Part 3 of 6

Numbers

Twelve labels, placed with the same turned pins as the ticks.

01

Placing the labels

canvas.text.label creates a text label. Its position is the pin for its hour, moved 100 pixels forward. Points.copy writes only the position into the label, so the text stays upright.

02

Centering the text

text-anchor and dominant-baseline center each number on its point. user-select: none keeps the numbers from being selected as text, which matters once there is something to drag.