-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(presenter): use screen capture mirroring, resolve #1987
- Loading branch information
Showing
13 changed files
with
245 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { | ||
getHashColorFromString, | ||
getHsla, | ||
} from '../logic/color' | ||
const props = withDefaults( | ||
defineProps<{ | ||
text?: string | ||
color?: boolean | number | ||
as?: string | ||
size?: string | ||
}>(), | ||
{ | ||
color: true, | ||
}, | ||
) | ||
const style = computed(() => { | ||
if (!props.text || props.color === false) | ||
return {} | ||
return { | ||
color: typeof props.color === 'number' | ||
? getHsla(props.color) | ||
: getHashColorFromString(props.text), | ||
background: typeof props.color === 'number' | ||
? getHsla(props.color, 0.1) | ||
: getHashColorFromString(props.text, 0.1), | ||
} | ||
}) | ||
const sizeClasses = computed(() => { | ||
switch (props.size || 'sm') { | ||
case 'sm': | ||
return 'px-1.5 text-11px leading-1.6em' | ||
} | ||
return '' | ||
}) | ||
</script> | ||
|
||
<template> | ||
<component :is="as || 'span'" ws-nowrap rounded :class="sizeClasses" :style> | ||
<slot> | ||
<span v-text="props.text" /> | ||
</slot> | ||
</component> | ||
</template> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script setup lang="ts"> | ||
import { shallowRef, useTemplateRef } from 'vue' | ||
const video = useTemplateRef('video') | ||
const stream = shallowRef<MediaStream | null>(null) | ||
const started = shallowRef(false) | ||
async function startCapture() { | ||
stream.value = await navigator.mediaDevices.getDisplayMedia({ | ||
video: { | ||
// @ts-expect-error missing types | ||
cursor: 'always', | ||
}, | ||
audio: false, | ||
selfBrowserSurface: 'include', | ||
preferCurrentTab: false, | ||
}) | ||
video.value!.srcObject = stream.value | ||
video.value!.play() | ||
started.value = true | ||
stream.value.addEventListener('inactive', () => { | ||
video.value!.srcObject = null | ||
started.value = false | ||
}) | ||
stream.value.addEventListener('ended', () => { | ||
video.value!.srcObject = null | ||
started.value = false | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div h-full w-full> | ||
<video v-show="started" ref="video" class="w-full h-full object-contain" /> | ||
<div v-if="!started" w-full h-full flex="~ col gap-4 items-center justify-center"> | ||
<div op50> | ||
Use screen capturing to mirror your main screen back to presenter view.<br> | ||
Click the button below and <b>select your other monitor or window</b>. | ||
</div> | ||
<button class="slidev-form-button" @click="startCapture"> | ||
Start Screen Mirroring | ||
</button> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script setup lang="ts"> | ||
import Badge from './Badge.vue' | ||
defineProps<{ | ||
options: { label: string, value: any }[] | ||
modelValue: any | ||
}>() | ||
defineEmits<{ | ||
(event: 'update:modelValue', newValue: any): void | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div flex="~ gap-1 items-center" rounded bg-gray:2 p1> | ||
<Badge | ||
v-for="option in options" | ||
:key="option.value" | ||
class="px-2 py-1 text-xs font-mono" | ||
:class="option.value === modelValue ? '' : 'op50'" | ||
:color="option.value === modelValue" | ||
:aria-pressed="option.value === modelValue" | ||
size="none" | ||
:text="option.label" | ||
as="button" | ||
@click="$emit('update:modelValue', option.value)" | ||
/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { isDark } from './dark' | ||
|
||
/** | ||
* Predefined color map for matching the branding | ||
* | ||
* Accpet a 6-digit hex color string or a hue number | ||
* Hue numbers are preferred because they will adapt better contrast in light/dark mode | ||
* | ||
* Hue numbers reference: | ||
* - 0: red | ||
* - 30: orange | ||
* - 60: yellow | ||
* - 120: green | ||
* - 180: cyan | ||
* - 240: blue | ||
* - 270: purple | ||
*/ | ||
const predefinedColorMap = { | ||
error: 0, | ||
client: 60, | ||
} as Record<string, number> | ||
|
||
export function getHashColorFromString( | ||
name: string, | ||
opacity: number | string = 1, | ||
) { | ||
if (predefinedColorMap[name]) | ||
return getHsla(predefinedColorMap[name], opacity) | ||
|
||
let hash = 0 | ||
for (let i = 0; i < name.length; i++) | ||
hash = name.charCodeAt(i) + ((hash << 5) - hash) | ||
const hue = hash % 360 | ||
return getHsla(hue, opacity) | ||
} | ||
|
||
export function getHsla( | ||
hue: number, | ||
opacity: number | string = 1, | ||
) { | ||
const saturation = hue === -1 | ||
? 0 | ||
: isDark.value ? 50 : 100 | ||
const lightness = isDark.value ? 60 : 20 | ||
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${opacity})` | ||
} | ||
|
||
export function getPluginColor(name: string, opacity = 1): string { | ||
if (predefinedColorMap[name]) { | ||
const color = predefinedColorMap[name] | ||
if (typeof color === 'number') { | ||
return getHsla(color, opacity) | ||
} | ||
else { | ||
if (opacity === 1) | ||
return color | ||
const opacityHex = Math.floor(opacity * 255).toString(16).padStart(2, '0') | ||
return color + opacityHex | ||
} | ||
} | ||
return getHashColorFromString(name, opacity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.