asciify-engine 1.0.9 → 1.0.11
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/embed.js +1 -1
- package/dist/index.cjs +67 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +67 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -251,6 +251,34 @@ declare function renderWaveBackground(ctx: CanvasRenderingContext2D, width: numb
|
|
|
251
251
|
x: number;
|
|
252
252
|
y: number;
|
|
253
253
|
}, options?: WaveBackgroundOptions): void;
|
|
254
|
+
/**
|
|
255
|
+
* Drop-in helper that mounts an interactive ASCII wave background onto any
|
|
256
|
+
* element. Creates and injects a `<canvas>`, wires mouse tracking, DPR
|
|
257
|
+
* resize, and the RAF loop — all internally.
|
|
258
|
+
*
|
|
259
|
+
* Returns a `destroy()` function to clean everything up.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* // 1 line — that's it:
|
|
264
|
+
* import { mountWaveBackground } from 'asciify-engine';
|
|
265
|
+
* const { destroy } = mountWaveBackground('#hero', { opacity: 0.2 });
|
|
266
|
+
*
|
|
267
|
+
* // React:
|
|
268
|
+
* useEffect(() => mountWaveBackground(ref.current).destroy, []);
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
interface MountWaveOptions extends WaveBackgroundOptions {
|
|
272
|
+
/** CSS opacity applied to the canvas element (default: 0.2) */
|
|
273
|
+
opacity?: number;
|
|
274
|
+
/** Extra CSS class names added to the injected canvas */
|
|
275
|
+
className?: string;
|
|
276
|
+
/** z-index of the canvas (default: 0) */
|
|
277
|
+
zIndex?: number;
|
|
278
|
+
}
|
|
279
|
+
declare function mountWaveBackground(target: string | HTMLElement, options?: MountWaveOptions): {
|
|
280
|
+
destroy: () => void;
|
|
281
|
+
};
|
|
254
282
|
|
|
255
283
|
interface WebGLRenderer {
|
|
256
284
|
render(frame: AsciiFrame, options: AsciiOptions, displayW: number, displayH: number, time: number, hoverPos?: {
|
|
@@ -269,4 +297,4 @@ interface WebGLRenderer {
|
|
|
269
297
|
*/
|
|
270
298
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
271
299
|
|
|
272
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, HOVER_PRESETS, type HoverEffect, type HoverPreset, type RenderMode, type SourceType, type WaveBackgroundOptions, type WebGLRenderer, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
300
|
+
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MountWaveOptions, type RenderMode, type SourceType, type WaveBackgroundOptions, type WebGLRenderer, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderFrameToCanvas, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
package/dist/index.d.ts
CHANGED
|
@@ -251,6 +251,34 @@ declare function renderWaveBackground(ctx: CanvasRenderingContext2D, width: numb
|
|
|
251
251
|
x: number;
|
|
252
252
|
y: number;
|
|
253
253
|
}, options?: WaveBackgroundOptions): void;
|
|
254
|
+
/**
|
|
255
|
+
* Drop-in helper that mounts an interactive ASCII wave background onto any
|
|
256
|
+
* element. Creates and injects a `<canvas>`, wires mouse tracking, DPR
|
|
257
|
+
* resize, and the RAF loop — all internally.
|
|
258
|
+
*
|
|
259
|
+
* Returns a `destroy()` function to clean everything up.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* // 1 line — that's it:
|
|
264
|
+
* import { mountWaveBackground } from 'asciify-engine';
|
|
265
|
+
* const { destroy } = mountWaveBackground('#hero', { opacity: 0.2 });
|
|
266
|
+
*
|
|
267
|
+
* // React:
|
|
268
|
+
* useEffect(() => mountWaveBackground(ref.current).destroy, []);
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
interface MountWaveOptions extends WaveBackgroundOptions {
|
|
272
|
+
/** CSS opacity applied to the canvas element (default: 0.2) */
|
|
273
|
+
opacity?: number;
|
|
274
|
+
/** Extra CSS class names added to the injected canvas */
|
|
275
|
+
className?: string;
|
|
276
|
+
/** z-index of the canvas (default: 0) */
|
|
277
|
+
zIndex?: number;
|
|
278
|
+
}
|
|
279
|
+
declare function mountWaveBackground(target: string | HTMLElement, options?: MountWaveOptions): {
|
|
280
|
+
destroy: () => void;
|
|
281
|
+
};
|
|
254
282
|
|
|
255
283
|
interface WebGLRenderer {
|
|
256
284
|
render(frame: AsciiFrame, options: AsciiOptions, displayW: number, displayH: number, time: number, hoverPos?: {
|
|
@@ -269,4 +297,4 @@ interface WebGLRenderer {
|
|
|
269
297
|
*/
|
|
270
298
|
declare function tryCreateWebGLRenderer(canvas: HTMLCanvasElement): WebGLRenderer | null;
|
|
271
299
|
|
|
272
|
-
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, HOVER_PRESETS, type HoverEffect, type HoverPreset, type RenderMode, type SourceType, type WaveBackgroundOptions, type WebGLRenderer, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
300
|
+
export { ART_STYLE_PRESETS, type AnimationStyle, type ArtStyle, type AsciiCell, type AsciiFrame, type AsciiOptions, type AsciiResult, type AsciifySimpleOptions, CHARSETS, type CharsetKey, type ColorMode, DEFAULT_OPTIONS, HOVER_PRESETS, type HoverEffect, type HoverPreset, type MountWaveOptions, type RenderMode, type SourceType, type WaveBackgroundOptions, type WebGLRenderer, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderFrameToCanvas, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
package/dist/index.js
CHANGED
|
@@ -720,7 +720,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
720
720
|
function serializeFrame(frame, fullColor) {
|
|
721
721
|
const rows = frame.length;
|
|
722
722
|
const cols = rows > 0 ? frame[0].length : 0;
|
|
723
|
-
const stride = fullColor ?
|
|
723
|
+
const stride = fullColor ? 3 : 1;
|
|
724
724
|
const buf = new Uint8Array(1 + rows * cols * stride);
|
|
725
725
|
buf[0] = stride;
|
|
726
726
|
let i = 1;
|
|
@@ -731,10 +731,8 @@ function serializeFrame(frame, fullColor) {
|
|
|
731
731
|
buf[i++] = cell.r;
|
|
732
732
|
buf[i++] = cell.g;
|
|
733
733
|
buf[i++] = cell.b;
|
|
734
|
-
buf[i++] = cell.a;
|
|
735
734
|
} else {
|
|
736
735
|
buf[i++] = Math.round(0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b);
|
|
737
|
-
buf[i++] = cell.a;
|
|
738
736
|
}
|
|
739
737
|
}
|
|
740
738
|
}
|
|
@@ -832,7 +830,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
|
|
|
832
830
|
cancelAnimationFrame(animId);
|
|
833
831
|
};
|
|
834
832
|
}
|
|
835
|
-
var EMBED_CDN_VERSION = "1.0.
|
|
833
|
+
var EMBED_CDN_VERSION = "1.0.11";
|
|
836
834
|
function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
|
|
837
835
|
const o = {
|
|
838
836
|
r: rows,
|
|
@@ -999,6 +997,70 @@ function renderWaveBackground(ctx, width, height, time, mousePos = { x: 0.5, y:
|
|
|
999
997
|
}
|
|
1000
998
|
}
|
|
1001
999
|
}
|
|
1000
|
+
function mountWaveBackground(target, options = {}) {
|
|
1001
|
+
const { opacity = 0.2, className, zIndex = 0, ...renderOpts } = options;
|
|
1002
|
+
const container = typeof target === "string" ? document.querySelector(target) : target;
|
|
1003
|
+
if (!container) {
|
|
1004
|
+
console.warn("[asciify] mountWaveBackground: target not found", target);
|
|
1005
|
+
return { destroy: () => {
|
|
1006
|
+
} };
|
|
1007
|
+
}
|
|
1008
|
+
const prevPosition = container.style.position;
|
|
1009
|
+
if (getComputedStyle(container).position === "static") {
|
|
1010
|
+
container.style.position = "relative";
|
|
1011
|
+
}
|
|
1012
|
+
const canvas = document.createElement("canvas");
|
|
1013
|
+
canvas.style.cssText = [
|
|
1014
|
+
"position:absolute",
|
|
1015
|
+
"inset:0",
|
|
1016
|
+
"width:100%",
|
|
1017
|
+
"height:100%",
|
|
1018
|
+
`opacity:${opacity}`,
|
|
1019
|
+
"pointer-events:none",
|
|
1020
|
+
`z-index:${zIndex}`
|
|
1021
|
+
].join(";");
|
|
1022
|
+
if (className) canvas.className = className;
|
|
1023
|
+
container.prepend(canvas);
|
|
1024
|
+
const ctx = canvas.getContext("2d");
|
|
1025
|
+
const dpr = window.devicePixelRatio || 1;
|
|
1026
|
+
const mouse = { x: 0.5, y: 0.5 };
|
|
1027
|
+
const smoothMouse = { x: 0.5, y: 0.5 };
|
|
1028
|
+
const resize = () => {
|
|
1029
|
+
const r = container.getBoundingClientRect();
|
|
1030
|
+
canvas.width = r.width * dpr;
|
|
1031
|
+
canvas.height = r.height * dpr;
|
|
1032
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
1033
|
+
};
|
|
1034
|
+
resize();
|
|
1035
|
+
const onMouseMove = (e) => {
|
|
1036
|
+
const r = container.getBoundingClientRect();
|
|
1037
|
+
mouse.x = (e.clientX - r.left) / r.width;
|
|
1038
|
+
mouse.y = (e.clientY - r.top) / r.height;
|
|
1039
|
+
};
|
|
1040
|
+
const ro = new ResizeObserver(resize);
|
|
1041
|
+
ro.observe(container);
|
|
1042
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
1043
|
+
let time = 0;
|
|
1044
|
+
let raf = 0;
|
|
1045
|
+
const tick = () => {
|
|
1046
|
+
smoothMouse.x += (mouse.x - smoothMouse.x) * 0.07;
|
|
1047
|
+
smoothMouse.y += (mouse.y - smoothMouse.y) * 0.07;
|
|
1048
|
+
const r = container.getBoundingClientRect();
|
|
1049
|
+
renderWaveBackground(ctx, r.width, r.height, time, smoothMouse, renderOpts);
|
|
1050
|
+
time += 0.016;
|
|
1051
|
+
raf = requestAnimationFrame(tick);
|
|
1052
|
+
};
|
|
1053
|
+
raf = requestAnimationFrame(tick);
|
|
1054
|
+
return {
|
|
1055
|
+
destroy: () => {
|
|
1056
|
+
cancelAnimationFrame(raf);
|
|
1057
|
+
ro.disconnect();
|
|
1058
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
1059
|
+
canvas.remove();
|
|
1060
|
+
container.style.position = prevPosition;
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1002
1064
|
|
|
1003
1065
|
// src/webgl-engine.ts
|
|
1004
1066
|
var VERT_SRC = (
|
|
@@ -1448,6 +1510,6 @@ function tryCreateWebGLRenderer(canvas) {
|
|
|
1448
1510
|
}
|
|
1449
1511
|
}
|
|
1450
1512
|
|
|
1451
|
-
export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, renderFrameToCanvas, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
1513
|
+
export { ART_STYLE_PRESETS, CHARSETS, DEFAULT_OPTIONS, HOVER_PRESETS, asciify, asciifyGif, asciifyVideo, generateAnimatedEmbedCode, generateEmbedCode, gifToAsciiFrames, imageToAsciiFrame, mountWaveBackground, renderFrameToCanvas, renderWaveBackground, tryCreateWebGLRenderer, videoToAsciiFrames };
|
|
1452
1514
|
//# sourceMappingURL=index.js.map
|
|
1453
1515
|
//# sourceMappingURL=index.js.map
|