feat(kaak): refine voice dock visuals

This commit is contained in:
Corrupted ILLUSIA committed 2026-10-11 10:12:16 +08:00
1 parent 16df12e4b2
commit 13f4ddac4d
19 files changed
+4573 -3971

No files matched your search

+107 -103
View File
@@ -1,110 +1,114 @@
<template>
<svg
class="ui-icon"
:width="size"
:height="size"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path v-if="name === 'home'" d="m3 10 9-7 9 7v10a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z" />
<path v-else-if="name === 'activity'" d="M3 12h4l2.2-7 4.1 14 2.2-7H21" />
<template v-else-if="name === 'server'">
<rect x="4" y="3" width="16" height="7" rx="1.5" />
<rect x="4" y="14" width="16" height="7" rx="1.5" />
<path d="M8 6.5h.01M8 17.5h.01M11 6.5h5M11 17.5h5" />
</template>
<template v-else-if="name === 'compass'">
<circle cx="12" cy="12" r="9" />
<path d="m15.5 8.5-2.2 4.8-4.8 2.2 2.2-4.8z" />
</template>
<template v-else-if="name === 'download'">
<path d="M12 3v12m0 0 4-4m-4 4-4-4M4 19v2h16v-2" />
</template>
<template v-else-if="name === 'settings'">
<path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0L6.2 6.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" />
<circle cx="12" cy="12" r="3" />
</template>
<path v-else-if="name === 'mic'" d="M12 14a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v5a3 3 0 0 0 3 3Zm-7-3a7 7 0 0 0 14 0m-7 7v3m-3 0h6" />
<path v-else-if="name === 'mic-off'" d="m4 4 16 16M10 6v5a2 2 0 0 0 3.2 1.6M14 6V5a2 2 0 0 0-3.7-1M5 11a7 7 0 0 0 10.6 6m3.4-6a7 7 0 0 0-.5-2.5M12 18v3m-3 0h6" />
<template v-else-if="name === 'music'">
<path d="M9 18V5l10-2v13" />
<circle cx="6" cy="18" r="3" />
<circle cx="16" cy="16" r="3" />
</template>
<path v-else-if="name === 'headset'" d="M4 14v-2a8 8 0 0 1 16 0v2M4 14h3v5H5a1 1 0 0 1-1-1zm16 0h-3v5h2a1 1 0 0 1-1-1z" />
<path v-else-if="name === 'volume'" d="M4 10v4h3l4 3V7l-4 3zm10.5-2.5a6 6 0 0 1 0 9m2-11a9 9 0 0 1 0 13" />
<path v-else-if="name === 'volume-off'" d="m4 4 16 16M4 10v4h3l4 3V7l-4 3z" />
<template v-else-if="name === 'search'">
<circle cx="10.8" cy="10.8" r="6.8" />
<path d="m16 16 4.5 4.5" />
</template>
<path v-else-if="name === 'bell'" d="M18 9a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9M10 21h4" />
<path v-else-if="name === 'clock'" d="M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-14v5l3 2" />
<path v-else-if="name === 'help'" d="M9.3 9a3 3 0 1 1 4.9 2.3c-1.3 1-2.2 1.5-2.2 3m0 3h.01M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Z" />
<template v-else-if="name === 'info'">
<circle cx="12" cy="12" r="9" />
<path d="M12 10v6m0-9h.01" />
</template>
<template>
<svg
class="ui-icon"
:width="size"
:height="size"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path v-if="name === 'home'" d="m3 10 9-7 9 7v10a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z" />
<path v-else-if="name === 'activity'" d="M3 12h4l2.2-7 4.1 14 2.2-7H21" />
<template v-else-if="name === 'server'">
<rect x="4" y="3" width="16" height="7" rx="1.5" />
<rect x="4" y="14" width="16" height="7" rx="1.5" />
<path d="M8 6.5h.01M8 17.5h.01M11 6.5h5M11 17.5h5" />
</template>
<template v-else-if="name === 'compass'">
<circle cx="12" cy="12" r="9" />
<path d="m15.5 8.5-2.2 4.8-4.8 2.2 2.2-4.8z" />
</template>
<template v-else-if="name === 'download'">
<path d="M12 3v12m0 0 4-4m-4 4-4-4M4 19v2h16v-2" />
</template>
<template v-else-if="name === 'settings'">
<path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0L6.2 6.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" />
<circle cx="12" cy="12" r="3" />
</template>
<path v-else-if="name === 'mic'" d="M12 14a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v5a3 3 0 0 0 3 3Zm-7-3a7 7 0 0 0 14 0m-7 7v3m-3 0h6" />
<path v-else-if="name === 'mic-off'" d="m4 4 16 16M10 6v5a2 2 0 0 0 3.2 1.6M14 6V5a2 2 0 0 0-3.7-1M5 11a7 7 0 0 0 10.6 6m3.4-6a7 7 0 0 0-.5-2.5M12 18v3m-3 0h6" />
<template v-else-if="name === 'music'">
<path d="M9 18V5l10-2v13" />
<circle cx="6" cy="18" r="3" />
<circle cx="16" cy="16" r="3" />
</template>
<path v-else-if="name === 'headset'" d="M4 14v-2a8 8 0 0 1 16 0v2M4 14h3v5H5a1 1 0 0 1-1-1zm16 0h-3v5h2a1 1 0 0 1-1-1z" />
<path v-else-if="name === 'volume'" d="M4 10v4h3l4 3V7l-4 3zm10.5-2.5a6 6 0 0 1 0 9m2-11a9 9 0 0 1 0 13" />
<path v-else-if="name === 'volume-off'" d="m4 4 16 16M4 10v4h3l4 3V7l-4 3z" />
<template v-else-if="name === 'search'">
<circle cx="10.8" cy="10.8" r="6.8" />
<path d="m16 16 4.5 4.5" />
</template>
<path v-else-if="name === 'bell'" d="M18 9a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9M10 21h4" />
<path v-else-if="name === 'clock'" d="M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-14v5l3 2" />
<path v-else-if="name === 'help'" d="M9.3 9a3 3 0 1 1 4.9 2.3c-1.3 1-2.2 1.5-2.2 3m0 3h.01M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Z" />
<template v-else-if="name === 'info'">
<circle cx="12" cy="12" r="9" />
<path d="M12 10v6m0-9h.01" />
</template>
<template v-else-if="name === 'plus'">
<path d="M12 5v14M5 12h14" />
</template>
<path v-else-if="name === 'star'" d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2-5.6-3-5.6 3 1.1-6.2L3 9.6l6.2-.9z" />
<path v-else-if="name === 'chevron-down'" d="m6 9 6 6 6-6" />
<path v-else-if="name === 'chevron-right'" d="m9 6 6 6-6 6" />
<path v-else-if="name === 'hash'" d="M9 3 7 21M17 3l-2 18M4 9h16M3 15h16" />
<path v-else-if="name === 'send'" d="m21 3-7.4 18-3.6-7-7-3.6zM21 3 10 14" />
<template v-else-if="name === 'smile'">
<circle cx="12" cy="12" r="9" />
<path d="M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01" />
</template>
<path v-else-if="name === 'paperclip'" d="m20 11-7.5 7.5a5 5 0 0 1-7-7L13 4a3.5 3.5 0 0 1 5 5l-7.5 7.5a2 2 0 0 1-3-3L14 7" />
<path v-else-if="name === 'share'" d="M4 12v7a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7M16 6l-4-4-4 4m4-4v13" />
<path v-else-if="name === 'copy'" d="M8 8V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-3M6 8h7a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z" />
<path v-else-if="name === 'close'" d="m6 6 12 12M18 6 6 18" />
<path v-else-if="name === 'more'" d="M5 12h.01M12 12h.01M19 12h.01" stroke-width="3" />
<path v-else-if="name === 'refresh'" d="M20 11a8 8 0 0 0-14-4L4 9m0-4v4h4M4 13a8 8 0 0 0 14 4l2-2m0 4v-4h-4" />
<path v-else-if="name === 'lock'" d="M6 10h12v10H6zM8 10V7a4 4 0 0 1 8 0v3" />
<path v-else-if="name === 'users'" d="M16 21v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2m6-10a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm6-7a4 4 0 0 1 0 7m2 5h1a4 4 0 0 1 4 4v1" />
<path v-else-if="name === 'message'" d="M20 11.5a7.5 7.5 0 0 1-8 7.5 9.4 9.4 0 0 1-3-.5L4 20l1.5-3.6A7.2 7.2 0 0 1 4 11.5 7.5 7.5 0 0 1 12 4a7.5 7.5 0 0 1 8 7.5Z" />
<path v-else-if="name === 'chevron-down'" d="m6 9 6 6 6-6" />
<path v-else-if="name === 'chevron-right'" d="m9 6 6 6-6 6" />
<path v-else-if="name === 'hash'" d="M9 3 7 21M17 3l-2 18M4 9h16M3 15h16" />
<path v-else-if="name === 'send'" d="m21 3-7.4 18-3.6-7-7-3.6zM21 3 10 14" />
<template v-else-if="name === 'smile'">
<circle cx="12" cy="12" r="9" />
<path d="M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01" />
</template>
<path v-else-if="name === 'paperclip'" d="m20 11-7.5 7.5a5 5 0 0 1-7-7L13 4a3.5 3.5 0 0 1 5 5l-7.5 7.5a2 2 0 0 1-3-3L14 7" />
<path v-else-if="name === 'share'" d="M4 12v7a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7M16 6l-4-4-4 4m4-4v13" />
<path v-else-if="name === 'copy'" d="M8 8V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-3M6 8h7a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z" />
<path v-else-if="name === 'close'" d="m6 6 12 12M18 6 6 18" />
<path v-else-if="name === 'more'" d="M5 12h.01M12 12h.01M19 12h.01" stroke-width="3" />
<path v-else-if="name === 'refresh'" d="M20 11a8 8 0 0 0-14-4L4 9m0-4v4h4M4 13a8 8 0 0 0 14 4l2-2m0 4v-4h-4" />
<path v-else-if="name === 'lock'" d="M6 10h12v10H6zM8 10V7a4 4 0 0 1 8 0v3" />
<path v-else-if="name === 'users'" d="M16 21v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2m6-10a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm6-7a4 4 0 0 1 0 7m2 5h1a4 4 0 0 1 4 4v1" />
<path v-else-if="name === 'message'" d="M20 11.5a7.5 7.5 0 0 1-8 7.5 9.4 9.4 0 0 1-3-.5L4 20l1.5-3.6A7.2 7.2 0 0 1 4 11.5 7.5 7.5 0 0 1 12 4a7.5 7.5 0 0 1 8 7.5Z" />
<path v-else-if="name === 'door'" d="M10 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5m5 14 5-5-5-5m5 5H9" />
<path v-else-if="name === 'waveform'" d="M3 12h2l2-6 3 12 3-9 2 6h6" />
<template v-else-if="name === 'noise-suppression'">
<path d="M2.5 13h2l2-5 2.7 9 2.4-7 1.4 3H15" />
<path d="M19 5.5v4m-2-2h4" />
</template>
<path v-else-if="name === 'shield'" d="M12 21s8-3.5 8-10V5l-8-3-8 3v6c0 6.5 8 10 8 10Z" />
<template v-else-if="name === 'sun'">
<circle cx="12" cy="12" r="4" />
<path d="M12 2v2m0 16v2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M2 12h2m16 0h2M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42" />
</template>
<path v-else-if="name === 'moon'" d="M20.4 15.2A8.5 8.5 0 0 1 8.8 3.6 8.5 8.5 0 1 0 20.4 15.2Z" />
<path v-else-if="name === 'monitor'" d="M4 4h16v12H4zM8 20h8M12 16v4" />
<path v-else-if="name === 'fullscreen'" d="M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5" />
<path v-else-if="name === 'fullscreen-exit'" d="M9 4v5H4M20 9h-5V4M15 20v-5h5M4 15h5v5" />
<path v-else-if="name === 'github'" fill="currentColor" stroke="none" d="M12 .5C5.65.5.5 5.65.5 12c0 5.08 3.29 9.39 7.86 10.91.58.11.79-.25.79-.56 0-.28-.01-1.02-.02-2-3.2.7-3.88-1.54-3.88-1.54-.53-1.33-1.28-1.68-1.28-1.68-1.04-.71.08-.7.08-.7 1.15.08 1.75 1.18 1.75 1.18 1.02 1.75 2.68 1.24 3.33.95.1-.74.4-1.24.73-1.52-2.55-.29-5.23-1.28-5.23-5.68 0-1.25.45-2.27 1.18-3.07-.12-.29-.51-1.45.11-3.03 0 0 .96-.31 3.15 1.17.91-.25 1.88-.38 2.85-.38.97 0 1.94.13 2.85.38 2.19-1.48 3.15-1.17 3.15-1.17.62 1.58.23 2.74.11 3.03.73.8 1.18 1.82 1.18 3.07 0 4.41-2.69 5.38-5.25 5.67.41.35.78 1.04.78 2.1 0 1.52-.01 2.75-.01 3.12 0 .3.21.67.8.56C20.71 21.39 24 17.08 24 12 24 5.65 18.35.5 12 .5Z" />
<template v-else-if="name === 'qq'">
<ellipse cx="12" cy="12.3" rx="7.25" ry="8.85" fill="#202a2a" stroke="none" />
<ellipse cx="12" cy="14.8" rx="4.1" ry="5.55" fill="#fff" stroke="none" />
<circle cx="9.45" cy="9.55" r="1.35" fill="#fff" stroke="none" />
<circle cx="14.55" cy="9.55" r="1.35" fill="#fff" stroke="none" />
<circle cx="9.45" cy="9.55" r=".52" fill="#202a2a" stroke="none" />
<circle cx="14.55" cy="9.55" r=".52" fill="#202a2a" stroke="none" />
<path d="m10 11.15 2-1.05 2 1.05-2 1.45z" fill="#f2a53d" stroke="none" />
<path d="m5.8 18.55-2.1 2.1 3.75-.45m10.75-1.65 2.1 2.1-3.75-.45" fill="#f2a53d" stroke="#f2a53d" stroke-width="1.5" />
</template>
<path v-else-if="name === 'check'" d="m5 12 4 4L19 6" />
<circle v-else cx="12" cy="12" r="8" />
</svg>
</template>
<script setup lang="ts">
withDefaults(defineProps<{ name: string; size?: number }>(), { size: 18 });
</script>
<style scoped>
.ui-icon {
display: block;
flex: 0 0 auto;
}
</style>
<template v-else-if="name === 'sun'">
<circle cx="12" cy="12" r="4" />
<path d="M12 2v2m0 16v2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M2 12h2m16 0h2M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42" />
</template>
<path v-else-if="name === 'moon'" d="M20.4 15.2A8.5 8.5 0 0 1 8.8 3.6 8.5 8.5 0 1 0 20.4 15.2Z" />
<path v-else-if="name === 'monitor'" d="M4 4h16v12H4zM8 20h8M12 16v4" />
<path v-else-if="name === 'fullscreen'" d="M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5" />
<path v-else-if="name === 'fullscreen-exit'" d="M9 4v5H4M20 9h-5V4M15 20v-5h5M4 15h5v5" />
<path v-else-if="name === 'github'" fill="currentColor" stroke="none" d="M12 .5C5.65.5.5 5.65.5 12c0 5.08 3.29 9.39 7.86 10.91.58.11.79-.25.79-.56 0-.28-.01-1.02-.02-2-3.2.7-3.88-1.54-3.88-1.54-.53-1.33-1.28-1.68-1.28-1.68-1.04-.71.08-.7.08-.7 1.15.08 1.75 1.18 1.75 1.18 1.02 1.75 2.68 1.24 3.33.95.1-.74.4-1.24.73-1.52-2.55-.29-5.23-1.28-5.23-5.68 0-1.25.45-2.27 1.18-3.07-.12-.29-.51-1.45.11-3.03 0 0 .96-.31 3.15 1.17.91-.25 1.88-.38 2.85-.38.97 0 1.94.13 2.85.38 2.19-1.48 3.15-1.17 3.15-1.17.62 1.58.23 2.74.11 3.03.73.8 1.18 1.82 1.18 3.07 0 4.41-2.69 5.38-5.25 5.67.41.35.78 1.04.78 2.1 0 1.52-.01 2.75-.01 3.12 0 .3.21.67.8.56C20.71 21.39 24 17.08 24 12 24 5.65 18.35.5 12 .5Z" />
<template v-else-if="name === 'qq'">
<ellipse cx="12" cy="12.3" rx="7.25" ry="8.85" fill="#202a2a" stroke="none" />
<ellipse cx="12" cy="14.8" rx="4.1" ry="5.55" fill="#fff" stroke="none" />
<circle cx="9.45" cy="9.55" r="1.35" fill="#fff" stroke="none" />
<circle cx="14.55" cy="9.55" r="1.35" fill="#fff" stroke="none" />
<circle cx="9.45" cy="9.55" r=".52" fill="#202a2a" stroke="none" />
<circle cx="14.55" cy="9.55" r=".52" fill="#202a2a" stroke="none" />
<path d="m10 11.15 2-1.05 2 1.05-2 1.45z" fill="#f2a53d" stroke="none" />
<path d="m5.8 18.55-2.1 2.1 3.75-.45m10.75-1.65 2.1 2.1-3.75-.45" fill="#f2a53d" stroke="#f2a53d" stroke-width="1.5" />
</template>
<path v-else-if="name === 'check'" d="m5 12 4 4L19 6" />
<circle v-else cx="12" cy="12" r="8" />
</svg>
</template>
<script setup lang="ts">
withDefaults(defineProps<{ name: string; size?: number }>(), { size: 18 });
</script>
<style scoped>
.ui-icon {
display: block;
flex: 0 0 auto;
}
</style>
+42 -13
View File
@@ -1,10 +1,23 @@
<template>
<div
class="desktop-audio-dock"
:class="[
'desktop-audio-dock',
{ 'desktop-audio-dock-room-panel': layout === 'room-panel' },
]"
data-ws-part="voice.audio-dock"
role="toolbar"
:aria-label="t('desktopAudioControls')"
>
<button
v-if="layout === 'room-panel'"
type="button"
class="room-panel-voice-sensitivity"
:aria-label="t('voiceActivity')"
:title="t('voiceActivity')"
aria-haspopup="dialog"
@click="emit('settings')"
><Icon name="activity" :size="16" /><span>{{ t("voiceActivity") }}</span></button
>
<div class="desktop-audio-dock-copy"
><strong>{{ t("desktopAudioControls") }}</strong
><span>{{
@@ -12,6 +25,17 @@
}}</span></div
>
<div class="desktop-audio-dock-actions">
<button
v-if="layout === 'room-panel'"
type="button"
class="dock-audio-button noise-suppression-toggle"
:class="{ active: noiseSuppressionEnabled }"
:title="t('noiseSuppression')"
:aria-label="t('noiseSuppression')"
:aria-pressed="noiseSuppressionEnabled"
@click="toggleNoiseSuppression"
><Icon name="noise-suppression" :size="20" /></button
>
<div
class="dock-hover-control"
data-ws-part="voice.audio-dock.microphone"
@@ -49,16 +73,18 @@
:aria-label="t('inputVolume')"
@input="onInputVolume"
/>
<div class="dock-panel-divider"></div>
<label class="dock-switch-row"
><span
><strong>{{ t("noiseSuppression") }}</strong></span
><input
type="checkbox"
:checked="noiseSuppressionEnabled"
:aria-label="t('noiseSuppression')"
@change="onNoiseSuppressionToggle"
/></label>
<template v-if="layout === 'default'">
<div class="dock-panel-divider"></div>
<label class="dock-switch-row"
><span
><strong>{{ t("noiseSuppression") }}</strong></span
><input
type="checkbox"
:checked="noiseSuppressionEnabled"
:aria-label="t('noiseSuppression')"
@change="onNoiseSuppressionToggle"
/></label>
</template>
</div>
</div>
<div
@@ -101,6 +127,7 @@
</div>
</div>
<button
v-if="layout === 'default'"
type="button"
class="dock-audio-button"
:title="t('audioSettings')"
@@ -133,11 +160,13 @@ import type { useWebClientAudioControls } from "../../composables/useWebClientAu
const props = defineProps<{
model: Pick<ReturnType<typeof useVoiceWebSocket>, "microphoneMuted" | "inputVolume" | "outputVolume" | "outputMuted" | "noiseSuppressionEnabled" | "accompanimentActive">;
controls: Pick<ReturnType<typeof useWebClientAudioControls>, "toggleMicrophone" | "onInputVolume" | "onOutputVolume" | "onNoiseSuppressionToggle" | "toggleAccompaniment">;
controls: Pick<ReturnType<typeof useWebClientAudioControls>, "toggleMicrophone" | "toggleNoiseSuppression" | "onInputVolume" | "onOutputVolume" | "onNoiseSuppressionToggle" | "toggleAccompaniment">;
layout?: "default" | "room-panel";
t: (key: string) => string;
rangeStyle: (value: number, max: number) => Record<string, string>;
}>();
const { microphoneMuted, inputVolume, outputVolume, outputMuted, noiseSuppressionEnabled, accompanimentActive } = props.model;
const { toggleMicrophone, onInputVolume, onOutputVolume, onNoiseSuppressionToggle, toggleAccompaniment } = props.controls;
const { toggleMicrophone, toggleNoiseSuppression, onInputVolume, onOutputVolume, onNoiseSuppressionToggle, toggleAccompaniment } = props.controls;
const layout = props.layout ?? "default";
const emit = defineEmits<{ settings: []; outputMute: [] }>();
</script>
+157 -150
View File
@@ -1,66 +1,68 @@
import { computed, onScopeDispose, ref, watch, type Ref } from "vue";
interface UseWebClientAudioControlsOptions {
interface UseWebClientAudioControlsOptions {
settingsOpen: Ref<boolean>;
microphoneMuted: Readonly<Ref<boolean>>;
inputVolume: Readonly<Ref<number>>;
voxThreshold: Readonly<Ref<number>>;
notificationVolume: Readonly<Ref<number>>;
micLevel: Readonly<Ref<number>>;
microphoneTestActive: Readonly<Ref<boolean>>;
accompanimentActive: Readonly<Ref<boolean>>;
accompanimentErrorCode: Readonly<Ref<string>>;
whisperTargetIds: Set<number>;
prepareInputDevices: () => Promise<void>;
setInputVolume: (value: number) => void;
setNoiseSuppressionEnabled: (enabled: boolean) => Promise<void>;
setOutputVolume: (value: number) => void;
setVoxThreshold: (value: number) => void;
setNotificationVolume: (value: number) => void;
setInputDevice: (deviceId: string) => Promise<void>;
setOutputDevice: (deviceId: string) => Promise<void>;
setMicrophoneMuted: (muted: boolean) => void;
startMicrophoneTest: () => Promise<void>;
stopMicrophoneTest: () => void;
startAccompaniment: () => Promise<void>;
stopAccompaniment: () => Promise<void>;
setWhisperActive: (active: boolean) => void;
localizedMessage: (message: string) => string;
showToast: (message: string) => void;
t: (key: string) => string;
}
export function useWebClientAudioControls({
noiseSuppressionEnabled: Readonly<Ref<boolean>>;
inputVolume: Readonly<Ref<number>>;
voxThreshold: Readonly<Ref<number>>;
notificationVolume: Readonly<Ref<number>>;
micLevel: Readonly<Ref<number>>;
microphoneTestActive: Readonly<Ref<boolean>>;
accompanimentActive: Readonly<Ref<boolean>>;
accompanimentErrorCode: Readonly<Ref<string>>;
whisperTargetIds: Set<number>;
prepareInputDevices: () => Promise<void>;
setInputVolume: (value: number) => void;
setNoiseSuppressionEnabled: (enabled: boolean) => Promise<void>;
setOutputVolume: (value: number) => void;
setVoxThreshold: (value: number) => void;
setNotificationVolume: (value: number) => void;
setInputDevice: (deviceId: string) => Promise<void>;
setOutputDevice: (deviceId: string) => Promise<void>;
setMicrophoneMuted: (muted: boolean) => void;
startMicrophoneTest: () => Promise<void>;
stopMicrophoneTest: () => void;
startAccompaniment: () => Promise<void>;
stopAccompaniment: () => Promise<void>;
setWhisperActive: (active: boolean) => void;
localizedMessage: (message: string) => string;
showToast: (message: string) => void;
t: (key: string) => string;
}
export function useWebClientAudioControls({
settingsOpen,
microphoneMuted,
inputVolume,
voxThreshold,
notificationVolume,
micLevel,
microphoneTestActive,
accompanimentActive,
accompanimentErrorCode,
whisperTargetIds,
prepareInputDevices,
setInputVolume,
setNoiseSuppressionEnabled,
setOutputVolume,
setVoxThreshold,
setNotificationVolume,
setInputDevice,
setOutputDevice,
setMicrophoneMuted,
startMicrophoneTest,
stopMicrophoneTest,
startAccompaniment,
stopAccompaniment,
setWhisperActive,
localizedMessage,
showToast,
t,
}: UseWebClientAudioControlsOptions) {
const settingsError = ref("");
const whisperPttActive = ref(false);
noiseSuppressionEnabled,
inputVolume,
voxThreshold,
notificationVolume,
micLevel,
microphoneTestActive,
accompanimentActive,
accompanimentErrorCode,
whisperTargetIds,
prepareInputDevices,
setInputVolume,
setNoiseSuppressionEnabled,
setOutputVolume,
setVoxThreshold,
setNotificationVolume,
setInputDevice,
setOutputDevice,
setMicrophoneMuted,
startMicrophoneTest,
stopMicrophoneTest,
startAccompaniment,
stopAccompaniment,
setWhisperActive,
localizedMessage,
showToast,
t,
}: UseWebClientAudioControlsOptions) {
const settingsError = ref("");
const whisperPttActive = ref(false);
const micMeterBars = computed(() => Math.round(micLevel.value * 24));
let settingsGeneration = 0;
let settingsRequest = 0;
@@ -73,39 +75,43 @@ export function useWebClientAudioControls({
const request = ++settingsRequest;
return () => settingsOpen.value && generation === settingsGeneration && request === settingsRequest;
}
function microphoneErrorMessage(error: unknown, fallback = "请检查浏览器权限"): string {
const name = error instanceof DOMException ? error.name : "";
const reasons: Record<string, string> = {
NotAllowedError: "浏览器未授予麦克风权限",
NotFoundError: "未找到可用的麦克风",
NotReadableError: "麦克风可能正被其他程序占用",
OverconstrainedError: "所选麦克风当前不可用",
SecurityError: "浏览器阻止了麦克风访问",
};
return `麦克风访问失败:${reasons[name] ?? fallback}`;
}
function onInputVolume(event: Event): void {
setInputVolume(Number((event.target as HTMLInputElement).value) / 100);
}
function microphoneErrorMessage(error: unknown, fallback = "请检查浏览器权限"): string {
const name = error instanceof DOMException ? error.name : "";
const reasons: Record<string, string> = {
NotAllowedError: "浏览器未授予麦克风权限",
NotFoundError: "未找到可用的麦克风",
NotReadableError: "麦克风可能正被其他程序占用",
OverconstrainedError: "所选麦克风当前不可用",
SecurityError: "浏览器阻止了麦克风访问",
};
return `麦克风访问失败:${reasons[name] ?? fallback}`;
}
function onInputVolume(event: Event): void {
setInputVolume(Number((event.target as HTMLInputElement).value) / 100);
}
function onNoiseSuppressionToggle(event: Event): void {
void setNoiseSuppressionEnabled((event.target as HTMLInputElement).checked);
}
function onOutputVolume(event: Event): void {
setOutputVolume(Number((event.target as HTMLInputElement).value) / 100);
function toggleNoiseSuppression(): void {
void setNoiseSuppressionEnabled(!noiseSuppressionEnabled.value);
}
function onVoxThreshold(event: Event): void {
setVoxThreshold(Number((event.target as HTMLInputElement).value) / 1000);
}
function onNotificationVolume(event: Event): void {
setNotificationVolume(Number((event.target as HTMLInputElement).value) / 100);
}
function onOutputVolume(event: Event): void {
setOutputVolume(Number((event.target as HTMLInputElement).value) / 100);
}
function onVoxThreshold(event: Event): void {
setVoxThreshold(Number((event.target as HTMLInputElement).value) / 1000);
}
function onNotificationVolume(event: Event): void {
setNotificationVolume(Number((event.target as HTMLInputElement).value) / 100);
}
async function onInputDeviceChange(selection: Event | string): Promise<void> {
const isCurrent = beginSettingsRequest();
try {
@@ -124,52 +130,52 @@ export function useWebClientAudioControls({
} catch (error: unknown) {
if (isCurrent()) settingsError.value = localizedMessage(error instanceof Error ? error.message : "无法切换扬声器");
}
}
}
async function toggleMicTest(): Promise<void> {
const isCurrent = beginSettingsRequest();
try {
if (microphoneTestActive.value) stopMicrophoneTest();
else await startMicrophoneTest();
} catch (error: unknown) {
try {
if (microphoneTestActive.value) stopMicrophoneTest();
else await startMicrophoneTest();
} catch (error: unknown) {
if (isCurrent()) settingsError.value = microphoneErrorMessage(error);
}
}
function meterBarHeight(index: number): number {
if (!microphoneTestActive.value) return 5;
const intensity = Math.max(0, micLevel.value - (index / 24) * 0.65);
return 5 + Math.round(intensity * 34);
}
function toggleMicrophone(): void {
setMicrophoneMuted(!microphoneMuted.value);
showToast(t(microphoneMuted.value ? "microphoneMuted" : "microphoneActive"));
}
async function toggleAccompaniment(): Promise<void> {
try {
if (accompanimentActive.value) {
await stopAccompaniment();
showToast(t("accompanimentStopped"));
return;
}
await startAccompaniment();
if (accompanimentActive.value) showToast(t("accompanimentStarted"));
} catch {
const messageKey = accompanimentErrorCode.value === "needsWebRtc"
? "accompanimentNeedsWebRtc"
: accompanimentErrorCode.value === "noAudio"
? "accompanimentNoAudio"
}
}
function meterBarHeight(index: number): number {
if (!microphoneTestActive.value) return 5;
const intensity = Math.max(0, micLevel.value - (index / 24) * 0.65);
return 5 + Math.round(intensity * 34);
}
function toggleMicrophone(): void {
setMicrophoneMuted(!microphoneMuted.value);
showToast(t(microphoneMuted.value ? "microphoneMuted" : "microphoneActive"));
}
async function toggleAccompaniment(): Promise<void> {
try {
if (accompanimentActive.value) {
await stopAccompaniment();
showToast(t("accompanimentStopped"));
return;
}
await startAccompaniment();
if (accompanimentActive.value) showToast(t("accompanimentStarted"));
} catch {
const messageKey = accompanimentErrorCode.value === "needsWebRtc"
? "accompanimentNeedsWebRtc"
: accompanimentErrorCode.value === "noAudio"
? "accompanimentNoAudio"
: accompanimentErrorCode.value === "unsupported"
? "accompanimentUnsupported"
: accompanimentErrorCode.value === "audio"
? "accompanimentAudioFailed"
: "accompanimentPermissionDenied";
showToast(t(messageKey));
}
}
showToast(t(messageKey));
}
}
function onWhisperPttDown(event: PointerEvent): void {
if (!whisperTargetIds.size || whisperPttActive.value || event.button !== 0 || !event.isPrimary) return;
const target = event.currentTarget as HTMLElement | null;
@@ -214,45 +220,46 @@ export function useWebClientAudioControls({
setWhisperActive(false);
// Clear ownership first: releasing capture can synchronously emit lostpointercapture.
if (pointer?.target.hasPointerCapture(pointer.id)) pointer.target.releasePointerCapture(pointer.id);
}
}
watch(settingsOpen, (open) => {
settingsGeneration++;
if (open) {
const isCurrent = beginSettingsRequest();
prepareInputDevices().catch((error: unknown) => {
if (isCurrent()) settingsError.value = microphoneErrorMessage(error);
});
} else {
stopMicrophoneTest();
}
});
} else {
stopMicrophoneTest();
}
}, { flush: "sync" });
onScopeDispose(() => {
settingsGeneration++;
stopMicrophoneTest();
stopWhisperTalk();
});
return {
settingsError,
whisperPttActive,
micMeterBars,
onInputVolume,
return {
settingsError,
whisperPttActive,
micMeterBars,
onInputVolume,
onNoiseSuppressionToggle,
onOutputVolume,
onVoxThreshold,
onNotificationVolume,
onInputDeviceChange,
onOutputDeviceChange,
toggleMicTest,
microphoneErrorMessage,
meterBarHeight,
toggleMicrophone,
toggleAccompaniment,
onWhisperPttDown,
toggleNoiseSuppression,
onOutputVolume,
onVoxThreshold,
onNotificationVolume,
onInputDeviceChange,
onOutputDeviceChange,
toggleMicTest,
microphoneErrorMessage,
meterBarHeight,
toggleMicrophone,
toggleAccompaniment,
onWhisperPttDown,
onWhisperPttUp,
onWhisperPttKeyDown,
onWhisperPttKeyUp,
stopWhisperTalk,
};
}
stopWhisperTalk,
};
}
+2 -2
View File
@@ -46,10 +46,10 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
{
id: BUILTIN_KAAK_SKIN_ID,
name: "KAAK",
version: "3.1.52",
version: "3.1.54",
author: "WebSpeak Project",
license: "AGPL-3.0-only",
description: "A KOOK-inspired voice-room workspace with collapsible voice groups, channel chat, TeamSpeak profile cards, and accessible host-owned member controls.",
description: "A KOOK-inspired voice-room workspace with collapsible voice groups, channel chat, TeamSpeak profile cards, accessible host-owned member controls, and WebSpeak screen sharing.",
minAppVersion: "0.2.7-preview",
installedAt: 0,
builtIn: true,
+250 -255
View File
@@ -1,262 +1,257 @@
import layoutRuntimeCss from "../skins/layout-runtime.css?inline";
import {
canEditSkinLayoutComponent,
getSkinLayoutComponentId,
getSkinLayoutComponent,
type SkinLayoutDocument,
type SkinLayoutPage,
type SkinLayoutPlacement,
type SkinLayoutProfile,
} from "../../../src/shared/skin-layout.js";
import {
clearSkinLayoutOverrides,
loadSkinLayoutOverrides,
saveSkinLayoutOverrides,
updateSkinLayoutOverride,
} from "./skin-layout-storage.js";
const STYLE_ID = "webspeak-layout-runtime";
const MOBILE_QUERY = "(max-width: 740px)";
const TABLET_QUERY = "(min-width: 741px) and (max-width: 1100px)";
export interface ActiveSkinLayoutContext {
root: HTMLElement;
skinId: string;
page: SkinLayoutPage;
profile: SkinLayoutProfile;
}
let activePackageSkinId: string | null = null;
let activePackageLayout: SkinLayoutDocument | null = null;
let observer: MutationObserver | null = null;
let refreshFrame = 0;
let editorEnabled = false;
let selectedComponentId: string | null = null;
let previewComponentId: string | null = null;
let previewPlacement: SkinLayoutPlacement | null = null;
let previewScope = "";
function isLayoutPage(value: string | undefined): value is SkinLayoutPage {
return value === "home" || value === "voice" || value === "demo";
}
function currentProfile(): SkinLayoutProfile {
if (typeof window === "undefined") return "desktop";
if (window.matchMedia(MOBILE_QUERY).matches) return "mobile";
return window.matchMedia(TABLET_QUERY).matches ? "tablet" : "desktop";
}
function activeRoots(): HTMLElement[] {
if (typeof document === "undefined") return [];
return [...document.querySelectorAll<HTMLElement>(".ws-skin-root[data-ws-page]")];
}
export function getActiveSkinLayoutContext(): ActiveSkinLayoutContext | null {
const root = activeRoots()[0];
if (!root || !isLayoutPage(root.dataset.wsPage)) return null;
return {
root,
skinId: root.dataset.wsSkin || activePackageSkinId || "builtin.light",
page: root.dataset.wsPage,
profile: currentProfile(),
};
}
function effectivePlacements(context: ActiveSkinLayoutContext): Record<string, SkinLayoutPlacement> {
const packageEntries = activePackageSkinId === context.skinId
? activePackageLayout?.pages[context.page]?.[context.profile] ?? {}
: {};
const userEntries = loadSkinLayoutOverrides(context.skinId).pages[context.page]?.[context.profile] ?? {};
const result: Record<string, SkinLayoutPlacement> = {};
for (const [id, placement] of Object.entries(packageEntries)) result[id] = { ...placement };
for (const [id, placement] of Object.entries(userEntries)) result[id] = { ...result[id], ...placement };
const scope = context.skinId + ":" + context.page + ":" + context.profile;
if (previewComponentId && previewPlacement && previewScope === scope) {
result[previewComponentId] = { ...result[previewComponentId], ...previewPlacement };
}
return result;
}
function setVariable(element: HTMLElement, dataFlag: string, variable: string, value: string | undefined): void {
if (value === undefined) {
delete element.dataset[dataFlag];
element.style.removeProperty(variable);
} else {
element.dataset[dataFlag] = "true";
element.style.setProperty(variable, value);
}
}
function clearLayoutAttributes(element: HTMLElement): void {
for (const key of ["wsLayoutActive", "wsLayoutHidden", "wsLayoutSelected", "wsLayoutForeground", "wsLayoutBackground", "wsLayoutBorder", "wsLayoutRadius", "wsLayoutWidth", "wsLayoutHeight", "wsLayoutOrder", "wsLayoutTouchTarget"]) {
delete element.dataset[key];
}
for (const key of ["--ws-layout-x", "--ws-layout-y", "--ws-layout-scale", "--ws-layout-order", "--ws-layout-width", "--ws-layout-height", "--ws-layout-foreground", "--ws-layout-background", "--ws-layout-border", "--ws-layout-radius"]) {
element.style.removeProperty(key);
}
}
function componentId(element: HTMLElement): string | null {
return getSkinLayoutComponentId(element.dataset.wsPart, element.dataset.wsControlKind);
}
function trustedAncestorIds(element: HTMLElement, root: HTMLElement): string[] {
const ids: string[] = [];
let ancestor = element.parentElement;
while (ancestor && ancestor !== root) {
const id = componentId(ancestor);
if (id) ids.push(id);
ancestor = ancestor.parentElement;
}
return ids;
}
function applyRoot(root: HTMLElement): void {
const pageValue = root.dataset.wsPage;
if (!isLayoutPage(pageValue)) return;
const skinId = root.dataset.wsSkin || activePackageSkinId || "builtin.light";
const context: ActiveSkinLayoutContext = { root, skinId, page: pageValue, profile: currentProfile() };
const placements = effectivePlacements(context);
const nodes = [
...(root.matches("[data-ws-part]") ? [root] : []),
...root.querySelectorAll<HTMLElement>("[data-ws-part]"),
];
for (const element of nodes) {
const id = componentId(element);
const component = id ? getSkinLayoutComponent(id, context.page) : undefined;
if (!component || !canEditSkinLayoutComponent(id!, context.page, trustedAncestorIds(element, root))) {
clearLayoutAttributes(element);
continue;
}
import layoutRuntimeCss from "../skins/layout-runtime.css?inline";
import {
canEditSkinLayoutComponent,
getSkinLayoutComponentId,
getSkinLayoutComponent,
type SkinLayoutDocument,
type SkinLayoutPage,
type SkinLayoutPlacement,
type SkinLayoutProfile,
} from "../../../src/shared/skin-layout.js";
import {
clearSkinLayoutOverrides,
loadSkinLayoutOverrides,
saveSkinLayoutOverrides,
updateSkinLayoutOverride,
} from "./skin-layout-storage.js";
const STYLE_ID = "webspeak-layout-runtime";
const MOBILE_QUERY = "(max-width: 740px)";
const TABLET_QUERY = "(min-width: 741px) and (max-width: 1100px)";
export interface ActiveSkinLayoutContext {
root: HTMLElement;
skinId: string;
page: SkinLayoutPage;
profile: SkinLayoutProfile;
}
let activePackageSkinId: string | null = null;
let activePackageLayout: SkinLayoutDocument | null = null;
let observer: MutationObserver | null = null;
let refreshFrame = 0;
let editorEnabled = false;
let selectedComponentId: string | null = null;
let previewComponentId: string | null = null;
let previewPlacement: SkinLayoutPlacement | null = null;
let previewScope = "";
function isLayoutPage(value: string | undefined): value is SkinLayoutPage {
return value === "home" || value === "voice" || value === "demo";
}
function currentProfile(): SkinLayoutProfile {
if (typeof window === "undefined") return "desktop";
if (window.matchMedia(MOBILE_QUERY).matches) return "mobile";
return window.matchMedia(TABLET_QUERY).matches ? "tablet" : "desktop";
}
function activeRoots(): HTMLElement[] {
if (typeof document === "undefined") return [];
return [...document.querySelectorAll<HTMLElement>(".ws-skin-root[data-ws-page]")];
}
export function getActiveSkinLayoutContext(): ActiveSkinLayoutContext | null {
const root = activeRoots()[0];
if (!root || !isLayoutPage(root.dataset.wsPage)) return null;
return {
root,
skinId: root.dataset.wsSkin || activePackageSkinId || "builtin.light",
page: root.dataset.wsPage,
profile: currentProfile(),
};
}
function effectivePlacements(context: ActiveSkinLayoutContext): Record<string, SkinLayoutPlacement> {
const packageEntries = activePackageSkinId === context.skinId
? activePackageLayout?.pages[context.page]?.[context.profile] ?? {}
: {};
const userEntries = loadSkinLayoutOverrides(context.skinId).pages[context.page]?.[context.profile] ?? {};
const result: Record<string, SkinLayoutPlacement> = {};
for (const [id, placement] of Object.entries(packageEntries)) result[id] = { ...placement };
for (const [id, placement] of Object.entries(userEntries)) result[id] = { ...result[id], ...placement };
const scope = context.skinId + ":" + context.page + ":" + context.profile;
if (previewComponentId && previewPlacement && previewScope === scope) {
result[previewComponentId] = { ...result[previewComponentId], ...previewPlacement };
}
return result;
}
function setVariable(element: HTMLElement, dataFlag: string, variable: string, value: string | undefined): void {
if (value === undefined) {
delete element.dataset[dataFlag];
element.style.removeProperty(variable);
} else {
element.dataset[dataFlag] = "true";
element.style.setProperty(variable, value);
}
}
function clearLayoutAttributes(element: HTMLElement): void {
for (const key of ["wsLayoutActive", "wsLayoutHidden", "wsLayoutSelected", "wsLayoutForeground", "wsLayoutBackground", "wsLayoutBorder", "wsLayoutRadius", "wsLayoutWidth", "wsLayoutHeight", "wsLayoutOrder", "wsLayoutTouchTarget"]) {
delete element.dataset[key];
}
for (const key of ["--ws-layout-x", "--ws-layout-y", "--ws-layout-scale", "--ws-layout-order", "--ws-layout-width", "--ws-layout-height", "--ws-layout-foreground", "--ws-layout-background", "--ws-layout-border", "--ws-layout-radius"]) {
element.style.removeProperty(key);
}
}
function componentId(element: HTMLElement): string | null {
return getSkinLayoutComponentId(element.dataset.wsPart, element.dataset.wsControlKind);
}
function trustedAncestorIds(element: HTMLElement, root: HTMLElement): string[] {
const ids: string[] = [];
let ancestor = element.parentElement;
while (ancestor && ancestor !== root) {
const id = componentId(ancestor);
if (id) ids.push(id);
ancestor = ancestor.parentElement;
}
return ids;
}
function applyRoot(root: HTMLElement): void {
const pageValue = root.dataset.wsPage;
if (!isLayoutPage(pageValue)) return;
const skinId = root.dataset.wsSkin || activePackageSkinId || "builtin.light";
const context: ActiveSkinLayoutContext = { root, skinId, page: pageValue, profile: currentProfile() };
const placements = effectivePlacements(context);
const nodes = [
...(root.matches("[data-ws-part]") ? [root] : []),
...root.querySelectorAll<HTMLElement>("[data-ws-part]"),
];
for (const element of nodes) {
const id = componentId(element);
const component = id ? getSkinLayoutComponent(id, context.page) : undefined;
if (!component || !canEditSkinLayoutComponent(id!, context.page, trustedAncestorIds(element, root))) {
clearLayoutAttributes(element);
continue;
}
const placement = placements[id!];
if (!placement || !Object.keys(placement).length) {
clearLayoutAttributes(element);
// Registered touch controls keep their minimum hit area even before a
// user applies a layout override; editing must never be required for safety.
if (component.minTouchTarget) element.dataset.wsLayoutTouchTarget = String(component.minTouchTarget);
continue;
}
element.dataset.wsLayoutActive = "true";
if (component.minTouchTarget) element.dataset.wsLayoutTouchTarget = String(component.minTouchTarget);
else delete element.dataset.wsLayoutTouchTarget;
if (placement.visible === false) element.dataset.wsLayoutHidden = "true";
else delete element.dataset.wsLayoutHidden;
if (placement.x !== undefined) element.style.setProperty("--ws-layout-x", placement.x + "px");
else element.style.removeProperty("--ws-layout-x");
if (placement.y !== undefined) element.style.setProperty("--ws-layout-y", placement.y + "px");
else element.style.removeProperty("--ws-layout-y");
if (placement.scale !== undefined) element.style.setProperty("--ws-layout-scale", String(placement.scale));
else element.style.removeProperty("--ws-layout-scale");
setVariable(element, "wsLayoutOrder", "--ws-layout-order", placement.order === undefined ? undefined : String(placement.order));
setVariable(element, "wsLayoutWidth", "--ws-layout-width", placement.width === undefined ? undefined : placement.width + "px");
setVariable(element, "wsLayoutHeight", "--ws-layout-height", placement.height === undefined ? undefined : placement.height + "px");
setVariable(element, "wsLayoutForeground", "--ws-layout-foreground", placement.foreground);
setVariable(element, "wsLayoutBackground", "--ws-layout-background", placement.background);
setVariable(element, "wsLayoutBorder", "--ws-layout-border", placement.border);
setVariable(element, "wsLayoutRadius", "--ws-layout-radius", placement.radius === undefined ? undefined : placement.radius + "px");
if (editorEnabled && selectedComponentId === id) element.dataset.wsLayoutSelected = "true";
else delete element.dataset.wsLayoutSelected;
}
root.dataset.wsLayoutEditing = editorEnabled ? "true" : "false";
}
export function refreshSkinLayout(): void {
if (typeof document === "undefined") return;
for (const root of activeRoots()) applyRoot(root);
}
function scheduleRefresh(): void {
if (typeof window === "undefined" || refreshFrame) return;
refreshFrame = window.requestAnimationFrame(() => {
refreshFrame = 0;
refreshSkinLayout();
});
}
export function initializeSkinLayoutRuntime(): void {
if (typeof document === "undefined") return;
if (!document.getElementById(STYLE_ID)) {
const style = document.createElement("style");
style.id = STYLE_ID;
style.textContent = layoutRuntimeCss;
document.head.append(style);
}
if (!observer) {
observer = new MutationObserver(scheduleRefresh);
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ["data-ws-page", "data-ws-skin", "data-ws-part", "data-ws-control-kind"],
});
window.addEventListener("resize", scheduleRefresh, { passive: true });
}
scheduleRefresh();
}
export function setSkinLayoutPackage(skinId: string, layout: SkinLayoutDocument | null): void {
activePackageSkinId = skinId;
activePackageLayout = layout;
previewComponentId = null;
previewPlacement = null;
previewScope = "";
scheduleRefresh();
}
export function setSkinLayoutEditorState(enabled: boolean, selectedId: string | null = selectedComponentId): void {
editorEnabled = enabled;
selectedComponentId = enabled ? selectedId : null;
scheduleRefresh();
}
export function getEffectiveSkinLayoutPlacement(componentIdValue: string): SkinLayoutPlacement | undefined {
const context = getActiveSkinLayoutContext();
if (!context || !getSkinLayoutComponent(componentIdValue, context.page)?.editable) return undefined;
return effectivePlacements(context)[componentIdValue];
}
export function getActiveSkinLayoutOverride(componentIdValue: string): SkinLayoutPlacement | undefined {
const context = getActiveSkinLayoutContext();
if (!context || !getSkinLayoutComponent(componentIdValue, context.page)?.editable) return undefined;
return loadSkinLayoutOverrides(context.skinId).pages[context.page]?.[context.profile]?.[componentIdValue];
}
export function previewActiveSkinLayoutPlacement(componentIdValue: string, placement: SkinLayoutPlacement | null): void {
const context = getActiveSkinLayoutContext();
previewComponentId = context && placement ? componentIdValue : null;
previewPlacement = context ? placement : null;
previewScope = context ? context.skinId + ":" + context.page + ":" + context.profile : "";
scheduleRefresh();
}
export function saveActiveSkinLayoutPlacement(componentIdValue: string, placement: SkinLayoutPlacement | null): void {
const context = getActiveSkinLayoutContext();
if (!context) throw new Error("There is no active public skin layout.");
previewComponentId = null;
previewPlacement = null;
previewScope = "";
updateSkinLayoutOverride(context.skinId, context.page, context.profile, componentIdValue, placement);
scheduleRefresh();
}
export function getActiveSkinLayoutOverrides(): SkinLayoutDocument {
const context = getActiveSkinLayoutContext();
return context ? loadSkinLayoutOverrides(context.skinId) : { schemaVersion: 1, pages: {} };
}
export function replaceActiveSkinLayoutOverrides(layout: SkinLayoutDocument): void {
const context = getActiveSkinLayoutContext();
if (!context) throw new Error("There is no active public skin layout.");
saveSkinLayoutOverrides(context.skinId, layout);
scheduleRefresh();
}
export function clearActiveSkinLayoutOverrides(): void {
const context = getActiveSkinLayoutContext();
if (!context) return;
previewComponentId = null;
previewPlacement = null;
previewScope = "";
clearSkinLayoutOverrides(context.skinId);
scheduleRefresh();
}
else delete element.dataset.wsLayoutHidden;
if (placement.x !== undefined) element.style.setProperty("--ws-layout-x", placement.x + "px");
else element.style.removeProperty("--ws-layout-x");
if (placement.y !== undefined) element.style.setProperty("--ws-layout-y", placement.y + "px");
else element.style.removeProperty("--ws-layout-y");
if (placement.scale !== undefined) element.style.setProperty("--ws-layout-scale", String(placement.scale));
else element.style.removeProperty("--ws-layout-scale");
setVariable(element, "wsLayoutOrder", "--ws-layout-order", placement.order === undefined ? undefined : String(placement.order));
setVariable(element, "wsLayoutWidth", "--ws-layout-width", placement.width === undefined ? undefined : placement.width + "px");
setVariable(element, "wsLayoutHeight", "--ws-layout-height", placement.height === undefined ? undefined : placement.height + "px");
setVariable(element, "wsLayoutForeground", "--ws-layout-foreground", placement.foreground);
setVariable(element, "wsLayoutBackground", "--ws-layout-background", placement.background);
setVariable(element, "wsLayoutBorder", "--ws-layout-border", placement.border);
setVariable(element, "wsLayoutRadius", "--ws-layout-radius", placement.radius === undefined ? undefined : placement.radius + "px");
if (editorEnabled && selectedComponentId === id) element.dataset.wsLayoutSelected = "true";
else delete element.dataset.wsLayoutSelected;
}
root.dataset.wsLayoutEditing = editorEnabled ? "true" : "false";
}
export function refreshSkinLayout(): void {
if (typeof document === "undefined") return;
for (const root of activeRoots()) applyRoot(root);
}
function scheduleRefresh(): void {
if (typeof window === "undefined" || refreshFrame) return;
refreshFrame = window.requestAnimationFrame(() => {
refreshFrame = 0;
refreshSkinLayout();
});
}
export function initializeSkinLayoutRuntime(): void {
if (typeof document === "undefined") return;
if (!document.getElementById(STYLE_ID)) {
const style = document.createElement("style");
style.id = STYLE_ID;
style.textContent = layoutRuntimeCss;
document.head.append(style);
}
if (!observer) {
observer = new MutationObserver(scheduleRefresh);
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ["data-ws-page", "data-ws-skin", "data-ws-part", "data-ws-control-kind"],
});
window.addEventListener("resize", scheduleRefresh, { passive: true });
}
scheduleRefresh();
}
export function setSkinLayoutPackage(skinId: string, layout: SkinLayoutDocument | null): void {
activePackageSkinId = skinId;
activePackageLayout = layout;
previewComponentId = null;
previewPlacement = null;
previewScope = "";
scheduleRefresh();
}
export function setSkinLayoutEditorState(enabled: boolean, selectedId: string | null = selectedComponentId): void {
editorEnabled = enabled;
selectedComponentId = enabled ? selectedId : null;
scheduleRefresh();
}
export function getEffectiveSkinLayoutPlacement(componentIdValue: string): SkinLayoutPlacement | undefined {
const context = getActiveSkinLayoutContext();
if (!context || !getSkinLayoutComponent(componentIdValue, context.page)?.editable) return undefined;
return effectivePlacements(context)[componentIdValue];
}
export function getActiveSkinLayoutOverride(componentIdValue: string): SkinLayoutPlacement | undefined {
const context = getActiveSkinLayoutContext();
if (!context || !getSkinLayoutComponent(componentIdValue, context.page)?.editable) return undefined;
return loadSkinLayoutOverrides(context.skinId).pages[context.page]?.[context.profile]?.[componentIdValue];
}
export function previewActiveSkinLayoutPlacement(componentIdValue: string, placement: SkinLayoutPlacement | null): void {
const context = getActiveSkinLayoutContext();
previewComponentId = context && placement ? componentIdValue : null;
previewPlacement = context ? placement : null;
previewScope = context ? context.skinId + ":" + context.page + ":" + context.profile : "";
scheduleRefresh();
}
export function saveActiveSkinLayoutPlacement(componentIdValue: string, placement: SkinLayoutPlacement | null): void {
const context = getActiveSkinLayoutContext();
if (!context) throw new Error("There is no active public skin layout.");
previewComponentId = null;
previewPlacement = null;
previewScope = "";
updateSkinLayoutOverride(context.skinId, context.page, context.profile, componentIdValue, placement);
scheduleRefresh();
}
export function getActiveSkinLayoutOverrides(): SkinLayoutDocument {
const context = getActiveSkinLayoutContext();
return context ? loadSkinLayoutOverrides(context.skinId) : { schemaVersion: 1, pages: {} };
}
export function replaceActiveSkinLayoutOverrides(layout: SkinLayoutDocument): void {
const context = getActiveSkinLayoutContext();
if (!context) throw new Error("There is no active public skin layout.");
saveSkinLayoutOverrides(context.skinId, layout);
scheduleRefresh();
}
export function clearActiveSkinLayoutOverrides(): void {
const context = getActiveSkinLayoutContext();
if (!context) return;
previewComponentId = null;
previewPlacement = null;
previewScope = "";
clearSkinLayoutOverrides(context.skinId);
scheduleRefresh();
}
Binary file not shown.
+42 -47
View File
@@ -1,48 +1,43 @@
.ws-skin-root[data-ws-layout-hidden="true"],
.ws-skin-root [data-ws-layout-hidden="true"] {
display: none !important;
}
.ws-skin-root [data-ws-layout-active="true"] {
translate: var(--ws-layout-x, 0px) var(--ws-layout-y, 0px) !important;
scale: var(--ws-layout-scale, 1) !important;
}
.ws-skin-root [data-ws-layout-order="true"] {
order: var(--ws-layout-order) !important;
}
.ws-skin-root [data-ws-layout-width="true"] {
width: var(--ws-layout-width) !important;
}
.ws-skin-root [data-ws-layout-height="true"] {
height: var(--ws-layout-height) !important;
}
.ws-skin-root [data-ws-layout-touch-target="44"] {
min-width: 44px !important;
min-height: 44px !important;
}
.ws-skin-root[data-ws-layout-hidden="true"],
.ws-skin-root [data-ws-layout-hidden="true"] {
display: none !important;
}
.ws-skin-root [data-ws-layout-active="true"] {
translate: var(--ws-layout-x, 0px) var(--ws-layout-y, 0px) !important;
scale: var(--ws-layout-scale, 1) !important;
}
.ws-skin-root [data-ws-layout-order="true"] {
order: var(--ws-layout-order) !important;
}
.ws-skin-root [data-ws-layout-width="true"] {
width: var(--ws-layout-width) !important;
}
.ws-skin-root [data-ws-layout-height="true"] {
height: var(--ws-layout-height) !important;
}
.ws-skin-root [data-ws-layout-foreground="true"] {
color: var(--ws-layout-foreground) !important;
}
.ws-skin-root [data-ws-layout-background="true"] {
background-color: var(--ws-layout-background) !important;
}
.ws-skin-root [data-ws-layout-border="true"] {
border-color: var(--ws-layout-border) !important;
}
.ws-skin-root [data-ws-layout-radius="true"] {
border-radius: var(--ws-layout-radius) !important;
}
.ws-skin-root[data-ws-layout-editing="true"] [data-ws-layout-selected="true"] {
outline: 2px solid #4f46e5 !important;
outline-offset: 2px !important;
cursor: move !important;
}
color: var(--ws-layout-foreground) !important;
}
.ws-skin-root [data-ws-layout-background="true"] {
background-color: var(--ws-layout-background) !important;
}
.ws-skin-root [data-ws-layout-border="true"] {
border-color: var(--ws-layout-border) !important;
}
.ws-skin-root [data-ws-layout-radius="true"] {
border-radius: var(--ws-layout-radius) !important;
}
.ws-skin-root[data-ws-layout-editing="true"] [data-ws-layout-selected="true"] {
outline: 2px solid #4f46e5 !important;
outline-offset: 2px !important;
cursor: move !important;
}
Binary file not shown.