@avoid.quest/audio 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -2
- package/dist/effects/index.d.ts +266 -0
- package/dist/effects/index.js +744 -0
- package/dist/effects/index.js.map +1 -0
- package/dist/errors-BT9HxDLn.js +74 -0
- package/dist/errors-BT9HxDLn.js.map +1 -0
- package/dist/errors-ChTQFwuZ.d.ts +53 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/midi/index.d.ts +162 -0
- package/dist/midi/index.js +338 -0
- package/dist/midi/index.js.map +1 -0
- package/dist/playback/index.d.ts +349 -0
- package/dist/playback/index.js +1372 -0
- package/dist/playback/index.js.map +1 -0
- package/dist/queue/index.d.ts +144 -0
- package/dist/queue/index.js +1062 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/recognize/index.d.ts +161 -0
- package/dist/recognize/index.js +2816 -0
- package/dist/recognize/index.js.map +1 -0
- package/dist/routing/index.d.ts +140 -0
- package/dist/routing/index.js +678 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sync/index.d.ts +282 -0
- package/dist/sync/index.js +1103 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/worklet-loader-BvEW0oVO.d.ts +44 -0
- package/dist/worklet-loader-S7R8ZAmP.js +175 -0
- package/dist/worklet-loader-S7R8ZAmP.js.map +1 -0
- package/dist/worklets/couch-live.d.ts +1 -0
- package/dist/worklets/couch-live.js +365 -0
- package/dist/worklets/couch-live.js.map +1 -0
- package/dist/worklets/meter.d.ts +7 -0
- package/dist/worklets/meter.js +80 -0
- package/dist/worklets/meter.js.map +1 -0
- package/package.json +109 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/queue/shuffle.ts","../../src/queue/types.ts","../../src/queue/state.ts"],"sourcesContent":["/* oxlint-disable eslint/no-bitwise */\n\n/**\n * Mulberry32 deterministic 32-bit PRNG returning values in `[0, 1)`.\n */\nexport function createSeededRandom(seed: number): () => number {\n let state = seed >>> 0;\n return () => {\n state = (state + 0x6d_2b_79_f5) >>> 0;\n let t = Math.imul(state ^ (state >>> 15), 1 | state);\n t ^= t + Math.imul(t ^ (t >>> 7), 61 | t);\n return ((t ^ (t >>> 14)) >>> 0) / 4_294_967_296;\n };\n}\n\n/**\n * Deterministic Fisher-Yates shuffle returning a new array without mutating the input.\n */\nexport function fisherYatesShuffle<T>(items: readonly T[], seed: number): T[] {\n const result = [...items];\n const random = createSeededRandom(seed);\n for (let i = result.length - 1; i > 0; i -= 1) {\n const j = Math.floor(random() * (i + 1));\n const current = result[i];\n const swap = result[j];\n if (current !== undefined && swap !== undefined) {\n result[i] = swap;\n result[j] = current;\n }\n }\n return result;\n}\n","import { Schema } from \"effect\";\n\nexport const RepeatModeSchema = Schema.Literals([\"off\", \"one\", \"all\"]);\nexport type RepeatMode = typeof RepeatModeSchema.Type;\n\nexport const EnqueuePlacementSchema = Schema.Literals([\"end\", \"next\"]);\nexport type EnqueuePlacement = typeof EnqueuePlacementSchema.Type;\n\nexport const QueueLoadModeSchema = Schema.Literals([\n \"replace\",\n \"append\",\n \"play\",\n]);\nexport type QueueLoadMode = typeof QueueLoadModeSchema.Type;\n\nexport const UrlRenewalReasonSchema = Schema.Literals([\n \"proactive\",\n \"expired\",\n \"playback-error\",\n \"early-end\",\n]);\nexport type UrlRenewalReason = typeof UrlRenewalReasonSchema.Type;\n\nexport interface QueueEntry<T = unknown> {\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly durationSeconds?: number;\n readonly expiresAtMs?: number;\n readonly meta?: T;\n}\n\nexport interface AutoplayContinuation<T = unknown> {\n readonly title?: string;\n readonly entries: readonly QueueEntry<T>[];\n}\n\nexport interface RemovedEntryPosition<T = unknown> {\n readonly entry: QueueEntry<T>;\n readonly index: number;\n}\n\nexport interface UndoRemovalSnapshot<T = unknown> {\n readonly token: string;\n readonly entries: readonly QueueEntry<T>[];\n readonly positions: readonly RemovedEntryPosition<T>[];\n readonly priorOriginalOrder: readonly string[];\n readonly index: number;\n readonly queueIds: readonly string[];\n readonly currentEntryId: string | undefined;\n readonly expiresAtMs: number;\n}\n\nexport interface UndoStopSnapshot {\n readonly token: string;\n readonly entryId: string;\n readonly cursor: number;\n readonly positionSeconds: number;\n readonly paused: boolean;\n readonly expiresAtMs: number;\n readonly mutated: boolean;\n}\n\nexport interface QueueState<T = unknown> {\n readonly entries: readonly QueueEntry<T>[];\n readonly cursor: number;\n readonly repeat: RepeatMode;\n readonly shuffle: boolean;\n readonly shuffleSeed: number | undefined;\n readonly originalOrder: readonly string[];\n readonly history: readonly QueueEntry<T>[];\n readonly continuation: AutoplayContinuation<T> | undefined;\n readonly undoRemoval: UndoRemovalSnapshot<T> | undefined;\n readonly undoStop: UndoStopSnapshot | undefined;\n}\n\nexport interface RenewedStreamUrl {\n readonly url: string;\n readonly expiresAtMs?: number;\n readonly durationSeconds?: number;\n}\n\nexport const DEFAULT_MAX_QUEUE_ENTRIES = 500;\nexport const DEFAULT_UNDO_REMOVAL_TTL_MS = 6000;\nexport const DEFAULT_UNDO_STOP_TTL_MS = 11_000;\nexport const DEFAULT_URL_RENEW_AHEAD_MS = 60_000;\n","import { Context, Effect, Layer, Ref } from \"effect\";\nimport * as Atom from \"effect/reactivity/Atom\";\nimport * as AtomRef from \"effect/reactivity/AtomRef\";\n\nimport { AudioQueueError } from \"../errors.ts\";\nimport { fisherYatesShuffle } from \"./shuffle.ts\";\nimport {\n DEFAULT_MAX_QUEUE_ENTRIES,\n DEFAULT_UNDO_REMOVAL_TTL_MS,\n DEFAULT_UNDO_STOP_TTL_MS,\n DEFAULT_URL_RENEW_AHEAD_MS,\n} from \"./types.ts\";\nimport type {\n AutoplayContinuation,\n EnqueuePlacement,\n QueueEntry,\n QueueLoadMode,\n QueueState,\n RenewedStreamUrl,\n RepeatMode,\n UrlRenewalReason,\n} from \"./types.ts\";\n\nexport interface QueueOptions<T = unknown> {\n readonly maxEntries?: number;\n readonly undoRemovalTtlMs?: number;\n readonly undoStopTtlMs?: number;\n readonly renewAheadMs?: number;\n readonly now?: () => number;\n readonly nextToken?: () => string;\n readonly initialEntries?: readonly QueueEntry<T>[];\n readonly onAutoplay?: (\n lastEntry: QueueEntry<T>,\n state: QueueState<T>\n ) => Effect.Effect<AutoplayContinuation<T> | undefined, AudioQueueError>;\n readonly onRenewUrl?: (\n entry: QueueEntry<T>,\n reason: UrlRenewalReason\n ) => Effect.Effect<RenewedStreamUrl, AudioQueueError>;\n}\n\nexport interface RemoveResult<T = unknown> {\n readonly state: QueueState<T>;\n readonly removed: readonly QueueEntry<T>[];\n readonly undoToken: string | undefined;\n}\n\nexport interface StopResult<T = unknown> {\n readonly state: QueueState<T>;\n readonly undoToken: string | undefined;\n}\n\nexport interface UndoStopResult<T = unknown> {\n readonly state: QueueState<T>;\n readonly positionSeconds: number;\n readonly paused: boolean;\n}\n\nexport interface AudioQueue<T = unknown> {\n readonly ref: Ref.Ref<QueueState<T>>;\n readonly atomRef: AtomRef.AtomRef<QueueState<T>>;\n readonly stateAtom: Atom.Atom<QueueState<T>>;\n readonly getState: Effect.Effect<QueueState<T>>;\n readonly currentEntry: Effect.Effect<QueueEntry<T> | undefined>;\n readonly upcoming: Effect.Effect<readonly QueueEntry<T>[]>;\n readonly enqueue: (\n entries: readonly QueueEntry<T>[],\n placement?: EnqueuePlacement\n ) => Effect.Effect<QueueState<T>, AudioQueueError>;\n readonly load: (\n entries: readonly QueueEntry<T>[],\n mode?: QueueLoadMode\n ) => Effect.Effect<QueueState<T>, AudioQueueError>;\n readonly remove: (\n entryIds: readonly string[]\n ) => Effect.Effect<RemoveResult<T>, AudioQueueError>;\n readonly clearUpNext: () => Effect.Effect<RemoveResult<T>>;\n readonly restoreRemoved: (\n token: string\n ) => Effect.Effect<QueueState<T>, AudioQueueError>;\n readonly move: (\n entryId: string,\n beforeEntryId: string | undefined\n ) => Effect.Effect<QueueState<T>, AudioQueueError>;\n readonly jumpTo: (\n entryId: string\n ) => Effect.Effect<QueueEntry<T>, AudioQueueError>;\n readonly next: () => Effect.Effect<\n QueueEntry<T> | undefined,\n AudioQueueError\n >;\n readonly previous: () => Effect.Effect<QueueEntry<T> | undefined>;\n readonly setRepeat: (mode: RepeatMode) => Effect.Effect<QueueState<T>>;\n readonly setShuffle: (\n enabled: boolean,\n seed?: number\n ) => Effect.Effect<QueueState<T>>;\n readonly setContinuation: (\n continuation: AutoplayContinuation<T> | undefined\n ) => Effect.Effect<QueueState<T>>;\n readonly stop: (\n positionSeconds?: number,\n paused?: boolean\n ) => Effect.Effect<StopResult<T>>;\n readonly undoStop: (\n token: string\n ) => Effect.Effect<UndoStopResult<T>, AudioQueueError>;\n readonly renewEntryUrl: (\n entryId: string,\n reason?: UrlRenewalReason\n ) => Effect.Effect<QueueEntry<T>, AudioQueueError>;\n readonly ensureFreshUrl: (\n entryId: string\n ) => Effect.Effect<QueueEntry<T>, AudioQueueError>;\n}\n\nexport class QueueService extends Context.Service<\n QueueService,\n AudioQueue<unknown>\n>()(\"@avoid.quest/audio/QueueService\") {}\n\nconst EXPIRE_PATH_REGEX = /\\/expire\\/(?<epoch>\\d{9,11})(?:\\/|$)/iu;\nconst EXPIRE_JSON_REGEX = /\"expires\"\\s*:\\s*(?<epoch>\\d{9,11})/u;\nconst EXPIRE_DIGITS_REGEX = /^\\d{9,11}$/u;\n\n/**\n * Extracts a Unix epoch millisecond expiry timestamp from signed media URLs\n * (`?expire=`, `?expires=`, `?ts=`, `/expire/<sec>/`, or JSON `\"expires\": <sec>`).\n */\nexport function extractLinkExpiryMs(url: string): number | undefined {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return undefined;\n }\n\n for (const key of [\"expire\", \"expires\"]) {\n const val = parsed.searchParams.get(key);\n if (val !== null && EXPIRE_DIGITS_REGEX.test(val)) {\n return Number(val) * 1000;\n }\n }\n\n const pathMatch = EXPIRE_PATH_REGEX.exec(parsed.pathname);\n if (pathMatch?.groups?.epoch !== undefined) {\n return Number(pathMatch.groups.epoch) * 1000;\n }\n\n for (const value of parsed.searchParams.values()) {\n const jsonMatch = EXPIRE_JSON_REGEX.exec(value);\n if (jsonMatch?.groups?.epoch !== undefined) {\n return Number(jsonMatch.groups.epoch) * 1000;\n }\n }\n\n return undefined;\n}\n\n/**\n * Checks whether a queue entry's URL is expired or within `renewAheadMs` of expiry.\n */\nexport function isUrlExpiringSoon<T>(\n entry: QueueEntry<T>,\n nowMs: number = Date.now(),\n renewAheadMs: number = DEFAULT_URL_RENEW_AHEAD_MS\n): boolean {\n const expiry = entry.expiresAtMs ?? extractLinkExpiryMs(entry.url);\n if (expiry === undefined) {\n return false;\n }\n return expiry - nowMs < renewAheadMs;\n}\n\nexport function createInitialQueueState<T = unknown>(\n initialEntries: readonly QueueEntry<T>[] = []\n): QueueState<T> {\n return {\n continuation: undefined,\n cursor: initialEntries.length > 0 ? 0 : -1,\n entries: [...initialEntries],\n history: [],\n originalOrder: initialEntries.map((entry) => entry.id),\n repeat: \"off\",\n shuffle: false,\n shuffleSeed: undefined,\n undoRemoval: undefined,\n undoStop: undefined,\n };\n}\n\nfunction defaultTokenGenerator(): () => string {\n let counter = 0;\n return () => {\n if (\n globalThis.crypto !== undefined &&\n typeof globalThis.crypto.randomUUID === \"function\"\n ) {\n return globalThis.crypto.randomUUID();\n }\n counter += 1;\n return `undo-${Date.now()}-${counter}`;\n };\n}\n\nfunction appendHistory<T>(\n history: readonly QueueEntry<T>[],\n entry: QueueEntry<T> | undefined,\n maxEntries: number\n): readonly QueueEntry<T>[] {\n if (!entry) {\n return history;\n }\n const next = [...history, entry];\n return next.length > maxEntries ? next.slice(next.length - maxEntries) : next;\n}\n\nfunction markUndoStopMutated<T>(state: QueueState<T>): QueueState<T> {\n if (!state.undoStop || state.undoStop.mutated) {\n return state;\n }\n return {\n ...state,\n undoStop: { ...state.undoStop, mutated: true },\n };\n}\n\nfunction arraysEqual(a: readonly string[], b: readonly string[]): boolean {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i += 1) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Removes exact per-ID occurrence counts from `order` (scanning from the right\n * so earlier retained duplicate occurrences keep their original positions).\n */\nfunction removeOccurrencesFromOrder<T>(\n order: readonly string[],\n removedEntries: readonly QueueEntry<T>[]\n): string[] {\n if (removedEntries.length === 0) {\n return [...order];\n }\n const counts = new Map<string, number>();\n for (const entry of removedEntries) {\n counts.set(entry.id, (counts.get(entry.id) ?? 0) + 1);\n }\n const kept: string[] = [];\n for (let i = order.length - 1; i >= 0; i -= 1) {\n const id = order[i];\n if (id === undefined) {\n continue;\n }\n const remaining = counts.get(id) ?? 0;\n if (remaining > 0) {\n counts.set(id, remaining - 1);\n } else {\n kept.push(id);\n }\n }\n kept.reverse();\n return kept;\n}\n\n/**\n * Finds the index in `originalOrder` corresponding to the entry at `cursor`\n * (respecting duplicate IDs by matching occurrence rank).\n */\nfunction findCursorIndexInOrder<T>(state: QueueState<T>): number {\n if (state.cursor < 0) {\n return -1;\n }\n const current = state.entries[state.cursor];\n if (!current) {\n return -1;\n }\n let occurrence = 0;\n for (let i = 0; i < state.cursor; i += 1) {\n if (state.entries[i]?.id === current.id) {\n occurrence += 1;\n }\n }\n let seen = 0;\n for (let i = 0; i < state.originalOrder.length; i += 1) {\n if (state.originalOrder[i] === current.id) {\n if (seen === occurrence) {\n return i;\n }\n seen += 1;\n }\n }\n return state.originalOrder.indexOf(current.id);\n}\n\nfunction updateOriginalOrderOnMove<T>(\n state: QueueState<T>,\n nextEntries: readonly QueueEntry<T>[],\n entryId: string,\n beforeEntryId: string | undefined\n): readonly string[] {\n if (!state.shuffle) {\n return nextEntries.map((entry) => entry.id);\n }\n const orderFromIndex = state.originalOrder.indexOf(entryId);\n if (orderFromIndex === -1) {\n return state.originalOrder;\n }\n const without = [\n ...state.originalOrder.slice(0, orderFromIndex),\n ...state.originalOrder.slice(orderFromIndex + 1),\n ];\n let orderToIndex = without.length;\n if (beforeEntryId !== undefined) {\n const targetIdx = without.indexOf(beforeEntryId);\n if (targetIdx !== -1) {\n orderToIndex = targetIdx;\n }\n }\n return [\n ...without.slice(0, orderToIndex),\n entryId,\n ...without.slice(orderToIndex),\n ];\n}\n\nfunction advanceWithContinuation<T>(\n state: QueueState<T>,\n continuation: AutoplayContinuation<T>,\n current: QueueEntry<T> | undefined,\n maxEntries: number\n):\n | {\n readonly nextEntry: QueueEntry<T>;\n readonly nextState: QueueState<T>;\n }\n | undefined {\n const [nextEntry, ...rest] = continuation.entries;\n if (!nextEntry) {\n return undefined;\n }\n\n const keepCount = maxEntries - 1;\n let trimmedEntries = [...state.entries];\n let trimmedCursor = state.cursor;\n let droppedEntries: readonly QueueEntry<T>[] = [];\n\n // Trim oldest entries when at max capacity; handle maxEntries === 1 without slice(-0)\n if (trimmedEntries.length >= maxEntries) {\n if (keepCount <= 0) {\n droppedEntries = trimmedEntries;\n trimmedEntries = [];\n trimmedCursor = -1;\n } else if (trimmedCursor > 0) {\n const dropCount = trimmedEntries.length - keepCount;\n droppedEntries = trimmedEntries.slice(0, dropCount);\n trimmedEntries = trimmedEntries.slice(dropCount);\n trimmedCursor = Math.max(-1, trimmedCursor - dropCount);\n } else {\n const dropCount = trimmedEntries.length - keepCount;\n droppedEntries = trimmedEntries.slice(0, dropCount);\n trimmedEntries = trimmedEntries.slice(-keepCount);\n trimmedCursor = trimmedEntries.length - 1;\n }\n }\n\n const nextEntries = [...trimmedEntries, nextEntry];\n const newCursor = trimmedCursor + 1;\n const trimmedOrder = removeOccurrencesFromOrder(\n state.originalOrder,\n droppedEntries\n );\n const nextOriginal = [...trimmedOrder, nextEntry.id].slice(-maxEntries);\n\n return {\n nextEntry,\n nextState: {\n ...state,\n continuation:\n rest.length > 0\n ? { entries: rest, title: continuation.title }\n : undefined,\n cursor: newCursor,\n entries: nextEntries,\n history: appendHistory(state.history, current, maxEntries),\n originalOrder: nextOriginal,\n undoStop: undefined,\n },\n };\n}\n\n/**\n * Restores `originalOrder` while preserving exact per-occurrence identity for\n * duplicate item IDs via pre-shuffle rank ordering.\n */\nfunction unshuffleEntries<T>(\n state: QueueState<T>,\n preShuffleRank?: WeakMap<QueueEntry<T>, number>\n): {\n readonly entries: readonly QueueEntry<T>[];\n readonly cursor: number;\n} {\n const current = state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n const buckets = new Map<string, { items: QueueEntry<T>[]; offset: number }>();\n for (const entry of state.entries) {\n const bucket = buckets.get(entry.id);\n if (bucket) {\n bucket.items.push(entry);\n } else {\n buckets.set(entry.id, { items: [entry], offset: 0 });\n }\n }\n\n if (preShuffleRank) {\n for (const bucket of buckets.values()) {\n if (bucket.items.length > 1) {\n bucket.items.sort(\n (a, b) =>\n (preShuffleRank.get(a) ?? Number.MAX_SAFE_INTEGER) -\n (preShuffleRank.get(b) ?? Number.MAX_SAFE_INTEGER)\n );\n }\n }\n }\n\n const restored: QueueEntry<T>[] = [];\n for (const id of state.originalOrder) {\n const bucket = buckets.get(id);\n if (bucket && bucket.offset < bucket.items.length) {\n const item = bucket.items[bucket.offset];\n bucket.offset += 1;\n if (item !== undefined) {\n restored.push(item);\n }\n }\n }\n\n for (const bucket of buckets.values()) {\n while (bucket.offset < bucket.items.length) {\n const item = bucket.items[bucket.offset];\n bucket.offset += 1;\n if (item !== undefined) {\n restored.push(item);\n }\n }\n }\n\n let nextCursor = state.cursor;\n if (current !== undefined) {\n const refIdx = restored.indexOf(current);\n nextCursor =\n refIdx === -1\n ? restored.findIndex((entry) => entry.id === current.id)\n : refIdx;\n }\n\n return { cursor: nextCursor, entries: restored };\n}\n\ntype AtomicOutcome<A, T> =\n | {\n readonly ok: true;\n readonly value: A;\n readonly nextState: QueueState<T>;\n readonly changed?: boolean;\n }\n | {\n readonly ok: false;\n readonly error: AudioQueueError;\n readonly nextState?: QueueState<T>;\n };\n\n/**\n * Creates a DOM-free Effect v4 reactive audio queue backed by atomic `Ref.modify`\n * transitions, `AtomRef`, and `Atom` (`effect/reactivity`).\n */\nexport function createAudioQueue<T = unknown>(\n options: QueueOptions<T> = {}\n): Effect.Effect<AudioQueue<T>> {\n return Effect.gen(function* () {\n const maxEntries = Math.max(\n 1,\n Math.floor(options.maxEntries ?? DEFAULT_MAX_QUEUE_ENTRIES)\n );\n const undoRemovalTtlMs =\n options.undoRemovalTtlMs ?? DEFAULT_UNDO_REMOVAL_TTL_MS;\n const undoStopTtlMs = options.undoStopTtlMs ?? DEFAULT_UNDO_STOP_TTL_MS;\n const renewAheadMs = options.renewAheadMs ?? DEFAULT_URL_RENEW_AHEAD_MS;\n const now = options.now ?? (() => Date.now());\n const nextToken = options.nextToken ?? defaultTokenGenerator();\n\n const initialEntries = (options.initialEntries ?? []).slice(0, maxEntries);\n const initialState = createInitialQueueState<T>(initialEntries);\n\n const ref = yield* Ref.make<QueueState<T>>(initialState);\n const atomRef = AtomRef.make<QueueState<T>>(initialState);\n const stateAtom = Atom.readable<QueueState<T>>((get) => {\n const unsubscribe = atomRef.subscribe((value) => {\n get.setSelf(value);\n });\n get.addFinalizer(unsubscribe);\n return atomRef.value;\n });\n const preShuffleRank = new WeakMap<QueueEntry<T>, number>();\n let generation = 0;\n\n const publishState = (nextState: QueueState<T>): Effect.Effect<void> =>\n Effect.sync(() => {\n atomRef.set(nextState);\n });\n\n const modifyState = <A>(\n fn: (\n state: QueueState<T>\n ) => readonly [result: A, nextState: QueueState<T>, changed?: boolean]\n ): Effect.Effect<A> =>\n Ref.modify(ref, (state) => {\n const [result, nextState, explicitChanged] = fn(state);\n const changed = explicitChanged ?? nextState !== state;\n if (changed) {\n generation += 1;\n }\n return [{ changed, nextState, result }, nextState] as const;\n }).pipe(\n Effect.tap(({ changed, nextState }) =>\n changed ? publishState(nextState) : Effect.void\n ),\n Effect.map(({ result }) => result)\n );\n\n const modifyStateOrFail = <A>(\n fn: (state: QueueState<T>) => AtomicOutcome<A, T>\n ): Effect.Effect<A, AudioQueueError> =>\n Ref.modify(\n ref,\n (\n state\n ): readonly [\n {\n readonly changed: boolean;\n readonly nextState: QueueState<T>;\n readonly outcome: AtomicOutcome<A, T>;\n },\n QueueState<T>,\n ] => {\n const outcome = fn(state);\n if (outcome.ok) {\n const changed = outcome.changed ?? outcome.nextState !== state;\n if (changed) {\n generation += 1;\n }\n return [\n { changed, nextState: outcome.nextState, outcome },\n outcome.nextState,\n ];\n }\n const nextState = outcome.nextState ?? state;\n const changed = nextState !== state;\n if (changed) {\n generation += 1;\n }\n return [{ changed, nextState, outcome }, nextState];\n }\n ).pipe(\n Effect.tap(({ changed, nextState }) =>\n changed ? publishState(nextState) : Effect.void\n ),\n Effect.flatMap(({ outcome }) =>\n outcome.ok\n ? Effect.succeed(outcome.value)\n : Effect.fail(outcome.error)\n )\n );\n\n const getState = Ref.get(ref);\n\n const currentEntry = getState.pipe(\n Effect.map((state) =>\n state.cursor >= 0 ? state.entries[state.cursor] : undefined\n )\n );\n\n const upcoming = getState.pipe(\n Effect.map((state) =>\n state.cursor >= 0\n ? state.entries.slice(state.cursor + 1)\n : state.entries\n )\n );\n\n const enqueue = (\n entries: readonly QueueEntry<T>[],\n placement: EnqueuePlacement = \"end\"\n ): Effect.Effect<QueueState<T>, AudioQueueError> =>\n modifyStateOrFail((rawState) => {\n if (entries.length === 0) {\n const state = markUndoStopMutated(rawState);\n return {\n changed: state !== rawState,\n nextState: state,\n ok: true,\n value: state,\n };\n }\n const state = markUndoStopMutated(rawState);\n if (state.entries.length + entries.length > maxEntries) {\n return {\n error: new AudioQueueError({\n code: \"QUEUE_FULL\",\n message: `Queue capacity of ${maxEntries} entries exceeded.`,\n }),\n ok: false,\n };\n }\n\n const insertAt =\n placement === \"next\" && state.cursor >= 0\n ? state.cursor + 1\n : state.entries.length;\n const nextEntries = [\n ...state.entries.slice(0, insertAt),\n ...entries,\n ...state.entries.slice(insertAt),\n ];\n\n const newIds = entries.map((entry) => entry.id);\n let nextOriginal: readonly string[];\n if (!state.shuffle) {\n nextOriginal = nextEntries.map((entry) => entry.id);\n } else if (placement === \"next\" && state.cursor >= 0) {\n const orderAnchor = findCursorIndexInOrder(state);\n const orderInsertAt =\n orderAnchor === -1\n ? Math.min(insertAt, state.originalOrder.length)\n : orderAnchor + 1;\n nextOriginal = [\n ...state.originalOrder.slice(0, orderInsertAt),\n ...newIds,\n ...state.originalOrder.slice(orderInsertAt),\n ];\n } else {\n nextOriginal = [...state.originalOrder, ...newIds];\n }\n\n const nextCursor = state.cursor === -1 ? 0 : state.cursor;\n const nextState: QueueState<T> = {\n ...state,\n cursor: nextCursor,\n entries: nextEntries,\n originalOrder: nextOriginal,\n undoRemoval: undefined,\n };\n return {\n changed: true,\n nextState,\n ok: true,\n value: nextState,\n };\n });\n\n const load = (\n entries: readonly QueueEntry<T>[],\n mode: QueueLoadMode = \"replace\"\n ): Effect.Effect<QueueState<T>, AudioQueueError> => {\n if (mode === \"append\") {\n return enqueue(entries, \"end\");\n }\n return modifyStateOrFail((prev) => {\n if (entries.length > maxEntries) {\n return {\n error: new AudioQueueError({\n code: \"QUEUE_FULL\",\n message: `Cannot load ${entries.length} entries; max is ${maxEntries}.`,\n }),\n ok: false,\n };\n }\n const current =\n prev.cursor >= 0 ? prev.entries[prev.cursor] : undefined;\n const nextEntries = [...entries];\n const nextState: QueueState<T> = {\n ...prev,\n continuation: undefined,\n cursor: nextEntries.length > 0 ? 0 : -1,\n entries: nextEntries,\n history:\n mode === \"play\"\n ? appendHistory(prev.history, current, maxEntries)\n : prev.history,\n originalOrder: nextEntries.map((entry) => entry.id),\n shuffle: false,\n shuffleSeed: undefined,\n undoRemoval: undefined,\n undoStop: undefined,\n };\n return {\n changed: true,\n nextState,\n ok: true,\n value: nextState,\n };\n });\n };\n\n const remove = (\n entryIds: readonly string[]\n ): Effect.Effect<RemoveResult<T>, AudioQueueError> =>\n modifyStateOrFail<RemoveResult<T>>((rawState) => {\n const state = markUndoStopMutated(rawState);\n if (entryIds.length === 0) {\n return {\n changed: state !== rawState,\n nextState: state,\n ok: true,\n value: { removed: [], state, undoToken: undefined },\n };\n }\n const idSet = new Set(entryIds);\n let firstRemovedIndex = -1;\n const removed: QueueEntry<T>[] = [];\n const positions: {\n readonly entry: QueueEntry<T>;\n readonly index: number;\n }[] = [];\n const remaining: QueueEntry<T>[] = [];\n\n for (let i = 0; i < state.entries.length; i += 1) {\n const entry = state.entries[i];\n if (!entry) {\n continue;\n }\n if (idSet.has(entry.id)) {\n if (firstRemovedIndex === -1) {\n firstRemovedIndex = i;\n }\n removed.push(entry);\n positions.push({ entry, index: i });\n } else {\n remaining.push(entry);\n }\n }\n\n if (removed.length === 0) {\n return {\n error: new AudioQueueError({\n code: \"ENTRY_NOT_FOUND\",\n message: \"None of the specified queue entries were found.\",\n }),\n ok: false,\n };\n }\n\n const currentBefore =\n state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n let nextCursor = state.cursor;\n if (remaining.length === 0) {\n nextCursor = -1;\n } else if (currentBefore && !idSet.has(currentBefore.id)) {\n const refIdx = remaining.indexOf(currentBefore);\n nextCursor =\n refIdx === -1\n ? remaining.findIndex((e) => e.id === currentBefore.id)\n : refIdx;\n } else {\n nextCursor = Math.min(state.cursor, remaining.length - 1);\n }\n\n const token = nextToken();\n const nextState: QueueState<T> = {\n ...state,\n cursor: nextCursor,\n entries: remaining,\n originalOrder: state.originalOrder.filter((id) => !idSet.has(id)),\n undoRemoval: {\n currentEntryId:\n nextCursor >= 0 ? remaining[nextCursor]?.id : undefined,\n entries: removed,\n expiresAtMs: now() + undoRemovalTtlMs,\n index: firstRemovedIndex,\n positions,\n priorOriginalOrder: state.originalOrder,\n queueIds: remaining.map((entry) => entry.id),\n token,\n },\n };\n return {\n changed: true,\n nextState,\n ok: true,\n value: { removed, state: nextState, undoToken: token },\n };\n });\n\n const clearUpNext = (): Effect.Effect<RemoveResult<T>> =>\n modifyState<RemoveResult<T>>((rawState) => {\n const state = markUndoStopMutated(rawState);\n const splitAt = state.cursor >= 0 ? state.cursor + 1 : 0;\n const removed = state.entries.slice(splitAt);\n if (removed.length === 0) {\n return [\n { removed: [], state, undoToken: undefined },\n state,\n state !== rawState,\n ];\n }\n const remaining = state.entries.slice(0, splitAt);\n const token = nextToken();\n const nextState: QueueState<T> = {\n ...state,\n entries: remaining,\n originalOrder: removeOccurrencesFromOrder(\n state.originalOrder,\n removed\n ),\n undoRemoval: {\n currentEntryId:\n state.cursor >= 0 ? remaining[state.cursor]?.id : undefined,\n entries: removed,\n expiresAtMs: now() + undoRemovalTtlMs,\n index: splitAt,\n positions: removed.map((entry, idx) => ({\n entry,\n index: splitAt + idx,\n })),\n priorOriginalOrder: state.originalOrder,\n queueIds: remaining.map((entry) => entry.id),\n token,\n },\n };\n return [\n { removed, state: nextState, undoToken: token },\n nextState,\n true,\n ];\n });\n\n const restoreRemoved = (\n token: string\n ): Effect.Effect<QueueState<T>, AudioQueueError> =>\n modifyStateOrFail((state) => {\n const snapshot = state.undoRemoval;\n if (!snapshot || snapshot.token !== token) {\n return {\n error: new AudioQueueError({\n code: \"UNDO_MISMATCH\",\n message: \"Undo removal snapshot does not match token.\",\n }),\n ok: false,\n };\n }\n if (now() > snapshot.expiresAtMs) {\n return {\n error: new AudioQueueError({\n code: \"UNDO_EXPIRED\",\n message: \"Undo removal window has expired.\",\n }),\n nextState: { ...state, undoRemoval: undefined },\n ok: false,\n };\n }\n const currentEntryBefore =\n state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n const currentId = currentEntryBefore?.id;\n const currentIds = state.entries.map((entry) => entry.id);\n if (\n currentId !== snapshot.currentEntryId ||\n !arraysEqual(currentIds, snapshot.queueIds)\n ) {\n return {\n error: new AudioQueueError({\n code: \"UNDO_MISMATCH\",\n message: \"Queue changed since removal; cannot safely restore.\",\n }),\n ok: false,\n };\n }\n if (state.entries.length + snapshot.entries.length > maxEntries) {\n return {\n error: new AudioQueueError({\n code: \"QUEUE_FULL\",\n message: `Restoring entries would exceed queue capacity (${maxEntries}).`,\n }),\n ok: false,\n };\n }\n\n const restoredEntries = [...state.entries];\n const sortedPositions = [...snapshot.positions].toSorted(\n (a, b) => a.index - b.index\n );\n for (const item of sortedPositions) {\n const targetIdx = Math.min(item.index, restoredEntries.length);\n restoredEntries.splice(targetIdx, 0, item.entry);\n }\n let restoredCursor = -1;\n if (currentEntryBefore !== undefined) {\n const refIdx = restoredEntries.indexOf(currentEntryBefore);\n restoredCursor =\n refIdx === -1\n ? restoredEntries.findIndex((e) => e.id === currentId)\n : refIdx;\n } else if (restoredEntries.length > 0) {\n restoredCursor = Math.min(snapshot.index, restoredEntries.length - 1);\n }\n\n const nextState: QueueState<T> = {\n ...state,\n cursor: restoredCursor,\n entries: restoredEntries,\n originalOrder: snapshot.priorOriginalOrder,\n undoRemoval: undefined,\n };\n return {\n changed: true,\n nextState,\n ok: true,\n value: nextState,\n };\n });\n\n const move = (\n entryId: string,\n beforeEntryId: string | undefined\n ): Effect.Effect<QueueState<T>, AudioQueueError> =>\n modifyStateOrFail((rawState) => {\n const state = markUndoStopMutated(rawState);\n const fromIndex = state.entries.findIndex((e) => e.id === entryId);\n if (fromIndex === -1) {\n return {\n error: new AudioQueueError({\n code: \"ENTRY_NOT_FOUND\",\n message: `Queue entry \"${entryId}\" not found.`,\n }),\n ok: false,\n };\n }\n const moving = state.entries[fromIndex];\n if (!moving) {\n return {\n changed: state !== rawState,\n nextState: state,\n ok: true,\n value: state,\n };\n }\n if (entryId === beforeEntryId) {\n return {\n changed: state !== rawState,\n nextState: state,\n ok: true,\n value: state,\n };\n }\n const currentBefore =\n state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n const without = [\n ...state.entries.slice(0, fromIndex),\n ...state.entries.slice(fromIndex + 1),\n ];\n let toIndex = without.length;\n if (beforeEntryId !== undefined) {\n const targetIdx = without.findIndex((e) => e.id === beforeEntryId);\n if (targetIdx === -1) {\n return {\n error: new AudioQueueError({\n code: \"ENTRY_NOT_FOUND\",\n message: `Target entry \"${beforeEntryId}\" not found.`,\n }),\n ok: false,\n };\n }\n toIndex = targetIdx;\n }\n const nextEntries = [\n ...without.slice(0, toIndex),\n moving,\n ...without.slice(toIndex),\n ];\n let nextCursor = state.cursor;\n if (currentBefore !== undefined) {\n const refIdx = nextEntries.indexOf(currentBefore);\n nextCursor =\n refIdx === -1\n ? nextEntries.findIndex((e) => e.id === currentBefore.id)\n : refIdx;\n }\n const nextOriginalOrder = updateOriginalOrderOnMove(\n state,\n nextEntries,\n entryId,\n beforeEntryId\n );\n const nextState: QueueState<T> = {\n ...state,\n cursor: nextCursor,\n entries: nextEntries,\n originalOrder: nextOriginalOrder,\n undoRemoval: undefined,\n };\n return {\n changed: true,\n nextState,\n ok: true,\n value: nextState,\n };\n });\n\n const jumpTo = (\n entryId: string\n ): Effect.Effect<QueueEntry<T>, AudioQueueError> =>\n modifyStateOrFail((rawState) => {\n const state = markUndoStopMutated(rawState);\n const targetIndex = state.entries.findIndex((e) => e.id === entryId);\n const target =\n targetIndex === -1 ? undefined : state.entries[targetIndex];\n if (!target) {\n return {\n error: new AudioQueueError({\n code: \"ENTRY_NOT_FOUND\",\n message: `Queue entry \"${entryId}\" not found.`,\n }),\n ok: false,\n };\n }\n const current =\n state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n const nextState: QueueState<T> = {\n ...state,\n cursor: targetIndex,\n history:\n current && current.id !== target.id\n ? appendHistory(state.history, current, maxEntries)\n : state.history,\n undoStop: undefined,\n };\n return {\n changed: true,\n nextState,\n ok: true,\n value: target,\n };\n });\n\n const next = (): Effect.Effect<\n QueueEntry<T> | undefined,\n AudioQueueError\n > =>\n Effect.gen(function* () {\n type NextStep =\n | { readonly kind: \"done\"; readonly entry: QueueEntry<T> | undefined }\n | {\n readonly kind: \"fetchAutoplay\";\n readonly current: QueueEntry<T>;\n readonly snapshot: QueueState<T>;\n readonly startGeneration: number;\n };\n\n const step = yield* modifyState<NextStep>((state) => {\n if (state.entries.length === 0) {\n return [{ entry: undefined, kind: \"done\" }, state, false];\n }\n const current =\n state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n\n if (state.repeat === \"one\" && current !== undefined) {\n return [{ entry: current, kind: \"done\" }, state, false];\n }\n\n const nextIndex = state.cursor + 1;\n if (nextIndex < state.entries.length) {\n const nextEntry = state.entries[nextIndex];\n const nextState: QueueState<T> = {\n ...state,\n cursor: nextIndex,\n history: appendHistory(state.history, current, maxEntries),\n undoStop: undefined,\n };\n return [{ entry: nextEntry, kind: \"done\" }, nextState, true];\n }\n\n if (state.repeat === \"all\") {\n const [first] = state.entries;\n const nextState: QueueState<T> = {\n ...state,\n cursor: 0,\n history: appendHistory(state.history, current, maxEntries),\n undoStop: undefined,\n };\n return [{ entry: first, kind: \"done\" }, nextState, true];\n }\n\n if (state.continuation && state.continuation.entries.length > 0) {\n const advanced = advanceWithContinuation(\n state,\n state.continuation,\n current,\n maxEntries\n );\n if (advanced) {\n return [\n { entry: advanced.nextEntry, kind: \"done\" },\n advanced.nextState,\n true,\n ];\n }\n }\n\n if (options.onAutoplay && current !== undefined) {\n return [\n {\n current,\n kind: \"fetchAutoplay\",\n snapshot: state,\n startGeneration: generation,\n },\n state,\n false,\n ];\n }\n\n return [{ entry: undefined, kind: \"done\" }, state, false];\n });\n\n if (step.kind === \"done\") {\n return step.entry;\n }\n\n const { onAutoplay } = options;\n if (!onAutoplay) {\n return;\n }\n const fetched = yield* onAutoplay(step.current, step.snapshot);\n if (!fetched || fetched.entries.length === 0) {\n return;\n }\n\n // Revalidate generation atomically so a late autoplay result never clobbers a concurrent mutation\n return yield* modifyState<QueueEntry<T> | undefined>((latestState) => {\n if (generation !== step.startGeneration) {\n return [undefined, latestState, false];\n }\n const latestCurrent =\n latestState.cursor >= 0\n ? latestState.entries[latestState.cursor]\n : undefined;\n const advanced = advanceWithContinuation(\n latestState,\n fetched,\n latestCurrent,\n maxEntries\n );\n if (!advanced) {\n return [undefined, latestState, false];\n }\n return [advanced.nextEntry, advanced.nextState, true];\n });\n });\n\n const previous = (): Effect.Effect<QueueEntry<T> | undefined> =>\n modifyState((state) => {\n if (state.entries.length === 0) {\n return [undefined, state, false];\n }\n if (state.cursor > 0) {\n const prevIndex = state.cursor - 1;\n const prevEntry = state.entries[prevIndex];\n return [\n prevEntry,\n {\n ...state,\n cursor: prevIndex,\n undoStop: undefined,\n },\n true,\n ];\n }\n if (state.repeat === \"all\") {\n const lastIndex = state.entries.length - 1;\n const lastEntry = state.entries[lastIndex];\n return [\n lastEntry,\n {\n ...state,\n cursor: lastIndex,\n undoStop: undefined,\n },\n true,\n ];\n }\n return [state.entries[0], state, false];\n });\n\n const setRepeat = (mode: RepeatMode): Effect.Effect<QueueState<T>> =>\n modifyState((state) => {\n const nextState: QueueState<T> = { ...state, repeat: mode };\n return [nextState, nextState, true];\n });\n\n const setShuffle = (\n enabled: boolean,\n seed?: number\n ): Effect.Effect<QueueState<T>> =>\n modifyState((state) => {\n if (\n enabled === state.shuffle &&\n (seed === undefined || seed === state.shuffleSeed)\n ) {\n return [state, state, false];\n }\n\n const current =\n state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n\n if (enabled) {\n const chosenSeed = seed ?? Math.trunc(now()) % 4_294_967_296;\n if (!state.shuffle) {\n for (const [idx, entry] of state.entries.entries()) {\n preShuffleRank.set(entry, idx);\n }\n }\n const originalOrder = state.shuffle\n ? state.originalOrder\n : state.entries.map((entry) => entry.id);\n\n if (state.cursor >= 0 && current !== undefined) {\n const played = state.entries.slice(0, state.cursor + 1);\n const rest = state.entries.slice(state.cursor + 1);\n const shuffledRest = fisherYatesShuffle(rest, chosenSeed);\n const nextState: QueueState<T> = {\n ...state,\n entries: [...played, ...shuffledRest],\n originalOrder,\n shuffle: true,\n shuffleSeed: chosenSeed,\n };\n return [nextState, nextState, true];\n }\n\n const nextState: QueueState<T> = {\n ...state,\n entries: fisherYatesShuffle(state.entries, chosenSeed),\n originalOrder,\n shuffle: true,\n shuffleSeed: chosenSeed,\n };\n return [nextState, nextState, true];\n }\n\n // Disable shuffle: restore original order while keeping exact occurrence identity\n const { cursor: nextCursor, entries: restored } = unshuffleEntries(\n state,\n preShuffleRank\n );\n const nextState: QueueState<T> = {\n ...state,\n cursor: nextCursor,\n entries: restored,\n shuffle: false,\n shuffleSeed: undefined,\n };\n return [nextState, nextState, true];\n });\n\n const setContinuation = (\n continuation: AutoplayContinuation<T> | undefined\n ): Effect.Effect<QueueState<T>> =>\n modifyState((state) => {\n const nextState: QueueState<T> = { ...state, continuation };\n return [nextState, nextState, true];\n });\n\n const stop = (\n positionSeconds = 0,\n paused = false\n ): Effect.Effect<StopResult<T>> =>\n modifyState<StopResult<T>>((state) => {\n const current =\n state.cursor >= 0 ? state.entries[state.cursor] : undefined;\n if (!current) {\n return [{ state, undoToken: undefined }, state, false];\n }\n const token = nextToken();\n const nextState: QueueState<T> = {\n ...state,\n cursor: -1,\n undoStop: {\n cursor: state.cursor,\n entryId: current.id,\n expiresAtMs: now() + undoStopTtlMs,\n mutated: false,\n paused,\n positionSeconds,\n token,\n },\n };\n return [{ state: nextState, undoToken: token }, nextState, true];\n });\n\n const undoStop = (\n token: string\n ): Effect.Effect<UndoStopResult<T>, AudioQueueError> =>\n modifyStateOrFail((state) => {\n const snapshot = state.undoStop;\n if (!snapshot || snapshot.token !== token) {\n return {\n error: new AudioQueueError({\n code: \"UNDO_MISMATCH\",\n message: \"Undo stop snapshot does not match token.\",\n }),\n ok: false,\n };\n }\n if (snapshot.mutated) {\n return {\n error: new AudioQueueError({\n code: \"UNDO_MISMATCH\",\n message: \"Queue was mutated after stop; cannot undo stop.\",\n }),\n nextState: { ...state, undoStop: undefined },\n ok: false,\n };\n }\n if (now() > snapshot.expiresAtMs) {\n return {\n error: new AudioQueueError({\n code: \"UNDO_EXPIRED\",\n message: \"Undo stop window has expired.\",\n }),\n nextState: { ...state, undoStop: undefined },\n ok: false,\n };\n }\n const entryIndex = state.entries.findIndex(\n (e) => e.id === snapshot.entryId\n );\n if (entryIndex === -1) {\n return {\n error: new AudioQueueError({\n code: \"ENTRY_NOT_FOUND\",\n message: \"Stopped entry is no longer in queue.\",\n }),\n ok: false,\n };\n }\n const nextState: QueueState<T> = {\n ...state,\n cursor: entryIndex,\n undoStop: undefined,\n };\n return {\n changed: true,\n nextState,\n ok: true,\n value: {\n paused: snapshot.paused,\n positionSeconds: snapshot.positionSeconds,\n state: nextState,\n },\n };\n });\n\n const renewEntryUrl = (\n entryId: string,\n reason: UrlRenewalReason = \"expired\"\n ): Effect.Effect<QueueEntry<T>, AudioQueueError> =>\n Effect.gen(function* () {\n const state = yield* Ref.get(ref);\n const entry = state.entries.find((e) => e.id === entryId);\n if (!entry) {\n return yield* Effect.fail(\n new AudioQueueError({\n code: \"ENTRY_NOT_FOUND\",\n message: `Queue entry \"${entryId}\" not found.`,\n })\n );\n }\n if (!options.onRenewUrl) {\n return yield* Effect.fail(\n new AudioQueueError({\n code: \"RENEWAL_FAILED\",\n message: \"No onRenewUrl hook configured for this queue.\",\n })\n );\n }\n const renewed = yield* options.onRenewUrl(entry, reason);\n return yield* modifyState<QueueEntry<T>>((latest) => {\n const latestIndex = latest.entries.findIndex((e) => e.id === entryId);\n const baseEntry =\n latestIndex === -1 ? entry : (latest.entries[latestIndex] ?? entry);\n const updatedEntry: QueueEntry<T> = {\n ...baseEntry,\n durationSeconds:\n renewed.durationSeconds ?? baseEntry.durationSeconds,\n expiresAtMs:\n renewed.expiresAtMs ?? extractLinkExpiryMs(renewed.url),\n url: renewed.url,\n };\n if (latestIndex === -1) {\n return [updatedEntry, latest, false];\n }\n const nextEntries = [...latest.entries];\n nextEntries[latestIndex] = updatedEntry;\n return [updatedEntry, { ...latest, entries: nextEntries }, true];\n });\n });\n\n const ensureFreshUrl = (\n entryId: string\n ): Effect.Effect<QueueEntry<T>, AudioQueueError> =>\n Effect.gen(function* () {\n const state = yield* Ref.get(ref);\n const entry = state.entries.find((e) => e.id === entryId);\n if (!entry) {\n return yield* Effect.fail(\n new AudioQueueError({\n code: \"ENTRY_NOT_FOUND\",\n message: `Queue entry \"${entryId}\" not found.`,\n })\n );\n }\n if (\n options.onRenewUrl &&\n isUrlExpiringSoon(entry, now(), renewAheadMs)\n ) {\n return yield* renewEntryUrl(entryId, \"proactive\");\n }\n return entry;\n });\n\n return {\n atomRef,\n clearUpNext,\n currentEntry,\n enqueue,\n ensureFreshUrl,\n getState,\n jumpTo,\n load,\n move,\n next,\n previous,\n ref,\n remove,\n renewEntryUrl,\n restoreRemoved,\n setContinuation,\n setRepeat,\n setShuffle,\n stateAtom,\n stop,\n undoStop,\n upcoming,\n };\n });\n}\n\nexport function makeQueueServiceLayer(\n options: QueueOptions<unknown> = {}\n): Layer.Layer<QueueService> {\n return Layer.effect(QueueService, createAudioQueue(options));\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,mBAAmB,MAA4B;CAC7D,IAAI,QAAQ,SAAS;CACrB,aAAa;EACX,QAAS,QAAQ,eAAmB;EACpC,IAAI,IAAI,KAAK,KAAK,QAAS,UAAU,IAAK,IAAI,KAAK;EACnD,KAAK,IAAI,KAAK,KAAK,IAAK,MAAM,GAAI,KAAK,CAAC;EACxC,SAAS,IAAK,MAAM,QAAS,KAAK;CACpC;AACF;;;;AAKA,SAAgB,mBAAsB,OAAqB,MAAmB;CAC5E,MAAM,SAAS,CAAC,GAAG,KAAK;CACxB,MAAM,SAAS,mBAAmB,IAAI;CACtC,KAAK,IAAI,IAAI,OAAO,SAAS,GAAG,IAAI,GAAG,KAAK,GAAG;EAC7C,MAAM,IAAI,KAAK,MAAM,OAAO,KAAK,IAAI,EAAE;EACvC,MAAM,UAAU,OAAO;EACvB,MAAM,OAAO,OAAO;EACpB,IAAI,YAAY,KAAA,KAAa,SAAS,KAAA,GAAW;GAC/C,OAAO,KAAK;GACZ,OAAO,KAAK;EACd;CACF;CACA,OAAO;AACT;;AC7BA,MAAa,mBAAmB,OAAO,SAAS;CAAC;CAAO;CAAO;AAAK,CAAC;AAGrE,MAAa,yBAAyB,OAAO,SAAS,CAAC,OAAO,MAAM,C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GACA;GACA;GACA;EACF;CACF,CAAC;AACH;AAEA,SAAgB,sBACd,UAAiC,CAAC,GACP;CAC3B,OAAO,MAAM,OAAO,cAAc,iBAAiB,OAAO,CAAC;AAC7D"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { n as AudioDecodeError } from "../errors-ChTQFwuZ.js";
|
|
3
|
+
/**
|
|
4
|
+
* Pure TypeScript IEEE 802.3 CRC32 over `Uint8Array` (zero `node:zlib` imports).
|
|
5
|
+
* Matches IEEE test vector: `crc32(utf8("123456789")) === 0xcbf43926`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function crc32(bytes: Uint8Array, seed?: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* Convenience helper computing IEEE 802.3 CRC32 over a UTF-8 string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function crc32String(input: string, seed?: number): number;
|
|
12
|
+
interface PlaylistEntry {
|
|
13
|
+
readonly url: string;
|
|
14
|
+
readonly title: string;
|
|
15
|
+
readonly durationSeconds?: number;
|
|
16
|
+
readonly attributes?: Readonly<Record<string, string>>;
|
|
17
|
+
}
|
|
18
|
+
interface M3uPlaylist {
|
|
19
|
+
readonly format: "m3u";
|
|
20
|
+
readonly isExtended: boolean;
|
|
21
|
+
readonly tvgUrl?: string;
|
|
22
|
+
readonly entries: readonly PlaylistEntry[];
|
|
23
|
+
}
|
|
24
|
+
interface PlsPlaylist {
|
|
25
|
+
readonly format: "pls";
|
|
26
|
+
readonly numberOfEntries?: number;
|
|
27
|
+
readonly version?: number;
|
|
28
|
+
readonly entries: readonly PlaylistEntry[];
|
|
29
|
+
}
|
|
30
|
+
type ParsedPlaylist = M3uPlaylist | PlsPlaylist;
|
|
31
|
+
interface HlsVariantStream {
|
|
32
|
+
readonly url: string;
|
|
33
|
+
readonly bandwidth: number;
|
|
34
|
+
readonly averageBandwidth?: number;
|
|
35
|
+
readonly codecs?: string;
|
|
36
|
+
readonly resolution?: {
|
|
37
|
+
readonly width: number;
|
|
38
|
+
readonly height: number;
|
|
39
|
+
};
|
|
40
|
+
readonly frameRate?: number;
|
|
41
|
+
readonly audioGroup?: string;
|
|
42
|
+
readonly subtitlesGroup?: string;
|
|
43
|
+
readonly name?: string;
|
|
44
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
45
|
+
}
|
|
46
|
+
interface HlsMediaRendition {
|
|
47
|
+
readonly type: string;
|
|
48
|
+
readonly groupId: string;
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly url?: string;
|
|
51
|
+
readonly language?: string;
|
|
52
|
+
readonly isDefault: boolean;
|
|
53
|
+
readonly autoSelect: boolean;
|
|
54
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
55
|
+
}
|
|
56
|
+
interface HlsMasterPlaylist {
|
|
57
|
+
readonly kind: "master";
|
|
58
|
+
readonly version?: number;
|
|
59
|
+
readonly independentSegments: boolean;
|
|
60
|
+
readonly variants: readonly HlsVariantStream[];
|
|
61
|
+
readonly renditions: readonly HlsMediaRendition[];
|
|
62
|
+
readonly cacheTtlMs: number;
|
|
63
|
+
}
|
|
64
|
+
interface HlsMediaSegment {
|
|
65
|
+
readonly url: string;
|
|
66
|
+
readonly durationSeconds: number;
|
|
67
|
+
readonly title?: string;
|
|
68
|
+
readonly sequence: number;
|
|
69
|
+
readonly discontinuity: boolean;
|
|
70
|
+
readonly mapUri?: string;
|
|
71
|
+
}
|
|
72
|
+
interface HlsMediaPlaylist {
|
|
73
|
+
readonly kind: "media";
|
|
74
|
+
readonly version?: number;
|
|
75
|
+
readonly targetDurationSeconds: number;
|
|
76
|
+
readonly mediaSequence: number;
|
|
77
|
+
readonly playlistType?: "VOD" | "EVENT";
|
|
78
|
+
readonly hasEndList: boolean;
|
|
79
|
+
readonly isLive: boolean;
|
|
80
|
+
readonly segments: readonly HlsMediaSegment[];
|
|
81
|
+
readonly cacheTtlMs: number;
|
|
82
|
+
}
|
|
83
|
+
type HlsManifest = HlsMasterPlaylist | HlsMediaPlaylist;
|
|
84
|
+
/**
|
|
85
|
+
* Pure-TS M3U / M3U8 playlist parser supporting `#EXTM3U`, `#EXTINF`,
|
|
86
|
+
* IPTV/Kodi attributes (`tvg-id`, `tvg-name`, `tvg-logo`, `group-title`),
|
|
87
|
+
* and relative URL resolution.
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseM3u(content: string, baseUrl?: string): M3uPlaylist;
|
|
90
|
+
/**
|
|
91
|
+
* Pure-TS PLS (`[playlist]`) parser sorting entries numerically by index.
|
|
92
|
+
*/
|
|
93
|
+
export declare function parsePls(content: string, baseUrl?: string): PlsPlaylist;
|
|
94
|
+
/**
|
|
95
|
+
* Auto-detects PLS (`[playlist]`) vs M3U/M3U8 and parses accordingly.
|
|
96
|
+
*/
|
|
97
|
+
export declare function parsePlaylist(content: string, baseUrl?: string): ParsedPlaylist;
|
|
98
|
+
/**
|
|
99
|
+
* Pure-TS RFC 8216 HLS manifest parser supporting Master playlists
|
|
100
|
+
* (`#EXT-X-STREAM-INF`, `#EXT-X-MEDIA`) and Media playlists (VOD/EVENT/Live).
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseHlsManifest(content: string, baseUrl?: string): HlsManifest;
|
|
103
|
+
/*! @license
|
|
104
|
+
MIT License
|
|
105
|
+
Copyright (c) 2024 dotX12 (shazamio-core)
|
|
106
|
+
Exact pre-rounded f32 2048-point Hanning window coefficients from shazamio-core
|
|
107
|
+
commit d7608768ab274c1b149f0d9086b75db2e661b9bb.
|
|
108
|
+
*/
|
|
109
|
+
export declare const SHAZAM_HANNING_WINDOW: Float32Array;
|
|
110
|
+
export declare const SHAZAM_SAMPLE_RATE = 16000;
|
|
111
|
+
export declare const SHAZAM_MAX_DURATION_SECONDS = 12;
|
|
112
|
+
export declare const SHAZAM_MAX_SAMPLES: number;
|
|
113
|
+
export declare const SHAZAM_MAX_PCM_BYTES: number;
|
|
114
|
+
interface ShazamPeak {
|
|
115
|
+
readonly pass: number;
|
|
116
|
+
readonly magnitude: number;
|
|
117
|
+
readonly bin: number;
|
|
118
|
+
}
|
|
119
|
+
interface ShazamSignatureResult {
|
|
120
|
+
readonly uri: string;
|
|
121
|
+
readonly base64: string;
|
|
122
|
+
readonly bytes: Uint8Array;
|
|
123
|
+
readonly sampleMs: number;
|
|
124
|
+
readonly peakCount: number;
|
|
125
|
+
readonly peaksByBand: readonly [number, number, number, number];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Pure-TS Uint8Array-to-base64 encoder (isomorphic, zero Node Buffer or DOM btoa dependency).
|
|
129
|
+
*/
|
|
130
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
131
|
+
/**
|
|
132
|
+
* Pure-TS base64-to-Uint8Array decoder (isomorphic).
|
|
133
|
+
*/
|
|
134
|
+
export declare function base64ToBytes(base64: string): Uint8Array;
|
|
135
|
+
/**
|
|
136
|
+
* Converts normalized mono Float32 samples `[-1, 1]` to signed 16-bit LE PCM bytes.
|
|
137
|
+
*/
|
|
138
|
+
export declare function float32ToPcm16Le(samples: Float32Array): Uint8Array;
|
|
139
|
+
/**
|
|
140
|
+
* Anti-aliased mono resampler to 16 kHz for browser/worker callers starting
|
|
141
|
+
* from 44.1/48 kHz Float32 PCM. Applies a 4th-order Butterworth low-pass filter
|
|
142
|
+
* before downsampling to prevent high-frequency fold-back into Shazam bands.
|
|
143
|
+
*/
|
|
144
|
+
export declare function resampleMonoTo16kHz(samples: Float32Array, sourceSampleRate: number): Float32Array;
|
|
145
|
+
/**
|
|
146
|
+
* Computes the Shazam parabolic sub-bin peak correction, returning `undefined`
|
|
147
|
+
* when `variation === 0` or non-finite to guard against division-by-zero
|
|
148
|
+
* (`NaN` / `±Infinity`).
|
|
149
|
+
*/
|
|
150
|
+
export declare function computePeakCorrection(before: number, peak: number, after: number): number | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Synchronous pure-TS Shazam spectral-peak fingerprinter.
|
|
153
|
+
* Accepts mono 16 kHz PCM16LE bytes (`Uint8Array`) or `Int16Array` (up to 12 s).
|
|
154
|
+
*/
|
|
155
|
+
export declare function generateShazamSignatureSync(pcm: Uint8Array | Int16Array): ShazamSignatureResult;
|
|
156
|
+
/**
|
|
157
|
+
* Cooperative Effect-based Shazam spectral-peak fingerprinter (yields every
|
|
158
|
+
* 16,384 samples so concurrent audio/network fibers stay responsive).
|
|
159
|
+
*/
|
|
160
|
+
export declare function generateShazamSignature(pcm: Uint8Array | Int16Array): Effect.Effect<ShazamSignatureResult, AudioDecodeError>;
|
|
161
|
+
export type { HlsManifest, HlsMasterPlaylist, HlsMediaPlaylist, HlsMediaRendition, HlsMediaSegment, HlsVariantStream, M3uPlaylist, ParsedPlaylist, PlaylistEntry, PlsPlaylist, ShazamPeak, ShazamSignatureResult };
|