@nakamura-123/pages 1.3.14 → 1.3.15
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.
|
@@ -27,5 +27,6 @@ export type ExplainBlock = {
|
|
|
27
27
|
lines: string[];
|
|
28
28
|
};
|
|
29
29
|
export declare const groupExplainLines: (lines: string[]) => ExplainBlock[];
|
|
30
|
+
export declare const columnWeights: (rows: string[][]) => number[];
|
|
30
31
|
export declare const getHeading: (word: string) => string | null;
|
|
31
32
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHeading = exports.groupExplainLines = exports.getExplainDatas = void 0;
|
|
3
|
+
exports.getHeading = exports.columnWeights = exports.groupExplainLines = exports.getExplainDatas = void 0;
|
|
4
4
|
const getExplainDatas = (word, Q) => {
|
|
5
5
|
const { yearId, num, form } = Q;
|
|
6
6
|
if (word.startsWith("lmn"))
|
|
@@ -103,6 +103,38 @@ const splitCells = (line) => {
|
|
|
103
103
|
cells.pop();
|
|
104
104
|
return cells;
|
|
105
105
|
};
|
|
106
|
+
// 表の列幅。均等に割ると、短い名前の列が空き、長い説明の列だけが何行にも折り返す。
|
|
107
|
+
// 列ごとに「本文行の平均字数」と「見出しの字数」の大きいほうに3字を足した比で割る。
|
|
108
|
+
// 見出しを数えないと本文の短い列で見出しが細かく折り返し、3字を足さないと短い列が
|
|
109
|
+
// セルの余白の分だけ中身より細くなる。細くなりすぎる列は下限で止める。
|
|
110
|
+
// 記法は増やさず、書き手に比率を考えさせない
|
|
111
|
+
const EXTRA_CHARS = 3;
|
|
112
|
+
const columnWeights = (rows) => {
|
|
113
|
+
const columns = Math.max(...rows.map((cells) => cells.length));
|
|
114
|
+
if (columns <= 1)
|
|
115
|
+
return [1];
|
|
116
|
+
const [head, ...body] = rows;
|
|
117
|
+
const lengths = Array.from({ length: columns }, (_, c) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const average = body.length
|
|
120
|
+
? body.reduce((sum, cells) => { var _a; return sum + visibleLength((_a = cells[c]) !== null && _a !== void 0 ? _a : ""); }, 0) /
|
|
121
|
+
body.length
|
|
122
|
+
: 0;
|
|
123
|
+
return Math.max(average, visibleLength((_a = head[c]) !== null && _a !== void 0 ? _a : "")) + EXTRA_CHARS;
|
|
124
|
+
});
|
|
125
|
+
const total = lengths.reduce((a, b) => a + b, 0);
|
|
126
|
+
// 合計が1未満だと Yoga は行を埋めないので、比は正規化せずに返す
|
|
127
|
+
return lengths.map((length) => Math.max(length, (total * 0.5) / columns));
|
|
128
|
+
};
|
|
129
|
+
exports.columnWeights = columnWeights;
|
|
130
|
+
// 画面に出る字数。目印は数えず、数式は1つ4字分、半角は0.5字とみなす
|
|
131
|
+
const visibleLength = (cell) => [
|
|
132
|
+
...cell
|
|
133
|
+
.replace(/qq.*?qq/g, "****")
|
|
134
|
+
.replace(/ZZ[AB]ZZ/g, "**")
|
|
135
|
+
.replace(/udl\[(.*?)\]/g, "$1")
|
|
136
|
+
.replace(/yy|JJ|JB|BJ|XX/g, ""),
|
|
137
|
+
].reduce((n, ch) => n + (ch <= "\u007f" ? 0.5 : 1), 0);
|
|
106
138
|
// 要素全体が【…】だけなら見出し
|
|
107
139
|
const HEADING = /^【([^【】]+)】$/;
|
|
108
140
|
const getHeading = (word) => { var _a, _b; return (_b = (_a = word.trim().match(HEADING)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : null; };
|
|
@@ -7,14 +7,20 @@ const react_1 = __importDefault(require("react"));
|
|
|
7
7
|
const react_native_1 = require("react-native");
|
|
8
8
|
const lib_1 = require("@nakamura-123/lib");
|
|
9
9
|
const MyTextqqyy_1 = __importDefault(require("../common/MyTextqqyy"));
|
|
10
|
+
const ExplainLogic_1 = require("./ExplainLogic");
|
|
10
11
|
// 問題の画面は横スワイプで次の問題へ移るため、横スクロールにせずセルの中で折り返す
|
|
11
12
|
const ExplainTable = ({ rows }) => {
|
|
12
|
-
const
|
|
13
|
+
const weights = (0, ExplainLogic_1.columnWeights)(rows);
|
|
14
|
+
const columns = weights.length;
|
|
13
15
|
return (<react_native_1.View style={styles.table}>
|
|
14
16
|
{rows.map((cells, r) => (<react_native_1.View key={r} style={[styles.row, r === 0 && styles.headRow]}>
|
|
15
17
|
{Array.from({ length: columns }, (_, c) => {
|
|
16
18
|
var _a;
|
|
17
|
-
return (<react_native_1.View key={c} style={[
|
|
19
|
+
return (<react_native_1.View key={c} style={[
|
|
20
|
+
styles.cell,
|
|
21
|
+
{ flex: weights[c] },
|
|
22
|
+
c === columns - 1 && styles.lastCell,
|
|
23
|
+
]}>
|
|
18
24
|
<MyTextqqyy_1.default weight={r === 0 ? 700 : undefined}>
|
|
19
25
|
{(_a = cells[c]) !== null && _a !== void 0 ? _a : ""}
|
|
20
26
|
</MyTextqqyy_1.default>
|
|
@@ -39,7 +45,6 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
39
45
|
backgroundColor: lib_1.colors.light,
|
|
40
46
|
},
|
|
41
47
|
cell: {
|
|
42
|
-
flex: 1,
|
|
43
48
|
borderRightWidth: 1,
|
|
44
49
|
borderColor: lib_1.colors.ltBlack,
|
|
45
50
|
},
|