style: lint fix
This commit is contained in:
parent
aeee0ec8de
commit
4fcbd5511e
@ -15,7 +15,7 @@ const api = 'https://caniuse.pengzhanbo.cn/features.json'
|
||||
|
||||
const pastVersions: SelectItem[] = [
|
||||
{ label: '不显示旧版本', value: '0' },
|
||||
...Array(5).fill(0).map((_, i) => ({
|
||||
...Array.from({ length: 5 }).fill(0).map((_, i) => ({
|
||||
label: `旧版本(当前版本 - ${i + 1})`,
|
||||
value: `${i + 1}`,
|
||||
})),
|
||||
@ -23,7 +23,7 @@ const pastVersions: SelectItem[] = [
|
||||
|
||||
const futureVersions: SelectItem[] = [
|
||||
{ label: '不显示未来版本', value: '0' },
|
||||
...Array(3).fill(0).map((_, i) => ({
|
||||
...Array.from({ length: 3 }).fill(0).map((_, i) => ({
|
||||
label: `未来版本(当前版本 + ${i + 1})`,
|
||||
value: `${i + 1}`,
|
||||
})),
|
||||
|
||||
@ -114,16 +114,6 @@ export function setupThemeColors() {
|
||||
return content
|
||||
}
|
||||
|
||||
function resolveDefaultColors(type: 'light' | 'dark') {
|
||||
return preset.map(group => ({
|
||||
name: group.name,
|
||||
group: group.group.map(item => ({
|
||||
...item,
|
||||
value: DEFAULT_PRESET[type][item.key],
|
||||
})),
|
||||
}))
|
||||
}
|
||||
|
||||
function reset() {
|
||||
lightColors.value = resolveDefaultColors('light')
|
||||
darkColors.value = resolveDefaultColors('dark')
|
||||
@ -137,6 +127,16 @@ export function setupThemeColors() {
|
||||
})
|
||||
}
|
||||
|
||||
function resolveDefaultColors(type: 'light' | 'dark') {
|
||||
return preset.map(group => ({
|
||||
name: group.name,
|
||||
group: group.group.map(item => ({
|
||||
...item,
|
||||
value: DEFAULT_PRESET[type][item.key],
|
||||
})),
|
||||
}))
|
||||
}
|
||||
|
||||
export function useThemeColors() {
|
||||
const result = inject(themeColorSymbol)
|
||||
|
||||
|
||||
@ -31,18 +31,6 @@ export function useSize<T extends HTMLElement>(
|
||||
const width = computed(() => toValue(options.width) || '100%')
|
||||
const height = ref('auto')
|
||||
|
||||
const getRadio = (ratio: number | string | undefined): number => {
|
||||
if (typeof ratio === 'string') {
|
||||
const [width, height] = ratio.split(':')
|
||||
const parsedRadio = Number(width) / Number(height)
|
||||
|
||||
if (!Number.isNaN(parsedRadio))
|
||||
return parsedRadio
|
||||
}
|
||||
|
||||
return typeof ratio === 'number' ? ratio : 16 / 9
|
||||
}
|
||||
|
||||
const getHeight = (width: number): string => {
|
||||
const height = toValue(options.height)
|
||||
const ratio = getRadio(toValue(options.ratio))
|
||||
@ -66,3 +54,15 @@ export function useSize<T extends HTMLElement>(
|
||||
|
||||
return { el, width, height, resize }
|
||||
}
|
||||
|
||||
function getRadio(ratio: number | string | undefined): number {
|
||||
if (typeof ratio === 'string') {
|
||||
const [width, height] = ratio.split(':')
|
||||
const parsedRadio = Number(width) / Number(height)
|
||||
|
||||
if (!Number.isNaN(parsedRadio))
|
||||
return parsedRadio
|
||||
}
|
||||
|
||||
return typeof ratio === 'number' ? ratio : 16 / 9
|
||||
}
|
||||
|
||||
@ -31,27 +31,6 @@ export async function highlight(
|
||||
await options.shikiSetup?.(highlighter)
|
||||
|
||||
const loadedLanguages = highlighter.getLoadedLanguages()
|
||||
const removeMustache = (s: string, mustaches: Map<string, string>) => {
|
||||
return s.replace(mustacheRE, (match) => {
|
||||
let marker = mustaches.get(match)
|
||||
if (!marker) {
|
||||
marker = nanoid()
|
||||
mustaches.set(match, marker)
|
||||
}
|
||||
return marker
|
||||
})
|
||||
}
|
||||
|
||||
const restoreMustache = (s: string, mustaches: Map<string, string>, twoslash: boolean) => {
|
||||
mustaches.forEach((marker, match) => {
|
||||
s = s.replaceAll(marker, match)
|
||||
})
|
||||
|
||||
if (twoslash)
|
||||
s = s.replace(/\{/g, '{')
|
||||
|
||||
return `${s}\n`
|
||||
}
|
||||
|
||||
return (str: string, language: string, attrs: string = '') => {
|
||||
const lang = getLanguage(loadedLanguages, language, defaultLang)
|
||||
@ -85,3 +64,25 @@ export async function highlight(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeMustache(s: string, mustaches: Map<string, string>) {
|
||||
return s.replace(mustacheRE, (match) => {
|
||||
let marker = mustaches.get(match)
|
||||
if (!marker) {
|
||||
marker = nanoid()
|
||||
mustaches.set(match, marker)
|
||||
}
|
||||
return marker
|
||||
})
|
||||
}
|
||||
|
||||
function restoreMustache(s: string, mustaches: Map<string, string>, twoslash: boolean) {
|
||||
mustaches.forEach((marker, match) => {
|
||||
s = s.replaceAll(marker, match)
|
||||
})
|
||||
|
||||
if (twoslash)
|
||||
s = s.replace(/\{/g, '{')
|
||||
|
||||
return `${s}\n`
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ export function lineNumberPlugin(md: Markdown, { lineNumbers = true }: LineNumbe
|
||||
= Number(info.match(LINE_NUMBERS_START_REGEXP)?.[1] ?? 1) - 1
|
||||
const lineNumbersStyle = `style="counter-reset:line-number ${startNumbers}"`
|
||||
|
||||
const lineNumbersCode = [...Array(lines.length)]
|
||||
const lineNumbersCode = [...Array.from({ length: lines.length })]
|
||||
.map(() => `<div class="line-number"></div>`)
|
||||
.join('')
|
||||
|
||||
|
||||
@ -47,29 +47,6 @@ export function rendererFloatingVue(options: TwoslashFloatingVueRendererOptions
|
||||
'theme': floatingVueTheme,
|
||||
}
|
||||
|
||||
function compose(parts: { token: Element | Text, popup: Element }): Element[] {
|
||||
return [
|
||||
{
|
||||
type: 'element',
|
||||
tagName: 'span',
|
||||
properties: {},
|
||||
children: [parts.token],
|
||||
},
|
||||
{
|
||||
type: 'element',
|
||||
tagName: 'template',
|
||||
properties: {
|
||||
'v-slot:popper': '{}',
|
||||
},
|
||||
content: {
|
||||
type: 'root',
|
||||
children: [vPre(parts.popup)],
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
const rich = rendererRich({
|
||||
classExtra: classCopyIgnore,
|
||||
...options,
|
||||
@ -142,6 +119,29 @@ export function rendererFloatingVue(options: TwoslashFloatingVueRendererOptions
|
||||
return rich
|
||||
}
|
||||
|
||||
function compose(parts: { token: Element | Text, popup: Element }): Element[] {
|
||||
return [
|
||||
{
|
||||
type: 'element',
|
||||
tagName: 'span',
|
||||
properties: {},
|
||||
children: [parts.token],
|
||||
},
|
||||
{
|
||||
type: 'element',
|
||||
tagName: 'template',
|
||||
properties: {
|
||||
'v-slot:popper': '{}',
|
||||
},
|
||||
content: {
|
||||
type: 'root',
|
||||
children: [vPre(parts.popup)],
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
function vPre<T extends ElementContent>(el: T): T {
|
||||
if (el.type === 'element') {
|
||||
el.properties = el.properties || {}
|
||||
|
||||
@ -64,30 +64,6 @@ export function useHomeHeroTintPlate(
|
||||
return defaultTint
|
||||
})
|
||||
|
||||
function toPlate(plate: number | string) {
|
||||
return typeof plate === 'number' || Number(plate) === Number.parseInt(plate)
|
||||
? [plate, plate, plate].map(n => Number(n))
|
||||
: plate.includes(',') ? plate.replace(/\s/g, '').split(',').map(n => Number(n)) : []
|
||||
}
|
||||
|
||||
function toTint([r, g, b]: number[]) {
|
||||
return { r: toColor(r), g: toColor(g), b: toColor(b) }
|
||||
}
|
||||
|
||||
function toColor(num: number) {
|
||||
const offset = 256 - num
|
||||
return { value: num, offset: offset > 64 ? 64 : offset }
|
||||
}
|
||||
|
||||
function toNumber(tint: TintPlate): TintPlate {
|
||||
Object.keys(tint).forEach((key) => {
|
||||
const p = tint[key]
|
||||
p.value = Number(p.value)
|
||||
p.offset = Number(p.offset)
|
||||
})
|
||||
return tint
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (canvas.value && enable.value) {
|
||||
ctx = canvas.value.getContext('2d')!
|
||||
@ -135,3 +111,27 @@ export function useHomeHeroTintPlate(
|
||||
return (Math.floor(b.value + b.offset * Math.sin(5 * Math.sin(t / 9) + ((x - 100) * (x - 100) + (y - 100) * (y - 100)) / 1100)))
|
||||
}
|
||||
}
|
||||
|
||||
function toPlate(plate: number | string) {
|
||||
return typeof plate === 'number' || Number(plate) === Number.parseInt(plate)
|
||||
? [plate, plate, plate].map(n => Number(n))
|
||||
: plate.includes(',') ? plate.replace(/\s/g, '').split(',').map(n => Number(n)) : []
|
||||
}
|
||||
|
||||
function toTint([r, g, b]: number[]) {
|
||||
return { r: toColor(r), g: toColor(g), b: toColor(b) }
|
||||
}
|
||||
|
||||
function toColor(num: number) {
|
||||
const offset = 256 - num
|
||||
return { value: num, offset: offset > 64 ? 64 : offset }
|
||||
}
|
||||
|
||||
function toNumber(tint: TintPlate): TintPlate {
|
||||
Object.keys(tint).forEach((key) => {
|
||||
const p = tint[key]
|
||||
p.value = Number(p.value)
|
||||
p.offset = Number(p.offset)
|
||||
})
|
||||
return tint
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ export function resolveHeaders(headers: MenuItem[], range?: ThemeOutline): MenuI
|
||||
resolvedHeaders.push({ element, link })
|
||||
|
||||
const ret: MenuItem[] = []
|
||||
// eslint-disable-next-line no-labels, no-restricted-syntax
|
||||
// eslint-disable-next-line no-labels
|
||||
outer: for (let i = 0; i < headers.length; i++) {
|
||||
const cur = headers[i]
|
||||
if (i === 0) {
|
||||
|
||||
@ -30,8 +30,9 @@ export async function prepareEncrypt(app: App, encrypt?: PlumeThemeEncrypt) {
|
||||
}
|
||||
}
|
||||
|
||||
const salt = () => genSaltSync(random(8, 16))
|
||||
|
||||
function resolveEncrypt(encrypt?: PlumeThemeEncrypt): EncryptConfig {
|
||||
const salt = () => genSaltSync(random(8, 16))
|
||||
const admin = encrypt?.admin
|
||||
? toArray(encrypt.admin)
|
||||
.filter(isStringLike)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user