@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/look.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Named looks: the colours of a whole drawing (the surface, its lines, the ground round it and the words on that ground) as one palette, in a light and a
|
|
2
|
+
// dark set, for every sport. A look is a set of the stylesheet's own custom properties on `.kyogijo[data-palette=...]`, at no weight (`:where()`), so
|
|
3
|
+
// that a page's own rule and the options' `colors` always win; the sports differ where their surfaces do (ice is not grass). Written for this package.
|
|
4
|
+
// sportypy's `update_colors` and ggsoccer's `theme` were the ideas; none of their code or palettes is used.
|
|
5
|
+
import { luminance, rgbOf } from "./colour.js";
|
|
6
|
+
const PROPERTY = {
|
|
7
|
+
ink: "--ky-ink", line: "--ky-line", apron: "--ky-apron", surface: "--ky-surface", alt: "--ky-surface-alt", zone: "--ky-zone", boards: "--ky-boards",
|
|
8
|
+
red: "--ky-red", blue: "--ky-blue", dirt: "--ky-dirt", foul: "--ky-foul", infield: "--ky-infield", crease: "--ky-crease", key: "--ky-key", court: "--ky-court",
|
|
9
|
+
post: "--ky-post", pylon: "--ky-pylon", rgo: "--ky-rg-o", rgm: "--ky-rg-m", rgi: "--ky-rg-i", rgb: "--ky-rg-b", hog: "--ky-hog", hack: "--ky-hack",
|
|
10
|
+
fgz: "--ky-fgz", pebble: "--ky-pebble", free: "--ky-free", net: "--ky-net", area: "--ky-area",
|
|
11
|
+
};
|
|
12
|
+
/** The sports of each group. */
|
|
13
|
+
const GROUP_SPORTS = { football: ["nfl", "cfl", "ifaf"], nhl: ["nhl"], nba: ["nba"], mlb: ["mlb"], soccer: ["soccer"], curling: ["curling"], net: ["tennis", "volleyball", "badminton", "pickleball", "tabletennis"] };
|
|
14
|
+
/** The group a sport is painted with, or `undefined` for a surface with no palette of its own (it takes the look's base). */
|
|
15
|
+
export const groupOf = (sport) => Object.keys(GROUP_SPORTS).find((group) => GROUP_SPORTS[group].includes(sport));
|
|
16
|
+
// ---- The looks. ----
|
|
17
|
+
const GRASS = {
|
|
18
|
+
about: "The natural colours of each sport (grass, ice, maple), tuned so that every painted line reads against what it is painted on.",
|
|
19
|
+
light: {
|
|
20
|
+
base: { ink: "#1f2320", line: "#ffffff", apron: "#dcd8c9", surface: "#3f8f55", alt: "#3a864f", zone: "#2d6a40", boards: "#c8c1b0", red: "#c8372d", blue: "#2a5db0", dirt: "#a8744a", foul: "#3a8148", infield: "#58a05d", crease: "#bfd3ec", key: "#c25b3c", court: "#3b79ad", post: "#f2c230", pylon: "#f26a1b" },
|
|
21
|
+
groups: {
|
|
22
|
+
nhl: { surface: "#eef5fa", alt: "#e6eff6", apron: "#d3dbe1", boards: "#9aa4ab" },
|
|
23
|
+
nba: { surface: "#b8864d", alt: "#ae7d44", apron: "#c9c3b4", boards: "#8a5f30" },
|
|
24
|
+
mlb: { surface: "#4f9a55", alt: "#478f4e", apron: "#bdb59f", boards: "#2f4a36" },
|
|
25
|
+
soccer: { surface: "#4c9b56", alt: "#438f4d", apron: "#c9d2bd" },
|
|
26
|
+
curling: { surface: "#eaf3f9", apron: "#cfd8de", boards: "#8d98a0", line: "#23292d", rgo: "#2a5db0", rgm: "#ffffff", rgi: "#c8372d", rgb: "#ffffff", hog: "#c8372d", hack: "#3a4046", fgz: "rgba(42,93,176,.1)", pebble: "rgba(110,140,165,.4)" },
|
|
27
|
+
net: { surface: "#3d78bd", alt: "#3d78bd", free: "#2f5f9a", apron: "#dcd8c9", area: "#4a86c8", net: "#20262b" },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
dark: {
|
|
31
|
+
base: { ink: "#ece8dc", line: "#e9ece6", apron: "#1b1f1c", surface: "#2c6a3f", alt: "#296239", zone: "#1f4a2d", boards: "#4d5450", red: "#d4574d", blue: "#5584d4", dirt: "#8a6040", foul: "#275a31", infield: "#367a42", crease: "#8ea9cc", key: "#8a3f2b", court: "#2a5478", post: "#f2c230", pylon: "#f26a1b" },
|
|
32
|
+
groups: {
|
|
33
|
+
nhl: { surface: "#34444f", alt: "#2f3e48", apron: "#1a2025", boards: "#4b5156", red: "#ff8f84", blue: "#86b4ff", crease: "#4f6f8c" },
|
|
34
|
+
nba: { surface: "#8f6a3c", alt: "#876234", apron: "#1a1c1b", boards: "#5e4426" },
|
|
35
|
+
mlb: { surface: "#2f6b3a", alt: "#2b6336", apron: "#1b1f1c", boards: "#1c2b20" },
|
|
36
|
+
soccer: { surface: "#2d6c3e", alt: "#276136", apron: "#1b1f1c" },
|
|
37
|
+
curling: { surface: "#8fa6b7", apron: "#1a2025", boards: "#4b5156", line: "#11171b", rgo: "#3f6cc0", rgm: "#dfe8ef", rgi: "#c9473e", rgb: "#dfe8ef", hog: "#8a1f19", hack: "#161b1f", fgz: "rgba(20,40,90,.18)", pebble: "rgba(80,105,125,.4)" },
|
|
38
|
+
net: { surface: "#2f5f99", alt: "#2f5f99", free: "#244a78", apron: "#1b1f1c", area: "#3a6fae", net: "#e6e9ec" },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const NIGHT_DARK = {
|
|
43
|
+
base: { ink: "#e8ecf2", line: "#f3f5ef", apron: "#070a10", surface: "#1d4a2c", alt: "#1a4328", zone: "#163a22", boards: "#2a3140", red: "#ff6b5e", blue: "#6ea2ff", dirt: "#6b4a30", foul: "#153d22", infield: "#276a37", crease: "#2e4a66", key: "#7a3524", court: "#1d4468", post: "#ffd23f", pylon: "#ff8a3d" },
|
|
44
|
+
groups: {
|
|
45
|
+
nhl: { surface: "#26343f", alt: "#222f39", boards: "#3a4652", crease: "#3b5873" },
|
|
46
|
+
nba: { surface: "#5a4128", alt: "#533b24", boards: "#1c1410", key: "#16263f", line: "#f3f0e6" },
|
|
47
|
+
mlb: { surface: "#1d4a2c" },
|
|
48
|
+
soccer: { surface: "#1d4a2c" },
|
|
49
|
+
curling: { surface: "#2a3a47", boards: "#3a4652", line: "#e6eef5", rgo: "#6a97ff", rgm: "#dfe8ef", rgi: "#ff6b5e", rgb: "#dfe8ef", hog: "#ff7a6e", hack: "#c9d3da", fgz: "rgba(120,160,255,.12)", pebble: "rgba(190,210,225,.35)" },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const NIGHT = {
|
|
53
|
+
about: "A floodlit evening: a deep ground, a dark apron and pale lines.",
|
|
54
|
+
light: { ...NIGHT_DARK, base: { ...NIGHT_DARK.base, apron: "#10151f" } },
|
|
55
|
+
dark: NIGHT_DARK,
|
|
56
|
+
};
|
|
57
|
+
const chalkboard = (surface, alt, apron) => ({
|
|
58
|
+
base: { ink: "#eef0e6", line: "#f4f1e6", apron, surface, alt, zone: "#26332d", boards: "#4a5a52", red: "#f1a8a0", blue: "#a5c8ee", dirt: "#3e4a42", foul: "#26312b", infield: "#34423a", crease: "#3b4d58", key: "#3a463f", court: "#2e4655", post: "#f2e6a8", pylon: "#f1b98a", rgo: "#a5c8ee", rgm: "#f4f1e6", rgi: "#f1a8a0", rgb: "#f4f1e6", hog: "#f1a8a0", hack: "#d8d4c4", fgz: "rgba(165,200,238,.12)", pebble: "rgba(244,241,230,.25)" },
|
|
59
|
+
});
|
|
60
|
+
const CHALKBOARD = {
|
|
61
|
+
about: "Chalk on a slate board: white lines, pink and blue chalk for the red and blue ones, for a teaching diagram.",
|
|
62
|
+
light: chalkboard("#2e3b35", "#2a362f", "#1c2622"),
|
|
63
|
+
dark: chalkboard("#232d28", "#202923", "#151c19"),
|
|
64
|
+
};
|
|
65
|
+
const blueprint = (surface, alt, apron, boards) => ({
|
|
66
|
+
base: { ink: "#e6f1ff", line: "#e6f1ff", apron, surface, alt, zone: alt, boards, red: "#ffd1c9", blue: "#bfe0ff", dirt: "#2a64a8", foul: alt, infield: "#2358a0", crease: "#2f6aae", key: "#164277", court: surface, post: "#ffe08a", pylon: "#ffb86b", rgo: "#8ec1ff", rgm: "#e6f1ff", rgi: "#ffd1c9", rgb: "#e6f1ff", hog: "#ffd1c9", hack: "#cfe3fb", fgz: "rgba(190,224,255,.14)", pebble: "rgba(230,241,255,.25)" },
|
|
67
|
+
});
|
|
68
|
+
const BLUEPRINT = {
|
|
69
|
+
about: "White lines on blueprint blue, as a drawing office would print the rulebook's plan.",
|
|
70
|
+
light: blueprint("#1d4f8f", "#1a4983", "#123a6b", "#2c63a6"),
|
|
71
|
+
dark: blueprint("#153e72", "#123864", "#0c2c54", "#21528c"),
|
|
72
|
+
};
|
|
73
|
+
const PRINT = {
|
|
74
|
+
about: "Black on white with greys for the parts a colour would tell apart: for a printer that has no colour (dark: the same as white on black).",
|
|
75
|
+
light: {
|
|
76
|
+
base: { ink: "#111111", line: "#111111", apron: "#ffffff", surface: "#ffffff", alt: "#f0f0f0", zone: "#d9d9d9", boards: "#888888", red: "#444444", blue: "#111111", dirt: "#d6d6d6", foul: "#fafafa", infield: "#ececec", crease: "#e4e4e4", key: "#d4d4d4", court: "#e8e8e8", post: "#333333", pylon: "#333333", rgo: "#666666", rgm: "#eeeeee", rgi: "#999999", rgb: "#ffffff", hog: "#444444", hack: "#222222", fgz: "rgba(0,0,0,.08)", pebble: "rgba(0,0,0,.18)" },
|
|
77
|
+
},
|
|
78
|
+
dark: {
|
|
79
|
+
base: { ink: "#f2f2f2", line: "#f2f2f2", apron: "#000000", surface: "#111111", alt: "#1a1a1a", zone: "#2a2a2a", boards: "#777777", red: "#cfcfcf", blue: "#ffffff", dirt: "#333333", foul: "#0a0a0a", infield: "#1e1e1e", crease: "#262626", key: "#2e2e2e", court: "#1c1c1c", post: "#dddddd", pylon: "#dddddd", rgo: "#aaaaaa", rgm: "#222222", rgi: "#777777", rgb: "#000000", hog: "#cfcfcf", hack: "#eeeeee", fgz: "rgba(255,255,255,.1)", pebble: "rgba(255,255,255,.2)" },
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
const BROADCAST_LIGHT = {
|
|
83
|
+
base: { ink: "#f2f6fb", line: "#ffffff", apron: "#0d1b2e", surface: "#1f8a3a", alt: "#1b7d34", zone: "#14602a", boards: "#1a2a40", red: "#e0342b", blue: "#1f56d6", dirt: "#b0753f", foul: "#1a7733", infield: "#2f9d49", crease: "#bcd6f5", key: "#d1491f", court: "#1f5fb0", post: "#ffd21f", pylon: "#ff6a1a" },
|
|
84
|
+
groups: {
|
|
85
|
+
nhl: { surface: "#f4f9ff", alt: "#ecf3fb", boards: "#3b4d66", red: "#d11f17", blue: "#1a49c4" },
|
|
86
|
+
nba: { surface: "#b97a2e", alt: "#af7228", key: "#1d4ed8", boards: "#6b4318" },
|
|
87
|
+
curling: { surface: "#f4f9ff", boards: "#3b4d66", line: "#0d1b2e", rgo: "#1a49c4", rgm: "#ffffff", rgi: "#d11f17", rgb: "#ffffff", hog: "#d11f17", hack: "#1a2a40", fgz: "rgba(26,73,196,.12)", pebble: "rgba(80,110,150,.4)" },
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const BROADCAST = {
|
|
91
|
+
about: "Television graphics: saturated turf and wood, a deep navy apron, bright red and blue lines.",
|
|
92
|
+
light: BROADCAST_LIGHT,
|
|
93
|
+
dark: {
|
|
94
|
+
base: { ...BROADCAST_LIGHT.base, apron: "#060d18", surface: "#176a2d", alt: "#146027", zone: "#0f4a20", foul: "#135a27", infield: "#237b39" },
|
|
95
|
+
groups: {
|
|
96
|
+
nhl: { surface: "#2f4e6e", alt: "#2a4766", boards: "#223047", red: "#ff8a80", blue: "#8db6ff" },
|
|
97
|
+
nba: { surface: "#8f5b1f", alt: "#865418", key: "#1d4ed8", boards: "#4a2f10" },
|
|
98
|
+
curling: { surface: "#7f9db8", boards: "#223047", line: "#0d1b2e", rgo: "#1a49c4", rgm: "#e6eef5", rgi: "#b3140d", rgb: "#e6eef5", hog: "#8f0f09", hack: "#0d1b2e", fgz: "rgba(26,73,196,.15)", pebble: "rgba(40,70,100,.35)" },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
const HIGH_CONTRAST = {
|
|
103
|
+
about: "Black on white, or white on black: every line at the highest contrast the colours allow (WCAG AAA), for low vision and for projectors.",
|
|
104
|
+
light: {
|
|
105
|
+
base: { ink: "#000000", line: "#000000", apron: "#ffffff", surface: "#ffffff", alt: "#e6e6e6", zone: "#e6e6e6", boards: "#000000", red: "#b00020", blue: "#0030c0", dirt: "#d0d0d0", foul: "#f2f2f2", infield: "#e0e0e0", crease: "#dcdcdc", key: "#cfcfcf", court: "#e6e6e6", post: "#000000", pylon: "#000000", rgo: "#0030c0", rgm: "#ffffff", rgi: "#b00020", rgb: "#ffffff", hog: "#b00020", hack: "#000000", fgz: "rgba(0,48,192,.12)", pebble: "rgba(0,0,0,.25)" },
|
|
106
|
+
},
|
|
107
|
+
dark: {
|
|
108
|
+
base: { ink: "#ffffff", line: "#ffffff", apron: "#000000", surface: "#000000", alt: "#141414", zone: "#141414", boards: "#ffffff", red: "#ff6b6b", blue: "#7fb2ff", dirt: "#3a3a3a", foul: "#0a0a0a", infield: "#222222", crease: "#1a2a40", key: "#333333", court: "#0a0a0a", post: "#ffeb3b", pylon: "#ffeb3b", rgo: "#7fb2ff", rgm: "#000000", rgi: "#ff6b6b", rgb: "#000000", hog: "#ff6b6b", hack: "#ffffff", fgz: "rgba(127,178,255,.18)", pebble: "rgba(255,255,255,.3)" },
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* The named looks. Each is a light and a dark palette for every sport, as custom properties on `.kyogijo[data-palette="<name>"]`; pass one as `look`.
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { LOOKS, drawKyogijo } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
116
|
+
* const svg = drawKyogijo({ sport: "nhl", look: "chalkboard" });
|
|
117
|
+
* console.log(Object.keys(LOOKS).length, svg.includes('data-palette="chalkboard"'));
|
|
118
|
+
* // 7 true
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export const LOOKS = { grass: GRASS, night: NIGHT, chalkboard: CHALKBOARD, blueprint: BLUEPRINT, print: PRINT, broadcast: BROADCAST, "high-contrast": HIGH_CONTRAST };
|
|
122
|
+
/** The names of the looks, in the order a menu lists them. */
|
|
123
|
+
export const LOOK_NAMES = Object.freeze(Object.keys(LOOKS));
|
|
124
|
+
/** True when a value names a look. */
|
|
125
|
+
export const isLook = (value) => typeof value === "string" && Object.prototype.hasOwnProperty.call(LOOKS, value);
|
|
126
|
+
/** What the net sports' courts paint besides the surface and the apron, when a look does not say: the free zone in the second tone, a painted area in the key's, the net in the line's. */
|
|
127
|
+
const withNet = (palette) => ({ free: palette.alt, area: palette.key, net: palette.line, ...palette });
|
|
128
|
+
/** A look's palette for a sport in one mode: the look's base with what the sport's group changes. */
|
|
129
|
+
export function lookPalette(look, mode, sport) {
|
|
130
|
+
const m = LOOKS[look][mode];
|
|
131
|
+
const group = groupOf(sport);
|
|
132
|
+
const merged = { ...m.base, ...(group === undefined ? {} : m.groups?.[group]) };
|
|
133
|
+
return group === "net" ? withNet(merged) : merged;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The pairs of a palette that must read: what is painted on what, as `[ink, ground, least contrast]` (WCAG 2.2's 3:1 for a line, 4.5:1 for text). The words
|
|
137
|
+
* of the drawing are on the apron; a line is on the surface and, where its sport paints them under it, on the second tone of the mowing or planks, the key,
|
|
138
|
+
* the dirt, the infield and the foul ground.
|
|
139
|
+
*/
|
|
140
|
+
export const LOOK_PAIRS = {
|
|
141
|
+
all: [["ink", "apron", 4.5]],
|
|
142
|
+
football: [["line", "surface", 3], ["line", "alt", 3]],
|
|
143
|
+
nhl: [["red", "surface", 3], ["blue", "surface", 3]],
|
|
144
|
+
nba: [["line", "surface", 3], ["line", "alt", 3], ["line", "key", 3]],
|
|
145
|
+
mlb: [["line", "surface", 3], ["line", "alt", 3], ["line", "infield", 3], ["line", "dirt", 3], ["line", "foul", 3]],
|
|
146
|
+
soccer: [["line", "surface", 3], ["line", "alt", 3], ["line", "court", 3]],
|
|
147
|
+
curling: [["line", "surface", 3], ["hog", "surface", 3], ["hack", "surface", 3]],
|
|
148
|
+
net: [["line", "surface", 3], ["line", "free", 3], ["line", "area", 3]],
|
|
149
|
+
};
|
|
150
|
+
/** The contrast ratio of two colours (WCAG 2.2): 1 to 21, or `undefined` when a colour cannot be read without a browser. */
|
|
151
|
+
export function contrastOf(a, b) {
|
|
152
|
+
const x = rgbOf(a);
|
|
153
|
+
const y = rgbOf(b);
|
|
154
|
+
if (x === undefined || y === undefined)
|
|
155
|
+
return undefined;
|
|
156
|
+
const [hi, lo] = [luminance(x), luminance(y)].sort((p, q) => q - p);
|
|
157
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
158
|
+
}
|
|
159
|
+
// ---- The stylesheet. ----
|
|
160
|
+
const declarations = (palette) => Object.keys(palette)
|
|
161
|
+
.map((key) => `${PROPERTY[key]}:${palette[key]}`)
|
|
162
|
+
.join(";");
|
|
163
|
+
/** The rules of one mode of one look, for the base and each group, behind a selector that says which mode it is. */
|
|
164
|
+
function modeRules(name, mode, wrap) {
|
|
165
|
+
const out = [`${wrap(`.kyogijo[data-palette=${name}]`)}{${declarations(mode.base)}}`];
|
|
166
|
+
const groups = new Set([...Object.keys(mode.groups ?? {}), "net"]);
|
|
167
|
+
for (const group of groups) {
|
|
168
|
+
const palette = mode.groups?.[group] ?? {};
|
|
169
|
+
// A net sport's court has three colours the other surfaces have not: the group's rule carries them, made from the base where the look gives none.
|
|
170
|
+
const net = group === "net" ? withNet({ ...mode.base, ...palette }) : {};
|
|
171
|
+
const written = group === "net" ? { ...palette, free: net.free, area: net.area, net: net.net } : palette;
|
|
172
|
+
out.push(`${wrap(GROUP_SPORTS[group].map((sport) => `.kyogijo[data-palette=${name}][data-sport=${sport}]`).join(","))}{${declarations(written)}}`);
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
/** The stylesheet of one look, light and dark, at no weight. A drawing with a `look` carries its look's. */
|
|
177
|
+
export function lookStyle(name) {
|
|
178
|
+
const look = LOOKS[name];
|
|
179
|
+
const light = modeRules(name, look.light, (s) => `:where(${s})`);
|
|
180
|
+
// The device's setting (unless the page says light), then the page's or the drawing's own `data-theme="dark"`.
|
|
181
|
+
const auto = modeRules(name, look.dark, (s) => `:where(${s.split(",").map((one) => `html:not([data-theme=light]) ${one}:not([data-theme=light])`).join(",")})`);
|
|
182
|
+
const forced = modeRules(name, look.dark, (s) => `:where(${s.split(",").flatMap((one) => [`html[data-theme=dark] ${one}`, one.replace(/^\.kyogijo/, ".kyogijo[data-theme=dark]")]).join(",")})`);
|
|
183
|
+
return [...light, `@media (prefers-color-scheme:dark){${auto.join("\n")}}`, ...forced].join("\n");
|
|
184
|
+
}
|
|
185
|
+
/** The stylesheet of every look, for a page that draws with `style: "none"`. */
|
|
186
|
+
export const KYOGIJO_LOOK_STYLE = LOOK_NAMES.map(lookStyle).join("\n");
|
package/dist/mark.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules of a round team mark: the disc under the picture (the team's colour, or a plain one), the white ring and the hairline outside it, and the initials. The colours
|
|
3
|
+
* are custom properties with fallbacks (`--ky-mark-ring`, `--ky-mark-edge`, `--ky-mark-plain`), so a page can set them. A drawing with a round mark writes these rules in;
|
|
4
|
+
* `KYOGIJO_STYLE` has them for a page that draws with `style: "none"`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const KYOGIJO_MARK_STYLE: string;
|
|
7
|
+
/** What a round mark is drawn from. */
|
|
8
|
+
export interface RoundMark {
|
|
9
|
+
/** A prefix for the id of the clip path: unique in the drawing. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** The centre and the radius, in the drawing's units. */
|
|
12
|
+
cx: number;
|
|
13
|
+
cy: number;
|
|
14
|
+
r: number;
|
|
15
|
+
/** The picture as `safeLogo` wrote it: an address. Without one the mark is the team's colour with its initials. */
|
|
16
|
+
href?: string;
|
|
17
|
+
/** `cover` (the default; a flag fills the circle, its edges cut) or `contain` (a crest is shown whole on a plain disc). */
|
|
18
|
+
fit?: "cover" | "contain";
|
|
19
|
+
/** The letters for a mark with no picture. */
|
|
20
|
+
initials?: string;
|
|
21
|
+
/** The team's colour (`safeColour`): the disc of a mark with no picture. */
|
|
22
|
+
color?: string;
|
|
23
|
+
/** The colour of the initials on that disc. Black or white by the colour's lightness when missing. */
|
|
24
|
+
ink?: string;
|
|
25
|
+
/** The words for a tooltip. */
|
|
26
|
+
title?: string;
|
|
27
|
+
/** The ring's width: nine hundredths of the radius by default. */
|
|
28
|
+
ring?: number;
|
|
29
|
+
/** The mark is set in a group that is turned by this many degrees, so that it is turned back and stays upright. */
|
|
30
|
+
upright?: number;
|
|
31
|
+
/** A class added to the mark's group (the road chart's `ky-r-dim` for a team that did not advance). */
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The markup of one round mark. */
|
|
35
|
+
export declare function roundMarkup(m: RoundMark): string;
|
package/dist/mark.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The round team mark: a flag or a logo clipped to a circle with a thin ring, or, when a team has no picture, its initials on its colour. One function draws it for the
|
|
2
|
+
// score on a surface (a banner at each end, the badge and the strip under a compact card) and for the road-to-the-final chart, so a country has the same mark everywhere.
|
|
3
|
+
import { inkOn, safeColour } from "./colour.js";
|
|
4
|
+
import { el, esc, num } from "./format.js";
|
|
5
|
+
import { textWidth } from "./text.js";
|
|
6
|
+
/**
|
|
7
|
+
* The rules of a round team mark: the disc under the picture (the team's colour, or a plain one), the white ring and the hairline outside it, and the initials. The colours
|
|
8
|
+
* are custom properties with fallbacks (`--ky-mark-ring`, `--ky-mark-edge`, `--ky-mark-plain`), so a page can set them. A drawing with a round mark writes these rules in;
|
|
9
|
+
* `KYOGIJO_STYLE` has them for a page that draws with `style: "none"`.
|
|
10
|
+
*/
|
|
11
|
+
export const KYOGIJO_MARK_STYLE = `
|
|
12
|
+
.kyogijo .ky-mark-bg{fill:var(--c,var(--ky-mark-plain,#d9dde0))}
|
|
13
|
+
.kyogijo .ky-mark-light{fill:var(--ky-mark-plain,#f4f5f6)}
|
|
14
|
+
.kyogijo .ky-mark-ring{fill:none;stroke:var(--ky-mark-ring,#fff)}
|
|
15
|
+
.kyogijo .ky-mark-edge{fill:none;stroke:var(--ky-mark-edge,rgba(0,0,0,.32))}
|
|
16
|
+
.kyogijo .ky-mark-i{fill:var(--ci,#fff);font-family:var(--ky-font,system-ui,sans-serif);font-weight:800;text-anchor:middle;font-variant-numeric:tabular-nums}`.trim();
|
|
17
|
+
/** The markup of one round mark. */
|
|
18
|
+
export function roundMarkup(m) {
|
|
19
|
+
const { cx, cy, r } = m;
|
|
20
|
+
const ring = m.ring ?? Math.max(r * 0.09, 0.2);
|
|
21
|
+
const color = safeColour(m.color);
|
|
22
|
+
const ink = safeColour(m.ink) ?? inkOn(color);
|
|
23
|
+
const contain = m.fit === "contain";
|
|
24
|
+
let inner = "";
|
|
25
|
+
if (m.title !== undefined)
|
|
26
|
+
inner += `<title>${esc(m.title)}</title>`;
|
|
27
|
+
const clip = `${m.id}-c`;
|
|
28
|
+
if (m.href !== undefined) {
|
|
29
|
+
inner += el("clipPath", { id: clip }, el("circle", { cx: num(cx), cy: num(cy), r: num(r) }));
|
|
30
|
+
inner += el("circle", { class: contain ? "ky-mark-bg ky-mark-light" : "ky-mark-bg", cx: num(cx), cy: num(cy), r: num(r) });
|
|
31
|
+
const inset = contain ? r * 0.12 : 0;
|
|
32
|
+
inner += el("image", {
|
|
33
|
+
class: "ky-logo",
|
|
34
|
+
href: m.href,
|
|
35
|
+
x: num(cx - r + inset),
|
|
36
|
+
y: num(cy - r + inset),
|
|
37
|
+
width: num(2 * (r - inset)),
|
|
38
|
+
height: num(2 * (r - inset)),
|
|
39
|
+
preserveAspectRatio: contain ? "xMidYMid meet" : "xMidYMid slice",
|
|
40
|
+
"clip-path": `url(#${clip})`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
inner += el("circle", { class: "ky-mark-bg", cx: num(cx), cy: num(cy), r: num(r) });
|
|
45
|
+
const letters = (m.initials ?? "").trim();
|
|
46
|
+
if (letters !== "") {
|
|
47
|
+
const size = Math.min(r * 0.8, (r * 1.2) / Math.max(1, textWidth(letters)));
|
|
48
|
+
inner += el("text", { class: "ky-mark-i", x: num(cx), y: num(cy + size * 0.36), "font-size": num(size) }, esc(letters));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
inner += el("circle", { class: "ky-mark-ring", cx: num(cx), cy: num(cy), r: num(r - ring / 2), "stroke-width": num(ring) });
|
|
52
|
+
inner += el("circle", { class: "ky-mark-edge", cx: num(cx), cy: num(cy), r: num(r), "stroke-width": num(Math.max(ring * 0.3, 0.1)) });
|
|
53
|
+
const style = [color === undefined ? undefined : `--c:${color}`, m.href === undefined ? `--ci:${ink}` : undefined].filter((part) => part !== undefined).join(";");
|
|
54
|
+
return el("g", {
|
|
55
|
+
class: m.className === undefined ? "ky-mark" : `ky-mark ${m.className}`,
|
|
56
|
+
style: style === "" ? undefined : style,
|
|
57
|
+
transform: m.upright === undefined || m.upright === 0 ? undefined : `rotate(${num(-m.upright)} ${num(cx)} ${num(cy)})`,
|
|
58
|
+
}, inner);
|
|
59
|
+
}
|
package/dist/mount.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ReplayController } from "./replay.control.ts";
|
|
2
|
+
import type { ReplaySettings, ReplayTimeline } from "./replay.types.ts";
|
|
3
|
+
import type { ScoreOptions, SurfaceOptions } from "./types.ts";
|
|
4
|
+
/** A replay on a mount: the controller of its clock, and `destroy` to take the replay away and leave the surface. */
|
|
5
|
+
export type KyogijoReplay = ReplayController & {
|
|
6
|
+
destroy(): void;
|
|
7
|
+
};
|
|
8
|
+
/** What `mountKyogijo` gives back. */
|
|
9
|
+
export interface KyogijoMount {
|
|
10
|
+
/** Draw again with new options: a score that moved, a theme that changed. */
|
|
11
|
+
update(options: SurfaceOptions | ScoreOptions): void;
|
|
12
|
+
/** The drawing, or `null` after `destroy`. */
|
|
13
|
+
svg(): SVGSVGElement | null;
|
|
14
|
+
/** The orientation the drawing lies in now. */
|
|
15
|
+
orientation(): "landscape" | "portrait";
|
|
16
|
+
/**
|
|
17
|
+
* Play tracking data on the surface: the players, the ball and the events of a timeline, with controls under the drawing (play, pause, step,
|
|
18
|
+
* speed, loop, position), the keyboard (space, the arrow keys, Home and End) and a live region for goals and shots. Only the marks that move are
|
|
19
|
+
* moved, on animation frames. A reader who prefers reduced motion gets steps, and nothing plays by itself; a hidden page pauses. `update` keeps the replay.
|
|
20
|
+
*/
|
|
21
|
+
replay(timeline: ReplayTimeline, settings?: ReplaySettings): KyogijoReplay;
|
|
22
|
+
/** Stop watching the container and empty it. */
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
/** What `mountKyogijo` can be told. */
|
|
26
|
+
export interface MountSettings {
|
|
27
|
+
/** For `orientation: "auto"` on a container whose height follows its content: it is portrait when narrower than this many pixels. 560 by default. */
|
|
28
|
+
breakpoint?: number;
|
|
29
|
+
/** Highlight a score that changes in `update`: a short pulse of the number, or a fade for a reader who prefers reduced motion. On by default. */
|
|
30
|
+
highlight?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The container's width over its height, for `orientation: "auto"`. A container with a height of its own (a card of a fixed
|
|
34
|
+
* size, a flex or grid cell) gives its real shape; one whose height follows what is drawn in it gives a tall shape when it is
|
|
35
|
+
* narrower than the breakpoint and a wide one otherwise.
|
|
36
|
+
*/
|
|
37
|
+
export declare function containerAspect(host: HTMLElement, breakpoint?: number): number | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Draw into a container, and keep it drawn: with `orientation: "auto"` the container is watched, and the drawing is laid
|
|
40
|
+
* out again, tall or wide, when its shape changes.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts no-run
|
|
43
|
+
* import { mountKyogijo } from "@johnmorrisdotca/kyogijo-stadiums/mount";
|
|
44
|
+
* const card = mountKyogijo(document.querySelector("#game")!, {
|
|
45
|
+
* sport: "nhl",
|
|
46
|
+
* orientation: "auto",
|
|
47
|
+
* away: { name: "Harbour City Gulls", score: 1 },
|
|
48
|
+
* home: { name: "Prairie Ridge Bison", score: 0 },
|
|
49
|
+
* status: "live",
|
|
50
|
+
* });
|
|
51
|
+
* card.update({ sport: "nhl", orientation: "auto", away: { name: "Harbour City Gulls", score: 2 }, home: { name: "Prairie Ridge Bison", score: 0 } });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function mountKyogijo(host: HTMLElement, options: SurfaceOptions | ScoreOptions, settings?: MountSettings): KyogijoMount;
|
|
55
|
+
/**
|
|
56
|
+
* The drawing as an `svg` element, made by the browser's own parser, for code that appends nodes rather than sets text.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts no-run
|
|
59
|
+
* import { kyogijoElement } from "@johnmorrisdotca/kyogijo-stadiums/mount";
|
|
60
|
+
* document.body.append(kyogijoElement({ sport: "nba" }));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function kyogijoElement(options: SurfaceOptions | ScoreOptions): SVGSVGElement;
|
package/dist/mount.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { drawKyogijo, isPortrait } from "./draw.js";
|
|
2
|
+
import { resolveHomeSide } from "./homeside.js";
|
|
3
|
+
import { chooseLeague } from "./leagues.js";
|
|
4
|
+
import { createReplayView } from "./replay.dom.js";
|
|
5
|
+
const isScored = (o) => o.home !== undefined && o.away !== undefined;
|
|
6
|
+
const scoreText = (team) => (team.score === undefined || team.score === null ? "" : String(team.score));
|
|
7
|
+
/**
|
|
8
|
+
* Pulse the number of each team whose score is not what it was: it swells a little and settles (a fade only, for a reader who prefers
|
|
9
|
+
* reduced motion). Done with the Web Animations API, so no rule is added to the page and nothing is left on the element.
|
|
10
|
+
*/
|
|
11
|
+
function highlightScores(host, before, after) {
|
|
12
|
+
if (!isScored(before) || !isScored(after))
|
|
13
|
+
return;
|
|
14
|
+
// The sport as drawn: a league that is a sport of its own (`league: "cfl"` on an `nfl`) is that sport.
|
|
15
|
+
const chosen = { ...after, sport: chooseLeague(after).sport };
|
|
16
|
+
const order = resolveHomeSide(chosen) === "left" ? ["home", "away"] : ["away", "home"];
|
|
17
|
+
const numbers = host.querySelectorAll(".ky-score");
|
|
18
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
19
|
+
order.forEach((role, index) => {
|
|
20
|
+
const el = numbers[index];
|
|
21
|
+
if (el === undefined || typeof el.animate !== "function" || scoreText(before[role]) === scoreText(after[role]))
|
|
22
|
+
return;
|
|
23
|
+
if (reduced)
|
|
24
|
+
el.animate([{ opacity: 0.3 }], { duration: 900, easing: "ease-out" });
|
|
25
|
+
else {
|
|
26
|
+
el.style.transformBox = "fill-box";
|
|
27
|
+
el.style.transformOrigin = "center";
|
|
28
|
+
el.animate([{ transform: "scale(1)" }, { transform: "scale(1.28)", offset: 0.35 }, { transform: "scale(1)" }], { duration: 800, easing: "ease-out" });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The container's width over its height, for `orientation: "auto"`. A container with a height of its own (a card of a fixed
|
|
34
|
+
* size, a flex or grid cell) gives its real shape; one whose height follows what is drawn in it gives a tall shape when it is
|
|
35
|
+
* narrower than the breakpoint and a wide one otherwise.
|
|
36
|
+
*/
|
|
37
|
+
export function containerAspect(host, breakpoint = 560) {
|
|
38
|
+
const width = host.clientWidth;
|
|
39
|
+
if (width === 0)
|
|
40
|
+
return undefined;
|
|
41
|
+
// Empty, and with no least height of its own, a container has a height only if its style gives it one.
|
|
42
|
+
const nodes = [...host.childNodes];
|
|
43
|
+
const least = host.style.minHeight;
|
|
44
|
+
host.replaceChildren();
|
|
45
|
+
host.style.minHeight = "0";
|
|
46
|
+
const height = host.clientHeight;
|
|
47
|
+
host.style.minHeight = least;
|
|
48
|
+
host.replaceChildren(...nodes);
|
|
49
|
+
if (height >= 40)
|
|
50
|
+
return width / height;
|
|
51
|
+
return width < breakpoint ? 0.75 : 1.5;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Draw into a container, and keep it drawn: with `orientation: "auto"` the container is watched, and the drawing is laid
|
|
55
|
+
* out again, tall or wide, when its shape changes.
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts no-run
|
|
58
|
+
* import { mountKyogijo } from "@johnmorrisdotca/kyogijo-stadiums/mount";
|
|
59
|
+
* const card = mountKyogijo(document.querySelector("#game")!, {
|
|
60
|
+
* sport: "nhl",
|
|
61
|
+
* orientation: "auto",
|
|
62
|
+
* away: { name: "Harbour City Gulls", score: 1 },
|
|
63
|
+
* home: { name: "Prairie Ridge Bison", score: 0 },
|
|
64
|
+
* status: "live",
|
|
65
|
+
* });
|
|
66
|
+
* card.update({ sport: "nhl", orientation: "auto", away: { name: "Harbour City Gulls", score: 2 }, home: { name: "Prairie Ridge Bison", score: 0 } });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function mountKyogijo(host, options, settings = {}) {
|
|
70
|
+
let current = options;
|
|
71
|
+
let portrait = false;
|
|
72
|
+
let alive = true;
|
|
73
|
+
let frame = 0;
|
|
74
|
+
let view;
|
|
75
|
+
const breakpoint = settings.breakpoint ?? 560;
|
|
76
|
+
const resolved = () => {
|
|
77
|
+
let aspect = current.aspect;
|
|
78
|
+
if (current.orientation === "auto" && aspect === undefined)
|
|
79
|
+
aspect = containerAspect(host, breakpoint);
|
|
80
|
+
const next = { ...current, aspect };
|
|
81
|
+
portrait = isPortrait(next);
|
|
82
|
+
return next;
|
|
83
|
+
};
|
|
84
|
+
const render = () => {
|
|
85
|
+
if (!alive)
|
|
86
|
+
return;
|
|
87
|
+
const next = resolved();
|
|
88
|
+
if (view === undefined)
|
|
89
|
+
host.innerHTML = drawKyogijo(next);
|
|
90
|
+
else
|
|
91
|
+
view.draw(next);
|
|
92
|
+
};
|
|
93
|
+
const watch = () => {
|
|
94
|
+
if (!alive || current.orientation !== "auto" || current.aspect !== undefined)
|
|
95
|
+
return;
|
|
96
|
+
if (frame !== 0)
|
|
97
|
+
return;
|
|
98
|
+
frame = requestAnimationFrame(() => {
|
|
99
|
+
frame = 0;
|
|
100
|
+
if (!alive)
|
|
101
|
+
return;
|
|
102
|
+
const aspect = containerAspect(host, breakpoint);
|
|
103
|
+
if (aspect === undefined)
|
|
104
|
+
return;
|
|
105
|
+
if ((aspect < 1) !== portrait)
|
|
106
|
+
render();
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
render();
|
|
110
|
+
let observer;
|
|
111
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
112
|
+
observer = new ResizeObserver(watch);
|
|
113
|
+
observer.observe(host);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
update(next) {
|
|
117
|
+
const before = current;
|
|
118
|
+
current = next;
|
|
119
|
+
render();
|
|
120
|
+
if (settings.highlight !== false)
|
|
121
|
+
highlightScores(host, before, next);
|
|
122
|
+
},
|
|
123
|
+
replay(timeline, replaySettings = {}) {
|
|
124
|
+
if (!alive)
|
|
125
|
+
throw new Error("this mount was destroyed");
|
|
126
|
+
view?.destroy();
|
|
127
|
+
const mine = createReplayView(host, timeline, replaySettings, resolved());
|
|
128
|
+
view = mine;
|
|
129
|
+
return {
|
|
130
|
+
...mine.controller,
|
|
131
|
+
destroy() {
|
|
132
|
+
if (view !== mine)
|
|
133
|
+
return;
|
|
134
|
+
mine.destroy();
|
|
135
|
+
view = undefined;
|
|
136
|
+
render();
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
svg: () => (alive ? host.querySelector("svg.kyogijo") : null),
|
|
141
|
+
orientation: () => (portrait ? "portrait" : "landscape"),
|
|
142
|
+
destroy() {
|
|
143
|
+
alive = false;
|
|
144
|
+
view?.destroy();
|
|
145
|
+
view = undefined;
|
|
146
|
+
observer?.disconnect();
|
|
147
|
+
if (frame !== 0)
|
|
148
|
+
cancelAnimationFrame(frame);
|
|
149
|
+
host.replaceChildren();
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The drawing as an `svg` element, made by the browser's own parser, for code that appends nodes rather than sets text.
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts no-run
|
|
157
|
+
* import { kyogijoElement } from "@johnmorrisdotca/kyogijo-stadiums/mount";
|
|
158
|
+
* document.body.append(kyogijoElement({ sport: "nba" }));
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export function kyogijoElement(options) {
|
|
162
|
+
const doc = new DOMParser().parseFromString(drawKyogijo(options), "image/svg+xml");
|
|
163
|
+
const svg = doc.documentElement;
|
|
164
|
+
if (svg.localName !== "svg" || doc.querySelector("parsererror") !== null)
|
|
165
|
+
throw new Error("kyogijo drew something the browser could not read as SVG");
|
|
166
|
+
return document.importNode(svg, true);
|
|
167
|
+
}
|
package/dist/mow.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { StripePattern } from "./types.ts";
|
|
2
|
+
/** A rectangle of turf. */
|
|
3
|
+
export interface Turf {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
w: number;
|
|
7
|
+
h: number;
|
|
8
|
+
}
|
|
9
|
+
/** The lighter tone of a mowing pattern: one path, whether it must be cut to the turf, and whether its rings are cut out of each other (`fill-rule: evenodd`). */
|
|
10
|
+
export interface Mown {
|
|
11
|
+
path: string;
|
|
12
|
+
/** True when the path runs past the turf and a clip path of the turf must cut it. */
|
|
13
|
+
clip: boolean;
|
|
14
|
+
evenodd: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** An odd whole number of cells nearest to a length over a cell: odd, so that both ends of the turf are mown alike. */
|
|
17
|
+
export declare const oddCells: (length: number, cell: number) => number;
|
|
18
|
+
/**
|
|
19
|
+
* The lighter tone of a pattern on a rectangle of turf. `band` is the width of the usual stripe, along x; `wide` and `narrow` are twice and half of it.
|
|
20
|
+
* `bands` run across the turf (side by side along x), `lengthwise` along it, `checks` are squares of about `band`, `diagonal` are 45-degree stripes
|
|
21
|
+
* `band` wide across, and `circles` are rings `band` wide about the middle. A pattern that is not one of these (`none`, `rings`, `fan`) has no tone here.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mowTurf(pattern: StripePattern, turf: Turf, band: number): Mown;
|
|
24
|
+
/** A ballpark's fair ground, as the field of its stripes: how far it reaches either side of the line to centre field and how far out. */
|
|
25
|
+
export interface Park {
|
|
26
|
+
umin: number;
|
|
27
|
+
umax: number;
|
|
28
|
+
vmax: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The lighter tone of a pattern on a ballpark: coordinates are the field's screen frame (x across, y minus the distance out from home plate). `band` is
|
|
32
|
+
* 30 feet, the width of a stripe of the usual rings. `bands` run across the field at fixed distances out from home, `lengthwise` along the line to centre
|
|
33
|
+
* field, `checks` are squares, `diagonal` run at 45 degrees, `fan` is wedges out from home plate, 6 degrees each. `rings` and `circles` are the park's own
|
|
34
|
+
* arcs about home plate (drawn by the field itself) and `none` is plain, so they have no tone here. The path runs past the fence and must be cut to the fair ground.
|
|
35
|
+
*/
|
|
36
|
+
export declare function mowPark(pattern: StripePattern, park: Park, band?: number): Mown;
|