@web-ppt/viewer-core 0.3.0 → 0.4.1
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.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -201
- package/dist/index.d.ts +1 -1
- package/dist/state.d.ts +6 -1
- package/dist/viewer-core.js +75 -50
- package/dist/viewer.d.ts +13 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,83 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录对使用者可见的变化。版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## 0.4.1
|
|
6
|
+
|
|
7
|
+
全是中文排版的修正。四处都由同一份小学课件暴露出来,每一处都拿 PowerPoint
|
|
8
|
+
自己写进文件的 `spAutoFit` 框高做的判据 —— 那个高度是它按实际行数算完存下来的,
|
|
9
|
+
等于文件自己作证该排几行。
|
|
10
|
+
|
|
11
|
+
### 修复
|
|
12
|
+
|
|
13
|
+
- **CJK 标点挤压**。汉字和全角标点都占一整格,但标点的墨迹只占半格
|
|
14
|
+
(`,` `。` 的墨在左半格,`(` `《` 在右半格)。一行放不下时 PowerPoint 会把
|
|
15
|
+
这些空半格挤掉,我们没做,于是多断出一行。规则取「放不下才挤」:放得下时
|
|
16
|
+
保持全角。两条渲染路径算同一笔账——原生 `<text>` 用逐字符 `dx`,
|
|
17
|
+
HTML 用负边距,都与字体无关,不依赖字体是否提供 `halt` 半角替换字形。
|
|
18
|
+
|
|
19
|
+
顺带一句:这类问题**换字体救不了**。所有中文字体的方格一样大,黑体、
|
|
20
|
+
PingFang、思源黑体量出来完全相同
|
|
21
|
+
- **量不到字时的中文估宽**。回退估算原本把每个字符都当 0.55em,中文因此窄掉
|
|
22
|
+
将近一半。Node / jsdom 里恒走这条路,于是**自动缩放对中文一直缩不够**——
|
|
23
|
+
autofit 固件实测旧值排出来 204px、框只有 140px,仍然溢出;按全角整格算
|
|
24
|
+
之后是 146px
|
|
25
|
+
- **百分比行距的基准**。`lnSpc/spcPct` 是「单倍行距」的百分比,而单倍行距是
|
|
26
|
+
**字体的行高**(≈1.2em),不是字号。把 150% 直接当 CSS `line-height:1.5` 用,
|
|
27
|
+
每行矮两成。中文文档里 1.5 倍行距是标配,影响面不小;行距偏紧还会连累
|
|
28
|
+
自动缩放与居中 / 底对齐文本的位置
|
|
29
|
+
- **静态画面改取动画初始态**(原本取终态)。缩略图、主视图、进演示模式后的
|
|
30
|
+
第一帧现在是同一个画面,不再「先把这页演完、再从头演一遍」。
|
|
31
|
+
「不能全部画出来」的理由不变:一页里入场与退场的元素属于不同时刻,摊开画
|
|
32
|
+
等于把几帧叠在一起。例外从「全员退场的收尾页」换成「整页都带入场动画的
|
|
33
|
+
封面页」——那种情况初始态一片空白,退回全部可见
|
|
34
|
+
|
|
35
|
+
### 其它
|
|
36
|
+
|
|
37
|
+
- 测试:1848 → **1873 项断言**,快照 160 → 162 个。`sample-autofit.pptx` 补一页
|
|
38
|
+
把百分比行距与绝对行距放在一起对照——之前 17 个固件里没有一个用过
|
|
39
|
+
`spcPct`,这条路径从没被走过
|
|
40
|
+
- `@web-ppt/viewer-core` 与 `@web-ppt/fonts` 本版无改动,跟随版本号对齐
|
|
41
|
+
|
|
42
|
+
## 0.4.0
|
|
43
|
+
|
|
44
|
+
本版围绕**字体**:嵌入字体此前从来没有真正生效过,替换字体则完全没有。
|
|
45
|
+
顺带修掉一个让静态画面把动画的几帧叠在一起的问题。
|
|
46
|
+
|
|
47
|
+
### 新增
|
|
48
|
+
|
|
49
|
+
- **嵌入字体真的能用了**。PowerPoint 的 `ppt/fonts/*.fntdata` 不是裸 TTF,是 EOT 容器,
|
|
50
|
+
而且实测**全部**开着 MTX 压缩(POI 语料 6/6、ORCID 样本 10/10)。此前把这段字节
|
|
51
|
+
原样当 `font/ttf` 塞进 `@font-face`,浏览器一个都不认,只在控制台留一行
|
|
52
|
+
`invalid sfntVersion`。现在 core 自己剥容器(含异或混淆),MTX 解压走
|
|
53
|
+
`setFontDecoder()` 注入——官网接的是 [`mtx-decompressor`](https://www.npmjs.com/package/mtx-decompressor) 的 `eotToTtf`,
|
|
54
|
+
core 本身仍然只依赖 fflate。解不出来就跳过这个字体,不再塞浏览器注定拒绝的字节
|
|
55
|
+
- **`collectFonts(slides)`**:统计若干页用到哪些字体、每个字体要渲染哪些字。
|
|
56
|
+
纯函数、只依赖 `types.ts`,`.ppt` 链路同样适用,Worker 里能跑
|
|
57
|
+
- **新包 [`@web-ppt/fonts`](packages/fonts)**(gzip 2.8KB,**包里零字节字体**):
|
|
58
|
+
文件没带字体、本机也没装时的兜底。拉丁换**度量兼容**的免费字体
|
|
59
|
+
(Calibri→Carlito、Arial→Arimo 等,前进宽度逐字相等,断行与 PowerPoint 对齐),
|
|
60
|
+
中文换思源系 / 霞鹜文楷。切片指向钉死版本的 fontsource,按 `unicode-range` 只下用到的那几片
|
|
61
|
+
- **`Viewer.refresh()`**:重渲当前页而不动页码与动画进度。网络字体到货后必须重渲——
|
|
62
|
+
排版是同步的、加载是异步的,首帧一定是按回退字体断的行
|
|
63
|
+
|
|
64
|
+
### 修复
|
|
65
|
+
|
|
66
|
+
- **静态渲染取动画终态,而不是「全部可见」**。一页里入场与退场的元素属于不同时刻,
|
|
67
|
+
全画出来等于把几帧叠在一起:ORCID 那份样本的第 7 页三段文字本该逐条替换,
|
|
68
|
+
叠起来一个字都读不出。终态会清空整页时(全员退场的收尾页)退回全部可见
|
|
69
|
+
- **run 没写 `a:latin` 时落到主题的 minorFont**。ECMA-376 的继承链最后一站就是
|
|
70
|
+
`fontScheme/minorFont`,此前直接当「没有字体」,渲染掉到 CSS 通用回退上,
|
|
71
|
+
字宽与 PowerPoint 对不齐。真实文件大多在母版 txStyles 里写了 `+mn-lt` 所以少见,
|
|
72
|
+
但这是「断行对不齐」的一个隐藏来源
|
|
73
|
+
- 字体栈去重:主题的 ea 字体常常正好是回退列表里的 `PingFang SC`,之前会拼出重复项
|
|
74
|
+
|
|
75
|
+
### 其它
|
|
76
|
+
|
|
77
|
+
- 测试:1689 → **1848 项断言**,快照 158 → 160 个;新增 `sample-embedfont.pptx`
|
|
78
|
+
覆盖嵌入字体的四种容器形态(未压缩 EOT / 未压缩+异或 / MTX 压缩 / 裸 TTF)
|
|
79
|
+
- `@web-ppt/core` gzip 84KB 不变;`@web-ppt/viewer-core` 6.8KB → 7.4KB
|
|
80
|
+
- 两个既有包的 peer 依赖同步升到 `^0.4.0`
|
|
81
|
+
|
|
5
82
|
## 0.3.0
|
|
6
83
|
|
|
7
84
|
本版把 ECMA-376 的几处主要缺口补齐,并首次拿 **Apache POI 的 242 个公开测试文件**跑批验证:
|
package/LICENSE
CHANGED
|
@@ -1,201 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 unStone
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ export { Viewer } from './viewer';
|
|
|
11
11
|
export { foreignObjectScalesCorrectly, resetForeignObjectProbe } from './foreign-object';
|
|
12
12
|
export type { ViewerOptions } from './viewer';
|
|
13
13
|
export { autoAdvanceMs, framesFor, morphPairs, playGroup, playTransition, transitionFrames } from './playback';
|
|
14
|
-
export { groupSteps, hiddenBefore } from '@web-ppt/core';
|
|
14
|
+
export { groupSteps, hiddenBefore, staticHidden } from '@web-ppt/core';
|
|
15
15
|
export type { PlayHandle } from './playback';
|
package/dist/state.d.ts
CHANGED
|
@@ -55,7 +55,12 @@ export declare class PresentationState {
|
|
|
55
55
|
get animationTotal(): number;
|
|
56
56
|
get animationDone(): number;
|
|
57
57
|
get hasPendingAnimation(): boolean;
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* 当前应当隐藏的元素 id —— UI 据此设置可见性。
|
|
60
|
+
*
|
|
61
|
+
* 不播动画时不是「全部可见」,而是动画终态:入场与退场的元素属于不同时刻,
|
|
62
|
+
* 一起画出来就是几帧叠在一起(见 core 的 staticHidden)。
|
|
63
|
+
*/
|
|
59
64
|
get hiddenElementIds(): ReadonlySet<number>;
|
|
60
65
|
/** 本页的自动换片延迟(毫秒),未配置则为 null */
|
|
61
66
|
get autoAdvanceDelay(): number | null;
|
package/dist/viewer-core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { hiddenBefore as
|
|
2
|
-
import { groupSteps as
|
|
1
|
+
import { hiddenBefore as C, staticHidden as w, groupSteps as M, slideText as S, renderSlideToSvg as v, slideToPng as T } from "@web-ppt/core";
|
|
2
|
+
import { groupSteps as R, hiddenBefore as W, staticHidden as G } from "@web-ppt/core";
|
|
3
3
|
const h = 1.15;
|
|
4
|
-
function
|
|
4
|
+
function $(s) {
|
|
5
5
|
switch (s) {
|
|
6
6
|
case "l":
|
|
7
7
|
return [-100 * h, 0];
|
|
@@ -40,12 +40,12 @@ function d(s, t) {
|
|
|
40
40
|
return `inset(${e}% 0 0 0)`;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function A(s) {
|
|
44
44
|
switch (s.effect) {
|
|
45
45
|
case "appear":
|
|
46
46
|
return { from: { opacity: 0 }, to: { opacity: 1 } };
|
|
47
47
|
case "fly": {
|
|
48
|
-
const [t, e] =
|
|
48
|
+
const [t, e] = $(s.dir);
|
|
49
49
|
return {
|
|
50
50
|
from: { opacity: 0, transform: `translate(${t}%, ${e}%)` },
|
|
51
51
|
to: { opacity: 1, transform: "translate(0, 0)" }
|
|
@@ -83,11 +83,11 @@ function w(s) {
|
|
|
83
83
|
return { from: { opacity: 0 }, to: { opacity: 1 } };
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
const t =
|
|
86
|
+
function k(s) {
|
|
87
|
+
const t = A({ ...s });
|
|
88
88
|
return { from: t.to, to: t.from };
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function E(s) {
|
|
91
91
|
switch (s.effect) {
|
|
92
92
|
case "spin":
|
|
93
93
|
return { from: { transform: "rotate(0)" }, to: { transform: "rotate(360deg)" } };
|
|
@@ -97,10 +97,10 @@ function k(s) {
|
|
|
97
97
|
return { from: { opacity: 1 }, to: { opacity: 0.35 } };
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
return s.kind === "exit" ?
|
|
100
|
+
function z(s) {
|
|
101
|
+
return s.kind === "exit" ? k(s) : s.kind === "emphasis" ? E(s) : s.kind === "motion" ? { from: { opacity: 1 }, to: { opacity: 1 } } : A(s);
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function Y(s, t) {
|
|
104
104
|
var n, r;
|
|
105
105
|
const e = [];
|
|
106
106
|
let a = 0;
|
|
@@ -109,7 +109,7 @@ function z(s, t) {
|
|
|
109
109
|
if (!c) continue;
|
|
110
110
|
const o = i.trigger === "afterPrev" ? a + i.delayMs : i.delayMs;
|
|
111
111
|
i.trigger === "afterPrev" ? a = o + i.durationMs : a = Math.max(a, o + i.durationMs);
|
|
112
|
-
const { from: l, to: p } =
|
|
112
|
+
const { from: l, to: p } = z(i);
|
|
113
113
|
c.style.visibility = "visible", i.kind === "entrance" && (c.style.opacity = "");
|
|
114
114
|
const f = (n = i.motionPath) != null && n.length ? i.motionPath.map(([u, y]) => ({ transform: `translate(${u}px, ${y}px)` })) : [l, p];
|
|
115
115
|
try {
|
|
@@ -244,13 +244,13 @@ function x(s, t) {
|
|
|
244
244
|
return t ? [{ opacity: 0 }, { opacity: 1 }] : [{ opacity: 1 }, { opacity: 0 }];
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function b(s, t) {
|
|
248
248
|
const e = Promise.all(s.map((a) => a.catch(() => {
|
|
249
249
|
}))).then(() => {
|
|
250
250
|
});
|
|
251
251
|
return typeof setTimeout != "function" ? e : Promise.race([e, new Promise((a) => setTimeout(a, t + 250))]);
|
|
252
252
|
}
|
|
253
|
-
function
|
|
253
|
+
function L(s, t) {
|
|
254
254
|
const e = /* @__PURE__ */ new Map();
|
|
255
255
|
s.querySelectorAll("[data-el]").forEach((n) => {
|
|
256
256
|
const r = n.getBoundingClientRect();
|
|
@@ -264,18 +264,18 @@ function Y(s, t) {
|
|
|
264
264
|
i.width <= 0 && i.height <= 0 || a.push({ node: n, from: r, to: i });
|
|
265
265
|
}), a;
|
|
266
266
|
}
|
|
267
|
-
function
|
|
267
|
+
function X(s, t, e) {
|
|
268
268
|
if (!s) return Promise.resolve();
|
|
269
|
-
const a = { duration: e.durationMs, easing: "ease-in-out", fill: "both" }, n =
|
|
269
|
+
const a = { duration: e.durationMs, easing: "ease-in-out", fill: "both" }, n = L(s, t), r = new Set(n.map((o) => o.node.getAttribute("data-el"))), i = [], c = (o, l) => {
|
|
270
270
|
try {
|
|
271
271
|
i.push(o.animate(l, a).finished);
|
|
272
272
|
} catch {
|
|
273
273
|
}
|
|
274
274
|
};
|
|
275
275
|
for (const { node: o, from: l, to: p } of n) {
|
|
276
|
-
const f = l.left - p.left, u = l.top - p.top, y = p.width > 0 ? l.width / p.width : 1,
|
|
276
|
+
const f = l.left - p.left, u = l.top - p.top, y = p.width > 0 ? l.width / p.width : 1, P = p.height > 0 ? l.height / p.height : 1;
|
|
277
277
|
c(o, [
|
|
278
|
-
{ transformOrigin: "left top", transform: `translate(${f}px, ${u}px) scale(${y}, ${
|
|
278
|
+
{ transformOrigin: "left top", transform: `translate(${f}px, ${u}px) scale(${y}, ${P})` },
|
|
279
279
|
{ transformOrigin: "left top", transform: "none" }
|
|
280
280
|
]);
|
|
281
281
|
}
|
|
@@ -284,30 +284,30 @@ function L(s, t, e) {
|
|
|
284
284
|
c(o, l ? [{ opacity: 0 }, { opacity: 0 }] : [{ opacity: 1 }, { opacity: 0 }]);
|
|
285
285
|
}), t.querySelectorAll("[data-el]").forEach((o) => {
|
|
286
286
|
r.has(o.getAttribute("data-el")) || c(o, [{ opacity: 0 }, { opacity: 1 }]);
|
|
287
|
-
}),
|
|
287
|
+
}), b(i, e.durationMs).then(() => {
|
|
288
288
|
s.remove();
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
-
function
|
|
291
|
+
function N(s, t, e) {
|
|
292
292
|
if (!e || e.type === "none")
|
|
293
293
|
return s == null || s.remove(), Promise.resolve();
|
|
294
|
-
if (e.type === "morph" && s) return
|
|
294
|
+
if (e.type === "morph" && s) return X(s, t, e);
|
|
295
295
|
const a = { duration: e.durationMs, easing: "ease-in-out", fill: "both" }, n = [];
|
|
296
296
|
try {
|
|
297
297
|
n.push(t.animate(x(e, !0), a).finished), s && n.push(s.animate(x(e, !1), a).finished);
|
|
298
298
|
} catch {
|
|
299
299
|
return s == null || s.remove(), Promise.resolve();
|
|
300
300
|
}
|
|
301
|
-
return
|
|
301
|
+
return b(n, e.durationMs).then(() => {
|
|
302
302
|
s == null || s.remove();
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
|
-
function
|
|
305
|
+
function V(s) {
|
|
306
306
|
var e;
|
|
307
307
|
const t = (e = s.transition) == null ? void 0 : e.advanceAfterMs;
|
|
308
308
|
return t !== void 0 && t > 0 ? t : null;
|
|
309
309
|
}
|
|
310
|
-
class
|
|
310
|
+
class F {
|
|
311
311
|
constructor(t, e = {}) {
|
|
312
312
|
this.presentation = t, this.options = e, this.idx = 0, this.zoomValue = 1, this.groups = [], this.cursor = 0, this.listeners = /* @__PURE__ */ new Set(), this.autoTimer = null, this.textCache = /* @__PURE__ */ new Map(), this.idx = this.clamp(e.index ?? 0), this.loadAnimations();
|
|
313
313
|
}
|
|
@@ -336,13 +336,18 @@ class V {
|
|
|
336
336
|
get hasPendingAnimation() {
|
|
337
337
|
return this.animate && this.cursor < this.groups.length;
|
|
338
338
|
}
|
|
339
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* 当前应当隐藏的元素 id —— UI 据此设置可见性。
|
|
341
|
+
*
|
|
342
|
+
* 不播动画时不是「全部可见」,而是动画终态:入场与退场的元素属于不同时刻,
|
|
343
|
+
* 一起画出来就是几帧叠在一起(见 core 的 staticHidden)。
|
|
344
|
+
*/
|
|
340
345
|
get hiddenElementIds() {
|
|
341
|
-
return this.animate ?
|
|
346
|
+
return this.animate ? C(this.groups, this.cursor) : w(this.slide);
|
|
342
347
|
}
|
|
343
348
|
/** 本页的自动换片延迟(毫秒),未配置则为 null */
|
|
344
349
|
get autoAdvanceDelay() {
|
|
345
|
-
return this.options.autoAdvance ?
|
|
350
|
+
return this.options.autoAdvance ? V(this.slide) : null;
|
|
346
351
|
}
|
|
347
352
|
// ---------------- 订阅 ----------------
|
|
348
353
|
subscribe(t) {
|
|
@@ -395,7 +400,7 @@ class V {
|
|
|
395
400
|
}
|
|
396
401
|
// ---------------- 动画 ----------------
|
|
397
402
|
loadAnimations() {
|
|
398
|
-
this.groups = this.animate ?
|
|
403
|
+
this.groups = this.animate ? M(this.slide.animations) : [], this.cursor = 0;
|
|
399
404
|
}
|
|
400
405
|
/**
|
|
401
406
|
* 推进一批动画。返回应播放的这一批;没有待播批次时返回 null。
|
|
@@ -426,7 +431,7 @@ class V {
|
|
|
426
431
|
// ---------------- 文本 / 搜索 ----------------
|
|
427
432
|
text(t) {
|
|
428
433
|
let e = this.textCache.get(t);
|
|
429
|
-
return e === void 0 && (e =
|
|
434
|
+
return e === void 0 && (e = S(this.presentation.slides[t]), this.textCache.set(t, e)), e;
|
|
430
435
|
}
|
|
431
436
|
/** 全文搜索,返回命中的页索引 */
|
|
432
437
|
search(t) {
|
|
@@ -447,12 +452,12 @@ class V {
|
|
|
447
452
|
this.cancelAutoAdvance(), this.listeners.clear(), this.textCache.clear();
|
|
448
453
|
}
|
|
449
454
|
}
|
|
450
|
-
const g = "http://www.w3.org/2000/svg",
|
|
455
|
+
const g = "http://www.w3.org/2000/svg", D = "http://www.w3.org/1999/xhtml";
|
|
451
456
|
let m = null;
|
|
452
|
-
function
|
|
457
|
+
function H() {
|
|
453
458
|
m = null;
|
|
454
459
|
}
|
|
455
|
-
function
|
|
460
|
+
function q(s) {
|
|
456
461
|
if (m !== null) return m;
|
|
457
462
|
const t = s.body ?? s.documentElement;
|
|
458
463
|
if (!t) return !0;
|
|
@@ -460,7 +465,7 @@ function D(s) {
|
|
|
460
465
|
e.setAttribute("viewBox", "0 0 100 100"), e.setAttribute("width", "200"), e.setAttribute("height", "200"), e.setAttribute("style", "position:absolute;left:-9999px;top:-9999px;pointer-events:none");
|
|
461
466
|
const a = s.createElementNS(g, "foreignObject");
|
|
462
467
|
a.setAttribute("width", "100"), a.setAttribute("height", "100");
|
|
463
|
-
const n = s.createElementNS(
|
|
468
|
+
const n = s.createElementNS(D, "div");
|
|
464
469
|
n.setAttribute("style", "width:100px;height:100px"), a.appendChild(n), e.appendChild(a), t.appendChild(e);
|
|
465
470
|
const r = n.getBoundingClientRect().width;
|
|
466
471
|
return e.remove(), m = r === 0 || r > 150, m;
|
|
@@ -479,7 +484,7 @@ class O {
|
|
|
479
484
|
l && this.onLinkClick && this.onLinkClick(l) === !0 && r.preventDefault();
|
|
480
485
|
}, this.media = a.media ?? "badge";
|
|
481
486
|
const n = a.textMode ?? "auto";
|
|
482
|
-
this.textMode = n !== "auto" ? n :
|
|
487
|
+
this.textMode = n !== "auto" ? n : q(t.ownerDocument) ? "html" : "svg", this.state = new F(e, a), this.unsubscribe = this.state.subscribe((r) => {
|
|
483
488
|
var i, c;
|
|
484
489
|
r.type === "slide" ? (this.paint(r.transition), (i = this.onChange) == null || i.call(this, r.index)) : r.type === "animation" ? (r.group ? this.play(r.group) : this.applyVisibility(), (c = this.onAnimStep) == null || c.call(this, r.done, r.total)) : r.type === "zoom" && this.applyZoom();
|
|
485
490
|
}), this.container.addEventListener("click", this.handleClick), this.paint();
|
|
@@ -544,10 +549,26 @@ class O {
|
|
|
544
549
|
}
|
|
545
550
|
/** 不走缓存,用于缩略图等需要独立 defs id 的场景 */
|
|
546
551
|
renderSlide(t) {
|
|
547
|
-
|
|
552
|
+
const e = this.presentation.slides[t];
|
|
553
|
+
return v(this.presentation, e, {
|
|
554
|
+
// 缩略图不嵌播放器:既没意义,还会为每个缩略图各建一个媒体元素
|
|
555
|
+
textMode: this.textMode,
|
|
556
|
+
// 缩略图是静态产物,没有后续的 applyVisibility,隐藏状态只能烘进 SVG
|
|
557
|
+
hiddenElements: [...w(e)]
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* 重渲当前页,页码与动画进度都不变。
|
|
562
|
+
*
|
|
563
|
+
* 给「渲染完之后世界才变」的情况用,最典型的是网络字体到货:原生 `<text>`
|
|
564
|
+
* 路径的断行是渲染时拿 canvas 量出来烘进 SVG 的,字体换了就必须重量一遍;
|
|
565
|
+
* `foreignObject` 路径由浏览器自己重排,重渲只是顺带把缓存换掉。
|
|
566
|
+
*/
|
|
567
|
+
refresh() {
|
|
568
|
+
this.svgCache.delete(this.index), this.paint();
|
|
548
569
|
}
|
|
549
570
|
exportPng(t = 2, e = this.index) {
|
|
550
|
-
return
|
|
571
|
+
return T(this.presentation, this.presentation.slides[e], t);
|
|
551
572
|
}
|
|
552
573
|
paint(t) {
|
|
553
574
|
var i, c, o;
|
|
@@ -555,17 +576,20 @@ class O {
|
|
|
555
576
|
const e = document.createElement("div");
|
|
556
577
|
e.style.cssText = "position:absolute;inset:0;display:flex;align-items:center;justify-content:center", e.innerHTML = this.slideSvg(this.index);
|
|
557
578
|
const a = this.container.firstElementChild, n = this.container.ownerDocument.defaultView;
|
|
558
|
-
(!n || n.getComputedStyle(this.container).position === "static") && (this.container.style.position = "relative"), t && a ? (this.container.appendChild(e),
|
|
579
|
+
(!n || n.getComputedStyle(this.container).position === "static") && (this.container.style.position = "relative"), t && a ? (this.container.appendChild(e), N(a, e, t).then(() => this.startAutoAdvance())) : (this.container.innerHTML = "", this.container.appendChild(e), this.startAutoAdvance());
|
|
559
580
|
const r = e.querySelector("svg");
|
|
560
581
|
r && (r.style.display = "block", r.style.maxWidth = "none"), this.applyZoom(), this.applyVisibility(), (o = this.onAnimStep) == null || o.call(this, this.state.animationDone, this.state.animationTotal);
|
|
561
582
|
}
|
|
562
583
|
play(t) {
|
|
563
584
|
var e;
|
|
564
|
-
(e = this.playing) == null || e.cancel(), this.playing =
|
|
585
|
+
(e = this.playing) == null || e.cancel(), this.playing = Y(this.container, t), this.applyVisibility();
|
|
565
586
|
}
|
|
566
|
-
/**
|
|
587
|
+
/**
|
|
588
|
+
* 按状态机给出的隐藏集合设置元素可见性。
|
|
589
|
+
*
|
|
590
|
+
* 不播动画时也要跑:静态画面取的是动画终态,退场元素同样得藏起来。
|
|
591
|
+
*/
|
|
567
592
|
applyVisibility() {
|
|
568
|
-
if (!this.state.animate) return;
|
|
569
593
|
const t = this.state.hiddenElementIds;
|
|
570
594
|
this.container.querySelectorAll("[data-el]").forEach((e) => {
|
|
571
595
|
const a = Number(e.getAttribute("data-el"));
|
|
@@ -587,16 +611,17 @@ class O {
|
|
|
587
611
|
}
|
|
588
612
|
}
|
|
589
613
|
export {
|
|
590
|
-
|
|
614
|
+
F as PresentationState,
|
|
591
615
|
O as Viewer,
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
616
|
+
V as autoAdvanceMs,
|
|
617
|
+
q as foreignObjectScalesCorrectly,
|
|
618
|
+
z as framesFor,
|
|
619
|
+
R as groupSteps,
|
|
620
|
+
W as hiddenBefore,
|
|
621
|
+
L as morphPairs,
|
|
622
|
+
Y as playGroup,
|
|
623
|
+
N as playTransition,
|
|
624
|
+
H as resetForeignObjectProbe,
|
|
625
|
+
G as staticHidden,
|
|
601
626
|
x as transitionFrames
|
|
602
627
|
};
|
package/dist/viewer.d.ts
CHANGED
|
@@ -55,10 +55,22 @@ export declare class Viewer {
|
|
|
55
55
|
slideSvg(i: number): string;
|
|
56
56
|
/** 不走缓存,用于缩略图等需要独立 defs id 的场景 */
|
|
57
57
|
renderSlide(i: number): string;
|
|
58
|
+
/**
|
|
59
|
+
* 重渲当前页,页码与动画进度都不变。
|
|
60
|
+
*
|
|
61
|
+
* 给「渲染完之后世界才变」的情况用,最典型的是网络字体到货:原生 `<text>`
|
|
62
|
+
* 路径的断行是渲染时拿 canvas 量出来烘进 SVG 的,字体换了就必须重量一遍;
|
|
63
|
+
* `foreignObject` 路径由浏览器自己重排,重渲只是顺带把缓存换掉。
|
|
64
|
+
*/
|
|
65
|
+
refresh(): void;
|
|
58
66
|
exportPng(scale?: number, i?: number): Promise<Blob>;
|
|
59
67
|
private paint;
|
|
60
68
|
private play;
|
|
61
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* 按状态机给出的隐藏集合设置元素可见性。
|
|
71
|
+
*
|
|
72
|
+
* 不播动画时也要跑:静态画面取的是动画终态,退场元素同样得藏起来。
|
|
73
|
+
*/
|
|
62
74
|
private applyVisibility;
|
|
63
75
|
private applyZoom;
|
|
64
76
|
private startAutoAdvance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web-ppt/viewer-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Web-PPT 查看器的 headless 状态机与播放层:导航 / 缩放 / 搜索 / 动画批次,可被任意 UI 框架驱动",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pptx",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"prepack": "node ../../tooling/sync-package-docs.mjs"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@web-ppt/core": "^0.
|
|
53
|
+
"@web-ppt/core": "^0.4.0"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|