UNPKG

7.04 kBMarkdownView Raw
1<img src="https://pag.art/img/readme/logo.png" alt="PAG Logo" width="474"/>
2
3[Homepage](https://pag.art) | English | [简体中文](./README.zh_CN.md)
4
5## Introduction
6
7libpag is a real-time rendering library for PAG (Portable Animated Graphics) files that renders both
8vector-based and raster-based animations across most platforms, such as iOS, Android, macOS,
9Windows, Linux, and Web.
10
11## Features
12
13PAG Web SDK is built on WebAssembly and WebGL which supports all of the PAG features.
14
15## Quick start
16
17PAG Web SDK consists of two files: `libpag.js` and `libpag.wasm`.
18
19### Browser (Recommend)
20
21Use <script/> to include the library directly, `libpag` will be registered as a global variable.
22
23For production use, we recommend using a specific version number of libpag to avoid unexpected breakage from newer versions:
24
25```html
26<script src="https://cdn.jsdelivr.net/npm/libpag@4.1.8/lib/libpag.min.js"></script>
27```
28
29You can browse the files of the NPM package at the public CDN [cdn.jsdelivr.net/npm/libpag/](https://cdn.jsdelivr.net/npm/libpag/) , and you can use the keyword `@lastest` to get the lastest version.
30
31The PAG library is also available on other public CDNs that sync with NPM, such as [unpkg](https://unpkg.com/libpag@latest/lib/libpag.min.js).
32
33```html
34<canvas class="canvas" id="pag"></canvas>
35<script src="https://cdn.jsdelivr.net/npm/libpag@latest/lib/libpag.min.js"></script>
36<script>
37 window.onload = async () => {
38 // Initialize pag webassembly module.
39 const PAG = await window.libpag.PAGInit();
40 // Fetch pag file data.
41 const buffer = await fetch('https://pag.art/file/like.pag').then((response) => response.arrayBuffer());
42 // Load the PAGFile from data.
43 const pagFile = await PAG.PAGFile.load(buffer);
44 // Set canvas size from the PAGFile size.
45 const canvas = document.getElementById('pag');
46 canvas.width = pagFile.width();
47 canvas.height = pagFile.height();
48 // Create PAGView.
49 const pagView = await PAG.PAGView.init(pagFile, canvas);
50 // Play PAGView.
51 await pagView.play();
52 };
53</script>
54```
55
56You can use the `locateFile` function to get the path of `libpag.wasm` file. By default, the `libpag.wasm` file is located next to the `libpag.js` file. For example:
57
58```js
59const PAG = await window.libpag.PAGInit({
60 locateFile: () => {
61 if (location.host === 'dev.pag.art') {
62 // development environment
63 return 'https://dev.pag.art/file/libpag.wasm';
64 } else {
65 // production environment
66 return 'https://pag.art/file/libpag.wasm';
67 }
68 },
69});
70```
71
72### EsModule
73
74```bash
75$ npm i libpag
76```
77
78```js
79import { PAGInit } from 'libpag';
80
81PAGInit().then((PAG) => {
82 // Initialize pag webassembly module.
83});
84```
85
86**Note: If you are using ESModule to import PAG Web SDK, you must pack the `libpag.wasm` file manually into the final web program, because the common packing tools usually ignore the wasm file. Then use the `locateFile` function to get the path of the `libpag.wasm` . You also need to upload the `libpag.wasm` file to a server so that users can load it from network.**
87
88There are many kinds of products in the npm package after building. You could read the [doc](./doc/develop-install.md) to know about them.
89
90There is also a [repository](https://github.com/libpag/pag-web) that contains some demos about using PAG Web SDK with HTML / Vue / React / PixiJS.
91
92You can find the API documentation [here](https://pag.art/docs/apis-web.html).
93
94## Browser
95
96| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Chrome for Android | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Safari on iOS | QQ Browser Mobile |
97| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------- |
98| Chrome >= 69 | Safari >= 11.3 | Android >= 7.0 | iOS >= 11.3 | last 2 versions |
99
100More compatible versions are coming soon.
101
102## Roadmap
103
104Please visit [here](https://github.com/Tencent/libpag/wiki/PAG-Web-roadmap) to see the roadmap of the PAG Web SDK.
105
106## Development
107
108First, make sure you have installed all the tools and dependencies listed in the [README.md](../README.md#Development) located in the project root directory.
109
110### Dependency Management
111
112Then run the following command to install required node modules:
113
114```bash
115$ npm install
116```
117
118### Build (Debug)
119
120Execute `build.sh debug` to get `libpag.wasm` file.
121
122```bash
123# ./web/script/
124$ cd script
125$ chmod +x ./build.sh
126$ ./build.sh debug
127```
128
129Build Typescript file.
130
131```bash
132# ./web/
133$ npm run dev
134```
135
136Start HTTP server.
137
138```bash
139# ./
140$ npm run server
141```
142Use Chrome to open `http://localhost:8081/web/demo/index.html` to see the demo.
143
144If you need to debug, you can install [C/C++ DevTools Support (DWARF)](https://chrome.google.com/webstore/detail/cc%20%20-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb), and open Chrome DevTools > Settings > Experiments > Check the "WebAssembly Debugging: Enable DWARF support" option to enable SourceMap support. Now you can debug C++ files in Chrome DevTools.
145
146#### PS
147
148When using build.sh to compile libpag.wasm, undefined symbols error was suppressed due to compatibility issues between emscripten and the system's std library.
149
150```shell
151# build.sh
152emcc -s ERROR_ON_UNDEFINED_SYMBOLS=0
153```
154
155During the compilation process, it is necessary to pay attention to any warning messages unrelated to std library to avoid the undefined symbols errors during runtime.
156
157### Build (Release)
158
159```bash
160# ./web/script
161$ cd script
162$ chmod +x ./build.sh
163$ ./build.sh
164```
165
166### Build with CLion
167
168Create a new build target in CLion, and use the following **CMake options**(find them under **CLion** > **Preferences** > **Build, Execution, Deployment** > **CMake**
169
170```
171-DCMAKE_TOOLCHAIN_FILE=path/to/emscripten/emscripten/version/cmake/Modules/Platform/Emscripten.cmake
172```
173
174### Test
175
176Build release version
177
178```bash
179$ cd script & ./build.sh
180```
181
182Start test HTTP server.
183
184```bash
185$ npm run server
186```
187
188Start cypress test.
189
190```bash
191$ npm run test
192```