Skip to content

Commit fe0448a

Browse files
committed
Document extension architecture and refresh branding assets
1 parent 569d8a8 commit fe0448a

19 files changed

+348
-1
lines changed

docs/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Documentation Hub
2+
3+
CoderChart centralises product, technical, and process documentation inside `/docs`. Start here for high-level context and jump to deeper guides as needed.
4+
5+
## Project Overview
6+
7+
CoderChart is a Chrome extension that auto-renders Mermaid diagrams on supported AI chat surfaces. It detects Mermaid blocks, injects a themed inline preview with toolbar controls, and keeps settings in sync across browsers via `chrome.storage.sync`.
8+
9+
## Quickstart
10+
11+
```bash
12+
pnpm install
13+
pnpm dev
14+
# Load the dist/ directory as an unpacked extension in Chrome
15+
```
16+
17+
Additional scripts live in `package.json`, including `pnpm build` for production bundles and `pnpm run zip` to package the extension.
18+
19+
## Documentation Map
20+
21+
- [Product Requirements](./prd.md)
22+
- [Architecture](./architecture.md)
23+
- [Extension Flow](./extension-flow.md)
24+
- [UI Guidelines](./ui-guidelines.md)
25+
- [Testing Guide](./testing.md)
26+
- [Changelog](./changelog.md)
27+
28+
## Doc Conventions
29+
30+
- Use Markdown with concise, action-oriented language.
31+
- Reference code with workspace-relative paths (e.g. `src/contentScript/index.ts`).
32+
- Call out defaults and limitations explicitly.
33+
- Prefer Mermaid diagrams for flows or sequences.
34+
35+
## Ownership
36+
37+
Primary owner: _TBD_. Contact: _TBD_. Update this section once a maintainer is assigned.

docs/architecture.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Architecture
2+
3+
CoderChart follows the typical MV3 separation: a background service worker maintains defaults, the content script renders diagrams in-page, and the options UI manages configuration. Shared utilities in `src/shared` allow all surfaces to agree on settings and URL matching.
4+
5+
## Runtime Components
6+
7+
- **Background (`src/background/index.ts`)**
8+
- Runs once on install/upgrade.
9+
- Normalises settings saved in `chrome.storage.sync`, ensuring defaults exist (`autoRender: true`, ChatGPT host patterns).
10+
- Acts as the central authority for schema migrations.
11+
- **Content Script (`src/contentScript/index.ts`)**
12+
- Loads settings on startup and listens for `chrome.storage.onChanged` updates.
13+
- Checks `window.location.href` against the whitelist via `doesUrlMatchPatterns`.
14+
- Sets up DOM observers to detect new Mermaid blocks, renders via Mermaid, and injects inline toolbars plus themed containers.
15+
- Handles export flows by converting SVG strings to downloadable SVG/PNG blobs.
16+
- **Options UI (`src/options/Options.tsx`)**
17+
- Fetches settings on mount, exposes toggles and editable host patterns, and persists updates through `saveSettings`.
18+
- Implements optimistic UI with save-status feedback and reset-to-defaults shortcut.
19+
- Validates input lightly by ignoring empty/duplicate patterns.
20+
- **Shared Utilities (`src/shared`)**
21+
- `settings.ts` centralises defaults, coercion, and persistence helpers.
22+
- `url.ts` compiles user patterns into regular expressions for whitelist checks.
23+
24+
## Data Flow Sequence
25+
26+
```mermaid
27+
flowchart TD
28+
A[Load content script] --> B[getSettings()]
29+
B --> C{autoRender enabled?}
30+
C -- No --> D[Stay idle]
31+
C -- Yes --> E{URL matches whitelist?}
32+
E -- No --> D
33+
E -- Yes --> F[Configure Mermaid theme]
34+
F --> G[Process existing DOM]
35+
G --> H[Start MutationObserver]
36+
H --> I[Render new Mermaid blocks]
37+
I --> J[Update toolbar + downloads]
38+
J --> K[Listen for storage changes]
39+
K --> C
40+
```
41+
42+
## Mermaid Rendering & Downloads
43+
44+
- Mermaid is initialised with `startOnLoad: false` and theming keyed to system or page dark mode.
45+
- Each detected Mermaid block is rendered into a managed container that stores the last SVG string for reuse.
46+
- **SVG export:** cached SVG is wrapped in a Blob and downloaded via `URL.createObjectURL`.
47+
- **PNG export:** the SVG is rendered into an off-screen `<canvas>` using `drawImage`, respecting intrinsic dimensions before exporting to PNG via `canvas.toBlob`.
48+
- Toolbar buttons are disabled until render completes to avoid empty exports.
49+
50+
## Settings Synchronisation
51+
52+
- The background script seeds defaults, but the content script defensively normalises settings each time it loads.
53+
- Storage updates trigger a content-script listener that either re-activates, re-renders, or deactivates depending on `autoRender`/whitelist changes.
54+
- The options UI trims, deduplicates, and validates entries before writing, preventing malformed patterns from breaking runtime checks.
55+
56+
## Known Constraints
57+
58+
- Builds occasionally report Rollup chunk-size warnings; adjust splitting before release if bundle size grows.
59+
- Rendering currently assumes Mermaid syntax; invalid diagrams surface an inline error but do not retry automatically.

