@johnmorrisdotca/sugoroku 1.1.0 → 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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,18 @@ All notable changes to this project are written here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.1] - 2026-10-31
10
+
11
+ ### Changed
12
+
13
+ - Biome replaces ESLint as the formatter and linter, with the family's shared settings in `scripts/biome-family.json`; `pnpm lint` checks formatting too, and `pnpm format` applies it. The code is formatted once to 120 columns. Nothing a user of the package sees has changed.
14
+ - TypeScript targets ES2022, treats an indexed read as possibly missing, and refuses switch fallthrough and unmarked overrides.
15
+ - `pnpm check` also holds every source file to at most 500 lines of code (`scripts/check-size.mjs`; blank lines, comments, tests and data files are not counted). The board is split across `src/elementFrame.ts` and `src/positionElement.ts`, and the play view lives in `src/mountView.ts`, so those files stay within that.
16
+
17
+ ### Fixed
18
+
19
+ - The issue chooser's security link shows again: an unquoted colon had made `.github/ISSUE_TEMPLATE/config.yml` invalid YAML.
20
+
9
21
  ## [1.1.0] - 2026-10-14
10
22
 
11
23
  The board and the position are custom elements with the family's standard embed attributes and a shared builder, and the package has an English and Japanese documentation site with a checked example for every export. The rules, dice, records and computer players are unchanged.
package/README.md CHANGED
@@ -971,7 +971,7 @@ Please follow the [code of conduct](./CODE_OF_CONDUCT.md). A record or a positio
971
971
 
972
972
  See [CHANGELOG.md](./CHANGELOG.md).
973
973
 
974
- The latest release is 1.1.0: the board and position as elements, the shared embed builder, and the documentation site with a checked example for every export.
974
+ The latest release, 1.1.1, changes nothing a player sees.
975
975
 
976
976
  ## Licence
977
977
 
package/dist/board.js CHANGED
@@ -1,4 +1,4 @@
1
- import { sideIndex, otherSide } from "./side.js";
1
+ import { otherSide, sideIndex } from "./side.js";
2
2
  import { startCounts, startReserve } from "./variants.js";
3
3
  /** The points on the board.
4
4
  *
package/dist/colours.js CHANGED
@@ -86,4 +86,9 @@ export const SUGOROKU_CHECKER_SETS = {
86
86
  * console.log(SUGOROKU_CHECKER_SET_NAMES);
87
87
  * ```
88
88
  */
89
- export const SUGOROKU_CHECKER_SET_NAMES = ["classic", "red-and-white", "gold-and-blue", "contrast"];
89
+ export const SUGOROKU_CHECKER_SET_NAMES = [
90
+ "classic",
91
+ "red-and-white",
92
+ "gold-and-blue",
93
+ "contrast",
94
+ ];
@@ -1,6 +1,6 @@
1
1
  import type { DiceSource } from "./dice.ts";
2
- import { type GameState } from "./game.ts";
3
2
  import { type EvaluationWeights } from "./evaluate.ts";
3
+ import { type GameState } from "./game.ts";
4
4
  import { type Play } from "./plays.ts";
5
5
  import type { Random } from "./random.ts";
6
6
  import { type Side } from "./side.ts";
package/dist/computer.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { inContact } from "./board.js";
2
2
  import { rollFrom } from "./dice.js";
3
- import { canDouble, endTurn, legalPlaysOf, offerDouble, playTurn, rollDice, rollOpening, takeDouble, dropDouble } from "./game.js";
4
3
  import { EVALUATION_WEIGHTS, evaluateFor, keithCount, winChance } from "./evaluate.js";
4
+ import { canDouble, dropDouble, endTurn, legalPlaysOf, offerDouble, playTurn, rollDice, rollOpening, takeDouble, } from "./game.js";
5
5
  import { legalPlays } from "./plays.js";
6
6
  import { otherSide } from "./side.js";
7
7
  /** The strengths, weakest first.
@@ -34,7 +34,9 @@ const ROLLS_OF_THREE = (() => {
34
34
  })();
35
35
  /** The plays best first by what they leave, each with its score. */
36
36
  function ranked(spec, plays, side, weights) {
37
- return plays.map((play) => ({ play, score: evaluateFor(spec, play.position, side, weights) })).sort((a, b) => b.score - a.score);
37
+ return plays
38
+ .map((play) => ({ play, score: evaluateFor(spec, play.position, side, weights) }))
39
+ .sort((a, b) => b.score - a.score);
38
40
  }
39
41
  /** The value, for `side`, of a position that the other side is about to move from: the average over its rolls of what its best reply leaves. */
