ssovee-os-web-ui 0.1.40 → 0.1.41

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 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,58 @@ 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 getAssetUrl = (asset) => {
3270
- if (typeof asset === "string") return asset;
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
- };
3289
3268
  var isSoundType = (type) => {
3290
3269
  return type in soundMap;
3291
3270
  };
3292
3271
  var useSound = () => {
3272
+ const audioCache = React22.useRef({});
3293
3273
  const playSound = React22.useCallback((type) => {
3294
- if (typeof window === "undefined" || typeof window.Audio === "undefined") {
3274
+ if (typeof window === "undefined") {
3295
3275
  return;
3296
3276
  }
3297
3277
  const requestedType = isSoundType(type) ? type : DEFAULT_SOUND_TYPE;
3298
- const soundSrc = getAssetUrl(soundMap[requestedType]);
3299
- const sourceCandidates = resolveSoundCandidates(soundSrc);
3300
- if (sourceCandidates.length === 0) {
3301
- console.error(`Sound playback failed: no source found for "${requestedType}"`);
3278
+ const src = soundMap[requestedType];
3279
+ if (!src) {
3280
+ console.error(
3281
+ `Sound playback failed: no source found for "${requestedType}"`
3282
+ );
3302
3283
  return;
3303
3284
  }
3304
- void (async () => {
3305
- let lastError;
3306
- for (const source of sourceCandidates) {
3307
- try {
3308
- const audio = new window.Audio(source);
3309
- audio.preload = "auto";
3310
- audio.currentTime = 0;
3311
- await audio.play();
3312
- return;
3313
- } catch (err) {
3314
- lastError = err;
3315
- }
3285
+ try {
3286
+ let audio = audioCache.current[requestedType];
3287
+ if (!audio) {
3288
+ audio = new Audio(src);
3289
+ audio.preload = "auto";
3290
+ audioCache.current[requestedType] = audio;
3291
+ }
3292
+ audio.pause();
3293
+ audio.currentTime = 0;
3294
+ const playPromise = audio.play();
3295
+ if (playPromise !== void 0) {
3296
+ playPromise.catch((error) => {
3297
+ console.error(
3298
+ `Sound playback failed for "${requestedType}":`,
3299
+ error
3300
+ );
3301
+ });
3316
3302
  }
3317
- console.error("Sound playback failed:", lastError);
3318
- })();
3303
+ } catch (error) {
3304
+ console.error(
3305
+ `Sound playback failed for "${requestedType}":`,
3306
+ error
3307
+ );
3308
+ }
3319
3309
  }, []);
3320
- return { playSound };
3310
+ return {
3311
+ playSound
3312
+ };
3321
3313
  };
3322
3314
 
3323
3315
  exports.Accordion = Accordion_default;