docs/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
## 2025-09-26 – Initial Mermaid Rendering Milestone
4+
5+
- Content script renders Mermaid diagrams inline with themed containers and toolbar controls.
6+
- Toolbar enables show/hide, scroll-to-code, and SVG/PNG downloads.
7+
- Options page manages auto-render toggle and host whitelist synced via `chrome.storage.sync`.
8+
- Background script seeds default settings (auto-render true, ChatGPT host patterns) on install.
9+
- Known follow-up: monitor Vite build warnings about chunk sizes before publishing.
10+
11+
_Use ISO dates and reverse chronological order for future entries._

docs/extension-flow.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Extension Flow
2+
3+
This guide walks through the end-to-end experience from installation to exporting rendered diagrams.
4+
5+
## Narrative Flow
6+
7+
1. **Install:** User loads the unpacked build or installs from the Chrome Web Store. The background script seeds default settings in `chrome.storage.sync`.
8+
2. **Grant permissions:** Chrome applies host permissions declared in `manifest.ts` (ChatGPT domains and localhost during development).
9+
3. **Open supported page:** When the user opens chatgpt.com or another whitelisted host, the content script loads, retrieves settings, and checks the URL against the whitelist.
10+
4. **Render diagrams:** Matching Mermaid code fences trigger the inline renderer. Mermaid initialises with theme selection, generates SVG, and injects a container with toolbar controls.
11+
5. **Adjust settings:** Users can visit `options.html` to disable auto-rendering, edit host patterns, or reset to defaults. Changes sync across devices.
12+
6. **Use toolbar:** Inline buttons allow collapsing/expanding the diagram, scrolling back to the source code block, and exporting as SVG or PNG.
13+
7. **Download pipeline:** SVG downloads reuse the cached render, while PNG downloads convert the SVG via an off-screen canvas before prompting a file save.
14+
8. **Keep updated:** A MutationObserver re-runs rendering when the chat adds new content, and storage listeners reconfigure the script when settings change.
15+
16+
## Sequence Diagram
17+
18+
```mermaid
19+
sequenceDiagram
20+
participant U as User
21+
participant C as Chrome
22+
participant B as Background
23+
participant CS as Content Script
24+
participant Opt as Options UI
25+
26+
U->>C: Install extension
27+
C->>B: fire onInstalled
28+
B->>chrome.storage.sync: normalize defaults (autoRender true, ChatGPT hosts)
29+
U->>C: Open chatgpt.com
30+
C->>CS: Inject content script
31+
CS->>chrome.storage.sync: getSettings()
32+
chrome.storage.sync-->>CS: settings
33+
CS->>CS: doesUrlMatchPatterns()
34+
alt Matches whitelist
35+
CS->>Mermaid: initialize(theme)
36+
CS->>U: Render inline diagram and toolbar
37+
else Not matched
38+
CS->>CS: stay dormant
39+
end
40+
U->>Toolbar: Click download SVG/PNG
41+
Toolbar->>CS: fetch cached SVG / convert to PNG
42+
CS->>U: Trigger file download
43+
U->>Opt: Open options page
44+
Opt->>chrome.storage.sync: save updated settings
45+
chrome.storage.sync-->>CS: onChanged event
46+
CS->>CS: Apply settings (activate/deactivate/re-render)
47+
```

