mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 17:01:20 -08:00
fix(core): [CORE-25] read defaults without navigator
This commit is contained in:
1 parent
4a299eb2d4
commit
3b016970f2
26 files changed
+916
-35
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { ResolvedOption } from './types'
|
||||
import type { DefaultOption } from './types'
|
||||
import { isSafari } from '../utils/compatibility'
|
||||
|
||||
export default function createDefaults(): ResolvedOption {
|
||||
export default function createDefaults(): DefaultOption {
|
||||
return {
|
||||
id: '',
|
||||
container: '#artplayer',
|
||||
@@ -70,6 +70,6 @@ export default function createDefaults(): ResolvedOption {
|
||||
icons: {},
|
||||
cssVar: {},
|
||||
customType: {},
|
||||
lang: navigator?.language.toLowerCase(),
|
||||
lang: typeof navigator === 'undefined' ? undefined : navigator?.language.toLowerCase(),
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { OptionInput, ResolvedInput, ResolvedOption } from './types'
|
||||
import type { DefaultOption, OptionInput, ResolvedInput } from './types'
|
||||
import validator from 'option-validator'
|
||||
import scheme from '../scheme'
|
||||
import { mergeDeep } from '../utils/property'
|
||||
|
||||
export default function resolveOption<Input extends OptionInput>(input: Input, defaults: ResolvedOption): ResolvedInput<Input> {
|
||||
export default function resolveOption<Input extends OptionInput>(input: Input, defaults: DefaultOption): ResolvedInput<Input> {
|
||||
const merged = mergeDeep(defaults, input)
|
||||
merged.container = input.container
|
||||
// Keep the existing runtime validator. It checks the known schema, not extension data.
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { MediaSurface } from '../media/types'
|
||||
import type { PluginFactory } from '../plugins/types'
|
||||
import type { SettingItem } from '../setting/types'
|
||||
import type { UrlHost } from '../source/types'
|
||||
import type { OptionInput, ResolvedOption } from './types'
|
||||
import type { DefaultOption, OptionInput, ResolvedOption } from './types'
|
||||
import resolveOption from './resolve'
|
||||
|
||||
interface RuntimeCallbacks<Host> {
|
||||
@@ -20,7 +20,7 @@ interface RuntimeCallbacks<Host> {
|
||||
|
||||
export type RuntimeOption<Host> = Omit<ResolvedOption, keyof RuntimeCallbacks<Host>> & RuntimeCallbacks<Host>
|
||||
|
||||
export default function resolveRuntimeOption<Host>(input: OptionInput, defaults: ResolvedOption): RuntimeOption<Host> {
|
||||
export default function resolveRuntimeOption<Host>(input: OptionInput, defaults: DefaultOption): RuntimeOption<Host> {
|
||||
// The external declaration facade and internal module views describe the same
|
||||
// caller-owned callbacks. Do not wrap, clone or rebind their runtime identity.
|
||||
// All non-callback options still derive directly from the validated merge type.
|
||||
|
||||
@@ -10,4 +10,8 @@ export interface ResolvedOption extends Omit<Required<OptionInput>, 'proxy' | 's
|
||||
thumbnails: Required<Thumbnails>
|
||||
}
|
||||
|
||||
export interface DefaultOption extends Omit<ResolvedOption, 'lang'> {
|
||||
lang: OptionInput['lang']
|
||||
}
|
||||
|
||||
export type ResolvedInput<Input extends OptionInput> = ResolvedOption & Omit<Input, keyof OptionInput>
|
||||
Reference in new issue
Block a user