ai-rag-viewer
PDF viewer component — renders PDF pages with react-pdf (PDF.js), highlights matching text spans from RAG search results, scroll-to-page navigation, and zoom controls. Use this skill when the user says "add PDF viewer", "setup PDF rendering", "setup ai-rag-viewer", or "add document viewer".
What this skill does
# AI RAG Viewer
PDF viewer component built with `react-pdf` (PDF.js wrapper for React). Renders PDF pages, highlights text spans from RAG search results, supports scroll-to-page navigation, and provides zoom controls.
## Prerequisites
- Next.js app with `src/` directory and App Router
- `storage` skill installed (for PDF download URLs)
- Tailwind CSS v4
## Installation
```bash
bun add react-pdf
```
### Copy PDF.js Worker
react-pdf requires the PDF.js worker file. Configure it in the component.
## What Gets Created
```
src/
└── components/
└── rag/
├── pdf-viewer.tsx # Main PDF viewer with page rendering
├── pdf-page.tsx # Single page renderer with text layer
├── pdf-highlights.tsx # Text highlight overlay
└── pdf-toolbar.tsx # Zoom, page nav, download controls
```
## Setup Steps
### Step 1: Configure PDF.js Worker in `next.config.ts`
Add the webpack and turbopack configuration to disable the `canvas` module (not needed in browser):
```typescript
// In next.config.ts, add to the config object:
turbopack: {
resolveAlias: {
canvas: "",
},
},
webpack: (config) => {
config.resolve.alias.canvas = false;
return config;
},
```
### Step 2: Create `src/components/rag/pdf-toolbar.tsx`
```tsx
"use client";
import { Button } from "@/components/ui/button";
import {
MagnifyingGlassPlus,
MagnifyingGlassMinus,
CaretLeft,
CaretRight,
DownloadSimple,
} from "@phosphor-icons/react";
type PdfToolbarProps = {
currentPage: number;
totalPages: number;
scale: number;
onPageChange: (page: number) => void;
onScaleChange: (scale: number) => void;
onDownload?: () => void;
fileName?: string;
};
export function PdfToolbar({
currentPage,
totalPages,
scale,
onPageChange,
onScaleChange,
onDownload,
fileName,
}: PdfToolbarProps) {
return (
<div className="flex items-center justify-between border-b bg-muted/30 px-3 py-2">
<div className="flex items-center gap-1">
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={() => onPageChange(Math.max(1, currentPage - 1))}
disabled={currentPage <= 1}
>
<CaretLeft className="h-4 w-4" />
</Button>
<span className="min-w-[80px] text-center text-sm tabular-nums">
{currentPage} / {totalPages}
</span>
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={() => onPageChange(Math.min(totalPages, currentPage + 1))}
disabled={currentPage >= totalPages}
>
<CaretRight className="h-4 w-4" />
</Button>
</div>
{fileName && (
<span className="hidden max-w-[200px] truncate text-sm text-muted-foreground md:block">
{fileName}
</span>
)}
<div className="flex items-center gap-1">
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={() => onScaleChange(Math.max(0.5, scale - 0.25))}
disabled={scale <= 0.5}
>
<MagnifyingGlassMinus className="h-4 w-4" />
</Button>
<span className="min-w-[50px] text-center text-sm tabular-nums">
{Math.round(scale * 100)}%
</span>
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={() => onScaleChange(Math.min(3, scale + 0.25))}
disabled={scale >= 3}
>
<MagnifyingGlassPlus className="h-4 w-4" />
</Button>
{onDownload && (
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={onDownload}
>
<DownloadSimple className="h-4 w-4" />
</Button>
)}
</div>
</div>
);
}
```
### Step 3: Create `src/components/rag/pdf-highlights.tsx`
```tsx
"use client";
type Highlight = {
text: string;
pageNumber: number;
};
type PdfHighlightsProps = {
highlights: Highlight[];
pageNumber: number;
pageRef: HTMLDivElement | null;
};
/**
* Highlights matching text spans within the PDF.js text layer.
* Uses DOM traversal to find and wrap matching text with highlight spans.
*/
export function PdfHighlights({
highlights,
pageNumber,
pageRef,
}: PdfHighlightsProps) {
// This component doesn't render its own DOM — it applies highlights
// to the text layer rendered by react-pdf via useEffect in the parent.
return null;
}
/**
* Apply text highlights to a PDF page's text layer.
* Call this after the text layer has rendered.
*/
export function applyHighlights(
pageElement: HTMLDivElement,
highlights: Highlight[],
pageNumber: number
): () => void {
const pageHighlights = highlights.filter((h) => h.pageNumber === pageNumber);
if (pageHighlights.length === 0) return () => {};
const textLayer = pageElement.querySelector(".react-pdf__Page__textContent");
if (!textLayer) return () => {};
const spans = textLayer.querySelectorAll("span");
const cleanupFns: (() => void)[] = [];
for (const highlight of pageHighlights) {
const searchText = highlight.text.toLowerCase().trim();
// Find contiguous text spans that contain the search text
// Use a sliding window approach across text layer spans
const words = searchText.split(/\s+/).filter(Boolean);
if (words.length === 0) continue;
const firstWord = words[0];
for (const span of spans) {
const spanText = (span.textContent ?? "").toLowerCase();
if (spanText.includes(firstWord)) {
span.classList.add("rag-highlight");
cleanupFns.push(() => span.classList.remove("rag-highlight"));
}
}
}
return () => {
for (const cleanup of cleanupFns) {
cleanup();
}
};
}
```
### Step 4: Create `src/components/rag/pdf-page.tsx`
```tsx
"use client";
import { useRef, useEffect, useCallback, memo } from "react";
import { Page } from "react-pdf";
import { applyHighlights } from "./pdf-highlights";
type Highlight = {
text: string;
pageNumber: number;
};
type PdfPageProps = {
pageNumber: number;
scale: number;
highlights?: Highlight[];
isActive?: boolean;
};
export const PdfPage = memo(function PdfPage({
pageNumber,
scale,
highlights = [],
isActive = false,
}: PdfPageProps) {
const pageRef = useRef<HTMLDivElement>(null);
const cleanupRef = useRef<(() => void) | null>(null);
const handleTextLayerRendered = useCallback(() => {
// Clean up previous highlights
if (cleanupRef.current) {
cleanupRef.current();
}
if (pageRef.current && highlights.length > 0) {
cleanupRef.current = applyHighlights(
pageRef.current,
highlights,
pageNumber
);
}
}, [highlights, pageNumber]);
useEffect(() => {
return () => {
if (cleanupRef.current) {
cleanupRef.current();
}
};
}, []);
return (
<div
ref={pageRef}
data-page-number={pageNumber}
className={`relative mb-4 shadow-md ${isActive ? "ring-2 ring-blue-500" : ""}`}
>
<Page
pageNumber={pageNumber}
scale={scale}
renderTextLayer={true}
renderAnnotationLayer={true}
onRenderTextLayerSuccess={handleTextLayerRendered}
/>
</div>
);
});
```
### Step 5: Create `src/components/rag/pdf-viewer.tsx`
```tsx
"use client";
import { useState, useRef, useCallback, useEffect, useId } from "react";
import { Document, pdfjs } from "react-pdf";
import "react-pdf/dist/Page/AnnotationLayer.css";
import "react-pdf/dist/Page/TextLayer.css";
import { PdfPage } from "./pdf-page";
import { PdfToolbar } from "./pdf-toolbar";
// Configure PDF.js worker
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
type Highlight = {
text: string;
pageNumber: number;
};
type PdfViewerRelated in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.