@shiodome47/planner 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/dist/core.js ADDED
@@ -0,0 +1,790 @@
1
+ // src/core/types.ts
2
+ var e = [
3
+ "today",
4
+ "week",
5
+ "month",
6
+ "year",
7
+ "life"
8
+ ], t = [
9
+ "A",
10
+ "B",
11
+ "C",
12
+ "D",
13
+ "P"
14
+ ];
15
+ // src/core/period.ts
16
+ function n(e) {
17
+ return `${e.getFullYear()}-${g(e.getMonth() + 1)}-${g(e.getDate())}`;
18
+ }
19
+ function r(e) {
20
+ return n(i(e));
21
+ }
22
+ function i(e) {
23
+ let t = new Date(e.getFullYear(), e.getMonth(), e.getDate()), n = (t.getDay() + 6) % 7;
24
+ return t.setDate(t.getDate() - n), t;
25
+ }
26
+ function a(e) {
27
+ return `${e.getFullYear()}-${g(e.getMonth() + 1)}`;
28
+ }
29
+ function o(e) {
30
+ return String(e.getFullYear());
31
+ }
32
+ function s(e, t) {
33
+ switch (e) {
34
+ case "day": return n(t);
35
+ case "week": return r(t);
36
+ case "month": return a(t);
37
+ case "year": return o(t);
38
+ }
39
+ }
40
+ var c = {
41
+ today: "day",
42
+ week: "week",
43
+ month: "month",
44
+ year: "year",
45
+ life: "year"
46
+ }, l = {
47
+ today: "day",
48
+ week: "week",
49
+ month: "month",
50
+ year: "year"
51
+ };
52
+ function u(e, t) {
53
+ let n = new Date(e.getFullYear(), e.getMonth(), e.getDate());
54
+ return n.setDate(n.getDate() + t), n;
55
+ }
56
+ function d(e, t, n) {
57
+ if (!t) return !1;
58
+ let r = new Date(t);
59
+ return !Number.isNaN(r.getTime()) && s(e, r) === s(e, n);
60
+ }
61
+ var f = [
62
+ "日",
63
+ "月",
64
+ "火",
65
+ "水",
66
+ "木",
67
+ "金",
68
+ "土"
69
+ ];
70
+ function p(e, t) {
71
+ switch (e) {
72
+ case "today": return `${t.getMonth() + 1}/${t.getDate()}(${f[t.getDay()]})`;
73
+ case "week": {
74
+ let e = i(t), n = u(e, 6);
75
+ return `${e.getMonth() + 1}/${e.getDate()}〜${n.getMonth() + 1}/${n.getDate()}`;
76
+ }
77
+ case "month": return `${t.getMonth() + 1} 月〜`;
78
+ case "year": return `${t.getFullYear()} 年`;
79
+ case "life": return "いつか・ずっと";
80
+ }
81
+ }
82
+ function m(e, t) {
83
+ let [n, r, i] = e.split("-").map(Number);
84
+ return !n || !r || !i ? e : n === t.getFullYear() ? `${r}/${i}` : `${String(n).slice(-2)}/${r}/${i}`;
85
+ }
86
+ function h(e, t) {
87
+ let [n, r, i] = e.split("-").map(Number);
88
+ if (!n || !r || !i) return null;
89
+ let a = new Date(n, r - 1, i), o = new Date(t.getFullYear(), t.getMonth(), t.getDate());
90
+ return Math.round((a.getTime() - o.getTime()) / 864e5);
91
+ }
92
+ function g(e) {
93
+ return String(e).padStart(2, "0");
94
+ }
95
+ function _(e) {
96
+ return e === "day" ? "today" : e === "week" ? "week" : e === "month" ? "month" : "year";
97
+ }
98
+ function v(e) {
99
+ if (e === "end") return "月末";
100
+ if (typeof e == "number") return `${e}日`;
101
+ let t = y(e);
102
+ return t ? `${t.week === "L" ? "最終" : `第${t.week}`}${f[t.weekday]}` : String(e);
103
+ }
104
+ function y(e) {
105
+ let t = typeof e == "string" ? /^w([1-5L])-([0-6])$/.exec(e) : null;
106
+ return t ? {
107
+ week: t[1] === "L" ? "L" : Number(t[1]),
108
+ weekday: Number(t[2])
109
+ } : null;
110
+ }
111
+ function b(e, t) {
112
+ let n = t.getFullYear(), r = t.getMonth(), i = new Date(n, r + 1, 0).getDate();
113
+ if (e === "end") return new Date(n, r, i);
114
+ if (typeof e == "number") return e >= 1 ? new Date(n, r, Math.min(e, i)) : void 0;
115
+ let a = y(e);
116
+ if (!a) return;
117
+ let o = (a.weekday - new Date(n, r, 1).getDay() + 7) % 7 + 1, s = o + Math.floor((i - o) / 7) * 7, c = a.week === "L" ? s : Math.min(o + (a.week - 1) * 7, s);
118
+ return new Date(n, r, c);
119
+ }
120
+ function ee(e, t) {
121
+ let [n, r, i] = e.split("-").map(Number);
122
+ if (!n || !r || !i) return e;
123
+ let a = f[new Date(n, r - 1, i).getDay()];
124
+ return `${m(e, t)}(${a})`;
125
+ }
126
+ function te(e, t) {
127
+ let [n, r, i] = e.split("-").map(Number);
128
+ if (!n || !r || !i) return e;
129
+ let a = h(e, t) ?? 0;
130
+ return a > 330 || a < -330 ? `${String(n).slice(-2)}/${r}/${i}` : `${r}/${i}`;
131
+ }
132
+ // src/core/when.ts
133
+ var ne = [
134
+ "日",
135
+ "月",
136
+ "火",
137
+ "水",
138
+ "木",
139
+ "金",
140
+ "土"
141
+ ];
142
+ function x(e) {
143
+ let t = e ? /^(\d{1,2})(?:-(\d{1,2}))?$/.exec(e) : null;
144
+ if (!t) return null;
145
+ let n = Number(t[1]), r = t[2] ? Number(t[2]) : void 0;
146
+ return n < 1 || n > 12 || r !== void 0 && (r < 1 || r > 31) ? null : {
147
+ month: n,
148
+ ...r ? { day: r } : {}
149
+ };
150
+ }
151
+ function S(e) {
152
+ return e.period === "month" ? !!e.day : e.period === "week" ? e.weekday !== void 0 && e.weekday >= 0 && e.weekday <= 6 : e.period === "year" && !!x(e.yearDay);
153
+ }
154
+ function re(e) {
155
+ if (!S(e)) return;
156
+ if (e.period === "month") return v(e.day);
157
+ if (e.period === "week") return `${ne[e.weekday]}曜`;
158
+ let t = x(e.yearDay);
159
+ return t.day ? `${t.month}/${t.day}` : `${t.month}月`;
160
+ }
161
+ function C(e, t) {
162
+ if (!S(e)) return;
163
+ if (e.period === "month") return b(e.day, t);
164
+ if (e.period === "week") return u(i(t), (e.weekday + 6) % 7);
165
+ let n = x(e.yearDay), r = new Date(t.getFullYear(), n.month, 0).getDate();
166
+ return new Date(t.getFullYear(), n.month - 1, Math.min(n.day ?? 1, r));
167
+ }
168
+ function w(e, t, r) {
169
+ if (!S(e) || e.period === "day" || d(e.period, e.checkedAt, r)) return;
170
+ let a = C(e, r);
171
+ if (!a) return;
172
+ let o = e.period === "year" && !x(e.yearDay).day;
173
+ if (t === "today") return !o && n(a) <= n(r) ? a : void 0;
174
+ if (t === "week") {
175
+ if (e.period === "week" || o) return;
176
+ if (e.period === "month") return ie(e, r);
177
+ let t = i(r);
178
+ return n(a) >= n(t) && n(a) <= n(u(t, 6)) ? a : void 0;
179
+ }
180
+ if (t === "month") return e.period === "year" && a.getMonth() === r.getMonth() ? a : void 0;
181
+ }
182
+ function ie(e, t) {
183
+ let r = i(t), a = u(r, 6);
184
+ for (let t of [r, a]) {
185
+ let i = b(e.day, t);
186
+ if (i && n(i) >= n(r) && n(i) <= n(a)) return i;
187
+ }
188
+ }
189
+ function ae(e, t) {
190
+ let { weekday: n, yearDay: r, ...i } = e, a = (/* @__PURE__ */ new Date()).toISOString();
191
+ return e.period === "week" ? {
192
+ ...i,
193
+ ...e.yearDay ? { yearDay: e.yearDay } : {},
194
+ ...typeof t == "number" ? { weekday: t } : {},
195
+ updatedAt: a
196
+ } : e.period === "year" ? {
197
+ ...i,
198
+ ...e.weekday === void 0 ? {} : { weekday: e.weekday },
199
+ ...typeof t == "string" && x(t) ? { yearDay: t } : {},
200
+ updatedAt: a
201
+ } : e;
202
+ }
203
+ function oe(e) {
204
+ return e.period === "year" && !!x(e.yearDay) && !x(e.yearDay).day;
205
+ }
206
+ // src/core/logic.ts
207
+ var T = {
208
+ today: 0,
209
+ week: 1,
210
+ month: 2,
211
+ year: 3,
212
+ life: 4
213
+ };
214
+ function E(e, t) {
215
+ if (e === "today") return n(t);
216
+ if (e === "tomorrow") return n(u(t, 1));
217
+ if (e === "nextweek") return s("week", u(t, 7));
218
+ if (e === "week") return s("week", t);
219
+ if (e === "month") return s("month", t);
220
+ }
221
+ function se(e, t) {
222
+ if (e === "today") return n(t);
223
+ if (e === "week") return s("week", t);
224
+ if (e === "month") return s("month", t);
225
+ }
226
+ function D(e, t) {
227
+ if (!(e.parentId || e.habitId) || !e.placedFor) return !1;
228
+ let n = se(e.horizon, t);
229
+ return n !== void 0 && e.placedFor < n;
230
+ }
231
+ function O(e, t) {
232
+ return j(e) ? k(e.due, t) : !M(e) && e.horizon === "week" && !!e.placedFor && e.placedFor > s("week", t);
233
+ }
234
+ function k(e, t) {
235
+ let r = u(i(t), 7);
236
+ return e >= n(r) && e <= n(u(r, 6));
237
+ }
238
+ function A(e, t) {
239
+ return j(e) ? h(e.due, t) === 1 : e.horizon === "today" && !!e.placedFor && e.placedFor > n(t);
240
+ }
241
+ function j(e) {
242
+ return !!e.due && !e.parentId && !e.habitId;
243
+ }
244
+ function M(e) {
245
+ return !!e.projectId && !e.parentId;
246
+ }
247
+ function N(e, t) {
248
+ let r = h(e, t);
249
+ return r === null ? "life" : r <= 1 ? "today" : e <= n(u(i(t), 13)) ? "week" : r <= 92 ? "month" : r <= 366 ? "year" : "life";
250
+ }
251
+ function P(e, t) {
252
+ return j(e) ? N(e.due, t) : M(e) ? "pool" : e.horizon;
253
+ }
254
+ function ce(e, t) {
255
+ if (!e.doneAt) return !0;
256
+ let n = P(e, t);
257
+ return n === "pool" || d(c[n], e.doneAt, t);
258
+ }
259
+ function F(e, t) {
260
+ return !D(e, t) && ce(e, t);
261
+ }
262
+ function I(e, t, n) {
263
+ return t.find((t) => t.parentId === e.id && !D(t, n));
264
+ }
265
+ function L(t) {
266
+ if (t === "pool") return [...e];
267
+ if (t === "today") return [];
268
+ let n = T[t];
269
+ return e.filter((e) => T[e] < n).flatMap((e) => e === "today" ? ["today", "tomorrow"] : e === "week" ? ["week", "nextweek"] : [e]);
270
+ }
271
+ function le(e) {
272
+ return L(e).filter((e) => e !== "tomorrow" && e !== "nextweek").at(-1);
273
+ }
274
+ function R(e) {
275
+ let n = [];
276
+ for (let r of t) e.filter((e) => e.priority === r).sort(z).forEach((e, t) => n.push({
277
+ task: e,
278
+ label: `${r}${t + 1}`
279
+ }));
280
+ return n;
281
+ }
282
+ function z(e, t) {
283
+ return e.order - t.order || e.createdAt.localeCompare(t.createdAt);
284
+ }
285
+ function ue(t, n) {
286
+ let r = new Map(t.projects.map((e) => [e.id, e])), i = new Map(t.tasks.map((e) => [e.id, e])), a = new Map(t.habits.map((e) => [e.id, e])), o = (e) => {
287
+ let t = a.get(e);
288
+ return t ? _(t.period) : void 0;
289
+ }, s = (e, a) => {
290
+ let s = I(e, t.tasks, n), c = e.parentId ? i.get(e.parentId) : void 0;
291
+ return {
292
+ task: e,
293
+ horizon: P(e, n),
294
+ label: a,
295
+ done: !!e.doneAt,
296
+ faded: !!s && !e.doneAt,
297
+ placedTo: s ? A(s, n) ? "tomorrow" : O(s, n) ? "nextweek" : s.horizon : void 0,
298
+ from: c ? P(c, n) : e.habitId ? o(e.habitId) : void 0,
299
+ project: e.projectId ? r.get(e.projectId) : void 0
300
+ };
301
+ };
302
+ return e.map((e) => {
303
+ let i = t.tasks.filter((t) => P(t, n) === e && F(t, n)), a = e === "today" ? i.filter((e) => !A(e, n)) : e === "week" ? i.filter((e) => !O(e, n)) : i, o = e === "today" ? i.filter((e) => A(e, n)) : [], c = e === "week" ? i.filter((e) => O(e, n)) : [], u = l[e], f = (e, i, a) => {
304
+ let o = d(e.period, e.checkedAt, n), s = Z(e, t.tasks, n);
305
+ return {
306
+ habit: e,
307
+ checked: o,
308
+ project: e.projectId ? r.get(e.projectId) : void 0,
309
+ faded: !!s && !o && !i,
310
+ placedTo: s && !i ? A(s, n) ? "tomorrow" : O(s, n) ? "nextweek" : s.horizon : void 0,
311
+ auto: i,
312
+ dueDay: a ?? C(e, n)
313
+ };
314
+ }, p = u ? t.habits.filter((e) => e.period === u).sort(z).map((e) => f(e, !1)) : [], m = [];
315
+ for (let r of t.habits.filter((e) => e.period !== u).sort(z)) {
316
+ let t = w(r, e, n);
317
+ t && m.push(f(r, !0, t));
318
+ }
319
+ return {
320
+ horizon: e,
321
+ habitPeriod: u,
322
+ habits: [...p, ...m],
323
+ tasks: R(a).map(({ task: e, label: t }) => s(e, t)),
324
+ tomorrow: R(o).map(({ task: e, label: t }) => s(e, t)),
325
+ nextWeek: R(c).map(({ task: e, label: t }) => s(e, t))
326
+ };
327
+ });
328
+ }
329
+ var B = (e) => e.toISOString();
330
+ function V(e, t, n) {
331
+ let r = e.filter((e) => e.horizon === t && e.priority === n);
332
+ return r.length === 0 ? 0 : Math.max(...r.map((e) => e.order)) + 1;
333
+ }
334
+ function H(e, t, n) {
335
+ let r = B(n);
336
+ return {
337
+ id: crypto.randomUUID(),
338
+ title: t.title,
339
+ horizon: t.horizon,
340
+ priority: t.priority,
341
+ order: V(e.tasks, t.horizon, t.priority),
342
+ ...t.tomorrow ? { placedFor: E("tomorrow", n) } : {},
343
+ ...t.nextWeek ? { placedFor: E("nextweek", n) } : {},
344
+ ...t.projectId ? { projectId: t.projectId } : {},
345
+ ...t.due ? { due: t.due } : {},
346
+ createdAt: r,
347
+ updatedAt: r
348
+ };
349
+ }
350
+ function U(e, t, n, r) {
351
+ let i = B(r), a = n === "tomorrow" ? "today" : n === "nextweek" ? "week" : n, o = I(t, e.tasks, r), s = o && !o.doneAt ? W(e.tasks, o.id, r).concat(o.id) : [];
352
+ return {
353
+ tasks: [{
354
+ id: crypto.randomUUID(),
355
+ title: t.title,
356
+ horizon: a,
357
+ priority: t.priority,
358
+ order: V(e.tasks, a, t.priority),
359
+ parentId: t.id,
360
+ ...E(n, r) ? { placedFor: E(n, r) } : {},
361
+ ...t.projectId ? { projectId: t.projectId } : {},
362
+ ...t.due ? { due: t.due } : {},
363
+ ...t.note ? { note: t.note } : {},
364
+ createdAt: i,
365
+ updatedAt: i
366
+ }],
367
+ deleteTaskIds: s
368
+ };
369
+ }
370
+ function de(e, t, n) {
371
+ return { deleteTaskIds: [t.id, ...W(e.tasks, t.id, n)] };
372
+ }
373
+ function fe(e, t, n, r) {
374
+ if (t.horizon === n) return {};
375
+ let { placedFor: i, ...a } = t;
376
+ return { tasks: [{
377
+ ...a,
378
+ horizon: n,
379
+ order: V(e.tasks, n, t.priority),
380
+ updatedAt: B(r)
381
+ }] };
382
+ }
383
+ function W(e, t, n) {
384
+ let r = [];
385
+ for (let i of e) i.parentId === t && !D(i, n) && r.push(i.id, ...W(e, i.id, n));
386
+ return r;
387
+ }
388
+ function G(e, t, n) {
389
+ let r = new Map(e.tasks.map((e) => [e.id, e])), i = /* @__PURE__ */ new Set([t.id, ...W(e.tasks, t.id, n)]);
390
+ for (let e = t.parentId ? r.get(t.parentId) : void 0; e; e = e.parentId ? r.get(e.parentId) : void 0) i.add(e.id);
391
+ let a = B(n), o = !t.doneAt, s = [...i].map((e) => r.get(e)).filter((e) => !!e).map((e) => {
392
+ let { doneAt: t, ...n } = e;
393
+ return o ? {
394
+ ...n,
395
+ doneAt: e.doneAt ?? a,
396
+ updatedAt: a
397
+ } : {
398
+ ...n,
399
+ updatedAt: a
400
+ };
401
+ }), c = t.habitId ? e.habits.find((e) => e.id === t.habitId) : void 0;
402
+ return c && d(c.period, c.checkedAt, n) !== o ? {
403
+ tasks: s,
404
+ habits: [K(c, n)]
405
+ } : { tasks: s };
406
+ }
407
+ function pe(e, t, n, r) {
408
+ let i = e.tasks.filter((e) => e.horizon === t.horizon && e.priority === t.priority && F(e, r) && A(e, r) === A(t, r)).sort(z), a = i.findIndex((e) => e.id === t.id), o = a + n;
409
+ if (a < 0 || o < 0 || o >= i.length) return {};
410
+ let s = B(r), c = [...i];
411
+ [c[a], c[o]] = [c[o], c[a]];
412
+ let l = new Map(i.map((e) => [e.id, e.order]));
413
+ return { tasks: c.map((e, t) => ({
414
+ ...e,
415
+ order: t,
416
+ updatedAt: s
417
+ })).filter((e) => l.get(e.id) !== e.order) };
418
+ }
419
+ function me(e, t, n, r) {
420
+ return t.priority === n ? {} : { tasks: [{
421
+ ...t,
422
+ priority: n,
423
+ order: V(e.tasks, t.horizon, n),
424
+ updatedAt: B(r)
425
+ }] };
426
+ }
427
+ function he(e, t, n) {
428
+ return { deleteTaskIds: [t.id, ...W(e.tasks, t.id, n)] };
429
+ }
430
+ function ge(e, t, n) {
431
+ let r = e.habits.filter((e) => e.period === t.period), i = B(n);
432
+ return {
433
+ id: crypto.randomUUID(),
434
+ title: t.title,
435
+ period: t.period,
436
+ order: r.length === 0 ? 0 : Math.max(...r.map((e) => e.order)) + 1,
437
+ ...t.projectId ? { projectId: t.projectId } : {},
438
+ createdAt: i,
439
+ updatedAt: i
440
+ };
441
+ }
442
+ function K(e, t) {
443
+ let { checkedAt: r, ...i } = e, a = B(t), o = e.history ?? [];
444
+ if (d(e.period, e.checkedAt, t)) {
445
+ let t = n(new Date(e.checkedAt));
446
+ return {
447
+ ...i,
448
+ history: o.filter((e) => e !== t),
449
+ updatedAt: a
450
+ };
451
+ }
452
+ let s = n(t), c = o.includes(s) ? o : [...o, s].sort().slice(-_e);
453
+ return {
454
+ ...i,
455
+ checkedAt: a,
456
+ history: c,
457
+ updatedAt: a
458
+ };
459
+ }
460
+ var _e = 800;
461
+ function ve(e, t, n) {
462
+ let r = B(n), i = e.projects.filter((e) => e.parentId === t.parentId);
463
+ return {
464
+ id: crypto.randomUUID(),
465
+ name: t.name,
466
+ color: t.color,
467
+ order: i.length === 0 ? 0 : Math.max(...i.map((e) => e.order)) + 1,
468
+ ...t.parentId ? { parentId: t.parentId } : {},
469
+ createdAt: r,
470
+ updatedAt: r
471
+ };
472
+ }
473
+ function q(e, t) {
474
+ return e.projects.filter((e) => e.parentId === t).sort((e, t) => e.order - t.order);
475
+ }
476
+ function ye(e) {
477
+ let t = new Set(e.projects.map((e) => e.id));
478
+ return e.projects.filter((e) => !e.parentId || !t.has(e.parentId)).sort((e, t) => e.order - t.order);
479
+ }
480
+ function be(e, t) {
481
+ let n = /* @__PURE__ */ new Set([t.id, ...q(e, t.id).map((e) => e.id)]);
482
+ return {
483
+ deleteProjectIds: [...n],
484
+ deleteTaskIds: e.tasks.filter((e) => e.projectId && n.has(e.projectId)).map((e) => e.id),
485
+ deleteHabitIds: e.habits.filter((e) => e.projectId && n.has(e.projectId)).map((e) => e.id)
486
+ };
487
+ }
488
+ function J(e, t, n, r) {
489
+ if (n === t.parentId || n === t.id || n && q(e, t.id).length > 0) return {};
490
+ let i = e.projects.filter((e) => e.parentId === n && e.id !== t.id), { parentId: a, ...o } = t;
491
+ return { projects: [{
492
+ ...o,
493
+ ...n ? { parentId: n } : {},
494
+ order: i.length === 0 ? 0 : Math.max(...i.map((e) => e.order)) + 1,
495
+ updatedAt: B(r)
496
+ }] };
497
+ }
498
+ function Y(e, t = [], n = []) {
499
+ let r = new Set(n), i = new Map(t.map((e) => [e.id, e])), a = e.filter((e) => !r.has(e.id)).map((e) => i.get(e.id) ?? e), o = t.filter((t) => !e.some((e) => e.id === t.id) && !r.has(t.id));
500
+ return [...a, ...o];
501
+ }
502
+ function xe(e, t) {
503
+ return {
504
+ ...e,
505
+ tasks: Y(e.tasks, t.tasks, t.deleteTaskIds),
506
+ habits: Y(e.habits, t.habits, t.deleteHabitIds),
507
+ projects: Y(e.projects, t.projects, t.deleteProjectIds)
508
+ };
509
+ }
510
+ function X(e, t, n) {
511
+ let r = [...e], [i] = r.splice(t, 1);
512
+ return r.splice(n, 0, i), r;
513
+ }
514
+ function Se(e, n, r, i, a) {
515
+ let o = n.indexOf(r), s = n.indexOf(i);
516
+ if (o < 0 || s < 0 || o === s) return {};
517
+ let c = new Map(e.tasks.map((e) => [e.id, e])), l = c.get(i), u = c.get(r);
518
+ if (!l || !u) return {};
519
+ let d = l.priority, f = X(n, o, s).map((e) => c.get(e)).filter((e) => !!e).map((e) => e.id === r ? {
520
+ ...e,
521
+ priority: d
522
+ } : e), p = B(a), m = [];
523
+ for (let e of t) f.filter((t) => t.priority === e).forEach((e, t) => {
524
+ let n = c.get(e.id);
525
+ (n.order !== t || n.priority !== e.priority) && m.push({
526
+ ...e,
527
+ order: t,
528
+ updatedAt: p
529
+ });
530
+ });
531
+ return { tasks: m };
532
+ }
533
+ function Ce(e, t, n, r, i) {
534
+ let a = t.indexOf(n), o = t.indexOf(r);
535
+ if (a < 0 || o < 0 || a === o) return {};
536
+ let s = new Map(e.habits.map((e) => [e.id, e])), c = B(i);
537
+ return { habits: X(t, a, o).map((e, t) => ({
538
+ habit: s.get(e),
539
+ order: t
540
+ })).filter((e) => !!e.habit && e.habit.order !== e.order).map(({ habit: e, order: t }) => ({
541
+ ...e,
542
+ order: t,
543
+ updatedAt: c
544
+ })) };
545
+ }
546
+ function we(e, t, n, r) {
547
+ let i = e.projects.find((e) => e.id === t), a = [...e.projects].filter((e) => e.parentId === i?.parentId).sort((e, t) => e.order - t.order).map((e) => e.id), o = a.indexOf(t), s = a.indexOf(n);
548
+ if (o < 0 || s < 0 || o === s) return {};
549
+ let c = new Map(e.projects.map((e) => [e.id, e])), l = B(r);
550
+ return { projects: X(a, o, s).map((e, t) => ({
551
+ project: c.get(e),
552
+ order: t
553
+ })).filter(({ project: e, order: t }) => e.order !== t).map(({ project: e, order: t }) => ({
554
+ ...e,
555
+ order: t,
556
+ updatedAt: l
557
+ })) };
558
+ }
559
+ function Z(e, t, n) {
560
+ return t.find((t) => t.habitId === e.id && !D(t, n));
561
+ }
562
+ function Te(e) {
563
+ return L(_(e.period));
564
+ }
565
+ function Ee(e, t, n, r) {
566
+ let i = B(r), a = n === "tomorrow" ? "today" : n === "nextweek" ? "week" : n, o = Z(t, e.tasks, r);
567
+ return {
568
+ tasks: [{
569
+ id: crypto.randomUUID(),
570
+ title: t.title,
571
+ horizon: a,
572
+ priority: "C",
573
+ order: V(e.tasks, a, "C"),
574
+ habitId: t.id,
575
+ ...E(n, r) ? { placedFor: E(n, r) } : {},
576
+ ...t.projectId ? { projectId: t.projectId } : {},
577
+ ...t.note ? { note: t.note } : {},
578
+ createdAt: i,
579
+ updatedAt: i
580
+ }],
581
+ deleteTaskIds: o && !o.doneAt ? [o.id] : []
582
+ };
583
+ }
584
+ function De(e, t, n) {
585
+ let r = K(t, n), i = d(r.period, r.checkedAt, n), a = Z(t, e.tasks, n);
586
+ if (!a || !!a.doneAt === i) return { habits: [r] };
587
+ let o = B(n), { doneAt: s, ...c } = a;
588
+ return {
589
+ habits: [r],
590
+ tasks: [i ? {
591
+ ...c,
592
+ doneAt: o,
593
+ updatedAt: o
594
+ } : {
595
+ ...c,
596
+ updatedAt: o
597
+ }]
598
+ };
599
+ }
600
+ function Oe(e, t, n) {
601
+ let r = H(e, {
602
+ title: t.title,
603
+ horizon: _(t.period),
604
+ priority: "C",
605
+ projectId: t.projectId
606
+ }, n);
607
+ return {
608
+ tasks: [t.note ? {
609
+ ...r,
610
+ note: t.note
611
+ } : r],
612
+ deleteHabitIds: [t.id]
613
+ };
614
+ }
615
+ function ke(e, t) {
616
+ if (e.day) return b(e.day, t);
617
+ }
618
+ function Ae(e, t) {
619
+ let { due: n, ...r } = e, i = (/* @__PURE__ */ new Date()).toISOString();
620
+ return { tasks: [t ? {
621
+ ...r,
622
+ due: t,
623
+ updatedAt: i
624
+ } : {
625
+ ...r,
626
+ updatedAt: i
627
+ }] };
628
+ }
629
+ function je(e, t) {
630
+ let { day: n, ...r } = e;
631
+ return {
632
+ ...r,
633
+ ...t === void 0 ? {} : { day: t },
634
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
635
+ };
636
+ }
637
+ function Me(e, t, r) {
638
+ let i = n(t), a = e.history ?? [], o = B(r), c = s(e.period, t) === s(e.period, r);
639
+ if (a.includes(i)) {
640
+ let { checkedAt: t, ...r } = e, s = a.filter((e) => e !== i);
641
+ return {
642
+ ...e.checkedAt && n(new Date(e.checkedAt)) !== i ? e : r,
643
+ history: s,
644
+ updatedAt: o
645
+ };
646
+ }
647
+ let l = [...a, i].sort().slice(-800), u = i === n(r) ? r : new Date(t.getFullYear(), t.getMonth(), t.getDate(), 12), f = c && !d(e.period, e.checkedAt, r);
648
+ return {
649
+ ...e,
650
+ ...f ? { checkedAt: B(u) } : {},
651
+ history: l,
652
+ updatedAt: o
653
+ };
654
+ }
655
+ function Ne(e, t, r, i) {
656
+ return G(e, t, n(r) === n(i) ? i : new Date(r.getFullYear(), r.getMonth(), r.getDate(), 12));
657
+ }
658
+ function Pe(e, t) {
659
+ let r = B(t), i = n(u(t, 1));
660
+ return j(e) ? { tasks: [{
661
+ ...e,
662
+ due: i,
663
+ updatedAt: r
664
+ }] } : { tasks: [{
665
+ ...e,
666
+ horizon: e.parentId || e.habitId ? e.horizon : "today",
667
+ placedFor: i,
668
+ updatedAt: r
669
+ }] };
670
+ }
671
+ function Fe(e, t) {
672
+ let r = B(t);
673
+ if (j(e)) return { tasks: [{
674
+ ...e,
675
+ due: n(t),
676
+ updatedAt: r
677
+ }] };
678
+ if (e.parentId || e.habitId) return { tasks: [{
679
+ ...e,
680
+ placedFor: n(t),
681
+ updatedAt: r
682
+ }] };
683
+ let { placedFor: i, ...a } = e;
684
+ return { tasks: [{
685
+ ...a,
686
+ horizon: "today",
687
+ updatedAt: r
688
+ }] };
689
+ }
690
+ function Ie(e, t) {
691
+ let n = e.tasks.filter((e) => M(e) && e.projectId === t), r = n.filter((e) => !e.doneAt), i = (e) => e.goalOrder ?? (e.due ? 2 ** 53 - 1 : -(2 ** 53 - 1)), a = [...r].sort((e, t) => i(e) - i(t) || e.createdAt.localeCompare(t.createdAt)), o = r.filter((e) => e.due).sort((e, t) => t.due.localeCompare(e.due) || e.createdAt.localeCompare(t.createdAt)), s = 0;
692
+ return {
693
+ open: a.map((e) => e.due ? o[s++] : e),
694
+ done: n.filter((e) => e.doneAt).sort((e, t) => (t.due ?? "").localeCompare(e.due ?? "") || e.createdAt.localeCompare(t.createdAt))
695
+ };
696
+ }
697
+ function Le(e, t) {
698
+ let n = e.tasks.filter((e) => e.projectId === t && e.goalOrder !== void 0).map((e) => e.goalOrder), r = e.tasks.filter((e) => M(e) && e.projectId === t).length;
699
+ return Math.max(r, ...n.map((e) => e + 1));
700
+ }
701
+ function Re(e, t, n, r, i) {
702
+ let a = t.indexOf(n), o = t.indexOf(r);
703
+ if (a < 0 || o < 0 || a === o) return {};
704
+ let s = new Map(e.tasks.map((e) => [e.id, e])), c = B(i);
705
+ return { tasks: X(t, a, o).map((e, t) => ({
706
+ task: s.get(e),
707
+ goalOrder: t
708
+ })).filter((e) => !!e.task && e.task.goalOrder !== e.goalOrder).map(({ task: e, goalOrder: t }) => ({
709
+ ...e,
710
+ goalOrder: t,
711
+ updatedAt: c
712
+ })) };
713
+ }
714
+ // src/core/labels.ts
715
+ var Q = {
716
+ today: "今日",
717
+ week: "今週",
718
+ month: "数か月",
719
+ year: "今年",
720
+ life: "一生"
721
+ }, ze = {
722
+ today: "Action",
723
+ week: "Week",
724
+ month: "Month",
725
+ year: "Year",
726
+ life: "⭐"
727
+ }, Be = {
728
+ ...Q,
729
+ pool: "未定(置き場)"
730
+ }, Ve = {
731
+ today: "今日やる",
732
+ tomorrow: "明日やる",
733
+ nextweek: "来週やる",
734
+ week: "今週やる",
735
+ month: "数か月以内にやる",
736
+ year: "今年やる",
737
+ life: "一生のうちに"
738
+ }, He = {
739
+ today: "今日",
740
+ tomorrow: "明日",
741
+ nextweek: "来週",
742
+ week: "今週",
743
+ month: "数か月",
744
+ year: "今年",
745
+ life: "一生"
746
+ }, Ue = {
747
+ A: "重要・緊急",
748
+ B: "重要",
749
+ C: "通常",
750
+ D: "低",
751
+ P: "Private"
752
+ }, We = {
753
+ day: "毎日",
754
+ week: "毎週",
755
+ month: "毎月",
756
+ year: "毎年"
757
+ };
758
+ // src/core/review.ts
759
+ function $(e) {
760
+ let t = new Set(e.history ?? []);
761
+ return e.checkedAt && t.add(n(new Date(e.checkedAt))), t;
762
+ }
763
+ function Ge(e, t) {
764
+ let r = $(e);
765
+ if (e.period === "day") return r.has(n(t));
766
+ let i = s(e.period, t);
767
+ for (let t of r) {
768
+ let [n, r, a] = t.split("-").map(Number);
769
+ if (s(e.period, new Date(n, r - 1, a)) === i) return !0;
770
+ }
771
+ return !1;
772
+ }
773
+ function Ke(e, t) {
774
+ if (e.period !== "day") return 0;
775
+ let r = $(e), i = r.has(n(t)) ? t : u(t, -1), a = 0;
776
+ for (; r.has(n(i));) a++, i = u(i, -1);
777
+ return a;
778
+ }
779
+ function qe(e, t, r) {
780
+ let i = n(t), a = new Map(e.projects.map((e) => [e.id, e])), o = new Set(e.tasks.filter((e) => e.parentId && e.doneAt).map((e) => e.parentId));
781
+ return e.tasks.filter((e) => e.doneAt && n(new Date(e.doneAt)) === i && !o.has(e.id)).sort((e, t) => e.doneAt.localeCompare(t.doneAt)).map((e) => ({
782
+ task: e,
783
+ horizon: P(e, r),
784
+ project: e.projectId ? a.get(e.projectId) : void 0
785
+ }));
786
+ }
787
+ function Je(e, t) {
788
+ return Array.from({ length: t }, (n, r) => u(e, r - t + 1));
789
+ }
790
+ export { e as HORIZONS, l as HORIZON_HABIT_PERIOD, Q as HORIZON_NAME, Be as HORIZON_OPTION, c as HORIZON_PERIOD, ze as HORIZON_SUB, We as PERIOD_NAME, He as PLACED_MARK, Ve as PLACE_LABEL, t as PRIORITIES, Ue as PRIORITY_NAME, I as activeChild, Z as activeHabitChild, u as addDays, xe as applyChanges, w as autoDue, Fe as bringToToday, ue as buildColumns, q as childProjects, n as dayKey, v as dayLabel, h as daysUntil, qe as doneOn, m as dueLabel, ee as dueLabelWeekday, P as effectiveHorizon, Ne as finishOnDay, j as followsDue, k as goalDueNextWeek, $ as habitDays, Ge as habitDoneOn, Te as habitPlaceTargets, Oe as habitToTask, S as hasWhen, N as horizonForDue, d as inSamePeriod, D as isExpired, O as isForNextWeek, A as isForTomorrow, oe as isMonthOnly, M as isProjectGoal, F as isVisible, Je as lastDays, Y as mergeById, b as monthDayDate, a as monthKey, ke as monthlyDueDate, J as moveProject, pe as moveStep, fe as moveTo, ge as newHabit, ve as newProject, H as newTask, Le as nextGoalOrder, R as numbered, y as parseNthWeekday, x as parseYearDay, _ as periodHorizon, s as periodKey, p as periodLabel, U as placeDown, Ee as placeHabitDown, L as placeTargets, E as placedForKey, Pe as postponeToTomorrow, Ie as projectGoals, le as quickTarget, be as removeProject, he as removeTask, Re as reorderGoals, Ce as reorderHabits, we as reorderProjects, Se as reorderTasks, de as returnUp, Ae as setDue, me as setPriority, te as shortDueLabel, Ke as streak, G as toggleDone, K as toggleHabit, De as toggleHabitAll, Me as toggleHabitOnDay, ye as topProjects, r as weekKey, i as weekStart, C as whenDate, re as whenLabel, je as withDay, ae as withWhen, o as yearKey };