@silurus/ooxml 0.50.0 → 0.51.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/README.md CHANGED
@@ -30,7 +30,7 @@ pnpm add @silurus/ooxml
30
30
 
31
31
  > **Bundler note**: this package embeds `.wasm` files. With Vite add [`vite-plugin-wasm`](https://github.com/Menci/vite-plugin-wasm); with webpack use [`experiments.asyncWebAssembly`](https://webpack.js.org/configuration/experiments/).
32
32
 
33
- > **Bundle size note**: the package is ESM-only (`.mjs`). npm's *Unpacked Size* sums all four entry bundles, including the **opt-in** math engine (MathJax + STIX Two Math, ~3 MB). What actually lands in your app is much smaller — import only the format you need (e.g. `@silurus/ooxml/pptx`). The math engine is a **separate entry** (`@silurus/ooxml/math`): it is bundled **only if you import it and pass it to a viewer** (see [Rendering equations](#rendering-equations)). Viewers that never receive a `math` engine — and all xlsx usage — tree-shake the ~3 MB away entirely.
33
+ > **Bundle size note**: the package is ESM-only (`.mjs`). npm's *Unpacked Size* sums all four entry bundles, including the **opt-in** math engine (MathJax + STIX Two Math, ~3 MB). What actually lands in your app is much smaller — import only the format you need (e.g. `@silurus/ooxml/pptx`). The math engine is a **separate entry** (`@silurus/ooxml/math`): it is bundled **only if you import it and pass it to a viewer** (see [Rendering equations](#rendering-equations)). Viewers that never receive a `math` engine tree-shake the ~3 MB away entirely.
34
34
 
35
35
  ---
36
36
 
@@ -78,9 +78,12 @@ const docx = new DocxViewer(canvas, { math }); // ← equations now render
78
78
  await docx.load('/paper-with-equations.docx');
79
79
  ```
80
80
 
81
- The same `math` engine works for `PptxViewer` and the headless `DocxDocument` /
82
- `PptxPresentation` APIs (which take `math` in their options). xlsx has no equation
83
- support and never references the engine.
81
+ The same `math` engine works for `PptxViewer`, `XlsxViewer`, and the headless
82
+ `DocxDocument` / `PptxPresentation` APIs (which take `math` in their options).
83
+ Excel stores "Insert > Equation" as OMML inside the shared DrawingML `<xdr:txBody>`
84
+ grammar, so `XlsxViewer` renders equations embedded in shapes / text boxes the same
85
+ way — pass `math` and they render; omit it and those equations are skipped and the
86
+ engine is tree-shaken away.
84
87
 
85
88
  ---
86
89
 
@@ -446,6 +449,7 @@ export const PptxViewerComponent = component$<{ src: string }>(({ src }) => {
446
449
  | | Hidden rows / columns | ✅ |
447
450
  | **Elements** | Images (`<xdr:twoCellAnchor>`) | ✅ |
448
451
  | | Drawing shapes / text boxes (`xdr:sp`, `xdr:txBody`) | ✅ |
452
+ | | Math equations in shapes (OMML `m:oMath` / `m:oMathPara` in `xdr:txBody`, incl. `a14:m` / `mc:AlternateContent`; rendered via MathJax — opt-in `@silurus/ooxml/math`) | ✅ |
449
453
  | | Charts (bar, line, area, radar, scatter / bubble) | ✅ |
450
454
  | | Chart markers (circle / square / diamond / triangle / x / plus / star / dot / dash, per-point `<c:dPt>` overrides) | ✅ |
451
455
  | | Chart data labels (`<c:dLbl>` per-point with CELLRANGE / VALUE / SERIESNAME / CATEGORYNAME field references, position `l`/`r`/`t`/`b`/`ctr`/`outEnd`) | ✅ |
@@ -0,0 +1,228 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.defineProperty, t = (t, n) => {
3
+ let r = {};
4
+ for (var i in t) e(r, i, {
5
+ get: t[i],
6
+ enumerable: !0
7
+ });
8
+ return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ }, n = 3e3, r = 20, i = 25;
10
+ async function a(e, t) {
11
+ if (typeof document > "u") return;
12
+ let a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
13
+ for (let n of e) {
14
+ if (!n) continue;
15
+ let e = n.toLowerCase();
16
+ if (a.has(e)) continue;
17
+ a.add(e);
18
+ let r = t[e];
19
+ if (r) {
20
+ if (!document.querySelector(`link[href="${r.url}"]`)) try {
21
+ let e = document.createElement("link");
22
+ e.rel = "stylesheet", e.href = r.url, document.head.appendChild(e);
23
+ } catch {}
24
+ o.add((r.loadFamily ?? n).toLowerCase());
25
+ }
26
+ }
27
+ if (o.size === 0) return;
28
+ let s = [];
29
+ for (let e = 0; e < i && (s = [...document.fonts].filter((e) => o.has(e.family.toLowerCase())), !(s.length > 0)); e++) await new Promise((e) => setTimeout(e, r));
30
+ await Promise.race([Promise.allSettled(s.map((e) => e.load())).then(() => document.fonts.ready), new Promise((e) => setTimeout(e, n))]);
31
+ }
32
+ //#endregion
33
+ //#region packages/core/src/units.ts
34
+ var o = 12700, s = 9525, c = 4 / 3;
35
+ //#endregion
36
+ //#region packages/core/src/autoResize.ts
37
+ function l(e, t, n = {}) {
38
+ let r = n.pauseWhenHidden ?? !0, i = null, a = 0, o = 0, s = null, c = !1, l = !1, u = () => {
39
+ if (!l && !(r && typeof document < "u" && document.hidden)) {
40
+ if (s) {
41
+ c = !0;
42
+ return;
43
+ }
44
+ i === null && (i = requestAnimationFrame(d));
45
+ }
46
+ }, d = async () => {
47
+ if (i = null, l) return;
48
+ let t = a, n = o;
49
+ try {
50
+ let r = e(t, n);
51
+ s = r instanceof Promise ? r : Promise.resolve(), await s;
52
+ } catch (e) {
53
+ console.error("[autoResize] render failed:", e);
54
+ } finally {
55
+ s = null, c && !l && (c = !1, u());
56
+ }
57
+ }, f = new ResizeObserver((e) => {
58
+ for (let t of e) {
59
+ let e = t.contentRect;
60
+ a = e.width, o = e.height;
61
+ }
62
+ u();
63
+ });
64
+ f.observe(t);
65
+ let p = () => {
66
+ typeof document < "u" && !document.hidden && u();
67
+ };
68
+ return r && typeof document < "u" && document.addEventListener("visibilitychange", p), () => {
69
+ l = !0, f.disconnect(), i !== null && (cancelAnimationFrame(i), i = null), r && typeof document < "u" && document.removeEventListener("visibilitychange", p);
70
+ };
71
+ }
72
+ //#endregion
73
+ //#region packages/core/src/math/mathml.ts
74
+ var u = {
75
+ "&": "&amp;",
76
+ "<": "&lt;",
77
+ ">": "&gt;",
78
+ "\"": "&quot;"
79
+ }, d = (e) => e.replace(/[&<>"]/g, (e) => u[e]);
80
+ function f(e) {
81
+ switch (e) {
82
+ case "roman": return "normal";
83
+ case "bold": return "bold";
84
+ case "boldItalic": return "bold-italic";
85
+ case "italic": return null;
86
+ }
87
+ }
88
+ var p = new Set([..."⏞⏟⎴⎵︷︸⏜⏝{}[]()¯_‾"]), m = "+−±∓×÷·∗⋅∘∙*/", h = "=≠<>≤≥≈≡∼≅≃→←↔⇒∈∉⊂⊆⊃⊇∝≪≫⊥≔", g = "([{⟨⌈⌊", _ = ")]}⟩⌉⌋", v = ",;";
89
+ function y(e, t) {
90
+ let n = f(t), r = n ? ` mathvariant="${n}"` : "", i = "", a = "", o = () => {
91
+ a &&= (i += `<mn${r}>${d(a)}</mn>`, "");
92
+ };
93
+ for (let t of e) {
94
+ if (t === " ") {
95
+ o();
96
+ continue;
97
+ }
98
+ if (t >= "0" && t <= "9") {
99
+ a += t;
100
+ continue;
101
+ }
102
+ o(), m.includes(t) || h.includes(t) || v.includes(t) ? i += `<mo>${d(t)}</mo>` : g.includes(t) || _.includes(t) ? i += `<mo fence="true" stretchy="false">${d(t)}</mo>` : i += `<mi${r}>${d(t)}</mi>`;
103
+ }
104
+ return o(), i;
105
+ }
106
+ function b(e) {
107
+ return e.map(S).join("");
108
+ }
109
+ function x(e) {
110
+ return `<mrow>${b(e)}</mrow>`;
111
+ }
112
+ function S(e) {
113
+ switch (e.kind) {
114
+ case "run": return y(e.text, e.style);
115
+ case "group": return x(e.items);
116
+ case "fraction": return `<mfrac${e.bar === !1 ? " linethickness=\"0\"" : ""}>${x(e.num)}${x(e.den)}</mfrac>`;
117
+ case "sup": return `<msup>${x(e.base)}${x(e.sup ?? [])}</msup>`;
118
+ case "sub": return `<msub>${x(e.base)}${x(e.sub ?? [])}</msub>`;
119
+ case "subSup": return `<msubsup>${x(e.base)}${x(e.sub ?? [])}${x(e.sup ?? [])}</msubsup>`;
120
+ case "nary": return k(e);
121
+ case "delimiter": return A(e);
122
+ case "radical": return e.index && e.index.length ? `<mroot>${x(e.radicand)}${x(e.index)}</mroot>` : `<msqrt>${b(e.radicand)}</msqrt>`;
123
+ case "limit": return E(e);
124
+ case "array": return D(e);
125
+ case "groupChr": {
126
+ let t = x(e.base), n = p.has(e.char), r = e.pos === "top" ? "mover" : "munder", i = `<mo stretchy="${n}">${d(e.char)}</mo>`;
127
+ return n ? `<${r}>${t}${i}</${r}>` : `<${r} accent="true">${t}${i}</${r}>`;
128
+ }
129
+ case "bar": {
130
+ let t = x(e.base), n = "<mo stretchy=\"true\">&#x2015;</mo>";
131
+ return e.pos === "bot" ? `<munder>${t}${n}</munder>` : `<mover>${t}${n}</mover>`;
132
+ }
133
+ case "accent": return T(e);
134
+ case "func": return `<mrow>${x(e.name)}<mo>&#x2061;</mo>${x(e.arg)}</mrow>`;
135
+ }
136
+ }
137
+ var C = {
138
+ "̀": "`",
139
+ "́": "´",
140
+ "̂": "^",
141
+ "̃": "~",
142
+ "̆": "˘",
143
+ "̇": "˙",
144
+ "̈": "¨",
145
+ "̌": "ˇ",
146
+ "⃗": "→",
147
+ "⃖": "←"
148
+ }, w = new Set([
149
+ "̅",
150
+ "̄",
151
+ "¯",
152
+ "‾",
153
+ "̲",
154
+ "̳"
155
+ ]);
156
+ function T(e) {
157
+ let t = x(e.base);
158
+ if (w.has(e.char)) return `<mover>${t}<mo stretchy="true">&#x2015;</mo></mover>`;
159
+ let n = C[e.char] ?? e.char;
160
+ return `<mover accent="true">${t}<mo stretchy="${n === "→" || n === "←" ? "true" : "false"}">${d(n)}</mo></mover>`;
161
+ }
162
+ function E(e) {
163
+ let t = x(e.base), n = e.lower && e.lower.length ? x(e.lower) : null, r = e.upper && e.upper.length ? x(e.upper) : null;
164
+ return n && r ? `<munderover>${t}${n}${r}</munderover>` : n ? `<munder>${t}${n}</munder>` : r ? `<mover>${t}${r}</mover>` : t;
165
+ }
166
+ function D(e) {
167
+ let t = Math.max(1, ...e.rows.map((e) => e.length)), n;
168
+ n = e.align === "eq" ? Array.from({ length: t }, (e, t) => t % 2 == 0 ? "right" : "left").join(" ") : e.align === "left" ? "left" : "center";
169
+ let r = e.rows.map((e) => `<mtr>${e.map((e) => `<mtd>${b(e)}</mtd>`).join("")}</mtr>`).join("");
170
+ return `<mtable columnalign="${n}" rowspacing="0.2em" columnspacing="0.3em">${r}</mtable>`;
171
+ }
172
+ var O = new Set([..."∫∬∭∮∯∰∱∲∳⨌⨍⨎⨏⨐⨑⨒⨓⨔⨕⨖⨗"]);
173
+ function k(e) {
174
+ let t = e.limLoc === "subSup" ? !0 : e.limLoc === "undOvr" ? !1 : O.has(e.op), n = `<mo largeop="true">${d(e.op)}</mo>`, r = e.sub ?? [], i = e.sup ?? [], a;
175
+ return a = t ? r.length && i.length ? `<msubsup>${n}${x(r)}${x(i)}</msubsup>` : r.length ? `<msub>${n}${x(r)}</msub>` : i.length ? `<msup>${n}${x(i)}</msup>` : n : r.length && i.length ? `<munderover>${n}${x(r)}${x(i)}</munderover>` : r.length ? `<munder>${n}${x(r)}</munder>` : i.length ? `<mover>${n}${x(i)}</mover>` : n, `<mrow>${a}${b(e.body)}</mrow>`;
176
+ }
177
+ function A(e) {
178
+ let t = (e) => `<mo fence="true" stretchy="true">${d(e)}</mo>`, n = e.items.map((e) => x(e)).join("<mo separator=\"true\">,</mo>");
179
+ return `<mrow>${t(e.begChar)}${n}${t(e.endChar)}</mrow>`;
180
+ }
181
+ function j(e, t) {
182
+ return `<math xmlns="http://www.w3.org/1998/Math/MathML" display="${t ? "block" : "inline"}">${b(e)}</math>`;
183
+ }
184
+ //#endregion
185
+ //#region packages/core/src/worker/bridge.ts
186
+ var M = class {
187
+ _worker;
188
+ _opts;
189
+ _pending = /* @__PURE__ */ new Map();
190
+ _nextId = 1;
191
+ constructor(e, t) {
192
+ this._worker = e, this._opts = t, this._worker.addEventListener("message", this._handle);
193
+ }
194
+ _handle = (e) => {
195
+ let t = e.data, n = this._opts.correlate(t);
196
+ if (n === void 0) {
197
+ this._opts.onUnsolicited?.(t);
198
+ return;
199
+ }
200
+ let r = this._pending.get(n);
201
+ if (!r) return;
202
+ this._pending.delete(n);
203
+ let i = this._opts.toError?.(t);
204
+ i === void 0 ? r.resolve(t) : r.reject(Error(i));
205
+ };
206
+ nextId() {
207
+ return this._nextId++;
208
+ }
209
+ request(e, t) {
210
+ let n = this._nextId++;
211
+ return new Promise((r, i) => {
212
+ this._pending.set(n, {
213
+ resolve: r,
214
+ reject: i
215
+ }), this._worker.postMessage(e(n), t);
216
+ });
217
+ }
218
+ post(e, t) {
219
+ this._worker.postMessage(e, t);
220
+ }
221
+ terminate() {
222
+ this._worker.removeEventListener("message", this._handle), this._worker.terminate();
223
+ for (let e of this._pending.values()) e.reject(/* @__PURE__ */ Error("Worker terminated"));
224
+ this._pending.clear();
225
+ }
226
+ };
227
+ //#endregion
228
+ export { s as a, t as c, o as i, j as n, c as o, l as r, a as s, M as t };