Compare commits

..

12 Commits

Author SHA1 Message Date
Lukas a045e3a0f9 Unmount Dialog children when closed
CI / build-image (push) Successful in 38s
CI / check (push) Successful in 2m50s
The native <dialog> wrapper rendered its children unconditionally
and only called dialog.close() on the underlying element when
open went false. The React subtree stayed mounted, so component
state (e.g. a ConfirmButton mid-confirm with a red checkmark
showing) survived a close/reopen cycle and reappeared the next
time the user opened the same dialog.

Gate children on open so the subtree unmounts on close. Next open
gets a fresh tree with default state.
2026-06-19 16:52:17 +02:00
Lukas 934d98025e chore(deps): suppress two new unreachable undici advisories
GHSA-vxpw-j846-p89q (WebSocket DoS via fragment count bypass) and
GHSA-hm92-r4w5-c3mj (SOCKS5 proxy pool cross-origin reuse) just
landed in the registry. Both are fixed in undici>=7.28.0 and both
sit in code paths we don't exercise from tests (no WebSocket
client, no SOCKS5 proxy). Same blocker as GHSA-vmh5-mc38-953g:
jsdom@29.1.1 reaches into undici 7's private module layout, so
we can't move the pin to 7.28+. Added them to the existing
ignoreGhsas list and consolidated the per-entry notes.
2026-06-19 16:51:56 +02:00
Lukas 3b2fb99b37 Fix duplicate player character ids after page reload
The PC id counter lived in a module-level let that reset to 0 on
every page load. After rehydrating PCs from localStorage, the next
create would hand out pc-1 again, colliding with an existing id.
That broke React's keyed reconciliation and caused the wrong PC
to be deleted (deletePlayerCharacter matches the first occurrence
of the id, so deleting the new pc-1 would remove the rehydrated
one instead).

Derive the next id from the max numeric suffix of existing
characters at the moment of creation. No more shared counter, so
no more reset on reload and no collision after import.
2026-06-19 16:36:20 +02:00
Lukas 111b464da5 Add Centaur Youth to bundled bestiary under Homebrew source
CR 1/4 Medium Fey with Gallop (advantage-cancelling skirmisher
trait) and Charge (bonus 1d6 on a 15 ft. straight-line melee),
matching the centaur PC traits players already have access to.
2026-06-19 16:30:01 +02:00
Lukas a97ffe5ed1 chore(deps): bump vite, jsdom; pin undici and suppress unreachable advisory
Bumps vite ^8.0.5 → ^8.0.16 (GHSA-fx2h-pf6j-xcff, server.fs.deny
bypass on Windows) and jsdom ^29.0.1 → ^29.1.1 to unblock the
pre-commit audit gate.

