asciify-engine 1.0.15 → 1.0.16

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.
package/dist/index.d.cts CHANGED
@@ -407,6 +407,30 @@ declare function renderGridBackground(ctx: CanvasRenderingContext2D, width: numb
407
407
  x: number;
408
408
  y: number;
409
409
  }, options?: GridBackgroundOptions): void;
410
+ interface AuroraBackgroundOptions {
411
+ /** Character grid density. Default 14. */
412
+ fontSize?: number;
413
+ /** Character ramp from sparse to dense. Default fine gradient ramp. */
414
+ chars?: string;
415
+ /** Base character color. Default theme-aware white/black. */
416
+ color?: string;
417
+ /** Accent color for intensity peaks. Default '#d4ff00'. */
418
+ accentColor?: string;
419
+ /** Animation speed multiplier. Default 1. */
420
+ speed?: number;
421
+ /** Number of wave layers stacked. More = richer interference. Default 5. */
422
+ layers?: number;
423
+ /** Wave spread/softness — higher = broader, more diffuse bands. Default 1.2. */
424
+ softness?: number;
425
+ /** Mouse distortion radius (0–1). Elegant ripple that follows the cursor. Default 0.2. */
426
+ mouseRipple?: number;
427
+ /** Force light mode (dark chars on light bg). Default false. */
428
+ lightMode?: boolean;
429
+ }
430
+ declare function renderAuroraBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, mousePos?: {
431
+ x: number;
432
+ y: number;
433
+ }, options?: AuroraBackgroundOptions): void;
410
434
  /**
411
435
  * Drop-in helper that mounts an interactive ASCII wave background onto any
412
436
  * element. Injects a canvas, wires DPR resize, mouse tracking, and the RAF
@@ -429,7 +453,7 @@ declare function renderGridBackground(ctx: CanvasRenderingContext2D, width: numb
429
453
  * useEffect(() => asciiBackground(ref.current).destroy, []);
430
454
  * ```
431
455
  */
