Changeset 0c6b92a for imaps-frontend/node_modules/konva/lib/shapes/Text.js
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/konva/lib/shapes/Text.js
rd565449 r0c6b92a 1 1 "use strict"; 2 2 Object.defineProperty(exports, "__esModule", { value: true }); 3 exports.Text = exports.stringToArray = void 0; 3 exports.Text = void 0; 4 exports.stringToArray = stringToArray; 4 5 const Util_1 = require("../Util"); 5 6 const Factory_1 = require("../Factory"); … … 9 10 const Global_2 = require("../Global"); 10 11 function stringToArray(string) { 11 return Array.from(string); 12 } 13 exports.stringToArray = stringToArray; 14 var AUTO = 'auto', CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', LTR = 'ltr', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [ 12 return [...string].reduce((acc, char, index, array) => { 13 if (/\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?(?:\u200D\p{Emoji_Presentation})+/u.test(char)) { 14 acc.push(char); 15 } 16 else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) { 17 acc.push(char + array[index + 1]); 18 } 19 else if (index > 0 && /\p{Mn}|\p{Me}|\p{Mc}/u.test(char)) { 20 acc[acc.length - 1] += char; 21 } 22 else { 23 acc.push(char); 24 } 25 return acc; 26 }, []); 27 } 28 const AUTO = 'auto', CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [ 15 29 'direction', 16 30 'fontFamily', … … 43 57 .join(', '); 44 58 } 45 vardummyContext;59 let dummyContext; 46 60 function getDummyContext() { 47 61 if (dummyContext) { … … 72 86 this._partialTextX = 0; 73 87 this._partialTextY = 0; 74 for ( varn = 0; n < attrChangeListLen; n++) {88 for (let n = 0; n < attrChangeListLen; n++) { 75 89 this.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, this._setTextData); 76 90 } … … 78 92 } 79 93 _sceneFunc(context) { 80 vartextArr = this.textArr, textArrLen = textArr.length;94 const textArr = this.textArr, textArrLen = textArr.length; 81 95 if (!this.text()) { 82 96 return; 83 97 } 84 varpadding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;98 let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n; 85 99 direction = direction === INHERIT ? context.direction : direction; 86 vartranslateY = lineHeightPx / 2;87 varbaseline = MIDDLE;100 let translateY = lineHeightPx / 2; 101 let baseline = MIDDLE; 88 102 if (Global_1.Konva._fixTextRendering) { 89 varmetrics = this.measureSize('M');103 const metrics = this.measureSize('M'); 90 104 baseline = 'alphabetic'; 91 105 translateY = … … 122 136 context.save(); 123 137 context.beginPath(); 124 let yOffset = Global_1.Konva._fixTextRendering138 const yOffset = Global_1.Konva._fixTextRendering 125 139 ? Math.round(fontSize / 4) 126 140 : Math.round(fontSize / 2); … … 142 156 context.save(); 143 157 context.beginPath(); 144 let yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0;158 const yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0; 145 159 context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset); 146 160 spacesNumber = text.split(' ').length - 1; … … 159 173 if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) { 160 174 spacesNumber = text.split(' ').length - 1; 161 vararray = stringToArray(text);162 for ( varli = 0; li < array.length; li++) {163 varletter = array[li];175 const array = stringToArray(text); 176 for (let li = 0; li < array.length; li++) { 177 const letter = array[li]; 164 178 if (letter === ' ' && !lastLine && align === JUSTIFY) { 165 179 lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber; … … 188 202 } 189 203 _hitFunc(context) { 190 varwidth = this.getWidth(), height = this.getHeight();204 const width = this.getWidth(), height = this.getHeight(); 191 205 context.beginPath(); 192 206 context.rect(0, 0, width, height); … … 195 209 } 196 210 setText(text) { 197 varstr = Util_1.Util._isString(text)211 const str = Util_1.Util._isString(text) 198 212 ? text 199 213 : text === null || text === undefined … … 204 218 } 205 219 getWidth() { 206 varisAuto = this.attrs.width === AUTO || this.attrs.width === undefined;220 const isAuto = this.attrs.width === AUTO || this.attrs.width === undefined; 207 221 return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width; 208 222 } 209 223 getHeight() { 210 varisAuto = this.attrs.height === AUTO || this.attrs.height === undefined;224 const isAuto = this.attrs.height === AUTO || this.attrs.height === undefined; 211 225 return isAuto 212 226 ? this.fontSize() * this.textArr.length * this.lineHeight() + … … 223 237 measureSize(text) { 224 238 var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; 225 var_context = getDummyContext(), fontSize = this.fontSize(), metrics;239 let _context = getDummyContext(), fontSize = this.fontSize(), metrics; 226 240 _context.save(); 227 241 _context.font = this._getContextFont(); … … 258 272 line = line.trim(); 259 273 } 260 varwidth = this._getTextWidth(line);274 const width = this._getTextWidth(line); 261 275 return this.textArr.push({ 262 276 text: line, … … 266 280 } 267 281 _getTextWidth(text) { 268 varletterSpacing = this.letterSpacing();269 varlength = text.length;282 const letterSpacing = this.letterSpacing(); 283 const length = text.length; 270 284 return (getDummyContext().measureText(text).width + 271 285 (length ? letterSpacing * (length - 1) : 0)); 272 286 } 273 287 _setTextData() { 274 varlines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();288 let lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis(); 275 289 this.textArr = []; 276 290 getDummyContext().font = this._getContextFont(); 277 varadditionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;278 for ( vari = 0, max = lines.length; i < max; ++i) {279 varline = lines[i];280 varlineWidth = this._getTextWidth(line);291 const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0; 292 for (let i = 0, max = lines.length; i < max; ++i) { 293 let line = lines[i]; 294 let lineWidth = this._getTextWidth(line); 281 295 if (fixedWidth && lineWidth > maxWidth) { 282 296 while (line.length > 0) { 283 varlow = 0, high = line.length, match = '', matchWidth = 0;297 let low = 0, high = line.length, match = '', matchWidth = 0; 284 298 while (low < high) { 285 varmid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;299 const mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth; 286 300 if (substrWidth <= maxWidth) { 287 301 low = mid + 1; … … 296 310 if (wrapAtWord) { 297 311 var wrapIndex; 298 varnextChar = line[match.length];299 varnextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;312 const nextChar = line[match.length]; 313 const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH; 300 314 if (nextIsSpaceOrDash && matchWidth <= maxWidth) { 301 315 wrapIndex = match.length; … … 316 330 textWidth = Math.max(textWidth, matchWidth); 317 331 currentHeightPx += lineHeightPx; 318 varshouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);332 const shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx); 319 333 if (shouldHandleEllipsis) { 320 334 this._tryToAddEllipsisToLastLine(); … … 357 371 } 358 372 _shouldHandleEllipsis(currentHeightPx) { 359 varfontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;373 const fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE; 360 374 return (!shouldWrap || 361 375 (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)); 362 376 } 363 377 _tryToAddEllipsisToLastLine() { 364 varwidth = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();365 varlastLine = this.textArr[this.textArr.length - 1];378 const width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis(); 379 const lastLine = this.textArr[this.textArr.length - 1]; 366 380 if (!lastLine || !shouldAddEllipsis) { 367 381 return; 368 382 } 369 383 if (fixedWidth) { 370 varhaveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;384 const haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth; 371 385 if (!haveSpace) { 372 386 lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
Note:
See TracChangeset
for help on using the changeset viewer.