The existing >=7.24.0 undici override was floating to 8.x, which
broke jsdom (it reaches into undici 7's private module layout).
Tightened to ~7.24.0 to keep jsdom working. That leaves
GHSA-vmh5-mc38-953g (undici SOCKS5 ProxyAgent TLS bypass) open —
patched in 7.28+ but we can't move there until jsdom updates its
pin. We never use a SOCKS5 proxy in tests, so the vulnerable code
path is unreachable. Added an auditConfig.ignoreGhsas entry with
a note explaining the rationale and the condition for removing it.
2026-06-19 16:29:42 +02:00
Lukas 1930473753 Bundle The Great Labors bestiary (27 creatures)
CI / check (push) Successful in 2m54s
CI / build-image (push) Successful in 36s
Adds the monsters from appendix B (pages 163-199) of The Great Labors:
Anarch Boar, Blemys, Bronze Automaton/Strategos, Cerberus/Young Cerberus,
Empusa, Goatling/Trickster, Gygan, Keledone, Maenad, Thylean Manticore,
Marble Golem, Minotaur Berserker/Warrior, the three mythic beasts
(White Stag, Golden Lion, Golden Ram), the five nymph lineages
(Aurae, Naiad, Nereid, Oceanid, Oread), Satyr Minstrel, and
Soldier/Soldier Captain.

Generated by scripts/extract-great-labors.py from the source PDF.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 15:50:15 +02:00
Lukas c343fd3cd0 Add bundled-bestiary mechanism for shipping creatures with the app
D&D creatures listed in data/bestiary/dnd-bundled.json are now merged into
the search index and pre-loaded into creatureMap, so they appear alongside
5etools creatures with no "Load source" step. Source codes are derived from
the JSON itself (each creature carries source + sourceDisplayName), so adding
a new book is a pure data change. Bundled sources are excluded from
getAllSourceCodes() so bulk-import skips them, and they never appear in the
source manager (which only lists cached sources).

Includes a reference extractor (scripts/extract-great-labors.py) for the
5.5e revised stat-block format and a /bundle-bestiary skill that future
agents can follow to add monsters from other PDF books.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 15:49:34 +02:00
Lukas d9fb271607 Add PF2e encounter difficulty calculation with 5-tier budget system
CI / check (push) Successful in 2m39s
CI / build-image (push) Successful in 18s
Implements PF2e encounter difficulty alongside the existing D&D system.
PF2e uses creature level vs party level to derive XP, compares against
5-tier budgets (Trivial/Low/Moderate/Severe/Extreme), and adjusts
thresholds for party size. The indicator shows 4 bars in PF2e mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 15:24:18 +02:00
Lukas 064af16f95 Fix persistent damage tag ordering and differentiate condition icons
CI / check (push) Successful in 2m39s
CI / build-image (push) Successful in 18s
- Render persistent damage tags before the "+" button, not after
- Use insertion order for conditions on the row instead of definition order
- Differentiate Undetected condition (EyeClosed/slate) from Invisible (Ghost/violet)
- Use purple for void persistent damage to distinguish from violet conditions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 13:06:31 +02:00
Lukas 0f640601b6 Add force, void, spirit, vitality, and piercing persistent damage types
CI / check (push) Successful in 2m39s
CI / build-image (push) Successful in 19s
Expands persistent damage from 7 to 12 types to cover all PF2e damage
types that have verified persistent damage sources in published content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 12:44:03 +02:00
Lukas 4b1c1deda2 Add PF2e persistent damage condition tags
CI / check (push) Successful in 2m39s
CI / build-image (push) Successful in 19s
Persistent damage displayed as compact tags with damage type icon and
formula (e.g., Flame + "2d6"). Supports fire, bleed, acid, cold,
electricity, poison, and mental types. One instance per type, added via
sub-picker in the condition picker. PF2e only, persists across reload.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 12:09:31 +02:00
Lukas 09a801487d Add PF2e weak/elite creature adjustments with stat block toggle
CI / check (push) Successful in 2m32s
CI / build-image (push) Successful in 19s
Weak/Normal/Elite toggle in PF2e stat block header applies standard
adjustments (level, AC, HP, saves, Perception, attacks, damage) to
individual combatants. Adjusted stats are highlighted blue (elite) or
red (weak). Persisted via creatureAdjustment field on Combatant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 02:24:30 +02:00
63 changed files with 7072 additions and 401 deletions
+148
View File
@@ -0,0 +1,148 @@
---
name: bundle-bestiary
description: Bundle creatures from a third-party PDF into the app's D&D bestiary so they appear in search alongside 5etools creatures, with no "Load source" step. Use when the user asks to add monsters from a PDF book / adventure / supplement to the bundled bestiary.
---
## Instructions
Add the creatures from a PDF to `data/bestiary/dnd-bundled.json` so they appear in the D&D search index and render as normal stat blocks. Bundled creatures bypass the fetch/cache flow — they're shipped in the JS bundle and pre-loaded into `creatureMap` on startup.
### How the bundling works
- `data/bestiary/dnd-bundled.json` is an array of normalized `Creature` objects (the same shape produced by `bestiary-adapter.ts` for 5etools creatures).
- `apps/web/src/adapters/dnd-bundled-adapter.ts` static-imports the JSON and derives:
- `loadBundledDndCreatures()` — full stat blocks for the in-memory creature map
- `loadBundledDndIndexEntries()` — compact summaries for the search index
- `getBundledDndSources()` — source code → display name map, **derived from the JSON itself** (each creature carries its own `source` + `sourceDisplayName`)
- `bestiary-index-adapter.ts` merges the bundled entries into the search index and excludes bundled sources from `getAllSourceCodes()` (so bulk-import skips them).
- `use-bestiary.ts` merges bundled full creatures into `creatureMap` on init/refresh.
This means **adding a new bundled book is purely a data change**: append creatures to `dnd-bundled.json` with the new source's code and display name. No adapter or index code needs editing.
### Step 1 — Confirm scope and source code
Ask the user (don't guess):
1. **PDF path** and the **page range** containing the stat blocks. Many PDFs have hundreds of pages; only a slice has the bestiary.
2. **Source code abbreviation** — short uppercase letters, e.g., `TGL` for *The Great Labors*. Used in creature IDs and the index.
3. **Display name** — the human-readable book title shown in the source column.
4. **Edition / system** — confirm this is D&D (5e or 5.5e). Bundled creatures show in both 5e and 5.5e modes (the bestiary index only differentiates pf2e vs not). PF2e isn't currently supported by the bundled flow — if requested, this would need a parallel `pf2e-bundled-adapter.ts`.
5. **Licensing** — verify the user has the right to bundle the book's content. Don't make assumptions.
### Step 2 — Inspect the PDF
Check Python's PyPDF2 is available:
```bash
python3 -c "from PyPDF2 import PdfReader; print('ok')"
```
If not, the user has `pdftotext`-equivalent tooling configured at `~/Nextcloud/dnd/D&D/PROMPT_prep.md` worth checking.
Then dump and skim the target pages to learn the stat-block format:
```bash
python3 - <<'EOF'
from PyPDF2 import PdfReader
import os
r = PdfReader(os.path.expanduser('PATH/TO/PDF'))
for i in range(START-1, END):
print(f"\n===PAGE {i+1}===\n{r.pages[i].extract_text()}")
EOF
```
Look for the layout — the existing extractor (`scripts/extract-great-labors.py`) assumes the 5.5e/2024 revised format:
- `<Name>` line, then
- `<Size> <Type>(optional subtype), <Alignment>`, then
- `AC X Initiative ±Y (Z)`, then
- `HP N (NdN + N)`, then
- `Speed X ft., …`, then
- A `MOD SAVE MOD SAVE MOD SAVE` header followed by two ability-score rows, then
- Optional meta lines: `Skills`, `Saving Throws`, `Resistances`, `Immunities`, `Vulnerabilities`, `Senses`, `Languages`, then
- `Challenge X (NN XP; PB +N)`, then
- Section blocks: `Traits` / `Actions` / `Bonus Actions` / `Reactions` / `Legendary Actions`, each containing entries shaped like `Name. body...`.
If the PDF format matches, adapt the existing extractor. If it's a different format (5e 2014 with `STR DEX CON …` column layout, an older publisher's layout, a homebrew layout), expect to rework the parser more substantively.
### Step 3 — Adapt or extend the extractor
Copy `scripts/extract-great-labors.py` to a new script per book (e.g., `scripts/extract-<book-slug>.py`) and update:
- `SOURCE_CODE`, `SOURCE_DISPLAY`, `PAGE_START`, `PAGE_END` constants.
- The output path (`data/bestiary/dnd-bundled.json`). **Don't overwrite — merge.** The simplest pattern: read the existing file, drop any entries with the same `source`, then append the new ones.
- The `PROSE_TAIL_PATTERNS` list — every book has its own running headers (`<PageNumber>APPENDIX B … MONSTERS`-style), section-header phrases, and quote-attribution dashes. Run the extractor, audit the output (see Step 4), and add curated trim patterns for any prose tails that bleed in.
Run it:
```bash
python3 scripts/extract-<book-slug>.py PATH/TO/PDF
```
### Step 4 — Audit the output
PyPDF text extraction is messy. Always audit before claiming done:
```bash
python3 - <<'EOF'
import json, re
data = json.load(open('data/bestiary/dnd-bundled.json'))
new = [c for c in data if c['source'] == 'XXX'] # replace XXX with your code
for c in new:
print(f"{c['name']}: CR {c['cr']}, AC {c['ac']}, HP {c['hp']['average']} ({c['hp']['formula']})")
abs_ = c['abilities']
print(f" STR {abs_['str']} DEX {abs_['dex']} CON {abs_['con']} INT {abs_['int']} WIS {abs_['wis']} CHA {abs_['cha']}, PP {c['passive']}")
# Then audit bodies for prose-tail bleed and weird splits.
for c in new:
for sec in ('traits', 'actions', 'bonusActions', 'reactions'):
for e in c.get(sec, []):
body = e['segments'][0]['value']
issues = []
if len(body) > 600: issues.append(f"long({len(body)})")
if re.search(r'\.[A-Z][a-z]', body): issues.append("dot-Capital")
if 'APPENDIX' in body: issues.append("APPENDIX")
if re.search(r'—\s*[A-Z]\w+,\s', body): issues.append("attribution")
if issues:
print(f" {c['name']} [{sec}] {e['name']}: {', '.join(issues)}")
print(f" ...{body[-200:]}")
EOF
```
Common PDF extraction problems to fix in the parser:
- **PDF kerning quirks**: multi-digit values rendered with spaces (e.g., "Passive Perception 1 1" → 11, "Wis 81 1" with no space before negative). The existing parser handles most; check for new ones.
- **Smushed section headers**: lines like `...plants.Actions` where the section header for the next block was concatenated. Handle via `SECTION_HEADER_SMUSH_RE` preprocessing.
- **Cross-page prose bleed**: text from the next page's flavor prose absorbed into the last entry's body. Catch via `PROSE_TAIL_PATTERNS` — add curated phrases observed in this specific book.
- **Sibling-entry inline smush**: `damage.Ram. Melee Attack Roll: …` where two entries got concatenated. Already handled by the mid-line entry boundary regex in the existing parser.
- **Title-cased false positives**: words like `Bloodied.`, `Restrained.`, `Frightened.` at sentence ends would otherwise match the entry-name pattern. Filtered via `NAME_FALSE_POSITIVES` — add to it if the new book uses condition names you haven't seen yet.
### Step 5 — Verify in the app
```bash
pnpm check
```
Then start the dev server and search for one of the new creatures by name:
```bash
pnpm --filter web dev
```
Confirm in the browser:
1. Search finds the creature with the right book name as the source label.
2. Clicking it shows the full stat block immediately — **no "Load source" prompt**.
3. The source manager UI does **not** list the bundled book (it only shows cached sources).
4. Bulk import skips the bundled book.
### Notes for future agents
- **No need to edit `dnd-bundled-adapter.ts` or `bestiary-index-adapter.ts`** when adding a new book — the adapter derives source codes from the JSON.
- `data/bestiary/index.json` is regenerated from 5etools and should **not** be edited to add bundled entries. The merge happens at runtime in `bestiary-index-adapter.ts`.
- Each bundled creature must have:
- A unique `id` like `<sourcecode>:<slug>` (e.g., `tgl:anarch-boar`).
- `source` field matching the source code (e.g., `"TGL"`).
- `sourceDisplayName` field matching the book's display name (e.g., `"The Great Labors"`).
- All the required `Creature` fields from `packages/domain/src/creature-types.ts`.
- The script approach is preferred over hand-editing JSON for >5 creatures. For a single creature or two, hand-editing the JSON is reasonable; just match an existing entry's shape exactly.
- After any change to `dnd-bundled.json`, run `pnpm typecheck` — the static import in the adapter will catch shape mismatches at compile time.
+2 -2
View File
@@ -27,8 +27,8 @@
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^6.0.1",
"jsdom": "^29.0.1",
"jsdom": "^29.1.1",
"tailwindcss": "^4.2.2",
"vite": "^8.0.5"
"vite": "^8.0.16"
}
}
@@ -0,0 +1,28 @@
import type { Pf2eCreature } from "@initiative/domain";
import { creatureId } from "@initiative/domain";
let counter = 0;
export function buildPf2eCreature(
overrides?: Partial<Pf2eCreature>,
): Pf2eCreature {
const id = ++counter;
return {
system: "pf2e",
id: creatureId(`pf2e-creature-${id}`),
name: `PF2e Creature ${id}`,
source: "crb",
sourceDisplayName: "Core Rulebook",
level: 1,
traits: ["humanoid"],
perception: 5,
abilityMods: { str: 2, dex: 1, con: 2, int: 0, wis: 1, cha: -1 },
ac: 15,
saveFort: 7,
saveRef: 4,
saveWill: 5,
hp: 20,
speed: "25 ft.",
...overrides,
};
}
@@ -1,3 +1,4 @@
export { buildCombatant } from "./build-combatant.js";
export { buildCreature } from "./build-creature.js";
export { buildEncounter } from "./build-encounter.js";
export { buildPf2eCreature } from "./build-pf2e-creature.js";
@@ -16,12 +16,18 @@ vi.mock("../contexts/bestiary-context.js", () => ({
useBestiaryContext: vi.fn(),
}));
vi.mock("../contexts/encounter-context.js", () => ({
useEncounterContext: vi.fn(),
}));
import { StatBlockPanel } from "../components/stat-block-panel.js";
import { useBestiaryContext } from "../contexts/bestiary-context.js";
import { useEncounterContext } from "../contexts/encounter-context.js";
import { useSidePanelContext } from "../contexts/side-panel-context.js";
const mockUseSidePanelContext = vi.mocked(useSidePanelContext);
const mockUseBestiaryContext = vi.mocked(useBestiaryContext);
const mockUseEncounterContext = vi.mocked(useEncounterContext);
const CLOSE_REGEX = /close/i;
const COLLAPSE_REGEX = /collapse/i;
@@ -82,6 +88,7 @@ function setupMocks(overrides: PanelOverrides = {}) {
mockUseSidePanelContext.mockReturnValue({
selectedCreatureId: panelRole === "browse" ? creatureId : null,
selectedCombatantId: null,
pinnedCreatureId: panelRole === "pinned" ? creatureId : null,
isRightPanelCollapsed: panelRole === "browse" ? isCollapsed : false,
isWideDesktop: false,
@@ -110,6 +117,11 @@ function setupMocks(overrides: PanelOverrides = {}) {
refreshCache: vi.fn(),
} as ReturnType<typeof useBestiaryContext>);
mockUseEncounterContext.mockReturnValue({
encounter: { combatants: [], activeIndex: 0, roundNumber: 1 },
setCreatureAdjustment: vi.fn(),
} as unknown as ReturnType<typeof useEncounterContext>);
return { onToggleCollapse, onPin, onUnpin, onDismiss };
}
@@ -49,10 +49,9 @@ describe("loadBestiaryIndex", () => {
});
describe("getAllSourceCodes", () => {
it("returns all keys from the index sources", () => {
it("returns all index sources except bundled ones", () => {
const codes = getAllSourceCodes();
const index = loadBestiaryIndex();
expect(codes).toEqual(Object.keys(index.sources));
expect(codes).not.toContain("TGL");
});
it("returns only strings", () => {
@@ -0,0 +1,45 @@
import { describe, expect, it } from "vitest";
import {
getBundledDndSources,
loadBundledDndCreatures,
loadBundledDndIndexEntries,
} from "../dnd-bundled-adapter.js";
describe("dnd-bundled-adapter", () => {
it("loads bundled creatures with a valid shape", () => {
const creatures = loadBundledDndCreatures();
const sources = getBundledDndSources();
for (const c of creatures) {
expect(sources.has(c.source)).toBe(true);
expect(c.sourceDisplayName).toBe(sources.get(c.source));
expect(c.id.startsWith(`${c.source.toLowerCase()}:`)).toBe(true);
}
});
it("derives source codes from the creature data", () => {
const creatures = loadBundledDndCreatures();
const sources = getBundledDndSources();
const seen = new Set(creatures.map((c) => c.source));
expect(sources.size).toBe(seen.size);
for (const s of seen) {
expect(sources.has(s)).toBe(true);
}
});
it("derives index entries that match the bundled creatures", () => {
const creatures = loadBundledDndCreatures();
const entries = loadBundledDndIndexEntries();
expect(entries.length).toBe(creatures.length);
const entryNames = new Set(entries.map((e) => e.name));
for (const c of creatures) {
expect(entryNames.has(c.name)).toBe(true);
}
});
it("abbreviates sizes to single-letter codes in index entries", () => {
const entries = loadBundledDndIndexEntries();
for (const e of entries) {
expect(["T", "S", "M", "L", "H", "G"]).toContain(e.size);
}
});
});
@@ -1,6 +1,10 @@
import type { BestiaryIndex, BestiaryIndexEntry } from "@initiative/domain";
import rawIndex from "../../../../data/bestiary/index.json";
import {
getBundledDndSources,
loadBundledDndIndexEntries,
} from "./dnd-bundled-adapter.js";
interface CompactCreature {
readonly n: string;
@@ -55,23 +59,32 @@ export function loadBestiaryIndex(): BestiaryIndex {
if (cachedIndex) return cachedIndex;
const compact = rawIndex as unknown as CompactIndex;
const sources = Object.fromEntries(
const sources: Record<string, string> = Object.fromEntries(
Object.entries(compact.sources).filter(
([code]) => !EXCLUDED_SOURCES.has(code),
),
);
for (const [code, name] of getBundledDndSources()) {
sources[code] = name;
}
cachedIndex = {
sources,
creatures: compact.creatures
.filter((c) => !EXCLUDED_SOURCES.has(c.s))
.map(mapCreature),
creatures: [
...compact.creatures
.filter((c) => !EXCLUDED_SOURCES.has(c.s))
.map(mapCreature),
...loadBundledDndIndexEntries(),
],
};
return cachedIndex;
}
export function getAllSourceCodes(): string[] {
const index = loadBestiaryIndex();
return Object.keys(index.sources).filter((c) => !EXCLUDED_SOURCES.has(c));
const bundled = getBundledDndSources();
return Object.keys(index.sources).filter(
(c) => !EXCLUDED_SOURCES.has(c) && !bundled.has(c),
);
}
function sourceCodeToFilename(sourceCode: string): string {
@@ -0,0 +1,53 @@
import type { BestiaryIndexEntry, Creature } from "@initiative/domain";
import { creatureId } from "@initiative/domain";
import rawBundled from "../../../../data/bestiary/dnd-bundled.json";
type RawBundledCreature = Omit<Creature, "id"> & { id: string };
const SIZE_TO_CODE: Record<string, string> = {
Tiny: "T",
Small: "S",
Medium: "M",
Large: "L",
Huge: "H",
Gargantuan: "G",
};
/** Full normalized stat blocks for bundled D&D creatures. */
export function loadBundledDndCreatures(): Creature[] {
return (rawBundled as RawBundledCreature[]).map((c) => ({
...c,
id: creatureId(c.id),
}));
}
/** Index entries derived from the bundled creatures, in the compact shape
* used by the search index. */
export function loadBundledDndIndexEntries(): BestiaryIndexEntry[] {
return (rawBundled as RawBundledCreature[]).map((c) => ({
name: c.name,
source: c.source,
ac: c.ac,
hp: c.hp.average,
dex: c.abilities.dex,
cr: c.cr,
initiativeProficiency: c.initiativeProficiency,
size: SIZE_TO_CODE[c.size.split(" ")[0]] ?? "M",
type: c.type.split(" ")[0].toLowerCase(),
}));
}
/** Source codes → display names, derived from the bundled creatures' own
* `source` and `sourceDisplayName` fields. Adding a new book just means
* appending creatures with the right `source` field to dnd-bundled.json;
* no code change is required here. */
export function getBundledDndSources(): ReadonlyMap<string, string> {
const map = new Map<string, string>();
for (const c of rawBundled as RawBundledCreature[]) {
if (!map.has(c.source)) {
map.set(c.source, c.sourceDisplayName);
}
}
return map;
}
@@ -5,43 +5,73 @@ import {
type ConditionEntry,
type ConditionId,
getConditionsForEdition,
type PersistentDamageEntry,
type PersistentDamageType,
type RulesEdition,
} from "@initiative/domain";
import { cleanup, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { createRef, type RefObject } from "react";
import { createRef, type ReactNode, type RefObject, useEffect } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { RulesEditionProvider } from "../../contexts/index.js";
import { useRulesEditionContext } from "../../contexts/rules-edition-context.js";
import { ConditionPicker } from "../condition-picker";
afterEach(cleanup);
function EditionSetter({
edition,
children,
}: {
edition: RulesEdition;
children: ReactNode;
}) {
const { setEdition } = useRulesEditionContext();
useEffect(() => {
setEdition(edition);
}, [edition, setEdition]);
return <>{children}</>;
}
function renderPicker(
overrides: Partial<{
activeConditions: readonly ConditionEntry[];
activePersistentDamage: readonly PersistentDamageEntry[];
onToggle: (conditionId: ConditionId) => void;
onSetValue: (conditionId: ConditionId, value: number) => void;
onAddPersistentDamage: (
damageType: PersistentDamageType,
formula: string,
) => void;
onClose: () => void;
edition: RulesEdition;
}> = {},
) {
const onToggle = overrides.onToggle ?? vi.fn();
const onSetValue = overrides.onSetValue ?? vi.fn();
const onAddPersistentDamage = overrides.onAddPersistentDamage ?? vi.fn();
const onClose = overrides.onClose ?? vi.fn();
const edition = overrides.edition ?? "5.5e";
const anchorRef = createRef<HTMLElement>() as RefObject<HTMLElement>;
const anchor = document.createElement("div");
document.body.appendChild(anchor);
(anchorRef as { current: HTMLElement }).current = anchor;
const result = render(
<RulesEditionProvider>
<ConditionPicker
anchorRef={anchorRef}
activeConditions={overrides.activeConditions ?? []}
onToggle={onToggle}
onSetValue={onSetValue}
onClose={onClose}
/>
<EditionSetter edition={edition}>
<ConditionPicker
anchorRef={anchorRef}
activeConditions={overrides.activeConditions ?? []}
activePersistentDamage={overrides.activePersistentDamage}
onToggle={onToggle}
onSetValue={onSetValue}
onAddPersistentDamage={onAddPersistentDamage}
onClose={onClose}
/>
</EditionSetter>
</RulesEditionProvider>,
);
return { ...result, onToggle, onSetValue, onClose };
return { ...result, onToggle, onSetValue, onAddPersistentDamage, onClose };
}
describe("ConditionPicker", () => {
@@ -77,4 +107,111 @@ describe("ConditionPicker", () => {
const label = screen.getByText("Charmed");
expect(label.className).toContain("text-foreground");
});
describe("Valued conditions (PF2e)", () => {
it("clicking a valued condition opens the counter editor", async () => {
const user = userEvent.setup();
renderPicker({ edition: "pf2e" });
await user.click(screen.getByText("Frightened"));
// Counter editor shows value badge and [-]/[+] buttons
expect(screen.getByText("1")).toBeInTheDocument();
expect(
screen
.getAllByRole("button")
.some((b) => b.querySelector(".lucide-minus")),
).toBe(true);
});
it("increment and decrement adjust the counter value", async () => {
const user = userEvent.setup();
renderPicker({ edition: "pf2e" });
await user.click(screen.getByText("Frightened"));
// Value starts at 1; click [+] to go to 2
const plusButtons = screen.getAllByRole("button");
const plusButton = plusButtons.find((b) =>
b.querySelector(".lucide-plus"),
);
if (!plusButton) throw new Error("Plus button not found");
await user.click(plusButton);
expect(screen.getByText("2")).toBeInTheDocument();
// Click [-] to go back to 1
const minusButton = plusButtons.find((b) =>
b.querySelector(".lucide-minus"),
);
if (!minusButton) throw new Error("Minus button not found");
await user.click(minusButton);
expect(screen.getByText("1")).toBeInTheDocument();
});
it("confirm button calls onSetValue with condition and value", async () => {
const user = userEvent.setup();
const { onSetValue } = renderPicker({ edition: "pf2e" });
await user.click(screen.getByText("Frightened"));
// Increment to 2, then confirm
const plusButton = screen
.getAllByRole("button")
.find((b) => b.querySelector(".lucide-plus"));
if (!plusButton) throw new Error("Plus button not found");
await user.click(plusButton);
const checkButton = screen
.getAllByRole("button")
.find((b) => b.querySelector(".lucide-check"));
if (!checkButton) throw new Error("Check button not found");
await user.click(checkButton);
expect(onSetValue).toHaveBeenCalledWith("frightened", 2);
});
it("shows active value badge for existing valued condition", () => {
renderPicker({
edition: "pf2e",
activeConditions: [{ id: "frightened", value: 3 }],
});
expect(screen.getByText("3")).toBeInTheDocument();
});
it("pre-fills counter with existing value when editing", async () => {
const user = userEvent.setup();
renderPicker({
edition: "pf2e",
activeConditions: [{ id: "frightened", value: 3 }],
});
await user.click(screen.getByText("Frightened"));
expect(screen.getByText("3")).toBeInTheDocument();
});
it("disables increment at maxValue", async () => {
const user = userEvent.setup();
renderPicker({
edition: "pf2e",
activeConditions: [{ id: "doomed", value: 3 }],
});
// Doomed has maxValue: 3, click to edit
await user.click(screen.getByText("Doomed"));
const plusButton = screen
.getAllByRole("button")
.find((b) => b.querySelector(".lucide-plus"));
expect(plusButton).toBeDisabled();
});
});
describe("Persistent Damage (PF2e)", () => {
it("shows 'Persistent Damage' entry when edition is pf2e", () => {
renderPicker({ edition: "pf2e" });
expect(screen.getByText("Persistent Damage")).toBeInTheDocument();
});
it("clicking 'Persistent Damage' opens sub-picker", async () => {
const user = userEvent.setup();
renderPicker({ edition: "pf2e" });
await user.click(screen.getByText("Persistent Damage"));
expect(screen.getByPlaceholderText("2d6")).toBeInTheDocument();
});
});
describe("Persistent Damage (D&D)", () => {
it("hides 'Persistent Damage' entry when edition is D&D", () => {
renderPicker({ edition: "5.5e" });
expect(screen.queryByText("Persistent Damage")).not.toBeInTheDocument();
});
});
});
@@ -38,6 +38,22 @@ describe("Dialog", () => {
expect(dialog?.hasAttribute("open")).toBe(false);
});
it("unmounts children when closed so internal state does not persist", () => {
const { rerender } = render(
<Dialog open={true} onClose={() => {}}>
<span>Body</span>
</Dialog>,
);
expect(screen.queryByText("Body")).not.toBeNull();
rerender(
<Dialog open={false} onClose={() => {}}>
<span>Body</span>
</Dialog>,
);
expect(screen.queryByText("Body")).toBeNull();
});
it("calls onClose on cancel event", () => {
const onClose = vi.fn();
render(
@@ -1,7 +1,11 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
import type { Creature, CreatureId, PlayerCharacter } from "@initiative/domain";
import type {
AnyCreature,
CreatureId,
PlayerCharacter,
} from "@initiative/domain";
import { combatantId, creatureId, playerCharacterId } from "@initiative/domain";
import {
cleanup,
@@ -17,6 +21,7 @@ import {
buildCombatant,
buildCreature,
buildEncounter,
buildPf2eCreature,
} from "../../__tests__/factories/index.js";
import { AllProviders } from "../../__tests__/test-providers.js";
import { useRulesEdition } from "../../hooks/use-rules-edition.js";
@@ -52,7 +57,7 @@ const goblinCreature = buildCreature({
function renderPanel(options: {
encounter: ReturnType<typeof buildEncounter>;
playerCharacters?: PlayerCharacter[];
creatures?: Map<CreatureId, Creature>;
creatures?: Map<CreatureId, AnyCreature>;
onClose?: () => void;
}) {
const adapters = createTestAdapters({
@@ -357,4 +362,157 @@ describe("DifficultyBreakdownPanel", () => {
expect(onClose).toHaveBeenCalledOnce();
});
describe("PF2e edition", () => {
const orcWarrior = buildPf2eCreature({
id: creatureId("pf2e:orc-warrior"),
name: "Orc Warrior",
level: 3,
source: "crb",
sourceDisplayName: "Core Rulebook",
});
function pf2eEncounter() {
return buildEncounter({
combatants: [
buildCombatant({
id: combatantId("c-1"),
name: "Hero",
playerCharacterId: pcId1,
}),
buildCombatant({
id: combatantId("c-2"),
name: "Orc Warrior",
creatureId: orcWarrior.id,
}),
],
});
}
it("shows PF2e tier label", async () => {
const { result: editionResult } = renderHook(() => useRulesEdition());
editionResult.current.setEdition("pf2e");
try {
renderPanel({
encounter: pf2eEncounter(),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[orcWarrior.id, orcWarrior]]),
});
await waitFor(() => {
expect(
screen.getByText("Encounter Difficulty:", { exact: false }),
).toBeInTheDocument();
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
it("shows party level", async () => {
const { result: editionResult } = renderHook(() => useRulesEdition());
editionResult.current.setEdition("pf2e");
try {
renderPanel({
encounter: pf2eEncounter(),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[orcWarrior.id, orcWarrior]]),
});
await waitFor(() => {
expect(
screen.getByText("Party Level: 5", { exact: false }),
).toBeInTheDocument();
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
it("shows creature level and level difference", async () => {
const { result: editionResult } = renderHook(() => useRulesEdition());
editionResult.current.setEdition("pf2e");
try {
renderPanel({
encounter: pf2eEncounter(),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[orcWarrior.id, orcWarrior]]),
});
await waitFor(() => {
// Orc Warrior level 3, party level 5 → diff 2
expect(
screen.getByText("Lv 3 (-2)", { exact: false }),
).toBeInTheDocument();
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
it("shows 5 thresholds with short labels", async () => {
const { result: editionResult } = renderHook(() => useRulesEdition());
editionResult.current.setEdition("pf2e");
try {
renderPanel({
encounter: pf2eEncounter(),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[orcWarrior.id, orcWarrior]]),
});
await waitFor(() => {
expect(
screen.getByText("Triv:", { exact: false }),
).toBeInTheDocument();
expect(
screen.getByText("Low:", { exact: false }),
).toBeInTheDocument();
expect(
screen.getByText("Mod:", { exact: false }),
).toBeInTheDocument();
expect(
screen.getByText("Sev:", { exact: false }),
).toBeInTheDocument();
expect(
screen.getByText("Ext:", { exact: false }),
).toBeInTheDocument();
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
it("shows Net Creature XP label in PF2e mode", async () => {
const { result: editionResult } = renderHook(() => useRulesEdition());
editionResult.current.setEdition("pf2e");
try {
renderPanel({
encounter: pf2eEncounter(),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[orcWarrior.id, orcWarrior]]),
});
await waitFor(() => {
expect(screen.getByText("Net Creature XP")).toBeInTheDocument();
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
});
});
@@ -7,6 +7,7 @@ import {
DifficultyIndicator,
TIER_LABELS_5_5E,
TIER_LABELS_2014,
TIER_LABELS_PF2E,
} from "../difficulty-indicator.js";
afterEach(cleanup);
@@ -23,6 +24,7 @@ function makeResult(tier: DifficultyResult["tier"]): DifficultyResult {
encounterMultiplier: undefined,
adjustedXp: undefined,
partySizeAdjusted: undefined,
partyLevel: undefined,
};
}
@@ -125,4 +127,64 @@ describe("DifficultyIndicator", () => {
const element = container.querySelector("[role='img']");
expect(element?.tagName).toBe("BUTTON");
});
it("renders 4 bars when barCount is 4", () => {
const { container } = render(
<DifficultyIndicator
result={makeResult(2)}
labels={TIER_LABELS_PF2E}
barCount={4}
/>,
);
const bars = container.querySelectorAll("[class*='rounded-sm']");
expect(bars).toHaveLength(4);
});
it("shows 0 filled bars for tier 0 with 4 bars", () => {
const { container } = render(
<DifficultyIndicator
result={makeResult(0)}
labels={TIER_LABELS_PF2E}
barCount={4}
/>,
);
const bars = container.querySelectorAll("[class*='rounded-sm']");
for (const bar of bars) {
expect(bar.className).toContain("bg-muted");
}
});
it("shows correct PF2e tooltip for Severe tier", () => {
render(
<DifficultyIndicator
result={makeResult(3)}
labels={TIER_LABELS_PF2E}
barCount={4}
/>,
);
expect(
screen.getByRole("img", { name: "Severe encounter difficulty" }),
).toBeDefined();
});
it("shows correct PF2e tooltip for Extreme tier", () => {
render(
<DifficultyIndicator
result={makeResult(4)}
labels={TIER_LABELS_PF2E}
barCount={4}
/>,
);
expect(
screen.getByRole("img", { name: "Extreme encounter difficulty" }),
).toBeDefined();
});
it("D&D indicator still renders 3 bars (no regression)", () => {
const { container } = render(
<DifficultyIndicator result={makeResult(3)} labels={TIER_LABELS_5_5E} />,
);
const bars = container.querySelectorAll("[class*='rounded-sm']");
expect(bars).toHaveLength(3);
});
});
@@ -0,0 +1,76 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
import { cleanup, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { PersistentDamagePicker } from "../persistent-damage-picker.js";
afterEach(cleanup);
function renderPicker(
overrides: Partial<{
activeEntries: { type: string; formula: string }[];
onAdd: (damageType: string, formula: string) => void;
onClose: () => void;
}> = {},
) {
const onAdd = overrides.onAdd ?? vi.fn();
const onClose = overrides.onClose ?? vi.fn();
const result = render(
<PersistentDamagePicker
activeEntries={
(overrides.activeEntries as Parameters<
typeof PersistentDamagePicker
>[0]["activeEntries"]) ?? undefined
}
onAdd={onAdd as Parameters<typeof PersistentDamagePicker>[0]["onAdd"]}
onClose={onClose}
/>,
);
return { ...result, onAdd, onClose };
}
describe("PersistentDamagePicker", () => {
it("renders damage type dropdown and formula input", () => {
renderPicker();
expect(screen.getByRole("combobox")).toBeInTheDocument();
expect(screen.getByPlaceholderText("2d6")).toBeInTheDocument();
});
it("confirm button is disabled when formula is empty", () => {
renderPicker();
expect(
screen.getByRole("button", { name: "Add persistent damage" }),
).toBeDisabled();
});
it("submitting calls onAdd with selected type and formula", async () => {
const user = userEvent.setup();
const { onAdd } = renderPicker();
await user.type(screen.getByPlaceholderText("2d6"), "3d6");
await user.click(
screen.getByRole("button", { name: "Add persistent damage" }),
);
expect(onAdd).toHaveBeenCalledWith("fire", "3d6");
});
it("Enter in formula input confirms", async () => {
const user = userEvent.setup();
const { onAdd } = renderPicker();
await user.type(screen.getByPlaceholderText("2d6"), "2d6{Enter}");
expect(onAdd).toHaveBeenCalledWith("fire", "2d6");
});
it("pre-fills formula for existing active entry", async () => {
const user = userEvent.setup();
renderPicker({
activeEntries: [{ type: "fire", formula: "2d6" }],
});
expect(screen.getByPlaceholderText("2d6")).toHaveValue("2d6");
// Change type to one without active entry
await user.selectOptions(screen.getByRole("combobox"), "bleed");
expect(screen.getByPlaceholderText("2d6")).toHaveValue("");
});
});
@@ -0,0 +1,66 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
import type {
PersistentDamageEntry,
PersistentDamageType,
} from "@initiative/domain";
import { cleanup, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { PersistentDamageTags } from "../persistent-damage-tags.js";
afterEach(cleanup);
function renderTags(
entries: readonly PersistentDamageEntry[] | undefined,
onRemove = vi.fn(),
) {
const result = render(
<PersistentDamageTags entries={entries} onRemove={onRemove} />,
);
return { ...result, onRemove };
}
describe("PersistentDamageTags", () => {
it("renders nothing when entries undefined", () => {
const { container } = renderTags(undefined);
expect(container.innerHTML).toBe("");
});
it("renders nothing when entries is empty array", () => {
const { container } = renderTags([]);
expect(container.innerHTML).toBe("");
});
it("renders tag per entry with icon and formula text", () => {
renderTags([
{ type: "fire", formula: "2d6" },
{ type: "bleed", formula: "1d4" },
]);
expect(screen.getByText("2d6")).toBeInTheDocument();
expect(screen.getByText("1d4")).toBeInTheDocument();
});
it("click calls onRemove with correct damage type", async () => {
const user = userEvent.setup();
const { onRemove } = renderTags([{ type: "fire", formula: "2d6" }]);
await user.click(
screen.getByRole("button", {
name: "Remove persistent Fire damage",
}),
);
expect(onRemove).toHaveBeenCalledWith(
"fire" satisfies PersistentDamageType,
);
});
it("tooltip shows full description", () => {
renderTags([{ type: "fire", formula: "2d6" }]);
expect(
screen.getByRole("button", {
name: "Remove persistent Fire damage",
}),
).toBeInTheDocument();
});
});
+29 -5
View File
@@ -3,6 +3,7 @@ import {
type ConditionEntry,
type CreatureId,
deriveHpStatus,
type PersistentDamageEntry,
type PlayerIcon,
type RollMode,
} from "@initiative/domain";
@@ -19,6 +20,7 @@ import { ConditionPicker } from "./condition-picker.js";
import { ConditionTags } from "./condition-tags.js";
import { D20Icon } from "./d20-icon.js";
import { HpAdjustPopover } from "./hp-adjust-popover.js";
import { PersistentDamageTags } from "./persistent-damage-tags.js";
import { PLAYER_COLOR_HEX, PLAYER_ICON_MAP } from "./player-icon-map.js";
import { RollModeMenu } from "./roll-mode-menu.js";
import { ConfirmButton } from "./ui/confirm-button.js";
@@ -33,6 +35,7 @@ interface Combatant {
readonly tempHp?: number;
readonly ac?: number;
readonly conditions?: readonly ConditionEntry[];
readonly persistentDamage?: readonly PersistentDamageEntry[];
readonly isConcentrating?: boolean;
readonly color?: string;
readonly icon?: string;
@@ -454,15 +457,23 @@ export function CombatantRow({
setConditionValue,
decrementCondition,
toggleConcentration,
addPersistentDamage,
removePersistentDamage,
} = useEncounterContext();
const { selectedCreatureId, showCreature, toggleCollapse } =
useSidePanelContext();
const {
selectedCreatureId,
selectedCombatantId,
showCreature,
toggleCollapse,
} = useSidePanelContext();
const { handleRollInitiative } = useInitiativeRollsContext();
const { edition } = useRulesEditionContext();
const isPf2e = edition === "pf2e";
// Derive what was previously conditional props
const isStatBlockOpen = combatant.creatureId === selectedCreatureId;
const isStatBlockOpen =
combatant.creatureId === selectedCreatureId &&
combatant.id === selectedCombatantId;
const { creatureId } = combatant;
const hasStatBlock = !!creatureId;
const onToggleStatBlock = hasStatBlock
@@ -470,7 +481,7 @@ export function CombatantRow({
if (isStatBlockOpen) {
toggleCollapse();
} else {
showCreature(creatureId);
showCreature(creatureId, combatant.id);
}
}
: undefined;
@@ -607,16 +618,29 @@ export function CombatantRow({
onRemove={(conditionId) => toggleCondition(id, conditionId)}
onDecrement={(conditionId) => decrementCondition(id, conditionId)}
onOpenPicker={() => setPickerOpen((prev) => !prev)}
/>
>
{isPf2e && (
<PersistentDamageTags
entries={combatant.persistentDamage}
onRemove={(damageType) =>
removePersistentDamage(id, damageType)
}
/>
)}
</ConditionTags>
</div>
{!!pickerOpen && (
<ConditionPicker
anchorRef={conditionAnchorRef}
activeConditions={combatant.conditions}
activePersistentDamage={combatant.persistentDamage}
onToggle={(conditionId) => toggleCondition(id, conditionId)}
onSetValue={(conditionId, value) =>
setConditionValue(id, conditionId, value)
}
onAddPersistentDamage={(damageType, formula) =>
addPersistentDamage(id, damageType, formula)
}
onClose={() => setPickerOpen(false)}
/>
)}
+162 -101
View File
@@ -3,9 +3,11 @@ import {
type ConditionId,
getConditionDescription,
getConditionsForEdition,
type PersistentDamageEntry,
type PersistentDamageType,
} from "@initiative/domain";
import { Check, Minus, Plus } from "lucide-react";
import { useLayoutEffect, useRef, useState } from "react";
import { Check, Flame, Minus, Plus } from "lucide-react";
import React, { useLayoutEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import { useRulesEditionContext } from "../contexts/rules-edition-context.js";
import { useClickOutside } from "../hooks/use-click-outside.js";
@@ -14,21 +16,29 @@ import {
CONDITION_COLOR_CLASSES,
CONDITION_ICON_MAP,
} from "./condition-styles.js";
import { PersistentDamagePicker } from "./persistent-damage-picker.js";
import { Tooltip } from "./ui/tooltip.js";
interface ConditionPickerProps {
anchorRef: React.RefObject<HTMLElement | null>;
activeConditions: readonly ConditionEntry[] | undefined;
activePersistentDamage?: readonly PersistentDamageEntry[];
onToggle: (conditionId: ConditionId) => void;
onSetValue: (conditionId: ConditionId, value: number) => void;
onAddPersistentDamage?: (
damageType: PersistentDamageType,
formula: string,
) => void;
onClose: () => void;
}
export function ConditionPicker({
anchorRef,
activeConditions,
activePersistentDamage,
onToggle,
onSetValue,
onAddPersistentDamage,
onClose,
}: Readonly<ConditionPickerProps>) {
const ref = useRef<HTMLDivElement>(null);
@@ -42,6 +52,7 @@ export function ConditionPicker({
id: ConditionId;
value: number;
} | null>(null);
const [showPersistentDamage, setShowPersistentDamage] = useState(false);
useLayoutEffect(() => {
const anchor = anchorRef.current;
@@ -71,6 +82,51 @@ export function ConditionPicker({
const activeMap = new Map(
(activeConditions ?? []).map((e) => [e.id, e.value]),
);
const showPersistentDamageEntry =
edition === "pf2e" && !!onAddPersistentDamage;
const persistentDamageInsertIndex = showPersistentDamageEntry
? conditions.findIndex(
(d) => d.label.localeCompare("Persistent Damage") > 0,
)
: -1;
const persistentDamageEntry = showPersistentDamageEntry ? (
<React.Fragment key="persistent-damage">
<div
className={cn(
"flex w-full items-center gap-2 rounded px-2 py-1 text-sm transition-colors",
showPersistentDamage && "bg-card/50",
)}
>
<button
type="button"
className="flex flex-1 items-center gap-2"
onClick={() => setShowPersistentDamage((prev) => !prev)}
>
<Flame
size={14}
className={
showPersistentDamage ? "text-orange-400" : "text-muted-foreground"
}
/>
<span
className={
showPersistentDamage ? "text-foreground" : "text-muted-foreground"
}
>
Persistent Damage
</span>
</button>
</div>
{!!showPersistentDamage && (
<PersistentDamagePicker
activeEntries={activePersistentDamage}
onAdd={onAddPersistentDamage}
onClose={() => setShowPersistentDamage(false)}
/>
)}
</React.Fragment>
) : null;
return createPortal(
<div
@@ -82,7 +138,7 @@ export function ConditionPicker({
: { visibility: "hidden" as const }
}
>
{conditions.map((def) => {
{conditions.map((def, index) => {
const Icon = CONDITION_ICON_MAP[def.iconName];
if (!Icon) return null;
const isActive = activeMap.has(def.id);
@@ -104,111 +160,116 @@ export function ConditionPicker({
};
return (
<Tooltip
key={def.id}
content={getConditionDescription(def, edition)}
className="block"
>
<div
className={cn(
"flex w-full items-center gap-2 rounded px-2 py-1 text-sm transition-colors",
(isActive || isEditing) && "bg-card/50",
)}
<React.Fragment key={def.id}>
{index === persistentDamageInsertIndex && persistentDamageEntry}
<Tooltip
content={getConditionDescription(def, edition)}
className="block"
>
<button
type="button"
className="flex flex-1 items-center gap-2"
onClick={handleClick}
<div
className={cn(
"flex w-full items-center gap-2 rounded px-2 py-1 text-sm transition-colors",
(isActive || isEditing) && "bg-card/50",
)}
>
<Icon
size={14}
className={
isActive || isEditing ? colorClass : "text-muted-foreground"
}
/>
<span
className={
isActive || isEditing
? "text-foreground"
: "text-muted-foreground"
}
<button
type="button"
className="flex flex-1 items-center gap-2"
onClick={handleClick}
>
{def.label}
</span>
</button>
{isActive && def.valued && edition === "pf2e" && !isEditing && (
<span className="min-w-5 rounded-full bg-accent px-1.5 py-0.5 text-center font-medium text-primary-foreground text-xs">
{activeValue}
</span>
)}
{isEditing && (
<div className="flex items-center gap-0.5">
<button
type="button"
className="rounded p-0.5 text-foreground hover:bg-accent/40"
onMouseDown={(e) => e.preventDefault()}
onClick={(e) => {
e.stopPropagation();
if (editing.value > 1) {
setEditing({
...editing,
value: editing.value - 1,
});
}
}}
<Icon
size={14}
className={
isActive || isEditing
? colorClass
: "text-muted-foreground"
}
/>
<span
className={
isActive || isEditing
? "text-foreground"
: "text-muted-foreground"
}
>
<Minus className="h-3 w-3" />
</button>
<span className="min-w-5 rounded-full bg-accent px-1.5 py-0.5 text-center font-medium text-primary-foreground text-xs">
{editing.value}
{def.label}
</span>
{(() => {
const atMax =
def.maxValue !== undefined &&
editing.value >= def.maxValue;
return (
<button
type="button"
className={cn(
"rounded p-0.5",
atMax
? "cursor-not-allowed text-muted-foreground opacity-50"
: "text-foreground hover:bg-accent/40",
)}
disabled={atMax}
onMouseDown={(e) => e.preventDefault()}
onClick={(e) => {
e.stopPropagation();
if (!atMax) {
setEditing({
...editing,
value: editing.value + 1,
});
}
}}
>
<Plus className="h-3 w-3" />
</button>
);
})()}
<button
type="button"
className="ml-0.5 rounded p-0.5 text-foreground hover:bg-accent/40"
onMouseDown={(e) => e.preventDefault()}
onClick={(e) => {
e.stopPropagation();
onSetValue(editing.id, editing.value);
setEditing(null);
}}
>
<Check className="h-3.5 w-3.5" />
</button>
</div>
)}
</div>
</Tooltip>
</button>
{isActive && def.valued && edition === "pf2e" && !isEditing && (
<span className="min-w-5 rounded-full bg-accent px-1.5 py-0.5 text-center font-medium text-primary-foreground text-xs">
{activeValue}
</span>
)}
{isEditing && (
<div className="flex items-center gap-0.5">
<button
type="button"
className="rounded p-0.5 text-foreground hover:bg-accent/40"
onMouseDown={(e) => e.preventDefault()}
onClick={(e) => {
e.stopPropagation();
if (editing.value > 1) {
setEditing({
...editing,
value: editing.value - 1,
});
}
}}
>
<Minus className="h-3 w-3" />
</button>
<span className="min-w-5 rounded-full bg-accent px-1.5 py-0.5 text-center font-medium text-primary-foreground text-xs">
{editing.value}
</span>
{(() => {
const atMax =
def.maxValue !== undefined &&
editing.value >= def.maxValue;
return (
<button
type="button"
className={cn(
"rounded p-0.5",
atMax
? "cursor-not-allowed text-muted-foreground opacity-50"
: "text-foreground hover:bg-accent/40",
)}
disabled={atMax}
onMouseDown={(e) => e.preventDefault()}
onClick={(e) => {
e.stopPropagation();
if (!atMax) {
setEditing({
...editing,
value: editing.value + 1,
});
}
}}
>
<Plus className="h-3 w-3" />
</button>
);
})()}
<button
type="button"
className="ml-0.5 rounded p-0.5 text-foreground hover:bg-accent/40"
onMouseDown={(e) => e.preventDefault()}
onClick={(e) => {
e.stopPropagation();
onSetValue(editing.id, editing.value);
setEditing(null);
}}
>
<Check className="h-3.5 w-3.5" />
</button>
</div>
)}
</div>
</Tooltip>
</React.Fragment>
);
})}
{persistentDamageInsertIndex === -1 && persistentDamageEntry}
</div>,
document.body,
);
@@ -11,8 +11,12 @@ import {
Droplet,
Droplets,
EarOff,
Eclipse,
Eye,
EyeClosed,
EyeOff,
Flame,
FlaskConical,
Footprints,
Gem,
Ghost,
@@ -22,15 +26,20 @@ import {
HeartPulse,
Link,
Moon,
Orbit,
PersonStanding,
ShieldMinus,
ShieldOff,
Siren,
Skull,
Snail,
Snowflake,
Sparkle,
Sparkles,
Sun,
Sword,
TrendingDown,
Wind,
Zap,
ZapOff,
} from "lucide-react";
@@ -47,8 +56,12 @@ export const CONDITION_ICON_MAP: Record<string, LucideIcon> = {
Droplet,
Droplets,
EarOff,
Eclipse,
Eye,
EyeClosed,
EyeOff,
Flame,
FlaskConical,
Footprints,
Gem,
Ghost,
@@ -58,15 +71,20 @@ export const CONDITION_ICON_MAP: Record<string, LucideIcon> = {
HeartPulse,
Link,
Moon,
Orbit,
PersonStanding,
ShieldMinus,
ShieldOff,
Siren,
Skull,
Snail,
Snowflake,
Sparkle,
Sparkles,
Sun,
Sword,
TrendingDown,
Wind,
Zap,
ZapOff,
};
@@ -76,11 +94,13 @@ export const CONDITION_COLOR_CLASSES: Record<string, string> = {
pink: "text-pink-400",
amber: "text-amber-400",
orange: "text-orange-400",
purple: "text-purple-400",
gray: "text-gray-400",
violet: "text-violet-400",
yellow: "text-yellow-400",
slate: "text-slate-400",
green: "text-green-400",
lime: "text-lime-400",
indigo: "text-indigo-400",
sky: "text-sky-400",
red: "text-red-400",
@@ -5,6 +5,7 @@ import {
getConditionDescription,
} from "@initiative/domain";
import { Plus } from "lucide-react";
import type { ReactNode } from "react";
import { useRulesEditionContext } from "../contexts/rules-edition-context.js";
import { cn } from "../lib/utils.js";
import {
@@ -18,6 +19,7 @@ interface ConditionTagsProps {
onRemove: (conditionId: ConditionId) => void;
onDecrement: (conditionId: ConditionId) => void;
onOpenPicker: () => void;
children?: ReactNode;
}
export function ConditionTags({
@@ -25,6 +27,7 @@ export function ConditionTags({
onRemove,
onDecrement,
onOpenPicker,
children,
}: Readonly<ConditionTagsProps>) {
const { edition } = useRulesEditionContext();
return (
@@ -69,6 +72,7 @@ export function ConditionTags({
</Tooltip>
);
})}
{children}
<button
type="button"
title="Add condition"
@@ -19,12 +19,21 @@ const TIER_LABEL_MAP: Partial<
1: { label: "Low", color: "text-green-500" },
2: { label: "Moderate", color: "text-yellow-500" },
3: { label: "High", color: "text-red-500" },
4: { label: "High", color: "text-red-500" },
},
"5e": {
0: { label: "Easy", color: "text-muted-foreground" },
1: { label: "Medium", color: "text-green-500" },
2: { label: "Hard", color: "text-yellow-500" },
3: { label: "Deadly", color: "text-red-500" },
4: { label: "Deadly", color: "text-red-500" },
},
pf2e: {
0: { label: "Trivial", color: "text-muted-foreground" },
1: { label: "Low", color: "text-green-500" },
2: { label: "Moderate", color: "text-yellow-500" },
3: { label: "Severe", color: "text-orange-500" },
4: { label: "Extreme", color: "text-red-500" },
},
};
@@ -32,6 +41,9 @@ const TIER_LABEL_MAP: Partial<
const SHORT_LABELS: Readonly<Record<string, string>> = {
Moderate: "Mod",
Medium: "Med",
Trivial: "Triv",
Severe: "Sev",
Extreme: "Ext",
};
function shortLabel(label: string): string {
@@ -107,6 +119,54 @@ function NpcRow({
);
}
function Pf2eNpcRow({
entry,
onToggleSide,
}: {
entry: BreakdownCombatant;
onToggleSide: () => void;
}) {
const isParty = entry.side === "party";
const targetSide = isParty ? "enemy" : "party";
let xpDisplay: string;
if (entry.xp == null) {
xpDisplay = "\u2014";
} else if (isParty) {
xpDisplay = `\u2212${formatXp(entry.xp)}`;
} else {
xpDisplay = formatXp(entry.xp);
}
let levelDisplay: string;
if (entry.creatureLevel === undefined) {
levelDisplay = "\u2014";
} else if (entry.levelDifference === undefined) {
levelDisplay = `Lv ${entry.creatureLevel}`;
} else {
const sign = entry.levelDifference >= 0 ? "+" : "";
levelDisplay = `Lv ${entry.creatureLevel} (${sign}${entry.levelDifference})`;
}
return (
<div className="col-span-4 grid grid-cols-subgrid items-center text-xs">
<span className="min-w-0 truncate" title={entry.combatant.name}>
{entry.combatant.name}
</span>
<Button
variant="ghost"
size="icon-sm"
onClick={onToggleSide}
aria-label={`Move ${entry.combatant.name} to ${targetSide} side`}
>
<ArrowLeftRight className="h-3 w-3" />
</Button>
<span className="text-muted-foreground">{levelDisplay}</span>
<span className="text-right tabular-nums">{xpDisplay}</span>
</div>
);
}
export function DifficultyBreakdownPanel({ onClose }: { onClose: () => void }) {
const ref = useRef<HTMLDivElement>(null);
useClickOutside(ref, onClose);
@@ -128,6 +188,8 @@ export function DifficultyBreakdownPanel({ onClose }: { onClose: () => void }) {
const isPC = (entry: BreakdownCombatant) =>
entry.combatant.playerCharacterId != null;
const CreatureRow = edition === "pf2e" ? Pf2eNpcRow : NpcRow;
return (
<div
ref={ref}
@@ -142,6 +204,9 @@ export function DifficultyBreakdownPanel({ onClose }: { onClose: () => void }) {
<div className="mb-1 text-muted-foreground text-xs">
Party Budget ({breakdown.pcCount}{" "}
{breakdown.pcCount === 1 ? "PC" : "PCs"})
{breakdown.partyLevel !== undefined && (
<> &middot; Party Level: {breakdown.partyLevel}</>
)}
</div>
<div className="flex gap-3 text-xs">
{breakdown.thresholds.map((t) => (
@@ -166,7 +231,7 @@ export function DifficultyBreakdownPanel({ onClose }: { onClose: () => void }) {
isPC(entry) ? (
<PcRow key={entry.combatant.id} entry={entry} />
) : (
<NpcRow
<CreatureRow
key={entry.combatant.id}
entry={entry}
onToggleSide={() => handleToggle(entry)}
@@ -186,7 +251,7 @@ export function DifficultyBreakdownPanel({ onClose }: { onClose: () => void }) {
isPC(entry) ? (
<PcRow key={entry.combatant.id} entry={entry} />
) : (
<NpcRow
<CreatureRow
key={entry.combatant.id}
entry={entry}
onToggleSide={() => handleToggle(entry)}
@@ -218,7 +283,9 @@ export function DifficultyBreakdownPanel({ onClose }: { onClose: () => void }) {
</div>
) : (
<div className="mt-2 flex justify-between border-border border-t pt-2 font-medium text-xs">
<span>Net Monster XP</span>
<span>
{edition === "pf2e" ? "Net Creature XP" : "Net Monster XP"}
</span>
<span className="tabular-nums">
{formatXp(breakdown.totalMonsterXp)}
</span>
@@ -6,6 +6,7 @@ export const TIER_LABELS_5_5E: Record<DifficultyTier, string> = {
1: "Low",
2: "Moderate",
3: "High",
4: "High",
};
export const TIER_LABELS_2014: Record<DifficultyTier, string> = {
@@ -13,30 +14,49 @@ export const TIER_LABELS_2014: Record<DifficultyTier, string> = {
1: "Medium",
2: "Hard",
3: "Deadly",
4: "Deadly",
};
const TIER_COLORS: Record<
DifficultyTier,
{ filledBars: number; color: string }
> = {
0: { filledBars: 0, color: "" },
1: { filledBars: 1, color: "bg-green-500" },
2: { filledBars: 2, color: "bg-yellow-500" },
3: { filledBars: 3, color: "bg-red-500" },
export const TIER_LABELS_PF2E: Record<DifficultyTier, string> = {
0: "Trivial",
1: "Low",
2: "Moderate",
3: "Severe",
4: "Extreme",
};
const BAR_HEIGHTS = ["h-2", "h-3", "h-4"] as const;
const BAR_HEIGHTS_3 = ["h-2", "h-3", "h-4"] as const;
const BAR_HEIGHTS_4 = ["h-1.5", "h-2", "h-3", "h-4"] as const;
/** Color for the Nth filled bar (1-indexed) in 4-bar mode. */
const BAR_COLORS: Record<number, string> = {
1: "bg-green-500",
2: "bg-yellow-500",
3: "bg-orange-500",
4: "bg-red-500",
};
/** For 3-bar mode, bar 3 uses red directly (skip orange). */
const BAR_COLORS_3: Record<number, string> = {
1: "bg-green-500",
2: "bg-yellow-500",
3: "bg-red-500",
};
export function DifficultyIndicator({
result,
labels,
barCount = 3,
onClick,
}: {
result: DifficultyResult;
labels: Record<DifficultyTier, string>;
barCount?: 3 | 4;
onClick?: () => void;
}) {
const config = TIER_COLORS[result.tier];
const barHeights = barCount === 4 ? BAR_HEIGHTS_4 : BAR_HEIGHTS_3;
const colorMap = barCount === 4 ? BAR_COLORS : BAR_COLORS_3;
const filledBars = result.tier;
const label = labels[result.tier];
const tooltip = `${label} encounter difficulty`;
@@ -54,13 +74,13 @@ export function DifficultyIndicator({
onClick={onClick}
type={onClick ? "button" : undefined}
>
{BAR_HEIGHTS.map((height, i) => (
{barHeights.map((height, i) => (
<div
key={height}
className={cn(
"w-1 rounded-sm",
height,
i < config.filledBars ? config.color : "bg-muted",
i < filledBars ? colorMap[i + 1] : "bg-muted",
)}
/>
))}
@@ -0,0 +1,97 @@
import {
PERSISTENT_DAMAGE_DEFINITIONS,
type PersistentDamageEntry,
type PersistentDamageType,
} from "@initiative/domain";
import { Check } from "lucide-react";
import { useEffect, useRef, useState } from "react";
interface PersistentDamagePickerProps {
activeEntries: readonly PersistentDamageEntry[] | undefined;
onAdd: (damageType: PersistentDamageType, formula: string) => void;
onClose: () => void;
}
export function PersistentDamagePicker({
activeEntries,
onAdd,
onClose,
}: Readonly<PersistentDamagePickerProps>) {
const [selectedType, setSelectedType] = useState<PersistentDamageType>(
PERSISTENT_DAMAGE_DEFINITIONS[0].type,
);
const activeFormula =
activeEntries?.find((e) => e.type === selectedType)?.formula ?? "";
const [formula, setFormula] = useState(activeFormula);
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
inputRef.current?.focus();
}, []);
useEffect(() => {
const existing = activeEntries?.find(
(e) => e.type === selectedType,
)?.formula;
setFormula(existing ?? "");
}, [selectedType, activeEntries]);
const canSubmit = formula.trim().length > 0;
function handleSubmit() {
if (canSubmit) {
onAdd(selectedType, formula);
onClose();
}
}
function handleEscape(e: React.KeyboardEvent) {
if (e.key === "Escape") {
e.stopPropagation();
onClose();
}
}
return (
<div className="flex items-center gap-1.5 py-1 pr-2 pl-6">
<select
value={selectedType}
onChange={(e) =>
setSelectedType(e.target.value as PersistentDamageType)
}
onKeyDown={handleEscape}
className="h-7 rounded border border-border bg-background px-1 text-foreground text-xs"
>
{PERSISTENT_DAMAGE_DEFINITIONS.map((def) => (
<option key={def.type} value={def.type}>
{def.label}
</option>
))}
</select>
<input
ref={inputRef}
type="text"
value={formula}
placeholder="2d6"
className="h-7 w-16 rounded border border-border bg-background px-1.5 text-foreground text-xs"
onChange={(e) => setFormula(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
handleSubmit();
}
handleEscape(e);
}}
/>
<button
type="button"
disabled={!canSubmit}
onClick={handleSubmit}
className="rounded p-0.5 text-foreground hover:bg-accent/40 disabled:cursor-not-allowed disabled:opacity-50"
aria-label="Add persistent damage"
>
<Check className="h-3.5 w-3.5" />
</button>
</div>
);
}
@@ -0,0 +1,63 @@
import {
PERSISTENT_DAMAGE_DEFINITIONS,
type PersistentDamageEntry,
type PersistentDamageType,
} from "@initiative/domain";
import { cn } from "../lib/utils.js";
import {
CONDITION_COLOR_CLASSES,
CONDITION_ICON_MAP,
} from "./condition-styles.js";
import { Tooltip } from "./ui/tooltip.js";
interface PersistentDamageTagsProps {
entries: readonly PersistentDamageEntry[] | undefined;
onRemove: (damageType: PersistentDamageType) => void;
}
export function PersistentDamageTags({
entries,
onRemove,
}: Readonly<PersistentDamageTagsProps>) {
if (!entries || entries.length === 0) return null;
return (
<>
{entries.map((entry) => {
const def = PERSISTENT_DAMAGE_DEFINITIONS.find(
(d) => d.type === entry.type,
);
if (!def) return null;
const Icon = CONDITION_ICON_MAP[def.iconName];
if (!Icon) return null;
const colorClass =
CONDITION_COLOR_CLASSES[def.color] ?? "text-muted-foreground";
return (
<Tooltip
key={entry.type}
content={`Persistent ${def.label} ${entry.formula}\nTake damage at end of turn. DC 15 flat check to end.`}
>
<button
type="button"
aria-label={`Remove persistent ${def.label} damage`}
className={cn(
"inline-flex items-center gap-0.5 rounded p-0.5 transition-colors hover:bg-hover-neutral-bg",
colorClass,
)}
onClick={(e) => {
e.stopPropagation();
onRemove(entry.type);
}}
>
<Icon size={14} />
<span className="font-medium text-xs leading-none">
{entry.formula}
</span>
</button>
</Tooltip>
);
})}
</>
);
}
+64 -6
View File
@@ -1,10 +1,13 @@
import type {
CombatantId,
EquipmentItem,
Pf2eCreature,
SpellReference,
} from "@initiative/domain";
import { formatInitiativeModifier, recallKnowledge } from "@initiative/domain";
import { ChevronDown, ChevronUp } from "lucide-react";
import { useCallback, useRef, useState } from "react";
import { cn } from "../lib/utils.js";
import { EquipmentDetailPopover } from "./equipment-detail-popover.js";
import { SpellDetailPopover } from "./spell-detail-popover.js";
import {
@@ -15,6 +18,14 @@ import {
interface Pf2eStatBlockProps {
creature: Pf2eCreature;
adjustment?: "weak" | "elite";
combatantId?: CombatantId;
baseCreature?: Pf2eCreature;
onSetAdjustment?: (
id: CombatantId,
adj: "weak" | "elite" | undefined,
base: Pf2eCreature,
) => void;
}
const ALIGNMENTS = new Set([
@@ -41,6 +52,13 @@ function formatMod(mod: number): string {
return mod >= 0 ? `+${mod}` : `${mod}`;
}
/** Returns the text color class for stats affected by weak/elite adjustment. */
function adjustmentColor(adjustment: "weak" | "elite" | undefined): string {
if (adjustment === "elite") return "text-blue-400";
if (adjustment === "weak") return "text-red-400";
return "";
}
interface SpellLinkProps {
readonly spell: SpellReference;
readonly onOpen: (spell: SpellReference, rect: DOMRect) => void;
@@ -136,7 +154,13 @@ function EquipmentLink({ item, onOpen }: Readonly<EquipmentLinkProps>) {
);
}
export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
export function Pf2eStatBlock({
creature,
adjustment,
combatantId,
baseCreature,
onSetAdjustment,
}: Readonly<Pf2eStatBlockProps>) {
const [openSpell, setOpenSpell] = useState<{
spell: SpellReference;
rect: DOMRect;
@@ -157,6 +181,7 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
const handleCloseEquipment = useCallback(() => setOpenEquipment(null), []);
const rk = recallKnowledge(creature.level, creature.traits);
const adjColor = adjustmentColor(adjustment);
const abilityEntries = [
{ label: "Str", mod: creature.abilityMods.str },
@@ -172,13 +197,46 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
{/* Header */}
<div>
<div className="flex items-baseline justify-between gap-2">
<h2 className="font-bold text-stat-heading text-xl">
<h2 className="flex items-center gap-1.5 font-bold text-stat-heading text-xl">
{adjustment === "elite" && (
<ChevronUp className="h-5 w-5 shrink-0 text-blue-400" />
)}
{adjustment === "weak" && (
<ChevronDown className="h-5 w-5 shrink-0 text-red-400" />
)}
{creature.name}
</h2>
<span className="shrink-0 font-semibold text-sm">
<span className={cn("shrink-0 font-semibold text-sm", adjColor)}>
Level {creature.level}
</span>
</div>
{combatantId != null &&
onSetAdjustment != null &&
baseCreature != null && (
<div className="mt-1 flex gap-1">
{(["weak", "normal", "elite"] as const).map((opt) => {
const value = opt === "normal" ? undefined : opt;
const isActive = adjustment === value;
return (
<button
key={opt}
type="button"
className={cn(
"rounded px-2 py-0.5 font-medium text-xs capitalize",
isActive
? "bg-accent text-primary-foreground"
: "bg-card text-muted-foreground hover:bg-accent/30",
)}
onClick={() =>
onSetAdjustment(combatantId, value, baseCreature)
}
>
{opt}
</button>
);
})}
</div>
)}
<div className="mt-1 flex flex-wrap gap-1">
{displayTraits(creature.traits).map((trait) => (
<span
@@ -204,7 +262,7 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
{/* Perception, Languages, Skills */}
<div className="space-y-0.5 text-sm">
<div>
<div className={adjColor}>
<span className="font-semibold">Perception</span>{" "}
{formatInitiativeModifier(creature.perception)}
{creature.senses || creature.perceptionDetails
@@ -236,7 +294,7 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
{/* Defenses */}
<div className="space-y-0.5 text-sm">
<div>
<div className={adjColor}>
<span className="font-semibold">AC</span> {creature.ac}
{creature.acConditional ? ` (${creature.acConditional})` : ""};{" "}
<span className="font-semibold">Fort</span>{" "}
@@ -247,7 +305,7 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
{formatMod(creature.saveWill)}
{creature.saveConditional ? `; ${creature.saveConditional}` : ""}
</div>
<div>
<div className={adjColor}>
<span className="font-semibold">HP</span> {creature.hp}
{creature.hpDetails ? ` (${creature.hpDetails})` : ""}
</div>
+49 -5
View File
@@ -1,8 +1,17 @@
import type { Creature, CreatureId } from "@initiative/domain";
import type {
AnyCreature,
Combatant,
CombatantId,
Creature,
CreatureId,
Pf2eCreature,
} from "@initiative/domain";
import { applyPf2eAdjustment } from "@initiative/domain";
import { PanelRightClose, Pin, PinOff } from "lucide-react";
import type { ReactNode } from "react";
import { useEffect, useState } from "react";
import { useBestiaryContext } from "../contexts/bestiary-context.js";
import { useEncounterContext } from "../contexts/encounter-context.js";
import { useSidePanelContext } from "../contexts/side-panel-context.js";
import { useSwipeToDismiss } from "../hooks/use-swipe-to-dismiss.js";
import { cn } from "../lib/utils.js";
@@ -216,6 +225,7 @@ function MobileDrawer({
function usePanelRole(panelRole: "browse" | "pinned") {
const sidePanel = useSidePanelContext();
const { getCreature } = useBestiaryContext();
const { encounter, setCreatureAdjustment } = useEncounterContext();
const creatureId =
panelRole === "browse"
@@ -223,10 +233,18 @@ function usePanelRole(panelRole: "browse" | "pinned") {
: sidePanel.pinnedCreatureId;
const creature = creatureId ? (getCreature(creatureId) ?? null) : null;
const combatantId =
panelRole === "browse" ? sidePanel.selectedCombatantId : null;
const combatant = combatantId
? (encounter.combatants.find((c) => c.id === combatantId) ?? null)
: null;
const isBrowse = panelRole === "browse";
return {
creatureId,
creature,
combatant,
setCreatureAdjustment,
isCollapsed: isBrowse ? sidePanel.isRightPanelCollapsed : false,
onToggleCollapse: isBrowse ? sidePanel.toggleCollapse : () => {},
onDismiss: isBrowse ? sidePanel.dismissPanel : () => {},
@@ -238,6 +256,33 @@ function usePanelRole(panelRole: "browse" | "pinned") {
};
}
function renderStatBlock(
creature: AnyCreature,
combatant: Combatant | null,
setCreatureAdjustment: (
id: CombatantId,
adj: "weak" | "elite" | undefined,
base: Pf2eCreature,
) => void,
) {
if ("system" in creature && creature.system === "pf2e") {
const baseCreature = creature;
const adjusted = combatant?.creatureAdjustment
? applyPf2eAdjustment(baseCreature, combatant.creatureAdjustment)
: baseCreature;
return (
<Pf2eStatBlock
creature={adjusted}
adjustment={combatant?.creatureAdjustment}
combatantId={combatant?.id}
baseCreature={baseCreature}
onSetAdjustment={setCreatureAdjustment}
/>
);
}
return <DndStatBlock creature={creature as Creature} />;
}
export function StatBlockPanel({
panelRole,
side,
@@ -245,6 +290,8 @@ export function StatBlockPanel({
const {
creatureId,
creature,
combatant,
setCreatureAdjustment,
isCollapsed,
onToggleCollapse,
onDismiss,
@@ -316,10 +363,7 @@ export function StatBlockPanel({
}
if (creature) {
if ("system" in creature && creature.system === "pf2e") {
return <Pf2eStatBlock creature={creature} />;
}
return <DndStatBlock creature={creature as Creature} />;
return renderStatBlock(creature, combatant, setCreatureAdjustment);
}
if (needsFetch && sourceCode) {
+9 -1
View File
@@ -8,6 +8,7 @@ import {
DifficultyIndicator,
TIER_LABELS_5_5E,
TIER_LABELS_2014,
TIER_LABELS_PF2E,
} from "./difficulty-indicator.js";
import { Button } from "./ui/button.js";
import { ConfirmButton } from "./ui/confirm-button.js";
@@ -26,7 +27,13 @@ export function TurnNavigation() {
const difficulty = useDifficulty();
const { edition } = useRulesEditionContext();
const tierLabels = edition === "5e" ? TIER_LABELS_2014 : TIER_LABELS_5_5E;
const TIER_LABELS_BY_EDITION = {
pf2e: TIER_LABELS_PF2E,
"5e": TIER_LABELS_2014,
"5.5e": TIER_LABELS_5_5E,
} as const;
const tierLabels = TIER_LABELS_BY_EDITION[edition];
const barCount = edition === "pf2e" ? 4 : 3;
const [showBreakdown, setShowBreakdown] = useState(false);
const hasCombatants = encounter.combatants.length > 0;
const isAtStart = encounter.roundNumber === 1 && encounter.activeIndex === 0;
@@ -87,6 +94,7 @@ export function TurnNavigation() {
<DifficultyIndicator
result={difficulty}
labels={tierLabels}
barCount={barCount}
onClick={() => setShowBreakdown((prev) => !prev)}
/>
{showBreakdown ? (
+1 -1
View File
@@ -46,7 +46,7 @@ export function Dialog({ open, onClose, className, children }: DialogProps) {
className,
)}
>
<div className="p-6">{children}</div>
{open ? <div className="p-6">{children}</div> : null}
</dialog>
);
}
@@ -1,5 +1,9 @@
// @vitest-environment jsdom
import type { Creature, CreatureId, PlayerCharacter } from "@initiative/domain";
import type {
AnyCreature,
CreatureId,
PlayerCharacter,
} from "@initiative/domain";
import { combatantId, creatureId, playerCharacterId } from "@initiative/domain";
import { renderHook, waitFor } from "@testing-library/react";
import type { ReactNode } from "react";
@@ -9,6 +13,7 @@ import {
buildCombatant,
buildCreature,
buildEncounter,
buildPf2eCreature,
} from "../../__tests__/factories/index.js";
import { AllProviders } from "../../__tests__/test-providers.js";
import { useDifficultyBreakdown } from "../use-difficulty-breakdown.js";
@@ -42,7 +47,7 @@ const goblinCreature = buildCreature({
function makeWrapper(options: {
encounter: ReturnType<typeof buildEncounter>;
playerCharacters?: PlayerCharacter[];
creatures?: Map<CreatureId, Creature>;
creatures?: Map<CreatureId, AnyCreature>;
}) {
const adapters = createTestAdapters({
encounter: options.encounter,
@@ -345,4 +350,115 @@ describe("useDifficultyBreakdown", () => {
editionResult.current.setEdition("5.5e");
}
});
describe("PF2e edition", () => {
const orcWarrior = buildPf2eCreature({
id: creatureId("pf2e:orc-warrior"),
name: "Orc Warrior",
level: 3,
source: "crb",
sourceDisplayName: "Core Rulebook",
});
it("returns breakdown with creatureLevel, levelDifference, and XP for PF2e creatures", async () => {
const wrapper = makeWrapper({
encounter: buildEncounter({
combatants: [
buildCombatant({
id: combatantId("c-1"),
name: "Hero",
playerCharacterId: pcId1,
}),
buildCombatant({
id: combatantId("c-2"),
name: "Orc Warrior",
creatureId: orcWarrior.id,
}),
],
}),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[orcWarrior.id, orcWarrior]]),
});
const { result: editionResult } = renderHook(() => useRulesEdition(), {
wrapper,
});
editionResult.current.setEdition("pf2e");
try {
const { result } = renderHook(() => useDifficultyBreakdown(), {
wrapper,
});
await waitFor(() => {
const breakdown = result.current;
expect(breakdown).not.toBeNull();
// Party level should be 5
expect(breakdown?.partyLevel).toBe(5);
// Orc Warrior: level 3, party level 5 → diff 2 → 20 XP
const orc = breakdown?.enemyCombatants[0];
expect(orc?.creatureLevel).toBe(3);
expect(orc?.levelDifference).toBe(-2);
expect(orc?.xp).toBe(20);
expect(orc?.cr).toBeNull();
expect(orc?.source).toBe("Core Rulebook");
// PC should have no creature level
const pc = breakdown?.partyCombatants[0];
expect(pc?.creatureLevel).toBeUndefined();
expect(pc?.levelDifference).toBeUndefined();
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
it("returns partyLevel in result", async () => {
const wrapper = makeWrapper({
encounter: buildEncounter({
combatants: [
buildCombatant({
id: combatantId("c-1"),
name: "Hero",
playerCharacterId: pcId1,
}),
buildCombatant({
id: combatantId("c-2"),
name: "Orc Warrior",
creatureId: orcWarrior.id,
}),
],
}),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[orcWarrior.id, orcWarrior]]),
});
const { result: editionResult } = renderHook(() => useRulesEdition(), {
wrapper,
});
editionResult.current.setEdition("pf2e");
try {
const { result } = renderHook(() => useDifficultyBreakdown(), {
wrapper,
});
await waitFor(() => {
expect(result.current).not.toBeNull();
expect(result.current?.partyLevel).toBe(5);
// 5 thresholds for PF2e
expect(result.current?.thresholds).toHaveLength(5);
expect(result.current?.thresholds[0].label).toBe("Trivial");
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
});
});
@@ -1,5 +1,9 @@
// @vitest-environment jsdom
import type { Creature, CreatureId, PlayerCharacter } from "@initiative/domain";
import type {
AnyCreature,
CreatureId,
PlayerCharacter,
} from "@initiative/domain";
import { combatantId, creatureId, playerCharacterId } from "@initiative/domain";
import { renderHook, waitFor } from "@testing-library/react";
import type { ReactNode } from "react";
@@ -9,6 +13,7 @@ import {
buildCombatant,
buildCreature,
buildEncounter,
buildPf2eCreature,
} from "../../__tests__/factories/index.js";
import { AllProviders } from "../../__tests__/test-providers.js";
import { useDifficulty } from "../use-difficulty.js";
@@ -43,7 +48,7 @@ const goblinCreature = buildCreature({
function makeWrapper(options: {
encounter: ReturnType<typeof buildEncounter>;
playerCharacters?: PlayerCharacter[];
creatures?: Map<CreatureId, Creature>;
creatures?: Map<CreatureId, AnyCreature>;
}) {
const adapters = createTestAdapters({
encounter: options.encounter,
@@ -424,4 +429,134 @@ describe("useDifficulty", () => {
expect(result.current?.totalMonsterXp).toBe(0);
});
});
describe("PF2e edition", () => {
const pf2eCreature = buildPf2eCreature({
id: creatureId("pf2e:orc-warrior"),
name: "Orc Warrior",
level: 5,
});
function makePf2eWrapper(options: {
encounter: ReturnType<typeof buildEncounter>;
playerCharacters?: PlayerCharacter[];
creatures?: Map<CreatureId, AnyCreature>;
}) {
const adapters = createTestAdapters({
encounter: options.encounter,
playerCharacters: options.playerCharacters ?? [],
creatures: options.creatures,
});
return ({ children }: { children: ReactNode }) => (
<AllProviders adapters={adapters}>{children}</AllProviders>
);
}
it("returns result for PF2e with leveled PCs and PF2e creatures", async () => {
const wrapper = makePf2eWrapper({
encounter: buildEncounter({
combatants: [
buildCombatant({
id: combatantId("c1"),
name: "Hero",
playerCharacterId: pcId1,
}),
buildCombatant({
id: combatantId("c2"),
name: "Orc Warrior",
creatureId: pf2eCreature.id,
}),
],
}),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
creatures: new Map([[pf2eCreature.id, pf2eCreature]]),
});
const { result: editionResult } = renderHook(() => useRulesEdition(), {
wrapper,
});
editionResult.current.setEdition("pf2e");
try {
const { result } = renderHook(() => useDifficulty(), { wrapper });
await waitFor(() => {
expect(result.current).not.toBeNull();
// Creature level 5, party level 5 → diff 0 → 40 XP
expect(result.current?.totalMonsterXp).toBe(40);
expect(result.current?.partyLevel).toBe(5);
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
it("returns null for PF2e when no PF2e creatures with level", () => {
const wrapper = makePf2eWrapper({
encounter: buildEncounter({
combatants: [
buildCombatant({
id: combatantId("c1"),
name: "Hero",
playerCharacterId: pcId1,
}),
buildCombatant({
id: combatantId("c2"),
name: "Custom Monster",
}),
],
}),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 5 },
],
});
const { result: editionResult } = renderHook(() => useRulesEdition(), {
wrapper,
});
editionResult.current.setEdition("pf2e");
try {
const { result } = renderHook(() => useDifficulty(), { wrapper });
expect(result.current).toBeNull();
} finally {
editionResult.current.setEdition("5.5e");
}
});
it("returns null for PF2e when no PCs with level", () => {
const wrapper = makePf2eWrapper({
encounter: buildEncounter({
combatants: [
buildCombatant({
id: combatantId("c1"),
name: "Hero",
playerCharacterId: pcId1,
}),
buildCombatant({
id: combatantId("c2"),
name: "Orc Warrior",
creatureId: pf2eCreature.id,
}),
],
}),
playerCharacters: [{ id: pcId1, name: "Hero", ac: 15, maxHp: 30 }],
creatures: new Map([[pf2eCreature.id, pf2eCreature]]),
});
const { result: editionResult } = renderHook(() => useRulesEdition(), {
wrapper,
});
editionResult.current.setEdition("pf2e");
try {
const { result } = renderHook(() => useDifficulty(), { wrapper });
expect(result.current).toBeNull();
} finally {
editionResult.current.setEdition("5.5e");
}
});
});
});
@@ -0,0 +1,238 @@
import type { Pf2eCreature } from "@initiative/domain";
import {
combatantId,
creatureId,
EMPTY_UNDO_REDO_STATE,
} from "@initiative/domain";
import { describe, expect, it } from "vitest";
import { type EncounterState, encounterReducer } from "../use-encounter.js";
const BASE_CREATURE: Pf2eCreature = {
system: "pf2e",
id: creatureId("b1:goblin-warrior"),
name: "Goblin Warrior",
source: "B1",
sourceDisplayName: "Bestiary",
level: 5,
traits: ["humanoid"],
perception: 12,
abilityMods: { str: 4, dex: 2, con: 3, int: 0, wis: 1, cha: -1 },
ac: 22,
saveFort: 14,
saveRef: 11,
saveWill: 9,
hp: 75,
speed: "25 feet",
};
function stateWithCreature(
name: string,
hp: number,
ac: number,
adj?: "weak" | "elite",
): EncounterState {
return {
encounter: {
combatants: [
{
id: combatantId("c-1"),
name,
maxHp: hp,
currentHp: hp,
ac,
creatureId: creatureId("b1:goblin-warrior"),
...(adj !== undefined && { creatureAdjustment: adj }),
},
],
activeIndex: 0,
roundNumber: 1,
},
undoRedoState: EMPTY_UNDO_REDO_STATE,
events: [],
nextId: 1,
lastCreatureId: null,
};
}
describe("set-creature-adjustment", () => {
it("Normal → Elite: HP increases, AC +2, name prefixed, adjustment stored", () => {
const state = stateWithCreature("Goblin Warrior", 75, 22);
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "elite",
baseCreature: BASE_CREATURE,
});
const c = next.encounter.combatants[0];
expect(c.maxHp).toBe(95); // 75 + 20 (level 5 bracket)
expect(c.currentHp).toBe(95);
expect(c.ac).toBe(24);
expect(c.name).toBe("Elite Goblin Warrior");
expect(c.creatureAdjustment).toBe("elite");
});
it("Normal → Weak: HP decreases, AC 2, name prefixed", () => {
const state = stateWithCreature("Goblin Warrior", 75, 22);
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "weak",
baseCreature: BASE_CREATURE,
});
const c = next.encounter.combatants[0];
expect(c.maxHp).toBe(55); // 75 - 20
expect(c.currentHp).toBe(55);
expect(c.ac).toBe(20);
expect(c.name).toBe("Weak Goblin Warrior");
expect(c.creatureAdjustment).toBe("weak");
});
it("Elite → Normal: HP/AC/name revert", () => {
const state = stateWithCreature("Elite Goblin Warrior", 95, 24, "elite");
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: undefined,
baseCreature: BASE_CREATURE,
});
const c = next.encounter.combatants[0];
expect(c.maxHp).toBe(75);
expect(c.currentHp).toBe(75);
expect(c.ac).toBe(22);
expect(c.name).toBe("Goblin Warrior");
expect(c.creatureAdjustment).toBeUndefined();
});
it("Elite → Weak: full swing applied in one step", () => {
const state = stateWithCreature("Elite Goblin Warrior", 95, 24, "elite");
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "weak",
baseCreature: BASE_CREATURE,
});
const c = next.encounter.combatants[0];
expect(c.maxHp).toBe(55); // 95 - 40 (revert +20, apply -20)
expect(c.currentHp).toBe(55);
expect(c.ac).toBe(20); // 24 - 4
expect(c.name).toBe("Weak Goblin Warrior");
expect(c.creatureAdjustment).toBe("weak");
});
it("toggle with damage taken: currentHp shifted by delta, clamped to 0", () => {
const state: EncounterState = {
...stateWithCreature("Goblin Warrior", 75, 22),
};
// Simulate damage: currentHp = 10
const damaged: EncounterState = {
...state,
encounter: {
...state.encounter,
combatants: [{ ...state.encounter.combatants[0], currentHp: 10 }],
},
};
const next = encounterReducer(damaged, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "weak",
baseCreature: BASE_CREATURE,
});
const c = next.encounter.combatants[0];
expect(c.maxHp).toBe(55);
// currentHp = 10 - 20 = -10, clamped to 0
expect(c.currentHp).toBe(0);
});
it("toggle with temp HP: temp HP unchanged", () => {
const state = stateWithCreature("Goblin Warrior", 75, 22);
const withTemp: EncounterState = {
...state,
encounter: {
...state.encounter,
combatants: [{ ...state.encounter.combatants[0], tempHp: 10 }],
},
};
const next = encounterReducer(withTemp, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "elite",
baseCreature: BASE_CREATURE,
});
expect(next.encounter.combatants[0].tempHp).toBe(10);
});
it("name with auto-number suffix: 'Goblin 2' → 'Elite Goblin 2'", () => {
const state = stateWithCreature("Goblin 2", 75, 22);
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "elite",
baseCreature: BASE_CREATURE,
});
expect(next.encounter.combatants[0].name).toBe("Elite Goblin 2");
});
it("manually renamed combatant: prefix not found, name unchanged", () => {
// Combatant was elite but manually renamed to "Big Boss"
const state = stateWithCreature("Big Boss", 95, 24, "elite");
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: undefined,
baseCreature: BASE_CREATURE,
});
// No "Elite " prefix found, so name stays as is
expect(next.encounter.combatants[0].name).toBe("Big Boss");
});
it("emits CreatureAdjustmentSet event", () => {
const state = stateWithCreature("Goblin Warrior", 75, 22);
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "elite",
baseCreature: BASE_CREATURE,
});
const event = next.events.find((e) => e.type === "CreatureAdjustmentSet");
expect(event).toEqual({
type: "CreatureAdjustmentSet",
combatantId: "c-1",
adjustment: "elite",
});
});
it("returns unchanged state when adjustment is the same", () => {
const state = stateWithCreature("Elite Goblin Warrior", 95, 24, "elite");
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-1"),
adjustment: "elite",
baseCreature: BASE_CREATURE,
});
expect(next).toBe(state);
});
it("returns unchanged state for unknown combatant", () => {
const state = stateWithCreature("Goblin Warrior", 75, 22);
const next = encounterReducer(state, {
type: "set-creature-adjustment",
id: combatantId("c-99"),
adjustment: "elite",
baseCreature: BASE_CREATURE,
});
expect(next).toBe(state);
});
});
@@ -112,6 +112,49 @@ describe("usePlayerCharacters", () => {
expect(result.current.characters[0].name).toBe("Vex'ahlia");
});
it("createCharacter assigns a fresh id after rehydration from persistence", () => {
const stored = [
{
id: playerCharacterId("pc-1"),
name: "Mikka",
ac: 12,
maxHp: 58,
color: undefined,
icon: undefined,
},
{
id: playerCharacterId("pc-3"),
name: "Bob",
ac: 14,
maxHp: 40,
color: undefined,
icon: undefined,
},
];
const adapters = createTestAdapters({ playerCharacters: stored });
const { result } = renderHook(() => usePlayerCharacters(), {
wrapper: ({ children }: { children: ReactNode }) => (
<AllProviders adapters={adapters}>{children}</AllProviders>
),
});
act(() => {
result.current.createCharacter(
"Charlie",
13,
25,
undefined,
undefined,
undefined,
);
});
const ids = result.current.characters.map((pc) => pc.id);
expect(new Set(ids).size).toBe(ids.length);
expect(ids).toContain(playerCharacterId("pc-4"));
});
it("deleteCharacter removes character and persists", () => {
const { result } = renderHook(() => usePlayerCharacters(), { wrapper });
+10 -4
View File
@@ -6,8 +6,8 @@ export function useAutoStatBlock(): void {
const { encounter } = useEncounterContext();
const { panelView, updateCreature } = useSidePanelContext();
const activeCreatureId =
encounter.combatants[encounter.activeIndex]?.creatureId;
const activeCombatant = encounter.combatants[encounter.activeIndex];
const activeCreatureId = activeCombatant?.creatureId;
const prevActiveIndexRef = useRef(encounter.activeIndex);
useEffect(() => {
@@ -21,7 +21,13 @@ export function useAutoStatBlock(): void {
activeCreatureId &&
panelView.mode === "creature"
) {
updateCreature(activeCreatureId);
updateCreature(activeCreatureId, activeCombatant.id);
}
}, [encounter.activeIndex, activeCreatureId, panelView.mode, updateCreature]);
}, [
encounter.activeIndex,
activeCreatureId,
activeCombatant?.id,
panelView.mode,
updateCreature,
]);
}
+9 -1
View File
@@ -9,6 +9,7 @@ import {
normalizeBestiary,
setSourceDisplayNames,
} from "../adapters/bestiary-adapter.js";
import { loadBundledDndCreatures } from "../adapters/dnd-bundled-adapter.js";
import { normalizeFoundryCreatures } from "../adapters/pf2e-bestiary-adapter.js";
import { useAdapters } from "../contexts/adapter-context.js";
import { useRulesEditionContext } from "../contexts/rules-edition-context.js";
@@ -160,7 +161,11 @@ export function useBestiary(): BestiaryHook {
}
void bestiaryCache.loadAllCachedCreatures().then((map) => {
setCreatureMap(map);
const merged = new Map(map);
for (const c of loadBundledDndCreatures()) {
merged.set(c.id, c);
}
setCreatureMap(merged);
});
}, [bestiaryCache, bestiaryIndex, pf2eBestiaryIndex]);
@@ -300,6 +305,9 @@ export function useBestiary(): BestiaryHook {
const refreshCache = useCallback(async (): Promise<void> => {
const map = await bestiaryCache.loadAllCachedCreatures();
for (const c of loadBundledDndCreatures()) {
map.set(c.id, c);
}
setCreatureMap(map);
}, [bestiaryCache]);
+113 -14
View File
@@ -1,11 +1,17 @@
import type {
AnyCreature,
Combatant,
CreatureId,
DifficultyThreshold,
DifficultyTier,
PlayerCharacter,
} from "@initiative/domain";
import { calculateEncounterDifficulty, crToXp } from "@initiative/domain";
import {
calculateEncounterDifficulty,
crToXp,
derivePartyLevel,
pf2eCreatureXp,
} from "@initiative/domain";
import { useMemo } from "react";
import { useBestiaryContext } from "../contexts/bestiary-context.js";
import { useEncounterContext } from "../contexts/encounter-context.js";
@@ -21,6 +27,10 @@ export interface BreakdownCombatant {
readonly editable: boolean;
readonly side: "party" | "enemy";
readonly level: number | undefined;
/** PF2e only: the creature's level from bestiary data. */
readonly creatureLevel: number | undefined;
/** PF2e only: creature level minus party level. */
readonly levelDifference: number | undefined;
}
interface DifficultyBreakdown {
@@ -30,6 +40,7 @@ interface DifficultyBreakdown {
readonly encounterMultiplier: number | undefined;
readonly adjustedXp: number | undefined;
readonly partySizeAdjusted: boolean | undefined;
readonly partyLevel: number | undefined;
readonly pcCount: number;
readonly partyCombatants: readonly BreakdownCombatant[];
readonly enemyCombatants: readonly BreakdownCombatant[];
@@ -48,9 +59,16 @@ export function useDifficultyBreakdown(): DifficultyBreakdown | null {
const hasPartyLevel = descriptors.some(
(d) => d.side === "party" && d.level !== undefined,
);
const hasCr = descriptors.some((d) => d.cr !== undefined);
if (!hasPartyLevel || !hasCr) return null;
if (edition === "pf2e") {
const hasCreatureLevel = descriptors.some(
(d) => d.creatureLevel !== undefined,
);
if (!hasPartyLevel || !hasCreatureLevel) return null;
} else {
const hasCr = descriptors.some((d) => d.cr !== undefined);
if (!hasPartyLevel || !hasCr) return null;
}
const result = calculateEncounterDifficulty(descriptors, edition);
@@ -65,6 +83,7 @@ export function useDifficultyBreakdown(): DifficultyBreakdown | null {
type CreatureInfo = {
cr?: string;
creatureLevel?: number;
source: string;
sourceDisplayName: string;
};
@@ -74,6 +93,7 @@ function buildBreakdownEntry(
side: "party" | "enemy",
level: number | undefined,
creature: CreatureInfo | undefined,
partyLevel: number | undefined,
): BreakdownCombatant {
if (c.playerCharacterId) {
return {
@@ -84,6 +104,29 @@ function buildBreakdownEntry(
editable: false,
side,
level,
creatureLevel: undefined,
levelDifference: undefined,
};
}
if (creature && creature.creatureLevel !== undefined) {
const levelDiff =
partyLevel === undefined
? undefined
: creature.creatureLevel - partyLevel;
const xp =
partyLevel === undefined
? null
: pf2eCreatureXp(creature.creatureLevel, partyLevel);
return {
combatant: c,
cr: null,
xp,
source: creature.sourceDisplayName ?? creature.source,
editable: false,
side,
level: undefined,
creatureLevel: creature.creatureLevel,
levelDifference: levelDiff,
};
}
if (creature) {
@@ -96,6 +139,8 @@ function buildBreakdownEntry(
editable: false,
side,
level: undefined,
creatureLevel: undefined,
levelDifference: undefined,
};
}
if (c.cr) {
@@ -107,6 +152,8 @@ function buildBreakdownEntry(
editable: true,
side,
level: undefined,
creatureLevel: undefined,
levelDifference: undefined,
};
}
return {
@@ -117,6 +164,8 @@ function buildBreakdownEntry(
editable: !c.creatureId,
side,
level: undefined,
creatureLevel: undefined,
levelDifference: undefined,
};
}
@@ -128,41 +177,91 @@ function resolveLevel(
return characters.find((p) => p.id === c.playerCharacterId)?.level;
}
function resolveCr(
function resolveCreatureInfo(
c: Combatant,
getCreature: (id: CreatureId) => CreatureInfo | undefined,
): { cr: string | null; creature: CreatureInfo | undefined } {
const creature = c.creatureId ? getCreature(c.creatureId) : undefined;
const cr = creature?.cr ?? c.cr ?? null;
return { cr, creature };
getCreature: (id: CreatureId) => AnyCreature | undefined,
): {
cr: string | null;
creatureLevel: number | undefined;
creature: CreatureInfo | undefined;
} {
const rawCreature = c.creatureId ? getCreature(c.creatureId) : undefined;
if (!rawCreature) {
return {
cr: c.cr ?? null,
creatureLevel: undefined,
creature: undefined,
};
}
if ("system" in rawCreature && rawCreature.system === "pf2e") {
return {
cr: null,
creatureLevel: rawCreature.level,
creature: {
creatureLevel: rawCreature.level,
source: rawCreature.source,
sourceDisplayName: rawCreature.sourceDisplayName,
},
};
}
const cr = "cr" in rawCreature ? rawCreature.cr : undefined;
return {
cr: cr ?? c.cr ?? null,
creatureLevel: undefined,
creature: {
cr,
source: rawCreature.source,
sourceDisplayName: rawCreature.sourceDisplayName,
},
};
}
function collectPartyLevel(
combatants: readonly Combatant[],
characters: readonly PlayerCharacter[],
): number | undefined {
const partyLevels: number[] = [];
for (const c of combatants) {
if (resolveSide(c) !== "party") continue;
const level = resolveLevel(c, characters);
if (level !== undefined) partyLevels.push(level);
}
return partyLevels.length > 0 ? derivePartyLevel(partyLevels) : undefined;
}
function classifyCombatants(
combatants: readonly Combatant[],
characters: readonly PlayerCharacter[],
getCreature: (id: CreatureId) => CreatureInfo | undefined,
getCreature: (id: CreatureId) => AnyCreature | undefined,
) {
const partyCombatants: BreakdownCombatant[] = [];
const enemyCombatants: BreakdownCombatant[] = [];
const descriptors: {
level?: number;
cr?: string;
creatureLevel?: number;
side: "party" | "enemy";
}[] = [];
let pcCount = 0;
const partyLevel = collectPartyLevel(combatants, characters);
for (const c of combatants) {
const side = resolveSide(c);
const level = resolveLevel(c, characters);
if (level !== undefined) pcCount++;
const { cr, creature } = resolveCr(c, getCreature);
const { cr, creatureLevel, creature } = resolveCreatureInfo(c, getCreature);
if (level !== undefined || cr != null) {
descriptors.push({ level, cr: cr ?? undefined, side });
if (level !== undefined || cr != null || creatureLevel !== undefined) {
descriptors.push({
level,
cr: cr ?? undefined,
creatureLevel,
side,
});
}
const entry = buildBreakdownEntry(c, side, level, creature);
const entry = buildBreakdownEntry(c, side, level, creature, partyLevel);
const target = side === "party" ? partyCombatants : enemyCombatants;
target.push(entry);
}
+19 -6
View File
@@ -33,9 +33,17 @@ function buildDescriptors(
const creatureCr =
creature && !("system" in creature) ? creature.cr : undefined;
const cr = creatureCr ?? c.cr ?? undefined;
const creatureLevel =
creature && "system" in creature && creature.system === "pf2e"
? creature.level
: undefined;
if (level !== undefined || cr !== undefined) {
descriptors.push({ level, cr, side });
if (
level !== undefined ||
cr !== undefined ||
creatureLevel !== undefined
) {
descriptors.push({ level, cr, creatureLevel, side });
}
}
return descriptors;
@@ -48,8 +56,6 @@ export function useDifficulty(): DifficultyResult | null {
const { edition } = useRulesEditionContext();
return useMemo(() => {
if (edition === "pf2e") return null;
const descriptors = buildDescriptors(
encounter.combatants,
characters,
@@ -59,9 +65,16 @@ export function useDifficulty(): DifficultyResult | null {
const hasPartyLevel = descriptors.some(
(d) => d.side === "party" && d.level !== undefined,
);
const hasCr = descriptors.some((d) => d.cr !== undefined);
if (!hasPartyLevel || !hasCr) return null;
if (edition === "pf2e") {
const hasCreatureLevel = descriptors.some(
(d) => d.creatureLevel !== undefined,
);
if (!hasPartyLevel || !hasCreatureLevel) return null;
} else {
const hasCr = descriptors.some((d) => d.cr !== undefined);
if (!hasPartyLevel || !hasCr) return null;
}
return calculateEncounterDifficulty(descriptors, edition);
}, [encounter.combatants, characters, getCreature, edition]);
+141
View File
@@ -1,6 +1,7 @@
import type { EncounterStore, UndoRedoStore } from "@initiative/application";
import {
addCombatantUseCase,
addPersistentDamageUseCase,
adjustHpUseCase,
advanceTurnUseCase,
clearEncounterUseCase,
@@ -8,6 +9,7 @@ import {
editCombatantUseCase,
redoUseCase,
removeCombatantUseCase,
removePersistentDamageUseCase,
retreatTurnUseCase,
setAcUseCase,
setConditionValueUseCase,
@@ -28,12 +30,16 @@ import type {
DomainError,
DomainEvent,
Encounter,
PersistentDamageType,
Pf2eCreature,
PlayerCharacter,
UndoRedoState,
} from "@initiative/domain";
import {
acDelta,
clearHistory,
combatantId,
hpDelta,
isDomainError,
creatureId as makeCreatureId,
pushUndo,
@@ -75,6 +81,17 @@ type EncounterAction =
conditionId: ConditionId;
}
| { type: "toggle-concentration"; id: CombatantId }
| {
type: "add-persistent-damage";
id: CombatantId;
damageType: PersistentDamageType;
formula: string;
}
| {
type: "remove-persistent-damage";
id: CombatantId;
damageType: PersistentDamageType;
}
| { type: "clear-encounter" }
| { type: "undo" }
| { type: "redo" }
@@ -84,6 +101,12 @@ type EncounterAction =
entry: SearchResult;
count: number;
}
| {
type: "set-creature-adjustment";
id: CombatantId;
adjustment: "weak" | "elite" | undefined;
baseCreature: Pf2eCreature;
}
| { type: "add-from-player-character"; pc: PlayerCharacter }
| {
type: "import";
@@ -279,6 +302,76 @@ function handleAddFromPlayerCharacter(
};
}
function applyNamePrefix(
name: string,
oldAdj: "weak" | "elite" | undefined,
newAdj: "weak" | "elite" | undefined,
): string {
let base = name;
if (oldAdj === "weak" && name.startsWith("Weak ")) base = name.slice(5);
else if (oldAdj === "elite" && name.startsWith("Elite "))
base = name.slice(6);
if (newAdj === "weak") return `Weak ${base}`;
if (newAdj === "elite") return `Elite ${base}`;
return base;
}
function handleSetCreatureAdjustment(
state: EncounterState,
id: CombatantId,
adjustment: "weak" | "elite" | undefined,
baseCreature: Pf2eCreature,
): EncounterState {
const combatant = state.encounter.combatants.find((c) => c.id === id);
if (!combatant) return state;
const oldAdj = combatant.creatureAdjustment;
if (oldAdj === adjustment) return state;
const baseLevel = baseCreature.level;
const oldHpDelta = oldAdj ? hpDelta(baseLevel, oldAdj) : 0;
const newHpDelta = adjustment ? hpDelta(baseLevel, adjustment) : 0;
const netHpDelta = newHpDelta - oldHpDelta;
const oldAcDelta = oldAdj ? acDelta(oldAdj) : 0;
const newAcDelta = adjustment ? acDelta(adjustment) : 0;
const netAcDelta = newAcDelta - oldAcDelta;
const newMaxHp =
combatant.maxHp === undefined ? undefined : combatant.maxHp + netHpDelta;
const newCurrentHp =
combatant.currentHp === undefined || newMaxHp === undefined
? undefined
: Math.max(0, Math.min(combatant.currentHp + netHpDelta, newMaxHp));
const newAc =
combatant.ac === undefined ? undefined : combatant.ac + netAcDelta;
const newName = applyNamePrefix(combatant.name, oldAdj, adjustment);
const updatedCombatant: typeof combatant = {
...combatant,
name: newName,
...(newMaxHp !== undefined && { maxHp: newMaxHp }),
...(newCurrentHp !== undefined && { currentHp: newCurrentHp }),
...(newAc !== undefined && { ac: newAc }),
...(adjustment === undefined
? { creatureAdjustment: undefined }
: { creatureAdjustment: adjustment }),
};
const combatants = state.encounter.combatants.map((c) =>
c.id === id ? updatedCombatant : c,
);
return {
...state,
encounter: { ...state.encounter, combatants },
events: [
...state.events,
{ type: "CreatureAdjustmentSet", combatantId: id, adjustment },
],
};
}
// -- Reducer --
export function encounterReducer(
@@ -310,6 +403,13 @@ export function encounterReducer(
lastCreatureId: null,
};
}
case "set-creature-adjustment":
return handleSetCreatureAdjustment(
state,
action.id,
action.adjustment,
action.baseCreature,
);
case "add-from-bestiary":
return handleAddFromBestiary(state, action.entry, 1);
case "add-multiple-from-bestiary":
@@ -341,6 +441,8 @@ function dispatchEncounterAction(
| { type: "set-condition-value" }
| { type: "decrement-condition" }
| { type: "toggle-concentration" }
| { type: "add-persistent-damage" }
| { type: "remove-persistent-damage" }
>,
): EncounterState {
const { store, getEncounter } = makeStoreFromState(state);
@@ -402,6 +504,21 @@ function dispatchEncounterAction(
case "toggle-concentration":
result = toggleConcentrationUseCase(store, action.id);
break;
case "add-persistent-damage":
result = addPersistentDamageUseCase(
store,
action.id,
action.damageType,
action.formula,
);
break;
case "remove-persistent-damage":
result = removePersistentDamageUseCase(
store,
action.id,
action.damageType,
);
break;
}
if (isDomainError(result)) return state;
@@ -565,6 +682,30 @@ export function useEncounter() {
(id: CombatantId) => dispatch({ type: "toggle-concentration", id }),
[],
),
addPersistentDamage: useCallback(
(id: CombatantId, damageType: PersistentDamageType, formula: string) =>
dispatch({ type: "add-persistent-damage", id, damageType, formula }),
[],
),
removePersistentDamage: useCallback(
(id: CombatantId, damageType: PersistentDamageType) =>
dispatch({ type: "remove-persistent-damage", id, damageType }),
[],
),
setCreatureAdjustment: useCallback(
(
id: CombatantId,
adjustment: "weak" | "elite" | undefined,
baseCreature: Pf2eCreature,
) =>
dispatch({
type: "set-creature-adjustment",
id,
adjustment,
baseCreature,
}),
[],
),
clearEncounter: useCallback(
() => dispatch({ type: "clear-encounter" }),
[],
+12 -4
View File
@@ -9,10 +9,18 @@ import { isDomainError, playerCharacterId } from "@initiative/domain";
import { useCallback, useEffect, useRef, useState } from "react";
import { useAdapters } from "../contexts/adapter-context.js";
let nextPcId = 0;
const PC_ID_PATTERN = /^pc-(\d+)$/;
function generatePcId(): PlayerCharacterId {
return playerCharacterId(`pc-${++nextPcId}`);
function generatePcId(existing: readonly PlayerCharacter[]): PlayerCharacterId {
let max = 0;
for (const pc of existing) {
const match = PC_ID_PATTERN.exec(pc.id);
if (match) {
const n = Number(match[1]);
if (n > max) max = n;
}
}
return playerCharacterId(`pc-${max + 1}`);
}
interface EditFields {
@@ -55,7 +63,7 @@ export function usePlayerCharacters() {
icon: string | undefined,
level: number | undefined,
) => {
const id = generatePcId();
const id = generatePcId(charactersRef.current);
const result = createPlayerCharacterUseCase(
makeStore(),
id,
+22 -11
View File
@@ -1,15 +1,16 @@
import type { CreatureId } from "@initiative/domain";
import type { CombatantId, CreatureId } from "@initiative/domain";
import { useCallback, useEffect, useState } from "react";
type PanelView =
| { mode: "closed" }
| { mode: "creature"; creatureId: CreatureId }
| { mode: "creature"; creatureId: CreatureId; combatantId?: CombatantId }
| { mode: "bulk-import" }
| { mode: "source-manager" };
interface SidePanelState {
panelView: PanelView;
selectedCreatureId: CreatureId | null;
selectedCombatantId: CombatantId | null;
bulkImportMode: boolean;
sourceManagerMode: boolean;
isRightPanelCollapsed: boolean;
@@ -18,8 +19,8 @@ interface SidePanelState {
}
interface SidePanelActions {
showCreature: (creatureId: CreatureId) => void;
updateCreature: (creatureId: CreatureId) => void;
showCreature: (creatureId: CreatureId, combatantId?: CombatantId) => void;
updateCreature: (creatureId: CreatureId, combatantId?: CombatantId) => void;
showBulkImport: () => void;
showSourceManager: () => void;
dismissPanel: () => void;
@@ -48,14 +49,23 @@ export function useSidePanelState(): SidePanelState & SidePanelActions {
const selectedCreatureId =
panelView.mode === "creature" ? panelView.creatureId : null;
const showCreature = useCallback((creatureId: CreatureId) => {
setPanelView({ mode: "creature", creatureId });
setIsRightPanelCollapsed(false);
}, []);
const selectedCombatantId =
panelView.mode === "creature" ? (panelView.combatantId ?? null) : null;
const updateCreature = useCallback((creatureId: CreatureId) => {
setPanelView({ mode: "creature", creatureId });
}, []);
const showCreature = useCallback(
(creatureId: CreatureId, combatantId?: CombatantId) => {
setPanelView({ mode: "creature", creatureId, combatantId });
setIsRightPanelCollapsed(false);
},
[],
);
const updateCreature = useCallback(
(creatureId: CreatureId, combatantId?: CombatantId) => {
setPanelView({ mode: "creature", creatureId, combatantId });
},
[],
);
const showBulkImport = useCallback(() => {
setPanelView({ mode: "bulk-import" });
@@ -90,6 +100,7 @@ export function useSidePanelState(): SidePanelState & SidePanelActions {
return {
panelView,
selectedCreatureId,
selectedCombatantId,
bulkImportMode: panelView.mode === "bulk-import",
sourceManagerMode: panelView.mode === "source-manager",
isRightPanelCollapsed,
File diff suppressed because it is too large Load Diff
+14 -1
View File
@@ -3,8 +3,21 @@
"packageManager": "pnpm@10.32.1+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
"pnpm": {
"overrides": {
"undici": ">=7.24.0",
"undici": "~7.24.0",
"picomatch": ">=4.0.4"
},
"auditConfig": {
"ignoreGhsas": [
"GHSA-vmh5-mc38-953g",
"GHSA-vxpw-j846-p89q",
"GHSA-hm92-r4w5-c3mj"
],
"_ignoreGhsasNotes": {
"_shared": "All three advisories sit in undici, are reached only via jsdom in test runs, and are fixed in undici>=7.28.0. We can't move there because jsdom@29.1.1 reaches into undici 7's private module layout and crashes on the 7.28+ restructure. None of the vulnerable code paths run in our tests (no SOCKS5 proxy, no WebSocket client). Drop these entries when jsdom updates its undici pin.",
"GHSA-vmh5-mc38-953g": "SOCKS5 ProxyAgent TLS bypass — unreachable, no SOCKS5 proxy in tests.",
"GHSA-vxpw-j846-p89q": "WebSocket client DoS via fragment-count bypass — unreachable, no WS client in tests.",
"GHSA-hm92-r4w5-c3mj": "SOCKS5 proxy pool cross-origin reuse — unreachable, no SOCKS5 proxy in tests."
}
}
},
"devDependencies": {
@@ -0,0 +1,20 @@
import {
addPersistentDamage,
type CombatantId,
type DomainError,
type DomainEvent,
type PersistentDamageType,
} from "@initiative/domain";
import type { EncounterStore } from "./ports.js";
import { runEncounterAction } from "./run-encounter-action.js";
export function addPersistentDamageUseCase(
store: EncounterStore,
combatantId: CombatantId,
damageType: PersistentDamageType,
formula: string,
): DomainEvent[] | DomainError {
return runEncounterAction(store, (encounter) =>
addPersistentDamage(encounter, combatantId, damageType, formula),
);
}
+2
View File
@@ -1,4 +1,5 @@
export { addCombatantUseCase } from "./add-combatant-use-case.js";
export { addPersistentDamageUseCase } from "./add-persistent-damage-use-case.js";
export { adjustHpUseCase } from "./adjust-hp-use-case.js";
export { advanceTurnUseCase } from "./advance-turn-use-case.js";
export { clearEncounterUseCase } from "./clear-encounter-use-case.js";
@@ -15,6 +16,7 @@ export type {
} from "./ports.js";
export { redoUseCase } from "./redo-use-case.js";
export { removeCombatantUseCase } from "./remove-combatant-use-case.js";
export { removePersistentDamageUseCase } from "./remove-persistent-damage-use-case.js";
export { retreatTurnUseCase } from "./retreat-turn-use-case.js";
export {
type RollAllResult,
@@ -0,0 +1,19 @@
import {
type CombatantId,
type DomainError,
type DomainEvent,
type PersistentDamageType,
removePersistentDamage,
} from "@initiative/domain";
import type { EncounterStore } from "./ports.js";
import { runEncounterAction } from "./run-encounter-action.js";
export function removePersistentDamageUseCase(
store: EncounterStore,
combatantId: CombatantId,
damageType: PersistentDamageType,
): DomainEvent[] | DomainError {
return runEncounterAction(store, (encounter) =>
removePersistentDamage(encounter, combatantId, damageType),
);
}
@@ -2,6 +2,8 @@ import { describe, expect, it } from "vitest";
import {
calculateEncounterDifficulty,
crToXp,
derivePartyLevel,
pf2eCreatureXp,
} from "../encounter-difficulty.js";
describe("crToXp", () => {
@@ -386,3 +388,234 @@ describe("calculateEncounterDifficulty — 2014 edition", () => {
expect(result.adjustedXp).toBeUndefined();
});
});
/** Helper to build a PF2e enemy-side descriptor with creature level. */
function pf2eEnemy(creatureLevel: number) {
return { creatureLevel, side: "enemy" as const };
}
/** Helper to build a PF2e party-side creature descriptor. */
function pf2eAlly(creatureLevel: number) {
return { creatureLevel, side: "party" as const };
}
describe("derivePartyLevel", () => {
it("returns 0 for empty array", () => {
expect(derivePartyLevel([])).toBe(0);
});
it("returns the level for a single PC", () => {
expect(derivePartyLevel([7])).toBe(7);
});
it("returns the unanimous level", () => {
expect(derivePartyLevel([5, 5, 5, 5])).toBe(5);
});
it("returns the mode when one level is most common", () => {
expect(derivePartyLevel([3, 3, 3, 5])).toBe(3);
});
it("returns rounded average when mode is tied", () => {
// 3,3,5,5 → average 4
expect(derivePartyLevel([3, 3, 5, 5])).toBe(4);
});
it("returns rounded average when all levels are different", () => {
// 2,4,6,8 → average 5
expect(derivePartyLevel([2, 4, 6, 8])).toBe(5);
});
it("rounds average to nearest integer", () => {
// 1,2 → average 1.5 → rounds to 2
expect(derivePartyLevel([1, 2])).toBe(2);
});
});
describe("pf2eCreatureXp", () => {
it.each([
[-4, 10],
[-3, 15],
[-2, 20],
[-1, 30],
[0, 40],
[1, 60],
[2, 80],
[3, 120],
[4, 160],
])("level diff %i returns %i XP", (diff, expectedXp) => {
// partyLevel 5, creatureLevel = 5 + diff
expect(pf2eCreatureXp(5 + diff, 5)).toBe(expectedXp);
});
it("clamps level diff below 4 to 4 (10 XP)", () => {
expect(pf2eCreatureXp(0, 10)).toBe(10);
});
it("clamps level diff above +4 to +4 (160 XP)", () => {
expect(pf2eCreatureXp(15, 5)).toBe(160);
});
});
describe("calculateEncounterDifficulty — pf2e edition", () => {
it("returns Trivial (tier 0) for 40 XP with party of 4", () => {
// 1 creature at party level = 40 XP, below Low (60)
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(5)],
"pf2e",
);
expect(result.tier).toBe(0);
expect(result.totalMonsterXp).toBe(40);
expect(result.partyLevel).toBe(5);
expect(result.thresholds).toEqual([
{ label: "Trivial", value: 40 },
{ label: "Low", value: 60 },
{ label: "Moderate", value: 80 },
{ label: "Severe", value: 120 },
{ label: "Extreme", value: 160 },
]);
});
it("returns Low (tier 1) for 60 XP", () => {
// 1 creature at party level +1 = 60 XP
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(6)],
"pf2e",
);
expect(result.tier).toBe(1);
expect(result.totalMonsterXp).toBe(60);
});
it("returns Moderate (tier 2) for 80 XP", () => {
// 1 creature at +2 = 80 XP
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(7)],
"pf2e",
);
expect(result.tier).toBe(2);
expect(result.totalMonsterXp).toBe(80);
});
it("returns Severe (tier 3) for 120 XP", () => {
// 1 creature at +3 = 120 XP
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(8)],
"pf2e",
);
expect(result.tier).toBe(3);
expect(result.totalMonsterXp).toBe(120);
});
it("returns Extreme (tier 4) for 160 XP", () => {
// 1 creature at +4 = 160 XP
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(9)],
"pf2e",
);
expect(result.tier).toBe(4);
expect(result.totalMonsterXp).toBe(160);
});
it("returns tier 0 when XP is below Low threshold", () => {
// 1 creature at 4 = 10 XP, Low = 60
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(1)],
"pf2e",
);
expect(result.tier).toBe(0);
expect(result.totalMonsterXp).toBe(10);
});
it("adjusts thresholds for 5 PCs (increases by adjustment)", () => {
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), party(5), pf2eEnemy(5)],
"pf2e",
);
expect(result.thresholds).toEqual([
{ label: "Trivial", value: 50 },
{ label: "Low", value: 75 },
{ label: "Moderate", value: 100 },
{ label: "Severe", value: 150 },
{ label: "Extreme", value: 200 },
]);
});
it("adjusts thresholds for 3 PCs (decreases by adjustment)", () => {
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), pf2eEnemy(5)],
"pf2e",
);
expect(result.thresholds).toEqual([
{ label: "Trivial", value: 30 },
{ label: "Low", value: 45 },
{ label: "Moderate", value: 60 },
{ label: "Severe", value: 90 },
{ label: "Extreme", value: 120 },
]);
});
it("floors thresholds at 0 for very small parties", () => {
const result = calculateEncounterDifficulty(
[party(5), pf2eEnemy(5)],
"pf2e",
);
// 1 PC: adjustment = 3
// Trivial: 40 + (3 * 10) = 10
// Low: 60 + (3 * 15) = 15
expect(result.thresholds[0].value).toBe(10);
expect(result.thresholds[1].value).toBe(15);
expect(result.thresholds[2].value).toBe(20); // 80 60
expect(result.thresholds[3].value).toBe(30); // 120 90
expect(result.thresholds[4].value).toBe(40); // 160 120
});
it("subtracts XP for party-side creatures", () => {
// 2 enemies at party level = 80 XP, 1 ally at party level = 40 XP
// Net = 80 40 = 40 XP
const result = calculateEncounterDifficulty(
[
party(5),
party(5),
party(5),
party(5),
pf2eEnemy(5),
pf2eEnemy(5),
pf2eAlly(5),
],
"pf2e",
);
expect(result.totalMonsterXp).toBe(40);
});
it("floors net creature XP at 0", () => {
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(1), pf2eAlly(9)],
"pf2e",
);
expect(result.totalMonsterXp).toBe(0);
});
it("derives party level using mode", () => {
// 3x level 3, 1x level 5 → mode is 3
const result = calculateEncounterDifficulty(
[party(3), party(3), party(3), party(5), pf2eEnemy(3)],
"pf2e",
);
expect(result.partyLevel).toBe(3);
});
it("has no encounterMultiplier, adjustedXp, or partySizeAdjusted", () => {
const result = calculateEncounterDifficulty(
[party(5), party(5), party(5), party(5), pf2eEnemy(5)],
"pf2e",
);
expect(result.encounterMultiplier).toBeUndefined();
expect(result.adjustedXp).toBeUndefined();
expect(result.partySizeAdjusted).toBeUndefined();
});
it("returns partyLevel undefined for D&D editions", () => {
const result = calculateEncounterDifficulty([party(1), enemy("1")], "5.5e");
expect(result.partyLevel).toBeUndefined();
});
});
@@ -0,0 +1,237 @@
import { describe, expect, it } from "vitest";
import {
addPersistentDamage,
type PersistentDamageType,
removePersistentDamage,
} from "../persistent-damage.js";
import type { Encounter } from "../types.js";
import { combatantId } from "../types.js";
const goblinId = combatantId("goblin-1");
function buildEncounter(overrides: Partial<Encounter> = {}): Encounter {
return {
combatants: [
{
id: goblinId,
name: "Goblin",
...overrides.combatants?.[0],
},
],
activeIndex: overrides.activeIndex ?? 0,
roundNumber: overrides.roundNumber ?? 1,
};
}
describe("addPersistentDamage", () => {
it("adds persistent fire damage to combatant", () => {
const encounter = buildEncounter();
const result = addPersistentDamage(encounter, goblinId, "fire", "2d6");
expect(result).not.toHaveProperty("kind");
if ("kind" in result) return;
const target = result.encounter.combatants[0];
expect(target.persistentDamage).toEqual([{ type: "fire", formula: "2d6" }]);
expect(result.events).toEqual([
{
type: "PersistentDamageAdded",
combatantId: goblinId,
damageType: "fire",
formula: "2d6",
},
]);
});
it("replaces existing entry of same type with new formula", () => {
const encounter = buildEncounter({
combatants: [
{
id: goblinId,
name: "Goblin",
persistentDamage: [{ type: "fire", formula: "2d6" }],
},
],
});
const result = addPersistentDamage(encounter, goblinId, "fire", "3d6");
expect(result).not.toHaveProperty("kind");
if ("kind" in result) return;
expect(result.encounter.combatants[0].persistentDamage).toEqual([
{ type: "fire", formula: "3d6" },
]);
});
it("allows multiple different damage types", () => {
const encounter = buildEncounter({
combatants: [
{
id: goblinId,
name: "Goblin",
persistentDamage: [{ type: "fire", formula: "2d6" }],
},
],
});
const result = addPersistentDamage(encounter, goblinId, "bleed", "1d4");
expect(result).not.toHaveProperty("kind");
if ("kind" in result) return;
expect(result.encounter.combatants[0].persistentDamage).toEqual([
{ type: "fire", formula: "2d6" },
{ type: "bleed", formula: "1d4" },
]);
});
it("sorts entries by definition order", () => {
const encounter = buildEncounter({
combatants: [
{
id: goblinId,
name: "Goblin",
persistentDamage: [{ type: "cold", formula: "1d6" }],
},
],
});
const result = addPersistentDamage(encounter, goblinId, "fire", "2d6");
expect(result).not.toHaveProperty("kind");
if ("kind" in result) return;
const types = result.encounter.combatants[0].persistentDamage?.map(
(e) => e.type,
);
expect(types).toEqual(["fire", "cold"]);
});
it("returns domain error for empty formula", () => {
const encounter = buildEncounter();
const result = addPersistentDamage(encounter, goblinId, "fire", " ");
expect(result).toHaveProperty("kind", "domain-error");
if (!("kind" in result)) return;
expect(result.code).toBe("empty-formula");
});
it("returns domain error for unknown damage type", () => {
const encounter = buildEncounter();
const result = addPersistentDamage(
encounter,
goblinId,
"radiant" as PersistentDamageType,
"2d6",
);
expect(result).toHaveProperty("kind", "domain-error");
if (!("kind" in result)) return;
expect(result.code).toBe("unknown-damage-type");
});
it("returns domain error for unknown combatant", () => {
const encounter = buildEncounter();
const result = addPersistentDamage(
encounter,
combatantId("nonexistent"),
"fire",
"2d6",
);
expect(result).toHaveProperty("kind", "domain-error");
if (!("kind" in result)) return;
expect(result.code).toBe("combatant-not-found");
});
it("trims formula whitespace", () => {
const encounter = buildEncounter();
const result = addPersistentDamage(encounter, goblinId, "fire", " 2d6 ");
expect(result).not.toHaveProperty("kind");
if ("kind" in result) return;
expect(result.encounter.combatants[0].persistentDamage?.[0].formula).toBe(
"2d6",
);
});
it("does not mutate input encounter", () => {
const encounter = buildEncounter();
const originalCombatants = encounter.combatants;
addPersistentDamage(encounter, goblinId, "fire", "2d6");
expect(encounter.combatants).toBe(originalCombatants);
expect(encounter.combatants[0].persistentDamage).toBeUndefined();
});
});
describe("removePersistentDamage", () => {
it("removes existing persistent damage entry", () => {
const encounter = buildEncounter({
combatants: [
{
id: goblinId,
name: "Goblin",
persistentDamage: [
{ type: "fire", formula: "2d6" },
{ type: "bleed", formula: "1d4" },
],
},
],
});
const result = removePersistentDamage(encounter, goblinId, "fire");
expect(result).not.toHaveProperty("kind");
if ("kind" in result) return;
expect(result.encounter.combatants[0].persistentDamage).toEqual([
{ type: "bleed", formula: "1d4" },
]);
expect(result.events).toEqual([
{
type: "PersistentDamageRemoved",
combatantId: goblinId,
damageType: "fire",
},
]);
});
it("sets persistentDamage to undefined when last entry removed", () => {
const encounter = buildEncounter({
combatants: [
{
id: goblinId,
name: "Goblin",
persistentDamage: [{ type: "fire", formula: "2d6" }],
},
],
});
const result = removePersistentDamage(encounter, goblinId, "fire");
expect(result).not.toHaveProperty("kind");
if ("kind" in result) return;
expect(result.encounter.combatants[0].persistentDamage).toBeUndefined();
});
it("returns domain error when damage type not active", () => {
const encounter = buildEncounter();
const result = removePersistentDamage(encounter, goblinId, "fire");
expect(result).toHaveProperty("kind", "domain-error");
if (!("kind" in result)) return;
expect(result.code).toBe("persistent-damage-not-active");
});
it("returns domain error for unknown combatant", () => {
const encounter = buildEncounter();
const result = removePersistentDamage(
encounter,
combatantId("nonexistent"),
"fire",
);
expect(result).toHaveProperty("kind", "domain-error");
if (!("kind" in result)) return;
expect(result.code).toBe("combatant-not-found");
});
});
@@ -0,0 +1,270 @@
import { describe, expect, it } from "vitest";
import type { Pf2eCreature } from "../creature-types.js";
import { creatureId } from "../creature-types.js";
import {
acDelta,
adjustedLevel,
applyPf2eAdjustment,
hpDelta,
modDelta,
} from "../pf2e-adjustments.js";
describe("adjustedLevel", () => {
it("elite on level 5 → 6", () => {
expect(adjustedLevel(5, "elite")).toBe(6);
});
it("elite on level 0 → 2 (double bump)", () => {
expect(adjustedLevel(0, "elite")).toBe(2);
});
it("elite on level 1 → 1 (double bump)", () => {
expect(adjustedLevel(-1, "elite")).toBe(1);
});
it("weak on level 5 → 4", () => {
expect(adjustedLevel(5, "weak")).toBe(4);
});
it("weak on level 1 → 1 (double drop)", () => {
expect(adjustedLevel(1, "weak")).toBe(-1);
});
it("weak on level 0 → 1", () => {
expect(adjustedLevel(0, "weak")).toBe(-1);
});
});
describe("hpDelta", () => {
it("level 1 elite → +10", () => {
expect(hpDelta(1, "elite")).toBe(10);
});
it("level 1 weak → 10", () => {
expect(hpDelta(1, "weak")).toBe(-10);
});
it("level 3 elite → +15", () => {
expect(hpDelta(3, "elite")).toBe(15);
});
it("level 3 weak → 15", () => {
expect(hpDelta(3, "weak")).toBe(-15);
});
it("level 10 elite → +20", () => {
expect(hpDelta(10, "elite")).toBe(20);
});
it("level 10 weak → 20", () => {
expect(hpDelta(10, "weak")).toBe(-20);
});
it("level 25 elite → +30", () => {
expect(hpDelta(25, "elite")).toBe(30);
});
it("level 25 weak → 30", () => {
expect(hpDelta(25, "weak")).toBe(-30);
});
});
describe("acDelta", () => {
it("elite → +2", () => {
expect(acDelta("elite")).toBe(2);
});
it("weak → 2", () => {
expect(acDelta("weak")).toBe(-2);
});
});
describe("modDelta", () => {
it("elite → +2", () => {
expect(modDelta("elite")).toBe(2);
});
it("weak → 2", () => {
expect(modDelta("weak")).toBe(-2);
});
});
function baseCreature(overrides?: Partial<Pf2eCreature>): Pf2eCreature {
return {
system: "pf2e",
id: creatureId("test-creature"),
name: "Test Creature",
source: "test-source",
sourceDisplayName: "Test Source",
level: 5,
traits: ["humanoid"],
perception: 12,
skills: "Athletics +14",
abilityMods: {
str: 4,
dex: 2,
con: 3,
int: 0,
wis: 1,
cha: -1,
},
ac: 22,
saveFort: 14,
saveRef: 11,
saveWill: 9,
hp: 75,
speed: "25 feet",
...overrides,
};
}
describe("applyPf2eAdjustment", () => {
it("adjusts all numeric stats for elite", () => {
const creature = baseCreature();
const result = applyPf2eAdjustment(creature, "elite");
expect(result.level).toBe(6);
expect(result.ac).toBe(24);
expect(result.hp).toBe(95); // 75 + 20 (level 5 bracket)
expect(result.perception).toBe(14);
expect(result.saveFort).toBe(16);
expect(result.saveRef).toBe(13);
expect(result.saveWill).toBe(11);
});
it("adjusts all numeric stats for weak", () => {
const creature = baseCreature();
const result = applyPf2eAdjustment(creature, "weak");
expect(result.level).toBe(4);
expect(result.ac).toBe(20);
expect(result.hp).toBe(55); // 75 - 20 (level 5 bracket)
expect(result.perception).toBe(10);
expect(result.saveFort).toBe(12);
expect(result.saveRef).toBe(9);
expect(result.saveWill).toBe(7);
});
it("adjusts attack bonuses and damage", () => {
const creature = baseCreature({
attacks: [
{
name: "Melee",
activity: { number: 1, unit: "action" },
segments: [
{
type: "text",
value: "+15 [+10/+5] (agile), 2d12+7 piercing plus Grab",
},
],
},
],
});
const result = applyPf2eAdjustment(creature, "elite");
const text = result.attacks?.[0].segments[0];
expect(text).toEqual({
type: "text",
value: "+17 [+12/+7] (agile), 2d12+9 piercing plus Grab",
});
});
it("adjusts attack damage for weak", () => {
const creature = baseCreature({
attacks: [
{
name: "Melee",
activity: { number: 1, unit: "action" },
segments: [
{
type: "text",
value: "+15 (agile), 2d12+7 piercing plus Grab",
},
],
},
],
});
const result = applyPf2eAdjustment(creature, "weak");
const text = result.attacks?.[0].segments[0];
expect(text).toEqual({
type: "text",
value: "+13 (agile), 2d12+5 piercing plus Grab",
});
});
it("handles damage bonus becoming zero", () => {
const creature = baseCreature({
attacks: [
{
name: "Melee",
activity: { number: 1, unit: "action" },
segments: [{ type: "text", value: "+10, 1d4+2 slashing" }],
},
],
});
const result = applyPf2eAdjustment(creature, "weak");
const text = result.attacks?.[0].segments[0];
expect(text).toEqual({
type: "text",
value: "+8, 1d4 slashing",
});
});
it("handles damage bonus becoming negative", () => {
const creature = baseCreature({
attacks: [
{
name: "Melee",
activity: { number: 1, unit: "action" },
segments: [{ type: "text", value: "+10, 1d4+1 slashing" }],
},
],
});
const result = applyPf2eAdjustment(creature, "weak");
const text = result.attacks?.[0].segments[0];
expect(text).toEqual({
type: "text",
value: "+8, 1d4-1 slashing",
});
});
it("does not modify non-attack abilities", () => {
const creature = baseCreature({
abilitiesTop: [
{
name: "Darkvision",
segments: [{ type: "text", value: "Can see in darkness." }],
},
],
});
const result = applyPf2eAdjustment(creature, "elite");
expect(result.abilitiesTop).toEqual(creature.abilitiesTop);
});
it("preserves non-text segments in attacks", () => {
const creature = baseCreature({
attacks: [
{
name: "Melee",
activity: { number: 1, unit: "action" },
segments: [
{
type: "list",
items: [{ text: "some list item" }],
},
],
},
],
});
const result = applyPf2eAdjustment(creature, "elite");
expect(result.attacks?.[0].segments[0]).toEqual({
type: "list",
items: [{ text: "some list item" }],
});
});
});
@@ -301,6 +301,52 @@ describe("rehydrateCombatant", () => {
expect(result?.side).toBeUndefined();
});
it("preserves valid persistent damage entries", () => {
const result = rehydrateCombatant({
...minimalCombatant(),
persistentDamage: [
{ type: "fire", formula: "2d6" },
{ type: "bleed", formula: "1d4" },
],
});
expect(result?.persistentDamage).toEqual([
{ type: "fire", formula: "2d6" },
{ type: "bleed", formula: "1d4" },
]);
});
it("filters out invalid persistent damage entries", () => {
const result = rehydrateCombatant({
...minimalCombatant(),
persistentDamage: [
{ type: "fire", formula: "2d6" },
{ type: "radiant", formula: "1d4" },
{ type: "bleed", formula: "" },
{ type: "acid" },
{ formula: "1d6" },
],
});
expect(result?.persistentDamage).toEqual([
{ type: "fire", formula: "2d6" },
]);
});
it("returns undefined persistentDamage for non-array value", () => {
const result = rehydrateCombatant({
...minimalCombatant(),
persistentDamage: "fire",
});
expect(result?.persistentDamage).toBeUndefined();
});
it("returns undefined persistentDamage for empty array", () => {
const result = rehydrateCombatant({
...minimalCombatant(),
persistentDamage: [],
});
expect(result?.persistentDamage).toBeUndefined();
});
it("drops invalid tempHp — keeps combatant", () => {
for (const tempHp of [-1, 1.5, "3"]) {
const result = rehydrateCombatant({
@@ -60,13 +60,13 @@ describe("toggleCondition", () => {
]);
});
it("maintains definition order when adding conditions", () => {
it("appends new conditions to the end (insertion order)", () => {
const e = enc([makeCombatant("A", [{ id: "poisoned" }])]);
const { encounter } = success(e, "A", "blinded");
expect(encounter.combatants[0].conditions).toEqual([
{ id: "blinded" },
{ id: "poisoned" },
{ id: "blinded" },
]);
});
@@ -109,15 +109,16 @@ describe("toggleCondition", () => {
expect(encounter.combatants[0].conditions).toBeUndefined();
});
it("preserves order across all conditions", () => {
it("preserves insertion order across all conditions", () => {
const order = CONDITION_DEFINITIONS.map((d) => d.id);
// Add in reverse order
// Add in reverse order — result should be reverse order (insertion order)
const reversed = [...order].reverse();
let e = enc([makeCombatant("A")]);
for (const cond of [...order].reverse()) {
for (const cond of reversed) {
const result = success(e, "A", cond);
e = result.encounter;
}
expect(e.combatants[0].conditions).toEqual(order.map((id) => ({ id })));
expect(e.combatants[0].conditions).toEqual(reversed.map((id) => ({ id })));
});
});
+4
View File
@@ -14,6 +14,7 @@ export interface CombatantInit {
readonly ac?: number;
readonly initiative?: number;
readonly creatureId?: CreatureId;
readonly creatureAdjustment?: "weak" | "elite";
readonly color?: string;
readonly icon?: string;
readonly playerCharacterId?: PlayerCharacterId;
@@ -67,6 +68,9 @@ function buildCombatant(
...(init?.ac !== undefined && { ac: init.ac }),
...(init?.initiative !== undefined && { initiative: init.initiative }),
...(init?.creatureId !== undefined && { creatureId: init.creatureId }),
...(init?.creatureAdjustment !== undefined && {
creatureAdjustment: init.creatureAdjustment,
}),
...(init?.color !== undefined && { color: init.color }),
...(init?.icon !== undefined && { icon: init.icon }),
...(init?.playerCharacterId !== undefined && {
+2 -2
View File
@@ -500,8 +500,8 @@ export const CONDITION_DEFINITIONS: readonly ConditionDefinition[] = [
description5e: "",
descriptionPf2e:
"Location unknown. Must pick a square to target; DC 11 flat check. Attacker is off-guard against your attacks.",
iconName: "Ghost",
color: "violet",
iconName: "EyeClosed",
color: "slate",
systems: ["pf2e"],
},
{
+169 -2
View File
@@ -1,7 +1,7 @@
import type { RulesEdition } from "./rules-edition.js";
/** Abstract difficulty severity: 0 = negligible, 3 = maximum. Maps to filled bar count. */
export type DifficultyTier = 0 | 1 | 2 | 3;
/** Abstract difficulty severity: 0 = negligible, up to 4 (PF2e Extreme). Maps to filled bar count. */
export type DifficultyTier = 0 | 1 | 2 | 3 | 4;
export interface DifficultyThreshold {
readonly label: string;
@@ -18,6 +18,8 @@ export interface DifficultyResult {
readonly adjustedXp: number | undefined;
/** 2014 only: true when the multiplier was shifted due to party size (<3 or 6+). */
readonly partySizeAdjusted: boolean | undefined;
/** PF2e only: the derived party level used for XP calculation. */
readonly partyLevel: number | undefined;
}
/** Maps challenge rating strings to XP values (standard 5e). */
@@ -160,6 +162,133 @@ function getEncounterMultiplier(
};
}
/**
* PF2e: XP granted by a creature based on its level relative to party level.
* Key is (creature level party level), clamped to [4, +4].
*/
const PF2E_LEVEL_DIFF_XP: Readonly<Record<number, number>> = {
[-4]: 10,
[-3]: 15,
[-2]: 20,
[-1]: 30,
0: 40,
1: 60,
2: 80,
3: 120,
4: 160,
};
/** PF2e base encounter budget thresholds for a party of 4. */
const PF2E_THRESHOLDS_BASE = {
trivial: 40,
low: 60,
moderate: 80,
severe: 120,
extreme: 160,
} as const;
/** PF2e per-PC adjustment to each threshold (added per PC beyond 4, subtracted per PC fewer). */
const PF2E_THRESHOLD_ADJUSTMENTS = {
trivial: 10,
low: 15,
moderate: 20,
severe: 30,
extreme: 40,
} as const;
/**
* Derives PF2e party level from PC levels.
* Returns the mode (most common level). If no unique mode, returns
* the average rounded to the nearest integer.
*/
export function derivePartyLevel(levels: readonly number[]): number {
if (levels.length === 0) return 0;
if (levels.length === 1) return levels[0];
const counts = new Map<number, number>();
for (const l of levels) {
counts.set(l, (counts.get(l) ?? 0) + 1);
}
let maxCount = 0;
let mode: number | undefined;
let isTied = false;
for (const [level, count] of counts) {
if (count > maxCount) {
maxCount = count;
mode = level;
isTied = false;
} else if (count === maxCount) {
isTied = true;
}
}
if (!isTied && mode !== undefined) return mode;
const sum = levels.reduce((a, b) => a + b, 0);
return Math.round(sum / levels.length);
}
/** Returns PF2e XP for a creature given its level and the party level. */
export function pf2eCreatureXp(
creatureLevel: number,
partyLevel: number,
): number {
const diff = Math.max(-4, Math.min(4, creatureLevel - partyLevel));
return PF2E_LEVEL_DIFF_XP[diff] ?? 0;
}
function calculatePf2eBudget(partySize: number) {
const adjustment = partySize - 4;
return {
trivial: Math.max(
0,
PF2E_THRESHOLDS_BASE.trivial +
adjustment * PF2E_THRESHOLD_ADJUSTMENTS.trivial,
),
low: Math.max(
0,
PF2E_THRESHOLDS_BASE.low + adjustment * PF2E_THRESHOLD_ADJUSTMENTS.low,
),
moderate: Math.max(
0,
PF2E_THRESHOLDS_BASE.moderate +
adjustment * PF2E_THRESHOLD_ADJUSTMENTS.moderate,
),
severe: Math.max(
0,
PF2E_THRESHOLDS_BASE.severe +
adjustment * PF2E_THRESHOLD_ADJUSTMENTS.severe,
),
extreme: Math.max(
0,
PF2E_THRESHOLDS_BASE.extreme +
adjustment * PF2E_THRESHOLD_ADJUSTMENTS.extreme,
),
};
}
function scanCombatantsPf2e(
combatants: readonly CombatantDescriptor[],
partyLevel: number,
) {
let totalCreatureXp = 0;
for (const c of combatants) {
if (c.creatureLevel !== undefined) {
const xp = pf2eCreatureXp(c.creatureLevel, partyLevel);
if (c.side === "enemy") {
totalCreatureXp += xp;
} else {
totalCreatureXp -= xp;
}
}
}
return { totalCreatureXp: Math.max(0, totalCreatureXp) };
}
/** All standard 5e challenge rating strings, in ascending order. */
export const VALID_CR_VALUES: readonly string[] = Object.keys(CR_TO_XP);
@@ -171,6 +300,7 @@ export function crToXp(cr: string): number {
export interface CombatantDescriptor {
readonly level?: number;
readonly cr?: string;
readonly creatureLevel?: number;
readonly side: "party" | "enemy";
}
@@ -247,6 +377,41 @@ export function calculateEncounterDifficulty(
combatants: readonly CombatantDescriptor[],
edition: RulesEdition,
): DifficultyResult {
if (edition === "pf2e") {
const partyLevels: number[] = [];
for (const c of combatants) {
if (c.level !== undefined && c.side === "party") {
partyLevels.push(c.level);
}
}
const partyLevel = derivePartyLevel(partyLevels);
const { totalCreatureXp } = scanCombatantsPf2e(combatants, partyLevel);
const budget = calculatePf2eBudget(partyLevels.length);
const thresholds: DifficultyThreshold[] = [
{ label: "Trivial", value: budget.trivial },
{ label: "Low", value: budget.low },
{ label: "Moderate", value: budget.moderate },
{ label: "Severe", value: budget.severe },
{ label: "Extreme", value: budget.extreme },
];
return {
tier: determineTier(totalCreatureXp, [
budget.low,
budget.moderate,
budget.severe,
budget.extreme,
]),
totalMonsterXp: totalCreatureXp,
thresholds,
encounterMultiplier: undefined,
adjustedXp: undefined,
partySizeAdjusted: undefined,
partyLevel,
};
}
const { totalMonsterXp, monsterCount, partyLevels } =
scanCombatants(combatants);
@@ -268,6 +433,7 @@ export function calculateEncounterDifficulty(
encounterMultiplier: undefined,
adjustedXp: undefined,
partySizeAdjusted: undefined,
partyLevel: undefined,
};
}
@@ -294,5 +460,6 @@ export function calculateEncounterDifficulty(
encounterMultiplier,
adjustedXp,
partySizeAdjusted,
partyLevel: undefined,
};
}
+23
View File
@@ -1,5 +1,6 @@
import type { ConditionId } from "./conditions.js";
import type { CreatureId } from "./creature-types.js";
import type { PersistentDamageType } from "./persistent-damage.js";
import type { PlayerCharacterId } from "./player-character-types.js";
import type { CombatantId } from "./types.js";
@@ -132,6 +133,25 @@ export interface ConcentrationEnded {
readonly combatantId: CombatantId;
}
export interface PersistentDamageAdded {
readonly type: "PersistentDamageAdded";
readonly combatantId: CombatantId;
readonly damageType: PersistentDamageType;
readonly formula: string;
}
export interface PersistentDamageRemoved {
readonly type: "PersistentDamageRemoved";
readonly combatantId: CombatantId;
readonly damageType: PersistentDamageType;
}
export interface CreatureAdjustmentSet {
readonly type: "CreatureAdjustmentSet";
readonly combatantId: CombatantId;
readonly adjustment: "weak" | "elite" | undefined;
}
export interface EncounterCleared {
readonly type: "EncounterCleared";
readonly combatantCount: number;
@@ -175,6 +195,9 @@ export type DomainEvent =
| ConditionRemoved
| ConcentrationStarted
| ConcentrationEnded
| PersistentDamageAdded
| PersistentDamageRemoved
| CreatureAdjustmentSet
| EncounterCleared
| PlayerCharacterCreated
| PlayerCharacterUpdated
+24
View File
@@ -64,6 +64,8 @@ export {
type DifficultyResult,
type DifficultyThreshold,
type DifficultyTier,
derivePartyLevel,
pf2eCreatureXp,
VALID_CR_VALUES,
} from "./encounter-difficulty.js";
export type {
@@ -75,12 +77,15 @@ export type {
ConcentrationStarted,
ConditionAdded,
ConditionRemoved,
CreatureAdjustmentSet,
CrSet,
CurrentHpAdjusted,
DomainEvent,
EncounterCleared,
InitiativeSet,
MaxHpSet,
PersistentDamageAdded,
PersistentDamageRemoved,
PlayerCharacterCreated,
PlayerCharacterDeleted,
PlayerCharacterUpdated,
@@ -99,6 +104,25 @@ export {
formatInitiativeModifier,
type InitiativeResult,
} from "./initiative.js";
export {
addPersistentDamage,
PERSISTENT_DAMAGE_DEFINITIONS,
PERSISTENT_DAMAGE_TYPES,
type PersistentDamageDefinition,
type PersistentDamageEntry,
type PersistentDamageSuccess,
type PersistentDamageType,
removePersistentDamage,
VALID_PERSISTENT_DAMAGE_TYPES,
} from "./persistent-damage.js";
export {
acDelta,
adjustedLevel,
applyPf2eAdjustment,
type CreatureAdjustment,
hpDelta,
modDelta,
} from "./pf2e-adjustments.js";
export {
type PlayerCharacter,
type PlayerCharacterId,
+185
View File
@@ -0,0 +1,185 @@
import type { DomainEvent } from "./events.js";
import {
type CombatantId,
type DomainError,
type Encounter,
findCombatant,
isDomainError,
} from "./types.js";
export const PERSISTENT_DAMAGE_TYPES = [
"fire",
"bleed",
"acid",
"cold",
"electricity",
"poison",
"mental",
"force",
"void",
"spirit",
"vitality",
"piercing",
] as const;
export type PersistentDamageType = (typeof PERSISTENT_DAMAGE_TYPES)[number];
export const VALID_PERSISTENT_DAMAGE_TYPES: ReadonlySet<string> = new Set(
PERSISTENT_DAMAGE_TYPES,
);
export interface PersistentDamageEntry {
readonly type: PersistentDamageType;
readonly formula: string;
}
export interface PersistentDamageDefinition {
readonly type: PersistentDamageType;
readonly label: string;
readonly iconName: string;
readonly color: string;
}
export const PERSISTENT_DAMAGE_DEFINITIONS: readonly PersistentDamageDefinition[] =
[
{ type: "fire", label: "Fire", iconName: "Flame", color: "orange" },
{ type: "bleed", label: "Bleed", iconName: "Droplets", color: "red" },
{
type: "acid",
label: "Acid",
iconName: "FlaskConical",
color: "lime",
},
{ type: "cold", label: "Cold", iconName: "Snowflake", color: "sky" },
{
type: "electricity",
label: "Electricity",
iconName: "Zap",
color: "yellow",
},
{
type: "poison",
label: "Poison",
iconName: "Droplet",
color: "green",
},
{
type: "mental",
label: "Mental",
iconName: "BrainCog",
color: "pink",
},
{ type: "force", label: "Force", iconName: "Orbit", color: "indigo" },
{ type: "void", label: "Void", iconName: "Eclipse", color: "purple" },
{ type: "spirit", label: "Spirit", iconName: "Wind", color: "neutral" },
{
type: "vitality",
label: "Vitality",
iconName: "Sparkle",
color: "amber",
},
{
type: "piercing",
label: "Piercing",
iconName: "Sword",
color: "neutral",
},
];
export interface PersistentDamageSuccess {
readonly encounter: Encounter;
readonly events: DomainEvent[];
}
function applyPersistentDamage(
encounter: Encounter,
combatantId: CombatantId,
newEntries: readonly PersistentDamageEntry[] | undefined,
): Encounter {
return {
combatants: encounter.combatants.map((c) =>
c.id === combatantId ? { ...c, persistentDamage: newEntries } : c,
),
activeIndex: encounter.activeIndex,
roundNumber: encounter.roundNumber,
};
}
export function addPersistentDamage(
encounter: Encounter,
combatantId: CombatantId,
damageType: PersistentDamageType,
formula: string,
): PersistentDamageSuccess | DomainError {
if (!VALID_PERSISTENT_DAMAGE_TYPES.has(damageType)) {
return {
kind: "domain-error",
code: "unknown-damage-type",
message: `Unknown persistent damage type "${damageType}"`,
};
}
if (formula.trim().length === 0) {
return {
kind: "domain-error",
code: "empty-formula",
message: "Persistent damage formula must not be empty",
};
}
const found = findCombatant(encounter, combatantId);
if (isDomainError(found)) return found;
const { combatant: target } = found;
const current = target.persistentDamage ?? [];
// Replace existing entry of same type, or append
const filtered = current.filter((e) => e.type !== damageType);
const newEntries = [
...filtered,
{ type: damageType, formula: formula.trim() },
];
// Sort by definition order
const order = PERSISTENT_DAMAGE_DEFINITIONS.map((d) => d.type);
newEntries.sort((a, b) => order.indexOf(a.type) - order.indexOf(b.type));
return {
encounter: applyPersistentDamage(encounter, combatantId, newEntries),
events: [
{
type: "PersistentDamageAdded",
combatantId,
damageType,
formula: formula.trim(),
},
],
};
}
export function removePersistentDamage(
encounter: Encounter,
combatantId: CombatantId,
damageType: PersistentDamageType,
): PersistentDamageSuccess | DomainError {
const found = findCombatant(encounter, combatantId);
if (isDomainError(found)) return found;
const { combatant: target } = found;
const current = target.persistentDamage ?? [];
if (!current.some((e) => e.type === damageType)) {
return {
kind: "domain-error",
code: "persistent-damage-not-active",
message: `Persistent ${damageType} damage is not active`,
};
}
const filtered = current.filter((e) => e.type !== damageType);
return {
encounter: applyPersistentDamage(
encounter,
combatantId,
filtered.length > 0 ? filtered : undefined,
),
events: [{ type: "PersistentDamageRemoved", combatantId, damageType }],
};
}
+110
View File
@@ -0,0 +1,110 @@
import type {
Pf2eCreature,
TraitBlock,
TraitSegment,
} from "./creature-types.js";
export type CreatureAdjustment = "weak" | "elite";
/** HP bracket delta by creature level (standard PF2e table). */
function hpBracketDelta(level: number): number {
if (level <= 1) return 10;
if (level <= 4) return 15;
if (level <= 19) return 20;
return 30;
}
/** Level shift: elite +1 (or +2 if level ≤ 0), weak 1 (or 2 if level is 1). */
export function adjustedLevel(
baseLevel: number,
adjustment: CreatureAdjustment,
): number {
if (adjustment === "elite") {
return baseLevel <= 0 ? baseLevel + 2 : baseLevel + 1;
}
return baseLevel === 1 ? baseLevel - 2 : baseLevel - 1;
}
/** Signed HP delta for a given base level and adjustment. */
export function hpDelta(
baseLevel: number,
adjustment: CreatureAdjustment,
): number {
const delta = hpBracketDelta(baseLevel);
return adjustment === "elite" ? delta : -delta;
}
/** AC delta: +2 for elite, 2 for weak. */
export function acDelta(adjustment: CreatureAdjustment): number {
return adjustment === "elite" ? 2 : -2;
}
/** Generic ±2 modifier delta. Used for saves, Perception, attacks, damage. */
export function modDelta(adjustment: CreatureAdjustment): number {
return adjustment === "elite" ? 2 : -2;
}
const ATTACK_BONUS_RE = /^([+-])(\d+)/;
const MAP_RE = /\[([+-]\d+)\/([+-]\d+)\]/g;
const DAMAGE_BONUS_RE = /(\d+d\d+)([+-])(\d+)/g;
/**
* Adjust attack bonus in a formatted attack string.
* "+15 (agile), 2d12+7 piercing plus Grab" → "+17 (agile), 2d12+9 piercing plus Grab"
*/
function adjustAttackText(text: string, delta: number): string {
// Adjust leading attack bonus: "+15" → "+17"
let result = text.replace(ATTACK_BONUS_RE, (_, sign, num) => {
const adjusted = (sign === "+" ? 1 : -1) * Number(num) + delta;
return adjusted >= 0 ? `+${adjusted}` : `${adjusted}`;
});
// Adjust MAP values in brackets: "[+10/+5]" → "[+12/+7]"
result = result.replace(MAP_RE, (_, m1, m2) => {
const a1 = Number(m1) + delta;
const a2 = Number(m2) + delta;
const f = (n: number) => (n >= 0 ? `+${n}` : `${n}`);
return `[${f(a1)}/${f(a2)}]`;
});
// Adjust damage bonus in "NdN+N type" patterns
result = result.replace(DAMAGE_BONUS_RE, (_, dice, sign, num) => {
const current = (sign === "+" ? 1 : -1) * Number(num);
const adjusted = current + delta;
if (adjusted === 0) return dice as string;
return adjusted > 0 ? `${dice}+${adjusted}` : `${dice}${adjusted}`;
});
return result;
}
function adjustTraitBlock(block: TraitBlock, delta: number): TraitBlock {
return {
...block,
segments: block.segments.map(
(seg): TraitSegment =>
seg.type === "text"
? { type: "text", value: adjustAttackText(seg.value, delta) }
: seg,
),
};
}
/**
* Apply a weak or elite adjustment to a full PF2e creature.
* Returns a new Pf2eCreature with all numeric stats adjusted.
*/
export function applyPf2eAdjustment(
creature: Pf2eCreature,
adjustment: CreatureAdjustment,
): Pf2eCreature {
const d = modDelta(adjustment);
return {
...creature,
level: adjustedLevel(creature.level, adjustment),
ac: creature.ac + d,
hp: creature.hp + hpDelta(creature.level, adjustment),
perception: creature.perception + d,
saveFort: creature.saveFort + d,
saveRef: creature.saveRef + d,
saveWill: creature.saveWill + d,
attacks: creature.attacks?.map((a) => adjustTraitBlock(a, d)),
};
}
@@ -2,6 +2,8 @@ import type { ConditionEntry, ConditionId } from "./conditions.js";
import { VALID_CONDITION_IDS } from "./conditions.js";
import { creatureId } from "./creature-types.js";
import { VALID_CR_VALUES } from "./encounter-difficulty.js";
import type { PersistentDamageEntry } from "./persistent-damage.js";
import { VALID_PERSISTENT_DAMAGE_TYPES } from "./persistent-damage.js";
import {
playerCharacterId,
VALID_PLAYER_COLORS,
@@ -42,6 +44,32 @@ function validateConditions(value: unknown): ConditionEntry[] | undefined {
return entries.length > 0 ? entries : undefined;
}
function validatePersistentDamage(
value: unknown,
): PersistentDamageEntry[] | undefined {
if (!Array.isArray(value)) return undefined;
const entries: PersistentDamageEntry[] = [];
for (const item of value) {
if (
typeof item === "object" &&
item !== null &&
typeof (item as Record<string, unknown>).type === "string" &&
VALID_PERSISTENT_DAMAGE_TYPES.has(
(item as Record<string, unknown>).type as string,
) &&
typeof (item as Record<string, unknown>).formula === "string" &&
((item as Record<string, unknown>).formula as string).length > 0
) {
entries.push({
type: (item as Record<string, unknown>)
.type as PersistentDamageEntry["type"],
formula: (item as Record<string, unknown>).formula as string,
});
}
}
return entries.length > 0 ? entries : undefined;
}
function validateHp(
rawMaxHp: unknown,
rawCurrentHp: unknown,
@@ -93,6 +121,7 @@ function validateCr(value: unknown): string | undefined {
: undefined;
}
const VALID_ADJUSTMENTS = new Set(["weak", "elite"]);
const VALID_SIDES = new Set(["party", "enemy"]);
function validateSide(value: unknown): "party" | "enemy" | undefined {
@@ -106,10 +135,15 @@ function parseOptionalFields(entry: Record<string, unknown>) {
initiative: validateInteger(entry.initiative),
ac: validateAc(entry.ac),
conditions: validateConditions(entry.conditions),
persistentDamage: validatePersistentDamage(entry.persistentDamage),
isConcentrating: entry.isConcentrating === true ? true : undefined,
creatureId: validateNonEmptyString(entry.creatureId)
? creatureId(entry.creatureId as string)
: undefined,
creatureAdjustment: validateSetMember(
entry.creatureAdjustment,
VALID_ADJUSTMENTS,
) as "weak" | "elite" | undefined,
cr: validateCr(entry.cr),
side: validateSide(entry.side),
color: validateSetMember(entry.color, VALID_PLAYER_COLORS),
+2 -12
View File
@@ -14,12 +14,6 @@ export interface ToggleConditionSuccess {
readonly events: DomainEvent[];
}
function sortByDefinitionOrder(entries: ConditionEntry[]): ConditionEntry[] {
const order = CONDITION_DEFINITIONS.map((d) => d.id);
entries.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
return entries;
}
function validateConditionId(conditionId: ConditionId): DomainError | null {
if (!VALID_CONDITION_IDS.has(conditionId)) {
return {
@@ -67,8 +61,7 @@ export function toggleCondition(
newConditions = filtered.length > 0 ? filtered : undefined;
event = { type: "ConditionRemoved", combatantId, condition: conditionId };
} else {
const added = sortByDefinitionOrder([...current, { id: conditionId }]);
newConditions = added;
newConditions = [...current, { id: conditionId }];
event = { type: "ConditionAdded", combatantId, condition: conditionId };
}
@@ -125,10 +118,7 @@ export function setConditionValue(
};
}
const added = sortByDefinitionOrder([
...current,
{ id: conditionId, value: clampedValue },
]);
const added = [...current, { id: conditionId, value: clampedValue }];
return {
encounter: applyConditions(encounter, combatantId, added),
events: [
+3
View File
@@ -7,6 +7,7 @@ export function combatantId(id: string): CombatantId {
import type { ConditionEntry } from "./conditions.js";
import type { CreatureId } from "./creature-types.js";
import type { PersistentDamageEntry } from "./persistent-damage.js";
import type { PlayerCharacterId } from "./player-character-types.js";
export interface Combatant {
@@ -18,8 +19,10 @@ export interface Combatant {
readonly tempHp?: number;
readonly ac?: number;
readonly conditions?: readonly ConditionEntry[];
readonly persistentDamage?: readonly PersistentDamageEntry[];
readonly isConcentrating?: boolean;
readonly creatureId?: CreatureId;
readonly creatureAdjustment?: "weak" | "elite";
readonly cr?: string;
readonly side?: "party" | "enemy";
readonly color?: string;
+224 -177
View File
@@ -5,7 +5,7 @@ settings:
excludeLinksFromLockfile: false
overrides:
undici: '>=7.24.0'
undici: ~7.24.0
picomatch: '>=4.0.4'
importers:
@@ -17,7 +17,7 @@ importers:
version: 2.4.8
'@vitest/coverage-v8':
specifier: ^4.1.0
version: 4.1.0(vitest@4.1.0(@types/node@25.3.3)(jsdom@29.0.1)(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)))
version: 4.1.0(vitest@4.1.0(@types/node@25.3.3)(jsdom@29.1.1)(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)))
jscpd:
specifier: ^4.0.8
version: 4.0.8
@@ -41,7 +41,7 @@ importers:
version: 5.9.3
vitest:
specifier: ^4.1.0
version: 4.1.0(@types/node@25.3.3)(jsdom@29.0.1)(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
version: 4.1.0(@types/node@25.3.3)(jsdom@29.1.1)(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
apps/web:
dependencies:
@@ -75,7 +75,7 @@ importers:
devDependencies:
'@tailwindcss/vite':
specifier: ^4.2.2
version: 4.2.2(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
version: 4.2.2(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
'@testing-library/jest-dom':
specifier: ^6.9.1
version: 6.9.1
@@ -93,16 +93,16 @@ importers:
version: 19.2.3(@types/react@19.2.14)
'@vitejs/plugin-react':
specifier: ^6.0.1
version: 6.0.1(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
version: 6.0.1(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
jsdom:
specifier: ^29.0.1
version: 29.0.1
specifier: ^29.1.1
version: 29.1.1
tailwindcss:
specifier: ^4.2.2
version: 4.2.2
vite:
specifier: ^8.0.5
version: 8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
specifier: ^8.0.16
version: 8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
packages/application:
dependencies:
@@ -117,19 +117,23 @@ packages:
'@adobe/css-tools@4.4.4':
resolution: {integrity: sha512-Elp+iwUx5rN5+Y8xLt5/GRoG20WGoDCQ/1Fb+1LiGtvwbDavuSk0jhD/eZdckHAuzcDzccnkv+rEjyWfRx18gg==}
'@asamuzakjp/css-color@5.0.1':
resolution: {integrity: sha512-2SZFvqMyvboVV1d15lMf7XiI3m7SDqXUuKaTymJYLN6dSGadqp+fVojqJlVoMlbZnlTmu3S0TLwLTJpvBMO1Aw==}
'@asamuzakjp/css-color@5.1.11':
resolution: {integrity: sha512-KVw6qIiCTUQhByfTd78h2yD1/00waTmm9uy/R7Ck/ctUyAPj+AEDLkQIdJW0T8+qGgj3j5bpNKK7Q3G+LedJWg==}
engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
'@asamuzakjp/dom-selector@7.0.4':
resolution: {integrity: sha512-jXR6x4AcT3eIrS2fSNAwJpwirOkGcd+E7F7CP3zjdTqz9B/2huHOL8YJZBgekKwLML+u7qB/6P1LXQuMScsx0w==}
'@asamuzakjp/dom-selector@7.1.1':
resolution: {integrity: sha512-67RZDnYRc8H/8MLDgQCDE//zoqVFwajkepHZgmXrbwybzXOEwOWGPYGmALYl9J2DOLfFPPs6kKCqmbzV895hTQ==}
engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
'@asamuzakjp/generational-cache@1.0.1':
resolution: {integrity: sha512-wajfB8KqzMCN2KGNFdLkReeHncd0AslUSrvHVvvYWuU8ghncRJoA50kT3zP9MVL0+9g4/67H+cdvBskj9THPzg==}
engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
'@asamuzakjp/nwsapi@2.3.9':
resolution: {integrity: sha512-n8GuYSrI9bF7FFZ/SjhwevlHc8xaVlb/7HmHelnc/PZXBD2ZR49NnN9sMMuDdEGPeeRQ5d0hqlSlEpgCX3Wl0Q==}
'@babel/code-frame@7.29.0':
resolution: {integrity: sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==}
'@babel/code-frame@7.29.7':
resolution: {integrity: sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==}
engines: {node: '>=6.9.0'}
'@babel/helper-string-parser@7.27.1':
@@ -144,6 +148,10 @@ packages:
resolution: {integrity: sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==}
engines: {node: '>=6.9.0'}
'@babel/helper-validator-identifier@7.29.7':
resolution: {integrity: sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==}
engines: {node: '>=6.9.0'}
'@babel/helper-validator-identifier@8.0.0-rc.3':
resolution: {integrity: sha512-8AWCJ2VJJyDFlGBep5GpaaQ9AAaE/FjAcrqI7jyssYhtL7WGV0DOKpJsQqM037xDbpRLHXsY8TwU7zDma7coOw==}
engines: {node: ^20.19.0 || >=22.12.0}
@@ -162,8 +170,8 @@ packages:
resolution: {integrity: sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA==}
engines: {node: '>=6.9.0'}
'@babel/runtime@7.29.2':
resolution: {integrity: sha512-JiDShH45zKHWyGe4ZNVRrCjBz8Nh9TMmZG1kh4QTK8hCBTWBi8Da+i7s1fJw7/lYpM4ccepSNfqzZ/QvABBi5g==}
'@babel/runtime@7.29.7':
resolution: {integrity: sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw==}
engines: {node: '>=6.9.0'}
'@babel/types@7.29.0':
@@ -247,15 +255,15 @@ packages:
resolution: {integrity: sha512-LMGQLS9EuADloEFkcTBR3BwV/CGHV7zyDxVRtVDTwdI2Ca4it0CCVTT9wCkxSgokjE5Ho41hEPgb8OEUwoXr6Q==}
engines: {node: '>=20.19.0'}
'@csstools/css-calc@3.1.1':
resolution: {integrity: sha512-HJ26Z/vmsZQqs/o3a6bgKslXGFAungXGbinULZO3eMsOyNJHeBBZfup5FiZInOghgoM4Hwnmw+OgbJCNg1wwUQ==}
'@csstools/css-calc@3.2.1':
resolution: {integrity: sha512-DtdHlgXh5ZkA43cwBcAm+huzgJiwx3ZTWVjBs94kwz2xKqSimDA3lBgCjphYgwgVUMWatSM0pDd8TILB1yrVVg==}
engines: {node: '>=20.19.0'}
peerDependencies:
'@csstools/css-parser-algorithms': ^4.0.0
'@csstools/css-tokenizer': ^4.0.0
'@csstools/css-color-parser@4.0.2':
resolution: {integrity: sha512-0GEfbBLmTFf0dJlpsNU7zwxRIH0/BGEMuXLTCvFYxuL1tNhqzTbtnFICyJLTNK4a+RechKP75e7w42ClXSnJQw==}
'@csstools/css-color-parser@4.1.8':
resolution: {integrity: sha512-3chWb7PRLijpJpPIKkDxdu6IBeO5MrFACND57On0j8OPpc0wZibcGc3xAHrSEbOx/KDRyMHoIxGn0w1PhXMYHw==}
engines: {node: '>=20.19.0'}
peerDependencies:
'@csstools/css-parser-algorithms': ^4.0.0
@@ -267,8 +275,8 @@ packages:
peerDependencies:
'@csstools/css-tokenizer': ^4.0.0
'@csstools/css-syntax-patches-for-csstree@1.1.1':
resolution: {integrity: sha512-BvqN0AMWNAnLk9G8jnUT77D+mUbY/H2b3uDTvg2isJkHaOufUE2R3AOwxWo7VBQKT1lOdwdvorddo2B/lk64+w==}
'@csstools/css-syntax-patches-for-csstree@1.1.5':
resolution: {integrity: sha512-oNjBvzLq2GPZtJphCjLqXow/cHySHSgtxvKZb7OqSZ/xHgw6NWNhfad+6AB9cLeVm6eA9d/qMll3JdEHjy6M+A==}
peerDependencies:
css-tree: ^3.2.1
peerDependenciesMeta:
@@ -279,15 +287,24 @@ packages:
resolution: {integrity: sha512-QxULHAm7cNu72w97JUNCBFODFaXpbDg+dP8b/oWFAZ2MTRppA3U00Y2L1HqaS4J6yBqxwa/Y3nMBaxVKbB/NsA==}
engines: {node: '>=20.19.0'}
'@emnapi/core@1.10.0':
resolution: {integrity: sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==}
'@emnapi/core@1.8.1':
resolution: {integrity: sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg==}
'@emnapi/runtime@1.10.0':
resolution: {integrity: sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==}
'@emnapi/runtime@1.8.1':
resolution: {integrity: sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg==}
'@emnapi/wasi-threads@1.1.0':
resolution: {integrity: sha512-WI0DdZ8xFSbgMjR1sFsKABJ/C5OnRrjT06JXbZKexJGrDuPTzZdDYfFlsgcCXCyf+suG5QU2e/y1Wo2V/OapLQ==}
'@emnapi/wasi-threads@1.2.1':
resolution: {integrity: sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==}
'@exodus/bytes@1.15.0':
resolution: {integrity: sha512-UY0nlA+feH81UGSHv92sLEPLCeZFjXOuHhrIo0HQydScuQc8s0A7kL/UdgwgDq8g8ilksmuoF35YVTNphV2aBQ==}
engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
@@ -331,8 +348,8 @@ packages:
'@napi-rs/wasm-runtime@1.1.1':
resolution: {integrity: sha512-p64ah1M1ld8xjWv3qbvFwHiFVWrq1yFvV4f7w+mzaqiR4IlSgkqhcRdHwsGgomwzBH51sRY4NEowLxnaBjcW/A==}
'@napi-rs/wasm-runtime@1.1.2':
resolution: {integrity: sha512-sNXv5oLJ7ob93xkZ1XnxisYhGYXfaG9f65/ZgYuAu3qt7b3NadcOEhLvx28hv31PgX8SZJRYrAIPQilQmFpLVw==}
'@napi-rs/wasm-runtime@1.1.5':
resolution: {integrity: sha512-AWPoBRJ9tsnVhor4sjO7rkni+7p+2IAEFj6cx06UgP10jkQHqay/36uRV/bFkgrh18D9vb4cr8Q0Pthskgzy+Q==}
peerDependencies:
'@emnapi/core': ^1.7.1
'@emnapi/runtime': ^1.7.1
@@ -349,8 +366,8 @@ packages:
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
engines: {node: '>= 8'}
'@oxc-project/types@0.122.0':
resolution: {integrity: sha512-oLAl5kBpV4w69UtFZ9xqcmTi+GENWOcPF7FCrczTiBbmC0ibXxCwyvZGbO39rCVEuLGAZM84DH0pUIyyv/YJzA==}
'@oxc-project/types@0.133.0':
resolution: {integrity: sha512-KzkdCd6Uxqnf6l3HOw1xfatAlUURA0g14cvBYFyJ5SaNOQbOUvBr9PKArcPcrNIeRsBdgcUzOGrhKveVpvOIGA==}
'@oxc-resolver/binding-android-arm-eabi@11.19.1':
resolution: {integrity: sha512-aUs47y+xyXHUKlbhqHUjBABjvycq6YSD7bpxSW7vplUmdzAlJ93yXY6ZR0c1o1x5A/QKbENCvs3+NlY8IpIVzg==}
@@ -612,107 +629,107 @@ packages:
cpu: [x64]
os: [win32]
'@rolldown/binding-android-arm64@1.0.0-rc.12':
resolution: {integrity: sha512-pv1y2Fv0JybcykuiiD3qBOBdz6RteYojRFY1d+b95WVuzx211CRh+ytI/+9iVyWQ6koTh5dawe4S/yRfOFjgaA==}
'@rolldown/binding-android-arm64@1.0.3':
resolution: {integrity: sha512-454rs7jHngixp/NMxd5srYD57OnzSlZ/eFTETjORQHLwJG1lRtmNOJcBerZlfu4GjKqeq8aCCIQrMdHyhI51Hw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [android]
'@rolldown/binding-darwin-arm64@1.0.0-rc.12':
resolution: {integrity: sha512-cFYr6zTG/3PXXF3pUO+umXxt1wkRK/0AYT8lDwuqvRC+LuKYWSAQAQZjCWDQpAH172ZV6ieYrNnFzVVcnSflAg==}
'@rolldown/binding-darwin-arm64@1.0.3':
resolution: {integrity: sha512-PcAhP+ynjURNyy8SKGl5DQP94aGuB/7JrXJb/t7P+hanXvQVMWzUvRRhBAcg/lNRadBhoUPqSoP4xw5tR/KBEA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [darwin]
'@rolldown/binding-darwin-x64@1.0.0-rc.12':
resolution: {integrity: sha512-ZCsYknnHzeXYps0lGBz8JrF37GpE9bFVefrlmDrAQhOEi4IOIlcoU1+FwHEtyXGx2VkYAvhu7dyBf75EJQffBw==}
'@rolldown/binding-darwin-x64@1.0.3':
resolution: {integrity: sha512-9YpfeUvSE2RS7wysJ81uOZkXJz7f7Q55H2Gvp3VEw/EsahqDtrphrZ0EwDLK5vvKOzaCrBsjF8JmnMLcUt78Gg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [darwin]
'@rolldown/binding-freebsd-x64@1.0.0-rc.12':
resolution: {integrity: sha512-dMLeprcVsyJsKolRXyoTH3NL6qtsT0Y2xeuEA8WQJquWFXkEC4bcu1rLZZSnZRMtAqwtrF/Ib9Ddtpa/Gkge9Q==}
'@rolldown/binding-freebsd-x64@1.0.3':
resolution: {integrity: sha512-yB1IlAsSNHncV6SCTL27/MVGR5htvQsoGxIv5KMGXALp+Ll1wYsn+x98M9MW7qa+NdSbvrrY7ANI4wLJ0n1e6g==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [freebsd]
'@rolldown/binding-linux-arm-gnueabihf@1.0.0-rc.12':
resolution: {integrity: sha512-YqWjAgGC/9M1lz3GR1r1rP79nMgo3mQiiA+Hfo+pvKFK1fAJ1bCi0ZQVh8noOqNacuY1qIcfyVfP6HoyBRZ85Q==}
'@rolldown/binding-linux-arm-gnueabihf@1.0.3':
resolution: {integrity: sha512-Yi30IVAAfLUCy2MseFjbB1jAMDl1VMCAas5StnYp8da9+CKvMd2H2cbEjWcw5NPaPqzvYkVIaF1nNUG+b7u/sw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [linux]
'@rolldown/binding-linux-arm64-gnu@1.0.0-rc.12':
resolution: {integrity: sha512-/I5AS4cIroLpslsmzXfwbe5OmWvSsrFuEw3mwvbQ1kDxJ822hFHIx+vsN/TAzNVyepI/j/GSzrtCIwQPeKCLIg==}
'@rolldown/binding-linux-arm64-gnu@1.0.3':
resolution: {integrity: sha512-jsO7R8To+AdlYgUmN5sHSCZbfhtMBkO0WUx8iORQnPcMMdgr7qM2DQmMwgabs3GhNztdmoKkMKQFHD6DTMCIQw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@rolldown/binding-linux-arm64-musl@1.0.0-rc.12':
resolution: {integrity: sha512-V6/wZztnBqlx5hJQqNWwFdxIKN0m38p8Jas+VoSfgH54HSj9tKTt1dZvG6JRHcjh6D7TvrJPWFGaY9UBVOaWPw==}
'@rolldown/binding-linux-arm64-musl@1.0.3':
resolution: {integrity: sha512-VWkUHwWriDciit80wleYwKILoR/KMvxh/IdwS/paX+ZgpuRpCrKLUdadJbc0NpBEiyhpYawsJ73j9aCvOH+f7Q==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
libc: [musl]
'@rolldown/binding-linux-ppc64-gnu@1.0.0-rc.12':
resolution: {integrity: sha512-AP3E9BpcUYliZCxa3w5Kwj9OtEVDYK6sVoUzy4vTOJsjPOgdaJZKFmN4oOlX0Wp0RPV2ETfmIra9x1xuayFB7g==}
'@rolldown/binding-linux-ppc64-gnu@1.0.3':
resolution: {integrity: sha512-5f1laC0SlIR0yDbFCd8acUhvJIag6N3zC5P7oUPN6wX0aOma+uKJ0wBDH5aq7I1PVI2ttTlhJwzwRIBnLiSGEg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [ppc64]
os: [linux]
libc: [glibc]
'@rolldown/binding-linux-s390x-gnu@1.0.0-rc.12':
resolution: {integrity: sha512-nWwpvUSPkoFmZo0kQazZYOrT7J5DGOJ/+QHHzjvNlooDZED8oH82Yg67HvehPPLAg5fUff7TfWFHQS8IV1n3og==}
'@rolldown/binding-linux-s390x-gnu@1.0.3':
resolution: {integrity: sha512-Iq4ko0r4XsgbrF/LunNgHtAGLRRVE2kXonAXQ/MV0mC6jQpMOhW1SvtZja2EhC/kd05++bP78dsqBeIQyYJ6Yg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [s390x]
os: [linux]
libc: [glibc]
'@rolldown/binding-linux-x64-gnu@1.0.0-rc.12':
resolution: {integrity: sha512-RNrafz5bcwRy+O9e6P8Z/OCAJW/A+qtBczIqVYwTs14pf4iV1/+eKEjdOUta93q2TsT/FI0XYDP3TCky38LMAg==}
'@rolldown/binding-linux-x64-gnu@1.0.3':
resolution: {integrity: sha512-B8m6tD5+/N5FeNQFbKlLA/2yVq9ycQP1SeedyEYYKWBNR3ZQbkvIUcNnDNM03lO1l5F2roiiFJGgvoLLyZXtSg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
libc: [glibc]
'@rolldown/binding-linux-x64-musl@1.0.0-rc.12':
resolution: {integrity: sha512-Jpw/0iwoKWx3LJ2rc1yjFrj+T7iHZn2JDg1Yny1ma0luviFS4mhAIcd1LFNxK3EYu3DHWCps0ydXQ5i/rrJ2ig==}
'@rolldown/binding-linux-x64-musl@1.0.3':
resolution: {integrity: sha512-pSdpdUJHkuCxun9LE7jvgUB9qsRgaiyNNCX7m/AvHTcq67AiT/Yhoxvw5zPfhrM8k/BfP8ce/hMOpthKDpEUow==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
libc: [musl]
'@rolldown/binding-openharmony-arm64@1.0.0-rc.12':
resolution: {integrity: sha512-vRugONE4yMfVn0+7lUKdKvN4D5YusEiPilaoO2sgUWpCvrncvWgPMzK00ZFFJuiPgLwgFNP5eSiUlv2tfc+lpA==}
'@rolldown/binding-openharmony-arm64@1.0.3':
resolution: {integrity: sha512-OXXS3RKJgX2uLwM+gYyuH5omcH8fL1LJs96pZGgtetVCahON57+d4SJHzTgZiOjxgGkSnpXpOsWuPDGAKAigEg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [openharmony]
'@rolldown/binding-wasm32-wasi@1.0.0-rc.12':
resolution: {integrity: sha512-ykGiLr/6kkiHc0XnBfmFJuCjr5ZYKKofkx+chJWDjitX+KsJuAmrzWhwyOMSHzPhzOHOy7u9HlFoa5MoAOJ/Zg==}
engines: {node: '>=14.0.0'}
'@rolldown/binding-wasm32-wasi@1.0.3':
resolution: {integrity: sha512-JTtb8BWFynicNSoPrehsCzBtOKjZ6jhMiPFEmOiuXg1Fl8dn2KHQob+GuPSGR0dryQa1PQJbzjF3dqO/whhjLg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [wasm32]
'@rolldown/binding-win32-arm64-msvc@1.0.0-rc.12':
resolution: {integrity: sha512-5eOND4duWkwx1AzCxadcOrNeighiLwMInEADT0YM7xeEOOFcovWZCq8dadXgcRHSf3Ulh1kFo/qvzoFiCLOL1Q==}
'@rolldown/binding-win32-arm64-msvc@1.0.3':
resolution: {integrity: sha512-gEdFFEN70A/jxb2svrWsN3aDL7OUtmvlOy+6fa2jxG8K0wQ1ZbdeLGnidov6Yu5/733dI5ySfzFlQ/cb0bSz1g==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [win32]
'@rolldown/binding-win32-x64-msvc@1.0.0-rc.12':
resolution: {integrity: sha512-PyqoipaswDLAZtot351MLhrlrh6lcZPo2LSYE+VDxbVk24LVKAGOuE4hb8xZQmrPAuEtTZW8E6D2zc5EUZX4Lw==}
'@rolldown/binding-win32-x64-msvc@1.0.3':
resolution: {integrity: sha512-eXB7CHuaQdqmJcc3koCNtNPmT/bj2gc999kUFgBxG8Ac0NdgXc4rkCHhqrgrhN3zddvvvrgzj1e90SuSfmyIXA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [win32]
'@rolldown/pluginutils@1.0.0-rc.12':
resolution: {integrity: sha512-HHMwmarRKvoFsJorqYlFeFRzXZqCt2ETQlEDOb9aqssrnVBB1/+xgTGtuTrIk5vzLNX1MjMtTf7W9z3tsSbrxw==}
'@rolldown/pluginutils@1.0.0-rc.7':
resolution: {integrity: sha512-qujRfC8sFVInYSPPMLQByRh7zhwkGFS4+tyMQ83srV1qrxL4g8E2tyxVVyxd0+8QeBM1mIk9KbWxkegRr76XzA==}
'@rolldown/pluginutils@1.0.1':
resolution: {integrity: sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==}
'@standard-schema/spec@1.1.0':
resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==}
@@ -842,6 +859,9 @@ packages:
'@tybys/wasm-util@0.10.1':
resolution: {integrity: sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==}
'@tybys/wasm-util@0.10.2':
resolution: {integrity: sha512-RoBvJ2X0wuKlWFIjrwffGw1IqZHKQqzIchKaadZZfnNpsAYp2mM0h36JtPCjNDAHGgYez/15uMBpfGwchhiMgg==}
'@types/aria-query@5.0.4':
resolution: {integrity: sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==}
@@ -1083,9 +1103,9 @@ packages:
resolution: {integrity: sha512-/ce7+jQ1PQ6rVXwe+jKEg5hW5ciicHwIQUagZkp6IufBoY3YDgdTTY1azVs0qoRgVmvsNB+rbjLJxDAeHHtwsQ==}
engines: {node: '>=10.13.0'}
entities@6.0.1:
resolution: {integrity: sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==}
engines: {node: '>=0.12'}
entities@8.0.0:
resolution: {integrity: sha512-zwfzJecQ/Uej6tusMqwAqU/6KL2XaB2VZ2Jg54Je6ahNBGNH6Ek6g3jjNCF0fG9EWQKGZNddNjU5F1ZQn/sBnA==}
engines: {node: '>=20.19.0'}
es-define-property@1.0.1:
resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==}
@@ -1300,8 +1320,8 @@ packages:
resolution: {integrity: sha512-d2VNT/2Hv4dxT2/59He8Lyda4DYOxPRyRG9zBaOpTZAqJCVf2xLrBlZkT8Va6Lo9u3X2qz8Bpq4HrDi4JsrQhA==}
hasBin: true
jsdom@29.0.1:
resolution: {integrity: sha512-z6JOK5gRO7aMybVq/y/MlIpKh8JIi68FBKMUtKkK2KH/wMSRlCxQ682d08LB9fYXplyY/UXG8P4XXTScmdjApg==}
jsdom@29.1.1:
resolution: {integrity: sha512-ECi4Fi2f7BdJtUKTflYRTiaMxIB0O6zfR1fX0GXpUrf6flp8QIYn1UT20YQqdSOfk2dfkCwS8LAFoJDEppNK5Q==}
engines: {node: ^20.19.0 || ^22.13.0 || >=24.0.0}
peerDependencies:
canvas: ^3.0.0
@@ -1455,8 +1475,8 @@ packages:
resolution: {integrity: sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==}
engines: {node: '>= 12.0.0'}
lru-cache@11.2.7:
resolution: {integrity: sha512-aY/R+aEsRelme17KGQa/1ZSIpLpNYYrhcrepKTZgE+W3WM16YMCaPwOHLHsmopZHELU0Ojin1lPVxKR0MihncA==}
lru-cache@11.5.1:
resolution: {integrity: sha512-RPimw/7aMdv2oqRrxKwvZXcPfwBrn/JZ2xYcY9Hus/6LaS3VOAKVWKWgNLCFSiOm1ESXinjsDlidVU7JlnCN2A==}
engines: {node: 20 || >=22}
lucide-react@0.577.0:
@@ -1510,8 +1530,8 @@ packages:
minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
nanoid@3.3.11:
resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==}
nanoid@3.3.13:
resolution: {integrity: sha512-sPdqC6ByMVVGvF1ynvvMo0/o+oD1VX7DaHhijt1bFgjvBkHBib4t49GoNDhf2NDta4oeUNlaGbSt5K7qjZ955Q==}
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
@@ -1554,8 +1574,8 @@ packages:
oxlint-tsgolint:
optional: true
parse5@8.0.0:
resolution: {integrity: sha512-9m4m5GSgXjL4AjumKzq1Fgfp3Z8rsvjRNbnkVwfu2ImRqE5D0LnY2QfDen18FSY9C573YU5XxSapdHZTZ2WolA==}
parse5@8.0.1:
resolution: {integrity: sha512-z1e/HMG90obSGeidlli3hj7cbocou0/wa5HacvI3ASx34PecNjNQeaHNo5WIZpWofN9kgkqV1q5YvXe3F0FoPw==}
path-key@3.1.1:
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
@@ -1574,8 +1594,8 @@ packages:
resolution: {integrity: sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==}
engines: {node: '>=12'}
postcss@8.5.8:
resolution: {integrity: sha512-OW/rX8O/jXnm82Ey1k44pObPtdblfiuWnrd8X7GJ7emImCOstunGbXUpp7HdBrFQX6rJzn3sPT397Wp5aCwCHg==}
postcss@8.5.15:
resolution: {integrity: sha512-FfR8sjd4em2T6fb3I2MwAJU7HWVMr9zba+enmQeeWFfCbm+UOC/0X4DS8XtpUTMwWMGbjKYP7xjfNekzyGmB3A==}
engines: {node: ^10 || ^12 || >=14}
pretty-format@27.5.1:
@@ -1667,8 +1687,8 @@ packages:
resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==}
engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
rolldown@1.0.0-rc.12:
resolution: {integrity: sha512-yP4USLIMYrwpPHEFB5JGH1uxhcslv6/hL0OyvTuY+3qlOSJvZ7ntYnoWpehBxufkgN0cvXxppuTu5hHa/zPh+A==}
rolldown@1.0.3:
resolution: {integrity: sha512-i00lAJ2ks1BYr7rjNjKC7BcqAS7nVfiT3QX1SI5aY+AFHblCmaUf9OE9dbdzDvW6dJxbi2ZCZiy9v3CcwOiX3g==}
engines: {node: ^20.19.0 || >=22.12.0}
hasBin: true
@@ -1782,6 +1802,10 @@ packages:
resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==}
engines: {node: '>=12.0.0'}
tinyglobby@0.2.17:
resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==}
engines: {node: '>=12.0.0'}
tinyrainbow@3.1.0:
resolution: {integrity: sha512-Bf+ILmBgretUrdJxzXM0SgXLZ3XfiaUuOj/IKQHuTXip+05Xn+uyEYdVg0kYDipTBcLrCVyUzAPz7QmArb0mmw==}
engines: {node: '>=14.0.0'}
@@ -1823,21 +1847,21 @@ packages:
undici-types@7.18.2:
resolution: {integrity: sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==}
undici@7.24.2:
resolution: {integrity: sha512-P9J1HWYV/ajFr8uCqk5QixwiRKmB1wOamgS0e+o2Z4A44Ej2+thFVRLG/eA7qprx88XXhnV5Bl8LHXTURpzB3Q==}
undici@7.24.8:
resolution: {integrity: sha512-6KQ/+QxK49Z/p3HO6E5ZCZWNnCasyZLa5ExaVYyvPxUwKtbCPMKELJOqh7EqOle0t9cH/7d2TaaTRRa6Nhs4YQ==}
engines: {node: '>=20.18.1'}
universalify@2.0.1:
resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==}
engines: {node: '>= 10.0.0'}
vite@8.0.5:
resolution: {integrity: sha512-nmu43Qvq9UopTRfMx2jOYW5l16pb3iDC1JH6yMuPkpVbzK0k+L7dfsEDH4jRgYFmsg0sTAqkojoZgzLMlwHsCQ==}
vite@8.0.16:
resolution: {integrity: sha512-h9bXPmJichP5fLmVQo3PyaGSDE2n3aPuomeAlVRm0JLmt4rY6zmPKd59HYI4LNW8oTK7tlTsuC7l/m7awx9Jcw==}
engines: {node: ^20.19.0 || >=22.12.0}
hasBin: true
peerDependencies:
'@types/node': ^20.19.0 || >=22.12.0
'@vitejs/devtools': ^0.1.0
'@vitejs/devtools': ^0.1.18
esbuild: ^0.27.0 || ^0.28.0
jiti: '>=1.21.0'
less: ^4.0.0
@@ -1969,27 +1993,29 @@ snapshots:
'@adobe/css-tools@4.4.4': {}
'@asamuzakjp/css-color@5.0.1':
'@asamuzakjp/css-color@5.1.11':
dependencies:
'@csstools/css-calc': 3.1.1(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)
'@csstools/css-color-parser': 4.0.2(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)
'@asamuzakjp/generational-cache': 1.0.1
'@csstools/css-calc': 3.2.1(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)
'@csstools/css-color-parser': 4.1.8(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)
'@csstools/css-parser-algorithms': 4.0.0(@csstools/css-tokenizer@4.0.0)
'@csstools/css-tokenizer': 4.0.0
lru-cache: 11.2.7
'@asamuzakjp/dom-selector@7.0.4':
'@asamuzakjp/dom-selector@7.1.1':
dependencies:
'@asamuzakjp/generational-cache': 1.0.1
'@asamuzakjp/nwsapi': 2.3.9
bidi-js: 1.0.3
css-tree: 3.2.1
is-potential-custom-element-name: 1.0.1
lru-cache: 11.2.7
'@asamuzakjp/generational-cache@1.0.1': {}
'@asamuzakjp/nwsapi@2.3.9': {}
'@babel/code-frame@7.29.0':
'@babel/code-frame@7.29.7':
dependencies:
'@babel/helper-validator-identifier': 7.28.5
'@babel/helper-validator-identifier': 7.29.7
js-tokens: 4.0.0
picocolors: 1.1.1
@@ -1999,6 +2025,8 @@ snapshots:
'@babel/helper-validator-identifier@7.28.5': {}
'@babel/helper-validator-identifier@7.29.7': {}
'@babel/helper-validator-identifier@8.0.0-rc.3': {}
'@babel/parser@7.29.0':
@@ -2011,7 +2039,7 @@ snapshots:
'@babel/runtime@7.28.6': {}
'@babel/runtime@7.29.2': {}
'@babel/runtime@7.29.7': {}
'@babel/types@7.29.0':
dependencies:
@@ -2069,15 +2097,15 @@ snapshots:
'@csstools/color-helpers@6.0.2': {}
'@csstools/css-calc@3.1.1(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)':
'@csstools/css-calc@3.2.1(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)':
dependencies:
'@csstools/css-parser-algorithms': 4.0.0(@csstools/css-tokenizer@4.0.0)
'@csstools/css-tokenizer': 4.0.0
'@csstools/css-color-parser@4.0.2(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)':
'@csstools/css-color-parser@4.1.8(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)':
dependencies:
'@csstools/color-helpers': 6.0.2
'@csstools/css-calc': 3.1.1(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)
'@csstools/css-calc': 3.2.1(@csstools/css-parser-algorithms@4.0.0(@csstools/css-tokenizer@4.0.0))(@csstools/css-tokenizer@4.0.0)
'@csstools/css-parser-algorithms': 4.0.0(@csstools/css-tokenizer@4.0.0)
'@csstools/css-tokenizer': 4.0.0
@@ -2085,18 +2113,29 @@ snapshots:
dependencies:
'@csstools/css-tokenizer': 4.0.0
'@csstools/css-syntax-patches-for-csstree@1.1.1(css-tree@3.2.1)':
'@csstools/css-syntax-patches-for-csstree@1.1.5(css-tree@3.2.1)':
optionalDependencies:
css-tree: 3.2.1
'@csstools/css-tokenizer@4.0.0': {}
'@emnapi/core@1.10.0':
dependencies:
'@emnapi/wasi-threads': 1.2.1
tslib: 2.8.1
optional: true
'@emnapi/core@1.8.1':
dependencies:
'@emnapi/wasi-threads': 1.1.0
tslib: 2.8.1
optional: true
'@emnapi/runtime@1.10.0':
dependencies:
tslib: 2.8.1
optional: true
'@emnapi/runtime@1.8.1':
dependencies:
tslib: 2.8.1
@@ -2107,6 +2146,11 @@ snapshots:
tslib: 2.8.1
optional: true
'@emnapi/wasi-threads@1.2.1':
dependencies:
tslib: 2.8.1
optional: true
'@exodus/bytes@1.15.0': {}
'@jridgewell/gen-mapping@0.3.13':
@@ -2170,11 +2214,11 @@ snapshots:
'@tybys/wasm-util': 0.10.1
optional: true
'@napi-rs/wasm-runtime@1.1.2(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)':
'@napi-rs/wasm-runtime@1.1.5(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)':
dependencies:
'@emnapi/core': 1.8.1
'@emnapi/runtime': 1.8.1
'@tybys/wasm-util': 0.10.1
'@emnapi/core': 1.10.0
'@emnapi/runtime': 1.10.0
'@tybys/wasm-util': 0.10.2
optional: true
'@nodelib/fs.scandir@2.1.5':
@@ -2189,7 +2233,7 @@ snapshots:
'@nodelib/fs.scandir': 2.1.5
fastq: 1.20.1
'@oxc-project/types@0.122.0': {}
'@oxc-project/types@0.133.0': {}
'@oxc-resolver/binding-android-arm-eabi@11.19.1':
optional: true
@@ -2328,60 +2372,59 @@ snapshots:
'@oxlint/binding-win32-x64-msvc@1.56.0':
optional: true
'@rolldown/binding-android-arm64@1.0.0-rc.12':
'@rolldown/binding-android-arm64@1.0.3':
optional: true
'@rolldown/binding-darwin-arm64@1.0.0-rc.12':
'@rolldown/binding-darwin-arm64@1.0.3':
optional: true
'@rolldown/binding-darwin-x64@1.0.0-rc.12':
'@rolldown/binding-darwin-x64@1.0.3':
optional: true
'@rolldown/binding-freebsd-x64@1.0.0-rc.12':
'@rolldown/binding-freebsd-x64@1.0.3':
optional: true
'@rolldown/binding-linux-arm-gnueabihf@1.0.0-rc.12':
'@rolldown/binding-linux-arm-gnueabihf@1.0.3':
optional: true
'@rolldown/binding-linux-arm64-gnu@1.0.0-rc.12':
'@rolldown/binding-linux-arm64-gnu@1.0.3':
optional: true
'@rolldown/binding-linux-arm64-musl@1.0.0-rc.12':
'@rolldown/binding-linux-arm64-musl@1.0.3':
optional: true
'@rolldown/binding-linux-ppc64-gnu@1.0.0-rc.12':
'@rolldown/binding-linux-ppc64-gnu@1.0.3':
optional: true
'@rolldown/binding-linux-s390x-gnu@1.0.0-rc.12':
'@rolldown/binding-linux-s390x-gnu@1.0.3':
optional: true
'@rolldown/binding-linux-x64-gnu@1.0.0-rc.12':
'@rolldown/binding-linux-x64-gnu@1.0.3':
optional: true
'@rolldown/binding-linux-x64-musl@1.0.0-rc.12':
'@rolldown/binding-linux-x64-musl@1.0.3':
optional: true
'@rolldown/binding-openharmony-arm64@1.0.0-rc.12':
'@rolldown/binding-openharmony-arm64@1.0.3':
optional: true
'@rolldown/binding-wasm32-wasi@1.0.0-rc.12(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)':
'@rolldown/binding-wasm32-wasi@1.0.3':
dependencies:
'@napi-rs/wasm-runtime': 1.1.2(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)
transitivePeerDependencies:
- '@emnapi/core'
- '@emnapi/runtime'
'@emnapi/core': 1.10.0
'@emnapi/runtime': 1.10.0
'@napi-rs/wasm-runtime': 1.1.5(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)
optional: true
'@rolldown/binding-win32-arm64-msvc@1.0.0-rc.12':
'@rolldown/binding-win32-arm64-msvc@1.0.3':
optional: true
'@rolldown/binding-win32-x64-msvc@1.0.0-rc.12':
'@rolldown/binding-win32-x64-msvc@1.0.3':
optional: true
'@rolldown/pluginutils@1.0.0-rc.12': {}
'@rolldown/pluginutils@1.0.0-rc.7': {}
'@rolldown/pluginutils@1.0.1': {}
'@standard-schema/spec@1.1.0': {}
'@tailwindcss/node@4.2.2':
@@ -2445,17 +2488,17 @@ snapshots:
'@tailwindcss/oxide-win32-arm64-msvc': 4.2.2
'@tailwindcss/oxide-win32-x64-msvc': 4.2.2
'@tailwindcss/vite@4.2.2(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))':
'@tailwindcss/vite@4.2.2(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))':
dependencies:
'@tailwindcss/node': 4.2.2
'@tailwindcss/oxide': 4.2.2
tailwindcss: 4.2.2
vite: 8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
vite: 8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
'@testing-library/dom@10.4.1':
dependencies:
'@babel/code-frame': 7.29.0
'@babel/runtime': 7.29.2
'@babel/code-frame': 7.29.7
'@babel/runtime': 7.29.7
'@types/aria-query': 5.0.4
aria-query: 5.3.0
dom-accessibility-api: 0.5.16
@@ -2491,6 +2534,11 @@ snapshots:
tslib: 2.8.1
optional: true
'@tybys/wasm-util@0.10.2':
dependencies:
tslib: 2.8.1
optional: true
'@types/aria-query@5.0.4': {}
'@types/chai@5.2.3':
@@ -2516,12 +2564,12 @@ snapshots:
'@types/sarif@2.1.7': {}
'@vitejs/plugin-react@6.0.1(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))':
'@vitejs/plugin-react@6.0.1(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))':
dependencies:
'@rolldown/pluginutils': 1.0.0-rc.7
vite: 8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
vite: 8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
'@vitest/coverage-v8@4.1.0(vitest@4.1.0(@types/node@25.3.3)(jsdom@29.0.1)(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)))':
'@vitest/coverage-v8@4.1.0(vitest@4.1.0(@types/node@25.3.3)(jsdom@29.1.1)(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)))':
dependencies:
'@bcoe/v8-coverage': 1.0.2
'@vitest/utils': 4.1.0
@@ -2533,7 +2581,7 @@ snapshots:
obug: 2.1.1
std-env: 4.0.0
tinyrainbow: 3.1.0
vitest: 4.1.0(@types/node@25.3.3)(jsdom@29.0.1)(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
vitest: 4.1.0(@types/node@25.3.3)(jsdom@29.1.1)(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
'@vitest/expect@4.1.0':
dependencies:
@@ -2544,13 +2592,13 @@ snapshots:
chai: 6.2.2
tinyrainbow: 3.1.0
'@vitest/mocker@4.1.0(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))':
'@vitest/mocker@4.1.0(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))':
dependencies:
'@vitest/spy': 4.1.0
estree-walker: 3.0.3
magic-string: 0.30.21
optionalDependencies:
vite: 8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
vite: 8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
'@vitest/pretty-format@4.1.0':
dependencies:
@@ -2729,7 +2777,7 @@ snapshots:
graceful-fs: 4.2.11
tapable: 2.3.0
entities@6.0.1: {}
entities@8.0.0: {}
es-define-property@1.0.1: {}
@@ -2938,24 +2986,24 @@ snapshots:
gitignore-to-glob: 0.3.0
jscpd-sarif-reporter: 4.0.6
jsdom@29.0.1:
jsdom@29.1.1:
dependencies:
'@asamuzakjp/css-color': 5.0.1
'@asamuzakjp/dom-selector': 7.0.4
'@asamuzakjp/css-color': 5.1.11
'@asamuzakjp/dom-selector': 7.1.1
'@bramus/specificity': 2.4.2
'@csstools/css-syntax-patches-for-csstree': 1.1.1(css-tree@3.2.1)
'@csstools/css-syntax-patches-for-csstree': 1.1.5(css-tree@3.2.1)
'@exodus/bytes': 1.15.0
css-tree: 3.2.1
data-urls: 7.0.0
decimal.js: 10.6.0
html-encoding-sniffer: 6.0.0
is-potential-custom-element-name: 1.0.1
lru-cache: 11.2.7
parse5: 8.0.0
lru-cache: 11.5.1
parse5: 8.0.1
saxes: 6.0.0
symbol-tree: 3.2.4
tough-cookie: 6.0.1
undici: 7.24.2
undici: 7.24.8
w3c-xmlserializer: 5.0.0
webidl-conversions: 8.0.1
whatwg-mimetype: 5.0.0
@@ -3095,7 +3143,7 @@ snapshots:
lightningcss-win32-arm64-msvc: 1.32.0
lightningcss-win32-x64-msvc: 1.32.0
lru-cache@11.2.7: {}
lru-cache@11.5.1: {}
lucide-react@0.577.0(react@19.2.4):
dependencies:
@@ -3140,7 +3188,7 @@ snapshots:
minimist@1.2.8: {}
nanoid@3.3.11: {}
nanoid@3.3.13: {}
node-sarif-builder@3.4.0:
dependencies:
@@ -3218,9 +3266,9 @@ snapshots:
'@oxlint/binding-win32-x64-msvc': 1.56.0
oxlint-tsgolint: 0.17.1
parse5@8.0.0:
parse5@8.0.1:
dependencies:
entities: 6.0.1
entities: 8.0.0
path-key@3.1.1: {}
@@ -3232,9 +3280,9 @@ snapshots:
picomatch@4.0.4: {}
postcss@8.5.8:
postcss@8.5.15:
dependencies:
nanoid: 3.3.11
nanoid: 3.3.13
picocolors: 1.1.1
source-map-js: 1.2.1
@@ -3352,29 +3400,26 @@ snapshots:
reusify@1.1.0: {}
rolldown@1.0.0-rc.12(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1):
rolldown@1.0.3:
dependencies:
'@oxc-project/types': 0.122.0
'@rolldown/pluginutils': 1.0.0-rc.12
'@oxc-project/types': 0.133.0
'@rolldown/pluginutils': 1.0.1
optionalDependencies:
'@rolldown/binding-android-arm64': 1.0.0-rc.12
'@rolldown/binding-darwin-arm64': 1.0.0-rc.12
'@rolldown/binding-darwin-x64': 1.0.0-rc.12
'@rolldown/binding-freebsd-x64': 1.0.0-rc.12
'@rolldown/binding-linux-arm-gnueabihf': 1.0.0-rc.12
'@rolldown/binding-linux-arm64-gnu': 1.0.0-rc.12
'@rolldown/binding-linux-arm64-musl': 1.0.0-rc.12
'@rolldown/binding-linux-ppc64-gnu': 1.0.0-rc.12
'@rolldown/binding-linux-s390x-gnu': 1.0.0-rc.12
'@rolldown/binding-linux-x64-gnu': 1.0.0-rc.12
'@rolldown/binding-linux-x64-musl': 1.0.0-rc.12
'@rolldown/binding-openharmony-arm64': 1.0.0-rc.12
'@rolldown/binding-wasm32-wasi': 1.0.0-rc.12(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)
'@rolldown/binding-win32-arm64-msvc': 1.0.0-rc.12
'@rolldown/binding-win32-x64-msvc': 1.0.0-rc.12
transitivePeerDependencies:
- '@emnapi/core'
- '@emnapi/runtime'
'@rolldown/binding-android-arm64': 1.0.3
'@rolldown/binding-darwin-arm64': 1.0.3
'@rolldown/binding-darwin-x64': 1.0.3
'@rolldown/binding-freebsd-x64': 1.0.3
'@rolldown/binding-linux-arm-gnueabihf': 1.0.3
'@rolldown/binding-linux-arm64-gnu': 1.0.3
'@rolldown/binding-linux-arm64-musl': 1.0.3
'@rolldown/binding-linux-ppc64-gnu': 1.0.3
'@rolldown/binding-linux-s390x-gnu': 1.0.3
'@rolldown/binding-linux-x64-gnu': 1.0.3
'@rolldown/binding-linux-x64-musl': 1.0.3
'@rolldown/binding-openharmony-arm64': 1.0.3
'@rolldown/binding-wasm32-wasi': 1.0.3
'@rolldown/binding-win32-arm64-msvc': 1.0.3
'@rolldown/binding-win32-x64-msvc': 1.0.3
run-parallel@1.2.0:
dependencies:
@@ -3457,6 +3502,11 @@ snapshots:
fdir: 6.5.0(picomatch@4.0.4)
picomatch: 4.0.4
tinyglobby@0.2.17:
dependencies:
fdir: 6.5.0(picomatch@4.0.4)
picomatch: 4.0.4
tinyrainbow@3.1.0: {}
tldts-core@7.0.25: {}
@@ -3488,30 +3538,27 @@ snapshots:
undici-types@7.18.2: {}
undici@7.24.2: {}
undici@7.24.8: {}
universalify@2.0.1: {}
vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3):
vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3):
dependencies:
lightningcss: 1.32.0
picomatch: 4.0.4
postcss: 8.5.8
rolldown: 1.0.0-rc.12(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)
tinyglobby: 0.2.15
postcss: 8.5.15
rolldown: 1.0.3
tinyglobby: 0.2.17
optionalDependencies:
'@types/node': 25.3.3
fsevents: 2.3.3
jiti: 2.6.1
yaml: 2.8.3
transitivePeerDependencies:
- '@emnapi/core'
- '@emnapi/runtime'
vitest@4.1.0(@types/node@25.3.3)(jsdom@29.0.1)(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)):
vitest@4.1.0(@types/node@25.3.3)(jsdom@29.1.1)(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)):
dependencies:
'@vitest/expect': 4.1.0
'@vitest/mocker': 4.1.0(vite@8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
'@vitest/mocker': 4.1.0(vite@8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3))
'@vitest/pretty-format': 4.1.0
'@vitest/runner': 4.1.0
'@vitest/snapshot': 4.1.0
@@ -3528,11 +3575,11 @@ snapshots:
tinyexec: 1.0.4
tinyglobby: 0.2.15
tinyrainbow: 3.1.0
vite: 8.0.5(@emnapi/core@1.8.1)(@emnapi/runtime@1.8.1)(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
vite: 8.0.16(@types/node@25.3.3)(jiti@2.6.1)(yaml@2.8.3)
why-is-node-running: 2.3.0
optionalDependencies:
'@types/node': 25.3.3
jsdom: 29.0.1
jsdom: 29.1.1
transitivePeerDependencies:
- msw
+561
View File
@@ -0,0 +1,561 @@
#!/usr/bin/env python3
"""Extract D&D 5.5e stat blocks from The Great Labors PDF.
Usage:
python3 scripts/extract-great-labors.py <path-to-pdf>
Reads pages 163-199 (Appendix B: Monsters) and emits
data/bestiary/dnd-bundled.json in the Creature[] shape from
packages/domain/src/creature-types.ts.
Requires: PyPDF2 (pip install PyPDF2)
"""
import json
import os
import re
import sys
from pathlib import Path
from PyPDF2 import PdfReader
# --- Constants ---
SOURCE_CODE = "TGL"
SOURCE_DISPLAY = "The Great Labors"
PAGE_START = 163 # 1-indexed
PAGE_END = 199
SIZE_RE = r"(Tiny|Small|Medium|Large|Huge|Gargantuan)"
TYPE_PIECE = r"[A-Za-z][A-Za-z\- ]*?"
ALIGN_PIECE = r"[A-Za-z][A-Za-z ()]*?"
HEADER_RE = re.compile(
rf"^{SIZE_RE}\s+({TYPE_PIECE}(?:\s+\([^)]+\))?),\s+({ALIGN_PIECE})\s*$"
)
AC_RE = re.compile(r"^AC\s+(\d+)\s+Initiative\s+([+\-]\s*\d+|[+\-]?\d+)")
HP_RE = re.compile(r"^HP\s+(\d+)\s*\(([^)]+)\)")
SPEED_RE = re.compile(r"^Speed\s+(.+?)\s*$")
ABILITY_ROW_RE = re.compile(
r"^(Str|Dex|Con|Int|Wis|Cha)\s+(\d+)\s*([+\-]?\s*\d+)\s+([+\-]?\s*\d+)\s+"
r"(Str|Dex|Con|Int|Wis|Cha)\s+(\d+)\s*([+\-]?\s*\d+)\s+([+\-]?\s*\d+)\s+"
r"(Str|Dex|Con|Int|Wis|Cha)\s+(\d+)\s*([+\-]?\s*\d+)\s+([+\-]?\s*\d+)\s*$"
)
CR_RE = re.compile(
r"^Challenge\s+([\d/]+)\s*\(([\d,]+)\s*XP;\s*PB\s+\+(\d+)\)"
)
SECTION_HEADERS = ("Traits", "Actions", "Bonus Actions", "Reactions",
"Legendary Actions", "Mythic Actions")
# Page running header like "166APPENDIX B MONSTERS..." -- marks the
# transition from stat-block content into prose on the next page.
RUNNING_HEADER_RE = re.compile(r"^\d+APPENDIX B\b")
# Condition / status-word false positives that the title-case entry regex
# would otherwise mistake for a new entry name. These names commonly end a
# sentence inside an entry's body (e.g. "...while it is Bloodied.").
NAME_FALSE_POSITIVES = {
"Bloodied", "Restrained", "Grappled", "Charmed", "Frightened",
"Prone", "Incapacitated", "Stunned", "Paralyzed", "Petrified",
"Poisoned", "Blinded", "Deafened", "Invisible", "Unconscious",
"Exhaustion", "Surprised", "Furious",
"Failure", "Success", "Trigger", "Response", "Hit", "Miss",
"Habitat", "Treasure", "Bonus Actions", "Reactions", "Traits", "Actions",
"Disadvantage", "Advantage",
}
# --- Helpers ---
def norm_dash(s: str) -> str:
return s.replace("", "-").replace("", "-").replace("", "-")
def proficiency_bonus(cr_str: str) -> int:
if "/" in cr_str:
n, d = cr_str.split("/")
cr = int(n) / int(d)
else:
cr = int(cr_str)
if cr <= 4:
return 2
if cr <= 8:
return 3
if cr <= 12:
return 4
if cr <= 16:
return 5
if cr <= 20:
return 6
if cr <= 24:
return 7
if cr <= 28:
return 8
return 9
def make_creature_id(source: str, name: str) -> str:
slug = re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-")
return f"{source.lower()}:{slug}"
def parse_passive_perception(senses_text: str) -> int | None:
# The PDF sometimes renders multi-digit values with a kerning space
# (e.g. "Passive Perception 1 1" meaning 11). Collapse those.
m = re.search(r"Passive Perception\s+(\d(?:\s*\d)*)\s*$", senses_text)
if not m:
m = re.search(r"Passive Perception\s+(\d+)", senses_text)
return int(m.group(1).replace(" ", "")) if m else None
# --- Page extraction ---
def extract_pages(pdf_path: Path) -> str:
reader = PdfReader(str(pdf_path))
parts = []
for i in range(PAGE_START - 1, PAGE_END):
parts.append(reader.pages[i].extract_text())
return "\n".join(parts)
# --- Block splitting ---
def find_stat_block_starts(lines: list[str]) -> list[int]:
starts = []
for i, line in enumerate(lines):
if AC_RE.match(line.strip()):
header_idx = None
for j in range(i - 1, max(-1, i - 5), -1):
if HEADER_RE.match(lines[j].strip()):
header_idx = j
break
if header_idx is None:
continue
name_idx = header_idx - 1
if name_idx >= 0 and lines[name_idx].strip():
starts.append(name_idx)
return starts
SECTION_HEADER_SMUSH_RE = re.compile(
r"^(?P<body>.+?)\.(?P<hdr>Actions|Bonus Actions|Reactions|Legendary Actions|Traits)\s*$"
)
def block_for(lines: list[str], start: int, next_start: int | None) -> list[str]:
"""Build the line list for one stat block.
Drops page markers and everything from the first running-header line
onward (which marks the transition to a new prose page). Splits PDF
smush lines like "...plants.Actions" into two lines so section header
detection works.
"""
end = next_start if next_start is not None else len(lines)
out: list[str] = []
for ln in lines[start:end]:
if ln.startswith("===PAGE"):
continue
if RUNNING_HEADER_RE.match(ln.strip()):
break
m = SECTION_HEADER_SMUSH_RE.match(ln.strip())
if m:
out.append(m.group("body") + ".")
out.append(m.group("hdr"))
else:
out.append(ln)
return out
# --- Vitals parsing ---
def parse_header(block: list[str]) -> dict:
name = block[0].strip()
header = block[1].strip()
m = HEADER_RE.match(header)
if not m:
raise ValueError(f"Bad header for {name!r}: {header!r}")
size, ctype, alignment = m.group(1), m.group(2).strip(), m.group(3).strip()
return {"name": name, "size": size, "type": ctype, "alignment": alignment}
def parse_ac(line: str) -> int:
m = AC_RE.match(line.strip())
if not m:
raise ValueError(f"Bad AC line: {line!r}")
return int(m.group(1))
def parse_hp(line: str) -> dict:
m = HP_RE.match(line.strip())
if not m:
raise ValueError(f"Bad HP line: {line!r}")
return {"average": int(m.group(1)), "formula": m.group(2).strip()}
def parse_speed(line: str) -> str:
m = SPEED_RE.match(line.strip())
if not m:
raise ValueError(f"Bad Speed line: {line!r}")
speed = m.group(1).rstrip(".").strip()
# Normalize "30 ft" → "30 ft." to match 5etools adapter output style.
speed = re.sub(r"(\d+)\s+ft\b\.?", r"\1 ft.", speed)
return speed
def parse_abilities(row1: str, row2: str) -> dict:
out = {}
for row in (row1, row2):
m = ABILITY_ROW_RE.match(row.strip())
if not m:
raise ValueError(f"Bad ability row: {row!r}")
for off in (0, 4, 8):
ab = m.group(off + 1).lower()
score = int(m.group(off + 2))
out[ab] = score
return out
# --- Meta lines ---
META_KEYS = ("Skills", "Saving Throws", "Resistances", "Immunities",
"Vulnerabilities", "Senses", "Languages", "Gear")
def is_meta_start(line: str) -> str | None:
for key in META_KEYS:
if line.startswith(key + " ") or line.startswith(key + " "):
return key
return None
def parse_meta(lines: list[str], start: int) -> tuple[dict, int]:
meta: dict[str, str] = {}
i = start
current_key: str | None = None
current_val_parts: list[str] = []
def flush() -> None:
nonlocal current_key, current_val_parts
if current_key is not None:
meta[current_key] = " ".join(p.strip() for p in current_val_parts).strip()
current_key = None
current_val_parts = []
while i < len(lines):
line = lines[i].strip()
if not line:
i += 1
continue
if line.startswith("Challenge "):
flush()
return meta, i
key = is_meta_start(line)
if key:
flush()
current_key = key
current_val_parts.append(line[len(key):].strip())
elif current_key is not None:
current_val_parts.append(line)
i += 1
flush()
return meta, i
# --- Section discovery ---
def find_section_starts(block: list[str], start_idx: int) -> list[tuple[str, int]]:
starts = []
for i in range(start_idx, len(block)):
ln = block[i].strip()
if ln in SECTION_HEADERS:
starts.append((ln, i))
return starts
def collect_section_lines(block: list[str], start: int, end: int) -> list[str]:
"""Collect the raw lines for one section (between header indices)."""
out: list[str] = []
for line in block[start:end]:
if not line.strip():
continue
out.append(line.rstrip())
return out
def join_section_text(lines: list[str]) -> str:
"""Join section lines into a single text blob, repairing wrap hyphens."""
text = " ".join(line.strip() for line in lines if line.strip())
text = re.sub(r"\s+", " ", text)
# Repair "civi -li zation" → "civilization" (PDF column-wrap hyphens).
text = re.sub(r"(\w)\s*-\s+(\w)", r"\1\2", text)
return text.strip()
# --- Entry splitting ---
# Entry name: title-case phrase, where each "word" is either a Capitalized
# word, a lowercase connector (of/the/and/or/in/at/on/to/with/from), a roman
# numeral, etc. Optionally followed by parenthesized modifier.
ENTRY_NAME_INNER = (
r"[A-Z][A-Za-z']*"
r"(?:[ \-](?:[A-Z][A-Za-z']*|of|the|and|or|in|at|on|to|with|from))*"
r"(?:\s*\([^)]+\))?"
)
# An entry boundary occurs at the start of the joined section text, or
# immediately after a sentence-ending punctuation. The PDF sometimes drops
# the space between the period and the new entry name, so `\s*` is fine.
ENTRY_BOUNDARY = re.compile(
rf"(?:^|(?<=[\.\?\!]))\s*(?P<name>{ENTRY_NAME_INNER})\.\s+(?=[A-Z“\"(])"
)
# Trim attribution quotes / page-header bleed-through from entry bodies.
PROSE_TAIL_PATTERNS = (
# Em-dash attribution: " —Chondrus, Priest of Lutheria"
re.compile(r"\s+—\s*[A-Z][^—]*$"),
# Smushed section header at end ("...plants.Actions").
re.compile(
r"\.\s*(?:Actions|Bonus\s+Actions|Reactions|Legendary\s+Actions|Traits)\s*$"
),
# Curated prose subheadings / phrase markers that follow stat blocks in
# this book. PDF reflow often merges prose onto the same logical line
# as the last action body, so the leading whitespace is optional.
re.compile(
r"\.?\s*(?:Random Trapped Creature|Maenad Bacchanal|The Phalanx Formation"
r"|Reinforced Portal|TRAPPED|HUNGER FOR|PURSUIT OF|RITUAL|MyTHIC|BRON"
r"|GOlDEN|NyMPH|MARBlE|KElEDONE|SOlDIER|MINOTAUR|SATyRS|GOATlING|EMPUS"
r"|ANARCH|GyGAN|CERBERUS|WHITE STAG|STORM|FEy|VOlKAN).*",
re.DOTALL,
),
# Specific prose sentence-starts observed leaking in.
re.compile(
r"\.(?:will gleefully|Some report that|Storm Dory|This magic weapon"
r"|Thylean soldiers|Some claim|These leaders).*",
re.DOTALL,
),
# All-caps run of 3+ uppercase letters in a word, then a space, then
# another word with 3+ uppercase letters (PDF small-caps section header
# like "BRON zE STRATEGOS", "MyTHIC BEAST", "GOlDEN RAM").
re.compile(r"(?<=[\.\s])[A-Z]{2}\w*\s+[\w ]{0,12}[A-Z]{3}[A-Z\w ]*"),
)
def trim_prose_tail(body: str) -> str:
out = body
for pat in PROSE_TAIL_PATTERNS:
m = pat.search(out)
if m:
out = out[:m.start()].rstrip().rstrip(".") + "."
return out.strip()
def is_valid_entry_name(name: str) -> bool:
"""Filter false-positive matches that aren't really entry names."""
if name in NAME_FALSE_POSITIVES:
return False
# Single short capitalized word that's a common condition or noun is
# usually a false positive when followed by a period. Real entry names
# almost always have either multiple words or a parenthesized modifier.
bare = re.sub(r"\s*\([^)]+\)\s*", "", name).strip()
if bare in NAME_FALSE_POSITIVES:
return False
return True
def split_text_into_entries(text: str) -> list[tuple[str, str]]:
"""Split section text into (name, body) entries by scanning for entry-name
boundaries (start-of-text or after a sentence period)."""
matches: list[tuple[int, int, str]] = []
for m in ENTRY_BOUNDARY.finditer(text):
name = m.group("name").strip()
if is_valid_entry_name(name):
matches.append((m.start(), m.end(), name))
if not matches:
return []
entries: list[tuple[str, str]] = []
for i, (_, body_start, name) in enumerate(matches):
body_end = matches[i + 1][0] if i + 1 < len(matches) else len(text)
body = text[body_start:body_end].strip()
entries.append((name, body))
return entries
def parse_section_traits(lines: list[str]) -> list[dict]:
text = join_section_text(lines)
entries = split_text_into_entries(text)
out = []
for name, body in entries:
body = trim_prose_tail(body)
if body or name:
out.append({"name": name,
"segments": [{"type": "text", "value": body}]})
return out
def parse_legendary(lines: list[str], creature_name: str) -> dict | None:
"""Parse the Legendary Actions section. Text before the first entry whose
body contains action vocabulary forms the preamble.
"""
text = join_section_text(lines)
all_matches: list[tuple[int, int, str]] = []
for m in ENTRY_BOUNDARY.finditer(text):
name = m.group("name").strip()
if is_valid_entry_name(name):
all_matches.append((m.start(), m.end(), name))
action_anchors = ("Saving Throw", "Attack Roll", "Trigger", "Recharge",
"Melee", "Ranged", "Constitution", "Dexterity",
"Strength", "Intelligence", "Wisdom", "Charisma")
first_action_idx = None
for i, (_, body_start, _) in enumerate(all_matches):
body_end = all_matches[i + 1][0] if i + 1 < len(all_matches) else len(text)
body_head = text[body_start:min(body_end, body_start + 100)]
if any(a in body_head for a in action_anchors):
first_action_idx = i
break
if first_action_idx is None:
return None
preamble = text[:all_matches[first_action_idx][0]].strip()
if not preamble:
preamble = f"{creature_name} can take Legendary Actions."
entries = []
for i in range(first_action_idx, len(all_matches)):
_, body_start, name = all_matches[i]
body_end = all_matches[i + 1][0] if i + 1 < len(all_matches) else len(text)
body = text[body_start:body_end].strip()
entries.append((name, body))
if not entries:
return None
return {
"preamble": preamble,
"entries": [
{"name": name,
"segments": [{"type": "text", "value": trim_prose_tail(body)}]}
for name, body in entries if body
],
}
# --- Top-level parse ---
def parse_block(block: list[str]) -> dict:
head = parse_header(block)
ac = parse_ac(block[2])
hp = parse_hp(block[3])
speed = parse_speed(block[4])
if not block[5].strip().startswith("MOD"):
raise ValueError(f"Expected MOD header, got: {block[5]!r}")
abilities = parse_abilities(block[6], block[7])
meta, ch_idx = parse_meta(block, 8)
cr_match = CR_RE.match(block[ch_idx].strip())
if not cr_match:
raise ValueError(f"Bad Challenge line: {block[ch_idx]!r}")
cr_str = cr_match.group(1)
section_starts = find_section_starts(block, ch_idx + 1)
sections: dict[str, list[str]] = {}
for i, (name, idx) in enumerate(section_starts):
end = section_starts[i + 1][1] if i + 1 < len(section_starts) else len(block)
sections[name] = collect_section_lines(block, idx + 1, end)
creature: dict = {
"id": make_creature_id(SOURCE_CODE, head["name"]),
"name": head["name"],
"source": SOURCE_CODE,
"sourceDisplayName": SOURCE_DISPLAY,
"size": head["size"],
"type": head["type"],
"alignment": head["alignment"],
"ac": ac,
"hp": hp,
"speed": speed,
"abilities": abilities,
"cr": cr_str,
"initiativeProficiency": 0,
"proficiencyBonus": proficiency_bonus(cr_str),
"passive": parse_passive_perception(meta.get("Senses", "")) or 10,
}
if "Saving Throws" in meta:
creature["savingThrows"] = meta["Saving Throws"]
if "Skills" in meta:
creature["skills"] = meta["Skills"]
if "Resistances" in meta:
creature["resist"] = meta["Resistances"]
if "Immunities" in meta:
creature["immune"] = meta["Immunities"]
if "Vulnerabilities" in meta:
creature["vulnerable"] = meta["Vulnerabilities"]
if "Senses" in meta:
senses = re.sub(r"[;,]?\s*Passive Perception\s+\d+\s*$", "", meta["Senses"])
senses = senses.strip().rstrip(";").strip()
if senses:
creature["senses"] = senses
if "Languages" in meta:
creature["languages"] = meta["Languages"]
if "Traits" in sections:
creature["traits"] = parse_section_traits(sections["Traits"])
if "Actions" in sections:
creature["actions"] = parse_section_traits(sections["Actions"])
if "Bonus Actions" in sections:
creature["bonusActions"] = parse_section_traits(sections["Bonus Actions"])
if "Reactions" in sections:
creature["reactions"] = parse_section_traits(sections["Reactions"])
if "Legendary Actions" in sections:
leg = parse_legendary(sections["Legendary Actions"], head["name"])
if leg:
creature["legendaryActions"] = leg
return creature
def main() -> int:
if len(sys.argv) != 2:
print("Usage: python3 extract-great-labors.py <path-to-pdf>",
file=sys.stderr)
return 1
pdf_path = Path(os.path.expanduser(sys.argv[1]))
if not pdf_path.exists():
print(f"PDF not found: {pdf_path}", file=sys.stderr)
return 1
text = extract_pages(pdf_path)
lines = text.split("\n")
starts = find_stat_block_starts(lines)
print(f"Detected {len(starts)} stat blocks", file=sys.stderr)
creatures = []
failures = []
for i, s in enumerate(starts):
next_s = starts[i + 1] if i + 1 < len(starts) else None
block = block_for(lines, s, next_s)
try:
creatures.append(parse_block(block))
except Exception as e:
failures.append((block[0] if block else "<empty>", str(e)))
if failures:
print(f"\n{len(failures)} parse failures:", file=sys.stderr)
for name, err in failures:
print(f" - {name}: {err}", file=sys.stderr)
out_path = Path(__file__).resolve().parent.parent / "data" / "bestiary" / "dnd-bundled.json"
out_path.parent.mkdir(parents=True, exist_ok=True)
with out_path.open("w") as f:
json.dump(creatures, f, indent="\t", ensure_ascii=False)
f.write("\n")
print(f"Wrote {len(creatures)} creatures to {out_path}", file=sys.stderr)
return 0 if not failures else 2
if __name__ == "__main__":
sys.exit(main())
+23
View File
@@ -128,6 +128,22 @@ A user wants to rename a combatant. Clicking the combatant's name immediately en
4. **Given** a bestiary combatant row and a custom combatant row, **When** the user clicks either combatant's name, **Then** the behavior is identical — inline edit mode is entered immediately in both cases.
**Story C4 — Name Updates on Weak/Elite Toggle (Priority: P2)**
When a PF2e weak/elite adjustment is toggled on a bestiary-linked combatant, the name automatically gains or loses a "Weak" or "Elite" prefix. Auto-numbered suffixes are preserved (e.g., "Goblin 2" → "Elite Goblin 2"). Toggling back to Normal removes the prefix. Existing auto-numbering of other combatants is not affected.
**Acceptance Scenarios**:
1. **Given** a combatant named "Iron Hag", **When** the DM toggles to "Elite", **Then** the name becomes "Elite Iron Hag".
2. **Given** a combatant named "Goblin 2", **When** the DM toggles to "Weak", **Then** the name becomes "Weak Goblin 2".
3. **Given** a combatant named "Elite Iron Hag", **When** the DM toggles back to "Normal", **Then** the name becomes "Iron Hag".
4. **Given** "Goblin 1" and "Goblin 2" exist, **When** the DM toggles "Goblin 1" to "Elite", **Then** it becomes "Elite Goblin 1" and "Goblin 2" is not renamed.
5. **Given** a combatant named "Elite Goblin 1", **When** the DM manually renames it to "Big Boss", **Then** the rename proceeds normally (manual names override the prefix convention).
---
### Clearing the Encounter
@@ -291,6 +307,12 @@ EditCombatant MUST preserve the combatant's position in the list, `activeIndex`,
#### FR-024 — Edit: UI
The UI MUST provide an inline name-edit mechanism for each combatant, activated by a single click on the name. Clicking the name MUST enter inline edit mode immediately — no delay, no timer, consistent for all combatant types. The name MUST display a `cursor-text` cursor on hover to signal editability. The updated name MUST be immediately visible after submission. The 250ms click timer and double-click detection logic MUST be removed entirely.
#### FR-041 — Edit: Weak/Elite name prefix
When a PF2e weak/elite adjustment is toggled on a bestiary-linked combatant (see `specs/004-bestiary/spec.md`, FR-101), the system MUST prepend "Weak " or "Elite " to the combatant's name, preserving any auto-numbered suffix. Toggling to "Normal" MUST remove the prefix. Switching directly between "Weak" and "Elite" MUST swap the prefix.
#### FR-042 — Edit: Prefix does not trigger re-numbering
Adding or removing a weak/elite prefix MUST NOT trigger auto-numbering recalculation for other combatants. "Goblin 1" becoming "Elite Goblin 1" does not cause "Goblin 2" to be renumbered.
#### FR-025 — ConfirmButton: Reusable component
The system MUST provide a reusable `ConfirmButton` component that wraps any icon button to add a two-step confirmation flow.
@@ -363,6 +385,7 @@ All domain events MUST be returned as plain data values from operations, not dis
- **ConfirmButton: two instances in confirm state simultaneously**: Each manages its own state independently.
- **ConfirmButton: combatant row re-renders while in confirm state**: Confirm state persists through re-renders as long as combatant identity is stable.
- **Name click behavior is uniform**: A single click on any combatant's name enters inline edit mode immediately. There is no gesture disambiguation (no timer, no double-click detection). Stat block access is handled via the dedicated book icon on bestiary rows (see `specs/004-bestiary/spec.md`, FR-062).
- **Weak/elite prefix on a manually renamed combatant**: If the user manually renames "Elite Goblin" to "Big Boss" and then toggles to Normal, the prefix "Elite " is not present to remove — the name "Big Boss" remains unchanged.
---
+57 -1
View File
@@ -25,6 +25,7 @@ interface Combatant {
readonly ac?: number; // non-negative integer
readonly conditions?: readonly ConditionEntry[];
readonly isConcentrating?: boolean;
readonly persistentDamage?: readonly PersistentDamageEntry[]; // PF2e only
readonly creatureId?: CreatureId; // link to bestiary entry
}
@@ -32,6 +33,11 @@ interface ConditionEntry {
readonly id: ConditionId;
readonly value?: number; // PF2e valued conditions (e.g., Clumsy 2); undefined for D&D
}
interface PersistentDamageEntry {
readonly type: PersistentDamageType; // "fire" | "bleed" | "acid" | "cold" | "electricity" | "poison" | "mental"
readonly formula: string; // e.g., "2d6", "1d4+2"
}
```
---
@@ -115,6 +121,15 @@ Acceptance scenarios:
7. **Given** no combatant has temp HP, **When** viewing the encounter, **Then** no extra space is reserved for temp HP display.
8. **Given** one combatant has temp HP, **When** viewing the encounter, **Then** all rows reserve space for the temp HP display to maintain column alignment.
**Story HP-8 — HP Adjusts on Weak/Elite Toggle (P2)**
As a game master toggling a PF2e creature between weak, normal, and elite, I want the combatant's max HP and current HP to update automatically so that the tracker reflects the adjusted creature's durability.
Acceptance scenarios:
1. **Given** a combatant with 75/75 HP (Normal), **When** the DM toggles to "Elite" (HP bracket +20), **Then** maxHp becomes 95 and currentHp becomes 95.
2. **Given** a combatant with 65/75 HP (Normal, 10 damage taken), **When** the DM toggles to "Elite" (HP bracket +20), **Then** maxHp becomes 95 and currentHp becomes 85 (shifted by +20, preserving the 10-damage deficit).
3. **Given** a combatant with 5/75 HP (Normal), **When** the DM toggles to "Weak" (HP bracket 20), **Then** maxHp becomes 55 and currentHp becomes 0 (clamped, since 520 < 0).
4. **Given** a combatant with 95/95 HP (Elite), **When** the DM toggles back to "Normal" (HP bracket 20), **Then** maxHp becomes 75 and currentHp becomes 75.
### Requirements
- **FR-001**: Each combatant MAY have an optional `maxHp` value (positive integer >= 1). HP tracking is optional per combatant.
@@ -148,6 +163,8 @@ Acceptance scenarios:
- **FR-029**: When any combatant in the encounter has temp HP > 0, all rows MUST reserve space for the temp HP display to maintain column alignment. When no combatant has temp HP, no space is reserved.
- **FR-030**: The HP adjustment popover MUST include a third button (Shield icon) for setting temp HP.
- **FR-031**: Temp HP MUST persist across page reloads via the existing persistence mechanism.
- **FR-113**: When a PF2e weak/elite adjustment is toggled (see `specs/004-bestiary/spec.md`, FR-101), `maxHp` MUST be updated by the HP bracket delta for the creature's base level: ±10 (level ≤ 1), ±15 (level 24), ±20 (level 519), ±30 (level 20+). When switching directly between weak and elite, the full swing (reverse + apply) MUST be computed as a single delta.
- **FR-114**: When `maxHp` changes due to a weak/elite toggle, `currentHp` MUST shift by the same delta as `maxHp`, clamped to [0, new `maxHp`]. Temp HP is unaffected.
### Edge Cases
@@ -166,6 +183,7 @@ Acceptance scenarios:
- There is no death/unconscious game mechanic triggered at 0 HP; the system displays the state only.
- There is no damage type tracking, resistance/vulnerability calculation, or hit log in the MVP baseline.
- There is no undo/redo for HP changes in the MVP baseline.
- Weak/elite toggle when combatant has temp HP: temp HP is unaffected; only maxHp and currentHp change. A combatant at 10+5/75 toggled to Elite becomes 30+5/95.
---
@@ -192,6 +210,14 @@ Acceptance scenarios:
4. **Given** the inline AC edit is active, **When** the user presses Escape, **Then** the edit is cancelled and the original value is preserved.
5. **Given** the inline AC edit is active, **When** the user clears the field and presses Enter, **Then** AC is unset and the shield shows an empty state.
**Story AC-3 — AC Adjusts on Weak/Elite Toggle (P2)**
As a game master toggling a PF2e creature between weak, normal, and elite, I want the combatant's AC to update automatically so that the tracker reflects the adjusted creature's defenses.
Acceptance scenarios:
1. **Given** a combatant with AC 22 (Normal), **When** the DM toggles to "Elite", **Then** AC becomes 24.
2. **Given** a combatant with AC 24 (Elite), **When** the DM toggles to "Weak", **Then** AC becomes 20 (base 22, 2 for weak).
3. **Given** a combatant with AC 20 (Weak), **When** the DM toggles to "Normal", **Then** AC becomes 22.
### Requirements
- **FR-023**: Each combatant MAY have an optional `ac` value, a non-negative integer (>= 0).
@@ -203,6 +229,8 @@ Acceptance scenarios:
- **FR-029**: AC MUST reject negative values. Zero is a valid AC.
- **FR-030**: AC values MUST persist via the existing persistence mechanism.
- **FR-031**: The AC shield MUST scale appropriately for single-digit, double-digit, and any valid AC values.
- **FR-115**: When a PF2e weak/elite adjustment is toggled (see `specs/004-bestiary/spec.md`, FR-101), `ac` MUST be updated by ±2. When switching directly between weak and elite, the full swing (±4) MUST be applied as a single update.
- **FR-116**: AC changes from weak/elite toggles MUST persist via the existing persistence mechanism, consistent with FR-030.
### Edge Cases
@@ -324,6 +352,19 @@ Acceptance scenarios:
4. **Given** the game system is D&D (5e or 5.5e), **When** interacting with conditions, **Then** no maximum enforcement is applied.
5. **Given** a PF2e valued condition without a defined maximum (e.g., Frightened, Clumsy), **When** incrementing, **Then** no cap is enforced — the value can increase without limit.
**Story CC-11 — Persistent Damage Tags (P2)**
As a DM running a PF2e encounter, I want to apply persistent damage to a combatant as a compact tag showing a damage type icon and formula so I can track ongoing damage effects without manual bookkeeping.
Acceptance scenarios:
1. **Given** the game system is Pathfinder 2e and the condition picker is open, **When** the user clicks "Persistent Damage", **Then** a sub-picker opens with a damage type dropdown (fire, bleed, acid, cold, electricity, poison, mental, force, void, spirit, vitality, piercing) and a formula text input.
2. **Given** the sub-picker is open, **When** the user selects "fire" and types "2d6" and confirms, **Then** a compact tag appears on the combatant row showing a fire icon and "2d6".
3. **Given** a combatant has persistent fire 2d6, **When** the user adds persistent bleed 1d4, **Then** both tags appear on the row simultaneously.
4. **Given** a combatant has persistent fire 2d6, **When** the user adds persistent fire 3d6, **Then** the existing fire entry is replaced with 3d6 (one instance per type).
5. **Given** a combatant has a persistent damage tag, **When** the user clicks the tag on the row, **Then** the persistent damage entry is removed.
6. **Given** a combatant has a persistent damage tag, **When** the user hovers over it, **Then** a tooltip shows the full description (e.g., "Persistent Fire 2d6 — Take damage at end of turn. DC 15 flat check to end.").
7. **Given** the game system is D&D (5e or 5.5e), **When** viewing the condition picker, **Then** no "Persistent Damage" option is available.
8. **Given** a combatant has persistent damage entries, **When** the page is reloaded, **Then** all entries are restored exactly.
### Requirements
- **FR-032**: When a D&D game system is active, the system MUST support the following 15 standard D&D 5e/5.5e conditions: blinded, charmed, deafened, exhaustion, frightened, grappled, incapacitated, invisible, paralyzed, petrified, poisoned, prone, restrained, stunned, unconscious. When Pathfinder 2e is active, the system MUST support the PF2e condition set (see FR-103).
@@ -379,6 +420,15 @@ Acceptance scenarios:
- **FR-110**: Maximum value enforcement MUST only apply when the Pathfinder 2e game system is active. D&D conditions are unaffected.
- **FR-111**: When Pathfinder 2e is the active game system, the concentration UI (Brain icon toggle, purple left border accent, damage pulse animation) MUST be hidden entirely. The Brain icon MUST NOT be shown on hover or at rest, and the concentration toggle MUST NOT be interactive.
- **FR-112**: Switching the game system MUST NOT clear or modify `isConcentrating` state on any combatant. The state MUST be preserved in storage and restored to the UI when switching back to a D&D game system.
- **FR-117**: When Pathfinder 2e is active, the condition picker MUST include a "Persistent Damage" entry that opens a sub-picker instead of toggling directly.
- **FR-118**: The persistent damage sub-picker MUST contain a dropdown of PF2e damage types (fire, bleed, acid, cold, electricity, poison, mental, force, void, spirit, vitality, piercing) and a text input for the damage formula (e.g., "2d6").
- **FR-119**: Each persistent damage entry MUST be displayed as a compact tag on the combatant row showing a damage type icon and the formula text (e.g., fire icon + "2d6").
- **FR-120**: Only one persistent damage entry per damage type is allowed per combatant. Adding the same damage type MUST replace the existing formula.
- **FR-121**: Clicking a persistent damage tag on the combatant row MUST remove that entry.
- **FR-122**: Hovering a persistent damage tag MUST show a tooltip with the full description: "{Type} {formula} — Take damage at end of turn. DC 15 flat check to end."
- **FR-123**: Persistent damage MUST NOT be available when a D&D game system is active.
- **FR-124**: Persistent damage entries MUST persist across page reloads via the existing persistence mechanism.
- **FR-125**: Persistent damage tags MUST be displayed inline after condition icons, following the same wrapping behavior as conditions (FR-041).
### Edge Cases
@@ -395,7 +445,11 @@ Acceptance scenarios:
- When the game system is switched from D&D to PF2e, existing D&D conditions on combatants are hidden (not deleted). Switching back to D&D restores them.
- PF2e valued condition at value 0 is treated as removed — it MUST NOT appear on the row.
- Dying, doomed, wounded, and slowed have enforced maximum values in PF2e (4, 3, 3, 3 respectively). The `[+]` button is disabled at the cap. The dynamic dying cap based on doomed value (dying max = 4 doomed) is not enforced — only the static maximum applies.
- Persistent damage is excluded from the PF2e MVP condition set. It can be added as a follow-up feature.
- Persistent damage tags are separate from the `conditions` array — they use a dedicated `persistentDamage` field on `Combatant`.
- Adding persistent damage with an empty formula is rejected; the formula field must be non-empty.
- When the game system is switched from PF2e to D&D, existing persistent damage entries are preserved in storage but hidden from display, consistent with condition behavior (FR-107).
- Persistent damage has no automation — the system does not auto-apply damage or prompt for flat checks. It is a visual reminder only.
- The persistent damage sub-picker closes when the user clicks outside of it or confirms an entry.
- When PF2e is active, concentration state (`isConcentrating`) is preserved in storage but the entire concentration UI is hidden. Switching back to D&D restores Brain icons, purple borders, and pulse behavior without data loss.
---
@@ -600,3 +654,5 @@ Acceptance scenarios:
- **SC-035**: PF2e valued conditions display their current value and can be incremented/decremented within 1 click each.
- **SC-036**: Switching game system immediately changes the available conditions, bestiary search results, stat block layout, and initiative calculation — no page reload required.
- **SC-037**: The game system preference survives a full page reload.
- **SC-038**: A persistent damage entry can be added to a combatant in 3 clicks or fewer (click "+", click "Persistent Damage", select type + enter formula + confirm).
- **SC-039**: Persistent damage tags are visually distinguishable from conditions by their icon + formula format.
+29 -1
View File
@@ -113,6 +113,11 @@ As a DM running a PF2e encounter, I want to see a creature's carried equipment
An "Equipment" section appears on the stat block listing each carried item with its name and relevant details (level, traits, activation description). Scrolls additionally show the embedded spell name and rank (e.g., "Scroll of Teleport (Rank 6)"). The section is omitted entirely for creatures that carry no equipment. Equipment data is extracted from the existing cached creature JSON — no additional fetch is required.
**US-D7 — Toggle Weak/Elite Adjustment on PF2e Stat Block (P2)**
As a DM running a PF2e encounter, I want to toggle a weak or elite adjustment on a bestiary-linked combatant's stat block so that the standard PF2e stat modifications are applied to that specific combatant and reflected in both the stat block and the tracker.
When viewing a PF2e creature's stat block, a Weak/Normal/Elite toggle appears in the header. Selecting "Elite" or "Weak" applies the standard PF2e adjustments: ±2 to AC, saves, Perception, attack rolls, and strike damage; HP adjusted by the standard level bracket table; level shifted. The combatant's stored HP and AC update accordingly (see `specs/003-combatant-state/spec.md`, FR-113FR-116), and its name gains a prefix (see `specs/001-combatant-management/spec.md`, FR-041FR-042). The toggle defaults to "Normal" and is not shown for D&D creatures. A visual indicator (the same icon used in the toggle) appears next to the creature name in the header.
### Requirements
- **FR-016**: The system MUST display a stat block panel with full creature information when a creature is selected.
@@ -138,6 +143,14 @@ An "Equipment" section appears on the stat block listing each carried item with
- **FR-081**: Spell descriptions MUST be processed through the existing Foundry tag-stripping utility before display (consistent with FR-068).
- **FR-082**: When a spell name has a parenthetical modifier (e.g., "Heal (×3)", "Unfettered Movement (Constant)"), only the spell name portion MUST be the click target; the modifier MUST remain as adjacent plain text.
- **FR-083**: The spell description display MUST handle both representations of heightening present in Foundry VTT data: `system.heightening` and `system.overlays`.
- **FR-101**: PF2e stat blocks MUST include a Weak/Normal/Elite toggle in the header, defaulting to "Normal".
- **FR-102**: The Weak/Normal/Elite toggle MUST NOT be shown for D&D creatures or non-bestiary combatants.
- **FR-103**: Selecting "Elite" MUST display the stat block with the standard PF2e elite adjustment applied: +2 to AC, saving throws, Perception, and attack rolls; +2 to strike damage; HP increase by level bracket (per the standard PF2e table); level +1 (or +2 if base level ≤ 0).
- **FR-104**: Selecting "Weak" MUST display the stat block with the standard PF2e weak adjustment applied: 2 to AC, saving throws, Perception, and attack rolls; 2 to strike damage; HP decrease by level bracket (per the standard PF2e table); level 1 (or 2 if base level is 1).
- **FR-105**: Toggling the adjustment MUST update the combatant's stored maxHp and ac to the adjusted values (see `specs/003-combatant-state/spec.md`, FR-113FR-116). The combatant's currentHp MUST shift by the same delta as maxHp, clamped to [0, new maxHp].
- **FR-106**: Toggling the adjustment MUST update the combatant's name with the appropriate prefix — "Weak" or "Elite" — or remove the prefix when returning to "Normal" (see `specs/001-combatant-management/spec.md`, FR-041FR-042).
- **FR-107**: The stat block header MUST display a visual indicator (the same icon used in the toggle) next to the creature name when the creature has a weak or elite adjustment.
- **FR-108**: The adjustment MUST be stored on the combatant as a `creatureAdjustment` field and persist across page reloads.
### Acceptance Scenarios
@@ -173,6 +186,14 @@ An "Equipment" section appears on the stat block listing each carried item with
30. **Given** a PF2e creature with an ability that has no frequency limit, **When** the DM views the stat block, **Then** the ability name renders without any frequency annotation.
31. **Given** a PF2e creature with `perception.details: "smoke vision"`, **When** the DM views the stat block, **Then** the perception line shows "smoke vision" alongside the senses.
32. **Given** a PF2e creature with no perception details, **When** the DM views the stat block, **Then** the perception line shows only the modifier and senses as before.
33. **Given** a PF2e creature's stat block is open, **When** the DM views the header, **Then** a Weak/Normal/Elite toggle is visible, set to "Normal" by default.
34. **Given** a D&D creature's stat block is open, **When** the DM views the header, **Then** no Weak/Normal/Elite toggle is shown.
35. **Given** a PF2e creature (level 5, AC 22, HP 75) stat block is open, **When** the DM selects "Elite", **Then** the stat block shows AC 24, HP 95 (75+20 for level 5 bracket), level 6, and all saves/Perception/attacks are adjusted by +2.
36. **Given** a PF2e creature (level 5, AC 22, HP 75) stat block is open, **When** the DM selects "Weak", **Then** the stat block shows AC 20, HP 55 (7520 for level 5 bracket), level 4, and all saves/Perception/attacks are adjusted by 2.
37. **Given** a PF2e creature with level 0 stat block is open, **When** the DM selects "Elite", **Then** the level increases by 2 (not 1).
38. **Given** a PF2e creature with level 1 stat block is open, **When** the DM selects "Weak", **Then** the level decreases by 2 (to 1, not 0).
39. **Given** a PF2e combatant was set to "Elite" and the page is reloaded, **When** the DM opens the stat block, **Then** the toggle shows "Elite" and the stat block displays adjusted stats.
40. **Given** a PF2e combatant was set to "Elite", **When** the DM toggles back to "Normal", **Then** the stat block reverts to base stats, the combatant's HP/AC revert, and the name prefix is removed.
### Edge Cases
@@ -184,6 +205,13 @@ An "Equipment" section appears on the stat block listing each carried item with
- Equipment item with empty description: the item is displayed with its name and metadata (level, traits) but no description text.
- Cached source data from before the spell description feature was added: existing cached entries lack the new per-spell data fields. The IndexedDB schema version MUST be bumped to invalidate old caches and trigger re-fetch (re-normalization from raw Foundry data is not possible because the original raw JSON is not retained).
- Creature with no recognized type trait (e.g., a creature whose only traits are not in the type-to-skill mapping): the Recall Knowledge line is omitted entirely.
- Weak adjustment on a level 1 creature: level becomes 1 (special case, 2 instead of 1).
- Elite adjustment on a level ≤ 0 creature: level increases by 2 instead of 1.
- HP bracket table: HP adjustments follow the standard PF2e weak/elite HP adjustment table keyed by creature level (1 or lower: ±10, 24: ±15, 519: ±20, 20+: ±30).
- Toggling from Elite to Weak: applies the full swing (reverts elite, then applies weak) in a single operation.
- Combatant has taken damage before toggle: currentHp shifts by the maxHp delta, clamped to [0, new maxHp]. E.g., 65/75 HP → Elite → 85/95 HP.
- Source data not yet cached when toggling: toggle is disabled until source data is loaded (adjustment requires full creature data to compute).
- Recall Knowledge DC updates based on adjusted level.
- Creature with a type trait that maps to multiple skills (e.g., Beast → Arcana/Nature): both skills are shown.
- Attack with multiple on-hit effects (e.g., `["grab", "knockdown"]`): all effects shown, joined with "and" (e.g., "plus Grab and Knockdown").
- Attack effect slug with creature-name prefix (e.g., `"lich-siphon-life"` on a Lich): the creature-name prefix is stripped, rendering as "Siphon Life".
@@ -368,7 +396,7 @@ As a DM with a creature pinned, I want to collapse the right (browse) panel inde
- **Source** (`BestiarySource`): A D&D or PF2e publication identified by a code (e.g., "XMM") with a display name (e.g., "Monster Manual (2025)"). Caching and fetching operate at the source level.
- **Creature (Full)** (`Creature`): A complete creature record with all stat block data (traits, actions, legendary actions, spellcasting, etc.), available only after source data is fetched/uploaded and cached. Identified by a branded `CreatureId`. For PF2e creatures, each spell entry inside `spellcasting` carries full per-spell data (slug, level, traits, range, action cost, target/area, duration, defense, description, heightening) extracted from the embedded `items[type=spell]` data on the source NPC, enabling inline spell description display without additional fetches. PF2e creatures also carry an `equipment` list of carried items (weapons, consumables) extracted from `items[type=weapon]` and `items[type=consumable]` entries, each with name, level, traits, description, and (for scrolls) embedded spell data. PF2e attack entries carry an optional `attackEffects` list of on-hit effect names. PF2e ability entries carry an optional `frequency` with `max` and `per` fields. PF2e creature perception carries an optional `details` string (e.g., "smoke vision").
- **Cached Source Data**: The full normalized bestiary data for a single source, stored in IndexedDB. Contains complete creature stat blocks.
- **Combatant** (extended): Gains an optional `creatureId` reference to a `Creature`, enabling stat block lookup and stat pre-fill on creation.
- **Combatant** (extended): Gains an optional `creatureId` reference to a `Creature`, enabling stat block lookup and stat pre-fill on creation. PF2e bestiary-linked combatants may also carry a `creatureAdjustment` (`"weak" | "elite"`) indicating the active PF2e weak/elite adjustment, persisted across reloads.
- **Queued Creature**: Transient UI-only state representing a bestiary creature selected for batch-add, containing the creature reference and a count (1+). Not persisted.
- **Bulk Import Operation**: Tracks total sources, completed count, failed count, and current status (idle / loading / complete / partial-failure).
- **Toast Notification**: Lightweight custom UI element at bottom-center of screen with text, optional progress bar, and optional dismiss button.