@johnmorrisdotca/sugoroku 1.0.2 → 1.1.1

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 (67) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +78 -68
  3. package/dist/board.d.ts +216 -12
  4. package/dist/board.js +205 -13
  5. package/dist/colours.d.ts +80 -8
  6. package/dist/colours.js +57 -7
  7. package/dist/computer.d.ts +139 -9
  8. package/dist/computer.js +118 -11
  9. package/dist/dice.d.ts +53 -4
  10. package/dist/dice.js +42 -3
  11. package/dist/draw-entry.d.ts +3 -3
  12. package/dist/draw-entry.js +2 -2
  13. package/dist/draw.d.ts +43 -3
  14. package/dist/draw.js +63 -13
  15. package/dist/element-define.d.ts +1 -1
  16. package/dist/element-define.js +4 -13
  17. package/dist/element.d.ts +116 -5
  18. package/dist/element.js +378 -102
  19. package/dist/elementFrame.d.ts +21 -0
  20. package/dist/elementFrame.js +110 -0
  21. package/dist/evaluate.d.ts +76 -4
  22. package/dist/evaluate.js +70 -5
  23. package/dist/game.d.ts +408 -23
  24. package/dist/game.js +344 -20
  25. package/dist/geometry.d.ts +50 -3
  26. package/dist/geometry.js +64 -28
  27. package/dist/index.d.ts +12 -11
  28. package/dist/index.js +10 -9
  29. package/dist/match.d.ts +66 -4
  30. package/dist/match.js +69 -6
  31. package/dist/mount.d.ts +77 -6
  32. package/dist/mount.js +105 -357
  33. package/dist/mountView.d.ts +58 -0
  34. package/dist/mountView.js +459 -0
  35. package/dist/moves.d.ts +48 -1
  36. package/dist/moves.js +35 -1
  37. package/dist/notation.d.ts +92 -4
  38. package/dist/notation.js +88 -5
  39. package/dist/play-entry.d.ts +4 -4
  40. package/dist/play-entry.js +1 -1
  41. package/dist/playStyle.d.ts +6 -0
  42. package/dist/playStyle.js +6 -0
  43. package/dist/plays.d.ts +108 -3
  44. package/dist/plays.js +96 -3
  45. package/dist/positionElement.d.ts +107 -0
  46. package/dist/positionElement.js +303 -0
  47. package/dist/positionId.d.ts +29 -1
  48. package/dist/positionId.js +33 -2
  49. package/dist/random.d.ts +33 -3
  50. package/dist/random.js +22 -2
  51. package/dist/record.d.ts +151 -8
  52. package/dist/record.js +121 -36
  53. package/dist/rules.d.ts +130 -10
  54. package/dist/rules.js +133 -14
  55. package/dist/side.d.ts +38 -3
  56. package/dist/side.js +30 -3
  57. package/dist/sound.d.ts +61 -3
  58. package/dist/sound.js +27 -2
  59. package/dist/strings.d.ts +42 -2
  60. package/dist/strings.js +37 -3
  61. package/dist/style.d.ts +6 -0
  62. package/dist/style.js +6 -0
  63. package/dist/variants.d.ts +113 -8
  64. package/dist/variants.js +81 -7
  65. package/dist/version.d.ts +9 -2
  66. package/dist/version.js +9 -2
  67. package/package.json +29 -22
package/dist/rules.js CHANGED
@@ -1,7 +1,34 @@
1
1
  import { isVariantKey, variantSpec } from "./variants.js";
