|
395 | 395 | * @param maxCharacters The maximum number of characters per line |
396 | 396 | * @returns A new string with line breaks inserted, so each line is within `maxCharacters` length |
397 | 397 | */ |
398 | | - function getStringWithLineBreaks(string, maxCharacters) { |
| 398 | + function addLineBreaks(string, maxCharacters) { |
399 | 399 | const splitRegex = new RegExp('(.{' + maxCharacters + '}[^ ]* )', 'g'); |
400 | 400 | return string.replace(splitRegex, '$1\n'); |
401 | 401 | } |
|
413 | 413 | } |
414 | 414 | return false; |
415 | 415 | } |
| 416 | + /** |
| 417 | + * |
| 418 | + * @param string The input string to add line breaks to |
| 419 | + * @param maxCharacters The maximum characters in each line |
| 420 | + * @param minWords The minimum number of words in a line |
| 421 | + * @returns The given string with line breaks inserted, where each line has less than `maxCharacters`. If a line has less than the `minWords`, line breaks are inserted more often to avoid short lines. |
| 422 | + */ |
416 | 423 | function breakWithoutOrphans(string, maxCharacters, minWords, options = { |
417 | 424 | minCharacters: 12, |
418 | 425 | characterStep: 4, |
419 | 426 | }) { |
420 | 427 | function smartBreak(string, maxCharacters, minWords, options) { |
421 | | - const brokenString = getStringWithLineBreaks(string, maxCharacters); |
| 428 | + const brokenString = addLineBreaks(string, maxCharacters); |
422 | 429 | if (!hasAShortLine(brokenString, minWords) || |
423 | 430 | maxCharacters < options.minCharacters) { |
424 | 431 | return brokenString; |
|
427 | 434 | } |
428 | 435 | return smartBreak(string, maxCharacters, minWords, options); |
429 | 436 | } |
| 437 | + /** |
| 438 | + * |
| 439 | + * @returns A scale value that will stay consistent regardless of the parent layers scale |
| 440 | + */ |
430 | 441 | function maintainScale(parentLayer = thisLayer.parent) { |
431 | 442 | if (typeof thisLayer.transform === 'undefined') { |
432 | 443 | throw funcError('maintainScale', `Current layer (${thisLayer.name}) doesn't have transform values`); |
|
441 | 452 | ? (scale * 100) / (parentLayer.transform.scale.value[index] || 0) |
442 | 453 | : 0); |
443 | 454 | } |
| 455 | + /** |
| 456 | + * |
| 457 | + * @param position The position value to offset from |
| 458 | + * @param offset The amount to offset from the given `position` |
| 459 | + * @param anchor The direction to offset it, e.g. an anchor of 'topLeft' will offset towards the bottom right |
| 460 | + * @returns The given position value plus the offset, in the direction away from the given `anchor` |
| 461 | + */ |
444 | 462 | function offsetFromAnchor(position, [offsetX, offsetY], anchor) { |
445 | 463 | switch (anchor) { |
446 | 464 | case 'topLeft': |
|
477 | 495 | breakWithoutOrphans, |
478 | 496 | maintainScale, |
479 | 497 | offsetFromAnchor, |
480 | | - getStringWithLineBreaks, |
| 498 | + addLineBreaks, |
481 | 499 | }; |
482 | 500 | }, |
483 | 501 | version: '2.0.1', |
|
0 commit comments