Skip to content

Commit

Permalink
feat: add ass.global.js
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhenye committed Jul 28, 2024
1 parent 8e18953 commit 4b19674
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,26 @@ npm install assjs

CDN: [jsDelivr](https://www.jsdelivr.com/package/npm/assjs), [unpkg](https://unpkg.com/assjs/)

ASS.js can be used as a JavaScript module:

```html
<script type="module">
import ASS from '/path/to/assjs/dist/ass.min.js';
</script>
```

or a classic script:

```html
<script src="/path/to/assjs/dist/ass.global.min.js">
```
## Usage
```html
<div id="container" style="position: relative;">
<video
id="video"
src="./example.mp4"
style="position: absolute; width: 100%; height: 100%;"
></video>
<!-- ASS will be added here -->
<div id="player">
<video id="video" src="./example.mp4"></video>
<div id="ass-container"></div>
</div>
```
Expand All @@ -39,11 +49,20 @@ import ASS from 'assjs';
const content = await fetch('/path/to/example.ass').then((res) => res.text());
const ass = new ASS(content, document.querySelector('#video'), {
container: document.querySelector('#container'),
container: document.querySelector('#ass-container'),
});
```
If you click the native fullscreen button in video element, only `<video>` will be fullscreened, so ASS will not show. You should use a custom button and call `document.querySelector('#container').requestFullscreen()` to ensure ASS is contained.
`new ASS()` will create some elements and append to the container, and sync the render area's size with the video element. **You should set styles yourself to make sure the container is overlap on the video and match the position.** For example:
```html
<div id="player" style="position: relative;">
<video id="video" src="./example.mp4" style="position: absolute; top: 0; left: 0;"></video>
<div id="ass-container" style="position: absolute; top: 0; left: 0;"></div>
</div>
```
If you click the native fullscreen button in video element, only `<video>` will be fullscreened, so ASS will not show. You should use a custom button and call `document.querySelector('#player').requestFullscreen()` to ensure ASS is contained.
## API
Expand Down
11 changes: 11 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ export default {
format: 'esm',
plugins: [terser()],
},
{
file: 'dist/ass.global.js',
format: 'iife',
name: 'ASS',
},
{
file: 'dist/ass.global.min.js',
format: 'iife',
name: 'ASS',
plugins: [terser()],
},
],
plugins: [
replace({
Expand Down
2 changes: 0 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export function addGlobalStyle(container) {
}
}

export const strokeTags = ['c3', 'a3', 'c4', 'a4', 'xbord', 'ybord', 'xshad', 'yshad', 'blur', 'be'];

export function initAnimation($el, keyframes, options) {
const animation = $el.animate(keyframes, options);
animation.pause();
Expand Down

0 comments on commit 4b19674

Please sign in to comment.