html2canvas/src/Unicode.js

28 lines
741 B
JavaScript
Raw Normal View History

2017-12-21 17:39:02 +03:00
/* @flow */
'use strict';
2018-07-06 17:28:48 +03:00
import type NodeContainer from './NodeContainer';
2017-12-30 19:12:28 +03:00
import {LineBreaker, fromCodePoint, toCodePoints} from 'css-line-break';
import {OVERFLOW_WRAP} from './parsing/overflowWrap';
2017-12-21 17:39:02 +03:00
2017-12-30 19:12:28 +03:00
export {toCodePoints, fromCodePoint} from 'css-line-break';
2017-12-21 17:39:02 +03:00
2017-12-30 19:12:28 +03:00
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
});
2017-12-21 17:39:02 +03:00
2017-12-30 19:12:28 +03:00
const words = [];
let bk;
while (!(bk = breaker.next()).done) {
words.push(bk.value.slice());
2017-12-21 17:39:02 +03:00
}
2017-12-30 19:12:28 +03:00
return words;
2017-12-21 17:39:02 +03:00
};