Skip to content

Commit ca8be9c

Browse files
Preact register (#2)
* feat: add Windows path utilities and byte slice stream - Implemented `fromFileUrl`, `join`, `normalize`, `relative`, and `resolve` functions for Windows path handling. - Introduced `ByteSliceStream` for transforming byte streams based on specified byte ranges. - Updated DOM main entry to register new Preact components and custom elements. - Created import map for Preact dependencies. - Added main entry point for server-side rendering with Preact. - Developed template components for buttons and counters. - Removed deprecated test runner script. - Added `wrangler.jsonc` configuration for Cloudflare Workers. * refactor: enhance Counter2 component structure and styling; update routes for button2 and counter2 CSS * feat: implement Button2 component with CSS styling and integrate into Home component; add serve script and template files
1 parent 39f6358 commit ca8be9c

270 files changed

Lines changed: 45828 additions & 98 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

WARP.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# WARP.md
2+
3+
This file provides guidance to WARP (warp.dev) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a **Declarative Shadow DOM (DSD) with Preact** project that demonstrates modern web component architecture using Deno as the runtime. It showcases reusable components with encapsulation, server-side rendering (SSR), and dual packaging for both Deno and npm ecosystems.
8+
9+
## Development Commands
10+
11+
### Core Development
12+
- `deno task dev` - Start development server with hot reload (serves on http://localhost:8000)
13+
- `deno task serve` - Start production server without file watching
14+
- `deno task build` - Build and package for npm distribution (outputs to `package/` directory)
15+
- `deno task ssg` - Generate static site HTML files
16+
17+
### Build Pipeline Details
18+
The build process (`deno task build`) performs multiple steps:
19+
1. Uses `@deno/dnt` to transpile Deno TypeScript to Node.js compatible code
20+
2. Generates static HTML using SSG (Static Site Generation)
21+
3. Copies CSS templates to the package directory
22+
4. Runs Vite build for optimized bundling
23+
5. Uses JSPM to generate optimized import maps with integrity and preloading
24+
25+
## Architecture Overview
26+
27+
### Dual Component Strategy
28+
The project implements components using **two complementary approaches**:
29+
30+
1. **Custom Elements** (`elements/` directory):
31+
- Native Web Components with Shadow DOM
32+
- TypeScript classes extending `HTMLElement`
33+
- Examples: `Button`, `Counter`, `ButtonPreact`, `CounterPreact`
34+
35+
2. **Preact Components** (`components/` directory):
36+
- Standard Preact functional components
37+
- Server-side renderable
38+
- Examples: `Button`, `Counter`, `DSDButton`, `DSDCounter`
39+
40+
### Key Architectural Patterns
41+
42+
#### Server-Side Rendering (SSR)
43+
- `main.tsx` serves as the primary server entry point using Deno's native HTTP server
44+
- Route-based file serving with explicit URL patterns for assets
45+
- Full HTML document generation with `renderToStringAsync` from Preact
46+
- Declarative Shadow DOM templates embedded in server-rendered HTML
47+
48+
#### Import Map Strategy
49+
- **Development**: Uses `deno.json` imports with path aliases (e.g., `#button`, `#counter`)
50+
- **Browser**: Uses `importmap.json` with CDN URLs for production dependencies
51+
- **Build**: Transpiles and resolves all imports for npm compatibility
52+
53+
#### Signal-Based State Management
54+
- Uses `@preact/signals` for reactive state management
55+
- Shared state between components via `signals/counter.ts`
56+
- Enables cross-component reactivity without prop drilling
57+
58+
### Directory Structure Significance
59+
60+
- `components/` - Preact components for SSR and composition
61+
- `elements/` - Web Components (Custom Elements) for browser hydration
62+
- `templates/` - HTML templates and CSS for Shadow DOM styling
63+
- `functions/` - Build scripts, bundling, and deployment configuration
64+
- `dom/` - Browser-specific code that registers Custom Elements
65+
- `package/` - Generated npm-compatible output (created by build process)
66+
67+
## Development Workflow
68+
69+
### Working with Components
70+
1. **Adding new components**: Create both a Preact component (`components/`) and a Custom Element (`elements/`) if browser interactivity is needed
71+
2. **Styling**: Place CSS in `templates/` directory - it gets copied to the package during build
72+
3. **State**: Use signals from `signals/` for shared reactive state
73+
4. **Import aliases**: Use the `#` prefix imports defined in `deno.json` (e.g., `#button`, `#home`)
74+
75+
### Testing Changes
76+
- Use `deno task dev` for rapid iteration with hot reload
77+
- Visit `/elements` route to see the component showcase
78+
- Check `package/` directory after build to verify npm output
79+
80+
### Build Output Verification
81+
After running `deno task build`, verify:
82+
- `package/esm/` contains transpiled JavaScript modules
83+
- `package/index.html` is generated with proper import maps
84+
- CSS files are copied to `package/templates/`
85+
- Vite and JSPM optimizations are applied
86+
87+
## Key Technologies
88+
89+
- **Runtime**: Deno (TypeScript-first, secure by default)
90+
- **UI Framework**: Preact (lightweight React alternative)
91+
- **State Management**: `@preact/signals` (fine-grained reactivity)
92+
- **Web Standards**: Custom Elements, Shadow DOM, Declarative Shadow DOM
93+
- **Build Tools**: `@deno/dnt`, Vite, JSPM
94+
- **Server**: Native Deno HTTP server with URL pattern routing
95+
- **Deployment**: Cloudflare Workers compatible (via Vite plugin)
96+
97+
## Important Implementation Details
98+
99+
### Declarative Shadow DOM
100+
The project uses server-rendered Shadow DOM templates that hydrate on the client. Components like `DSDButton` and `DSDCounter` render with `<template shadowrootmode="open">` for immediate styling encapsulation.
101+
102+
### Custom Element Registration
103+
Browser-side Custom Elements are registered in `dom/main.ts` and loaded via `package/esm/dom/main.js`. The server pre-renders the HTML structure while the client-side code adds interactivity.
104+
105+
### Import Resolution
106+
The dual import map system allows the same component code to work in both server (Deno) and browser (CDN) environments. Path aliases in `deno.json` resolve to different targets during development vs. build.

0 commit comments

Comments
 (0)