shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$text_bitmap$utils$getBitmapTextLayout = function(global, require, module, exports) { function alignCenter(measurementData) { for (let i = 0; i < measurementData.lines.length; i++) { const line = measurementData.lines[i], offset = measurementData.width / 2 - line.width / 2; for (let j = 0; j < line.charPositions.length; j++) { line.charPositions[j] += offset; } } } function alignRight(measurementData) { for (let i = 0; i < measurementData.lines.length; i++) { const line = measurementData.lines[i], offset = measurementData.width - line.width; for (let j = 0; j < line.charPositions.length; j++) { line.charPositions[j] += offset; } } } function alignJustify(measurementData) { const width = measurementData.width; for (let i = 0; i < measurementData.lines.length - 2; i++) { const line = measurementData.lines[i]; let indy = 0, spaceIndex = line.spacesIndex[indy++], offset = 0; const spaceWidth = (width - line.width) / line.spacesIndex.length; for (let j = 0; j < line.charPositions.length; j++) { j === spaceIndex && (spaceIndex = line.spacesIndex[indy++], offset += spaceWidth), line.charPositions[j] += offset; } } } var textTokenization = require("module$node_modules$pixi_DOT_js$lib$scene$text$canvas$utils$textTokenization"); "use strict"; exports.getBitmapTextLayout = function(chars, style, font, trimEnd) { const layoutData = {width:0, height:0, offsetY:0, scale:style.fontSize / font.baseMeasurementFontSize, lines:[{width:0, charPositions:[], spaceWidth:0, spacesIndex:[], chars:[]}]}; layoutData.offsetY = font.baseLineOffset; let currentLine = layoutData.lines[0]; var previousChar = null; let firstWord = !0; const currentWord = {spaceWord:!1, width:0, start:0, index:0, positions:[], chars:[]}; var scale = font.baseMeasurementFontSize / style.fontSize; const adjustedLetterSpacing = style.letterSpacing * scale, adjustedWordWrapWidth = style.wordWrapWidth * scale, adjustedLineHeight = style.lineHeight ? style.lineHeight * scale : font.lineHeight; scale = style.wordWrap && style.breakWords; const shouldCollapseSpaces = textTokenization.collapseSpaces(style.whiteSpace); var shouldCollapseNewlines = textTokenization.collapseNewlines(style.whiteSpace); if (shouldCollapseSpaces || shouldCollapseNewlines) { var processed = [], prevWasBreakingSpace = shouldCollapseSpaces; for (var c = 0; c < chars.length; c++) { var char$jscomp$0 = chars[c]; if ("\r" === char$jscomp$0 || "\n" === char$jscomp$0) { if (shouldCollapseNewlines) { "\r" === char$jscomp$0 && "\n" === chars[c + 1] && c++, char$jscomp$0 = " "; } else { shouldCollapseSpaces && (prevWasBreakingSpace = !0); processed.push(char$jscomp$0); continue; } } textTokenization.isBreakingSpace(char$jscomp$0) ? shouldCollapseSpaces && textTokenization.isCollapsibleSpace(char$jscomp$0) ? prevWasBreakingSpace || (prevWasBreakingSpace = !0, processed.push(" ")) : (prevWasBreakingSpace = !1, processed.push(char$jscomp$0)) : (prevWasBreakingSpace = !1, processed.push(char$jscomp$0)); } chars = processed; } shouldCollapseNewlines = word => { const start = currentLine.width; for (let j = 0; j < currentWord.index; j++) { const position = word.positions[j]; currentLine.chars.push(word.chars[j]); currentLine.charPositions.push(position + start); } currentLine.width += word.width; if (0 < currentWord.index || !shouldCollapseSpaces) { firstWord = !1; } currentWord.width = 0; currentWord.index = 0; currentWord.chars.length = 0; }; processed = () => { let index = currentLine.chars.length - 1; if (trimEnd) { let lastChar = currentLine.chars[index]; for (; textTokenization.isCollapsibleSpace(lastChar);) { currentLine.width -= font.chars[lastChar].xAdvance, currentLine.spacesIndex.pop(), lastChar = currentLine.chars[--index]; } } layoutData.width = Math.max(layoutData.width, currentLine.width); currentLine = {width:0, charPositions:[], chars:[], spaceWidth:0, spacesIndex:[]}; firstWord = !0; layoutData.lines.push(currentLine); layoutData.height += adjustedLineHeight; }; for (prevWasBreakingSpace = 0; prevWasBreakingSpace < chars.length + 1; prevWasBreakingSpace++) { let char; (char$jscomp$0 = prevWasBreakingSpace === chars.length) || (char = chars[prevWasBreakingSpace]); c = font.chars[char]; /(?:\s)/.test(char) || "\r" === char || "\n" === char || char$jscomp$0 ? (!firstWord && style.wordWrap && currentLine.width + currentWord.width - adjustedLetterSpacing > adjustedWordWrapWidth ? processed() : currentWord.start = currentLine.width, shouldCollapseNewlines(currentWord), !char$jscomp$0 && c && currentLine.charPositions.push(0), "\r" === char || "\n" === char ? processed() : !char$jscomp$0 && c && (previousChar = c.xAdvance + (c.kerning?.[previousChar] || 0) + adjustedLetterSpacing, currentLine.width += previousChar, currentLine.spaceWidth = previousChar, currentLine.spacesIndex.push(currentLine.charPositions.length), currentLine.chars.push(char))) : c && (previousChar = c.kerning?.[previousChar] || 0, c = c.xAdvance + previousChar + adjustedLetterSpacing, scale && currentWord.width + c - adjustedLetterSpacing > adjustedWordWrapWidth && (firstWord || processed(), shouldCollapseNewlines(currentWord), processed()), currentWord.positions[currentWord.index++] = currentWord.width + previousChar, currentWord.chars.push(char), currentWord.width += c, textTokenization.isBreakAfterChar(char) && (!firstWord && style.wordWrap && currentLine.width + currentWord.width - adjustedLetterSpacing > adjustedWordWrapWidth && processed(), shouldCollapseNewlines(currentWord))); previousChar = char; } processed(); "center" === style.align ? alignCenter(layoutData) : "right" === style.align ? alignRight(layoutData) : "justify" === style.align && alignJustify(layoutData); return layoutData; }; }; //# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$text_bitmap$utils$getBitmapTextLayout.js.map