This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Development
npm run dev # Start development server at http://localhost:5173
# Building
npm run build # Build library package (outputs to dist/)
npm run deploy # Build for deployment (includes HTML demos)
# Testing
npm test # Run tests once
npm run test:watch # Run tests in watch mode
npm run coverage # Run tests with coverage report
npm run test -- path/to/file.test.ts # Run specific test fileQuyuan (屈原) is a GeoJSON template engine with multimedia viewer components for web maps. It processes GeoJSON features through Nunjucks templates to generate dynamic HTML content (popups, markers) and integrates with Leaflet, OpenLayers, and MapLibre GL.
-
Template Processing Pipeline
QyTemplateExtractor(src/utils/qy-template-extractor.ts) is the core engine- Processes templates with Nunjucks, using GeoJSON feature properties as template variables
- Supports multiple template keys (e.g.,
iconfor markers,htmlfor popups) - Returns enhanced GeoJSON with results stored in
feature.resultobject
-
Web Components Structure
- All components extend Lit's
LitElementwith TypeScript decorators - Components use Shadow DOM for style encapsulation
- Event communication pattern: child components dispatch custom events to parents
- Main components:
qy-viewer: Controller component that manages different media typesqy-swiper: Touch-enabled carousel container using Swiper.jsqy-viewer-image: Image viewer using Viewer.jsqy-viewer-panorama: 360° panorama viewer using A-Frameqy-viewer-youtube: YouTube video embedding
- All components extend Lit's
-
Build Configuration
- Dual-mode Vite configuration:
- Library mode: Builds ES, CJS, and UMD modules with TypeScript declarations
- Demo mode: Builds multiple HTML entry points for GitHub Pages
- TypeScript path aliases:
@/*maps tosrc/* - External dependencies: lit, nunjucks, swiper, viewerjs, aframe
- Dual-mode Vite configuration:
-
Integration Pattern
// Process GeoJSON with templates const result = Quyuan.templateExtractor({ geojson, templates }); // Each feature gets enhanced with result object // feature.result.icon - processed marker icon path // feature.result.html - processed popup HTML
- Template Processing: Uses standard Nunjucks syntax with feature properties as variables
- Media Detection: Viewer components automatically detect media type from URLs
- Component Registration: Web components auto-register when imported via side effects
- Style Isolation: Each component defines styles in a separate
*-styles.tsfile using Lit'scsstemplate literal - Testing: Vitest with JSDOM for Web Components, includes DOM cleanup and async element update testing