@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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/editor/CourseEditor.tsx"],"sourcesContent":["import { CardBoard, flattenCards, type CardBoardCardState, type CardPlace } from 'linkshelf'\nimport { useMemo, useState } from 'react'\nimport { newGate, newItem } from '../core/course'\nimport type { CheckItem, Course, Gate } from '../core/types'\nimport { stampOf, type TargetAdapter } from '../ui/connectors'\nimport { JA_LABELS } from '../ui/labels'\nimport type { CourseEditorProps } from '../ui/Sekisho'\nimport { Stamp } from '../ui/Stamp'\n\nexport type { CourseEditorProps }\n\nconst MAX_COUNT = 999\n\n/**\n * コースを作る・直す画面。自分のコースにも、管理者が配るコースにも使う。\n * 関所はカードにして段組みで並べ、ドラッグで動かす(linkshelf の <CardBoard>)。\n * 保存するまでは、手元の下書きだけを変える\n */\nexport function CourseEditor({ course, onSave, onCancel, targets, labels: labelsPatch }: CourseEditorProps) {\n const labels = useMemo(() => ({ ...JA_LABELS, ...labelsPatch }), [labelsPatch])\n const [draft, setDraft] = useState<Course>(course)\n const setGates = (fn: (gates: Gate[]) => Gate[]) => setDraft((d) => ({ ...d, gates: fn(d.gates) }))\n const setGate = (gateId: string, fn: (g: Gate) => Gate) => setGates((gs) => gs.map((g) => (g.id === gateId ? fn(g) : g)))\n\n const cards = draft.gates.map((g, i) => ({ ...g, order: g.board?.order ?? i, column: g.board?.column, size: g.items.length + 4 }))\n\n const onMove = (places: CardPlace[]) => {\n const byId = new Map(places.map((p) => [p.id, p]))\n const placed = cards.map((c) => {\n const p = byId.get(c.id)\n return p ? { ...c, order: p.order, column: p.column } : c\n })\n // 左上から読む順を、回る順(関所の並び)にする\n const order = flattenCards(placed).map((c) => c.id)\n setGates((gs) =>\n order\n .map((id) => gs.find((g) => g.id === id)!)\n .map((g) => {\n const p = byId.get(g.id)\n return p ? { ...g, board: { order: p.order, ...(p.column !== undefined ? { column: p.column } : {}) } } : g\n }),\n )\n }\n\n const addGate = () => setGates((gs) => [...gs, newGate({ title: labels.newGateTitle(gs.length + 1) })])\n\n const save = () => {\n const at = new Date().toISOString()\n onSave({\n ...draft,\n title: draft.title.trim() || labels.untitled,\n description: draft.description?.trim() || undefined,\n gates: draft.gates.map((g) => ({ ...g, title: g.title.trim() || labels.gateTitle, items: g.items.filter((i) => i.title.trim()) })),\n revision: course.revision + 1,\n updatedAt: at,\n })\n }\n\n const route = draft.route ?? 'free'\n return (\n <div className=\"sk-editor\">\n <div className=\"sk-toolbar\">\n <button type=\"button\" className=\"sk-btn sk-btn--ghost\" onClick={onCancel}>\n {labels.cancel}\n </button>\n <button type=\"button\" className=\"sk-btn sk-btn--primary\" onClick={save}>\n {labels.save}\n </button>\n </div>\n\n <div className=\"sk-card sk-editor__course\">\n <label className=\"sk-field\">\n <span className=\"sk-field__label\">{labels.courseTitle}</span>\n <input className=\"sk-input\" value={draft.title} onChange={(e) => setDraft({ ...draft, title: e.target.value })} autoFocus={!course.title} />\n </label>\n <label className=\"sk-field\">\n <span className=\"sk-field__label\">{labels.courseDescription}</span>\n <textarea className=\"sk-input\" rows={2} value={draft.description ?? ''} onChange={(e) => setDraft({ ...draft, description: e.target.value })} />\n </label>\n <div className=\"sk-field\">\n <span className=\"sk-field__label\">{labels.route}</span>\n <div className=\"sk-segmented\" role=\"radiogroup\" aria-label={labels.route}>\n {(['free', 'ordered'] as const).map((r) => (\n <button\n key={r}\n type=\"button\"\n role=\"radio\"\n aria-checked={route === r}\n className={route === r ? 'is-on' : ''}\n onClick={() => setDraft({ ...draft, route: r })}\n >\n {r === 'free' ? labels.routeFree : labels.routeOrdered}\n </button>\n ))}\n </div>\n </div>\n </div>\n\n <CardBoard\n cards={cards}\n onMove={onMove}\n minColumnWidth={320}\n gap={12}\n addon={\n <button type=\"button\" className=\"sk-btn sk-add-gate\" onClick={addGate}>\n + {labels.addGate}\n </button>\n }\n renderCard={(card, { dragHandle, isDragging }) => {\n const gate = draft.gates.find((g) => g.id === card.id)!\n const index = draft.gates.indexOf(gate)\n return (\n <GateEditor\n gate={gate}\n index={index}\n color={draft.color}\n labels={labels}\n dragHandle={dragHandle}\n isDragging={isDragging}\n canPick={!!targets?.pick}\n onPick={async () => {\n const picked = await targets!.pick!()\n if (picked) setGate(gate.id, (g) => ({ ...g, items: [...g.items, newItem({ title: picked.title, target: picked.target })] }))\n }}\n renderBadge={targets?.renderBadge}\n onChange={(fn) => setGate(gate.id, fn)}\n onRemove={() => {\n if (gate.items.length === 0 || window.confirm(labels.removeGateConfirm(gate.title))) setGates((gs) => gs.filter((g) => g.id !== gate.id))\n }}\n />\n )\n }}\n />\n </div>\n )\n}\n\ntype L = typeof JA_LABELS\n\nfunction GateEditor({\n gate,\n index,\n color,\n labels,\n dragHandle,\n isDragging,\n canPick,\n onPick,\n renderBadge,\n onChange,\n onRemove,\n}: {\n gate: Gate\n index: number\n color?: string\n labels: L\n dragHandle: CardBoardCardState['dragHandle']\n isDragging: boolean\n canPick: boolean\n onPick: () => void\n renderBadge?: TargetAdapter['renderBadge']\n onChange: (fn: (g: Gate) => Gate) => void\n onRemove: () => void\n}) {\n const [text, setText] = useState('')\n const s = stampOf(gate, color)\n const setItem = (itemId: string, patch: Partial<CheckItem>) =>\n onChange((g) => ({ ...g, items: g.items.map((i) => (i.id === itemId ? { ...i, ...patch } : i)) }))\n const moveItem = (from: number, to: number) =>\n onChange((g) => {\n if (to < 0 || to >= g.items.length) return g\n const items = g.items.slice()\n const [x] = items.splice(from, 1)\n items.splice(to, 0, x)\n return { ...g, items }\n })\n const addText = () => {\n const title = text.trim()\n if (!title) return\n // 「10 回」「×10」「x10」が文にあれば、回数にする\n const m = title.match(/(\\d{1,3})\\s*(回|times|x)|[×x]\\s*(\\d{1,3})/i)\n const count = m ? Number(m[1] ?? m[3]) : undefined\n onChange((g) => ({ ...g, items: [...g.items, newItem({ title, count })] }))\n setText('')\n }\n const message = gate.reward?.type === 'message' ? String(gate.reward.text ?? '') : ''\n return (\n <section className=\"sk-card sk-gate-editor\" style={{ opacity: isDragging ? 0.5 : 1 }}>\n <div className=\"sk-gate-editor__head\">\n <button type=\"button\" className=\"sk-handle\" aria-label={labels.moveGate(gate.title)} {...dragHandle}>\n ⋮⋮\n </button>\n <span className=\"sk-gate-editor__number\">{labels.gateNumber(index + 1)}</span>\n <button type=\"button\" className=\"sk-icon-btn sk-icon-btn--danger\" aria-label={labels.removeGate} title={labels.removeGate} onClick={onRemove}>\n ×\n </button>\n </div>\n <div className=\"sk-gate-editor__title\">\n <Stamp text={s.text} color={s.color} size={44} />\n <label className=\"sk-field sk-grow\">\n <span className=\"sk-field__label\">{labels.gateTitle}</span>\n <input className=\"sk-input\" value={gate.title} onChange={(e) => onChange((g) => ({ ...g, title: e.target.value }))} />\n </label>\n <label className=\"sk-field sk-field--narrow\">\n <span className=\"sk-field__label\">{labels.stampText}</span>\n <input\n className=\"sk-input\"\n value={gate.stamp?.text ?? ''}\n placeholder={[...gate.title.trim()][0] ?? ''}\n title=\"1〜2 文字\"\n maxLength={4}\n onChange={(e) => onChange((g) => ({ ...g, stamp: { ...g.stamp, text: [...e.target.value].slice(0, 2).join('') } }))}\n />\n </label>\n </div>\n\n <ul className=\"sk-edit-items\">\n {gate.items.map((item, i) => (\n <li key={item.id} className=\"sk-edit-item\">\n {item.target && renderBadge ? <span className=\"sk-item__badge\">{renderBadge(item.target, item)}</span> : null}\n <input className=\"sk-input sk-grow\" aria-label={labels.itemTitle} value={item.title} onChange={(e) => setItem(item.id, { title: e.target.value })} />\n <span className=\"sk-edit-item__tools\">\n <label className=\"sk-count-field\">\n <input\n className=\"sk-input\"\n type=\"number\"\n min={1}\n max={MAX_COUNT}\n aria-label={labels.itemCount}\n value={item.count ?? 1}\n onChange={(e) => {\n const n = Math.max(1, Math.min(MAX_COUNT, Math.floor(Number(e.target.value) || 1)))\n setItem(item.id, { count: n > 1 ? n : undefined })\n }}\n />\n <span>{labels.itemCount}</span>\n </label>\n <span className=\"sk-edit-item__moves\">\n <button type=\"button\" className=\"sk-icon-btn\" aria-label={labels.moveUp(item.title)} disabled={i === 0} onClick={() => moveItem(i, i - 1)}>\n ↑\n </button>\n <button type=\"button\" className=\"sk-icon-btn\" aria-label={labels.moveDown(item.title)} disabled={i === gate.items.length - 1} onClick={() => moveItem(i, i + 1)}>\n ↓\n </button>\n <button\n type=\"button\"\n className=\"sk-icon-btn sk-icon-btn--danger\"\n aria-label={labels.removeItem(item.title)}\n onClick={() => onChange((g) => ({ ...g, items: g.items.filter((x) => x.id !== item.id) }))}\n >\n ×\n </button>\n </span>\n </span>\n </li>\n ))}\n </ul>\n\n <form\n className=\"sk-add-item\"\n onSubmit={(e) => {\n e.preventDefault()\n addText()\n }}\n >\n <input className=\"sk-input sk-grow\" aria-label={labels.addItem} placeholder={labels.addItemPlaceholder} value={text} onChange={(e) => setText(e.target.value)} />\n <button type=\"submit\" className=\"sk-btn\" disabled={!text.trim()}>\n {labels.addItem}\n </button>\n </form>\n {canPick ? (\n <button type=\"button\" className=\"sk-btn sk-btn--ghost sk-pick\" onClick={onPick}>\n + {labels.pickTarget}\n </button>\n ) : null}\n\n {gate.reward && gate.reward.type !== 'message' ? (\n <p className=\"sk-reward-chip\">\n {labels.rewardOther(gate.reward.type)}\n <button type=\"button\" className=\"sk-icon-btn sk-icon-btn--danger\" aria-label={labels.removeReward} onClick={() => onChange(({ reward: _r, ...g }) => g)}>\n ×\n </button>\n </p>\n ) : (\n <label className=\"sk-field\">\n <span className=\"sk-field__label\">{labels.rewardMessage}</span>\n <textarea\n className=\"sk-input\"\n rows={2}\n value={message}\n onChange={(e) => {\n const t = e.target.value\n onChange(({ reward: _r, ...g }) => (t ? { ...g, reward: { type: 'message', text: t } } : g))\n }}\n />\n </label>\n )}\n </section>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,WAAW,oBAA6D;AACjF,SAAS,SAAS,gBAAgB;AA4D5B,SAC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C,qBAAC,YAAO,MAAK,UAAS,WAAU,gCAA+B,SAAS,QAAQ;AAAA;AAAA,MAC3E,OAAO;AAAA,OACZ,IACE;AAAA,IAEH,KAAK,UAAU,KAAK,OAAO,SAAS,YACnC,qBAAC,OAAE,WAAU,kBACV;AAAA,aAAO,YAAY,KAAK,OAAO,IAAI;AAAA,MACpC,oBAAC,YAAO,MAAK,UAAS,WAAU,mCAAkC,cAAY,OAAO,cAAc,SAAS,MAAM,SAAS,CAAC,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,CAAC,GAAG,kBAEzJ;AAAA,OACF,IAEA,qBAAC,WAAM,WAAU,YACf;AAAA,0BAAC,UAAK,WAAU,mBAAmB,iBAAO,eAAc;AAAA,MACxD;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,MAAM;AAAA,UACN,OAAO;AAAA,UACP,UAAU,CAAC,MAAM;AACf,kBAAM,IAAI,EAAE,OAAO;AACnB,qBAAS,CAAC,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAO,IAAI,EAAE,GAAG,GAAG,QAAQ,EAAE,MAAM,WAAW,MAAM,EAAE,EAAE,IAAI,CAAE;AAAA,UAC7F;AAAA;AAAA,MACF;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
@@ -0,0 +1,53 @@
1
+ import { C as ClearEvent } from './types-DxLG2LO0.js';
2
+ export { A as Activity, a as Changes, b as CheckItem, c as Clear, d as Course, G as Gate, I as ItemProgress, R as RewardRef, e as Route, S as SekishoData, T as TargetRef } from './types-DxLG2LO0.js';
3
+ export { CourseView, GateView, ImportResult, ItemView, SekishoFile, addGate, addItem, addOne, applyChanges, checkItem, clearId, deleteCourse, duplicateCourse, exportCourses, importCourses, isGateOpen, itemGoal, moveGate, moveItem, newCourse, newGate, newItem, newerProgress, parseCourses, progressId, readCourse, removeGate, removeItem, removeOne, report, sameTarget, settleClears, toggleItem, uncheckItem, updateCourse, updateGate, updateItem, viewCourse } from './core/index.js';
4
+ import { R as RewardConnector, S as StampRenderProps, L as Labels } from './Sekisho-Bmo9R4cU.js';
5
+ export { C as CourseEditorProps, D as DEFAULT_STAMP_COLOR, E as EN_LABELS, J as JA_LABELS, a as RewardRenderProps, b as Sekisho, c as SekishoProps, T as TargetAdapter, s as stampOf } from './Sekisho-Bmo9R4cU.js';
6
+ import * as react from 'react';
7
+ import { ReactNode } from 'react';
8
+
9
+ /** 部品に入っているご褒美: ひみつの一言({ type: 'message', text: '…' }) */
10
+ declare const messageReward: RewardConnector;
11
+ interface CelebrationProps {
12
+ /** 見せるクリアの知らせ(古いものから)。空なら何も出さない */
13
+ events: ClearEvent[];
14
+ /** 全部見せ終えたとき(閉じたとき)。アプリは events を空にする */
15
+ onDone: () => void;
16
+ /** ご褒美のコネクタ(部品に入っている message に足す・差し替える) */
17
+ rewards?: RewardConnector[];
18
+ /** スタンプの演出を差し替える */
19
+ renderStamp?: (props: StampRenderProps) => ReactNode;
20
+ /** 演出を減らす。無ければ端末の設定(prefers-reduced-motion)に従う */
21
+ reducedMotion?: boolean;
22
+ /** 音を出さない(コネクタに渡す)。既定は true */
23
+ muted?: boolean;
24
+ labels?: Partial<Labels>;
25
+ theme?: 'light' | 'dark' | 'system';
26
+ className?: string;
27
+ }
28
+ /**
29
+ * クリアの演出。知らせ 1 つにつき「スタンプ → ご褒美(あれば)」の順に見せる。
30
+ * 画面いっぱいに重ねて出す。<Sekisho> の中でも使っているが、自動のチェック(report)の知らせを
31
+ * 練習の画面の上で見せたいときは、アプリがこれを置く
32
+ */
33
+ declare function Celebration({ events, onDone, rewards, renderStamp, reducedMotion: forceReduced, muted, labels: labelsPatch, theme, className, }: CelebrationProps): react.JSX.Element | null;
34
+
35
+ /**
36
+ * 丸い印(スタンプ)。押した印・まだの印(点線の丸)・鍵のかかった印。
37
+ * 色は朱肉のように、少しかすれた二重の丸で描く
38
+ */
39
+ declare function Stamp({ text, color, state, size, tilt, label, }: {
40
+ text: string;
41
+ color: string;
42
+ state?: 'pressed' | 'empty' | 'locked';
43
+ size?: number;
44
+ /** 傾き(度)。押した印だけ */
45
+ tilt?: number;
46
+ /** 読み上げ用の名前 */
47
+ label?: string;
48
+ }): react.JSX.Element;
49
+ /** 端末の「視差効果を減らす」(prefers-reduced-motion)に合わせる。force を渡せば、それに従う */
50
+ declare function useReducedMotion(force?: boolean): boolean;
51
+
52
+ export { Celebration, ClearEvent, Labels, RewardConnector, Stamp, StampRenderProps, messageReward, useReducedMotion };
53
+ export type { CelebrationProps };
package/dist/index.js ADDED
@@ -0,0 +1,516 @@
1
+ 'use client'
2
+ import {
3
+ addOne,
4
+ applyChanges,
5
+ checkItem,
6
+ clearId,
7
+ deleteCourse,
8
+ exportCourses,
9
+ importCourses,
10
+ isGateOpen,
11
+ itemGoal,
12
+ newerProgress,
13
+ parseCourses,
14
+ progressId,
15
+ readCourse,
16
+ removeOne,
17
+ report,
18
+ sameTarget,
19
+ settleClears,
20
+ toggleItem,
21
+ uncheckItem,
22
+ viewCourse
23
+ } from "./chunk-V2NPSBAT.js";
24
+ import {
25
+ DEFAULT_STAMP_COLOR,
26
+ EN_LABELS,
27
+ JA_LABELS,
28
+ Stamp,
29
+ stampOf,
30
+ useReducedMotion
31
+ } from "./chunk-N6EMSDTH.js";
32
+ import {
33
+ addGate,
34
+ addItem,
35
+ duplicateCourse,
36
+ moveGate,
37
+ moveItem,
38
+ newCourse,
39
+ newGate,
40
+ newItem,
41
+ removeGate,
42
+ removeItem,
43
+ updateCourse,
44
+ updateGate,
45
+ updateItem
46
+ } from "./chunk-IQYSUTRQ.js";
47
+
48
+ // src/ui/Sekisho.tsx
49
+ import { useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
50
+
51
+ // src/ui/Celebration.tsx
52
+ import { useEffect, useMemo, useRef, useState } from "react";
53
+ import { jsx, jsxs } from "react/jsx-runtime";
54
+ var messageReward = {
55
+ type: "message",
56
+ render: ({ reward, done, labels }) => {
57
+ const text = typeof reward.text === "string" ? reward.text : "";
58
+ return /* @__PURE__ */ jsxs("div", { className: "sk-reward-message", children: [
59
+ /* @__PURE__ */ jsx("p", { className: "sk-reward-message__label", children: labels.secretMessage }),
60
+ /* @__PURE__ */ jsx("p", { className: "sk-reward-message__text", children: text }),
61
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sk-btn sk-btn--primary", onClick: done, autoFocus: true, children: labels.next })
62
+ ] });
63
+ }
64
+ };
65
+ var isEmptyMessage = (r) => r.type === "message" && !(typeof r.text === "string" && r.text.trim());
66
+ function Celebration({
67
+ events,
68
+ onDone,
69
+ rewards = [],
70
+ renderStamp,
71
+ reducedMotion: forceReduced,
72
+ muted = true,
73
+ labels: labelsPatch,
74
+ theme = "system",
75
+ className
76
+ }) {
77
+ const labels = useMemo(() => ({ ...JA_LABELS, ...labelsPatch }), [labelsPatch]);
78
+ const reducedMotion = useReducedMotion(forceReduced);
79
+ const connectors = useMemo(() => {
80
+ const m = /* @__PURE__ */ new Map([[messageReward.type, messageReward]]);
81
+ for (const r of rewards) m.set(r.type, r);
82
+ return m;
83
+ }, [rewards]);
84
+ const steps = useMemo(
85
+ () => events.flatMap((event2) => {
86
+ const reward = event2.kind === "gate" ? event2.gate?.reward : event2.course.reward;
87
+ const connector = reward && !isEmptyMessage(reward) ? connectors.get(reward.type) : void 0;
88
+ return connector ? [{ event: event2, part: "stamp" }, { event: event2, part: "reward", connector }] : [{ event: event2, part: "stamp" }];
89
+ }),
90
+ [events, connectors]
91
+ );
92
+ const [index, setIndex] = useState(0);
93
+ const doneRef = useRef(onDone);
94
+ doneRef.current = onDone;
95
+ useEffect(() => setIndex(0), [events]);
96
+ const step = steps[index];
97
+ const next = () => {
98
+ if (index + 1 >= steps.length) doneRef.current();
99
+ else setIndex(index + 1);
100
+ };
101
+ useEffect(() => {
102
+ if (!step) return;
103
+ const onKey = (e) => {
104
+ if (e.key === "Escape") doneRef.current();
105
+ };
106
+ window.addEventListener("keydown", onKey);
107
+ return () => window.removeEventListener("keydown", onKey);
108
+ }, [step]);
109
+ if (!step) return null;
110
+ const { event } = step;
111
+ let body;
112
+ if (step.part === "reward") {
113
+ const reward = event.kind === "gate" ? event.gate?.reward : event.course.reward;
114
+ body = step.connector.render({ reward, event, done: next, reducedMotion, muted, labels });
115
+ } else {
116
+ const stamp = event.gate ? stampOf(event.gate, event.course.color) : { text: "\u5236\u8987", color: event.course.color || "#d9480f" };
117
+ const props = { event, stamp, done: next, reducedMotion, muted, labels };
118
+ body = renderStamp ? renderStamp(props) : /* @__PURE__ */ jsx(DefaultStamp, { ...props });
119
+ }
120
+ return /* @__PURE__ */ jsx(
121
+ "div",
122
+ {
123
+ className: ["sekisho", "sk-celebration", reducedMotion ? "sk-reduced" : "", className ?? ""].filter(Boolean).join(" "),
124
+ "data-theme": theme,
125
+ role: "dialog",
126
+ "aria-modal": "true",
127
+ "aria-label": event.kind === "gate" ? labels.gateClear : labels.courseClear,
128
+ children: /* @__PURE__ */ jsx("div", { className: "sk-celebration__panel", children: body }, index)
129
+ }
130
+ );
131
+ }
132
+ function DefaultStamp({ event, stamp, done, labels }) {
133
+ const course = event.kind === "course";
134
+ return /* @__PURE__ */ jsxs("div", { className: "sk-clear", children: [
135
+ /* @__PURE__ */ jsx("p", { className: "sk-clear__title", "aria-live": "assertive", children: course ? labels.courseClear : labels.gateClear }),
136
+ /* @__PURE__ */ jsx("div", { className: "sk-clear__paper", children: course ? /* @__PURE__ */ jsx("div", { className: "sk-clear__row", children: event.course.gates.map((g, i) => {
137
+ const s = stampOf(g, event.course.color);
138
+ return /* @__PURE__ */ jsx("span", { className: "sk-clear__mini", style: { animationDelay: `${0.15 + i * 0.12}s` }, children: /* @__PURE__ */ jsx(Stamp, { text: s.text, color: s.color, size: 44, tilt: i * 7 % 15 - 7, label: g.title }) }, g.id);
139
+ }) }) : /* @__PURE__ */ jsxs("span", { className: "sk-clear__stamp", children: [
140
+ /* @__PURE__ */ jsx(Stamp, { text: stamp.text, color: stamp.color, size: 140, label: event.gate?.title }),
141
+ /* @__PURE__ */ jsx("span", { className: "sk-clear__splash", style: { borderColor: stamp.color }, "aria-hidden": "true" })
142
+ ] }) }),
143
+ /* @__PURE__ */ jsx("p", { className: "sk-clear__name", children: course ? event.course.title : event.gate?.title }),
144
+ /* @__PURE__ */ jsx("p", { className: "sk-clear__count", children: labels.clearedOf(event.cleared, event.total) }),
145
+ /* @__PURE__ */ jsx("button", { type: "button", className: "sk-btn sk-btn--primary", onClick: done, autoFocus: true, children: labels.next })
146
+ ] });
147
+ }
148
+
149
+ // src/ui/Sekisho.tsx
150
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
151
+ function Sekisho(props) {
152
+ const {
153
+ data,
154
+ onChange,
155
+ now = () => /* @__PURE__ */ new Date(),
156
+ targets,
157
+ rewards,
158
+ renderStamp,
159
+ editor: Editor,
160
+ allowImport = true,
161
+ allowExport = true,
162
+ reducedMotion: forceReduced,
163
+ muted = true,
164
+ theme = "system",
165
+ labels: labelsPatch,
166
+ className
167
+ } = props;
168
+ const labels = useMemo2(() => ({ ...JA_LABELS, ...labelsPatch }), [labelsPatch]);
169
+ const reducedMotion = useReducedMotion(forceReduced);
170
+ const [screen, setScreen] = useState2({ kind: "list" });
171
+ const [events, setEvents] = useState2([]);
172
+ const [notice, setNotice] = useState2("");
173
+ const change = (changes) => {
174
+ if (Object.keys(changes).length === 0) return;
175
+ onChange(changes);
176
+ if (changes.events?.length) setEvents((q) => [...q, ...changes.events]);
177
+ };
178
+ const saveCourse = (course) => {
179
+ const next = applyChanges(data, { courses: [course] });
180
+ const settled = settleClears(next, now(), [course.id]);
181
+ change({ courses: [course], ...settled });
182
+ setScreen({ kind: "course", id: course.id });
183
+ };
184
+ const current = screen.kind === "course" ? data.courses.find((c) => c.id === screen.id) : void 0;
185
+ let body;
186
+ if (screen.kind === "edit" && Editor) {
187
+ body = /* @__PURE__ */ jsx2(
188
+ Editor,
189
+ {
190
+ course: screen.course,
191
+ onSave: saveCourse,
192
+ onCancel: () => setScreen(screen.isNew ? { kind: "list" } : { kind: "course", id: screen.course.id }),
193
+ targets,
194
+ labels: labelsPatch
195
+ }
196
+ );
197
+ } else if (current) {
198
+ body = /* @__PURE__ */ jsx2(
199
+ CoursePage,
200
+ {
201
+ view: viewCourse(data, current),
202
+ labels,
203
+ targets,
204
+ reducedMotion,
205
+ onBack: () => setScreen({ kind: "list" }),
206
+ onToggle: (itemId) => change(toggleItem(data, current.id, itemId, now())),
207
+ onPlus: (itemId) => change(addOne(data, current.id, itemId, now())),
208
+ onMinus: (itemId) => change(removeOne(data, current.id, itemId, now())),
209
+ onEdit: Editor && current.origin === "own" ? () => setScreen({ kind: "edit", course: current, isNew: false }) : void 0,
210
+ onDuplicate: Editor && current.origin === "given" ? () => {
211
+ const copy = duplicateCourse(current, now());
212
+ change({ courses: [copy] });
213
+ setScreen({ kind: "course", id: copy.id });
214
+ } : void 0,
215
+ onExport: allowExport ? () => download(current) : void 0,
216
+ onDelete: () => {
217
+ if (!window.confirm(labels.deleteConfirm(current.title))) return;
218
+ change(deleteCourse(data, current.id));
219
+ setScreen({ kind: "list" });
220
+ }
221
+ }
222
+ );
223
+ } else {
224
+ body = /* @__PURE__ */ jsx2(
225
+ CourseList,
226
+ {
227
+ data,
228
+ labels,
229
+ notice,
230
+ onOpen: (id) => {
231
+ setNotice("");
232
+ setScreen({ kind: "course", id });
233
+ },
234
+ onCreate: Editor ? () => setScreen({ kind: "edit", course: newCourse({ title: "" }, now()), isNew: true }) : void 0,
235
+ onImport: allowImport ? (json) => {
236
+ const { courses, errors } = parseCourses(json, now());
237
+ const r = importCourses(data, courses, now());
238
+ change(r.changes);
239
+ const n = r.added.length + r.updated.length;
240
+ setNotice([n > 0 ? labels.importDone(n) : labels.importNothing, ...errors].join("\n"));
241
+ } : void 0
242
+ }
243
+ );
244
+ }
245
+ return /* @__PURE__ */ jsxs2("div", { className: ["sekisho", reducedMotion ? "sk-reduced" : "", className ?? ""].filter(Boolean).join(" "), "data-theme": theme, children: [
246
+ body,
247
+ /* @__PURE__ */ jsx2(
248
+ Celebration,
249
+ {
250
+ events,
251
+ onDone: () => setEvents([]),
252
+ rewards,
253
+ renderStamp,
254
+ reducedMotion,
255
+ muted,
256
+ labels: labelsPatch,
257
+ theme
258
+ }
259
+ )
260
+ ] });
261
+ }
262
+ function download(course) {
263
+ const blob = new Blob([JSON.stringify(exportCourses([course]), null, 2)], { type: "application/json" });
264
+ const url = URL.createObjectURL(blob);
265
+ const a = document.createElement("a");
266
+ a.href = url;
267
+ a.download = `${course.title.replace(/[\\/:*?"<>|]/g, "_") || "course"}.sekisho.json`;
268
+ a.click();
269
+ setTimeout(() => URL.revokeObjectURL(url), 1e3);
270
+ }
271
+ function CourseList({
272
+ data,
273
+ labels,
274
+ notice,
275
+ onOpen,
276
+ onCreate,
277
+ onImport
278
+ }) {
279
+ const fileRef = useRef2(null);
280
+ const views = data.courses.map((c) => viewCourse(data, c));
281
+ return /* @__PURE__ */ jsxs2("div", { className: "sk-list", children: [
282
+ /* @__PURE__ */ jsxs2("div", { className: "sk-toolbar", children: [
283
+ /* @__PURE__ */ jsx2("h2", { className: "sk-h2", children: labels.courses }),
284
+ /* @__PURE__ */ jsxs2("div", { className: "sk-toolbar__actions", children: [
285
+ onImport ? /* @__PURE__ */ jsxs2(Fragment, { children: [
286
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-btn", onClick: () => fileRef.current?.click(), children: labels.importCourses }),
287
+ /* @__PURE__ */ jsx2(
288
+ "input",
289
+ {
290
+ ref: fileRef,
291
+ type: "file",
292
+ accept: ".json,application/json",
293
+ hidden: true,
294
+ onChange: async (e) => {
295
+ const file = e.target.files?.[0];
296
+ e.target.value = "";
297
+ if (!file) return;
298
+ try {
299
+ onImport(JSON.parse(await file.text()));
300
+ } catch {
301
+ onImport(null);
302
+ }
303
+ }
304
+ }
305
+ )
306
+ ] }) : null,
307
+ onCreate ? /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-btn sk-btn--primary", onClick: onCreate, children: labels.createCourse }) : null
308
+ ] })
309
+ ] }),
310
+ notice ? /* @__PURE__ */ jsx2("p", { className: "sk-notice", role: "status", children: notice }) : null,
311
+ views.length === 0 ? /* @__PURE__ */ jsx2("p", { className: "sk-empty", children: labels.noCourses }) : null,
312
+ /* @__PURE__ */ jsx2("ul", { className: "sk-cards", children: views.map((v) => /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsxs2("button", { type: "button", className: "sk-card sk-card--button", onClick: () => onOpen(v.course.id), children: [
313
+ /* @__PURE__ */ jsxs2("span", { className: "sk-card__head", children: [
314
+ /* @__PURE__ */ jsx2("span", { className: "sk-card__title", children: v.course.title }),
315
+ /* @__PURE__ */ jsx2("span", { className: "sk-tag", children: v.course.origin === "given" ? labels.given : labels.own })
316
+ ] }),
317
+ /* @__PURE__ */ jsx2(MiniPassport, { view: v }),
318
+ /* @__PURE__ */ jsx2("span", { className: "sk-meter", "aria-hidden": "true", children: /* @__PURE__ */ jsx2("span", { style: { width: `${v.total ? v.cleared / v.total * 100 : 0}%` } }) }),
319
+ /* @__PURE__ */ jsxs2("span", { className: "sk-card__meta", children: [
320
+ labels.clearedOf(v.cleared, v.total),
321
+ v.complete ? ` \u30FB ${labels.courseCleared}` : ""
322
+ ] })
323
+ ] }) }, v.course.id)) })
324
+ ] });
325
+ }
326
+ function MiniPassport({ view }) {
327
+ if (view.gates.length === 0) return null;
328
+ return /* @__PURE__ */ jsx2("span", { className: "sk-mini-passport", "aria-hidden": "true", children: view.gates.map((g, i) => {
329
+ const s = stampOf(g.gate, view.course.color);
330
+ return /* @__PURE__ */ jsx2(Stamp, { text: s.text, color: s.color, size: 26, tilt: i * 7 % 15 - 7, state: g.cleared ? "pressed" : "empty" }, g.gate.id);
331
+ }) });
332
+ }
333
+ function CoursePage({
334
+ view,
335
+ labels,
336
+ targets,
337
+ reducedMotion,
338
+ onBack,
339
+ onToggle,
340
+ onPlus,
341
+ onMinus,
342
+ onEdit,
343
+ onDuplicate,
344
+ onExport,
345
+ onDelete
346
+ }) {
347
+ const { course } = view;
348
+ return /* @__PURE__ */ jsxs2("div", { className: "sk-course", children: [
349
+ /* @__PURE__ */ jsxs2("div", { className: "sk-toolbar", children: [
350
+ /* @__PURE__ */ jsxs2("button", { type: "button", className: "sk-btn sk-btn--ghost", onClick: onBack, children: [
351
+ "\u2190 ",
352
+ labels.back
353
+ ] }),
354
+ /* @__PURE__ */ jsxs2("div", { className: "sk-toolbar__actions", children: [
355
+ onEdit ? /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-btn", onClick: onEdit, children: labels.editCourse }) : null,
356
+ onDuplicate ? /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-btn", onClick: onDuplicate, children: labels.duplicateCourse }) : null,
357
+ onExport ? /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-btn", onClick: onExport, children: labels.exportCourse }) : null
358
+ ] })
359
+ ] }),
360
+ /* @__PURE__ */ jsxs2("header", { className: "sk-course__head", children: [
361
+ /* @__PURE__ */ jsx2("h2", { className: "sk-h2", children: course.title }),
362
+ course.description ? /* @__PURE__ */ jsx2("p", { className: "sk-course__desc", children: course.description }) : null,
363
+ /* @__PURE__ */ jsxs2("p", { className: "sk-course__meta", children: [
364
+ /* @__PURE__ */ jsx2("span", { className: "sk-tag", children: course.origin === "given" ? labels.given : labels.own }),
365
+ /* @__PURE__ */ jsx2("span", { className: "sk-tag", children: (course.route ?? "free") === "ordered" ? labels.routeOrdered : labels.routeFree }),
366
+ /* @__PURE__ */ jsx2("span", { children: labels.clearedOf(view.cleared, view.total) }),
367
+ view.complete ? /* @__PURE__ */ jsx2("span", { className: "sk-tag sk-tag--done", children: labels.courseCleared }) : null
368
+ ] })
369
+ ] }),
370
+ view.gates.length > 0 ? /* @__PURE__ */ jsxs2("section", { className: "sk-passport", "aria-label": labels.passport, children: [
371
+ /* @__PURE__ */ jsx2("h3", { className: "sk-passport__title", children: labels.passport }),
372
+ /* @__PURE__ */ jsx2("ol", { className: "sk-passport__grid", children: view.gates.map((g, i) => {
373
+ const s = stampOf(g.gate, course.color);
374
+ return /* @__PURE__ */ jsxs2("li", { className: "sk-passport__cell", children: [
375
+ /* @__PURE__ */ jsx2(
376
+ Stamp,
377
+ {
378
+ text: s.text,
379
+ color: s.color,
380
+ size: 60,
381
+ tilt: i * 7 % 15 - 7,
382
+ state: g.cleared ? "pressed" : g.open ? "empty" : "locked",
383
+ label: `${g.gate.title}: ${g.cleared ? labels.cleared : g.open ? `${g.done} / ${g.total}` : labels.locked}`
384
+ }
385
+ ),
386
+ /* @__PURE__ */ jsx2("span", { className: "sk-passport__name", children: g.gate.title })
387
+ ] }, g.gate.id);
388
+ }) })
389
+ ] }) : null,
390
+ /* @__PURE__ */ jsx2("ol", { className: "sk-gates", children: view.gates.map((g) => /* @__PURE__ */ jsx2(
391
+ GateCard,
392
+ {
393
+ gate: g,
394
+ courseColor: course.color,
395
+ labels,
396
+ targets,
397
+ reducedMotion,
398
+ onToggle,
399
+ onPlus,
400
+ onMinus
401
+ },
402
+ g.gate.id
403
+ )) }),
404
+ /* @__PURE__ */ jsx2("div", { className: "sk-danger-zone", children: /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-btn sk-btn--danger", onClick: onDelete, children: labels.deleteCourse }) })
405
+ ] });
406
+ }
407
+ function GateCard({
408
+ gate: g,
409
+ courseColor,
410
+ labels,
411
+ targets,
412
+ onToggle,
413
+ onPlus,
414
+ onMinus
415
+ }) {
416
+ const s = stampOf(g.gate, courseColor);
417
+ return /* @__PURE__ */ jsxs2("li", { className: ["sk-card", "sk-gate", g.open ? "" : "sk-gate--locked", g.cleared ? "sk-gate--cleared" : ""].filter(Boolean).join(" "), children: [
418
+ /* @__PURE__ */ jsxs2("div", { className: "sk-gate__head", children: [
419
+ /* @__PURE__ */ jsx2(Stamp, { text: s.text, color: s.color, size: 40, state: g.cleared ? "pressed" : g.open ? "empty" : "locked" }),
420
+ /* @__PURE__ */ jsxs2("div", { className: "sk-gate__titles", children: [
421
+ /* @__PURE__ */ jsx2("h3", { className: "sk-gate__title", children: g.gate.title }),
422
+ g.gate.description ? /* @__PURE__ */ jsx2("p", { className: "sk-gate__desc", children: g.gate.description }) : null
423
+ ] }),
424
+ /* @__PURE__ */ jsx2("span", { className: "sk-gate__count", children: g.open ? g.cleared && !g.complete ? labels.cleared : `${g.done} / ${g.total}` : `\u{1F512} ${labels.locked}` })
425
+ ] }),
426
+ g.items.length === 0 ? /* @__PURE__ */ jsx2("p", { className: "sk-empty", children: labels.emptyGate }) : null,
427
+ /* @__PURE__ */ jsx2("ul", { className: "sk-items", children: g.items.map((v) => /* @__PURE__ */ jsx2(ItemRow, { view: v, disabled: !g.open, labels, targets, onToggle, onPlus, onMinus }, v.item.id)) })
428
+ ] });
429
+ }
430
+ function ItemRow({
431
+ view: v,
432
+ disabled,
433
+ labels,
434
+ targets,
435
+ onToggle,
436
+ onPlus,
437
+ onMinus
438
+ }) {
439
+ const { item } = v;
440
+ const target = item.target;
441
+ const canOpen = !!target && !!targets?.open && (targets.canOpen?.(target) ?? true);
442
+ return /* @__PURE__ */ jsxs2("li", { className: ["sk-item", v.complete ? "sk-item--done" : ""].filter(Boolean).join(" "), children: [
443
+ /* @__PURE__ */ jsx2(
444
+ "button",
445
+ {
446
+ type: "button",
447
+ className: "sk-check",
448
+ role: "checkbox",
449
+ "aria-checked": v.complete,
450
+ "aria-label": v.complete ? labels.uncheck(item.title) : labels.check(item.title),
451
+ disabled,
452
+ onClick: () => onToggle(item.id),
453
+ children: v.complete ? /* @__PURE__ */ jsx2("svg", { viewBox: "0 0 20 20", width: "14", height: "14", "aria-hidden": "true", children: /* @__PURE__ */ jsx2("path", { d: "M4 10.5l4 4 8-9", fill: "none", stroke: "currentColor", strokeWidth: "2.6", strokeLinecap: "round", strokeLinejoin: "round" }) }) : null
454
+ }
455
+ ),
456
+ /* @__PURE__ */ jsxs2("span", { className: "sk-item__body", children: [
457
+ target && targets?.renderBadge ? /* @__PURE__ */ jsx2("span", { className: "sk-item__badge", children: targets.renderBadge(target, item) }) : null,
458
+ canOpen ? /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-item__title sk-item__title--link", "aria-label": labels.open(item.title), onClick: () => targets.open(target, item), children: item.title }) : /* @__PURE__ */ jsx2("span", { className: "sk-item__title", children: item.title }),
459
+ item.note ? /* @__PURE__ */ jsx2("span", { className: "sk-item__note", children: item.note }) : null
460
+ ] }),
461
+ v.goal > 1 ? /* @__PURE__ */ jsxs2("span", { className: "sk-counter", children: [
462
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-counter__btn", "aria-label": labels.minusOne(item.title), disabled: disabled || v.done === 0, onClick: () => onMinus(item.id), children: "\u2212" }),
463
+ /* @__PURE__ */ jsxs2("span", { className: "sk-counter__value", "aria-live": "polite", children: [
464
+ v.done,
465
+ " / ",
466
+ v.goal
467
+ ] }),
468
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "sk-counter__btn sk-counter__btn--plus", "aria-label": labels.plusOne(item.title), disabled: disabled || v.complete, onClick: () => onPlus(item.id), children: "\uFF0B" })
469
+ ] }) : null
470
+ ] });
471
+ }
472
+ export {
473
+ Celebration,
474
+ DEFAULT_STAMP_COLOR,
475
+ EN_LABELS,
476
+ JA_LABELS,
477
+ Sekisho,
478
+ Stamp,
479
+ addGate,
480
+ addItem,
481
+ addOne,
482
+ applyChanges,
483
+ checkItem,
484
+ clearId,
485
+ deleteCourse,
486
+ duplicateCourse,
487
+ exportCourses,
488
+ importCourses,
489
+ isGateOpen,
490
+ itemGoal,
491
+ messageReward,
492
+ moveGate,
493
+ moveItem,
494
+ newCourse,
495
+ newGate,
496
+ newItem,
497
+ newerProgress,
498
+ parseCourses,
499
+ progressId,
500
+ readCourse,
501
+ removeGate,
502
+ removeItem,
503
+ removeOne,
504
+ report,
505
+ sameTarget,
506
+ settleClears,
507
+ stampOf,
508
+ toggleItem,
509
+ uncheckItem,
510
+ updateCourse,
511
+ updateGate,
512
+ updateItem,
513
+ useReducedMotion,
514
+ viewCourse
515
+ };
516
+ //# sourceMappingURL=index.js.map