Prettified all files.

This commit is contained in:
2019-07-18 12:26:39 +02:00
parent 7744b92771
commit 2d400a18ec
125 changed files with 11184 additions and 8154 deletions
+62 -57
View File
@@ -1438,13 +1438,10 @@
</div>
</header>
<article>
<pre id="source-code" class="prettyprint source linenums"><code>
/**
<pre id="source-code" class="prettyprint source linenums"><code>/**
* Defines usefull default text styles.
*/
export class FontInfo {
static get small() {
return app.theme.textStyleSmall
}
@@ -1460,15 +1457,13 @@ export class FontInfo {
/**
* Static methods to support hyphenation of lines.
*
*
* @class Hypenate
*/
export class Hypenate {
static splitPart(part) {
let parts = part.split('-')
if (parts.length == 1)
return [part]
if (parts.length == 1) return [part]
let result = []
let last = parts.pop()
for (let p of parts) {
@@ -1479,7 +1474,7 @@ export class Hypenate {
}
static splitWord(word) {
if (typeof (language) == 'undefined') {
if (typeof language == 'undefined') {
if (word.indexOf('-') > -1) {
return word.split('-')
}
@@ -1496,13 +1491,13 @@ export class Hypenate {
}
static abbreviateLine(label, style, width) {
const pixiStyle = new PIXI.TextStyle(style)
const pixiStyle = new PIXI.TextStyle(style)
let metrics = PIXI.TextMetrics.measureText(label, pixiStyle)
while(metrics.width > width &amp;&amp; label.length > 3) {
label = label.slice(0, label.length-1)
while (metrics.width > width &amp;&amp; label.length > 3) {
label = label.slice(0, label.length - 1)
metrics = PIXI.TextMetrics.measureText(label, pixiStyle)
}
label = label.slice(0, label.length-1)
label = label.slice(0, label.length - 1)
return label + '…'
}
@@ -1518,17 +1513,21 @@ export class Hypenate {
if (parts.length == 1) {
newWord += '\n' + word + ' '
x = wordMetrics.width + space.width
}
else {
} else {
let first = true
let lastPart = ''
for (let part of parts) {
let partMetrics = PIXI.TextMetrics.measureText(part, pixiStyle)
let partMetrics = PIXI.TextMetrics.measureText(
part,
pixiStyle
)
if (x + partMetrics.width + space.width > width) {
newWord += ((first || lastPart.endsWith('-')) ? '\n' : '-\n') + part
newWord +=
(first || lastPart.endsWith('-')
? '\n'
: '-\n') + part
x = partMetrics.width
}
else {
} else {
newWord += part
x += partMetrics.width
}
@@ -1538,8 +1537,7 @@ export class Hypenate {
x += space.width
}
result += newWord + ' '
}
else {
} else {
result += word + ' '
x += wordMetrics.width + space.width
}
@@ -1548,7 +1546,7 @@ export class Hypenate {
}
/**
* Main method and entry point for text hyphenation
* Main method and entry point for text hyphenation
*
* @static
* @param {*} text
@@ -1571,17 +1569,21 @@ export class Hypenate {
}
class TextLabel extends PIXI.Text {
/**
*Creates an instance of TextLabel.
* @param {string} text - The string that you would like the text to display
* @param {object|PIXI.TextStyle} [style] - The style parameters
* @param {canvas}
* @param {object|PIXI.TextStyle} [style] - The style parameters
* @param {canvas}
* @memberof TextLabel
*/
constructor(text, style=null, canvas=null, { minZoom = 0.1, maxZoom = 10} = {}) {
super(text, style, canvas )
this.normFontSize = this.style.fontSize
constructor(
text,
style = null,
canvas = null,
{ minZoom = 0.1, maxZoom = 10 } = {}
) {
super(text, style, canvas)
this.normFontSize = this.style.fontSize
this.minZoom = minZoom
this.maxZoom = maxZoom
}
@@ -1620,10 +1622,9 @@ class TextLabel extends PIXI.Text {
* @extends {PIXI.Graphics}
*/
export class LabeledGraphics extends PIXI.Graphics {
/**
* Creates an instance of LabeledGraphics and defines a local label cache.
*
*
* @memberof LabeledGraphics
*/
constructor() {
@@ -1635,14 +1636,13 @@ export class LabeledGraphics extends PIXI.Graphics {
return new TextLabel(label, fontInfo)
}
/**
* Main additional method. Ensures that a text object is created that is cached
* under the given key.
*
* @param {*} key - The cache key
* @param {*} label - The label to show
* @param {*} [attrs={}] - Defines attributes of the text object.
* @param {*} [attrs={}] - Defines attributes of the text object.
* align: 'right', 'left', or 'center'
* justify: 'top', 'bottom', or 'center'
* maxLines: {integer} truncates the text and adds ellipsis
@@ -1653,11 +1653,9 @@ export class LabeledGraphics extends PIXI.Graphics {
* @memberof LabeledGraphics
*/
ensureLabel(key, label, attrs = {}, fontInfo = FontInfo.normal) {
if (attrs.maxWidth &amp;&amp; attrs.maxLines == 1) {
label = Hypenate.abbreviateLine(label, fontInfo, attrs.maxWidth)
}
else {
} else {
if (attrs.maxWidth) {
label = Hypenate.splitLines(label, fontInfo, attrs.maxWidth)
}
@@ -1671,7 +1669,7 @@ export class LabeledGraphics extends PIXI.Graphics {
label = this.truncateLabel(label, fontInfo, maxLines)
}
}
if (!this.labels.has(key)) {
let text = this._createText(label, fontInfo)
this.labels.set(key, text)
@@ -1681,8 +1679,7 @@ export class LabeledGraphics extends PIXI.Graphics {
for (let k in attrs) {
text[k] = attrs[k]
}
if (label != text.text)
text.text = label
if (label != text.text) text.text = label
// We do not follow the flexbox jargon and use align for x and justify for y axis
// This deviation is needed to ensure backward compatability
switch (attrs.justify || null) {
@@ -1733,17 +1730,30 @@ export class LabeledGraphics extends PIXI.Graphics {
const truncatedLines = lines.slice(0, maxLines)
const lastLine = truncatedLines[truncatedLines.length - 1]
const words = lastLine.split(' ')
const wordMetrics = PIXI.TextMetrics.measureText(`\u00A0\n...\n${words.join('\n')}`, pixiStyle)
const [spaceLength, dotsLength, ...wordLengths] = wordMetrics.lineWidths
const { text: newLastLine } = wordLengths.reduce((data, wordLength, i) => {
if (data.length + wordLength + spaceLength >= wordWrapWidth) {
return { ...data, length: wordWrapWidth }
}
return {
text: `${data.text}${i > 0 ? ' ' : ''}${words[i]}`,
length: data.length + wordLength + spaceLength,
};
}, { text: '', length: dotsLength })
const wordMetrics = PIXI.TextMetrics.measureText(
`\u00A0\n...\n${words.join('\n')}`,
pixiStyle
)
const [
spaceLength,
dotsLength,
...wordLengths
] = wordMetrics.lineWidths
const { text: newLastLine } = wordLengths.reduce(
(data, wordLength, i) => {
if (
data.length + wordLength + spaceLength >=
wordWrapWidth
) {
return { ...data, length: wordWrapWidth }
}
return {
text: `${data.text}${i > 0 ? ' ' : ''}${words[i]}`,
length: data.length + wordLength + spaceLength
}
},
{ text: '', length: dotsLength }
)
truncatedLines[truncatedLines.length - 1] = `${newLastLine}...`
newText = truncatedLines.join('\n')
}
@@ -1761,7 +1771,7 @@ export class LabeledGraphics extends PIXI.Graphics {
return this.labels.get(key)
}
/**
/**
* Hides the label with the given key.
* @param {*} key
* @memberof LabeledGraphics
@@ -1773,7 +1783,7 @@ export class LabeledGraphics extends PIXI.Graphics {
}
}
/**
/**
* Removes the label with the given key.
* @param {*} key
* @memberof LabeledGraphics
@@ -1784,7 +1794,6 @@ export class LabeledGraphics extends PIXI.Graphics {
label.destroy()
}
/**
* Ensures that labels are hidden on clear.
*
@@ -1807,7 +1816,6 @@ export class LabeledGraphics extends PIXI.Graphics {
}
}
const labelCache = new Map()
function getTexture(label, fontInfo = FontInfo.normal) {
@@ -1825,7 +1833,6 @@ function getTexture(label, fontInfo = FontInfo.normal) {
}
class SpriteLabel extends PIXI.Sprite {
constructor(label, fontInfo) {
let texture = getTexture(label, fontInfo)
super(texture)
@@ -1845,12 +1852,10 @@ class SpriteLabel extends PIXI.Sprite {
}
export class BitmapLabeledGraphics extends LabeledGraphics {
_createText(label, fontInfo) {
let texture = getTexture(label, fontInfo)
return new SpriteLabel(texture)
}
}
</code></pre>
</article>
@@ -1865,7 +1870,7 @@ export class BitmapLabeledGraphics extends LabeledGraphics {
<footer class="content-size">
<div class="footer">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> on Wed Jul 10 2019 11:54:25 GMT+0200 (Mitteleuropäische Sommerzeit)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jul 18 2019 12:16:18 GMT+0200 (Mitteleuropäische Sommerzeit)
</div>
</footer>
</div>