@shiodome47/sekisho 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,33 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shiodome47
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ The button icons in src/icons.tsx are drawn after Lucide (https://lucide.dev),
26
+ licensed under the ISC License:
27
+
28
+ Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of
29
+ Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
30
+
31
+ Permission to use, copy, modify, and/or distribute this software for any purpose
32
+ with or without fee is hereby granted, provided that the above copyright notice
33
+ and this permission notice appear in all copies.
package/README.md CHANGED
@@ -1,3 +1,141 @@
1
- # Temporary Holding Version
1
+ # @shiodome47/sekisho — 関所めぐり
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ チェックリストをクリアしていくと、通行手形にスタンプが押される部品です。
4
+ いろいろなアプリ(手話学習・英語など)に入れて使います。
5
+
6
+ - **コース**(関所の集まり)→ **関所**(チェック項目のまとまり。全部済んだらクリア)→ **チェック項目**
7
+ - 回り方はコースごとに「どこからでも」か「順番」
8
+ - 「10 回くり返す」のような回数のある項目は「3 / 10」と数える
9
+ - 自分でチェックするのが基本。アプリが「これをした」と知らせると、自動でも進む
10
+ - 関所をクリアするたびに、スタンプとご褒美(コネクタでつなぐ)
11
+
12
+ > 状態: **作っているところ**(npm にはまだ出していません)。設計は [`docs/design.md`](docs/design.md)。
13
+ > 見本のページは `npm run dev` で開けます。
14
+
15
+ | 入り口 | 中身 | 要るもの |
16
+ |---|---|---|
17
+ | `@shiodome47/sekisho` | 画面(`<Sekisho>`・`<Celebration>`)と、土台のすべて | React 18・19 |
18
+ | `@shiodome47/sekisho/editor` | コースを作る・直す画面(`<CourseEditor>`) | React と **linkshelf**(関所のカードを並べる `<CardBoard>`) |
19
+ | `@shiodome47/sekisho/core` | 画面なしの土台(計算だけ) | なし |
20
+ | `@shiodome47/sekisho/style.css` | 見た目(`.sekisho` の中だけに効く) | — |
21
+
22
+ ## 画面(`<Sekisho>`)
23
+
24
+ コースの一覧 → コース(通行手形・関所・チェック項目)までを、まるごと出します。
25
+ 関所をクリアすると、通行手形にスタンプが「ポン!」と押され、続けてご褒美が出ます。
26
+
27
+ ```tsx
28
+ import { Sekisho, applyChanges } from '@shiodome47/sekisho'
29
+ import { CourseEditor } from '@shiodome47/sekisho/editor' // 作る画面が要るときだけ
30
+ import '@shiodome47/sekisho/style.css'
31
+
32
+ <Sekisho
33
+ data={data} // { courses, progress, clears }
34
+ onChange={(changes) => {
35
+ myStorage.save(changes) // 保存はアプリ
36
+ setData((d) => applyChanges(d, changes))
37
+ }}
38
+ targets={targets} // チェック項目の中身(動画・区間など)の窓口
39
+ rewards={[videoReward]} // ご褒美のコネクタ
40
+ editor={CourseEditor} // 渡すと「コースを作る」「直す」が出る
41
+ />
42
+ ```
43
+
44
+ | 設定 | 中身 |
45
+ |---|---|
46
+ | `data` / `onChange` | データと、変わったとき(必須) |
47
+ | `targets` | チェック項目の中身の窓口。`open`(押したら開く)・`renderBadge`(▶ などの印)・`pick`(作る画面で「動画・区間から足す」)・`canOpen` |
48
+ | `rewards` | ご褒美のコネクタ(下) |
49
+ | `renderStamp` | スタンプの演出そのものを差し替える(メダル・花丸など) |
50
+ | `editor` | 作る画面。渡さなければ回るだけ |
51
+ | `allowImport` / `allowExport` | 「コースを読み込む」「書き出す(配る用)」を出す(既定は出す) |
52
+ | `reducedMotion` | 演出を減らす。無ければ端末の設定(視差効果を減らす)に従う |
53
+ | `muted` | 音を出さない(コネクタに渡す。既定は true) |
54
+ | `theme` | `light` / `dark` / `system`(既定) |
55
+ | `labels` | 文言の一部を差し替え。英語は `EN_LABELS` |
56
+
57
+ 色は CSS の変数で変えます: `.sekisho { --sk-accent: #2563eb; }`(ほかに `--sk-surface`・`--sk-text`・`--sk-danger`・`--sk-paper` など)。
58
+
59
+ ### ご褒美のコネクタ(差込口)
60
+
61
+ 関所(`gate.reward`)とコース(`course.reward`)に、ご褒美を書いておけます。
62
+ `type` が同じコネクタを、アプリが `rewards` で渡すと、スタンプのあとに出ます。
63
+
64
+ ```tsx
65
+ import type { RewardConnector } from '@shiodome47/sekisho'
66
+
67
+ // コースの JSON: "reward": { "type": "video", "id": "lesson-123" }
68
+ const videoReward: RewardConnector = {
69
+ type: 'video',
70
+ render: ({ reward, done, muted }) => <MyVideo id={String(reward.id)} muted={muted} onEnded={done} />,
71
+ }
72
+ ```
73
+
74
+ - 部品に入っているもの: `message`(ひみつの一言。`{ "type": "message", "text": "…" }`)。同じ `type` を渡せば差し替わる
75
+ - 知らない `type` のご褒美は飛ばす(古い版のアプリでも止まらない)
76
+ - `done()` を呼ぶと次へ進む。`reducedMotion`・`muted` も届くので、演出を合わせる
77
+
78
+ ### 自動のチェックの演出(`<Celebration>`)
79
+
80
+ アプリが `report()` で知らせて関所がクリアになったときは、返ってきた `events` を `<Celebration>` に渡して、練習の画面の上で見せます。
81
+
82
+ ```tsx
83
+ const changes = report(data, { target: { type: 'segment', id } }, new Date())
84
+ save(changes)
85
+ setEvents((q) => [...q, ...(changes.events ?? [])])
86
+
87
+ <Celebration events={events} onDone={() => setEvents([])} rewards={[videoReward]} />
88
+ ```
89
+
90
+ ## 土台(`@shiodome47/sekisho/core`)
91
+
92
+ React にも保存先にも頼らない、計算だけの入り口です。
93
+ 関数はデータを書き換えず、**変更(`Changes`)を返す**だけ。保存はアプリが行い、`applyChanges` で手元にも当てます。
94
+ 「今」(`now`)は関数に渡します。
95
+
96
+ ```ts
97
+ import { addOne, applyChanges, report, viewCourse, type SekishoData } from '@shiodome47/sekisho/core'
98
+
99
+ let data: SekishoData = await myStorage.load() // { courses, progress, clears }
100
+
101
+ // 自分で「+1」を押した
102
+ const changes = addOne(data, courseId, itemId, new Date())
103
+ await myStorage.save(changes) // courses / progress / clears を書き、delete… を消す
104
+ data = applyChanges(data, changes)
105
+ for (const e of changes.events ?? []) showStamp(e) // 新しくクリアした関所・コース
106
+
107
+ // アプリから「区間を 1 回くり返した」と知らせる(target が同じ項目が、全部のコースで進む)
108
+ report(data, { target: { type: 'segment', id: segmentId } }, new Date())
109
+
110
+ // 画面に出す形(関所ごとの「2 / 3」・開いているか・クリアしたか)
111
+ const view = viewCourse(data, data.courses[0])
112
+ ```
113
+
114
+ | 種類 | 関数 |
115
+ |---|---|
116
+ | 進める・戻す | `addOne`(+1)・`removeOne`(−1)・`checkItem`(済みにする)・`uncheckItem`(外す)・`toggleItem`・`report`(自動のチェック) |
117
+ | 見る | `viewCourse`・`isGateOpen`・`itemGoal` |
118
+ | コースを作る・直す | `newCourse`・`newGate`・`newItem`・`updateCourse`・`addGate`・`updateGate`・`removeGate`・`moveGate`・`addItem`・`updateItem`・`removeItem`・`moveItem`・`duplicateCourse` |
119
+ | 配る・受け取る | `exportCourses`(JSON にする)・`parseCourses`(形を確かめて読む)・`importCourses`(新しい版だけ取り込む) |
120
+ | 保存・同期 | `applyChanges`・`deleteCourse`・`settleClears`・`newerProgress` |
121
+
122
+ 決まりごと:
123
+
124
+ - チェックは 1 回きり(日付が変わっても外れない)。自分で外せる
125
+ - 関所のクリアの記録は消えない。項目を外しても残り、演出は 2 回目は出ない
126
+ - 順番のコースでは、開いていない関所の項目は進まない
127
+ - 進み具合はチェック項目の `id` で結びつく。コースが新しい版になっても残る
128
+
129
+ ## 見本のページ
130
+
131
+ ```bash
132
+ npm install
133
+ npm run dev
134
+ ```
135
+
136
+ `examples/web` にあります。紙吹雪のご褒美(アプリが足すコネクタの見本)・区間を選ぶ窓口・自動のチェックを試せます。
137
+ 公開の手順は [`PUBLISHING.md`](PUBLISHING.md)。
138
+
139
+ ## ライセンス
140
+
141
+ MIT
@@ -0,0 +1,173 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import { T as TargetRef, b as CheckItem, R as RewardRef, C as ClearEvent, G as Gate, d as Course, S as SekishoData, a as Changes } from './types-DxLG2LO0.js';
4
+
5
+ /** 画面の文言。labels で一部だけ差し替えられる。英語は EN_LABELS */
6
+ declare const JA_LABELS: {
7
+ courses: string;
8
+ noCourses: string;
9
+ given: string;
10
+ own: string;
11
+ back: string;
12
+ createCourse: string;
13
+ importCourses: string;
14
+ importDone: (n: number) => string;
15
+ importNothing: string;
16
+ editCourse: string;
17
+ duplicateCourse: string;
18
+ exportCourse: string;
19
+ deleteCourse: string;
20
+ deleteConfirm: (title: string) => string;
21
+ passport: string;
22
+ routeFree: string;
23
+ routeOrdered: string;
24
+ clearedOf: (cleared: number, total: number) => string;
25
+ locked: string;
26
+ cleared: string;
27
+ courseCleared: string;
28
+ check: (title: string) => string;
29
+ uncheck: (title: string) => string;
30
+ plusOne: (title: string) => string;
31
+ minusOne: (title: string) => string;
32
+ open: (title: string) => string;
33
+ gateClear: string;
34
+ courseClear: string;
35
+ next: string;
36
+ close: string;
37
+ secretMessage: string;
38
+ emptyGate: string;
39
+ courseTitle: string;
40
+ courseDescription: string;
41
+ route: string;
42
+ gateTitle: string;
43
+ gateNumber: (n: number) => string;
44
+ stampText: string;
45
+ addGate: string;
46
+ newGateTitle: (n: number) => string;
47
+ removeGate: string;
48
+ removeGateConfirm: (title: string) => string;
49
+ moveGate: (title: string) => string;
50
+ itemTitle: string;
51
+ itemCount: string;
52
+ addItem: string;
53
+ addItemPlaceholder: string;
54
+ pickTarget: string;
55
+ moveUp: (title: string) => string;
56
+ moveDown: (title: string) => string;
57
+ removeItem: (title: string) => string;
58
+ rewardMessage: string;
59
+ rewardOther: (type: string) => string;
60
+ removeReward: string;
61
+ save: string;
62
+ cancel: string;
63
+ untitled: string;
64
+ };
65
+ type Labels = typeof JA_LABELS;
66
+ declare const EN_LABELS: Labels;
67
+
68
+ /**
69
+ * アプリとのつなぎ(コネクタ・窓口)の形。
70
+ * 部品はチェック項目の中身もご褒美の中身も知らない。アプリがこれを渡して、表示・開く・演出を受け持つ。
71
+ */
72
+
73
+ /** チェック項目の中身(動画・区間など)の窓口 */
74
+ interface TargetAdapter {
75
+ /** 「動画・区間を選ぶ」を押したとき。アプリが自分の画面で選ばせ、選んだものを返す(やめたら null) */
76
+ pick?: () => Promise<{
77
+ target: TargetRef;
78
+ title: string;
79
+ } | null>;
80
+ /** 項目の横に出す小さな印(▶ 動画、🔁 区間 など) */
81
+ renderBadge?: (target: TargetRef, item: CheckItem) => ReactNode;
82
+ /** 項目を押したとき、その中身を開く(手話アプリなら、動画や区間に飛ぶ)。無ければ押せない */
83
+ open?: (target: TargetRef, item: CheckItem) => void;
84
+ /** 開けるか(消した動画など、開けないものは false)。無ければ開ける */
85
+ canOpen?: (target: TargetRef) => boolean;
86
+ }
87
+ /** ご褒美のコネクタに渡すもの */
88
+ interface RewardRenderProps {
89
+ reward: RewardRef;
90
+ event: ClearEvent;
91
+ /** 呼ぶと次へ進む(閉じる) */
92
+ done: () => void;
93
+ /** 演出を減らす(動きを止める)とき true */
94
+ reducedMotion: boolean;
95
+ /** 音を出さないとき true */
96
+ muted: boolean;
97
+ labels: Labels;
98
+ }
99
+ /**
100
+ * ご褒美のコネクタ。type が同じご褒美(gate.reward・course.reward)を出す。
101
+ * アプリが <Sekisho rewards={[...]} /> で渡す。部品に入っているもの(message)と同じ type なら、こちらが使われる
102
+ */
103
+ interface RewardConnector {
104
+ type: string;
105
+ render: (props: RewardRenderProps) => ReactNode;
106
+ }
107
+ /** スタンプ(クリアの演出)を差し替えるときに渡すもの */
108
+ interface StampRenderProps {
109
+ event: ClearEvent;
110
+ /** スタンプの文字・色(gate.stamp ・コースの色から決めたもの) */
111
+ stamp: {
112
+ text: string;
113
+ color: string;
114
+ };
115
+ done: () => void;
116
+ reducedMotion: boolean;
117
+ muted: boolean;
118
+ labels: Labels;
119
+ }
120
+ /** 関所のスタンプの文字と色(無ければ名前の 1 文字目・コースの色・朱色) */
121
+ declare function stampOf(gate: Pick<Gate, 'title' | 'stamp'>, courseColor?: string): {
122
+ text: string;
123
+ color: string;
124
+ };
125
+ declare const DEFAULT_STAMP_COLOR = "#d9480f";
126
+
127
+ /** コースを作る・直す画面(@shiodome47/sekisho/editor の CourseEditor)に渡すもの */
128
+ interface CourseEditorProps {
129
+ course: Course;
130
+ /** 保存したとき(直したコースが届く) */
131
+ onSave: (course: Course) => void;
132
+ onCancel: () => void;
133
+ targets?: TargetAdapter;
134
+ labels?: Partial<Labels>;
135
+ }
136
+ interface SekishoProps {
137
+ /** コース・進み具合・クリアの記録(アプリが保存先から読んだもの) */
138
+ data: SekishoData;
139
+ /** 変わったとき。アプリは保存して、applyChanges で data を新しくする */
140
+ onChange: (changes: Changes) => void;
141
+ /** 今(テスト・見本用)。無ければ new Date() */
142
+ now?: () => Date;
143
+ /** チェック項目の中身(動画・区間など)の窓口 */
144
+ targets?: TargetAdapter;
145
+ /** ご褒美のコネクタ */
146
+ rewards?: RewardConnector[];
147
+ /** スタンプの演出を差し替える */
148
+ renderStamp?: (props: StampRenderProps) => ReactNode;
149
+ /**
150
+ * コースを作る・直す画面(import { CourseEditor } from '@shiodome47/sekisho/editor')。
151
+ * 渡すと「コースを作る」「直す」が出る。渡さなければ、回るだけ
152
+ */
153
+ editor?: ComponentType<CourseEditorProps>;
154
+ /** 「コースを読み込む」(JSON のファイル)を出す。既定は true */
155
+ allowImport?: boolean;
156
+ /** 「書き出す(配る用)」を出す。既定は true */
157
+ allowExport?: boolean;
158
+ /** 演出を減らす。無ければ端末の設定に従う */
159
+ reducedMotion?: boolean;
160
+ /** 音を出さない(コネクタに渡す)。既定は true */
161
+ muted?: boolean;
162
+ theme?: 'light' | 'dark' | 'system';
163
+ labels?: Partial<Labels>;
164
+ className?: string;
165
+ }
166
+ /**
167
+ * 関所めぐりの画面まるごと: コースの一覧 → コース(通行手形・関所・チェック項目)。
168
+ * クリアすると、スタンプとご褒美の演出を出す
169
+ */
170
+ declare function Sekisho(props: SekishoProps): react.JSX.Element;
171
+
172
+ export { DEFAULT_STAMP_COLOR as D, EN_LABELS as E, JA_LABELS as J, Sekisho as b, stampOf as s };
173
+ export type { CourseEditorProps as C, Labels as L, RewardConnector as R, StampRenderProps as S, TargetAdapter as T, RewardRenderProps as a, SekishoProps as c };
@@ -0,0 +1,125 @@
1
+ 'use client'
2
+
3
+ // src/core/course.ts
4
+ var newId = () => crypto.randomUUID();
5
+ function newCourse(input, now) {
6
+ const at = now.toISOString();
7
+ return {
8
+ id: newId(),
9
+ title: input.title.trim(),
10
+ ...input.description?.trim() ? { description: input.description.trim() } : {},
11
+ origin: input.origin ?? "own",
12
+ route: input.route ?? "free",
13
+ ...input.color ? { color: input.color } : {},
14
+ gates: [],
15
+ revision: 1,
16
+ createdAt: at,
17
+ updatedAt: at
18
+ };
19
+ }
20
+ function newGate(input) {
21
+ return {
22
+ id: newId(),
23
+ title: input.title.trim(),
24
+ ...input.description?.trim() ? { description: input.description.trim() } : {},
25
+ items: []
26
+ };
27
+ }
28
+ function newItem(input) {
29
+ return {
30
+ id: newId(),
31
+ title: input.title.trim(),
32
+ ...input.note?.trim() ? { note: input.note.trim() } : {},
33
+ ...input.target ? { target: input.target } : {},
34
+ ...input.count && input.count > 1 ? { count: Math.floor(input.count) } : {}
35
+ };
36
+ }
37
+ function touch(course, gates, now, patch = {}) {
38
+ return { ...course, ...patch, gates, revision: course.revision + 1, updatedAt: now.toISOString() };
39
+ }
40
+ function moveIn(list, from, toIndex) {
41
+ const out = list.slice();
42
+ const [x] = out.splice(from, 1);
43
+ out.splice(Math.max(0, Math.min(out.length, toIndex)), 0, x);
44
+ return out;
45
+ }
46
+ function updateCourse(course, patch, now) {
47
+ return touch(course, course.gates, now, patch);
48
+ }
49
+ function addGate(course, gate, now, index) {
50
+ const gates = course.gates.slice();
51
+ gates.splice(index ?? gates.length, 0, gate);
52
+ return touch(course, gates, now);
53
+ }
54
+ function updateGate(course, gateId, patch, now) {
55
+ return touch(course, course.gates.map((g) => g.id === gateId ? { ...g, ...patch } : g), now);
56
+ }
57
+ function removeGate(course, gateId, now) {
58
+ return touch(course, course.gates.filter((g) => g.id !== gateId), now);
59
+ }
60
+ function moveGate(course, gateId, toIndex, now) {
61
+ const from = course.gates.findIndex((g) => g.id === gateId);
62
+ if (from < 0) return course;
63
+ return touch(course, moveIn(course.gates, from, toIndex), now);
64
+ }
65
+ function addItem(course, gateId, item, now, index) {
66
+ return touch(
67
+ course,
68
+ course.gates.map((g) => {
69
+ if (g.id !== gateId) return g;
70
+ const items = g.items.slice();
71
+ items.splice(index ?? items.length, 0, item);
72
+ return { ...g, items };
73
+ }),
74
+ now
75
+ );
76
+ }
77
+ function updateItem(course, itemId, patch, now) {
78
+ return touch(
79
+ course,
80
+ course.gates.map((g) => ({ ...g, items: g.items.map((i) => i.id === itemId ? { ...i, ...patch } : i) })),
81
+ now
82
+ );
83
+ }
84
+ function removeItem(course, itemId, now) {
85
+ return touch(course, course.gates.map((g) => ({ ...g, items: g.items.filter((i) => i.id !== itemId) })), now);
86
+ }
87
+ function moveItem(course, itemId, toGateId, toIndex, now) {
88
+ const item = course.gates.flatMap((g) => g.items).find((i) => i.id === itemId);
89
+ if (!item || !course.gates.some((g) => g.id === toGateId)) return course;
90
+ const gates = course.gates.map((g) => {
91
+ const items = g.items.filter((i) => i.id !== itemId);
92
+ if (g.id === toGateId) items.splice(Math.max(0, Math.min(items.length, toIndex)), 0, item);
93
+ return { ...g, items };
94
+ });
95
+ return touch(course, gates, now);
96
+ }
97
+ function duplicateCourse(course, now, title) {
98
+ const at = now.toISOString();
99
+ return {
100
+ ...structuredClone(course),
101
+ id: newId(),
102
+ title: (title ?? course.title).trim(),
103
+ origin: "own",
104
+ revision: 1,
105
+ createdAt: at,
106
+ updatedAt: at
107
+ };
108
+ }
109
+
110
+ export {
111
+ newCourse,
112
+ newGate,
113
+ newItem,
114
+ updateCourse,
115
+ addGate,
116
+ updateGate,
117
+ removeGate,
118
+ moveGate,
119
+ addItem,
120
+ updateItem,
121
+ removeItem,
122
+ moveItem,
123
+ duplicateCourse
124
+ };
125
+ //# sourceMappingURL=chunk-IQYSUTRQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/course.ts"],"sourcesContent":["/**\n * コースを作る・直す(画面なし)。自分のコースを作る画面と、管理者がコースを作る画面の両方で使う。\n * どの関数も元のコースは変えず、新しいコースを返す。直すたびに revision(設計の版)が 1 つ上がる。\n */\nimport type { CheckItem, Course, Gate, Route } from './types'\n\nconst newId = () => crypto.randomUUID()\n\n/** 新しいコース(関所は空) */\nexport function newCourse(\n input: { title: string; description?: string; route?: Route; origin?: Course['origin']; color?: string },\n now: Date,\n): Course {\n const at = now.toISOString()\n return {\n id: newId(),\n title: input.title.trim(),\n ...(input.description?.trim() ? { description: input.description.trim() } : {}),\n origin: input.origin ?? 'own',\n route: input.route ?? 'free',\n ...(input.color ? { color: input.color } : {}),\n gates: [],\n revision: 1,\n createdAt: at,\n updatedAt: at,\n }\n}\n\n/** 新しい関所(項目は空) */\nexport function newGate(input: { title: string; description?: string }): Gate {\n return {\n id: newId(),\n title: input.title.trim(),\n ...(input.description?.trim() ? { description: input.description.trim() } : {}),\n items: [],\n }\n}\n\n/** 新しいチェック項目 */\nexport function newItem(input: { title: string; target?: CheckItem['target']; count?: number; note?: string }): CheckItem {\n return {\n id: newId(),\n title: input.title.trim(),\n ...(input.note?.trim() ? { note: input.note.trim() } : {}),\n ...(input.target ? { target: input.target } : {}),\n ...(input.count && input.count > 1 ? { count: Math.floor(input.count) } : {}),\n }\n}\n\n/** 直したコース(版を上げ、直した日時を入れる) */\nfunction touch(course: Course, gates: Gate[], now: Date, patch: Partial<Course> = {}): Course {\n return { ...course, ...patch, gates, revision: course.revision + 1, updatedAt: now.toISOString() }\n}\n\n/** 並びの中で 1 つを動かす(toIndex は動かしたあとの位置) */\nfunction moveIn<T>(list: T[], from: number, toIndex: number): T[] {\n const out = list.slice()\n const [x] = out.splice(from, 1)\n out.splice(Math.max(0, Math.min(out.length, toIndex)), 0, x)\n return out\n}\n\n/** コースの名前・説明・回り方・色・ご褒美を直す */\nexport function updateCourse(\n course: Course,\n patch: Partial<Pick<Course, 'title' | 'description' | 'route' | 'color' | 'reward'>>,\n now: Date,\n): Course {\n return touch(course, course.gates, now, patch)\n}\n\n/** 関所を足す(index が無ければ最後に) */\nexport function addGate(course: Course, gate: Gate, now: Date, index?: number): Course {\n const gates = course.gates.slice()\n gates.splice(index ?? gates.length, 0, gate)\n return touch(course, gates, now)\n}\n\n/** 関所の名前・説明・スタンプ・ご褒美を直す */\nexport function updateGate(\n course: Course,\n gateId: string,\n patch: Partial<Pick<Gate, 'title' | 'description' | 'stamp' | 'reward' | 'points'>>,\n now: Date,\n): Course {\n return touch(course, course.gates.map((g) => (g.id === gateId ? { ...g, ...patch } : g)), now)\n}\n\n/** 関所を消す(中の項目ごと) */\nexport function removeGate(course: Course, gateId: string, now: Date): Course {\n return touch(course, course.gates.filter((g) => g.id !== gateId), now)\n}\n\n/** 関所の並びを変える */\nexport function moveGate(course: Course, gateId: string, toIndex: number, now: Date): Course {\n const from = course.gates.findIndex((g) => g.id === gateId)\n if (from < 0) return course\n return touch(course, moveIn(course.gates, from, toIndex), now)\n}\n\n/** 関所にチェック項目を足す(index が無ければ最後に) */\nexport function addItem(course: Course, gateId: string, item: CheckItem, now: Date, index?: number): Course {\n return touch(\n course,\n course.gates.map((g) => {\n if (g.id !== gateId) return g\n const items = g.items.slice()\n items.splice(index ?? items.length, 0, item)\n return { ...g, items }\n }),\n now,\n )\n}\n\n/** チェック項目を直す */\nexport function updateItem(\n course: Course,\n itemId: string,\n patch: Partial<Pick<CheckItem, 'title' | 'note' | 'target' | 'count'>>,\n now: Date,\n): Course {\n return touch(\n course,\n course.gates.map((g) => ({ ...g, items: g.items.map((i) => (i.id === itemId ? { ...i, ...patch } : i)) })),\n now,\n )\n}\n\n/** チェック項目を消す */\nexport function removeItem(course: Course, itemId: string, now: Date): Course {\n return touch(course, course.gates.map((g) => ({ ...g, items: g.items.filter((i) => i.id !== itemId) })), now)\n}\n\n/** チェック項目を動かす(同じ関所の中でも、ほかの関所へも) */\nexport function moveItem(course: Course, itemId: string, toGateId: string, toIndex: number, now: Date): Course {\n const item = course.gates.flatMap((g) => g.items).find((i) => i.id === itemId)\n if (!item || !course.gates.some((g) => g.id === toGateId)) return course\n const gates = course.gates.map((g) => {\n const items = g.items.filter((i) => i.id !== itemId)\n if (g.id === toGateId) items.splice(Math.max(0, Math.min(items.length, toIndex)), 0, item)\n return { ...g, items }\n })\n return touch(course, gates, now)\n}\n\n/**\n * 複製して自分のコースにする(与えられたコースを、自分用に直したいとき)。\n * 新しい id になるので、進み具合は引き継がない\n */\nexport function duplicateCourse(course: Course, now: Date, title?: string): Course {\n const at = now.toISOString()\n return {\n ...structuredClone(course),\n id: newId(),\n title: (title ?? course.title).trim(),\n origin: 'own',\n revision: 1,\n createdAt: at,\n updatedAt: at,\n }\n}\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