@nakamura-123/pages 1.4.0 → 1.4.2

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 (48) hide show
  1. package/dist/component/Article/ArticleContentView.d.ts +5 -1
  2. package/dist/component/Article/ArticleContentView.js +218 -37
  3. package/dist/component/Article/ArticleImage.d.ts +9 -0
  4. package/dist/component/Article/ArticleImage.js +46 -0
  5. package/dist/component/Article/ArticleSectionPager.d.ts +17 -0
  6. package/dist/component/Article/ArticleSectionPager.js +193 -0
  7. package/dist/component/Article/ArticleTable.d.ts +10 -0
  8. package/dist/component/Article/ArticleTable.js +74 -0
  9. package/dist/component/Article/ChipStrip.d.ts +10 -0
  10. package/dist/component/Article/ChipStrip.js +82 -0
  11. package/dist/component/Article/Cloze.d.ts +31 -0
  12. package/dist/component/Article/Cloze.js +338 -0
  13. package/dist/component/Article/FramesFigure.d.ts +27 -0
  14. package/dist/component/Article/FramesFigure.js +438 -0
  15. package/dist/component/Article/RefLink.d.ts +42 -0
  16. package/dist/component/Article/RefLink.js +184 -0
  17. package/dist/component/Rating/RatingBar.d.ts +9 -0
  18. package/dist/component/Rating/RatingBar.js +358 -0
  19. package/dist/component/Rating/keyboardScroll.d.ts +7 -0
  20. package/dist/component/Rating/keyboardScroll.js +37 -0
  21. package/dist/component/Result/QuizFlatList.js +11 -10
  22. package/dist/component/Result/ResultActions.js +152 -59
  23. package/dist/component/Result/ResultHero.js +19 -18
  24. package/dist/component/SettingBtns/LanguageModal.js +1 -0
  25. package/dist/functions/articleContentFnc.d.ts +49 -1
  26. package/dist/functions/articleContentFnc.js +191 -2
  27. package/dist/functions/questionFormatD.d.ts +1 -0
  28. package/dist/functions/questionFormatD.js +14 -13
  29. package/dist/functions/ratingFnc.d.ts +4 -0
  30. package/dist/functions/ratingFnc.js +30 -0
  31. package/dist/functions/retryQuizFnc.d.ts +1 -0
  32. package/dist/functions/retryQuizFnc.js +13 -0
  33. package/dist/hooks/resultHook.d.ts +3 -1
  34. package/dist/hooks/resultHook.js +29 -6
  35. package/dist/page/ArticleDetail.js +58 -15
  36. package/dist/page/ImgZoom.d.ts +4 -3
  37. package/dist/page/ImgZoom.js +16 -2
  38. package/dist/page/QuizPage.js +23 -11
  39. package/dist/page/ReportPage.js +3 -2
  40. package/dist/page/ResultPage.js +2 -1
  41. package/dist/quiz/QuizContentsDrill.js +26 -16
  42. package/dist/quiz/common/MyTextqqyy.d.ts +4 -0
  43. package/dist/quiz/common/MyTextqqyy.js +14 -4
  44. package/dist/quiz/explain/ExplainLogic.d.ts +1 -0
  45. package/dist/quiz/explain/ExplainLogic.js +3 -2
  46. package/dist/quiz/explain/NormalExplain.js +3 -0
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +2 -2
@@ -5,103 +5,196 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const react_native_1 = require("react-native");
8
+ const react_redux_1 = require("react-redux");
8
9
  const common_1 = require("@nakamura-123/common");
9
10
  const lib_1 = require("@nakamura-123/lib");
11
+ const stores_1 = require("@nakamura-123/stores");
10
12
  const resultHook_1 = require("../../hooks/resultHook");
