@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.
Files changed (321) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE.md +293 -0
  4. package/README.md +600 -2
  5. package/dist/annotate.d.ts +47 -0
  6. package/dist/annotate.js +349 -0
  7. package/dist/atlas-entry.d.ts +4 -0
  8. package/dist/atlas-entry.js +3 -0
  9. package/dist/atlas.d.ts +131 -0
  10. package/dist/atlas.js +149 -0
  11. package/dist/background.d.ts +56 -0
  12. package/dist/background.js +127 -0
  13. package/dist/ballpark.d.ts +48 -0
  14. package/dist/ballpark.js +129 -0
  15. package/dist/canvas-entry.d.ts +2 -0
  16. package/dist/canvas-entry.js +2 -0
  17. package/dist/canvas.d.ts +85 -0
  18. package/dist/canvas.js +279 -0
  19. package/dist/charts-entry.d.ts +10 -0
  20. package/dist/charts-entry.js +8 -0
  21. package/dist/charts.baseball.d.ts +30 -0
  22. package/dist/charts.baseball.js +152 -0
  23. package/dist/charts.curling.d.ts +52 -0
  24. package/dist/charts.curling.js +196 -0
  25. package/dist/charts.d.ts +172 -0
  26. package/dist/charts.js +508 -0
  27. package/dist/charts.network.d.ts +66 -0
  28. package/dist/charts.network.js +64 -0
  29. package/dist/charts.soccer.d.ts +43 -0
  30. package/dist/charts.soccer.js +191 -0
  31. package/dist/charts.types.d.ts +396 -0
  32. package/dist/charts.types.js +1 -0
  33. package/dist/colour.d.ts +29 -0
  34. package/dist/colour.js +97 -0
  35. package/dist/common.d.ts +14 -0
  36. package/dist/common.js +32 -0
  37. package/dist/court.d.ts +89 -0
  38. package/dist/court.js +248 -0
  39. package/dist/courts.style.d.ts +20 -0
  40. package/dist/courts.style.js +54 -0
  41. package/dist/cricket.board.d.ts +18 -0
  42. package/dist/cricket.board.js +67 -0
  43. package/dist/curling.board.d.ts +24 -0
  44. package/dist/curling.board.js +147 -0
  45. package/dist/d3-entry.d.ts +3 -0
  46. package/dist/d3-entry.js +2 -0
  47. package/dist/d3.d.ts +45 -0
  48. package/dist/d3.js +56 -0
  49. package/dist/draw.d.ts +52 -0
  50. package/dist/draw.js +705 -0
  51. package/dist/element-define.d.ts +2 -0
  52. package/dist/element-define.js +4 -0
  53. package/dist/element-entry.d.ts +1 -0
  54. package/dist/element-entry.js +2 -0
  55. package/dist/element.d.ts +39 -0
  56. package/dist/element.js +321 -0
  57. package/dist/eras-entry.d.ts +2 -0
  58. package/dist/eras-entry.js +2 -0
  59. package/dist/eras.d.ts +204 -0
  60. package/dist/eras.js +396 -0
  61. package/dist/events-entry.d.ts +3 -0
  62. package/dist/events-entry.js +3 -0
  63. package/dist/events.d.ts +54 -0
  64. package/dist/events.data.d.ts +59 -0
  65. package/dist/events.data.js +297 -0
  66. package/dist/events.js +127 -0
  67. package/dist/features.d.ts +31 -0
  68. package/dist/features.js +284 -0
  69. package/dist/field.score.d.ts +5 -0
  70. package/dist/field.score.js +33 -0
  71. package/dist/fields/afl.d.ts +11 -0
  72. package/dist/fields/afl.js +103 -0
  73. package/dist/fields/cricket.d.ts +9 -0
  74. package/dist/fields/cricket.js +81 -0
  75. package/dist/fields/fieldhockey.d.ts +6 -0
  76. package/dist/fields/fieldhockey.js +81 -0
  77. package/dist/fields/gaelic.d.ts +10 -0
  78. package/dist/fields/gaelic.js +86 -0
  79. package/dist/fields/handball.d.ts +6 -0
  80. package/dist/fields/handball.js +85 -0
  81. package/dist/fields/lacrosse.d.ts +17 -0
  82. package/dist/fields/lacrosse.js +169 -0
  83. package/dist/fields/rugby.d.ts +10 -0
  84. package/dist/fields/rugby.js +130 -0
  85. package/dist/fields.d.ts +12 -0
  86. package/dist/fields.js +44 -0
  87. package/dist/fields.kit.d.ts +63 -0
  88. package/dist/fields.kit.js +108 -0
  89. package/dist/fields.style.d.ts +4 -0
  90. package/dist/fields.style.js +19 -0
  91. package/dist/fields.types.d.ts +155 -0
  92. package/dist/fields.types.js +1 -0
  93. package/dist/format.d.ts +10 -0
  94. package/dist/format.js +28 -0
  95. package/dist/formations.d.ts +18 -0
  96. package/dist/formations.js +211 -0
  97. package/dist/frames-entry.d.ts +8 -0
  98. package/dist/frames-entry.js +7 -0
  99. package/dist/frames.d.ts +199 -0
  100. package/dist/frames.js +271 -0
  101. package/dist/frames.providers.d.ts +16 -0
  102. package/dist/frames.providers.js +302 -0
  103. package/dist/geojson-entry.d.ts +2 -0
  104. package/dist/geojson-entry.js +2 -0
  105. package/dist/geojson.d.ts +79 -0
  106. package/dist/geojson.js +147 -0
  107. package/dist/geometry-entry.d.ts +7 -0
  108. package/dist/geometry-entry.js +5 -0
  109. package/dist/geometry.d.ts +295 -0
  110. package/dist/geometry.js +361 -0
  111. package/dist/grounds-entry.d.ts +4 -0
  112. package/dist/grounds-entry.js +3 -0
  113. package/dist/grounds.d.ts +134 -0
  114. package/dist/grounds.data.d.ts +2 -0
  115. package/dist/grounds.data.js +1849 -0
  116. package/dist/grounds.js +74 -0
  117. package/dist/heat.colour.d.ts +37 -0
  118. package/dist/heat.colour.js +54 -0
  119. package/dist/heat.d.ts +43 -0
  120. package/dist/heat.js +614 -0
  121. package/dist/heat.stats.d.ts +123 -0
  122. package/dist/heat.stats.js +413 -0
  123. package/dist/heat.types.d.ts +145 -0
  124. package/dist/heat.types.js +1 -0
  125. package/dist/heat.zones.d.ts +54 -0
  126. package/dist/heat.zones.js +424 -0
  127. package/dist/homeside.d.ts +16 -0
  128. package/dist/homeside.js +43 -0
  129. package/dist/index.d.ts +47 -0
  130. package/dist/index.js +29 -0
  131. package/dist/layers-entry.d.ts +19 -0
  132. package/dist/layers-entry.js +11 -0
  133. package/dist/layers.d.ts +41 -0
  134. package/dist/layers.env.d.ts +72 -0
  135. package/dist/layers.env.js +79 -0
  136. package/dist/layers.js +533 -0
  137. package/dist/layers.marks.d.ts +45 -0
  138. package/dist/layers.marks.js +168 -0
  139. package/dist/layers.types.d.ts +226 -0
  140. package/dist/layers.types.js +1 -0
  141. package/dist/layout.d.ts +97 -0
  142. package/dist/layout.js +381 -0
  143. package/dist/layout.style.d.ts +6 -0
  144. package/dist/layout.style.js +17 -0
  145. package/dist/layouts-entry.d.ts +5 -0
  146. package/dist/layouts-entry.js +4 -0
  147. package/dist/leagues/aussie.d.ts +57 -0
  148. package/dist/leagues/aussie.js +36 -0
  149. package/dist/leagues/baseball.d.ts +58 -0
  150. package/dist/leagues/baseball.js +171 -0
  151. package/dist/leagues/basketball.d.ts +67 -0
  152. package/dist/leagues/basketball.js +128 -0
  153. package/dist/leagues/courts.d.ts +212 -0
  154. package/dist/leagues/courts.js +114 -0
  155. package/dist/leagues/cricket.d.ts +45 -0
  156. package/dist/leagues/cricket.js +34 -0
  157. package/dist/leagues/curling.d.ts +64 -0
  158. package/dist/leagues/curling.js +53 -0
  159. package/dist/leagues/fieldhockey.d.ts +48 -0
  160. package/dist/leagues/fieldhockey.js +29 -0
  161. package/dist/leagues/fields.d.ts +10 -0
  162. package/dist/leagues/fields.js +6 -0
  163. package/dist/leagues/football.d.ts +8 -0
  164. package/dist/leagues/football.js +82 -0
  165. package/dist/leagues/gaelic.d.ts +50 -0
  166. package/dist/leagues/gaelic.js +29 -0
  167. package/dist/leagues/handball.d.ts +45 -0
  168. package/dist/leagues/handball.js +32 -0
  169. package/dist/leagues/hockey.d.ts +63 -0
  170. package/dist/leagues/hockey.js +166 -0
  171. package/dist/leagues/lacrosse.d.ts +103 -0
  172. package/dist/leagues/lacrosse.js +175 -0
  173. package/dist/leagues/rugby.d.ts +59 -0
  174. package/dist/leagues/rugby.js +72 -0
  175. package/dist/leagues/sources.d.ts +18 -0
  176. package/dist/leagues/sources.js +95 -0
  177. package/dist/leagues/types.d.ts +43 -0
  178. package/dist/leagues/types.js +5 -0
  179. package/dist/leagues-entry.d.ts +23 -0
  180. package/dist/leagues-entry.js +15 -0
  181. package/dist/leagues.d.ts +172 -0
  182. package/dist/leagues.js +462 -0
  183. package/dist/look.d.ts +50 -0
  184. package/dist/look.js +186 -0
  185. package/dist/mark.d.ts +35 -0
  186. package/dist/mark.js +59 -0
  187. package/dist/mount-entry.d.ts +2 -0
  188. package/dist/mount-entry.js +2 -0
  189. package/dist/mount.d.ts +63 -0
  190. package/dist/mount.js +167 -0
  191. package/dist/mow.d.ts +36 -0
  192. package/dist/mow.js +111 -0
  193. package/dist/names.d.ts +77 -0
  194. package/dist/names.js +97 -0
  195. package/dist/outline.d.ts +25 -0
  196. package/dist/outline.js +112 -0
  197. package/dist/parks-entry.d.ts +4 -0
  198. package/dist/parks-entry.js +3 -0
  199. package/dist/parks.d.ts +200 -0
  200. package/dist/parks.data.d.ts +2 -0
  201. package/dist/parks.data.js +4489 -0
  202. package/dist/parks.js +92 -0
  203. package/dist/plot-entry.d.ts +2 -0
  204. package/dist/plot-entry.js +2 -0
  205. package/dist/plot.d.ts +74 -0
  206. package/dist/plot.js +68 -0
  207. package/dist/png-entry.d.ts +2 -0
  208. package/dist/png-entry.js +2 -0
  209. package/dist/png.d.ts +26 -0
  210. package/dist/png.js +46 -0
  211. package/dist/ranges.d.ts +33 -0
  212. package/dist/ranges.js +178 -0
  213. package/dist/ranges.names.d.ts +31 -0
  214. package/dist/ranges.names.js +65 -0
  215. package/dist/react-entry.d.ts +2 -0
  216. package/dist/react-entry.js +2 -0
  217. package/dist/react.d.ts +53 -0
  218. package/dist/react.js +58 -0
  219. package/dist/replay-entry.d.ts +5 -0
  220. package/dist/replay-entry.js +4 -0
  221. package/dist/replay.control.d.ts +47 -0
  222. package/dist/replay.control.js +184 -0
  223. package/dist/replay.d.ts +170 -0
  224. package/dist/replay.dom.d.ts +21 -0
  225. package/dist/replay.dom.js +388 -0
  226. package/dist/replay.js +579 -0
  227. package/dist/replay.types.d.ts +152 -0
  228. package/dist/replay.types.js +1 -0
  229. package/dist/restyle.d.ts +21 -0
  230. package/dist/restyle.js +70 -0
  231. package/dist/road.d.ts +26 -0
  232. package/dist/road.draw.d.ts +6 -0
  233. package/dist/road.draw.js +269 -0
  234. package/dist/road.js +59 -0
  235. package/dist/road.model.d.ts +63 -0
  236. package/dist/road.model.js +215 -0
  237. package/dist/road.style.d.ts +7 -0
  238. package/dist/road.style.js +26 -0
  239. package/dist/road.types.d.ts +122 -0
  240. package/dist/road.types.js +1 -0
  241. package/dist/scene-entry.d.ts +7 -0
  242. package/dist/scene-entry.js +5 -0
  243. package/dist/scene.css.d.ts +44 -0
  244. package/dist/scene.css.js +296 -0
  245. package/dist/scene.d.ts +27 -0
  246. package/dist/scene.fit.d.ts +12 -0
  247. package/dist/scene.fit.js +18 -0
  248. package/dist/scene.flat.d.ts +38 -0
  249. package/dist/scene.flat.js +167 -0
  250. package/dist/scene.js +420 -0
  251. package/dist/scene.path.d.ts +40 -0
  252. package/dist/scene.path.js +357 -0
  253. package/dist/scene.types.d.ts +172 -0
  254. package/dist/scene.types.js +1 -0
  255. package/dist/scene.xml.d.ts +31 -0
  256. package/dist/scene.xml.js +81 -0
  257. package/dist/score.d.ts +70 -0
  258. package/dist/score.js +212 -0
  259. package/dist/sets.board.d.ts +22 -0
  260. package/dist/sets.board.js +89 -0
  261. package/dist/sheet.d.ts +18 -0
  262. package/dist/sheet.js +38 -0
  263. package/dist/special.d.ts +44 -0
  264. package/dist/special.js +204 -0
  265. package/dist/special.style.d.ts +8 -0
  266. package/dist/special.style.js +36 -0
  267. package/dist/strings.d.ts +581 -0
  268. package/dist/strings.js +411 -0
  269. package/dist/style.d.ts +35 -0
  270. package/dist/style.js +177 -0
  271. package/dist/surfaces/baseball.d.ts +33 -0
  272. package/dist/surfaces/baseball.js +208 -0
  273. package/dist/surfaces/baseball.walls.d.ts +16 -0
  274. package/dist/surfaces/baseball.walls.js +150 -0
  275. package/dist/surfaces/basketball.d.ts +8 -0
  276. package/dist/surfaces/basketball.js +199 -0
  277. package/dist/surfaces/curling.d.ts +23 -0
  278. package/dist/surfaces/curling.js +128 -0
  279. package/dist/surfaces/field.d.ts +12 -0
  280. package/dist/surfaces/field.js +163 -0
  281. package/dist/surfaces/football.d.ts +12 -0
  282. package/dist/surfaces/football.js +208 -0
  283. package/dist/surfaces/hockey.d.ts +10 -0
  284. package/dist/surfaces/hockey.js +166 -0
  285. package/dist/surfaces/net.d.ts +7 -0
  286. package/dist/surfaces/net.js +151 -0
  287. package/dist/surfaces/soccer-providers.d.ts +124 -0
  288. package/dist/surfaces/soccer-providers.js +334 -0
  289. package/dist/surfaces/soccer-spec.d.ts +138 -0
  290. package/dist/surfaces/soccer-spec.js +175 -0
  291. package/dist/surfaces/soccer.d.ts +25 -0
  292. package/dist/surfaces/soccer.js +270 -0
  293. package/dist/surfaces/surface.d.ts +180 -0
  294. package/dist/surfaces/surface.js +49 -0
  295. package/dist/team.common.d.ts +75 -0
  296. package/dist/team.common.js +97 -0
  297. package/dist/team.formation.d.ts +24 -0
  298. package/dist/team.formation.js +121 -0
  299. package/dist/team.geometry.d.ts +66 -0
  300. package/dist/team.geometry.js +304 -0
  301. package/dist/team.layers.d.ts +16 -0
  302. package/dist/team.layers.js +32 -0
  303. package/dist/team.motion.d.ts +9 -0
  304. package/dist/team.motion.js +325 -0
  305. package/dist/team.network.d.ts +43 -0
  306. package/dist/team.network.js +215 -0
  307. package/dist/team.shape.d.ts +12 -0
  308. package/dist/team.shape.js +217 -0
  309. package/dist/team.types.d.ts +189 -0
  310. package/dist/team.types.js +1 -0
  311. package/dist/text.d.ts +31 -0
  312. package/dist/text.js +88 -0
  313. package/dist/themes.d.ts +14 -0
  314. package/dist/themes.js +24 -0
  315. package/dist/types.d.ts +565 -0
  316. package/dist/types.js +1 -0
  317. package/dist/units.d.ts +45 -0
  318. package/dist/units.js +90 -0
  319. package/dist/version.d.ts +2 -0
  320. package/dist/version.js +2 -0
  321. package/package.json +234 -4