432
- interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions {
456
+ interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions, AuroraBackgroundOptions {
433
457
  /**
434
458
  * Which background to render (default: 'wave').
435
459
  * - 'wave' — interactive ASCII field with vortex, sparkles, breathe
@@ -439,7 +463,7 @@ interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOp
439
463
  * - 'noise' — slow-drifting organic fractal noise field
440
464
  * - 'grid' — CRT-style horizontal scan bands with cursor glitch zone
441
465
  */
442
- type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid';
466
+ type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid' | 'aurora';
443
467
  /** CSS opacity applied to the canvas element (default: 0.2) */
444
468
  opacity?: number;
445
469
  /** Extra CSS class names added to the injected canvas */
@@ -485,4 +509,4 @@ interface WebGLRenderer {
485
509
  */
486
510
  declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
487
511
 
488
- export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MountWaveOptions, type NoiseBackgroundOptions, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SourceType, type StarsBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderFrameToCanvas, renderGridBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderStarsBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
512
+ export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MountWaveOptions, type NoiseBackgroundOptions, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SourceType, type StarsBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderFrameToCanvas, renderGridBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderStarsBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
package/dist/index.d.ts CHANGED
@@ -407,6 +407,30 @@ declare function renderGridBackground(ctx: CanvasRenderingContext2D, width: numb
407
407
  x: number;
408
408
  y: number;
409
409
  }, options?: GridBackgroundOptions): void;
410
+ interface AuroraBackgroundOptions {
411
+ /** Character grid density. Default 14. */
412
+ fontSize?: number;
413
+ /** Character ramp from sparse to dense. Default fine gradient ramp. */
414
+ chars?: string;
415
+ /** Base character color. Default theme-aware white/black. */
416
+ color?: string;
417
+ /** Accent color for intensity peaks. Default '#d4ff00'. */
418
+ accentColor?: string;
419
+ /** Animation speed multiplier. Default 1. */
420
+ speed?: number;
421
+ /** Number of wave layers stacked. More = richer interference. Default 5. */
422
+ layers?: number;
423
+ /** Wave spread/softness — higher = broader, more diffuse bands. Default 1.2. */
424
+ softness?: number;
425
+ /** Mouse distortion radius (0–1). Elegant ripple that follows the cursor. Default 0.2. */
426
+ mouseRipple?: number;
427
+ /** Force light mode (dark chars on light bg). Default false. */
428
+ lightMode?: boolean;
429
+ }
430
+ declare function renderAuroraBackground(ctx: CanvasRenderingContext2D, width: number, height: number, time: number, mousePos?: {
431
+ x: number;
432
+ y: number;
433
+ }, options?: AuroraBackgroundOptions): void;
410
434
  /**
411
435
  * Drop-in helper that mounts an interactive ASCII wave background onto any
412
436
  * element. Injects a canvas, wires DPR resize, mouse tracking, and the RAF
@@ -429,7 +453,7 @@ declare function renderGridBackground(ctx: CanvasRenderingContext2D, width: numb
429
453
  * useEffect(() => asciiBackground(ref.current).destroy, []);
430
454
  * ```
431
455
  */
432
- interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions {
456
+ interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOptions, StarsBackgroundOptions, PulseBackgroundOptions, NoiseBackgroundOptions, GridBackgroundOptions, AuroraBackgroundOptions {
433
457
  /**
434
458
  * Which background to render (default: 'wave').
435
459
  * - 'wave' — interactive ASCII field with vortex, sparkles, breathe
@@ -439,7 +463,7 @@ interface AsciiBackgroundOptions extends WaveBackgroundOptions, RainBackgroundOp
439
463
  * - 'noise' — slow-drifting organic fractal noise field
440
464
  * - 'grid' — CRT-style horizontal scan bands with cursor glitch zone
441
465
  */
442
- type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid';
466
+ type?: 'wave' | 'rain' | 'stars' | 'pulse' | 'noise' | 'grid' | 'aurora';
443
467
  /** CSS opacity applied to the canvas element (default: 0.2) */
444
468
  opacity?: number;
445
469
  /** Extra CSS class names added to the injected canvas */
@@ -485,4 +509,4 @@ interface WebGLRenderer {
485
509
  */
486
510
  declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
487
511
 
488
- export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MountWaveOptions, type NoiseBackgroundOptions, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SourceType, type StarsBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderFrameToCanvas, renderGridBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderStarsBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
512
+ export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiBackgroundOptions, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, type AuroraBackgroundOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, type GridBackgroundOptions, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MountWaveOptions, type NoiseBackgroundOptions, type PulseBackgroundOptions, type RainBackgroundOptions, type RenderMode, type SourceType, type StarsBackgroundOptions, type WaveBackgroundOptions, type WebGLRenderer, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderFrameToCanvas, renderGridBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderStarsBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
package/dist/index.js CHANGED
@@ -830,7 +830,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
830
830
  cancelAnimationFrame(animId);
831
831
  };
832
832
  }
833
- var EMBED_CDN_VERSION = "1.0.15";
833
+ var EMBED_CDN_VERSION = "1.0.16";
834
834
  function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
835
835
  const o = {
836
836
  r: rows,
@@ -1326,6 +1326,95 @@ function renderGridBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
1326
1326
  }
1327
1327
  }
1328
1328
  }
1329
+ function renderAuroraBackground(ctx, width, height, time, mousePos = { x: 0.5, y: 0.5 }, options = {}) {
1330
+ const {
1331
+ fontSize = 14,
1332
+ chars = " \xB7\u2219\u2022:;+=\u2261\u2263#@",
1333
+ color,
1334
+ accentColor = "#d4ff00",
1335
+ speed = 1,
1336
+ layers = 5,
1337
+ softness = 1.2,
1338
+ mouseRipple = 0.2,
1339
+ lightMode = false
1340
+ } = options;
1341
+ const charW = fontSize * 0.62;
1342
+ const lineH = fontSize * 1.4;
1343
+ const cols = Math.ceil(width / charW);
1344
+ const rows = Math.ceil(height / lineH);
1345
+ ctx.clearRect(0, 0, width, height);
1346
+ ctx.font = `${fontSize}px monospace`;
1347
+ ctx.textBaseline = "top";
1348
+ let cr = 255, cg = 255, cb = 255;
1349
+ if (lightMode) {
1350
+ cr = 0;
1351
+ cg = 0;
1352
+ cb = 0;
1353
+ }
1354
+ if (color) {
1355
+ const p = _parseColor(color);
1356
+ if (p) {
1357
+ cr = p.r;
1358
+ cg = p.g;
1359
+ cb = p.b;
1360
+ }
1361
+ }
1362
+ let acR = 212, acG = 255, acB = 0;
1363
+ const ap = _parseColor(accentColor);
1364
+ if (ap) {
1365
+ acR = ap.r;
1366
+ acG = ap.g;
1367
+ acB = ap.b;
1368
+ }
1369
+ const t = time * speed;
1370
+ const layerParams = [];
1371
+ for (let l = 0; l < layers; l++) {
1372
+ const seed = _hash2(l * 17, l * 31 + 7);
1373
+ const seed2 = _hash2(l * 23 + 5, l * 11);
1374
+ layerParams.push({
1375
+ fx: 0.8 + seed * 2.2,
1376
+ // x spatial frequency
1377
+ fy: 1.2 + seed2 * 1.8,
1378
+ // y spatial frequency
1379
+ phase: seed * Math.PI * 4,
1380
+ // phase offset
1381
+ dt: (0.3 + _hash2(l * 7, l * 13 + 3) * 0.5) * (l % 2 === 0 ? 1 : -1),
1382
+ // drift speed & direction
1383
+ amp: 0.55 + _hash2(l * 29, l * 3) * 0.45
1384
+ // amplitude weight
1385
+ });
1386
+ }
1387
+ for (let row = 0; row < rows; row++) {
1388
+ const ny = row / rows;
1389
+ for (let col = 0; col < cols; col++) {
1390
+ const nx = col / cols;
1391
+ const mdx = nx - mousePos.x;
1392
+ const mdy = ny - mousePos.y;
1393
+ const md = Math.sqrt(mdx * mdx + mdy * mdy);
1394
+ const warp = mouseRipple * Math.exp(-md * md / 0.06);
1395
+ const wx = nx + mdx * warp;
1396
+ const wy = ny + mdy * warp;
1397
+ let sum = 0;
1398
+ let totalAmp = 0;
1399
+ for (let l = 0; l < layers; l++) {
1400
+ const { fx, fy, phase, dt, amp } = layerParams[l];
1401
+ const wave = Math.sin(wx * fx * Math.PI * 2 + t * dt + phase) * Math.cos(wy * fy * Math.PI * 2 + t * dt * 0.7 + phase * 1.3);
1402
+ sum += wave * amp;
1403
+ totalAmp += amp;
1404
+ }
1405
+ const rawVal = sum / totalAmp;
1406
+ const curved = 0.5 + 0.5 * Math.tanh(rawVal * softness * 2.2);
1407
+ if (curved < 0.12) continue;
1408
+ const normalized = (curved - 0.12) / 0.88;
1409
+ const charIdx = Math.min(chars.length - 1, Math.floor(normalized * chars.length));
1410
+ const ch = chars[charIdx];
1411
+ const isAccent = curved > 0.82;
1412
+ const alpha = lightMode ? curved * 0.18 : curved * 0.14;
1413
+ ctx.fillStyle = isAccent ? `rgba(${acR},${acG},${acB},${lightMode ? 0.5 : 0.32})` : `rgba(${cr},${cg},${cb},${alpha})`;
1414
+ ctx.fillText(ch, col * charW, row * lineH);
1415
+ }
1416
+ }
1417
+ }
1329
1418
  function _parseColor(c) {
1330
1419
  const hex = c.match(/^#([0-9a-f]{3,8})$/i)?.[1];
1331
1420
  if (hex) {
@@ -1409,6 +1498,11 @@ function asciiBackground(target, options = {}) {
1409
1498
  lightMode: renderOpts.lightMode !== void 0 ? renderOpts.lightMode : isLight(),
1410
1499
  color: color ?? renderOpts.color
1411
1500
  });
1501
+ const buildAuroraOpts = () => ({
1502
+ ...renderOpts,
1503
+ lightMode: renderOpts.lightMode !== void 0 ? renderOpts.lightMode : isLight(),
1504
+ color: color ?? renderOpts.color
1505
+ });
1412
1506
  const optsRef = { current: buildWaveOpts() };
1413
1507
  const rebuildOpts = () => {
1414
1508
  if (type === "rain") optsRef.current = buildRainOpts();
@@ -1416,6 +1510,7 @@ function asciiBackground(target, options = {}) {
1416
1510
  else if (type === "pulse") optsRef.current = buildPulseOpts();
1417
1511
  else if (type === "noise") optsRef.current = buildNoiseOpts();
1418
1512
  else if (type === "grid") optsRef.current = buildGridOpts();
1513
+ else if (type === "aurora") optsRef.current = buildAuroraOpts();
1419
1514
  else optsRef.current = buildWaveOpts();
1420
1515
  };
1421
1516
  rebuildOpts();
@@ -1454,6 +1549,8 @@ function asciiBackground(target, options = {}) {
1454
1549
  renderNoiseBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1455
1550
  } else if (type === "grid") {
1456
1551
  renderGridBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1552
+ } else if (type === "aurora") {
1553
+ renderAuroraBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1457
1554
  } else {
1458
1555
  renderWaveBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1459
1556
  }
@@ -1922,6 +2019,6 @@ function tryCreateWebGLRenderer(canvas) {
1922
2019
  }
1923
2020
  }
1924
2021
 
1925
- export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderFrameToCanvas, renderGridBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderStarsBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
2022
+ export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, asciiBackground, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderAuroraBackground, renderFrameToCanvas, renderGridBackground, renderNoiseBackground, renderPulseBackground, renderRainBackground, renderStarsBackground, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
1926
2023
  //# sourceMappingURL=index.js.map
1927
2024
  //# sourceMappingURL=index.js.map