40
42
  function lookedAhead(spec, position, side, weights) {
@@ -43,7 +45,9 @@ function lookedAhead(spec, position, side, weights) {
43
45
  let weight = 0;
44
46
  const rolls = spec.dice === 2 ? ROLLS : ROLLS_OF_THREE;
45
47
  for (const roll of rolls) {
46
- const dice = spec.dice === 2 ? [roll[0], roll[1]] : [roll[0], roll[1], roll[2]];
48
+ const dice = spec.dice === 2
49
+ ? [roll[0], roll[1]]
50
+ : [roll[0], roll[1], roll[2]];
47
51
  const chance = roll[spec.dice];
48
52
  const replies = legalPlays(spec, position, opp, dice);
49
53
  // The other side picks the reply it likes best; we judge what that leaves us.
@@ -170,7 +174,8 @@ export function wantsToDouble(game, options = {}) {
170
174
  if (!inContact(spec, game.position)) {
171
175
  const race = raceCube(game, side, holds);
172
176
  // Not when the race is so lopsided that the other side must drop and the gammon is the only prize: keep it simple and double.
173
- return race.double && keithCount(game.position, side, true) < keithCount(game.position, otherSide(side), false) + (holds ? 4 : 5);
177
+ return (race.double &&
178
+ keithCount(game.position, side, true) < keithCount(game.position, otherSide(side), false) + (holds ? 4 : 5));
174
179
  }
175
180
  if (strength === "greedy")
176
181
  return false;
@@ -4,10 +4,10 @@
4
4
  * (`@johnmorrisdotca/sugoroku/draw`), so a server that only checks a game never
5
5
  * loads any of it.
6
6
  */
7
- export { colourProperty, SUGOROKU_BOARD_NAMES, SUGOROKU_BOARDS, SUGOROKU_CHECKER_SET_NAMES, SUGOROKU_CHECKER_SETS, SUGOROKU_COLOUR_NAMES } from "./colours.ts";
8
7
  export type { SugorokuBoardName, SugorokuCheckerSetName, SugorokuColours } from "./colours.ts";
9
- export { colourStyle, drawSugoroku, MOST_DRAWN } from "./draw.ts";
8
+ export { colourProperty, SUGOROKU_BOARD_NAMES, SUGOROKU_BOARDS, SUGOROKU_CHECKER_SET_NAMES, SUGOROKU_CHECKER_SETS, SUGOROKU_COLOUR_NAMES, } from "./colours.ts";
10
9
  export type { SugorokuDrawOptions } from "./draw.ts";
11
- export { boardSize, BoardLayout } from "./geometry.ts";
10
+ export { colourStyle, drawSugoroku, MOST_DRAWN } from "./draw.ts";
12
11
  export type { BoardOptions, Box, Orientation } from "./geometry.ts";
12
+ export { BoardLayout, boardSize } from "./geometry.ts";
13
13
  export { SUGOROKU_STYLE } from "./style.ts";
@@ -4,7 +4,7 @@
4
4
  * (`@johnmorrisdotca/sugoroku/draw`), so a server that only checks a game never
5
5
  * loads any of it.
6
6
  */
7
- export { colourProperty, SUGOROKU_BOARD_NAMES, SUGOROKU_BOARDS, SUGOROKU_CHECKER_SET_NAMES, SUGOROKU_CHECKER_SETS, SUGOROKU_COLOUR_NAMES } from "./colours.js";
7
+ export { colourProperty, SUGOROKU_BOARD_NAMES, SUGOROKU_BOARDS, SUGOROKU_CHECKER_SET_NAMES, SUGOROKU_CHECKER_SETS, SUGOROKU_COLOUR_NAMES, } from "./colours.js";
8
8
  export { colourStyle, drawSugoroku, MOST_DRAWN } from "./draw.js";
9
- export { boardSize, BoardLayout } from "./geometry.js";
9
+ export { BoardLayout, boardSize } from "./geometry.js";
10
10
  export { SUGOROKU_STYLE } from "./style.js";
package/dist/draw.js CHANGED
@@ -1,10 +1,10 @@
1
- import { boardPoint, BAR, POINTS } from "./board.js";
2
- import { colourProperty, SUGOROKU_BOARDS, SUGOROKU_CHECKER_SETS, SUGOROKU_COLOUR_NAMES } from "./colours.js";
3
- import { BAR_WIDTH, BoardLayout, boardSize, CHECKER, DIE, PAD, POINT_WIDTH, STACK_STEP, TRAY_WIDTH } from "./geometry.js";
4
- import { sideIndex, SIDES } from "./side.js";
1
+ import { BAR, boardPoint, POINTS } from "./board.js";
2
+ import { colourProperty, SUGOROKU_BOARDS, SUGOROKU_CHECKER_SETS, SUGOROKU_COLOUR_NAMES, } from "./colours.js";
3
+ import { BAR_WIDTH, BoardLayout, boardSize, CHECKER, DIE, PAD, POINT_WIDTH, STACK_STEP, TRAY_WIDTH, } from "./geometry.js";
4
+ import { SIDES, sideIndex } from "./side.js";
5
5
  import { SUGOROKU_STYLE } from "./style.js";
6
6
  import { VARIANTS } from "./variants.js";
7
- const escape = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
7
+ const escapeXml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
8
8
  const n = (value) => String(Math.round(value * 100) / 100);
9
9
  /** How many checkers are drawn on a stack before the last one carries the count.
10
10
  *
@@ -16,7 +16,15 @@ const n = (value) => String(Math.round(value * 100) / 100);
16
16
  */
17
17
  export const MOST_DRAWN = 5;
18
18
  /** The pips of each die face, as places on a three by three grid, 0 to 8 reading across and down. */
19
- const PIPS = [[], [4], [0, 8], [0, 4, 8], [0, 2, 6, 8], [0, 2, 4, 6, 8], [0, 2, 3, 5, 6, 8]];
19
+ const PIPS = [
20
+ [],
21
+ [4],
22
+ [0, 8],
23
+ [0, 4, 8],
24
+ [0, 2, 6, 8],
25
+ [0, 2, 4, 6, 8],
26
+ [0, 2, 3, 5, 6, 8],
27
+ ];
20
28
  /** The inline custom properties of a drawing: the named board and checkers, then any colour given.
21
29
  *
22
30
  * @param options - Native drawing, geometry, mounting or computer choices specified by the signature.
@@ -29,8 +37,14 @@ const PIPS = [[], [4], [0, 8], [0, 4, 8], [0, 2, 6, 8], [0, 2, 4, 6, 8], [0, 2,
29
37
  * ```
30
38
  */
31
39
  export function colourStyle(options) {
32
- const colours = { ...(options.board === undefined ? {} : SUGOROKU_BOARDS[options.board]), ...(options.checkers === undefined ? {} : SUGOROKU_CHECKER_SETS[options.checkers]), ...options.colours };
33
- return SUGOROKU_COLOUR_NAMES.filter((name) => colours[name] !== undefined).map((name) => `${colourProperty(name)}:${escape(String(colours[name]))}`).join(";");
40
+ const colours = {
41
+ ...(options.board === undefined ? {} : SUGOROKU_BOARDS[options.board]),
42
+ ...(options.checkers === undefined ? {} : SUGOROKU_CHECKER_SETS[options.checkers]),
43
+ ...options.colours,
44
+ };
45
+ return SUGOROKU_COLOUR_NAMES.filter((name) => colours[name] !== undefined)
46
+ .map((name) => `${colourProperty(name)}:${escapeXml(String(colours[name]))}`)
47
+ .join(";");
34
48
  }
35
49
  /** The words a screen reader hears of a drawing when none is given. */
36
50
  function describe(position) {
@@ -70,7 +84,7 @@ export function drawSugoroku(position, options = {}) {
70
84
  const mx = (x, w = 0) => layout.mx(x, w);
71
85
  const out = [];
72
86
  /** Text drawn upright whichever way the board is turned. */
73
- const text = (x, y, content, className, extra = "") => `<text class="${className}" x="${n(x)}" y="${n(y)}" text-anchor="middle" dominant-baseline="central"${portrait ? ` transform="rotate(-90 ${n(x)} ${n(y)})"` : ""}${extra}>${escape(content)}</text>`;
87
+ const text = (x, y, content, className, extra = "") => `<text class="${className}" x="${n(x)}" y="${n(y)}" text-anchor="middle" dominant-baseline="central"${portrait ? ` transform="rotate(-90 ${n(x)} ${n(y)})"` : ""}${extra}>${escapeXml(content)}</text>`;
74
88
  // The frame, the field of play, the bar, and the trays' wells.
75
89
  const field = { x: layout.fieldLeft, y: layout.fieldTop, w: 2 * POINT_WIDTH * 6 + BAR_WIDTH, h: layout.fieldHeight };
76
90
  out.push(`<rect class="sg-frame" x="0" y="0" width="${n(layout.width)}" height="${n(layout.height)}" rx="16"/>`);
@@ -80,7 +94,12 @@ export function drawSugoroku(position, options = {}) {
80
94
  out.push(`<rect class="sg-tray-well" x="${n(mx(layout.trayLeft, TRAY_WIDTH))}" y="${n(field.y)}" width="${TRAY_WIDTH}" height="${n(field.h)}" rx="4"/>`);
81
95
  // The points, with the highlight on the one picked up and on those it may go to.
82
96
  const mover = options.highlight?.side;
83
- const fromBoard = mover !== undefined && options.highlight?.from != null && options.highlight.from !== BAR && options.highlight.from > 0 ? boardPoint(spec, mover, options.highlight.from) : null;
97
+ const fromBoard = mover !== undefined &&
98
+ options.highlight?.from != null &&
99
+ options.highlight.from !== BAR &&
100
+ options.highlight.from > 0
101
+ ? boardPoint(spec, mover, options.highlight.from)
102
+ : null;
84
103
  const targetBoard = new Set();
85
104
  let offTarget = false;
86
105
  const movableBoard = new Set();
@@ -200,7 +219,7 @@ export function drawSugoroku(position, options = {}) {
200
219
  const colours = colourStyle(options);
201
220
  const theme = options.theme === undefined || options.theme === "auto" ? "" : ` data-theme="${options.theme}"`;
202
221
  const inline = options.style === true ? `<style>${SUGOROKU_STYLE}</style>` : "";
203
- return (`<svg xmlns="http://www.w3.org/2000/svg" class="sugoroku" viewBox="0 0 ${n(width)} ${n(height)}" role="img" aria-label="${escape(options.label ?? describe(position))}"` +
222
+ return (`<svg xmlns="http://www.w3.org/2000/svg" class="sugoroku" viewBox="0 0 ${n(width)} ${n(height)}" role="img" aria-label="${escapeXml(options.label ?? describe(position))}"` +
204
223
  ` data-orientation="${orientation}" data-view="${view}" data-home="${options.home ?? "right"}"${theme}${colours === "" ? "" : ` style="${colours}"`}>${inline}${root}</svg>`);
205
224
  }
206
225
  /** Half the strip above or below the points: where their numbers sit. */
package/dist/element.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { type SugorokuDrawOptions } from "./draw.ts";
2
- import { type Position } from "./board.ts";
1
+ import { SugorokuFrame } from "./elementFrame.ts";
3
2
  import type { GameState } from "./game.ts";
4
3
  import type { Match } from "./match.ts";
5
4
  import { type SugorokuMount, type SugorokuMountOptions } from "./mount.ts";
6
- import type { Side } from "./side.ts";
7
- import { type VariantKey } from "./variants.ts";
8
5
  /**
9
6
  * THE `<sugoroku-board>` ELEMENT: a playable backgammon board in a tag, with no
10
7
  * framework. `@johnmorrisdotca/sugoroku/element/define` defines it; this entry
@@ -33,21 +30,6 @@ import { type VariantKey } from "./variants.ts";
33
30
  * `nextGame`, `newMatch`, `record`) and the properties `game` and `match`. Nothing in it can be selected, and its box stays
34
31
  * one steady shape whatever is on the board.
35
32
  */
36
- declare const ElementBase: typeof HTMLElement;
37
- declare class SugorokuFrame extends ElementBase {
38
- #private;
39
- protected frame(): void;
40
- protected write(name: string, value: unknown): void;
41
- /** Symbolic display size, reflected. */
42
- get size(): string | null;
43
- set size(value: string | null);
44
- /** Pixel display width, reflected. */
45
- get width(): string | null;
46
- set width(value: string | number | null);
47
- /** Spoken group label, reflected. */
48
- get label(): string | null;
49
- set label(value: string | null);
50
- }
51
33
  /** The real mounted options, checked alongside builder coverage.
52
34
  * @example
53
35
  * ```ts
@@ -181,106 +163,5 @@ export declare class SugorokuBoard extends SugorokuFrame {
181
163
  * ```
182
164
  */
183
165
  export declare function defineBoard(tagName?: string, registry?: CustomElementRegistry | undefined): void;
184
- /**
185
- * Reads a GNU position ID or bounded JSON position; null means invalid counts or input.
186
- * @param text - Position ID, JSON position, or null for the variant's start.
187
- * @param variant - The native variant used for checker counts and layout.
188
- * @param turn - The on-roll side encoded by a GNU ID.
189
- * @returns A complete position, or null for malformed or inconsistent input.
190
- * @example
191
- * ```ts
192
- * import { readEmbedPosition } from "@johnmorrisdotca/sugoroku/element";
193
- * console.log(readEmbedPosition("4HPwATDgc/ABMA")?.points[0].length);
194
- * ```
195
- */
196
- export declare function readEmbedPosition(text: string | null, variant?: VariantKey, turn?: Side): Position | null;
197
- /** Host data and all native SVG drawing choices for a position.
198
- * @example
199
- * ```ts
200
- * import type { SugorokuPositionOptions } from "@johnmorrisdotca/sugoroku/element";
201
- * const options: SugorokuPositionOptions = {};
202
- * console.log(Object.keys(options).length); // 0
203
- * ```
204
- */
205
- export type SugorokuPositionOptions = SugorokuDrawOptions & {
206
- position?: Position;
207
- onChange?: (position: Position) => void;
208
- };
209
- /** Native draw keys, checked by the shared builder.
210
- * @example
211
- * ```ts
212
- * import { SUGOROKU_DRAW_OPTION_KEYS } from "@johnmorrisdotca/sugoroku/element";
213
- * console.log(typeof SUGOROKU_DRAW_OPTION_KEYS); // object
214
- * ```
215
- */
216
- export declare const SUGOROKU_DRAW_OPTION_KEYS: string[];
217
- /** All host position options, checked by the builder.
218
- * @example
219
- * ```ts
220
- * import { SUGOROKU_POSITION_OPTION_KEYS } from "@johnmorrisdotca/sugoroku/element";
221
- * console.log(typeof SUGOROKU_POSITION_OPTION_KEYS); // object
222
- * ```
223
- */
224
- export declare const SUGOROKU_POSITION_OPTION_KEYS: string[];
225
- /** A read-only backgammon position, drawn by the native SVG writer.
226
- * @example
227
- * ```ts
228
- * import { SugorokuPosition } from "@johnmorrisdotca/sugoroku/element";
229
- * console.log(SugorokuPosition.observedAttributes.includes("lang")); // true
230
- * ```
231
- */
232
- export declare class SugorokuPosition extends SugorokuFrame {
233
- #private;
234
- static observedAttributes: string[];
235
- /** Structured current position, or null after an input error. */
236
- get value(): Position | null;
237
- /** Native drawing options and trusted host position data. */
238
- get options(): SugorokuPositionOptions;
239
- set options(value: SugorokuPositionOptions);
240
- connectedCallback(): void;
241
- disconnectedCallback(): void;
242
- attributeChangedCallback(): void;
243
- /** Position ID or JSON, reflected. Assign an object to serialize it. */
244
- get position(): string | null;
245
- set position(value: string | Position | null);
246
- /** The `variant` attribute, reflected. */
247
- get variant(): string | null;
248
- set variant(value: string | number | boolean | null | undefined);
249
- /** The `turn` attribute, reflected. */
250
- get turn(): string | null;
251
- set turn(value: string | number | boolean | null | undefined);
252
- /** The `board` attribute, reflected. */
253
- get board(): string | null;
254
- set board(value: string | number | boolean | null | undefined);
255
- /** The `checkers` attribute, reflected. */
256
- get checkers(): string | null;
257
- set checkers(value: string | number | boolean | null | undefined);
258
- /** The `theme` attribute, reflected. */
259
- get theme(): string | null;
260
- set theme(value: string | number | boolean | null | undefined);
261
- /** The `home` attribute, reflected. */
262
- get home(): string | null;
263
- set home(value: string | number | boolean | null | undefined);
264
- /** The `view` attribute, reflected. */
265
- get view(): string | null;
266
- set view(value: string | number | boolean | null | undefined);
267
- /** The `numbers` attribute, reflected. */
268
- get numbers(): string | null;
269
- set numbers(value: string | number | boolean | null | undefined);
270
- /** The `orientation` attribute, reflected. */
271
- get orientation(): string | null;
272
- set orientation(value: string | number | boolean | null | undefined);
273
- }
274
- /** Defines a static position, or a subclass under a host's tag. Safe on a server.
275
- * @param tagName - The custom tag name; omitted to use the package default.
276
- * @param registry - The custom-element registry; omitted outside a browser.
277
- * @returns Nothing; existing definitions and server imports remain safe.
278
- * @example
279
- * ```ts
280
- * import { definePosition } from "@johnmorrisdotca/sugoroku/element";
281
- * definePosition();
282
- * console.log(typeof definePosition); // function
283
- * ```
284
- */
285
- export declare function definePosition(tagName?: string, registry?: CustomElementRegistry | undefined): void;
286
- export {};
166
+ export type { SugorokuPositionOptions } from "./positionElement.ts";
167
+ export { definePosition, readEmbedPosition, SUGOROKU_DRAW_OPTION_KEYS, SUGOROKU_POSITION_OPTION_KEYS, SugorokuPosition, } from "./positionElement.ts";