asciify-engine 1.0.26 → 1.0.27

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
@@ -2236,6 +2236,47 @@ function asciiTextAnsi(source, options = {}, targetWidth, targetHeight) {
2236
2236
  return lines.join("\n");
2237
2237
  }
2238
2238
 
2239
+ // src/core/text-frame.ts
2240
+ function buildTextFrame(text, cols, rows, color = "#505050", opacity = 100) {
2241
+ if (!text || cols <= 0 || rows <= 0) return [];
2242
+ const parsed = parseColor(color) ?? { r: 80, g: 80, b: 80 };
2243
+ const pattern = text;
2244
+ const len = pattern.length;
2245
+ return Array.from(
2246
+ { length: rows },
2247
+ (_, row) => Array.from({ length: cols }, (_2, col) => ({
2248
+ char: pattern[(row * cols + col) % len],
2249
+ r: parsed.r,
2250
+ g: parsed.g,
2251
+ b: parsed.b,
2252
+ a: opacity
2253
+ }))
2254
+ );
2255
+ }
2256
+ function renderTextBackground(ctx, width, height, text, options = {}, hoverPos) {
2257
+ const {
2258
+ fontSize = 10,
2259
+ lineHeight = 1.6,
2260
+ color = "#505050",
2261
+ opacity = 100,
2262
+ hoverEffect = "spotlight",
2263
+ hoverStrength = 0.85,
2264
+ hoverRadius = 0.18,
2265
+ hoverColor = "#d4ff00"
2266
+ } = options;
2267
+ const cols = Math.max(1, Math.floor(width / fontSize));
2268
+ const rows = Math.max(1, Math.floor(height / (fontSize * lineHeight)));
2269
+ const frame = buildTextFrame(text, cols, rows, color, opacity);
2270
+ const renderOpts = {
2271
+ ...DEFAULT_OPTIONS,
2272
+ hoverEffect,
2273
+ hoverStrength,
2274
+ hoverRadius,
2275
+ hoverColor
2276
+ };
2277
+ renderFrameToCanvas(ctx, frame, renderOpts, width, height, 0, hoverPos ?? null);
2278
+ }
2279
+
2239
2280
  // src/core/record.ts
2240
2281
  function createRecorder(canvas, options = {}) {
2241
2282
  const {
@@ -2836,6 +2877,7 @@ exports.asciiTextAnsi = asciiTextAnsi;
2836
2877
  exports.asciify = asciify;
2837
2878
  exports.asciifyGif = asciifyGif;
2838
2879
  exports.asciifyVideo = asciifyVideo;
2880
+ exports.buildTextFrame = buildTextFrame;
2839
2881
  exports.createRecorder = createRecorder;
2840
2882
  exports.gifToAsciiFrames = gifToAsciiFrames;
2841
2883
  exports.imageToAsciiFrame = imageToAsciiFrame;
@@ -2854,6 +2896,7 @@ exports.renderRainBackground = renderRainBackground;
2854
2896
  exports.renderSilkBackground = renderSilkBackground;
2855
2897
  exports.renderStarsBackground = renderStarsBackground;
2856
2898
  exports.renderTerrainBackground = renderTerrainBackground;
2899
+ exports.renderTextBackground = renderTextBackground;
2857
2900
  exports.renderVoidBackground = renderVoidBackground;
2858
2901
  exports.renderWaveBackground = renderWaveBackground;
2859
2902
  exports.tryCreateWebGLRenderer = tryCreateWebGLRenderer;