This commit is contained in:
2026-03-16 07:35:20 +01:00
commit 5d54d1cf7b
20 changed files with 2676 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.vscode/
__pycache__/
.svelte-kit/

400
backend/card.py Normal file
View File

@@ -0,0 +1,400 @@
from math import sqrt, cbrt
from enum import Enum
from typing import NamedTuple
from urllib.parse import quote
from datetime import datetime, timedelta
from time import sleep
class CardType(Enum):
other = 0
person = 1
location = 2
artwork = 3
life_form = 4
conflict = 5
group = 6
science_thing = 7
vehicle = 8
class CardRarity(Enum):
common = 0
uncommon = 1
rare = 2
super_rare = 3
epic = 4
legendary = 5
class Card(NamedTuple):
name: str
created_at: datetime
image_link: str
card_rarity: CardRarity
card_type: CardType
wikidata_instance: str
text: str
attack: int
defense: int
cost: int
def __str__(self) -> str:
return_string = ""+""*50+"\n"
return_string += ""+f"{self.name:{' '}<50}"+"\n"
return_string += ""+""*50+"\n"
card_type = "Type: "+self.card_type.name
if self.card_type == CardType.other:
card_type += f" ({self.wikidata_instance})"
return_string += ""+f"{card_type:{' '}<50}"+"\n"
return_string += ""+""*50+"\n"
rarity_text = f"Rarity: {self.card_rarity.name}"
return_string += ""+f"{rarity_text:<50}"+"\n"
return_string += ""+""*50+"\n"
link = "Image: "+("Yes" if self.image_link != "" else "No")
return_string += ""+f"{link:{' '}<50}"+"\n"
return_string += ""+""*50+"\n"
lines = []
words = self.text.split(" ")
current_line = ""
for w in words:
if len(current_line + " " + w) < 50:
current_line += " " + w
elif len(current_line) < 40 and len(w) > 10:
new_len = 48 - len(current_line)
current_line += " " + w[:new_len] + "-"
lines.append(current_line)
current_line = w[new_len:]
else:
lines.append(current_line)
current_line = w
lines.append(current_line)
for l in lines :
return_string += ""+f"{l:{' '}<50}"+"\n"
return_string += ""+""*50+"\n"
date_text = str(self.created_at.date())
stats = f"{self.attack}/{self.defense}"
spaces = 50 - (len(date_text) + len(stats))
return_string += ""+date_text + " "*spaces + stats + "\n"
return_string += ""+""*50+""
return return_string
WIKIDATA_INSTANCE_TYPE_MAP = {
"Q5": CardType.person, # human
"Q15632617": CardType.person, # fictional human
"Q215627": CardType.person, # person
"Q7889": CardType.artwork, # video game
"Q1004": CardType.artwork, # comics
"Q15416": CardType.artwork, # television program
"Q11424": CardType.artwork, # film
"Q24862": CardType.artwork, # film
"Q11032": CardType.artwork, # newspaper
"Q25379": CardType.artwork, # play
"Q482994": CardType.artwork, # album
"Q134556": CardType.artwork, # single
"Q169930": CardType.artwork, # EP
"Q202866": CardType.artwork, # animated film
"Q734698": CardType.artwork, # collectible card game
"Q506240": CardType.artwork, # television film
"Q738377": CardType.artwork, # student newspaper
"Q3305213": CardType.artwork, # painting
"Q3177859": CardType.artwork, # dedicated deck card game
"Q5398426": CardType.artwork, # television series
"Q7725634": CardType.artwork, # literary work
"Q1761818": CardType.artwork, # advertising campaign
"Q1446621": CardType.artwork, # recital
"Q63952888": CardType.artwork, # anime television series
"Q47461344": CardType.artwork, # written work
"Q71631512": CardType.artwork, # tabletop role-playing game supplement
"Q21198342": CardType.artwork, # manga series
"Q24634210": CardType.artwork, # podcast show
"Q105543609": CardType.artwork, # musical work / composition
"Q106499608": CardType.artwork, # literary reading
"Q515": CardType.location, # city
"Q8502": CardType.location, # mountain
"Q4022": CardType.location, # river
"Q6256": CardType.location, # country
"Q41176": CardType.location, # building
"Q23442": CardType.location, # island
"Q82794": CardType.location, # geographic region
"Q34442": CardType.location, # road
"Q3624078": CardType.location, # sovereign state
"Q1093829": CardType.location, # city in the United States
"Q7930989": CardType.location, # city/town
"Q35145263": CardType.location, # natural geographic object
"Q16521": CardType.life_form, # taxon
"Q23038290": CardType.life_form, # fossil taxon
"Q198": CardType.conflict, # war
"Q8465": CardType.conflict, # civil war
"Q103495": CardType.conflict, # world war
"Q997267": CardType.conflict, # skirmish
"Q178561": CardType.conflict, # battle
"Q1361229": CardType.conflict, # conquest
"Q7278": CardType.group, # political party
"Q476028": CardType.group, # association football club
"Q215380": CardType.group, # musical group
"Q176799": CardType.group, # military unit
"Q178790": CardType.group, # labor union
"Q2367225": CardType.group, # university and college sports club
"Q9248092": CardType.group, # infantry division
"Q7210356": CardType.group, # political organization
"Q5419137": CardType.group, # veterans' organization
"Q12973014": CardType.group, # sports team
"Q135408445": CardType.group, # men's national association football team
"Q7187": CardType.science_thing, # gene
"Q8054": CardType.science_thing, # protein
"Q11276": CardType.science_thing, # globular cluster
"Q898273": CardType.science_thing, # protein domain
"Q168845": CardType.science_thing, # star cluster
"Q113145171": CardType.science_thing, # type of chemical entity
"Q43193": CardType.vehicle, # truck
"Q25956": CardType.vehicle, # space station
"Q174736": CardType.vehicle, # destroyer
"Q484000": CardType.vehicle, # unmanned aerial vehicle
"Q559026": CardType.vehicle, # ship class
"Q3231690": CardType.vehicle, # automobile model
"Q1428357": CardType.vehicle, # submarine class
"Q1499623": CardType.vehicle, # destroyer escort
}
import asyncio
import httpx
HEADERS = {"User-Agent": "WikiTCG/1.0 (nikolaj@gade.gg)"}
async def _get_random_summary_async(client: httpx.AsyncClient) -> dict:
try:
response = await client.get(
"https://en.wikipedia.org/api/rest_v1/page/random/summary",
headers=HEADERS,
follow_redirects=False,
)
if response.status_code in (301, 302, 303, 307, 308):
# Extract the title from the redirect location and re-encode it
location = response.headers["location"]
title = location.split("/page/summary/")[-1]
response = await client.get(
f"https://en.wikipedia.org/api/rest_v1/page/summary/{quote(title, safe='%')}",
headers=HEADERS,
follow_redirects=False,
)
except httpx.ReadTimeout:
return {}
if not response.is_success:
print("Error in request:")
print(response.status_code)
print(response.text)
return {}
return response.json()
async def _get_page_summary_async(client: httpx.AsyncClient, title: str) -> dict:
try:
response = await client.get(
f"https://en.wikipedia.org/api/rest_v1/page/summary/{title}",
headers=HEADERS,
follow_redirects=False,
)
if response.status_code in (301, 302, 303, 307, 308):
# Extract the title from the redirect location and re-encode it
location = response.headers["location"]
title = location.split("/page/summary/")[-1]
response = await client.get(
f"https://en.wikipedia.org/api/rest_v1/page/summary/{quote(title, safe='%')}",
headers=HEADERS,
follow_redirects=False,
)
except httpx.ReadTimeout:
return {}
if not response.is_success:
print("Error in request:")
print(response.status_code)
print(response.text)
return {}
return response.json()
async def _infer_card_type_async(client: httpx.AsyncClient, entity_id: str) -> tuple[CardType, str, int]:
response = await client.get(
"https://www.wikidata.org/wiki/Special:EntityData/" + entity_id + ".json",
headers=HEADERS
)
if not response.is_success:
return CardType.other, "", 0
entity = response.json().get("entities", {}).get(entity_id, {})
claims = entity.get("claims", {})
instance_of_claims = claims.get("P31", [])
qids = [c.get("mainsnak", {}).get("datavalue", {}).get("value", {}).get("id") for c in instance_of_claims]
sitelinks = entity.get("sitelinks", {})
language_count = sum(
1 for key in sitelinks
if key.endswith("wiki")
and key not in ("commonswiki", "wikidatawiki", "specieswiki")
)
if "P625" in claims:
return CardType.location, (qids[0] if qids != [] else ""), language_count
for qid in qids:
if qid in WIKIDATA_INSTANCE_TYPE_MAP:
return WIKIDATA_INSTANCE_TYPE_MAP[qid], qid, language_count
return CardType.other, (qids[0] if qids != [] else ""), language_count
async def _get_wikirank_score(client: httpx.AsyncClient, title: str) -> float | None:
"""Returns a quality score from 0-100, or None if unavailable."""
response = await client.get(
f"https://api.wikirank.net/api.php?name={quote(title, safe="")}&lang=en",
headers=HEADERS
)
if not response.is_success:
return None
data = response.json()
result = data.get("result",{})
if result == "not found":
return None
return result.get("en",{}).get("quality")
def _score_to_rarity(score: float | None) -> CardRarity:
if score is None:
return CardRarity.common
if score >= 95:
return CardRarity.legendary
if score >= 80:
return CardRarity.epic
if score >= 65:
return CardRarity.super_rare
if score >= 50:
return CardRarity.rare
if score >= 35:
return CardRarity.uncommon
return CardRarity.common
RARITY_MULTIPLIER = {
CardRarity.common: 1,
CardRarity.uncommon: 1.1,
CardRarity.rare: 1.3,
CardRarity.super_rare: 1.7,
CardRarity.epic: 2.5,
CardRarity.legendary: 3,
}
async def _get_monthly_pageviews(client: httpx.AsyncClient, title: str) -> int | None:
# Uses the last full month
today = datetime.now()
first_of_month = today.replace(day=1)
last_month_end = first_of_month - timedelta(days=1)
last_month_start = last_month_end.replace(day=1)
start = last_month_start.strftime("%Y%m01")
end = last_month_end.strftime("%Y%m%d")
try:
response = await client.get(
f"https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/{quote(title, safe='%')}/monthly/{start}/{end}",
headers=HEADERS,
)
if not response.is_success:
return None
items = response.json().get("items", [])
return items[0]["views"] if items else None
except httpx.ReadError:
return None
def _pageviews_to_defense(views: int | None) -> int:
if views is None:
return 0
return int(sqrt(views))
async def _get_card_async(client: httpx.AsyncClient, page_title: str|None = None) -> Card|None:
if page_title is None:
summary = await _get_random_summary_async(client)
else:
summary = await _get_page_summary_async(client, quote(page_title))
if summary == {}:
return None
title = summary["title"]
entity_id = summary.get("wikibase_item")
text = summary.get("extract", "")
card_type_task = (
_infer_card_type_async(client, entity_id)
if entity_id
else asyncio.sleep(0, result=(CardType.other, "", 0))
)
wikirank_task = _get_wikirank_score(client, title)
pageviews_task = _get_monthly_pageviews(client, title)
(card_type, instance, language_count), score, views = await asyncio.gather(
card_type_task, wikirank_task, pageviews_task
)
rarity = _score_to_rarity(score)
multiplier = RARITY_MULTIPLIER[rarity]
attack = int(language_count*1.5*multiplier**2)
defense = int(_pageviews_to_defense(views)*max(multiplier,(multiplier**2)/2))
return Card(
name=summary["title"],
created_at=datetime.now(),
image_link=summary.get("thumbnail", {}).get("source", ""),
card_rarity=rarity,
card_type=card_type,
wikidata_instance=instance,
text=text,
attack=attack,
defense=defense,
cost=min(12,max(1,int(cbrt(attack+defense)/1.5)))
)
async def _get_cards_async(size: int) -> list[Card]:
async with httpx.AsyncClient(follow_redirects=True) as client:
cards = await asyncio.gather(*[_get_card_async(client) for _ in range(size)])
return [c for c in cards if c is not None]
async def _get_specific_card_async(title: str) -> Card|None:
async with httpx.AsyncClient(follow_redirects=True) as client:
return await _get_card_async(client, title)
# Sync entrypoints
def generate_cards(size: int) -> list[Card]:
print(f"Generating {size} cards")
batches = [10 for _ in range(size//10)] + ([size%10] if size%10 != 0 else [])
n_batches = len(batches)
cards = []
for i in range(n_batches):
b = batches[i]
print(f"Generating batch of {b} cards (batch {i+1}/{n_batches})")
if i != 0:
sleep(5)
cards += asyncio.run(_get_cards_async(b))
return cards
def generate_card(title: str) -> Card|None:
return asyncio.run(_get_specific_card_async(title))
# for card in generate_cards(5):
# print(card)
# rarities = []
# from collections import Counter
# for card in generate_cards(1000):
# rarities.append(card.card_rarity)
# if card.card_rarity == CardRarity.legendary:
# print(card)
# print(Counter(rarities))
# for card in generate_cards(100):
# if card.card_type == CardType.other:
# print(card)

22
backend/main.py Normal file
View File

@@ -0,0 +1,22 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from card import _get_cards_async
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"], # SvelteKit's default dev port
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/pack/{size}")
async def open_pack(size: int = 10):
cards = await _get_cards_async(size)
return [
{**card._asdict(),
"card_type": card.card_type.name,
"card_rarity": card.card_rarity.name}
for card in cards
]

0
backend/requirements.txt Normal file
View File

23
frontend/.gitignore vendored Normal file
View File

@@ -0,0 +1,23 @@
node_modules
# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build
# OS
.DS_Store
Thumbs.db
# Env
.env
.env.*
!.env.example
!.env.test
# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

1
frontend/.npmrc Normal file
View File

@@ -0,0 +1 @@
engine-strict=true

42
frontend/README.md Normal file
View File

@@ -0,0 +1,42 @@
# sv
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```sh
# create a new project
npx sv create my-app
```
To recreate this project with the same configuration:
```sh
# recreate this project
npx sv@0.12.7 create --template minimal --types ts --install npm frontend
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```sh
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```sh
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

1666
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
frontend/package.json Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "frontend",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^7.0.0",
"@sveltejs/kit": "^2.50.2",
"@sveltejs/vite-plugin-svelte": "^6.2.4",
"svelte": "^5.51.0",
"svelte-check": "^4.4.2",
"typescript": "^5.9.3",
"vite": "^7.3.1"
}
}

13
frontend/src/app.d.ts vendored Normal file
View File

@@ -0,0 +1,13 @@
// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}
export {};

11
frontend/src/app.html Normal file
View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

View File

@@ -0,0 +1,350 @@
<script>
let { card } = $props();
const RARITY_BADGE = {
common: { symbol: "C", label: "Common", bg: "#c8c8c8", color: "#333" },
uncommon: { symbol: "U", label: "Uncommon", bg: "#4a7a50", color: "#fff" },
rare: { symbol: "R", label: "Rare", bg: "#2a5a9b", color: "#fff" },
super_rare: { symbol: "SR", label: "Super Rare", bg: "#7a3a9b", color: "#fff" },
epic: { symbol: "E", label: "Epic", bg: "#9b3a3a", color: "#fff" },
legendary: { symbol: "L", label: "Legendary", bg: "#b87820", color: "#fff" },
};
const TYPE_COLORS = {
person: { bg: "#f0e0c8", header: "#b87830" },
location: { bg: "#d8e8d4", header: "#4a7a50" },
artwork: { bg: "#e4d4e8", header: "#7a5090" },
life_form: { bg: "#ccdce8", header: "#3a6878" },
conflict: { bg: "#e8d4d4", header: "#8b2020" },
group: { bg: "#e8e4d0", header: "#748c12" },
science_thing: { bg: "#c7c5c1", header: "#060c17" },
vehicle: { bg: "#c7c1c4", header: "#801953" },
other: { bg: "#dddad4", header: "#6a6860" },
};
const FOIL_RARITIES = new Set(["super_rare", "epic", "legendary"]);
let rarity = $derived(card.card_rarity);
let badge = $derived(RARITY_BADGE[rarity] ?? RARITY_BADGE.common);
let foil = $derived(FOIL_RARITIES.has(rarity))
let foilOffset = $derived(foil ? `${-(Math.random() * 5).toFixed(2)}s` : '0s');
let super_rare = $derived(rarity == "super_rare");
let epic = $derived(rarity == "epic");
let legendary = $derived(rarity === "legendary");
let colors = $derived(TYPE_COLORS[card.card_type] ?? TYPE_COLORS.other);
let typeLabel = $derived(card.card_type.charAt(0).toUpperCase() + card.card_type.slice(1).replace("_", " "));
let wikiUrl = $derived("https://en.wikipedia.org/wiki/" + encodeURIComponent(card.name.replace(/ /g, "_")));
</script>
<div class="card" class:foil class:super_rare class:epic class:legendary style="--foil-offset: {foilOffset}">
<div class="card-inner" style="--bg: {colors.bg}; --header: {colors.header}">
<div class="card-header">
<span class="card-name">{card.name}</span>
<span class="card-type-badge">{typeLabel}</span>
</div>
<div class="card-image-wrap">
{#if card.image_link}
<img src={card.image_link} alt={card.name} class="card-image" />
{:else}
<div class="card-image-placeholder">
<span>{card.name[0]}</span>
</div>
{/if}
<div class="rarity-badge" title={badge.label} style="--rb: {badge.bg}; --rc: {badge.color}">{badge.symbol}</div>
<a href={wikiUrl} target="_blank" rel="noopener noreferrer" class="wiki-link" title="Open Wikipedia article">
<svg viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<circle cx="25" cy="25" r="24" fill="white" stroke="#888" stroke-width="1"/>
<text x="25" y="33" text-anchor="middle" font-family="serif" font-size="28" font-weight="bold" fill="#000">W</text>
</svg>
</a>
<div class="cost-bubbles">
{#each { length: card.cost } as _}
<div class="cost-bubble"></div>
{/each}
</div>
</div>
<div class="card-divider"></div>
<div class="card-text">{card.text}</div>
<div class="card-footer">
<span class="stat">ATK <strong>{card.attack}</strong></span>
<span class="card-date">{new Date(card.created_at).toLocaleDateString()}</span>
<span class="stat">DEF <strong>{card.defense}</strong></span>
</div>
</div>
</div>
<style>
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Crimson+Text:ital,wght@0,400;0,600;1,400&display=swap');
.card {
width: 300px;
border-radius: 12px;
padding: 7px;
background: #111;
border: 2px solid #111;
box-shadow: 0 4px 24px rgba(0,0,0,0.5);
font-family: 'Crimson Text', serif;
position: relative;
transition: transform 0.2s ease, box-shadow 0.2s ease;
flex-shrink: 0;
user-select: none;
-webkit-user-select: none;
}
.card:hover {
transform: translateY(-4px) scale(1.02);
box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.card.foil::before {
content: "";
position: absolute;
inset: 0;
border-radius: 12px;
animation: foil-shift 2.5s ease-in-out infinite alternate;
animation-delay: var(--foil-offset, 0s);
pointer-events: none;
z-index: 2;
mix-blend-mode: screen;
}
.card.super_rare::before {
background: repeating-linear-gradient(
105deg,
transparent 0%,
rgba(255,255,255,0.15) 20%,
rgba(200,220,255,0.2) 35%,
rgba(255,255,255,0.15) 50%,
transparent 70%
);
background-size: 300% 300%;
}
.card.foil.epic::before {
background: repeating-linear-gradient(
105deg,
rgba(255,0,128,0.3) 0%,
rgba(255,200,0,0.3) 10%,
rgba(0,255,128,0.3) 20%,
rgba(0,200,255,0.3) 30%,
rgba(128,0,255,0.3) 40%,
rgba(255,0,128,0.3) 50%
);
background-size: 300% 300%;
}
.card.foil.legendary::before {
background: repeating-linear-gradient(
105deg,
rgba(255,215,0,0.30) 0%,
rgba(255,180,0,0.15) 15%,
rgba(255,255,180,0.35) 30%,
rgba(255,200,0,0.15) 45%,
rgba(255,215,0,0.30) 60%
);
animation-duration: 1.8s;
background-size: 300% 300%;
}
@keyframes foil-shift {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
.card-inner {
border-radius: 8px;
overflow: hidden;
background: var(--bg);
border: 2px solid #000;
display: flex;
flex-direction: column;
}
.card-header {
padding: 9px 12px 7px;
background: var(--header);
border-bottom: 2px solid #000;
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 8px;
}
.card-name {
font-family: 'Cinzel', serif;
font-size: 13px;
font-weight: 700;
color: #fff;
line-height: 1.3;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.card-type-badge {
font-family: 'Cinzel', serif;
font-size: 9px;
color: rgba(255,255,255,0.95);
text-transform: uppercase;
letter-spacing: 0.05em;
white-space: nowrap;
text-shadow: 0 1px 3px rgba(0,0,0,0.7);
background: rgba(0,0,0,0.25);
padding: 1px 5px;
border-radius: 3px;
}
.card-image-wrap {
position: relative;
width: 100%;
aspect-ratio: 4/3;
background: #222;
overflow: hidden;
border-bottom: 2px solid #000;
}
.card-image {
width: 100%;
height: 100%;
object-fit: cover;
object-position: 50% 25%;
display: block;
}
.card-image-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: #ddd;
font-family: 'Cinzel', serif;
font-size: 64px;
color: rgba(0,0,0,0.15);
}
.rarity-badge {
position: absolute;
top: 7px;
left: 7px;
width: 26px;
height: 26px;
border-radius: 50%;
background: var(--rb);
border: 2.5px solid #000;
color: var(--rc);
font-family: 'Cinzel', serif;
font-size: 9px;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
z-index: 3;
letter-spacing: -0.02em;
}
.wiki-link {
position: absolute;
top: 7px;
right: 7px;
width: 26px;
height: 26px;
border-radius: 50%;
background: rgba(255,255,255,0.92);
border: 1.5px solid #000;
display: flex;
align-items: center;
justify-content: center;
z-index: 3;
transition: background 0.15s, transform 0.15s;
}
.wiki-link:hover {
background: rgba(255,255,255,1);
transform: scale(1.15);
}
.card-divider {
height: 2px;
background: #000;
}
.card-text {
padding: 10px 12px;
font-size: 13px;
line-height: 1.55;
color: #1a1208;
font-style: italic;
background: #f0e6cc;
border-bottom: 2px solid #000;
height: 110px;
overflow: hidden;
}
.card-footer {
padding: 7px 12px;
background: #e8d8b8;
display: flex;
justify-content: space-between;
align-items: center;
}
.stat {
font-family: 'Cinzel', serif;
font-size: 11px;
color: #2a2010;
letter-spacing: 0.03em;
}
.stat strong {
color: #000;
font-size: 15px;
}
.card-date {
font-size: 10px;
color: rgba(0,0,0,0.5);
font-style: italic;
font-family: 'Crimson Text', serif;
}
.cost-bubbles {
position: absolute;
bottom: 6px;
left: 8px;
display: flex;
gap: 3px;
flex-wrap: wrap;
justify-content: center;
max-width: calc(100% - 16px);
}
.cost-bubble {
width: 16px;
height: 16px;
border-radius: 50%;
background: #6ea0ec;
border: 2.5px solid #000;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
color: #08152c;
font-size: 12px;
font-weight: 700;
font-family: 'Cinzel', serif;
line-height: 1;
}
</style>

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.157 22.819c-10.4-14.885-30.94-19.297-45.792-9.835L22.282 29.608A29.92 29.92 0 0 0 8.764 49.65a31.5 31.5 0 0 0 3.108 20.231 30 30 0 0 0-4.477 11.183 31.9 31.9 0 0 0 5.448 24.116c10.402 14.887 30.942 19.297 45.791 9.835l26.083-16.624A29.92 29.92 0 0 0 98.235 78.35a31.53 31.53 0 0 0-3.105-20.232 30 30 0 0 0 4.474-11.182 31.88 31.88 0 0 0-5.447-24.116" style="fill:#ff3e00"/><path d="M45.817 106.582a20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.503 18 18 0 0 1 .624-2.435l.49-1.498 1.337.981a33.6 33.6 0 0 0 10.203 5.098l.97.294-.09.968a5.85 5.85 0 0 0 1.052 3.878 6.24 6.24 0 0 0 6.695 2.485 5.8 5.8 0 0 0 1.603-.704L69.27 76.28a5.43 5.43 0 0 0 2.45-3.631 5.8 5.8 0 0 0-.987-4.371 6.24 6.24 0 0 0-6.698-2.487 5.7 5.7 0 0 0-1.6.704l-9.953 6.345a19 19 0 0 1-5.296 2.326 20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.502 17.99 17.99 0 0 1 8.13-12.052l26.081-16.623a19 19 0 0 1 5.3-2.329 20.72 20.72 0 0 1 22.237 8.243 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-.624 2.435l-.49 1.498-1.337-.98a33.6 33.6 0 0 0-10.203-5.1l-.97-.294.09-.968a5.86 5.86 0 0 0-1.052-3.878 6.24 6.24 0 0 0-6.696-2.485 5.8 5.8 0 0 0-1.602.704L37.73 51.72a5.42 5.42 0 0 0-2.449 3.63 5.79 5.79 0 0 0 .986 4.372 6.24 6.24 0 0 0 6.698 2.486 5.8 5.8 0 0 0 1.602-.704l9.952-6.342a19 19 0 0 1 5.295-2.328 20.72 20.72 0 0 1 22.237 8.242 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-8.13 12.053l-26.081 16.622a19 19 0 0 1-5.3 2.328" style="fill:#fff"/></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.

View File

@@ -0,0 +1,11 @@
<script lang="ts">
import favicon from '$lib/assets/favicon.svg';
let { children } = $props();
</script>
<svelte:head>
<link rel="icon" href={favicon} />
</svelte:head>
{@render children()}

View File

@@ -0,0 +1,63 @@
<script>
import Card from "$lib/Card.svelte";
let cards = $state([]);
let loading = $state(false);
async function openPack() {
loading = true;
try {
const res = await fetch("http://localhost:8000/pack/14");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
cards = await res.json();
} catch (e) {
console.error("Failed to open pack:", e);
} finally {
loading = false;
}
}
</script>
<main>
<button onclick={openPack} disabled={loading}>
{loading ? "Opening..." : "Open Pack"}
</button>
<div class="pack">
{#each cards as card}
<Card {card} />
{/each}
</div>
</main>
<style>
main {
min-height: 100vh;
background: #0d0a04;
padding: 2rem;
}
button {
display: block;
margin: 0 auto 2rem;
padding: 10px 28px;
font-family: 'Cinzel', serif;
font-size: 14px;
background: #2e1c05;
color: #f0d080;
border: 1px solid #6b4c1e;
border-radius: 6px;
cursor: pointer;
}
button:hover:not(:disabled) {
background: #3d2507;
}
.pack {
display: flex;
flex-wrap: wrap;
gap: 16px;
justify-content: center;
}
</style>

View File

@@ -0,0 +1,3 @@
# allow crawling everything by default
User-agent: *
Disallow:

17
frontend/svelte.config.js Normal file
View File

@@ -0,0 +1,17 @@
import adapter from '@sveltejs/adapter-auto';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
},
vitePlugin: {
dynamicCompileOptions: ({ filename }) =>
filename.includes('node_modules') ? undefined : { runes: true }
}
};
export default config;

20
frontend/tsconfig.json Normal file
View File

@@ -0,0 +1,20 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"rewriteRelativeImportExtensions": true,
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// To make changes to top-level options such as include and exclude, we recommend extending
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
}

6
frontend/vite.config.ts Normal file
View File

@@ -0,0 +1,6 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()]
});