xmmath 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmmath",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "main": "./dist/xmmath.umd.js",
6
6
  "module": "./dist/xmmath.es.js",
package/src/main.ts CHANGED
@@ -57,6 +57,21 @@ function limits_active(base: tree) {
57
57
  return !!is_limit(t);
58
58
  }
59
59
 
60
+ // 在 fn() 期间把全局 display 标志换成 d(渲染完恢复),供 display/inline/
61
+ // script/sscript 这类局部样式使用;is_limit 读这个标志,故嵌套子树
62
+ // (lr/abs/mat/attach 的底座…)自动继承局部模式。注意 x_table 的行对齐也
63
+ // 读它 —— 嵌套多行的对齐是否该跟着局部模式走,官方图未逐例核过,先不动,
64
+ // 见 test/custom.test.ts 里的说明。
65
+ function with_display(d: boolean, fn: () => VEl | VFragment) {
66
+ const prev = isDisplay();
67
+ setDisplay(d);
68
+ try {
69
+ return fn();
70
+ } finally {
71
+ setDisplay(prev);
72
+ }
73
+ }
74
+
60
75
  function delim(dic: fdic, _default: string) {
61
76
  const d = get_value(dic, "delim") as string;
62
77
  let x = "";
@@ -302,35 +317,44 @@ const f: {
302
317
  s.append(render(attr[0], e));
303
318
  return s;
304
319
  },
305
- display: (attr: tree[], _dic: fdic, e) => {
306
- const m = createMath("mrow", null, { displaystyle: "true" });
307
- m.append(render(attr[0], e));
308
- return m;
309
- },
310
- inline: (attr: tree[], _dic: fdic, e) => {
311
- const m = createMath("mrow", null, {
312
- displaystyle: "false",
313
- scriptlevel: "0",
314
- });
315
- m.append(render(attr[0], e));
316
- return m;
317
- },
318
- script: (attr: tree[], _dic: fdic, e) => {
319
- const m = createMath("mrow", null, {
320
- displaystyle: "false",
321
- scriptlevel: "1",
322
- });
323
- m.append(render(attr[0], e));
324
- return m;
325
- },
326
- sscript: (attr: tree[], _dic: fdic, e) => {
327
- const m = createMath("mrow", null, {
328
- displaystyle: "false",
329
- scriptlevel: "2",
330
- });
331
- m.append(render(attr[0], e));
332
- return m;
333
- },
320
+ // display/inline/script/sscript 是局部样式(typst 的样式栈:内层覆盖外层,
321
+ // `display(script(sum_1^2))` 仍走角标)。limits 的判定在 ast3 的「处理^_」
322
+ // 里读全局 display 标志,故在渲染子树期间改写它、渲染完恢复;wrapper 用
323
+ // mstyle 而不是 mrow —— MathML Core 里 displaystyle/scriptlevel 是 mstyle
324
+ // 的属性,挂在 mrow 上浏览器会忽略(∑ 大小/脚标层级都随之失真)。
325
+ display: (attr: tree[], _dic: fdic, e) =>
326
+ with_display(true, () => {
327
+ const m = createMath("mstyle", null, { displaystyle: "true" });
328
+ m.append(render(attr[0], e));
329
+ return m;
330
+ }),
331
+ inline: (attr: tree[], _dic: fdic, e) =>
332
+ with_display(false, () => {
333
+ const m = createMath("mstyle", null, {
334
+ displaystyle: "false",
335
+ scriptlevel: "0",
336
+ });
337
+ m.append(render(attr[0], e));
338
+ return m;
339
+ }),
340
+ script: (attr: tree[], _dic: fdic, e) =>
341
+ with_display(false, () => {
342
+ const m = createMath("mstyle", null, {
343
+ displaystyle: "false",
344
+ scriptlevel: "1",
345
+ });
346
+ m.append(render(attr[0], e));
347
+ return m;
348
+ }),
349
+ sscript: (attr: tree[], _dic: fdic, e) =>
350
+ with_display(false, () => {
351
+ const m = createMath("mstyle", null, {
352
+ displaystyle: "false",
353
+ scriptlevel: "2",
354
+ });
355
+ m.append(render(attr[0], e));
356
+ return m;
357
+ }),
334
358
  upright: (attr: tree[], _dic: fdic, e) => {
335
359
  const r = createMath("mrow");
336
360
  r.append(render(attr[0], e));