koin.js 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +75 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -266,6 +266,7 @@ interface UseNostalgistOptions {
|
|
|
266
266
|
initialVolume?: number;
|
|
267
267
|
romFileName?: string;
|
|
268
268
|
shader?: string;
|
|
269
|
+
romId?: string;
|
|
269
270
|
}
|
|
270
271
|
interface UseNostalgistReturn {
|
|
271
272
|
status: EmulatorStatus;
|
|
@@ -306,7 +307,7 @@ interface UseNostalgistReturn {
|
|
|
306
307
|
getNostalgistInstance: () => Nostalgist | null;
|
|
307
308
|
isPerformanceMode: boolean;
|
|
308
309
|
}
|
|
309
|
-
declare const useNostalgist: ({ system, romUrl, core, biosUrl, initialState, getCanvasElement, keyboardControls, gamepadBindings, retroAchievements, onReady, onError, initialVolume, romFileName, shader, }: UseNostalgistOptions) => UseNostalgistReturn;
|
|
310
|
+
declare const useNostalgist: ({ system, romUrl, core, biosUrl, initialState, getCanvasElement, keyboardControls, gamepadBindings, retroAchievements, onReady, onError, initialVolume, romFileName, shader, romId, }: UseNostalgistOptions) => UseNostalgistReturn;
|
|
310
311
|
|
|
311
312
|
/**
|
|
312
313
|
* Available CRT Shader Presets
|
|
@@ -855,4 +856,10 @@ interface UseGameRecordingReturn {
|
|
|
855
856
|
*/
|
|
856
857
|
declare function useGameRecording({ getCanvasElement, }: UseGameRecordingProps): UseGameRecordingReturn;
|
|
857
858
|
|
|
858
|
-
|
|
859
|
+
/**
|
|
860
|
+
* Get a ROM blob from the browser cache
|
|
861
|
+
*/
|
|
862
|
+
declare function getCachedRom(romId: string): Promise<Blob | null>;
|
|
863
|
+
declare function fetchAndCacheRom(romId: string, url: string): Promise<Blob>;
|
|
864
|
+
|
|
865
|
+
export { ALL_BUTTONS, AchievementPopup, BUTTON_GROUPS, BUTTON_LABELS, type ButtonId, CONSOLE_CAPABILITIES, CONSOLE_KEYBOARD_OVERRIDES, type Cheat, type CheatModalProps, type ConsoleCapabilities, type ControlConfig, type ControlMapperProps, type ControlMapping, type ControllerBrand, DEFAULT_CONTROLS, DEFAULT_GAMEPAD, DEFAULT_KEYBOARD, DPAD_BUTTONS, type EmulatorStatus, FACE_BUTTONS, GamePlayer, type GamePlayerProps, type GamepadInfo, type GamepadMapping, type KeyboardMapping, PERFORMANCE_TIER_1_SYSTEMS, PERFORMANCE_TIER_2_SYSTEMS, type PlayerControlsProps, type PlayerIndex, type RAAchievement, type RACredentials, type RAGame, type RAGameExtended, type RAHardcodeRestrictions, RASidebar, type RAUser, RA_MEDIA_BASE, type RetroAchievementsConfig, SHADER_PRESETS, SHOULDER_BUTTONS, STANDARD_AXIS_MAP, STANDARD_GAMEPAD_BUTTONS, STICK_BUTTONS, SUPPORTED_EXTENSIONS, SYSTEMS, SYSTEM_BUTTONS, type SaveSlot, type SaveSlotModalProps, type ShaderPresetId, ShaderSelector, ShortcutsReference, type ShowToastOptions, type SpeedMultiplier, type StandardAxis, type SystemConfig, TRIGGER_BUTTONS, type Toast, ToastContainer, type ToastType, type UseGamepadOptions, type UseGamepadReturn, type UseNostalgistReturn, type UseToastReturn, buildRetroArchConfig, clearAllControls, consoleHasButton, detectControllerBrand, detectSystem, fetchAndCacheRom, formatGamepadButton, formatKeyCode, gamepadToRetroArchConfig, getAchievementBadgeUrl, getCachedRom, getConsoleButtons, getConsoleCapabilities, getConsoleKeyboardDefaults, getCore, getDBSystemNames, getFullGamepadMapping, getFullKeyboardMapping, getSupportedExtensions, getSystem, getSystemByDbName, getSystemByKey, getSystemFromExtension, getSystemsList, getUserAvatarUrl, isSystemSupported, keyboardToRetroArchConfig, loadAllGamepadMappings, loadGamepadMapping, loadKeyboardMapping, normalizeSystemKey, saveGamepadMapping, saveKeyboardMapping, systemsMatch, useGameRecording, useGamepad, useNostalgist, useToast };
|
package/dist/index.d.ts
CHANGED
|
@@ -266,6 +266,7 @@ interface UseNostalgistOptions {
|
|
|
266
266
|
initialVolume?: number;
|
|
267
267
|
romFileName?: string;
|
|
268
268
|
shader?: string;
|
|
269
|
+
romId?: string;
|
|
269
270
|
}
|
|
270
271
|
interface UseNostalgistReturn {
|
|
271
272
|
status: EmulatorStatus;
|
|
@@ -306,7 +307,7 @@ interface UseNostalgistReturn {
|
|
|
306
307
|
getNostalgistInstance: () => Nostalgist | null;
|
|
307
308
|
isPerformanceMode: boolean;
|
|
308
309
|
}
|
|
309
|
-
declare const useNostalgist: ({ system, romUrl, core, biosUrl, initialState, getCanvasElement, keyboardControls, gamepadBindings, retroAchievements, onReady, onError, initialVolume, romFileName, shader, }: UseNostalgistOptions) => UseNostalgistReturn;
|
|
310
|
+
declare const useNostalgist: ({ system, romUrl, core, biosUrl, initialState, getCanvasElement, keyboardControls, gamepadBindings, retroAchievements, onReady, onError, initialVolume, romFileName, shader, romId, }: UseNostalgistOptions) => UseNostalgistReturn;
|
|
310
311
|
|
|
311
312
|
/**
|
|
312
313
|
* Available CRT Shader Presets
|
|
@@ -855,4 +856,10 @@ interface UseGameRecordingReturn {
|
|
|
855
856
|
*/
|
|
856
857
|
declare function useGameRecording({ getCanvasElement, }: UseGameRecordingProps): UseGameRecordingReturn;
|
|
857
858
|
|
|
858
|
-
|
|
859
|
+
/**
|
|
860
|
+
* Get a ROM blob from the browser cache
|
|
861
|
+
*/
|
|
862
|
+
declare function getCachedRom(romId: string): Promise<Blob | null>;
|
|
863
|
+
declare function fetchAndCacheRom(romId: string, url: string): Promise<Blob>;
|
|
864
|
+
|
|
865
|
+
export { ALL_BUTTONS, AchievementPopup, BUTTON_GROUPS, BUTTON_LABELS, type ButtonId, CONSOLE_CAPABILITIES, CONSOLE_KEYBOARD_OVERRIDES, type Cheat, type CheatModalProps, type ConsoleCapabilities, type ControlConfig, type ControlMapperProps, type ControlMapping, type ControllerBrand, DEFAULT_CONTROLS, DEFAULT_GAMEPAD, DEFAULT_KEYBOARD, DPAD_BUTTONS, type EmulatorStatus, FACE_BUTTONS, GamePlayer, type GamePlayerProps, type GamepadInfo, type GamepadMapping, type KeyboardMapping, PERFORMANCE_TIER_1_SYSTEMS, PERFORMANCE_TIER_2_SYSTEMS, type PlayerControlsProps, type PlayerIndex, type RAAchievement, type RACredentials, type RAGame, type RAGameExtended, type RAHardcodeRestrictions, RASidebar, type RAUser, RA_MEDIA_BASE, type RetroAchievementsConfig, SHADER_PRESETS, SHOULDER_BUTTONS, STANDARD_AXIS_MAP, STANDARD_GAMEPAD_BUTTONS, STICK_BUTTONS, SUPPORTED_EXTENSIONS, SYSTEMS, SYSTEM_BUTTONS, type SaveSlot, type SaveSlotModalProps, type ShaderPresetId, ShaderSelector, ShortcutsReference, type ShowToastOptions, type SpeedMultiplier, type StandardAxis, type SystemConfig, TRIGGER_BUTTONS, type Toast, ToastContainer, type ToastType, type UseGamepadOptions, type UseGamepadReturn, type UseNostalgistReturn, type UseToastReturn, buildRetroArchConfig, clearAllControls, consoleHasButton, detectControllerBrand, detectSystem, fetchAndCacheRom, formatGamepadButton, formatKeyCode, gamepadToRetroArchConfig, getAchievementBadgeUrl, getCachedRom, getConsoleButtons, getConsoleCapabilities, getConsoleKeyboardDefaults, getCore, getDBSystemNames, getFullGamepadMapping, getFullKeyboardMapping, getSupportedExtensions, getSystem, getSystemByDbName, getSystemByKey, getSystemFromExtension, getSystemsList, getUserAvatarUrl, isSystemSupported, keyboardToRetroArchConfig, loadAllGamepadMappings, loadGamepadMapping, loadKeyboardMapping, normalizeSystemKey, saveGamepadMapping, saveKeyboardMapping, systemsMatch, useGameRecording, useGamepad, useNostalgist, useToast };
|
package/dist/index.js
CHANGED
|
@@ -5646,10 +5646,59 @@ function getCore2(system) {
|
|
|
5646
5646
|
return getCore(system);
|
|
5647
5647
|
}
|
|
5648
5648
|
|
|
5649
|
+
// src/lib/rom-cache.ts
|
|
5650
|
+
var CACHE_NAME = "koin-rom-cache-v1";
|
|
5651
|
+
async function getCachedRom(romId) {
|
|
5652
|
+
if (typeof caches === "undefined") return null;
|
|
5653
|
+
try {
|
|
5654
|
+
const cache = await caches.open(CACHE_NAME);
|
|
5655
|
+
const response = await cache.match(romId);
|
|
5656
|
+
if (response) {
|
|
5657
|
+
console.log(`[Cache] Hit for ROM ${romId}`);
|
|
5658
|
+
return await response.blob();
|
|
5659
|
+
}
|
|
5660
|
+
} catch (e) {
|
|
5661
|
+
console.warn("[Cache] Read failed:", e);
|
|
5662
|
+
}
|
|
5663
|
+
return null;
|
|
5664
|
+
}
|
|
5665
|
+
var pendingFetches = /* @__PURE__ */ new Map();
|
|
5666
|
+
async function fetchAndCacheRom(romId, url) {
|
|
5667
|
+
if (pendingFetches.has(romId)) {
|
|
5668
|
+
console.log(`[Cache] Joining in-flight fetch for ${romId}`);
|
|
5669
|
+
return pendingFetches.get(romId);
|
|
5670
|
+
}
|
|
5671
|
+
const fetchPromise = (async () => {
|
|
5672
|
+
try {
|
|
5673
|
+
const cached = await getCachedRom(romId);
|
|
5674
|
+
if (cached) return cached;
|
|
5675
|
+
console.log(`[Cache] Fetching ROM ${romId}...`);
|
|
5676
|
+
const response = await fetch(url);
|
|
5677
|
+
if (!response.ok) throw new Error(`Failed to fetch ROM: ${response.statusText}`);
|
|
5678
|
+
const blob = await response.blob();
|
|
5679
|
+
if (typeof caches !== "undefined") {
|
|
5680
|
+
try {
|
|
5681
|
+
const cache = await caches.open(CACHE_NAME);
|
|
5682
|
+
await cache.put(romId, new Response(blob));
|
|
5683
|
+
console.log(`[Cache] Cached ROM ${romId}`);
|
|
5684
|
+
} catch (e) {
|
|
5685
|
+
console.warn("[Cache] Write failed:", e);
|
|
5686
|
+
}
|
|
5687
|
+
}
|
|
5688
|
+
return blob;
|
|
5689
|
+
} finally {
|
|
5690
|
+
pendingFetches.delete(romId);
|
|
5691
|
+
}
|
|
5692
|
+
})();
|
|
5693
|
+
pendingFetches.set(romId, fetchPromise);
|
|
5694
|
+
return fetchPromise;
|
|
5695
|
+
}
|
|
5696
|
+
|
|
5649
5697
|
// src/hooks/emulator/useEmulatorCore.ts
|
|
5650
5698
|
function useEmulatorCore({
|
|
5651
5699
|
system,
|
|
5652
5700
|
romUrl,
|
|
5701
|
+
romId,
|
|
5653
5702
|
core: coreOverride,
|
|
5654
5703
|
biosUrl,
|
|
5655
5704
|
initialState,
|
|
@@ -5731,7 +5780,25 @@ function useEmulatorCore({
|
|
|
5731
5780
|
setError(null);
|
|
5732
5781
|
const core = coreOverride || getCore2(system);
|
|
5733
5782
|
let romOption = romUrl;
|
|
5734
|
-
if (
|
|
5783
|
+
if (romId) {
|
|
5784
|
+
try {
|
|
5785
|
+
let blob = await getCachedRom(romId);
|
|
5786
|
+
if (!blob) {
|
|
5787
|
+
console.log(`[Nostalgist] Fetching and caching ROM ${romId}`);
|
|
5788
|
+
blob = await fetchAndCacheRom(romId, romUrl);
|
|
5789
|
+
} else {
|
|
5790
|
+
console.log(`[Nostalgist] Loaded ROM ${romId} from cache`);
|
|
5791
|
+
}
|
|
5792
|
+
if (blob) {
|
|
5793
|
+
romOption = {
|
|
5794
|
+
fileName: romFileName || "rom.bin",
|
|
5795
|
+
fileContent: blob
|
|
5796
|
+
};
|
|
5797
|
+
}
|
|
5798
|
+
} catch (err) {
|
|
5799
|
+
console.error("[Nostalgist] Cache/Fetch error, falling back to direct URL:", err);
|
|
5800
|
+
}
|
|
5801
|
+
} else if (romFileName) {
|
|
5735
5802
|
romOption = { fileName: romFileName, fileContent: romUrl };
|
|
5736
5803
|
}
|
|
5737
5804
|
const inputConfig = buildRetroArchConfig({
|
|
@@ -6398,7 +6465,8 @@ var useNostalgist = ({
|
|
|
6398
6465
|
onError,
|
|
6399
6466
|
initialVolume = 100,
|
|
6400
6467
|
romFileName,
|
|
6401
|
-
shader
|
|
6468
|
+
shader,
|
|
6469
|
+
romId
|
|
6402
6470
|
}) => {
|
|
6403
6471
|
const isHeavySystem = React5.useMemo(() => {
|
|
6404
6472
|
return PERFORMANCE_TIER_2_SYSTEMS.has(system.toUpperCase());
|
|
@@ -6426,6 +6494,7 @@ var useNostalgist = ({
|
|
|
6426
6494
|
} = useEmulatorCore({
|
|
6427
6495
|
system,
|
|
6428
6496
|
romUrl,
|
|
6497
|
+
romId,
|
|
6429
6498
|
core,
|
|
6430
6499
|
biosUrl,
|
|
6431
6500
|
initialState,
|
|
@@ -6619,6 +6688,7 @@ function useControls(system, onNotify) {
|
|
|
6619
6688
|
function useGameSession(props) {
|
|
6620
6689
|
const {
|
|
6621
6690
|
romUrl,
|
|
6691
|
+
romId,
|
|
6622
6692
|
romFileName,
|
|
6623
6693
|
system,
|
|
6624
6694
|
core,
|
|
@@ -6667,6 +6737,7 @@ function useGameSession(props) {
|
|
|
6667
6737
|
const nostalgist = useNostalgist({
|
|
6668
6738
|
system,
|
|
6669
6739
|
romUrl,
|
|
6740
|
+
romId,
|
|
6670
6741
|
romFileName,
|
|
6671
6742
|
core,
|
|
6672
6743
|
biosUrl,
|
|
@@ -8163,10 +8234,12 @@ exports.clearAllControls = clearAllControls;
|
|
|
8163
8234
|
exports.consoleHasButton = consoleHasButton;
|
|
8164
8235
|
exports.detectControllerBrand = detectControllerBrand;
|
|
8165
8236
|
exports.detectSystem = detectSystem;
|
|
8237
|
+
exports.fetchAndCacheRom = fetchAndCacheRom;
|
|
8166
8238
|
exports.formatGamepadButton = formatGamepadButton;
|
|
8167
8239
|
exports.formatKeyCode = formatKeyCode;
|
|
8168
8240
|
exports.gamepadToRetroArchConfig = gamepadToRetroArchConfig;
|
|
8169
8241
|
exports.getAchievementBadgeUrl = getAchievementBadgeUrl;
|
|
8242
|
+
exports.getCachedRom = getCachedRom;
|
|
8170
8243
|
exports.getConsoleButtons = getConsoleButtons;
|
|
8171
8244
|
exports.getConsoleCapabilities = getConsoleCapabilities;
|
|
8172
8245
|
exports.getConsoleKeyboardDefaults = getConsoleKeyboardDefaults;
|