11
- // 大きいボタンは「×の問題だけ解く」と「次へ」(次の項目があるときだけ)。全問○なら左は「全問やり直す」になる。
12
- // 下の薄い段に「全問やり直す」(×があるとき)と「成績を見る」。戻るは画面左上にあるので置かない
13
+ const NEXT_LABEL = {
14
+ article: "quiz.result.nextLesson",
15
+ unit: "quiz.result.nextUnit",
16
+ year: "quiz.result.nextQuiz",
17
+ };
18
+ // 上に緑の大きいボタン(×があれば×の解き直し、全問○なら次へ)、その下に「この単元をもう一度」と「次へ」の札を並べる。
19
+ // 形は試作のA1(2026-11-09、本人)。下の2つの札は、外側の端に小さい矢印だけを置く(同日)。
20
+ // 文字は問題設定画面に揃える:緑のボタンはM(見出しと同じ)、ほかはS(選択肢・下のボタンと同じ)(同日)。
21
+ // 「この単元をもう一度」は同じ単元の問題設定画面へ戻す。同じ10問を同じ順で解き直すと、位置で答えを覚えてしまうため(同日)
13
22
  const ResultActions = ({ navigation }) => {
14
23
  const { t } = (0, common_1.useDrillTranslation)();
15
- const wrongCnt = (0, resultHook_1.useWrongCount)();
24
+ const dispatch = (0, react_redux_1.useDispatch)();
25
+ const selected = (0, react_redux_1.useSelector)((state) => state.quiz.selected);
26
+ const wrongCnt = (0, resultHook_1.useFrozenOnRetry)((0, resultHook_1.useWrongCount)());
16
27
  const retry = (0, resultHook_1.useRetryQuizAction)(navigation);
17
28
  const next = (0, resultHook_1.useNextInResult)(navigation);
29
+ // 下の2つの札は、問題設定画面がある単元別・試験別だけ。模擬試験・集中特訓・ミニテストには出さない(2026-11-09、本人)
30
+ const showTiles = selected.type === "unit" || selected.type === "year";
31
+ const againLabel = t(selected.type === "unit"
32
+ ? "quiz.result.againUnit"
33
+ : "quiz.result.againYear");
34
+ const goAgain = () => {
35
+ dispatch(stores_1.quizAction.setLesson(selected));
36
+ navigation.replace("QuizSetup");
37
+ };
38
+ const nextLabel = next ? t(NEXT_LABEL[next.kind]) : "";
39
+ const nextIsMain = wrongCnt === 0 && !!next;
18
40
  return (<react_native_1.View style={styles.container}>
19
- <react_native_1.View style={styles.acts}>
20
- <common_1.PressAnimatedWrap onPress={() => retry(wrongCnt > 0)} outerStyle={styles.actOuter} style={[styles.act, styles.ghost]}>
21
- <common_1.Icon5 name="redo" size={13} color="text" style={styles.icon}/>
22
- <common_1.MyText fsize="sm" weight={700}>
23
- {wrongCnt > 0
24
- ? t("quiz.result.retryWrong", { cnt: wrongCnt })
25
- : t("quiz.result.retryAll")}
26
- </common_1.MyText>
27
- </common_1.PressAnimatedWrap>
28
- {next && (<common_1.PressAnimatedWrap onPress={next.go} outerStyle={styles.actOuter} style={[styles.act, styles.fill]}>
29
- <common_1.MyText fsize="sm" weight={700} color="white">
30
- {t(next.kind === "article"
31
- ? "quiz.result.nextLesson"
32
- : "quiz.result.nextQuiz")}
41
+ {wrongCnt > 0 ? (<MainButton icon="redo" label={t("quiz.result.retryWrong", { cnt: wrongCnt })} onPress={() => retry(true)}/>) : (next && <NextMain next={next} label={nextLabel}/>)}
42
+ {showTiles && (<react_native_1.View style={styles.row}>
43
+ <Tile onPress={goAgain}>
44
+ <SideArrow side="left"/>
45
+ <common_1.MyText fsize="sm" weight={700} style={styles.center}>
46
+ {againLabel}
33
47
  </common_1.MyText>
34
- <common_1.Icon5 name="arrow-right" size={13} color="white" style={styles.iconRight}/>
35
- </common_1.PressAnimatedWrap>)}
36
- </react_native_1.View>
37
- <react_native_1.View style={styles.subacts}>
38
- {wrongCnt > 0 && (<>
39
- <react_native_1.Pressable style={styles.sub} onPress={() => retry(false)}>
40
- <common_1.Icon5 name="redo" size={11} color="ltBlack" style={styles.icon}/>
41
- <common_1.MyText fsize="xs" color="ltBlack">
42
- {t("quiz.result.retryAll")}
43
- </common_1.MyText>
44
- </react_native_1.Pressable>
45
- <react_native_1.View style={styles.sep}/>
46
- </>)}
47
- <react_native_1.Pressable style={styles.sub} onPress={() => navigation.navigate("Grade")}>
48
- <common_1.Icon5 name="chart-line" size={11} color="ltBlack" style={styles.icon}/>
49
- <common_1.MyText fsize="xs" color="ltBlack">
48
+ </Tile>
49
+ {next && !nextIsMain && (<Tile onPress={next.go}>
50
+ <react_native_1.View style={styles.tileText}>
51
+ <common_1.MyText fsize="sm" weight={700} numberOfLines={1} style={styles.center}>
52
+ {nextLabel}
53
+ </common_1.MyText>
54
+ <NextTitle title={next.title}/>
55
+ </react_native_1.View>
56
+ <SideArrow side="right"/>
57
+ </Tile>)}
58
+ </react_native_1.View>)}
59
+ <react_native_1.View style={styles.gradeRow}>
60
+ <react_native_1.Pressable style={styles.grade} hitSlop={6} onPress={() => navigation.navigate("Grade")}>
61
+ <common_1.Icon5 name="chart-line" size={12} color="text"/>
62
+ <common_1.MyText fsize="sm" weight={700}>
50
63
  {t("quiz.result.seeGrade")}
51
64
  </common_1.MyText>
65
+ <common_1.Icon5 name="chevron-right" size={10} color="ltBlack"/>
52
66
  </react_native_1.Pressable>
53
67
  </react_native_1.View>
54
68
  </react_native_1.View>);
55
69
  };
