@autumnsgrove/gossamer 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/dist/animation.js +165 -0
  3. package/dist/animation.test.js +204 -0
  4. package/dist/characters.d.ts.map +1 -1
  5. package/dist/characters.js +176 -0
  6. package/dist/characters.test.js +115 -0
  7. package/dist/colors.d.ts +312 -0
  8. package/dist/colors.d.ts.map +1 -0
  9. package/dist/colors.js +199 -0
  10. package/dist/index.d.ts +5 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +79 -1308
  13. package/dist/index.test.js +92 -0
  14. package/dist/patterns.d.ts +119 -2
  15. package/dist/patterns.d.ts.map +1 -1
  16. package/dist/patterns.js +539 -0
  17. package/dist/patterns.test.js +223 -0
  18. package/dist/renderer.d.ts +27 -0
  19. package/dist/renderer.d.ts.map +1 -1
  20. package/dist/renderer.js +362 -0
  21. package/dist/svelte/GossamerBorder.svelte.d.ts +56 -1
  22. package/dist/svelte/GossamerBorder.svelte.d.ts.map +1 -0
  23. package/{src → dist}/svelte/GossamerClouds.svelte +6 -6
  24. package/dist/svelte/GossamerClouds.svelte.d.ts +31 -1
  25. package/dist/svelte/GossamerClouds.svelte.d.ts.map +1 -0
  26. package/dist/svelte/GossamerImage.svelte.d.ts +28 -1
  27. package/dist/svelte/GossamerImage.svelte.d.ts.map +1 -0
  28. package/dist/svelte/GossamerOverlay.svelte.d.ts +32 -1
  29. package/dist/svelte/GossamerOverlay.svelte.d.ts.map +1 -0
  30. package/dist/svelte/GossamerText.svelte.d.ts +29 -1
  31. package/dist/svelte/GossamerText.svelte.d.ts.map +1 -0
  32. package/dist/svelte/index.js +31 -3649
  33. package/dist/svelte/presets.d.ts +4 -2
  34. package/dist/svelte/presets.js +161 -0
  35. package/dist/utils/canvas.js +139 -0
  36. package/dist/utils/image.js +195 -0
  37. package/dist/utils/performance.js +205 -0
  38. package/package.json +20 -15
  39. package/dist/index.js.map +0 -1
  40. package/dist/style.css +0 -124
  41. package/dist/svelte/index.js.map +0 -1
  42. package/src/animation.test.ts +0 -254
  43. package/src/animation.ts +0 -243
  44. package/src/characters.test.ts +0 -148
  45. package/src/characters.ts +0 -164
  46. package/src/index.test.ts +0 -115
  47. package/src/index.ts +0 -203
  48. package/src/patterns.test.ts +0 -273
  49. package/src/patterns.ts +0 -316
  50. package/src/renderer.ts +0 -309
  51. package/src/svelte/index.ts +0 -75
  52. package/src/svelte/presets.ts +0 -174
  53. package/src/utils/canvas.ts +0 -210
  54. package/src/utils/image.ts +0 -275
  55. package/src/utils/performance.ts +0 -282
  56. /package/{src → dist}/svelte/GossamerBorder.svelte +0 -0
  57. /package/{src → dist}/svelte/GossamerImage.svelte +0 -0
  58. /package/{src → dist}/svelte/GossamerOverlay.svelte +0 -0
  59. /package/{src → dist}/svelte/GossamerText.svelte +0 -0
