@kumix/ui 0.4.4 → 0.5.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 +14 -12
- package/dist/components/agents/approval-card/index.js +0 -1
- package/dist/components/agents/approval-card/index.js.map +1 -1
- package/dist/components/agents/prompt-input.js +0 -1
- package/dist/components/agents/prompt-input.js.map +1 -1
- package/dist/components/charts/bar-chart/context.d.ts.map +1 -1
- package/dist/components/charts/line-chart/context.d.ts.map +1 -1
- package/dist/components/charts/returns-calendar.d.ts.map +1 -1
- package/dist/components/charts/treemap.d.ts.map +1 -1
- package/dist/components/motion/bouncy-accordion.d.ts.map +1 -1
- package/dist/components/motion/bouncy-accordion.js +20 -34
- package/dist/components/motion/bouncy-accordion.js.map +1 -1
- package/dist/components/motion/crash/crash-balloon.d.ts +9 -0
- package/dist/components/motion/crash/crash-balloon.d.ts.map +1 -0
- package/dist/components/motion/crash/crash-balloon.js +829 -0
- package/dist/components/motion/crash/crash-balloon.js.map +1 -0
- package/dist/components/motion/crash/crash-parts.d.ts +59 -0
- package/dist/components/motion/crash/crash-parts.d.ts.map +1 -0
- package/dist/components/motion/crash/crash-parts.js +2 -0
- package/dist/components/motion/crash/crash-tower.d.ts +9 -0
- package/dist/components/motion/crash/crash-tower.d.ts.map +1 -0
- package/dist/components/motion/crash/crash-tower.js +370 -0
- package/dist/components/motion/crash/crash-tower.js.map +1 -0
- package/dist/components/motion/crash.d.ts +9 -0
- package/dist/components/motion/crash.d.ts.map +1 -0
- package/dist/components/motion/crash.js +590 -0
- package/dist/components/motion/crash.js.map +1 -0
- package/dist/components/motion/feedback-widget.js +0 -1
- package/dist/components/motion/feedback-widget.js.map +1 -1
- package/dist/components/motion/liquid.js +2 -2
- package/dist/components/motion/liquid.js.map +1 -1
- package/dist/components/motion/mines.d.ts +41 -0
- package/dist/components/motion/mines.d.ts.map +1 -0
- package/dist/components/motion/mines.js +762 -0
- package/dist/components/motion/mines.js.map +1 -0
- package/dist/components/motion/plinko.d.ts +59 -0
- package/dist/components/motion/plinko.d.ts.map +1 -0
- package/dist/components/motion/plinko.js +385 -0
- package/dist/components/motion/plinko.js.map +1 -0
- package/dist/components/motion/signup-form.js +0 -1
- package/dist/components/motion/signup-form.js.map +1 -1
- package/dist/components/motion/swap.d.ts +1 -1
- package/dist/components/motion/tooltip.d.ts +2 -2
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/wallet-card/index.js +0 -1
- package/dist/components/motion/wallet-card/index.js.map +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/code-block/code-block.d.ts +1 -0
- package/dist/components/reui/code-block/code-block.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/reui/tree.d.ts +1 -0
- package/dist/components/reui/tree.d.ts.map +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/empty.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/crash-parts-CUv5gFYQ.js +1053 -0
- package/dist/crash-parts-CUv5gFYQ.js.map +1 -0
- package/dist/{ease-CHhXKlG3.d.ts → ease-DjhlGGZO.d.ts} +4 -2
- package/dist/ease-DjhlGGZO.d.ts.map +1 -0
- package/dist/hooks/use-highlighted-code.d.ts +1 -1
- package/dist/hooks/use-highlighted-code.d.ts.map +1 -1
- package/dist/lib/audio-context.d.ts +11 -0
- package/dist/lib/audio-context.d.ts.map +1 -0
- package/dist/lib/audio-context.js +37 -0
- package/dist/lib/audio-context.js.map +1 -0
- package/dist/lib/ease.d.ts +2 -2
- package/dist/lib/ease.js +8 -1
- package/dist/lib/ease.js.map +1 -1
- package/dist/lib/game-sounds.d.ts +18 -0
- package/dist/lib/game-sounds.d.ts.map +1 -0
- package/dist/lib/game-sounds.js +142 -0
- package/dist/lib/game-sounds.js.map +1 -0
- package/dist/lib/tick-sound.d.ts +4 -3
- package/dist/lib/tick-sound.d.ts.map +1 -1
- package/dist/lib/tick-sound.js +30 -37
- package/dist/lib/tick-sound.js.map +1 -1
- package/dist/tooltip-CNEYdIX3.d.ts.map +1 -1
- package/dist/use-crash-game-B3RHxFkm.d.ts +108 -0
- package/dist/use-crash-game-B3RHxFkm.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/ease-CHhXKlG3.d.ts.map +0 -1
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { EASE_OUT } from "../../lib/ease.js";
|
|
3
|
+
import { createGameSounds } from "../../lib/game-sounds.js";
|
|
4
|
+
import { t as PresenceGate } from "../../presence-gate-DC7yL1Ls.js";
|
|
5
|
+
import { ActionSwapCascadeIcon } from "./action-swap-cascade.js";
|
|
6
|
+
import { AdaptiveStepper, AdaptiveStepperDecrement, AdaptiveStepperIncrement, AdaptiveStepperValue } from "./adaptive-stepper.js";
|
|
7
|
+
import { Button } from "./button/base.js";
|
|
8
|
+
import { NumberTicker } from "./number-ticker.js";
|
|
9
|
+
import { t as Tooltip } from "../../tooltip-CuHpilPN.js";
|
|
10
|
+
import { useEffect, useRef, useState } from "react";
|
|
11
|
+
import { cn } from "@kumix/utils";
|
|
12
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { AnimatePresence, motion, useAnimate, useReducedMotion } from "motion/react";
|
|
14
|
+
import { Gem, Volume2, VolumeX } from "lucide-react";
|
|
15
|
+
// src/components/motion/mines.tsx
|
|
16
|
+
/**
|
|
17
|
+
* Fair payout after `gems` safe picks on a board of `tiles` with `mines`:
|
|
18
|
+
* the inverse of the chance of picking that many gems in a row. `mines` is
|
|
19
|
+
* kept between 0 and tiles − 1 and `gems` between 0 and the safe tiles, so
|
|
20
|
+
* the result is always finite.
|
|
21
|
+
*/
|
|
22
|
+
function minesMultiplier(tiles, mines, gems) {
|
|
23
|
+
const safeMines = Math.max(0, Math.min(Math.round(mines), tiles - 1));
|
|
24
|
+
const safeGems = Math.max(0, Math.min(Math.round(gems), tiles - safeMines));
|
|
25
|
+
let multiplier = 1;
|
|
26
|
+
for (let i = 0; i < safeGems; i++) multiplier *= (tiles - i) / (tiles - safeMines - i);
|
|
27
|
+
return multiplier;
|
|
28
|
+
}
|
|
29
|
+
const ICON_SPRING = {
|
|
30
|
+
type: "spring",
|
|
31
|
+
duration: .3,
|
|
32
|
+
bounce: 0
|
|
33
|
+
};
|
|
34
|
+
const RIPPLE_STEP = .025;
|
|
35
|
+
const SHAKE = {
|
|
36
|
+
duration: .3,
|
|
37
|
+
ease: EASE_OUT
|
|
38
|
+
};
|
|
39
|
+
const GEM_POP = {
|
|
40
|
+
type: "spring",
|
|
41
|
+
duration: .35,
|
|
42
|
+
bounce: .4
|
|
43
|
+
};
|
|
44
|
+
const PULSE_STEP = .04;
|
|
45
|
+
const PULSE_TIME = .35;
|
|
46
|
+
const EXIT = {
|
|
47
|
+
duration: .12,
|
|
48
|
+
ease: EASE_OUT
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A mines board: pick tiles to find gems, each raising the multiplier, and
|
|
52
|
+
* cash out before you hit a mine. The round's end reveals every tile.
|
|
53
|
+
*/
|
|
54
|
+
function Mines({ size: sizeProp = 5, mines: minesProp, defaultMines = 3, onMinesChange, onReveal, onCashOut, sound, defaultSound = false, onSoundChange, showResult = true, "aria-label": ariaLabel = "Mines", className }) {
|
|
55
|
+
const reduce = useReducedMotion() ?? false;
|
|
56
|
+
const size = Math.max(2, Math.round(sizeProp) || 2);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (process.env.NODE_ENV !== "production" && size !== sizeProp) console.warn(`Mines: size must be a whole number of at least 2; using ${size}.`);
|
|
59
|
+
}, [size, sizeProp]);
|
|
60
|
+
const tiles = size * size;
|
|
61
|
+
const [internalMines, setInternalMines] = useState(defaultMines);
|
|
62
|
+
const chosenMines = Math.min(Math.max(1, Math.round(minesProp ?? internalMines) || 1), tiles - 1);
|
|
63
|
+
const [phase, setPhase] = useState("idle");
|
|
64
|
+
const [mineSet, setMineSet] = useState(/* @__PURE__ */ new Set());
|
|
65
|
+
const [picked, setPicked] = useState([]);
|
|
66
|
+
const [cursor, setCursor] = useState(0);
|
|
67
|
+
const [announcement, setAnnouncement] = useState("");
|
|
68
|
+
const [resultOpen, setResultOpen] = useState(false);
|
|
69
|
+
const sectionRef = useRef(null);
|
|
70
|
+
const mainButtonRef = useRef(null);
|
|
71
|
+
const tileRefs = useRef([]);
|
|
72
|
+
const [, animate] = useAnimate();
|
|
73
|
+
const resetBoard = () => {
|
|
74
|
+
setPhase("idle");
|
|
75
|
+
setPicked([]);
|
|
76
|
+
setMineSet(/* @__PURE__ */ new Set());
|
|
77
|
+
setResultOpen(false);
|
|
78
|
+
};
|
|
79
|
+
const [boardSize, setBoardSize] = useState(size);
|
|
80
|
+
if (boardSize !== size) {
|
|
81
|
+
setBoardSize(size);
|
|
82
|
+
resetBoard();
|
|
83
|
+
setCursor(0);
|
|
84
|
+
}
|
|
85
|
+
const mines = phase === "idle" ? chosenMines : mineSet.size;
|
|
86
|
+
const gems = picked.filter((tile) => !mineSet.has(tile)).length;
|
|
87
|
+
const multiplier = minesMultiplier(tiles, mines, gems);
|
|
88
|
+
const next = minesMultiplier(tiles, mines, gems + 1);
|
|
89
|
+
const over = phase === "busted" || phase === "cashed";
|
|
90
|
+
const safe = (tiles - mines - gems) / (tiles - gems);
|
|
91
|
+
const lastPick = picked.at(-1) ?? Math.floor(tiles / 2);
|
|
92
|
+
const resultShown = resultOpen && showResult && over;
|
|
93
|
+
const [internalSound, setInternalSound] = useState(defaultSound);
|
|
94
|
+
const soundOn = sound ?? internalSound;
|
|
95
|
+
const player = useRef(null);
|
|
96
|
+
const getPlayer = () => {
|
|
97
|
+
if (!player.current) player.current = createGameSounds();
|
|
98
|
+
return player.current;
|
|
99
|
+
};
|
|
100
|
+
useEffect(() => () => {
|
|
101
|
+
player.current?.dispose();
|
|
102
|
+
player.current = null;
|
|
103
|
+
}, []);
|
|
104
|
+
const setMines = (value) => {
|
|
105
|
+
if (over) resetBoard();
|
|
106
|
+
if (minesProp === void 0) setInternalMines(value);
|
|
107
|
+
onMinesChange?.(value);
|
|
108
|
+
};
|
|
109
|
+
const closeResult = () => {
|
|
110
|
+
setResultOpen(false);
|
|
111
|
+
mainButtonRef.current?.focus();
|
|
112
|
+
};
|
|
113
|
+
const start = () => {
|
|
114
|
+
resetBoard();
|
|
115
|
+
const order = Array.from({ length: tiles }, (_, i) => i);
|
|
116
|
+
for (let i = order.length - 1; i > 0; i--) {
|
|
117
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
118
|
+
[order[i], order[j]] = [order[j], order[i]];
|
|
119
|
+
}
|
|
120
|
+
setMineSet(new Set(order.slice(0, chosenMines)));
|
|
121
|
+
setPhase("playing");
|
|
122
|
+
if (!reduce) tileRefs.current.forEach((tile, index) => {
|
|
123
|
+
if (!tile) return;
|
|
124
|
+
const wave = Math.floor(index / size) + index % size;
|
|
125
|
+
animate(tile, {
|
|
126
|
+
scale: [.94, 1],
|
|
127
|
+
opacity: [.5, 1]
|
|
128
|
+
}, {
|
|
129
|
+
duration: .2,
|
|
130
|
+
delay: wave * .025,
|
|
131
|
+
ease: EASE_OUT
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
setAnnouncement(`Round started with ${chosenMines} ${chosenMines === 1 ? "mine" : "mines"}.`);
|
|
135
|
+
if (soundOn) getPlayer().prepare();
|
|
136
|
+
};
|
|
137
|
+
const cashOut = (finalGems = gems) => {
|
|
138
|
+
if (phase !== "playing" || finalGems === 0) return;
|
|
139
|
+
const value = minesMultiplier(tiles, mines, finalGems);
|
|
140
|
+
setPhase("cashed");
|
|
141
|
+
setAnnouncement(`Cashed out at ${formatMultiplier(value)}.`);
|
|
142
|
+
if (soundOn) getPlayer().cashOut();
|
|
143
|
+
onCashOut?.(value, finalGems);
|
|
144
|
+
};
|
|
145
|
+
const pick = (tile) => {
|
|
146
|
+
if (phase !== "playing" || picked.includes(tile)) return;
|
|
147
|
+
setPicked((current) => [...current, tile]);
|
|
148
|
+
if (mineSet.has(tile)) {
|
|
149
|
+
setPhase("busted");
|
|
150
|
+
setAnnouncement("Mine. The round is over.");
|
|
151
|
+
if (soundOn) getPlayer().mine();
|
|
152
|
+
onReveal?.(tile, "mine", 0);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const found = gems + 1;
|
|
156
|
+
const node = tileRefs.current[tile];
|
|
157
|
+
if (node && !reduce) animate(node, { scale: [.92, 1] }, GEM_POP);
|
|
158
|
+
const value = minesMultiplier(tiles, mines, found);
|
|
159
|
+
if (soundOn) getPlayer().gem(found);
|
|
160
|
+
onReveal?.(tile, "gem", value);
|
|
161
|
+
if (found === tiles - mines) {
|
|
162
|
+
cashOut(found);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
setAnnouncement(`Gem. ${formatMultiplier(value)}.`);
|
|
166
|
+
};
|
|
167
|
+
const onKeyDown = (event, tile) => {
|
|
168
|
+
const row = Math.floor(tile / size);
|
|
169
|
+
const col = tile % size;
|
|
170
|
+
const target = {
|
|
171
|
+
ArrowRight: row * size + Math.min(size - 1, col + 1),
|
|
172
|
+
ArrowLeft: row * size + Math.max(0, col - 1),
|
|
173
|
+
ArrowDown: Math.min(size - 1, row + 1) * size + col,
|
|
174
|
+
ArrowUp: Math.max(0, row - 1) * size + col,
|
|
175
|
+
Home: row * size,
|
|
176
|
+
End: row * size + size - 1
|
|
177
|
+
}[event.key];
|
|
178
|
+
if (target === void 0) return;
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
setCursor(target);
|
|
181
|
+
tileRefs.current[target]?.focus();
|
|
182
|
+
};
|
|
183
|
+
let closingEnd = 0;
|
|
184
|
+
if (over) for (let tile = 0; tile < tiles; tile++) {
|
|
185
|
+
const order = picked.indexOf(tile);
|
|
186
|
+
const end = order === -1 ? ringFrom(lastPick, tile, size) * RIPPLE_STEP + ICON_SPRING.duration : phase === "cashed" && !reduce ? order * PULSE_STEP + PULSE_TIME : 0;
|
|
187
|
+
closingEnd = Math.max(closingEnd, end);
|
|
188
|
+
}
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
if (!over || !showResult) return;
|
|
191
|
+
const id = setTimeout(() => {
|
|
192
|
+
if (sectionRef.current?.contains(document.activeElement)) mainButtonRef.current?.focus({ preventScroll: true });
|
|
193
|
+
setResultOpen(true);
|
|
194
|
+
}, closingEnd * 1e3);
|
|
195
|
+
return () => clearTimeout(id);
|
|
196
|
+
}, [
|
|
197
|
+
over,
|
|
198
|
+
showResult,
|
|
199
|
+
closingEnd
|
|
200
|
+
]);
|
|
201
|
+
const toggleSound = () => {
|
|
202
|
+
const nextSound = !soundOn;
|
|
203
|
+
if (nextSound) getPlayer().prepare();
|
|
204
|
+
if (sound === void 0) setInternalSound(nextSound);
|
|
205
|
+
onSoundChange?.(nextSound);
|
|
206
|
+
};
|
|
207
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
208
|
+
ref: sectionRef,
|
|
209
|
+
"aria-label": ariaLabel,
|
|
210
|
+
className: cn("flex w-full max-w-md flex-col gap-4", className),
|
|
211
|
+
onKeyDown: (event) => {
|
|
212
|
+
if (event.key !== "Escape" || !resultShown) return;
|
|
213
|
+
event.stopPropagation();
|
|
214
|
+
closeResult();
|
|
215
|
+
},
|
|
216
|
+
children: [
|
|
217
|
+
/* @__PURE__ */ jsxs("div", {
|
|
218
|
+
className: "flex flex-wrap items-center justify-between gap-3",
|
|
219
|
+
children: [/* @__PURE__ */ jsxs(AdaptiveStepper, {
|
|
220
|
+
value: chosenMines,
|
|
221
|
+
onValueChange: setMines,
|
|
222
|
+
min: 1,
|
|
223
|
+
max: tiles - 1,
|
|
224
|
+
disabled: phase === "playing",
|
|
225
|
+
formatValueText: (value) => `${value} ${value === 1 ? "mine" : "mines"}`,
|
|
226
|
+
"aria-label": "Mine count",
|
|
227
|
+
children: [
|
|
228
|
+
/* @__PURE__ */ jsx(AdaptiveStepperDecrement, {}),
|
|
229
|
+
/* @__PURE__ */ jsx(AdaptiveStepperValue, { children: (value) => /* @__PURE__ */ jsxs("span", {
|
|
230
|
+
className: "inline-flex items-center gap-1.5",
|
|
231
|
+
children: [/* @__PURE__ */ jsx(MineIcon, { className: "text-muted-foreground size-4" }), value]
|
|
232
|
+
}) }),
|
|
233
|
+
/* @__PURE__ */ jsx(AdaptiveStepperIncrement, {})
|
|
234
|
+
]
|
|
235
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
236
|
+
className: "text-right",
|
|
237
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
238
|
+
className: "text-foreground text-2xl font-semibold",
|
|
239
|
+
children: phase === "busted" ? /* @__PURE__ */ jsx("span", {
|
|
240
|
+
className: "text-muted-foreground tabular-nums line-through decoration-2",
|
|
241
|
+
children: formatMultiplier(multiplier)
|
|
242
|
+
}) : /* @__PURE__ */ jsx(NumberTicker, {
|
|
243
|
+
value: multiplier,
|
|
244
|
+
decimals: 2,
|
|
245
|
+
format: compact,
|
|
246
|
+
suffix: "×",
|
|
247
|
+
startOnView: false,
|
|
248
|
+
duration: .35
|
|
249
|
+
})
|
|
250
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
251
|
+
className: "text-muted-foreground flex items-center justify-end gap-1.5 text-xs tabular-nums",
|
|
252
|
+
children: over ? phase === "busted" ? "Multiplier lost" : "Multiplier" : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(OddsRing, {
|
|
253
|
+
safe,
|
|
254
|
+
reduce
|
|
255
|
+
}), phase === "playing" ? `${Math.round(safe * 100)}% safe · next ${formatMultiplier(next)}` : `First pick ${Math.round(safe * 100)}% safe`] })
|
|
256
|
+
})]
|
|
257
|
+
})]
|
|
258
|
+
}),
|
|
259
|
+
/* @__PURE__ */ jsxs("div", {
|
|
260
|
+
className: "bg-muted/40 relative rounded-3xl p-3",
|
|
261
|
+
children: [/* @__PURE__ */ jsxs("fieldset", {
|
|
262
|
+
inert: resultShown,
|
|
263
|
+
className: "m-0 grid min-w-0 gap-2 border-0 p-0",
|
|
264
|
+
style: { gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))` },
|
|
265
|
+
children: [/* @__PURE__ */ jsx("legend", {
|
|
266
|
+
className: "sr-only",
|
|
267
|
+
children: "Tiles"
|
|
268
|
+
}), Array.from({ length: tiles }, (_, tile) => {
|
|
269
|
+
const isPicked = picked.includes(tile);
|
|
270
|
+
const isMine = mineSet.has(tile);
|
|
271
|
+
const shown = isPicked || over;
|
|
272
|
+
const content = shown ? isMine ? "mine" : "gem" : null;
|
|
273
|
+
const hit = isPicked && isMine;
|
|
274
|
+
const row = Math.floor(tile / size);
|
|
275
|
+
const col = tile % size;
|
|
276
|
+
const ripple = ringFrom(lastPick, tile, size);
|
|
277
|
+
const order = picked.indexOf(tile);
|
|
278
|
+
const celebrate = phase === "cashed" && isPicked && !reduce;
|
|
279
|
+
const interactive = phase === "playing" && !isPicked;
|
|
280
|
+
return /* @__PURE__ */ jsxs(motion.button, {
|
|
281
|
+
ref: (node) => {
|
|
282
|
+
tileRefs.current[tile] = node;
|
|
283
|
+
},
|
|
284
|
+
type: "button",
|
|
285
|
+
tabIndex: tile === cursor ? 0 : -1,
|
|
286
|
+
"aria-disabled": !interactive,
|
|
287
|
+
"aria-label": `Row ${row + 1}, column ${col + 1}, ${tileState(content, isPicked, order)}`,
|
|
288
|
+
onFocus: () => setCursor(tile),
|
|
289
|
+
onClick: () => pick(tile),
|
|
290
|
+
onKeyDown: (event) => onKeyDown(event, tile),
|
|
291
|
+
animate: hit && !reduce ? { x: [
|
|
292
|
+
0,
|
|
293
|
+
-5,
|
|
294
|
+
5,
|
|
295
|
+
-3,
|
|
296
|
+
3,
|
|
297
|
+
0
|
|
298
|
+
] } : { x: 0 },
|
|
299
|
+
transition: SHAKE,
|
|
300
|
+
className: cn("relative grid aspect-square place-items-center rounded-xl border outline-none", hit && "z-10", "transition-[translate,scale,background-color,border-color] duration-150 ease-out", "focus-visible:ring-ring focus-visible:ring-2", interactive ? "border-border bg-card cursor-pointer hover:-translate-y-0.5 hover:border-(--color-border-strong) active:scale-[0.96]" : "cursor-default border-transparent", !interactive && !shown && "bg-card/60", content === "gem" && (isPicked ? "bg-primary/15" : "bg-card/40"), content === "mine" && (hit ? "bg-rose-500/20" : "bg-card/40")),
|
|
301
|
+
children: [
|
|
302
|
+
hit && !reduce ? /* @__PURE__ */ jsx(motion.span, {
|
|
303
|
+
"aria-hidden": "true",
|
|
304
|
+
className: "pointer-events-none absolute inset-0 rounded-xl border-2 border-rose-500",
|
|
305
|
+
initial: {
|
|
306
|
+
scale: 1,
|
|
307
|
+
opacity: .7
|
|
308
|
+
},
|
|
309
|
+
animate: {
|
|
310
|
+
scale: 1.7,
|
|
311
|
+
opacity: 0
|
|
312
|
+
},
|
|
313
|
+
transition: {
|
|
314
|
+
duration: .45,
|
|
315
|
+
ease: EASE_OUT
|
|
316
|
+
}
|
|
317
|
+
}) : null,
|
|
318
|
+
isPicked && !isMine ? /* @__PURE__ */ jsx(motion.span, {
|
|
319
|
+
"aria-hidden": "true",
|
|
320
|
+
initial: { opacity: 0 },
|
|
321
|
+
animate: { opacity: 1 },
|
|
322
|
+
transition: {
|
|
323
|
+
duration: .15,
|
|
324
|
+
ease: EASE_OUT,
|
|
325
|
+
delay: .1
|
|
326
|
+
},
|
|
327
|
+
className: "text-primary/70 absolute top-1.5 left-2 text-[10px] font-medium tabular-nums",
|
|
328
|
+
children: order + 1
|
|
329
|
+
}) : null,
|
|
330
|
+
/* @__PURE__ */ jsx(AnimatePresence, {
|
|
331
|
+
initial: false,
|
|
332
|
+
children: content ? /* @__PURE__ */ jsx(motion.span, {
|
|
333
|
+
"aria-hidden": "true",
|
|
334
|
+
initial: reduce ? { opacity: 0 } : {
|
|
335
|
+
opacity: 0,
|
|
336
|
+
scale: .25,
|
|
337
|
+
filter: "blur(4px)"
|
|
338
|
+
},
|
|
339
|
+
animate: celebrate ? {
|
|
340
|
+
opacity: 1,
|
|
341
|
+
scale: [
|
|
342
|
+
1,
|
|
343
|
+
1.2,
|
|
344
|
+
1
|
|
345
|
+
],
|
|
346
|
+
filter: "blur(0px)"
|
|
347
|
+
} : {
|
|
348
|
+
opacity: isPicked ? 1 : .4,
|
|
349
|
+
scale: 1,
|
|
350
|
+
filter: "blur(0px)"
|
|
351
|
+
},
|
|
352
|
+
exit: reduce ? {
|
|
353
|
+
opacity: 0,
|
|
354
|
+
transition: EXIT
|
|
355
|
+
} : {
|
|
356
|
+
opacity: 0,
|
|
357
|
+
scale: .9,
|
|
358
|
+
transition: EXIT
|
|
359
|
+
},
|
|
360
|
+
transition: celebrate ? {
|
|
361
|
+
duration: PULSE_TIME,
|
|
362
|
+
ease: EASE_OUT,
|
|
363
|
+
delay: order * PULSE_STEP
|
|
364
|
+
} : {
|
|
365
|
+
...ICON_SPRING,
|
|
366
|
+
delay: isPicked ? 0 : ripple * RIPPLE_STEP
|
|
367
|
+
},
|
|
368
|
+
className: cn("grid place-items-center", content === "gem" ? "text-primary" : "text-rose-500 dark:text-rose-400"),
|
|
369
|
+
children: content === "gem" ? /* @__PURE__ */ jsx(Gem, {
|
|
370
|
+
className: "size-[45%] min-h-5 min-w-5",
|
|
371
|
+
strokeWidth: 2
|
|
372
|
+
}) : /* @__PURE__ */ jsx(MineIcon, { className: "size-[45%] min-h-5 min-w-5" })
|
|
373
|
+
}, content) : null
|
|
374
|
+
})
|
|
375
|
+
]
|
|
376
|
+
}, tile);
|
|
377
|
+
})]
|
|
378
|
+
}), /* @__PURE__ */ jsx(AnimatePresence, { children: resultShown ? /* @__PURE__ */ jsx(PresenceGate, { children: ({ gate }) => /* @__PURE__ */ jsx(ResultCard, {
|
|
379
|
+
gate,
|
|
380
|
+
outcome: phase === "cashed" ? "cashed" : "busted",
|
|
381
|
+
multiplier,
|
|
382
|
+
gems,
|
|
383
|
+
safeTiles: tiles - mines,
|
|
384
|
+
mines,
|
|
385
|
+
size,
|
|
386
|
+
picked,
|
|
387
|
+
mineSet,
|
|
388
|
+
reduce,
|
|
389
|
+
onClose: closeResult
|
|
390
|
+
}) }, "result") : null })]
|
|
391
|
+
}),
|
|
392
|
+
/* @__PURE__ */ jsxs("div", {
|
|
393
|
+
className: "flex items-center gap-2",
|
|
394
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
395
|
+
ref: mainButtonRef,
|
|
396
|
+
className: "flex-1 aria-disabled:cursor-not-allowed aria-disabled:opacity-50",
|
|
397
|
+
pressScale: .96,
|
|
398
|
+
"aria-disabled": phase === "playing" && gems === 0 || void 0,
|
|
399
|
+
onClick: () => phase === "playing" ? cashOut() : start(),
|
|
400
|
+
children: phase === "playing" ? `Cash out ${formatMultiplier(multiplier)}` : over ? "Play again" : "Start"
|
|
401
|
+
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
402
|
+
content: "Sound",
|
|
403
|
+
side: "top",
|
|
404
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
405
|
+
variant: "secondary",
|
|
406
|
+
onClick: toggleSound,
|
|
407
|
+
"aria-label": "Sound",
|
|
408
|
+
"aria-pressed": soundOn,
|
|
409
|
+
pressScale: .96,
|
|
410
|
+
className: cn("w-10 px-0", soundOn ? "text-foreground" : "text-muted-foreground"),
|
|
411
|
+
children: /* @__PURE__ */ jsx(ActionSwapCascadeIcon, {
|
|
412
|
+
value: soundOn ? "on" : "off",
|
|
413
|
+
className: "size-4",
|
|
414
|
+
children: soundOn ? /* @__PURE__ */ jsx(Volume2, {
|
|
415
|
+
"aria-hidden": "true",
|
|
416
|
+
className: "size-4"
|
|
417
|
+
}) : /* @__PURE__ */ jsx(VolumeX, {
|
|
418
|
+
"aria-hidden": "true",
|
|
419
|
+
className: "size-4"
|
|
420
|
+
})
|
|
421
|
+
})
|
|
422
|
+
})
|
|
423
|
+
})]
|
|
424
|
+
}),
|
|
425
|
+
/* @__PURE__ */ jsx("p", {
|
|
426
|
+
"aria-live": "polite",
|
|
427
|
+
className: "sr-only",
|
|
428
|
+
children: announcement
|
|
429
|
+
})
|
|
430
|
+
]
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
const TEAR = 104;
|
|
434
|
+
const NOTCH_MASK = `radial-gradient(circle 9px at 0 ${TEAR}px, transparent 98%, black), radial-gradient(circle 9px at 100% ${TEAR}px, transparent 98%, black)`;
|
|
435
|
+
const CARD_IN = {
|
|
436
|
+
type: "spring",
|
|
437
|
+
duration: .4,
|
|
438
|
+
bounce: .15
|
|
439
|
+
};
|
|
440
|
+
const CARD_OUT = {
|
|
441
|
+
duration: .15,
|
|
442
|
+
ease: EASE_OUT
|
|
443
|
+
};
|
|
444
|
+
/**
|
|
445
|
+
* The end-of-round summary over a dimmed board. It has no buttons: the main
|
|
446
|
+
* action below the board already says Play again, and tapping anywhere on
|
|
447
|
+
* the board (or Escape) puts the card away to study the board.
|
|
448
|
+
*/
|
|
449
|
+
function ResultCard(props) {
|
|
450
|
+
const { gate, reduce, onClose } = props;
|
|
451
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(motion.button, {
|
|
452
|
+
type: "button",
|
|
453
|
+
"aria-label": "Hide result and show the board",
|
|
454
|
+
onClick: onClose,
|
|
455
|
+
...gate,
|
|
456
|
+
className: "bg-background/55 focus-visible:ring-ring absolute inset-0 z-20 cursor-default rounded-3xl backdrop-blur-[2px] outline-none focus-visible:ring-2",
|
|
457
|
+
initial: { opacity: 0 },
|
|
458
|
+
animate: { opacity: 1 },
|
|
459
|
+
exit: {
|
|
460
|
+
opacity: 0,
|
|
461
|
+
transition: CARD_OUT
|
|
462
|
+
},
|
|
463
|
+
transition: {
|
|
464
|
+
duration: .2,
|
|
465
|
+
ease: EASE_OUT
|
|
466
|
+
}
|
|
467
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
468
|
+
inert: gate.inert,
|
|
469
|
+
className: "pointer-events-none absolute inset-0 z-20 grid place-items-center p-4",
|
|
470
|
+
children: /* @__PURE__ */ jsx(motion.div, {
|
|
471
|
+
role: "group",
|
|
472
|
+
"aria-label": "Round result",
|
|
473
|
+
className: cn("w-full max-w-[17rem]", TICKET_SHADOW),
|
|
474
|
+
initial: reduce ? { opacity: 0 } : {
|
|
475
|
+
opacity: 0,
|
|
476
|
+
y: 16,
|
|
477
|
+
scale: .96
|
|
478
|
+
},
|
|
479
|
+
animate: {
|
|
480
|
+
opacity: 1,
|
|
481
|
+
y: 0,
|
|
482
|
+
scale: 1
|
|
483
|
+
},
|
|
484
|
+
exit: reduce ? {
|
|
485
|
+
opacity: 0,
|
|
486
|
+
transition: CARD_OUT
|
|
487
|
+
} : {
|
|
488
|
+
opacity: 0,
|
|
489
|
+
y: 8,
|
|
490
|
+
scale: .98,
|
|
491
|
+
transition: CARD_OUT
|
|
492
|
+
},
|
|
493
|
+
transition: reduce ? { duration: .2 } : CARD_IN,
|
|
494
|
+
children: /* @__PURE__ */ jsx(Ticket, { ...props })
|
|
495
|
+
})
|
|
496
|
+
})] });
|
|
497
|
+
}
|
|
498
|
+
const STAGE = {
|
|
499
|
+
duration: .25,
|
|
500
|
+
ease: EASE_OUT
|
|
501
|
+
};
|
|
502
|
+
const REPLAY_START = .3;
|
|
503
|
+
const REPLAY_STEP = .05;
|
|
504
|
+
const CELL_SPRING = {
|
|
505
|
+
type: "spring",
|
|
506
|
+
duration: .3,
|
|
507
|
+
bounce: .3
|
|
508
|
+
};
|
|
509
|
+
function Stage({ delay, reduce, className, children }) {
|
|
510
|
+
return /* @__PURE__ */ jsx(motion.div, {
|
|
511
|
+
className,
|
|
512
|
+
initial: reduce ? { opacity: 0 } : {
|
|
513
|
+
opacity: 0,
|
|
514
|
+
y: 6
|
|
515
|
+
},
|
|
516
|
+
animate: {
|
|
517
|
+
opacity: 1,
|
|
518
|
+
y: 0
|
|
519
|
+
},
|
|
520
|
+
transition: {
|
|
521
|
+
...STAGE,
|
|
522
|
+
delay: reduce ? 0 : delay
|
|
523
|
+
},
|
|
524
|
+
children
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
function MiniMap({ size, picked, mineSet, reduce }) {
|
|
528
|
+
const hit = picked.at(-1);
|
|
529
|
+
const gap = size > 10 ? 1 : 3;
|
|
530
|
+
return /* @__PURE__ */ jsx("div", {
|
|
531
|
+
"aria-hidden": "true",
|
|
532
|
+
className: "grid shrink-0",
|
|
533
|
+
style: {
|
|
534
|
+
gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))`,
|
|
535
|
+
gap,
|
|
536
|
+
width: Math.min(88, size * 8 + (size - 1) * gap)
|
|
537
|
+
},
|
|
538
|
+
children: Array.from({ length: size * size }, (_, tile) => {
|
|
539
|
+
const isMine = mineSet.has(tile);
|
|
540
|
+
const isPicked = picked.includes(tile);
|
|
541
|
+
const order = picked.indexOf(tile);
|
|
542
|
+
return /* @__PURE__ */ jsx(motion.span, {
|
|
543
|
+
initial: isPicked && !reduce ? {
|
|
544
|
+
opacity: 0,
|
|
545
|
+
scale: .4
|
|
546
|
+
} : false,
|
|
547
|
+
animate: {
|
|
548
|
+
opacity: 1,
|
|
549
|
+
scale: 1
|
|
550
|
+
},
|
|
551
|
+
transition: {
|
|
552
|
+
...CELL_SPRING,
|
|
553
|
+
delay: REPLAY_START + order * REPLAY_STEP
|
|
554
|
+
},
|
|
555
|
+
className: cn("aspect-square rounded-[2px]", isPicked && !isMine && "bg-primary", isPicked && isMine && tile === hit && "bg-rose-500", !isPicked && isMine && "ring-1 ring-rose-500/60 ring-inset", !isPicked && !isMine && "bg-foreground/10")
|
|
556
|
+
}, tile);
|
|
557
|
+
})
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
const TICKET_SHADOW = "[filter:drop-shadow(0_1px_1px_rgb(0_0_0/0.12))_drop-shadow(0_12px_16px_rgb(0_0_0/0.3))]";
|
|
561
|
+
/** A ticket stub, notched at a dashed tear line. */
|
|
562
|
+
function Ticket({ outcome, multiplier, gems, safeTiles, mines, size, picked, mineSet, reduce }) {
|
|
563
|
+
const cashed = outcome === "cashed";
|
|
564
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
565
|
+
className: "bg-card text-foreground @container w-full rounded-2xl",
|
|
566
|
+
style: {
|
|
567
|
+
WebkitMaskImage: NOTCH_MASK,
|
|
568
|
+
WebkitMaskComposite: "source-in",
|
|
569
|
+
maskImage: NOTCH_MASK,
|
|
570
|
+
maskComposite: "intersect"
|
|
571
|
+
},
|
|
572
|
+
children: [
|
|
573
|
+
/* @__PURE__ */ jsxs("div", {
|
|
574
|
+
className: cn("flex flex-col items-center justify-center gap-1 rounded-t-2xl px-5 text-center", cashed ? "bg-primary/10" : "bg-rose-500/10"),
|
|
575
|
+
style: { height: TEAR },
|
|
576
|
+
children: [/* @__PURE__ */ jsx(Stage, {
|
|
577
|
+
delay: .05,
|
|
578
|
+
reduce,
|
|
579
|
+
children: /* @__PURE__ */ jsx("p", {
|
|
580
|
+
className: cn("text-xs font-medium tracking-wide uppercase", cashed ? "text-primary" : "text-rose-600 dark:text-rose-400"),
|
|
581
|
+
children: cashed ? "Cashed out" : "Mine hit"
|
|
582
|
+
})
|
|
583
|
+
}), /* @__PURE__ */ jsx(Stage, {
|
|
584
|
+
delay: .1,
|
|
585
|
+
reduce,
|
|
586
|
+
children: /* @__PURE__ */ jsx("p", {
|
|
587
|
+
className: cn("text-3xl font-semibold", !cashed && "text-muted-foreground line-through decoration-2"),
|
|
588
|
+
children: cashed ? /* @__PURE__ */ jsx(NumberTicker, {
|
|
589
|
+
value: multiplier,
|
|
590
|
+
decimals: 2,
|
|
591
|
+
format: compact,
|
|
592
|
+
suffix: "×",
|
|
593
|
+
startOnView: false,
|
|
594
|
+
duration: .6,
|
|
595
|
+
stagger: .05
|
|
596
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
597
|
+
className: "tabular-nums",
|
|
598
|
+
children: formatMultiplier(multiplier)
|
|
599
|
+
})
|
|
600
|
+
})
|
|
601
|
+
})]
|
|
602
|
+
}),
|
|
603
|
+
/* @__PURE__ */ jsx("div", {
|
|
604
|
+
"aria-hidden": "true",
|
|
605
|
+
className: "border-border mx-4 border-t-2 border-dashed"
|
|
606
|
+
}),
|
|
607
|
+
/* @__PURE__ */ jsxs("div", {
|
|
608
|
+
className: "flex items-center gap-4 px-5 pt-4 pb-5",
|
|
609
|
+
children: [/* @__PURE__ */ jsx(Stage, {
|
|
610
|
+
delay: .18,
|
|
611
|
+
reduce,
|
|
612
|
+
className: "flex-1",
|
|
613
|
+
children: /* @__PURE__ */ jsxs("dl", {
|
|
614
|
+
className: "grid gap-1.5 text-xs",
|
|
615
|
+
children: [
|
|
616
|
+
/* @__PURE__ */ jsx(Row, {
|
|
617
|
+
label: "Gems",
|
|
618
|
+
value: `${gems} of ${safeTiles}`
|
|
619
|
+
}),
|
|
620
|
+
/* @__PURE__ */ jsx(Row, {
|
|
621
|
+
label: "Mines",
|
|
622
|
+
value: mines
|
|
623
|
+
}),
|
|
624
|
+
/* @__PURE__ */ jsx(Row, {
|
|
625
|
+
label: cashed ? "Odds beaten" : "Lost on pick",
|
|
626
|
+
value: cashed ? `1 in ${compact(multiplier)}` : picked.length
|
|
627
|
+
})
|
|
628
|
+
]
|
|
629
|
+
})
|
|
630
|
+
}), /* @__PURE__ */ jsx(Stage, {
|
|
631
|
+
delay: .24,
|
|
632
|
+
reduce,
|
|
633
|
+
className: "@max-[15rem]:hidden",
|
|
634
|
+
children: /* @__PURE__ */ jsx(MiniMap, {
|
|
635
|
+
size,
|
|
636
|
+
picked,
|
|
637
|
+
mineSet,
|
|
638
|
+
reduce
|
|
639
|
+
})
|
|
640
|
+
})]
|
|
641
|
+
})
|
|
642
|
+
]
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
function Row({ label, value }) {
|
|
646
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
647
|
+
className: "flex justify-between gap-2 whitespace-nowrap",
|
|
648
|
+
children: [/* @__PURE__ */ jsx("dt", {
|
|
649
|
+
className: "text-muted-foreground",
|
|
650
|
+
children: label
|
|
651
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
652
|
+
className: "font-medium tabular-nums",
|
|
653
|
+
children: value
|
|
654
|
+
})]
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
const SPIKES = Array.from({ length: 8 }, (_, i) => {
|
|
658
|
+
const angle = i * Math.PI / 4;
|
|
659
|
+
const main = i % 2 === 0;
|
|
660
|
+
const [cos, sin] = [Math.cos(angle), Math.sin(angle)];
|
|
661
|
+
const reach = main ? 10.5 : 9;
|
|
662
|
+
return {
|
|
663
|
+
main,
|
|
664
|
+
x1: 12 + cos * 6,
|
|
665
|
+
y1: 12 + sin * 6,
|
|
666
|
+
x2: 12 + cos * reach,
|
|
667
|
+
y2: 12 + sin * reach
|
|
668
|
+
};
|
|
669
|
+
});
|
|
670
|
+
/** A mine on Lucide's 24px grid, sized to pair with the gem. */
|
|
671
|
+
function MineIcon({ className }) {
|
|
672
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
673
|
+
"aria-hidden": "true",
|
|
674
|
+
viewBox: "0 0 24 24",
|
|
675
|
+
fill: "currentColor",
|
|
676
|
+
stroke: "currentColor",
|
|
677
|
+
strokeLinecap: "round",
|
|
678
|
+
className,
|
|
679
|
+
children: [
|
|
680
|
+
SPIKES.map((spike) => /* @__PURE__ */ jsx("line", {
|
|
681
|
+
x1: spike.x1,
|
|
682
|
+
y1: spike.y1,
|
|
683
|
+
x2: spike.x2,
|
|
684
|
+
y2: spike.y2,
|
|
685
|
+
strokeWidth: spike.main ? 2.5 : 2
|
|
686
|
+
}, `${spike.x2.toFixed(2)}-${spike.y2.toFixed(2)}`)),
|
|
687
|
+
/* @__PURE__ */ jsx("circle", {
|
|
688
|
+
cx: 12,
|
|
689
|
+
cy: 12,
|
|
690
|
+
r: 6.5,
|
|
691
|
+
stroke: "none"
|
|
692
|
+
}),
|
|
693
|
+
/* @__PURE__ */ jsx("circle", {
|
|
694
|
+
cx: 9.75,
|
|
695
|
+
cy: 9.75,
|
|
696
|
+
r: 1.6,
|
|
697
|
+
fill: "white",
|
|
698
|
+
fillOpacity: .75,
|
|
699
|
+
stroke: "none"
|
|
700
|
+
})
|
|
701
|
+
]
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
/** A small ring that fills with the chance the next pick is safe. */
|
|
705
|
+
function OddsRing({ safe, reduce }) {
|
|
706
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
707
|
+
"aria-hidden": "true",
|
|
708
|
+
viewBox: "0 0 14 14",
|
|
709
|
+
className: "size-3.5 -rotate-90",
|
|
710
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
711
|
+
cx: 7,
|
|
712
|
+
cy: 7,
|
|
713
|
+
r: 5.5,
|
|
714
|
+
fill: "none",
|
|
715
|
+
strokeWidth: 2,
|
|
716
|
+
className: "stroke-foreground/10"
|
|
717
|
+
}), /* @__PURE__ */ jsx(motion.circle, {
|
|
718
|
+
cx: 7,
|
|
719
|
+
cy: 7,
|
|
720
|
+
r: 5.5,
|
|
721
|
+
fill: "none",
|
|
722
|
+
strokeWidth: 2,
|
|
723
|
+
strokeLinecap: "round",
|
|
724
|
+
className: safe < .5 ? "stroke-rose-500 dark:stroke-rose-400" : "stroke-primary",
|
|
725
|
+
initial: false,
|
|
726
|
+
animate: { pathLength: safe },
|
|
727
|
+
transition: reduce ? { duration: 0 } : {
|
|
728
|
+
duration: .2,
|
|
729
|
+
ease: EASE_OUT
|
|
730
|
+
}
|
|
731
|
+
})]
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
/** What a tile shows, and for revealed tiles whether the player picked it. */
|
|
735
|
+
function tileState(content, isPicked, order) {
|
|
736
|
+
if (!content) return "hidden";
|
|
737
|
+
if (!isPicked) return `${content}, not picked`;
|
|
738
|
+
return content === "mine" ? "mine, hit" : `gem, pick ${order + 1}`;
|
|
739
|
+
}
|
|
740
|
+
/** Rings between two tiles: 0 for the same tile, 1 for its neighbours. */
|
|
741
|
+
function ringFrom(from, tile, size) {
|
|
742
|
+
return Math.max(Math.abs(Math.floor(tile / size) - Math.floor(from / size)), Math.abs(tile % size - from % size));
|
|
743
|
+
}
|
|
744
|
+
const SHORT = new Intl.NumberFormat("en", {
|
|
745
|
+
notation: "compact",
|
|
746
|
+
maximumFractionDigits: 1
|
|
747
|
+
});
|
|
748
|
+
const SCIENTIFIC = new Intl.NumberFormat("en", {
|
|
749
|
+
notation: "scientific",
|
|
750
|
+
maximumFractionDigits: 1
|
|
751
|
+
});
|
|
752
|
+
function compact(multiplier) {
|
|
753
|
+
if (multiplier < 1e4) return multiplier.toFixed(2);
|
|
754
|
+
return (multiplier < 0x38d7ea4c68000 ? SHORT : SCIENTIFIC).format(multiplier);
|
|
755
|
+
}
|
|
756
|
+
/** A multiplier as Mines shows it: 2.50×, or shortened when large (5.2M×). */
|
|
757
|
+
function formatMultiplier(multiplier) {
|
|
758
|
+
return `${compact(multiplier)}×`;
|
|
759
|
+
}
|
|
760
|
+
export { Mines, formatMultiplier, minesMultiplier };
|
|
761
|
+
|
|
762
|
+
//# sourceMappingURL=mines.js.map
|