1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export function computedImageSize(width, height, containerWidth) {
|
11 | if (width <= containerWidth) {
|
12 | return { width, height };
|
13 | } else {
|
14 | return {
|
15 | width: containerWidth,
|
16 | height: parseInt((height / width) * containerWidth, 10)
|
17 | };
|
18 | }
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export function helperGetLastLIne(textList) {
|
27 | let results = [];
|
28 |
|
29 | for (let i = textList.length - 1; i >= 0; i--) {
|
30 | let inlineText = textList[i].content;
|
31 | let match = inlineText.match(/\n(.*?)$/);
|
32 | if (match) {
|
33 | let { 1: matched, index } = match;
|
34 |
|
35 |
|
36 | textList[i].content = inlineText.substr(0, index + 1);
|
37 | results.push({ ...textList[i], content: matched });
|
38 |
|
39 | break;
|
40 | } else {
|
41 | results.push(textList[i]);
|
42 |
|
43 | textList.pop();
|
44 | }
|
45 | }
|
46 | return results.reverse();
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | export function addEvent(el, event, func) {
|
57 | const callback = e => func(e);
|
58 | el.addEventListener(event, callback);
|
59 | return () => el.removeEventListener(event, callback);
|
60 | }
|