mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 10:31:20 -08:00
fix(types): [PKG-FACTORY-01] preserve published factory compatibility
This commit is contained in:
1 parent
1117107032
commit
c4c7491e16
35 files changed
+670
-229
No files matched your search
@@ -29,14 +29,19 @@ historical `require('artplayer-proxy-canvas').default` refer to the same factory
|
||||
|
||||
## TypeScript
|
||||
|
||||
The optional callback and exact `HTMLCanvasElement` return type retain published 1.1.0
|
||||
inference. `Option`, `Result`, `Factory` and `MediaCanvas` are exported types. The last is
|
||||
an explicit view for code using supported forwarded media members:
|
||||
The root and `/legacy` declarations preserve the latest published 1.1.0 factory:
|
||||
an optional callback, an exact `HTMLCanvasElement` result, and no required factory
|
||||
properties. Ordinary replacement functions remain assignable in both directions.
|
||||
`Factory` describes that historical shape. The additive `/runtime` entry uses the same
|
||||
JavaScript implementation and describes its readonly `default` self alias with
|
||||
`RuntimeFactory`. It also exports an explicit `MediaCanvas` view:
|
||||
|
||||
```ts
|
||||
import type { MediaCanvas, Option } from 'artplayer-proxy-canvas'
|
||||
import type { MediaCanvas, Option } from 'artplayer-proxy-canvas/runtime'
|
||||
import canvas from 'artplayer-proxy-canvas/runtime'
|
||||
|
||||
const callback: Option = (context, video) => context.drawImage(video, 0, 0)
|
||||
canvas.default(callback)
|
||||
const media = art.template.$video as MediaCanvas
|
||||
await media.play()
|
||||
```
|
||||
@@ -48,6 +53,27 @@ Runtime falsy callback arguments retain historical behavior; declarations accept
|
||||
optional function, matching the published types. Implementation and test guidance is in
|
||||
[ARCHITECTURE.md](ARCHITECTURE.md).
|
||||
|
||||
### Older TypeScript consumers
|
||||
|
||||
The 1.0.0 declaration used `export =` and required a callback; 1.1.0 changed to
|
||||
`export default` and made the callback optional. These conflicting type shapes cannot
|
||||
both remain the root factory. Following the approved compatibility policy, the root
|
||||
keeps 1.1.0. A 1.0.0 TypeScript `import canvas = require('artplayer-proxy-canvas')`
|
||||
consumer that directly calls `canvas(...)` can select the accurate entry instead:
|
||||
|
||||
```ts
|
||||
import canvas = require('artplayer-proxy-canvas/runtime')
|
||||
canvas((context, video) => context.drawImage(video, 0, 0))
|
||||
canvas.default()
|
||||
```
|
||||
|
||||
This works with Node10 resolution even without `esModuleInterop`. Default imports from
|
||||
`/runtime` work with interoperability enabled and with native NodeNext ESM. Under
|
||||
NodeNext ESM, the root intentionally preserves 1.1.0's historical declaration namespace
|
||||
shape (`root.default(...)` after a default import); that declaration shape does not
|
||||
describe the actual ESM factory. Use a default import from `/runtime` for accurate ESM
|
||||
typing. Existing JavaScript root/legacy calls and distribution paths keep working.
|
||||
|
||||
## Demo
|
||||
|
||||
[https://artplayer.org](https://artplayer.org/?libs=./uncompiled/artplayer-proxy-canvas/index.js&example=canvas)
|
||||
|
||||
Reference in new issue
Block a user