packing-bingo 0.1.1 → 0.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.
- package/README.md +293 -185
- package/dist/{chunk-ZDBGKPFF.js → chunk-Z34GMJW2.js} +208 -108
- package/dist/core.cjs +208 -108
- package/dist/core.d.cts +51 -11
- package/dist/core.d.ts +51 -11
- package/dist/core.js +3 -1
- package/dist/index.cjs +212 -111
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -5
- package/dist/packing-bingo.global.js +37 -33
- package/package.json +2 -2
package/dist/core.d.cts
CHANGED
|
@@ -3,13 +3,26 @@ interface BingoItem {
|
|
|
3
3
|
emoji: string;
|
|
4
4
|
label: string;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The default 16 school-trip items (Japanese), listed row by row from the top left.
|
|
8
|
+
* Smaller cards (`size` 2 or 3, without `items`) use the first ones.
|
|
9
|
+
* Labels keep each unbreakable run to about 6 characters so they fit the narrow (phone) card;
|
|
10
|
+
* `\u200B` marks where a longer label may wrap.
|
|
11
|
+
*/
|
|
7
12
|
declare const DEFAULT_ITEMS: readonly BingoItem[];
|
|
8
13
|
|
|
14
|
+
/**
|
|
15
|
+
* The winning lines of a size × size card, as indices into its items (row by row, skipping the
|
|
16
|
+
* FREE square): first the rows, then the columns, then the diagonal from the top left and the
|
|
17
|
+
* one from the top right. With `free`, the lines through the center have size − 1 items.
|
|
18
|
+
*/
|
|
19
|
+
declare function bingoLines(size: number, free?: boolean): number[][];
|
|
20
|
+
|
|
9
21
|
/** Every piece of UI text. Pass a partial object as `messages` to override some of them. */
|
|
10
22
|
interface Messages {
|
|
11
23
|
title: string;
|
|
12
24
|
tag: string;
|
|
25
|
+
/** A line under the title; empty (not shown) by default. */
|
|
13
26
|
subtitle: string;
|
|
14
27
|
packed: string;
|
|
15
28
|
bingo: string;
|
|
@@ -20,6 +33,8 @@ interface Messages {
|
|
|
20
33
|
soundOn: string;
|
|
21
34
|
soundOff: string;
|
|
22
35
|
stamp: string;
|
|
36
|
+
/** Text on the FREE square in the center (with `free`). */
|
|
37
|
+
free: string;
|
|
23
38
|
reachBadge: string;
|
|
24
39
|
reachPop: string;
|
|
25
40
|
bannerSingle: string;
|
|
@@ -27,6 +42,7 @@ interface Messages {
|
|
|
27
42
|
bannerTriple: string;
|
|
28
43
|
bannerNth: (totalLines: number) => string;
|
|
29
44
|
bannerMulti: (newLines: number) => string;
|
|
45
|
+
/** The status line before the first line is complete; empty by default. */
|
|
30
46
|
statusStart: (left: number) => string;
|
|
31
47
|
statusLines: (lines: number, left: number) => string;
|
|
32
48
|
/** `labels` are the items that would each complete a line right now. */
|
|
@@ -36,8 +52,8 @@ interface Messages {
|
|
|
36
52
|
/** Text inside the round stamp; `\n` starts a new line. */
|
|
37
53
|
perfectStamp: string;
|
|
38
54
|
perfectTitle: string;
|
|
39
|
-
/** `\n` starts a new line. */
|
|
40
|
-
perfectBody: string;
|
|
55
|
+
/** `\n` starts a new line. As a function, it gets the number of items on the card. */
|
|
56
|
+
perfectBody: string | ((total: number) => string);
|
|
41
57
|
perfectBonus: (points: number) => string;
|
|
42
58
|
statScore: string;
|
|
43
59
|
statCombo: string;
|
|
@@ -53,19 +69,26 @@ declare const ja: Messages;
|
|
|
53
69
|
/** English. */
|
|
54
70
|
declare const en: Messages;
|
|
55
71
|
|
|
56
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* The 10 winning lines of a 4×4 card: 4 rows, 4 columns, 2 diagonals (indices are row-major).
|
|
74
|
+
* For other sizes, use `bingoLines(size, free)`.
|
|
75
|
+
*/
|
|
57
76
|
declare const LINES: readonly (readonly number[])[];
|
|
58
77
|
interface PackingBingoState {
|
|
59
|
-
/**
|
|
78
|
+
/** One boolean per item, row by row (the FREE square is not included). */
|
|
60
79
|
checked: boolean[];
|
|
61
|
-
/**
|
|
80
|
+
/** The completed lines, as indices into `bingoLines(size, free)`. */
|
|
62
81
|
lines: number[];
|
|
63
82
|
score: number;
|
|
64
83
|
maxCombo: number;
|
|
65
84
|
complete: boolean;
|
|
85
|
+
/** Squares per side. */
|
|
86
|
+
size: number;
|
|
87
|
+
/** Whether the center is a FREE square. */
|
|
88
|
+
free: boolean;
|
|
66
89
|
}
|
|
67
90
|
interface BingoEvent {
|
|
68
|
-
/** Lines (indices into LINES) completed by this change. */
|
|
91
|
+
/** Lines (indices into `bingoLines(size, free)`, which is LINES for 4×4) completed by this change. */
|
|
69
92
|
newLines: number[];
|
|
70
93
|
totalLines: number;
|
|
71
94
|
score: number;
|
|
@@ -75,21 +98,38 @@ interface PerfectEvent {
|
|
|
75
98
|
maxCombo: number;
|
|
76
99
|
}
|
|
77
100
|
interface PackingBingoOptions {
|
|
78
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* One item per square, row by row (skipping the FREE square). Defaults to a Japanese
|
|
103
|
+
* school-trip list of 16. The count sets the size unless `size` is given: 9 → 3×3, 16 → 4×4.
|
|
104
|
+
*/
|
|
79
105
|
items?: readonly BingoItem[];
|
|
106
|
+
/**
|
|
107
|
+
* Squares per side, 2 to 10. By default it follows the number of items. Without `items`,
|
|
108
|
+
* a 2×2 or 3×3 card uses the first default items.
|
|
109
|
+
*/
|
|
110
|
+
size?: number;
|
|
111
|
+
/**
|
|
112
|
+
* Make the center a FREE square (odd sizes only): it is always stamped and counts toward the
|
|
113
|
+
* lines through it. `items`, `checked` and `defaultChecked` then have size² − 1 entries.
|
|
114
|
+
*/
|
|
115
|
+
free?: boolean;
|
|
80
116
|
/** Overrides for UI text. Start from `ja` (default) or `en`. */
|
|
81
117
|
messages?: Partial<Messages>;
|
|
82
118
|
title?: string;
|
|
83
119
|
tag?: string;
|
|
84
120
|
subtitle?: string;
|
|
85
|
-
/** Initial state (
|
|
121
|
+
/** Initial state (one boolean per item), used when nothing is saved under `storageKey`. */
|
|
86
122
|
defaultChecked?: readonly boolean[];
|
|
87
123
|
/**
|
|
88
124
|
* When true, taps don't change the card by themselves: they call `onChange` with the
|
|
89
125
|
* requested state, and the card only changes through `setChecked`. (React's `checked` prop.)
|
|
90
126
|
*/
|
|
91
127
|
controlled?: boolean;
|
|
92
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Where the checks are saved in localStorage. By default (omitted) a key derived from the
|
|
130
|
+
* items is used, so progress is saved automatically; pass a string to choose the key, or null
|
|
131
|
+
* to turn saving off. Ignored when controlled. Demo cards only save when given a key.
|
|
132
|
+
*/
|
|
93
133
|
storageKey?: string | null;
|
|
94
134
|
/** Start with sound on (default) or off. A choice made with the sound button is remembered. */
|
|
95
135
|
sound?: boolean;
|
|
@@ -120,5 +160,5 @@ interface PackingBingoInstance {
|
|
|
120
160
|
/** Render a packing bingo card into `container`. Call only in the browser. */
|
|
121
161
|
declare function createPackingBingo(container: HTMLElement, options?: PackingBingoOptions): PackingBingoInstance;
|
|
122
162
|
|
|
123
|
-
export { DEFAULT_ITEMS, LINES, createPackingBingo, en, ja };
|
|
163
|
+
export { DEFAULT_ITEMS, LINES, bingoLines, createPackingBingo, en, ja };
|
|
124
164
|
export type { BingoEvent, BingoItem, Messages, PackingBingoInstance, PackingBingoOptions, PackingBingoState, PerfectEvent };
|
package/dist/core.d.ts
CHANGED
|
@@ -3,13 +3,26 @@ interface BingoItem {
|
|
|
3
3
|
emoji: string;
|
|
4
4
|
label: string;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The default 16 school-trip items (Japanese), listed row by row from the top left.
|
|
8
|
+
* Smaller cards (`size` 2 or 3, without `items`) use the first ones.
|
|
9
|
+
* Labels keep each unbreakable run to about 6 characters so they fit the narrow (phone) card;
|
|
10
|
+
* `\u200B` marks where a longer label may wrap.
|
|
11
|
+
*/
|
|
7
12
|
declare const DEFAULT_ITEMS: readonly BingoItem[];
|
|
8
13
|
|
|
14
|
+
/**
|
|
15
|
+
* The winning lines of a size × size card, as indices into its items (row by row, skipping the
|
|
16
|
+
* FREE square): first the rows, then the columns, then the diagonal from the top left and the
|
|
17
|
+
* one from the top right. With `free`, the lines through the center have size − 1 items.
|
|
18
|
+
*/
|
|
19
|
+
declare function bingoLines(size: number, free?: boolean): number[][];
|
|
20
|
+
|
|
9
21
|
/** Every piece of UI text. Pass a partial object as `messages` to override some of them. */
|
|
10
22
|
interface Messages {
|
|
11
23
|
title: string;
|
|
12
24
|
tag: string;
|
|
25
|
+
/** A line under the title; empty (not shown) by default. */
|
|
13
26
|
subtitle: string;
|
|
14
27
|
packed: string;
|
|
15
28
|
bingo: string;
|
|
@@ -20,6 +33,8 @@ interface Messages {
|
|
|
20
33
|
soundOn: string;
|
|
21
34
|
soundOff: string;
|
|
22
35
|
stamp: string;
|
|
36
|
+
/** Text on the FREE square in the center (with `free`). */
|
|
37
|
+
free: string;
|
|
23
38
|
reachBadge: string;
|
|
24
39
|
reachPop: string;
|
|
25
40
|
bannerSingle: string;
|
|
@@ -27,6 +42,7 @@ interface Messages {
|
|
|
27
42
|
bannerTriple: string;
|
|
28
43
|
bannerNth: (totalLines: number) => string;
|
|
29
44
|
bannerMulti: (newLines: number) => string;
|
|
45
|
+
/** The status line before the first line is complete; empty by default. */
|
|
30
46
|
statusStart: (left: number) => string;
|
|
31
47
|
statusLines: (lines: number, left: number) => string;
|
|
32
48
|
/** `labels` are the items that would each complete a line right now. */
|
|
@@ -36,8 +52,8 @@ interface Messages {
|
|
|
36
52
|
/** Text inside the round stamp; `\n` starts a new line. */
|
|
37
53
|
perfectStamp: string;
|
|
38
54
|
perfectTitle: string;
|
|
39
|
-
/** `\n` starts a new line. */
|
|
40
|
-
perfectBody: string;
|
|
55
|
+
/** `\n` starts a new line. As a function, it gets the number of items on the card. */
|
|
56
|
+
perfectBody: string | ((total: number) => string);
|
|
41
57
|
perfectBonus: (points: number) => string;
|
|
42
58
|
statScore: string;
|
|
43
59
|
statCombo: string;
|
|
@@ -53,19 +69,26 @@ declare const ja: Messages;
|
|
|
53
69
|
/** English. */
|
|
54
70
|
declare const en: Messages;
|
|
55
71
|
|
|
56
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* The 10 winning lines of a 4×4 card: 4 rows, 4 columns, 2 diagonals (indices are row-major).
|
|
74
|
+
* For other sizes, use `bingoLines(size, free)`.
|
|
75
|
+
*/
|
|
57
76
|
declare const LINES: readonly (readonly number[])[];
|
|
58
77
|
interface PackingBingoState {
|
|
59
|
-
/**
|
|
78
|
+
/** One boolean per item, row by row (the FREE square is not included). */
|
|
60
79
|
checked: boolean[];
|
|
61
|
-
/**
|
|
80
|
+
/** The completed lines, as indices into `bingoLines(size, free)`. */
|
|
62
81
|
lines: number[];
|
|
63
82
|
score: number;
|
|
64
83
|
maxCombo: number;
|
|
65
84
|
complete: boolean;
|
|
85
|
+
/** Squares per side. */
|
|
86
|
+
size: number;
|
|
87
|
+
/** Whether the center is a FREE square. */
|
|
88
|
+
free: boolean;
|
|
66
89
|
}
|
|
67
90
|
interface BingoEvent {
|
|
68
|
-
/** Lines (indices into LINES) completed by this change. */
|
|
91
|
+
/** Lines (indices into `bingoLines(size, free)`, which is LINES for 4×4) completed by this change. */
|
|
69
92
|
newLines: number[];
|
|
70
93
|
totalLines: number;
|
|
71
94
|
score: number;
|
|
@@ -75,21 +98,38 @@ interface PerfectEvent {
|
|
|
75
98
|
maxCombo: number;
|
|
76
99
|
}
|
|
77
100
|
interface PackingBingoOptions {
|
|
78
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* One item per square, row by row (skipping the FREE square). Defaults to a Japanese
|
|
103
|
+
* school-trip list of 16. The count sets the size unless `size` is given: 9 → 3×3, 16 → 4×4.
|
|
104
|
+
*/
|
|
79
105
|
items?: readonly BingoItem[];
|
|
106
|
+
/**
|
|
107
|
+
* Squares per side, 2 to 10. By default it follows the number of items. Without `items`,
|
|
108
|
+
* a 2×2 or 3×3 card uses the first default items.
|
|
109
|
+
*/
|
|
110
|
+
size?: number;
|
|
111
|
+
/**
|
|
112
|
+
* Make the center a FREE square (odd sizes only): it is always stamped and counts toward the
|
|
113
|
+
* lines through it. `items`, `checked` and `defaultChecked` then have size² − 1 entries.
|
|
114
|
+
*/
|
|
115
|
+
free?: boolean;
|
|
80
116
|
/** Overrides for UI text. Start from `ja` (default) or `en`. */
|
|
81
117
|
messages?: Partial<Messages>;
|
|
82
118
|
title?: string;
|
|
83
119
|
tag?: string;
|
|
84
120
|
subtitle?: string;
|
|
85
|
-
/** Initial state (
|
|
121
|
+
/** Initial state (one boolean per item), used when nothing is saved under `storageKey`. */
|
|
86
122
|
defaultChecked?: readonly boolean[];
|
|
87
123
|
/**
|
|
88
124
|
* When true, taps don't change the card by themselves: they call `onChange` with the
|
|
89
125
|
* requested state, and the card only changes through `setChecked`. (React's `checked` prop.)
|
|
90
126
|
*/
|
|
91
127
|
controlled?: boolean;
|
|
92
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Where the checks are saved in localStorage. By default (omitted) a key derived from the
|
|
130
|
+
* items is used, so progress is saved automatically; pass a string to choose the key, or null
|
|
131
|
+
* to turn saving off. Ignored when controlled. Demo cards only save when given a key.
|
|
132
|
+
*/
|
|
93
133
|
storageKey?: string | null;
|
|
94
134
|
/** Start with sound on (default) or off. A choice made with the sound button is remembered. */
|
|
95
135
|
sound?: boolean;
|
|
@@ -120,5 +160,5 @@ interface PackingBingoInstance {
|
|
|
120
160
|
/** Render a packing bingo card into `container`. Call only in the browser. */
|
|
121
161
|
declare function createPackingBingo(container: HTMLElement, options?: PackingBingoOptions): PackingBingoInstance;
|
|
122
162
|
|
|
123
|
-
export { DEFAULT_ITEMS, LINES, createPackingBingo, en, ja };
|
|
163
|
+
export { DEFAULT_ITEMS, LINES, bingoLines, createPackingBingo, en, ja };
|
|
124
164
|
export type { BingoEvent, BingoItem, Messages, PackingBingoInstance, PackingBingoOptions, PackingBingoState, PerfectEvent };
|
package/dist/core.js
CHANGED