@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
@@ -0,0 +1,204 @@
1
+ // A special game: one surface set inside another, to scale (a hockey rink in a ballpark, a basketball court on a ship's deck). The host is drawn as it
2
+ // is drawn alone; the guest, which is the drawing's own surface, is put on it through one transform, so that the lines, the team banners, the score and
3
+ // the data layers are the guest's, in its own frame. Nothing here is a second way of drawing a rink or a field.
4
+ import { convertLength } from "./units.js";
5
+ import { num, el } from "./format.js";
6
+ import { MLB } from "./geometry.js";
7
+ import { groundById } from "./grounds.js";
8
+ import { lengthUnit } from "./common.js";
9
+ import { lineLook, restyleLines } from "./restyle.js";
10
+ import { outlineOf } from "./outline.js";
11
+ /** The host as options for a surface of its own: the options `outlineOf` and the drawing take. */
12
+ export function hostSurfaceOptions(host, o) {
13
+ const year = host.year ?? o.year;
14
+ const common = { detail: o.detail, stripes: o.stripes, stripePattern: o.stripePattern, exactLines: o.exactLines, year };
15
+ if (host.park !== undefined)
16
+ return { ...common, sport: "mlb", park: host.park };
17
+ if (host.ground !== undefined || host.pitch !== undefined) {
18
+ const ground = groundById(host.ground);
19
+ const pitch = host.pitch ?? (ground === undefined || ground.pitchSize === "default" ? undefined : { ...ground.pitch, unit: "m" });
20
+ return { ...common, sport: "soccer", ground: host.ground, pitch };
21
+ }
22
+ if (host.field !== undefined)
23
+ return { ...common, sport: host.field, league: host.league };
24
+ return undefined;
25
+ }
26
+ /** The host's outline in its frame, in feet. */
27
+ export function hostOutline(host, o) {
28
+ if (host.deck !== undefined) {
29
+ const unit = host.deck.unit ?? "ft";
30
+ const w = convertLength(host.deck.length, unit, "ft");
31
+ const h = convertLength(host.deck.width, unit, "ft");
32
+ const box = { x: 0, y: 0, w, h };
33
+ return { d: `M0 0H${num(w)}V${num(h)}H0Z`, box, contains: (x, y) => x >= 0 && x <= w && y >= 0 && y <= h };
34
+ }
35
+ const options = hostSurfaceOptions(host, o);
36
+ if (options === undefined)
37
+ throw new Error("A host needs one of park, ground, pitch, field or deck");
38
+ return outlineOf(options);
39
+ }
40
+ /** The sport of the host as the drawing's palette knows it. */
41
+ export function hostSport(host) {
42
+ if (host.park !== undefined)
43
+ return "mlb";
44
+ if (host.ground !== undefined || host.pitch !== undefined)
45
+ return "soccer";
46
+ if (host.field !== undefined)
47
+ return host.field;
48
+ return "deck";
49
+ }
50
+ /** A ballpark's infield is a square 90 feet on a side: its middle is where the line from first base to third crosses the line from home plate to second. */
51
+ export const INFIELD_CENTRE = Math.round((MLB.base * Math.SQRT2 * 100) / 2) / 100;
52
+ /** The point of the guest that is put at the placement's `x` and `y`: the middle of the playing surface, and for a ballpark home plate. */
53
+ export function guestAnchor(o) {
54
+ const outline = outlineOf(o);
55
+ if (o.sport === "mlb")
56
+ return { x: 0, y: 0 };
57
+ return { x: outline.box.x + outline.box.w / 2, y: outline.box.y + outline.box.h / 2 };
58
+ }
59
+ /**
60
+ * Where the guest stands when the options do not say: the middle of the host's field, with the guest as it lies; the middle of a ballpark's infield; for a
61
+ * ballpark set inside another surface, its infield's middle on the middle of the host.
62
+ */
63
+ export function defaultPlacement(o) {
64
+ const host = o.host;
65
+ const box = hostOutline(host, o).box;
66
+ const cx = box.x + box.w / 2;
67
+ const cy = box.y + box.h / 2;
68
+ if (o.sport === "mlb")
69
+ return { x: cx, y: cy + INFIELD_CENTRE, angle: 0 };
70
+ if (host.park !== undefined)
71
+ return { x: 0, y: -INFIELD_CENTRE, angle: 0 };
72
+ return { x: cx, y: cy, angle: 0 };
73
+ }
74
+ const finite = (n) => typeof n === "number" && Number.isFinite(n);
75
+ /** The placement the options ask for, with a part it leaves out filled from the default. */
76
+ export function placementOf(o) {
77
+ const base = defaultPlacement(o);
78
+ const p = o.placement;
79
+ if (p === undefined)
80
+ return base;
81
+ return { x: finite(p.x) ? p.x : base.x, y: finite(p.y) ? p.y : base.y, angle: finite(p.angle) ? p.angle : base.angle };
82
+ }
83
+ /** The point of the guest's own frame at the host's, for a placement. */
84
+ export function guestToHost(o, p) {
85
+ const a = guestAnchor(o);
86
+ const t = (p.angle * Math.PI) / 180;
87
+ const cos = Math.cos(t);
88
+ const sin = Math.sin(t);
89
+ return (x, y) => {
90
+ const dx = x - a.x;
91
+ const dy = y - a.y;
92
+ return [p.x + dx * cos - dy * sin, p.y + dx * sin + dy * cos];
93
+ };
94
+ }
95
+ /** The transform that does the same, as SVG writes it. */
96
+ export function guestTransform(o, p) {
97
+ const a = guestAnchor(o);
98
+ return `translate(${num(p.x)} ${num(p.y)})${p.angle === 0 ? "" : ` rotate(${num(p.angle)})`}${a.x === 0 && a.y === 0 ? "" : ` translate(${num(-a.x)} ${num(-a.y)})`}`;
99
+ }
100
+ /**
101
+ * How the guest sits in its host, worked out on a grid over the guest's outline (a rink's rounded corners and a fence's curve are the guest's own).
102
+ * For a ballpark the host's outline is the fair ground inside the fence: a rink across the infield reaches into foul ground, which this reports as outside.
103
+ */
104
+ export function fitOf(o) {
105
+ const host = o.host;
106
+ const hostBox = hostOutline(host, o);
107
+ const guest = outlineOf(o);
108
+ const to = guestToHost(o, placementOf(o));
109
+ const steps = 60;
110
+ let all = 0;
111
+ let out = 0;
112
+ for (let i = 0; i < steps; i += 1) {
113
+ for (let j = 0; j < steps; j += 1) {
114
+ const gx = guest.box.x + ((i + 0.5) / steps) * guest.box.w;
115
+ const gy = guest.box.y + ((j + 0.5) / steps) * guest.box.h;
116
+ if (!guest.contains(gx, gy))
117
+ continue;
118
+ all += 1;
119
+ const [hx, hy] = to(gx, gy);
120
+ if (!hostBox.contains(hx, hy))
121
+ out += 1;
122
+ }
123
+ }
124
+ return { inside: out === 0, outside: all === 0 ? 0 : Math.round((out / all) * 1000) / 1000 };
125
+ }
126
+ /** The leading ground rectangle of a surface's markup (the apron, or a ballpark's foul ground): a guest has none, as it is on the host's ground. */
127
+ const GROUND = /^<rect class="ky-(?:apron|foul)(?: [^"]*)?"[^>]*\/>/;
128
+ /** Turn a text's angle upright: the least turn that leaves words readable, between -90 and 90 degrees. */
129
+ const upright = (angle) => {
130
+ let a = ((((angle + 90) % 180) + 180) % 180) - 90;
131
+ if (Object.is(a, -0))
132
+ a = 0;
133
+ return a === -90 ? 90 : a;
134
+ };
135
+ const moved = (zone, to, angle) => {
136
+ const [cx, cy] = to(zone.cx, zone.cy);
137
+ return { ...zone, cx, cy, rot: upright(zone.rot + angle) };
138
+ };
139
+ /** The corners of a box, moved by `to`. */
140
+ function corners(box, to) {
141
+ return [
142
+ to(box.x, box.y),
143
+ to(box.x + box.w, box.y),
144
+ to(box.x + box.w, box.y + box.h),
145
+ to(box.x, box.y + box.h),
146
+ ];
147
+ }
148
+ /**
149
+ * The host and the guest as one surface. `guest` is the drawing's own surface, built wide with no margin; `build` draws the host as a surface of its own.
150
+ * The result has the host's frame, the guest's team places and score moved onto the guest, and `frame`, the transform the guest's data goes through.
151
+ */
152
+ export function composeSpecial(o, guest, build, id) {
153
+ const host = o.host;
154
+ const placement = placementOf(o);
155
+ const to = guestToHost(o, placement);
156
+ const frame = guestTransform(o, placement);
157
+ const hostSurface = hostSurfaceOptions(host, o);
158
+ const outline = hostOutline(host, o);
159
+ const guestBox = outlineOf(o).box;
160
+ const margin = typeof o.margin === "number" && Number.isFinite(o.margin) && o.margin >= 0 ? convertLength(o.margin, lengthUnit(o), "ft") : 8;
161
+ let base;
162
+ let defs = guest.defs;
163
+ let view;
164
+ const sport = hostSport(host);
165
+ if (hostSurface === undefined) {
166
+ // A plain rectangle, such as the deck of a ship.
167
+ const b = outline.box;
168
+ view = { x: b.x - margin, y: b.y - margin, w: b.w + 2 * margin, h: b.h + 2 * margin };
169
+ base = el("g", { class: "ky-host", "data-sport": sport }, el("rect", { class: "ky-deck", x: b.x, y: b.y, width: b.w, height: b.h }));
170
+ }
171
+ else {
172
+ const surface = build(hostSurface, `${id}-host`);
173
+ view = { ...surface.view };
174
+ base = el("g", { class: "ky-host", "data-sport": sport }, surface.base + surface.lines);
175
+ defs = surface.defs + defs;
176
+ }
177
+ // The view holds the host and the guest with a margin round it, wherever the guest hangs over.
178
+ const points = corners({ x: guestBox.x - margin, y: guestBox.y - margin, w: guestBox.w + 2 * margin, h: guestBox.h + 2 * margin }, to);
179
+ const x0 = Math.min(view.x, ...points.map(([x]) => x));
180
+ const y0 = Math.min(view.y, ...points.map(([, y]) => y));
181
+ const x1 = Math.max(view.x + view.w, ...points.map(([x]) => x));
182
+ const y1 = Math.max(view.y + view.h, ...points.map(([, y]) => y));
183
+ view = { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };
184
+ const unit = lengthUnit(o);
185
+ const look = lineLook(o, guest.lineRef, unit);
186
+ const guestLines = look === undefined ? guest.lines : restyleLines(guest.lines, look);
187
+ const apron = el("rect", { class: "ky-apron", x: view.x, y: view.y, width: view.w, height: view.h });
188
+ const own = el("g", { class: "ky-guest", transform: frame }, guest.base.replace(GROUND, ""));
189
+ const [px, py] = to(guest.plate.cx, guest.plate.cy);
190
+ return {
191
+ sport: guest.sport,
192
+ view,
193
+ base: apron + base + own,
194
+ lines: el("g", { class: "ky-guest-lines", transform: frame }, guestLines),
195
+ defs,
196
+ left: moved(guest.left, to, placement.angle),
197
+ right: moved(guest.right, to, placement.angle),
198
+ plate: { ...guest.plate, cx: px, cy: py },
199
+ turned: false,
200
+ bannersOver: guest.bannersOver,
201
+ box: outline.box,
202
+ frame,
203
+ };
204
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The rules of a special game: the host keeps the colours of its own sport (a ballpark's grass under a rink's ice) inside the drawing, which has those of
3
+ * the guest, and the deck of a ship its steel. The guest needs none: the drawing is of its sport. A drawing that has a host writes in the rules of its host's
4
+ * sport (`specialStyle`), and `KYOGIJO_STYLE` has the rules of every host.
5
+ */
6
+ export declare function specialStyle(only?: string): string;
7
+ /** The rules of every host's sport. */
8
+ export declare const KYOGIJO_SPECIAL_STYLE: string;
@@ -0,0 +1,36 @@
1
+ // The rules of a special game's host, kept apart like the courts' so that style.ts can hold them without importing the code that draws one.
2
+ /** The colours of the host's surface, by the sport it is for: what a rule in the stylesheet gives the host's group. */
3
+ const PALETTES = {
4
+ default: { light: "--ky-surface:#3f8f55;--ky-surface-alt:#3a864f;--ky-apron:#dcd8c9;--ky-boards:#c8c1b0", dark: "--ky-surface:#2c6a3f;--ky-surface-alt:#296239;--ky-apron:#1b1f1c;--ky-boards:#4d5450" },
5
+ nhl: { light: "--ky-surface:#eef5fa;--ky-surface-alt:#3a864f;--ky-apron:#d3dbe1;--ky-boards:#9aa4ab", dark: "--ky-surface:#a9bccb;--ky-surface-alt:#296239;--ky-apron:#1a2025;--ky-boards:#4b5156" },
6
+ nba: { light: "--ky-surface:#d9a766;--ky-surface-alt:#cf9c5b;--ky-apron:#c9c3b4;--ky-boards:#a97d46", dark: "--ky-surface:#8f6a3c;--ky-surface-alt:#876234;--ky-apron:#1a1c1b;--ky-boards:#5e4426" },
7
+ mlb: { light: "--ky-surface:#4f9a55;--ky-surface-alt:#478f4e;--ky-apron:#bdb59f;--ky-boards:#2f4a36", dark: "--ky-surface:#2f6b3a;--ky-surface-alt:#2b6336;--ky-apron:#1b1f1c;--ky-boards:#1c2b20" },
8
+ soccer: { light: "--ky-surface:#4c9b56;--ky-surface-alt:#438f4d;--ky-apron:#c9d2bd;--ky-boards:#c8c1b0;--ky-court:#3b79ad", dark: "--ky-surface:#2d6c3e;--ky-surface-alt:#276136;--ky-apron:#1b1f1c;--ky-boards:#4d5450;--ky-court:#2a5478" },
9
+ };
10
+ /** The ends of a football host are not the guest's teams': they keep the colours they have without any. */
11
+ const NOT_TEAMS = "--ky-left:#2f6db0;--ky-right:#b5452c;--ky-left-ink:#fff;--ky-right-ink:#fff";
12
+ /** The host's sports and the palette each takes. */
13
+ const HOST_PALETTE = { nfl: "default", cfl: "default", ifaf: "default", deck: "default", mlb: "mlb", soccer: "soccer", nhl: "nhl", nba: "nba" };
14
+ /**
15
+ * The rules of a special game: the host keeps the colours of its own sport (a ballpark's grass under a rink's ice) inside the drawing, which has those of
16
+ * the guest, and the deck of a ship its steel. The guest needs none: the drawing is of its sport. A drawing that has a host writes in the rules of its host's
17
+ * sport (`specialStyle`), and `KYOGIJO_STYLE` has the rules of every host.
18
+ */
19
+ export function specialStyle(only) {
20
+ const rules = [":where(.kyogijo){--ky-deck:#8d979e}", "@media (prefers-color-scheme:dark){:where(html:not([data-theme=light]) .kyogijo:not([data-theme=light])){--ky-deck:#4f585e}}", ":where(html[data-theme=dark] .kyogijo,.kyogijo[data-theme=dark]){--ky-deck:#4f585e}", ".kyogijo .ky-deck{fill:var(--ky-deck)}"];
21
+ const light = [];
22
+ const auto = [];
23
+ const forced = [];
24
+ for (const sport of Object.keys(HOST_PALETTE)) {
25
+ if (only !== undefined && sport !== only)
26
+ continue;
27
+ const palette = { light: `${PALETTES[HOST_PALETTE[sport]].light};${NOT_TEAMS}`, dark: `${PALETTES[HOST_PALETTE[sport]].dark};${NOT_TEAMS}` };
28
+ const mine = `.ky-host[data-sport=${sport}]`;
29
+ light.push(`:where(.kyogijo ${mine}){${palette.light}}`);
30
+ auto.push(`:where(html:not([data-theme=light]) .kyogijo:not([data-theme=light]) ${mine}){${palette.dark}}`);
31
+ forced.push(`:where(html[data-theme=dark] .kyogijo ${mine},.kyogijo[data-theme=dark] ${mine}){${palette.dark}}`);
32
+ }
33
+ return [...rules, ...light, `@media (prefers-color-scheme:dark){${auto.join("")}}`, ...forced].join("\n");
34
+ }
35
+ /** The rules of every host's sport. */
36
+ export const KYOGIJO_SPECIAL_STYLE = specialStyle();