@r_masseater/masseater-utils 0.8.2 → 0.9.1
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 +46 -40
- package/dist/browser-test/vite.mjs +1 -29
- package/dist/browser-test-vite-DS3fTcyM.mjs +29 -0
- package/dist/browser-test-vite-DS3fTcyM.mjs.map +1 -0
- package/dist/button-980Op0uF.mjs +30 -0
- package/dist/button-980Op0uF.mjs.map +1 -0
- package/dist/desktop-shell/media-notes/protocol.d.mts +2 -0
- package/dist/desktop-shell/media-notes/protocol.mjs +1 -0
- package/dist/desktop-shell/media-notes.d.mts +125 -0
- package/dist/desktop-shell/media-notes.mjs +865 -0
- package/dist/desktop-shell/media-notes.mjs.map +1 -0
- package/dist/desktop-shell/release-cli.d.mts +1 -0
- package/dist/desktop-shell/release-cli.mjs +290 -0
- package/dist/desktop-shell/release-cli.mjs.map +1 -0
- package/dist/desktop-shell/telemetry.d.mts +5 -0
- package/dist/desktop-shell/telemetry.mjs +55 -0
- package/dist/desktop-shell/telemetry.mjs.map +1 -0
- package/dist/desktop-shell/vite.d.mts +24 -0
- package/dist/desktop-shell/vite.mjs +58 -0
- package/dist/desktop-shell/vite.mjs.map +1 -0
- package/dist/index-BtcxUsGh.d.mts +4 -0
- package/dist/index-CjUS4pmA.d.mts +59 -0
- package/dist/lapse.mjs +1 -1
- package/dist/media-protocol-CMyatw7A.mjs +32 -0
- package/dist/media-protocol-CMyatw7A.mjs.map +1 -0
- package/dist/node-main-Bwril94o.mjs +19 -0
- package/dist/node-main-Bwril94o.mjs.map +1 -0
- package/dist/node-main.mjs +1 -18
- package/dist/plugin-kit.mjs +22 -22
- package/dist/plugin-kit.mjs.map +1 -1
- package/dist/security-headers.d.mts +2 -1
- package/dist/ui/button.d.mts +1 -1
- package/dist/ui/button.mjs +1 -30
- package/dist/ui/next-page-trigger.mjs +1 -1
- package/dist/ui/page-footer.d.mts +1 -1
- package/dist/ui/page-header.d.mts +1 -1
- package/dist/ui/table.d.mts +1 -1
- package/dist/ui/web-analytics.d.mts +1 -0
- package/dist/vitest-otlp/workers.mjs +1 -1
- package/dist/workers-tracing/alchemy.d.mts +1 -1
- package/native/desktop-shell/Cargo.toml +38 -0
- package/native/desktop-shell/src/app/builder.rs +39 -0
- package/native/desktop-shell/src/app/mod.rs +3 -0
- package/native/desktop-shell/src/entities/access_token.rs +77 -0
- package/native/desktop-shell/src/entities/mod.rs +1 -0
- package/native/desktop-shell/src/features/mod.rs +4 -0
- package/native/desktop-shell/src/features/record_telemetry/appender.rs +127 -0
- package/native/desktop-shell/src/features/record_telemetry/forwarder.rs +183 -0
- package/native/desktop-shell/src/features/record_telemetry/invoke.rs +80 -0
- package/native/desktop-shell/src/features/record_telemetry/mod.rs +231 -0
- package/native/desktop-shell/src/features/serve_screen/mod.rs +135 -0
- package/native/desktop-shell/src/features/serve_tools/mod.rs +37 -0
- package/native/desktop-shell/src/features/update_app/mod.rs +53 -0
- package/native/desktop-shell/src/lib.rs +17 -0
- package/native/desktop-shell/src/shared/lib/bearer.rs +49 -0
- package/native/desktop-shell/src/shared/lib/host.rs +1 -0
- package/native/desktop-shell/src/shared/lib/mod.rs +5 -0
- package/native/desktop-shell/src/shared/mod.rs +2 -0
- package/native/desktop-shell/src/shared/ui/log.rs +15 -0
- package/native/desktop-shell/src/shared/ui/menu.rs +37 -0
- package/native/desktop-shell/src/shared/ui/mod.rs +7 -0
- package/native/desktop-shell/src/shared/ui/window.rs +49 -0
- package/native/media-notes/Cargo.toml +36 -0
- package/native/media-notes/src/entities/media_file.rs +89 -0
- package/native/media-notes/src/entities/media_notes.rs +31 -0
- package/native/media-notes/src/entities/mod.rs +3 -0
- package/native/media-notes/src/entities/source/credit.rs +129 -0
- package/native/media-notes/src/entities/source/link.rs +194 -0
- package/native/media-notes/src/entities/source/mod.rs +5 -0
- package/native/media-notes/src/features/mod.rs +2 -0
- package/native/media-notes/src/features/open_media/mod.rs +88 -0
- package/native/media-notes/src/features/share_mcp_access.rs +15 -0
- package/native/media-notes/src/lib.rs +12 -0
- package/native/media-notes/src/shared/db/mod.rs +3 -0
- package/native/media-notes/src/shared/db/store.rs +276 -0
- package/native/media-notes/src/shared/lib/failure.rs +55 -0
- package/native/media-notes/src/shared/lib/mcp.rs +34 -0
- package/native/media-notes/src/shared/lib/mod.rs +5 -0
- package/native/media-notes/src/shared/mod.rs +3 -0
- package/native/media-notes/src/shared/protocol.rs +69 -0
- package/package.json +129 -56
- package/skills/build-tauri-app/SKILL.md +58 -0
- package/dist/browser-test/vite.mjs.map +0 -1
- package/dist/node-main.mjs.map +0 -1
- package/dist/ui/button.mjs.map +0 -1
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
import { r as OpenedSchema, t as McpAccessSchema } from "../media-protocol-CMyatw7A.mjs";
|
|
2
|
+
import { t as Button } from "../button-980Op0uF.mjs";
|
|
3
|
+
import { Array, Effect, Fiber, Match, MutableRef, Option, Predicate, Record, Schedule, Schema, Stream, String as String$1, pipe } from "effect";
|
|
4
|
+
import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
|
|
5
|
+
import { Check, Copy, ExternalLink, FolderOpen, LoaderCircle } from "lucide-react";
|
|
6
|
+
import { convertFileSrc, invoke } from "@tauri-apps/api/core";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { useAtom, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
9
|
+
import { useCallback, useEffect, useId, useMemo } from "react";
|
|
10
|
+
import { KeyValueStore } from "effect/persistence";
|
|
11
|
+
import { getCurrentWebview } from "@tauri-apps/api/webview";
|
|
12
|
+
import { constVoid } from "effect/Function";
|
|
13
|
+
import { createNiconicoEngine } from "niconico-embed-player";
|
|
14
|
+
import { listen } from "@tauri-apps/api/event";
|
|
15
|
+
// src/entities/media/model/media.ts
|
|
16
|
+
/** @internal */
|
|
17
|
+
const openedAtom = Atom.make(Option.none()).pipe(Atom.keepAlive);
|
|
18
|
+
const keyOf = ({ site, id }) => `${site}:${id}`;
|
|
19
|
+
const pageOf = ({ site, id }) => Match.value(site).pipe(Match.when("youtube", () => Option.some(`https://www.youtube.com/watch?v=${id}`)), Match.when("niconico", () => Option.some(`https://www.nicovideo.jp/watch/${id}`)), Match.when("soundcloud", () => Option.some(`https://soundcloud.com/${id}`)), Match.when("file", () => Option.none()), Match.exhaustive);
|
|
20
|
+
// src/shared/config/sites.ts
|
|
21
|
+
const SITE_NAMES = {
|
|
22
|
+
youtube: "YouTube",
|
|
23
|
+
niconico: "ニコニコ",
|
|
24
|
+
soundcloud: "SoundCloud",
|
|
25
|
+
file: "ファイル"
|
|
26
|
+
};
|
|
27
|
+
// src/shared/lib/clock.ts
|
|
28
|
+
const SECONDS_PER_MINUTE = 60;
|
|
29
|
+
const START$2 = 0;
|
|
30
|
+
const CLOCK_DIGITS = 2;
|
|
31
|
+
const TENTHS = 10;
|
|
32
|
+
const TENTH_DIGITS = 1;
|
|
33
|
+
const whole = (seconds) => Math.max(Math.floor(seconds), START$2);
|
|
34
|
+
const clock = (seconds) => {
|
|
35
|
+
const total = whole(seconds);
|
|
36
|
+
return `${Math.floor(total / SECONDS_PER_MINUTE)}:${String$1.padStart(CLOCK_DIGITS, "0")(String(total % SECONDS_PER_MINUTE))}`;
|
|
37
|
+
};
|
|
38
|
+
const preciseClock = (seconds) => {
|
|
39
|
+
const tenths = Math.floor(Math.max(seconds, START$2) * TENTHS) % TENTHS;
|
|
40
|
+
return `${clock(seconds)}.${String$1.padStart(TENTH_DIGITS, "0")(String(tenths))}`;
|
|
41
|
+
};
|
|
42
|
+
// src/entities/media/ui/media-meta.tsx
|
|
43
|
+
const PageLink = ({ media }) => Option.match(pageOf(media.source), {
|
|
44
|
+
onNone: () => false,
|
|
45
|
+
onSome: (page) => /* @__PURE__ */ jsx("a", {
|
|
46
|
+
href: page,
|
|
47
|
+
target: "_blank",
|
|
48
|
+
rel: "noreferrer",
|
|
49
|
+
"aria-label": "元のページ",
|
|
50
|
+
className: "text-muted-foreground hover:text-foreground self-center",
|
|
51
|
+
children: /* @__PURE__ */ jsx(ExternalLink, { className: "size-4" })
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
const MediaMeta = ({ media, duration }) => /* @__PURE__ */ jsxs("header", {
|
|
55
|
+
className: "flex min-w-0 items-baseline gap-3",
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ jsx("span", {
|
|
58
|
+
className: "text-muted-foreground text-xs",
|
|
59
|
+
children: SITE_NAMES[media.source.site]
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ jsx("h1", {
|
|
62
|
+
className: "min-w-0 truncate text-base font-semibold",
|
|
63
|
+
children: media.title
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ jsx("span", {
|
|
66
|
+
className: "text-muted-foreground truncate text-sm",
|
|
67
|
+
children: media.artist
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ jsx("span", {
|
|
70
|
+
className: "text-muted-foreground ml-auto font-mono text-xs tabular-nums",
|
|
71
|
+
children: clock(duration)
|
|
72
|
+
}),
|
|
73
|
+
/* @__PURE__ */ jsx(PageLink, { media })
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
// src/shared/api/media-notes/media.ts
|
|
77
|
+
const taggedError = Schema.TaggedError;
|
|
78
|
+
var ApiFailed = class extends taggedError()("ApiFailed", { message: Schema.String }) {};
|
|
79
|
+
const RefusalSchema = Schema.Struct({ message: Schema.String });
|
|
80
|
+
const failed = (cause) => ApiFailed.make({ message: Option.match(Schema.decodeUnknownOption(RefusalSchema)(cause), {
|
|
81
|
+
onNone: () => String(cause),
|
|
82
|
+
onSome: ({ message }) => message
|
|
83
|
+
}) });
|
|
84
|
+
const called = (decode, command, input) => Effect.tryPromise({
|
|
85
|
+
try: () => invoke(command, input),
|
|
86
|
+
catch: failed
|
|
87
|
+
}).pipe(Effect.flatMap(decode), Effect.catchTag("SchemaError", (cause) => cause.pipe(failed, Effect.fail)));
|
|
88
|
+
const decodeOpened = Schema.decodeUnknownEffect(OpenedSchema);
|
|
89
|
+
const decodeChosen = Schema.decodeUnknownEffect(Schema.NullOr(OpenedSchema));
|
|
90
|
+
const decodeAccess = Schema.decodeUnknownEffect(McpAccessSchema);
|
|
91
|
+
const openLink = (link) => called(decodeOpened, "open_link", { link });
|
|
92
|
+
const openFile = (path) => called(decodeOpened, "open_file", { path });
|
|
93
|
+
const chooseFile = Effect.suspend(() => called(decodeChosen, "choose_file", {})).pipe(Effect.map(Option.fromNullishOr));
|
|
94
|
+
const mcpAccess = Effect.suspend(() => called(decodeAccess, "mcp_access", {}));
|
|
95
|
+
// src/shared/api/media-notes/settled.ts
|
|
96
|
+
const thrown = (cause) => ApiFailed.make({ message: String(cause) });
|
|
97
|
+
const settled = (run) => Effect.tryPromise({
|
|
98
|
+
try: run,
|
|
99
|
+
catch: thrown
|
|
100
|
+
}).pipe(Effect.flatMap((answer) => {
|
|
101
|
+
if (answer.status === "ok") return Effect.succeed(answer.data);
|
|
102
|
+
return Effect.fail(ApiFailed.make({ message: answer.error.message }));
|
|
103
|
+
}));
|
|
104
|
+
const settledAs = (decode) => (run) => Effect.suspend(() => settled(run)).pipe(Effect.flatMap(decode), Effect.catchTag("SchemaError", (cause) => cause.pipe(thrown, Effect.fail)));
|
|
105
|
+
// src/shared/lib/runtime.ts
|
|
106
|
+
/** @internal */
|
|
107
|
+
const runtime = Atom.runtime(KeyValueStore.layerStorage(() => globalThis.localStorage));
|
|
108
|
+
// src/features/connect-mcp/model/access.ts
|
|
109
|
+
const commandOf = (name, { url, token }) => `claude mcp add --transport http ${name} ${url} --header "Authorization: Bearer ${token}"`;
|
|
110
|
+
/** @internal */
|
|
111
|
+
const copyAtom = runtime.fn((name) => mcpAccess.pipe(Effect.flatMap((access) => Effect.promise(() => navigator.clipboard.writeText(commandOf(name, access))))));
|
|
112
|
+
// src/features/connect-mcp/ui/copy-mcp-command.tsx
|
|
113
|
+
const LABEL = "MCP";
|
|
114
|
+
const HINT = "Claude Code に追加するコマンドをコピー";
|
|
115
|
+
const COPIED = "コピーしました";
|
|
116
|
+
const FAILED = "コピーできませんでした";
|
|
117
|
+
const SILENT = "";
|
|
118
|
+
const iconOf = (done) => {
|
|
119
|
+
if (done) return /* @__PURE__ */ jsx(Check, { "aria-hidden": "true" });
|
|
120
|
+
return /* @__PURE__ */ jsx(Copy, { "aria-hidden": "true" });
|
|
121
|
+
};
|
|
122
|
+
const statusOf = (done, failed) => {
|
|
123
|
+
if (done) return COPIED;
|
|
124
|
+
if (failed) return FAILED;
|
|
125
|
+
return SILENT;
|
|
126
|
+
};
|
|
127
|
+
const CopyMcpCommand = ({ name }) => {
|
|
128
|
+
const [copied, copy] = useAtom(copyAtom);
|
|
129
|
+
const click = useCallback(() => {
|
|
130
|
+
copy(name);
|
|
131
|
+
}, [copy, name]);
|
|
132
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Button, {
|
|
133
|
+
variant: "outline",
|
|
134
|
+
title: HINT,
|
|
135
|
+
onClick: click,
|
|
136
|
+
children: [iconOf(AsyncResult.isSuccess(copied)), LABEL]
|
|
137
|
+
}), /* @__PURE__ */ jsx("output", {
|
|
138
|
+
className: "sr-only",
|
|
139
|
+
children: statusOf(AsyncResult.isSuccess(copied), AsyncResult.isFailure(copied))
|
|
140
|
+
})] });
|
|
141
|
+
};
|
|
142
|
+
// src/features/open-media/model/open.ts
|
|
143
|
+
/** @internal */
|
|
144
|
+
const linkAtom = Atom.make("").pipe(Atom.keepAlive);
|
|
145
|
+
const shown = (opened) => AtomRegistry.AtomRegistry.pipe(Effect.flatMap((registry) => Effect.sync(() => {
|
|
146
|
+
if (Option.isSome(opened)) registry.set(openedAtom, opened);
|
|
147
|
+
})));
|
|
148
|
+
/** @internal */
|
|
149
|
+
const openLinkAtom = runtime.fn((link) => openLink(link).pipe(Effect.asSome, Effect.flatMap(shown)));
|
|
150
|
+
/** @internal */
|
|
151
|
+
const openFileAtom = runtime.fn((path) => openFile(path).pipe(Effect.asSome, Effect.flatMap(shown)));
|
|
152
|
+
/** @internal */
|
|
153
|
+
const chooseFileAtom = runtime.fn(() => chooseFile.pipe(Effect.flatMap(shown)));
|
|
154
|
+
// src/features/open-media/model/use-file-drop.ts
|
|
155
|
+
const listening = (open) => Effect.acquireRelease(Effect.promise(() => getCurrentWebview().onDragDropEvent(({ payload }) => {
|
|
156
|
+
if (payload.type === "drop") Option.map(Array.head(payload.paths), open);
|
|
157
|
+
})), (stop) => Effect.sync(stop)).pipe(Effect.andThen(Effect.never), Effect.scoped);
|
|
158
|
+
const useFileDrop = (enabled) => {
|
|
159
|
+
const open = useAtomSet(openFileAtom);
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (!enabled) return constVoid;
|
|
162
|
+
const fiber = Effect.runFork(listening(open));
|
|
163
|
+
return () => {
|
|
164
|
+
fiber.pipe(Fiber.interrupt, Effect.runFork);
|
|
165
|
+
};
|
|
166
|
+
}, [enabled, open]);
|
|
167
|
+
};
|
|
168
|
+
// src/features/open-media/ui/choose-file.tsx
|
|
169
|
+
const CHOOSE = "ファイルを開く";
|
|
170
|
+
const ChooseFile = () => {
|
|
171
|
+
const [chosen, choose] = useAtom(chooseFileAtom);
|
|
172
|
+
const click = useCallback(() => {
|
|
173
|
+
choose();
|
|
174
|
+
}, [choose]);
|
|
175
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
176
|
+
type: "button",
|
|
177
|
+
variant: "outline",
|
|
178
|
+
disabled: chosen.waiting,
|
|
179
|
+
onClick: click,
|
|
180
|
+
children: [/* @__PURE__ */ jsx(FolderOpen, { "aria-hidden": "true" }), CHOOSE]
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
// src/features/open-media/ui/refusal.tsx
|
|
184
|
+
const Refusal = ({ id }) => {
|
|
185
|
+
const link = useAtomValue(openLinkAtom).pipe(AsyncResult.error);
|
|
186
|
+
const file = useAtomValue(openFileAtom).pipe(AsyncResult.error);
|
|
187
|
+
const chosen = useAtomValue(chooseFileAtom).pipe(AsyncResult.error);
|
|
188
|
+
return Option.match(Option.firstSomeOf([
|
|
189
|
+
link,
|
|
190
|
+
file,
|
|
191
|
+
chosen
|
|
192
|
+
]), {
|
|
193
|
+
onNone: () => false,
|
|
194
|
+
onSome: ({ message }) => /* @__PURE__ */ jsx("p", {
|
|
195
|
+
id,
|
|
196
|
+
role: "alert",
|
|
197
|
+
className: "text-destructive basis-full text-xs",
|
|
198
|
+
children: message
|
|
199
|
+
})
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
// src/features/open-media/ui/open-bar.tsx
|
|
203
|
+
const OPEN = "開く";
|
|
204
|
+
const OpenBar = ({ files, label }) => {
|
|
205
|
+
const [link, setLink] = useAtom(linkAtom);
|
|
206
|
+
const [opened, open] = useAtom(openLinkAtom);
|
|
207
|
+
const refusalId = useId();
|
|
208
|
+
const failed = AsyncResult.isFailure(opened);
|
|
209
|
+
useFileDrop(files);
|
|
210
|
+
const submit = useCallback((event) => {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
open(link);
|
|
213
|
+
}, [open, link]);
|
|
214
|
+
const change = useCallback((event) => {
|
|
215
|
+
setLink(event.currentTarget.value);
|
|
216
|
+
}, [setLink]);
|
|
217
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
218
|
+
className: "flex flex-wrap gap-2",
|
|
219
|
+
onSubmit: submit,
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsx("input", {
|
|
222
|
+
type: "url",
|
|
223
|
+
value: link,
|
|
224
|
+
"aria-label": label,
|
|
225
|
+
"aria-invalid": failed,
|
|
226
|
+
"aria-describedby": Option.getOrUndefined(Option.liftPredicate(refusalId, () => failed)),
|
|
227
|
+
placeholder: "https://",
|
|
228
|
+
className: "border-input bg-background focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive h-9 min-w-0 flex-1 rounded-md border px-3 font-mono text-sm outline-none focus-visible:ring-3",
|
|
229
|
+
onChange: change
|
|
230
|
+
}),
|
|
231
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
232
|
+
type: "submit",
|
|
233
|
+
disabled: opened.waiting,
|
|
234
|
+
children: [opened.waiting && /* @__PURE__ */ jsx(LoaderCircle, { className: "animate-spin" }), OPEN]
|
|
235
|
+
}),
|
|
236
|
+
files && /* @__PURE__ */ jsx(ChooseFile, {}),
|
|
237
|
+
/* @__PURE__ */ jsx(Refusal, { id: refusalId })
|
|
238
|
+
]
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
// src/features/play-media/lib/file.ts
|
|
242
|
+
const START$1 = 0;
|
|
243
|
+
const seconds = (value) => {
|
|
244
|
+
if (Number.isFinite(value)) return value;
|
|
245
|
+
return START$1;
|
|
246
|
+
};
|
|
247
|
+
const placed = ({ stage, opened }) => Effect.sync(() => {
|
|
248
|
+
const video = document.createElement("video");
|
|
249
|
+
video.src = convertFileSrc(opened.location);
|
|
250
|
+
video.preload = "auto";
|
|
251
|
+
video.playsInline = true;
|
|
252
|
+
stage.replaceChildren(video);
|
|
253
|
+
return video;
|
|
254
|
+
});
|
|
255
|
+
const removed$1 = ({ stage }) => Effect.sync(() => {
|
|
256
|
+
stage.replaceChildren();
|
|
257
|
+
});
|
|
258
|
+
const mountFile = (mount) => Effect.acquireRelease(placed(mount), () => removed$1(mount)).pipe(Effect.map((video) => ({
|
|
259
|
+
time: () => ({
|
|
260
|
+
current: seconds(video.currentTime),
|
|
261
|
+
duration: seconds(video.duration)
|
|
262
|
+
}),
|
|
263
|
+
seek: (to) => {
|
|
264
|
+
video.currentTime = to;
|
|
265
|
+
},
|
|
266
|
+
toggle: () => {
|
|
267
|
+
if (video.paused) {
|
|
268
|
+
Effect.tryPromise({
|
|
269
|
+
try: () => video.play(),
|
|
270
|
+
catch: constVoid
|
|
271
|
+
}).pipe(Effect.ignore, Effect.runFork);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
video.pause();
|
|
275
|
+
}
|
|
276
|
+
})));
|
|
277
|
+
// src/features/play-media/lib/niconico.ts
|
|
278
|
+
const mountNiconico = ({ stage, opened }) => {
|
|
279
|
+
const playing = MutableRef.make(false);
|
|
280
|
+
const stopped = () => {
|
|
281
|
+
MutableRef.set(playing, false);
|
|
282
|
+
};
|
|
283
|
+
const created = Effect.sync(() => createNiconicoEngine(stage, {
|
|
284
|
+
videoId: opened.media.source.id,
|
|
285
|
+
title: "niconico"
|
|
286
|
+
}, {
|
|
287
|
+
onPlaying: () => {
|
|
288
|
+
MutableRef.set(playing, true);
|
|
289
|
+
},
|
|
290
|
+
onPaused: stopped,
|
|
291
|
+
onEnded: stopped
|
|
292
|
+
}));
|
|
293
|
+
return Effect.acquireRelease(created, (engine) => Effect.sync(() => {
|
|
294
|
+
engine.destroy();
|
|
295
|
+
})).pipe(Effect.map((engine) => ({
|
|
296
|
+
time: () => engine.time(),
|
|
297
|
+
seek: (seconds) => {
|
|
298
|
+
engine.seek(seconds);
|
|
299
|
+
},
|
|
300
|
+
toggle: () => {
|
|
301
|
+
if (MutableRef.get(playing)) {
|
|
302
|
+
engine.pause();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
engine.play();
|
|
306
|
+
}
|
|
307
|
+
})));
|
|
308
|
+
};
|
|
309
|
+
// src/shared/lib/player.ts
|
|
310
|
+
const STILL = {
|
|
311
|
+
current: 0,
|
|
312
|
+
duration: 0
|
|
313
|
+
};
|
|
314
|
+
// src/features/play-media/lib/soundcloud.ts
|
|
315
|
+
const MILLISECONDS = 1e3;
|
|
316
|
+
const widgetUrl = ({ media, location }) => `https://w.soundcloud.com/player/?${new URLSearchParams({
|
|
317
|
+
url: Option.getOrElse(pageOf(media.source), () => location),
|
|
318
|
+
visual: "true",
|
|
319
|
+
auto_play: "false",
|
|
320
|
+
show_comments: "false"
|
|
321
|
+
}).toString()}`;
|
|
322
|
+
const framed = ({ stage, opened }) => Effect.sync(() => {
|
|
323
|
+
const iframe = document.createElement("iframe");
|
|
324
|
+
iframe.src = widgetUrl(opened);
|
|
325
|
+
iframe.allow = "autoplay";
|
|
326
|
+
iframe.title = "SoundCloud";
|
|
327
|
+
stage.replaceChildren(iframe);
|
|
328
|
+
return iframe;
|
|
329
|
+
});
|
|
330
|
+
const cleared = ({ stage }) => Effect.sync(() => {
|
|
331
|
+
stage.replaceChildren();
|
|
332
|
+
});
|
|
333
|
+
const ready = ({ frame }) => Effect.callback((resume) => {
|
|
334
|
+
const widget = SC.Widget(frame);
|
|
335
|
+
const position = MutableRef.make(STILL);
|
|
336
|
+
widget.bind(SC.Widget.Events.PLAY_PROGRESS, ({ currentPosition }) => {
|
|
337
|
+
MutableRef.update(position, (now) => ({
|
|
338
|
+
...now,
|
|
339
|
+
current: currentPosition / MILLISECONDS
|
|
340
|
+
}));
|
|
341
|
+
});
|
|
342
|
+
widget.bind(SC.Widget.Events.READY, () => {
|
|
343
|
+
widget.getDuration((milliseconds) => {
|
|
344
|
+
MutableRef.update(position, (now) => ({
|
|
345
|
+
...now,
|
|
346
|
+
duration: milliseconds / MILLISECONDS
|
|
347
|
+
}));
|
|
348
|
+
resume(Effect.succeed({
|
|
349
|
+
time: () => MutableRef.get(position),
|
|
350
|
+
seek: (seconds) => {
|
|
351
|
+
widget.seekTo(seconds * MILLISECONDS);
|
|
352
|
+
MutableRef.update(position, (now) => ({
|
|
353
|
+
...now,
|
|
354
|
+
current: seconds
|
|
355
|
+
}));
|
|
356
|
+
},
|
|
357
|
+
toggle: () => {
|
|
358
|
+
widget.toggle();
|
|
359
|
+
}
|
|
360
|
+
}));
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
const mountSoundcloud = (mount) => Effect.acquireRelease(framed(mount), () => cleared(mount)).pipe(Effect.flatMap((frame) => ready({ frame })));
|
|
365
|
+
// src/features/play-media/lib/youtube.ts
|
|
366
|
+
const LOADED = 1;
|
|
367
|
+
const isCallback = (value) => Predicate.isFunction(value);
|
|
368
|
+
const apiReady = () => "YT" in globalThis && pipe(Option.liftPredicate(YT, Predicate.hasProperty("loaded")), Option.exists(({ loaded }) => loaded === LOADED));
|
|
369
|
+
const whenApiReady = Effect.callback((resume) => {
|
|
370
|
+
if (apiReady()) {
|
|
371
|
+
resume(Effect.void);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const previous = pipe(Option.liftPredicate(globalThis, Predicate.hasProperty("onYouTubeIframeAPIReady")), Option.map((found) => found.onYouTubeIframeAPIReady), Option.getOrUndefined);
|
|
375
|
+
Reflect.set(globalThis, "onYouTubeIframeAPIReady", () => {
|
|
376
|
+
if (isCallback(previous)) previous();
|
|
377
|
+
resume(Effect.void);
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
const removed = ({ player, host }) => Effect.sync(() => {
|
|
381
|
+
player.destroy();
|
|
382
|
+
host.remove();
|
|
383
|
+
});
|
|
384
|
+
const created = (mount) => Effect.callback((resume) => {
|
|
385
|
+
const host = document.createElement("div");
|
|
386
|
+
mount.stage.replaceChildren(host);
|
|
387
|
+
const player = new YT.Player(host, {
|
|
388
|
+
videoId: mount.opened.media.source.id,
|
|
389
|
+
width: "100%",
|
|
390
|
+
height: "100%",
|
|
391
|
+
events: { onReady: () => {
|
|
392
|
+
resume(Effect.succeed({
|
|
393
|
+
player,
|
|
394
|
+
host
|
|
395
|
+
}));
|
|
396
|
+
} }
|
|
397
|
+
});
|
|
398
|
+
return removed({
|
|
399
|
+
player,
|
|
400
|
+
host
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
const owned = (mount) => Effect.acquireRelease(created(mount), removed);
|
|
404
|
+
const mountYoutube = (mount) => whenApiReady.pipe(Effect.andThen(owned(mount)), Effect.map(({ player }) => ({
|
|
405
|
+
time: () => ({
|
|
406
|
+
current: player.getCurrentTime(),
|
|
407
|
+
duration: player.getDuration()
|
|
408
|
+
}),
|
|
409
|
+
seek: (seconds) => {
|
|
410
|
+
player.seekTo(seconds, true);
|
|
411
|
+
},
|
|
412
|
+
toggle: () => {
|
|
413
|
+
if (player.getPlayerState() === YT.PlayerState.PLAYING) {
|
|
414
|
+
player.pauseVideo();
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
player.playVideo();
|
|
418
|
+
}
|
|
419
|
+
})));
|
|
420
|
+
// src/features/play-media/lib/mount.ts
|
|
421
|
+
const mountPlayer = (mount) => Match.value(mount.opened.media.source.site).pipe(Match.when("youtube", () => mountYoutube(mount)), Match.when("niconico", () => mountNiconico(mount)), Match.when("soundcloud", () => mountSoundcloud(mount)), Match.when("file", () => mountFile(mount)), Match.exhaustive);
|
|
422
|
+
// src/features/play-media/model/player.ts
|
|
423
|
+
const TICK = "200 millis";
|
|
424
|
+
/** @internal */
|
|
425
|
+
const stageAtom = Atom.make(Option.none());
|
|
426
|
+
/** @internal */
|
|
427
|
+
const playerAtom = Atom.make(Effect.fnUntraced(function* player(get) {
|
|
428
|
+
const stage = yield* Effect.fromOption(get(stageAtom));
|
|
429
|
+
const opened = yield* Effect.fromOption(get(openedAtom));
|
|
430
|
+
return yield* mountPlayer({
|
|
431
|
+
stage,
|
|
432
|
+
opened
|
|
433
|
+
});
|
|
434
|
+
}));
|
|
435
|
+
const positionAtom = Atom.make((get) => pipe(get.result(playerAtom), Effect.map((player) => Stream.fromEffectSchedule(Effect.sync(() => player.time()), Schedule.spaced(TICK))), Stream.unwrap));
|
|
436
|
+
const usePlayer = () => useAtomValue(playerAtom).pipe(AsyncResult.value);
|
|
437
|
+
const usePosition = () => AsyncResult.getOrElse(useAtomValue(positionAtom), () => STILL);
|
|
438
|
+
// src/shared/lib/keys.ts
|
|
439
|
+
const FIELD = "input, textarea, select, button, [contenteditable]";
|
|
440
|
+
const MODIFIERS = [
|
|
441
|
+
"ctrlKey",
|
|
442
|
+
"metaKey",
|
|
443
|
+
"altKey",
|
|
444
|
+
"isComposing"
|
|
445
|
+
];
|
|
446
|
+
const inField = ({ target }) => target instanceof Element && target.closest(FIELD) !== null;
|
|
447
|
+
const ignoredKey = (event) => pipe(MODIFIERS, Array.some((key) => event[key])) || inField(event);
|
|
448
|
+
// src/features/play-media/model/use-play-key.ts
|
|
449
|
+
const KEY$1 = " ";
|
|
450
|
+
const usePlayKey = (player) => {
|
|
451
|
+
useEffect(() => {
|
|
452
|
+
const onKey = (event) => {
|
|
453
|
+
if (event.key !== KEY$1 || ignoredKey(event) || Option.isNone(player)) return;
|
|
454
|
+
event.preventDefault();
|
|
455
|
+
player.value.toggle();
|
|
456
|
+
};
|
|
457
|
+
globalThis.addEventListener("keydown", onKey);
|
|
458
|
+
return () => {
|
|
459
|
+
globalThis.removeEventListener("keydown", onKey);
|
|
460
|
+
};
|
|
461
|
+
}, [player]);
|
|
462
|
+
};
|
|
463
|
+
// src/features/play-media/ui/key-hints.tsx
|
|
464
|
+
const HINTS = [{
|
|
465
|
+
key: "M",
|
|
466
|
+
meaning: "始点・終点"
|
|
467
|
+
}, {
|
|
468
|
+
key: "Space",
|
|
469
|
+
meaning: "再生・一時停止"
|
|
470
|
+
}];
|
|
471
|
+
const KeyHints = ({ hints }) => /* @__PURE__ */ jsx("p", {
|
|
472
|
+
className: "text-muted-foreground flex flex-wrap items-center gap-x-4 gap-y-1 text-xs",
|
|
473
|
+
children: pipe([...HINTS, ...hints], Array.map(({ key, meaning }) => /* @__PURE__ */ jsxs("span", {
|
|
474
|
+
className: "flex items-center gap-2",
|
|
475
|
+
children: [/* @__PURE__ */ jsx("kbd", {
|
|
476
|
+
className: "border-input rounded border px-1.5 font-mono",
|
|
477
|
+
children: key
|
|
478
|
+
}), meaning]
|
|
479
|
+
}, key)))
|
|
480
|
+
});
|
|
481
|
+
// src/features/play-media/ui/media-player.tsx
|
|
482
|
+
const FRAME = "size-full [&>iframe]:size-full [&>iframe]:border-0 [&>video]:size-full [&>video]:object-contain";
|
|
483
|
+
const Stage = () => {
|
|
484
|
+
const setStage = useAtomSet(stageAtom);
|
|
485
|
+
usePlayer();
|
|
486
|
+
const attach = useCallback((stage) => {
|
|
487
|
+
setStage(Option.fromNullishOr(stage));
|
|
488
|
+
return () => {
|
|
489
|
+
setStage(Option.none());
|
|
490
|
+
};
|
|
491
|
+
}, [setStage]);
|
|
492
|
+
return /* @__PURE__ */ jsx("div", {
|
|
493
|
+
className: "size-full",
|
|
494
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
495
|
+
ref: attach,
|
|
496
|
+
className: FRAME
|
|
497
|
+
})
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
const MediaPlayer = () => Option.match(useAtomValue(openedAtom), {
|
|
501
|
+
onNone: () => false,
|
|
502
|
+
onSome: ({ media, location }) => /* @__PURE__ */ jsx("div", {
|
|
503
|
+
className: "aspect-video w-full overflow-hidden rounded-md bg-black",
|
|
504
|
+
children: /* @__PURE__ */ jsx(Stage, {}, `${keyOf(media.source)}:${location}`)
|
|
505
|
+
})
|
|
506
|
+
});
|
|
507
|
+
// src/features/select-range/model/range.ts
|
|
508
|
+
/** @internal */
|
|
509
|
+
const perMedia = (initial) => Atom.writable((get) => {
|
|
510
|
+
get(openedAtom);
|
|
511
|
+
return initial;
|
|
512
|
+
}, (context, value) => {
|
|
513
|
+
context.setSelf(value);
|
|
514
|
+
}).pipe(Atom.keepAlive);
|
|
515
|
+
/** @internal */
|
|
516
|
+
const rangeAtom = perMedia(Option.none());
|
|
517
|
+
/** @internal */
|
|
518
|
+
const anchorAtom = perMedia(Option.none());
|
|
519
|
+
const spanOf = ([one, other]) => ({
|
|
520
|
+
from: Math.min(one, other),
|
|
521
|
+
to: Math.max(one, other)
|
|
522
|
+
});
|
|
523
|
+
// src/features/select-range/ui/range-readout.tsx
|
|
524
|
+
const DIGITS = 1;
|
|
525
|
+
const EMPTY = "–";
|
|
526
|
+
const RangeReadout = () => Option.match(useAtomValue(rangeAtom), {
|
|
527
|
+
onNone: () => /* @__PURE__ */ jsx("p", {
|
|
528
|
+
className: "text-muted-foreground font-mono text-sm tabular-nums",
|
|
529
|
+
children: EMPTY
|
|
530
|
+
}),
|
|
531
|
+
onSome: ({ from, to }) => /* @__PURE__ */ jsxs("p", {
|
|
532
|
+
className: "flex items-baseline justify-between font-mono text-sm tabular-nums",
|
|
533
|
+
children: [/* @__PURE__ */ jsx("span", { children: `${preciseClock(from)}–${preciseClock(to)}` }), /* @__PURE__ */ jsx("span", {
|
|
534
|
+
className: "text-muted-foreground text-xs",
|
|
535
|
+
children: `${(to - from).toFixed(DIGITS)} 秒`
|
|
536
|
+
})]
|
|
537
|
+
})
|
|
538
|
+
});
|
|
539
|
+
// src/features/select-range/ui/ruler.tsx
|
|
540
|
+
const WHOLE$1 = 100;
|
|
541
|
+
const SHORT_SONG = 600;
|
|
542
|
+
const SHORT_STEP = 30;
|
|
543
|
+
const LONG_STEP = 60;
|
|
544
|
+
const FIRST = 0;
|
|
545
|
+
const stepFor = (duration) => {
|
|
546
|
+
if (duration <= SHORT_SONG) return SHORT_STEP;
|
|
547
|
+
return LONG_STEP;
|
|
548
|
+
};
|
|
549
|
+
const Ruler = ({ duration }) => {
|
|
550
|
+
if (duration <= FIRST) return false;
|
|
551
|
+
const step = stepFor(duration);
|
|
552
|
+
const ticks = pipe(Array.range(FIRST, Math.floor(duration / step)), Array.map((index) => index * step));
|
|
553
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
554
|
+
className: "h-4 w-full overflow-visible",
|
|
555
|
+
"aria-hidden": true,
|
|
556
|
+
children: pipe(ticks, Array.map((seconds) => /* @__PURE__ */ jsx("text", {
|
|
557
|
+
x: `${seconds / duration * WHOLE$1}%`,
|
|
558
|
+
y: "75%",
|
|
559
|
+
className: "fill-muted-foreground font-mono text-xs tabular-nums",
|
|
560
|
+
children: clock(seconds)
|
|
561
|
+
}, seconds)))
|
|
562
|
+
});
|
|
563
|
+
};
|
|
564
|
+
// src/features/select-range/ui/lanes.ts
|
|
565
|
+
const MARK_LANE = {
|
|
566
|
+
y: "0%",
|
|
567
|
+
height: "22%"
|
|
568
|
+
};
|
|
569
|
+
const PLAY_LANE = {
|
|
570
|
+
y: "30%",
|
|
571
|
+
height: "70%"
|
|
572
|
+
};
|
|
573
|
+
const WHOLE_LANE = {
|
|
574
|
+
y: "0%",
|
|
575
|
+
height: "100%"
|
|
576
|
+
};
|
|
577
|
+
const HEAD = .25;
|
|
578
|
+
// src/features/select-range/ui/span-rect.tsx
|
|
579
|
+
const WHOLE = 100;
|
|
580
|
+
const NONE$1 = 0;
|
|
581
|
+
const FULL$1 = 1;
|
|
582
|
+
const percent = (seconds, duration) => {
|
|
583
|
+
if (duration <= NONE$1) return NONE$1;
|
|
584
|
+
return Math.min(Math.max(seconds / duration, NONE$1), FULL$1) * WHOLE;
|
|
585
|
+
};
|
|
586
|
+
const SpanRect = ({ from, to, duration, lane, className }) => /* @__PURE__ */ jsx("rect", {
|
|
587
|
+
x: `${percent(from, duration)}%`,
|
|
588
|
+
width: `${Math.max(percent(to, duration) - percent(from, duration), NONE$1)}%`,
|
|
589
|
+
y: lane.y,
|
|
590
|
+
height: lane.height,
|
|
591
|
+
className
|
|
592
|
+
});
|
|
593
|
+
// src/features/select-range/ui/range-layer.tsx
|
|
594
|
+
const RangeLayer = ({ duration }) => Option.match(useAtomValue(rangeAtom), {
|
|
595
|
+
onNone: () => false,
|
|
596
|
+
onSome: ({ from, to }) => /* @__PURE__ */ jsx(SpanRect, {
|
|
597
|
+
from,
|
|
598
|
+
to: Math.max(to, from + HEAD),
|
|
599
|
+
duration,
|
|
600
|
+
lane: WHOLE_LANE,
|
|
601
|
+
className: "fill-primary/15 stroke-primary"
|
|
602
|
+
})
|
|
603
|
+
});
|
|
604
|
+
// src/features/select-range/ui/spans-layer.tsx
|
|
605
|
+
const GUESS = "fill-none [stroke-dasharray:4_3] stroke-[1.5]";
|
|
606
|
+
const LOOK = {
|
|
607
|
+
plain: {
|
|
608
|
+
lane: MARK_LANE,
|
|
609
|
+
className: "fill-foreground/70"
|
|
610
|
+
},
|
|
611
|
+
warn: {
|
|
612
|
+
lane: MARK_LANE,
|
|
613
|
+
className: "fill-destructive/70"
|
|
614
|
+
},
|
|
615
|
+
faint: {
|
|
616
|
+
lane: MARK_LANE,
|
|
617
|
+
className: "fill-muted-foreground/30"
|
|
618
|
+
},
|
|
619
|
+
guess: {
|
|
620
|
+
lane: PLAY_LANE,
|
|
621
|
+
className: `${GUESS} stroke-foreground`
|
|
622
|
+
},
|
|
623
|
+
"guess-warn": {
|
|
624
|
+
lane: PLAY_LANE,
|
|
625
|
+
className: `${GUESS} stroke-destructive`
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
const SpansLayer = ({ spans, duration }) => pipe(spans, Array.map((span) => /* @__PURE__ */ jsx(SpanRect, {
|
|
629
|
+
from: span.from,
|
|
630
|
+
to: span.to,
|
|
631
|
+
duration,
|
|
632
|
+
lane: LOOK[span.tone].lane,
|
|
633
|
+
className: LOOK[span.tone].className
|
|
634
|
+
}, span.key)));
|
|
635
|
+
// src/features/select-range/ui/track.tsx
|
|
636
|
+
const START = 0;
|
|
637
|
+
const Track = ({ position, spans }) => /* @__PURE__ */ jsxs("svg", {
|
|
638
|
+
className: "size-full overflow-visible",
|
|
639
|
+
"aria-hidden": true,
|
|
640
|
+
children: [
|
|
641
|
+
/* @__PURE__ */ jsx(SpanRect, {
|
|
642
|
+
from: START,
|
|
643
|
+
to: position.duration,
|
|
644
|
+
duration: position.duration,
|
|
645
|
+
lane: PLAY_LANE,
|
|
646
|
+
className: "fill-muted"
|
|
647
|
+
}),
|
|
648
|
+
/* @__PURE__ */ jsx(SpansLayer, {
|
|
649
|
+
spans,
|
|
650
|
+
duration: position.duration
|
|
651
|
+
}),
|
|
652
|
+
/* @__PURE__ */ jsx(RangeLayer, { duration: position.duration }),
|
|
653
|
+
/* @__PURE__ */ jsx(SpanRect, {
|
|
654
|
+
from: position.current,
|
|
655
|
+
to: position.current + HEAD,
|
|
656
|
+
duration: position.duration,
|
|
657
|
+
lane: WHOLE_LANE,
|
|
658
|
+
className: "fill-foreground"
|
|
659
|
+
})
|
|
660
|
+
]
|
|
661
|
+
});
|
|
662
|
+
// src/features/select-range/ui/use-scrub.ts
|
|
663
|
+
const DRAG_PIXELS = 4;
|
|
664
|
+
const NONE = 0;
|
|
665
|
+
const FULL = 1;
|
|
666
|
+
const secondsAt = ({ element, duration }, x) => {
|
|
667
|
+
const { left, width } = element.getBoundingClientRect();
|
|
668
|
+
return Math.min(Math.max((x - left) / Math.max(width, FULL), NONE), FULL) * duration;
|
|
669
|
+
};
|
|
670
|
+
const down = (scrubbing, event) => {
|
|
671
|
+
scrubbing.element.setPointerCapture(event.pointerId);
|
|
672
|
+
scrubbing.press(Option.some({
|
|
673
|
+
seconds: secondsAt(scrubbing, event.clientX),
|
|
674
|
+
x: event.clientX,
|
|
675
|
+
dragged: false
|
|
676
|
+
}));
|
|
677
|
+
};
|
|
678
|
+
const move = (scrubbing, event) => {
|
|
679
|
+
const press = scrubbing.pressed();
|
|
680
|
+
if (Option.isNone(press)) return;
|
|
681
|
+
const { seconds, x, dragged } = press.value;
|
|
682
|
+
if (dragged || Math.abs(event.clientX - x) >= DRAG_PIXELS) {
|
|
683
|
+
scrubbing.press(Option.some({
|
|
684
|
+
seconds,
|
|
685
|
+
x,
|
|
686
|
+
dragged: true
|
|
687
|
+
}));
|
|
688
|
+
scrubbing.select(spanOf([seconds, secondsAt(scrubbing, event.clientX)]));
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
const up = (scrubbing, event) => {
|
|
692
|
+
const press = scrubbing.pressed();
|
|
693
|
+
if (Option.isSome(press) && !press.value.dragged) scrubbing.seek(secondsAt(scrubbing, event.clientX));
|
|
694
|
+
scrubbing.press(Option.none());
|
|
695
|
+
};
|
|
696
|
+
const POINTER_HANDLERS = {
|
|
697
|
+
pointerdown: down,
|
|
698
|
+
pointermove: move,
|
|
699
|
+
pointerup: up
|
|
700
|
+
};
|
|
701
|
+
const listen$1 = (scrubbing) => {
|
|
702
|
+
const bound = pipe(POINTER_HANDLERS, Record.map((handle) => (event) => {
|
|
703
|
+
handle(scrubbing, event);
|
|
704
|
+
}));
|
|
705
|
+
const entries = Record.toEntries(bound);
|
|
706
|
+
for (const [type, listener] of entries) scrubbing.element.addEventListener(type, listener);
|
|
707
|
+
return () => {
|
|
708
|
+
for (const [type, listener] of entries) scrubbing.element.removeEventListener(type, listener);
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
const useScrub = ({ duration, seek }) => {
|
|
712
|
+
const setRange = useAtomSet(rangeAtom);
|
|
713
|
+
const press = useMemo(() => MutableRef.make(Option.none()), []);
|
|
714
|
+
return useCallback((element) => Option.match(Option.fromNullishOr(element), {
|
|
715
|
+
onNone: () => constVoid,
|
|
716
|
+
onSome: (found) => listen$1({
|
|
717
|
+
element: found,
|
|
718
|
+
duration,
|
|
719
|
+
seek,
|
|
720
|
+
pressed: () => MutableRef.get(press),
|
|
721
|
+
press: (next) => {
|
|
722
|
+
MutableRef.set(press, next);
|
|
723
|
+
},
|
|
724
|
+
select: (range) => {
|
|
725
|
+
setRange(Option.some(range));
|
|
726
|
+
}
|
|
727
|
+
})
|
|
728
|
+
}), [
|
|
729
|
+
duration,
|
|
730
|
+
seek,
|
|
731
|
+
setRange,
|
|
732
|
+
press
|
|
733
|
+
]);
|
|
734
|
+
};
|
|
735
|
+
// src/features/select-range/ui/timeline.tsx
|
|
736
|
+
const Timeline = ({ position, spans, seek }) => {
|
|
737
|
+
const attach = useScrub({
|
|
738
|
+
duration: position.duration,
|
|
739
|
+
seek
|
|
740
|
+
});
|
|
741
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
742
|
+
className: "grid gap-1",
|
|
743
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
744
|
+
ref: attach,
|
|
745
|
+
className: "h-16 cursor-crosshair touch-pan-y select-none",
|
|
746
|
+
children: /* @__PURE__ */ jsx(Track, {
|
|
747
|
+
position,
|
|
748
|
+
spans
|
|
749
|
+
})
|
|
750
|
+
}), /* @__PURE__ */ jsx(Ruler, { duration: position.duration })]
|
|
751
|
+
});
|
|
752
|
+
};
|
|
753
|
+
// src/features/select-range/ui/use-range-key.ts
|
|
754
|
+
const KEY = "m";
|
|
755
|
+
const useRangeKey = (player) => {
|
|
756
|
+
const anchor = useAtomValue(anchorAtom);
|
|
757
|
+
const setAnchor = useAtomSet(anchorAtom);
|
|
758
|
+
const setRange = useAtomSet(rangeAtom);
|
|
759
|
+
useEffect(() => {
|
|
760
|
+
const mark = (now) => {
|
|
761
|
+
Option.match(anchor, {
|
|
762
|
+
onNone: () => {
|
|
763
|
+
setAnchor(Option.some(now));
|
|
764
|
+
setRange(Option.some({
|
|
765
|
+
from: now,
|
|
766
|
+
to: now
|
|
767
|
+
}));
|
|
768
|
+
},
|
|
769
|
+
onSome: (start) => {
|
|
770
|
+
setAnchor(Option.none());
|
|
771
|
+
setRange(Option.some(spanOf([start, now])));
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
const onKey = (event) => {
|
|
776
|
+
if (String$1.toLowerCase(event.key) !== KEY || ignoredKey(event)) return;
|
|
777
|
+
if (Option.isSome(player)) mark(player.value.time().current);
|
|
778
|
+
};
|
|
779
|
+
globalThis.addEventListener("keydown", onKey);
|
|
780
|
+
return () => {
|
|
781
|
+
globalThis.removeEventListener("keydown", onKey);
|
|
782
|
+
};
|
|
783
|
+
}, [
|
|
784
|
+
player,
|
|
785
|
+
anchor,
|
|
786
|
+
setAnchor,
|
|
787
|
+
setRange
|
|
788
|
+
]);
|
|
789
|
+
};
|
|
790
|
+
// src/widgets/media-stage/ui/media-stage.tsx
|
|
791
|
+
const MediaStage = ({ media, spans, hints }) => {
|
|
792
|
+
const player = usePlayer();
|
|
793
|
+
const position = usePosition();
|
|
794
|
+
useRangeKey(player);
|
|
795
|
+
usePlayKey(player);
|
|
796
|
+
const seek = useCallback((seconds) => {
|
|
797
|
+
if (Option.isSome(player)) player.value.seek(seconds);
|
|
798
|
+
}, [player]);
|
|
799
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
800
|
+
className: "grid content-start gap-3 lg:col-span-2",
|
|
801
|
+
children: [
|
|
802
|
+
/* @__PURE__ */ jsx(MediaMeta, {
|
|
803
|
+
media,
|
|
804
|
+
duration: position.duration
|
|
805
|
+
}),
|
|
806
|
+
/* @__PURE__ */ jsx(MediaPlayer, {}),
|
|
807
|
+
/* @__PURE__ */ jsx(Timeline, {
|
|
808
|
+
position,
|
|
809
|
+
spans,
|
|
810
|
+
seek
|
|
811
|
+
}),
|
|
812
|
+
/* @__PURE__ */ jsx(KeyHints, { hints })
|
|
813
|
+
]
|
|
814
|
+
});
|
|
815
|
+
};
|
|
816
|
+
// src/widgets/media-stage/model/use-jump.ts
|
|
817
|
+
const useJump = () => {
|
|
818
|
+
const player = usePlayer();
|
|
819
|
+
const setRange = useAtomSet(rangeAtom);
|
|
820
|
+
return useCallback(({ from, to }) => {
|
|
821
|
+
setRange(Option.some({
|
|
822
|
+
from,
|
|
823
|
+
to
|
|
824
|
+
}));
|
|
825
|
+
if (Option.isSome(player)) player.value.seek(from);
|
|
826
|
+
}, [player, setRange]);
|
|
827
|
+
};
|
|
828
|
+
// src/app/desktop-media-notes-model-save-range.ts
|
|
829
|
+
/** @internal */
|
|
830
|
+
const savedRange = (post) => Effect.gen(function* saving() {
|
|
831
|
+
const registry = yield* AtomRegistry.AtomRegistry;
|
|
832
|
+
yield* post(yield* Effect.fromOption(registry.get(openedAtom)), yield* Effect.fromOption(registry.get(rangeAtom)));
|
|
833
|
+
registry.set(rangeAtom, Option.none());
|
|
834
|
+
registry.set(anchorAtom, Option.none());
|
|
835
|
+
return registry;
|
|
836
|
+
});
|
|
837
|
+
// src/shared/lib/use-submit.ts
|
|
838
|
+
/** @internal */
|
|
839
|
+
const useSubmit = (save) => {
|
|
840
|
+
const [saved, run] = useAtom(save);
|
|
841
|
+
const submit = useCallback((event) => {
|
|
842
|
+
event.preventDefault();
|
|
843
|
+
run();
|
|
844
|
+
}, [run]);
|
|
845
|
+
return {
|
|
846
|
+
waiting: saved.waiting,
|
|
847
|
+
submit
|
|
848
|
+
};
|
|
849
|
+
};
|
|
850
|
+
// src/shared/lib/use-following.ts
|
|
851
|
+
const following = ({ event, refresh }) => Effect.acquireRelease(Effect.promise(() => listen(event, refresh)), (stop) => Effect.sync(stop)).pipe(Effect.andThen(Effect.never), Effect.scoped);
|
|
852
|
+
const useFollowing = ({ event, refresh }) => {
|
|
853
|
+
useEffect(() => {
|
|
854
|
+
const fiber = Effect.runFork(following({
|
|
855
|
+
event,
|
|
856
|
+
refresh
|
|
857
|
+
}));
|
|
858
|
+
return () => {
|
|
859
|
+
fiber.pipe(Fiber.interrupt, Effect.runFork);
|
|
860
|
+
};
|
|
861
|
+
}, [event, refresh]);
|
|
862
|
+
};
|
|
863
|
+
export { ApiFailed, CopyMcpCommand, KeyHints, MediaMeta, MediaPlayer, MediaStage, OpenBar, RangeReadout, SITE_NAMES, Timeline, anchorAtom, chooseFileAtom, clock, ignoredKey, keyOf, linkAtom, openFileAtom, openLinkAtom, openedAtom, pageOf, perMedia, preciseClock, rangeAtom, runtime, savedRange, settled, settledAs, useFollowing, useJump, usePlayKey, usePlayer, usePosition, useRangeKey, useSubmit };
|
|
864
|
+
|
|
865
|
+
//# sourceMappingURL=media-notes.mjs.map
|