rapier-math 2.2.0 → 2.3.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.
@@ -101,14 +101,20 @@ coordinates if present. Missing italic corrections are zero; missing accent atta
101
101
  Assembly parts retain the OpenType order: bottom to top vertically, left to right horizontally. Latin Modern has
102
102
  no MATH Device adjustments. Hint programs and general text shaping tables are not used by the SVG renderer.
103
103
 
104
- Contour profiles cover 1,187 ASCII alphanumeric, mathematical italic and script glyphs, including optical and
105
- dotless forms. Entry `i + 1` bounds the original contour within `[y0 + i * edgeStep, y0 + (i + 1) * edgeStep]`;
104
+ Contour profiles cover 1,190 ASCII alphanumeric, mathematical italic and script glyphs, with U+210E (the
105
+ italic h) and the optical and dotless forms. Entry `i + 1` bounds the original contour within `[y0 + i * edgeStep, y0 + (i + 1) * edgeStep]`;
106
106
  `null` means no ink. Cubic intersections and horizontal extrema determine the bounds. Values round outward
107
107
  with a small numerical guard. Profiles are derived spacing data; they do not replace outlines or pretend to be
108
108
  an original MATH kern table. Layout compares intersecting strips from both glyphs when placing scripts.
109
109
 
110
- Character mappings, optical substitutions and record offsets occupy a compact index decoded at module load.
111
- Glyph metrics, outlines and contour profiles stay in independent raw DEFLATE pages until requested. Every page
110
+ The asset stores neither bounds nor profiles. The decoder derives both from the outline: bounds with the
111
+ arithmetic of fontTools' `BoundsPen`, profiles with the strip algorithm above, operation for operation in
112
+ IEEE double precision. For this font every derived bound and profile equals the value the 2.2.0 asset stored
113
+ (2.2.0 had no profile for U+210E and its two optical forms).
114
+
115
+ Character mappings, optical substitutions, stretch constructions, the profiled glyph set and record offsets
116
+ occupy a compact index decoded at module load. Glyph metrics and outlines stay in independent raw DEFLATE pages
117
+ until requested. Every page
112
118
  ends at a record boundary and contains at most 16,384 decoded bytes. The complete set of pages travels in the
113
119
  same asset; rare characters, stretch parts and optical forms require no additional download.
114
120
 
@@ -118,19 +124,19 @@ exact differences from an earlier contour with the same structure. Parent chains
118
124
  The generator prefers small coordinate differences as well as short records, because the smallest initial
119
125
  record does not necessarily produce the smallest compressed page. Glyph assembly restores the original
120
126
  absolute `M/L/H/V/C/Z` paths, including contour order; existing outline-part consumers use those commands.
127
+ A contour whose closing curve ends at its start omits that end point; the decoder returns the curve to the start.
121
128
 
122
- Glyph metrics use reversible bearing and half-advance predictors with a median origin per metric field.
123
- They retain the complete original bounds, advance, italic and accent measurements. Signed record integers
129
+ Glyph metrics use a reversible half-advance accent predictor with a median origin per metric field.
130
+ They retain the complete original advance, italic and accent measurements. Signed record integers
124
131
  use zigzag values: values below 240 take one byte, the next 3,840 values take two bytes, and larger values use
125
132
  an escape followed by unsigned LEB128. The coordinate unit is exact; this encoding performs no quantization.
126
133
 
127
- Profiles retain the original left/right strip coordinates and exact differences from matching strip structures.
128
- Identical arrays share storage: all 1,187 glyph-to-profile mappings are represented by 1,080 unique records.
129
134
  The renderer only asks for profiles when side-script placement can use them.
130
135
 