docs/prd.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Product Requirements
2+
3+
## Problem Statement
4+
5+
AI chat platforms often expose Mermaid code blocks as raw text, forcing users to copy/paste into external renderers. CoderChart removes that friction by transforming recognised Mermaid snippets directly within the chat interface.
6+
7+
## Goals
8+
9+
- Auto-render Mermaid diagrams on trusted hosts without manual intervention.
10+
- Provide inline controls to manage visibility, navigation, and exports.
11+
- Keep configuration lightweight and synced across Chrome profiles.
12+
- Fail gracefully when diagrams cannot render and surface actionable feedback.
13+
14+
## Target Users
15+
16+
- Engineers and analysts who rely on ChatGPT or similar tools to sketch flows, ERDs, or diagrams.
17+
- Technical writers who review Mermaid output in AI-assisted drafts.
18+
- Product teams evaluating AI-generated diagrams during reviews.
19+
20+
## Key Features
21+
22+
- Default auto-rendering (`autoRender = true`) for fast feedback loops.
23+
- Host whitelist seeded with ChatGPT domains (`https://chatgpt.com/*`, `https://chat.openai.com/*`).
24+
- MutationObserver-driven detection to keep up with streaming chat updates.
25+
- Inline toolbar with show/hide, scroll-to-code, and SVG/PNG download actions.
26+
- Themed containers that respect host dark/light schemes.
27+
- Options page (`options.html`) for toggling auto-render, editing whitelists, and resetting defaults.
28+
29+
## Success Metrics
30+
31+
- 90%+ of Mermaid blocks render without manual refresh.
32+
- Diagram render latency under 500ms on typical chat conversations (after initial page load).
33+
- Less than 5% of renders trigger unhandled errors in production logs.
34+
- At least 50% of active users keep the default auto-render setting enabled.
35+
- Positive qualitative feedback on export quality (SVG/PNG) from beta users.
36+
37+
## Non-goals
38+
39+
- Supporting arbitrary third-party diagramming syntaxes beyond Mermaid.
40+
- Providing a pop-up or new-tab renderer. Focus is inline augmentation.
41+
- Offline mode or local backup of diagrams beyond user-triggered downloads.
42+
- Autosaving edited diagrams or providing a diagram editor.
43+
44+
## Future Roadmap Ideas
45+
46+
- Guided onboarding surfaced on install to highlight toolbar controls.
47+
- Additional host presets (e.g. internal Confluence, GitHub Issues) with user opt-in.
48+
- Granular theme controls for high-contrast or dyslexia-friendly modes.
49+
- Export presets (transparent backgrounds, custom dimensions) for presentation teams.
50+
- Automated integration tests to catch regressions in the download pipeline.
51+
- Resolve build-time chunk-size warnings by tuning Vite rollup settings.

