mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 01:21:20 -08:00
refactor(iframe): [PKG-IFRAME-04] preserve types across module consumers
This commit is contained in:
1 parent
1342de94ef
commit
047e2df945
24 files changed
+1496
-69
No files matched your search
@@ -6,6 +6,35 @@ Iframe tool for ArtPlayer
|
||||
|
||||
[https://artplayer.org](https://artplayer.org/?libs=./uncompiled/artplayer-tool-iframe/index.js&example=iframe)
|
||||
|
||||
## TypeScript
|
||||
|
||||
Default imports keep the historical class signatures, including `resove`,
|
||||
required message `data`, and the original `commit` result inference. Named types
|
||||
include `Option`, `Message`, `ProtocolMessage` and optional runtime views:
|
||||
|
||||
```ts
|
||||
import type { ResolverInstance, RuntimeConstructor } from 'artplayer-tool-iframe'
|
||||
import Iframe from 'artplayer-tool-iframe'
|
||||
|
||||
const Runtime = Iframe as RuntimeConstructor
|
||||
const tool = new Runtime({ iframe: document.querySelector('iframe')!, url: '/iframe.html' })
|
||||
const resolver = tool as ResolverInstance
|
||||
const value = await resolver.commit<number>((resolve) => {
|
||||
resolve(42)
|
||||
})
|
||||
```
|
||||
|
||||
`commit` serializes the function body. Keep its braces, use the literal `resolve`
|
||||
name for asynchronous replies, and do not depend on closures or an async function
|
||||
body. Handle rejection when the child document changes or the tool is destroyed.
|
||||
The runtime views are types only; they do not validate messages or sandbox code.
|
||||
|
||||
The browser global is `ArtplayerToolIframe`. Modern TypeScript CommonJS consumers
|
||||
can use `import Iframe = require('artplayer-tool-iframe')`; older Node resolution
|
||||
uses the default import with `esModuleInterop`. The class has no `.default`
|
||||
property. The historical `artplayer-plugin-iframe` package and its separate helper
|
||||
have different export/protocol details; they are not aliases for this tool.
|
||||
|
||||
## Maintenance
|
||||
|
||||
See [ARCHITECTURE.md](ARCHITECTURE.md) for the TypeScript module map, request
|
||||
|
||||
Reference in new issue
Block a user