Skip to content

Commit 013f051

Browse files
ndbroadbentclaude
andcommitted
Add lightweight chat-to-map/shared export for web workers
Creates a minimal export path with zero heavy dependencies: - src/shared/index.ts: Types + pure utility functions only - src/categories-core.ts: Category definitions without lucide-static - Bundle size: 2.16 KB (5 modules) Exports available via `chat-to-map/shared`: - All core types (ActivityCategory, ClassifiedActivity, etc.) - Pure functions (calculateCombinedScore, formatLocation, isMappable) - Category constants (VALID_CATEGORIES, CATEGORY_EMOJI, CATEGORY_COLORS) No heavy dependencies: pdfkit, exceljs, lucide-static, sharp excluded. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a72ab68 commit 013f051

File tree

5 files changed

+190
-135
lines changed

5 files changed

+190
-135
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
"import": "./dist/index.js",
3939
"default": "./dist/index.js"
4040
},
41+
"./shared": {
42+
"types": "./dist/shared/index.d.ts",
43+
"import": "./dist/shared/index.js",
44+
"default": "./dist/shared/index.js"
45+
},
4146
"./costs": {
4247
"types": "./dist/costs/index.d.ts",
4348
"import": "./dist/costs/index.js",
@@ -52,7 +57,7 @@
5257
"scripts": {
5358
"cli": "bun run src/cli.ts",
5459
"dev": "bun run --watch src/cli.ts",
55-
"build": "bun build src/index.ts --outdir dist --target node && bun build src/costs/index.ts --outdir dist/costs --target node && bun build src/cli.ts --outdir dist --target node && tsc -p tsconfig.types.json",
60+
"build": "bun build src/index.ts --outdir dist --target node && bun build src/shared/index.ts --outdir dist/shared --target node && bun build src/costs/index.ts --outdir dist/costs --target node && bun build src/cli.ts --outdir dist --target node && tsc -p tsconfig.types.json",
5661
"build:types": "tsc -p tsconfig.types.json",
5762
"build:types:watch": "tsc -p tsconfig.types.json --watch",
5863
"build:binary": "bun build src/cli.ts --compile --outfile chat-to-map",

src/categories-core.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Activity Categories - Core Definitions
3+
*
4+
* Lightweight category definitions without icon dependencies.
5+
* Used by shared/index.ts for tree-shaking.
6+
*/
7+
8+
export const VALID_CATEGORIES = [
9+
'food',
10+
'nightlife',
11+
'nature',
12+
'arts',
13+
'culture',
14+
'music',
15+
'entertainment',
16+
'events',
17+
'sports',
18+
'fitness',
19+
'wellness',
20+
'shopping',
21+
'travel',
22+
'experiences',
23+
'hobbies',
24+
'gaming',
25+
'learning',
26+
'home',
27+
'work',
28+
'social',
29+
'family',
30+
'pets',
31+
'other'
32+
] as const
33+
34+
export type ActivityCategory = (typeof VALID_CATEGORIES)[number]
35+
36+
/** Emoji for each activity category */
37+
export const CATEGORY_EMOJI: Record<ActivityCategory, string> = {
38+
food: '🍽️',
39+
nightlife: '🍸',
40+
nature: '🌲',
41+
arts: '🎨',
42+
culture: '🏛️',
43+
music: '🎵',
44+
entertainment: '🎬',
45+
events: '🎉',
46+
sports: '⚽',
47+
fitness: '💪',
48+
wellness: '🧘',
49+
shopping: '🛍️',
50+
travel: '✈️',
51+
experiences: '✨',
52+
hobbies: '🎯',
53+
gaming: '🎮',
54+
learning: '📚',
55+
home: '🏠',
56+
work: '💼',
57+
social: '👥',
58+
family: '👨‍👩‍👧',
59+
pets: '🐾',
60+
other: '📍'
61+
}
62+
63+
/** Background color for each activity category (Tailwind CSS 500-600 shades) */
64+
export const CATEGORY_COLORS: Record<ActivityCategory, string> = {
65+
food: '#ef4444', // red-500
66+
nightlife: '#8b5cf6', // violet-500
67+
nature: '#22c55e', // green-500
68+
arts: '#f26b1f', // orange-550 (between 500 and 600)
69+
culture: '#6366f1', // indigo-500
70+
music: '#ec4899', // pink-500
71+
entertainment: '#ca8a04', // yellow-600
72+
events: '#14b8a6', // teal-500
73+
sports: '#3b82f6', // blue-500
74+
fitness: '#f43f5e', // rose-500
75+
wellness: '#d946ef', // fuchsia-500
76+
shopping: '#a855f7', // purple-500
77+
travel: '#0ea5e9', // sky-500
78+
experiences: '#d97706', // amber-600
79+
hobbies: '#65a30d', // lime-600
80+
gaming: '#7c3aed', // violet-600
81+
learning: '#0284c7', // sky-600
82+
home: '#78716c', // stone-500
83+
work: '#64748b', // slate-500
84+
social: '#06b6d4', // cyan-500
85+
family: '#fb7185', // rose-400
86+
pets: '#65a30d', // lime-600
87+
other: '#6b7280' // gray-500
88+
}

src/categories.ts

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*
44
* Source of truth for valid categories and their emoji/icons.
55
* Used across classifier, images, exports, and UI.
6+
*
7+
* Note: For lightweight imports without lucide-static, use categories-core.ts
68
*/
79

810
import {
@@ -31,60 +33,15 @@ import {
3133
Wine
3234
} from 'lucide-static'
3335

34-
export const VALID_CATEGORIES = [
35-
'food',
36-
'nightlife',
37-
'nature',
38-
'arts',
39-
'culture',
40-
'music',
41-
'entertainment',
42-
'events',
43-
'sports',
44-
'fitness',
45-
'wellness',
46-
'shopping',
47-
'travel',
48-
'experiences',
49-
'hobbies',
50-
'gaming',
51-
'learning',
52-
'home',
53-
'work',
54-
'social',
55-
'family',
56-
'pets',
57-
'other'
58-
] as const
59-
60-
export type ActivityCategory = (typeof VALID_CATEGORIES)[number]
36+
// Re-export core definitions (no heavy dependencies)
37+
export {
38+
type ActivityCategory,
39+
CATEGORY_COLORS,
40+
CATEGORY_EMOJI,
41+
VALID_CATEGORIES
42+
} from './categories-core'
6143

62-
/** Emoji for each activity category */
63-
export const CATEGORY_EMOJI: Record<ActivityCategory, string> = {
64-
food: '🍽️',
65-
nightlife: '🍸',
66-
nature: '🌲',
67-
arts: '🎨',
68-
culture: '🏛️',
69-
music: '🎵',
70-
entertainment: '🎬',
71-
events: '🎉',
72-
sports: '⚽',
73-
fitness: '💪',
74-
wellness: '🧘',
75-
shopping: '🛍️',
76-
travel: '✈️',
77-
experiences: '✨',
78-
hobbies: '🎯',
79-
gaming: '🎮',
80-
learning: '📚',
81-
home: '🏠',
82-
work: '💼',
83-
social: '👥',
84-
family: '👨‍👩‍👧',
85-
pets: '🐾',
86-
other: '📍'
87-
}
44+
import type { ActivityCategory } from './categories-core'
8845

8946
/** Lucide SVG icon for each activity category */
9047
export const CATEGORY_ICONS: Record<ActivityCategory, string> = {
@@ -112,30 +69,3 @@ export const CATEGORY_ICONS: Record<ActivityCategory, string> = {
11269
pets: PawPrint,
11370
other: MapPin
11471
}
115-
116-
/** Background color for each activity category (Tailwind CSS 500-600 shades) */
117-
export const CATEGORY_COLORS: Record<ActivityCategory, string> = {
118-
food: '#ef4444', // red-500
119-
nightlife: '#8b5cf6', // violet-500
120-
nature: '#22c55e', // green-500
121-
arts: '#f26b1f', // orange-550 (between 500 and 600)
122-
culture: '#6366f1', // indigo-500
123-
music: '#ec4899', // pink-500
124-
entertainment: '#ca8a04', // yellow-600
125-
events: '#14b8a6', // teal-500
126-
sports: '#3b82f6', // blue-500
127-
fitness: '#f43f5e', // rose-500
128-
wellness: '#d946ef', // fuchsia-500
129-
shopping: '#a855f7', // purple-500
130-
travel: '#0ea5e9', // sky-500
131-
experiences: '#d97706', // amber-600
132-
hobbies: '#65a30d', // lime-600
133-
gaming: '#7c3aed', // violet-600
134-
learning: '#0284c7', // sky-600
135-
home: '#78716c', // stone-500
136-
work: '#64748b', // slate-500
137-
social: '#06b6d4', // cyan-500
138-
family: '#fb7185', // rose-400
139-
pets: '#65a30d', // lime-600
140-
other: '#6b7280' // gray-500
141-
}

src/index.ts

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export {
1919
generateGeocodeCacheKey,
2020
generatePlaceLookupCacheKey
2121
} from './caching/index'
22-
// Categories and default activities
23-
export { VALID_CATEGORIES } from './categories'
22+
// Categories (also available via ./shared/index)
2423
// Classifier module
2524
export type {
2625
ParsedClassification,
@@ -220,55 +219,6 @@ export {
220219
searchWikidata,
221220
tryHeuristicMatch
222221
} from './search/index'
223-
// Types (type-only exports)
224-
export type {
225-
ActivityCategory,
226-
ActivityLink,
227-
ActivityLinkContext,
228-
ActivityLinkMetadata,
229-
ActivityLinkResult,
230-
ActivityLinkType,
231-
ActivityMessage,
232-
ApiError,
233-
ApiErrorType,
234-
CandidateMessage,
235-
CandidateSource,
236-
ChatSource,
237-
CLIOptions,
238-
ClassifiedActivity,
239-
ClassifiedImageHints,
240-
ClassifiedLinkHints,
241-
ClassifierConfig,
242-
ClassifierProvider,
243-
EmbeddedMessage,
244-
EmbeddingConfig,
245-
ExportMetadata,
246-
ExtractorOptions,
247-
ExtractorResult,
248-
GeocodedActivity,
249-
IntentSignals,
250-
MapConfig,
251-
MapStyle,
252-
MediaType,
253-
ParsedMessage,
254-
ParseResult,
255-
ParserOptions,
256-
PDFConfig,
257-
PlaceLookupConfig,
258-
PlaceLookupResult,
259-
PlaceLookupSource,
260-
ProcessingStats,
261-
ProviderConfig,
262-
Result,
263-
SemanticSearchConfig,
264-
SocialPlatform,
265-
UrlType,
266-
WhatsAppFormat
267-
} from './types'
268-
// Type helper functions (value exports)
269-
export { CATEGORY_EMOJI, formatLocation, isMappable } from './types/classifier'
270-
271-
/**
272-
* Library version.
273-
*/
274-
export const VERSION = '0.1.0'
222+
// Shared module re-exports (types + pure functions for lightweight imports)
223+
// These are also available via `chat-to-map/shared` with zero heavy dependencies
224+
export * from './shared/index'

src/shared/index.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* ChatToMap Shared Types & Utilities
3+
*
4+
* Lightweight exports for use in web workers and other environments where
5+
* heavy dependencies (pdfkit, exceljs) should not be bundled.
6+
*
7+
* This module exports ONLY:
8+
* - Type definitions
9+
* - Pure utility functions with zero external dependencies
10+
*
11+
* @license AGPL-3.0
12+
*/
13+
14+
// === Types ===
15+
16+
// Categories (from lightweight core - no lucide-static)
17+
export type { ActivityCategory } from '../categories-core'
18+
export { CATEGORY_COLORS, CATEGORY_EMOJI, VALID_CATEGORIES } from '../categories-core'
19+
// Image types (lightweight - just interfaces)
20+
export type { ImageMeta, ImageMetadata, ImageResult, ImageSource } from '../images/types'
21+
// Scraper types (lightweight - just interfaces)
22+
export type { ScrapedMetadata, ScrapeOutcome } from '../scraper/types'
23+
// Entity resolution types
24+
export type { EntityType, ExternalIdType, ResolvedEntity } from '../search/types'
25+
// Core activity types
26+
// Message types
27+
// Config types
28+
// Result types
29+
export type {
30+
ActivityLink,
31+
ActivityLinkContext,
32+
ActivityLinkMetadata,
33+
ActivityLinkResult,
34+
ActivityLinkType,
35+
ActivityMessage,
36+
ApiError,
37+
ApiErrorType,
38+
CandidateMessage,
39+
CandidateSource,
40+
ChatSource,
41+
CLIOptions,
42+
ClassifiedActivity,
43+
ClassifiedImageHints,
44+
ClassifiedLinkHints,
45+
ClassifierConfig,
46+
ClassifierProvider,
47+
EmbeddedMessage,
48+
EmbeddingConfig,
49+
ExportMetadata,
50+
ExtractorOptions,
51+
ExtractorResult,
52+
GeocodedActivity,
53+
IntentSignals,
54+
MapConfig,
55+
MapStyle,
56+
MediaType,
57+
ParsedMessage,
58+
ParseResult,
59+
ParserOptions,
60+
PDFConfig,
61+
PlaceLookupConfig,
62+
PlaceLookupResult,
63+
PlaceLookupSource,
64+
ProcessingStats,
65+
ProviderConfig,
66+
Result,
67+
SemanticSearchConfig,
68+
SocialPlatform,
69+
UrlType,
70+
WhatsAppFormat
71+
} from '../types'
72+
73+
// === Pure Utility Functions ===
74+
75+
// Activity helpers (zero dependencies)
76+
// Score calculation (zero dependencies)
77+
export { calculateCombinedScore, formatLocation, isMappable } from '../types/classifier'
78+
79+
/**
80+
* Library version.
81+
*/
82+
export const VERSION = '0.1.0'

0 commit comments

Comments
 (0)