• 简体中文
  • 末尾渐变

    shad 使用移动渐变,让末尾文字逐渐显现。已经显示的内容保持不变,最后几个字符随着流式输出慢慢变得清晰。

    末尾渐变

    使用方式

    选择对应框架查看代码。Core 示例中的 mappers 传入 Core 输入,并显式启用 mapper;组件通过 streaming.effect 启用相同效果,并内置视觉渲染器。

    import type { MapperPluggable } from '@fluxdown/core';
    import { Smooth } from '@fluxdown/core-plugins/plugins/mapper/smooth';
    import { Shad } from '@fluxdown/core-plugins/plugins/mapper/shad';
    
    const mappers: MapperPluggable[] = [
      [Smooth, { enabled: true }],
      [Shad, { enabled: true }],
    ];

    平滑化默认启用。按排版需要调整末尾字符数与渐变宽度:

    import type { MapperPluggable } from '@fluxdown/core';
    import { Smooth } from '@fluxdown/core-plugins/plugins/mapper/smooth';
    import { Shad } from '@fluxdown/core-plugins/plugins/mapper/shad';
    
    const mappers: MapperPluggable[] = [
      [Smooth, { enabled: true }],
      [Shad, { enabled: true, length: 3, maskWidth: 18 }],
    ];

    配置

    以下字段属于 ['shad', config] 中的 shad 配置对象。

    enabled 可选

    类型: boolean

    默认值: true

    是否开启末尾渐变。

    length 可选

    类型: number

    默认值: 10

    参与渐变的末尾字符数。小数向下取整,负数和非有限值按 0 处理。

    maskWidth 可选

    类型: number

    默认值: 15

    渐变遮罩宽度,单位为像素。0 隐藏遮罩,负数按 0 处理,非有限值使用默认宽度。