docs/testing.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Testing Guide
2+
3+
## Manual Test Plan
4+
5+
- **Local setup**
6+
- Run `pnpm install` and `pnpm dev`.
7+
- Load the generated `dist/` folder as an unpacked extension in Chrome (Developer Mode on).
8+
- **Settings sanity**
9+
- Confirm defaults: auto-render enabled, whitelist contains ChatGPT domains.
10+
- Toggle auto-render off in `options.html`; verify diagrams stop rendering until re-enabled.
11+
- Add and remove a custom host pattern; ensure the input trims whitespace and disallows duplicates.
12+
- **Rendering lifecycle**
13+
- On chatgpt.com, paste multiple Mermaid snippets (different diagram types) and verify each auto-renders below its code block.
14+
- Trigger chat updates or regenerate responses to confirm the MutationObserver handles new content without duplicates.
15+
- Switch the page between light and dark themes (or toggle system theme) and confirm container styling updates.
16+
- **Toolbar actions**
17+
- Use "Hide diagram" / "Show diagram" toggles; ensure state persists while on the page.
18+
- Click "Scroll to code" and verify smooth scrolling centers the source block.
19+
- Download SVG and PNG; confirm filenames are unique per block and PNG output matches expected dimensions.
20+
- Induce a Mermaid syntax error and check that the inline error pane displays message + hint.
21+
- **Extension lifecycle**
22+
- Reload the extension in `chrome://extensions` to verify background script restores defaults without duplicates.
23+
- Test on a non-whitelisted host to confirm the content script remains dormant.
24+
25+
## Automated Testing Opportunities
26+
27+
- Unit tests around `patternToRegExp` and `doesUrlMatchPatterns` to cover wildcard edge cases.
28+
- Jest/`@testing-library/react` tests for `Options` form interactions (validation, save states, reset behaviour).
29+
- Integration harness (e.g. Puppeteer) to open a static page with seeded Mermaid blocks and assert render/download flows.
30+
- Canvas conversion smoke tests ensuring `convertSvgToPng` returns blobs with expected dimensions.
31+
- CI check to detect Vite chunk-size warnings and fail builds when thresholds exceed targets.
32+
33+
## Known Gaps
34+
35+
- No automated coverage for the content script DOM manipulation; browser-based tests would increase confidence.
36+
- PNG export depends on browser canvas support; add fallbacks or better error messaging if conversion fails.

docs/ui-guidelines.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# UI Guidelines
2+
3+
## Inline Diagram Container
4+
5+
- Present diagrams directly beneath the source code block using a rounded container that mirrors host spacing.
6+
- Header displays "Mermaid diagram" with a compact toolbar aligned to the right.
7+
- Respect page theme changes: detect dark mode via root class or `prefers-color-scheme` and update backgrounds/borders accordingly.
8+
- Keep collapse/expand state intuitive; show "Hide diagram" when expanded and "Show diagram" when collapsed.
9+
10+
## Toolbar Buttons
11+
12+
- Order actions: `Hide diagram`, `Scroll to code`, `Download SVG`, `Download PNG`.
13+
- Disable download buttons until render succeeds to avoid empty files.
14+
- Provide hover feedback with subtle background changes; use consistent sizes and border radii.
15+
- Preserve the original label via `data-coderchart-label` so temporary text (e.g. "Preparing PNG…") can revert cleanly.
16+
17+
## Options Page
18+
19+
- Anchor primary controls (auto-render toggle) at the top of the form with descriptive copy.
20+
- Patterns list supports inline editing; include remove buttons with accessible labels.
21+
- Prevent duplicate or empty patterns; disable the "Add pattern" button until input is valid.
22+
- Show save status feedback (`Saving…`, `Settings saved`, error) near the form footer.
23+
- Include a "Reset to defaults" button for quick recovery.
24+
25+
## Accessibility Considerations
26+
27+
- Buttons and interactive elements use semantic `<button>`/`<input>` elements for screen-reader compatibility.
28+
- Contrast ratios aim to exceed WCAG AA by using muted backgrounds with solid borders and high-contrast text.
29+
- Scroll-to-code uses `scrollIntoView({ behavior: 'smooth', block: 'center' })` to avoid disorienting jumps.
30+
- Error notices provide text explanations and suggestions (`Check the Mermaid syntax and try again`).
31+
- Ensure focus outlines remain visible; do not disable browser outlines via CSS.
32+
33+
## Future Enhancements
34+
35+
- Add keyboard shortcuts for toggling diagrams or triggering exports.
36+
- Offer user-selectable themes or high-contrast mode overrides.
37+
- Surface toast confirmations after downloads to improve feedback.

public/img/logo-1024.png

22.4 KB
Loading

public/img/logo-128.png

-937 Bytes
Loading

public/img/logo-16.png

-79 Bytes
Loading

0 commit comments

Comments
 (0)