@siegesailor/terminal-sigma 1.1.0 → 1.3.0
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.
- package/README.md +68 -24
- package/build/app.js +151 -65
- package/build/app.js.map +1 -1
- package/build/command-line-interface.js +1 -1
- package/build/components/character.js +18 -11
- package/build/components/character.js.map +1 -1
- package/build/components/choice.js +39 -0
- package/build/components/choice.js.map +1 -0
- package/build/components/entry-form.js +9 -7
- package/build/components/entry-form.js.map +1 -1
- package/build/components/footer.js +10 -8
- package/build/components/footer.js.map +1 -1
- package/build/components/logs-view.js +35 -29
- package/build/components/logs-view.js.map +1 -1
- package/build/components/menu-grid.js +5 -3
- package/build/components/menu-grid.js.map +1 -1
- package/build/components/today-panel.js +24 -15
- package/build/components/today-panel.js.map +1 -1
- package/build/content.js +162 -42
- package/build/content.js.map +1 -1
- package/build/health.js +90 -0
- package/build/health.js.map +1 -0
- package/build/i18n.js +379 -30
- package/build/i18n.js.map +1 -1
- package/build/pixel-art.js +551 -344
- package/build/pixel-art.js.map +1 -1
- package/build/progress.js +14 -2
- package/build/progress.js.map +1 -1
- package/build/quotes.js +132 -27
- package/build/quotes.js.map +1 -1
- package/build/theme.js +119 -19
- package/build/theme.js.map +1 -1
- package/package.json +1 -1
package/build/content.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { adviceOf, targetsOf } from "./health.js";
|
|
2
|
+
import { formatNumber, genders, healthGoals, intensities, messagesOf, workoutActivities, workStyles, } from "./i18n.js";
|
|
2
3
|
import { dailyGoals, experienceOf, experiencePerLevel, todayOf, } from "./progress.js";
|
|
3
4
|
import { quoteRefreshMinutes } from "./quotes.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
5
|
+
export const characterWidth = 28;
|
|
6
|
+
// Header and footer take 5 rows. The character panel is 19 rows tall, Today
|
|
7
|
+
// 25 with its spacing or 16 compact, the menu about 11, and Recent 7.
|
|
7
8
|
const chromeRows = 5;
|
|
8
|
-
const
|
|
9
|
+
const characterRows = 19;
|
|
10
|
+
const todayRows = 25;
|
|
11
|
+
const compactTodayRows = 16;
|
|
12
|
+
const menuRows = 11;
|
|
13
|
+
const recentRows = 7;
|
|
9
14
|
// The panel that takes input always shows; the rest appears as space allows.
|
|
10
15
|
export function layoutOf(columns, rows) {
|
|
11
16
|
const menuColumnsOf = (panelWidth) => {
|
|
12
17
|
const inner = panelWidth - 4;
|
|
13
|
-
if (inner >=
|
|
18
|
+
if (inner >= 96) {
|
|
14
19
|
return 3;
|
|
15
20
|
}
|
|
16
|
-
return inner >=
|
|
21
|
+
return inner >= 60 ? 2 : 1;
|
|
17
22
|
};
|
|
23
|
+
const showRecent = rows >= chromeRows + menuRows + recentRows;
|
|
18
24
|
if (columns >= 120) {
|
|
19
25
|
const panelWidth = Math.floor((columns - characterWidth) / 2);
|
|
20
26
|
return {
|
|
@@ -22,7 +28,9 @@ export function layoutOf(columns, rows) {
|
|
|
22
28
|
todayWidth: columns - characterWidth - panelWidth,
|
|
23
29
|
menuColumns: menuColumnsOf(panelWidth),
|
|
24
30
|
showCharacter: true,
|
|
31
|
+
showRecent,
|
|
25
32
|
showToday: true,
|
|
33
|
+
isTodayCompact: rows < chromeRows + todayRows,
|
|
26
34
|
todayBeside: true,
|
|
27
35
|
stacked: false,
|
|
28
36
|
};
|
|
@@ -34,63 +42,107 @@ export function layoutOf(columns, rows) {
|
|
|
34
42
|
todayWidth: columns,
|
|
35
43
|
menuColumns: menuColumnsOf(panelWidth),
|
|
36
44
|
showCharacter: true,
|
|
37
|
-
|
|
45
|
+
showRecent,
|
|
46
|
+
showToday: rows >= chromeRows + characterRows + compactTodayRows,
|
|
47
|
+
isTodayCompact: rows < chromeRows + characterRows + todayRows,
|
|
38
48
|
todayBeside: false,
|
|
39
49
|
stacked: false,
|
|
40
50
|
};
|
|
41
51
|
}
|
|
52
|
+
const aboveToday = chromeRows + menuRows + recentRows + characterRows;
|
|
42
53
|
return {
|
|
43
54
|
panelWidth: columns,
|
|
44
55
|
todayWidth: columns,
|
|
45
56
|
menuColumns: menuColumnsOf(columns),
|
|
46
|
-
showCharacter: rows >=
|
|
47
|
-
|
|
57
|
+
showCharacter: rows >= aboveToday,
|
|
58
|
+
showRecent,
|
|
59
|
+
showToday: rows >= aboveToday + compactTodayRows,
|
|
60
|
+
isTodayCompact: rows < aboveToday + todayRows,
|
|
48
61
|
todayBeside: false,
|
|
49
62
|
stacked: true,
|
|
50
63
|
};
|
|
51
64
|
}
|
|
52
65
|
const percentOf = (value, goal) => (value / goal) * 100;
|
|
53
|
-
export function
|
|
66
|
+
export function sectionsOf(language, palette, progress, now) {
|
|
67
|
+
const messages = messagesOf(language);
|
|
54
68
|
const today = todayOf(progress, now);
|
|
69
|
+
const targets = targetsOf(progress.profile);
|
|
55
70
|
const experience = experienceOf(progress);
|
|
56
71
|
const level = Math.floor(experience / experiencePerLevel) + 1;
|
|
57
72
|
const levelExperience = experience % experiencePerLevel;
|
|
73
|
+
const advice = adviceOf(progress.profile, today, language, messages);
|
|
74
|
+
const format = (value) => formatNumber(language, value);
|
|
58
75
|
return [
|
|
59
76
|
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
metrics: [
|
|
78
|
+
{
|
|
79
|
+
label: messages.today.character,
|
|
80
|
+
detail: messages.today.characterDetail(level + 1, experiencePerLevel - levelExperience),
|
|
81
|
+
value: percentOf(levelExperience, experiencePerLevel),
|
|
82
|
+
color: palette.metrics.character,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: messages.today.focus,
|
|
86
|
+
detail: messages.today.focusDetail(today.focusSessions, dailyGoals.focusSessions),
|
|
87
|
+
value: percentOf(today.focusSessions, dailyGoals.focusSessions),
|
|
88
|
+
color: palette.metrics.focus,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
64
91
|
},
|
|
65
92
|
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
title: progress.profile
|
|
94
|
+
? messages.health.title(messages.goal[progress.profile.goal])
|
|
95
|
+
: messages.today.health,
|
|
96
|
+
metrics: [
|
|
97
|
+
{
|
|
98
|
+
label: messages.today.protein,
|
|
99
|
+
detail: messages.today.proteinDetail(format(today.protein), format(targets.protein)),
|
|
100
|
+
value: percentOf(today.protein, targets.protein),
|
|
101
|
+
color: palette.metrics.protein,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
label: messages.today.calories,
|
|
105
|
+
detail: messages.today.caloriesDetail(format(today.calories), format(targets.calories), today.meals),
|
|
106
|
+
value: percentOf(today.calories, targets.calories),
|
|
107
|
+
color: palette.metrics.calories,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
label: messages.today.workout,
|
|
111
|
+
detail: messages.today.workoutDetail(today.workoutMinutes, targets.workoutMinutes),
|
|
112
|
+
value: percentOf(today.workoutMinutes, targets.workoutMinutes),
|
|
113
|
+
color: palette.metrics.workout,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
advice: progress.profile
|
|
117
|
+
? (advice.find((item) => !item.isDone) ?? advice[0])
|
|
118
|
+
: { text: messages.health.noProfile, isDone: false },
|
|
82
119
|
},
|
|
83
120
|
];
|
|
84
121
|
}
|
|
85
122
|
export const menuOrder = [
|
|
86
123
|
"timer",
|
|
87
|
-
"
|
|
88
|
-
"workout",
|
|
124
|
+
"health",
|
|
89
125
|
"logs",
|
|
90
126
|
"quotes",
|
|
127
|
+
"profile",
|
|
128
|
+
"theme",
|
|
91
129
|
"language",
|
|
92
130
|
];
|
|
131
|
+
const languageSignal = {
|
|
132
|
+
en: "EN",
|
|
133
|
+
"zh-TW": "繁中",
|
|
134
|
+
ko: "한국어",
|
|
135
|
+
};
|
|
93
136
|
export function menuItemsOf(messages, language, state) {
|
|
137
|
+
const { profile } = state.progress;
|
|
138
|
+
const proteinLeft = targetsOf(profile).protein - todayOf(state.progress, state.now).protein;
|
|
139
|
+
let healthSignal = messages.signal.setUp;
|
|
140
|
+
if (profile) {
|
|
141
|
+
healthSignal =
|
|
142
|
+
proteinLeft > 0
|
|
143
|
+
? messages.signal.proteinLeft(proteinLeft)
|
|
144
|
+
: messages.signal.onTrack;
|
|
145
|
+
}
|
|
94
146
|
return [
|
|
95
147
|
{
|
|
96
148
|
label: messages.menu.timer,
|
|
@@ -98,14 +150,9 @@ export function menuItemsOf(messages, language, state) {
|
|
|
98
150
|
description: messages.describe.timer(state.focus, state.rest),
|
|
99
151
|
},
|
|
100
152
|
{
|
|
101
|
-
label: messages.menu.
|
|
102
|
-
signal:
|
|
103
|
-
description: messages.describe.
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
label: messages.menu.workout,
|
|
107
|
-
signal: messages.signal.minutes(state.workoutMinutes),
|
|
108
|
-
description: messages.describe.workout,
|
|
153
|
+
label: messages.menu.health,
|
|
154
|
+
signal: healthSignal,
|
|
155
|
+
description: messages.describe.health,
|
|
109
156
|
},
|
|
110
157
|
{
|
|
111
158
|
label: messages.menu.logs,
|
|
@@ -117,9 +164,19 @@ export function menuItemsOf(messages, language, state) {
|
|
|
117
164
|
signal: messages.signal.newQuote,
|
|
118
165
|
description: messages.describe.quotes(quoteRefreshMinutes),
|
|
119
166
|
},
|
|
167
|
+
{
|
|
168
|
+
label: messages.menu.profile,
|
|
169
|
+
signal: profile?.name ?? messages.signal.setUp,
|
|
170
|
+
description: messages.describe.profile,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
label: messages.menu.theme,
|
|
174
|
+
signal: messages.themes.names[state.theme],
|
|
175
|
+
description: messages.describe.theme,
|
|
176
|
+
},
|
|
120
177
|
{
|
|
121
178
|
label: messages.menu.language,
|
|
122
|
-
signal: language
|
|
179
|
+
signal: languageSignal[language],
|
|
123
180
|
description: messages.describe.language,
|
|
124
181
|
},
|
|
125
182
|
];
|
|
@@ -173,4 +230,67 @@ export const workoutFieldsOf = (messages) => [
|
|
|
173
230
|
})),
|
|
174
231
|
},
|
|
175
232
|
];
|
|
233
|
+
// Saved values come back as defaults, so editing the profile is a run of Enter.
|
|
234
|
+
export const profileFieldsOf = (messages, profile, name) => [
|
|
235
|
+
{
|
|
236
|
+
key: "name",
|
|
237
|
+
label: messages.form.name,
|
|
238
|
+
kind: "text",
|
|
239
|
+
defaultValue: profile?.name ?? name,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
key: "age",
|
|
243
|
+
label: messages.form.age,
|
|
244
|
+
kind: "number",
|
|
245
|
+
minimum: 10,
|
|
246
|
+
maximum: 100,
|
|
247
|
+
defaultValue: profile ? String(profile.age) : undefined,
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
key: "height",
|
|
251
|
+
label: messages.form.height,
|
|
252
|
+
kind: "number",
|
|
253
|
+
minimum: 100,
|
|
254
|
+
maximum: 250,
|
|
255
|
+
defaultValue: profile ? String(profile.height) : undefined,
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
key: "weight",
|
|
259
|
+
label: messages.form.weight,
|
|
260
|
+
kind: "number",
|
|
261
|
+
minimum: 30,
|
|
262
|
+
maximum: 300,
|
|
263
|
+
defaultValue: profile ? String(profile.weight) : undefined,
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
key: "gender",
|
|
267
|
+
label: messages.form.gender,
|
|
268
|
+
kind: "select",
|
|
269
|
+
options: genders.map((option) => ({
|
|
270
|
+
label: messages.gender[option],
|
|
271
|
+
value: option,
|
|
272
|
+
})),
|
|
273
|
+
defaultValue: profile?.gender,
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
key: "workStyle",
|
|
277
|
+
label: messages.form.workStyle,
|
|
278
|
+
kind: "select",
|
|
279
|
+
options: workStyles.map((option) => ({
|
|
280
|
+
label: messages.workStyle[option],
|
|
281
|
+
value: option,
|
|
282
|
+
})),
|
|
283
|
+
defaultValue: profile?.workStyle,
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
key: "goal",
|
|
287
|
+
label: messages.form.goal,
|
|
288
|
+
kind: "select",
|
|
289
|
+
options: healthGoals.map((option) => ({
|
|
290
|
+
label: messages.goal[option],
|
|
291
|
+
value: option,
|
|
292
|
+
})),
|
|
293
|
+
defaultValue: profile?.goal,
|
|
294
|
+
},
|
|
295
|
+
];
|
|
176
296
|
//# sourceMappingURL=content.js.map
|
package/build/content.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sourceRoot":"","sources":["../source/content.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,YAAY,EACZ,WAAW,EAGX,iBAAiB,
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../source/content.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACN,YAAY,EACZ,OAAO,EACP,WAAW,EACX,WAAW,EAGX,UAAU,EACV,iBAAiB,EACjB,UAAU,GACV,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,UAAU,EACV,YAAY,EACZ,kBAAkB,EAGlB,OAAO,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,4EAA4E;AAC5E,sEAAsE;AACtE,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,UAAU,GAAG,CAAC,CAAC;A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AQ,CAAC,IAAI,CAAC,MAAM,CAAC;YAC5B,KAAK,EAAE,MAAM;SACb,CAAC,CAAC;QACH,YAAY,EAAE,OAAO,EAAE,IAAI;KAC3B;CACD,CAAC"}
|
package/build/health.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { formatNumber, } from "./i18n.js";
|
|
2
|
+
// Without a profile: the common 2,000 kcal reference, 50 g protein, and 30 active minutes.
|
|
3
|
+
const defaultTargets = {
|
|
4
|
+
calories: 2000,
|
|
5
|
+
protein: 50,
|
|
6
|
+
workoutMinutes: 30,
|
|
7
|
+
};
|
|
8
|
+
// Physical activity levels, from sedentary to very active.
|
|
9
|
+
const activityFactor = {
|
|
10
|
+
desk: 1.2,
|
|
11
|
+
standing: 1.375,
|
|
12
|
+
active: 1.55,
|
|
13
|
+
athlete: 1.725,
|
|
14
|
+
};
|
|
15
|
+
// Mifflin-St Jeor's constant, averaged when gender is not given.
|
|
16
|
+
const genderConstant = {
|
|
17
|
+
male: 5,
|
|
18
|
+
female: -161,
|
|
19
|
+
other: -78,
|
|
20
|
+
};
|
|
21
|
+
const calorieShift = {
|
|
22
|
+
loseFat: -500,
|
|
23
|
+
maintain: 0,
|
|
24
|
+
buildMuscle: 300,
|
|
25
|
+
endurance: 200,
|
|
26
|
+
};
|
|
27
|
+
// Grams of protein per kilogram of body weight, within the 0.8 to 2.2 g that
|
|
28
|
+
// sports nutrition guidance covers.
|
|
29
|
+
const proteinPerKilogram = {
|
|
30
|
+
loseFat: 1.8,
|
|
31
|
+
maintain: 1,
|
|
32
|
+
buildMuscle: 2,
|
|
33
|
+
endurance: 1.4,
|
|
34
|
+
};
|
|
35
|
+
const proteinForWork = {
|
|
36
|
+
desk: 0,
|
|
37
|
+
standing: 0.1,
|
|
38
|
+
active: 0.2,
|
|
39
|
+
athlete: 0.3,
|
|
40
|
+
};
|
|
41
|
+
const workoutMinutes = {
|
|
42
|
+
loseFat: 45,
|
|
43
|
+
maintain: 30,
|
|
44
|
+
buildMuscle: 45,
|
|
45
|
+
endurance: 60,
|
|
46
|
+
};
|
|
47
|
+
export function targetsOf(profile) {
|
|
48
|
+
if (!profile) {
|
|
49
|
+
return defaultTargets;
|
|
50
|
+
}
|
|
51
|
+
const { weight, height, age, gender, workStyle, goal } = profile;
|
|
52
|
+
const restingCalories = 10 * weight + 6.25 * height - 5 * age + genderConstant[gender];
|
|
53
|
+
const calories = restingCalories * activityFactor[workStyle] + calorieShift[goal];
|
|
54
|
+
const proteinRate = Math.min(proteinPerKilogram[goal] + proteinForWork[workStyle], 2.2);
|
|
55
|
+
return {
|
|
56
|
+
calories: Math.round(Math.max(calories, 1200) / 10) * 10,
|
|
57
|
+
protein: Math.round(weight * proteinRate),
|
|
58
|
+
workoutMinutes: workoutMinutes[goal],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// What is left of today, most pressing first.
|
|
62
|
+
export function adviceOf(profile, today, language, messages) {
|
|
63
|
+
const targets = targetsOf(profile);
|
|
64
|
+
const goal = profile?.goal ?? "maintain";
|
|
65
|
+
const protein = targets.protein - today.protein;
|
|
66
|
+
const minutes = targets.workoutMinutes - today.workoutMinutes;
|
|
67
|
+
const calories = targets.calories - today.calories;
|
|
68
|
+
const { health } = messages;
|
|
69
|
+
return [
|
|
70
|
+
minutes > 0
|
|
71
|
+
? {
|
|
72
|
+
text: health.workoutLeft(minutes, health.suggestion[goal]),
|
|
73
|
+
isDone: false,
|
|
74
|
+
}
|
|
75
|
+
: { text: health.workoutDone, isDone: true },
|
|
76
|
+
protein > 0
|
|
77
|
+
? { text: health.proteinLeft(protein), isDone: false }
|
|
78
|
+
: { text: health.proteinDone, isDone: true },
|
|
79
|
+
calories >= 0
|
|
80
|
+
? {
|
|
81
|
+
text: health.caloriesLeft(formatNumber(language, calories)),
|
|
82
|
+
isDone: false,
|
|
83
|
+
}
|
|
84
|
+
: {
|
|
85
|
+
text: health.caloriesOver(formatNumber(language, -calories)),
|
|
86
|
+
isDone: false,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../source/health.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,GAMZ,MAAM,WAAW,CAAC;AAWnB,2FAA2F;AAC3F,MAAM,cAAc,GAAY;IAC/B,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,EAAE;IACX,cAAc,EAAE,EAAE;CAClB,CAAC;AAEF,2DAA2D;AAC3D,MAAM,cAAc,GAA8B;IACjD,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,KAAK;CACd,CAAC;AAEF,iEAAiE;AACjE,MAAM,cAAc,GAA2B;IAC9C,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC,GAAG;IACZ,KAAK,EAAE,CAAC,EAAE;CACV,CAAC;AAEF,MAAM,YAAY,GAA+B;IAChD,OAAO,EAAE,CAAC,GAAG;IACb,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,GAAG;IAChB,SAAS,EAAE,GAAG;CACd,CAAC;AAEF,6EAA6E;AAC7E,oCAAoC;AACpC,MAAM,kBAAkB,GAA+B;IACtD,OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;IACd,SAAS,EAAE,GAAG;CACd,CAAC;AAEF,MAAM,cAAc,GAA8B;IACjD,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,GAAG;CACZ,CAAC;AAEF,MAAM,cAAc,GAA+B;IAClD,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,EAAE;IACZ,WAAW,EAAE,EAAE;IACf,SAAS,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,OAA4B;IACrD,IAAI,CAAC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