mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-30 03:51:25 -08:00
fix(thumbnail): [PKG-TOOL-THUMB-04] supply public types and installed module entries
This commit is contained in:
1 parent
15485b6420
commit
3bff236145
33 files changed
+2466
-164
No files matched your search
@@ -0,0 +1,60 @@
|
||||
# Public thumbnail types
|
||||
|
||||
The declaration describes the existing tool class, not an ArtPlayer plugin factory.
|
||||
The previous workspace manifest pointed to a missing declaration. There is no
|
||||
recovered legacy declaration to claim as an exact TypeScript baseline.
|
||||
|
||||
| Entry | Declaration | Runtime |
|
||||
| --- | --- | --- |
|
||||
| Root ESM import | artplayer-tool-thumbnail.d.mts | Default constructor in dist/artplayer-tool-thumbnail.mjs |
|
||||
| Root require | artplayer-tool-thumbnail.d.cts | Direct constructor in dist/artplayer-tool-thumbnail.js |
|
||||
| Older Node resolution / TS 4.3 | artplayer-tool-thumbnail.d.ts | main points to the direct CommonJS constructor |
|
||||
| artplayer-tool-thumbnail/legacy | d.cts or typesVersions fallback | Direct legacy constructor; native ESM gets its default |
|
||||
| Browser script / editor | Generated docs/assets/ts declaration | ArtplayerToolThumbnail global |
|
||||
|
||||
The d.ts file is the public source of truth. d.cts forwards its export assignment;
|
||||
d.mts exposes the default constructor and type-only named exports. No runtime
|
||||
named exports or .default self-alias exist. Keep the wrappers sharing one class.
|
||||
|
||||
```ts
|
||||
import Thumbnail, { Option } from 'artplayer-tool-thumbnail'
|
||||
|
||||
const input = document.createElement('input')
|
||||
input.type = 'file'
|
||||
const options: Option = { fileInput: input, number: 10 }
|
||||
const tool = new Thumbnail(options)
|
||||
tool.on('update', (url, progress) => console.log(url, progress))
|
||||
tool.on('custom', (value: number) => console.log(value))
|
||||
tool.emit('custom', 1)
|
||||
```
|
||||
|
||||
CommonJS TS can use `import Thumbnail = require('artplayer-tool-thumbnail')` without
|
||||
esModuleInterop. The optional constructor argument mirrors the JS signature, but
|
||||
successful initialization requires fileInput to be an actual file input or Element
|
||||
wrapper. Missing input throws synchronously. setup accepts partial options and
|
||||
retains unknown fields. Numeric range/clamp validation remains a runtime condition.
|
||||
|
||||
Known event tuples are precise. Custom string/number/symbol events infer annotated
|
||||
callback arguments; those protocols remain the caller's responsibility. ctx is
|
||||
inferred from the optional third argument. Dispatch through emit to retain event
|
||||
argument checks rather than directly invoking the heterogeneous e registry.
|
||||
file/videoUrl/thumbnailUrl/density may be absent before their operation.
|
||||
start returns Promise<void>; ready-metadata preflight may throw synchronously,
|
||||
and source replacement/destroy reject with AbortError. Error events usually contain
|
||||
strings, but callback throws can supply any message value, so narrow unknown first.
|
||||
|
||||
Source/declaration constructors are mutually checked in test/types/thumbnail-source.ts.
|
||||
Current and TS 4.3.5 consumers include ten invalid uses. Installed checks pack/install
|
||||
outside the workspace, offline with an unchanged frozen lock, verify every file
|
||||
and exercise native Node require/import without a DOM.
|
||||
|
||||
```sh
|
||||
yarn test:thumbnail
|
||||
yarn test:thumbnail-types-package
|
||||
yarn build:ts
|
||||
yarn test:browser test/browser/thumbnail-editor-types.spec.js
|
||||
```
|
||||
|
||||
build:ts selects package declaration entries rather than auxiliary types and emits
|
||||
the uppercase global. Actual file extraction, old-core composition and the full
|
||||
demo remain separate checks. The 3.5.31 versus 4.4.0 default policy remains pending.
|
||||
@@ -0,0 +1,4 @@
|
||||
// eslint-disable-next-line ts/no-require-imports -- Match the direct CommonJS constructor without a self-default alias.
|
||||
import ArtplayerToolThumbnail = require('./artplayer-tool-thumbnail.js')
|
||||
|
||||
export = ArtplayerToolThumbnail
|
||||
@@ -0,0 +1,2 @@
|
||||
export { default } from './artplayer-tool-thumbnail.cjs'
|
||||
export type { EventArgs, EventRegistry, Events, Listener, Option, ResolvedOption, ScreenshotPoint, SheetOptions } from './artplayer-tool-thumbnail.js'
|
||||
@@ -0,0 +1,83 @@
|
||||
/** Extract PNG thumbnail sheets from a locally selected video file. */
|
||||
declare class ArtplayerToolThumbnail {
|
||||
constructor(option?: ArtplayerToolThumbnail.Option)
|
||||
|
||||
static readonly DEFAULTS: ArtplayerToolThumbnail.SheetOptions
|
||||
static ondragover(event: DragEvent): void
|
||||
static creatVideo(): HTMLVideoElement
|
||||
|
||||
processing: boolean
|
||||
option: ArtplayerToolThumbnail.ResolvedOption
|
||||
video: HTMLVideoElement
|
||||
duration: number
|
||||
density: number | undefined
|
||||
file: File | undefined
|
||||
videoUrl: string | undefined
|
||||
thumbnailUrl: string | undefined
|
||||
e?: ArtplayerToolThumbnail.EventRegistry
|
||||
|
||||
setup(option?: ArtplayerToolThumbnail.Option): this
|
||||
inputChange(event: Event): void
|
||||
ondrop(event: DragEvent): void
|
||||
loadVideo(file?: File | null): void
|
||||
/** Ready-metadata preflight may throw synchronously. Cancellation rejects with AbortError. */
|
||||
start(): Promise<void>
|
||||
creatScreenshotDate(): ArtplayerToolThumbnail.ScreenshotPoint[]
|
||||
creatCanvas(): HTMLCanvasElement
|
||||
download(): this
|
||||
errorHandle(condition: unknown, message: string): void
|
||||
destroy(): void
|
||||
|
||||
on<Name extends PropertyKey, Custom extends unknown[], Context>(name: Name, callback: (this: Context, ...args: ArtplayerToolThumbnail.EventArgs<Name, Custom>) => unknown, ctx?: Context): this
|
||||
once<Name extends PropertyKey, Custom extends unknown[], Context>(name: Name, callback: (this: Context, ...args: ArtplayerToolThumbnail.EventArgs<Name, Custom>) => unknown, ctx?: Context): this
|
||||
emit<Name extends PropertyKey, Custom extends unknown[]>(name: Name, ...args: ArtplayerToolThumbnail.EventArgs<Name, Custom>): this
|
||||
off<Name extends PropertyKey, Custom extends unknown[]>(name: Name, callback?: ArtplayerToolThumbnail.Listener<ArtplayerToolThumbnail.EventArgs<Name, Custom>>): this
|
||||
}
|
||||
|
||||
declare namespace ArtplayerToolThumbnail {
|
||||
interface SheetOptions {
|
||||
number: number
|
||||
width: number
|
||||
height: number
|
||||
column: number
|
||||
begin: number
|
||||
end: number
|
||||
}
|
||||
|
||||
/** fileInput must be a file input or an Element wrapper when constructing. */
|
||||
interface Option extends Partial<SheetOptions> {
|
||||
fileInput?: Element
|
||||
[name: string]: unknown
|
||||
}
|
||||
|
||||
interface ResolvedOption extends SheetOptions {
|
||||
fileInput: HTMLInputElement
|
||||
[name: string]: unknown
|
||||
}
|
||||
|
||||
interface ScreenshotPoint {
|
||||
time: number
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
interface Events {
|
||||
file: [file: File]
|
||||
video: [video: HTMLVideoElement]
|
||||
canvas: [canvas: HTMLCanvasElement]
|
||||
update: [url: string, progress: number]
|
||||
done: []
|
||||
download: [name: string]
|
||||
/** Built-in failures are strings; user callbacks may throw any message value. */
|
||||
error: [message: unknown]
|
||||
destroy: []
|
||||
}
|
||||
|
||||
type EventArgs<Name extends PropertyKey, Custom extends unknown[] = unknown[]> = Name extends keyof Events ? [...Events[Name]] : Custom
|
||||
type Listener<Args extends unknown[]> = ((...args: Args) => unknown) & { _?: (...args: Args) => unknown }
|
||||
/** Heterogeneous listener storage; dispatch through emit to retain event argument checks. */
|
||||
type EventRegistry = Partial<Record<PropertyKey, { fn: Listener<never[]>, ctx: unknown }[]>>
|
||||
}
|
||||
|
||||
export = ArtplayerToolThumbnail
|
||||
export as namespace ArtplayerToolThumbnail
|
||||
Reference in new issue
Block a user