@nxtedition/lib 22.0.17 → 22.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/ass.js +3 -1
  2. package/package.json +1 -1
  3. package/wordwrap.js +7 -5
package/ass.js CHANGED
@@ -97,7 +97,9 @@ function formatDialogues(events, styles, scriptResX, futureWordWrapping) {
97
97
  .split(/\\n|\n|\\N/)
98
98
  .map((line) => line.trim())
99
99
  .flatMap((line) =>
100
- futureWordWrapping ? wordwrap(line, fontSize, fontFamily, maxWidth) : [line],
100
+ futureWordWrapping
101
+ ? wordwrap(line, { fontSize, fontFamily, maxWidth, breakWord: false })
102
+ : [line],
101
103
  )
102
104
  .map((line) => line.trim())
103
105
  .join('\\N')}\n`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "22.0.17",
3
+ "version": "22.0.18",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/wordwrap.js CHANGED
@@ -8,11 +8,13 @@ const ctx = canvas.getContext('2d')
8
8
  * Takes a string and a maxWidth and splits the text into lines.
9
9
  *
10
10
  * @param {string} text
11
- * @param {number} fontSize
12
- * @param {string} fontFamily
13
- * @param {number} maxWidth
11
+ * @param {object} options
12
+ * @param {number} options.fontSize
13
+ * @param {string} options.fontFamily
14
+ * @param {number} options.maxWidth
15
+ * @param {boolean} [options.breakWord]
14
16
  */
15
- export function wordwrap(text, fontSize, fontFamily, maxWidth) {
17
+ export function wordwrap(text, { fontSize, fontFamily, maxWidth, breakWord = true }) {
16
18
  // TODO: Register fonts
17
19
  // const fontFile = name =>
18
20
  // path.join(path.dirname(__dirname), 'fonts', `${name}.ttf`)
@@ -42,7 +44,7 @@ export function wordwrap(text, fontSize, fontFamily, maxWidth) {
42
44
  const measure = ctx.measureText(word).width
43
45
 
44
46
  // Edge case - If the current word is too long for one line, break it into maximized pieces.
45
- if (measure > maxWidth) {
47
+ if (breakWord && measure > maxWidth) {
46
48
  // TODO - a divide and conquer method might be nicer.
47
49
  const edgewords = splitWord(word, maxWidth)
48
50