131
- The font owns three bounded least-recently-used caches: eight inflated pages, 256 completed glyph records and
132
- 128 contour profiles. Temporary parent coordinates and page views are discarded after a glyph is assembled;
133
- cached glyphs contain the completed path and metrics. Reusing an evicted record reconstructs the same data.
136
+ Each inflated page, completed glyph record and contour profile stays for the life of the module, so the font
137
+ itself bounds these caches: the pages inflate to about 520 KB. Temporary parent coordinates and page views are
138
+ discarded after a glyph is assembled; cached glyphs keep the completed path and metrics, and profiled glyphs
139
+ also keep the outline segments their profile is derived from.
134
140
  These caches contain font data only. They retain no formula source, parse tree, layout result, SVG element or
135
141
  document. Returned internal records are read-only to consumers.
136
142
 
@@ -2,10 +2,10 @@
2
2
  "spdxVersion": "SPDX-2.3",
3
3
  "dataLicense": "CC0-1.0",
4
4
  "SPDXID": "SPDXRef-DOCUMENT",
5
- "name": "rapier-math-2.2.0",
6
- "documentNamespace": "https://rapier.website/spdx/rapier-math-2.2.0-2f4a4e405d0a7452d5ffbad2fae9da7ea2d3fcb18d6c662cd4d3823648b0e904",
5
+ "name": "rapier-math-2.3.0",
6
+ "documentNamespace": "https://rapier.website/spdx/rapier-math-2.3.0-f5df4637eb2c6fffe325f1f6e9c12132aa4f7741abd24c789fc7ac30c8cf499f",
7
7
  "creationInfo": {
8
- "created": "2026-10-14T16:53:42.535Z",
8
+ "created": "2026-10-15T04:22:09.842Z",
9
9
  "creators": [
10
10
  "Tool: rapier-math-components",
11
11
  "Organization: rapier.website"
@@ -15,17 +15,17 @@
15
15
  {
16
16
  "name": "rapier-math",
17
17
  "SPDXID": "SPDXRef-rapier-math",
18
- "versionInfo": "2.2.0",
18
+ "versionInfo": "2.3.0",
19
19
  "downloadLocation": "NOASSERTION",
20
20
  "filesAnalyzed": false,
21
21
  "licenseConcluded": "MIT AND LicenseRef-GUST-Font-License",
22
22
  "licenseDeclared": "MIT AND LicenseRef-GUST-Font-License",
23
23
  "copyrightText": "NOASSERTION",
24
- "sourceInfo": "Verified current build inputs: math-resources.json (SHA-256 cb1a80638a11b2a561cb43f0bc5cd787bb492f532ffa41ca01fbe8fe5e887cca).",
24
+ "sourceInfo": "Verified current build inputs: math-resources.json (SHA-256 43190d50be5b14a16f69f889041617766b62eab41b88be177aa3e2b388dc1f94).",
25
25
  "checksums": [
26
26
  {
27
27
  "algorithm": "SHA256",
28
- "checksumValue": "2f4a4e405d0a7452d5ffbad2fae9da7ea2d3fcb18d6c662cd4d3823648b0e904"
28
+ "checksumValue": "f5df4637eb2c6fffe325f1f6e9c12132aa4f7741abd24c789fc7ac30c8cf499f"
29
29
  }
30
30
  ]
31
31
  },
@@ -1,30 +1,30 @@
1
1
  {
2
- "bundle": "rapier-math-2.2.0.js",
2
+ "bundle": "rapier-math-2.3.0.js",
3
3
  "packageBundle": "dist/rapier-math.js",
4
- "version": "2.2.0",
4
+ "version": "2.3.0",
5
5
  "license": "MIT AND LicenseRef-GUST-Font-License",
6
- "bytes": 749536,
7
- "gzipBytes": 453279,
8
- "sha256": "2f4a4e405d0a7452d5ffbad2fae9da7ea2d3fcb18d6c662cd4d3823648b0e904",
9
- "sha384": "pzYte7azbAoS8XSwIKjFg7mxGOxAxBKo9/IUy07H4j0WoyguAS/zwkR1O6kDXq9S",
6
+ "bytes": 673393,
7
+ "gzipBytes": 399554,
8
+ "sha256": "f5df4637eb2c6fffe325f1f6e9c12132aa4f7741abd24c789fc7ac30c8cf499f",
9
+ "sha384": "ie925auPTOH6Zh27w4EowUzc61aeLAYB+3hxZS59bBrEZ21joUXxNWEPR+GBvVn1",
10
10
  "sources": [
11
11
  {
12
12
  "file": "math/font.js",
13
13
  "packageFile": "src/math/font.js",
14
- "bytes": 558741,
15
- "sha256": "ca92701353de9b79527e133d1b44931dedf2a5e647561d4b80626d86f74e7e8b"
14
+ "bytes": 465845,
15
+ "sha256": "d10ac2bcef6e624c4b052602efbbd70c8c69bd40b7e2c5096526291fcae4f60b"
16
16
  },
17
17
  {
18
18
  "file": "math/symbols.js",
19
19
  "packageFile": "src/math/symbols.js",
20
- "bytes": 8576,
21
- "sha256": "9a2cabd351b346f626a907a9475c8bb94beabcbde757fe342421bff487aa75f9"
20
+ "bytes": 9305,
21
+ "sha256": "b48853a637d57697b58dfec4f728e9d67ca9fa041b5a0ccdb4d513d0dc4b4137"
22
22
  },
23
23
  {
24
24
  "file": "math/parser.js",
25
25
  "packageFile": "src/math/parser.js",
26
- "bytes": 70821,
27
- "sha256": "fa07f68b3a158615748a352836ff1f9cb118d4b93490b573778734e6699ec037"
26
+ "bytes": 84418,
27
+ "sha256": "3b7ccf2c7f32fba45a70408939e4c7d5bf18ee5ee9f3f3109b101e81985d5050"
28
28
  },
29
29
  {
30
30
  "file": "math/source.js",
@@ -41,8 +41,8 @@
41
41
  {
42
42
  "file": "math/layout.js",
43
43
  "packageFile": "src/math/layout.js",
44
- "bytes": 39098,
45
- "sha256": "94f476f60abe2e4d37a2e51923f3f5968d7edf18defe0fc3e8de13092214549d"
44
+ "bytes": 40185,
45
+ "sha256": "c1425c843f3684e24a530a0bdfbeec65626cd6c41893abc395cc5766e38815c0"
46
46
  },
47
47
  {
48
48
  "file": "math/fallbacks.js",
@@ -53,8 +53,8 @@
53
53
  {
54
54
  "file": "math/responsive.js",
55
55
  "packageFile": "src/math/responsive.js",
56
- "bytes": 13839,
57
- "sha256": "d0cff2fd9a520d30b75b1d49074d93d2500c5f32ca6aaa30239498fe6d860e07"
56
+ "bytes": 14156,
57
+ "sha256": "ee1bc05c23be50380c59eed5f9a51057464991695c030563fca8d64d2230d3ec"
58
58
  },
59
59
  {
60
60
  "file": "math/api.js",
@@ -65,14 +65,14 @@
65
65
  {
66
66
  "file": "math/browser.js",
67
67
  "packageFile": "src/math/browser.js",
68
- "bytes": 10172,
69
- "sha256": "c56a36031169a40bbcbaa6be2b197945b5819ca0446392ae2142255ad2a5baa6"
68
+ "bytes": 10946,
69
+ "sha256": "3c163cbe795a6be2781295b10fc41bd8e94248c3bbee521abff43d03fbefbc5d"
70
70
  },
71
71
  {
72
72
  "file": "math/mathml.js",
73
73
  "packageFile": "src/math/mathml.js",
74
- "bytes": 29247,
75
- "sha256": "e97d9c77d9ca7aabc81b89160c6e8de00ca9905b1a2e5808d1674632603fbd79"
74
+ "bytes": 29496,
75
+ "sha256": "f91054b5cabbb32bce79eea6d60f91a3a513a1613ef587d08a86086a983859a5"
76
76
  },
77
77
  {
78
78
  "file": "math/semantic-api.js",
@@ -90,21 +90,21 @@
90
90
  "file": "math/classic.js",
91
91
  "packageFile": "src/math/classic.js",
92
92
  "bytes": 269,
93
- "sha256": "49ae3b9d1f332f77ca559ee371578ad9c04799e831460dd88f6ff757cee0583b"
93
+ "sha256": "e42b812cf9772909c9178b15a85ac300c5e35ae6f56d66261f24654916442c74"
94
94
  }
95
95
  ],
96
96
  "recipe": [
97
97
  {
98
98
  "file": "math/build-font.py",
99
99
  "packageFile": "src/math/build-font.py",
100
- "bytes": 33369,
101
- "sha256": "d54dba7b83d945da4bdeeac6a262c45d0b8f531c0801114451ac3f3d8dab9d35"
100
+ "bytes": 32576,
101
+ "sha256": "98599660cf23e0ee5e38d35732ff353f634c2d4ce641072b0834089533d94836"
102
102
  },
103
103
  {
104
104
  "file": "math/FONT-SOURCE.md",
105
105
  "packageFile": "docs/font-source.md",
106
- "bytes": 10357,
107
- "sha256": "84ab319b1f9342fa08b421231965dd685063d8fd6bb8a071e1f1c186848dcdd9"
106
+ "bytes": 10739,
107
+ "sha256": "621db58ca1b5fcacb450e8f74dfabc533d6856544cf2abb6333a637636d1e0c9"
108
108
  },
109
109
  {
110
110
  "file": "math/FONT-LICENSE.txt",
@@ -122,7 +122,7 @@
122
122
  "file": "tools/build-math.mjs",
123
123
  "packageFile": "src/tools/build-math.mjs",
124
124
  "bytes": 9577,
125
- "sha256": "680b437b190ff02d703880a44b463ed522dda9f732b70959ec4e4d7f45a28051"
125
+ "sha256": "442a21aa7c113f93aa706d52a352cb54cbbf2dac33e68e54bd47dafa6f2830e0"
126
126
  },
127
127
  {
128
128
  "file": "math/LICENSE-MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-math",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Self-contained offline LaTeX-to-SVG rendering with Latin Modern outlines, optional Markdown integrations and streaming helpers.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -42,9 +42,10 @@ function mathSnapRule(original, matrix, ratio) {
42
42
  'v' + mathNumber(height) + 'h' + mathNumber(-width) + 'Z'};
43
43
  }
44
44
 
45
- function mathSnapRules(svg) {
46
- const ratio=svg.ownerDocument.defaultView.devicePixelRatio || 1;
47
- for(const rule of svg.querySelectorAll('[data-math-rule],[data-math-line]')) {
45
+ // Every rule is measured before any is rewritten, so the browser lays the page out once, not once per formula.
46
+ function mathSnapRules(svgs) {
47
+ const measured=[];
48
+ for(const svg of svgs)for(const rule of svg.querySelectorAll('[data-math-rule],[data-math-line]')) {
48
49
  let original=mathRuleOriginals.get(rule);
49
50
  if(!original) {
50
51
  const box=rule.getBBox(), axis=rule.getAttribute('data-math-line'), thickness=Number(rule.getAttribute('stroke-width'));
@@ -53,7 +54,10 @@ function mathSnapRules(svg) {
53
54
  if(axis==='vertical') {original.x-=thickness/2;original.width=thickness;}
54
55
  mathRuleOriginals.set(rule,original);
55
56
  }
56
- const snapped=mathSnapRule(original,rule.getScreenCTM(),ratio);
57
+ measured.push([rule,original,rule.getScreenCTM(),svg.ownerDocument.defaultView.devicePixelRatio || 1]);
58
+ }
59
+ for(const [rule,original,matrix,ratio] of measured) {
60
+ const snapped=mathSnapRule(original,matrix,ratio);
57
61
  if(!snapped)continue;
58
62
  let path=snapped.d;
59
63
  if(original.axis==='horizontal') {
@@ -69,13 +73,18 @@ function mathSnapRules(svg) {
69
73
  }
70
74
  }
71
75
 
72
- function mathFitElement(svg, printing = false) {
76
+ // Reads only: the column, font and paper of one formula.
77
+ function mathFitMeasure(svg, printing) {
73
78
  if(!svg.isConnected)return null;
74
- const doc=svg.ownerDocument,view=doc.defaultView,column=mathColumn(svg),style=view.getComputedStyle(column),font=parseFloat(view.getComputedStyle(svg).fontSize);
79
+ const view=svg.ownerDocument.defaultView,column=mathColumn(svg),style=view.getComputedStyle(column),font=parseFloat(view.getComputedStyle(svg).fontSize);
75
80
  const available=column.clientWidth-(parseFloat(style.paddingLeft) || 0)-(parseFloat(style.paddingRight) || 0);
76
- if(!(available>0 && font>0))return column;
77
- const width=Math.max(.1,(available-.25)/font),source=svg.getAttribute('aria-label'),display=svg.getAttribute('data-rapier-math')==='display';
78
- const dark=!printing && mathDarkPaper(svg),ratio=view.devicePixelRatio || 1;
81
+ if(!(available>0 && font>0))return {column};
82
+ return {svg,column,font,width:Math.max(.1,(available-.25)/font),dark:!printing && mathDarkPaper(svg),ratio:view.devicePixelRatio || 1};
83
+ }
84
+
85
+ // Writes only: re-render and restyle one measured formula.
86
+ function mathFitApply({svg,font,width,dark,ratio}, printing) {
87
+ const doc=svg.ownerDocument,view=doc.defaultView,source=svg.getAttribute('aria-label'),display=svg.getAttribute('data-rapier-math')==='display';
79
88
  const screen=printing?undefined:{fontSize:font/mathFontRatio,pixelRatio:ratio,dark};
80
89
  const screenKey=printing?'':mathNumber(font)+'|'+mathNumber(ratio)+'|'+dark;
81
90
  let state=mathBrowserStates.get(svg);
@@ -112,13 +121,19 @@ function mathFitElement(svg, printing = false) {
112
121
  node.setAttribute('fill-opacity','1');node.setAttribute('stroke-opacity','1');
113
122
  }
114
123
  }
115
- if(!printing)mathSnapRules(svg);
116
- return column;
124
+ }
125
+
126
+ // All formulas are measured, then all rewritten, then all rules snapped: three layouts for any number of formulas.
127
+ function mathFitElements(svgs, printing) {
128
+ const measured=svgs.map(svg=>mathFitMeasure(svg,printing)).filter(Boolean),fitted=measured.filter(item=>item.svg);
129
+ for(const item of fitted)mathFitApply(item,printing);
130
+ if(!printing)mathSnapRules(fitted.map(item=>item.svg));
131
+ return measured.map(item=>item.column);
117
132
  }
118
133
 
119
134
  function mathFit(root) {
120
135
  const nodes=mathElements(root);
121
- for(const svg of nodes)mathFitElement(svg,svg.ownerDocument.defaultView.matchMedia('print').matches);
136
+ if(nodes.length)mathFitElements(nodes,nodes[0].ownerDocument.defaultView.matchMedia('print').matches);
122
137
  return nodes.length;
123
138
  }
124
139
 
@@ -129,11 +144,7 @@ function mathObserveDocument(doc) {
129
144
  if(!active)return;
130
145
  if(frame!==null)view.cancelAnimationFrame(frame);
131
146
  frame=null;
132
- const wanted=new Set();
133
- for(const svg of nodes.keys()) {
134
- if(!svg.isConnected || svg.ownerDocument!==doc || !svg.matches(mathSvgSelector))continue;
135
- const column=mathFitElement(svg,printing);if(column)wanted.add(column);
136
- }
147
+ const wanted=new Set(mathFitElements([...nodes.keys()].filter(svg=>svg.isConnected && svg.ownerDocument===doc && svg.matches(mathSvgSelector)),printing));
137
148
  for(const column of columns)if(!wanted.has(column)) {resize.unobserve(column);columns.delete(column);}
138
149
  for(const column of wanted)if(!columns.has(column)) {resize.observe(column);columns.add(column);}
139
150
  };