package/src/characters.ts DELETED
@@ -1,164 +0,0 @@
1
- /**
2
- * Gossamer Character Sets
3
- *
4
- * Predefined character sets for ASCII rendering, ordered from light to dark.
5
- * Character density determines which character represents each brightness level.
6
- */
7
-
8
- /**
9
- * Character set configuration
10
- */
11
- export interface CharacterSet {
12
- /** Unique identifier for the character set */
13
- name: string;
14
- /** Description of the set's aesthetic */
15
- description: string;
16
- /** Characters ordered from lightest (space) to darkest */
17
- characters: string;
18
- /** Recommended use cases */
19
- bestFor: string[];
20
- }
21
-
22
- /**
23
- * Standard character sets for ASCII rendering
24
- */
25
- export const CHARACTER_SETS: Record<string, CharacterSet> = {
26
- standard: {
27
- name: 'Standard',
28
- description: 'Classic ASCII art character set',
29
- characters: ' .:-=+*#%@',
30
- bestFor: ['general', 'images', 'patterns'],
31
- },
32
-
33
- dense: {
34
- name: 'Dense',
35
- description: 'High detail character set with many gradations',
36
- characters: " .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$",
37
- bestFor: ['detailed images', 'portraits', 'high contrast'],
38
- },
39
-
40
- minimal: {
41
- name: 'Minimal',
42
- description: 'Clean and simple with few characters',
43
- characters: ' .:*#',
44
- bestFor: ['backgrounds', 'subtle effects', 'clean aesthetic'],
45
- },
46
-
47
- grove: {
48
- name: 'Grove',
49
- description: 'Organic, soft characters inspired by nature',
50
- characters: ' ·∙•◦○◉●',
51
- bestFor: ['organic patterns', 'soft backgrounds', 'nature themes'],
52
- },
53
-
54
- dots: {
55
- name: 'Dots',
56
- description: 'Braille-like dot patterns',
57
- characters: ' ⋅∘∙●',
58
- bestFor: ['stipple effects', 'pointillism', 'dotted textures'],
59
- },
60
-
61
- blocks: {
62
- name: 'Blocks',
63
- description: 'Block-based characters for sharp edges',
64
- characters: ' ░▒▓█',
65
- bestFor: ['retro effects', 'pixel art', 'bold patterns'],
66
- },
67
-
68
- lines: {
69
- name: 'Lines',
70
- description: 'Line-based characters for directional effects',
71
- characters: ' -─═╌│┃',
72
- bestFor: ['rain effects', 'streaks', 'motion blur'],
73
- },
74
-
75
- stars: {
76
- name: 'Stars',
77
- description: 'Star and sparkle characters',
78
- characters: ' ·✧✦✫✬✯★',
79
- bestFor: ['sparkle effects', 'night sky', 'magical themes'],
80
- },
81
-
82
- nature: {
83
- name: 'Nature',
84
- description: 'Nature-themed decorative characters',
85
- characters: ' .~≈∿⌇☘',
86
- bestFor: ['decorative', 'themed effects', 'organic patterns'],
87
- },
88
-
89
- weather: {
90
- name: 'Weather',
91
- description: 'Weather-related symbols',
92
- characters: ' ·.:*❄❅❆',
93
- bestFor: ['snow effects', 'weather simulations', 'seasonal themes'],
94
- },
95
-
96
- binary: {
97
- name: 'Binary',
98
- description: 'Digital-style binary characters',
99
- characters: ' 01',
100
- bestFor: ['digital effects', 'matrix style', 'tech themes'],
101
- },
102
-
103
- math: {
104
- name: 'Math',
105
- description: 'Mathematical symbols',
106
- characters: ' +-×÷=≠≈∞',
107
- bestFor: ['abstract patterns', 'tech themes', 'decorative'],
108
- },
109
- };
110
-
111
- /**
112
- * Get a character set by name
113
- */
114
- export function getCharacterSet(name: string): CharacterSet | undefined {
115
- return CHARACTER_SETS[name];
116
- }
117
-
118
- /**
119
- * Get just the characters string from a named set
120
- */
121
- export function getCharacters(name: string): string {
122
- return CHARACTER_SETS[name]?.characters || CHARACTER_SETS.standard.characters;
123
- }
124
-
125
- /**
126
- * List all available character set names
127
- */
128
- export function getCharacterSetNames(): string[] {
129
- return Object.keys(CHARACTER_SETS);
130
- }
131
-
132
- /**
133
- * Create a custom character set
134
- */
135
- export function createCharacterSet(
136
- name: string,
137
- characters: string,
138
- description: string = '',
139
- bestFor: string[] = []
140
- ): CharacterSet {
141
- return {
142
- name,
143
- description,
144
- characters,
145
- bestFor,
146
- };
147
- }
148
-
149
- /**
150
- * Validate that a character string is suitable for ASCII rendering
151
- * (should start with space and have at least 2 characters)
152
- */
153
- export function validateCharacterSet(characters: string): boolean {
154
- if (characters.length < 2) return false;
155
- if (characters[0] !== ' ') return false;
156
- return true;
157
- }
158
-
159
- /**
160
- * Reverse a character set (for inverted brightness mapping)
161
- */
162
- export function invertCharacters(characters: string): string {
163
- return characters.split('').reverse().join('');
164
- }
package/src/index.test.ts DELETED
@@ -1,115 +0,0 @@
1
- /**
2
- * Tests for core index functions
3
- */
4
- import { describe, it, expect } from 'vitest';
5
- import {
6
- calculateBrightness,
7
- brightnessToChar,
8
- DEFAULT_CHARACTERS,
9
- DEFAULT_CONFIG,
10
- VERSION,
11
- } from './index';
12
-
13
- describe('calculateBrightness', () => {
14
- it('should return 0 for black', () => {
15
- expect(calculateBrightness(0, 0, 0)).toBe(0);
16
- });
17
-
18
- it('should return 255 for white', () => {
19
- expect(calculateBrightness(255, 255, 255)).toBeCloseTo(255, 5);
20
- });
21
-
22
- it('should weight green highest', () => {
23
- // Green contributes 0.72, so pure green should be brighter than pure red
24
- const greenBrightness = calculateBrightness(0, 255, 0);
25
- const redBrightness = calculateBrightness(255, 0, 0);
26
- const blueBrightness = calculateBrightness(0, 0, 255);
27
-
28
- expect(greenBrightness).toBeGreaterThan(redBrightness);
29
- expect(greenBrightness).toBeGreaterThan(blueBrightness);
30
- expect(redBrightness).toBeGreaterThan(blueBrightness);
31
- });
32
-
33
- it('should calculate correct luminance values', () => {
34
- // Pure red: 0.21 * 255 = 53.55
35
- expect(calculateBrightness(255, 0, 0)).toBeCloseTo(53.55, 1);
36
- // Pure green: 0.72 * 255 = 183.6
37
- expect(calculateBrightness(0, 255, 0)).toBeCloseTo(183.6, 1);
38
- // Pure blue: 0.07 * 255 = 17.85
39
- expect(calculateBrightness(0, 0, 255)).toBeCloseTo(17.85, 1);
40
- });
41
-
42
- it('should handle mid-gray', () => {
43
- const gray = calculateBrightness(128, 128, 128);
44
- // 128 * (0.21 + 0.72 + 0.07) = 128
45
- expect(gray).toBe(128);
46
- });
47
- });
48
-
49
- describe('brightnessToChar', () => {
50
- it('should return space for brightness 0', () => {
51
- expect(brightnessToChar(0)).toBe(' ');
52
- });
53
-
54
- it('should return last character for brightness 255', () => {
55
- expect(brightnessToChar(255)).toBe('@');
56
- });
57
-
58
- it('should map mid-brightness to middle character', () => {
59
- // With ' .:-=+*#%@' (10 chars), brightness 127-128 should be around index 4-5
60
- const char = brightnessToChar(127);
61
- expect(['=', '+'].includes(char)).toBe(true);
62
- });
63
-
64
- it('should use custom character set', () => {
65
- const customSet = ' abc';
66
- expect(brightnessToChar(0, customSet)).toBe(' ');
67
- expect(brightnessToChar(255, customSet)).toBe('c');
68
- });
69
-
70
- it('should handle two-character set', () => {
71
- const binarySet = ' #';
72
- expect(brightnessToChar(0, binarySet)).toBe(' ');
73
- expect(brightnessToChar(127, binarySet)).toBe(' ');
74
- expect(brightnessToChar(255, binarySet)).toBe('#');
75
- });
76
-
77
- it('should clamp to valid range', () => {
78
- // Even with extreme values, should not crash
79
- expect(() => brightnessToChar(-10)).not.toThrow();
80
- expect(() => brightnessToChar(300)).not.toThrow();
81
- });
82
- });
83
-
84
- describe('DEFAULT_CHARACTERS', () => {
85
- it('should be standard ASCII art character set', () => {
86
- expect(DEFAULT_CHARACTERS).toBe(' .:-=+*#%@');
87
- });
88
-
89
- it('should start with space', () => {
90
- expect(DEFAULT_CHARACTERS[0]).toBe(' ');
91
- });
92
-
93
- it('should have 10 characters', () => {
94
- expect(DEFAULT_CHARACTERS.length).toBe(10);
95
- });
96
- });
97
-
98
- describe('DEFAULT_CONFIG', () => {
99
- it('should have all required properties', () => {
100
- expect(DEFAULT_CONFIG.characters).toBe(DEFAULT_CHARACTERS);
101
- expect(DEFAULT_CONFIG.cellWidth).toBe(8);
102
- expect(DEFAULT_CONFIG.cellHeight).toBe(12);
103
- expect(DEFAULT_CONFIG.color).toBe('#ffffff');
104
- expect(DEFAULT_CONFIG.backgroundColor).toBe('');
105
- expect(DEFAULT_CONFIG.fontFamily).toBe('monospace');
106
- expect(DEFAULT_CONFIG.animate).toBe(false);
107
- expect(DEFAULT_CONFIG.fps).toBe(30);
108
- });
109
- });
110
-
111
- describe('VERSION', () => {
112
- it('should be a semver string', () => {
113
- expect(VERSION).toMatch(/^\d+\.\d+\.\d+$/);
114
- });
115
- });
package/src/index.ts DELETED
@@ -1,203 +0,0 @@
1
- /**
2
- * Gossamer - ASCII Visual Effects Library
3
- *
4
- * Threads of light. Delicate textures woven through your space.
5
- *
6
- * @packageDocumentation
7
- */
8
-
9
- // =============================================================================
10
- // Core Types
11
- // =============================================================================
12
-
13
- /**
14
- * Core configuration for ASCII rendering
15
- */
16
- export interface GossamerConfig {
17
- /** Character set for ASCII rendering (light to dark) */
18
- characters?: string;
19
- /** Cell width in pixels */
20
- cellWidth?: number;
21
- /** Cell height in pixels */
22
- cellHeight?: number;
23
- /** Foreground color */
24
- color?: string;
25
- /** Background color (transparent if not set) */
26
- backgroundColor?: string;
27
- /** Font family for ASCII characters */
28
- fontFamily?: string;
29
- /** Enable animation loop */
30
- animate?: boolean;
31
- /** Target FPS for animation */
32
- fps?: number;
33
- }
34
-
35
- /**
36
- * Preset configuration for effects
37
- */
38
- export interface PresetConfig {
39
- /** Preset display name */
40
- name: string;
41
- /** Preset description */
42
- description: string;
43
- /** Character set */
44
- characters: string;
45
- /** Pattern type */
46
- pattern: 'perlin' | 'waves' | 'static' | 'ripple' | 'fbm';
47
- /** Pattern frequency */
48
- frequency: number;
49
- /** Pattern amplitude */
50
- amplitude: number;
51
- /** Animation speed */
52
- speed: number;
53
- /** Default opacity */
54
- opacity: number;
55
- }
56
-
57
- // =============================================================================
58
- // Constants
59
- // =============================================================================
60
-
61
- /**
62
- * Default character set ordered from light to dark
63
- */
64
- export const DEFAULT_CHARACTERS = ' .:-=+*#%@';
65
-
66
- /**
67
- * Default configuration values
68
- */
69
- export const DEFAULT_CONFIG: Required<GossamerConfig> = {
70
- characters: DEFAULT_CHARACTERS,
71
- cellWidth: 8,
72
- cellHeight: 12,
73
- color: '#ffffff',
74
- backgroundColor: '',
75
- fontFamily: 'monospace',
76
- animate: false,
77
- fps: 30,
78
- };
79
-
80
- // =============================================================================
81
- // Core Functions
82
- // =============================================================================
83
-
84
- /**
85
- * Calculate brightness from RGB values using luminance formula
86
- * Uses the standard luminance coefficients: 0.21 R + 0.72 G + 0.07 B
87
- */
88
- export function calculateBrightness(r: number, g: number, b: number): number {
89
- return 0.21 * r + 0.72 * g + 0.07 * b;
90
- }
91
-
92
- /**
93
- * Map a brightness value (0-255) to an ASCII character
94
- */
95
- export function brightnessToChar(
96
- brightness: number,
97
- characters: string = DEFAULT_CHARACTERS
98
- ): string {
99
- const index = Math.floor((brightness / 255) * (characters.length - 1));
100
- return characters[Math.min(index, characters.length - 1)];
101
- }
102
-
103
- // =============================================================================
104
- // Module Exports
105
- // =============================================================================
106
-
107
- // Renderer
108
- export { GossamerRenderer } from './renderer';
109
- export type { RenderConfig } from './renderer';
110
-
111
- // Patterns
112
- export {
113
- perlinNoise2D,
114
- fbmNoise,
115
- wavePattern,
116
- ripplePattern,
117
- staticNoise,
118
- seededNoise2D,
119
- generateBrightnessGrid,
120
- gridToImageData,
121
- DEFAULT_PATTERN_CONFIG,
122
- } from './patterns';
123
- export type { PatternConfig, PatternType } from './patterns';
124
-
125
- // Characters
126
- export {
127
- CHARACTER_SETS,
128
- getCharacterSet,
129
- getCharacters,
130
- getCharacterSetNames,
131
- createCharacterSet,
132
- validateCharacterSet,
133
- invertCharacters,
134
- } from './characters';
135
- export type { CharacterSet } from './characters';
136
-
137
- // Animation
138
- export {
139
- createAnimationLoop,
140
- throttle,
141
- debounce,
142
- calculateFPS,
143
- easings,
144
- } from './animation';
145
- export type { AnimationState, AnimationOptions, EasingFunction } from './animation';
146
-
147
- // Canvas Utilities
148
- export {
149
- createCanvas,
150
- getDevicePixelRatio,
151
- resizeCanvasToContainer,
152
- createOffscreenCanvas,
153
- clearCanvas,
154
- getImageData,
155
- optimizeContext,
156
- setupTextRendering,
157
- measureTextWidth,
158
- calculateCellSize,
159
- setBlendMode,
160
- } from './utils/canvas';
161
- export type { CanvasOptions } from './utils/canvas';
162
-
163
- // Image Utilities
164
- export {
165
- loadImage,
166
- loadAndScaleImage,
167
- imageToPixelData,
168
- extractBrightness,
169
- sampleImageCells,
170
- rgbToHex,
171
- hexToRgb,
172
- adjustBrightness,
173
- adjustContrast,
174
- invertColors,
175
- toGrayscale,
176
- } from './utils/image';
177
- export type { ImageLoadOptions } from './utils/image';
178
-
179
- // Performance Utilities
180
- export {
181
- createVisibilityObserver,
182
- createResizeObserver,
183
- prefersReducedMotion,
184
- onReducedMotionChange,
185
- isLowPowerMode,
186
- getRecommendedFPS,
187
- createFPSCounter,
188
- requestIdleCallback,
189
- cancelIdleCallback,
190
- isBrowser,
191
- isCanvasSupported,
192
- isOffscreenCanvasSupported,
193
- } from './utils/performance';
194
- export type { VisibilityCallback, PerformanceMetrics } from './utils/performance';
195
-
196
- // =============================================================================
197
- // Version
198
- // =============================================================================
199
-
200
- /**
201
- * Gossamer version
202
- */
203
- export const VERSION = '0.1.0';