@johnmorrisdotca/kumimoji 1.2.1 → 1.3.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 (77) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/CONTRIBUTING.md +81 -44
  3. package/README.md +478 -327
  4. package/dist/check.d.ts +26 -1
  5. package/dist/check.js +26 -1
  6. package/dist/computer.types.d.ts +24 -2
  7. package/dist/computerPlay.d.ts +45 -2
  8. package/dist/computerPlay.js +45 -2
  9. package/dist/computerTurn.d.ts +42 -3
  10. package/dist/computerTurn.js +42 -3
  11. package/dist/daily.d.ts +22 -2
  12. package/dist/daily.js +22 -2
  13. package/dist/element-define.d.ts +1 -1
  14. package/dist/element-define.js +3 -13
  15. package/dist/element.d.ts +85 -4
  16. package/dist/element.js +176 -45
  17. package/dist/embed-day.d.ts +4 -0
  18. package/dist/embed-day.js +23 -0
  19. package/dist/export.d.ts +123 -6
  20. package/dist/export.js +91 -4
  21. package/dist/generate.d.ts +14 -0
  22. package/dist/generate.js +14 -0
  23. package/dist/grid.d.ts +181 -10
  24. package/dist/grid.js +122 -7
  25. package/dist/help.d.ts +36 -3
  26. package/dist/help.js +36 -3
  27. package/dist/judge.d.ts +14 -0
  28. package/dist/judge.js +14 -0
  29. package/dist/kana.d.ts +23 -1
  30. package/dist/kana.js +23 -1
  31. package/dist/kumimoji.types.d.ts +70 -5
  32. package/dist/party.d.ts +268 -14
  33. package/dist/party.js +268 -14
  34. package/dist/party.types.d.ts +50 -2
  35. package/dist/partyKept.d.ts +74 -4
  36. package/dist/partyKept.js +74 -4
  37. package/dist/partySeats.d.ts +92 -6
  38. package/dist/partySeats.js +72 -4
  39. package/dist/partyTurns.d.ts +171 -5
  40. package/dist/partyTurns.js +171 -5
  41. package/dist/placement.d.ts +50 -2
  42. package/dist/placement.js +30 -0
  43. package/dist/play.d.ts +247 -15
  44. package/dist/play.js +237 -15
  45. package/dist/random.d.ts +34 -3
  46. package/dist/random.js +23 -2
  47. package/dist/react.d.ts +42 -4
  48. package/dist/react.js +22 -5
  49. package/dist/showcase.d.ts +83 -7
  50. package/dist/showcase.js +49 -4
  51. package/dist/strings.d.ts +54 -5
  52. package/dist/strings.js +34 -3
  53. package/dist/tableView.d.ts +151 -8
  54. package/dist/tableView.js +129 -6
  55. package/dist/tileFace.d.ts +59 -5
  56. package/dist/tileFace.js +48 -4
  57. package/dist/tileFamily.d.ts +9 -0
  58. package/dist/tileFamily.js +9 -0
  59. package/dist/tileWords.d.ts +93 -6
  60. package/dist/tileWords.js +83 -6
  61. package/dist/tileWordsModule.d.ts +11 -1
  62. package/dist/tileWordsModule.js +11 -1
  63. package/dist/tiles.constants.d.ts +99 -5
  64. package/dist/tiles.constants.js +99 -5
  65. package/dist/turn.d.ts +82 -4
  66. package/dist/turn.js +82 -4
  67. package/dist/ui/board.d.ts +60 -5
  68. package/dist/ui/board.js +28 -2
  69. package/dist/ui/mount.d.ts +41 -2
  70. package/dist/ui/mount.js +38 -1
  71. package/dist/ui/style.d.ts +6 -1
  72. package/dist/ui/style.js +6 -0
  73. package/dist/version.d.ts +9 -2
  74. package/dist/version.js +9 -2
  75. package/dist/wilds.d.ts +22 -1
  76. package/dist/wilds.js +22 -1
  77. package/package.json +66 -57
package/dist/check.d.ts CHANGED
@@ -11,9 +11,34 @@ import type { KumimojiCheck, KumimojiLevel, KumimojiOptions } from "./kumimoji.t
11
11
  * Written out here rather than asked of the play page, which is what made the
12
12
  * grid; the list must have been loaded (`loadTileWords`), and a check that
13
13
  * cannot read it refuses.
