mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 06:31:20 -08:00
refactor(vast): [PKG-VAST-04] retain published types and add accurate runtime declarations
This commit is contained in:
1 parent
c162d2b3b3
commit
e5c73fa620
34 files changed
+7819
-1495
No files matched your search
+16
-32
@@ -1,36 +1,20 @@
|
||||
import type { Player, PlayerOptions } from '@glomex/vast-ima-player'
|
||||
import type Artplayer from 'artplayer'
|
||||
import type Artplayer from 'artplayer';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
artplayerPluginVast?: typeof artplayerPluginVast
|
||||
}
|
||||
}
|
||||
export = artplayerPluginVast;
|
||||
export as namespace artplayerPluginVast;
|
||||
|
||||
type PlayUrlFn = (url: string, config?: any) => void
|
||||
type PlayResFn = (res: string, config?: any) => void
|
||||
type Option = (params: {
|
||||
art: Artplayer;
|
||||
id: string;
|
||||
ima: any;
|
||||
imaPlayer: any;
|
||||
$container: HTMLDivElement;
|
||||
playUrl: (url: string) => void;
|
||||
playRes: (res: string) => void;
|
||||
}) => void;
|
||||
|
||||
interface VastPluginContext {
|
||||
art: Artplayer
|
||||
ima: any
|
||||
imaPlayer: Player | null
|
||||
playUrl: PlayUrlFn
|
||||
playRes: PlayResFn
|
||||
init: () => Player
|
||||
adsRenderingSettings: any
|
||||
playerOptions: PlayerOptions
|
||||
container: HTMLDivElement | null
|
||||
}
|
||||
type Result = {
|
||||
name: 'artplayerPluginVast';
|
||||
};
|
||||
|
||||
export type ArtplayerPluginVastOption = (params: VastPluginContext) => void | Promise<void>
|
||||
|
||||
export interface ArtplayerPluginVastInstance {
|
||||
name: 'artplayerPluginVast'
|
||||
destroy?: () => void
|
||||
}
|
||||
|
||||
declare function artplayerPluginVast(
|
||||
option: ArtplayerPluginVastOption,
|
||||
): (art: Artplayer) => ArtplayerPluginVastInstance
|
||||
|
||||
export default artplayerPluginVast
|
||||
declare const artplayerPluginVast: (option: Option) => (art: Artplayer) => Result;
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { google, ImaSdk } from '@alugha/ima'
|
||||
import type { Player, PlayerOptions } from '@glomex/vast-ima-player'
|
||||
import type Artplayer from 'artplayer'
|
||||
|
||||
export type RequestConfig = Record<string, unknown>
|
||||
|
||||
export interface CompatibilityOptions {
|
||||
compatibility?: 'workspace-1.2'
|
||||
}
|
||||
|
||||
export interface Context {
|
||||
art: Artplayer
|
||||
ima: ImaSdk
|
||||
adsRenderingSettings: google.ima.AdsRenderingSettings
|
||||
playerOptions: PlayerOptions
|
||||
playUrl: (url: string, config?: RequestConfig) => void
|
||||
playRes: (response: string, config?: RequestConfig) => void
|
||||
init: () => Player | null
|
||||
readonly container: HTMLDivElement | null
|
||||
}
|
||||
|
||||
/** Published data fields retain their last allocation after release. */
|
||||
export interface PublishedContext extends Context {
|
||||
imaPlayer: Player
|
||||
id: string
|
||||
$container: HTMLDivElement
|
||||
}
|
||||
|
||||
/** Resource getters are null before initialization and after release. */
|
||||
export interface WorkspaceContext extends Context {
|
||||
readonly imaPlayer: Player | null
|
||||
readonly id: string | null
|
||||
readonly $container: HTMLDivElement | null
|
||||
}
|
||||
|
||||
export type RuntimeContext = PublishedContext | WorkspaceContext
|
||||
export type RuntimeCallback<T extends RuntimeContext = RuntimeContext> = (context: T) => unknown
|
||||
|
||||
export interface RuntimeResult {
|
||||
name: 'artplayerPluginVast'
|
||||
destroy: () => void
|
||||
}
|
||||
|
||||
export type Registration = (art: Artplayer) => Promise<RuntimeResult>
|
||||
|
||||
export interface RuntimeFactory {
|
||||
(callback?: RuntimeCallback<PublishedContext>, options?: { compatibility?: undefined }): Registration
|
||||
(callback: RuntimeCallback<WorkspaceContext> | undefined, options: { compatibility: 'workspace-1.2' }): Registration
|
||||
(callback: RuntimeCallback | undefined, options: CompatibilityOptions): Registration
|
||||
default: RuntimeFactory
|
||||
}
|
||||
|
||||
export type ArtplayerPluginVastOption = RuntimeCallback<WorkspaceContext>
|
||||
export type ArtplayerPluginVastInstance = RuntimeResult
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { RuntimeFactory } from './runtime-api.js'
|
||||
|
||||
declare const artplayerPluginVast: RuntimeFactory
|
||||
// eslint-disable-next-line ts/no-redeclare -- Ambient merge exposes types on the CommonJS factory.
|
||||
declare namespace artplayerPluginVast {
|
||||
type ArtplayerPluginVastInstance = import('./runtime-api.js').ArtplayerPluginVastInstance
|
||||
type ArtplayerPluginVastOption = import('./runtime-api.js').ArtplayerPluginVastOption
|
||||
type CompatibilityOptions = import('./runtime-api.js').CompatibilityOptions
|
||||
type Context = import('./runtime-api.js').Context
|
||||
type PublishedContext = import('./runtime-api.js').PublishedContext
|
||||
type Registration = import('./runtime-api.js').Registration
|
||||
type RequestConfig = import('./runtime-api.js').RequestConfig
|
||||
type RuntimeCallback<T extends RuntimeContext = RuntimeContext> = import('./runtime-api.js').RuntimeCallback<T>
|
||||
type RuntimeContext = import('./runtime-api.js').RuntimeContext
|
||||
type RuntimeFactory = import('./runtime-api.js').RuntimeFactory
|
||||
type RuntimeResult = import('./runtime-api.js').RuntimeResult
|
||||
type WorkspaceContext = import('./runtime-api.js').WorkspaceContext
|
||||
}
|
||||
export = artplayerPluginVast
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { RuntimeFactory } from './runtime-api.js'
|
||||
|
||||
declare const artplayerPluginVast: RuntimeFactory
|
||||
export default artplayerPluginVast
|
||||
export type { ArtplayerPluginVastInstance, ArtplayerPluginVastOption, CompatibilityOptions, Context, PublishedContext, Registration, RequestConfig, RuntimeCallback, RuntimeContext, RuntimeFactory, RuntimeResult, WorkspaceContext } from './runtime-api.js'
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { RuntimeFactory } from './runtime-api.js'
|
||||
|
||||
declare const artplayerPluginVast: RuntimeFactory
|
||||
// eslint-disable-next-line ts/no-redeclare -- Ambient merge exposes types on the CommonJS factory.
|
||||
declare namespace artplayerPluginVast {
|
||||
type ArtplayerPluginVastInstance = import('./runtime-api.js').ArtplayerPluginVastInstance
|
||||
type ArtplayerPluginVastOption = import('./runtime-api.js').ArtplayerPluginVastOption
|
||||
type CompatibilityOptions = import('./runtime-api.js').CompatibilityOptions
|
||||
type Context = import('./runtime-api.js').Context
|
||||
type PublishedContext = import('./runtime-api.js').PublishedContext
|
||||
type Registration = import('./runtime-api.js').Registration
|
||||
type RequestConfig = import('./runtime-api.js').RequestConfig
|
||||
type RuntimeCallback<T extends RuntimeContext = RuntimeContext> = import('./runtime-api.js').RuntimeCallback<T>
|
||||
type RuntimeContext = import('./runtime-api.js').RuntimeContext
|
||||
type RuntimeFactory = import('./runtime-api.js').RuntimeFactory
|
||||
type RuntimeResult = import('./runtime-api.js').RuntimeResult
|
||||
type WorkspaceContext = import('./runtime-api.js').WorkspaceContext
|
||||
}
|
||||
export = artplayerPluginVast
|
||||
Reference in new issue
Block a user