libpag 4.5.1 → 4.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE.txt +1589 -0
  2. package/README.md +172 -10
  3. package/README.zh_CN.md +114 -15
  4. package/lib/libpag.cjs.js +389 -887
  5. package/lib/libpag.cjs.js.map +1 -1
  6. package/lib/libpag.esm.js +389 -887
  7. package/lib/libpag.esm.js.map +1 -1
  8. package/lib/libpag.min.js +1 -1
  9. package/lib/libpag.min.js.map +1 -1
  10. package/lib/libpag.umd.js +389 -887
  11. package/lib/libpag.umd.js.map +1 -1
  12. package/lib/libpag.wasm +0 -0
  13. package/package.json +24 -12
  14. package/src/.pag.wasm-mt.md5 +1 -0
  15. package/src/.pag.wasm.md5 +1 -1
  16. package/src/core/matrix.ts +1 -2
  17. package/src/core/video-reader.ts +73 -94
  18. package/src/interfaces.ts +8 -17
  19. package/src/pag-composition.ts +12 -5
  20. package/src/pag-file.ts +146 -129
  21. package/src/pag-font.ts +1 -3
  22. package/src/pag-image-layer.ts +1 -2
  23. package/src/pag-image.ts +1 -3
  24. package/src/pag-layer.ts +2 -3
  25. package/src/pag-player.ts +7 -6
  26. package/src/pag-solid-layer.ts +1 -2
  27. package/src/pag-surface.ts +1 -2
  28. package/src/pag-text-layer.ts +1 -2
  29. package/src/pag-view.ts +3 -14
  30. package/src/pag.ts +0 -6
  31. package/src/types.ts +46 -3
  32. package/src/utils/decorators.ts +0 -42
  33. package/src/utils/type-utils.ts +1 -9
  34. package/src/utils/ua.ts +0 -1
  35. package/src/wasm/libpag.js +1 -1
  36. package/src/wasm/libpag.wasm +0 -0
  37. package/src/wasm-mt/libpag.js +5 -5
  38. package/src/wasm-mt/libpag.wasm +0 -0
  39. package/src/wechat/pag-file.ts +1 -2
  40. package/src/wechat/pag-image.ts +0 -2
  41. package/src/wechat/pag-view.ts +1 -2
  42. package/types/third_party/tgfx/web/src/core/path-rasterizer.d.ts +4 -0
  43. package/types/third_party/tgfx/web/src/core/scaler-context.d.ts +9 -2
  44. package/types/third_party/tgfx/web/src/utils/decorators.d.ts +0 -2
  45. package/types/web/src/core/video-reader.d.ts +4 -3
  46. package/types/web/src/interfaces.d.ts +8 -15
  47. package/types/web/src/pag-composition.d.ts +4 -4
  48. package/types/web/src/pag-file.d.ts +4 -4
  49. package/types/web/src/pag-layer.d.ts +1 -1
  50. package/types/web/src/pag-player.d.ts +2 -2
  51. package/types/web/src/pag-view.d.ts +1 -1
  52. package/types/web/src/types.d.ts +13 -4
  53. package/types/web/src/utils/decorators.d.ts +0 -2
  54. package/types/web/src/utils/ua.d.ts +0 -1
  55. package/types/web/tsconfig.json +19 -0
  56. package/lib/libpag.worker.cjs.js +0 -798
  57. package/lib/libpag.worker.cjs.js.map +0 -1
  58. package/lib/libpag.worker.esm.js +0 -793
  59. package/lib/libpag.worker.esm.js.map +0 -1
  60. package/lib/libpag.worker.js +0 -804
  61. package/lib/libpag.worker.js.map +0 -1
  62. package/lib/libpag.worker.min.js +0 -2
  63. package/lib/libpag.worker.min.js.map +0 -1
  64. package/src/worker/client.ts +0 -80
  65. package/src/worker/events.ts +0 -41
  66. package/src/worker/pag-file.ts +0 -90
  67. package/src/worker/pag-image.ts +0 -43
  68. package/src/worker/pag-view.ts +0 -171
  69. package/src/worker/utils.ts +0 -29
  70. package/src/worker/video-reader.ts +0 -62
  71. package/src/worker/worker.ts +0 -169
  72. package/types/third_party/tgfx/web/src/core/web-mask.d.ts +0 -26
  73. package/types/web/src/utils/canvas.d.ts +0 -4
  74. package/types/web/src/worker/client.d.ts +0 -16
  75. package/types/web/src/worker/events.d.ts +0 -32
  76. package/types/web/src/worker/pag-file.d.ts +0 -33
  77. package/types/web/src/worker/pag-image.d.ts +0 -8
  78. package/types/web/src/worker/pag-view.d.ts +0 -67
  79. package/types/web/src/worker/utils.d.ts +0 -7
  80. package/types/web/src/worker/video-reader.d.ts +0 -16
  81. package/types/web/src/worker/worker.d.ts +0 -13
