System.register(["cc"], function (_export, _context) {
  "use strict";

  var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, VerbatimEffect, _crd;

  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

  _export("VerbatimEffect", void 0);

  return {
    setters: [function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "0a3efyhuFtIZ6sQMHFeWv8u", "Verbatim", undefined);

      __checkObsolete__(['Label']);
      /*
      ----------------------------------------------- 基础用法
      const typewriter = new VerbatimEffect(this.label, {
          speed: 0.1,       // 每个字符显示间隔
          delay: 1.0,       // 开始前的延迟
          callbackDelay: 0.5 // 完成回调延迟
      });
      //添加文字
      typewriter.addText("第一段文字")
               .addText("第二段文字")
               .addText(["第三段文字", "第四段文字"]);
      //设置回调
      typewriter.onComplete(() => {
          Logger.log("所有文字显示完成");
      });
      //开始播放
      typewriter.start();
      ----------------------------------------------- 显示数组用法
      const verseArr = this.seleteData.verse.split("，");
      const typewriter = new VerbatimEffect(this.verseLabel1, {
          speed: 0.15,
          preserveSpaces: true // 保留空格
      });
      typewriter.addText(verseArr)
               .onTextComplete((text, index) => {
                   Logger.log(`第${index + 1}句显示完成: ${text}`);
               })
               .onComplete(() => {
                   Logger.log("所有诗句显示完成");
               })
               .start();
      ----------------------------------------------- 高阶用法
      const typewriter = new VerbatimEffect(this.label);
      typewriter.addText("Hello World!")
          .addText("This is Typewriter Effect.")
          .onChar((char) => {
              // 每个字符显示时的音效
             audioMgr.playTypingSound();
          })
          .onTextStart((text, index) => {
              Logger.log(`开始显示第${index + 1}段文字: ${text}`);
          })
          .onTextComplete((text, index) => {
              Logger.log(`第${index + 1}段文字显示完成: ${text}`);
          })
          .onComplete(() => {
              Logger.log("全部文字显示完成");
          })
          .start();
      */

      /**
       * 打字机效果配置选项
       */


      /**
       * 打字机效果类 - 实现文字逐字显示效果
       */
      _export("VerbatimEffect", VerbatimEffect = class VerbatimEffect {
        /**
         * 构造函数
         * @param label 要显示文字的Label组件
         * @param options 配置选项
         */
        constructor(label, options) {
          if (options === void 0) {
            options = {};
          }

          this.label = void 0;
          this.textQueue = [];
          this.currentIndex = 0;
          this.isPlaying = false;
          this.options = void 0;
          this.onCompleteCallback = null;
          this.onCharCallback = null;
          this.onTextStartCallback = null;
          this.onTextCompleteCallback = null;
          this.label = label;
          this.options = _extends({
            speed: 0.1,
            delay: 0,
            callbackDelay: 0,
            autoStart: true,
            preserveSpaces: false
          }, options);
        }
        /**
         * 添加要显示的文字
         * @param text 文字内容（可以是字符串或字符串数组）
         * @return 当前实例（支持链式调用）
         */


        addText(text) {
          if (Array.isArray(text)) {
            this.textQueue.push(...text);
          } else {
            this.textQueue.push(text);
          }

          return this;
        }
        /**
         * 设置完成回调
         * @param callback 所有文字显示完成后的回调
         * @return 当前实例（支持链式调用）
         */


        onComplete(callback) {
          this.onCompleteCallback = callback;
          return this;
        }
        /**
         * 设置字符显示回调
         * @param callback 每个字符显示时的回调
         * @return 当前实例（支持链式调用）
         */


        onChar(callback) {
          this.onCharCallback = callback;
          return this;
        }
        /**
         * 设置单个文本开始显示回调
         * @param callback 单个文本开始显示时的回调
         * @return 当前实例（支持链式调用）
         */


        onTextStart(callback) {
          this.onTextStartCallback = callback;
          return this;
        }
        /**
         * 设置单个文本显示完成回调
         * @param callback 单个文本显示完成时的回调
         * @return 当前实例（支持链式调用）
         */


        onTextComplete(callback) {
          this.onTextCompleteCallback = callback;
          return this;
        }
        /**
         * 开始播放文字
         */


        start() {
          if (this.isPlaying || this.textQueue.length === 0) return;
          this.isPlaying = true;
          this.currentIndex = 0;
          this.label.node.active = true;
          this.label.string = '';

          if (this.options.delay && this.options.delay > 0) {
            this.label.scheduleOnce(() => this.playNextText(), this.options.delay);
          } else {
            this.playNextText();
          }
        }
        /**
         * 停止播放
         */


        stop() {
          this.isPlaying = false;
          this.label.unscheduleAllCallbacks();
        }
        /**
         * 跳过当前文本，立即显示完整内容
         */


        skipCurrent() {
          if (!this.isPlaying) return;
          this.label.unscheduleAllCallbacks();
          var currentText = this.textQueue[this.currentIndex];
          this.label.string = this.options.preserveSpaces ? currentText : currentText.replace(/\s/g, '');
          this.handleTextComplete(currentText, this.currentIndex);
        }
        /**
         * 跳过所有，立即显示所有完整内容
         */


        skipAll() {
          if (!this.isPlaying) return;
          this.stop();
          var fullText = '';

          for (var i = this.currentIndex; i < this.textQueue.length; i++) {
            fullText += this.options.preserveSpaces ? this.textQueue[i] : this.textQueue[i].replace(/\s/g, '');
          }

          this.label.string = fullText;

          if (this.onCompleteCallback) {
            this.executeCallback(this.onCompleteCallback, this.options.callbackDelay);
          }
        }
        /**
         * 清空文字队列
         */


        clear() {
          this.stop();
          this.textQueue = [];
          this.currentIndex = 0;
        }
        /**
         * 播放下一个文本（内部方法）
         */


        playNextText() {
          if (!this.isPlaying || this.currentIndex >= this.textQueue.length) {
            this.isPlaying = false;

            if (this.onCompleteCallback) {
              this.executeCallback(this.onCompleteCallback, this.options.callbackDelay);
            }

            return;
          }

          var currentText = this.textQueue[this.currentIndex];
          var processedText = this.options.preserveSpaces ? currentText : currentText.replace(/\s/g, '');
          var chars = processedText.split('');
          var currentPos = 0;
          var displayText = ''; // 触发文本开始回调

          if (this.onTextStartCallback) {
            this.onTextStartCallback(currentText, this.currentIndex);
          }

          var updateFunc = () => {
            if (!this.isPlaying) return;
            var char = chars[currentPos];
            displayText += char;
            this.label.string = displayText; // 触发字符回调

            if (this.onCharCallback) {
              this.onCharCallback(char);
            }

            if (++currentPos >= chars.length) {
              this.label.unschedule(updateFunc);
              this.handleTextComplete(currentText, this.currentIndex++);
            }
          };

          this.label.schedule(updateFunc, this.options.speed, chars.length - 1, 0);
        }
        /**
         * 处理文本完成（内部方法）
         */


        handleTextComplete(text, index) {
          // 触发文本完成回调
          if (this.onTextCompleteCallback) {
            this.onTextCompleteCallback(text, index);
          } // 播放下一个文本


          this.playNextText();
        }
        /**
         * 执行回调（带延迟）
         */


        executeCallback(callback, delay) {
          if (delay === void 0) {
            delay = 0;
          }

          if (delay && delay > 0) {
            this.label.scheduleOnce(() => callback(), delay);
          } else {
            callback();
          }
        }

      });

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=9c895e1052d9f4b627904715030171017e0db11e.js.map