Add comprehensive theme routing and browsing system
- Add React Router with theme browser, theme detail, and layout detail pages - Implement manifest-based theme discovery for better performance - Add Welcome component as home page with feature overview - Fix layout and styling issues with proper CSS centering - Implement introspective theme browsing (dynamically discover colors/variables) - Add layout preview system with iframe scaling - Create comprehensive theme detail page with color palette display - Fix TypeScript errors and build issues - Remove hardcoded theme assumptions in favor of dynamic discovery 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
6e6c09b5ba
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
67
CLAUDE.md
Normal file
67
CLAUDE.md
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Slide authoring and presentation tool
|
||||||
|
- Should run with no backend server required
|
||||||
|
- Data should be stored in indexdb in the browser
|
||||||
|
- leverage existing react and npm libraries
|
||||||
|
|
||||||
|
# Features
|
||||||
|
- Create new presentation
|
||||||
|
- Select theme for presentation
|
||||||
|
- Add slides to presentation and select layout for each slide based on the selected theme and it's layouts
|
||||||
|
- Add text to slide in theme layout "slots"
|
||||||
|
- Add images to slide in theme layout "slots"
|
||||||
|
- Add presentation notes to slide
|
||||||
|
- Present slides in a full screen mode
|
||||||
|
|
||||||
|
|
||||||
|
# Themes
|
||||||
|
- Themes should be baked into the app, but should be customizable
|
||||||
|
- Themes should be selectable when creating a new presentation
|
||||||
|
- Themes should be applied to all slides in the presentation
|
||||||
|
- Themes should be able to be updated after the presentation is created and presentations will be updated to reflect the new theme
|
||||||
|
- Themes should allow multiple layouts for slides that are selectable when creating a new slide
|
||||||
|
- Themes should allow for custom CSS to be applied to the presentation
|
||||||
|
- Themes should allow for custom fonts to be applied to the presentation
|
||||||
|
- Themes should allow for custom colors to be applied to the presentation
|
||||||
|
- Themes should allow for custom images to be applied to the presentation
|
||||||
|
- Themes should allow for "master slides" that have content that slide authors cannot override or change
|
||||||
|
|
||||||
|
# ROADMAP
|
||||||
|
- [x] build themeing system creating initial default theme
|
||||||
|
- [x] build theme selection system
|
||||||
|
- [ ] build theme browsing module
|
||||||
|
- [ ] build presentation creation system
|
||||||
|
- [ ] build slide creation system
|
||||||
|
- [ ] build slide authoring system
|
||||||
|
- [ ] build presentation system
|
||||||
|
|
||||||
|
# CURRENT FOCUS
|
||||||
|
## determine structure and approach for theming system
|
||||||
|
- [x] it should be flexible and allow for custom themes to be created using only html templates and css
|
||||||
|
- [x] themes and templates should be very close to native html and css so that they can be easily created and modified
|
||||||
|
-
|
||||||
|
|
||||||
|
# Code Standards
|
||||||
|
- Strongly prefer convention over configuration versus configuration over convention
|
||||||
|
- Use React for the UI, but allow for other libraries if needed and try to keep as close to html/js/css as possible
|
||||||
|
- Use functional components and hooks
|
||||||
|
- Use TypeScript for type safety, but allow for JavaScript in some cases
|
||||||
|
- **No inline styles** - All styling should be in CSS files with semantic class names
|
||||||
|
- Theme structure should be simple and easy to understand for someone familiar with html and ccss
|
||||||
|
- Theme structure should not repeat the same information in multiple places
|
||||||
|
- Theme structure should be flexible and allow for custom themes to be created using only html templates and css
|
||||||
|
- Metadata for themes should be stored as comments in the html and css files
|
||||||
|
- React compoonents and code should be modular and reusable and abide by [REACT19.md](REACT19.md)
|
||||||
|
- We should refer to [VITEBESTPRACTICES.md](VITEBESTPRACTICES.md) for best practices in Vite
|
||||||
|
-
|
||||||
|
# General Claude Guidelines
|
||||||
|
- Don't run npm commands, just tell me what to run and I'll run them myself
|
||||||
|
- When building componentns, refer to https://www.vite.dev
|
||||||
|
# Architecture
|
||||||
|
## Themes
|
||||||
|
- Themes should be stored in a directory structure under public directory that allows for easy access and modification by browser
|
||||||
|
- Themes should be stored in a directory structure that allows for easy access
|
||||||
|
|
||||||
|
- don't try to run command to restart, just tell me the command when necessary
|
||||||
|
- Add to memory. Just tell me to run build, I'll paste in results, don't try to run the command
|
||||||
|
- Add to memory. I want to make sure this approach is generally followed
|
||||||
|
- remember to always use introspection when browsing themes and details
|
311
REACT19.md
Normal file
311
REACT19.md
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
# React 19 Guidelines & Best Practices
|
||||||
|
|
||||||
|
*Based on [React 19 Release Blog](https://react.dev/blog/2024/12/05/react-19)*
|
||||||
|
|
||||||
|
## Core Philosophy
|
||||||
|
**"React 19 provides powerful tools to create more responsive, efficient web applications with simplified state management and rendering strategies."**
|
||||||
|
|
||||||
|
## Key New Features
|
||||||
|
|
||||||
|
### 1. Actions
|
||||||
|
Actions simplify data mutations and state updates by automatically managing:
|
||||||
|
- **Pending states** - know when operations are in progress
|
||||||
|
- **Optimistic updates** - update UI before server confirms
|
||||||
|
- **Error handling** - graceful error recovery
|
||||||
|
- **Form submissions** - streamlined form processing
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
// Example: Using Actions for form submission
|
||||||
|
function UpdateName({ name, updateName }) {
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form action={updateName}>
|
||||||
|
<input name="name" defaultValue={name} />
|
||||||
|
<button type="submit" disabled={isPending}>
|
||||||
|
{isPending ? 'Updating...' : 'Update'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. New Hooks
|
||||||
|
|
||||||
|
#### `useActionState`
|
||||||
|
Simplifies action handling with built-in state management:
|
||||||
|
```jsx
|
||||||
|
function MyComponent() {
|
||||||
|
const [state, formAction] = useActionState(actionFunction, initialState);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form action={formAction}>
|
||||||
|
{/* Form elements */}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `useOptimistic`
|
||||||
|
Enables optimistic UI updates for responsive user experience:
|
||||||
|
```jsx
|
||||||
|
function TodoList({ todos, addTodo }) {
|
||||||
|
const [optimisticTodos, addOptimisticTodo] = useOptimistic(
|
||||||
|
todos,
|
||||||
|
(state, newTodo) => [...state, { ...newTodo, sending: true }]
|
||||||
|
);
|
||||||
|
|
||||||
|
async function formAction(formData) {
|
||||||
|
addOptimisticTodo({ name: formData.get("name") });
|
||||||
|
await addTodo(formData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form action={formAction}>
|
||||||
|
{optimisticTodos.map(todo => (
|
||||||
|
<div key={todo.id} className={todo.sending ? "sending" : ""}>
|
||||||
|
{todo.name}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `useFormStatus`
|
||||||
|
Provides form submission status:
|
||||||
|
```jsx
|
||||||
|
function SubmitButton() {
|
||||||
|
const { pending, data, method, action } = useFormStatus();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button type="submit" disabled={pending}>
|
||||||
|
{pending ? 'Submitting...' : 'Submit'}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `use`
|
||||||
|
Reads resources during rendering:
|
||||||
|
```jsx
|
||||||
|
function Profile({ userPromise }) {
|
||||||
|
const user = use(userPromise);
|
||||||
|
|
||||||
|
return <h1>{user.name}</h1>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Improved Component Rendering
|
||||||
|
|
||||||
|
#### `ref` as a Prop
|
||||||
|
Function components can now receive `ref` as a regular prop:
|
||||||
|
```jsx
|
||||||
|
function MyInput({ placeholder, ref }) {
|
||||||
|
return <input placeholder={placeholder} ref={ref} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usage
|
||||||
|
<MyInput ref={inputRef} placeholder="Enter text" />
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Direct Context Rendering
|
||||||
|
Context can be rendered directly without `.Provider`:
|
||||||
|
```jsx
|
||||||
|
// Before React 19
|
||||||
|
<ThemeContext.Provider value={theme}>
|
||||||
|
<App />
|
||||||
|
</ThemeContext.Provider>
|
||||||
|
|
||||||
|
// React 19
|
||||||
|
<ThemeContext value={theme}>
|
||||||
|
<App />
|
||||||
|
</ThemeContext>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Cleanup Functions for Refs
|
||||||
|
```jsx
|
||||||
|
function MyComponent() {
|
||||||
|
const ref = useCallback((node) => {
|
||||||
|
if (node) {
|
||||||
|
// Setup
|
||||||
|
node.focus();
|
||||||
|
|
||||||
|
// Cleanup function
|
||||||
|
return () => {
|
||||||
|
node.blur();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <input ref={ref} />;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Metadata Support
|
||||||
|
Components can render metadata tags directly:
|
||||||
|
```jsx
|
||||||
|
function BlogPost({ post }) {
|
||||||
|
return (
|
||||||
|
<article>
|
||||||
|
<title>{post.title}</title>
|
||||||
|
<meta name="description" content={post.excerpt} />
|
||||||
|
<h1>{post.title}</h1>
|
||||||
|
<p>{post.content}</p>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Performance Enhancements
|
||||||
|
|
||||||
|
#### Resource Preloading
|
||||||
|
```jsx
|
||||||
|
import { preload, preinit } from 'react-dom';
|
||||||
|
|
||||||
|
// Preload resources
|
||||||
|
preload('/api/user', { as: 'fetch' });
|
||||||
|
preinit('/styles.css', { as: 'style' });
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Better Hydration Error Reporting
|
||||||
|
- More detailed error messages
|
||||||
|
- Better debugging information
|
||||||
|
- Improved compatibility with third-party scripts
|
||||||
|
|
||||||
|
### 5. Server Components
|
||||||
|
|
||||||
|
#### Server-Side Rendering
|
||||||
|
```jsx
|
||||||
|
// Server Component
|
||||||
|
async function BlogPost({ slug }) {
|
||||||
|
const post = await fetchPost(slug);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<article>
|
||||||
|
<h1>{post.title}</h1>
|
||||||
|
<p>{post.content}</p>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Server Actions
|
||||||
|
```jsx
|
||||||
|
// actions.js
|
||||||
|
'use server'
|
||||||
|
|
||||||
|
export async function updateUser(formData) {
|
||||||
|
const name = formData.get('name');
|
||||||
|
// Update user on server
|
||||||
|
await database.updateUser({ name });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Component
|
||||||
|
import { updateUser } from './actions.js';
|
||||||
|
|
||||||
|
function UserForm() {
|
||||||
|
return (
|
||||||
|
<form action={updateUser}>
|
||||||
|
<input name="name" />
|
||||||
|
<button type="submit">Update</button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Best Practices for Our Project
|
||||||
|
|
||||||
|
### 1. Forms and Data Management
|
||||||
|
- **Use Actions** for theme selection and configuration
|
||||||
|
- **Implement useOptimistic** for responsive theme preview
|
||||||
|
- **Leverage useFormStatus** for loading states
|
||||||
|
|
||||||
|
### 2. Component Design
|
||||||
|
- **Use ref as prop** for theme slot components
|
||||||
|
- **Implement cleanup functions** for theme CSS loading
|
||||||
|
- **Render metadata** for theme preview information
|
||||||
|
|
||||||
|
### 3. Performance
|
||||||
|
- **Preload theme assets** using new preloading APIs
|
||||||
|
- **Use Server Components** for theme discovery if server-side rendering is added
|
||||||
|
- **Implement error boundaries** with improved error handling
|
||||||
|
|
||||||
|
### 4. State Management
|
||||||
|
- **Use useActionState** for complex theme operations
|
||||||
|
- **Implement optimistic updates** for theme switching
|
||||||
|
- **Leverage new Context syntax** for theme providers
|
||||||
|
|
||||||
|
## Implementation Guidelines
|
||||||
|
|
||||||
|
### Theme Selection with Actions
|
||||||
|
```jsx
|
||||||
|
function ThemeBrowser({ themes }) {
|
||||||
|
const [selectedTheme, selectTheme] = useActionState(
|
||||||
|
async (currentState, formData) => {
|
||||||
|
const themeId = formData.get('themeId');
|
||||||
|
const theme = await loadTheme(themeId);
|
||||||
|
return theme;
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form>
|
||||||
|
{themes.map(theme => (
|
||||||
|
<button
|
||||||
|
key={theme.id}
|
||||||
|
formAction={() => selectTheme(new FormData([['themeId', theme.id]]))}
|
||||||
|
>
|
||||||
|
{theme.name}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Optimistic Theme Switching
|
||||||
|
```jsx
|
||||||
|
function ThemePreview({ currentTheme, onThemeChange }) {
|
||||||
|
const [optimisticTheme, setOptimisticTheme] = useOptimistic(
|
||||||
|
currentTheme,
|
||||||
|
(state, newTheme) => newTheme
|
||||||
|
);
|
||||||
|
|
||||||
|
async function switchTheme(newTheme) {
|
||||||
|
setOptimisticTheme(newTheme);
|
||||||
|
await onThemeChange(newTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`theme-preview theme-${optimisticTheme.id}`}>
|
||||||
|
<h3>{optimisticTheme.name}</h3>
|
||||||
|
{/* Theme preview content */}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Theme Context (New Syntax)
|
||||||
|
```jsx
|
||||||
|
function App() {
|
||||||
|
const [theme, setTheme] = useState(defaultTheme);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThemeContext value={{ theme, setTheme }}>
|
||||||
|
<ThemeBrowser />
|
||||||
|
<SlideEditor />
|
||||||
|
</ThemeContext>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Key Takeaways
|
||||||
|
|
||||||
|
1. **Embrace Actions** - Simplify form handling and state management
|
||||||
|
2. **Use Optimistic Updates** - Create responsive user interfaces
|
||||||
|
3. **Leverage New Hooks** - Reduce boilerplate code
|
||||||
|
4. **Improve Performance** - Utilize preloading and better error handling
|
||||||
|
5. **Simplify Context** - Use direct rendering without `.Provider`
|
||||||
|
6. **Handle Refs Better** - Pass refs as regular props to function components
|
69
README.md
Normal file
69
README.md
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# React + TypeScript + Vite
|
||||||
|
|
||||||
|
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||||
|
|
||||||
|
Currently, two official plugins are available:
|
||||||
|
|
||||||
|
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||||
|
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||||
|
|
||||||
|
## Expanding the ESLint configuration
|
||||||
|
|
||||||
|
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||||
|
|
||||||
|
```js
|
||||||
|
export default tseslint.config([
|
||||||
|
globalIgnores(['dist']),
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
extends: [
|
||||||
|
// Other configs...
|
||||||
|
|
||||||
|
// Remove tseslint.configs.recommended and replace with this
|
||||||
|
...tseslint.configs.recommendedTypeChecked,
|
||||||
|
// Alternatively, use this for stricter rules
|
||||||
|
...tseslint.configs.strictTypeChecked,
|
||||||
|
// Optionally, add this for stylistic rules
|
||||||
|
...tseslint.configs.stylisticTypeChecked,
|
||||||
|
|
||||||
|
// Other configs...
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||||
|
tsconfigRootDir: import.meta.dirname,
|
||||||
|
},
|
||||||
|
// other options...
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// eslint.config.js
|
||||||
|
import reactX from 'eslint-plugin-react-x'
|
||||||
|
import reactDom from 'eslint-plugin-react-dom'
|
||||||
|
|
||||||
|
export default tseslint.config([
|
||||||
|
globalIgnores(['dist']),
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
extends: [
|
||||||
|
// Other configs...
|
||||||
|
// Enable lint rules for React
|
||||||
|
reactX.configs['recommended-typescript'],
|
||||||
|
// Enable lint rules for React DOM
|
||||||
|
reactDom.configs.recommended,
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||||
|
tsconfigRootDir: import.meta.dirname,
|
||||||
|
},
|
||||||
|
// other options...
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
```
|
137
VITEBESTPRACTICES.md
Normal file
137
VITEBESTPRACTICES.md
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
# Vite Best Practices & Performance Guide
|
||||||
|
|
||||||
|
*Based on [Vite Performance Documentation](https://vite.dev/guide/performance)*
|
||||||
|
|
||||||
|
## Core Performance Principle
|
||||||
|
**"Reduce the amount of work for source files (JS/TS/CSS)"** to maintain performance as projects grow.
|
||||||
|
|
||||||
|
## Browser Setup
|
||||||
|
|
||||||
|
### Development Environment
|
||||||
|
- **Create a dev-only browser profile** without extensions
|
||||||
|
- **Use incognito mode** for faster performance
|
||||||
|
- **Don't disable browser cache** while using dev tools (it significantly slows down requests and HMR)
|
||||||
|
|
||||||
|
## Plugin Management
|
||||||
|
|
||||||
|
### Best Practices
|
||||||
|
- **Be cautious with community plugins** - they may impact performance
|
||||||
|
- **Dynamically import large dependencies** instead of importing them statically
|
||||||
|
- **Avoid long-running operations** in plugin hooks
|
||||||
|
- **Minimize file transformation time**
|
||||||
|
|
||||||
|
## Import and Resolve Optimization
|
||||||
|
|
||||||
|
### File Extensions
|
||||||
|
- **Be explicit with import paths** - use `import './Component.jsx'` instead of `import './Component'`
|
||||||
|
- **Narrow down `resolve.extensions` list** - don't include unnecessary file types
|
||||||
|
- Use common extensions first: `['.js', '.ts', '.jsx', '.tsx']`
|
||||||
|
|
||||||
|
### Module Imports
|
||||||
|
- **Avoid barrel files** that re-export multiple modules from index files
|
||||||
|
- **Import individual APIs directly** instead of from index files
|
||||||
|
- Example: Use `import { debounce } from 'lodash-es/debounce'` instead of `import { debounce } from 'lodash-es'`
|
||||||
|
|
||||||
|
## File Transformation
|
||||||
|
|
||||||
|
### Warmup Strategy
|
||||||
|
- **Use `server.warmup`** for frequently used files
|
||||||
|
- Pre-transform commonly accessed modules during dev server startup
|
||||||
|
|
||||||
|
### Native Tooling
|
||||||
|
- **Use native tooling when possible** for better performance
|
||||||
|
- Consider these alternatives:
|
||||||
|
- **Rolldown** instead of Rollup
|
||||||
|
- **LightningCSS** for CSS processing
|
||||||
|
- **`@vitejs/plugin-react-swc`** for React projects
|
||||||
|
|
||||||
|
## CSS and Styling
|
||||||
|
|
||||||
|
### CSS Optimization
|
||||||
|
- **Use CSS instead of preprocessors** when possible (native CSS is faster)
|
||||||
|
- **Import SVGs as strings/URLs** rather than components when appropriate
|
||||||
|
- **Minimize unnecessary transformations**
|
||||||
|
|
||||||
|
## Performance Profiling
|
||||||
|
|
||||||
|
### Diagnostic Tools
|
||||||
|
- **Use `vite --profile`** to generate performance profiles
|
||||||
|
- **Use `vite --debug plugin-transform`** to inspect transformation times
|
||||||
|
- **Use tools like speedscope** to analyze bottlenecks
|
||||||
|
|
||||||
|
### Monitoring
|
||||||
|
- Track build times and identify slow transformations
|
||||||
|
- Monitor bundle sizes and chunk splitting effectiveness
|
||||||
|
- Profile HMR performance during development
|
||||||
|
|
||||||
|
## Import Strategies
|
||||||
|
|
||||||
|
### Dynamic Imports
|
||||||
|
```typescript
|
||||||
|
// Good: Dynamic import for large dependencies
|
||||||
|
const heavyLibrary = await import('heavy-library');
|
||||||
|
|
||||||
|
// Bad: Static import of large library
|
||||||
|
import heavyLibrary from 'heavy-library';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Explicit Extensions
|
||||||
|
```typescript
|
||||||
|
// Good: Explicit file extension
|
||||||
|
import Component from './Component.jsx';
|
||||||
|
|
||||||
|
// Bad: Missing extension (requires resolution)
|
||||||
|
import Component from './Component';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Direct API Imports
|
||||||
|
```typescript
|
||||||
|
// Good: Direct import
|
||||||
|
import { debounce } from 'lodash-es/debounce';
|
||||||
|
|
||||||
|
// Bad: Barrel import (imports entire library)
|
||||||
|
import { debounce } from 'lodash-es';
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration Recommendations
|
||||||
|
|
||||||
|
### Resolve Extensions (in order of frequency)
|
||||||
|
```typescript
|
||||||
|
export default {
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.js', '.ts', '.jsx', '.tsx', '.json']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Server Warmup
|
||||||
|
```typescript
|
||||||
|
export default {
|
||||||
|
server: {
|
||||||
|
warmup: {
|
||||||
|
clientFiles: ['./src/components/**/*.tsx', './src/utils/**/*.ts']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development vs Production
|
||||||
|
|
||||||
|
### Development Focus
|
||||||
|
- Fast HMR and dev server startup
|
||||||
|
- Minimal transformations
|
||||||
|
- Browser-friendly module resolution
|
||||||
|
|
||||||
|
### Production Focus
|
||||||
|
- Optimized bundle sizes
|
||||||
|
- Tree shaking effectiveness
|
||||||
|
- Code splitting strategies
|
||||||
|
|
||||||
|
## Key Takeaways
|
||||||
|
|
||||||
|
1. **Minimize transformations** - every transformation adds overhead
|
||||||
|
2. **Be explicit** - help Vite resolve files faster with explicit paths
|
||||||
|
3. **Use native tools** - they're typically faster than JavaScript alternatives
|
||||||
|
4. **Profile regularly** - identify and fix performance bottlenecks early
|
||||||
|
5. **Optimize imports** - direct imports are faster than barrel imports
|
||||||
|
6. **Consider browser setup** - development environment affects performance significantly
|
23
eslint.config.js
Normal file
23
eslint.config.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import js from '@eslint/js'
|
||||||
|
import globals from 'globals'
|
||||||
|
import reactHooks from 'eslint-plugin-react-hooks'
|
||||||
|
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
import { globalIgnores } from 'eslint/config'
|
||||||
|
|
||||||
|
export default tseslint.config([
|
||||||
|
globalIgnores(['dist']),
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
extends: [
|
||||||
|
js.configs.recommended,
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
reactHooks.configs['recommended-latest'],
|
||||||
|
reactRefresh.configs.vite,
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 2020,
|
||||||
|
globals: globals.browser,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
13
index.html
Normal file
13
index.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Vite + React + TS</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
3464
package-lock.json
generated
Normal file
3464
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
package.json
Normal file
34
package.json
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"name": "slideshare",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "npm run generate-manifest && vite",
|
||||||
|
"build": "npm run generate-manifest && tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"generate-manifest": "node scripts/generate-themes-manifest.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"loglevel": "^1.9.2",
|
||||||
|
"postcss": "^8.5.6",
|
||||||
|
"react": "^19.1.1",
|
||||||
|
"react-dom": "^19.1.1",
|
||||||
|
"react-router-dom": "^7.8.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.33.0",
|
||||||
|
"@types/node": "^24.3.0",
|
||||||
|
"@types/react": "^19.1.10",
|
||||||
|
"@types/react-dom": "^19.1.7",
|
||||||
|
"@vitejs/plugin-react": "^5.0.0",
|
||||||
|
"eslint": "^9.33.0",
|
||||||
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.20",
|
||||||
|
"globals": "^16.3.0",
|
||||||
|
"typescript": "~5.8.3",
|
||||||
|
"typescript-eslint": "^8.39.1",
|
||||||
|
"vite": "^7.1.2"
|
||||||
|
}
|
||||||
|
}
|
15
public/themes-manifest.json
Normal file
15
public/themes-manifest.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"themes": {
|
||||||
|
"default": {
|
||||||
|
"id": "default",
|
||||||
|
"cssFile": "style.css",
|
||||||
|
"layouts": [
|
||||||
|
"content-slide",
|
||||||
|
"image-slide",
|
||||||
|
"title-slide"
|
||||||
|
],
|
||||||
|
"hasMasterSlide": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"generated": "2025-08-20T14:58:18.957Z"
|
||||||
|
}
|
8
public/themes/default/layouts/content-slide.html
Normal file
8
public/themes/default/layouts/content-slide.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<div class="slide layout-content-slide">
|
||||||
|
<h1 class="slot title-slot" data-slot="title" data-placeholder="Slide Title" data-required>
|
||||||
|
{{title}}
|
||||||
|
</h1>
|
||||||
|
<div class="slot content-area" data-slot="content" data-placeholder="Your content here..." data-multiline="true">
|
||||||
|
{{content}}
|
||||||
|
</div>
|
||||||
|
</div>
|
11
public/themes/default/layouts/image-slide.html
Normal file
11
public/themes/default/layouts/image-slide.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<div class="slide layout-image-slide">
|
||||||
|
<h1 class="slot title-slot" data-slot="title" data-placeholder="Slide Title" data-required>
|
||||||
|
{{title}}
|
||||||
|
</h1>
|
||||||
|
<div class="slot image-container" data-slot="image" data-placeholder="Click to add image" data-accept="image/*">
|
||||||
|
{{#image}}
|
||||||
|
<img src="{{image}}" alt="{{imageAlt}}" />
|
||||||
|
{{/image}}
|
||||||
|
</div>
|
||||||
|
<input type="text" class="slot image-alt" data-slot="image-alt" data-placeholder="Image description" data-hidden="true">
|
||||||
|
</div>
|
8
public/themes/default/layouts/title-slide.html
Normal file
8
public/themes/default/layouts/title-slide.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<div class="slide layout-title-slide">
|
||||||
|
<h1 class="slot title-slot" data-slot="title" data-placeholder="Presentation Title" data-required>
|
||||||
|
{{title}}
|
||||||
|
</h1>
|
||||||
|
<h2 class="slot subtitle-slot" data-slot="subtitle" data-placeholder="Subtitle or tagline">
|
||||||
|
{{subtitle}}
|
||||||
|
</h2>
|
||||||
|
</div>
|
3
public/themes/default/master-slide.html
Normal file
3
public/themes/default/master-slide.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div class="master-slide footer">
|
||||||
|
{{footerText}}
|
||||||
|
</div>
|
192
public/themes/default/style.css
Normal file
192
public/themes/default/style.css
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* Theme: Default
|
||||||
|
* Name: Default Theme
|
||||||
|
* Description: Clean and simple theme suitable for any presentation
|
||||||
|
* Author: Michael Mainguy (mike.mainguy@gmail.com)
|
||||||
|
* Version: 0.1.0
|
||||||
|
*/
|
||||||
|
:root {
|
||||||
|
--theme-primary: #2563eb;
|
||||||
|
--theme-secondary: #64748b;
|
||||||
|
--theme-accent: #0ea5e9;
|
||||||
|
--theme-background: #000000;
|
||||||
|
--theme-text: #ffffff;
|
||||||
|
--theme-text-secondary: #64748b;
|
||||||
|
|
||||||
|
--theme-font-heading: 'Inter', system-ui, sans-serif;
|
||||||
|
--theme-font-body: 'Inter', system-ui, sans-serif;
|
||||||
|
--theme-font-code: 'JetBrains Mono', 'Consolas', monospace;
|
||||||
|
|
||||||
|
--slide-width: 100vw;
|
||||||
|
--slide-height: 100vh;
|
||||||
|
--slide-padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Base slide container */
|
||||||
|
.slide {
|
||||||
|
width: var(--slide-width);
|
||||||
|
height: var(--slide-height);
|
||||||
|
background: var(--theme-background);
|
||||||
|
color: var(--theme-text);
|
||||||
|
font-family: var(--theme-font-body);
|
||||||
|
padding: var(--slide-padding);
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Master slide elements */
|
||||||
|
.master-slide {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.master-slide.footer {
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
padding: 1rem;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Slot styles */
|
||||||
|
.slot {
|
||||||
|
position: relative;
|
||||||
|
border: 2px dashed transparent;
|
||||||
|
min-height: 2rem;
|
||||||
|
transition: border-color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot:hover,
|
||||||
|
.slot.editing {
|
||||||
|
border-color: var(--theme-accent);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot.empty {
|
||||||
|
border-color: var(--theme-secondary);
|
||||||
|
opacity: 0.5;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot.empty::before {
|
||||||
|
content: attr(data-placeholder);
|
||||||
|
color: var(--theme-text-secondary);
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Text slots */
|
||||||
|
.slot[data-type="title"] {
|
||||||
|
font-family: var(--theme-font-heading);
|
||||||
|
font-weight: bold;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot[data-type="subtitle"] {
|
||||||
|
font-family: var(--theme-font-heading);
|
||||||
|
line-height: 1.4;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot[data-type="text"] {
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Image slots */
|
||||||
|
.slot[data-type="image"] {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #f8fafc;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot[data-type="image"] img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layout-specific styles */
|
||||||
|
|
||||||
|
/* Title slide layout */
|
||||||
|
.layout-title-slide {
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-title-slide .slot[data-slot="title"] {
|
||||||
|
font-size: clamp(2rem, 5vw, 4rem);
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
color: var(--theme-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-title-slide .slot[data-slot="subtitle"] {
|
||||||
|
font-size: clamp(1rem, 2.5vw, 2rem);
|
||||||
|
color: var(--theme-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Content slide layout */
|
||||||
|
.layout-content-slide .slot[data-slot="title"] {
|
||||||
|
font-size: clamp(1.5rem, 3vw, 2.5rem);
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
border-bottom: 2px solid var(--theme-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-content-slide .slot[data-slot="content"] {
|
||||||
|
font-size: clamp(1rem, 1.5vw, 1.25rem);
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Image slide layout */
|
||||||
|
.layout-image-slide .slot[data-slot="title"] {
|
||||||
|
font-size: clamp(1.5rem, 3vw, 2.5rem);
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-image-slide .slot[data-slot="image"] {
|
||||||
|
flex: 1;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive adjustments */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
:root {
|
||||||
|
--slide-padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-title-slide .slot[data-slot="title"] {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-content-slide .slot[data-slot="title"] {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print styles for presentations */
|
||||||
|
@media print {
|
||||||
|
.slide {
|
||||||
|
page-break-after: always;
|
||||||
|
width: 100%;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot {
|
||||||
|
border: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot.empty::before {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
1
public/vite.svg
Normal file
1
public/vite.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
74
scripts/generate-themes-manifest.js
Normal file
74
scripts/generate-themes-manifest.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
const PUBLIC_THEMES_DIR = path.join(__dirname, '..', 'public', 'themes');
|
||||||
|
const MANIFEST_OUTPUT = path.join(__dirname, '..', 'public', 'themes-manifest.json');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a manifest of all available themes and their layouts
|
||||||
|
*/
|
||||||
|
async function generateThemesManifest() {
|
||||||
|
const manifest = {
|
||||||
|
themes: {},
|
||||||
|
generated: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check if themes directory exists
|
||||||
|
if (!fs.existsSync(PUBLIC_THEMES_DIR)) {
|
||||||
|
console.warn('Themes directory not found:', PUBLIC_THEMES_DIR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read all theme directories
|
||||||
|
const themeDirectories = fs.readdirSync(PUBLIC_THEMES_DIR, { withFileTypes: true })
|
||||||
|
.filter(dirent => dirent.isDirectory())
|
||||||
|
.map(dirent => dirent.name);
|
||||||
|
|
||||||
|
for (const themeId of themeDirectories) {
|
||||||
|
const themePath = path.join(PUBLIC_THEMES_DIR, themeId);
|
||||||
|
const layoutsPath = path.join(themePath, 'layouts');
|
||||||
|
|
||||||
|
// Check for required files
|
||||||
|
const styleFile = path.join(themePath, 'style.css');
|
||||||
|
if (!fs.existsSync(styleFile)) {
|
||||||
|
console.warn(`Theme ${themeId} missing style.css, skipping`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const themeInfo = {
|
||||||
|
id: themeId,
|
||||||
|
cssFile: 'style.css',
|
||||||
|
layouts: [],
|
||||||
|
hasMasterSlide: fs.existsSync(path.join(themePath, 'master-slide.html'))
|
||||||
|
};
|
||||||
|
|
||||||
|
// Discover layouts
|
||||||
|
if (fs.existsSync(layoutsPath)) {
|
||||||
|
const layoutFiles = fs.readdirSync(layoutsPath)
|
||||||
|
.filter(file => file.endsWith('.html'))
|
||||||
|
.map(file => path.basename(file, '.html'));
|
||||||
|
|
||||||
|
themeInfo.layouts = layoutFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest.themes[themeId] = themeInfo;
|
||||||
|
console.log(`✓ Found theme: ${themeId} with ${themeInfo.layouts.length} layouts`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write manifest file
|
||||||
|
fs.writeFileSync(MANIFEST_OUTPUT, JSON.stringify(manifest, null, 2));
|
||||||
|
console.log(`✓ Generated themes manifest: ${MANIFEST_OUTPUT}`);
|
||||||
|
console.log(`✓ Found ${Object.keys(manifest.themes).length} themes total`);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error generating themes manifest:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateThemesManifest();
|
90
src/App.css
Normal file
90
src/App.css
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/* App Layout */
|
||||||
|
.app-root {
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
text-align: left;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-header {
|
||||||
|
padding: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
background: #ffffff;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-header h1 {
|
||||||
|
margin: 0;
|
||||||
|
color: #1f2937;
|
||||||
|
font-size: 2rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-header p {
|
||||||
|
margin: 0.5rem 0 0 0;
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-main {
|
||||||
|
padding: 2rem;
|
||||||
|
max-width: 1400px;
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-theme-section {
|
||||||
|
margin-top: 2rem;
|
||||||
|
padding: 1.5rem;
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background: #f9fafb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-theme-title {
|
||||||
|
margin: 0 0 1rem 0;
|
||||||
|
color: #1f2937;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-theme-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-theme-item {
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-theme-item strong {
|
||||||
|
color: #1f2937;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive Design */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.app-main {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-theme-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-header {
|
||||||
|
padding: 1.5rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-header h1 {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
}
|
26
src/App.tsx
Normal file
26
src/App.tsx
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'
|
||||||
|
import { ThemeBrowser, ThemeDetailPage, LayoutDetailPage } from './components/themes'
|
||||||
|
import { AppHeader } from './components/AppHeader'
|
||||||
|
import { Welcome } from './components/Welcome'
|
||||||
|
import './App.css'
|
||||||
|
import './components/themes/ThemeBrowser.css'
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
return (
|
||||||
|
<Router>
|
||||||
|
<div className="app-root">
|
||||||
|
<AppHeader />
|
||||||
|
<main className="app-main">
|
||||||
|
<Routes>
|
||||||
|
<Route path="/" element={<Welcome />} />
|
||||||
|
<Route path="/themes" element={<ThemeBrowser />} />
|
||||||
|
<Route path="/themes/:themeId" element={<ThemeDetailPage />} />
|
||||||
|
<Route path="/themes/:themeId/layouts/:layoutId" element={<LayoutDetailPage />} />
|
||||||
|
</Routes>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</Router>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App
|
1
src/assets/react.svg
Normal file
1
src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
After Width: | Height: | Size: 4.0 KiB |
61
src/components/AppHeader.tsx
Normal file
61
src/components/AppHeader.tsx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
|
export const AppHeader: React.FC = () => {
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
const getPageTitle = () => {
|
||||||
|
if (location.pathname === '/') {
|
||||||
|
return 'Welcome to Slideshare';
|
||||||
|
}
|
||||||
|
if (location.pathname === '/themes') {
|
||||||
|
return 'Theme Browser';
|
||||||
|
}
|
||||||
|
if (location.pathname.includes('/themes/')) {
|
||||||
|
const segments = location.pathname.split('/');
|
||||||
|
if (segments.length === 3) {
|
||||||
|
return `Theme: ${segments[2]}`;
|
||||||
|
}
|
||||||
|
if (segments.length === 5 && segments[3] === 'layouts') {
|
||||||
|
return `Layout: ${segments[4]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'Slideshare';
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPageDescription = () => {
|
||||||
|
if (location.pathname === '/') {
|
||||||
|
return 'Create beautiful presentations with customizable themes';
|
||||||
|
}
|
||||||
|
if (location.pathname === '/themes') {
|
||||||
|
return 'Browse and select themes for your presentations';
|
||||||
|
}
|
||||||
|
if (location.pathname.includes('/themes/')) {
|
||||||
|
const segments = location.pathname.split('/');
|
||||||
|
if (segments.length === 3) {
|
||||||
|
return 'View theme details, layouts, and color palette';
|
||||||
|
}
|
||||||
|
if (segments.length === 5 && segments[3] === 'layouts') {
|
||||||
|
return 'View layout template, slots, and configuration';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'Slide authoring and presentation tool';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header className="app-header">
|
||||||
|
<nav className="app-nav">
|
||||||
|
<Link to="/" className="app-logo">
|
||||||
|
Home
|
||||||
|
</Link>
|
||||||
|
<Link to="/themes" className="app-logo">
|
||||||
|
Slideshare
|
||||||
|
</Link>
|
||||||
|
</nav>
|
||||||
|
<div className="page-title-section">
|
||||||
|
<h1 className="page-title">{getPageTitle()}</h1>
|
||||||
|
<p className="page-description">{getPageDescription()}</p>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
};
|
124
src/components/Welcome.tsx
Normal file
124
src/components/Welcome.tsx
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
export const Welcome: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<div className="welcome-page">
|
||||||
|
<section className="hero-section">
|
||||||
|
<h1 className="hero-title">Welcome to Slideshare</h1>
|
||||||
|
<p className="hero-subtitle">
|
||||||
|
Create beautiful presentations with customizable themes and layouts
|
||||||
|
</p>
|
||||||
|
<div className="hero-actions">
|
||||||
|
<Link to="/themes" className="primary-button">
|
||||||
|
Browse Themes
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="features-section">
|
||||||
|
<h2 className="features-title">Features</h2>
|
||||||
|
<div className="features-grid">
|
||||||
|
<div className="feature-card">
|
||||||
|
<h3 className="feature-title">Theme System</h3>
|
||||||
|
<p className="feature-description">
|
||||||
|
Choose from professionally designed themes with customizable colors and layouts
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="feature-card">
|
||||||
|
<h3 className="feature-title">Multiple Layouts</h3>
|
||||||
|
<p className="feature-description">
|
||||||
|
Each theme includes various slide layouts for titles, content, images, and more
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="feature-card">
|
||||||
|
<h3 className="feature-title">No Backend Required</h3>
|
||||||
|
<p className="feature-description">
|
||||||
|
Works entirely in your browser with IndexDB storage - no server needed
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="feature-card">
|
||||||
|
<h3 className="feature-title">Presentation Notes</h3>
|
||||||
|
<p className="feature-description">
|
||||||
|
Add speaker notes to each slide for better presentation preparation
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="feature-card">
|
||||||
|
<h3 className="feature-title">Full Screen Mode</h3>
|
||||||
|
<p className="feature-description">
|
||||||
|
Present your slides in distraction-free full screen mode
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="feature-card">
|
||||||
|
<h3 className="feature-title">Customizable</h3>
|
||||||
|
<p className="feature-description">
|
||||||
|
Themes support custom CSS, fonts, colors, and images
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="getting-started-section">
|
||||||
|
<h2 className="section-title">Getting Started</h2>
|
||||||
|
<div className="steps-list">
|
||||||
|
<div className="step-item">
|
||||||
|
<div className="step-number">1</div>
|
||||||
|
<div className="step-content">
|
||||||
|
<h3 className="step-title">Browse Themes</h3>
|
||||||
|
<p className="step-description">
|
||||||
|
Explore available themes and preview their layouts
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="step-item">
|
||||||
|
<div className="step-number">2</div>
|
||||||
|
<div className="step-content">
|
||||||
|
<h3 className="step-title">Create Presentation</h3>
|
||||||
|
<p className="step-description">
|
||||||
|
Start a new presentation using your chosen theme
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="step-item">
|
||||||
|
<div className="step-number">3</div>
|
||||||
|
<div className="step-content">
|
||||||
|
<h3 className="step-title">Add Content</h3>
|
||||||
|
<p className="step-description">
|
||||||
|
Fill in text, images, and other content using theme layouts
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="step-item">
|
||||||
|
<div className="step-number">4</div>
|
||||||
|
<div className="step-content">
|
||||||
|
<h3 className="step-title">Present</h3>
|
||||||
|
<p className="step-description">
|
||||||
|
Share your presentation in full screen mode
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="cta-section">
|
||||||
|
<div className="cta-content">
|
||||||
|
<h2 className="cta-title">Ready to Create?</h2>
|
||||||
|
<p className="cta-description">
|
||||||
|
Start building your presentation with our theme collection
|
||||||
|
</p>
|
||||||
|
<Link to="/themes" className="primary-button">
|
||||||
|
Explore Themes
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
203
src/components/themes/LayoutDetailPage.tsx
Normal file
203
src/components/themes/LayoutDetailPage.tsx
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { useParams, Link } from 'react-router-dom';
|
||||||
|
import type { Theme, SlideLayout } from '../../types/theme';
|
||||||
|
import { getTheme } from '../../themes';
|
||||||
|
import { LayoutPreview } from './LayoutPreview';
|
||||||
|
|
||||||
|
export const LayoutDetailPage: React.FC = () => {
|
||||||
|
const { themeId, layoutId } = useParams<{ themeId: string; layoutId: string }>();
|
||||||
|
const [theme, setTheme] = useState<Theme | null>(null);
|
||||||
|
const [layout, setLayout] = useState<SlideLayout | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [viewMode, setViewMode] = useState<'preview' | 'template' | 'slots'>('preview');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadThemeAndLayout = async () => {
|
||||||
|
if (!themeId || !layoutId) {
|
||||||
|
setError('Missing theme ID or layout ID');
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const themeData = await getTheme(themeId);
|
||||||
|
if (!themeData) {
|
||||||
|
setError(`Theme "${themeId}" not found`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const layoutData = themeData.layouts.find((l: SlideLayout) => l.id === layoutId);
|
||||||
|
if (!layoutData) {
|
||||||
|
setError(`Layout "${layoutId}" not found in theme "${themeId}"`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTheme(themeData);
|
||||||
|
setLayout(layoutData);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to load theme and layout');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadThemeAndLayout();
|
||||||
|
}, [themeId, layoutId]);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="layout-detail-page">
|
||||||
|
<div className="loading-spinner">Loading layout...</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="layout-detail-page">
|
||||||
|
<div className="error-message">
|
||||||
|
<h2>Error</h2>
|
||||||
|
<p>{error}</p>
|
||||||
|
<Link to="/themes" className="back-link">← Back to Themes</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!theme || !layout) {
|
||||||
|
return (
|
||||||
|
<div className="layout-detail-page">
|
||||||
|
<div className="not-found">
|
||||||
|
<h2>Layout Not Found</h2>
|
||||||
|
<p>The requested layout could not be found.</p>
|
||||||
|
<Link to="/themes" className="back-link">← Back to Themes</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="layout-detail-page">
|
||||||
|
<header className="layout-detail-header">
|
||||||
|
<nav className="breadcrumb">
|
||||||
|
<Link to="/themes">Themes</Link>
|
||||||
|
<span className="separator">›</span>
|
||||||
|
<Link to={`/themes/${theme.id}`}>{theme.name}</Link>
|
||||||
|
<span className="separator">›</span>
|
||||||
|
<span className="current">{layout.name}</span>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div className="layout-info">
|
||||||
|
<h1 className="layout-name">{layout.name}</h1>
|
||||||
|
<p className="layout-description">{layout.description}</p>
|
||||||
|
<div className="layout-stats">
|
||||||
|
<span className="slot-count">{layout.slots.length} slots</span>
|
||||||
|
<span className="theme-name">from {theme.name}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="view-mode-selector">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`mode-button ${viewMode === 'preview' ? 'active' : ''}`}
|
||||||
|
onClick={() => setViewMode('preview')}
|
||||||
|
>
|
||||||
|
Preview
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`mode-button ${viewMode === 'template' ? 'active' : ''}`}
|
||||||
|
onClick={() => setViewMode('template')}
|
||||||
|
>
|
||||||
|
Template
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`mode-button ${viewMode === 'slots' ? 'active' : ''}`}
|
||||||
|
onClick={() => setViewMode('slots')}
|
||||||
|
>
|
||||||
|
Slots
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main className="layout-content">
|
||||||
|
{viewMode === 'preview' && (
|
||||||
|
<section className="preview-section">
|
||||||
|
<h2>Layout Preview</h2>
|
||||||
|
<div className="large-preview">
|
||||||
|
<LayoutPreview layout={layout} theme={theme} />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{viewMode === 'template' && (
|
||||||
|
<section className="template-section">
|
||||||
|
<h2>HTML Template</h2>
|
||||||
|
<div className="template-code">
|
||||||
|
<pre><code>{layout.htmlTemplate}</code></pre>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{viewMode === 'slots' && (
|
||||||
|
<section className="slots-section">
|
||||||
|
<h2>Slot Configuration</h2>
|
||||||
|
<div className="slots-grid">
|
||||||
|
{layout.slots.map((slot) => (
|
||||||
|
<div key={slot.id} className="slot-card">
|
||||||
|
<div className="slot-header">
|
||||||
|
<h3 className="slot-id">{slot.id}</h3>
|
||||||
|
<span className={`slot-type ${slot.type}`}>{slot.type}</span>
|
||||||
|
{slot.required && <span className="required-badge">Required</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="slot-details">
|
||||||
|
{slot.placeholder && (
|
||||||
|
<div className="slot-field">
|
||||||
|
<strong>Placeholder:</strong> {slot.placeholder}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{slot.defaultContent && (
|
||||||
|
<div className="slot-field">
|
||||||
|
<strong>Default Content:</strong> {slot.defaultContent}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{slot.className && (
|
||||||
|
<div className="slot-field">
|
||||||
|
<strong>CSS Class:</strong> <code>{slot.className}</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{slot.style && (
|
||||||
|
<div className="slot-field">
|
||||||
|
<strong>Inline Style:</strong> <code>{slot.style}</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{slot.attributes && Object.keys(slot.attributes).length > 0 && (
|
||||||
|
<div className="slot-field">
|
||||||
|
<strong>Attributes:</strong>
|
||||||
|
<div className="attributes-list">
|
||||||
|
{Object.entries(slot.attributes).map(([key, value]) => (
|
||||||
|
<div key={key} className="attribute-item">
|
||||||
|
<code>{key}="{value}"</code>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
69
src/components/themes/LayoutPreview.tsx
Normal file
69
src/components/themes/LayoutPreview.tsx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import React, { useRef, useEffect } from 'react';
|
||||||
|
import type { SlideLayout, Theme } from '../../types/theme';
|
||||||
|
import { renderTemplateWithSampleData, createPreviewDocument } from '../../utils/templateRenderer';
|
||||||
|
|
||||||
|
interface LayoutPreviewProps {
|
||||||
|
layout: SlideLayout;
|
||||||
|
theme: Theme;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LayoutPreview: React.FC<LayoutPreviewProps> = ({
|
||||||
|
layout,
|
||||||
|
theme,
|
||||||
|
className = ''
|
||||||
|
}) => {
|
||||||
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!iframeRef.current) return;
|
||||||
|
|
||||||
|
const iframe = iframeRef.current;
|
||||||
|
|
||||||
|
// Render the template with sample data
|
||||||
|
const renderedTemplate = renderTemplateWithSampleData(layout.htmlTemplate, layout);
|
||||||
|
|
||||||
|
// Create the preview document with theme CSS
|
||||||
|
const themeCssUrl = `${theme.basePath}/${theme.cssFile}`;
|
||||||
|
const previewDocument = createPreviewDocument(renderedTemplate, themeCssUrl);
|
||||||
|
|
||||||
|
// Write the document to the iframe
|
||||||
|
const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;
|
||||||
|
if (iframeDoc) {
|
||||||
|
iframeDoc.open();
|
||||||
|
iframeDoc.write(previewDocument);
|
||||||
|
iframeDoc.close();
|
||||||
|
}
|
||||||
|
}, [layout, theme]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`layout-preview ${className}`}>
|
||||||
|
<div className="layout-preview-header">
|
||||||
|
<h5 className="layout-preview-title">{layout.name}</h5>
|
||||||
|
<span className="layout-preview-slots">
|
||||||
|
{layout.slots.length} slot{layout.slots.length !== 1 ? 's' : ''}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="layout-preview-container">
|
||||||
|
<iframe
|
||||||
|
ref={iframeRef}
|
||||||
|
className="layout-preview-frame"
|
||||||
|
title={`Preview of ${layout.name}`}
|
||||||
|
sandbox="allow-same-origin"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="layout-preview-details">
|
||||||
|
<p className="layout-preview-description">{layout.description}</p>
|
||||||
|
<div className="layout-preview-slot-types">
|
||||||
|
{Array.from(new Set(layout.slots.map(slot => slot.type))).map(type => (
|
||||||
|
<span key={type} className={`slot-type-badge slot-type-${type}`}>
|
||||||
|
{type}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
482
src/components/themes/ThemeBrowser.css
Normal file
482
src/components/themes/ThemeBrowser.css
Normal file
@ -0,0 +1,482 @@
|
|||||||
|
.theme-browser {
|
||||||
|
width: 100%;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-browser-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
border-bottom: 2px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-browser-header h2 {
|
||||||
|
margin: 0;
|
||||||
|
color: #1f2937;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-count {
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
background: #f3f4f6;
|
||||||
|
padding: 0.25rem 0.75rem;
|
||||||
|
border-radius: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loading and error states */
|
||||||
|
.theme-browser.loading,
|
||||||
|
.theme-browser.error,
|
||||||
|
.theme-browser.empty {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
text-align: center;
|
||||||
|
color: #ef4444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message h3 {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
text-align: center;
|
||||||
|
color: #6b7280;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state h3 {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Theme list */
|
||||||
|
.theme-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-card {
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 1.25rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
background: white;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-card:hover {
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-card.selected {
|
||||||
|
border-color: #3b82f6;
|
||||||
|
background: #eff6ff;
|
||||||
|
box-shadow: 0 0 0 1px #3b82f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Theme header */
|
||||||
|
.theme-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-info {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-name {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
font-size: 1.125rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-description {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-author,
|
||||||
|
.theme-version {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
padding: 0.125rem 0.5rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-author {
|
||||||
|
background: #f3f4f6;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-version {
|
||||||
|
background: #dbeafe;
|
||||||
|
color: #1e40af;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.expand-button {
|
||||||
|
background: #f9fafb;
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
width: 2rem;
|
||||||
|
height: 2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: #6b7280;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.expand-button:hover {
|
||||||
|
background: #e5e7eb;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Theme preview */
|
||||||
|
.theme-preview {
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
clear: both;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-palette {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-swatch {
|
||||||
|
width: 2rem;
|
||||||
|
height: 2rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
|
cursor: help;
|
||||||
|
flex-shrink: 0;
|
||||||
|
background: #f3f4f6; /* fallback for non-color variables */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Theme details */
|
||||||
|
.theme-details {
|
||||||
|
border-top: 1px solid #e5e7eb;
|
||||||
|
padding-top: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-details h4 {
|
||||||
|
margin: 0 0 0.75rem 0;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-layouts,
|
||||||
|
.theme-variables,
|
||||||
|
.theme-meta {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-layouts:last-child,
|
||||||
|
.theme-variables:last-child,
|
||||||
|
.theme-meta:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background: #f9fafb;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-name {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-slots {
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-list {
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-bottom: 1px solid #f3f4f6;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-name {
|
||||||
|
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
|
||||||
|
color: #7c3aed;
|
||||||
|
background: #f5f3ff;
|
||||||
|
padding: 0.125rem 0.25rem;
|
||||||
|
border-radius: 0.125rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-value {
|
||||||
|
color: #374151;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.25rem 0;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
border-bottom: 1px solid #f3f4f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item strong {
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layout Preview Styles */
|
||||||
|
.layout-preview {
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
overflow: hidden;
|
||||||
|
background: white;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview:hover {
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-header {
|
||||||
|
padding: 0.75rem;
|
||||||
|
background: #f9fafb;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-slots {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #6b7280;
|
||||||
|
background: #e5e7eb;
|
||||||
|
padding: 0.125rem 0.5rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-container {
|
||||||
|
height: 200px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #f8fafc;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-frame {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: none;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-details {
|
||||||
|
padding: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-description {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #6b7280;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-slot-types {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-badge {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.625rem;
|
||||||
|
font-weight: 500;
|
||||||
|
padding: 0.125rem 0.375rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.025em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-title {
|
||||||
|
background: #dbeafe;
|
||||||
|
color: #1e40af;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-subtitle {
|
||||||
|
background: #e0e7ff;
|
||||||
|
color: #5b21b6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-text {
|
||||||
|
background: #f3f4f6;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-image {
|
||||||
|
background: #dcfce7;
|
||||||
|
color: #166534;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-video {
|
||||||
|
background: #fef3c7;
|
||||||
|
color: #92400e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-audio {
|
||||||
|
background: #fed7d7;
|
||||||
|
color: #c53030;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-list {
|
||||||
|
background: #e0f2fe;
|
||||||
|
color: #0c4a6e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slot-type-code {
|
||||||
|
background: #f1f5f9;
|
||||||
|
color: #475569;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layout grid for previews */
|
||||||
|
.layout-previews-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Enhanced theme layouts section */
|
||||||
|
.theme-layouts {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-layouts h4 {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layouts-toggle {
|
||||||
|
background: #f3f4f6;
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #6b7280;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layouts-toggle:hover {
|
||||||
|
background: #e5e7eb;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layouts-toggle.active {
|
||||||
|
background: #3b82f6;
|
||||||
|
color: white;
|
||||||
|
border-color: #2563eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive design */
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.theme-browser {
|
||||||
|
padding: 0 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-card {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-header {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-list {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-previews-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-item,
|
||||||
|
.meta-item {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
}
|
235
src/components/themes/ThemeBrowser.tsx
Normal file
235
src/components/themes/ThemeBrowser.tsx
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import type { Theme } from '../../types/theme';
|
||||||
|
import { getThemes } from '../../themes';
|
||||||
|
import { LayoutPreview } from './LayoutPreview';
|
||||||
|
|
||||||
|
export const ThemeBrowser: React.FC = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [themes, setThemes] = useState<Theme[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [expandedTheme, setExpandedTheme] = useState<string | null>(null);
|
||||||
|
const [showLayoutPreviews, setShowLayoutPreviews] = useState<Record<string, boolean>>({});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadThemes = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const discoveredThemes = await getThemes();
|
||||||
|
setThemes(discoveredThemes);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to load themes');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadThemes();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Listen for theme changes via HMR
|
||||||
|
useEffect(() => {
|
||||||
|
if (import.meta.hot) {
|
||||||
|
const handleThemeChange = (data: { filename: string; eventType: string; timestamp: number }) => {
|
||||||
|
console.log('Theme changed, reloading themes:', data);
|
||||||
|
|
||||||
|
// Clear theme cache and reload
|
||||||
|
setLoading(true);
|
||||||
|
setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
const discoveredThemes = await getThemes(true); // Force cache bust
|
||||||
|
setThemes(discoveredThemes);
|
||||||
|
setError(null);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to reload themes');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, 100); // Small delay to ensure file is fully written
|
||||||
|
};
|
||||||
|
|
||||||
|
import.meta.hot.on('theme-changed', handleThemeChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
import.meta.hot?.off('theme-changed', handleThemeChange);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleThemeClick = (theme: Theme) => {
|
||||||
|
navigate(`/themes/${theme.id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleThemeExpand = (themeId: string) => {
|
||||||
|
setExpandedTheme(expandedTheme === themeId ? null : themeId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLayoutPreviewsToggle = (themeId: string) => {
|
||||||
|
setShowLayoutPreviews(prev => ({
|
||||||
|
...prev,
|
||||||
|
[themeId]: !prev[themeId]
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="theme-browser loading">
|
||||||
|
<div className="loading-spinner">Loading themes...</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="theme-browser error">
|
||||||
|
<div className="error-message">
|
||||||
|
<h3>Error loading themes</h3>
|
||||||
|
<p>{error}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (themes.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="theme-browser empty">
|
||||||
|
<div className="empty-state">
|
||||||
|
<h3>No themes found</h3>
|
||||||
|
<p>No themes were discovered. Check your themes directory.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="theme-browser">
|
||||||
|
<header className="theme-browser-header">
|
||||||
|
<h2>Available Themes</h2>
|
||||||
|
<span className="theme-count">{themes.length} theme{themes.length !== 1 ? 's' : ''}</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="theme-list">
|
||||||
|
{themes.map((theme) => (
|
||||||
|
<div
|
||||||
|
key={theme.id}
|
||||||
|
className="theme-card"
|
||||||
|
onClick={() => handleThemeClick(theme)}
|
||||||
|
>
|
||||||
|
<div className="theme-header">
|
||||||
|
<div className="theme-info">
|
||||||
|
<h3 className="theme-name">{theme.name}</h3>
|
||||||
|
<p className="theme-description">{theme.description}</p>
|
||||||
|
{theme.author && (
|
||||||
|
<span className="theme-author">by {theme.author}</span>
|
||||||
|
)}
|
||||||
|
{theme.version && (
|
||||||
|
<span className="theme-version">v{theme.version}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="theme-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="expand-button"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handleThemeExpand(theme.id);
|
||||||
|
}}
|
||||||
|
aria-label={`${expandedTheme === theme.id ? 'Collapse' : 'Expand'} ${theme.name}`}
|
||||||
|
>
|
||||||
|
{expandedTheme === theme.id ? '−' : '+'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{theme.variables && Object.keys(theme.variables).length > 0 && (
|
||||||
|
<div className="theme-preview">
|
||||||
|
<div className="color-palette">
|
||||||
|
{Object.entries(theme.variables)
|
||||||
|
.filter(([_, value]) => value.startsWith('#') || value.includes('rgb') || value.includes('hsl'))
|
||||||
|
.slice(0, 6) // Show max 6 color swatches to avoid overcrowding
|
||||||
|
.map(([key, value]) => (
|
||||||
|
<div
|
||||||
|
key={key}
|
||||||
|
className="color-swatch"
|
||||||
|
style={{ backgroundColor: value }}
|
||||||
|
title={`--${key}: ${value}`}
|
||||||
|
></div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{expandedTheme === theme.id && (
|
||||||
|
<div className="theme-details">
|
||||||
|
<div className="theme-layouts">
|
||||||
|
<h4>
|
||||||
|
Layouts ({theme.layouts.length})
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`layouts-toggle ${showLayoutPreviews[theme.id] ? 'active' : ''}`}
|
||||||
|
onClick={() => handleLayoutPreviewsToggle(theme.id)}
|
||||||
|
>
|
||||||
|
{showLayoutPreviews[theme.id] ? 'Hide Previews' : 'Show Previews'}
|
||||||
|
</button>
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
{showLayoutPreviews[theme.id] ? (
|
||||||
|
<div className="layout-previews-grid">
|
||||||
|
{theme.layouts.map((layout) => (
|
||||||
|
<LayoutPreview
|
||||||
|
key={layout.id}
|
||||||
|
layout={layout}
|
||||||
|
theme={theme}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="layout-list">
|
||||||
|
{theme.layouts.map((layout) => (
|
||||||
|
<div key={layout.id} className="layout-item">
|
||||||
|
<span className="layout-name">{layout.name}</span>
|
||||||
|
<span className="layout-slots">
|
||||||
|
{layout.slots.length} slot{layout.slots.length !== 1 ? 's' : ''}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{theme.variables && (
|
||||||
|
<div className="theme-variables">
|
||||||
|
<h4>CSS Variables</h4>
|
||||||
|
<div className="variable-list">
|
||||||
|
{Object.entries(theme.variables).map(([key, value]) => (
|
||||||
|
<div key={key} className="variable-item">
|
||||||
|
<code className="variable-name">--{key}</code>
|
||||||
|
<span className="variable-value">{value}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="theme-meta">
|
||||||
|
<div className="meta-item">
|
||||||
|
<strong>Path:</strong> {theme.basePath}
|
||||||
|
</div>
|
||||||
|
<div className="meta-item">
|
||||||
|
<strong>CSS File:</strong> {theme.cssFile}
|
||||||
|
</div>
|
||||||
|
{theme.masterSlideTemplate && (
|
||||||
|
<div className="meta-item">
|
||||||
|
<strong>Master Slide:</strong> Yes
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
314
src/components/themes/ThemeDetailPage.css
Normal file
314
src/components/themes/ThemeDetailPage.css
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
.theme-detail-page {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-detail-header {
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-link {
|
||||||
|
display: inline-block;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
color: #3b82f6;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-info h1 {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
font-size: 2rem;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-info p {
|
||||||
|
margin: 0 0 1rem 0;
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-meta {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-author,
|
||||||
|
.theme-version {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
padding: 0.25rem 0.75rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-author {
|
||||||
|
background: #f3f4f6;
|
||||||
|
color: #374151;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-version {
|
||||||
|
background: #dbeafe;
|
||||||
|
color: #1e40af;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Color Palette Section */
|
||||||
|
.theme-colors {
|
||||||
|
margin-bottom: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-colors h2 {
|
||||||
|
margin: 0 0 1.5rem 0;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-palette-large {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-swatch-large {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-preview {
|
||||||
|
width: 3rem;
|
||||||
|
height: 3rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-details {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-name {
|
||||||
|
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #7c3aed;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-value {
|
||||||
|
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #6b7280;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layouts Section */
|
||||||
|
.theme-layouts {
|
||||||
|
margin-bottom: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-layouts h2 {
|
||||||
|
margin: 0 0 1.5rem 0;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layouts-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
|
||||||
|
gap: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-card {
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.75rem;
|
||||||
|
overflow: hidden;
|
||||||
|
background: white;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-card:hover {
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-header {
|
||||||
|
padding: 1rem;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
background: #f9fafb;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-name {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-slots {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #6b7280;
|
||||||
|
background: #e5e7eb;
|
||||||
|
padding: 0.125rem 0.5rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-detail-link {
|
||||||
|
color: #3b82f6;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-detail-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-preview-container {
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Variables Section */
|
||||||
|
.theme-variables {
|
||||||
|
margin-bottom: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-variables h2 {
|
||||||
|
margin: 0 0 1.5rem 0;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variables-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-card {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
background: white;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-name {
|
||||||
|
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
|
||||||
|
color: #7c3aed;
|
||||||
|
background: #f5f3ff;
|
||||||
|
padding: 0.125rem 0.25rem;
|
||||||
|
border-radius: 0.125rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-value {
|
||||||
|
color: #374151;
|
||||||
|
font-weight: 500;
|
||||||
|
word-break: break-all;
|
||||||
|
margin-left: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Technical Details Section */
|
||||||
|
.theme-technical {
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-technical h2 {
|
||||||
|
margin: 0 0 1rem 0;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tech-details {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tech-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
background: white;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tech-item strong {
|
||||||
|
color: #374151;
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tech-item code {
|
||||||
|
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
|
||||||
|
background: #f1f5f9;
|
||||||
|
padding: 0.125rem 0.25rem;
|
||||||
|
border-radius: 0.125rem;
|
||||||
|
color: #475569;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Error States */
|
||||||
|
.error-message,
|
||||||
|
.not-found {
|
||||||
|
text-align: center;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message h2,
|
||||||
|
.not-found h2 {
|
||||||
|
color: #ef4444;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
text-align: center;
|
||||||
|
padding: 2rem;
|
||||||
|
color: #6b7280;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.theme-detail-page {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-palette-large {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layouts-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variables-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-swatch-large {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variable-card,
|
||||||
|
.tech-item {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
162
src/components/themes/ThemeDetailPage.tsx
Normal file
162
src/components/themes/ThemeDetailPage.tsx
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { useParams, Link } from 'react-router-dom';
|
||||||
|
import type { Theme } from '../../types/theme';
|
||||||
|
import { getTheme } from '../../themes';
|
||||||
|
import { LayoutPreview } from './LayoutPreview';
|
||||||
|
import './ThemeDetailPage.css';
|
||||||
|
|
||||||
|
export const ThemeDetailPage: React.FC = () => {
|
||||||
|
const { themeId } = useParams<{ themeId: string }>();
|
||||||
|
const [theme, setTheme] = useState<Theme | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadTheme = async () => {
|
||||||
|
if (!themeId) {
|
||||||
|
setError('No theme ID provided');
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const themeData = await getTheme(themeId);
|
||||||
|
if (!themeData) {
|
||||||
|
setError(`Theme "${themeId}" not found`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setTheme(themeData);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to load theme');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadTheme();
|
||||||
|
}, [themeId]);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="theme-detail-page">
|
||||||
|
<div className="loading-spinner">Loading theme...</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="theme-detail-page">
|
||||||
|
<div className="error-message">
|
||||||
|
<h2>Error</h2>
|
||||||
|
<p>{error}</p>
|
||||||
|
<Link to="/themes" className="back-link">← Back to Themes</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!theme) {
|
||||||
|
return (
|
||||||
|
<div className="theme-detail-page">
|
||||||
|
<div className="not-found">
|
||||||
|
<h2>Theme Not Found</h2>
|
||||||
|
<p>The requested theme could not be found.</p>
|
||||||
|
<Link to="/themes" className="back-link">← Back to Themes</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="theme-detail-page">
|
||||||
|
<header className="theme-detail-header">
|
||||||
|
<Link to="/themes" className="back-link">← Back to Themes</Link>
|
||||||
|
<div className="theme-info">
|
||||||
|
<h1 className="theme-name">{theme.name}</h1>
|
||||||
|
<p className="theme-description">{theme.description}</p>
|
||||||
|
<div className="theme-meta">
|
||||||
|
{theme.author && <span className="theme-author">by {theme.author}</span>}
|
||||||
|
{theme.version && <span className="theme-version">v{theme.version}</span>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{theme.variables && Object.keys(theme.variables).length > 0 && (
|
||||||
|
<section className="theme-colors">
|
||||||
|
<h2>Color Palette</h2>
|
||||||
|
<div className="color-palette-large">
|
||||||
|
{Object.entries(theme.variables)
|
||||||
|
.filter(([_, value]) => value.startsWith('#') || value.includes('rgb') || value.includes('hsl'))
|
||||||
|
.map(([key, value]) => (
|
||||||
|
<div key={key} className="color-swatch-large">
|
||||||
|
<div
|
||||||
|
className="color-preview"
|
||||||
|
style={{ backgroundColor: value }}
|
||||||
|
title={`--${key}: ${value}`}
|
||||||
|
></div>
|
||||||
|
<div className="color-details">
|
||||||
|
<div className="color-name">--{key}</div>
|
||||||
|
<div className="color-value">{value}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<section className="theme-layouts">
|
||||||
|
<h2>Available Layouts ({theme.layouts.length})</h2>
|
||||||
|
<div className="layouts-grid">
|
||||||
|
{theme.layouts.map((layout) => (
|
||||||
|
<div key={layout.id} className="layout-card">
|
||||||
|
<div className="layout-header">
|
||||||
|
<h3 className="layout-name">{layout.name}</h3>
|
||||||
|
<span className="layout-slots">{layout.slots.length} slots</span>
|
||||||
|
<Link
|
||||||
|
to={`/themes/${theme.id}/layouts/${layout.id}`}
|
||||||
|
className="layout-detail-link"
|
||||||
|
>
|
||||||
|
View Details →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div className="layout-preview-container">
|
||||||
|
<LayoutPreview layout={layout} theme={theme} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{theme.variables && (
|
||||||
|
<section className="theme-variables">
|
||||||
|
<h2>CSS Variables</h2>
|
||||||
|
<div className="variables-grid">
|
||||||
|
{Object.entries(theme.variables).map(([key, value]) => (
|
||||||
|
<div key={key} className="variable-card">
|
||||||
|
<code className="variable-name">--{key}</code>
|
||||||
|
<span className="variable-value">{value}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<section className="theme-technical">
|
||||||
|
<h2>Technical Details</h2>
|
||||||
|
<div className="tech-details">
|
||||||
|
<div className="tech-item">
|
||||||
|
<strong>Path:</strong> <code>{theme.basePath}</code>
|
||||||
|
</div>
|
||||||
|
<div className="tech-item">
|
||||||
|
<strong>CSS File:</strong> <code>{theme.cssFile}</code>
|
||||||
|
</div>
|
||||||
|
<div className="tech-item">
|
||||||
|
<strong>Master Slide:</strong> {theme.masterSlideTemplate ? 'Yes' : 'No'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
5
src/components/themes/index.ts
Normal file
5
src/components/themes/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export { ThemeBrowser } from './ThemeBrowser';
|
||||||
|
export { LayoutPreview } from './LayoutPreview';
|
||||||
|
export { ThemeDetailPage } from './ThemeDetailPage';
|
||||||
|
export { LayoutDetailPage } from './LayoutDetailPage';
|
||||||
|
export type { Theme } from '../../types/theme';
|
66
src/index.css
Normal file
66
src/index.css
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
:root {
|
||||||
|
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
|
color-scheme: light dark;
|
||||||
|
color: rgba(255, 255, 255, 0.87);
|
||||||
|
background-color: #242424;
|
||||||
|
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #646cff;
|
||||||
|
text-decoration: inherit;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #535bf2;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-width: 320px;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 3.2em;
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: 0.6em 1.2em;
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: 500;
|
||||||
|
font-family: inherit;
|
||||||
|
background-color: #1a1a1a;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.25s;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
border-color: #646cff;
|
||||||
|
}
|
||||||
|
button:focus,
|
||||||
|
button:focus-visible {
|
||||||
|
outline: 4px auto -webkit-focus-ring-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
:root {
|
||||||
|
color: #213547;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #747bff;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
}
|
10
src/main.tsx
Normal file
10
src/main.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { StrictMode } from 'react'
|
||||||
|
import { createRoot } from 'react-dom/client'
|
||||||
|
import './index.css'
|
||||||
|
import App from './App.tsx'
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')!).render(
|
||||||
|
<StrictMode>
|
||||||
|
<App />
|
||||||
|
</StrictMode>,
|
||||||
|
)
|
51
src/plugins/themeWatcher.ts
Normal file
51
src/plugins/themeWatcher.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import type { Plugin } from 'vite';
|
||||||
|
import { watch } from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vite plugin to watch theme files in public directory and trigger HMR
|
||||||
|
*/
|
||||||
|
export function themeWatcherPlugin(): Plugin {
|
||||||
|
return {
|
||||||
|
name: 'theme-watcher',
|
||||||
|
configureServer(server) {
|
||||||
|
const publicThemesPath = path.resolve(process.cwd(), 'public/themes');
|
||||||
|
|
||||||
|
// Watch for changes in the themes directory
|
||||||
|
const watcher = watch(
|
||||||
|
publicThemesPath,
|
||||||
|
{ recursive: true },
|
||||||
|
(eventType: string, filename: string | null) => {
|
||||||
|
if (filename && (filename.endsWith('.css') || filename.endsWith('.html'))) {
|
||||||
|
console.log(`Theme file changed: ${filename}`);
|
||||||
|
|
||||||
|
// Invalidate theme cache and send HMR update
|
||||||
|
const moduleId = '/src/utils/themeLoader.ts';
|
||||||
|
const module = server.moduleGraph.getModuleById(moduleId);
|
||||||
|
if (module) {
|
||||||
|
server.reloadModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send custom HMR event to notify components
|
||||||
|
server.ws.send({
|
||||||
|
type: 'custom',
|
||||||
|
event: 'theme-changed',
|
||||||
|
data: {
|
||||||
|
filename,
|
||||||
|
eventType,
|
||||||
|
timestamp: Date.now()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Cleanup watcher on server close
|
||||||
|
server.httpServer?.on('close', () => {
|
||||||
|
if (typeof watcher === 'object' && 'close' in watcher) {
|
||||||
|
watcher.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
10
src/themes/index.ts
Normal file
10
src/themes/index.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Re-export from the theme loader utility
|
||||||
|
export { discoverThemes as getThemes, loadTheme } from '../utils/themeLoader';
|
||||||
|
|
||||||
|
// Import for internal use
|
||||||
|
import { loadTheme } from '../utils/themeLoader';
|
||||||
|
|
||||||
|
// Helper function to get a single theme by ID
|
||||||
|
export const getTheme = async (themeId: string) => {
|
||||||
|
return loadTheme(themeId, false);
|
||||||
|
};
|
36
src/types/theme.ts
Normal file
36
src/types/theme.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
export interface SlotConfig {
|
||||||
|
id: string;
|
||||||
|
type: string; // Allow any slot type discovered from templates
|
||||||
|
placeholder?: string;
|
||||||
|
required?: boolean;
|
||||||
|
defaultContent?: string;
|
||||||
|
// Additional metadata that can be extracted from HTML
|
||||||
|
className?: string;
|
||||||
|
style?: string;
|
||||||
|
attributes?: Record<string, string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SlideLayout {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
htmlTemplate: string;
|
||||||
|
slots: SlotConfig[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ThemeVariables {
|
||||||
|
[key: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Theme {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
author?: string;
|
||||||
|
version?: string;
|
||||||
|
basePath: string;
|
||||||
|
cssFile: string;
|
||||||
|
variables?: ThemeVariables;
|
||||||
|
layouts: SlideLayout[];
|
||||||
|
masterSlideTemplate?: string;
|
||||||
|
}
|
250
src/utils/cssParser.ts
Normal file
250
src/utils/cssParser.ts
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
import postcss from 'postcss';
|
||||||
|
|
||||||
|
export interface CSSVariables {
|
||||||
|
[key: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ThemeMetadata {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
author?: string;
|
||||||
|
version?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses CSS variables from CSS text content using PostCSS
|
||||||
|
*/
|
||||||
|
export const parseCSSVariables = (cssContent: string): CSSVariables => {
|
||||||
|
const variables: CSSVariables = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ast = postcss.parse(cssContent);
|
||||||
|
|
||||||
|
// Find :root rule and extract custom properties
|
||||||
|
ast.walkRules(':root', (rule) => {
|
||||||
|
rule.walkDecls((decl) => {
|
||||||
|
if (decl.prop.startsWith('--')) {
|
||||||
|
const name = decl.prop.substring(2); // Remove '--' prefix
|
||||||
|
variables[name] = decl.value.trim();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Error parsing CSS with PostCSS:', error);
|
||||||
|
// Fallback to regex parsing if PostCSS fails
|
||||||
|
return parseCSSVariablesRegex(cssContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback regex-based CSS variable parsing
|
||||||
|
*/
|
||||||
|
const parseCSSVariablesRegex = (cssContent: string): CSSVariables => {
|
||||||
|
const variables: CSSVariables = {};
|
||||||
|
|
||||||
|
const rootRegex = /:root\s*\{([^}]+)\}/g;
|
||||||
|
const variableRegex = /--([^:]+):\s*([^;]+);/g;
|
||||||
|
|
||||||
|
const rootMatch = rootRegex.exec(cssContent);
|
||||||
|
if (rootMatch) {
|
||||||
|
const rootContent = rootMatch[1];
|
||||||
|
let variableMatch;
|
||||||
|
|
||||||
|
while ((variableMatch = variableRegex.exec(rootContent)) !== null) {
|
||||||
|
const [, name, value] = variableMatch;
|
||||||
|
variables[name.trim()] = value.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads CSS file and extracts variables
|
||||||
|
*/
|
||||||
|
export const loadCSSVariables = async (cssFilePath: string): Promise<CSSVariables> => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(cssFilePath);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to load CSS file: ${cssFilePath}`);
|
||||||
|
}
|
||||||
|
const cssContent = await response.text();
|
||||||
|
return parseCSSVariables(cssContent);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Could not load CSS variables from ${cssFilePath}:`, error);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets computed CSS variable value from the document
|
||||||
|
*/
|
||||||
|
export const getCSSVariable = (variableName: string, element?: HTMLElement): string => {
|
||||||
|
const target = element || document.documentElement;
|
||||||
|
return getComputedStyle(target).getPropertyValue(`--${variableName}`).trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets CSS variable on the document or element
|
||||||
|
*/
|
||||||
|
export const setCSSVariable = (variableName: string, value: string, element?: HTMLElement): void => {
|
||||||
|
const target = element || document.documentElement;
|
||||||
|
target.style.setProperty(`--${variableName}`, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses theme metadata from CSS comment block using PostCSS
|
||||||
|
*/
|
||||||
|
export const parseThemeMetadata = (cssContent: string): ThemeMetadata | null => {
|
||||||
|
try {
|
||||||
|
const ast = postcss.parse(cssContent);
|
||||||
|
const metadata: Partial<ThemeMetadata> = {};
|
||||||
|
|
||||||
|
// Find the first comment that contains theme metadata
|
||||||
|
ast.walkComments((comment) => {
|
||||||
|
if (!metadata.id) { // Only process the first metadata comment
|
||||||
|
const commentContent = comment.text;
|
||||||
|
|
||||||
|
// Parse each line in the comment
|
||||||
|
const lines = commentContent.split('\n');
|
||||||
|
for (const line of lines) {
|
||||||
|
const cleanLine = line.replace(/^\s*\*\s?/, '').trim();
|
||||||
|
if (cleanLine.includes(':')) {
|
||||||
|
const [key, ...valueParts] = cleanLine.split(':');
|
||||||
|
const value = valueParts.join(':').trim();
|
||||||
|
|
||||||
|
switch (key.toLowerCase().trim()) {
|
||||||
|
case 'theme':
|
||||||
|
metadata.id = value.toLowerCase().replace(/\s+/g, '-');
|
||||||
|
break;
|
||||||
|
case 'name':
|
||||||
|
metadata.name = value;
|
||||||
|
break;
|
||||||
|
case 'description':
|
||||||
|
metadata.description = value;
|
||||||
|
break;
|
||||||
|
case 'author':
|
||||||
|
metadata.author = value;
|
||||||
|
break;
|
||||||
|
case 'version':
|
||||||
|
metadata.version = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure required fields
|
||||||
|
if (!metadata.id || !metadata.name || !metadata.description) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return metadata as ThemeMetadata;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Error parsing CSS metadata with PostCSS:', error);
|
||||||
|
// Fallback to regex parsing
|
||||||
|
return parseThemeMetadataRegex(cssContent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback regex-based metadata parsing
|
||||||
|
*/
|
||||||
|
const parseThemeMetadataRegex = (cssContent: string): ThemeMetadata | null => {
|
||||||
|
const commentRegex = /\/\*\s*([\s\S]*?)\s*\*\//;
|
||||||
|
const match = commentRegex.exec(cssContent);
|
||||||
|
|
||||||
|
if (!match) return null;
|
||||||
|
|
||||||
|
const commentContent = match[1];
|
||||||
|
const metadata: Partial<ThemeMetadata> = {};
|
||||||
|
|
||||||
|
// Parse each line in the comment
|
||||||
|
const lines = commentContent.split('\n');
|
||||||
|
for (const line of lines) {
|
||||||
|
const cleanLine = line.replace(/^\s*\*\s?/, '').trim();
|
||||||
|
if (cleanLine.includes(':')) {
|
||||||
|
const [key, ...valueParts] = cleanLine.split(':');
|
||||||
|
const value = valueParts.join(':').trim();
|
||||||
|
|
||||||
|
switch (key.toLowerCase().trim()) {
|
||||||
|
case 'theme':
|
||||||
|
metadata.id = value.toLowerCase().replace(/\s+/g, '-');
|
||||||
|
break;
|
||||||
|
case 'name':
|
||||||
|
metadata.name = value;
|
||||||
|
break;
|
||||||
|
case 'description':
|
||||||
|
metadata.description = value;
|
||||||
|
break;
|
||||||
|
case 'author':
|
||||||
|
metadata.author = value;
|
||||||
|
break;
|
||||||
|
case 'version':
|
||||||
|
metadata.version = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure required fields
|
||||||
|
if (!metadata.id || !metadata.name || !metadata.description) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return metadata as ThemeMetadata;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all CSS variables from computed styles
|
||||||
|
*/
|
||||||
|
export const getAllCSSVariables = (element?: HTMLElement): CSSVariables => {
|
||||||
|
const target = element || document.documentElement;
|
||||||
|
const computedStyles = getComputedStyle(target);
|
||||||
|
const variables: CSSVariables = {};
|
||||||
|
|
||||||
|
// Get all CSS properties and filter for custom properties
|
||||||
|
for (let i = 0; i < computedStyles.length; i++) {
|
||||||
|
const property = computedStyles[i];
|
||||||
|
if (property.startsWith('--')) {
|
||||||
|
const name = property.substring(2); // Remove '--' prefix
|
||||||
|
const value = computedStyles.getPropertyValue(property).trim();
|
||||||
|
if (value) {
|
||||||
|
variables[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads CSS file and extracts both metadata and variables
|
||||||
|
*/
|
||||||
|
export const loadThemeFromCSS = async (cssFilePath: string): Promise<{
|
||||||
|
metadata: ThemeMetadata | null;
|
||||||
|
variables: CSSVariables;
|
||||||
|
}> => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(cssFilePath);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to load CSS file: ${cssFilePath}`);
|
||||||
|
}
|
||||||
|
const cssContent = await response.text();
|
||||||
|
|
||||||
|
return {
|
||||||
|
metadata: parseThemeMetadata(cssContent),
|
||||||
|
variables: parseCSSVariables(cssContent)
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Could not load theme from ${cssFilePath}:`, error);
|
||||||
|
return {
|
||||||
|
metadata: null,
|
||||||
|
variables: {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
166
src/utils/templateRenderer.ts
Normal file
166
src/utils/templateRenderer.ts
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
import type { SlideLayout, SlotConfig } from '../types/theme';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates sample data for a slot based on its configuration
|
||||||
|
*/
|
||||||
|
export const generateSampleDataForSlot = (slot: SlotConfig): string => {
|
||||||
|
const { id, type, placeholder, defaultContent } = slot;
|
||||||
|
|
||||||
|
// Use default content if available
|
||||||
|
if (defaultContent && defaultContent.trim()) {
|
||||||
|
return defaultContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate sample data based on slot type
|
||||||
|
switch (type) {
|
||||||
|
case 'title':
|
||||||
|
if (id.includes('presentation') || id.includes('main')) {
|
||||||
|
return 'Sample Presentation Title';
|
||||||
|
}
|
||||||
|
return 'Slide Title Example';
|
||||||
|
|
||||||
|
case 'subtitle':
|
||||||
|
if (id.includes('presentation') || id.includes('main')) {
|
||||||
|
return 'A compelling subtitle for your presentation';
|
||||||
|
}
|
||||||
|
return 'Slide subtitle or description';
|
||||||
|
|
||||||
|
case 'text':
|
||||||
|
if (id.includes('content') || id.includes('body')) {
|
||||||
|
return `This is sample content for the ${id} slot. It demonstrates how text will appear in this layout with multiple sentences to show text flow and formatting.`;
|
||||||
|
}
|
||||||
|
return `Sample ${id} text content`;
|
||||||
|
|
||||||
|
case 'image':
|
||||||
|
return 'https://via.placeholder.com/400x300/e2e8f0/64748b?text=Sample+Image';
|
||||||
|
|
||||||
|
case 'video':
|
||||||
|
return 'https://www.example.com/sample-video.mp4';
|
||||||
|
|
||||||
|
case 'audio':
|
||||||
|
return 'https://www.example.com/sample-audio.mp3';
|
||||||
|
|
||||||
|
case 'list':
|
||||||
|
return '• First item example\n• Second item example\n• Third item example';
|
||||||
|
|
||||||
|
case 'code':
|
||||||
|
return `function example() {\n console.log("Sample code");\n return true;\n}`;
|
||||||
|
|
||||||
|
case 'table':
|
||||||
|
return 'Header 1 | Header 2\n--- | ---\nData 1 | Data 2\nData 3 | Data 4';
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Use placeholder as fallback, or generate from slot ID
|
||||||
|
if (placeholder && placeholder !== `Enter ${id}`) {
|
||||||
|
return placeholder.replace(/^(Enter|Add|Click to add)\s*/i, 'Sample ');
|
||||||
|
}
|
||||||
|
|
||||||
|
return `Sample ${id.replace(/-/g, ' ')} content`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a complete sample data object for all slots in a layout
|
||||||
|
*/
|
||||||
|
export const generateSampleDataForLayout = (layout: SlideLayout): Record<string, string> => {
|
||||||
|
const sampleData: Record<string, string> = {};
|
||||||
|
|
||||||
|
layout.slots.forEach(slot => {
|
||||||
|
sampleData[slot.id] = generateSampleDataForSlot(slot);
|
||||||
|
|
||||||
|
// Add related data for image slots
|
||||||
|
if (slot.type === 'image') {
|
||||||
|
sampleData[`${slot.id}Alt`] = `Sample ${slot.id} description`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add common template variables that might be used
|
||||||
|
sampleData.footerText = 'Sample Footer Text';
|
||||||
|
sampleData.author = 'Sample Author';
|
||||||
|
sampleData.date = new Date().toLocaleDateString();
|
||||||
|
|
||||||
|
return sampleData;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders an HTML template with sample data using simple string replacement
|
||||||
|
*/
|
||||||
|
export const renderTemplateWithSampleData = (
|
||||||
|
htmlTemplate: string,
|
||||||
|
layout: SlideLayout
|
||||||
|
): string => {
|
||||||
|
const sampleData = generateSampleDataForLayout(layout);
|
||||||
|
let rendered = htmlTemplate;
|
||||||
|
|
||||||
|
// Handle Handlebars-style templates: {{variable}}
|
||||||
|
Object.entries(sampleData).forEach(([key, value]) => {
|
||||||
|
const simpleRegex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
|
||||||
|
rendered = rendered.replace(simpleRegex, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle conditional blocks: {{#variable}}...{{/variable}}
|
||||||
|
Object.entries(sampleData).forEach(([key, value]) => {
|
||||||
|
const conditionalRegex = new RegExp(`\\{\\{#${key}\\}\\}([\\s\\S]*?)\\{\\{/${key}\\}\\}`, 'g');
|
||||||
|
if (value && value.trim()) {
|
||||||
|
// Replace conditional block with content, substituting variables within
|
||||||
|
rendered = rendered.replace(conditionalRegex, (_match, content) => {
|
||||||
|
// Replace variables within the conditional block
|
||||||
|
let blockContent = content;
|
||||||
|
Object.entries(sampleData).forEach(([innerKey, innerValue]) => {
|
||||||
|
const innerRegex = new RegExp(`\\{\\{${innerKey}\\}\\}`, 'g');
|
||||||
|
blockContent = blockContent.replace(innerRegex, innerValue);
|
||||||
|
});
|
||||||
|
return blockContent;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Remove conditional block if no data
|
||||||
|
rendered = rendered.replace(conditionalRegex, '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clean up any remaining template variables
|
||||||
|
rendered = rendered.replace(/\{\{[^}]+\}\}/g, '');
|
||||||
|
|
||||||
|
return rendered;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a preview-ready HTML document with theme CSS applied
|
||||||
|
*/
|
||||||
|
export const createPreviewDocument = (
|
||||||
|
renderedTemplate: string,
|
||||||
|
themeCssUrl: string
|
||||||
|
): string => {
|
||||||
|
return `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="${themeCssUrl}">
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.preview-container {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
transform: scale(0.25);
|
||||||
|
transform-origin: top left;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="preview-container">
|
||||||
|
${renderedTemplate}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
};
|
252
src/utils/themeLoader.ts
Normal file
252
src/utils/themeLoader.ts
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
import type { Theme, SlideLayout, SlotConfig } from '../types/theme';
|
||||||
|
import { parseThemeMetadata, parseCSSVariables } from './cssParser';
|
||||||
|
|
||||||
|
// Theme cache management
|
||||||
|
let themeCache: Theme[] | null = null;
|
||||||
|
let cacheTimestamp = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discovers all available themes using the themes manifest
|
||||||
|
*/
|
||||||
|
export const discoverThemes = async (bustCache = false): Promise<Theme[]> => {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
// Use cache if available and not busted
|
||||||
|
if (!bustCache && themeCache && (now - cacheTimestamp < 5000)) {
|
||||||
|
return themeCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
const themes: Theme[] = [];
|
||||||
|
const cacheParam = bustCache ? `?_=${Date.now()}` : '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Load the themes manifest
|
||||||
|
const manifestResponse = await fetch(`/themes-manifest.json${cacheParam}`);
|
||||||
|
if (!manifestResponse.ok) {
|
||||||
|
throw new Error('Could not load themes manifest');
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifest = await manifestResponse.json();
|
||||||
|
const themeIds = Object.keys(manifest.themes);
|
||||||
|
|
||||||
|
for (const themeId of themeIds) {
|
||||||
|
try {
|
||||||
|
const theme = await loadTheme(themeId, bustCache);
|
||||||
|
if (theme) {
|
||||||
|
themes.push(theme);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Failed to load theme ${themeId}:`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to load themes manifest:', error);
|
||||||
|
// Fallback to default theme if manifest fails
|
||||||
|
try {
|
||||||
|
const defaultTheme = await loadTheme('default', bustCache);
|
||||||
|
if (defaultTheme) {
|
||||||
|
themes.push(defaultTheme);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// No fallback available
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update cache
|
||||||
|
themeCache = themes;
|
||||||
|
cacheTimestamp = now;
|
||||||
|
|
||||||
|
return themes;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a single theme by ID from the public directory
|
||||||
|
*/
|
||||||
|
export const loadTheme = async (themeId: string, bustCache = false): Promise<Theme | null> => {
|
||||||
|
try {
|
||||||
|
const basePath = `/themes/${themeId}`;
|
||||||
|
const cacheParam = bustCache ? `?_=${Date.now()}` : '';
|
||||||
|
|
||||||
|
// Load theme CSS and parse metadata/variables
|
||||||
|
const cssResponse = await fetch(`${basePath}/style.css${cacheParam}`);
|
||||||
|
if (!cssResponse.ok) {
|
||||||
|
throw new Error(`Failed to load CSS: ${cssResponse.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cssContent = await cssResponse.text();
|
||||||
|
const metadata = parseThemeMetadata(cssContent);
|
||||||
|
const variables = parseCSSVariables(cssContent);
|
||||||
|
|
||||||
|
if (!metadata) {
|
||||||
|
throw new Error(`No valid metadata found in ${themeId} theme CSS`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Discover and load layouts
|
||||||
|
const layouts = await discoverLayouts(basePath, themeId, bustCache);
|
||||||
|
|
||||||
|
// Try to load master slide (optional)
|
||||||
|
let masterSlideTemplate: string | undefined;
|
||||||
|
try {
|
||||||
|
const masterResponse = await fetch(`${basePath}/master-slide.html${cacheParam}`);
|
||||||
|
if (masterResponse.ok) {
|
||||||
|
masterSlideTemplate = await masterResponse.text();
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Master slide is optional
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...metadata,
|
||||||
|
basePath,
|
||||||
|
cssFile: 'style.css',
|
||||||
|
variables,
|
||||||
|
layouts,
|
||||||
|
masterSlideTemplate
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Could not load theme ${themeId}:`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discovers layout files for a theme using the themes manifest
|
||||||
|
*/
|
||||||
|
const discoverLayouts = async (basePath: string, themeId: string, bustCache = false): Promise<SlideLayout[]> => {
|
||||||
|
const layouts: SlideLayout[] = [];
|
||||||
|
const cacheParam = bustCache ? `?_=${Date.now()}` : '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Load the themes manifest to get the list of available layouts
|
||||||
|
const manifestResponse = await fetch(`/themes-manifest.json${cacheParam}`);
|
||||||
|
if (!manifestResponse.ok) {
|
||||||
|
throw new Error('Could not load themes manifest');
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifest = await manifestResponse.json();
|
||||||
|
const themeInfo = manifest.themes[themeId];
|
||||||
|
|
||||||
|
if (!themeInfo || !themeInfo.layouts) {
|
||||||
|
return layouts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load each layout from the manifest
|
||||||
|
const layoutPromises = themeInfo.layouts.map(async (layoutId: string) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${basePath}/layouts/${layoutId}.html${cacheParam}`);
|
||||||
|
if (response.ok) {
|
||||||
|
const htmlTemplate = await response.text();
|
||||||
|
|
||||||
|
// Generate layout name from ID
|
||||||
|
const name = layoutId
|
||||||
|
.split('-')
|
||||||
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||||
|
.join(' ');
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: layoutId,
|
||||||
|
name,
|
||||||
|
description: `${name} layout`,
|
||||||
|
htmlTemplate,
|
||||||
|
slots: extractSlotsFromTemplate(htmlTemplate)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const results = await Promise.all(layoutPromises);
|
||||||
|
layouts.push(...results.filter((layout): layout is SlideLayout => layout !== null));
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Error discovering layouts:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return layouts;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts slot configurations from HTML template using DOM parsing
|
||||||
|
*/
|
||||||
|
const extractSlotsFromTemplate = (htmlTemplate: string) => {
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const doc = parser.parseFromString(htmlTemplate, 'text/html');
|
||||||
|
const slotElements = doc.querySelectorAll('[data-slot]');
|
||||||
|
|
||||||
|
const slots: SlotConfig[] = [];
|
||||||
|
|
||||||
|
slotElements.forEach((element) => {
|
||||||
|
const slotId = element.getAttribute('data-slot');
|
||||||
|
if (!slotId) return;
|
||||||
|
|
||||||
|
const slotConfig = {
|
||||||
|
id: slotId,
|
||||||
|
type: element.getAttribute('data-type') || inferSlotTypeFromElement(element),
|
||||||
|
placeholder: element.getAttribute('data-placeholder') || generateDefaultPlaceholder(slotId),
|
||||||
|
required: element.hasAttribute('data-required') || isRequiredByConvention(slotId),
|
||||||
|
defaultContent: element.getAttribute('data-default') || element.textContent?.trim() || undefined,
|
||||||
|
className: element.className || undefined,
|
||||||
|
style: element.getAttribute('style') || undefined,
|
||||||
|
attributes: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Extract custom data attributes
|
||||||
|
Array.from(element.attributes).forEach((attr) => {
|
||||||
|
if (attr.name.startsWith('data-') &&
|
||||||
|
!['data-slot', 'data-type', 'data-placeholder', 'data-required', 'data-default'].includes(attr.name)) {
|
||||||
|
(slotConfig.attributes as Record<string, string>)[attr.name] = attr.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clean up empty attributes
|
||||||
|
if (Object.keys(slotConfig.attributes!).length === 0) {
|
||||||
|
delete (slotConfig as any).attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
slots.push(slotConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
return slots;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Infer slot type from HTML element
|
||||||
|
*/
|
||||||
|
const inferSlotTypeFromElement = (element: Element): string => {
|
||||||
|
const tagName = element.tagName.toLowerCase();
|
||||||
|
const className = element.className.toLowerCase();
|
||||||
|
|
||||||
|
if (tagName === 'img') return 'image';
|
||||||
|
if (tagName === 'h1') return 'title';
|
||||||
|
if (tagName === 'h2' || tagName === 'h3') return 'subtitle';
|
||||||
|
if (tagName === 'textarea') return 'textarea';
|
||||||
|
if (tagName === 'input') return element.getAttribute('type') || 'text';
|
||||||
|
if (tagName === 'video') return 'video';
|
||||||
|
if (tagName === 'audio') return 'audio';
|
||||||
|
|
||||||
|
if (className.includes('title')) return 'title';
|
||||||
|
if (className.includes('subtitle')) return 'subtitle';
|
||||||
|
if (className.includes('image')) return 'image';
|
||||||
|
|
||||||
|
return 'text';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate default placeholder from slot ID
|
||||||
|
*/
|
||||||
|
const generateDefaultPlaceholder = (slotId: string): string => {
|
||||||
|
const readable = slotId
|
||||||
|
.split('-')
|
||||||
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||||
|
.join(' ');
|
||||||
|
|
||||||
|
return `Enter ${readable.toLowerCase()}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if slot is required by convention
|
||||||
|
*/
|
||||||
|
const isRequiredByConvention = (slotId: string): boolean => {
|
||||||
|
return slotId.includes('title') || slotId === 'heading';
|
||||||
|
};
|
1
src/vite-env.d.ts
vendored
Normal file
1
src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
27
tsconfig.app.json
Normal file
27
tsconfig.app.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"target": "ES2022",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
25
tsconfig.node.json
Normal file
25
tsconfig.node.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "ES2023",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
17
vite.config.ts
Normal file
17
vite.config.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react'
|
||||||
|
import { themeWatcherPlugin } from './src/plugins/themeWatcher'
|
||||||
|
|
||||||
|
// https://vite.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [
|
||||||
|
react(),
|
||||||
|
themeWatcherPlugin()
|
||||||
|
],
|
||||||
|
server: {
|
||||||
|
watch: {
|
||||||
|
// Watch public directory for theme changes
|
||||||
|
ignored: ['!**/public/themes/**']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user