V1
This commit is contained in:
1 parent
5fd12506cf
commit
bde6bc5942
30 files changed
+11392
-10300
No files matched your search
+2
-2
@@ -3,8 +3,8 @@ root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
# Image Caching Implementation
|
||||
|
||||
This application implements a comprehensive multi-layer image caching strategy for League of Legends champion icons.
|
||||
|
||||
## Caching Layers
|
||||
|
||||
### 1. HTTP Cache Headers (`image-cache.interceptor.ts`)
|
||||
- Intercepts HTTP requests for images
|
||||
- Adds `Cache-Control: public, max-age=86400, immutable` headers
|
||||
- Enables browser HTTP cache for 24 hours
|
||||
- Automatically detects image URLs (png, jpg, jpeg, webp, gif)
|
||||
- Specifically targets League of Legends CDN URLs
|
||||
|
||||
### 2. Cache API (`image-preload.service.ts`)
|
||||
- Uses browser Cache API for persistent storage
|
||||
- Cache name: `lol-champion-images-v1`
|
||||
- Cache expiry: 7 days
|
||||
- Features:
|
||||
- Preloads images in batches (10 images per batch)
|
||||
- Uses `requestIdleCallback` for non-blocking preload
|
||||
- Automatic cleanup of expired cache entries
|
||||
- Adds custom metadata (`x-cached-date`) to track cache age
|
||||
- Checks cache before fetching from network
|
||||
|
||||
### 3. Service Worker (Production Only)
|
||||
- Angular Service Worker configuration (`ngsw-config.json`)
|
||||
- Two data groups:
|
||||
- **champion-api**: Caches API responses for 1 day
|
||||
- **champion-images**: Caches champion images for 7 days
|
||||
- Strategy: `performance` (cache-first, network fallback)
|
||||
- Only active in production builds (`!isDevMode()`)
|
||||
- Registers 30 seconds after app stability
|
||||
|
||||
### 4. Local Storage (`champion-data.service.ts`)
|
||||
- Caches champion data (not images) for 24 hours
|
||||
- Prevents unnecessary API calls
|
||||
- Version-controlled cache with automatic invalidation
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **First Load**:
|
||||
- App fetches champion data from API
|
||||
- Data is cached in LocalStorage
|
||||
- Images are preloaded in background using Cache API
|
||||
- HTTP cache headers enable browser caching
|
||||
|
||||
2. **Subsequent Loads**:
|
||||
- Champion data loaded from LocalStorage
|
||||
- Images loaded from Cache API (instant)
|
||||
- If cache miss, browser HTTP cache serves images
|
||||
- If HTTP cache miss, network fetch with automatic caching
|
||||
|
||||
3. **Production Builds**:
|
||||
- Service Worker adds additional caching layer
|
||||
- Offline support for previously loaded images
|
||||
- Automatic cache updates on new versions
|
||||
|
||||
## Cache Management
|
||||
|
||||
### Clear Image Cache
|
||||
The `ImagePreloadService` provides a `clearCache()` method:
|
||||
```typescript
|
||||
inject(ImagePreloadService).clearCache();
|
||||
```
|
||||
|
||||
### Clear Champion Data Cache
|
||||
The `ChampionDataService` provides a `clearCache()` method:
|
||||
```typescript
|
||||
inject(ChampionDataService).clearCache();
|
||||
```
|
||||
|
||||
## Browser Optimization
|
||||
|
||||
- Preconnect hints to CDN in `index.html`
|
||||
- DNS prefetch for faster connections
|
||||
- Progressive Web App manifest for installability
|
||||
- Theme color for native app experience
|
||||
|
||||
## Cache Sizes
|
||||
|
||||
- Champion API: Max 100 entries
|
||||
- Champion Images: Max 200 images
|
||||
- Automatic cleanup when limits exceeded
|
||||
- Age-based expiration (7 days for images)
|
||||
|
||||
## Development vs Production
|
||||
|
||||
**Development** (ng serve):
|
||||
- HTTP cache only
|
||||
- Cache API preloading
|
||||
- No service worker
|
||||
|
||||
**Production** (ng build):
|
||||
- All caching layers active
|
||||
- Service worker enabled
|
||||
- Maximum performance and offline support
|
||||
|
||||
## Testing Cache
|
||||
|
||||
1. Open DevTools > Application > Cache Storage
|
||||
2. See `lol-champion-images-v1` with cached images
|
||||
3. Network tab shows cached responses (200 from cache)
|
||||
4. Offline mode works for previously loaded content
|
||||
|
||||
## Benefits
|
||||
|
||||
- **Instant Load Times**: Images load instantly from cache
|
||||
- **Reduced Bandwidth**: Images only fetched once
|
||||
- **Offline Support**: Works without internet (after first load)
|
||||
- **Better UX**: No flickering or loading delays
|
||||
- **CDN Cost Savings**: Fewer requests to external CDN
|
||||
@@ -0,0 +1,50 @@
|
||||
# Proxy Configuration
|
||||
|
||||
This project uses a proxy to avoid CORS issues when fetching champion data from the Meraki Analytics CDN.
|
||||
|
||||
## Architecture
|
||||
|
||||
### Development (`ng serve`)
|
||||
- Uses `proxy.conf.json` configuration
|
||||
- Angular CLI dev server handles the proxy
|
||||
- Requests to `/api/champions` are forwarded to the external CDN
|
||||
|
||||
### Production/SSR (`ng build` + `npm run serve:ssr:random-lol`)
|
||||
- Uses `http-proxy-middleware` in `src/server.ts`
|
||||
- Express server handles the proxy
|
||||
- Same endpoint `/api/champions` works consistently
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **Frontend** makes a request to `/api/champions` (relative URL)
|
||||
2. **Proxy layer** (dev server or Express) intercepts the request
|
||||
3. **External API** at `https://cdn.merakianalytics.com/riot/lol/resources/latest/en-US/champions.json` is called
|
||||
4. **Response** is returned to the frontend as if it came from the same origin
|
||||
|
||||
## Benefits
|
||||
|
||||
- ✅ No CORS issues in development or production
|
||||
- ✅ Consistent API endpoint across environments
|
||||
- ✅ External API URL changes only need updates in proxy config
|
||||
- ✅ Can add caching, rate limiting, or other middleware later
|
||||
|
||||
## Testing
|
||||
|
||||
### Development
|
||||
```bash
|
||||
npm start
|
||||
# Visit http://localhost:4200
|
||||
```
|
||||
|
||||
### Production SSR
|
||||
```bash
|
||||
npm run build
|
||||
npm run serve:ssr:random-lol
|
||||
# Visit http://localhost:4000
|
||||
```
|
||||
|
||||
## Configuration Files
|
||||
|
||||
- `proxy.conf.json` - Development proxy configuration
|
||||
- `src/server.ts` - Production SSR proxy implementation
|
||||
- `angular.json` - References proxy config for `ng serve`
|
||||
+94
-88
@@ -1,90 +1,96 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"random-lol": {
|
||||
"projectType": "application",
|
||||
"schematics": {},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular/build:application",
|
||||
"options": {
|
||||
"browser": "src/main.ts",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
],
|
||||
"server": "src/main.server.ts",
|
||||
"outputMode": "server",
|
||||
"ssr": {
|
||||
"entry": "src/server.ts"
|
||||
}
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kB",
|
||||
"maximumError": "1MB"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "4kB",
|
||||
"maximumError": "8kB"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular/build:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "random-lol:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "random-lol:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular/build:extract-i18n"
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular/build:karma",
|
||||
"options": {
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"random-lol": {
|
||||
"projectType": "application",
|
||||
"schematics": {},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular/build:application",
|
||||
"options": {
|
||||
"browser": "src/main.ts",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": ["src/custom-theme.scss", "src/styles.css"],
|
||||
"server": "src/main.server.ts",
|
||||
"outputMode": "server",
|
||||
"ssr": {
|
||||
"entry": "src/server.ts"
|
||||
},
|
||||
"loader": {
|
||||
".png": "file",
|
||||
".jpg": "file",
|
||||
".jpeg": "file",
|
||||
".webp": "file"
|
||||
},
|
||||
"serviceWorker": "ngsw-config.json"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kB",
|
||||
"maximumError": "1MB"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "4kB",
|
||||
"maximumError": "8kB"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular/build:dev-server",
|
||||
"options": {
|
||||
"proxyConfig": "proxy.conf.json"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "random-lol:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "random-lol:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular/build:extract-i18n"
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular/build:karma",
|
||||
"options": {
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": ["src/styles.css"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
|
||||
"index": "/index.html",
|
||||
"assetGroups": [
|
||||
{
|
||||
"name": "app",
|
||||
"installMode": "prefetch",
|
||||
"resources": {
|
||||
"files": ["/favicon.ico", "/index.html", "/*.css", "/*.js"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "assets",
|
||||
"installMode": "lazy",
|
||||
"updateMode": "prefetch",
|
||||
"resources": {
|
||||
"files": ["/assets/**", "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"dataGroups": [
|
||||
{
|
||||
"name": "champion-api",
|
||||
"urls": ["https://cdn.merakianalytics.com/**"],
|
||||
"cacheConfig": {
|
||||
"maxSize": 100,
|
||||
"maxAge": "1d",
|
||||
"timeout": "10s",
|
||||
"strategy": "performance"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "champion-images",
|
||||
"urls": [
|
||||
"https://ddragon.leagueoflegends.com/**",
|
||||
"https://*.leagueoflegends.com/**/*.png",
|
||||
"https://*.leagueoflegends.com/**/*.jpg"
|
||||
],
|
||||
"cacheConfig": {
|
||||
"maxSize": 200,
|
||||
"maxAge": "7d",
|
||||
"strategy": "performance"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Generated
+9905
-9743
File diff suppressed because it is too large.
Load diff
+61
-52
@@ -1,53 +1,62 @@
|
||||
{
|
||||
"name": "random-lol",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test",
|
||||
"serve:ssr:random-lol": "node dist/random-lol/server/server.mjs"
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 100,
|
||||
"singleQuote": true,
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.html",
|
||||
"options": {
|
||||
"parser": "angular"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/common": "^20.3.0",
|
||||
"@angular/compiler": "^20.3.0",
|
||||
"@angular/core": "^20.3.0",
|
||||
"@angular/forms": "^20.3.0",
|
||||
"@angular/platform-browser": "^20.3.0",
|
||||
"@angular/platform-server": "^20.3.0",
|
||||
"@angular/router": "^20.3.0",
|
||||
"@angular/ssr": "^20.3.7",
|
||||
"express": "^5.1.0",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/build": "^20.3.7",
|
||||
"@angular/cli": "^20.3.7",
|
||||
"@angular/compiler-cli": "^20.3.0",
|
||||
"@types/express": "^5.0.1",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"@types/node": "^20.17.19",
|
||||
"jasmine-core": "~5.9.0",
|
||||
"karma": "~6.4.0",
|
||||
"karma-chrome-launcher": "~3.2.0",
|
||||
"karma-coverage": "~2.2.0",
|
||||
"karma-jasmine": "~5.1.0",
|
||||
"karma-jasmine-html-reporter": "~2.1.0",
|
||||
"typescript": "~5.9.2"
|
||||
}
|
||||
}
|
||||
"name": "random-lol",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test",
|
||||
"serve:ssr:random-lol": "node dist/random-lol/server/server.mjs"
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 100,
|
||||
"singleQuote": true,
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.html",
|
||||
"options": {
|
||||
"parser": "angular"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^20.3.0",
|
||||
"@angular/cdk": "^20.2.12",
|
||||
"@angular/common": "^20.3.0",
|
||||
"@angular/compiler": "^20.3.0",
|
||||
"@angular/core": "^20.3.0",
|
||||
"@angular/forms": "^20.3.0",
|
||||
"@angular/material": "^20.2.12",
|
||||
"@angular/platform-browser": "^20.3.0",
|
||||
"@angular/platform-server": "^20.3.0",
|
||||
"@angular/router": "^20.3.0",
|
||||
"@angular/service-worker": "^20.3.10",
|
||||
"@angular/ssr": "^20.3.7",
|
||||
"@fortawesome/angular-fontawesome": "^3.0.0",
|
||||
"@fortawesome/free-brands-svg-icons": "^7.0.0",
|
||||
"@fortawesome/free-regular-svg-icons": "^7.0.0",
|
||||
"@fortawesome/free-solid-svg-icons": "^7.0.0",
|
||||
"express": "^5.1.0",
|
||||
"http-proxy-middleware": "^3.0.5",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/build": "^20.3.7",
|
||||
"@angular/cli": "^20.3.7",
|
||||
"@angular/compiler-cli": "^20.3.0",
|
||||
"@types/express": "^5.0.1",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"@types/node": "^20.17.19",
|
||||
"jasmine-core": "~5.9.0",
|
||||
"karma": "~6.4.0",
|
||||
"karma-chrome-launcher": "~3.2.0",
|
||||
"karma-coverage": "~2.2.0",
|
||||
"karma-jasmine": "~5.1.0",
|
||||
"karma-jasmine-html-reporter": "~2.1.0",
|
||||
"typescript": "~5.9.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"/api/champions": {
|
||||
"target": "https://cdn.merakianalytics.com",
|
||||
"secure": true,
|
||||
"changeOrigin": true,
|
||||
"pathRewrite": {
|
||||
"^/api/champions": "/riot/lol/resources/latest/en-US/champions.json"
|
||||
},
|
||||
"logLevel": "debug"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Random LOL Champion Picker",
|
||||
"short_name": "LOL Random",
|
||||
"theme_color": "#1976d2",
|
||||
"background_color": "#fafafa",
|
||||
"display": "standalone",
|
||||
"scope": "/",
|
||||
"start_url": "/",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,9 +4,7 @@ import { appConfig } from './app.config';
|
||||
import { serverRoutes } from './app.routes.server';
|
||||
|
||||
const serverConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideServerRendering(withRoutes(serverRoutes))
|
||||
]
|
||||
providers: [provideServerRendering(withRoutes(serverRoutes))],
|
||||
};
|
||||
|
||||
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
||||
+20
-6
@@ -1,13 +1,27 @@
|
||||
import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZonelessChangeDetection } from '@angular/core';
|
||||
import {
|
||||
ApplicationConfig,
|
||||
provideBrowserGlobalErrorListeners,
|
||||
provideZonelessChangeDetection,
|
||||
isDevMode,
|
||||
} from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
|
||||
import { routes } from './app.routes';
|
||||
import { provideClientHydration, withEventReplay } from '@angular/platform-browser';
|
||||
import { provideHttpClient, withFetch, withInterceptors } from '@angular/common/http';
|
||||
import { provideServiceWorker } from '@angular/service-worker';
|
||||
import { imageCacheInterceptor } from './image-cache.interceptor';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideBrowserGlobalErrorListeners(),
|
||||
provideZonelessChangeDetection(),
|
||||
provideRouter(routes), provideClientHydration(withEventReplay())
|
||||
]
|
||||
providers: [
|
||||
provideBrowserGlobalErrorListeners(),
|
||||
provideZonelessChangeDetection(),
|
||||
provideRouter(routes),
|
||||
provideClientHydration(withEventReplay()),
|
||||
provideHttpClient(withFetch(), withInterceptors([imageCacheInterceptor])),
|
||||
provideServiceWorker('ngsw-worker.js', {
|
||||
enabled: !isDevMode(),
|
||||
registrationStrategy: 'registerWhenStable:30000',
|
||||
}),
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.hero-toolbar {
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
padding-inline: clamp(1rem, 5vw, 4rem);
|
||||
}
|
||||
|
||||
.hero-toolbar .title {
|
||||
font-size: clamp(1.5rem, 4vw, 2.5rem);
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.app {
|
||||
margin: 0 auto;
|
||||
padding: clamp(1.5rem, 5vw, 3rem) 0 clamp(3rem, 6vw, 4rem);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.randomizer-card {
|
||||
max-width: 100%;
|
||||
border-radius: 1.5rem;
|
||||
}
|
||||
|
||||
.randomizer-card mat-card-content {
|
||||
padding: clamp(1.5rem, 4vw, 2.5rem);
|
||||
}
|
||||
|
||||
app-champion-randomizer {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.app {
|
||||
width: min(960px, 100% - 1.5rem);
|
||||
}
|
||||
}
|
||||
+14
-341
@@ -1,342 +1,15 @@
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * The content below * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * is only a placeholder * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * and can be replaced. * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * Delete the template below * * * * * * * * * -->
|
||||
<!-- * * * * * * * to get started with your project! * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
<mat-toolbar color="primary" class="hero-toolbar" role="banner">
|
||||
<mat-icon aria-hidden="true">casino</mat-icon>
|
||||
<span class="title">Random League Squad</span>
|
||||
</mat-toolbar>
|
||||
|
||||
<style>
|
||||
:host {
|
||||
--bright-blue: oklch(51.01% 0.274 263.83);
|
||||
--electric-violet: oklch(53.18% 0.28 296.97);
|
||||
--french-violet: oklch(47.66% 0.246 305.88);
|
||||
--vivid-pink: oklch(69.02% 0.277 332.77);
|
||||
--hot-red: oklch(61.42% 0.238 15.34);
|
||||
--orange-red: oklch(63.32% 0.24 31.68);
|
||||
|
||||
--gray-900: oklch(19.37% 0.006 300.98);
|
||||
--gray-700: oklch(36.98% 0.014 302.71);
|
||||
--gray-400: oklch(70.9% 0.015 304.04);
|
||||
|
||||
--red-to-pink-to-purple-vertical-gradient: linear-gradient(
|
||||
180deg,
|
||||
var(--orange-red) 0%,
|
||||
var(--vivid-pink) 50%,
|
||||
var(--electric-violet) 100%
|
||||
);
|
||||
|
||||
--red-to-pink-to-purple-horizontal-gradient: linear-gradient(
|
||||
90deg,
|
||||
var(--orange-red) 0%,
|
||||
var(--vivid-pink) 50%,
|
||||
var(--electric-violet) 100%
|
||||
);
|
||||
|
||||
--pill-accent: var(--bright-blue);
|
||||
|
||||
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
|
||||
"Segoe UI Symbol";
|
||||
box-sizing: border-box;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.125rem;
|
||||
color: var(--gray-900);
|
||||
font-weight: 500;
|
||||
line-height: 100%;
|
||||
letter-spacing: -0.125rem;
|
||||
margin: 0;
|
||||
font-family: "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
|
||||
"Segoe UI Symbol";
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--gray-700);
|
||||
}
|
||||
|
||||
main {
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 1rem;
|
||||
box-sizing: inherit;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.angular-logo {
|
||||
max-width: 9.2rem;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
width: 100%;
|
||||
max-width: 700px;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.content h1 {
|
||||
margin-top: 1.75rem;
|
||||
}
|
||||
|
||||
.content p {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 1px;
|
||||
background: var(--red-to-pink-to-purple-vertical-gradient);
|
||||
margin-inline: 0.5rem;
|
||||
}
|
||||
|
||||
.pill-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: start;
|
||||
flex-wrap: wrap;
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.pill {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
--pill-accent: var(--bright-blue);
|
||||
background: color-mix(in srgb, var(--pill-accent) 5%, transparent);
|
||||
color: var(--pill-accent);
|
||||
padding-inline: 0.75rem;
|
||||
padding-block: 0.375rem;
|
||||
border-radius: 2.75rem;
|
||||
border: 0;
|
||||
transition: background 0.3s ease;
|
||||
font-family: var(--inter-font);
|
||||
font-size: 0.875rem;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
line-height: 1.4rem;
|
||||
letter-spacing: -0.00875rem;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pill:hover {
|
||||
background: color-mix(in srgb, var(--pill-accent) 15%, transparent);
|
||||
}
|
||||
|
||||
.pill-group .pill:nth-child(6n + 1) {
|
||||
--pill-accent: var(--bright-blue);
|
||||
}
|
||||
.pill-group .pill:nth-child(6n + 2) {
|
||||
--pill-accent: var(--electric-violet);
|
||||
}
|
||||
.pill-group .pill:nth-child(6n + 3) {
|
||||
--pill-accent: var(--french-violet);
|
||||
}
|
||||
|
||||
.pill-group .pill:nth-child(6n + 4),
|
||||
.pill-group .pill:nth-child(6n + 5),
|
||||
.pill-group .pill:nth-child(6n + 6) {
|
||||
--pill-accent: var(--hot-red);
|
||||
}
|
||||
|
||||
.pill-group svg {
|
||||
margin-inline-start: 0.25rem;
|
||||
}
|
||||
|
||||
.social-links {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.73rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.social-links path {
|
||||
transition: fill 0.3s ease;
|
||||
fill: var(--gray-400);
|
||||
}
|
||||
|
||||
.social-links a:hover svg path {
|
||||
fill: var(--gray-900);
|
||||
}
|
||||
|
||||
@media screen and (max-width: 650px) {
|
||||
.content {
|
||||
flex-direction: column;
|
||||
width: max-content;
|
||||
}
|
||||
|
||||
.divider {
|
||||
height: 1px;
|
||||
width: 100%;
|
||||
background: var(--red-to-pink-to-purple-horizontal-gradient);
|
||||
margin-block: 1.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<main class="main">
|
||||
<div class="content">
|
||||
<div class="left-side">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 982 239"
|
||||
fill="none"
|
||||
class="angular-logo"
|
||||
>
|
||||
<g clip-path="url(#a)">
|
||||
<path
|
||||
fill="url(#b)"
|
||||
d="M388.676 191.625h30.849L363.31 31.828h-35.758l-56.215 159.797h30.848l13.174-39.356h60.061l13.256 39.356Zm-65.461-62.675 21.602-64.311h1.227l21.602 64.311h-44.431Zm126.831-7.527v70.202h-28.23V71.839h27.002v20.374h1.392c2.782-6.71 7.2-12.028 13.255-15.956 6.056-3.927 13.584-5.89 22.503-5.89 8.264 0 15.465 1.8 21.684 5.318 6.137 3.518 10.964 8.673 14.319 15.382 3.437 6.71 5.074 14.81 4.992 24.383v76.175h-28.23v-71.92c0-8.019-2.046-14.237-6.219-18.819-4.173-4.5-9.819-6.791-17.102-6.791-4.91 0-9.328 1.063-13.174 3.272-3.846 2.128-6.792 5.237-9.001 9.328-2.046 4.009-3.191 8.918-3.191 14.728ZM589.233 239c-10.147 0-18.82-1.391-26.103-4.091-7.282-2.7-13.092-6.382-17.511-10.964-4.418-4.582-7.528-9.655-9.164-15.219l25.448-6.136c1.145 2.372 2.782 4.663 4.991 6.954 2.209 2.291 5.155 4.255 8.837 5.81 3.683 1.554 8.428 2.291 14.074 2.291 8.019 0 14.647-1.964 19.884-5.81 5.237-3.845 7.856-10.227 7.856-19.064v-22.665h-1.391c-1.473 2.946-3.601 5.892-6.383 9.001-2.782 3.109-6.464 5.645-10.965 7.691-4.582 2.046-10.228 3.109-17.101 3.109-9.165 0-17.511-2.209-25.039-6.545-7.446-4.337-13.42-10.883-17.757-19.474-4.418-8.673-6.628-19.473-6.628-32.565 0-13.091 2.21-24.301 6.628-33.383 4.419-9.082 10.311-15.955 17.839-20.7 7.528-4.746 15.874-7.037 25.039-7.037 7.037 0 12.846 1.145 17.347 3.518 4.582 2.373 8.182 5.236 10.883 8.51 2.7 3.272 4.746 6.382 6.137 9.327h1.554v-19.8h27.821v121.749c0 10.228-2.454 18.737-7.364 25.447-4.91 6.709-11.538 11.7-20.048 15.055-8.509 3.355-18.165 4.991-28.884 4.991Zm.245-71.266c5.974 0 11.047-1.473 15.302-4.337 4.173-2.945 7.446-7.118 9.573-12.519 2.21-5.482 3.274-12.027 3.274-19.637 0-7.609-1.064-14.155-3.274-19.8-2.127-5.646-5.318-10.064-9.491-13.255-4.174-3.11-9.329-4.746-15.384-4.746s-11.537 1.636-15.792 4.91c-4.173 3.272-7.365 7.772-9.492 13.418-2.128 5.727-3.191 12.191-3.191 19.392 0 7.2 1.063 13.745 3.273 19.228 2.127 5.482 5.318 9.736 9.573 12.764 4.174 3.027 9.41 4.582 15.629 4.582Zm141.56-26.51V71.839h28.23v119.786h-27.412v-21.273h-1.227c-2.7 6.709-7.119 12.191-13.338 16.446-6.137 4.255-13.747 6.382-22.748 6.382-7.855 0-14.81-1.718-20.783-5.237-5.974-3.518-10.72-8.591-14.075-15.382-3.355-6.709-5.073-14.891-5.073-24.464V71.839h28.312v71.921c0 7.609 2.046 13.664 6.219 18.083 4.173 4.5 9.655 6.709 16.365 6.709 4.173 0 8.183-.982 12.111-3.028 3.927-2.045 7.118-5.072 9.655-9.082 2.537-4.091 3.764-9.164 3.764-15.218Zm65.707-109.395v159.796h-28.23V31.828h28.23Zm44.841 162.169c-7.61 0-14.402-1.391-20.457-4.091-6.055-2.7-10.883-6.791-14.32-12.109-3.518-5.319-5.237-11.946-5.237-19.801 0-6.791 1.228-12.355 3.765-16.773 2.536-4.419 5.891-7.937 10.228-10.637 4.337-2.618 9.164-4.664 14.647-6.055 5.4-1.391 11.046-2.373 16.856-3.027 7.037-.737 12.683-1.391 17.102-1.964 4.337-.573 7.528-1.555 9.574-2.782 1.963-1.309 3.027-3.273 3.027-5.973v-.491c0-5.891-1.718-10.391-5.237-13.664-3.518-3.191-8.51-4.828-15.056-4.828-6.955 0-12.356 1.473-16.447 4.5-4.009 3.028-6.71 6.546-8.183 10.719l-26.348-3.764c2.046-7.282 5.483-13.336 10.31-18.328 4.746-4.909 10.638-8.59 17.511-11.045 6.955-2.455 14.565-3.682 22.912-3.682 5.809 0 11.537.654 17.265 2.045s10.965 3.6 15.711 6.71c4.746 3.109 8.51 7.282 11.455 12.6 2.864 5.318 4.337 11.946 4.337 19.883v80.184h-27.166v-16.446h-.9c-1.719 3.355-4.092 6.464-7.201 9.328-3.109 2.864-6.955 5.237-11.619 6.955-4.828 1.718-10.229 2.536-16.529 2.536Zm7.364-20.701c5.646 0 10.556-1.145 14.729-3.354 4.173-2.291 7.364-5.237 9.655-9.001 2.292-3.763 3.355-7.854 3.355-12.273v-14.155c-.9.737-2.373 1.391-4.5 2.046-2.128.654-4.419 1.145-7.037 1.636-2.619.491-5.155.9-7.692 1.227-2.537.328-4.746.655-6.628.901-4.173.572-8.019 1.472-11.292 2.781-3.355 1.31-5.973 3.11-7.855 5.401-1.964 2.291-2.864 5.318-2.864 8.918 0 5.237 1.882 9.164 5.728 11.782 3.682 2.782 8.51 4.091 14.401 4.091Zm64.643 18.328V71.839h27.412v19.965h1.227c2.21-6.955 5.974-12.274 11.292-16.038 5.319-3.763 11.456-5.645 18.329-5.645 1.555 0 3.355.082 5.237.163 1.964.164 3.601.328 4.91.573v25.938c-1.227-.41-3.109-.819-5.646-1.146a58.814 58.814 0 0 0-7.446-.49c-5.155 0-9.738 1.145-13.829 3.354-4.091 2.209-7.282 5.236-9.655 9.164-2.373 3.927-3.519 8.427-3.519 13.5v70.448h-28.312ZM222.077 39.192l-8.019 125.923L137.387 0l84.69 39.192Zm-53.105 162.825-57.933 33.056-57.934-33.056 11.783-28.556h92.301l11.783 28.556ZM111.039 62.675l30.357 73.803H80.681l30.358-73.803ZM7.937 165.115 0 39.192 84.69 0 7.937 165.115Z"
|
||||
/>
|
||||
<path
|
||||
fill="url(#c)"
|
||||
d="M388.676 191.625h30.849L363.31 31.828h-35.758l-56.215 159.797h30.848l13.174-39.356h60.061l13.256 39.356Zm-65.461-62.675 21.602-64.311h1.227l21.602 64.311h-44.431Zm126.831-7.527v70.202h-28.23V71.839h27.002v20.374h1.392c2.782-6.71 7.2-12.028 13.255-15.956 6.056-3.927 13.584-5.89 22.503-5.89 8.264 0 15.465 1.8 21.684 5.318 6.137 3.518 10.964 8.673 14.319 15.382 3.437 6.71 5.074 14.81 4.992 24.383v76.175h-28.23v-71.92c0-8.019-2.046-14.237-6.219-18.819-4.173-4.5-9.819-6.791-17.102-6.791-4.91 0-9.328 1.063-13.174 3.272-3.846 2.128-6.792 5.237-9.001 9.328-2.046 4.009-3.191 8.918-3.191 14.728ZM589.233 239c-10.147 0-18.82-1.391-26.103-4.091-7.282-2.7-13.092-6.382-17.511-10.964-4.418-4.582-7.528-9.655-9.164-15.219l25.448-6.136c1.145 2.372 2.782 4.663 4.991 6.954 2.209 2.291 5.155 4.255 8.837 5.81 3.683 1.554 8.428 2.291 14.074 2.291 8.019 0 14.647-1.964 19.884-5.81 5.237-3.845 7.856-10.227 7.856-19.064v-22.665h-1.391c-1.473 2.946-3.601 5.892-6.383 9.001-2.782 3.109-6.464 5.645-10.965 7.691-4.582 2.046-10.228 3.109-17.101 3.109-9.165 0-17.511-2.209-25.039-6.545-7.446-4.337-13.42-10.883-17.757-19.474-4.418-8.673-6.628-19.473-6.628-32.565 0-13.091 2.21-24.301 6.628-33.383 4.419-9.082 10.311-15.955 17.839-20.7 7.528-4.746 15.874-7.037 25.039-7.037 7.037 0 12.846 1.145 17.347 3.518 4.582 2.373 8.182 5.236 10.883 8.51 2.7 3.272 4.746 6.382 6.137 9.327h1.554v-19.8h27.821v121.749c0 10.228-2.454 18.737-7.364 25.447-4.91 6.709-11.538 11.7-20.048 15.055-8.509 3.355-18.165 4.991-28.884 4.991Zm.245-71.266c5.974 0 11.047-1.473 15.302-4.337 4.173-2.945 7.446-7.118 9.573-12.519 2.21-5.482 3.274-12.027 3.274-19.637 0-7.609-1.064-14.155-3.274-19.8-2.127-5.646-5.318-10.064-9.491-13.255-4.174-3.11-9.329-4.746-15.384-4.746s-11.537 1.636-15.792 4.91c-4.173 3.272-7.365 7.772-9.492 13.418-2.128 5.727-3.191 12.191-3.191 19.392 0 7.2 1.063 13.745 3.273 19.228 2.127 5.482 5.318 9.736 9.573 12.764 4.174 3.027 9.41 4.582 15.629 4.582Zm141.56-26.51V71.839h28.23v119.786h-27.412v-21.273h-1.227c-2.7 6.709-7.119 12.191-13.338 16.446-6.137 4.255-13.747 6.382-22.748 6.382-7.855 0-14.81-1.718-20.783-5.237-5.974-3.518-10.72-8.591-14.075-15.382-3.355-6.709-5.073-14.891-5.073-24.464V71.839h28.312v71.921c0 7.609 2.046 13.664 6.219 18.083 4.173 4.5 9.655 6.709 16.365 6.709 4.173 0 8.183-.982 12.111-3.028 3.927-2.045 7.118-5.072 9.655-9.082 2.537-4.091 3.764-9.164 3.764-15.218Zm65.707-109.395v159.796h-28.23V31.828h28.23Zm44.841 162.169c-7.61 0-14.402-1.391-20.457-4.091-6.055-2.7-10.883-6.791-14.32-12.109-3.518-5.319-5.237-11.946-5.237-19.801 0-6.791 1.228-12.355 3.765-16.773 2.536-4.419 5.891-7.937 10.228-10.637 4.337-2.618 9.164-4.664 14.647-6.055 5.4-1.391 11.046-2.373 16.856-3.027 7.037-.737 12.683-1.391 17.102-1.964 4.337-.573 7.528-1.555 9.574-2.782 1.963-1.309 3.027-3.273 3.027-5.973v-.491c0-5.891-1.718-10.391-5.237-13.664-3.518-3.191-8.51-4.828-15.056-4.828-6.955 0-12.356 1.473-16.447 4.5-4.009 3.028-6.71 6.546-8.183 10.719l-26.348-3.764c2.046-7.282 5.483-13.336 10.31-18.328 4.746-4.909 10.638-8.59 17.511-11.045 6.955-2.455 14.565-3.682 22.912-3.682 5.809 0 11.537.654 17.265 2.045s10.965 3.6 15.711 6.71c4.746 3.109 8.51 7.282 11.455 12.6 2.864 5.318 4.337 11.946 4.337 19.883v80.184h-27.166v-16.446h-.9c-1.719 3.355-4.092 6.464-7.201 9.328-3.109 2.864-6.955 5.237-11.619 6.955-4.828 1.718-10.229 2.536-16.529 2.536Zm7.364-20.701c5.646 0 10.556-1.145 14.729-3.354 4.173-2.291 7.364-5.237 9.655-9.001 2.292-3.763 3.355-7.854 3.355-12.273v-14.155c-.9.737-2.373 1.391-4.5 2.046-2.128.654-4.419 1.145-7.037 1.636-2.619.491-5.155.9-7.692 1.227-2.537.328-4.746.655-6.628.901-4.173.572-8.019 1.472-11.292 2.781-3.355 1.31-5.973 3.11-7.855 5.401-1.964 2.291-2.864 5.318-2.864 8.918 0 5.237 1.882 9.164 5.728 11.782 3.682 2.782 8.51 4.091 14.401 4.091Zm64.643 18.328V71.839h27.412v19.965h1.227c2.21-6.955 5.974-12.274 11.292-16.038 5.319-3.763 11.456-5.645 18.329-5.645 1.555 0 3.355.082 5.237.163 1.964.164 3.601.328 4.91.573v25.938c-1.227-.41-3.109-.819-5.646-1.146a58.814 58.814 0 0 0-7.446-.49c-5.155 0-9.738 1.145-13.829 3.354-4.091 2.209-7.282 5.236-9.655 9.164-2.373 3.927-3.519 8.427-3.519 13.5v70.448h-28.312ZM222.077 39.192l-8.019 125.923L137.387 0l84.69 39.192Zm-53.105 162.825-57.933 33.056-57.934-33.056 11.783-28.556h92.301l11.783 28.556ZM111.039 62.675l30.357 73.803H80.681l30.358-73.803ZM7.937 165.115 0 39.192 84.69 0 7.937 165.115Z"
|
||||
/>
|
||||
</g>
|
||||
<defs>
|
||||
<radialGradient
|
||||
id="c"
|
||||
cx="0"
|
||||
cy="0"
|
||||
r="1"
|
||||
gradientTransform="rotate(118.122 171.182 60.81) scale(205.794)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
>
|
||||
<stop stop-color="#FF41F8" />
|
||||
<stop offset=".707" stop-color="#FF41F8" stop-opacity=".5" />
|
||||
<stop offset="1" stop-color="#FF41F8" stop-opacity="0" />
|
||||
</radialGradient>
|
||||
<linearGradient
|
||||
id="b"
|
||||
x1="0"
|
||||
x2="982"
|
||||
y1="192"
|
||||
y2="192"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
>
|
||||
<stop stop-color="#F0060B" />
|
||||
<stop offset="0" stop-color="#F0070C" />
|
||||
<stop offset=".526" stop-color="#CC26D5" />
|
||||
<stop offset="1" stop-color="#7702FF" />
|
||||
</linearGradient>
|
||||
<clipPath id="a"><path fill="#fff" d="M0 0h982v239H0z" /></clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
<h1>Hello, {{ title() }}</h1>
|
||||
<p>Congratulations! Your app is running. 🎉</p>
|
||||
</div>
|
||||
<div class="divider" role="separator" aria-label="Divider"></div>
|
||||
<div class="right-side">
|
||||
<div class="pill-group">
|
||||
@for (item of [
|
||||
{ title: 'Explore the Docs', link: 'https://angular.dev' },
|
||||
{ title: 'Learn with Tutorials', link: 'https://angular.dev/tutorials' },
|
||||
{ title: 'Prompt and best practices for AI', link: 'https://angular.dev/ai/develop-with-ai'},
|
||||
{ title: 'CLI Docs', link: 'https://angular.dev/tools/cli' },
|
||||
{ title: 'Angular Language Service', link: 'https://angular.dev/tools/language-service' },
|
||||
{ title: 'Angular DevTools', link: 'https://angular.dev/tools/devtools' },
|
||||
]; track item.title) {
|
||||
<a
|
||||
class="pill"
|
||||
[href]="item.link"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
<span>{{ item.title }}</span>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
height="14"
|
||||
viewBox="0 -960 960 960"
|
||||
width="14"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path
|
||||
d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
<div class="social-links">
|
||||
<a
|
||||
href="https://github.com/angular/angular"
|
||||
aria-label="Github"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
<svg
|
||||
width="25"
|
||||
height="24"
|
||||
viewBox="0 0 25 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
alt="Github"
|
||||
>
|
||||
<path
|
||||
d="M12.3047 0C5.50634 0 0 5.50942 0 12.3047C0 17.7423 3.52529 22.3535 8.41332 23.9787C9.02856 24.0946 9.25414 23.7142 9.25414 23.3871C9.25414 23.0949 9.24389 22.3207 9.23876 21.2953C5.81601 22.0377 5.09414 19.6444 5.09414 19.6444C4.53427 18.2243 3.72524 17.8449 3.72524 17.8449C2.61064 17.082 3.81137 17.0973 3.81137 17.0973C5.04697 17.1835 5.69604 18.3647 5.69604 18.3647C6.79321 20.2463 8.57636 19.7029 9.27978 19.3881C9.39052 18.5924 9.70736 18.0499 10.0591 17.7423C7.32641 17.4347 4.45429 16.3765 4.45429 11.6618C4.45429 10.3185 4.9311 9.22133 5.72065 8.36C5.58222 8.04931 5.16694 6.79833 5.82831 5.10337C5.82831 5.10337 6.85883 4.77319 9.2121 6.36459C10.1965 6.09082 11.2424 5.95546 12.2883 5.94931C13.3342 5.95546 14.3801 6.09082 15.3644 6.36459C17.7023 4.77319 18.7328 5.10337 18.7328 5.10337C19.3942 6.79833 18.9789 8.04931 18.8559 8.36C19.6403 9.22133 20.1171 10.3185 20.1171 11.6618C20.1171 16.3888 17.2409 17.4296 14.5031 17.7321C14.9338 18.1012 15.3337 18.8559 15.3337 20.0084C15.3337 21.6552 15.3183 22.978 15.3183 23.3779C15.3183 23.7009 15.5336 24.0854 16.1642 23.9623C21.0871 22.3484 24.6094 17.7341 24.6094 12.3047C24.6094 5.50942 19.0999 0 12.3047 0Z"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
<a
|
||||
href="https://twitter.com/angular"
|
||||
aria-label="Twitter"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
alt="Twitter"
|
||||
>
|
||||
<path
|
||||
d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
<a
|
||||
href="https://www.youtube.com/channel/UCbn1OgGei-DV7aSRo_HaAiw"
|
||||
aria-label="Youtube"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
<svg
|
||||
width="29"
|
||||
height="20"
|
||||
viewBox="0 0 29 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
alt="Youtube"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M27.4896 1.52422C27.9301 1.96749 28.2463 2.51866 28.4068 3.12258C29.0004 5.35161 29.0004 10 29.0004 10C29.0004 10 29.0004 14.6484 28.4068 16.8774C28.2463 17.4813 27.9301 18.0325 27.4896 18.4758C27.0492 18.9191 26.5 19.2389 25.8972 19.4032C23.6778 20 14.8068 20 14.8068 20C14.8068 20 5.93586 20 3.71651 19.4032C3.11363 19.2389 2.56449 18.9191 2.12405 18.4758C1.68361 18.0325 1.36732 17.4813 1.20683 16.8774C0.613281 14.6484 0.613281 10 0.613281 10C0.613281 10 0.613281 5.35161 1.20683 3.12258C1.36732 2.51866 1.68361 1.96749 2.12405 1.52422C2.56449 1.08095 3.11363 0.76113 3.71651 0.596774C5.93586 0 14.8068 0 14.8068 0C14.8068 0 23.6778 0 25.8972 0.596774C26.5 0.76113 27.0492 1.08095 27.4896 1.52422ZM19.3229 10L11.9036 5.77905V14.221L19.3229 10Z"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * The content above * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * is only a placeholder * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * and can be replaced. * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * End of Placeholder * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
|
||||
|
||||
<router-outlet />
|
||||
<section class="app" aria-labelledby="app-intro">
|
||||
<p id="app-intro" class="subtitle mat-body-large">
|
||||
Roll a unique champion for every lane in one click.
|
||||
</p>
|
||||
<mat-card class="randomizer-card">
|
||||
<mat-card-content>
|
||||
<app-champion-randomizer />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</section>
|
||||
@@ -1,8 +1,8 @@
|
||||
import { RenderMode, ServerRoute } from '@angular/ssr';
|
||||
|
||||
export const serverRoutes: ServerRoute[] = [
|
||||
{
|
||||
path: '**',
|
||||
renderMode: RenderMode.Prerender
|
||||
}
|
||||
{
|
||||
path: '**',
|
||||
renderMode: RenderMode.Client,
|
||||
},
|
||||
];
|
||||
+17
-17
@@ -3,23 +3,23 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { App } from './app';
|
||||
|
||||
describe('App', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [App],
|
||||
providers: [provideZonelessChangeDetection()]
|
||||
}).compileComponents();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [App],
|
||||
providers: [provideZonelessChangeDetection()],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render title', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, random-lol');
|
||||
});
|
||||
it('should render title', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, random-lol');
|
||||
});
|
||||
});
|
||||
+13
-7
@@ -1,12 +1,18 @@
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { ChampionRandomizerComponent } from './champion-randomizer.component';
|
||||
import { ImagePreloadService } from './image-preload.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
imports: [RouterOutlet],
|
||||
templateUrl: './app.html',
|
||||
styleUrl: './app.css'
|
||||
selector: 'app-root',
|
||||
imports: [MatToolbarModule, MatIconModule, MatCardModule, ChampionRandomizerComponent],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
templateUrl: './app.html',
|
||||
styleUrls: ['./app.css'],
|
||||
})
|
||||
export class App {
|
||||
protected readonly title = signal('random-lol');
|
||||
// Initialize the image preload service
|
||||
private readonly imagePreload = inject(ImagePreloadService);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
import { Injectable, inject, signal } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
import { Champion, Lane, CHAMPION_DATA_URL, LANES } from './champions.data';
|
||||
|
||||
type RemotePosition = 'TOP' | 'JUNGLE' | 'MIDDLE' | 'BOTTOM' | 'SUPPORT';
|
||||
|
||||
interface RemoteChampion {
|
||||
readonly name: string;
|
||||
readonly icon: string;
|
||||
readonly positions: ReadonlyArray<RemotePosition>;
|
||||
}
|
||||
|
||||
const POSITION_TO_LANE: Record<RemotePosition, Lane> = {
|
||||
TOP: 'top',
|
||||
JUNGLE: 'jungle',
|
||||
MIDDLE: 'mid',
|
||||
BOTTOM: 'adc',
|
||||
SUPPORT: 'support',
|
||||
};
|
||||
|
||||
const CACHE_KEY = 'lol-champions-cache';
|
||||
const CACHE_VERSION = 1;
|
||||
const CACHE_EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||
|
||||
interface CachedData {
|
||||
version: number;
|
||||
timestamp: number;
|
||||
champions: Champion[];
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ChampionDataService {
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
private readonly championsSignal = signal<Champion[]>([]);
|
||||
private readonly championsByLaneSignal = signal<Map<Lane, Champion[]>>(new Map());
|
||||
private readonly loadingSignal = signal(false);
|
||||
private readonly errorSignal = signal<string | null>(null);
|
||||
|
||||
readonly champions = this.championsSignal.asReadonly();
|
||||
readonly championsByLane = this.championsByLaneSignal.asReadonly();
|
||||
readonly loading = this.loadingSignal.asReadonly();
|
||||
readonly error = this.errorSignal.asReadonly();
|
||||
|
||||
async ensureLoaded(force = false): Promise<void> {
|
||||
if (this.loadingSignal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!force && this.championsSignal().length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to load from cache first
|
||||
if (!force && this.loadFromCache()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.loadChampions();
|
||||
}
|
||||
|
||||
async reload(): Promise<void> {
|
||||
await this.ensureLoaded(true);
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
if (typeof localStorage === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
localStorage.removeItem(CACHE_KEY);
|
||||
} catch (error) {
|
||||
console.warn('Unable to clear cache', error);
|
||||
}
|
||||
}
|
||||
|
||||
private loadFromCache(): boolean {
|
||||
if (typeof localStorage === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const cached = localStorage.getItem(CACHE_KEY);
|
||||
if (!cached) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const data: CachedData = JSON.parse(cached);
|
||||
|
||||
// Validate cache
|
||||
if (
|
||||
data.version !== CACHE_VERSION ||
|
||||
Date.now() - data.timestamp > CACHE_EXPIRY_MS ||
|
||||
!Array.isArray(data.champions) ||
|
||||
data.champions.length === 0
|
||||
) {
|
||||
this.clearCache();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.championsSignal.set(data.champions);
|
||||
this.updateChampionsByLane(data.champions);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.warn('Unable to load from cache', error);
|
||||
this.clearCache();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private saveToCache(champions: Champion[]): void {
|
||||
if (typeof localStorage === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data: CachedData = {
|
||||
version: CACHE_VERSION,
|
||||
timestamp: Date.now(),
|
||||
champions,
|
||||
};
|
||||
localStorage.setItem(CACHE_KEY, JSON.stringify(data));
|
||||
} catch (error) {
|
||||
console.warn('Unable to save to cache', error);
|
||||
}
|
||||
}
|
||||
|
||||
private async loadChampions(): Promise<void> {
|
||||
this.loadingSignal.set(true);
|
||||
this.errorSignal.set(null);
|
||||
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.http.get<Record<string, RemoteChampion>>(CHAMPION_DATA_URL)
|
||||
);
|
||||
|
||||
const champions = Object.entries(response)
|
||||
.map(([id, data]) => this.toChampion(id, data))
|
||||
.filter((champion): champion is Champion => champion !== null)
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
this.championsSignal.set(champions);
|
||||
this.updateChampionsByLane(champions);
|
||||
this.saveToCache(champions);
|
||||
} catch (error) {
|
||||
console.error('Unable to load champion data', error);
|
||||
this.errorSignal.set('Unable to load champion data right now. Please try again.');
|
||||
} finally {
|
||||
this.loadingSignal.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
private updateChampionsByLane(champions: Champion[]): void {
|
||||
const map = new Map<Lane, Champion[]>();
|
||||
|
||||
for (const lane of LANES) {
|
||||
map.set(lane, []);
|
||||
}
|
||||
|
||||
for (const champion of champions) {
|
||||
for (const role of champion.roles) {
|
||||
map.get(role)!.push(champion);
|
||||
}
|
||||
}
|
||||
|
||||
this.championsByLaneSignal.set(map);
|
||||
}
|
||||
|
||||
private toChampion(id: string, data: RemoteChampion): Champion | null {
|
||||
const roles = Array.from(
|
||||
new Set(
|
||||
data.positions
|
||||
.map((position) => POSITION_TO_LANE[position])
|
||||
.filter((role): role is Lane => role !== undefined)
|
||||
)
|
||||
);
|
||||
|
||||
if (roles.length === 0 || !data.icon) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
name: data.name,
|
||||
roles,
|
||||
icon: this.ensureHttps(data.icon),
|
||||
};
|
||||
}
|
||||
|
||||
private ensureHttps(url: string): string {
|
||||
return url.startsWith('http://') ? `https://${url.slice('http://'.length)}` : url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.randomizer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.status button {
|
||||
padding: 0 0.25rem;
|
||||
min-width: auto;
|
||||
}
|
||||
|
||||
.status.error {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.status.error button {
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
.roll-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.roll-button mat-icon {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.hint {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.hint mat-icon {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
.lane-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.lane-card {
|
||||
flex: 1 1;
|
||||
width: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: var(--mat-sys-surface-container-high);
|
||||
}
|
||||
|
||||
.lane-card mat-card-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.mat-mdc-card-content {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.champion-details {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.champion-icon {
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
|
||||
}
|
||||
|
||||
.loading-image {
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.champion-name {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.champion-name-empty {
|
||||
color: #9ca3af;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.roles-set {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
justify-content: flex-start;
|
||||
height: 100%;
|
||||
align-content: center;
|
||||
}
|
||||
|
||||
.roles-set mat-chip {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.champion-roles {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.warning-card mat-card-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.warning-card mat-icon {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.change-champion-button {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.roll-button {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<section class="randomizer" aria-live="polite">
|
||||
<header class="controls">
|
||||
<button
|
||||
type="button"
|
||||
mat-raised-button
|
||||
color="primary"
|
||||
class="roll-button"
|
||||
[disabled]="isLoading() || !hasChampions()"
|
||||
(click)="rollAssignments()"
|
||||
>
|
||||
<mat-icon aria-hidden="true">casino</mat-icon>
|
||||
<span>Roll Champions</span>
|
||||
</button>
|
||||
<div class="hint mat-body-small">
|
||||
<mat-icon aria-hidden="true">info</mat-icon>
|
||||
<span>Each roll keeps champions unique across every lane.</span>
|
||||
</div>
|
||||
@if (isLoading()) {
|
||||
<div class="status mat-body-small" aria-live="polite">
|
||||
<mat-icon aria-hidden="true">autorenew</mat-icon>
|
||||
<span>Loading champion data…</span>
|
||||
</div>
|
||||
} @else if (loadError(); as errorMessage) {
|
||||
<div class="status error mat-body-small" aria-live="polite">
|
||||
<mat-icon aria-hidden="true" color="warn">error</mat-icon>
|
||||
<span>{{ errorMessage }}</span>
|
||||
<button type="button" mat-button color="accent" (click)="retryLoad()">
|
||||
<mat-icon aria-hidden="true">refresh</mat-icon>
|
||||
<span>Retry</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</header>
|
||||
<div class="lane-grid">
|
||||
@for (assignment of laneAssignments(); track assignment.lane) {
|
||||
<mat-card class="lane-card">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ laneLabel(assignment.lane) }}</mat-card-title>
|
||||
<mat-card-subtitle>
|
||||
{{
|
||||
assignment.champion
|
||||
? 'Unique pick locked in'
|
||||
: 'Champion needed for this lane'
|
||||
}}
|
||||
</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
@if (assignment.champion; as champion) {
|
||||
<div class="champion-details">
|
||||
<img
|
||||
[ngSrc]="champion.icon"
|
||||
width="96"
|
||||
height="96"
|
||||
[class.loading-image]="isLoading()"
|
||||
[alt]="champion.name + ' portrait'"
|
||||
[priority]="true"
|
||||
class="champion-icon"
|
||||
/>
|
||||
<p class="champion-name mat-title-medium">{{ champion.name }}</p>
|
||||
</div>
|
||||
<mat-chip-set class="roles-set" [attr.aria-label]="'Roles for ' + champion.name">
|
||||
@for (role of champion.roles; track role) {
|
||||
<mat-chip>{{ roleLabel(role) }}</mat-chip>
|
||||
}
|
||||
</mat-chip-set>
|
||||
} @else {
|
||||
<p class="champion-name champion-name-empty mat-title-medium">
|
||||
No champion available
|
||||
</p>
|
||||
<p class="champion-roles mat-body-small">
|
||||
Roll again once champions finish loading.
|
||||
</p>
|
||||
}
|
||||
<button
|
||||
type="button"
|
||||
matFab
|
||||
extended
|
||||
color="accent"
|
||||
class="change-champion-button"
|
||||
[disabled]="isLoading() || !hasChampions()"
|
||||
(click)="changeChampion(assignment.lane)"
|
||||
>
|
||||
<mat-icon aria-hidden="true">refresh</mat-icon>
|
||||
Re-Roll ?
|
||||
</button>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
@if (hasMissingChampion()) {
|
||||
<mat-card class="warning-card">
|
||||
<mat-card-content>
|
||||
<mat-icon aria-hidden="true" color="warn">warning</mat-icon>
|
||||
<span>
|
||||
Unable to assign a unique champion to every lane. Add more champions to the pool.
|
||||
</span>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</section>
|
||||
@@ -0,0 +1,157 @@
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
computed,
|
||||
effect,
|
||||
inject,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { CommonModule, NgOptimizedImage } from '@angular/common';
|
||||
import { MatButton, MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { LANES, Lane, Champion } from './champions.data';
|
||||
import { ChampionDataService } from './champion-data.service';
|
||||
|
||||
interface LaneAssignmentView {
|
||||
readonly lane: Lane;
|
||||
readonly champion: Champion | null;
|
||||
readonly rolesText: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-champion-randomizer',
|
||||
imports: [
|
||||
CommonModule,
|
||||
NgOptimizedImage,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatChipsModule,
|
||||
MatIconModule,
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
templateUrl: './champion-randomizer.component.html',
|
||||
styleUrl: './champion-randomizer.component.css',
|
||||
})
|
||||
export class ChampionRandomizerComponent {
|
||||
private readonly championData = inject(ChampionDataService);
|
||||
private readonly laneTitleMap: Record<Lane, string> = {
|
||||
top: 'Top Lane',
|
||||
jungle: 'Jungle',
|
||||
mid: 'Mid Lane',
|
||||
adc: 'Bot Carry',
|
||||
support: 'Support',
|
||||
};
|
||||
|
||||
private previousChampionStamp = '';
|
||||
|
||||
protected readonly lanes = LANES;
|
||||
protected readonly champions = this.championData.champions;
|
||||
protected readonly championsByLane = this.championData.championsByLane;
|
||||
protected readonly isLoading = this.championData.loading;
|
||||
protected readonly loadError = this.championData.error;
|
||||
|
||||
protected readonly hasChampions = computed(() => this.champions().length > 0);
|
||||
|
||||
protected readonly assignments = signal<Record<Lane, Champion | null>>(
|
||||
this.createEmptyAssignments()
|
||||
);
|
||||
|
||||
protected readonly laneAssignments = computed<LaneAssignmentView[]>(() =>
|
||||
this.lanes.map((lane) => {
|
||||
const champion = this.assignments()[lane];
|
||||
const rolesText = champion
|
||||
? champion.roles.map((role) => this.laneTitleMap[role]).join(', ')
|
||||
: '';
|
||||
|
||||
return {
|
||||
lane,
|
||||
champion,
|
||||
rolesText,
|
||||
} satisfies LaneAssignmentView;
|
||||
})
|
||||
);
|
||||
|
||||
protected readonly hasMissingChampion = computed(() =>
|
||||
this.lanes.some((lane) => this.assignments()[lane] === null)
|
||||
);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (this.isLoading()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const champions = this.champions();
|
||||
if (champions.length === 0) {
|
||||
this.assignments.set(this.createEmptyAssignments());
|
||||
this.previousChampionStamp = '';
|
||||
return;
|
||||
}
|
||||
|
||||
const stamp = champions.map((champion) => champion.id).join('|');
|
||||
if (stamp !== this.previousChampionStamp) {
|
||||
this.previousChampionStamp = stamp;
|
||||
this.rollAssignments();
|
||||
}
|
||||
});
|
||||
|
||||
void this.championData.ensureLoaded();
|
||||
}
|
||||
|
||||
protected rollAssignments(): void {
|
||||
const championsByLaneMap = this.championsByLane();
|
||||
|
||||
if (championsByLaneMap.size === 0) {
|
||||
this.assignments.set(this.createEmptyAssignments());
|
||||
return;
|
||||
}
|
||||
|
||||
const selected = new Set<string>();
|
||||
const result = this.createEmptyAssignments();
|
||||
|
||||
for (const lane of this.lanes) {
|
||||
const candidates = (championsByLaneMap.get(lane) || []).filter(
|
||||
(champion) => !selected.has(champion.name)
|
||||
);
|
||||
|
||||
if (candidates.length === 0) {
|
||||
result[lane] = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
const champion = candidates[Math.floor(Math.random() * candidates.length)];
|
||||
result[lane] = champion;
|
||||
selected.add(champion.name);
|
||||
}
|
||||
|
||||
this.assignments.set(result);
|
||||
}
|
||||
|
||||
protected retryLoad(): void {
|
||||
void this.championData.reload();
|
||||
}
|
||||
|
||||
protected laneLabel(lane: Lane): string {
|
||||
return this.laneTitleMap[lane];
|
||||
}
|
||||
|
||||
protected roleLabel(role: Lane): string {
|
||||
return this.laneTitleMap[role];
|
||||
}
|
||||
|
||||
private createEmptyAssignments(): Record<Lane, Champion | null> {
|
||||
return {
|
||||
top: null,
|
||||
jungle: null,
|
||||
mid: null,
|
||||
adc: null,
|
||||
support: null,
|
||||
} satisfies Record<Lane, Champion | null>;
|
||||
}
|
||||
|
||||
changeChampion(arg0: string) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export const LANES = ['top', 'jungle', 'mid', 'adc', 'support'] as const;
|
||||
|
||||
export type Lane = (typeof LANES)[number];
|
||||
|
||||
export interface Champion {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly roles: ReadonlyArray<Lane>;
|
||||
readonly icon: string;
|
||||
}
|
||||
|
||||
export const CHAMPION_DATA_URL = '/api/champions';
|
||||
@@ -0,0 +1,29 @@
|
||||
import { HttpInterceptorFn } from '@angular/common/http';
|
||||
|
||||
/**
|
||||
* HTTP interceptor that adds cache-control headers for image requests
|
||||
* to enable browser caching of champion icons and other images.
|
||||
*/
|
||||
export const imageCacheInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
// Check if the request is for an image
|
||||
const isImageRequest =
|
||||
req.url.includes('.png') ||
|
||||
req.url.includes('.jpg') ||
|
||||
req.url.includes('.jpeg') ||
|
||||
req.url.includes('.webp') ||
|
||||
req.url.includes('.gif') ||
|
||||
req.url.includes('/champion/') ||
|
||||
req.url.includes('ddragon.leagueoflegends.com');
|
||||
|
||||
if (isImageRequest) {
|
||||
// Clone the request to add cache headers
|
||||
const cachedReq = req.clone({
|
||||
setHeaders: {
|
||||
'Cache-Control': 'public, max-age=86400, immutable',
|
||||
},
|
||||
});
|
||||
return next(cachedReq);
|
||||
}
|
||||
|
||||
return next(req);
|
||||
};
|
||||
@@ -0,0 +1,191 @@
|
||||
import { Injectable, inject, afterNextRender } from '@angular/core';
|
||||
import { ChampionDataService } from './champion-data.service';
|
||||
|
||||
const IMAGE_CACHE_NAME = 'lol-champion-images-v1';
|
||||
const CACHE_EXPIRY_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ImagePreloadService {
|
||||
private readonly championData = inject(ChampionDataService);
|
||||
private preloadedImages = new Set<string>();
|
||||
private cachePromise: Promise<Cache | null> | null = null;
|
||||
|
||||
constructor() {
|
||||
afterNextRender(() => {
|
||||
this.initCache();
|
||||
this.schedulePreload();
|
||||
});
|
||||
}
|
||||
|
||||
private async initCache(): Promise<void> {
|
||||
if (!('caches' in window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cachePromise = caches.open(IMAGE_CACHE_NAME);
|
||||
|
||||
// Clean up old cached images
|
||||
try {
|
||||
const cache = await this.cachePromise;
|
||||
if (!cache) return;
|
||||
|
||||
const requests = await cache.keys();
|
||||
const now = Date.now();
|
||||
|
||||
for (const request of requests) {
|
||||
const response = await cache.match(request);
|
||||
if (!response) continue;
|
||||
|
||||
const cachedDate = response.headers.get('x-cached-date');
|
||||
if (cachedDate) {
|
||||
const cacheAge = now - parseInt(cachedDate, 10);
|
||||
if (cacheAge > CACHE_EXPIRY_MS) {
|
||||
await cache.delete(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to clean up old cache:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private schedulePreload(): void {
|
||||
// Wait for the browser to be idle before preloading images
|
||||
if ('requestIdleCallback' in window) {
|
||||
requestIdleCallback(() => this.preloadImages(), { timeout: 5000 });
|
||||
} else {
|
||||
setTimeout(() => this.preloadImages(), 2000);
|
||||
}
|
||||
}
|
||||
|
||||
private async preloadImages(): Promise<void> {
|
||||
await this.championData.ensureLoaded();
|
||||
|
||||
const champions = this.championData.champions();
|
||||
const imagesToPreload = champions
|
||||
.map((champion) => champion.icon)
|
||||
.filter((icon) => !this.preloadedImages.has(icon));
|
||||
|
||||
if (imagesToPreload.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Preloading ${imagesToPreload.length} champion images...`);
|
||||
|
||||
// Preload images in batches to avoid overwhelming the network
|
||||
const batchSize = 10;
|
||||
for (let i = 0; i < imagesToPreload.length; i += batchSize) {
|
||||
const batch = imagesToPreload.slice(i, i + batchSize);
|
||||
await Promise.allSettled(batch.map((url) => this.preloadAndCacheImage(url)));
|
||||
|
||||
// Small delay between batches to keep the browser responsive
|
||||
if (i + batchSize < imagesToPreload.length) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Champion images preloaded and cached successfully');
|
||||
}
|
||||
|
||||
private async preloadAndCacheImage(url: string): Promise<void> {
|
||||
if (this.preloadedImages.has(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if already cached
|
||||
if (await this.isImageCached(url)) {
|
||||
this.preloadedImages.add(url);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch and cache the image
|
||||
const response = await fetch(url, {
|
||||
mode: 'cors',
|
||||
cache: 'force-cache',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch: ${response.status}`);
|
||||
}
|
||||
|
||||
// Cache the response
|
||||
await this.cacheImage(url, response.clone());
|
||||
|
||||
// Also preload in the browser's image cache
|
||||
await this.preloadImageInBrowser(url);
|
||||
|
||||
this.preloadedImages.add(url);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to preload and cache image: ${url}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
private async isImageCached(url: string): Promise<boolean> {
|
||||
if (!this.cachePromise) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const cache = await this.cachePromise;
|
||||
if (!cache) return false;
|
||||
|
||||
const response = await cache.match(url);
|
||||
return response !== undefined;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async cacheImage(url: string, response: Response): Promise<void> {
|
||||
if (!this.cachePromise) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const cache = await this.cachePromise;
|
||||
if (!cache) return;
|
||||
|
||||
// Create a new response with cache metadata
|
||||
const blob = await response.blob();
|
||||
const cachedResponse = new Response(blob, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: {
|
||||
...Object.fromEntries(response.headers.entries()),
|
||||
'x-cached-date': Date.now().toString(),
|
||||
},
|
||||
});
|
||||
|
||||
await cache.put(url, cachedResponse);
|
||||
} catch (error) {
|
||||
console.warn('Failed to cache image:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private preloadImageInBrowser(url: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => resolve();
|
||||
img.onerror = () => reject(new Error(`Failed to load: ${url}`));
|
||||
img.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cached images
|
||||
*/
|
||||
async clearCache(): Promise<void> {
|
||||
if (!('caches' in window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await caches.delete(IMAGE_CACHE_NAME);
|
||||
this.preloadedImages.clear();
|
||||
console.log('Image cache cleared');
|
||||
} catch (error) {
|
||||
console.warn('Failed to clear image cache:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { Directive, inject, input, afterNextRender } from '@angular/core';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
|
||||
/**
|
||||
* Directive to add preload link tags for images in the document head.
|
||||
* This helps the browser discover and start loading images earlier.
|
||||
*/
|
||||
@Directive({
|
||||
selector: '[appPreloadLink]',
|
||||
standalone: true,
|
||||
})
|
||||
export class PreloadLinkDirective {
|
||||
private readonly document = inject(DOCUMENT);
|
||||
|
||||
readonly src = input.required<string>({ alias: 'appPreloadLink' });
|
||||
|
||||
constructor() {
|
||||
afterNextRender(() => {
|
||||
this.addPreloadLink();
|
||||
});
|
||||
}
|
||||
|
||||
private addPreloadLink(): void {
|
||||
const url = this.src();
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if preload link already exists
|
||||
const existing = this.document.head.querySelector(`link[rel="preload"][href="${url}"]`);
|
||||
if (existing) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create and append preload link
|
||||
const link = this.document.createElement('link');
|
||||
link.rel = 'preload';
|
||||
link.as = 'image';
|
||||
link.href = url;
|
||||
|
||||
// Add fetchpriority for high priority images
|
||||
if (this.isHighPriority(url)) {
|
||||
link.setAttribute('fetchpriority', 'high');
|
||||
}
|
||||
|
||||
this.document.head.appendChild(link);
|
||||
}
|
||||
|
||||
private isHighPriority(url: string): boolean {
|
||||
// You can customize this logic based on your needs
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Include theming for Angular Material with `mat.theme()`.
|
||||
// This Sass mixin will define CSS variables that are used for styling Angular Material
|
||||
// components according to the Material 3 design spec.
|
||||
// Learn more about theming and how to use it for your application's
|
||||
// custom components at https://material.angular.dev/guide/theming
|
||||
@use '@angular/material' as mat;
|
||||
|
||||
html {
|
||||
@include mat.theme(
|
||||
(
|
||||
color: (
|
||||
primary: mat.$rose-palette,
|
||||
tertiary: mat.$red-palette,
|
||||
),
|
||||
typography: Roboto,
|
||||
density: 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
body {
|
||||
// Default the application to a light color theme. This can be changed to
|
||||
// `dark` to enable the dark color theme, or to `light dark` to defer to the
|
||||
// user's system settings.
|
||||
color-scheme: dark light;
|
||||
|
||||
// Set a default background, font and text colors for the application using
|
||||
// Angular Material's system-level CSS variables. Learn more about these
|
||||
// variables at https://material.angular.dev/guide/system-variables
|
||||
background-color: var(--mat-sys-surface);
|
||||
color: var(--mat-sys-on-surface);
|
||||
font: var(--mat-sys-body-medium);
|
||||
|
||||
// Reset the user agent margin.
|
||||
margin: 0;
|
||||
}
|
||||
+23
-11
@@ -1,13 +1,25 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>RandomLol</title>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>RandomLol</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#1976d2" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
<link rel="manifest" href="manifest.json" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
|
||||
<!-- Preconnect to champion image CDN -->
|
||||
<link rel="preconnect" href="https://ddragon.leagueoflegends.com" crossorigin />
|
||||
<link rel="dns-prefetch" href="https://ddragon.leagueoflegends.com" />
|
||||
<link rel="preconnect" href="https://cdn.merakianalytics.com" crossorigin />
|
||||
<link rel="dns-prefetch" href="https://cdn.merakianalytics.com" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
+1
-2
@@ -2,7 +2,6 @@ import { BootstrapContext, bootstrapApplication } from '@angular/platform-browse
|
||||
import { App } from './app/app';
|
||||
import { config } from './app/app.config.server';
|
||||
|
||||
const bootstrap = (context: BootstrapContext) =>
|
||||
bootstrapApplication(App, config, context);
|
||||
const bootstrap = (context: BootstrapContext) => bootstrapApplication(App, config, context);
|
||||
|
||||
export default bootstrap;
|
||||
+1
-2
@@ -2,5 +2,4 @@ import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { appConfig } from './app/app.config';
|
||||
import { App } from './app/app';
|
||||
|
||||
bootstrapApplication(App, appConfig)
|
||||
.catch((err) => console.error(err));
|
||||
bootstrapApplication(App, appConfig).catch((err) => console.error(err));
|
||||
+35
-22
@@ -1,10 +1,11 @@
|
||||
import {
|
||||
AngularNodeAppEngine,
|
||||
createNodeRequestHandler,
|
||||
isMainModule,
|
||||
writeResponseToNodeResponse,
|
||||
AngularNodeAppEngine,
|
||||
createNodeRequestHandler,
|
||||
isMainModule,
|
||||
writeResponseToNodeResponse,
|
||||
} from '@angular/ssr/node';
|
||||
import express from 'express';
|
||||
import { createProxyMiddleware } from 'http-proxy-middleware';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const browserDistFolder = join(import.meta.dirname, '../browser');
|
||||
@@ -24,27 +25,39 @@ const angularApp = new AngularNodeAppEngine();
|
||||
* ```
|
||||
*/
|
||||
|
||||
/**
|
||||
* Proxy API requests to external CDN to avoid CORS issues
|
||||
*/
|
||||
app.use(
|
||||
'/api/champions',
|
||||
createProxyMiddleware({
|
||||
target: 'https://cdn.merakianalytics.com/riot/lol/resources/latest/en-US/champions.json',
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^.*': '',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Serve static files from /browser
|
||||
*/
|
||||
app.use(
|
||||
express.static(browserDistFolder, {
|
||||
maxAge: '1y',
|
||||
index: false,
|
||||
redirect: false,
|
||||
}),
|
||||
express.static(browserDistFolder, {
|
||||
maxAge: '1y',
|
||||
index: false,
|
||||
redirect: false,
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Handle all other requests by rendering the Angular application.
|
||||
*/
|
||||
app.use((req, res, next) => {
|
||||
angularApp
|
||||
.handle(req)
|
||||
.then((response) =>
|
||||
response ? writeResponseToNodeResponse(response, res) : next(),
|
||||
)
|
||||
.catch(next);
|
||||
angularApp
|
||||
.handle(req)
|
||||
.then((response) => (response ? writeResponseToNodeResponse(response, res) : next()))
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -52,14 +65,14 @@ app.use((req, res, next) => {
|
||||
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
||||
*/
|
||||
if (isMainModule(import.meta.url) || process.env['pm_id']) {
|
||||
const port = process.env['PORT'] || 4000;
|
||||
app.listen(port, (error) => {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
const port = process.env['PORT'] || 4000;
|
||||
app.listen(port, (error) => {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.log(`Node Express server listening on http://localhost:${port}`);
|
||||
});
|
||||
console.log(`Node Express server listening on http://localhost:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
|
||||
html, body { height: 100%; }
|
||||
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
|
||||
Reference in new issue
Block a user