shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$text$canvas$utils$wordWrap = function(global, require, module, exports) {
  function getFromCache(key, letterSpacing, cache, context, measureTextFn) {
    let width = cache[key];
    "number" !== typeof width && (width = measureTextFn(key, letterSpacing, context) + letterSpacing, cache[key] = width);
    return width;
  }
  var textTokenization = require("module$node_modules$pixi_DOT_js$lib$scene$text$canvas$utils$textTokenization");
  "use strict";
  const contextSettings = {willReadFrequently:!0};
  exports.wordWrap = function(text, style, canvas, measureTextFn, canBreakWordsFn, canBreakCharsFn, wordWrapSplitFn) {
    const context = canvas.getContext("2d", contextSettings);
    context.font = style._fontString;
    let width = 0, line = "";
    canvas = [];
    const cache = Object.create(null), {letterSpacing, whiteSpace} = style, shouldCollapseSpaces = textTokenization.collapseSpaces(whiteSpace), shouldCollapseNewlines = textTokenization.collapseNewlines(whiteSpace);
    let canPrependSpaces = !shouldCollapseSpaces;
    const wordWrapWidth = style.wordWrapWidth + letterSpacing;
    text = textTokenization.tokenize(text);
    for (let i = 0; i < text.length; i++) {
      var token = text[i];
      if (textTokenization.isNewline(token)) {
        if (!shouldCollapseNewlines) {
          canvas.push(textTokenization.trimRight(line));
          canPrependSpaces = !shouldCollapseSpaces;
          line = "";
          width = 0;
          continue;
        }
        token = " ";
      }
      if (shouldCollapseSpaces) {
        var currIsBreakingSpace = textTokenization.isBreakingSpace(token);
        const lastIsBreakingSpace = textTokenization.isBreakingSpace(line[line.length - 1]);
        if (currIsBreakingSpace && lastIsBreakingSpace) {
          continue;
        }
      }
      currIsBreakingSpace = getFromCache(token, letterSpacing, cache, context, measureTextFn);
      if (currIsBreakingSpace > wordWrapWidth) {
        if ("" !== line && (canvas.push(textTokenization.trimRight(line)), line = "", width = 0), canBreakWordsFn(token, style.breakWords)) {
          token = textTokenization.getCharacterGroups(token, style.breakWords, wordWrapSplitFn, canBreakCharsFn);
          for (const char of token) {
            token = getFromCache(char, letterSpacing, cache, context, measureTextFn), token + width > wordWrapWidth && (canvas.push(textTokenization.trimRight(line)), canPrependSpaces = !1, line = "", width = 0), line += char, width += token;
          }
        } else {
          0 < line.length && canvas.push(textTokenization.trimRight(line)), canvas.push(textTokenization.trimRight(token)), canPrependSpaces = !1, line = "", width = 0;
        }
      } else {
        if (currIsBreakingSpace + width > wordWrapWidth && (canPrependSpaces = !1, canvas.push(textTokenization.trimRight(line)), line = "", width = 0), 0 < line.length || !textTokenization.isBreakingSpace(token) || canPrependSpaces) {
          line += token, width += currIsBreakingSpace;
        }
      }
    }
    style = textTokenization.trimRight(line);
    0 < style.length && canvas.push(style);
    return canvas.join("\n");
  };
};

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