jaml-ui 0.6.1 → 0.7.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/LICENSE +21 -21
- package/README.md +135 -145
- package/dist/assets.js +13 -10
- package/dist/components/JamlIdeToolbar.js +2 -36
- package/dist/components/JamlIdeVisual.js +2 -2
- package/dist/hooks/loadMotelyWasm.d.ts +7 -0
- package/dist/hooks/loadMotelyWasm.js +16 -0
- package/dist/hooks/searchWorkerCode.d.ts +1 -0
- package/dist/hooks/searchWorkerCode.js +62 -0
- package/dist/hooks/useAnalyzer.d.ts +8 -0
- package/dist/hooks/useAnalyzer.js +72 -0
- package/dist/hooks/useSearch.d.ts +21 -0
- package/dist/hooks/useSearch.js +76 -0
- package/dist/ui/footer.js +5 -5
- package/dist/ui/panel.d.ts +6 -17
- package/dist/ui/panel.js +12 -47
- package/dist/ui/showcase.js +4 -4
- package/dist/ui/sprites.d.ts +2 -2
- package/dist/ui/sprites.js +1 -1
- package/package.json +107 -109
- package/assets/8BitDeck.png +0 -0
- package/assets/BlindChips.png +0 -0
- package/assets/Boosters.png +0 -0
- package/assets/Editions.png +0 -0
- package/assets/Enhancers.png +0 -0
- package/assets/Jokers.png +0 -0
- package/assets/Tarots.png +0 -0
- package/assets/Vouchers.png +0 -0
- package/assets/fonts/m6x11plusplus.otf +0 -0
- package/assets/stickers.png +0 -0
- package/assets/tags.png +0 -0
- package/dist/data/balatro-jokers.json +0 -1241
- package/dist/r3f/BalatroJokerMesh3D.d.ts +0 -8
- package/dist/r3f/BalatroJokerMesh3D.js +0 -98
- package/dist/r3f/BalatroJokerPreview3D.d.ts +0 -14
- package/dist/r3f/BalatroJokerPreview3D.js +0 -30
- package/dist/r3f/BalatroPlayingCard3D.d.ts +0 -22
- package/dist/r3f/BalatroPlayingCard3D.js +0 -62
- package/dist/r3f/cardConstants.d.ts +0 -16
- package/dist/r3f/cardConstants.js +0 -14
- package/dist/r3f/compositedAtlas.d.ts +0 -5
- package/dist/r3f/compositedAtlas.js +0 -56
- package/dist/r3f/gridUV.d.ts +0 -22
- package/dist/r3f/gridUV.js +0 -30
- package/dist/r3f/index.d.ts +0 -12
- package/dist/r3f/index.js +0 -13
- package/dist/r3f/jokerRegistry.d.ts +0 -28
- package/dist/r3f/jokerRegistry.js +0 -40
- package/dist/r3f/jokerTilt.d.ts +0 -8
- package/dist/r3f/jokerTilt.js +0 -41
- package/dist/r3f/magneticTilt.d.ts +0 -18
- package/dist/r3f/magneticTilt.js +0 -34
- package/dist/r3f/playingCardTypes.d.ts +0 -24
- package/dist/r3f/playingCardTypes.js +0 -32
- package/dist/r3f/playingCardVisuals.d.ts +0 -7
- package/dist/r3f/playingCardVisuals.js +0 -45
- package/dist/r3f/usePlayingCardTexture.d.ts +0 -7
- package/dist/r3f/usePlayingCardTexture.js +0 -92
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 pifreak
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pifreak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,145 +1,135 @@
|
|
|
1
|
-
# jaml-ui
|
|
2
|
-
|
|
3
|
-
React components and utilities for Balatro/JAML
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import { JamlGameCard } from "jaml-ui";
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
import { setJamlAssetBaseUrl } from "jaml-ui";
|
|
91
|
-
|
|
92
|
-
setJamlAssetBaseUrl("/vendor/jaml-ui/");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export default nextConfig;
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## Browser-first runtime direction
|
|
142
|
-
|
|
143
|
-
`jaml-ui` is designed for browser/React consumers. The optional `jaml-ui/motely` entry targets plain `motely-wasm` and does not assume threaded WASM, SAB, or COEP setup.
|
|
144
|
-
|
|
145
|
-
The built-in `JamlIde` intentionally stays lightweight. Rich editor integrations like Monaco, custom language servers, or extension-host-specific tooling should live in app-level packages on top of `jaml-ui`, not in the base renderer package.
|
|
1
|
+
# jaml-ui
|
|
2
|
+
|
|
3
|
+
React components, UI tokens, sprites, and utilities for Balatro/JAML apps.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install jaml-ui react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Package exports
|
|
12
|
+
|
|
13
|
+
| Entry | Contents |
|
|
14
|
+
|-------|----------|
|
|
15
|
+
| `jaml-ui` | Game card components, JAML IDE, Analyzer Explorer, hooks |
|
|
16
|
+
| `jaml-ui/ui` | Jimbo design system — JimboPanel, JimboButton, JimboModal, tokens |
|
|
17
|
+
| `jaml-ui/core` | Pure asset helpers, sprite metadata, decode utilities (no React) |
|
|
18
|
+
| `jaml-ui/motely` | motely-wasm decode helpers (requires `motely-wasm` peer) |
|
|
19
|
+
| `jaml-ui/r3f` | 3D card component via React Three Fiber (requires r3f peers) |
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { JamlGameCard, AnalyzerExplorer, JamlIde } from "jaml-ui";
|
|
25
|
+
import { JimboPanel, JimboButton } from "jaml-ui/ui";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Game card
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { JamlGameCard } from "jaml-ui";
|
|
32
|
+
|
|
33
|
+
<JamlGameCard
|
|
34
|
+
type="joker"
|
|
35
|
+
card={{ name: "Blueprint", edition: "Foil", isEternal: true, scale: 1.5 }}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Jimbo UI (Balatro design system)
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { JimboPanel, JimboButton, JimboModal } from "jaml-ui/ui";
|
|
43
|
+
import { JimboColorOption } from "jaml-ui/ui";
|
|
44
|
+
|
|
45
|
+
<JimboPanel sway onBack={() => setOpen(false)}>
|
|
46
|
+
<JimboButton variant="primary" onClick={handleSearch}>Search</JimboButton>
|
|
47
|
+
</JimboPanel>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Available variants: `primary`, `secondary`, `danger`, `back`, `ghost`
|
|
51
|
+
|
|
52
|
+
### JAML IDE
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { JamlIde } from "jaml-ui";
|
|
56
|
+
|
|
57
|
+
<JamlIde
|
|
58
|
+
jaml={jaml}
|
|
59
|
+
onChange={setJaml}
|
|
60
|
+
searchResults={results}
|
|
61
|
+
onSearch={handleSearch}
|
|
62
|
+
isSearching={isSearching}
|
|
63
|
+
/>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Analyzer Explorer
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { AnalyzerExplorer } from "jaml-ui";
|
|
70
|
+
|
|
71
|
+
// antes: AnalyzerAnteView[] — stream from motely-wasm createSearchContext
|
|
72
|
+
<AnalyzerExplorer antes={antes} totalAntes={8} highlights={highlights} />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### JAML Map Preview
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { JamlMapPreview } from "jaml-ui";
|
|
79
|
+
|
|
80
|
+
<JamlMapPreview jaml={jaml} />
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Asset handling
|
|
84
|
+
|
|
85
|
+
By default sprites resolve from the package `assets/` directory via `import.meta.url`.
|
|
86
|
+
|
|
87
|
+
Override at app startup:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { setJamlAssetBaseUrl, clearJamlAssetBaseUrl } from "jaml-ui";
|
|
91
|
+
|
|
92
|
+
setJamlAssetBaseUrl("/vendor/jaml-ui/"); // custom CDN
|
|
93
|
+
clearJamlAssetBaseUrl(); // back to default
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Core utilities
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { SPRITE_SHEETS, getSpriteData, resolveJamlAssetUrl } from "jaml-ui/core";
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Motely decode helpers
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { decodeMotelyItemName, motelyItemTypeName } from "jaml-ui/motely";
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 3D card (optional)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm install three @react-three/fiber @react-three/drei @react-spring/three
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { Card3D } from "jaml-ui/r3f";
|
|
116
|
+
|
|
117
|
+
<Card3D itemName="Blueprint" />
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Next.js
|
|
121
|
+
|
|
122
|
+
Import pure helpers from `jaml-ui/core` for server components. For local workspace installs add:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
// next.config.ts
|
|
126
|
+
const nextConfig = { transpilePackages: ["jaml-ui"] };
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Peer dependencies
|
|
130
|
+
|
|
131
|
+
| Peer | Required for |
|
|
132
|
+
|------|-------------|
|
|
133
|
+
| `react`, `react-dom` | All components |
|
|
134
|
+
| `motely-wasm ^10 \|\| ^11 \|\| ^12` | `jaml-ui/motely`, `AnalyzerExplorer` data |
|
|
135
|
+
| `three`, `@react-three/fiber`, `@react-three/drei`, `@react-spring/three` | `jaml-ui/r3f` only |
|
package/dist/assets.js
CHANGED
|
@@ -11,17 +11,20 @@ export const JAML_ASSET_FILES = {
|
|
|
11
11
|
tags: "tags.png",
|
|
12
12
|
};
|
|
13
13
|
const assetKeyByFileName = Object.fromEntries(Object.entries(JAML_ASSET_FILES).map(([key, fileName]) => [fileName, key]));
|
|
14
|
+
// Keep in lockstep with package.json version. Upload assets to this path when publishing.
|
|
15
|
+
const JAML_UI_VERSION = "0.7.0";
|
|
16
|
+
const CDN_BASE = `https://cdn.seedfinder.app/jaml-ui/${JAML_UI_VERSION}/assets/`;
|
|
14
17
|
const defaultAssetUrls = {
|
|
15
|
-
deck:
|
|
16
|
-
blinds:
|
|
17
|
-
boosters:
|
|
18
|
-
editions:
|
|
19
|
-
enhancers:
|
|
20
|
-
jokers:
|
|
21
|
-
tarots:
|
|
22
|
-
vouchers:
|
|
23
|
-
stickers:
|
|
24
|
-
tags:
|
|
18
|
+
deck: `${CDN_BASE}${JAML_ASSET_FILES.deck}`,
|
|
19
|
+
blinds: `${CDN_BASE}${JAML_ASSET_FILES.blinds}`,
|
|
20
|
+
boosters: `${CDN_BASE}${JAML_ASSET_FILES.boosters}`,
|
|
21
|
+
editions: `${CDN_BASE}${JAML_ASSET_FILES.editions}`,
|
|
22
|
+
enhancers: `${CDN_BASE}${JAML_ASSET_FILES.enhancers}`,
|
|
23
|
+
jokers: `${CDN_BASE}${JAML_ASSET_FILES.jokers}`,
|
|
24
|
+
tarots: `${CDN_BASE}${JAML_ASSET_FILES.tarots}`,
|
|
25
|
+
vouchers: `${CDN_BASE}${JAML_ASSET_FILES.vouchers}`,
|
|
26
|
+
stickers: `${CDN_BASE}${JAML_ASSET_FILES.stickers}`,
|
|
27
|
+
tags: `${CDN_BASE}${JAML_ASSET_FILES.tags}`,
|
|
25
28
|
};
|
|
26
29
|
let customAssetBaseUrl = null;
|
|
27
30
|
function normalizeBaseUrl(baseUrl) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { JimboButton } from "../ui/panel.js";
|
|
3
4
|
import { JimboColorOption } from "../ui/tokens.js";
|
|
4
5
|
const TABS = [
|
|
5
6
|
{ id: "visual", label: "Visual" },
|
|
@@ -16,40 +17,5 @@ export function JamlIdeToolbar({ mode, onModeChange, resultCount = 0, className
|
|
|
16
17
|
padding: "6px 10px",
|
|
17
18
|
borderBottom: `1px solid ${JimboColorOption.PANEL_EDGE}`,
|
|
18
19
|
background: JimboColorOption.DARKEST,
|
|
19
|
-
}, children: [_jsx("div", { style: { display: "flex", alignItems: "center", gap: 4 }, children: TABS.map((tab) => {
|
|
20
|
-
const selected = mode === tab.id;
|
|
21
|
-
return (_jsxs("button", { type: "button", onClick: () => onModeChange(tab.id), style: {
|
|
22
|
-
cursor: "pointer",
|
|
23
|
-
borderRadius: 6,
|
|
24
|
-
border: selected ? `1px solid ${JimboColorOption.GOLD}` : "1px solid transparent",
|
|
25
|
-
background: selected ? `${JimboColorOption.GOLD}22` : "transparent",
|
|
26
|
-
color: selected ? JimboColorOption.GOLD_TEXT : JimboColorOption.GREY,
|
|
27
|
-
padding: "5px 10px",
|
|
28
|
-
fontSize: 11,
|
|
29
|
-
fontWeight: 700,
|
|
30
|
-
fontFamily: "m6x11plus, monospace",
|
|
31
|
-
transition: "background 120ms, color 120ms",
|
|
32
|
-
}, children: [tab.label, tab.id === "results" && resultCount > 0 ? (_jsx("span", { style: {
|
|
33
|
-
marginLeft: 6,
|
|
34
|
-
borderRadius: 999,
|
|
35
|
-
background: `${JimboColorOption.GOLD}33`,
|
|
36
|
-
color: JimboColorOption.GOLD_TEXT,
|
|
37
|
-
padding: "1px 6px",
|
|
38
|
-
fontSize: 10,
|
|
39
|
-
}, children: resultCount })) : null] }, tab.id));
|
|
40
|
-
}) }), onSearch ? (_jsx("button", { type: "button", onClick: onSearch, style: {
|
|
41
|
-
cursor: "pointer",
|
|
42
|
-
borderRadius: 6,
|
|
43
|
-
border: isSearching
|
|
44
|
-
? `1px solid ${JimboColorOption.DARK_RED}`
|
|
45
|
-
: `1px solid ${JimboColorOption.GREEN}`,
|
|
46
|
-
background: isSearching
|
|
47
|
-
? `${JimboColorOption.RED}22`
|
|
48
|
-
: `${JimboColorOption.GREEN}22`,
|
|
49
|
-
color: isSearching ? JimboColorOption.RED : JimboColorOption.GREEN_TEXT,
|
|
50
|
-
padding: "5px 14px",
|
|
51
|
-
fontSize: 11,
|
|
52
|
-
fontWeight: 700,
|
|
53
|
-
fontFamily: "m6x11plus, monospace",
|
|
54
|
-
}, children: isSearching ? "Stop" : "Search" })) : null] }));
|
|
20
|
+
}, children: [_jsx("div", { style: { display: "flex", alignItems: "center", gap: 4 }, children: TABS.map((tab) => (_jsxs(JimboButton, { tone: mode === tab.id ? "gold" : "grey", size: "xs", onClick: () => onModeChange(tab.id), children: [tab.label, tab.id === "results" && resultCount > 0 ? (_jsx("span", { style: { marginLeft: 6, borderRadius: 999, background: "rgba(228,182,67,0.2)", color: JimboColorOption.GOLD_TEXT, padding: "1px 6px", fontSize: 10 }, children: resultCount })) : null] }, tab.id))) }), onSearch ? (_jsx(JimboButton, { tone: isSearching ? "red" : "blue", size: "xs", onClick: onSearch, children: isSearching ? "Stop" : "Search" })) : null] }));
|
|
55
21
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { JimboColorOption } from "../ui/tokens.js";
|
|
5
|
-
import {
|
|
5
|
+
import { JimboSprite } from "../ui/sprites.js";
|
|
6
6
|
const ZONE_META = {
|
|
7
7
|
must: { label: "MUST", color: JimboColorOption.BLUE },
|
|
8
8
|
should: { label: "SHOULD", color: JimboColorOption.RED },
|
|
@@ -25,7 +25,7 @@ function ClauseSprite({ clause, size = 26 }) {
|
|
|
25
25
|
const sheet = clauseSpriteSheet(clause.type);
|
|
26
26
|
if (!sheet)
|
|
27
27
|
return null;
|
|
28
|
-
return _jsx(
|
|
28
|
+
return _jsx(JimboSprite, { name: clause.value, sheet: sheet, width: size });
|
|
29
29
|
}
|
|
30
30
|
function DragClausePill({ clause, zone, onDragStart, }) {
|
|
31
31
|
const z = ZONE_META[zone];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Module-level cache so multiple hooks share a single boot per URL.
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
const cache = new Map();
|
|
4
|
+
export function loadMotelyWasm(url) {
|
|
5
|
+
if (!cache.has(url)) {
|
|
6
|
+
cache.set(url, (async () => {
|
|
7
|
+
const mod = await import(/* @vite-ignore */ url);
|
|
8
|
+
await mod.default.boot();
|
|
9
|
+
return { MotelyWasm: mod.MotelyWasm, MotelyWasmEvents: mod.MotelyWasmEvents, Motely: mod.Motely };
|
|
10
|
+
})().catch((err) => {
|
|
11
|
+
cache.delete(url);
|
|
12
|
+
throw err;
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
return cache.get(url);
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SEARCH_WORKER_CODE = "\nlet MotelyWasm = null;\nlet MotelyWasmEvents = null;\nlet activeSearch = null;\n\nself.addEventListener('message', async function(e) {\n const msg = e.data;\n\n if (msg.type === 'init') {\n try {\n const mod = await import(msg.url);\n await mod.default.boot();\n MotelyWasm = mod.MotelyWasm;\n MotelyWasmEvents = mod.MotelyWasmEvents;\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', message: String(err) });\n }\n return;\n }\n\n if (msg.type === 'start') {\n if (!MotelyWasm) { self.postMessage({ type: 'error', message: 'Not initialized' }); return; }\n const validation = MotelyWasm.validateJaml(msg.jaml);\n if (validation !== 'valid') { self.postMessage({ type: 'error', message: validation }); return; }\n\n let rId, pId, cId;\n function cleanup() {\n MotelyWasmEvents.onResult.unsubscribeById(rId);\n MotelyWasmEvents.onProgress.unsubscribeById(pId);\n MotelyWasmEvents.onComplete.unsubscribeById(cId);\n activeSearch = null;\n }\n\n rId = MotelyWasmEvents.onResult.subscribe(function(seed, score) {\n self.postMessage({ type: 'result', seed, score });\n });\n pId = MotelyWasmEvents.onProgress.subscribe(function(searched, matching) {\n self.postMessage({ type: 'progress', searched: searched.toString(), matching: matching.toString() });\n });\n cId = MotelyWasmEvents.onComplete.subscribe(function(status, searched, matched) {\n cleanup();\n self.postMessage({ type: 'complete', status, searched: searched.toString(), matched: matched.toString() });\n });\n\n try {\n activeSearch = MotelyWasm.startRandomSearch(msg.jaml, msg.count);\n } catch (err) {\n cleanup();\n self.postMessage({ type: 'error', message: String(err) });\n }\n return;\n }\n\n if (msg.type === 'stop') {\n if (activeSearch) { activeSearch.cancel(); activeSearch = null; }\n self.postMessage({ type: 'cancelled' });\n }\n});\n";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Worker code as an inline string — created as a Blob URL at runtime.
|
|
2
|
+
// This avoids bundler/import.meta.url issues when shipped as an npm package.
|
|
3
|
+
export const SEARCH_WORKER_CODE = `
|
|
4
|
+
let MotelyWasm = null;
|
|
5
|
+
let MotelyWasmEvents = null;
|
|
6
|
+
let activeSearch = null;
|
|
7
|
+
|
|
8
|
+
self.addEventListener('message', async function(e) {
|
|
9
|
+
const msg = e.data;
|
|
10
|
+
|
|
11
|
+
if (msg.type === 'init') {
|
|
12
|
+
try {
|
|
13
|
+
const mod = await import(msg.url);
|
|
14
|
+
await mod.default.boot();
|
|
15
|
+
MotelyWasm = mod.MotelyWasm;
|
|
16
|
+
MotelyWasmEvents = mod.MotelyWasmEvents;
|
|
17
|
+
self.postMessage({ type: 'ready' });
|
|
18
|
+
} catch (err) {
|
|
19
|
+
self.postMessage({ type: 'error', message: String(err) });
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (msg.type === 'start') {
|
|
25
|
+
if (!MotelyWasm) { self.postMessage({ type: 'error', message: 'Not initialized' }); return; }
|
|
26
|
+
const validation = MotelyWasm.validateJaml(msg.jaml);
|
|
27
|
+
if (validation !== 'valid') { self.postMessage({ type: 'error', message: validation }); return; }
|
|
28
|
+
|
|
29
|
+
let rId, pId, cId;
|
|
30
|
+
function cleanup() {
|
|
31
|
+
MotelyWasmEvents.onResult.unsubscribeById(rId);
|
|
32
|
+
MotelyWasmEvents.onProgress.unsubscribeById(pId);
|
|
33
|
+
MotelyWasmEvents.onComplete.unsubscribeById(cId);
|
|
34
|
+
activeSearch = null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
rId = MotelyWasmEvents.onResult.subscribe(function(seed, score) {
|
|
38
|
+
self.postMessage({ type: 'result', seed, score });
|
|
39
|
+
});
|
|
40
|
+
pId = MotelyWasmEvents.onProgress.subscribe(function(searched, matching) {
|
|
41
|
+
self.postMessage({ type: 'progress', searched: searched.toString(), matching: matching.toString() });
|
|
42
|
+
});
|
|
43
|
+
cId = MotelyWasmEvents.onComplete.subscribe(function(status, searched, matched) {
|
|
44
|
+
cleanup();
|
|
45
|
+
self.postMessage({ type: 'complete', status, searched: searched.toString(), matched: matched.toString() });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
activeSearch = MotelyWasm.startRandomSearch(msg.jaml, msg.count);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
cleanup();
|
|
52
|
+
self.postMessage({ type: 'error', message: String(err) });
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (msg.type === 'stop') {
|
|
58
|
+
if (activeSearch) { activeSearch.cancel(); activeSearch = null; }
|
|
59
|
+
self.postMessage({ type: 'cancelled' });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AnalyzerAnteView } from "../components/AnalyzerExplorer.js";
|
|
2
|
+
export type AnalyzerStatus = "idle" | "running" | "done" | "error";
|
|
3
|
+
export declare function useAnalyzer(motelyWasmUrl: string): {
|
|
4
|
+
antes: AnalyzerAnteView[];
|
|
5
|
+
status: AnalyzerStatus;
|
|
6
|
+
error: string | null;
|
|
7
|
+
analyze: (seed: string, deck: string, stake: string, jaml?: string) => Promise<void>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useCallback } from "react";
|
|
3
|
+
import { loadMotelyWasm } from "./loadMotelyWasm.js";
|
|
4
|
+
import { extractVisualJamlItems } from "../utils/jamlMapPreview.js";
|
|
5
|
+
import { motelyItemDisplayNameFromValue } from "../motelyDisplay.js";
|
|
6
|
+
export function useAnalyzer(motelyWasmUrl) {
|
|
7
|
+
const [antes, setAntes] = useState([]);
|
|
8
|
+
const [status, setStatus] = useState("idle");
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const analyze = useCallback(async (seed, deck, stake, jaml) => {
|
|
11
|
+
setAntes([]);
|
|
12
|
+
setStatus("running");
|
|
13
|
+
setError(null);
|
|
14
|
+
try {
|
|
15
|
+
const { MotelyWasm, Motely } = await loadMotelyWasm(motelyWasmUrl);
|
|
16
|
+
const deckEnum = Motely.MotelyDeck[deck] ?? Motely.MotelyDeck.Red;
|
|
17
|
+
const stakeEnum = Motely.MotelyStake[stake] ?? Motely.MotelyStake.White;
|
|
18
|
+
const desiredNames = new Set();
|
|
19
|
+
if (jaml) {
|
|
20
|
+
const groups = extractVisualJamlItems(jaml);
|
|
21
|
+
for (const item of [...groups.must, ...groups.should]) {
|
|
22
|
+
desiredNames.add(item.value.toLowerCase());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const ctx = MotelyWasm.createSearchContext(seed, deckEnum, stakeEnum);
|
|
26
|
+
const bossStream = ctx.createBossStream();
|
|
27
|
+
let runState = { voucherBitfield: 0, bossBitfield: 0 };
|
|
28
|
+
const results = [];
|
|
29
|
+
for (let ante = 1; ante <= 8; ante++) {
|
|
30
|
+
const bossResult = ctx.getNextBossForAnte(bossStream, ante, runState);
|
|
31
|
+
const bossName = Motely.MotelyBossBlind[bossResult.boss] ?? `Unknown(${bossResult.boss})`;
|
|
32
|
+
runState = bossResult.runState;
|
|
33
|
+
const voucherResult = ctx.getAnteFirstVoucher(ante, runState);
|
|
34
|
+
const voucherName = Motely.MotelyVoucher[voucherResult.voucher] ?? `Unknown(${voucherResult.voucher})`;
|
|
35
|
+
runState = voucherResult.runState;
|
|
36
|
+
const tagStream = ctx.createTagStream(ante);
|
|
37
|
+
const tag1 = ctx.getNextTag(tagStream);
|
|
38
|
+
const tag2 = ctx.getNextTag(tagStream);
|
|
39
|
+
const packStream = ctx.createBoosterPackStream(ante);
|
|
40
|
+
const packs = [];
|
|
41
|
+
for (let p = 0; p < 2; p++) {
|
|
42
|
+
const packResult = ctx.getNextBoosterPack(packStream);
|
|
43
|
+
packs.push(Motely.MotelyBoosterPack[packResult.pack] ?? `Unknown(${packResult.pack})`);
|
|
44
|
+
}
|
|
45
|
+
const shopStream = ctx.createShopItemStream(ante, runState, Motely.MotelyShopStreamFlags.Default, Motely.MotelyJokerStreamFlags.Default);
|
|
46
|
+
const shop = [];
|
|
47
|
+
for (let i = 0; i < 4; i++) {
|
|
48
|
+
const itemResult = ctx.getNextShopItem(shopStream);
|
|
49
|
+
const name = motelyItemDisplayNameFromValue(itemResult.item.value);
|
|
50
|
+
const desired = desiredNames.size > 0 && desiredNames.has(name.toLowerCase());
|
|
51
|
+
shop.push({ id: `${ante}-shop-${i}`, name, value: itemResult.item.value, desired });
|
|
52
|
+
}
|
|
53
|
+
results.push({
|
|
54
|
+
ante,
|
|
55
|
+
boss: bossName,
|
|
56
|
+
voucher: voucherName,
|
|
57
|
+
smallBlindTag: Motely.MotelyTag[tag1.tag] ?? `Unknown(${tag1.tag})`,
|
|
58
|
+
bigBlindTag: Motely.MotelyTag[tag2.tag] ?? `Unknown(${tag2.tag})`,
|
|
59
|
+
packs,
|
|
60
|
+
shop,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
setAntes(results);
|
|
64
|
+
setStatus("done");
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
68
|
+
setStatus("error");
|
|
69
|
+
}
|
|
70
|
+
}, [motelyWasmUrl]);
|
|
71
|
+
return { antes, status, error, analyze };
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SearchResult {
|
|
2
|
+
seed: string;
|
|
3
|
+
score: number;
|
|
4
|
+
}
|
|
5
|
+
export type SearchStatus = "idle" | "booting" | "running" | "completed" | "cancelled" | "error";
|
|
6
|
+
export interface UseSearchState {
|
|
7
|
+
results: SearchResult[];
|
|
8
|
+
totalSearched: bigint;
|
|
9
|
+
matchingSeeds: bigint;
|
|
10
|
+
status: SearchStatus;
|
|
11
|
+
error: string | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function useSearch(motelyWasmUrl: string): {
|
|
14
|
+
start: (jaml: string, count: number) => void;
|
|
15
|
+
cancel: () => void;
|
|
16
|
+
results: SearchResult[];
|
|
17
|
+
totalSearched: bigint;
|
|
18
|
+
matchingSeeds: bigint;
|
|
19
|
+
status: SearchStatus;
|
|
20
|
+
error: string | null;
|
|
21
|
+
};
|