-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(play): support js engine in the playground
- Loading branch information
Showing
7 changed files
with
144 additions
and
31 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,68 @@ | ||
<script setup lang="ts"> | ||
import { isDark } from './state' | ||
const props = withDefaults( | ||
defineProps<{ | ||
text?: string | ||
color?: boolean | number | ||
as?: string | ||
size?: string | ||
}>(), | ||
{ | ||
color: true, | ||
}, | ||
) | ||
function getHashColorFromString( | ||
name: string, | ||
opacity: number | string = 1, | ||
) { | ||
if (name === 'JavaScript') | ||
return getHsla(45, 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) | ||
} | ||
function getHsla( | ||
hue: number, | ||
opacity: number | string = 1, | ||
) { | ||
const saturation = hue === -1 | ||
? 0 | ||
: isDark.value ? 60 : 100 | ||
const lightness = isDark.value ? 70 : 20 | ||
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${opacity})` | ||
} | ||
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 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,31 @@ | ||
<script setup lang="ts"> | ||
import Badge from './Badge.vue' | ||
defineProps<{ | ||
options: { label: string, value: string }[] | ||
modelValue: string | ||
}>() | ||
defineEmits<{ | ||
(event: 'update:modelValue', newValue: string): void | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div | ||
flex="~ gap-1 items-center" border="~ base rounded" bg-subtle 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const isDark = useDark() | ||
|
||
export const theme = useStorage('tm-theme', 'vitesse-dark') | ||
export const grammar = useStorage('tm-grammar', 'javascript') | ||
export const engine = useStorage<'wasm' | 'js'>('tm-use-engine', 'wasm') |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.