fix(thumbnail): [PKG-TOOL-THUMB-04] supply public types and installed module entries

This commit is contained in:
Harvey Zhao committed 2026-09-13 05:16:36 +08:00
1 parent 15485b6420
commit 3bff236145
33 files changed
+2466 -164

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
// eslint-disable-next-line ts/no-require-imports -- Test the actual CommonJS constructor without interop helpers.
import Thumbnail = require('artplayer-tool-thumbnail')
// eslint-disable-next-line ts/no-require-imports -- The legacy subpath also directly exports its constructor.
import Legacy = require('artplayer-tool-thumbnail/legacy')
const option: Thumbnail.Option = { fileInput: document.createElement('input') }
const tool: Thumbnail = new Thumbnail(option)
const legacy: Thumbnail = new Legacy(option)
const pending: Promise<void> = tool.start()
tool.on('update', (url, progress) => url + progress.toFixed())
void [legacy, pending]
// @ts-expect-error No self-default constructor is exported.
const WrongAlias = Thumbnail.default
void WrongAlias
+2 -1
View File
@@ -11,7 +11,7 @@ tool.once('file', function (file) {
this.name = file.name
}, { name: '' })
tool.on('error', (message) => {
const value: string | undefined = message
const value: unknown = message
void value
})
tool.on('custom', (...payload) => {
@@ -19,6 +19,7 @@ tool.on('custom', (...payload) => {
void values
})
tool.emit(Symbol('extension'), 'value')
tool.on('custom-number', (value: number) => value.toFixed())
const pending: Promise<void> = tool.start()
const point: { time: number, x: number, y: number } | undefined = tool.creatScreenshotDate()[0]
const canvas: HTMLCanvasElement = tool.creatCanvas()
+8
View File
@@ -0,0 +1,8 @@
import type Definition from 'artplayer-tool-thumbnail'
import Implementation from '../../packages/artplayer-tool-thumbnail/src'
const constructor: typeof Definition = Implementation
const RuntimeConstructor: typeof Implementation = constructor
const value: Definition = new RuntimeConstructor({ fileInput: document.createElement('input') })
value.on('custom', (count: number) => count.toFixed())
void value
+58
View File
@@ -0,0 +1,58 @@
import type { EventArgs, Option, ScreenshotPoint } from 'artplayer-tool-thumbnail'
import Thumbnail from 'artplayer-tool-thumbnail'
import Legacy from 'artplayer-tool-thumbnail/legacy'
const input = document.createElement('input')
const option: Option = { fileInput: input, number: 10, width: 80, custom: { id: 1 } }
const tool: Thumbnail = new Thumbnail(option)
const legacy: Thumbnail = new Legacy(option)
const duration: number = tool.duration
const file: File | undefined = tool.file
const url: string | undefined = tool.thumbnailUrl
const pending: Promise<void> = tool.start()
const canvas: HTMLCanvasElement = tool.creatCanvas()
const points: ScreenshotPoint[] = tool.creatScreenshotDate()
const extension: unknown = tool.option.custom
const progress: EventArgs<'update'> = ['blob:sheet', 0.5]
tool.on('file', file => file.name)
tool.on('video', video => video.videoWidth)
tool.on('canvas', canvas => canvas.width)
tool.on('update', (url, progress) => url + progress.toFixed())
tool.on('error', (message) => {
if (typeof message === 'string')
message.toUpperCase()
})
tool.on('custom', (count: number, label: string) => label + count.toFixed())
tool.once(Symbol('custom'), (value: { id: number }) => value.id)
tool.on('update', function (url, progress) {
this.last = `${url}:${progress}`
}, { last: '' })
tool.emit('update', ...progress).emit('custom', 1, 'one')
tool.off('file').setup({ width: 100 }).download()
tool.loadVideo(input.files?.[0])
tool.loadVideo(null)
const defaults: Thumbnail.SheetOptions = Thumbnail.DEFAULTS
const end: void = tool.destroy()
void [legacy, duration, file, url, pending, canvas, points, extension, defaults, end]
// @ts-expect-error Numeric width is required.
tool.setup({ width: '80' })
// @ts-expect-error Selectors have never been resolved by the tool.
const wrongInput = new Thumbnail({ fileInput: '#input' })
// @ts-expect-error File input is not a media source URL.
tool.loadVideo('video.mp4')
// @ts-expect-error Progress is numeric and follows the URL.
tool.emit('update', 0.5, 'blob:sheet')
// @ts-expect-error File callbacks receive files, not media elements.
tool.on('file', (value: HTMLVideoElement) => value.duration)
// @ts-expect-error Completion returns no URL.
const wrongResult: Promise<string> = tool.start()
// @ts-expect-error The direct constructor has no runtime .default self-alias.
const WrongAlias = Thumbnail.default
// @ts-expect-error density is absent until extraction preflight.
const earlyDensity: number = tool.density
// @ts-expect-error Error listeners must narrow arbitrary thrown message values.
tool.on('error', (message: string) => message.length)
// @ts-expect-error Built-in done does not carry a file.
tool.emit('done', input.files?.[0])
void [wrongInput, wrongResult, WrongAlias, earlyDensity]