package/README.md CHANGED
@@ -98,50 +98,209 @@ with HTML, Vue, React, and PixiJS.
98
98
 
99
99
  You can find the API documentation [here](https://pag.io/docs/apis-web.html).
100
100
 
101
- ## Browser
101
+ `The above steps integrate the single-threaded version of libpag. To integrate the multithreaded version, please refer to the following integration guide.`
102
+
103
+ ## Multithreaded Integration Guide
104
+
105
+ ### Multithreading Support Basics
106
+
107
+ [WebAssembly multithreaded](https://emscripten.org/docs/porting/pthreads.html) relies on browser support for [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer). By leveraging `SharedArrayBuffer` and `Web Worker`, multithreaded Wasm modules can perform parallel computation to improve performance.
108
+
109
+ - **Key mechanisms**:
110
+ - Wasm threads use shared memory via `SharedArrayBuffer` for data synchronization and communication.
111
+ - Multiple thread instances of the same wasm module run in separate `Web Worker` execution contexts.
112
+
113
+ - **Requirements**:
114
+ - Wasm must be compiled with threading-related flags enabled (e.g., Emscripten’s `-pthread` support).
115
+ - The runtime environment must support `SharedArrayBuffer` and `Web Worker`.
116
+
117
+ ### Cross-Origin Security Requirements
118
+
119
+ To mitigate side-channel attacks, modern browsers enforce strict environment restrictions on enabling [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer). Enabling Wasm multithreading requires satisfying **Cross-Origin Isolation** conditions.
120
+
121
+ #### Required Response Headers
122
+
123
+ To enable cross-origin isolation, the server must set the following HTTP response headers for all relevant resources (HTML, wasm, JS, etc.):
124
+
125
+ | Header | Example Value | Purpose |
126
+ |-------------------------------|---------------------|----------------------------------------------|
127
+ | `Cross-Origin-Opener-Policy` (COOP) | `same-origin` | Isolates the current browsing context from cross-origin documents |
128
+ | `Cross-Origin-Embedder-Policy` (COEP) | `require-corp` | Restricts embedded resources to those complying with CORP or CORS policies |
129
+
130
+ For more details, see the [SharedArrayBuffer documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer).
131
+
132
+ #### Notes
133
+
134
+ - **The page and related resources must be served over HTTPS (or localhost).**
135
+ Browsers enable cross-origin isolation and `SharedArrayBuffer` only in [secure contexts](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts). Multithreading depends on this secure environment.
136
+ - Cross-origin isolation cannot be enabled on HTTP, and multithreading support will be disabled.
137
+
138
+ ### Browser (Recommended)
139
+
140
+ The web-side code for integrating multithreading is the same as the single-threaded, but the server must meet the above requirements; otherwise, multithreading will fail to load.
141
+
142
+ #### Important Notes
143
+
144
+ - **Do NOT load wasm resources cross-origin directly from public CDNs (such as npm CDNs).**
145
+ Most public npm CDNs (e.g., unpkg, jsDelivr) do not set COOP/COEP response headers by default and do not enable cross-origin isolation for all requests.
146
+ As a result, loading wasm/js from these CDNs via cross-origin requests will prevent browsers from enabling shared memory, disabling multithreading features.
147
+ It is strongly recommended to deploy wasm/js along with your webpage under the same origin to avoid cross-origin loading issues that disable multithreading.
148
+ - The multithreaded wasm/js packages are not published on the npm registry. You can download the web packages from the [release page](https://github.com/Tencent/libpag/releases) and deploy them yourself.
149
+
150
+ ### Local Build
151
+
152
+ ```bash
153
+ # ./web
154
+ npm run build:mt
155
+ ```
156
+
157
+ This will generate wasm/js files in the `web/lib-mt` directory. You can then start a local HTTP server to run the demo:
158
+
159
+ ```bash
160
+ # ./web
161
+ npm run server:mt
162
+ ```
163
+
164
+ Open http://localhost:8081/index.html in Chrome to see the demo.
165
+
166
+ To build a debug version, follow these steps:
167
+
168
+ ```bash
169
+ # ./web
170
+ npm run build:debug:mt
171
+ npm run server:mt
172
+ ```
173
+
174
+ > ⚠️ In the multithreaded version, if you rename the compiled output file libpag.min.js, you must search within the libpag.min.js file for all occurrences of "libpag.min.js" and replace them with the new filename.
175
+ > Otherwise, the program will fail to run. The following shows an example of this modification:
176
+
177
+ Before modification:
178
+
179
+ ```js
180
+ // filename: libpag.min.js
181
+ var worker = new Worker(new URL("libpag.min.js", import.meta.url), {
182
+ type: "module",
183
+ name: "em-pthread"
184
+ });
185
+ ```
186
+
187
+ After modification:
188
+
189
+ ```js
190
+ // filename: libpag.min.test.js
191
+ var worker = new Worker(new URL("libpag.min.test.js", import.meta.url), {
192
+ type: "module",
193
+ name: "em-pthread"
194
+ });
195
+ ```
196
+
197
+ ## Browser Compatibility
102
198
 
103
199
  | [<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 |
104
200
  | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------- |
105
201
  | Chrome >= 69 | Safari >= 11.3 | Android >= 7.0 | iOS >= 11.3 | last 2 versions |
106
202
 
203
+ **The compatibility table above only represents the compatibility for running the application. For users requiring mobile access, please refer to this article on [compatibility details](./doc/compatibility.md).**
204
+
205
+ ## Usage Guide
206
+
207
+ ### Garbage Collection
208
+
209
+ Since libpag is based on WebAssembly for cross-platform applications, the objects retrieved from WebAssembly are essentially C++ pointers, so JavaScript's garbage collector (GC) cannot release this memory. Therefore, when you no longer need the objects created by libpag, you must call the `destroy` method on the object to free the memory.
210
+
211
+ ### Rendering
212
+
213
+ #### First Frame Rendering
214
+
215
+ `PAGView.init` will render the first frame by default. If you don't need this, you can pass `{ firstFrame: false }` as the third parameter to `PAGView.init` to disable first-frame rendering.
216
+
217
+ During first-frame rendering, if there are BMP pre-compositions in the PAG animation file (details on how to check for BMP pre-composition in PAG files will be explained later), the `VideoReader` module will be invoked.
218
+
219
+ Since the `VideoReader` module relies on `VideoElement` on the Web platform, on certain mobile scenarios where `PAGView.init` is not called within a user interaction chain, the video playback may not be allowed, preventing proper rendering.
220
+
221
+ In such cases, we recommend initializing `PAGView` early with `PAGView.init(pagFile, canvas, { firstFrame: false })` and disabling first-frame rendering, and then calling `pagView.play()` for rendering when the user interacts.
222
+
223
+ #### PAG Rendering Size
224
+
225
+ On the Web platform, the device pixel resolution differs from the CSS pixel resolution, and the ratio between them is called `devicePixelRatio`. Therefore, to display 1px in CSS pixels, the rendering size should be 1px * `devicePixelRatio`.
226
+
227
+ PAG will scale the Canvas based on its visible size on the screen, which may affect the Canvas width, height, and `style`. If you want to avoid scaling the Canvas, you can pass `{ useScale: false }` as the third parameter to `PAGView.init` to disable scaling.
228
+
229
+ #### Large PAGView Size
230
+
231
+ For high-definition rendering, `PAGView` will default to rendering at Canvas size * `devicePixelRatio`. Due to performance limitations of the device, the maximum renderable size for WebGL can vary. Rendering at too large a size may lead to a white screen.
232
+
233
+ For mobile devices, it is recommended that the actual renderable size not exceed 2560px.
234
+
235
+ #### Multiple PAGView Instances
236
+
237
+ Since the Web version of PAG is a single-threaded SDK, we do not recommend **playing multiple PAGView instances on the same screen**.
238
+
239
+ For scenarios involving multiple PAGView instances, you need to be aware that the number of active WebGL contexts in a browser is limited: 16 contexts for Chrome, 8 for Safari. Due to this limitation, it is important to use `destroy` to reclaim unused PAGView instances and remove Canvas references.
240
+
241
+ Here is a solution for special cases, though it is not recommended:
242
+
243
+ If you need to have multiple PAGView instances on the same screen in Chrome and do not require support in Safari, you can try using the `canvas2D` mode by passing `{ useCanvas2D: true }` when calling `PAGView.init`. In this mode, a single WebGL context is used as the renderer, and the frames are distributed to multiple canvas2D contexts, bypassing the WebGL context limit.
244
+
245
+ Since the performance of [`CanvasRenderingContext2D.drawImage()`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage) is poor on Safari, we do not recommend using this mode on Safari.
246
+
247
+ #### Registering a Decoder
248
+
249
+ To bypass the "Video tags can only be used after user interaction with the page" restriction, the PAG Web version provides a software decoder injection interface `PAG.registerSoftwareDecoderFactory()`.
250
+
251
+ After injecting a software decoder, PAG will schedule the decoder to decode and display the BMP pre-compositions, thus enabling auto-play functionality on some platforms.
252
+
253
+ Recommended decoder integration: https://github.com/libpag/ffavc/tree/main/web
254
+
255
+ Platforms known to have the "Video tags can only be used after user interaction" restriction include: mobile WeChat browsers, iPhone power-saving mode, and some Android browsers.
256
+
257
+ ## About BMP Pre-composition
258
+
259
+ You can download [PAGViewer](https://pag.io/docs/install.html) to open PAG files, click "View" -> "Show Edit Panel". In the edit panel, you can see the number of Videos. If the number of Videos is greater than 0, it indicates that the PAG animation file contains BMP pre-compositions.
260
+
107
261
 
108
262
  ## Development
109
263
 
110
264
  First, ensure you have installed all the tools and dependencies listed in the [README.md](../README.md#Development)
111
265
  located in the project root directory.
112
266
 
267
+ > This section describes the development and testing process for the single-threaded version of libpag.
268
+
113
269
  ### Dependency Management
114
270
 
115
271
  Next, run the following command to install the required Node modules:
116
272
 
117
273
  ```bash
274
+ # ./web
118
275
  $ npm install
119
276
  ```
120
277
 
121
278
  ### Build (Debug)
122
279
 
123
- Execute `build.sh debug` to get `libpag.wasm` file.
280
+ Run the following command to compile the wasm/js.
124
281
 
125
282
  ```bash
126
283
  # ./web
127
- $ npm run build:debug
284
+ $ npm run build:debug:st
128
285
  ```
129
286
 
287
+ This will generate the wasm/js files in the `web/lib` directory.
288
+
130
289
  Start the TypeScript compiler watcher (optional).
131
290
 
132
291
  ```bash
133
292
  # ./web
134
- $ npm run dev
293
+ $ npm run dev:st
135
294
  ```
136
295
 
137
296
  Start the HTTP server.
138
297
 
139
298
  ```bash
140
- # ./
141
- $ npm run server
299
+ # ./web
300
+ $ npm run server:st
142
301
  ```
143
302
 
144
- Open Chrome and go to `http://localhost:8081/demo/index.html` to see the demo.
303
+ Open Chrome and go to `http://localhost:8081/index-st.html` to see the demo.
145
304
 
146
305
  To debug, install [C/C++ DevTools Support (DWARF)](https://chrome.google.com/webstore/detail/cc%20%20-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb).
147
306
  Then, open Chrome DevTools, go to Settings, Experiments, and check the "WebAssembly Debugging: Enable
@@ -151,7 +310,7 @@ DWARF support" option to enable SourceMap support. Now you can debug C++ files i
151
310
 
152
311
  ```bash
153
312
  # ./web
154
- $ npm run build
313
+ $ npm run build:st
155
314
  ```
156
315
 
157
316
  ### Build with CLion
@@ -167,17 +326,20 @@ Create a new build target in CLion and use the following **CMake options** (foun
167
326
  Build the release version
168
327
 
169
328
  ```bash
170
- $ npm run build
329
+ # ./web
330
+ $ npm run build:st
171
331
  ```
172
332
 
173
333
  Start the HTTP server.
174
334
 
175
335
  ```bash
176
- $ npm run server
336
+ # ./web
337
+ $ npm run server:st
177
338
  ```
178
339
 
179
340
  Start the cypress test.
180
341
 
181
342
  ```bash
343
+ # ./web
182
344
  $ npm run test
183
345
  ```
package/README.zh_CN.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <img src="https://pag.io/img/readme/logo.png" alt="PAG Logo" width="474"/>
2
2
 
3
- [官网](https://pag.io) | [English](./README.md) | 简体中文 | [Weblite版本](./web/lite) | [小程序版本](./web/wechat) | [小程序lite版本](./web/lite/wechat)
3
+ [官网](https://pag.io) | [English](./README.md) | 简体中文 | [Weblite版本](./lite/README.md) | [小程序版本](./wechat/README.md) | [小程序lite版本](./lite/wechat/README.md)
4
4
 
5
5
  ## 介绍
6
6
 
@@ -91,6 +91,99 @@ Demo 项目提 [pag-web](https://github.com/libpag/pag-web) 供了简单的接
91
91
 
92
92
  更多的 API 接口可以阅读 [API 文档](https://pag.io/api.html#/apis/web/)。
93
93
 
94
+ `上述步骤接入的是 libpag 单线程版本,若要接入多线程版本请参考如下接入指南。`
95
+
96
+ ## 多线程接入指南
97
+
98
+ ### 多线程支持基础
99
+
100
+ [WebAssembly 多线程](https://emscripten.org/docs/porting/pthreads.html) 依赖于浏览器对 [SharedArrayBuffer](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) 的支持。通过 `SharedArrayBuffer` 和 `Web Worker` ,多线程 Wasm 模块可以实现并行计算以提升性能。
101
+
102
+ - **主要机制**:
103
+ - Wasm 线程使用共享内存 `SharedArrayBuffer` 实现数据同步与通信。
104
+ - 利用 `Web Worker` 作为执行上下文,加载同一个 wasm 模块的多个线程实例。
105
+
106
+ - **使用条件**:
107
+ - Wasm 编译时需启用 `threads` 等相关编译特性(例如 Emscripten 的 `-pthread` 支持)。
108
+ - 运行环境须支持 `SharedArrayBuffer` 和 `Web Worker`。
109
+
110
+ ### 跨域安全性要求
111
+
112
+ 为了防范侧信道攻击,现代浏览器对启用 [SharedArrayBuffer](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) 施加了严格的环境限制。开启 Wasm 多线程必须满足 **跨域隔离(Cross-Origin Isolation)** 条件。
113
+ #### 必须配置的响应头
114
+
115
+ 为启用跨域隔离,服务端必须为所有相关资源(html、wasm、js等)设置以下 HTTP 响应头:
116
+
117
+ | 头部名称 | 示例值 | 作用说明 |
118
+ |----------------------------|---------------------|----------------------------------|
119
+ | `Cross-Origin-Opener-Policy` (COOP) | `same-origin` | 将当前上下文与跨域文档隔离 |
120
+ | `Cross-Origin-Embedder-Policy` (COEP) | `require-corp` | 限制嵌入当前页面的资源必须遵守 CORP 或 CORS 策略 |
121
+
122
+ 详细信息见 [SharedArrayBuffer文档](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)。
123
+
124
+ #### 注意事项
125
+
126
+ - **必须通过 HTTPS(或 localhost)访问页面和相关资源**
127
+ 浏览器仅在 [安全上下文](https://developer.mozilla.org/zh-CN/docs/Web/Security/Secure_Contexts) 中启用跨域隔离和 SharedArrayBuffer,多线程功能依赖此安全环境。
128
+ - HTTP 协议下不允许启用跨域隔离,多线程支持将被禁用
129
+
130
+ ### Browser(推荐)
131
+
132
+ 接入多线程的 Web 端代码与单线程相同,但服务端要符合上述接入要求,否则多线程会加载失败。
133
+
134
+ #### 注意事项
135
+ - **禁止直接从公共 CDN(如 npm CDN)跨域加载 wasm 资源**
136
+ 大多数公共 npm CDN(如 unpkg、jsDelivr 等)不会为静态资源默认设置 COOP/COEP 相关头,也不会对所有请求启用跨源隔离。
137
+ 因此,将 wasm/js 上传至此类 CDN 并通过跨域方式加载时,浏览器不会开启共享内存,多线程功能将被禁用。建议将 wasm/js 与页面文件部署至同源服务器,避免出现跨域加载导致多线程失效的问题。
138
+ - 多线程 wasm/js 不会发布至 npm 官网,可从 [release](https://github.com/Tencent/libpag/releases) 下载 web 端压缩包后自行部署使用。
139
+
140
+ ### 本地编译
141
+
142
+ ```bash
143
+ # ./web
144
+ $ npm run build:mt
145
+ ```
146
+
147
+ 这将会在 `web/lib-mt` 目录中生成 wasm/js,接下来,您可以通过运行以下命令启动一个 HTTP 服务器运行本地 demo
148
+
149
+ ```bash
150
+ # ./web
151
+ $ npm run server:mt
152
+ ```
153
+
154
+ Chrome 浏览器打开 `http://localhost:8081/index.html` 即可看到效果
155
+
156
+ 可根据如下步骤编译 debug 版本
157
+
158
+ ```bash
159
+ # ./web
160
+ $ npm run build:debug:mt
161
+ $ npm run server:mt
162
+ ```
163
+
164
+ >**⚠️** 在多线程版本中,如果修改了编译输出文件 libpag.min.js 的文件名,需要在 libpag.min.js 文件内搜索关键字 "libpag.min.js" ,并将所有出现的 "libpag.min.js" 替换为新的文件名。
165
+ >否则程序将无法运行。以下是修改示例:
166
+
167
+ 修改前
168
+
169
+ ```js
170
+ // 文件名: libpag.min.js
171
+ var worker = new Worker(new URL("libpag.min.js", import.meta.url), {
172
+ type: "module",
173
+ name: "em-pthread"
174
+ });
175
+ ```
176
+
177
+ 修改后
178
+
179
+ ```js
180
+ // 文件名: libpag.min.test.js
181
+ var worker = new Worker(new URL("libpag.min.test.js", import.meta.url), {
182
+ type: "module",
183
+ name: "em-pthread"
184
+ });
185
+ ```
186
+
94
187
  ## 浏览器兼容性
95
188
 
96
189
  | [<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 |
@@ -158,49 +251,52 @@ PAG 默认会对 Canvas 在屏幕中的可视尺寸进行缩放计算后进行
158
251
 
159
252
  ## 参与开发
160
253
 
254
+ > 本节介绍的是 libpag 单线程版本的开发、测试流程
255
+
161
256
  ### 前置工作
162
257
 
163
258
  需要确保已经可编译 C++ libpag 库,并且安装 [Emscripten 套件](https://emscripten.org/docs/getting_started/downloads.html) 和 Node 依赖
164
259
 
165
260
  ```bash
166
261
  # 安装Node依赖
262
+ # ./web
167
263
  $ npm install
168
264
  ```
169
265
 
170
266
  ### 开发流程
171
267
 
172
- 执行 `build.sh debug` 来获得 `libpag.wasm` 文件
268
+ 执行如下命令编译 wasm/js
173
269
 
174
270
  ```bash
175
- # ./web 目录下
176
- $ npm run build:debug
271
+ # ./web
272
+ $ npm run build:debug:st
177
273
  ```
178
274
 
275
+ 这将会在 `web/lib` 目录中生成 wasm/js
276
+
179
277
  开启 Typescript 自动编译(可选),修改 Typescript 文件会自动打包到 Javascript 文件
180
278
 
181
279
  ```bash
182
- # web目录下
183
- $ npm run dev
280
+ # ./web
281
+ $ npm run dev:st
184
282
  ```
185
283
 
186
284
  启动 HTTP 服务
187
285
 
188
286
  ```bash
189
- # web目录下
190
- $ npm run server
287
+ # ./web
288
+ $ npm run server:st
191
289
  ```
192
290
 
193
- Chrome 浏览器打开 `http://localhost:8081/demo/index.html` 即可看到效果
291
+ Chrome 浏览器打开 `http://localhost:8081/index-st.html` 即可看到效果
194
292
 
195
293
  需要断点调试时,可以安装 [C/C++ DevTools Support (DWARF)](https://chrome.google.com/webstore/detail/cc%20%20-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb),并打开 Chrome DevTools > 设置 > 实验 > 勾选「WebAssembly Debugging: Enable DWARF support」选项启用 SourceMap 支持。现在就可以在 Chrome DevTools 中对 C++ 文件进行断点调试了。
196
294
 
197
295
  ### 生产流程
198
296
 
199
- 执行 `build.sh` 脚本
200
-
201
297
  ```bash
202
- # ./web 目录下
203
- $ npm run build
298
+ # ./web
299
+ $ npm run build:st
204
300
  ```
205
301
 
206
302
  ### CLion 编译
@@ -216,17 +312,20 @@ $ npm run build
216
312
  打包生产版本
217
313
 
218
314
  ```bash
219
- $ npm run build
315
+ # ./web
316
+ $ npm run build:st
220
317
  ```
221
318
 
222
319
  启动测试 HTTP 服务
223
320
 
224
321
  ```bash
225
- $ npm run server
322
+ # ./web
323
+ $ npm run server:st
226
324
  ```
227
325
 
228
326
  启动 cypress 测试
229
327
 
230
328
  ```bash
329
+ # ./web
231
330
  $ npm run test
232
331
  ```