-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
261 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[ignore] | ||
.*/www/.* | ||
.*/node_modules/css-line-break/scripts.* | ||
[include] | ||
[libs] | ||
./flow-typed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,27 @@ | ||
/* @flow */ | ||
'use strict'; | ||
|
||
export const fromCodePoint = (...codePoints: Array<number>): string => { | ||
if (String.fromCodePoint) { | ||
return String.fromCodePoint(...codePoints); | ||
} | ||
import NodeContainer from './NodeContainer'; | ||
import {LineBreaker, fromCodePoint, toCodePoints} from 'css-line-break'; | ||
import {OVERFLOW_WRAP} from './parsing/overflowWrap'; | ||
|
||
const length = codePoints.length; | ||
if (!length) { | ||
return ''; | ||
} | ||
export {toCodePoints, fromCodePoint} from 'css-line-break'; | ||
|
||
const codeUnits = []; | ||
export const breakWords = (str: string, parent: NodeContainer): Array<string> => { | ||
const breaker = LineBreaker(str, { | ||
lineBreak: parent.style.lineBreak, | ||
wordBreak: | ||
parent.style.overflowWrap === OVERFLOW_WRAP.BREAK_WORD | ||
? 'break-word' | ||
: parent.style.wordBreak | ||
}); | ||
|
||
let index = -1; | ||
let result = ''; | ||
while (++index < length) { | ||
let codePoint = codePoints[index]; | ||
if (codePoint <= 0xffff) { | ||
codeUnits.push(codePoint); | ||
} else { | ||
codePoint -= 0x10000; | ||
codeUnits.push((codePoint >> 10) + 0xd800, codePoint % 0x400 + 0xdc00); | ||
} | ||
if (index + 1 === length || codeUnits.length > 0x4000) { | ||
result += String.fromCharCode(...codeUnits); | ||
codeUnits.length = 0; | ||
} | ||
const words = []; | ||
let bk; | ||
|
||
while (!(bk = breaker.next()).done) { | ||
words.push(bk.value.slice()); | ||
} | ||
return result; | ||
|
||
return words; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* @flow */ | ||
'use strict'; | ||
|
||
export const LINE_BREAK = { | ||
NORMAL: 'normal', | ||
STRICT: 'strict' | ||
}; | ||
|
||
export type LineBreak = $Values<typeof LINE_BREAK>; | ||
|
||
export const parseLineBreak = (wordBreak: string): LineBreak => { | ||
switch (wordBreak) { | ||
case 'strict': | ||
return LINE_BREAK.STRICT; | ||
case 'normal': | ||
default: | ||
return LINE_BREAK.NORMAL; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* @flow */ | ||
'use strict'; | ||
|
||
export const OVERFLOW_WRAP = { | ||
NORMAL: 0, | ||
BREAK_WORD: 1 | ||
}; | ||
|
||
export type OverflowWrap = $Values<typeof OVERFLOW_WRAP>; | ||
|
||
export const parseOverflowWrap = (overflow: string): OverflowWrap => { | ||
switch (overflow) { | ||
case 'break-word': | ||
return OVERFLOW_WRAP.BREAK_WORD; | ||
case 'normal': | ||
default: | ||
return OVERFLOW_WRAP.NORMAL; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* @flow */ | ||
'use strict'; | ||
|
||
export const WORD_BREAK = { | ||
NORMAL: 'normal', | ||
BREAK_ALL: 'break-all', | ||
KEEP_ALL: 'keep-all' | ||
}; | ||
|
||
export type WordBreak = $Values<typeof WORD_BREAK>; | ||
|
||
export const parseWordBreak = (wordBreak: string): WordBreak => { | ||
switch (wordBreak) { | ||
case 'break-all': | ||
return WORD_BREAK.BREAK_ALL; | ||
case 'keep-all': | ||
return WORD_BREAK.KEEP_ALL; | ||
case 'normal': | ||
default: | ||
return WORD_BREAK.NORMAL; | ||
} | ||
}; |
Oops, something went wrong.