@johnmorrisdotca/kyogijo-stadiums 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -0
- package/LICENSE +21 -0
- package/NOTICE.md +293 -0
- package/README.md +600 -2
- package/dist/annotate.d.ts +47 -0
- package/dist/annotate.js +349 -0
- package/dist/atlas-entry.d.ts +4 -0
- package/dist/atlas-entry.js +3 -0
- package/dist/atlas.d.ts +131 -0
- package/dist/atlas.js +149 -0
- package/dist/background.d.ts +56 -0
- package/dist/background.js +127 -0
- package/dist/ballpark.d.ts +48 -0
- package/dist/ballpark.js +129 -0
- package/dist/canvas-entry.d.ts +2 -0
- package/dist/canvas-entry.js +2 -0
- package/dist/canvas.d.ts +85 -0
- package/dist/canvas.js +279 -0
- package/dist/charts-entry.d.ts +10 -0
- package/dist/charts-entry.js +8 -0
- package/dist/charts.baseball.d.ts +30 -0
- package/dist/charts.baseball.js +152 -0
- package/dist/charts.curling.d.ts +52 -0
- package/dist/charts.curling.js +196 -0
- package/dist/charts.d.ts +172 -0
- package/dist/charts.js +508 -0
- package/dist/charts.network.d.ts +66 -0
- package/dist/charts.network.js +64 -0
- package/dist/charts.soccer.d.ts +43 -0
- package/dist/charts.soccer.js +191 -0
- package/dist/charts.types.d.ts +396 -0
- package/dist/charts.types.js +1 -0
- package/dist/colour.d.ts +29 -0
- package/dist/colour.js +97 -0
- package/dist/common.d.ts +14 -0
- package/dist/common.js +32 -0
- package/dist/court.d.ts +89 -0
- package/dist/court.js +248 -0
- package/dist/courts.style.d.ts +20 -0
- package/dist/courts.style.js +54 -0
- package/dist/cricket.board.d.ts +18 -0
- package/dist/cricket.board.js +67 -0
- package/dist/curling.board.d.ts +24 -0
- package/dist/curling.board.js +147 -0
- package/dist/d3-entry.d.ts +3 -0
- package/dist/d3-entry.js +2 -0
- package/dist/d3.d.ts +45 -0
- package/dist/d3.js +56 -0
- package/dist/draw.d.ts +52 -0
- package/dist/draw.js +705 -0
- package/dist/element-define.d.ts +2 -0
- package/dist/element-define.js +4 -0
- package/dist/element-entry.d.ts +1 -0
- package/dist/element-entry.js +2 -0
- package/dist/element.d.ts +39 -0
- package/dist/element.js +321 -0
- package/dist/eras-entry.d.ts +2 -0
- package/dist/eras-entry.js +2 -0
- package/dist/eras.d.ts +204 -0
- package/dist/eras.js +396 -0
- package/dist/events-entry.d.ts +3 -0
- package/dist/events-entry.js +3 -0
- package/dist/events.d.ts +54 -0
- package/dist/events.data.d.ts +59 -0
- package/dist/events.data.js +297 -0
- package/dist/events.js +127 -0
- package/dist/features.d.ts +31 -0
- package/dist/features.js +284 -0
- package/dist/field.score.d.ts +5 -0
- package/dist/field.score.js +33 -0
- package/dist/fields/afl.d.ts +11 -0
- package/dist/fields/afl.js +103 -0
- package/dist/fields/cricket.d.ts +9 -0
- package/dist/fields/cricket.js +81 -0
- package/dist/fields/fieldhockey.d.ts +6 -0
- package/dist/fields/fieldhockey.js +81 -0
- package/dist/fields/gaelic.d.ts +10 -0
- package/dist/fields/gaelic.js +86 -0
- package/dist/fields/handball.d.ts +6 -0
- package/dist/fields/handball.js +85 -0
- package/dist/fields/lacrosse.d.ts +17 -0
- package/dist/fields/lacrosse.js +169 -0
- package/dist/fields/rugby.d.ts +10 -0
- package/dist/fields/rugby.js +130 -0
- package/dist/fields.d.ts +12 -0
- package/dist/fields.js +44 -0
- package/dist/fields.kit.d.ts +63 -0
- package/dist/fields.kit.js +108 -0
- package/dist/fields.style.d.ts +4 -0
- package/dist/fields.style.js +19 -0
- package/dist/fields.types.d.ts +155 -0
- package/dist/fields.types.js +1 -0
- package/dist/format.d.ts +10 -0
- package/dist/format.js +28 -0
- package/dist/formations.d.ts +18 -0
- package/dist/formations.js +211 -0
- package/dist/frames-entry.d.ts +8 -0
- package/dist/frames-entry.js +7 -0
- package/dist/frames.d.ts +199 -0
- package/dist/frames.js +271 -0
- package/dist/frames.providers.d.ts +16 -0
- package/dist/frames.providers.js +302 -0
- package/dist/geojson-entry.d.ts +2 -0
- package/dist/geojson-entry.js +2 -0
- package/dist/geojson.d.ts +79 -0
- package/dist/geojson.js +147 -0
- package/dist/geometry-entry.d.ts +7 -0
- package/dist/geometry-entry.js +5 -0
- package/dist/geometry.d.ts +295 -0
- package/dist/geometry.js +361 -0
- package/dist/grounds-entry.d.ts +4 -0
- package/dist/grounds-entry.js +3 -0
- package/dist/grounds.d.ts +134 -0
- package/dist/grounds.data.d.ts +2 -0
- package/dist/grounds.data.js +1849 -0
- package/dist/grounds.js +74 -0
- package/dist/heat.colour.d.ts +37 -0
- package/dist/heat.colour.js +54 -0
- package/dist/heat.d.ts +43 -0
- package/dist/heat.js +614 -0
- package/dist/heat.stats.d.ts +123 -0
- package/dist/heat.stats.js +413 -0
- package/dist/heat.types.d.ts +145 -0
- package/dist/heat.types.js +1 -0
- package/dist/heat.zones.d.ts +54 -0
- package/dist/heat.zones.js +424 -0
- package/dist/homeside.d.ts +16 -0
- package/dist/homeside.js +43 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +29 -0
- package/dist/layers-entry.d.ts +19 -0
- package/dist/layers-entry.js +11 -0
- package/dist/layers.d.ts +41 -0
- package/dist/layers.env.d.ts +72 -0
- package/dist/layers.env.js +79 -0
- package/dist/layers.js +533 -0
- package/dist/layers.marks.d.ts +45 -0
- package/dist/layers.marks.js +168 -0
- package/dist/layers.types.d.ts +226 -0
- package/dist/layers.types.js +1 -0
- package/dist/layout.d.ts +97 -0
- package/dist/layout.js +381 -0
- package/dist/layout.style.d.ts +6 -0
- package/dist/layout.style.js +17 -0
- package/dist/layouts-entry.d.ts +5 -0
- package/dist/layouts-entry.js +4 -0
- package/dist/leagues/aussie.d.ts +57 -0
- package/dist/leagues/aussie.js +36 -0
- package/dist/leagues/baseball.d.ts +58 -0
- package/dist/leagues/baseball.js +171 -0
- package/dist/leagues/basketball.d.ts +67 -0
- package/dist/leagues/basketball.js +128 -0
- package/dist/leagues/courts.d.ts +212 -0
- package/dist/leagues/courts.js +114 -0
- package/dist/leagues/cricket.d.ts +45 -0
- package/dist/leagues/cricket.js +34 -0
- package/dist/leagues/curling.d.ts +64 -0
- package/dist/leagues/curling.js +53 -0
- package/dist/leagues/fieldhockey.d.ts +48 -0
- package/dist/leagues/fieldhockey.js +29 -0
- package/dist/leagues/fields.d.ts +10 -0
- package/dist/leagues/fields.js +6 -0
- package/dist/leagues/football.d.ts +8 -0
- package/dist/leagues/football.js +82 -0
- package/dist/leagues/gaelic.d.ts +50 -0
- package/dist/leagues/gaelic.js +29 -0
- package/dist/leagues/handball.d.ts +45 -0
- package/dist/leagues/handball.js +32 -0
- package/dist/leagues/hockey.d.ts +63 -0
- package/dist/leagues/hockey.js +166 -0
- package/dist/leagues/lacrosse.d.ts +103 -0
- package/dist/leagues/lacrosse.js +175 -0
- package/dist/leagues/rugby.d.ts +59 -0
- package/dist/leagues/rugby.js +72 -0
- package/dist/leagues/sources.d.ts +18 -0
- package/dist/leagues/sources.js +95 -0
- package/dist/leagues/types.d.ts +43 -0
- package/dist/leagues/types.js +5 -0
- package/dist/leagues-entry.d.ts +23 -0
- package/dist/leagues-entry.js +15 -0
- package/dist/leagues.d.ts +172 -0
- package/dist/leagues.js +462 -0
- package/dist/look.d.ts +50 -0
- package/dist/look.js +186 -0
- package/dist/mark.d.ts +35 -0
- package/dist/mark.js +59 -0
- package/dist/mount-entry.d.ts +2 -0
- package/dist/mount-entry.js +2 -0
- package/dist/mount.d.ts +63 -0
- package/dist/mount.js +167 -0
- package/dist/mow.d.ts +36 -0
- package/dist/mow.js +111 -0
- package/dist/names.d.ts +77 -0
- package/dist/names.js +97 -0
- package/dist/outline.d.ts +25 -0
- package/dist/outline.js +112 -0
- package/dist/parks-entry.d.ts +4 -0
- package/dist/parks-entry.js +3 -0
- package/dist/parks.d.ts +200 -0
- package/dist/parks.data.d.ts +2 -0
- package/dist/parks.data.js +4489 -0
- package/dist/parks.js +92 -0
- package/dist/plot-entry.d.ts +2 -0
- package/dist/plot-entry.js +2 -0
- package/dist/plot.d.ts +74 -0
- package/dist/plot.js +68 -0
- package/dist/png-entry.d.ts +2 -0
- package/dist/png-entry.js +2 -0
- package/dist/png.d.ts +26 -0
- package/dist/png.js +46 -0
- package/dist/ranges.d.ts +33 -0
- package/dist/ranges.js +178 -0
- package/dist/ranges.names.d.ts +31 -0
- package/dist/ranges.names.js +65 -0
- package/dist/react-entry.d.ts +2 -0
- package/dist/react-entry.js +2 -0
- package/dist/react.d.ts +53 -0
- package/dist/react.js +58 -0
- package/dist/replay-entry.d.ts +5 -0
- package/dist/replay-entry.js +4 -0
- package/dist/replay.control.d.ts +47 -0
- package/dist/replay.control.js +184 -0
- package/dist/replay.d.ts +170 -0
- package/dist/replay.dom.d.ts +21 -0
- package/dist/replay.dom.js +388 -0
- package/dist/replay.js +579 -0
- package/dist/replay.types.d.ts +152 -0
- package/dist/replay.types.js +1 -0
- package/dist/restyle.d.ts +21 -0
- package/dist/restyle.js +70 -0
- package/dist/road.d.ts +26 -0
- package/dist/road.draw.d.ts +6 -0
- package/dist/road.draw.js +269 -0
- package/dist/road.js +59 -0
- package/dist/road.model.d.ts +63 -0
- package/dist/road.model.js +215 -0
- package/dist/road.style.d.ts +7 -0
- package/dist/road.style.js +26 -0
- package/dist/road.types.d.ts +122 -0
- package/dist/road.types.js +1 -0
- package/dist/scene-entry.d.ts +7 -0
- package/dist/scene-entry.js +5 -0
- package/dist/scene.css.d.ts +44 -0
- package/dist/scene.css.js +296 -0
- package/dist/scene.d.ts +27 -0
- package/dist/scene.fit.d.ts +12 -0
- package/dist/scene.fit.js +18 -0
- package/dist/scene.flat.d.ts +38 -0
- package/dist/scene.flat.js +167 -0
- package/dist/scene.js +420 -0
- package/dist/scene.path.d.ts +40 -0
- package/dist/scene.path.js +357 -0
- package/dist/scene.types.d.ts +172 -0
- package/dist/scene.types.js +1 -0
- package/dist/scene.xml.d.ts +31 -0
- package/dist/scene.xml.js +81 -0
- package/dist/score.d.ts +70 -0
- package/dist/score.js +212 -0
- package/dist/sets.board.d.ts +22 -0
- package/dist/sets.board.js +89 -0
- package/dist/sheet.d.ts +18 -0
- package/dist/sheet.js +38 -0
- package/dist/special.d.ts +44 -0
- package/dist/special.js +204 -0
- package/dist/special.style.d.ts +8 -0
- package/dist/special.style.js +36 -0
- package/dist/strings.d.ts +581 -0
- package/dist/strings.js +411 -0
- package/dist/style.d.ts +35 -0
- package/dist/style.js +177 -0
- package/dist/surfaces/baseball.d.ts +33 -0
- package/dist/surfaces/baseball.js +208 -0
- package/dist/surfaces/baseball.walls.d.ts +16 -0
- package/dist/surfaces/baseball.walls.js +150 -0
- package/dist/surfaces/basketball.d.ts +8 -0
- package/dist/surfaces/basketball.js +199 -0
- package/dist/surfaces/curling.d.ts +23 -0
- package/dist/surfaces/curling.js +128 -0
- package/dist/surfaces/field.d.ts +12 -0
- package/dist/surfaces/field.js +163 -0
- package/dist/surfaces/football.d.ts +12 -0
- package/dist/surfaces/football.js +208 -0
- package/dist/surfaces/hockey.d.ts +10 -0
- package/dist/surfaces/hockey.js +166 -0
- package/dist/surfaces/net.d.ts +7 -0
- package/dist/surfaces/net.js +151 -0
- package/dist/surfaces/soccer-providers.d.ts +124 -0
- package/dist/surfaces/soccer-providers.js +334 -0
- package/dist/surfaces/soccer-spec.d.ts +138 -0
- package/dist/surfaces/soccer-spec.js +175 -0
- package/dist/surfaces/soccer.d.ts +25 -0
- package/dist/surfaces/soccer.js +270 -0
- package/dist/surfaces/surface.d.ts +180 -0
- package/dist/surfaces/surface.js +49 -0
- package/dist/team.common.d.ts +75 -0
- package/dist/team.common.js +97 -0
- package/dist/team.formation.d.ts +24 -0
- package/dist/team.formation.js +121 -0
- package/dist/team.geometry.d.ts +66 -0
- package/dist/team.geometry.js +304 -0
- package/dist/team.layers.d.ts +16 -0
- package/dist/team.layers.js +32 -0
- package/dist/team.motion.d.ts +9 -0
- package/dist/team.motion.js +325 -0
- package/dist/team.network.d.ts +43 -0
- package/dist/team.network.js +215 -0
- package/dist/team.shape.d.ts +12 -0
- package/dist/team.shape.js +217 -0
- package/dist/team.types.d.ts +189 -0
- package/dist/team.types.js +1 -0
- package/dist/text.d.ts +31 -0
- package/dist/text.js +88 -0
- package/dist/themes.d.ts +14 -0
- package/dist/themes.js +24 -0
- package/dist/types.d.ts +565 -0
- package/dist/types.js +1 -0
- package/dist/units.d.ts +45 -0
- package/dist/units.js +90 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +234 -4
package/dist/score.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Side, Sport } from "./types.ts";
|
|
2
|
+
import type { PlateSpot, Zone } from "./surfaces/surface.ts";
|
|
3
|
+
/** A team as it is drawn: everything decided, nothing left to look up. */
|
|
4
|
+
export interface TeamView {
|
|
5
|
+
side: Side;
|
|
6
|
+
/** The name, in capitals if asked. */
|
|
7
|
+
name: string;
|
|
8
|
+
abbr: string;
|
|
9
|
+
score: string;
|
|
10
|
+
/** The logo as an image address, or `undefined`. */
|
|
11
|
+
logo: string | undefined;
|
|
12
|
+
/** The team's mark is round: its logo in a circle with a ring, or, with no logo, its initials on its colour (`color`). */
|
|
13
|
+
round?: boolean;
|
|
14
|
+
fit?: "cover" | "contain";
|
|
15
|
+
color?: string;
|
|
16
|
+
ink?: string;
|
|
17
|
+
state: "win" | "lose" | "none";
|
|
18
|
+
/** The role in the game, for part names. */
|
|
19
|
+
role: "home" | "away";
|
|
20
|
+
/** Curling: the score of each end, written; and whether the team has the hammer. */
|
|
21
|
+
ends?: string[];
|
|
22
|
+
hammer?: boolean;
|
|
23
|
+
/** The net sports: the score in each set, the tie-break points of each set, the points of the game in progress, and whether the team is serving. */
|
|
24
|
+
sets?: string[];
|
|
25
|
+
tiebreaks?: string[];
|
|
26
|
+
points?: string;
|
|
27
|
+
serving?: boolean;
|
|
28
|
+
/** Cricket: the wickets lost, the overs faced and the score of each innings, written. */
|
|
29
|
+
wickets?: string;
|
|
30
|
+
overs?: string;
|
|
31
|
+
innings?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A team's name and logo in its place. The place is a box in the surface's own frame; the words are set as the eye
|
|
35
|
+
* sees them, turned by `rot` (or a quarter back when the whole surface is turned).
|
|
36
|
+
*/
|
|
37
|
+
export declare function bannerMarkup(zone: Zone, team: TeamView, o: {
|
|
38
|
+
turned: boolean;
|
|
39
|
+
onColour: boolean;
|
|
40
|
+
parts: boolean;
|
|
41
|
+
id?: string;
|
|
42
|
+
}): string;
|
|
43
|
+
/** The words under or over the score. */
|
|
44
|
+
export interface PlateWords {
|
|
45
|
+
competition?: string;
|
|
46
|
+
/** The foot of the plate: the status and the date, or the label that replaces them. */
|
|
47
|
+
foot?: string;
|
|
48
|
+
}
|
|
49
|
+
/** The score, large, on a panel in the middle of the surface. */
|
|
50
|
+
export declare function plateMarkup(spot: PlateSpot, left: TeamView, right: TeamView, words: PlateWords, o: {
|
|
51
|
+
turned: boolean;
|
|
52
|
+
parts: boolean;
|
|
53
|
+
surfaceSport: Sport;
|
|
54
|
+
}): string;
|
|
55
|
+
/** A small picture of each sport's surface, for the badge: strokes in a box 36 wide and 20 tall, centred on the origin. */
|
|
56
|
+
export declare function glyph(sport: Sport): string;
|
|
57
|
+
/** The state each of two scores puts its team in. */
|
|
58
|
+
export declare function stateOf(winner: "home" | "away" | "none", role: "home" | "away"): "win" | "lose" | "none";
|
|
59
|
+
/** The badge: one strip, [logo abbreviation score] [picture and status] [score abbreviation logo]. */
|
|
60
|
+
export declare function badgeMarkup(left: TeamView, right: TeamView, o: {
|
|
61
|
+
sport: Sport;
|
|
62
|
+
status: string | undefined;
|
|
63
|
+
turned?: boolean;
|
|
64
|
+
parts: boolean;
|
|
65
|
+
id?: string;
|
|
66
|
+
}): {
|
|
67
|
+
w: number;
|
|
68
|
+
h: number;
|
|
69
|
+
markup: string;
|
|
70
|
+
};
|
package/dist/score.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { el, num } from "./format.js";
|
|
2
|
+
import { roundMarkup } from "./mark.js";
|
|
3
|
+
import { LINE_HEIGHT, fitLines, textWidth } from "./text.js";
|
|
4
|
+
const part = (on, names) => (on ? names : undefined);
|
|
5
|
+
/**
|
|
6
|
+
* A team's name and logo in its place. The place is a box in the surface's own frame; the words are set as the eye
|
|
7
|
+
* sees them, turned by `rot` (or a quarter back when the whole surface is turned).
|
|
8
|
+
*/
|
|
9
|
+
export function bannerMarkup(zone, team, o) {
|
|
10
|
+
const rot = o.turned ? -90 : zone.rot;
|
|
11
|
+
const { w, h } = zone;
|
|
12
|
+
let inner = "";
|
|
13
|
+
if (zone.panel)
|
|
14
|
+
inner += el("rect", { class: `ky-panel ky-panel-${team.side}`, x: -w / 2, y: -h / 2, width: w, height: h, rx: Math.min(h * 0.16, 8) });
|
|
15
|
+
const ink = `ky-${o.onColour || zone.panel ? "ink" : "paint"}-${team.side}`;
|
|
16
|
+
const logo = team.logo;
|
|
17
|
+
// A round mark is a picture even where the team has no logo (its initials on its colour), and stays upright in a zone that is turned.
|
|
18
|
+
const mark = (size, x, y) => team.round === true
|
|
19
|
+
? roundMarkup({ id: `${o.id ?? "ky"}-mk-${team.role}`, cx: x + size / 2, cy: y + size / 2, r: size / 2, href: logo, fit: team.fit, initials: team.abbr, color: team.color, ink: team.ink, upright: rot })
|
|
20
|
+
: el("image", { class: "ky-logo", href: logo, x, y, width: size, height: size, preserveAspectRatio: "xMidYMid meet" });
|
|
21
|
+
const pictured = logo !== undefined || team.round === true;
|
|
22
|
+
const row = pictured && w / h >= 2.6;
|
|
23
|
+
const stack = pictured && !row;
|
|
24
|
+
if (row) {
|
|
25
|
+
const size = Math.min(h * 0.9, w * 0.3);
|
|
26
|
+
const gap = size * 0.22;
|
|
27
|
+
const fit = fitLines(team.name, w - size - gap - h * 0.1, h * 0.92, h * 0.5);
|
|
28
|
+
const total = size + gap + fit.width;
|
|
29
|
+
const x0 = -total / 2;
|
|
30
|
+
inner += mark(size, x0, -size / 2);
|
|
31
|
+
inner += lines(fit.lines, fit.size, x0 + size + gap, 0, "start", ink);
|
|
32
|
+
}
|
|
33
|
+
else if (stack) {
|
|
34
|
+
const size = Math.min(h * 0.56, w * 0.8);
|
|
35
|
+
const gap = h * 0.05;
|
|
36
|
+
const fit = fitLines(team.name, w * 0.96, h - size - gap - h * 0.06, h * 0.22);
|
|
37
|
+
const total = size + gap + fit.height;
|
|
38
|
+
const top = -total / 2;
|
|
39
|
+
inner += mark(size, -size / 2, top);
|
|
40
|
+
inner += lines(fit.lines, fit.size, 0, top + size + gap + fit.height / 2, "middle", ink);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const fit = fitLines(team.name, w * 0.96, h * 0.92, h * 0.5);
|
|
44
|
+
inner += lines(fit.lines, fit.size, 0, 0, "middle", ink);
|
|
45
|
+
}
|
|
46
|
+
return el("g", {
|
|
47
|
+
class: `ky-banner ky-banner-${team.side} ky-${team.state}`,
|
|
48
|
+
transform: `translate(${num(zone.cx)} ${num(zone.cy)})${rot === 0 ? "" : ` rotate(${num(rot)})`}`,
|
|
49
|
+
part: part(o.parts, `team ${team.role}`),
|
|
50
|
+
"data-team": team.role,
|
|
51
|
+
}, inner);
|
|
52
|
+
}
|
|
53
|
+
/** Lines of a name centred on a vertical position. */
|
|
54
|
+
function lines(rows, size, x, cy, anchor, ink) {
|
|
55
|
+
const step = size * LINE_HEIGHT;
|
|
56
|
+
return rows
|
|
57
|
+
.map((row, i) => {
|
|
58
|
+
const y = cy + (i - (rows.length - 1) / 2) * step + size * 0.36;
|
|
59
|
+
return el("text", { class: `ky-text ky-name ${ink}`, x, y, "font-size": size, "text-anchor": anchor }, esc(row));
|
|
60
|
+
})
|
|
61
|
+
.join("");
|
|
62
|
+
}
|
|
63
|
+
function esc(text) {
|
|
64
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
65
|
+
}
|
|
66
|
+
/** The score, large, on a panel in the middle of the surface. */
|
|
67
|
+
export function plateMarkup(spot, left, right, words, o) {
|
|
68
|
+
const { w, h } = spot;
|
|
69
|
+
const rows = [];
|
|
70
|
+
if (words.competition)
|
|
71
|
+
rows.push({ kind: "comp", height: 0.15 });
|
|
72
|
+
rows.push({ kind: "main", height: 0.58 });
|
|
73
|
+
if (words.foot)
|
|
74
|
+
rows.push({ kind: "foot", height: 0.15 });
|
|
75
|
+
const gap = 0.03;
|
|
76
|
+
const total = rows.reduce((sum, row) => sum + row.height, 0) + gap * (rows.length - 1);
|
|
77
|
+
let y = (-total / 2) * h;
|
|
78
|
+
let inner = el("rect", { class: "ky-plate-bg", x: -w / 2, y: -h / 2, width: w, height: h, rx: h * 0.14 });
|
|
79
|
+
for (const row of rows) {
|
|
80
|
+
const rowH = row.height * h;
|
|
81
|
+
if (row.kind === "main")
|
|
82
|
+
inner += mainRow(y, rowH, w, h, left, right, o.parts);
|
|
83
|
+
else {
|
|
84
|
+
const text = (row.kind === "comp" ? words.competition : words.foot) ?? "";
|
|
85
|
+
const size = Math.min(rowH * 0.66, (w * 0.92) / Math.max(0.1, textWidth(text, false)));
|
|
86
|
+
inner += el("text", { class: `ky-text ky-${row.kind}`, x: 0, y: y + rowH / 2 + size * 0.36, "font-size": size }, esc(text));
|
|
87
|
+
}
|
|
88
|
+
y += rowH + gap * h;
|
|
89
|
+
}
|
|
90
|
+
return el("g", { class: "ky-plate", transform: `translate(${num(spot.cx)} ${num(spot.cy)})${o.turned ? " rotate(-90)" : ""}`, part: part(o.parts, "plate") }, inner);
|
|
91
|
+
}
|
|
92
|
+
function mainRow(top, rowH, w, h, left, right, parts) {
|
|
93
|
+
const abbrSize = rowH * 0.26;
|
|
94
|
+
const dash = h * 0.13;
|
|
95
|
+
const widest = Math.max(textWidth(left.score), textWidth(right.score), 1);
|
|
96
|
+
const scoreSize = Math.min(rowH * 0.7, (w / 2 - dash - w * 0.05) / widest);
|
|
97
|
+
const base = top + rowH * 0.3 + (rowH * 0.7) / 2 + scoreSize * 0.36;
|
|
98
|
+
const abbrY = top + abbrSize * 0.9;
|
|
99
|
+
let out = "";
|
|
100
|
+
for (const team of [left, right]) {
|
|
101
|
+
const sign = team.side === "left" ? -1 : 1;
|
|
102
|
+
const sw = textWidth(team.score) * scoreSize;
|
|
103
|
+
const centre = sign * (dash + sw / 2);
|
|
104
|
+
out += el("text", { class: `ky-text ky-abbr ky-abbr-${team.side}`, x: centre, y: abbrY, "font-size": abbrSize * 0.78 }, esc(team.abbr));
|
|
105
|
+
out += el("text", { class: `ky-text ky-score ky-${team.state}`, x: sign * dash, y: base, "font-size": scoreSize, "text-anchor": sign < 0 ? "end" : "start", part: part(parts, `score ${team.role}-score`) }, esc(team.score));
|
|
106
|
+
if (team.state === "win")
|
|
107
|
+
out += el("rect", { class: `ky-winbar ky-winbar-${team.side}`, x: sign < 0 ? -dash - sw : dash, y: base + scoreSize * 0.1, width: sw, height: Math.max(0.5, scoreSize * 0.07) });
|
|
108
|
+
}
|
|
109
|
+
out += el("text", { class: "ky-text ky-dash-text", x: 0, y: base, "font-size": scoreSize * 0.8 }, "–");
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/** A small picture of each sport's surface, for the badge: strokes in a box 36 wide and 20 tall, centred on the origin. */
|
|
113
|
+
export function glyph(sport) {
|
|
114
|
+
switch (sport) {
|
|
115
|
+
case "nfl":
|
|
116
|
+
case "cfl":
|
|
117
|
+
case "ifaf":
|
|
118
|
+
return "M-18 -10H18V10H-18ZM-12 -10V10M12 -10V10M0 -10V10M-6 -10V10M6 -10V10";
|
|
119
|
+
case "nhl":
|
|
120
|
+
return "M-14 -10H14A4 4 0 0 1 18 -6V6A4 4 0 0 1 14 10H-14A4 4 0 0 1 -18 6V-6A4 4 0 0 1 -14 -10ZM0 -10V10M-5 0A5 5 0 1 0 5 0A5 5 0 1 0 -5 0M-9 -10V10M9 -10V10";
|
|
121
|
+
case "nba":
|
|
122
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-5 0A5 5 0 1 0 5 0A5 5 0 1 0 -5 0M-18 -4H-10V4H-18M18 -4H10V4H18";
|
|
123
|
+
case "mlb":
|
|
124
|
+
return "M0 9L9 0L0 -9L-9 0ZM-18 10L0 9L18 10M0 -9A12 12 0 0 1 12 0";
|
|
125
|
+
case "soccer":
|
|
126
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-5 0A5 5 0 1 0 5 0A5 5 0 1 0 -5 0M-18 -5H-12V5H-18M18 -5H12V5H18";
|
|
127
|
+
case "curling":
|
|
128
|
+
// A house: the 12-, 8- and 4-foot circles round the button, with the centre line through it.
|
|
129
|
+
return "M-10 0A10 10 0 1 0 10 0A10 10 0 1 0 -10 0M-6.7 0A6.7 6.7 0 1 0 6.7 0A6.7 6.7 0 1 0 -6.7 0M-3.3 0A3.3 3.3 0 1 0 3.3 0A3.3 3.3 0 1 0 -3.3 0M-18 0H18";
|
|
130
|
+
case "tennis":
|
|
131
|
+
// A court: the net, the singles sidelines, the service lines and the centre service line.
|
|
132
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-18 -7.5H18M-18 7.5H18M-9.7 -7.5V7.5M9.7 -7.5V7.5M-9.7 0H9.7";
|
|
133
|
+
case "volleyball":
|
|
134
|
+
// A court: the centre line and the attack lines.
|
|
135
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-6 -10V10M6 -10V10";
|
|
136
|
+
case "badminton":
|
|
137
|
+
// A court: the net, the short service lines, the centre lines and the singles sidelines.
|
|
138
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-5.3 -10V10M5.3 -10V10M-18 0H-5.3M5.3 0H18M-18 -8.5H18M-18 8.5H18";
|
|
139
|
+
case "pickleball":
|
|
140
|
+
// A court: the net, the non-volley zone lines and the centrelines.
|
|
141
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-5.7 -10V10M5.7 -10V10M-18 0H-5.7M5.7 0H18";
|
|
142
|
+
case "tabletennis":
|
|
143
|
+
// A table: the net across it and the centre line.
|
|
144
|
+
return "M-16 -8H16V8H-16ZM0 -10V10M-16 0H16";
|
|
145
|
+
case "lacrosse":
|
|
146
|
+
// A field: the centre line, the goal circles and the restraining lines.
|
|
147
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-12 0A3 3 0 1 0 -6 0A3 3 0 1 0 -12 0M12 0A3 3 0 1 0 6 0A3 3 0 1 0 12 0M-7 -10V10M7 -10V10";
|
|
148
|
+
case "rugby":
|
|
149
|
+
// A field: the try lines and in-goal, the 22-metre lines and the half-way line, and the posts.
|
|
150
|
+
return "M-18 -10H18V10H-18ZM-14 -10V10M14 -10V10M-8 -10V10M8 -10V10M0 -10V10M-14 -2H-17M-14 2H-17M14 -2H17M14 2H17";
|
|
151
|
+
case "afl":
|
|
152
|
+
// An oval, with the centre square and the goal squares.
|
|
153
|
+
return "M-14 -7A18 10 0 0 1 14 -7V7A18 10 0 0 1 -14 7ZM-4 -4H4V4H-4ZM-14 -2H-9V2H-14M14 -2H9V2H14";
|
|
154
|
+
case "gaelic":
|
|
155
|
+
// A field: the lines across and the two rectangles at each end.
|
|
156
|
+
return "M-18 -10H18V10H-18ZM-18 -6H-12V6H-18M-18 -3H-15V3H-18M18 -6H12V6H18M18 -3H15V3H18M-9 -10V10M9 -10V10";
|
|
157
|
+
case "cricket":
|
|
158
|
+
// A ground: the boundary, the circle and the pitch with its creases.
|
|
159
|
+
return "M-17 0A17 10 0 1 0 17 0A17 10 0 1 0 -17 0M-9 -4H9A4 4 0 0 1 9 4H-9A4 4 0 0 1 -9 -4M-5 -1H5V1H-5M-5 -2V2M5 -2V2";
|
|
160
|
+
case "fieldhockey":
|
|
161
|
+
// A pitch: the centre line, the 23-metre lines and the circles.
|
|
162
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-7 -10V10M7 -10V10M-18 -5A5 5 0 0 1 -13 0A5 5 0 0 1 -18 5M18 -5A5 5 0 0 0 13 0A5 5 0 0 0 18 5";
|
|
163
|
+
case "handball":
|
|
164
|
+
// A court: the centre line, and the goal areas with their arcs.
|
|
165
|
+
return "M-18 -10H18V10H-18ZM0 -10V10M-18 -6A6 6 0 0 1 -12 0A6 6 0 0 1 -18 6M18 -6A6 6 0 0 0 12 0A6 6 0 0 0 18 6";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** The state each of two scores puts its team in. */
|
|
169
|
+
export function stateOf(winner, role) {
|
|
170
|
+
if (winner === "none")
|
|
171
|
+
return "none";
|
|
172
|
+
return winner === role ? "win" : "lose";
|
|
173
|
+
}
|
|
174
|
+
/** The badge: one strip, [logo abbreviation score] [picture and status] [score abbreviation logo]. */
|
|
175
|
+
export function badgeMarkup(left, right, o) {
|
|
176
|
+
const W = 440;
|
|
177
|
+
const H = 64;
|
|
178
|
+
const block = 182;
|
|
179
|
+
let out = el("rect", { class: "ky-badge-bg", x: 0, y: 0, width: W, height: H, rx: 12 });
|
|
180
|
+
out += el("path", { class: "ky-block ky-block-left", d: `M12 0H${block}V${H}H12A12 12 0 0 1 0 ${H - 12}V12A12 12 0 0 1 12 0Z` });
|
|
181
|
+
out += el("path", { class: "ky-block ky-block-right", d: `M${W - block} 0H${W - 12}A12 12 0 0 1 ${W} 12V${H - 12}A12 12 0 0 1 ${W - 12} ${H}H${W - block}Z` });
|
|
182
|
+
for (const team of [left, right]) {
|
|
183
|
+
const isLeft = team.side === "left";
|
|
184
|
+
const logoSize = 40;
|
|
185
|
+
const logoX = isLeft ? 12 : W - 12 - logoSize;
|
|
186
|
+
const textStart = isLeft ? (team.logo === undefined ? 14 : 60) : W - (team.logo === undefined ? 14 : 60);
|
|
187
|
+
const scoreEdge = isLeft ? block - 14 : W - block + 14;
|
|
188
|
+
const scoreSize = Math.min(32, (block * 0.42) / Math.max(1, textWidth(team.score)));
|
|
189
|
+
const room = Math.abs(scoreEdge - textStart) - textWidth(team.score) * scoreSize - 8;
|
|
190
|
+
const abbrSize = Math.max(8, Math.min(22, room / Math.max(1, textWidth(team.abbr))));
|
|
191
|
+
// The hammer: a small stone in the corner of the team's block.
|
|
192
|
+
if (team.hammer === true)
|
|
193
|
+
out += el("g", { class: `ky-badge-hammer ky-badge-hammer-${team.side}`, transform: `translate(${isLeft ? block - 11 : W - block + 11} 11)` }, el("circle", { class: "ky-hammer", r: 6 }) + el("circle", { class: "ky-hammer-in", r: 2.6 }));
|
|
194
|
+
// The ball of the team that is serving, in the same corner.
|
|
195
|
+
if (team.serving === true)
|
|
196
|
+
out += el("g", { transform: `translate(${isLeft ? block - 11 : W - block + 11} 11)` }, el("circle", { class: "ky-serve", r: 6 }) + el("path", { class: "ky-serve-seam", d: "M-4.7 -1.8Q0 1.8 4.7 -1.8", "stroke-width": 0.9 }));
|
|
197
|
+
out += el("g", { class: `ky-badge-team ky-badge-${team.side} ky-${team.state}`, part: part(o.parts, `team ${team.role}`) }, (team.logo === undefined
|
|
198
|
+
? ""
|
|
199
|
+
: team.round === true
|
|
200
|
+
? roundMarkup({ id: `${o.id ?? "ky"}-mk-${team.role}`, cx: logoX + logoSize / 2, cy: 12 + logoSize / 2, r: logoSize / 2, href: team.logo, fit: team.fit, ring: 2 })
|
|
201
|
+
: el("image", { class: "ky-logo", href: team.logo, x: logoX, y: 12, width: logoSize, height: logoSize, preserveAspectRatio: "xMidYMid meet" })) +
|
|
202
|
+
el("text", { class: `ky-text ky-name ky-ink-${team.side}`, x: textStart, y: H / 2 + abbrSize * 0.36, "font-size": abbrSize, "text-anchor": isLeft ? undefined : "end" }, esc(team.abbr)) +
|
|
203
|
+
el("text", { class: `ky-text ky-score ky-ink-${team.side} ky-${team.state}`, x: scoreEdge, y: H / 2 + scoreSize * 0.36, "font-size": scoreSize, "text-anchor": isLeft ? "end" : "start", part: part(o.parts, `score ${team.role}-score`) }, esc(team.score)));
|
|
204
|
+
}
|
|
205
|
+
const mid = W / 2;
|
|
206
|
+
out += el("path", { class: "ky-glyph", d: glyph(o.sport), transform: `translate(${mid} ${o.status ? 22 : 32}) scale(0.9)`, fill: "none" });
|
|
207
|
+
if (o.status) {
|
|
208
|
+
const size = Math.min(11.5, 76 / Math.max(1, textWidth(o.status, false)));
|
|
209
|
+
out += el("text", { class: "ky-text ky-badge-status", x: mid, y: 52 + size * 0.2, "font-size": size }, esc(o.status));
|
|
210
|
+
}
|
|
211
|
+
return { w: W, h: H, markup: el("g", { class: "ky-badge", part: part(o.parts, "badge") }, out) };
|
|
212
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TeamView } from "./score.ts";
|
|
2
|
+
import type { PlateSpot } from "./surfaces/surface.ts";
|
|
3
|
+
export interface SetsWords {
|
|
4
|
+
competition?: string;
|
|
5
|
+
foot?: string;
|
|
6
|
+
/** The head of the totals' column: "Sets" or "Games". */
|
|
7
|
+
head: string;
|
|
8
|
+
/** The head of the column of the game in progress. */
|
|
9
|
+
points: string;
|
|
10
|
+
}
|
|
11
|
+
/** The ball that marks the server, centred on a place. */
|
|
12
|
+
export declare function serveMark(cx: number, cy: number, r: number): string;
|
|
13
|
+
/** How many set columns a board has: the most either team gives, and at least `least`. */
|
|
14
|
+
export declare function setCount(left: readonly string[] | undefined, right: readonly string[] | undefined, least: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* The board as a group centred on the origin. `spot` is the room it has; it takes only what its rows and columns need. `least` is the number of set columns it
|
|
17
|
+
* always has (the sets a match can run to), more when a team gives more.
|
|
18
|
+
*/
|
|
19
|
+
export declare function setsBoardMarkup(spot: PlateSpot, left: TeamView, right: TeamView, words: SetsWords, o: {
|
|
20
|
+
parts: boolean;
|
|
21
|
+
least: number;
|
|
22
|
+
}): string;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The scoreboard of the net sports: each team's score in each set (tennis: its games; pickleball and table tennis: each game's points), the points of the game
|
|
2
|
+
// in progress in tennis, the sets or games won, and a ball beside the team that is serving. The board is drawn in the frame the eye sees; the caller turns it back
|
|
3
|
+
// when the court is turned. A tie-break's points are written small beside the games of the set that had one.
|
|
4
|
+
import { el, esc, num } from "./format.js";
|
|
5
|
+
import { fitLines, textWidth } from "./text.js";
|
|
6
|
+
/** The ball that marks the server, centred on a place. */
|
|
7
|
+
export function serveMark(cx, cy, r) {
|
|
8
|
+
return el("circle", { class: "ky-serve", cx, cy, r }) + el("path", { class: "ky-serve-seam", d: `M${num(cx - r * 0.78)} ${num(cy - r * 0.3)}Q${num(cx)} ${num(cy + r * 0.3)} ${num(cx + r * 0.78)} ${num(cy - r * 0.3)}`, "stroke-width": r * 0.14 });
|
|
9
|
+
}
|
|
10
|
+
const text = (x, cy, value, size, cls, extra = {}) => el("text", { class: `ky-text ${cls}`, x, y: cy + size * 0.36, "font-size": size, "text-anchor": "middle", ...extra }, esc(value));
|
|
11
|
+
const fit = (value, room, ceiling) => Math.max(0.1, Math.min(ceiling, room / Math.max(1, textWidth(value))));
|
|
12
|
+
/** How many set columns a board has: the most either team gives, and at least `least`. */
|
|
13
|
+
export function setCount(left, right, least) {
|
|
14
|
+
return Math.max(least, left?.length ?? 0, right?.length ?? 0);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The board as a group centred on the origin. `spot` is the room it has; it takes only what its rows and columns need. `least` is the number of set columns it
|
|
18
|
+
* always has (the sets a match can run to), more when a team gives more.
|
|
19
|
+
*/
|
|
20
|
+
export function setsBoardMarkup(spot, left, right, words, o) {
|
|
21
|
+
const n = setCount(left.sets, right.sets, o.least);
|
|
22
|
+
const team = [left, right];
|
|
23
|
+
const hasPoints = team.some((t) => t.points !== undefined && t.points !== "");
|
|
24
|
+
const cols = 2.9 + n + (hasPoints ? 1.3 : 0) + 1.4;
|
|
25
|
+
const extra = (words.competition ? 0.8 : 0) + (words.foot ? 0.8 : 0);
|
|
26
|
+
const rows = 3 + extra;
|
|
27
|
+
const colU = Math.min(spot.w / cols, spot.h / rows / 0.72);
|
|
28
|
+
const rowH = Math.min(spot.h / rows, colU * 0.72);
|
|
29
|
+
const w = colU * cols;
|
|
30
|
+
const h = rowH * rows;
|
|
31
|
+
const x0 = -w / 2;
|
|
32
|
+
let y = -h / 2;
|
|
33
|
+
const parts = (names) => (o.parts ? names : undefined);
|
|
34
|
+
let inner = el("rect", { class: "ky-plate-bg", x: -w / 2, y: -h / 2, width: w, height: h, rx: Math.min(rowH * 0.5, w * 0.04) });
|
|
35
|
+
const band = (value, cls) => {
|
|
36
|
+
const bandH = rowH * 0.8;
|
|
37
|
+
const size = fit(value, w * 0.92, bandH * 0.62);
|
|
38
|
+
inner += text(0, y + bandH / 2, value, size, cls);
|
|
39
|
+
y += bandH;
|
|
40
|
+
};
|
|
41
|
+
if (words.competition)
|
|
42
|
+
band(words.competition, "ky-comp");
|
|
43
|
+
const nameW = colU * 2.9;
|
|
44
|
+
const setX = (k) => x0 + nameW + colU * (k + 0.5);
|
|
45
|
+
const pointsX = x0 + nameW + colU * (n + 0.65);
|
|
46
|
+
const totalX = x0 + nameW + colU * (n + (hasPoints ? 1.3 : 0) + 0.7);
|
|
47
|
+
for (let k = 0; k < n; k += 1)
|
|
48
|
+
inner += text(setX(k), y + rowH / 2, String(k + 1), rowH * 0.46, "ky-foot");
|
|
49
|
+
if (hasPoints)
|
|
50
|
+
inner += text(pointsX, y + rowH / 2, words.points, fit(words.points, colU * 1.2, rowH * 0.42), "ky-foot");
|
|
51
|
+
inner += text(totalX, y + rowH / 2, words.head, fit(words.head, colU * 1.3, rowH * 0.42), "ky-foot");
|
|
52
|
+
y += rowH;
|
|
53
|
+
for (const [i, t] of team.entries()) {
|
|
54
|
+
const other = team[1 - i];
|
|
55
|
+
inner += el("rect", { class: `ky-panel-${t.side}`, x: x0 + 0.1 * colU, y: y + rowH * 0.06, width: nameW - 0.2 * colU, height: rowH * 0.88, rx: rowH * 0.2 });
|
|
56
|
+
const serving = t.serving === true;
|
|
57
|
+
const room = (nameW - 0.3 * colU) * (serving ? 0.74 : 0.92);
|
|
58
|
+
const name = fitLines(t.name, room, rowH * 0.8, rowH * 0.5);
|
|
59
|
+
const nameX = x0 + 0.1 * colU + (nameW - 0.2 * colU) * (serving ? 0.6 : 0.5);
|
|
60
|
+
name.lines.forEach((line, k) => {
|
|
61
|
+
inner += text(nameX, y + rowH / 2 + (k - (name.lines.length - 1) / 2) * name.size * 1.1, line, name.size, `ky-ink-${t.side}`);
|
|
62
|
+
});
|
|
63
|
+
if (serving)
|
|
64
|
+
inner += serveMark(x0 + 0.1 * colU + rowH * 0.45, y + rowH / 2, rowH * 0.17);
|
|
65
|
+
for (let k = 0; k < n; k += 1) {
|
|
66
|
+
const v = t.sets?.[k] ?? "";
|
|
67
|
+
if (v === "")
|
|
68
|
+
continue;
|
|
69
|
+
const a = Number(v);
|
|
70
|
+
const b = Number(other.sets?.[k]);
|
|
71
|
+
const behind = Number.isFinite(a) && Number.isFinite(b) && a < b;
|
|
72
|
+
const size = rowH * 0.62;
|
|
73
|
+
inner += text(setX(k), y + rowH / 2, v, size, behind ? "ky-score ky-lose" : "ky-score");
|
|
74
|
+
const tb = t.tiebreaks?.[k] ?? "";
|
|
75
|
+
if (tb !== "")
|
|
76
|
+
inner += text(setX(k) + (textWidth(v) * size) / 2 + rowH * 0.16, y + rowH * 0.3, tb, rowH * 0.3, "ky-score ky-tb", { "text-anchor": "start" });
|
|
77
|
+
}
|
|
78
|
+
if (hasPoints && t.points !== undefined && t.points !== "")
|
|
79
|
+
inner += text(pointsX, y + rowH / 2, t.points, fit(t.points, colU * 1.15, rowH * 0.62), "ky-score");
|
|
80
|
+
const totalSize = fit(t.score, colU * 1.2, rowH * 0.76);
|
|
81
|
+
inner += el("g", { class: `ky-total ky-${t.state}`, part: parts(`score ${t.role}-score`) }, text(totalX, y + rowH / 2, t.score, totalSize, "ky-score"));
|
|
82
|
+
if (t.state === "win")
|
|
83
|
+
inner += el("rect", { class: `ky-winbar ky-winbar-${t.side}`, x: totalX - (textWidth(t.score) * totalSize) / 2, y: y + rowH / 2 + totalSize * 0.5, width: textWidth(t.score) * totalSize, height: Math.max(0.05, totalSize * 0.07) });
|
|
84
|
+
y += rowH;
|
|
85
|
+
}
|
|
86
|
+
if (words.foot)
|
|
87
|
+
band(words.foot, "ky-foot");
|
|
88
|
+
return el("g", { class: "ky-plate ky-scoreboard", part: parts("plate") }, inner);
|
|
89
|
+
}
|
package/dist/sheet.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CurlingLeague, type SheetSpec } from "./leagues/curling.ts";
|
|
2
|
+
import type { SheetShow, SurfaceOptions } from "./types.ts";
|
|
3
|
+
/** A sheet to draw. */
|
|
4
|
+
export interface SheetPlan {
|
|
5
|
+
league: CurlingLeague;
|
|
6
|
+
/** The figures in feet, with the length and the width of the options. */
|
|
7
|
+
spec: SheetSpec;
|
|
8
|
+
pebble: boolean;
|
|
9
|
+
guardZone: boolean;
|
|
10
|
+
show: SheetShow;
|
|
11
|
+
end: "left" | "right";
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The sheet the options ask for. A `league` picks the rulebook (World Curling's by default); `sheet.length` and `sheet.width` are in `units`
|
|
15
|
+
* (feet by default) and must lie within what the rulebook allows, or it is an error that says the range.
|
|
16
|
+
* @throws RangeError when the length or the width is outside the league's range.
|
|
17
|
+
*/
|
|
18
|
+
export declare function sheetFor(o: Pick<SurfaceOptions, "sport" | "league" | "sheet" | "units" | "range">): SheetPlan;
|
package/dist/sheet.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// What a curling sheet is for a set of options: the league's figures with the length and the width the caller asked for, held to the
|
|
2
|
+
// range the rulebook allows, and how it is shown. Kept apart from the drawing so that the outline, the description and the charts agree.
|
|
3
|
+
import { chooseLeague, sheetOf } from "./leagues.js";
|
|
4
|
+
import { CURLING_LEAGUES } from "./leagues/curling.js";
|
|
5
|
+
import { lengthUnit } from "./common.js";
|
|
6
|
+
import { parseRange } from "./ranges.names.js";
|
|
7
|
+
import { convertLength } from "./units.js";
|
|
8
|
+
const SHOWS = ["sheet", "half", "house"];
|
|
9
|
+
const FEET = (feet) => String(Math.round(feet * 100) / 100);
|
|
10
|
+
/**
|
|
11
|
+
* The sheet the options ask for. A `league` picks the rulebook (World Curling's by default); `sheet.length` and `sheet.width` are in `units`
|
|
12
|
+
* (feet by default) and must lie within what the rulebook allows, or it is an error that says the range.
|
|
13
|
+
* @throws RangeError when the length or the width is outside the league's range.
|
|
14
|
+
*/
|
|
15
|
+
export function sheetFor(o) {
|
|
16
|
+
const picked = o.sport === "curling" ? chooseLeague(o).league : undefined;
|
|
17
|
+
const league = picked !== undefined && picked.family === "curling" ? picked : CURLING_LEAGUES[0];
|
|
18
|
+
const base = sheetOf(league);
|
|
19
|
+
const unit = lengthUnit(o);
|
|
20
|
+
const asked = o.sheet ?? {};
|
|
21
|
+
const pick = (name, least, most) => {
|
|
22
|
+
const given = asked[name];
|
|
23
|
+
if (given === undefined)
|
|
24
|
+
return most;
|
|
25
|
+
const feet = typeof given === "number" ? convertLength(given, unit, "ft") : NaN;
|
|
26
|
+
if (!(feet >= least - 0.01 && feet <= most + 0.01))
|
|
27
|
+
throw new RangeError(`The sheet's ${name} must be ${FEET(least)} to ${FEET(most)} feet in ${league.id}'s rules: ${String(given)} ${unit} is not`);
|
|
28
|
+
return feet;
|
|
29
|
+
};
|
|
30
|
+
const length = pick("length", base.lengthMin, base.length);
|
|
31
|
+
const width = pick("width", base.widthMin, base.width);
|
|
32
|
+
// The sheet's own `show` and `end`, and the named ranges of a curling sheet (`range: "house"`, or at an end), which say the same and win.
|
|
33
|
+
const ranged = o.sport === "curling" ? parseRange(o) : undefined;
|
|
34
|
+
const named = ranged !== undefined && ranged.kind === "name" ? ranged : undefined;
|
|
35
|
+
const show = named !== undefined ? named.name : SHOWS.includes(asked.show) ? asked.show : "sheet";
|
|
36
|
+
const end = named?.asked !== undefined ? named.asked : asked.end === "right" ? "right" : "left";
|
|
37
|
+
return { league, spec: { ...base, length, width }, pebble: asked.pebble === true, guardZone: asked.guardZone === true, show, end };
|
|
38
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Outline } from "./outline.ts";
|
|
2
|
+
import type { Surface } from "./surfaces/surface.ts";
|
|
3
|
+
import type { HostOptions, Placement, Sport, SurfaceOptions } from "./types.ts";
|
|
4
|
+
/** The host as options for a surface of its own: the options `outlineOf` and the drawing take. */
|
|
5
|
+
export declare function hostSurfaceOptions(host: HostOptions, o: Pick<SurfaceOptions, "year" | "detail" | "stripes" | "stripePattern" | "exactLines">): SurfaceOptions | undefined;
|
|
6
|
+
/** The host's outline in its frame, in feet. */
|
|
7
|
+
export declare function hostOutline(host: HostOptions, o: Pick<SurfaceOptions, "year" | "detail" | "stripes" | "stripePattern" | "exactLines">): Outline;
|
|
8
|
+
/** The sport of the host as the drawing's palette knows it. */
|
|
9
|
+
export declare function hostSport(host: HostOptions): Sport | "deck";
|
|
10
|
+
/** A ballpark's infield is a square 90 feet on a side: its middle is where the line from first base to third crosses the line from home plate to second. */
|
|
11
|
+
export declare const INFIELD_CENTRE: number;
|
|
12
|
+
/** The point of the guest that is put at the placement's `x` and `y`: the middle of the playing surface, and for a ballpark home plate. */
|
|
13
|
+
export declare function guestAnchor(o: Pick<SurfaceOptions, "sport" | "park" | "fence" | "units" | "pitch" | "league" | "year" | "sheet" | "net">): {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Where the guest stands when the options do not say: the middle of the host's field, with the guest as it lies; the middle of a ballpark's infield; for a
|
|
19
|
+
* ballpark set inside another surface, its infield's middle on the middle of the host.
|
|
20
|
+
*/
|
|
21
|
+
export declare function defaultPlacement(o: SurfaceOptions): Placement;
|
|
22
|
+
/** The placement the options ask for, with a part it leaves out filled from the default. */
|
|
23
|
+
export declare function placementOf(o: SurfaceOptions): Placement;
|
|
24
|
+
/** The point of the guest's own frame at the host's, for a placement. */
|
|
25
|
+
export declare function guestToHost(o: SurfaceOptions, p: Placement): (x: number, y: number) => [number, number];
|
|
26
|
+
/** The transform that does the same, as SVG writes it. */
|
|
27
|
+
export declare function guestTransform(o: SurfaceOptions, p: Placement): string;
|
|
28
|
+
/** How a guest sits in its host: the share of the guest's surface that lies outside the host's outline, from 0 (wholly inside) to 1. */
|
|
29
|
+
export interface Fit {
|
|
30
|
+
/** True when every point of the guest's surface is inside the host's outline. */
|
|
31
|
+
inside: boolean;
|
|
32
|
+
/** The share of the guest's area outside the host's outline, to a thousandth. */
|
|
33
|
+
outside: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* How the guest sits in its host, worked out on a grid over the guest's outline (a rink's rounded corners and a fence's curve are the guest's own).
|
|
37
|
+
* For a ballpark the host's outline is the fair ground inside the fence: a rink across the infield reaches into foul ground, which this reports as outside.
|
|
38
|
+
*/
|
|
39
|
+
export declare function fitOf(o: SurfaceOptions): Fit;
|
|
40
|
+
/**
|
|
41
|
+
* The host and the guest as one surface. `guest` is the drawing's own surface, built wide with no margin; `build` draws the host as a surface of its own.
|
|
42
|
+
* The result has the host's frame, the guest's team places and score moved onto the guest, and `frame`, the transform the guest's data goes through.
|
|
43
|
+
*/
|
|
44
|
+
export declare function composeSpecial(o: SurfaceOptions, guest: Surface, build: (options: SurfaceOptions, id: string) => Surface, id: string): Surface;
|