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

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

  // The face is a circle visual. Circles.circleAt writes the center and
  // the radius into it.
  const face = canvas.visuals.circle("face region-face");
  Circles.circleAt([280, 170], 130, face);
}
/* 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 1 of 6

The face

A graphic, a circle and a stylesheet: the starting point for the clock.

01

Creating the graphic

VisQuill.create creates an SVG inside the given div. The second argument, "clock-", is a prefix that VisQuill adds to every class name, so the clock's CSS does not affect the rest of the page.

rvg.canvas is the group that everything is drawn into.

02

The face

canvas.visuals.circle("face") creates an empty circle visual with the class clock-face. Circles.circleAt computes a circle from a center and a radius and writes it into the visual, which is passed as the last argument.

Most GDK functions work this way: the last argument receives the result. Without it, the function returns a new object.

03

Styles

Fill and stroke come from the stylesheet, not from the code. The rule for .clock-face uses the prefix from VisQuill.create.