@web-ppt/viewer-core 0.2.0 → 0.4.0

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 ADDED
@@ -0,0 +1,85 @@
1
+ # 更新日志
2
+
3
+ 本文件记录对使用者可见的变化。版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
+
5
+ ## 0.4.0
6
+
7
+ 本版围绕**字体**:嵌入字体此前从来没有真正生效过,替换字体则完全没有。
8
+ 顺带修掉一个让静态画面把动画的几帧叠在一起的问题。
9
+
10
+ ### 新增
11
+
12
+ - **嵌入字体真的能用了**。PowerPoint 的 `ppt/fonts/*.fntdata` 不是裸 TTF,是 EOT 容器,
13
+ 而且实测**全部**开着 MTX 压缩(POI 语料 6/6、ORCID 样本 10/10)。此前把这段字节
14
+ 原样当 `font/ttf` 塞进 `@font-face`,浏览器一个都不认,只在控制台留一行
15
+ `invalid sfntVersion`。现在 core 自己剥容器(含异或混淆),MTX 解压走
16
+ `setFontDecoder()` 注入——官网接的是 [`mtx-decompressor`](https://www.npmjs.com/package/mtx-decompressor) 的 `eotToTtf`,
17
+ core 本身仍然只依赖 fflate。解不出来就跳过这个字体,不再塞浏览器注定拒绝的字节
18
+ - **`collectFonts(slides)`**:统计若干页用到哪些字体、每个字体要渲染哪些字。
19
+ 纯函数、只依赖 `types.ts`,`.ppt` 链路同样适用,Worker 里能跑
20
+ - **新包 [`@web-ppt/fonts`](packages/fonts)**(gzip 2.8KB,**包里零字节字体**):
21
+ 文件没带字体、本机也没装时的兜底。拉丁换**度量兼容**的免费字体
22
+ (Calibri→Carlito、Arial→Arimo 等,前进宽度逐字相等,断行与 PowerPoint 对齐),
23
+ 中文换思源系 / 霞鹜文楷。切片指向钉死版本的 fontsource,按 `unicode-range` 只下用到的那几片
24
+ - **`Viewer.refresh()`**:重渲当前页而不动页码与动画进度。网络字体到货后必须重渲——
25
+ 排版是同步的、加载是异步的,首帧一定是按回退字体断的行
26
+
27
+ ### 修复
28
+
29
+ - **静态渲染取动画终态,而不是「全部可见」**。一页里入场与退场的元素属于不同时刻,
30
+ 全画出来等于把几帧叠在一起:ORCID 那份样本的第 7 页三段文字本该逐条替换,
31
+ 叠起来一个字都读不出。终态会清空整页时(全员退场的收尾页)退回全部可见
32
+ - **run 没写 `a:latin` 时落到主题的 minorFont**。ECMA-376 的继承链最后一站就是
33
+ `fontScheme/minorFont`,此前直接当「没有字体」,渲染掉到 CSS 通用回退上,
34
+ 字宽与 PowerPoint 对不齐。真实文件大多在母版 txStyles 里写了 `+mn-lt` 所以少见,
35
+ 但这是「断行对不齐」的一个隐藏来源
36
+ - 字体栈去重:主题的 ea 字体常常正好是回退列表里的 `PingFang SC`,之前会拼出重复项
37
+
38
+ ### 其它
39
+
40
+ - 测试:1689 → **1848 项断言**,快照 158 → 160 个;新增 `sample-embedfont.pptx`
41
+ 覆盖嵌入字体的四种容器形态(未压缩 EOT / 未压缩+异或 / MTX 压缩 / 裸 TTF)
42
+ - `@web-ppt/core` gzip 84KB 不变;`@web-ppt/viewer-core` 6.8KB → 7.4KB
43
+ - 两个既有包的 peer 依赖同步升到 `^0.4.0`
44
+
45
+ ## 0.3.0
46
+
47
+ 本版把 ECMA-376 的几处主要缺口补齐,并首次拿 **Apache POI 的 242 个公开测试文件**跑批验证:
48
+ 排除 22 个故意损坏的模糊测试样本后,真实文件成功率 **210/220 = 95.5%**。
49
+
50
+ ### 新增
51
+
52
+ - **预设几何补齐到规范全集**:163 → **187 个**。此前缺的 24 个走的是
53
+ `PRESETS[name] ?? PRESETS.rect`,会**静默画成矩形**,不报错也不进 `unsupported`——
54
+ `accentCallout*` 这类常见形状出现即无声画错
55
+ - **运动路径动画**:`p:animMotion@path` 此前从未被读取,`presetClass="path"` 一律退化成淡入。
56
+ 现按弧长等距重采样成位移点,播放层走 linear 缓动(PowerPoint 的路径动画是匀速)
57
+ - **切换效果 21 → 41 种**:补上 PowerPoint 2010+ 的全部 19 种 p14 扩展,以及 p159 的
58
+ **morph**——按形状 id 在前后两页之间配对做几何补间,不是淡入淡出
59
+ - **数学公式 OMML 真排版**:此前只把 `m:t` 拼成一行文字(分式变成 `a+b/2c`)。
60
+ 现做完整箱模型排版,覆盖分式 / 根式 / 上下标 / 大算符 / 定界符 / 矩阵 / 重音 / 极限等 12 类结构
61
+ - **加密文档**:
62
+ - `.pptx` 标准加密(AES-ECB)与敏捷加密(AES-CBC 分段)
63
+ - `.ppt` 老式 RC4 CryptoAPI(40 / 56 / 128 位)
64
+ - 用法 `parse(input, { password })`;密码错误抛 `WrongPasswordError`,与「文件损坏」区分开
65
+ - **PICT(Apple QuickDraw)解码器**:Mac 版 PowerPoint 存的 OLE 预览与图片此前只能是裂图
66
+ - **SmartArt 无缓存 drawing part 时自行排布**:python-pptx / Google Slides 导出的文件
67
+ 常常只写数据与版式定义,此前只能得到灰色占位框。现支持线性 / 循环 / 金字塔 / 层级 /
68
+ 蛇形 / 辐射六种布局族
69
+
70
+ ### 修复
71
+
72
+ - `borderCallout2` 的引线是三点**开放**子路径,会被 `fill` 补成实心楔形——引线画成了黑三角
73
+ - 后台标签页的 `document.timeline` 是暂停的,`Animation.finished` 永不 resolve,
74
+ 切换的收尾逻辑(移除旧图层)就永远不执行,配合自动换片会让图层持续堆积
75
+ - OLE 预览优先读 `p:oleObj` 内嵌的 `p:pic`(Office 2010+ 的主要写法),旧式 VML 快照作为后备
76
+
77
+ ### 其它
78
+
79
+ - `@web-ppt/core` gzip 68KB → 84KB(新增的解码器与公式排版;加密与 PICT 走 hook 注入,可 tree-shake)
80
+ - 测试:1298 → **1689 项断言**,快照 142 → 158 个
81
+ - `@web-ppt/viewer-core` 的 peer 依赖同步升到 `^0.3.0`
82
+
83
+ ## 0.2.0 及更早
84
+
85
+ 见 [提交历史](https://github.com/unStone/web-ppt/commits/master)。
package/LICENSE CHANGED
@@ -1,201 +1,21 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
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.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 探测当前引擎是否会给 <foreignObject> 里的 HTML 应用外层 SVG 的缩放。
3
+ *
4
+ * WebKit 从 2008 年起就不应用(bug 23113),直到新的 LBSE 引擎才修好。
5
+ * 本引擎的幻灯片是 `viewBox` + `width:100%`,也就是永远处在被缩放的状态,
6
+ * 所以在受影响的 Safari / iOS 上,foreignObject 里的文本会按 1× 排版并错位。
7
+ *
8
+ * Marp 的 marpit-svg-polyfill 用 getScreenCTM() 反算缩放再补回去,但那套做法
9
+ * 要求 foreignObject 就位于幻灯片原点;本引擎的 foreignObject 嵌在每个形状各自的
10
+ * translate/rotate 里,补偿量没法用一个标量表达。既然渲染层本来就有一条原生
11
+ * <text> 路径,受影响时直接切过去更稳——代价只是这些浏览器上文本不可选中。
12
+ */
13
+ /** 仅供测试:清掉探测缓存 */
14
+ export declare function resetForeignObjectProbe(): void;
15
+ /**
16
+ * `doc` 只在首次探测时用到——结论按引擎缓存,同一个页面里不会出现两种 SVG 实现,
17
+ * 没必要为每个 iframe / 游离文档各测一遍。
18
+ */
19
+ export declare function foreignObjectScalesCorrectly(doc: Document): boolean;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  export { PresentationState } from './state';
9
9
  export type { PresentationStateOptions, StateChange } from './state';
10
10
  export { Viewer } from './viewer';
11
+ export { foreignObjectScalesCorrectly, resetForeignObjectProbe } from './foreign-object';
11
12
  export type { ViewerOptions } from './viewer';
12
- export { autoAdvanceMs, framesFor, groupSteps, hiddenBefore, playGroup, playTransition, } from './playback';
13
+ export { autoAdvanceMs, framesFor, morphPairs, playGroup, playTransition, transitionFrames } from './playback';
14
+ export { groupSteps, hiddenBefore, staticHidden } from '@web-ppt/core';
13
15
  export type { PlayHandle } from './playback';
@@ -4,16 +4,26 @@ interface Keyframes {
4
4
  to: Keyframe;
5
5
  }
6
6
  export declare function framesFor(step: AnimStep): Keyframes;
7
- /** 把动画按点击批次分组 */
8
- export declare function groupSteps(steps: AnimStep[] | undefined): AnimStep[][];
9
- /** 一批动画开始前,哪些元素应处于隐藏状态 */
10
- export declare function hiddenBefore(groups: AnimStep[][], upTo: number): Set<number>;
11
7
  export interface PlayHandle {
12
8
  cancel(): void;
13
9
  finished: Promise<void>;
14
10
  }
15
11
  /** 播放一批动画;返回可取消的句柄 */
16
12
  export declare function playGroup(container: Element, group: AnimStep[]): PlayHandle;
13
+ export declare function transitionFrames(t: Transition, incoming: boolean): Keyframe[];
14
+ /**
15
+ * morph:按 data-el(形状 id)在前后两页之间配对,配上的元素做几何补间,
16
+ * 其余淡入淡出。PowerPoint 的 morph 也是按形状 id 匹配的——morph 版面
17
+ * 基本都由「复制上一页再改」得来,id 天然一致。
18
+ *
19
+ * 配对成功的旧元素立刻置 0,新元素全程不透明,看起来才是"同一个东西在动",
20
+ * 而不是两层叠化。option="byWord"/"byChar" 的细粒度拆分不做,一律按对象处理。
21
+ */
22
+ export declare function morphPairs(outgoing: Element, incoming: Element): {
23
+ node: HTMLElement;
24
+ from: DOMRect;
25
+ to: DOMRect;
26
+ }[];
17
27
  /**
18
28
  * 播放切换:把旧内容截图式地留在下层,新内容在上层按效果进场。
19
29
  * outgoing 为旧内容节点(可为 null),incoming 为新内容节点。
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
- /** 当前批次下应当隐藏的元素 id —— UI 据此设置可见性 */
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;
@@ -1,28 +1,29 @@
1
- import { slideText as m, renderSlideToSvg as d, slideToPng as y } from "@web-ppt/core";
2
- const l = 1.15;
3
- function v(s) {
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
+ const h = 1.15;
4
+ function $(s) {
4
5
  switch (s) {
5
6
  case "l":
6
- return [-100 * l, 0];
7
+ return [-100 * h, 0];
7
8
  case "r":
8
- return [100 * l, 0];
9
+ return [100 * h, 0];
9
10
  case "u":
10
- return [0, -100 * l];
11
+ return [0, -100 * h];
11
12
  case "d":
12
- return [0, 100 * l];
13
+ return [0, 100 * h];
13
14
  case "lu":
14
- return [-100 * l, -100 * l];
15
+ return [-100 * h, -100 * h];
15
16
  case "ru":
16
- return [100 * l, -100 * l];
17
+ return [100 * h, -100 * h];
17
18
  case "ld":
18
- return [-100 * l, 100 * l];
19
+ return [-100 * h, 100 * h];
19
20
  case "rd":
20
- return [100 * l, 100 * l];
21
+ return [100 * h, 100 * h];
21
22
  default:
22
- return [0, 100 * l];
23
+ return [0, 100 * h];
23
24
  }
24
25
  }
25
- function u(s, t) {
26
+ function d(s, t) {
26
27
  const e = t ? 100 : 0;
27
28
  switch (s) {
28
29
  case "l":
@@ -39,12 +40,12 @@ function u(s, t) {
39
40
  return `inset(${e}% 0 0 0)`;
40
41
  }
41
42
  }
42
- function f(s) {
43
+ function A(s) {
43
44
  switch (s.effect) {
44
45
  case "appear":
45
46
  return { from: { opacity: 0 }, to: { opacity: 1 } };
46
47
  case "fly": {
47
- const [t, e] = v(s.dir);
48
+ const [t, e] = $(s.dir);
48
49
  return {
49
50
  from: { opacity: 0, transform: `translate(${t}%, ${e}%)` },
50
51
  to: { opacity: 1, transform: "translate(0, 0)" }
@@ -72,8 +73,8 @@ function f(s) {
72
73
  case "split":
73
74
  case "wheel":
74
75
  return {
75
- from: { opacity: 1, clipPath: u(s.dir, !0) },
76
- to: { opacity: 1, clipPath: u(s.dir, !1) }
76
+ from: { opacity: 1, clipPath: d(s.dir, !0) },
77
+ to: { opacity: 1, clipPath: d(s.dir, !1) }
77
78
  };
78
79
  case "dissolve":
79
80
  case "fade":
@@ -82,11 +83,11 @@ function f(s) {
82
83
  return { from: { opacity: 0 }, to: { opacity: 1 } };
83
84
  }
84
85
  }
85
- function g(s) {
86
- const t = f({ ...s });
86
+ function k(s) {
87
+ const t = A({ ...s });
87
88
  return { from: t.to, to: t.from };
88
89
  }
89
- function x(s) {
90
+ function E(s) {
90
91
  switch (s.effect) {
91
92
  case "spin":
92
93
  return { from: { transform: "rotate(0)" }, to: { transform: "rotate(360deg)" } };
@@ -96,51 +97,35 @@ function x(s) {
96
97
  return { from: { opacity: 1 }, to: { opacity: 0.35 } };
97
98
  }
98
99
  }
99
- function A(s) {
100
- return s.kind === "exit" ? g(s) : s.kind === "emphasis" ? x(s) : f(s);
101
- }
102
- function w(s) {
103
- if (!(s != null && s.length)) return [];
104
- const t = [];
105
- for (const e of s) {
106
- const n = e.clickGroup ?? 0;
107
- (t[n] ?? (t[n] = [])).push(e);
108
- }
109
- return t.filter(Boolean);
110
- }
111
- function b(s, t) {
112
- const e = /* @__PURE__ */ new Set();
113
- for (let n = t; n < s.length; n++)
114
- for (const i of s[n]) i.kind === "entrance" && e.add(i.target);
115
- for (let n = 0; n < t; n++)
116
- for (const i of s[n]) i.kind === "exit" && e.add(i.target);
117
- for (let n = t; n < s.length; n++)
118
- for (const i of s[n]) i.kind === "entrance" && e.add(i.target);
119
- return e;
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);
120
102
  }
121
- function T(s, t) {
103
+ function Y(s, t) {
104
+ var n, r;
122
105
  const e = [];
123
- let n = 0;
106
+ let a = 0;
124
107
  for (const i of t) {
125
- const r = s.querySelector(`[data-el="${i.target}"]`);
126
- if (!r) continue;
127
- const a = i.trigger === "afterPrev" ? n + i.delayMs : i.delayMs;
128
- i.trigger === "afterPrev" ? n = a + i.durationMs : n = Math.max(n, a + i.durationMs);
129
- const { from: c, to: o } = A(i);
130
- r.style.visibility = "visible", i.kind === "entrance" && (r.style.opacity = "");
108
+ const c = s.querySelector(`[data-el="${i.target}"]`);
109
+ if (!c) continue;
110
+ const o = i.trigger === "afterPrev" ? a + i.delayMs : i.delayMs;
111
+ i.trigger === "afterPrev" ? a = o + i.durationMs : a = Math.max(a, o + i.durationMs);
112
+ const { from: l, to: p } = z(i);
113
+ c.style.visibility = "visible", i.kind === "entrance" && (c.style.opacity = "");
114
+ const f = (n = i.motionPath) != null && n.length ? i.motionPath.map(([u, y]) => ({ transform: `translate(${u}px, ${y}px)` })) : [l, p];
131
115
  try {
132
- const h = r.animate([c, o], {
116
+ const u = c.animate(f, {
133
117
  duration: i.durationMs,
134
- delay: a,
135
- easing: "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
118
+ delay: o,
119
+ // 路径动画在 PowerPoint 里是匀速,不能套入场用的缓动
120
+ easing: (r = i.motionPath) != null && r.length ? "linear" : "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
136
121
  fill: "both"
137
122
  });
138
- i.kind === "exit" && h.finished.then(() => {
139
- r.style.visibility = "hidden";
123
+ i.kind === "exit" && u.finished.then(() => {
124
+ c.style.visibility = "hidden";
140
125
  }).catch(() => {
141
- }), e.push(h);
126
+ }), e.push(u);
142
127
  } catch {
143
- Object.assign(r.style, o);
128
+ Object.assign(c.style, f[f.length - 1] ?? p);
144
129
  }
145
130
  }
146
131
  return {
@@ -155,27 +140,27 @@ function T(s, t) {
155
140
  })
156
141
  };
157
142
  }
158
- function p(s, t) {
159
- const e = s.dir ?? "", n = (r, a) => `translate(${r}, ${a})`, i = () => e.includes("l") ? ["-100%", "0"] : e.includes("r") ? ["100%", "0"] : e.includes("u") ? ["0", "-100%"] : ["0", "100%"];
143
+ function x(s, t) {
144
+ const e = s.dir ?? "", a = (r, i) => `translate(${r}, ${i})`, n = () => e.includes("l") ? ["-100%", "0"] : e.includes("r") ? ["100%", "0"] : e.includes("u") ? ["0", "-100%"] : ["0", "100%"];
160
145
  switch (s.type) {
161
146
  case "cut":
162
147
  return t ? [{ opacity: 1 }, { opacity: 1 }] : [{ opacity: 0 }, { opacity: 0 }];
163
148
  case "push":
164
149
  case "pull": {
165
- const [r, a] = i(), c = s.type === "pull" ? -1 : 1, o = (h) => h === "0" ? "0" : `${-parseFloat(h) * c}%`;
166
- return t ? [{ transform: n(c > 0 ? r : o(r), c > 0 ? a : o(a)) }, { transform: "translate(0,0)" }] : [{ transform: "translate(0,0)" }, { transform: n(o(r), o(a)) }];
150
+ const [r, i] = n(), c = s.type === "pull" ? -1 : 1, o = (l) => l === "0" ? "0" : `${-parseFloat(l) * c}%`;
151
+ return t ? [{ transform: a(c > 0 ? r : o(r), c > 0 ? i : o(i)) }, { transform: "translate(0,0)" }] : [{ transform: "translate(0,0)" }, { transform: a(o(r), o(i)) }];
167
152
  }
168
153
  case "cover": {
169
- const [r, a] = i();
170
- return t ? [{ transform: n(r, a) }, { transform: "translate(0,0)" }] : [{ opacity: 1 }, { opacity: 1 }];
154
+ const [r, i] = n();
155
+ return t ? [{ transform: a(r, i) }, { transform: "translate(0,0)" }] : [{ opacity: 1 }, { opacity: 1 }];
171
156
  }
172
157
  case "wipe": {
173
- const r = u(e || "d", !0), a = u(e || "d", !1);
174
- return t ? [{ clipPath: r }, { clipPath: a }] : [{ opacity: 1 }, { opacity: 1 }];
158
+ const r = d(e || "d", !0), i = d(e || "d", !1);
159
+ return t ? [{ clipPath: r }, { clipPath: i }] : [{ opacity: 1 }, { opacity: 1 }];
175
160
  }
176
161
  case "split": {
177
- const r = e.startsWith("vert"), a = e.endsWith("out"), c = r ? "inset(0 50% 0 50%)" : "inset(50% 0 50% 0)", o = "inset(0 0 0 0)";
178
- return t ? a ? [{ clipPath: c }, { clipPath: o }] : [{ clipPath: o }, { clipPath: o }] : [{ clipPath: o }, { clipPath: c }];
162
+ const r = e.startsWith("vert"), i = e.endsWith("out"), c = r ? "inset(0 50% 0 50%)" : "inset(50% 0 50% 0)", o = "inset(0 0 0 0)";
163
+ return t ? i ? [{ clipPath: c }, { clipPath: o }] : [{ clipPath: o }, { clipPath: o }] : [{ clipPath: o }, { clipPath: c }];
179
164
  }
180
165
  case "zoom":
181
166
  return t ? [{ opacity: 0, transform: e === "out" ? "scale(1.4)" : "scale(0.6)" }, { opacity: 1, transform: "scale(1)" }] : [{ opacity: 1 }, { opacity: 0 }];
@@ -185,6 +170,67 @@ function p(s, t) {
185
170
  case "plus":
186
171
  case "wedge":
187
172
  return t ? [{ opacity: 0, transform: "scale(0.7)" }, { opacity: 1, transform: "scale(1)" }] : [{ opacity: 1 }, { opacity: 0 }];
173
+ case "ripple":
174
+ return t ? [{ clipPath: "circle(0% at 50% 50%)" }, { clipPath: "circle(75% at 50% 50%)" }] : [{ opacity: 1 }, { opacity: 1 }];
175
+ case "vortex":
176
+ return t ? [{ opacity: 0, transform: "scale(0.2) rotate(-180deg)" }, { opacity: 1, transform: "none" }] : [{ opacity: 1 }, { opacity: 0 }];
177
+ case "honeycomb":
178
+ return t ? [{ opacity: 0, transform: "scale(0.85) rotate(-6deg)" }, { opacity: 1, transform: "none" }] : [{ opacity: 1, transform: "none" }, { opacity: 0, transform: "scale(1.1)" }];
179
+ case "glitter":
180
+ return t ? [{ opacity: 0, clipPath: d(e || "l", !0) }, { opacity: 1, clipPath: d(e || "l", !1) }] : [{ opacity: 1 }, { opacity: 0 }];
181
+ case "shred":
182
+ return t ? [{ opacity: 0, transform: "scale(1.06)" }, { opacity: 1, transform: "none" }] : [{ opacity: 1, transform: "none" }, { opacity: 0, transform: "scaleY(0.9)" }];
183
+ case "flash":
184
+ return t ? [{ opacity: 0, filter: "brightness(3)" }, { opacity: 1, filter: "brightness(1)" }] : [{ opacity: 1, filter: "brightness(1)" }, { opacity: 0, filter: "brightness(3)" }];
185
+ case "reveal": {
186
+ const [r, i] = n();
187
+ return t ? [{ opacity: 0, transform: a(r, i) }, { opacity: 1, transform: "translate(0,0)" }] : [{ opacity: 1 }, { opacity: 0 }];
188
+ }
189
+ case "wheelReverse":
190
+ return t ? [{ opacity: 0, transform: "scale(1.3) rotate(20deg)" }, { opacity: 1, transform: "none" }] : [{ opacity: 1 }, { opacity: 0 }];
191
+ case "doors":
192
+ return t ? [{ clipPath: "inset(0 50% 0 50%)" }, { clipPath: "inset(0 0 0 0)" }] : [{ opacity: 1 }, { opacity: 1 }];
193
+ case "window":
194
+ return t ? [{ clipPath: "inset(50% 0 50% 0)" }, { clipPath: "inset(0 0 0 0)" }] : [{ opacity: 1 }, { opacity: 1 }];
195
+ case "switch":
196
+ case "flip":
197
+ case "prism": {
198
+ const r = s.type === "flip" ? -1 : 1;
199
+ return t ? [
200
+ { opacity: 0, transform: `perspective(1400px) rotateY(${r * -80}deg)` },
201
+ { opacity: 1, transform: "perspective(1400px) rotateY(0)" }
202
+ ] : [
203
+ { opacity: 1, transform: "perspective(1400px) rotateY(0)" },
204
+ { opacity: 0, transform: `perspective(1400px) rotateY(${r * 80}deg)` }
205
+ ];
206
+ }
207
+ case "ferris":
208
+ return t ? [
209
+ { opacity: 0, transform: "perspective(1400px) rotateX(70deg)" },
210
+ { opacity: 1, transform: "perspective(1400px) rotateX(0)" }
211
+ ] : [
212
+ { opacity: 1, transform: "perspective(1400px) rotateX(0)" },
213
+ { opacity: 0, transform: "perspective(1400px) rotateX(-70deg)" }
214
+ ];
215
+ case "gallery":
216
+ case "conveyor": {
217
+ const r = s.type === "conveyor" ? 25 : 12, i = e.includes("l") ? "-100%" : "100%", c = e.includes("l") ? "100%" : "-100%";
218
+ return t ? [
219
+ { transform: `perspective(1600px) translateX(${i}) rotateY(${r}deg)` },
220
+ { transform: "perspective(1600px) translateX(0) rotateY(0)" }
221
+ ] : [
222
+ { transform: "perspective(1600px) translateX(0) rotateY(0)" },
223
+ { transform: `perspective(1600px) translateX(${c}) rotateY(${-r}deg)` }
224
+ ];
225
+ }
226
+ case "pan": {
227
+ const [r, i] = n(), c = (o) => o === "0" ? "0" : `${-parseFloat(o)}%`;
228
+ return t ? [{ transform: a(r, i) }, { transform: "translate(0,0)" }] : [{ transform: "translate(0,0)" }, { transform: a(c(r), c(i)) }];
229
+ }
230
+ case "flythrough":
231
+ return t ? [{ opacity: 0, transform: "perspective(1000px) scale(0.15)" }, { opacity: 1, transform: "none" }] : [{ opacity: 1, transform: "none" }, { opacity: 0, transform: "perspective(1000px) scale(2.2)" }];
232
+ case "warp":
233
+ return t ? [{ opacity: 0, transform: "skewX(-18deg) scale(1.15)" }, { opacity: 1, transform: "none" }] : [{ opacity: 1, transform: "none" }, { opacity: 0, transform: "skewX(18deg) scale(0.9)" }];
188
234
  case "blinds":
189
235
  case "checker":
190
236
  case "comb":
@@ -193,30 +239,75 @@ function p(s, t) {
193
239
  case "newsflash":
194
240
  case "dissolve":
195
241
  case "fade":
242
+ case "morph":
196
243
  default:
197
244
  return t ? [{ opacity: 0 }, { opacity: 1 }] : [{ opacity: 1 }, { opacity: 0 }];
198
245
  }
199
246
  }
200
- function k(s, t, e) {
247
+ function b(s, t) {
248
+ const e = Promise.all(s.map((a) => a.catch(() => {
249
+ }))).then(() => {
250
+ });
251
+ return typeof setTimeout != "function" ? e : Promise.race([e, new Promise((a) => setTimeout(a, t + 250))]);
252
+ }
253
+ function L(s, t) {
254
+ const e = /* @__PURE__ */ new Map();
255
+ s.querySelectorAll("[data-el]").forEach((n) => {
256
+ const r = n.getBoundingClientRect();
257
+ (r.width > 0 || r.height > 0) && e.set(n.getAttribute("data-el") ?? "", r);
258
+ });
259
+ const a = [];
260
+ return t.querySelectorAll("[data-el]").forEach((n) => {
261
+ const r = e.get(n.getAttribute("data-el") ?? "");
262
+ if (!r) return;
263
+ const i = n.getBoundingClientRect();
264
+ i.width <= 0 && i.height <= 0 || a.push({ node: n, from: r, to: i });
265
+ }), a;
266
+ }
267
+ function X(s, t, e) {
268
+ if (!s) return Promise.resolve();
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
+ try {
271
+ i.push(o.animate(l, a).finished);
272
+ } catch {
273
+ }
274
+ };
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, P = p.height > 0 ? l.height / p.height : 1;
277
+ c(o, [
278
+ { transformOrigin: "left top", transform: `translate(${f}px, ${u}px) scale(${y}, ${P})` },
279
+ { transformOrigin: "left top", transform: "none" }
280
+ ]);
281
+ }
282
+ return s.querySelectorAll("[data-el]").forEach((o) => {
283
+ const l = r.has(o.getAttribute("data-el"));
284
+ c(o, l ? [{ opacity: 0 }, { opacity: 0 }] : [{ opacity: 1 }, { opacity: 0 }]);
285
+ }), t.querySelectorAll("[data-el]").forEach((o) => {
286
+ r.has(o.getAttribute("data-el")) || c(o, [{ opacity: 0 }, { opacity: 1 }]);
287
+ }), b(i, e.durationMs).then(() => {
288
+ s.remove();
289
+ });
290
+ }
291
+ function N(s, t, e) {
201
292
  if (!e || e.type === "none")
202
293
  return s == null || s.remove(), Promise.resolve();
203
- const n = { duration: e.durationMs, easing: "ease-in-out", fill: "both" }, i = [];
294
+ if (e.type === "morph" && s) return X(s, t, e);
295
+ const a = { duration: e.durationMs, easing: "ease-in-out", fill: "both" }, n = [];
204
296
  try {
205
- i.push(t.animate(p(e, !0), n).finished), s && i.push(s.animate(p(e, !1), n).finished);
297
+ n.push(t.animate(x(e, !0), a).finished), s && n.push(s.animate(x(e, !1), a).finished);
206
298
  } catch {
207
299
  return s == null || s.remove(), Promise.resolve();
208
300
  }
209
- return Promise.all(i.map((r) => r.catch(() => {
210
- }))).then(() => {
301
+ return b(n, e.durationMs).then(() => {
211
302
  s == null || s.remove();
212
303
  });
213
304
  }
214
- function C(s) {
305
+ function V(s) {
215
306
  var e;
216
307
  const t = (e = s.transition) == null ? void 0 : e.advanceAfterMs;
217
308
  return t !== void 0 && t > 0 ? t : null;
218
309
  }
219
- class P {
310
+ class F {
220
311
  constructor(t, e = {}) {
221
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();
222
313
  }
@@ -245,13 +336,18 @@ class P {
245
336
  get hasPendingAnimation() {
246
337
  return this.animate && this.cursor < this.groups.length;
247
338
  }
248
- /** 当前批次下应当隐藏的元素 id —— UI 据此设置可见性 */
339
+ /**
340
+ * 当前应当隐藏的元素 id —— UI 据此设置可见性。
341
+ *
342
+ * 不播动画时不是「全部可见」,而是动画终态:入场与退场的元素属于不同时刻,
343
+ * 一起画出来就是几帧叠在一起(见 core 的 staticHidden)。
344
+ */
249
345
  get hiddenElementIds() {
250
- return this.animate ? b(this.groups, this.cursor) : /* @__PURE__ */ new Set();
346
+ return this.animate ? C(this.groups, this.cursor) : w(this.slide);
251
347
  }
252
348
  /** 本页的自动换片延迟(毫秒),未配置则为 null */
253
349
  get autoAdvanceDelay() {
254
- return this.options.autoAdvance ? C(this.slide) : null;
350
+ return this.options.autoAdvance ? V(this.slide) : null;
255
351
  }
256
352
  // ---------------- 订阅 ----------------
257
353
  subscribe(t) {
@@ -273,13 +369,13 @@ class P {
273
369
  * 前进时带上目标页的切换效果;回退不播切换,避免观感错乱。
274
370
  */
275
371
  goTo(t, e = "forward") {
276
- const n = this.clamp(t);
277
- if (n === this.idx) return !1;
278
- const i = this.idx;
279
- return this.idx = n, this.loadAnimations(), this.emit({
372
+ const a = this.clamp(t);
373
+ if (a === this.idx) return !1;
374
+ const n = this.idx;
375
+ return this.idx = a, this.loadAnimations(), this.emit({
280
376
  type: "slide",
281
- index: n,
282
- previous: i,
377
+ index: a,
378
+ previous: n,
283
379
  transition: e === "forward" && this.animate ? this.slide.transition : void 0
284
380
  }), !0;
285
381
  }
@@ -304,7 +400,7 @@ class P {
304
400
  }
305
401
  // ---------------- 动画 ----------------
306
402
  loadAnimations() {
307
- this.groups = this.animate ? w(this.slide.animations) : [], this.cursor = 0;
403
+ this.groups = this.animate ? M(this.slide.animations) : [], this.cursor = 0;
308
404
  }
309
405
  /**
310
406
  * 推进一批动画。返回应播放的这一批;没有待播批次时返回 null。
@@ -335,42 +431,62 @@ class P {
335
431
  // ---------------- 文本 / 搜索 ----------------
336
432
  text(t) {
337
433
  let e = this.textCache.get(t);
338
- return e === void 0 && (e = m(this.presentation.slides[t]), this.textCache.set(t, e)), e;
434
+ return e === void 0 && (e = S(this.presentation.slides[t]), this.textCache.set(t, e)), e;
339
435
  }
340
436
  /** 全文搜索,返回命中的页索引 */
341
437
  search(t) {
342
438
  const e = t.trim().toLowerCase();
343
439
  if (!e) return [];
344
- const n = [];
345
- for (let i = 0; i < this.count; i++)
346
- this.text(i).toLowerCase().includes(e) && n.push(i);
347
- return n;
440
+ const a = [];
441
+ for (let n = 0; n < this.count; n++)
442
+ this.text(n).toLowerCase().includes(e) && a.push(n);
443
+ return a;
348
444
  }
349
445
  /** 解析内部跳转目标(`slide:3` / `slide:last`)为页索引;外部链接返回 null */
350
446
  resolveLink(t) {
351
447
  if (!t.startsWith("slide:")) return null;
352
- const e = t.slice(6), n = e === "last" ? this.count : Number(e);
353
- return Number.isFinite(n) ? this.clamp(n - 1) : null;
448
+ const e = t.slice(6), a = e === "last" ? this.count : Number(e);
449
+ return Number.isFinite(a) ? this.clamp(a - 1) : null;
354
450
  }
355
451
  destroy() {
356
452
  this.cancelAutoAdvance(), this.listeners.clear(), this.textCache.clear();
357
453
  }
358
454
  }
359
- class M {
360
- constructor(t, e, n = {}) {
361
- this.container = t, this.presentation = e, this.svgCache = /* @__PURE__ */ new Map(), this.playing = null, this.cancelAuto = null, this.onChange = null, this.onAnimStep = null, this.onLinkClick = null, this.handleClick = (i) => {
362
- const r = i.target, a = r == null ? void 0 : r.closest("[data-slide]");
363
- if (a) {
364
- i.preventDefault();
365
- const h = this.state.resolveLink(`slide:${a.getAttribute("data-slide") ?? ""}`);
366
- h !== null && this.goTo(h);
455
+ const g = "http://www.w3.org/2000/svg", D = "http://www.w3.org/1999/xhtml";
456
+ let m = null;
457
+ function H() {
458
+ m = null;
459
+ }
460
+ function q(s) {
461
+ if (m !== null) return m;
462
+ const t = s.body ?? s.documentElement;
463
+ if (!t) return !0;
464
+ const e = s.createElementNS(g, "svg");
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");
466
+ const a = s.createElementNS(g, "foreignObject");
467
+ a.setAttribute("width", "100"), a.setAttribute("height", "100");
468
+ const n = s.createElementNS(D, "div");
469
+ n.setAttribute("style", "width:100px;height:100px"), a.appendChild(n), e.appendChild(a), t.appendChild(e);
470
+ const r = n.getBoundingClientRect().width;
471
+ return e.remove(), m = r === 0 || r > 150, m;
472
+ }
473
+ class O {
474
+ constructor(t, e, a = {}) {
475
+ this.container = t, this.presentation = e, this.svgCache = /* @__PURE__ */ new Map(), this.playing = null, this.cancelAuto = null, this.onChange = null, this.onAnimStep = null, this.onLinkClick = null, this.handleClick = (r) => {
476
+ const i = r.target, c = i == null ? void 0 : i.closest("[data-slide]");
477
+ if (c) {
478
+ r.preventDefault();
479
+ const p = this.state.resolveLink(`slide:${c.getAttribute("data-slide") ?? ""}`);
480
+ p !== null && this.goTo(p);
367
481
  return;
368
482
  }
369
- const c = r == null ? void 0 : r.closest("a[href]"), o = c == null ? void 0 : c.getAttribute("href");
370
- o && this.onLinkClick && this.onLinkClick(o) === !0 && i.preventDefault();
371
- }, this.state = new P(e, n), this.unsubscribe = this.state.subscribe((i) => {
372
- var r, a;
373
- i.type === "slide" ? (this.paint(i.transition), (r = this.onChange) == null || r.call(this, i.index)) : i.type === "animation" ? (i.group ? this.play(i.group) : this.applyVisibility(), (a = this.onAnimStep) == null || a.call(this, i.done, i.total)) : i.type === "zoom" && this.applyZoom();
483
+ const o = i == null ? void 0 : i.closest("a[href]"), l = o == null ? void 0 : o.getAttribute("href");
484
+ l && this.onLinkClick && this.onLinkClick(l) === !0 && r.preventDefault();
485
+ }, this.media = a.media ?? "badge";
486
+ const n = a.textMode ?? "auto";
487
+ this.textMode = n !== "auto" ? n : q(t.ownerDocument) ? "html" : "svg", this.state = new F(e, a), this.unsubscribe = this.state.subscribe((r) => {
488
+ var i, c;
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();
374
490
  }), this.container.addEventListener("click", this.handleClick), this.paint();
375
491
  }
376
492
  // ---------------- 转发给状态机 ----------------
@@ -426,36 +542,58 @@ class M {
426
542
  /** 带缓存的单页 SVG(主视图用) */
427
543
  slideSvg(t) {
428
544
  let e = this.svgCache.get(t);
429
- return e === void 0 && (e = d(this.presentation, this.presentation.slides[t]), this.svgCache.set(t, e)), e;
545
+ return e === void 0 && (e = v(this.presentation, this.presentation.slides[t], {
546
+ media: this.media,
547
+ textMode: this.textMode
548
+ }), this.svgCache.set(t, e)), e;
430
549
  }
431
550
  /** 不走缓存,用于缩略图等需要独立 defs id 的场景 */
432
551
  renderSlide(t) {
433
- return d(this.presentation, this.presentation.slides[t]);
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();
434
569
  }
435
570
  exportPng(t = 2, e = this.index) {
436
- return y(this.presentation, this.presentation.slides[e], t);
571
+ return T(this.presentation, this.presentation.slides[e], t);
437
572
  }
438
573
  paint(t) {
439
- var a, c, o;
440
- (a = this.playing) == null || a.cancel(), this.playing = null, (c = this.cancelAuto) == null || c.call(this);
574
+ var i, c, o;
575
+ (i = this.playing) == null || i.cancel(), this.playing = null, (c = this.cancelAuto) == null || c.call(this);
441
576
  const e = document.createElement("div");
442
577
  e.style.cssText = "position:absolute;inset:0;display:flex;align-items:center;justify-content:center", e.innerHTML = this.slideSvg(this.index);
443
- const n = this.container.firstElementChild, i = this.container.ownerDocument.defaultView;
444
- (!i || i.getComputedStyle(this.container).position === "static") && (this.container.style.position = "relative"), t && n ? (this.container.appendChild(e), k(n, e, t).then(() => this.startAutoAdvance())) : (this.container.innerHTML = "", this.container.appendChild(e), this.startAutoAdvance());
578
+ const a = this.container.firstElementChild, n = this.container.ownerDocument.defaultView;
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());
445
580
  const r = e.querySelector("svg");
446
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);
447
582
  }
448
583
  play(t) {
449
584
  var e;
450
- (e = this.playing) == null || e.cancel(), this.playing = T(this.container, t), this.applyVisibility();
585
+ (e = this.playing) == null || e.cancel(), this.playing = Y(this.container, t), this.applyVisibility();
451
586
  }
452
- /** 按状态机给出的隐藏集合设置元素可见性 */
587
+ /**
588
+ * 按状态机给出的隐藏集合设置元素可见性。
589
+ *
590
+ * 不播动画时也要跑:静态画面取的是动画终态,退场元素同样得藏起来。
591
+ */
453
592
  applyVisibility() {
454
- if (!this.state.animate) return;
455
593
  const t = this.state.hiddenElementIds;
456
594
  this.container.querySelectorAll("[data-el]").forEach((e) => {
457
- const n = Number(e.getAttribute("data-el"));
458
- e.style.visibility = t.has(n) ? "hidden" : "visible";
595
+ const a = Number(e.getAttribute("data-el"));
596
+ e.style.visibility = t.has(a) ? "hidden" : "visible";
459
597
  });
460
598
  }
461
599
  applyZoom() {
@@ -473,12 +611,17 @@ class M {
473
611
  }
474
612
  }
475
613
  export {
476
- P as PresentationState,
477
- M as Viewer,
478
- C as autoAdvanceMs,
479
- A as framesFor,
480
- w as groupSteps,
481
- b as hiddenBefore,
482
- T as playGroup,
483
- k as playTransition
614
+ F as PresentationState,
615
+ O as Viewer,
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,
626
+ x as transitionFrames
484
627
  };
package/dist/viewer.d.ts CHANGED
@@ -8,12 +8,25 @@ import { PresentationState, type PresentationStateOptions } from './state';
8
8
  * 因此换成 React / Vue 只需重写这三件事。
9
9
  */
10
10
  export interface ViewerOptions extends PresentationStateOptions {
11
+ /**
12
+ * 媒体呈现:'badge' 只画封面帧与播放标识,'player' 嵌入可播放的
13
+ * <video>/<audio>。导出(exportPng)不受影响,始终走 badge。
14
+ */
15
+ media?: 'badge' | 'player';
16
+ /**
17
+ * 文本渲染方式。默认 'auto':探测到引擎不给 foreignObject 应用 SVG 缩放
18
+ * (WebKit bug 23113)时自动切到原生 <text>,否则用 foreignObject。
19
+ * 传死值可绕过探测。
20
+ */
21
+ textMode?: 'auto' | 'html' | 'svg';
11
22
  }
12
23
  export declare class Viewer {
13
24
  private container;
14
25
  readonly presentation: Presentation;
15
26
  readonly state: PresentationState;
16
27
  private svgCache;
28
+ private media;
29
+ private textMode;
17
30
  private playing;
18
31
  private cancelAuto;
19
32
  private unsubscribe;
@@ -42,10 +55,22 @@ export declare class Viewer {
42
55
  slideSvg(i: number): string;
43
56
  /** 不走缓存,用于缩略图等需要独立 defs id 的场景 */
44
57
  renderSlide(i: number): string;
58
+ /**
59
+ * 重渲当前页,页码与动画进度都不变。
60
+ *
61
+ * 给「渲染完之后世界才变」的情况用,最典型的是网络字体到货:原生 `<text>`
62
+ * 路径的断行是渲染时拿 canvas 量出来烘进 SVG 的,字体换了就必须重量一遍;
63
+ * `foreignObject` 路径由浏览器自己重排,重渲只是顺带把缓存换掉。
64
+ */
65
+ refresh(): void;
45
66
  exportPng(scale?: number, i?: number): Promise<Blob>;
46
67
  private paint;
47
68
  private play;
48
- /** 按状态机给出的隐藏集合设置元素可见性 */
69
+ /**
70
+ * 按状态机给出的隐藏集合设置元素可见性。
71
+ *
72
+ * 不播动画时也要跑:静态画面取的是动画终态,退场元素同样得藏起来。
73
+ */
49
74
  private applyVisibility;
50
75
  private applyZoom;
51
76
  private startAutoAdvance;
package/package.json CHANGED
@@ -1,12 +1,22 @@
1
1
  {
2
2
  "name": "@web-ppt/viewer-core",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Web-PPT 查看器的 headless 状态机与播放层:导航 / 缩放 / 搜索 / 动画批次,可被任意 UI 框架驱动",
5
5
  "keywords": [
6
6
  "pptx",
7
+ "ppt",
8
+ "powerpoint",
7
9
  "viewer",
8
10
  "headless",
9
- "state-machine"
11
+ "state-machine",
12
+ "presentation",
13
+ "slideshow",
14
+ "svg",
15
+ "browser",
16
+ "react",
17
+ "vue",
18
+ "svelte",
19
+ "typescript"
10
20
  ],
11
21
  "license": "MIT",
12
22
  "author": "unStone",
@@ -31,6 +41,7 @@
31
41
  "files": [
32
42
  "dist",
33
43
  "README.md",
44
+ "CHANGELOG.md",
34
45
  "LICENSE"
35
46
  ],
36
47
  "scripts": {
@@ -39,7 +50,7 @@
39
50
  "prepack": "node ../../tooling/sync-package-docs.mjs"
40
51
  },
41
52
  "peerDependencies": {
42
- "@web-ppt/core": "^0.2.0"
53
+ "@web-ppt/core": "^0.4.0"
43
54
  },
44
55
  "publishConfig": {
45
56
  "access": "public"