14
+ *
15
+ * @param size - The supported initial hand size.
16
+ * @param givens - The original bag of internal tile codes.
17
+ * @param answer - The encoded completed grid to verify.
18
+ * @param options - Native game, component or presentation options.
19
+ * @returns WHETHER A GRID FINISHES A KUMIMOJI: the one check the server also runs. O(squares) and a lookup a word, nothing searched: the grid uses exactly the tiles of the bag, as many of each, it is all one piece, and every run of two or more across or down is in the list — and, for a game set up with Diagonals, every run of three or more along a diagonal. Which tiles were traded on the way does not matter — a finished game holds the whole bag whatever came out of it when — so the answer is the grid alone.
20
+ * @example
21
+ * ```ts
22
+ * import { checkKumimoji } from "@johnmorrisdotca/kumimoji";
23
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
24
+ *
25
+ * await loadTileWordsFromModule("english");
26
+ * console.log(checkKumimoji(3,"cat","cat",{level:"hard"}));
27
+ * ```
14
28
  */
15
29
  export declare function checkKumimoji(size: number, givens: string, answer: string, options?: KumimojiOptions & {
16
30
  level?: KumimojiLevel;
17
31
  }): KumimojiCheck;
18
- /** A finished game's leaderboard points (`KUMIMOJI_SCORE`): ten a tile, and up to as much again for speed. */
32
+ /** A finished game's leaderboard points (`KUMIMOJI_SCORE`): ten a tile, and up to as much again for speed.
33
+ *
34
+ * @param givens - The original bag of internal tile codes.
35
+ * @param elapsedMs - The elapsed solve time in milliseconds.
36
+ * @returns A finished game's leaderboard points (`KUMIMOJI_SCORE`): ten a tile, and up to as much again for speed.
37
+ * @example
38
+ * ```ts
39
+ * import { kumimojiPoints } from "@johnmorrisdotca/kumimoji";
40
+ *
41
+ * console.log(kumimojiPoints("cat",12000));
42
+ * ```
43
+ */
19
44
  export declare function kumimojiPoints(givens: string, elapsedMs: number): number;
package/dist/check.js CHANGED
@@ -14,6 +14,20 @@ import { tileWords } from "./tileWords.js";
14
14
  * Written out here rather than asked of the play page, which is what made the
15
15
  * grid; the list must have been loaded (`loadTileWords`), and a check that
16
16
  * cannot read it refuses.
17
+ *
18
+ * @param size - The supported initial hand size.
19
+ * @param givens - The original bag of internal tile codes.
20
+ * @param answer - The encoded completed grid to verify.
21
+ * @param options - Native game, component or presentation options.
22
+ * @returns WHETHER A GRID FINISHES A KUMIMOJI: the one check the server also runs. O(squares) and a lookup a word, nothing searched: the grid uses exactly the tiles of the bag, as many of each, it is all one piece, and every run of two or more across or down is in the list — and, for a game set up with Diagonals, every run of three or more along a diagonal. Which tiles were traded on the way does not matter — a finished game holds the whole bag whatever came out of it when — so the answer is the grid alone.
23
+ * @example
24
+ * ```ts
25
+ * import { checkKumimoji } from "@johnmorrisdotca/kumimoji";
26
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
27
+ *
28
+ * await loadTileWordsFromModule("english");
29
+ * console.log(checkKumimoji(3,"cat","cat",{level:"hard"}));
30
+ * ```
17
31
  */
