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.cjs CHANGED
@@ -832,7 +832,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
832
832
  cancelAnimationFrame(animId);
833
833
  };
834
834
  }
835
- var EMBED_CDN_VERSION = "1.0.15";
835
+ var EMBED_CDN_VERSION = "1.0.16";
836
836
  function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
837
837
  const o = {
838
838
  r: rows,
@@ -1328,6 +1328,95 @@ function renderGridBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
1328
1328
  }
1329
1329
  }
1330
1330
  }
1331
+ function renderAuroraBackground(ctx, width, height, time, mousePos = { x: 0.5, y: 0.5 }, options = {}) {
1332
+ const {
1333
+ fontSize = 14,
1334
+ chars = " \xB7\u2219\u2022:;+=\u2261\u2263#@",
1335
+ color,
1336
+ accentColor = "#d4ff00",
1337
+ speed = 1,
1338
+ layers = 5,
1339
+ softness = 1.2,
1340
+ mouseRipple = 0.2,
1341
+ lightMode = false
1342
+ } = options;
1343
+ const charW = fontSize * 0.62;
1344
+ const lineH = fontSize * 1.4;
1345
+ const cols = Math.ceil(width / charW);
1346
+ const rows = Math.ceil(height / lineH);
1347
+ ctx.clearRect(0, 0, width, height);
1348
+ ctx.font = `${fontSize}px monospace`;
1349
+ ctx.textBaseline = "top";
1350
+ let cr = 255, cg = 255, cb = 255;
1351
+ if (lightMode) {
1352
+ cr = 0;
1353
+ cg = 0;
1354
+ cb = 0;
1355
+ }
1356
+ if (color) {
1357
+ const p = _parseColor(color);
1358
+ if (p) {
1359
+ cr = p.r;
1360
+ cg = p.g;
1361
+ cb = p.b;
1362
+ }
1363
+ }
1364
+ let acR = 212, acG = 255, acB = 0;
1365
+ const ap = _parseColor(accentColor);
1366
+ if (ap) {
1367
+ acR = ap.r;
1368
+ acG = ap.g;
1369
+ acB = ap.b;
1370
+ }
1371
+ const t = time * speed;
1372
+ const layerParams = [];
1373
+ for (let l = 0; l < layers; l++) {
1374
+ const seed = _hash2(l * 17, l * 31 + 7);
1375
+ const seed2 = _hash2(l * 23 + 5, l * 11);
1376
+ layerParams.push({
1377
+ fx: 0.8 + seed * 2.2,
1378
+ // x spatial frequency
1379
+ fy: 1.2 + seed2 * 1.8,
1380
+ // y spatial frequency
1381
+ phase: seed * Math.PI * 4,
1382
+ // phase offset
1383
+ dt: (0.3 + _hash2(l * 7, l * 13 + 3) * 0.5) * (l % 2 === 0 ? 1 : -1),
1384
+ // drift speed & direction
1385
+ amp: 0.55 + _hash2(l * 29, l * 3) * 0.45
1386
+ // amplitude weight
1387
+ });
1388
+ }
1389
+ for (let row = 0; row < rows; row++) {
1390
+ const ny = row / rows;
1391
+ for (let col = 0; col < cols; col++) {
1392
+ const nx = col / cols;
1393
+ const mdx = nx - mousePos.x;
1394
+ const mdy = ny - mousePos.y;
1395
+ const md = Math.sqrt(mdx * mdx + mdy * mdy);
1396
+ const warp = mouseRipple * Math.exp(-md * md / 0.06);
1397
+ const wx = nx + mdx * warp;
1398
+ const wy = ny + mdy * warp;
1399
+ let sum = 0;
1400
+ let totalAmp = 0;
1401
+ for (let l = 0; l < layers; l++) {
1402
+ const { fx, fy, phase, dt, amp } = layerParams[l];
1403
+ 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);
1404
+ sum += wave * amp;
1405
+ totalAmp += amp;
1406
+ }
1407
+ const rawVal = sum / totalAmp;
1408
+ const curved = 0.5 + 0.5 * Math.tanh(rawVal * softness * 2.2);
1409
+ if (curved < 0.12) continue;
1410
+ const normalized = (curved - 0.12) / 0.88;
1411
+ const charIdx = Math.min(chars.length - 1, Math.floor(normalized * chars.length));
1412
+ const ch = chars[charIdx];
1413
+ const isAccent = curved > 0.82;
1414
+ const alpha = lightMode ? curved * 0.18 : curved * 0.14;
1415
+ ctx.fillStyle = isAccent ? `rgba(${acR},${acG},${acB},${lightMode ? 0.5 : 0.32})` : `rgba(${cr},${cg},${cb},${alpha})`;
1416
+ ctx.fillText(ch, col * charW, row * lineH);
1417
+ }
1418
+ }
1419
+ }
1331
1420
  function _parseColor(c) {
1332
1421
  const hex = c.match(/^#([0-9a-f]{3,8})$/i)?.[1];
1333
1422
  if (hex) {
@@ -1411,6 +1500,11 @@ function asciiBackground(target, options = {}) {
1411
1500
  lightMode: renderOpts.lightMode !== void 0 ? renderOpts.lightMode : isLight(),
1412
1501
  color: color ?? renderOpts.color
1413
1502
  });
1503
+ const buildAuroraOpts = () => ({
1504
+ ...renderOpts,
1505
+ lightMode: renderOpts.lightMode !== void 0 ? renderOpts.lightMode : isLight(),
1506
+ color: color ?? renderOpts.color
1507
+ });
1414
1508
  const optsRef = { current: buildWaveOpts() };
1415
1509
  const rebuildOpts = () => {
1416
1510
  if (type === "rain") optsRef.current = buildRainOpts();
@@ -1418,6 +1512,7 @@ function asciiBackground(target, options = {}) {
1418
1512
  else if (type === "pulse") optsRef.current = buildPulseOpts();
1419
1513
  else if (type === "noise") optsRef.current = buildNoiseOpts();
1420
1514
  else if (type === "grid") optsRef.current = buildGridOpts();
1515
+ else if (type === "aurora") optsRef.current = buildAuroraOpts();
1421
1516
  else optsRef.current = buildWaveOpts();
1422
1517
  };
1423
1518
  rebuildOpts();
@@ -1456,6 +1551,8 @@ function asciiBackground(target, options = {}) {
1456
1551
  renderNoiseBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1457
1552
  } else if (type === "grid") {
1458
1553
  renderGridBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1554
+ } else if (type === "aurora") {
1555
+ renderAuroraBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1459
1556
  } else {
1460
1557
  renderWaveBackground(ctx, r.width, r.height, time, smoothMouse, optsRef.current);
1461
1558
  }
@@ -1937,6 +2034,7 @@ exports.generateEmbedCode = generateEmbedCode;
1937
2034
  exports.gifToAsciiFrames = gifToAsciiFrames;
1938
2035
  exports.imageToAsciiFrame = imageToAsciiFrame;
1939
2036
  exports.mountWaveBackground = mountWaveBackground;
2037
+ exports.renderAuroraBackground = renderAuroraBackground;
1940
2038
  exports.renderFrameToCanvas = renderFrameToCanvas;
1941
2039
  exports.renderGridBackground = renderGridBackground;
1942
2040
  exports.renderNoiseBackground = renderNoiseBackground;