package/dist/layout.js ADDED
@@ -0,0 +1,381 @@
1
+ // Many drawings in one SVG: a grid of small multiples (one per park, per period, per player) with a title, a subtitle, a credit line and a key that they share. Each
2
+ // drawing is read as markup, given ids of its own, and set in a group that is moved and scaled into its cell, so that the grid is one picture a screen reader, the scene
3
+ // and every renderer read like any other drawing of the package. No drawing is drawn twice, and nothing is measured in a browser: the type is set by estimates (`textWidth`).
4
+ import { backgroundMarkup, resolveBackground, KYOGIJO_BACKGROUND_STYLE } from "./background.js";
5
+ import { safeColour } from "./colour.js";
6
+ import { safeClass } from "./common.js";
7
+ import { drawKyogijo } from "./draw.js";
8
+ import { el, esc, hash, num } from "./format.js";
9
+ import { KYOGIJO_GRID_STYLE } from "./layout.style.js";
10
+ import { KYOGIJO_MARK_STYLE } from "./mark.js";
11
+ import { KYOGIJO_ROAD_STYLE } from "./road.style.js";
12
+ import { isPolygon, shapePath } from "./layers.marks.js";
13
+ import { elements, parseSvg, textOf, writeSvg } from "./scene.xml.js";
14
+ import { KYOGIJO_STRINGS, fill } from "./strings.js";
15
+ import { KYOGIJO_BASE_STYLE, KYOGIJO_CURLING_STYLE, KYOGIJO_HEAT_STYLE, KYOGIJO_NOTE_STYLE, KYOGIJO_TEAM_STYLE } from "./style.js";
16
+ import { textWidth } from "./text.js";
17
+ import { VERSION } from "./version.js";
18
+ /**
19
+ * The presets of `drawGrid`: `card` is 1200 by 675 (the 16:9 card that social sites show for a link), `square` is 1080 by 1080, and `phone` is 390 wide in one column with
20
+ * the height the drawings need. A `width`, a `height` or `columns` in the options wins over the preset's.
21
+ */
22
+ export const GRID_PRESETS = Object.freeze({
23
+ card: { width: 1200, height: 675, columns: undefined, ground: true, about: "1200 by 675, a social card" },
24
+ square: { width: 1080, height: 1080, columns: undefined, ground: true, about: "1080 by 1080, a square post" },
25
+ phone: { width: 390, height: undefined, columns: 1, ground: false, about: "390 wide, one column, as tall as the drawings need" },
26
+ });
27
+ /** The most drawings a grid takes. */
28
+ export const GRID_MAX_CELLS = 200;
29
+ const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
30
+ const positive = (v) => (typeof v === "number" && Number.isFinite(v) && v > 0 ? v : undefined);
31
+ const fixed = (v) => String(Math.round(v * 100000) / 100000);
32
+ /** The lines a text breaks into at spaces, and inside a word that is wider than a line (Japanese has no spaces), the last one cut with an ellipsis when there are too many. */
33
+ function wrap(text, size, maxWidth, maxLines) {
34
+ const fits = (s) => textWidth(s) * size <= maxWidth;
35
+ const lines = [];
36
+ let line = "";
37
+ for (const word of text.trim().split(/\s+/).filter((w) => w !== "")) {
38
+ const joined = line === "" ? word : `${line} ${word}`;
39
+ if (fits(joined)) {
40
+ line = joined;
41
+ continue;
42
+ }
43
+ if (line !== "")
44
+ lines.push(line);
45
+ line = "";
46
+ if (fits(word)) {
47
+ line = word;
48
+ continue;
49
+ }
50
+ for (const ch of word) {
51
+ if (fits(line + ch) || line === "")
52
+ line += ch;
53
+ else {
54
+ lines.push(line);
55
+ line = ch;
56
+ }
57
+ }
58
+ }
59
+ if (line !== "")
60
+ lines.push(line);
61
+ if (lines.length > maxLines) {
62
+ lines.length = maxLines;
63
+ let last = lines[maxLines - 1];
64
+ while (last.length > 1 && !fits(`${last}…`))
65
+ last = last.slice(0, -1);
66
+ lines[maxLines - 1] = `${last}…`;
67
+ }
68
+ return lines;
69
+ }
70
+ /** A caption on one line: made smaller to fit, and cut with an ellipsis when it still does not at 60 percent. */
71
+ function caption(text, size, maxWidth) {
72
+ const all = textWidth(text);
73
+ if (all * size <= maxWidth)
74
+ return { text, size };
75
+ const smaller = maxWidth / all;
76
+ if (smaller >= size * 0.6)
77
+ return { text, size: smaller };
78
+ const s = size * 0.6;
79
+ let cut = text;
80
+ while (cut.length > 1 && textWidth(`${cut}…`) * s > maxWidth)
81
+ cut = cut.slice(0, -1);
82
+ return { text: `${cut}…`, size: s };
83
+ }
84
+ const isCell = (c) => typeof c === "object" && c !== null && "drawing" in c;
85
+ /** The SVG a cell holds, drawn when it is options or a chart. */
86
+ function svgOf(cell, o) {
87
+ const label = isCell(cell) ? (typeof cell.label === "string" && cell.label.trim() !== "" ? cell.label.trim() : undefined) : undefined;
88
+ const drawing = isCell(cell) ? cell.drawing : cell;
89
+ if (typeof drawing === "string")
90
+ return { svg: drawing, label };
91
+ if (typeof drawing === "object" && drawing !== null && typeof drawing.draw === "function")
92
+ return { svg: drawing.draw(), label };
93
+ if (typeof drawing === "object" && drawing !== null) {
94
+ const options = drawing;
95
+ return { svg: drawKyogijo({ ...(o.language === undefined ? {} : { language: o.language }), ...(o.style === "none" ? { style: "none" } : {}), ...options }), label };
96
+ }
97
+ throw new TypeError("A cell of a grid is the options of drawKyogijo, an SVG string, a chart or { drawing, label }");
98
+ }
99
+ /** The ids a tree defines, and the tree with each of them (and every reference to it) behind `prefix`. */
100
+ function renamed(root, prefix) {
101
+ const ids = new Set();
102
+ const find = (node) => {
103
+ if (node.attrs.id !== undefined)
104
+ ids.add(node.attrs.id);
105
+ for (const child of elements(node))
106
+ find(child);
107
+ };
108
+ find(root);
109
+ const styles = [];
110
+ const reference = (value) => value.replace(/url\(#([^)\s"']+)\)/g, (whole, id) => (ids.has(id) ? `url(#${prefix}${id})` : whole));
111
+ const rule = (css) => css.replace(/#([A-Za-z_][\w-]*)/g, (whole, id) => (ids.has(id) ? `#${prefix}${id}` : whole));
112
+ const walk = (node) => {
113
+ for (const [key, value] of Object.entries(node.attrs)) {
114
+ if (key === "id")
115
+ node.attrs[key] = `${prefix}${value}`;
116
+ else if (key === "href" || key === "xlink:href")
117
+ node.attrs[key] = value.startsWith("#") && ids.has(value.slice(1)) ? `#${prefix}${value.slice(1)}` : value;
118
+ else if (key === "aria-labelledby" || key === "aria-describedby" || key === "aria-controls")
119
+ node.attrs[key] = value.split(/\s+/).map((id) => (ids.has(id) ? `${prefix}${id}` : id)).join(" ");
120
+ else if (value.includes("url(#"))
121
+ node.attrs[key] = reference(value);
122
+ }
123
+ node.children = node.children.filter((child) => {
124
+ if (typeof child !== "string" && child.name === "style") {
125
+ styles.push(rule(child.children.filter((c) => typeof c === "string").join("")));
126
+ return false;
127
+ }
128
+ return true;
129
+ });
130
+ for (const child of elements(node))
131
+ walk(child);
132
+ };
133
+ walk(root);
134
+ return { styles };
135
+ }
136
+ /** The rules the package writes into a drawing, in the order it writes them: peeled off the front of a style so that each is said once however many drawings carry it. */
137
+ const KNOWN = [KYOGIJO_BASE_STYLE, KYOGIJO_CURLING_STYLE, KYOGIJO_HEAT_STYLE, KYOGIJO_TEAM_STYLE, KYOGIJO_NOTE_STYLE, KYOGIJO_BACKGROUND_STYLE, KYOGIJO_MARK_STYLE, KYOGIJO_ROAD_STYLE];
138
+ /** A drawing's stylesheet as the pieces it is made of. */
139
+ function pieces(css) {
140
+ const out = [];
141
+ let rest = css.replace(/^\s+/, "");
142
+ for (let again = true; again && rest !== "";) {
143
+ again = false;
144
+ for (const known of KNOWN) {
145
+ if (rest.startsWith(known)) {
146
+ out.push(known);
147
+ rest = rest.slice(known.length).replace(/^\s+/, "");
148
+ again = true;
149
+ }
150
+ }
151
+ }
152
+ if (rest !== "")
153
+ out.push(rest);
154
+ return out;
155
+ }
156
+ function parse(svg, label, index, total, words) {
157
+ const root = parseSvg(svg);
158
+ if (root.name !== "svg")
159
+ throw new TypeError(`Cell ${index + 1} of the grid is not an SVG`);
160
+ const box = (root.attrs.viewBox ?? "").split(/[\s,]+/).map(Number);
161
+ const frame = box.length === 4 && box.every(Number.isFinite) ? { x: box[0], y: box[1], w: box[2], h: box[3] } : { x: 0, y: 0, w: Number(root.attrs.width), h: Number(root.attrs.height) };
162
+ if (!(frame.w > 0) || !(frame.h > 0))
163
+ throw new RangeError(`Cell ${index + 1} of the grid has no size: it needs a viewBox`);
164
+ const named = elements(root).find((child) => child.name === "title");
165
+ return { root, frame, title: label ?? (named === undefined ? fill(words.grid.cell, { n: index + 1, total }) : textOf(named).trim()), label };
166
+ }
167
+ /** One mark of the key at `(x, y)` with the size `r`, and the width it takes with its words. */
168
+ function legendItem(item, x, y, size) {
169
+ const color = safeColour(item.color);
170
+ const shape = item.shape !== undefined && (item.shape === "circle" || isPolygon(item.shape)) ? item.shape : "circle";
171
+ const attrs = { class: `ky-g-m${item.hollow === true ? " ky-g-h" : ""}`, style: color === undefined ? undefined : `--c:${color}` };
172
+ const r = size * 0.45;
173
+ const mark = shape === "circle" ? el("circle", { ...attrs, cx: num(x + r), cy: num(y), r: num(r) }) : el("path", { ...attrs, d: shapePath(shape, x + r, y, r * 2, false) });
174
+ return mark + el("text", { class: "ky-g-k", x: num(x + size * 1.3), y: num(y + size * 0.33), "font-size": num(size) }, esc(item.label));
175
+ }
176
+ /**
177
+ * Many drawings in one SVG, as small multiples: one per park, per period or per player, in columns, under a title and a subtitle and over a credit line, with a key they share.
178
+ * A cell is the options of `drawKyogijo`, a drawing's SVG, a chart, or `{ drawing, label }`. Every drawing keeps its own title and description for a screen reader, with ids
179
+ * of its own, so that the same drawing may appear twice; the group has a title and a description made from them. Each is drawn at the largest size its cell allows, the
180
+ * last row centred. `preset` fits a social card (`card`, 1200 by 675; `square`, 1080 by 1080) or a phone (`phone`, 390 wide in one column); without a size the grid is 960
181
+ * wide and as tall as the drawings need. The scene and every renderer read it like any other drawing. The same cells and options always give the same string.
182
+ * @example
183
+ * ```ts
184
+ * import { drawGrid } from "@johnmorrisdotca/kyogijo-stadiums/layouts";
185
+ * const svg = drawGrid(
186
+ * [{ drawing: { sport: "nhl" }, label: "Rink" }, { drawing: { sport: "nba" }, label: "Court" }],
187
+ * { columns: 2, title: "Two surfaces", endnote: "Drawn by Kyogijo" },
188
+ * );
189
+ * console.log(svg.startsWith("<svg"), svg.includes("Two surfaces"));
190
+ * // true true
191
+ * ```
192
+ */
193
+ export function drawGrid(cells, options = {}) {
194
+ if (!Array.isArray(cells) || cells.length === 0)
195
+ throw new TypeError("drawGrid needs a list of at least one drawing");
196
+ if (cells.length > GRID_MAX_CELLS)
197
+ throw new RangeError(`A grid holds at most ${GRID_MAX_CELLS} drawings`);
198
+ const o = options;
199
+ const language = o.language === "ja" ? "ja" : "en";
200
+ const words = KYOGIJO_STRINGS[language];
201
+ const preset = o.preset !== undefined && Object.prototype.hasOwnProperty.call(GRID_PRESETS, o.preset) ? GRID_PRESETS[o.preset] : undefined;
202
+ const theme = o.theme === "light" || o.theme === "dark" ? o.theme : undefined;
203
+ const drawn = cells.map((cell) => svgOf(cell, o));
204
+ const gid = safeClass(o.id).replace(/ /g, "-") || `kg-${hash(JSON.stringify([drawn.map((d) => [d.svg, d.label]), o, VERSION]))}`;
205
+ const parsed = drawn.map((d, i) => parse(d.svg, d.label, i, drawn.length, words));
206
+ const n = parsed.length;
207
+ // ---- The size, the type and the room round it. ----
208
+ const W = clamp(positive(o.width) ?? preset?.width ?? 960, 120, 8000);
209
+ const fixedHeight = positive(o.height) ?? preset?.height;
210
+ const ts = clamp(W * 0.036, 18, 48);
211
+ const ss = Math.max(11, ts * 0.55);
212
+ const ls = Math.max(10, ts * 0.44);
213
+ const ks = Math.max(10.5, ts * 0.42);
214
+ const es = Math.max(10, ts * 0.38);
215
+ const pad = clamp(W * 0.03, 14, 40);
216
+ const gap = clamp(positive(o.gap) ?? W * 0.0167, 0, 200);
217
+ const room = W - 2 * pad;
218
+ const title = typeof o.title === "string" && o.title.trim() !== "" ? o.title.trim() : undefined;
219
+ const subtitle = typeof o.subtitle === "string" && o.subtitle.trim() !== "" ? o.subtitle.trim() : undefined;
220
+ const endnote = typeof o.endnote === "string" && o.endnote.trim() !== "" ? o.endnote.trim() : undefined;
221
+ const titleLines = title === undefined ? [] : wrap(title, ts, room, 3);
222
+ const subLines = subtitle === undefined ? [] : wrap(subtitle, ss, room, 4);
223
+ const endLines = endnote === undefined ? [] : wrap(endnote, es, room, 3);
224
+ const headH = titleLines.length * ts * 1.18 + (subLines.length > 0 ? (titleLines.length > 0 ? ts * 0.2 : 0) + subLines.length * ss * 1.32 : 0);
225
+ const endH = endLines.length * es * 1.35;
226
+ const legend = (o.legend ?? []).filter((item) => typeof item?.label === "string" && item.label.trim() !== "").map((item) => ({ ...item, label: item.label.trim() }));
227
+ const legendRows = [];
228
+ let legendRowCount = 0;
229
+ if (legend.length > 0) {
230
+ let x = 0;
231
+ let row = 0;
232
+ for (const item of legend) {
233
+ const w = ks * 1.3 + textWidth(item.label) * ks + ks * 1.6;
234
+ if (x > 0 && x + w - ks * 1.6 > room) {
235
+ row += 1;
236
+ x = 0;
237
+ }
238
+ legendRows.push({ item, x, row });
239
+ x += w;
240
+ }
241
+ legendRowCount = row + 1;
242
+ }
243
+ const legendH = legendRowCount * ks * 1.75;
244
+ const labelled = parsed.some((p) => p.label !== undefined);
245
+ const labelH = labelled ? ls * 1.55 : 0;
246
+ // ---- The columns. ----
247
+ const top = pad + headH + (headH > 0 ? gap * 0.6 : 0) + legendH + (legendH > 0 ? gap * 0.4 : 0);
248
+ const foot = endH > 0 ? endH + gap * 0.6 : 0;
249
+ const asked = positive(o.columns) === undefined ? undefined : Math.min(n, Math.max(1, Math.floor(o.columns)));
250
+ const wanted = asked ?? preset?.columns;
251
+ const arrange = (cols) => {
252
+ const rows = Math.ceil(n / cols);
253
+ const cw = (room - gap * (cols - 1)) / cols;
254
+ const ch = fixedHeight === undefined ? undefined : Math.max(8, (fixedHeight - top - pad - foot - gap * (rows - 1)) / rows);
255
+ return { cw, ch, rows };
256
+ };
257
+ let columns;
258
+ if (wanted !== undefined)
259
+ columns = Math.min(n, Math.max(1, Math.floor(wanted)));
260
+ else if (fixedHeight === undefined)
261
+ columns = Math.max(1, Math.min(n, Math.floor((room + gap) / (280 + gap))));
262
+ else {
263
+ // The columns that make the drawings largest, taken together: the fewest on a tie.
264
+ let best = -1;
265
+ columns = 1;
266
+ for (let cols = 1; cols <= Math.min(n, 12); cols += 1) {
267
+ const { cw, ch } = arrange(cols);
268
+ const height = (ch ?? 0) - labelH;
269
+ if (!(cw > 0) || !(height > 0))
270
+ continue;
271
+ const area = parsed.reduce((sum, p) => sum + (p.frame.w * p.frame.h * Math.min(cw / p.frame.w, height / p.frame.h) ** 2), 0);
272
+ if (area > best * 1.0001) {
273
+ best = area;
274
+ columns = cols;
275
+ }
276
+ }
277
+ }
278
+ const { cw, ch, rows } = arrange(columns);
279
+ // ---- The rows and the height. ----
280
+ const rowHeights = [];
281
+ for (let r = 0; r < rows; r += 1) {
282
+ const inRow = parsed.slice(r * columns, (r + 1) * columns);
283
+ rowHeights.push(ch !== undefined ? ch : Math.max(...inRow.map((p) => (cw * p.frame.h) / p.frame.w)) + labelH);
284
+ }
285
+ const H = fixedHeight ?? top + rowHeights.reduce((a, b) => a + b, 0) + gap * (rows - 1) + foot + pad;
286
+ const cellsEnd = H - pad - foot;
287
+ // ---- The drawings, each in its cell. ----
288
+ const sheets = new Set();
289
+ const sheetList = [];
290
+ const addSheet = (css) => {
291
+ for (const piece of pieces(css)) {
292
+ if (piece.trim() !== "" && !sheets.has(piece)) {
293
+ sheets.add(piece);
294
+ sheetList.push(piece);
295
+ }
296
+ }
297
+ };
298
+ let cellDefs = "";
299
+ let cellMarkup = "";
300
+ parsed.forEach((p, i) => {
301
+ const prefix = `${gid}-${i}-`;
302
+ const { styles } = renamed(p.root, prefix);
303
+ for (const css of styles)
304
+ addSheet(css);
305
+ const r = Math.floor(i / columns);
306
+ const c = i % columns;
307
+ const inRow = Math.min(columns, n - r * columns);
308
+ const rowWidth = inRow * cw + gap * (inRow - 1);
309
+ const x0 = pad + (room - rowWidth) / 2 + c * (cw + gap);
310
+ const y0 = top + rowHeights.slice(0, r).reduce((a, b) => a + b, 0) + gap * r;
311
+ const boxH = rowHeights[r] - labelH;
312
+ const scale = Math.min(cw / p.frame.w, boxH / p.frame.h);
313
+ const w = p.frame.w * scale;
314
+ const h = p.frame.h * scale;
315
+ // The caption and its drawing are one block, in the middle of the cell.
316
+ const off = (rowHeights[r] - labelH - h) / 2;
317
+ const tx = x0 + (cw - w) / 2 - p.frame.x * scale;
318
+ const ty = y0 + off + labelH - p.frame.y * scale;
319
+ const clip = `${prefix}clip`;
320
+ cellDefs += el("clipPath", { id: clip }, el("rect", { x: num(p.frame.x), y: num(p.frame.y), width: num(p.frame.w), height: num(p.frame.h) }));
321
+ const attrs = {};
322
+ for (const [key, value] of Object.entries(p.root.attrs))
323
+ if (key !== "xmlns" && key !== "viewBox" && key !== "width" && key !== "height")
324
+ attrs[key] = value;
325
+ if (theme !== undefined && attrs["data-theme"] === undefined)
326
+ attrs["data-theme"] = theme;
327
+ attrs.transform = `translate(${num(tx)} ${num(ty)}) scale(${fixed(scale)})`;
328
+ attrs["clip-path"] = `url(#${clip})`;
329
+ const group = writeSvg({ name: "g", attrs, children: p.root.children, empty: false });
330
+ let text = "";
331
+ if (p.label !== undefined) {
332
+ const fitted = caption(p.label, ls, cw);
333
+ text = el("text", { class: "ky-g-c", x: num(x0 + cw / 2), y: num(y0 + off + ls * 1.1), "font-size": num(fitted.size), "text-anchor": "middle" }, esc(fitted.text));
334
+ }
335
+ cellMarkup += el("g", { class: "ky-g-cell", "data-cell": i + 1 }, text + group);
336
+ });
337
+ // ---- The words round them. ----
338
+ let head = "";
339
+ let y = pad;
340
+ titleLines.forEach((line, i) => {
341
+ head += el("text", { class: "ky-g-t", x: num(pad), y: num(y + ts * 0.9 + i * ts * 1.18), "font-size": num(ts) }, esc(line));
342
+ });
343
+ y += titleLines.length * ts * 1.18 + (subLines.length > 0 && titleLines.length > 0 ? ts * 0.2 : 0);
344
+ subLines.forEach((line, i) => {
345
+ head += el("text", { class: "ky-g-s", x: num(pad), y: num(y + ss * 0.95 + i * ss * 1.32), "font-size": num(ss) }, esc(line));
346
+ });
347
+ const legendTop = pad + headH + (headH > 0 ? gap * 0.6 : 0);
348
+ const key = legendRows.length === 0 ? "" : el("g", { class: "ky-g-legend" }, legendRows.map(({ item, x, row }) => legendItem(item, pad + x, legendTop + ks * 0.95 + row * ks * 1.75, ks)).join(""));
349
+ const tail = endLines.map((line, i) => el("text", { class: "ky-g-e", x: num(pad), y: num(cellsEnd + gap * 0.6 + es * 1.0 + i * es * 1.35), "font-size": num(es) }, esc(line))).join("");
350
+ // ---- The ground, the style and the group's title and description. ----
351
+ const ground = o.background === undefined ? (preset?.ground === true ? { color: "var(--ky-grid-bg)" } : undefined) : o.background === "none" ? undefined : typeof o.background === "string" ? { pattern: o.background, color: "var(--ky-grid-bg)" } : { color: "var(--ky-grid-bg)", ...o.background };
352
+ const grounded = backgroundMarkup(ground, { x: 0, y: 0, w: W, h: H }, gid);
353
+ const hasGround = resolveBackground(ground) !== undefined;
354
+ const sheet = o.style === "none" ? "" : [KYOGIJO_BASE_STYLE, ...sheetList.filter((css) => css !== KYOGIJO_BASE_STYLE), KYOGIJO_GRID_STYLE, ...(hasGround && !sheets.has(KYOGIJO_BACKGROUND_STYLE) ? [KYOGIJO_BACKGROUND_STYLE] : [])].join("\n");
355
+ const sentence = (text) => (/[.!?。!?…]$/.test(text) ? text : `${text}${words.said.stop}`);
356
+ const heading = (o.label !== undefined && o.label.trim() !== "" ? o.label.trim() : undefined) ?? title ?? fill(words.grid.title, { n });
357
+ const names = parsed.map((p) => p.title);
358
+ const description = o.description ??
359
+ [subtitle === undefined ? undefined : sentence(subtitle), fill(words.grid.drawings, { n, list: names.join(words.grid.listSep) }), legend.length === 0 ? undefined : fill(words.grid.key, { list: legend.map((item) => item.label).join(words.grid.listSep) }), endnote === undefined ? undefined : sentence(endnote)]
360
+ .filter((part) => part !== undefined)
361
+ .join(words.said.gap);
362
+ return el("svg", {
363
+ xmlns: "http://www.w3.org/2000/svg",
364
+ class: `kyogijo kyogijo-grid${safeClass(o.className) === "" ? "" : ` ${safeClass(o.className)}`}`,
365
+ viewBox: `0 0 ${num(W)} ${num(H)}`,
366
+ role: "group",
367
+ "aria-labelledby": `${gid}-t ${gid}-d`,
368
+ "data-grid": n,
369
+ "data-columns": columns,
370
+ "data-preset": o.preset !== undefined && preset !== undefined ? o.preset : undefined,
371
+ "data-theme": theme,
372
+ "data-version": VERSION,
373
+ }, `<title id="${gid}-t">${esc(heading)}</title><desc id="${gid}-d">${esc(description)}</desc>` +
374
+ (sheet === "" ? "" : `<style>${sheet}</style>`) +
375
+ `<defs>${grounded.defs}${cellDefs}</defs>` +
376
+ grounded.shapes +
377
+ head +
378
+ key +
379
+ cellMarkup +
380
+ tail);
381
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The rules of a grid of drawings (`drawGrid`): the ground colour and the quiet ink of the subtitle and the credit line in light and dark, and the classes of the
3
+ * title, the subtitle, a cell's label, the key and the credit line. A grid is a `.kyogijo` as well, so the base rules give it the ink, the font and the colours of the
4
+ * layers; `KYOGIJO_STYLE` has these for a page that draws with `style: "none"`.
5
+ */
6
+ export declare const KYOGIJO_GRID_STYLE: string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The rules of a grid of drawings (`drawGrid`): the ground colour and the quiet ink of the subtitle and the credit line in light and dark, and the classes of the
3
+ * title, the subtitle, a cell's label, the key and the credit line. A grid is a `.kyogijo` as well, so the base rules give it the ink, the font and the colours of the
4
+ * layers; `KYOGIJO_STYLE` has these for a page that draws with `style: "none"`.
5
+ */
6
+ export const KYOGIJO_GRID_STYLE = `
7
+ :where(.kyogijo-grid){--ky-grid-bg:#f6f4ee;--ky-grid-muted:#566059}
8
+ @media (prefers-color-scheme:dark){:where(html:not([data-theme=light]) .kyogijo-grid:not([data-theme=light])){--ky-grid-bg:#131716;--ky-grid-muted:#a9b2ac}}
9
+ :where(html[data-theme=dark] .kyogijo-grid,.kyogijo-grid[data-theme=dark]){--ky-grid-bg:#131716;--ky-grid-muted:#a9b2ac}
10
+ .kyogijo-grid .ky-g-t,.kyogijo-grid .ky-g-s,.kyogijo-grid .ky-g-c,.kyogijo-grid .ky-g-k,.kyogijo-grid .ky-g-e{font-family:var(--ky-font)}
11
+ .kyogijo-grid .ky-g-t{fill:var(--ky-ink);font-weight:800}
12
+ .kyogijo-grid .ky-g-s{fill:var(--ky-grid-muted);font-weight:600}
13
+ .kyogijo-grid .ky-g-c{fill:var(--ky-ink);font-weight:700;text-anchor:middle}
14
+ .kyogijo-grid .ky-g-k{fill:var(--ky-ink);font-weight:600}
15
+ .kyogijo-grid .ky-g-e{fill:var(--ky-grid-muted);font-weight:500}
16
+ .kyogijo-grid .ky-g-m{fill:var(--c,var(--ky-layer));stroke:var(--ky-layer-edge);stroke-width:.6;stroke-linejoin:round}
17
+ .kyogijo-grid .ky-g-m.ky-g-h{fill:var(--ky-layer-hollow);stroke:var(--c,var(--ky-layer));stroke-width:1.6}`.trim();
@@ -0,0 +1,5 @@
1
+ export { GRID_MAX_CELLS, GRID_PRESETS, drawGrid } from "./layout.ts";
2
+ export type { GridCell, GridDrawing, GridLegendItem, GridOptions, GridPreset, GridPresetInfo } from "./layout.ts";
3
+ export { KYOGIJO_GRID_STYLE } from "./layout.style.ts";
4
+ export { BACKGROUND_OPACITY, BACKGROUND_PATTERNS, KYOGIJO_BACKGROUND_STYLE, backgroundMarkup, laidOn, resolveBackground } from "./background.ts";
5
+ export type { Background, BackgroundFit, BackgroundMarkup, BackgroundOptions, BackgroundPattern } from "./background.ts";
@@ -0,0 +1,4 @@
1
+ // Layouts: many drawings in one SVG (small multiples with a shared title, subtitle, credit line and key, in a size for a social card or a phone) and the grounds behind a drawing or a grid.
2
+ export { GRID_MAX_CELLS, GRID_PRESETS, drawGrid } from "./layout.js";
3
+ export { KYOGIJO_GRID_STYLE } from "./layout.style.js";
4
+ export { BACKGROUND_OPACITY, BACKGROUND_PATTERNS, KYOGIJO_BACKGROUND_STYLE, backgroundMarkup, laidOn, resolveBackground } from "./background.js";
@@ -0,0 +1,57 @@
1
+ import type { Unit } from "../units.ts";
2
+ import { type Span } from "./fields.ts";
3
+ import { type LeagueBase } from "./types.ts";
4
+ /** The figures of the ground, in the unit of the table they are in. */
5
+ export interface AflFigures {
6
+ /** The Playing Surface's length (goal line to goal line) and width, as the Laws allow; the size drawn is the MCG's. */
7
+ length: Span;
8
+ width: Span;
9
+ /** The goal posts' distance apart, and the behind posts' distance from each goal post on either side. */
10
+ goalPosts: number;
11
+ behindPosts: number;
12
+ /** The goal square: the depth of the two lines drawn at right angles to the goal line from each goal post. */
13
+ goalSquareDepth: number;
14
+ /** The centre square's side, the centre circle's diameter and the Ten Metre Circle's. */
15
+ centreSquare: number;
16
+ centreCircle: number;
17
+ tenMetreCircle: number;
18
+ /** The Fifty Metre Arc: its radius, from the middle of the goal line. */
19
+ fiftyArc: number;
20
+ /** The width the lines are drawn at: the Laws print none. */
21
+ lineWidth: number;
22
+ }
23
+ /** The ground as the drawing wants it: the figures with every length in feet. */
24
+ export type AflSpec = AflFigures;
25
+ /** The ground's figures in feet, from the unit the Laws give them in. */
26
+ export declare const aflInFeet: (figures: AflFigures, unit: Unit) => AflSpec;
27
+ /** The league with the Laws' ground. */
28
+ export type AflLeague = LeagueBase<"afl", AflFigures>;
29
+ /**
30
+ * Law 3 of the Laws of Australian Football 2026: oval, 135 to 185 m long and 110 to 155 m wide; goal posts 6.4 m apart and behind posts 6.4 m on each side of them, in a line (3.3.1); the goal
31
+ * square 9 m deep from each goal post (3.4); the centre square 50 by 50 m, the Centre Circle 3 m across and the Ten Metre Circle 10 m (3.5); a Fifty Metre Arc at each end, 50 m from the middle of
32
+ * the goal line (the definition, and Diagram 1). The length is measured as the Playing Surface is defined, inside the Boundary Line, Goal Line and Behind Line, so from goal line to goal line. The size
33
+ * drawn is the MCG's (160 by 141 m, its venue page). The Laws print no line width: 0.1 m is drawn.
34
+ */
35
+ export declare const AFL_GROUND: AflFigures;
36
+ /** The AFL league: the Laws' ground. */
37
+ export declare const AFL_LEAGUES: readonly AflLeague[];
38
+ /** A ground the AFL publishes the size of. */
39
+ export interface AflGround {
40
+ id: string;
41
+ name: {
42
+ en: string;
43
+ ja: string;
44
+ };
45
+ /** Metres, as the venue's page prints them: length by width. */
46
+ length: number;
47
+ width: number;
48
+ /** The page it was read on (a key of `LEAGUE_SOURCES`). */
49
+ source: string;
50
+ /** What else is published, when it disagrees. */
51
+ note?: string;
52
+ }
53
+ /**
54
+ * The grounds whose length and width the AFL's venue pages print (read 2026-10-13), each within the Laws' range. The AFL's page for Adelaide Oval prints 190 by 125 m, a length beyond
55
+ * the 185 m the Laws allow, so that ground is not here.
56
+ */
57
+ export declare const AFL_GROUNDS: readonly AflGround[];
@@ -0,0 +1,36 @@
1
+ import { span } from "./fields.js";
2
+ import { inFeet } from "./types.js";
3
+ /** The ground's figures in feet, from the unit the Laws give them in. */
4
+ export const aflInFeet = (figures, unit) => inFeet(figures, unit);
5
+ /**
6
+ * Law 3 of the Laws of Australian Football 2026: oval, 135 to 185 m long and 110 to 155 m wide; goal posts 6.4 m apart and behind posts 6.4 m on each side of them, in a line (3.3.1); the goal
7
+ * square 9 m deep from each goal post (3.4); the centre square 50 by 50 m, the Centre Circle 3 m across and the Ten Metre Circle 10 m (3.5); a Fifty Metre Arc at each end, 50 m from the middle of
8
+ * the goal line (the definition, and Diagram 1). The length is measured as the Playing Surface is defined, inside the Boundary Line, Goal Line and Behind Line, so from goal line to goal line. The size
9
+ * drawn is the MCG's (160 by 141 m, its venue page). The Laws print no line width: 0.1 m is drawn.
10
+ */
11
+ export const AFL_GROUND = {
12
+ length: span(135, 185, 160),
13
+ width: span(110, 155, 141),
14
+ goalPosts: 6.4,
15
+ behindPosts: 6.4,
16
+ goalSquareDepth: 9,
17
+ centreSquare: 50,
18
+ centreCircle: 3,
19
+ tenMetreCircle: 10,
20
+ fiftyArc: 50,
21
+ lineWidth: 0.1,
22
+ };
23
+ /** The AFL league: the Laws' ground. */
24
+ export const AFL_LEAGUES = [{ id: "afl", family: "afl", name: { en: "Australian football ground (AFL)", ja: "オーストラリアンフットボールのグラウンド(AFL)" }, unit: "m", dimensions: AFL_GROUND, sources: ["afl-laws"], builtIn: true }];
25
+ /**
26
+ * The grounds whose length and width the AFL's venue pages print (read 2026-10-13), each within the Laws' range. The AFL's page for Adelaide Oval prints 190 by 125 m, a length beyond
27
+ * the 185 m the Laws allow, so that ground is not here.
28
+ */
29
+ export const AFL_GROUNDS = [
30
+ { id: "mcg", name: { en: "Melbourne Cricket Ground", ja: "メルボルン・クリケット・グラウンド" }, length: 160, width: 141, source: "afl-venue-mcg", note: "an AFL article of 2018 printed 161 by 138 m" },
31
+ { id: "optus-stadium", name: { en: "Optus Stadium", ja: "オプタス・スタジアム" }, length: 165, width: 130, source: "afl-venue-optus", note: "the stadium's own page says this is boundary line to boundary line" },
32
+ { id: "gabba", name: { en: "The Gabba", ja: "ガバ" }, length: 156, width: 138, source: "afl-venue-gabba" },
33
+ { id: "scg", name: { en: "Sydney Cricket Ground", ja: "シドニー・クリケット・グラウンド" }, length: 149, width: 136, source: "afl-venue-scg", note: "an AFL article of 2018 printed 155 by 136 m" },
34
+ { id: "marvel-stadium", name: { en: "Marvel Stadium", ja: "マーベル・スタジアム" }, length: 159.5, width: 128.8, source: "afl-venue-marvel" },
35
+ { id: "gmhba-stadium", name: { en: "GMHBA Stadium", ja: "GMHBAスタジアム" }, length: 170, width: 114, source: "afl-venue-gmhba", note: "an AFL article of 2018 printed 170 by 116 m" },
36
+ ];
@@ -0,0 +1,58 @@
1
+ import { type FencePoint } from "../geometry.ts";
2
+ import type { Fence } from "../types.ts";
3
+ import type { Unit } from "../units.ts";
4
+ import { type LeagueBase } from "./types.ts";
5
+ /** The figures of a diamond. Lengths, in the unit of the table they are in. */
6
+ export interface DiamondFigures {
7
+ /** The distance between bases (the side of the square). */
8
+ base: number;
9
+ /** The side of a base. */
10
+ baseSize: number;
11
+ /** The front of the pitcher's plate, from the back point of home plate. */
12
+ pitcher: number;
13
+ /** The pitcher's plate: how long (across) and how deep. */
14
+ pitchersPlate: {
15
+ width: number;
16
+ depth: number;
17
+ };
18
+ /** The mound's radius, or a softball pitcher's circle's. */
19
+ moundRadius: number;
20
+ /** The middle of the mound or the circle, from the back point of home plate. */
21
+ moundCentre: number;
22
+ /** The dirt of the infield is cut by an arc of this radius round the pitcher's plate, or the rules give none. */
23
+ skinRadius: number | null;
24
+ /** Home plate: its width, and the length of its two parallel sides. */
25
+ plate: {
26
+ width: number;
27
+ side: number;
28
+ };
29
+ /** The batter's boxes, or none given. */
30
+ boxes: {
31
+ batterWidth: number;
32
+ batterLength: number;
33
+ gap: number;
34
+ } | null;
35
+ /** The three-foot lane for the batter-runner: where it begins on the line to first, and how wide; or none given. */
36
+ runningLane: {
37
+ from: number;
38
+ width: number;
39
+ } | null;
40
+ /** The least distance from home plate to the backstop. */
41
+ backstop: number;
42
+ /** The fence, at the places the rules give a distance for: what they recommend or require (the least of a range). */
43
+ fence: Partial<Fence>;
44
+ }
45
+ /** A diamond as the drawing wants it: the figures with every length in feet. */
46
+ export type DiamondSpec = DiamondFigures;
47
+ /** A diamond's figures in feet, from the unit its rulebook gives them in. */
48
+ export declare const diamondInFeet: (figures: DiamondFigures, unit: Unit) => DiamondSpec;
49
+ /** The baseball field of the Official Baseball Rules, from `MLB` (geometry.ts). */
50
+ export declare const MLB_DIAMOND: DiamondFigures;
51
+ /** A diamond's default fence as points: through the distances the rules give, and no others. */
52
+ export declare function diamondFence(diamond: DiamondSpec): FencePoint[];
53
+ /** A league with a diamond of its own. */
54
+ export type BaseballLeague = LeagueBase<"baseball", DiamondFigures> & {
55
+ game: "baseball" | "softball";
56
+ };
57
+ /** The baseball and softball leagues, MLB first. */
58
+ export declare const BASEBALL_LEAGUES: readonly BaseballLeague[];