;
// Für Custom HTML
customHTML?: string;
customCSS?: string;
// Gemeinsame Properties
constraints?: {
aspectRatio?: string;
maxWidth?: string;
minHeight?: string;
};
}
```
### Drei Ebenen der Anpassung:
#### Level 1: Module Builder (Anfänger)
```javascript
{
type: 'modular',
modules: [
{ type: 'header', props: { title: 'Meine Karte' } }
]
}
```
#### Level 2: Template Editor (Fortgeschritten)
```handlebars
{ type: 'template', template: `
{{title}}
{{description}}
`, templateVars: { title: 'Titel', description: 'Text' } }
```
#### Level 3: Custom HTML/CSS (Experten)
```javascript
{
type: 'custom-html',
customHTML: '...
',
customCSS: '.my-card { ... }'
}
```
## 💻 Implementierungsplan
### Phase 1: Basis-Infrastruktur (Woche 1-2)
#### 1.1 Sanitization Layer
```typescript
// src/lib/services/cardSanitizer.ts
export class CardSanitizer {
sanitizeHTML(html: string): string;
sanitizeCSS(css: string): string;
validateConstraints(html: string, constraints: Constraints): boolean;
extractVariables(html: string): string[];
}
```
#### 1.2 Rendering Engine
```svelte
```
### Phase 2: Editor & Preview (Woche 3-4)
#### 2.1 HTML/CSS Editor
```svelte
```
#### 2.2 Template Variables
```typescript
interface TemplateVariable {
name: string;
type: 'text' | 'number' | 'image' | 'link' | 'list';
default?: any;
required?: boolean;
}
// Variable extraction
function extractVariables(html: string): TemplateVariable[] {
const regex = /\{\{(\w+)(?::(\w+))?\}\}/g;
const variables: TemplateVariable[] = [];
let match;
while ((match = regex.exec(html)) !== null) {
variables.push({
name: match[1],
type: match[2] || 'text',
required: true
});
}
return variables;
}
```
### Phase 3: Datenbank-Migration (Woche 5)
#### Neue Datenbank-Struktur
```sql
-- Erweiterte cards Tabelle
ALTER TABLE cards ADD COLUMN render_type TEXT DEFAULT 'modular';
ALTER TABLE cards ADD COLUMN html_content TEXT;
ALTER TABLE cards ADD COLUMN css_content TEXT;
ALTER TABLE cards ADD COLUMN template_variables JSON;
ALTER TABLE cards ADD COLUMN constraints JSON;
-- Versionierung für Custom Cards
CREATE TABLE card_versions (
id TEXT PRIMARY KEY,
card_id TEXT REFERENCES cards(id),
version INTEGER,
html_content TEXT,
css_content TEXT,
created_at TIMESTAMP,
change_note TEXT
);
```
### Phase 4: Builder Integration (Woche 6)
```svelte
(builderMode = 'visual')}>
Visual Builder (Module)
(builderMode = 'template')}>
Template Editor
(builderMode = 'code')}>
HTML/CSS Code
{#if builderMode === 'visual'}
{:else if builderMode === 'template'}
{:else}
{/if}
```
## 🏗️ Technische Architektur
### Rendering Pipeline
```
User Input (HTML/CSS)
↓
Sanitization Layer
↓
Variable Replacement
↓
Constraint Validation
↓
iframe Sandboxing
↓
Final Render
```
### Aspect Ratio Enforcement
```css
/* Container styles */
.card-container {
position: relative;
width: 100%;
aspect-ratio: var(--card-aspect-ratio, 16/9);
overflow: hidden;
}
.card-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
/* Inside iframe */
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: auto;
}
```
## 📈 Migration Strategy
### Schritt 1: Parallel-Betrieb
- Bestehendes System bleibt
- HTML-Cards als "Advanced Mode"
- Opt-in für Power-User
### Schritt 2: Feature Parity
- Card Builder unterstützt beide Modi
- Import/Export zwischen Formaten
- Template Converter
### Schritt 3: Unified System
```typescript
// Universeller Card Renderer
function renderCard(card: UnifiedCard): HTMLElement {
switch (card.type) {
case 'modular':
return renderModularCard(card);
case 'template':
return renderTemplateCard(card);
case 'custom-html':
return renderCustomHTMLCard(card);
}
}
```
## 🎯 Empfehlung
### Hybrid-Ansatz implementieren mit:
1. **Beibehaltung des modularen Systems** für 80% der Nutzer
2. **Template-System** für fortgeschrittene Anpassungen
3. **HTML/CSS-Editor** für Power-User und Entwickler
4. **Strikte Sandboxing** für Sicherheit
5. **Progressive Enhancement** - Nutzer können zwischen Modi wechseln
### Vorteile dieses Ansatzes:
- ✅ Backward Compatibility
- ✅ Verschiedene Skill-Level bedient
- ✅ Sicherheit gewährleistet
- ✅ Performance optimiert
- ✅ Wartbarkeit erhalten
### Timeline:
- **Woche 1-2**: Proof of Concept
- **Woche 3-4**: Editor & Tools
- **Woche 5**: Datenbank-Migration
- **Woche 6**: Integration
- **Woche 7-8**: Testing & Rollout
## 🚀 Nächste Schritte
1. **Proof of Concept** mit einfachem HTML-Renderer
2. **Sicherheitsaudit** der Sanitization
3. **Performance-Tests** mit komplexen Cards
4. **User Research** - Welcher Ansatz wird bevorzugt?
5. **Schrittweise Migration** beginnen
## 💡 Zusätzliche Überlegungen
### AI-Unterstützung
```typescript
// KI generiert HTML/CSS basierend auf Beschreibung
async function generateCardFromPrompt(prompt: string): Promise {
const response = await ai.generate({
prompt: `Create a card with: ${prompt}`,
constraints: ['responsive', 'aspect-ratio: 16/9', 'no-javascript']
});
return sanitizeCard(response);
}
```
### Marketplace Evolution
- Verkauf von HTML/CSS Templates
- Code-Snippets Library
- Community Challenges
- Template Converter Tools
### Monitoring & Analytics
```typescript
// Track welcher Modus am meisten genutzt wird
analytics.track('card_created', {
type: 'modular' | 'template' | 'custom-html',
complexity: calculateComplexity(card),
render_time: measureRenderTime(card)
});
```