18
32
  export function checkKumimoji(size, givens, answer, options = {}) {
19
33
  const gameLength = options.gameLength ?? "short";
@@ -60,7 +74,18 @@ export function checkKumimoji(size, givens, answer, options = {}) {
60
74
  return { ok: false, reason: "the grid is not finished" };
61
75
  return { ok: true };
62
76
  }
63
- /** A finished game's leaderboard points (`KUMIMOJI_SCORE`): ten a tile, and up to as much again for speed. */
77
+ /** A finished game's leaderboard points (`KUMIMOJI_SCORE`): ten a tile, and up to as much again for speed.
78
+ *
79
+ * @param givens - The original bag of internal tile codes.
80
+ * @param elapsedMs - The elapsed solve time in milliseconds.
81
+ * @returns A finished game's leaderboard points (`KUMIMOJI_SCORE`): ten a tile, and up to as much again for speed.
82
+ * @example
83
+ * ```ts
84
+ * import { kumimojiPoints } from "@johnmorrisdotca/kumimoji";
85
+ *
86
+ * console.log(kumimojiPoints("cat",12000));
87
+ * ```
88
+ */
64
89
  export function kumimojiPoints(givens, elapsedMs) {
65
90
  const tiles = givens.length;
66
91
  const base = KUMIMOJI_SCORE.tile * tiles;
@@ -1,5 +1,14 @@
1
1
  import type { PartyGame } from "./party.types.ts";
2
- /** What a computer did in one step of its turn, for the line over its table. */
2
+ /** What a computer did in one step of its turn, for the line over its table.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import type { ComputerSaid } from "@johnmorrisdotca/kumimoji";
7
+ *
8
+ * const value: ComputerSaid = {kind:"drew"};
9
+ * console.log(value);
10
+ * ```
11
+ */
3
12
  export type ComputerSaid = {
4
13
  kind: "rebuilt";
5
14
  } | {
@@ -16,7 +25,20 @@ export type ComputerSaid = {
16
25
  } | {
17
26
  kind: "resigned";
18
27
  };
19
- /** One step of a computer's turn: the game after it, and what it did. The last step's game is the one kept. */
28
+ /** One step of a computer's turn: the game after it, and what it did. The last step's game is the one kept.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { startParty } from "@johnmorrisdotca/kumimoji";
33
+ * import type { ComputerStep } from "@johnmorrisdotca/kumimoji";
34
+ *
35
+ * const settings = {size:3,level:"hard",seed:44,gameLength:"short",language:"english",doubleSet:false,diagonals:false,hints:false} as const;
36
+ * const bag = "catdogsun";
37
+ * const game = startParty(settings,bag,["Seat 1","Seat 2"]);
38
+ * const value: ComputerStep = {game,said:{kind:"drew"}};
39
+ * console.log(value);
40
+ * ```
41
+ */
20
42
  export type ComputerStep = {
21
43
  game: PartyGame;
22
44
  said: ComputerSaid;
@@ -1,17 +1,60 @@
1
1
  import { type GridRules, type GridVerdict, type Tiles } from "./grid.ts";
2
2
  import { type TilePlay } from "./play.ts";
3
3
  import type { TileWords } from "./tileWords.ts";
4
- /** Whether a grid is sound, read against the loaded word list by the game's rules: the same judgement the desk shows. */
4
+ /** Whether a grid is sound, read against the loaded word list by the game's rules: the same judgement the desk shows.
5
+ *
6
+ * @param tiles - The map from row,column square names to internal tile codes.
7
+ * @param words - The loaded native language word list and tile mappings.
8
+ * @param rules - Whether diagonal runs are also judged.
9
+ * @returns Whether a grid is sound, read against the loaded word list by the game's rules: the same judgement the desk shows.
10
+ * @example
11
+ * ```ts
12
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
13
+ * import { judgeTiles } from "@johnmorrisdotca/kumimoji";
14
+ *
15
+ * const words = await loadTileWordsFromModule("english");
16
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
17
+ * console.log(judgeTiles(tiles,words));
18
+ * ```
19
+ */
5
20
  export declare function judgeTiles(tiles: Tiles, words: TileWords, rules?: GridRules): GridVerdict;
6
21
  /**
7
22
  * THE COMPUTER'S NEXT WORD: its play after laying the best word its hand can
8
23
  * lay on its table, and the word, or null when there is none. The grid after
9
24
  * it is judged against the list, by the game's rules (`rules`), and is
10
25
  * always sound.
26
+ *
27
+ * @param play - The current immutable solo-game progress.
28
+ * @param words - The loaded native language word list and tile mappings.
29
+ * @param rules - Whether diagonal runs are also judged.
30
+ * @returns THE COMPUTER'S NEXT WORD: its play after laying the best word its hand can lay on its table, and the word, or null when there is none. The grid after it is judged against the list, by the game's rules (`rules`), and is always sound.
31
+ * @example
32
+ * ```ts
33
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
34
+ * import { bestLaying, deal } from "@johnmorrisdotca/kumimoji";
35
+ *
36
+ * const words = await loadTileWordsFromModule("english");
37
+ * const play = deal("catdog",3);
38
+ * console.log(bestLaying(play,words)?.word);
39
+ * ```
11
40
  */
12
41
  export declare function bestLaying(play: TilePlay, words: TileWords, rules?: GridRules): {
13
42
  play: TilePlay;
14
43
  word: string;
15
44
  } | null;
16
- /** The tile a computer trades: its rarest letter in the set, the first of those in its hand; never a wild. Null for a hand of wilds. */
45
+ /** The tile a computer trades: its rarest letter in the set, the first of those in its hand; never a wild. Null for a hand of wilds.
46
+ *
47
+ * @param hand - The hand size or tile codes, as declared by the function signature.
48
+ * @param words - The loaded native language word list and tile mappings.
49
+ * @returns The tile a computer trades: its rarest letter in the set, the first of those in its hand; never a wild. null for a hand of wilds.
50
+ * @example
51
+ * ```ts
52
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
53
+ * import { deal, tradeChoice } from "@johnmorrisdotca/kumimoji";
54
+ *
55
+ * const words = await loadTileWordsFromModule("english");
56
+ * const play = deal("catdog",3);
57
+ * console.log(tradeChoice(play.hand,words));
58
+ * ```
59
+ */
17
60
  export declare function tradeChoice(hand: readonly string[], words: TileWords): number | null;
@@ -28,7 +28,22 @@ function plainOf(tile, words) {
28
28
  const sound = words.soundOf(tile);
29
29
  return sound === null ? "" : (words.codeOf(sound) ?? "");
30
30
  }
31
- /** Whether a grid is sound, read against the loaded word list by the game's rules: the same judgement the desk shows. */
31
+ /** Whether a grid is sound, read against the loaded word list by the game's rules: the same judgement the desk shows.
32
+ *
33
+ * @param tiles - The map from row,column square names to internal tile codes.
34
+ * @param words - The loaded native language word list and tile mappings.
35
+ * @param rules - Whether diagonal runs are also judged.
36
+ * @returns Whether a grid is sound, read against the loaded word list by the game's rules: the same judgement the desk shows.
37
+ * @example
38
+ * ```ts
39
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
40
+ * import { judgeTiles } from "@johnmorrisdotca/kumimoji";
41
+ *
42
+ * const words = await loadTileWordsFromModule("english");
43
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
44
+ * console.log(judgeTiles(tiles,words));
45
+ * ```
46
+ */
32
47
  export function judgeTiles(tiles, words, rules = {}) {
33
48
  return judgeWithWords(tiles, words, rules);
34
49
  }
@@ -173,6 +188,20 @@ const JUDGED_MOST = 12;
173
188
  * lay on its table, and the word, or null when there is none. The grid after
174
189
  * it is judged against the list, by the game's rules (`rules`), and is
175
190
  * always sound.
191
+ *
192
+ * @param play - The current immutable solo-game progress.
193
+ * @param words - The loaded native language word list and tile mappings.
194
+ * @param rules - Whether diagonal runs are also judged.
195
+ * @returns THE COMPUTER'S NEXT WORD: its play after laying the best word its hand can lay on its table, and the word, or null when there is none. The grid after it is judged against the list, by the game's rules (`rules`), and is always sound.
196
+ * @example
197
+ * ```ts
198
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
199
+ * import { bestLaying, deal } from "@johnmorrisdotca/kumimoji";
200
+ *
201
+ * const words = await loadTileWordsFromModule("english");
202
+ * const play = deal("catdog",3);
203
+ * console.log(bestLaying(play,words)?.word);
204
+ * ```
176
205
  */
177
206
  export function bestLaying(play, words, rules = {}) {
178
207
  if (play.hand.length === 0)
@@ -186,7 +215,21 @@ export function bestLaying(play, words, rules = {}) {
186
215
  }
187
216
  return null;
188
217
  }
189
- /** The tile a computer trades: its rarest letter in the set, the first of those in its hand; never a wild. Null for a hand of wilds. */
218
+ /** The tile a computer trades: its rarest letter in the set, the first of those in its hand; never a wild. Null for a hand of wilds.
219
+ *
220
+ * @param hand - The hand size or tile codes, as declared by the function signature.
221
+ * @param words - The loaded native language word list and tile mappings.
222
+ * @returns The tile a computer trades: its rarest letter in the set, the first of those in its hand; never a wild. null for a hand of wilds.
223
+ * @example
224
+ * ```ts
225
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
226
+ * import { deal, tradeChoice } from "@johnmorrisdotca/kumimoji";
227
+ *
228
+ * const words = await loadTileWordsFromModule("english");
229
+ * const play = deal("catdog",3);
230
+ * console.log(tradeChoice(play.hand,words));
231
+ * ```
232
+ */
190
233
  export function tradeChoice(hand, words) {
191
234
  let chosen = null;
192
235
  let fewest = Infinity;
@@ -24,9 +24,48 @@ import type { TileWords } from "./tileWords.ts";
24
24
  * - Resign only where the rules offer it (`mayResign`) and it can do nothing
25
25
  * at all: nothing to lay, nothing to trade for, and it is not its last turn.
26
26
  */
27
- /** The most things a computer does in one turn before pressing Done: at the page's pause, a turn of about three seconds. */
27
+ /** The most things a computer does in one turn before pressing Done: at the page's pause, a turn of about three seconds.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { COMPUTER_STEPS_MOST } from "@johnmorrisdotca/kumimoji";
32
+ * console.log(COMPUTER_STEPS_MOST);
33
+ * ```
34
+ */
28
35
  export declare const COMPUTER_STEPS_MOST = 8;
29
- /** A computer seat's whole turn as its steps, in order, for a page to show one at a time. None when it is not a computer's turn or the game is over. */
36
+ /** A computer seat's whole turn as its steps, in order, for a page to show one at a time. None when it is not a computer's turn or the game is over.
37
+ *
38
+ * @param game - The current immutable shared-bag party game.
39
+ * @param words - The loaded native language word list and tile mappings.
40
+ * @returns A computer seat's whole turn as its steps, in order, for a page to show one at a time. None when it is not a computer's turn or the game is over.
41
+ * @example
42
+ * ```ts no-run
43
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
44
+ * import { planComputerTurn, startParty } from "@johnmorrisdotca/kumimoji";
45
+ *
46
+ * const words = await loadTileWordsFromModule("english");
47
+ * const settings = {size:3,level:"hard",seed:44,gameLength:"short",language:"english",doubleSet:false,diagonals:false,hints:false} as const;
48
+ * const bag = "catdogsun";
49
+ * const game = startParty(settings,bag,["Seat 1","Seat 2"]);
50
+ * console.log(planComputerTurn(game,words).map(step=>step.said));
51
+ * ```
52
+ */
30
53
  export declare function planComputerTurn(game: PartyGame, words: TileWords): ComputerStep[];
31
- /** The game a computer's turn passes on: its plan's last step, or the game as it was where there is nothing to play. */
54
+ /** The game a computer's turn passes on: its plan's last step, or the game as it was where there is nothing to play.
55
+ *
56
+ * @param game - The current immutable shared-bag party game.
57
+ * @param words - The loaded native language word list and tile mappings.
58
+ * @returns The game a computer's turn passes on: its plan's last step, or the game as it was where there is nothing to play.
59
+ * @example
60
+ * ```ts no-run
61
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
62
+ * import { afterComputerTurn, startParty } from "@johnmorrisdotca/kumimoji";
63
+ *
64
+ * const words = await loadTileWordsFromModule("english");
65
+ * const settings = {size:3,level:"hard",seed:44,gameLength:"short",language:"english",doubleSet:false,diagonals:false,hints:false} as const;
66
+ * const bag = "catdogsun";
67
+ * const game = startParty(settings,bag,["Seat 1","Seat 2"]);
68
+ * console.log(afterComputerTurn(game,words).turn);
69
+ * ```
70
+ */
32
71
  export declare function afterComputerTurn(game: PartyGame, words: TileWords): PartyGame;
@@ -25,11 +25,34 @@ import { liftAll, mayTrade, trade } from "./play.js";
25
25
  * - Resign only where the rules offer it (`mayResign`) and it can do nothing
26
26
  * at all: nothing to lay, nothing to trade for, and it is not its last turn.
27
27
  */
28
- /** The most things a computer does in one turn before pressing Done: at the page's pause, a turn of about three seconds. */
28
+ /** The most things a computer does in one turn before pressing Done: at the page's pause, a turn of about three seconds.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { COMPUTER_STEPS_MOST } from "@johnmorrisdotca/kumimoji";
33
+ * console.log(COMPUTER_STEPS_MOST);
34
+ * ```
35
+ */
29
36
  export const COMPUTER_STEPS_MOST = 8;
30
37
  /** How many settling steps may be needed at the end to be allowed Done at all; one trade a turn and a hand of tiles, so it is bounded anyway. */
31
38
  const SETTLING_MOST = 200;
32
- /** A computer seat's whole turn as its steps, in order, for a page to show one at a time. None when it is not a computer's turn or the game is over. */
39
+ /** A computer seat's whole turn as its steps, in order, for a page to show one at a time. None when it is not a computer's turn or the game is over.
40
+ *
41
+ * @param game - The current immutable shared-bag party game.
42
+ * @param words - The loaded native language word list and tile mappings.
43
+ * @returns A computer seat's whole turn as its steps, in order, for a page to show one at a time. None when it is not a computer's turn or the game is over.
44
+ * @example
45
+ * ```ts no-run
46
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
47
+ * import { planComputerTurn, startParty } from "@johnmorrisdotca/kumimoji";
48
+ *
49
+ * const words = await loadTileWordsFromModule("english");
50
+ * const settings = {size:3,level:"hard",seed:44,gameLength:"short",language:"english",doubleSet:false,diagonals:false,hints:false} as const;
51
+ * const bag = "catdogsun";
52
+ * const game = startParty(settings,bag,["Seat 1","Seat 2"]);
53
+ * console.log(planComputerTurn(game,words).map(step=>step.said));
54
+ * ```
55
+ */
33
56
  export function planComputerTurn(game, words) {
34
57
  const steps = [];
35
58
  if (game.ending !== null || !isComputer(game, game.turn))
@@ -89,7 +112,23 @@ export function planComputerTurn(game, words) {
89
112
  take(endTurn(now, verdict(), handSpells), { kind: "done", out: goesOut(now, verdict()) });
90
113
  return steps;
91
114
  }
92
- /** The game a computer's turn passes on: its plan's last step, or the game as it was where there is nothing to play. */
115
+ /** The game a computer's turn passes on: its plan's last step, or the game as it was where there is nothing to play.
116
+ *
117
+ * @param game - The current immutable shared-bag party game.
118
+ * @param words - The loaded native language word list and tile mappings.
119
+ * @returns The game a computer's turn passes on: its plan's last step, or the game as it was where there is nothing to play.
120
+ * @example
121
+ * ```ts no-run
122
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
123
+ * import { afterComputerTurn, startParty } from "@johnmorrisdotca/kumimoji";
124
+ *
125
+ * const words = await loadTileWordsFromModule("english");
126
+ * const settings = {size:3,level:"hard",seed:44,gameLength:"short",language:"english",doubleSet:false,diagonals:false,hints:false} as const;
127
+ * const bag = "catdogsun";
128
+ * const game = startParty(settings,bag,["Seat 1","Seat 2"]);
129
+ * console.log(afterComputerTurn(game,words).turn);
130
+ * ```
131
+ */
93
132
  export function afterComputerTurn(game, words) {
94
133
  return planComputerTurn(game, words).at(-1)?.game ?? game;
95
134
  }
package/dist/daily.d.ts CHANGED
@@ -8,7 +8,27 @@
8
8
  * hand, level, length) gets the same bag, in the same order. The race against
9
9
  * the clock is then theirs.
10
10
  */
11
- /** The day a moment falls on, in UTC, written `YYYY-MM-DD`. Throws a `RangeError` for an invalid `Date`. */
11
+ /** The day a moment falls on, in UTC, written `YYYY-MM-DD`. Throws a `RangeError` for an invalid `Date`.
12
+ *
13
+ * @param at - The word offset, seat index or date specified by this signature.
14
+ * @returns The day a moment falls on, in UTC, written `YYYY-MM-DD`. Throws a `RangeError` for an invalid `Date`.
15
+ * @example
16
+ * ```ts
17
+ * import { kumimojiDay } from "@johnmorrisdotca/kumimoji";
18
+ *
19
+ * console.log(kumimojiDay(new Date("2026-10-12T12:00:00Z")));
20
+ * ```
21
+ */
12
22
  export declare function kumimojiDay(at: Date): string;
13
- /** Today's seed, the date as a number: 2026-10-01 is 20261001. The day is UTC, so it is one seed worldwide. */
23
+ /** Today's seed, the date as a number: 2026-10-01 is 20261001. The day is UTC, so it is one seed worldwide.
24
+ *
25
+ * @param at - The word offset, seat index or date specified by this signature.
26
+ * @returns Today's seed, the date as a number: 2026-10-01 is 20261001. The day is UTC, so it is one seed worldwide.
27
+ * @example
28
+ * ```ts
29
+ * import { kumimojiDailySeed } from "@johnmorrisdotca/kumimoji";
30
+ *
31
+ * console.log(kumimojiDailySeed(new Date("2026-10-12T12:00:00Z")));
32
+ * ```
33
+ */
14
34
  export declare function kumimojiDailySeed(at: Date): number;
package/dist/daily.js CHANGED
@@ -9,13 +9,33 @@
9
9
  * the clock is then theirs.
10
10
  */
11
11
  const pad = (value, width) => String(value).padStart(width, "0");
12
- /** The day a moment falls on, in UTC, written `YYYY-MM-DD`. Throws a `RangeError` for an invalid `Date`. */
12
+ /** The day a moment falls on, in UTC, written `YYYY-MM-DD`. Throws a `RangeError` for an invalid `Date`.
13
+ *
14
+ * @param at - The word offset, seat index or date specified by this signature.
15
+ * @returns The day a moment falls on, in UTC, written `YYYY-MM-DD`. Throws a `RangeError` for an invalid `Date`.
16
+ * @example
17
+ * ```ts
18
+ * import { kumimojiDay } from "@johnmorrisdotca/kumimoji";
19
+ *
20
+ * console.log(kumimojiDay(new Date("2026-10-12T12:00:00Z")));
21
+ * ```
22
+ */
13
23
  export function kumimojiDay(at) {
14
24
  if (Number.isNaN(at.getTime()))
15
25
  throw new RangeError("kumimoji: an invalid Date has no day");
16
26
  return `${pad(at.getUTCFullYear(), 4)}-${pad(at.getUTCMonth() + 1, 2)}-${pad(at.getUTCDate(), 2)}`;
17
27
  }
18
- /** Today's seed, the date as a number: 2026-10-01 is 20261001. The day is UTC, so it is one seed worldwide. */
28
+ /** Today's seed, the date as a number: 2026-10-01 is 20261001. The day is UTC, so it is one seed worldwide.
29
+ *
30
+ * @param at - The word offset, seat index or date specified by this signature.
31
+ * @returns Today's seed, the date as a number: 2026-10-01 is 20261001. The day is UTC, so it is one seed worldwide.
32
+ * @example
33
+ * ```ts
34
+ * import { kumimojiDailySeed } from "@johnmorrisdotca/kumimoji";
35
+ *
36
+ * console.log(kumimojiDailySeed(new Date("2026-10-12T12:00:00Z")));
37
+ * ```
38
+ */
19
39
  export function kumimojiDailySeed(at) {
20
40
  const [year, month, day] = kumimojiDay(at).split("-").map(Number);
21
41
  return year * 10000 + month * 100 + day;
@@ -1 +1 @@
1
- export {};
1
+ export * from "./element.ts";
@@ -1,13 +1,3 @@
1
- /**
2
- * Defines the `<kumimoji-table>` element on the page. Import it for its effect:
3
- *
4
- * ```html
5
- * <script type="module" src="https://cdn.jsdelivr.net/npm/@johnmorrisdotca/kumimoji@1/dist/element-define.js"></script>
6
- * <kumimoji-table language="english" hand="7"></kumimoji-table>
7
- * ```
8
- *
9
- * A tag already defined is left as it is, and on a server, where there is no page, nothing happens.
10
- */
11
- import { KumimojiTable } from "./element.js";
12
- if (typeof customElements !== "undefined" && customElements.get("kumimoji-table") === undefined)
13
- customElements.define("kumimoji-table", KumimojiTable);
1
+ import { defineTable } from "./element.js";
2
+ defineTable();
3
+ export * from "./element.js";
package/dist/element.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type KumimojiTableHandle } from "./ui/mount.ts";
1
+ import { type KumimojiTableHandle, type KumimojiTableOptions } from "./ui/mount.ts";
2
2
  import type { KumimojiSaved } from "./export.ts";
3
3
  declare const ElementBase: typeof HTMLElement;
4
4
  /**
@@ -12,8 +12,7 @@ declare const ElementBase: typeof HTMLElement;
12
12
  * <kumimoji-table language="japanese" level="easy" seed="daily"></kumimoji-table>
13
13
  * ```
14
14
  *
15
- * Attributes (each is read again when it changes; a change to any but `lang`
16
- * deals a new game):
15
+ * Attributes configure the starting game; display, language and control changes preserve play:
17
16
  * - `language`: the tiles, `english` (default) or `japanese` kana.
18
17
  * - `hand`: the opening hand, 3, 7 (default) or 11.
19
18
  * - `level`: how many tiles are wild, `easy` (most), `medium` (default) or `hard` (none).
@@ -25,11 +24,41 @@ declare const ElementBase: typeof HTMLElement;
25
24
  * It fires `kumimoji-change` after every change to the game, with the game as it would
26
25
  * be saved as `event.detail.saved`, and `kumimoji-finish` when the last tile is laid and every run
27
26
  * is a word, with `event.detail` the deal, the play and the time it took. It has the methods
28
- * `newGame()` and `setGame()`. A table the rules do not offer (a hand of 5, say) draws nothing.
27
+ * `newGame()` and `setGame()`. Invalid input shows a status and a plain error event.
28
+ */
29
+ /**
30
+ * Native table options, checked alongside builder coverage.
31
+ * @example
32
+ * ```ts
33
+ * import { KUMIMOJI_EMBED_OPTION_KEYS } from "@johnmorrisdotca/kumimoji/element";
34
+ * console.log(KUMIMOJI_EMBED_OPTION_KEYS.includes("saved"));
35
+ * ```
36
+ */
37
+ export declare const KUMIMOJI_EMBED_OPTION_KEYS: string[];
38
+ /**
39
+ * Full native host options, including saved state, private words and callbacks.
40
+ * @example
41
+ * ```ts
42
+ * import type { KumimojiElementOptions } from "@johnmorrisdotca/kumimoji/element";
43
+ * const options: KumimojiElementOptions = { keep: false, locale: "ja" };
44
+ * console.log(options.locale);
45
+ * ```
46
+ */
47
+ export type KumimojiElementOptions = KumimojiTableOptions;
48
+ /**
49
+ * A reflected crossword table with the native table handle and saved-state getter.
50
+ * @example
51
+ * ```ts
52
+ * import { KumimojiTable } from "@johnmorrisdotca/kumimoji/element";
53
+ * console.log(KumimojiTable.observedAttributes.includes("daily"));
54
+ * ```
29
55
  */
30
56
  export declare class KumimojiTable extends ElementBase {
31
57
  #private;
32
58
  static observedAttributes: string[];
59
+ /** Native host options. Callback/presentation changes preserve the current game. */
60
+ get options(): KumimojiElementOptions;
61
+ set options(value: KumimojiElementOptions);
33
62
  connectedCallback(): void;
34
63
  disconnectedCallback(): void;
35
64
  attributeChangedCallback(): void;
@@ -41,5 +70,57 @@ export declare class KumimojiTable extends ElementBase {
41
70
  newGame(options?: Parameters<KumimojiTableHandle["newGame"]>[0]): Promise<void>;
42
71
  /** Put a game on the table: see `KumimojiTableHandle.setGame`. */
43
72
  setGame(saved: KumimojiSaved): Promise<void>;
73
+ /** The `language` attribute, reflected. */
74
+ get language(): string | null;
75
+ set language(value: string | number | boolean | null | undefined);
76
+ /** The `hand` attribute, reflected. */
77
+ get hand(): string | null;
78
+ set hand(value: string | number | boolean | null | undefined);
79
+ /** The `level` attribute, reflected. */
80
+ get level(): string | null;
81
+ set level(value: string | number | boolean | null | undefined);
82
+ /** The `length` attribute, reflected. */
83
+ get length(): string | null;
84
+ set length(value: string | number | boolean | null | undefined);
85
+ /** The `diagonals` attribute, reflected. */
86
+ get diagonals(): string | null;
87
+ set diagonals(value: string | number | boolean | null | undefined);
88
+ /** The `seed` attribute, reflected. */
89
+ get seed(): string | null;
90
+ set seed(value: string | number | boolean | null | undefined);
91
+ /** The `keep` attribute, reflected. */
92
+ get keep(): string | null;
93
+ set keep(value: string | number | boolean | null | undefined);
94
+ /** The `daily` attribute, reflected. */
95
+ get daily(): string | null;
96
+ set daily(value: string | number | boolean | null | undefined);
97
+ /** The `controls` attribute, reflected. */
98
+ get controls(): string | null;
99
+ set controls(value: string | number | boolean | null | undefined);
100
+ /** The `theme` attribute, reflected. */
101
+ get theme(): string | null;
102
+ set theme(value: string | number | boolean | null | undefined);
103
+ /** The `size` attribute, reflected. */
104
+ get size(): string | null;
105
+ set size(value: string | number | boolean | null | undefined);
106
+ /** The `width` attribute, reflected. */
107
+ get width(): string | null;
108
+ set width(value: string | number | boolean | null | undefined);
109
+ /** The `label` attribute, reflected. */
110
+ get label(): string | null;
111
+ set label(value: string | number | boolean | null | undefined);
44
112
  }
113
+ /**
114
+ * Defines the table or a subclass under a custom tag. Server-safe and idempotent.
115
+ * @param tagName - The tag name; kumimoji-table by default.
116
+ * @param registry - The page registry, or undefined on a server.
117
+ * @returns Nothing; existing definitions are left alone.
118
+ * @example
119
+ * ```ts
120
+ * import { defineTable } from "@johnmorrisdotca/kumimoji/element";
121
+ * defineTable();
122
+ * console.log(typeof defineTable);
123
+ * ```
124
+ */
125
+ export declare function defineTable(tagName?: string, registry?: CustomElementRegistry | undefined): void;
45
126
  export {};