70
+ // 行き先の名前を「」で囲む(2026-11-09、本人)。長い名前は中だけを「…」で省き、閉じかっこは残す
71
+ const NextTitle = ({ title }) => {
72
+ const { t } = (0, common_1.useDrillTranslation)();
73
+ return (<react_native_1.View style={styles.titleRow}>
74
+ <common_1.MyText fsize="sm" weight={700} color="gray">
75
+ {t("quiz.result.quoteL")}
76
+ </common_1.MyText>
77
+ <common_1.MyText fsize="sm" weight={700} color="gray" numberOfLines={1} style={styles.titleText}>
78
+ {title}
79
+ </common_1.MyText>
80
+ <common_1.MyText fsize="sm" weight={700} color="gray">
81
+ {t("quiz.result.quoteR")}
82
+ </common_1.MyText>
83
+ </react_native_1.View>);
84
+ };
85
+ // 札の端に置く小さい矢印。文字は札の真ん中のまま(矢印の分ずらさない)
86
+ const SideArrow = ({ side }) => (<react_native_1.View pointerEvents="none" style={[styles.sideArrow, { [side]: 12 }]}>
87
+ <common_1.Icon5 name={side === "left" ? "arrow-left" : "arrow-right"} size={11} color="ltBlack"/>
88
+ </react_native_1.View>);
89
+ const IconCircle = ({ name, bg, size = 34, iconSize = 15 }) => (<react_native_1.View style={[
90
+ styles.circle,
91
+ {
92
+ width: size,
93
+ height: size,
94
+ borderRadius: size / 2,
95
+ backgroundColor: bg,
96
+ },
97
+ ]}>
98
+ <common_1.Icon5 name={name} size={iconSize} color="text"/>
99
+ </react_native_1.View>);
100
+ const MainButton = ({ icon, label, onPress }) => (<common_1.PressAnimatedWrap onPress={onPress} style={styles.main}>
101
+ <IconCircle name={icon} bg="rgba(255,255,255,0.6)" size={32} iconSize={14}/>
102
+ <common_1.MyText fsize="md" weight={700} numberOfLines={1}>
103
+ {label}
104
+ </common_1.MyText>
105
+ </common_1.PressAnimatedWrap>);
106
+ // 全問○のときは、次へを緑の大きいボタンにする。行き先の名前も添える
107
+ const NextMain = ({ next, label, }) => (<common_1.PressAnimatedWrap onPress={next.go} style={styles.main}>
108
+ <react_native_1.View style={styles.mainTexts}>
109
+ <common_1.MyText fsize="md" weight={700} numberOfLines={1}>
110
+ {label}
111
+ </common_1.MyText>
112
+ <NextTitle title={next.title}/>
113
+ </react_native_1.View>
114
+ <IconCircle name="arrow-right" bg="rgba(255,255,255,0.6)" size={32} iconSize={14}/>
115
+ </common_1.PressAnimatedWrap>);
116
+ const Tile = ({ onPress, children, }) => (<common_1.PressAnimatedWrap onPress={onPress} outerStyle={styles.tileOuter} style={styles.tile}>
117
+ {children}
118
+ </common_1.PressAnimatedWrap>);
56
119
  const styles = react_native_1.StyleSheet.create({
57
120
  container: {
58
121
  width: "100%",
122
+ marginTop: 12,
59
123
  },
60
- acts: {
124
+ // 枠はホームのメニュー(RectangleCard)と同じ、灰色の1pxと角の丸み10(ほかの画面のボタンと揃える。2026-11-09、本人)
125
+ main: {
126
+ minHeight: 48,
127
+ borderRadius: 10,
128
+ flexDirection: "row",
129
+ alignItems: "center",
130
+ justifyContent: "center",
131
+ gap: 10,
132
+ paddingHorizontal: 16,
133
+ paddingVertical: 8,
134
+ backgroundColor: lib_1.colors.green,
135
+ borderColor: lib_1.colors.ltBlack,
136
+ borderWidth: 1,
137
+ },
138
+ mainTexts: {
139
+ flexShrink: 1,
140
+ alignItems: "center",
141
+ },
142
+ row: {
61
143
  flexDirection: "row",
62
144
  gap: 8,
63
- marginTop: 10,
145
+ marginTop: 8,
64
146
  },
65
- actOuter: {
147
+ tileOuter: {
66
148
  flex: 1,
67
149
  },
68
- act: {
69
- height: 40,
150
+ tile: {
151
+ minHeight: 50,
70
152
  borderRadius: 10,
71
153
  flexDirection: "row",
72
154
  alignItems: "center",
73
155
  justifyContent: "center",
74
- },
75
- ghost: {
156
+ paddingHorizontal: 26,
157
+ paddingVertical: 8,
76
158
  backgroundColor: lib_1.colors.bkBeige,
77
- borderWidth: 1.5,
78
- borderColor: lib_1.colors.blue,
79
- },
80
- fill: {
81
- backgroundColor: lib_1.colors.green,
159
+ borderColor: lib_1.colors.ltBlack,
160
+ borderWidth: 1,
82
161
  },
83
- icon: {
84
- marginRight: 6,
162
+ tileText: {
163
+ flex: 1,
164
+ minWidth: 0,
85
165
  },
86
- iconRight: {
87
- marginLeft: 6,
166
+ center: {
167
+ textAlign: "center",
88
168
  },
89
- subacts: {
169
+ titleRow: {
90
170
  flexDirection: "row",
91
171
  justifyContent: "center",
172
+ },
173
+ titleText: {
174
+ flexShrink: 1,
175
+ },
176
+ sideArrow: {
177
+ position: "absolute",
178
+ top: 0,
179
+ bottom: 0,
180
+ justifyContent: "center",
181
+ },
182
+ circle: {
92
183
  alignItems: "center",
93
- paddingTop: 9,
184
+ justifyContent: "center",
94
185
  },
95
- sub: {
96
- flexDirection: "row",
186
+ gradeRow: {
97
187
  alignItems: "center",
98
- paddingHorizontal: 7,
188
+ paddingTop: 10,
99
189
  },
100
- sep: {
101
- width: 1,
102
- height: 12,
103
- backgroundColor: lib_1.colors.ltBlack,
104
- opacity: 0.5,
190
+ grade: {
191
+ flexDirection: "row",
192
+ alignItems: "center",
193
+ gap: 7,
194
+ paddingVertical: 5,
195
+ paddingHorizontal: 14,
196
+ borderRadius: 20,
197
+ backgroundColor: lib_1.colors.bkBeige,
105
198
  },
106
199
  });
107
200
  exports.default = ResultActions;
@@ -10,6 +10,7 @@ const common_1 = require("@nakamura-123/common");
10
10
  const lib_1 = require("@nakamura-123/lib");
11
11
  // 結果画面の上のカード。キャラ・言葉・点数・はんこを1枚にまとめる(試作 lesson_flow.html の「はんこ」案)。
12
12
  // はんこは画像を使わず、枠・内側の細い輪・回転で描く。色は点数の段階の色
13
+ // 文字は問題設定画面に揃えてS以上・太字にする(XSは小さすぎた。2026-11-09、本人)
13
14
  const ResultHero = ({ scoreInfo }) => {
14
15
  var _a, _b;
15
16
  const { t } = (0, common_1.useDrillTranslation)();
@@ -31,7 +32,7 @@ const ResultHero = ({ scoreInfo }) => {
31
32
  : t(isShuffle ? "quiz.result.random" : "quiz.result.ordered");
32
33
  return (<react_native_1.View style={styles.card}>
33
34
  <react_native_1.View style={styles.chip}>
34
- <common_1.MyText fsize="xs" color="gray" numberOfLines={1}>
35
+ <common_1.MyText fsize="sm" weight={700} color="gray" numberOfLines={1}>
35
36
  {kind ? `${selected.lesson.title}・${kind}` : selected.lesson.title}
36
37
  </common_1.MyText>
37
38
  </react_native_1.View>
@@ -41,20 +42,20 @@ const ResultHero = ({ scoreInfo }) => {
41
42
  <react_native_1.Image style={styles.chara} source={(_b = imgs.chara) === null || _b === void 0 ? void 0 : _b[level.level]}/>
42
43
  </react_native_1.View>)}
43
44
  <react_native_1.View style={styles.texts}>
44
- <common_1.MyText style={styles.enTitle}>{level.enTitle}</common_1.MyText>
45
- <common_1.MyText fsize="xs" color="gray">
45
+ <common_1.MyText weight={700} style={styles.enTitle}>{level.enTitle}</common_1.MyText>
46
+ <common_1.MyText fsize="sm" weight={700} color="gray">
46
47
  {t(`quiz.result.level.${level.level}`)}
47
48
  </common_1.MyText>
48
49
  <react_native_1.View style={styles.scoreRow}>
49
50
  <react_native_1.View>
50
- <common_1.MyText fsize="xs" color="ltBlack">
51
+ <common_1.MyText fsize="sm" weight={700} color="gray">
51
52
  {t(isMeaning ? "quiz.result.understood" : "quiz.result.correctCnt")}
52
53
  </common_1.MyText>
53
54
  <react_native_1.View style={styles.num}>
54
55
  <common_1.MyText weight={700} style={styles.score}>
55
56
  {score}
56
57
  </common_1.MyText>
57
- <common_1.MyText color="gray" style={styles.cnt}>
58
+ <common_1.MyText weight={700} color="gray" style={styles.cnt}>
58
59
  /{quizCnt}
59
60
  </common_1.MyText>
60
61
  </react_native_1.View>
@@ -86,8 +87,8 @@ const styles = react_native_1.StyleSheet.create({
86
87
  maxWidth: "100%",
87
88
  backgroundColor: lib_1.colors.beige,
88
89
  borderRadius: 10,
89
- paddingHorizontal: 9,
90
- paddingVertical: 1,
90
+ paddingHorizontal: 10,
91
+ paddingVertical: 2,
91
92
  },
92
93
  row: {
93
94
  flexDirection: "row",
@@ -118,8 +119,8 @@ const styles = react_native_1.StyleSheet.create({
118
119
  flex: 1,
119
120
  },
120
121
  enTitle: {
121
- fontSize: 21,
122
- lineHeight: 26,
122
+ fontSize: 22,
123
+ lineHeight: 28,
123
124
  },
124
125
  scoreRow: {
125
126
  flexDirection: "row",
@@ -131,18 +132,18 @@ const styles = react_native_1.StyleSheet.create({
131
132
  alignItems: "baseline",
132
133
  },
133
134
  score: {
134
- fontSize: 36,
135
- lineHeight: 40,
135
+ fontSize: 40,
136
+ lineHeight: 46,
136
137
  },
137
138
  cnt: {
138
- fontSize: 15,
139
+ fontSize: 17,
139
140
  marginLeft: 3,
140
141
  },
141
142
  hanko: {
142
143
  marginLeft: "auto",
143
- width: 54,
144
- height: 54,
145
- borderRadius: 27,
144
+ width: 58,
145
+ height: 58,
146
+ borderRadius: 29,
146
147
  borderWidth: 3,
147
148
  alignItems: "center",
148
149
  justifyContent: "center",
@@ -155,12 +156,12 @@ const styles = react_native_1.StyleSheet.create({
155
156
  left: 2,
156
157
  right: 2,
157
158
  bottom: 2,
158
- borderRadius: 22,
159
+ borderRadius: 24,
159
160
  borderWidth: 1.5,
160
161
  },
161
162
  hankoText: {
162
- fontSize: 11,
163
- lineHeight: 13,
163
+ fontSize: 13,
164
+ lineHeight: 15,
164
165
  },
165
166
  });
166
167
  exports.default = ResultHero;
@@ -17,6 +17,7 @@ exports.LANGUAGE_NAMES = {
17
17
  ko: "한국어",
18
18
  zhHans: "简体中文",
19
19
  zhHant: "繁體中文",
20
+ vi: "Tiếng Việt",
20
21
  };
21
22
  // 言語を選ぶ画面。ホームの言語ボタンと設定画面から開く
22
23
  const LanguageModal = ({ visible, onClose }) => {
@@ -1,5 +1,53 @@
1
1
  import { FontSize, FontWeight } from "@nakamura-123/lib";
2
- import { ArticleContent } from "@nakamura-123/types";
2
+ import { ArticleBlock, ArticleContent } from "@nakamura-123/types";
3
3
  export declare const getScaledFsize: (base: FontSize, userFsize: FontSize) => FontSize;
4
4
  export declare const getScaledWeight: (base: FontWeight, userWeight: FontWeight) => FontWeight;
5
+ export declare const fsizeToPx: (fsize: FontSize) => number;
6
+ export declare const getScaledLineHeight: (fsize: FontSize, base: number) => number;
7
+ export type ClozePart = {
8
+ type: "text";
9
+ content: string;
10
+ } | {
11
+ type: "math";
12
+ content: string;
13
+ } | {
14
+ type: "search";
15
+ content: string;
16
+ } | {
17
+ type: "hole";
18
+ content: string;
19
+ search: boolean;
20
+ } | {
21
+ type: "figref";
22
+ content: string;
23
+ };
24
+ export declare const hasCloze: (text: string) => boolean;
25
+ export declare const hasSearch: (text: string) => boolean;
26
+ export declare const hasFigref: (text: string) => boolean;
27
+ export declare const usesClozeText: (text: string, isLesson: boolean) => boolean;
28
+ export declare const splitCloze: (text: string) => ClozePart[];
29
+ export declare const holeGroup: (answer: string) => string;
30
+ export declare const tableHoleGroup: (blockIndex: number, row: number, col: number, hole: number) => string;
31
+ export type RubyPart = {
32
+ base: string;
33
+ ruby?: string;
34
+ };
35
+ export declare const hasRuby: (text: string) => boolean;
36
+ export declare const stripRuby: (text: string) => string;
37
+ export declare const splitRuby: (text: string) => RubyPart[];
38
+ export declare const exampleHoleGroup: (blockIndex: number) => string;
39
+ export declare const clozeGroups: (blocks: ArticleBlock[]) => string[];
5
40
  export declare const parseArticleContent: (raw: string) => ArticleContent;
41
+ export interface ArticleSection {
42
+ id?: string;
43
+ title: string;
44
+ blocks: ArticleBlock[];
45
+ exampleOffset: number;
46
+ }
47
+ export declare const splitArticleSections: (blocks: ArticleBlock[]) => ArticleSection[] | null;
48
+ export declare const findSectionIndex: (sections: ArticleSection[], id: string) => number;
49
+ export interface LessonAnchor {
50
+ articleId: string;
51
+ title: string;
52
+ }
53
+ export declare const collectLessonAnchors: (articleContents: Record<string, string>) => Record<string, LessonAnchor>;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseArticleContent = exports.getScaledWeight = exports.getScaledFsize = void 0;
3
+ exports.collectLessonAnchors = exports.findSectionIndex = exports.splitArticleSections = exports.parseArticleContent = exports.clozeGroups = exports.exampleHoleGroup = exports.splitRuby = exports.stripRuby = exports.hasRuby = exports.tableHoleGroup = exports.holeGroup = exports.splitCloze = exports.usesClozeText = exports.hasFigref = exports.hasSearch = exports.hasCloze = exports.getScaledLineHeight = exports.fsizeToPx = exports.getScaledWeight = exports.getScaledFsize = void 0;
4
4
  const lib_1 = require("@nakamura-123/lib");
5
+ const ExplainLogic_1 = require("../quiz/explain/ExplainLogic");
5
6
  const REI_PATTERN = /^rei\d*$/;
7
+ const HEADING_ID_PATTERN = /\s*\{#([\w-]+)\}$/;
6
8
  const FSIZE_ORDER = lib_1.infoFontSize.map((i) => i.size);
7
9
  const FWEIGHT_ORDER = [400, 500, 700];
8
10
  // ユーザー設定値(current)の、基準値(neutral)からのズレ分だけbaseをずらす
@@ -18,6 +20,99 @@ exports.getScaledFsize = getScaledFsize;
18
20
  // weightも同様に、ユーザー設定(quizCfg.inQuizOption.fWeight)からの相対シフトで適用する
19
21
  const getScaledWeight = (base, userWeight) => shift(FWEIGHT_ORDER, base, userWeight, 500);
20
22
  exports.getScaledWeight = getScaledWeight;
23
+ const fsizeToPx = (fsize) => { var _a, _b; return (_b = (_a = lib_1.infoFontSize.find((i) => i.size === fsize)) === null || _a === void 0 ? void 0 : _a.fsize) !== null && _b !== void 0 ? _b : 15; };
24
+ exports.fsizeToPx = fsizeToPx;
25
+ // 行の高さを文字の大きさに合わせる。baseはmd(15pt)のときの行の高さ。固定のままだと、利用者が文字を大きくしたときに行が重なる
26
+ const getScaledLineHeight = (fsize, base) => Math.round(((0, exports.fsizeToPx)(fsize) * base) / 15);
27
+ exports.getScaledLineHeight = getScaledLineHeight;
28
+ const CLOZE_SPLIT = /(ana\[[^\]]+\]|figref\[[A-Za-z0-9_]+\]|qq.*?qq|yy.+?yy)/;
29
+ const CLOZE_HOLE = /^ana\[([^\]]+)\]$/;
30
+ const SEARCH_WORD = /^yy(.+)yy$/;
31
+ const hasCloze = (text) => /ana\[[^\]]+\]/.test(text);
32
+ exports.hasCloze = hasCloze;
33
+ const hasSearch = (text) => /yy.+?yy/.test(text);
34
+ exports.hasSearch = hasSearch;
35
+ const hasFigref = (text) => /figref\[[A-Za-z0-9_]+\]/.test(text);
36
+ exports.hasFigref = hasFigref;
37
+ // 穴埋めの部品(ClozeText)で描く文か。検索語はLESSONだけ(ほかの記事はyyの書き方を前提に書かれていない)
38
+ const usesClozeText = (text, isLesson) => (0, exports.hasCloze)(text) || (0, exports.hasFigref)(text) || (isLesson && (0, exports.hasSearch)(text));
39
+ exports.usesClozeText = usesClozeText;
40
+ const splitCloze = (text) => text
41
+ .split(CLOZE_SPLIT)
42
+ .filter((chunk) => chunk.length > 0)
43
+ .map((chunk) => {
44
+ const hole = chunk.match(CLOZE_HOLE);
45
+ if (hole) {
46
+ const word = hole[1].match(SEARCH_WORD);
47
+ return word
48
+ ? { type: "hole", content: word[1], search: true }
49
+ : { type: "hole", content: hole[1], search: false };
50
+ }
51
+ if (chunk.length > 4 && chunk.startsWith("qq") && chunk.endsWith("qq"))
52
+ return { type: "math", content: chunk.slice(2, -2) };
53
+ const fig = chunk.match(/^figref\[([A-Za-z0-9_]+)\]$/);
54
+ if (fig)
55
+ return { type: "figref", content: fig[1] };
56
+ const word = chunk.match(SEARCH_WORD);
57
+ if (word)
58
+ return { type: "search", content: word[1] };
59
+ return { type: "text", content: chunk };
60
+ });
61
+ exports.splitCloze = splitCloze;
62
+ // 穴の組。表の外は、答えが同じ穴を1組にする(言い回しで避けられないとき、全部穴にすれば一緒に開く)。
63
+ // 表の穴は1つずつ開く(11/07、本人。表は1つずつ答えていくため。答えが同じでも別々)
64
+ const holeGroup = (answer) => `a:${answer}`;
65
+ exports.holeGroup = holeGroup;
66
+ const tableHoleGroup = (blockIndex, row, col, hole) => `t${blockIndex}-${row}-${col}-${hole}`;
67
+ exports.tableHoleGroup = tableHoleGroup;
68
+ // ふりがな((漢字)ff(よみ)。問題の文と同じ書き方)。説明の例文で、穴埋めの部品の中に描く
69
+ const RUBY = /\(([^)]+)\)ff\(([^)]+)\)/g;
70
+ const hasRuby = (text) => /\([^)]+\)ff\([^)]+\)/.test(text);
71
+ exports.hasRuby = hasRuby;
72
+ // ふりがなを外した字だけ(穴の答えはふりがなを付けずに出す)
73
+ const stripRuby = (text) => text.replace(RUBY, "$1");
74
+ exports.stripRuby = stripRuby;
75
+ const splitRuby = (text) => {
76
+ const parts = [];
77
+ const re = new RegExp(RUBY.source, "g");
78
+ let last = 0;
79
+ let m;
80
+ while ((m = re.exec(text)) !== null) {
81
+ if (m.index > last)
82
+ parts.push({ base: text.slice(last, m.index) });
83
+ parts.push({ base: m[1], ruby: m[2] });
84
+ last = re.lastIndex;
85
+ }
86
+ if (last < text.length)
87
+ parts.push({ base: text.slice(last) });
88
+ return parts;
89
+ };
90
+ exports.splitRuby = splitRuby;
91
+ // 例文の穴は例文ごとに1組(n2bのLessonは例文の文法の部分を穴にする。別の例文に同じ答えがあっても一緒に開かない)
92
+ const exampleHoleGroup = (blockIndex) => `e${blockIndex}`;
93
+ exports.exampleHoleGroup = exampleHoleGroup;
94
+ // ページ(ArticleContentViewに渡すblocks)にある穴の組を、出てくる順に重ねずに並べる
95
+ const clozeGroups = (blocks) => {
96
+ const groups = new Set();
97
+ const addText = (text) => (0, exports.splitCloze)(text).forEach((part) => {
98
+ if (part.type === "hole")
99
+ groups.add((0, exports.holeGroup)(part.content));
100
+ });
101
+ blocks.forEach((block, index) => {
102
+ if (block.type === "paragraph" ||
103
+ block.type === "point" ||
104
+ block.type === "exampleNote")
105
+ addText(block.text);
106
+ if (block.type === "example" && (0, exports.hasCloze)(block.japanese))
107
+ groups.add((0, exports.exampleHoleGroup)(index));
108
+ if (block.type === "table")
109
+ block.rows.forEach((cells, r) => cells.forEach((cell, c) => (0, exports.splitCloze)(cell)
110
+ .filter((part) => part.type === "hole")
111
+ .forEach((_, k) => groups.add((0, exports.tableHoleGroup)(index, r, c, k)))));
112
+ });
113
+ return [...groups];
114
+ };
115
+ exports.clozeGroups = clozeGroups;
21
116
  // 記事本文の生テキスト(行頭トークン形式)をArticleContentにパースする
22
117
  const parseArticleContent = (raw) => {
23
118
  const lines = raw
@@ -27,17 +122,29 @@ const parseArticleContent = (raw) => {
27
122
  let title = "";
28
123
  const blocks = [];
29
124
  let lastExampleBlock = null;
125
+ let lastTableBlock = null;
30
126
  lines.forEach((line) => {
31
127
  const spaceIndex = line.indexOf(" ");
32
128
  const token = spaceIndex === -1 ? line : line.slice(0, spaceIndex);
33
129
  const content = spaceIndex === -1 ? "" : line.slice(spaceIndex + 1).trim();
130
+ // 表は、tbl の直後に続く tr だけをその表の行にする(ほかの行が挟まれば表は終わる)
131
+ if (token !== "tr")
132
+ lastTableBlock = null;
34
133
  if (token === "title") {
35
134
  title = content;
36
135
  return;
37
136
  }
38
137
  if (token === "#" || token === "##" || token === "###") {
39
138
  const style = token === "#" ? "bar" : token === "##" ? "underline" : "bold";
40
- blocks.push({ type: "heading", style, text: content });
139
+ const anchor = content.match(HEADING_ID_PATTERN);
140
+ blocks.push(anchor
141
+ ? {
142
+ type: "heading",
143
+ style,
144
+ text: content.slice(0, anchor.index).trim(),
145
+ id: anchor[1],
146
+ }
147
+ : { type: "heading", style, text: content });
41
148
  lastExampleBlock = null;
42
149
  return;
43
150
  }
@@ -71,6 +178,41 @@ const parseArticleContent = (raw) => {
71
178
  lastExampleBlock = null;
72
179
  return;
73
180
  }
181
+ if (token === "tbl") {
182
+ const block = {
183
+ type: "table",
184
+ rows: [(0, ExplainLogic_1.splitCells)(content)],
185
+ };
186
+ blocks.push(block);
187
+ lastTableBlock = block;
188
+ lastExampleBlock = null;
189
+ return;
190
+ }
191
+ if (token === "tr") {
192
+ if (lastTableBlock) {
193
+ lastTableBlock.rows.push((0, ExplainLogic_1.splitCells)(content));
194
+ }
195
+ else if (__DEV__) {
196
+ console.warn(`[articleContent] trの直前にtblがありません: "${line}"`);
197
+ }
198
+ return;
199
+ }
200
+ if (token === "point") {
201
+ blocks.push({ type: "point", text: content });
202
+ lastExampleBlock = null;
203
+ return;
204
+ }
205
+ // 上の例文の補足(n2bのLessonに33行。どれも例文の直後にある)
206
+ if (token === "up") {
207
+ blocks.push({ type: "exampleNote", text: content });
208
+ lastExampleBlock = null;
209
+ return;
210
+ }
211
+ if (token === "img") {
212
+ blocks.push({ type: "image", name: content });
213
+ lastExampleBlock = null;
214
+ return;
215
+ }
74
216
  if (__DEV__) {
75
217
  console.warn(`[articleContent] 未知のトークンです: "${line}"`);
76
218
  }
@@ -78,3 +220,50 @@ const parseArticleContent = (raw) => {
78
220
  return { title, blocks };
79
221
  };
80
222
  exports.parseArticleContent = parseArticleContent;
223
+ // LESSON(#の見出しに名札がある記事)を#ごとのページに分ける。名札の無い記事(n2bの説明など)はnullで、今までどおり縦1本で出す。
224
+ // 最初の#より前の段落は、1ページ目の頭に入れる
225
+ const splitArticleSections = (blocks) => {
226
+ const isLesson = blocks.some((b) => b.type === "heading" && b.style === "bar" && b.id);
227
+ if (!isLesson)
228
+ return null;
229
+ const sections = [];
230
+ const lead = [];
231
+ let examples = 0;
232
+ blocks.forEach((block) => {
233
+ if (block.type === "heading" && block.style === "bar") {
234
+ sections.push({
235
+ id: block.id,
236
+ title: block.text,
237
+ blocks: sections.length === 0 ? [...lead, block] : [block],
238
+ exampleOffset: sections.length === 0 ? 0 : examples,
239
+ });
240
+ }
241
+ else if (sections.length === 0) {
242
+ lead.push(block);
243
+ }
244
+ else {
245
+ sections[sections.length - 1].blocks.push(block);
246
+ }
247
+ if (block.type === "example")
248
+ examples += 1;
249
+ });
250
+ return sections;
251
+ };
252
+ exports.splitArticleSections = splitArticleSections;
253
+ // 名札({#id})の付いた見出しが、どのページ(横に払うページ)にあるか。##・###の名札なら、それを含むページ
254
+ const findSectionIndex = (sections, id) => sections.findIndex((section) => section.id === id ||
255
+ section.blocks.some((b) => b.type === "heading" && b.id === id));
256
+ exports.findSectionIndex = findSectionIndex;
257
+ const ANCHOR_LINE = /^\s*#{1,3}\s+(.+?)\s*\{#([\w-]+)\}\s*$/gm;
258
+ // 解説のLESSONの札(lesson[名札])から、行き先の記事と見出しの名前を引く。アプリに入っている記事の本文から作る
259
+ const collectLessonAnchors = (articleContents) => {
260
+ const anchors = {};
261
+ Object.entries(articleContents).forEach(([articleId, raw]) => {
262
+ const re = new RegExp(ANCHOR_LINE.source, "gm");
263
+ let m;
264
+ while ((m = re.exec(raw)) !== null)
265
+ anchors[m[2]] = { articleId, title: m[1] };
266
+ });
267
+ return anchors;
268
+ };
269
+ exports.collectLessonAnchors = collectLessonAnchors;
@@ -4,4 +4,5 @@ import { Store } from "@nakamura-123/types";
4
4
  type QuestionType = typeof DQuestionSchema.prototype;
5
5
  type QR = Results<QuestionType>;
6
6
  export declare const formatQuestions: (questions: QR | QuestionType[]) => Store.DQInStore[];
7
+ export declare const shuffleMultiRow: (array: Store.ChoiceType[]) => Store.ChoiceType[];
7
8
  export {};