mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-22 12:11:27 -07:00
fix(ci): export asCssColor and subtitle sidebar autoOpen typing
This commit is contained in:
@@ -59,6 +59,7 @@ export const SUBTITLE_DEFAULT_CONFIG: Pick<ResolvedConfig, 'subtitleStyle' | 'su
|
|||||||
},
|
},
|
||||||
subtitleSidebar: {
|
subtitleSidebar: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
autoOpen: false,
|
||||||
layout: 'overlay',
|
layout: 'overlay',
|
||||||
toggleKey: 'Backslash',
|
toggleKey: 'Backslash',
|
||||||
pauseVideoOnHover: false,
|
pauseVideoOnHover: false,
|
||||||
|
|||||||
@@ -116,6 +116,12 @@ export function buildSubtitleConfigOptionRegistry(
|
|||||||
defaultValue: defaultConfig.subtitleSidebar.enabled,
|
defaultValue: defaultConfig.subtitleSidebar.enabled,
|
||||||
description: 'Enable the subtitle sidebar feature for parsed subtitle sources.',
|
description: 'Enable the subtitle sidebar feature for parsed subtitle sources.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'subtitleSidebar.autoOpen',
|
||||||
|
kind: 'boolean',
|
||||||
|
defaultValue: defaultConfig.subtitleSidebar.autoOpen,
|
||||||
|
description: 'Automatically open the subtitle sidebar once during overlay startup.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'subtitleSidebar.layout',
|
path: 'subtitleSidebar.layout',
|
||||||
kind: 'string',
|
kind: 'string',
|
||||||
|
|||||||
@@ -15,6 +15,22 @@ export function asBoolean(value: unknown): boolean | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hexColorPattern = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
const hexColorPattern = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
||||||
|
const cssColorKeywords = new Set([
|
||||||
|
'transparent',
|
||||||
|
'currentcolor',
|
||||||
|
'inherit',
|
||||||
|
'initial',
|
||||||
|
'unset',
|
||||||
|
'revert',
|
||||||
|
'revert-layer',
|
||||||
|
]);
|
||||||
|
const cssColorFunctionPattern = /^(?:rgba?|hsla?)\(\s*[^()]+?\s*\)$/i;
|
||||||
|
|
||||||
|
function supportsCssColor(text: string): boolean {
|
||||||
|
const css = (globalThis as { CSS?: { supports?: (property: string, value: string) => boolean } })
|
||||||
|
.CSS;
|
||||||
|
return css?.supports?.('color', text) ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
export function asColor(value: unknown): string | undefined {
|
export function asColor(value: unknown): string | undefined {
|
||||||
if (typeof value !== 'string') return undefined;
|
if (typeof value !== 'string') return undefined;
|
||||||
@@ -22,6 +38,30 @@ export function asColor(value: unknown): string | undefined {
|
|||||||
return hexColorPattern.test(text) ? text : undefined;
|
return hexColorPattern.test(text) ? text : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function asCssColor(value: unknown): string | undefined {
|
||||||
|
if (typeof value !== 'string') return undefined;
|
||||||
|
|
||||||
|
const text = value.trim();
|
||||||
|
if (text.length === 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (supportsCssColor(text)) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = text.toLowerCase();
|
||||||
|
if (
|
||||||
|
hexColorPattern.test(text) ||
|
||||||
|
cssColorKeywords.has(normalized) ||
|
||||||
|
cssColorFunctionPattern.test(text)
|
||||||
|
) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function asFrequencyBandedColors(
|
export function asFrequencyBandedColors(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
): [string, string, string, string, string] | undefined {
|
): [string, string, string, string, string] | undefined {
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ function createSubtitleSidebarSnapshotFixture(): SubtitleSidebarSnapshot {
|
|||||||
currentSubtitle: { text: '', startTime: null, endTime: null },
|
currentSubtitle: { text: '', startTime: null, endTime: null },
|
||||||
config: {
|
config: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
autoOpen: false,
|
||||||
layout: 'overlay',
|
layout: 'overlay',
|
||||||
toggleKey: 'Backslash',
|
toggleKey: 'Backslash',
|
||||||
pauseVideoOnHover: false,
|
pauseVideoOnHover: false,
|
||||||
|
|||||||
@@ -374,6 +374,7 @@ export type SubtitleSidebarLayout = 'overlay' | 'embedded';
|
|||||||
|
|
||||||
export interface SubtitleSidebarConfig {
|
export interface SubtitleSidebarConfig {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
|
autoOpen?: boolean;
|
||||||
layout?: SubtitleSidebarLayout;
|
layout?: SubtitleSidebarLayout;
|
||||||
toggleKey?: string;
|
toggleKey?: string;
|
||||||
pauseVideoOnHover?: boolean;
|
pauseVideoOnHover?: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user