shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$text$canvas$utils$measureTaggedText = function(global, require, module, exports) {
  function wordWrapTaggedLines(runsByLine, style, context, measureTextFn, canBreakCharsFn, wordWrapSplitFn) {
    const {letterSpacing, whiteSpace, wordWrapWidth, breakWords} = style;
    style = textTokenization.collapseSpaces(whiteSpace);
    const adjustedWrapWidth = wordWrapWidth + letterSpacing, tokenWidthCache = {};
    let lastFont = "";
    const measureTokenWidth = (token, tokenStyle) => {
      const cacheKey = `${token}|${tokenStyle.styleKey}`;
      var width = tokenWidthCache[cacheKey];
      void 0 === width && (width = tokenStyle._fontString, width !== lastFont && (lastFont = context.font = width), width = measureTextFn(token, tokenStyle.letterSpacing, context) + tokenStyle.letterSpacing, tokenWidthCache[cacheKey] = width);
      return width;
    }, result = [];
    for (const lineRuns of runsByLine) {
      const styledTokens = tokenizeTaggedRuns(lineRuns);
      runsByLine = result.length;
      var getWordGroupWidth = startIndex => {
        let totalWidth = 0;
        do {
          const {token:groupToken, style:groupStyle} = styledTokens[startIndex];
          totalWidth += measureTokenWidth(groupToken, groupStyle);
          startIndex++;
        } while (startIndex < styledTokens.length && styledTokens[startIndex].continuesFromPrevious);
        return totalWidth;
      };
      const getWordGroupTokens = startIndex => {
        const tokens = [];
        do {
          tokens.push({token:styledTokens[startIndex].token, style:styledTokens[startIndex].style}), startIndex++;
        } while (startIndex < styledTokens.length && styledTokens[startIndex].continuesFromPrevious);
        return tokens;
      };
      let currentLineRuns = [], currentWidth = 0, canPrependSpaces = !style, buildingRun = null;
      const flushBuildingRun = () => {
        buildingRun && 0 < buildingRun.text.length && currentLineRuns.push(buildingRun);
        buildingRun = null;
      }, startNewLine = () => {
        flushBuildingRun();
        if (0 < currentLineRuns.length) {
          const lastRun = currentLineRuns[currentLineRuns.length - 1];
          lastRun.text = textTokenization.trimRight(lastRun.text);
          0 === lastRun.text.length && currentLineRuns.pop();
        }
        result.push(currentLineRuns);
        currentLineRuns = [];
        currentWidth = 0;
        canPrependSpaces = !1;
      };
      for (let i = 0; i < styledTokens.length; i++) {
        const {token, style:tokenStyle, continuesFromPrevious} = styledTokens[i];
        var tokenWidth = measureTokenWidth(token, tokenStyle);
        if (style) {
          var currIsSpace = textTokenization.isBreakingSpace(token), lastChar = buildingRun?.text[buildingRun.text.length - 1] ?? currentLineRuns[currentLineRuns.length - 1]?.text.slice(-1) ?? "";
          lastChar = lastChar ? textTokenization.isBreakingSpace(lastChar) : !1;
          if (currIsSpace && lastChar) {
            continue;
          }
        }
        lastChar = (currIsSpace = !continuesFromPrevious) ? getWordGroupWidth(i) : tokenWidth;
        if (lastChar > adjustedWrapWidth && currIsSpace) {
          if (0 < currentWidth && startNewLine(), breakWords) {
            tokenWidth = getWordGroupTokens(i);
            for (currIsSpace = 0; currIsSpace < tokenWidth.length; currIsSpace++) {
              lastChar = tokenWidth[currIsSpace].style;
              var charGroups = textTokenization.getCharacterGroups(tokenWidth[currIsSpace].token, breakWords, wordWrapSplitFn, canBreakCharsFn);
              for (const char of charGroups) {
                charGroups = measureTokenWidth(char, lastChar), charGroups + currentWidth > adjustedWrapWidth && startNewLine(), buildingRun && buildingRun.style === lastChar ? buildingRun.text += char : (flushBuildingRun(), buildingRun = {text:char, style:lastChar}), currentWidth += charGroups;
              }
            }
            i += tokenWidth.length - 1;
          } else {
            tokenWidth = getWordGroupTokens(i), flushBuildingRun(), result.push(tokenWidth.map(t => ({text:t.token, style:t.style}))), canPrependSpaces = !1, i += tokenWidth.length - 1;
          }
        } else if (lastChar + currentWidth > adjustedWrapWidth && currIsSpace) {
          textTokenization.isBreakingSpace(token) ? canPrependSpaces = !1 : (startNewLine(), buildingRun = {text:token, style:tokenStyle}, currentWidth = tokenWidth);
        } else {
          if (!continuesFromPrevious || breakWords) {
            if (currIsSpace = textTokenization.isBreakingSpace(token), 0 === currentWidth && currIsSpace && !canPrependSpaces) {
              continue;
            }
          }
          buildingRun && buildingRun.style === tokenStyle ? buildingRun.text += token : (flushBuildingRun(), buildingRun = {text:token, style:tokenStyle});
          currentWidth += tokenWidth;
        }
      }
      flushBuildingRun();
      0 < currentLineRuns.length && (getWordGroupWidth = currentLineRuns[currentLineRuns.length - 1], getWordGroupWidth.text = textTokenization.trimRight(getWordGroupWidth.text), 0 === getWordGroupWidth.text.length && currentLineRuns.pop());
      (0 < currentLineRuns.length || result.length === runsByLine) && result.push(currentLineRuns);
    }
    return result;
  }
  function tokenizeTaggedRuns(runs) {
    const styledTokens = [];
    let lastTokenWasWord = !1;
    for (const run of runs) {
      var tokens = textTokenization.tokenize(run.text);
      runs = !0;
      for (const token of tokens) {
        tokens = textTokenization.isBreakingSpace(token) || textTokenization.isNewline(token), styledTokens.push({token, style:run.style, continuesFromPrevious:runs && lastTokenWasWord && !tokens}), lastTokenWasWord = !tokens, runs = !1;
      }
    }
    return styledTokens;
  }
  var parseTaggedText = require("module$node_modules$pixi_DOT_js$lib$scene$text$canvas$utils$parseTaggedText"), textTokenization = require("module$node_modules$pixi_DOT_js$lib$scene$text$canvas$utils$textTokenization");
  "use strict";
  const NEWLINE_TO_SPACE_REGEX = /\r\n|\r|\n/g;
  exports.measureTaggedText = function(text, style, wordWrap, context, measureTextFn, wrapMeasureTextFn, measureFontFn, canBreakCharsFn, wordWrapSplitFn) {
    var runs = parseTaggedText.parseTaggedText(text, style);
    if (textTokenization.collapseNewlines(style.whiteSpace)) {
      for (text = 0; text < runs.length; text++) {
        var run = runs[text];
        runs[text] = {text:run.text.replace(NEWLINE_TO_SPACE_REGEX, " "), style:run.style};
      }
    }
    text = [];
    run = [];
    for (var run$jscomp$0 of runs) {
      runs = run$jscomp$0.text.split(textTokenization.NEWLINE_SPLIT_REGEX);
      for (var i = 0; i < runs.length; i++) {
        var part = runs[i];
        "\r\n" === part || "\r" === part || "\n" === part ? (text.push(run), run = []) : 0 < part.length && run.push({text:part, style:run$jscomp$0.style});
      }
    }
    (0 < run.length || 0 === text.length) && text.push(run);
    wordWrap = wordWrap ? wordWrapTaggedLines(text, style, context, wrapMeasureTextFn, canBreakCharsFn, wordWrapSplitFn) : text;
    wrapMeasureTextFn = [];
    canBreakCharsFn = [];
    wordWrapSplitFn = [];
    run$jscomp$0 = [];
    text = [];
    run = 0;
    runs = measureFontFn(style._fontString);
    0 === runs.fontSize && (runs.fontSize = style.fontSize, runs.ascent = style.fontSize);
    part = "";
    i = !!style.dropShadow;
    let maxRunStrokeWidth = style._stroke?.width || 0;
    for (var lineRuns of wordWrap) {
      let lineWidth = 0, lineAscent = runs.ascent, lineDescent = runs.descent, lineText = "";
      for (const run of lineRuns) {
        var runFont = run.style._fontString, runFontProps = measureFontFn(runFont);
        runFont !== part && (part = context.font = runFont);
        runFont = measureTextFn(run.text, run.style.letterSpacing, context);
        lineWidth += runFont;
        lineAscent = Math.max(lineAscent, runFontProps.ascent);
        lineDescent = Math.max(lineDescent, runFontProps.descent);
        lineText += run.text;
        runFontProps = run.style._stroke?.width || 0;
        runFontProps > maxRunStrokeWidth && (maxRunStrokeWidth = runFontProps);
        !i && run.style.dropShadow && (i = !0);
      }
      0 === lineRuns.length && (lineAscent = runs.ascent, lineDescent = runs.descent);
      wrapMeasureTextFn.push(lineWidth);
      canBreakCharsFn.push(lineAscent);
      wordWrapSplitFn.push(lineDescent);
      text.push(lineText);
      run$jscomp$0.push((style.lineHeight || lineAscent + lineDescent) + style.leading);
      run = Math.max(run, lineWidth);
    }
    context = maxRunStrokeWidth;
    measureTextFn = run + context + (style.dropShadow ? style.dropShadow.distance : 0);
    measureFontFn = 0;
    for (lineRuns = 0; lineRuns < run$jscomp$0.length; lineRuns++) {
      measureFontFn += run$jscomp$0[lineRuns];
    }
    measureFontFn = Math.max(measureFontFn, run$jscomp$0[0] + context);
    return {width:measureTextFn, height:measureFontFn + (style.dropShadow ? style.dropShadow.distance : 0), lines:text, lineWidths:wrapMeasureTextFn, lineHeight:(style.lineHeight || runs.fontSize) + style.leading, maxLineWidth:run, fontProperties:runs, runsByLine:wordWrap, lineAscents:canBreakCharsFn, lineDescents:wordWrapSplitFn, lineHeights:run$jscomp$0, hasDropShadow:i};
  };
  exports.tokenizeTaggedRuns = tokenizeTaggedRuns;
  exports.wordWrapTaggedLines = wordWrapTaggedLines;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$text$canvas$utils$measureTaggedText.js.map