2
- /** The rules a variant is played with when nothing else is asked: a single game with no cube and no gammons. */
3
- export const DEFAULT_RULES = { points: 1, cube: false, crawford: true, jacoby: false, beaver: false, gammons: false };
4
- /** What goes wrong with a set of rules, as sentences; empty when they are fine. */
2
+ /** The rules a variant is played with when nothing else is asked: a single game with no cube and no gammons.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { DEFAULT_RULES } from "@johnmorrisdotca/sugoroku";
7
+ * console.log(DEFAULT_RULES);
8
+ * ```
9
+ */
10
+ export const DEFAULT_RULES = {
11
+ points: 1,
12
+ cube: false,
13
+ crawford: true,
14
+ jacoby: false,
15
+ beaver: false,
16
+ gammons: false,
17
+ };
18
+ /** What goes wrong with a set of rules, as sentences; empty when they are fine.
19
+ *
20
+ * @param rules - The complete or partial native rules specified by the signature.
21
+ * @param variant - The variant key or resolved specification.
22
+ * @returns What goes wrong with a set of rules, as sentences; empty when they are fine.
23
+ * @example
24
+ * ```ts
25
+ * import { rulesProblems, settingsFor } from "@johnmorrisdotca/sugoroku";
26
+ *
27
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
28
+ * const spec = settings.variant;
29
+ * console.log(rulesProblems(settings.rules,spec));
30
+ * ```
31
+ */
5
32
  export function rulesProblems(rules, variant) {
6
33
  const problems = [];
7
34
  if (!Number.isInteger(rules.points) || rules.points < 0)
@@ -18,7 +45,20 @@ export function rulesProblems(rules, variant) {
18
45
  problems.push("a game played to lose has no cube and no gammons");
19
46
  return problems;
20
47
  }
21
- /** The rules with anything left out filled from `DEFAULT_RULES`. Throws if the result is not a set of rules that can be played. */
48
+ /** The rules with anything left out filled from `DEFAULT_RULES`. Throws if the result is not a set of rules that can be played.
49
+ *
50
+ * @param rules - The complete or partial native rules specified by the signature.
51
+ * @param variant - The variant key or resolved specification.
52
+ * @returns The rules with anything left out filled from `DEFAULT_RULES`. Throws if the result is not a set of rules that can be played.
53
+ * @example
54
+ * ```ts
55
+ * import { resolveRules, settingsFor } from "@johnmorrisdotca/sugoroku";
56
+ *
57
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
58
+ * const spec = settings.variant;
59
+ * console.log(resolveRules({points:5,cube:true},spec));
60
+ * ```
61
+ */
22
62
  export function resolveRules(rules = {}, variant) {
23
63
  const resolved = { ...DEFAULT_RULES, ...rules };
24
64
  const problems = rulesProblems(resolved, variant);
@@ -26,22 +66,70 @@ export function resolveRules(rules = {}, variant) {
26
66
  throw new Error(`These rules cannot be played: ${problems.join("; ")}.`);
27
67
  return resolved;
28
68
  }
29
- /** Whether the cube is in play in a game of a match, given whether this is the Crawford game. */
69
+ /** Whether the cube is in play in a game of a match, given whether this is the Crawford game.
70
+ *
71
+ * @param rules - The complete or partial native rules specified by the signature.
72
+ * @param crawfordGame - Whether this is the match’s cube-free Crawford game.
73
+ * @returns Whether the cube is in play in a game of a match, given whether this is the Crawford game.
74
+ * @example
75
+ * ```ts
76
+ * import { cubeInPlay, settingsFor } from "@johnmorrisdotca/sugoroku";
77
+ *
78
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
79
+ * console.log(cubeInPlay(settings.rules,false));
80
+ * ```
81
+ */
30
82
  export function cubeInPlay(rules, crawfordGame) {
31
83
  return rules.cube && rules.points !== 1 && !crawfordGame;
32
84
  }
33
- /** The most the cube can show. */
85
+ /** The most the cube can show.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * import { CUBE_LIMIT } from "@johnmorrisdotca/sugoroku";
90
+ * console.log(CUBE_LIMIT);
91
+ * ```
92
+ */
34
93
  export const CUBE_LIMIT = 64;
35
- const MATCH = (points) => ({ points, cube: true, crawford: true, jacoby: false, beaver: false, gammons: true });
94
+ const MATCH = (points) => ({
95
+ points,
96
+ cube: true,
97
+ crawford: true,
98
+ jacoby: false,
99
+ beaver: false,
100
+ gammons: true,
101
+ });
36
102
  const SINGLE = DEFAULT_RULES;
37
- /** Every named way of playing, in the order of `docs/VARIANTS.md`. */
103
+ /** Every named way of playing, in the order of `docs/VARIANTS.md`.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { PRESETS } from "@johnmorrisdotca/sugoroku";
108
+ * console.log(PRESETS);
109
+ * ```
110
+ */
38
111
  export const PRESETS = [
39
- { key: "backgammon", variant: "backgammon", rules: SINGLE, names: ["Backgammon", "Backgammon Level 2", "Backgammon Level 3", "Casual Backgammon"] },
112
+ {
113
+ key: "backgammon",
114
+ variant: "backgammon",
115
+ rules: SINGLE,
116
+ names: ["Backgammon", "Backgammon Level 2", "Backgammon Level 3", "Casual Backgammon"],
117
+ },
40
118
  { key: "backgammon-3", variant: "backgammon", rules: MATCH(3), names: ["Backgammon (3 Point)"] },
41
- { key: "backgammon-5", variant: "backgammon", rules: MATCH(5), names: ["Backgammon (5 Point)", "Pro Backgammon", "Pro Backgammon Level 2"] },
119
+ {
120
+ key: "backgammon-5",
121
+ variant: "backgammon",
122
+ rules: MATCH(5),
123
+ names: ["Backgammon (5 Point)", "Pro Backgammon", "Pro Backgammon Level 2"],
124
+ },
42
125
  { key: "backgammon-7", variant: "backgammon", rules: MATCH(7), names: ["Backgammon (7 Point)"] },
43
126
  { key: "backgammon-9", variant: "backgammon", rules: MATCH(9), names: ["Backgammon (9 Point)", "Pro Backgammon-9"] },
44
- { key: "backgammon-race", variant: "backgammon-race", rules: SINGLE, names: ["Backgammon Race", "Backgammon Race Level 2"] },
127
+ {
128
+ key: "backgammon-race",
129
+ variant: "backgammon-race",
130
+ rules: SINGLE,
131
+ names: ["Backgammon Race", "Backgammon Race Level 2"],
132
+ },
45
133
  { key: "backgammon-race-5", variant: "backgammon-race", rules: MATCH(5), names: ["Pro Backgammon Race"] },
46
134
  { key: "anti-backgammon", variant: "anti-backgammon", rules: SINGLE, names: ["Anti-Backgammon"] },
47
135
  { key: "nackgammon", variant: "nackgammon", rules: SINGLE, names: ["Nackgammon"] },
@@ -59,16 +147,47 @@ export const PRESETS = [
59
147
  { key: "hypergammon-5", variant: "hypergammon", rules: MATCH(5), names: ["Hypergammon (5 Point)"] },
60
148
  { key: "tabula", variant: "tabula", rules: SINGLE, names: ["Tabula"] },
61
149
  ];
62
- /** The preset a site's printed name leads to, or undefined. Case and spacing around the name do not matter. */
150
+ /** The preset a site's printed name leads to, or undefined. Case and spacing around the name do not matter.
151
+ *
152
+ * @param name - The colour property, preset name or sound identifier specified by this signature.
153
+ * @returns The matching preset, or undefined for an unknown name.
154
+ * @example
155
+ * ```ts
156
+ * import { presetByName } from "@johnmorrisdotca/sugoroku";
157
+ *
158
+ * console.log(presetByName("backgammon")?.key);
159
+ * ```
160
+ */
63
161
  export function presetByName(name) {
64
162
  const wanted = name.trim().toLowerCase();
65
163
  return PRESETS.find((preset) => preset.names.some((one) => one.toLowerCase() === wanted));
66
164
  }
67
- /** The preset with this key, or undefined. */
165
+ /** The preset with this key, or undefined.
166
+ *
167
+ * @param key - The native variant, preset or localized-label key specified by the signature.
168
+ * @returns The matching preset, or undefined for an unknown key.
169
+ * @example
170
+ * ```ts
171
+ * import { PRESETS, presetByKey } from "@johnmorrisdotca/sugoroku";
172
+ *
173
+ * console.log(presetByKey(PRESETS[0].key)?.names);
174
+ * ```
175
+ */
68
176
  export function presetByKey(key) {
69
177
  return PRESETS.find((preset) => preset.key === key);
70
178
  }
71
- /** Settings from a variant key (or a row) and rules, left-out rules filled in. */
179
+ /** Settings from a variant key (or a row) and rules, left-out rules filled in.
180
+ *
181
+ * @param variant - The variant key or resolved specification.
182
+ * @param rules - The complete or partial native rules specified by the signature.
183
+ * @returns Settings from a variant key (or a row) and rules, left-out rules filled in.
184
+ * @example
185
+ * ```ts
186
+ * import { settingsFor } from "@johnmorrisdotca/sugoroku";
187
+ *
188
+ * console.log(settingsFor("nackgammon",{points:5}).variant.key);
189
+ * ```
190
+ */
72
191
  export function settingsFor(variant, rules = {}) {
73
192
  if (typeof variant === "string" && !isVariantKey(variant))
74
193
  throw new Error(`${variant} is not a variant`);
package/dist/side.d.ts CHANGED
@@ -3,11 +3,46 @@
3
3
  * position is kept per side, in that side's own numbering of the points: a
4
4
  * side's own point 1 is the one nearest its bearing-off, its own point 24 the
5
5
  * one farthest from it, whichever way the board is drawn.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import type { Side } from "@johnmorrisdotca/sugoroku";
10
+ *
11
+ * const value: Side = "white";
12
+ * console.log(value);
13
+ * ```
6
14
  */
7
15
  export type Side = "white" | "black";
8
- /** Both sides, white first. */
16
+ /** Both sides, white first.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { SIDES } from "@johnmorrisdotca/sugoroku";
21
+ * console.log(SIDES);
22
+ * ```
23
+ */
9
24
  export declare const SIDES: readonly [Side, Side];
10
- /** The other side. */
25
+ /** The other side.
26
+ *
27
+ * @param side - The side being examined: white or black.
28
+ * @returns The other side.
29
+ * @example
30
+ * ```ts
31
+ * import { otherSide } from "@johnmorrisdotca/sugoroku";
32
+ *
33
+ * console.log(otherSide("white"));
34
+ * ```
35
+ */
11
36
  export declare function otherSide(side: Side): Side;
12
- /** 0 for white and 1 for black: where a side's counts are kept in a position. */
37
+ /** 0 for white and 1 for black: where a side's counts are kept in a position.
38
+ *
39
+ * @param side - The side being examined: white or black.
40
+ * @returns 0 for white and 1 for black: where a side's counts are kept in a position.
41
+ * @example
42
+ * ```ts
43
+ * import { sideIndex } from "@johnmorrisdotca/sugoroku";
44
+ *
45
+ * console.log(sideIndex("black"));
46
+ * ```
47
+ */
13
48
  export declare function sideIndex(side: Side): 0 | 1;
package/dist/side.js CHANGED
@@ -1,10 +1,37 @@
1
- /** Both sides, white first. */
1
+ /** Both sides, white first.
2
+ *
3
+ * @example
4
+ * ```ts
5
+ * import { SIDES } from "@johnmorrisdotca/sugoroku";
6
+ * console.log(SIDES);
7
+ * ```
8
+ */
2
9
  export const SIDES = ["white", "black"];
3
- /** The other side. */
10
+ /** The other side.
11
+ *
12
+ * @param side - The side being examined: white or black.
13
+ * @returns The other side.
14
+ * @example
15
+ * ```ts
16
+ * import { otherSide } from "@johnmorrisdotca/sugoroku";
17
+ *
18
+ * console.log(otherSide("white"));
19
+ * ```
20
+ */
4
21
  export function otherSide(side) {
5
22
  return side === "white" ? "black" : "white";
6
23
  }
7
- /** 0 for white and 1 for black: where a side's counts are kept in a position. */
24
+ /** 0 for white and 1 for black: where a side's counts are kept in a position.
25
+ *
26
+ * @param side - The side being examined: white or black.
27
+ * @returns 0 for white and 1 for black: where a side's counts are kept in a position.
28
+ * @example
29
+ * ```ts
30
+ * import { sideIndex } from "@johnmorrisdotca/sugoroku";
31
+ *
32
+ * console.log(sideIndex("black"));
33
+ * ```
34
+ */
8
35
  export function sideIndex(side) {
9
36
  return side === "white" ? 0 : 1;
10
37
  }
package/dist/sound.d.ts CHANGED
@@ -5,16 +5,74 @@
5
5
  * `sounds/CREDITS.txt`) and are found beside the code with `import.meta.url`,
6
6
  * so a bundler that follows that pattern ships them. A page that serves them
7
7
  * from somewhere else gives their addresses.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import type { SoundName } from "@johnmorrisdotca/sugoroku/play";
12
+ *
13
+ * const value: SoundName = "clack";
14
+ * console.log(value);
15
+ * ```
8
16
  */
9
17
  export type SoundName = "clack" | "hit" | "dice" | "cube";
10
- /** The address of each sound. */
18
+ /** The address of each sound.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import type { SoundUrls } from "@johnmorrisdotca/sugoroku/play";
23
+ *
24
+ * const value: SoundUrls = {};
25
+ * console.log(value);
26
+ * ```
27
+ */
11
28
  export type SoundUrls = Partial<Record<SoundName, string>>;
12
- /** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners). */
29
+ /** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
30
+ *
31
+ * @returns The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
32
+ * @example
33
+ * ```ts
34
+ * import { packagedSounds } from "@johnmorrisdotca/sugoroku/play";
35
+ *
36
+ * console.log(Object.keys(packagedSounds()));
37
+ * ```
38
+ */
13
39
  export declare function packagedSounds(): SoundUrls;
40
+ /** Optional board-sound playback and cleanup methods.
41
+ *
42
+ * @example
43
+ * ```ts no-run
44
+ * import { legalPlaysOf, newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
45
+ * import type { SoundPlayer } from "@johnmorrisdotca/sugoroku/play";
46
+ * import { createSounds } from "@johnmorrisdotca/sugoroku/play";
47
+ *
48
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
49
+ * const game = rollOpening(newGame(settings),[3,1]);
50
+ * const play = legalPlaysOf(game)[0];
51
+ * const sounds: SoundPlayer = createSounds({});
52
+ * console.log(typeof sounds.play);
53
+ * sounds.destroy();
54
+ * ```
55
+ */
14
56
  export type SoundPlayer = {
15
57
  play: (name: SoundName) => void;
16
58
  /** Stop and let go of everything. */
17
59
  destroy: () => void;
18
60
  };
19
- /** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio. */
61
+ /** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
62
+ *
63
+ * @param urls - Optional URLs of the native board sounds.
64
+ * @returns A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
65
+ * @example
66
+ * ```ts no-run
67
+ * import { legalPlaysOf, newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
68
+ * import { createSounds } from "@johnmorrisdotca/sugoroku/play";
69
+ *
70
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
71
+ * const game = rollOpening(newGame(settings),[3,1]);
72
+ * const play = legalPlaysOf(game)[0];
73
+ * const sounds = createSounds({});
74
+ * console.log(typeof sounds.play);
75
+ * sounds.destroy();
76
+ * ```
77
+ */
20
78
  export declare function createSounds(urls: SoundUrls): SoundPlayer;
package/dist/sound.js CHANGED
@@ -1,5 +1,14 @@
1
1
  const FILES = { clack: "clack.wav", hit: "hit.wav", dice: "dice.wav", cube: "cube.wav" };
2
- /** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners). */
2
+ /** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
3
+ *
4
+ * @returns The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
5
+ * @example
6
+ * ```ts
7
+ * import { packagedSounds } from "@johnmorrisdotca/sugoroku/play";
8
+ *
9
+ * console.log(Object.keys(packagedSounds()));
10
+ * ```
11
+ */
3
12
  export function packagedSounds() {
4
13
  try {
5
14
  const urls = {};
@@ -11,7 +20,23 @@ export function packagedSounds() {
11
20
  return {};
12
21
  }
13
22
  }
14
- /** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio. */
23
+ /** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
24
+ *
25
+ * @param urls - Optional URLs of the native board sounds.
26
+ * @returns A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
27
+ * @example
28
+ * ```ts no-run
29
+ * import { legalPlaysOf, newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
30
+ * import { createSounds } from "@johnmorrisdotca/sugoroku/play";
31
+ *
32
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
33
+ * const game = rollOpening(newGame(settings),[3,1]);
34
+ * const play = legalPlaysOf(game)[0];
35
+ * const sounds = createSounds({});
36
+ * console.log(typeof sounds.play);
37
+ * sounds.destroy();
38
+ * ```
39
+ */
15
40
  export function createSounds(urls) {
16
41
  const cache = new Map();
17
42
  let gone = false;
package/dist/strings.d.ts CHANGED
@@ -6,10 +6,50 @@
6
6
  *
7
7
  * `{name}` in a line is a value filled in. The Japanese is a first draft that no
8
8
  * native reader has yet checked.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import type { SugorokuLanguage } from "@johnmorrisdotca/sugoroku/play";
13
+ *
14
+ * const value: SugorokuLanguage = "ja";
15
+ * console.log(value);
16
+ * ```
9
17
  */
10
18
  export type SugorokuLanguage = "en" | "ja";
19
+ /** The native English and Japanese labels, announcements and interpolation templates.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { SUGOROKU_STRINGS } from "@johnmorrisdotca/sugoroku/play";
24
+ * console.log(SUGOROKU_STRINGS);
25
+ * ```
26
+ */
11
27
  export declare const SUGOROKU_STRINGS: Record<SugorokuLanguage, Record<string, string>>;
12
- /** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible. */
28
+ /** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
29
+ *
30
+ * @param language - The English or Japanese display language.
31
+ * @param key - The native variant, preset or localized-label key specified by the signature.
32
+ * @param values - Replacement strings or numbers for brace-delimited placeholders.
33
+ * @returns A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
34
+ * @example
35
+ * ```ts
36
+ * import { sugorokuSay } from "@johnmorrisdotca/sugoroku/play";
37
+ *
38
+ * console.log(sugorokuSay("en","roll"));
39
+ * ```
40
+ */
13
41
  export declare function sugorokuSay(language: SugorokuLanguage, key: string, values?: Record<string, string | number>): string;
14
- /** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`. */
42
+ /** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
43
+ *
44
+ * @param element - The host element whose inherited language is read; null selects the fallback.
45
+ * @returns The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
46
+ * @example
47
+ * ```ts no-run
48
+ * import { sugorokuLanguageOf } from "@johnmorrisdotca/sugoroku/play";
49
+ *
50
+ * const host = document.createElement("div");
51
+ * host.lang="ja";
52
+ * console.log(sugorokuLanguageOf(host));
53
+ * ```
54
+ */
15
55
  export declare function sugorokuLanguageOf(element: Element | null): SugorokuLanguage;
package/dist/strings.js CHANGED
@@ -1,3 +1,11 @@
1
+ /** The native English and Japanese labels, announcements and interpolation templates.
2
+ *
3
+ * @example
4
+ * ```ts
5
+ * import { SUGOROKU_STRINGS } from "@johnmorrisdotca/sugoroku/play";
6
+ * console.log(SUGOROKU_STRINGS);
7
+ * ```
8
+ */
1
9
  export const SUGOROKU_STRINGS = {
2
10
  en: {
3
11
  variant_backgammon: "Backgammon",
@@ -118,13 +126,39 @@ export const SUGOROKU_STRINGS = {
118
126
  dice: "サイコロ {dice}",
119
127
  },
120
128
  };
121
- /** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible. */
129
+ /** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
130
+ *
131
+ * @param language - The English or Japanese display language.
132
+ * @param key - The native variant, preset or localized-label key specified by the signature.
133
+ * @param values - Replacement strings or numbers for brace-delimited placeholders.
134
+ * @returns A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
135
+ * @example
136
+ * ```ts
137
+ * import { sugorokuSay } from "@johnmorrisdotca/sugoroku/play";
138
+ *
139
+ * console.log(sugorokuSay("en","roll"));
140
+ * ```
141
+ */
122
142
  export function sugorokuSay(language, key, values = {}) {
123
143
  const line = SUGOROKU_STRINGS[language][key] ?? SUGOROKU_STRINGS.en[key] ?? key;
124
144
  return line.replace(/\{(\w+)\}/g, (whole, name) => (name in values ? String(values[name]) : whole));
125
145
  }
126
- /** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`. */
146
+ /** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
147
+ *
148
+ * @param element - The host element whose inherited language is read; null selects the fallback.
149
+ * @returns The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
150
+ * @example
151
+ * ```ts no-run
152
+ * import { sugorokuLanguageOf } from "@johnmorrisdotca/sugoroku/play";
153
+ *
154
+ * const host = document.createElement("div");
155
+ * host.lang="ja";
156
+ * console.log(sugorokuLanguageOf(host));
157
+ * ```
158
+ */
127
159
  export function sugorokuLanguageOf(element) {
128
- const tag = element?.closest("[lang]")?.getAttribute("lang") ?? element?.ownerDocument?.documentElement.getAttribute("lang") ?? "en";
160
+ const tag = element?.closest("[lang]")?.getAttribute("lang") ??
161
+ element?.ownerDocument?.documentElement.getAttribute("lang") ??
162
+ "en";
129
163
  return tag.toLowerCase().startsWith("ja") ? "ja" : "en";
130
164
  }
package/dist/style.d.ts CHANGED
@@ -8,5 +8,11 @@
8
8
  * Put it in the page once. Every colour is a custom property on `.sugoroku`,
9
9
  * so a page's own style needs only to set the ones it wants different; the
10
10
  * felt follows `--felt` where a page defines one.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { SUGOROKU_STYLE } from "@johnmorrisdotca/sugoroku/draw";
15
+ * console.log(SUGOROKU_STYLE.length);
16
+ * ```
11
17
  */
12
18
  export declare const SUGOROKU_STYLE = "\n.sugoroku {\n --sg-frame: #5b3a1f; --sg-felt: var(--felt, #2f5d4a); --sg-point-a: #e7d8b1; --sg-point-b: #8e3a2b; --sg-bar: #4a2f19; --sg-tray: #24493a;\n --sg-white: #f6f0df; --sg-white-edge: #b3a888; --sg-black: #2b2724; --sg-black-edge: #0d0b0a;\n --sg-number: #e8dcc0; --sg-selected: #ffd23f; --sg-target: #7fe3a1; --sg-die: #fbf8f1; --sg-pip: #1f2320; --sg-cube: #fbf8f1; --sg-cube-ink: #1f2320;\n display: block; width: 100%; height: auto; overflow: visible;\n user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent;\n font-family: system-ui, -apple-system, \"Segoe UI\", sans-serif;\n}\n@media (prefers-color-scheme: dark) {\n :root:not([data-theme=\"light\"]) .sugoroku:not([data-theme=\"light\"]) {\n --sg-frame: #2b1c0e; --sg-felt: var(--felt, #1f4135); --sg-point-a: #bdad88; --sg-point-b: #6b2a1f; --sg-bar: #21160b; --sg-tray: #173026;\n --sg-white: #e9e3d0; --sg-white-edge: #9a9078; --sg-number: #b9ae92; --sg-die: #e9e3d0; --sg-cube: #e9e3d0;\n }\n}\n:root[data-theme=\"dark\"] .sugoroku:not([data-theme=\"light\"]), .sugoroku[data-theme=\"dark\"] {\n --sg-frame: #2b1c0e; --sg-felt: var(--felt, #1f4135); --sg-point-a: #bdad88; --sg-point-b: #6b2a1f; --sg-bar: #21160b; --sg-tray: #173026;\n --sg-white: #e9e3d0; --sg-white-edge: #9a9078; --sg-number: #b9ae92; --sg-die: #e9e3d0; --sg-cube: #e9e3d0;\n}\n.sugoroku * { user-select: none; -webkit-user-select: none; }\n.sugoroku .sg-frame { fill: var(--sg-frame); }\n.sugoroku .sg-felt { fill: var(--sg-felt); }\n.sugoroku .sg-rail, .sugoroku .sg-tray-well { fill: var(--sg-tray); }\n.sugoroku .sg-bar { fill: var(--sg-bar); }\n.sugoroku .sg-point[data-tone=\"a\"] .sg-triangle { fill: var(--sg-point-a); }\n.sugoroku .sg-point[data-tone=\"b\"] .sg-triangle { fill: var(--sg-point-b); }\n.sugoroku .sg-hit { fill: transparent; }\n.sugoroku .sg-bar-hit { fill: transparent; }\n.sugoroku .sg-tray { fill: rgba(0, 0, 0, .18); stroke: rgba(0, 0, 0, .25); stroke-width: 1; }\n.sugoroku .sg-number { fill: var(--sg-number); font-size: 11px; font-weight: 600; pointer-events: none; }\n.sugoroku .sg-checker { pointer-events: none; }\n.sugoroku .sg-checker[data-side=\"white\"] .sg-face { fill: var(--sg-white); stroke: var(--sg-white-edge); stroke-width: 2; }\n.sugoroku .sg-checker[data-side=\"black\"] .sg-face { fill: var(--sg-black); stroke: var(--sg-black-edge); stroke-width: 2; }\n.sugoroku .sg-checker[data-side=\"white\"] .sg-ring { fill: none; stroke: var(--sg-white-edge); stroke-width: 1.5; opacity: .7; }\n.sugoroku .sg-checker[data-side=\"black\"] .sg-ring { fill: none; stroke: var(--sg-black-edge); stroke-width: 1.5; opacity: .9; }\n.sugoroku .sg-gleam { fill: #fff; opacity: .16; }\n.sugoroku .sg-checker[data-side=\"white\"] .sg-count { fill: var(--sg-pip); }\n.sugoroku .sg-checker[data-side=\"black\"] .sg-count { fill: var(--sg-white); }\n.sugoroku .sg-count { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; pointer-events: none; }\n.sugoroku .sg-off[data-side=\"white\"] { fill: var(--sg-white); stroke: var(--sg-white-edge); stroke-width: 1.5; pointer-events: none; }\n.sugoroku .sg-off[data-side=\"black\"] { fill: var(--sg-black); stroke: var(--sg-black-edge); stroke-width: 1.5; pointer-events: none; }\n.sugoroku .sg-die { pointer-events: none; }\n.sugoroku .sg-die rect { fill: var(--sg-die); stroke: rgba(0, 0, 0, .35); stroke-width: 1.5; }\n.sugoroku .sg-die[data-spent=\"true\"] { opacity: .38; }\n.sugoroku .sg-pip { fill: var(--sg-pip); }\n.sugoroku .sg-cube { pointer-events: none; }\n.sugoroku .sg-cube rect { fill: var(--sg-cube); stroke: rgba(0, 0, 0, .35); stroke-width: 1.5; }\n.sugoroku .sg-cube-text { fill: var(--sg-cube-ink); font-size: 22px; font-weight: 800; pointer-events: none; }\n.sugoroku .sg-point[data-movable=\"true\"] .sg-triangle { stroke: rgba(255, 255, 255, .55); stroke-width: 3; stroke-linejoin: round; }\n.sugoroku .sg-bar-hit[data-movable=\"true\"] { fill: rgba(255, 255, 255, .14); }\n.sugoroku .sg-point[data-selected=\"true\"] .sg-triangle { stroke: var(--sg-selected); stroke-width: 4; stroke-linejoin: round; }\n.sugoroku .sg-point[data-target=\"true\"] .sg-triangle { stroke: var(--sg-target); stroke-width: 4; stroke-linejoin: round; }\n.sugoroku .sg-bar-hit[data-selected=\"true\"] { fill: var(--sg-selected); opacity: .35; }\n.sugoroku .sg-tray[data-target=\"true\"] { stroke: var(--sg-target); stroke-width: 4; fill: rgba(127, 227, 161, .18); }\n.sugoroku .sg-point[data-target=\"true\"], .sugoroku .sg-tray[data-target=\"true\"] { cursor: pointer; }\n";
package/dist/style.js CHANGED
@@ -8,6 +8,12 @@
8
8
  * Put it in the page once. Every colour is a custom property on `.sugoroku`,
9
9
  * so a page's own style needs only to set the ones it wants different; the
10
10
  * felt follows `--felt` where a page defines one.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { SUGOROKU_STYLE } from "@johnmorrisdotca/sugoroku/draw";
15
+ * console.log(SUGOROKU_STYLE.length);
16
+ * ```
11
17
  */
12
18
  export const SUGOROKU_STYLE = `
13
19
  .sugoroku {