ssovee-os-web-ui 0.1.40 → 0.1.42
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.cjs +87 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -35
- package/dist/index.js.map +1 -1
- package/dist/sdk.cjs +87 -36
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.js +87 -35
- package/dist/sdk.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var react = require('@phosphor-icons/react');
|
|
6
6
|
var uaParserJs = require('ua-parser-js');
|
|
7
7
|
|
|
8
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
8
|
function _interopNamespace(e) {
|
|
10
9
|
if (e && e.__esModule) return e;
|
|
11
10
|
var n = Object.create(null);
|
|
@@ -3259,65 +3258,117 @@ var swipe_tone_default = "data:audio/wave;base64,UklGRuzOAgBXQVZFZm10IBAAAAABAAI
|
|
|
3259
3258
|
// src/hooks/useSound.tsx
|
|
3260
3259
|
var soundMap = {
|
|
3261
3260
|
click: click_tone_default,
|
|
3262
|
-
alert: error_tone_default,
|
|
3263
|
-
notification: notification_tone_default,
|
|
3264
3261
|
error: error_tone_default,
|
|
3265
3262
|
success: success_tone_default,
|
|
3263
|
+
alert: error_tone_default,
|
|
3264
|
+
notification: notification_tone_default,
|
|
3266
3265
|
swipe: swipe_tone_default
|
|
3267
3266
|
};
|
|
3268
3267
|
var DEFAULT_SOUND_TYPE = "click";
|
|
3269
|
-
var
|
|
3270
|
-
|
|
3271
|
-
if (asset && typeof asset === "object") {
|
|
3272
|
-
const record = asset;
|
|
3273
|
-
const candidate = record.default ?? record.src ?? record.url ?? record.href;
|
|
3274
|
-
if (typeof candidate === "string") return candidate;
|
|
3275
|
-
}
|
|
3276
|
-
return "";
|
|
3277
|
-
};
|
|
3278
|
-
var resolveSoundCandidates = (src) => {
|
|
3279
|
-
if (!src) return [];
|
|
3280
|
-
const candidates = [src];
|
|
3281
|
-
if (!/^https?:|^data:|^blob:/.test(src)) {
|
|
3282
|
-
try {
|
|
3283
|
-
candidates.push(new URL(src, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href);
|
|
3284
|
-
} catch {
|
|
3285
|
-
}
|
|
3286
|
-
}
|
|
3287
|
-
return [...new Set(candidates)];
|
|
3288
|
-
};
|
|
3268
|
+
var audioBufferCache = /* @__PURE__ */ new Map();
|
|
3269
|
+
var sharedAudioContext = null;
|
|
3289
3270
|
var isSoundType = (type) => {
|
|
3290
3271
|
return type in soundMap;
|
|
3291
3272
|
};
|
|
3292
3273
|
var useSound = () => {
|
|
3274
|
+
const getAudioContext = () => {
|
|
3275
|
+
if (typeof window === "undefined") {
|
|
3276
|
+
return null;
|
|
3277
|
+
}
|
|
3278
|
+
const AudioContextCtor = window.AudioContext ?? window.webkitAudioContext;
|
|
3279
|
+
if (!AudioContextCtor) {
|
|
3280
|
+
return null;
|
|
3281
|
+
}
|
|
3282
|
+
if (!sharedAudioContext || sharedAudioContext.state === "closed") {
|
|
3283
|
+
sharedAudioContext = new AudioContextCtor();
|
|
3284
|
+
}
|
|
3285
|
+
return sharedAudioContext;
|
|
3286
|
+
};
|
|
3287
|
+
const loadAudioBuffer = async (source) => {
|
|
3288
|
+
const cached = audioBufferCache.get(source);
|
|
3289
|
+
if (cached) {
|
|
3290
|
+
return cached;
|
|
3291
|
+
}
|
|
3292
|
+
const promise = (async () => {
|
|
3293
|
+
if (typeof fetch !== "function") {
|
|
3294
|
+
throw new Error("Fetch is not available");
|
|
3295
|
+
}
|
|
3296
|
+
const response = await fetch(source);
|
|
3297
|
+
if (!response.ok) {
|
|
3298
|
+
throw new Error(`Failed to load sound source: ${response.status} ${response.statusText}`);
|
|
3299
|
+
}
|
|
3300
|
+
const context = getAudioContext();
|
|
3301
|
+
if (!context) {
|
|
3302
|
+
throw new Error("Web Audio API is not available");
|
|
3303
|
+
}
|
|
3304
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
3305
|
+
return await context.decodeAudioData(arrayBuffer.slice(0));
|
|
3306
|
+
})().catch((error) => {
|
|
3307
|
+
audioBufferCache.delete(source);
|
|
3308
|
+
throw error;
|
|
3309
|
+
});
|
|
3310
|
+
audioBufferCache.set(source, promise);
|
|
3311
|
+
return promise;
|
|
3312
|
+
};
|
|
3313
|
+
const playWithAudioBuffer = async (buffer) => {
|
|
3314
|
+
const context = getAudioContext();
|
|
3315
|
+
if (!context) {
|
|
3316
|
+
throw new Error("Web Audio API is not available");
|
|
3317
|
+
}
|
|
3318
|
+
if (context.state === "suspended") {
|
|
3319
|
+
await context.resume();
|
|
3320
|
+
}
|
|
3321
|
+
await new Promise((resolve, reject) => {
|
|
3322
|
+
const sourceNode = context.createBufferSource();
|
|
3323
|
+
sourceNode.buffer = buffer;
|
|
3324
|
+
sourceNode.connect(context.destination);
|
|
3325
|
+
sourceNode.onended = () => resolve();
|
|
3326
|
+
try {
|
|
3327
|
+
sourceNode.start(0);
|
|
3328
|
+
} catch (error) {
|
|
3329
|
+
reject(error);
|
|
3330
|
+
}
|
|
3331
|
+
});
|
|
3332
|
+
};
|
|
3333
|
+
const playWithAudioElement = async (source) => {
|
|
3334
|
+
const audio = new Audio(source);
|
|
3335
|
+
audio.preload = "auto";
|
|
3336
|
+
audio.currentTime = 0;
|
|
3337
|
+
await audio.play();
|
|
3338
|
+
};
|
|
3293
3339
|
const playSound = React22.useCallback((type) => {
|
|
3294
|
-
if (typeof window === "undefined"
|
|
3340
|
+
if (typeof window === "undefined") {
|
|
3295
3341
|
return;
|
|
3296
3342
|
}
|
|
3297
3343
|
const requestedType = isSoundType(type) ? type : DEFAULT_SOUND_TYPE;
|
|
3298
|
-
const
|
|
3299
|
-
|
|
3300
|
-
if (sourceCandidates.length === 0) {
|
|
3344
|
+
const src = soundMap[requestedType];
|
|
3345
|
+
if (!src) {
|
|
3301
3346
|
console.error(`Sound playback failed: no source found for "${requestedType}"`);
|
|
3302
3347
|
return;
|
|
3303
3348
|
}
|
|
3304
3349
|
void (async () => {
|
|
3305
3350
|
let lastError;
|
|
3306
|
-
|
|
3351
|
+
if (getAudioContext()) {
|
|
3307
3352
|
try {
|
|
3308
|
-
const
|
|
3309
|
-
|
|
3310
|
-
audio.currentTime = 0;
|
|
3311
|
-
await audio.play();
|
|
3353
|
+
const buffer = await loadAudioBuffer(src);
|
|
3354
|
+
await playWithAudioBuffer(buffer);
|
|
3312
3355
|
return;
|
|
3313
|
-
} catch (
|
|
3314
|
-
lastError =
|
|
3356
|
+
} catch (error) {
|
|
3357
|
+
lastError = error;
|
|
3315
3358
|
}
|
|
3316
3359
|
}
|
|
3317
|
-
|
|
3360
|
+
try {
|
|
3361
|
+
await playWithAudioElement(src);
|
|
3362
|
+
return;
|
|
3363
|
+
} catch (error) {
|
|
3364
|
+
lastError = error;
|
|
3365
|
+
}
|
|
3366
|
+
console.error(`Sound playback failed for "${requestedType}":`, lastError);
|
|
3318
3367
|
})();
|
|
3319
3368
|
}, []);
|
|
3320
|
-
return {
|
|
3369
|
+
return {
|
|
3370
|
+
playSound
|
|
3371
|
+
};
|
|
3321
3372
|
};
|
|
3322
3373
|
|
|
3323
3374
|
exports.Accordion = Accordion_default;
|