rapier-math 1.1.0 → 1.1.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.
Files changed (61) hide show
  1. package/README.md +23 -195
  2. package/{index.mjs → dist/index.mjs} +1 -1
  3. package/{rapier-math-1.1.0.js → dist/rapier-math.js} +1 -1
  4. package/{src/math/README.md → docs/api.md} +9 -9
  5. package/{math-components.json → docs/math-components.json} +6 -6
  6. package/{src/shell → docs}/math-resources.json +62 -36
  7. package/examples/browser.mjs +1 -1
  8. package/examples/worker.mjs +1 -1
  9. package/package.json +31 -55
  10. package/src/math/api.js +1 -1
  11. package/src/math/package-build.mjs +0 -13
  12. package/src/math/package-layout.mjs +17 -0
  13. package/src/math/package-readme.mjs +42 -5
  14. package/src/tools/build-math.mjs +36 -17
  15. package/{src/math/adoption-verify.mjs → tests/adoption.mjs} +1 -1
  16. package/{check.mjs → tests/check.mjs} +8 -8
  17. package/tests/verify.mjs +46 -0
  18. package/LICENSE-MIT +0 -21
  19. package/adoption-check.mjs +0 -149
  20. package/math-LICENSE.txt +0 -21
  21. package/math-font-LICENSE.txt +0 -457
  22. package/src/math/classic.d.ts +0 -4
  23. package/src/math/delimiters.d.ts +0 -8
  24. package/src/math/delimiters.mjs +0 -39
  25. package/src/math/examples/README.md +0 -25
  26. package/src/math/examples/browser.html +0 -10
  27. package/src/math/examples/browser.mjs +0 -24
  28. package/src/math/examples/formula.mjs +0 -12
  29. package/src/math/examples/markdown.mjs +0 -9
  30. package/src/math/examples/react.tsx +0 -19
  31. package/src/math/examples/stream.mjs +0 -19
  32. package/src/math/examples/unified.mjs +0 -26
  33. package/src/math/examples/worker.mjs +0 -7
  34. package/src/math/index.d.ts +0 -43
  35. package/src/math/integration.d.ts +0 -9
  36. package/src/math/integration.mjs +0 -28
  37. package/src/math/markdown-it.d.ts +0 -6
  38. package/src/math/markdown-it.mjs +0 -45
  39. package/src/math/markdown-rules.mjs +0 -65
  40. package/src/math/package-check.mjs +0 -118
  41. package/src/math/package-verify.mjs +0 -45
  42. package/src/math/rehype.d.ts +0 -6
  43. package/src/math/rehype.mjs +0 -37
  44. package/src/package.json +0 -9
  45. package/stream.d.ts +0 -14
  46. package/stream.mjs +0 -46
  47. package/verify.mjs +0 -45
  48. /package/{classic.d.ts → dist/classic.d.ts} +0 -0
  49. /package/{delimiters.d.ts → dist/delimiters.d.ts} +0 -0
  50. /package/{delimiters.mjs → dist/delimiters.mjs} +0 -0
  51. /package/{index.d.ts → dist/index.d.ts} +0 -0
  52. /package/{integration.d.ts → dist/integration.d.ts} +0 -0
  53. /package/{integration.mjs → dist/integration.mjs} +0 -0
  54. /package/{markdown-it.d.ts → dist/markdown-it.d.ts} +0 -0
  55. /package/{markdown-it.mjs → dist/markdown-it.mjs} +0 -0
  56. /package/{markdown-rules.mjs → dist/markdown-rules.mjs} +0 -0
  57. /package/{rehype.d.ts → dist/rehype.d.ts} +0 -0
  58. /package/{rehype.mjs → dist/rehype.mjs} +0 -0
  59. /package/{src/math → dist}/stream.d.ts +0 -0
  60. /package/{src/math → dist}/stream.mjs +0 -0
  61. /package/{src/math/FONT-SOURCE.md → docs/font-source.md} +0 -0
@@ -1,457 +0,0 @@
1
- Copyright 2012--2014 for Latin Modern Math OTF by B. Jackowski, P. Strzelczyk and P. Pianowski (on behalf of TeX users groups). This work is released under the GUST Font License -- see http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt for details.
2
-
3
- Rapier math font data, derived from Latin Modern Math 1.959.
4
- Changes: SVG outline conversion, character and MATH data extraction,
5
- optical-form closure, derived contour profiles and lossless path packing.
6
- Original outlines are unchanged. Hinting and text shaping tables are omitted.
7
- The font authors do not maintain this conversion.
8
- Complete original work: https://mirrors.ctan.org/fonts/lm-math.zip
9
- Conversion details: FONT-SOURCE.md.
10
-
11
- % This is a preliminary version (2006-09-30), barring acceptance from
12
- % the LaTeX Project Team and other feedback, of the GUST Font License.
13
- % (GUST is the Polish TeX Users Group, http://www.gust.org.pl)
14
- %
15
- % For the most recent version of this license see
16
- % http://www.gust.org.pl/fonts/licenses/GUST-FONT-LICENSE.txt
17
- % or
18
- % http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt
19
- %
20
- % This work may be distributed and/or modified under the conditions
21
- % of the LaTeX Project Public License, either version 1.3c of this
22
- % license or (at your option) any later version.
23
- %
24
- % Please also observe the following clause:
25
- % 1) it is requested, but not legally required, that derived works be
26
- % distributed only after changing the names of the fonts comprising this
27
- % work and given in an accompanying "manifest", and that the
28
- % files comprising the Work, as listed in the manifest, also be given
29
- % new names. Any exceptions to this request are also given in the
30
- % manifest.
31
- %
32
- % We recommend the manifest be given in a separate file named
33
- % MANIFEST-<fontid>.txt, where <fontid> is some unique identification
34
- % of the font family. If a separate "readme" file accompanies the Work,
35
- % we recommend a name of the form README-<fontid>.txt.
36
- %
37
- % The latest version of the LaTeX Project Public License is in
38
- % http://www.latex-project.org/lppl.txt and version 1.3c or later
39
- % is part of all distributions of LaTeX version 2006/05/20 or later.
40
-
41
-
42
- The LaTeX Project Public License
43
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
44
-
45
- LPPL Version 1.3c 2008-05-04
46
-
47
- Copyright 1999 2002-2008 LaTeX3 Project
48
- Everyone is allowed to distribute verbatim copies of this
49
- license document, but modification of it is not allowed.
50
-
51
-
52
- PREAMBLE
53
- ========
54
-
55
- The LaTeX Project Public License (LPPL) is the primary license under
56
- which the LaTeX kernel and the base LaTeX packages are distributed.
57
-
58
- You may use this license for any work of which you hold the copyright
59
- and which you wish to distribute. This license may be particularly
60
- suitable if your work is TeX-related (such as a LaTeX package), but
61
- it is written in such a way that you can use it even if your work is
62
- unrelated to TeX.
63
-
64
- The section `WHETHER AND HOW TO DISTRIBUTE WORKS UNDER THIS LICENSE',
65
- below, gives instructions, examples, and recommendations for authors
66
- who are considering distributing their works under this license.
67
-
68
- This license gives conditions under which a work may be distributed
69
- and modified, as well as conditions under which modified versions of
70
- that work may be distributed.
71
-
72
- We, the LaTeX3 Project, believe that the conditions below give you
73
- the freedom to make and distribute modified versions of your work
74
- that conform with whatever technical specifications you wish while
75
- maintaining the availability, integrity, and reliability of
76
- that work. If you do not see how to achieve your goal while
77
- meeting these conditions, then read the document `cfgguide.tex'
78
- and `modguide.tex' in the base LaTeX distribution for suggestions.
79
-
80
-
81
- DEFINITIONS
82
- ===========
83
-
84
- In this license document the following terms are used:
85
-
86
- `Work'
87
- Any work being distributed under this License.
88
-
89
- `Derived Work'
90
- Any work that under any applicable law is derived from the Work.
91
-
92
- `Modification'
93
- Any procedure that produces a Derived Work under any applicable
94
- law -- for example, the production of a file containing an
95
- original file associated with the Work or a significant portion of
96
- such a file, either verbatim or with modifications and/or
97
- translated into another language.
98
-
99
- `Modify'
100
- To apply any procedure that produces a Derived Work under any
101
- applicable law.
102
-
103
- `Distribution'
104
- Making copies of the Work available from one person to another, in
105
- whole or in part. Distribution includes (but is not limited to)
106
- making any electronic components of the Work accessible by
107
- file transfer protocols such as FTP or HTTP or by shared file
108
- systems such as Sun's Network File System (NFS).
109
-
110
- `Compiled Work'
111
- A version of the Work that has been processed into a form where it
112
- is directly usable on a computer system. This processing may
113
- include using installation facilities provided by the Work,
114
- transformations of the Work, copying of components of the Work, or
115
- other activities. Note that modification of any installation
116
- facilities provided by the Work constitutes modification of the Work.
117
-
118
- `Current Maintainer'
119
- A person or persons nominated as such within the Work. If there is
120
- no such explicit nomination then it is the `Copyright Holder' under
121
- any applicable law.
122
-
123
- `Base Interpreter'
124
- A program or process that is normally needed for running or
125
- interpreting a part or the whole of the Work.
126
-
127
- A Base Interpreter may depend on external components but these
128
- are not considered part of the Base Interpreter provided that each
129
- external component clearly identifies itself whenever it is used
130
- interactively. Unless explicitly specified when applying the
131
- license to the Work, the only applicable Base Interpreter is a
132
- `LaTeX-Format' or in the case of files belonging to the
133
- `LaTeX-format' a program implementing the `TeX language'.
134
-
135
-
136
-
137
- CONDITIONS ON DISTRIBUTION AND MODIFICATION
138
- ===========================================
139
-
140
- 1. Activities other than distribution and/or modification of the Work
141
- are not covered by this license; they are outside its scope. In
142
- particular, the act of running the Work is not restricted and no
143
- requirements are made concerning any offers of support for the Work.
144
-
145
- 2. You may distribute a complete, unmodified copy of the Work as you
146
- received it. Distribution of only part of the Work is considered
147
- modification of the Work, and no right to distribute such a Derived
148
- Work may be assumed under the terms of this clause.
149
-
150
- 3. You may distribute a Compiled Work that has been generated from a
151
- complete, unmodified copy of the Work as distributed under Clause 2
152
- above, as long as that Compiled Work is distributed in such a way that
153
- the recipients may install the Compiled Work on their system exactly
154
- as it would have been installed if they generated a Compiled Work
155
- directly from the Work.
156
-
157
- 4. If you are the Current Maintainer of the Work, you may, without
158
- restriction, modify the Work, thus creating a Derived Work. You may
159
- also distribute the Derived Work without restriction, including
160
- Compiled Works generated from the Derived Work. Derived Works
161
- distributed in this manner by the Current Maintainer are considered to
162
- be updated versions of the Work.
163
-
164
- 5. If you are not the Current Maintainer of the Work, you may modify
165
- your copy of the Work, thus creating a Derived Work based on the Work,
166
- and compile this Derived Work, thus creating a Compiled Work based on
167
- the Derived Work.
168
-
169
- 6. If you are not the Current Maintainer of the Work, you may
170
- distribute a Derived Work provided the following conditions are met
171
- for every component of the Work unless that component clearly states
172
- in the copyright notice that it is exempt from that condition. Only
173
- the Current Maintainer is allowed to add such statements of exemption
174
- to a component of the Work.
175
-
176
- a. If a component of this Derived Work can be a direct replacement
177
- for a component of the Work when that component is used with the
178
- Base Interpreter, then, wherever this component of the Work
179
- identifies itself to the user when used interactively with that
180
- Base Interpreter, the replacement component of this Derived Work
181
- clearly and unambiguously identifies itself as a modified version
182
- of this component to the user when used interactively with that
183
- Base Interpreter.
184
-
185
- b. Every component of the Derived Work contains prominent notices
186
- detailing the nature of the changes to that component, or a
187
- prominent reference to another file that is distributed as part
188
- of the Derived Work and that contains a complete and accurate log
189
- of the changes.
190
-
191
- c. No information in the Derived Work implies that any persons,
192
- including (but not limited to) the authors of the original version
193
- of the Work, provide any support, including (but not limited to)
194
- the reporting and handling of errors, to recipients of the
195
- Derived Work unless those persons have stated explicitly that
196
- they do provide such support for the Derived Work.
197
-
198
- d. You distribute at least one of the following with the Derived Work:
199
-
200
- 1. A complete, unmodified copy of the Work;
201
- if your distribution of a modified component is made by
202
- offering access to copy the modified component from a
203
- designated place, then offering equivalent access to copy
204
- the Work from the same or some similar place meets this
205
- condition, even though third parties are not compelled to
206
- copy the Work along with the modified component;
207
-
208
- 2. Information that is sufficient to obtain a complete,
209
- unmodified copy of the Work.
210
-
211
- 7. If you are not the Current Maintainer of the Work, you may
212
- distribute a Compiled Work generated from a Derived Work, as long as
213
- the Derived Work is distributed to all recipients of the Compiled
214
- Work, and as long as the conditions of Clause 6, above, are met with
215
- regard to the Derived Work.
216
-
217
- 8. The conditions above are not intended to prohibit, and hence do not
218
- apply to, the modification, by any method, of any component so that it
219
- becomes identical to an updated version of that component of the Work as
220
- it is distributed by the Current Maintainer under Clause 4, above.
221
-
222
- 9. Distribution of the Work or any Derived Work in an alternative
223
- format, where the Work or that Derived Work (in whole or in part) is
224
- then produced by applying some process to that format, does not relax or
225
- nullify any sections of this license as they pertain to the results of
226
- applying that process.
227
-
228
- 10. a. A Derived Work may be distributed under a different license
229
- provided that license itself honors the conditions listed in
230
- Clause 6 above, in regard to the Work, though it does not have
231
- to honor the rest of the conditions in this license.
232
-
233
- b. If a Derived Work is distributed under a different license, that
234
- Derived Work must provide sufficient documentation as part of
235
- itself to allow each recipient of that Derived Work to honor the
236
- restrictions in Clause 6 above, concerning changes from the Work.
237
-
238
- 11. This license places no restrictions on works that are unrelated to
239
- the Work, nor does this license place any restrictions on aggregating
240
- such works with the Work by any means.
241
-
242
- 12. Nothing in this license is intended to, or may be used to, prevent
243
- complete compliance by all parties with all applicable laws.
244
-
245
-
246
- NO WARRANTY
247
- ===========
248
-
249
- There is no warranty for the Work. Except when otherwise stated in
250
- writing, the Copyright Holder provides the Work `as is', without
251
- warranty of any kind, either expressed or implied, including, but not
252
- limited to, the implied warranties of merchantability and fitness for a
253
- particular purpose. The entire risk as to the quality and performance
254
- of the Work is with you. Should the Work prove defective, you assume
255
- the cost of all necessary servicing, repair, or correction.
256
-
257
- In no event unless required by applicable law or agreed to in writing
258
- will The Copyright Holder, or any author named in the components of the
259
- Work, or any other party who may distribute and/or modify the Work as
260
- permitted above, be liable to you for damages, including any general,
261
- special, incidental or consequential damages arising out of any use of
262
- the Work or out of inability to use the Work (including, but not limited
263
- to, loss of data, data being rendered inaccurate, or losses sustained by
264
- anyone as a result of any failure of the Work to operate with any other
265
- programs), even if the Copyright Holder or said author or said other
266
- party has been advised of the possibility of such damages.
267
-
268
-
269
- MAINTENANCE OF THE WORK
270
- =======================
271
-
272
- The Work has the status `author-maintained' if the Copyright Holder
273
- explicitly and prominently states near the primary copyright notice in
274
- the Work that the Work can only be maintained by the Copyright Holder
275
- or simply that it is `author-maintained'.
276
-
277
- The Work has the status `maintained' if there is a Current Maintainer
278
- who has indicated in the Work that they are willing to receive error
279
- reports for the Work (for example, by supplying a valid e-mail
280
- address). It is not required for the Current Maintainer to acknowledge
281
- or act upon these error reports.
282
-
283
- The Work changes from status `maintained' to `unmaintained' if there
284
- is no Current Maintainer, or the person stated to be Current
285
- Maintainer of the work cannot be reached through the indicated means
286
- of communication for a period of six months, and there are no other
287
- significant signs of active maintenance.
288
-
289
- You can become the Current Maintainer of the Work by agreement with
290
- any existing Current Maintainer to take over this role.
291
-
292
- If the Work is unmaintained, you can become the Current Maintainer of
293
- the Work through the following steps:
294
-
295
- 1. Make a reasonable attempt to trace the Current Maintainer (and
296
- the Copyright Holder, if the two differ) through the means of
297
- an Internet or similar search.
298
-
299
- 2. If this search is successful, then enquire whether the Work
300
- is still maintained.
301
-
302
- a. If it is being maintained, then ask the Current Maintainer
303
- to update their communication data within one month.
304
-
305
- b. If the search is unsuccessful or no action to resume active
306
- maintenance is taken by the Current Maintainer, then announce
307
- within the pertinent community your intention to take over
308
- maintenance. (If the Work is a LaTeX work, this could be
309
- done, for example, by posting to comp.text.tex.)
310
-
311
- 3a. If the Current Maintainer is reachable and agrees to pass
312
- maintenance of the Work to you, then this takes effect
313
- immediately upon announcement.
314
-
315
- b. If the Current Maintainer is not reachable and the Copyright
316
- Holder agrees that maintenance of the Work be passed to you,
317
- then this takes effect immediately upon announcement.
318
-
319
- 4. If you make an `intention announcement' as described in 2b. above
320
- and after three months your intention is challenged neither by
321
- the Current Maintainer nor by the Copyright Holder nor by other
322
- people, then you may arrange for the Work to be changed so as
323
- to name you as the (new) Current Maintainer.
324
-
325
- 5. If the previously unreachable Current Maintainer becomes
326
- reachable once more within three months of a change completed
327
- under the terms of 3b) or 4), then that Current Maintainer must
328
- become or remain the Current Maintainer upon request provided
329
- they then update their communication data within one month.
330
-
331
- A change in the Current Maintainer does not, of itself, alter the fact
332
- that the Work is distributed under the LPPL license.
333
-
334
- If you become the Current Maintainer of the Work, you should
335
- immediately provide, within the Work, a prominent and unambiguous
336
- statement of your status as Current Maintainer. You should also
337
- announce your new status to the same pertinent community as
338
- in 2b) above.
339
-
340
-
341
- WHETHER AND HOW TO DISTRIBUTE WORKS UNDER THIS LICENSE
342
- ======================================================
343
-
344
- This section contains important instructions, examples, and
345
- recommendations for authors who are considering distributing their
346
- works under this license. These authors are addressed as `you' in
347
- this section.
348
-
349
- Choosing This License or Another License
350
- ----------------------------------------
351
-
352
- If for any part of your work you want or need to use *distribution*
353
- conditions that differ significantly from those in this license, then
354
- do not refer to this license anywhere in your work but, instead,
355
- distribute your work under a different license. You may use the text
356
- of this license as a model for your own license, but your license
357
- should not refer to the LPPL or otherwise give the impression that
358
- your work is distributed under the LPPL.
359
-
360
- The document `modguide.tex' in the base LaTeX distribution explains
361
- the motivation behind the conditions of this license. It explains,
362
- for example, why distributing LaTeX under the GNU General Public
363
- License (GPL) was considered inappropriate. Even if your work is
364
- unrelated to LaTeX, the discussion in `modguide.tex' may still be
365
- relevant, and authors intending to distribute their works under any
366
- license are encouraged to read it.
367
-
368
- A Recommendation on Modification Without Distribution
369
- -----------------------------------------------------
370
-
371
- It is wise never to modify a component of the Work, even for your own
372
- personal use, without also meeting the above conditions for
373
- distributing the modified component. While you might intend that such
374
- modifications will never be distributed, often this will happen by
375
- accident -- you may forget that you have modified that component; or
376
- it may not occur to you when allowing others to access the modified
377
- version that you are thus distributing it and violating the conditions
378
- of this license in ways that could have legal implications and, worse,
379
- cause problems for the community. It is therefore usually in your
380
- best interest to keep your copy of the Work identical with the public
381
- one. Many works provide ways to control the behavior of that work
382
- without altering any of its licensed components.
383
-
384
- How to Use This License
385
- -----------------------
386
-
387
- To use this license, place in each of the components of your work both
388
- an explicit copyright notice including your name and the year the work
389
- was authored and/or last substantially modified. Include also a
390
- statement that the distribution and/or modification of that
391
- component is constrained by the conditions in this license.
392
-
393
- Here is an example of such a notice and statement:
394
-
395
- %% pig.dtx
396
- %% Copyright 2008 M. Y. Name
397
- %
398
- % This work may be distributed and/or modified under the
399
- % conditions of the LaTeX Project Public License, either version 1.3
400
- % of this license or (at your option) any later version.
401
- % The latest version of this license is in
402
- % https://www.latex-project.org/lppl.txt
403
- % and version 1.3c or later is part of all distributions of LaTeX
404
- % version 2008 or later.
405
- %
406
- % This work has the LPPL maintenance status `maintained'.
407
- %
408
- % The Current Maintainer of this work is M. Y. Name.
409
- %
410
- % This work consists of the files pig.dtx and pig.ins
411
- % and the derived file pig.sty.
412
-
413
- Given such a notice and statement in a file, the conditions
414
- given in this license document would apply, with the `Work' referring
415
- to the three files `pig.dtx', `pig.ins', and `pig.sty' (the last being
416
- generated from `pig.dtx' using `pig.ins'), the `Base Interpreter'
417
- referring to any `LaTeX-Format', and both `Copyright Holder' and
418
- `Current Maintainer' referring to the person `M. Y. Name'.
419
-
420
- If you do not want the Maintenance section of LPPL to apply to your
421
- Work, change `maintained' above into `author-maintained'.
422
- However, we recommend that you use `maintained', as the Maintenance
423
- section was added in order to ensure that your Work remains useful to
424
- the community even when you can no longer maintain and support it
425
- yourself.
426
-
427
- Derived Works That Are Not Replacements
428
- ---------------------------------------
429
-
430
- Several clauses of the LPPL specify means to provide reliability and
431
- stability for the user community. They therefore concern themselves
432
- with the case that a Derived Work is intended to be used as a
433
- (compatible or incompatible) replacement of the original Work. If
434
- this is not the case (e.g., if a few lines of code are reused for a
435
- completely different task), then clauses 6b and 6d shall not apply.
436
-
437
-
438
- Important Recommendations
439
- -------------------------
440
-
441
- Defining What Constitutes the Work
442
-
443
- The LPPL requires that distributions of the Work contain all the
444
- files of the Work. It is therefore important that you provide a
445
- way for the licensee to determine which files constitute the Work.
446
- This could, for example, be achieved by explicitly listing all the
447
- files of the Work near the copyright notice of each file or by
448
- using a line such as:
449
-
450
- % This work consists of all files listed in manifest.txt.
451
-
452
- in that place. In the absence of an unequivocal list it might be
453
- impossible for the licensee to determine what is considered by you
454
- to comprise the Work and, in such a case, the licensee would be
455
- entitled to make reasonable conjectures as to which files comprise
456
- the Work.
457
-
@@ -1,4 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- import type API from './index.js';
3
- declare global {var RapierMath: typeof API;}
4
- export {};
@@ -1,8 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- export interface DelimiterOptions {singleDollar?: boolean; brackets?: boolean}
3
- export interface MathSpan {
4
- start: number; end: number; bodyStart: number; bodyEnd: number;
5
- open: string; close: string; displayMode: boolean;
6
- }
7
- /** Index a raw, host-owned text region. Does not parse Markdown or unescape source. */
8
- export function createMathMatcher(source: string, options?: DelimiterOptions): (start: number, limit?: number) => MathSpan | null;
@@ -1,39 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- // A boundary index for a host-owned text region, not a Markdown parser.
3
- export function createMathMatcher(source, {singleDollar = false, brackets = true} = {}) {
4
- if (typeof source !== 'string') throw new TypeError('Math boundaries require source text.');
5
- const markers = new Map(), next = Object.create(null);
6
- let slashes = 0, line = 0;
7
- for (let at = 0; at < source.length;) {
8
- const char = source[at];
9
- if (char === '\\') { slashes++; at++; continue; }
10
- if (char === '\n' || char === '\r') line++;
11
- if (char === '$') {
12
- let end = at + 1;
13
- while (source[end] === '$') end++;
14
- const count = end - at;
15
- if (!(slashes & 1) && (count === 2 || count === 1 && singleDollar))
16
- markers.set(at, {at, marker: count === 2 ? '$$' : '$', line});
17
- at = end;
18
- } else {
19
- if (brackets && slashes & 1 && '()[]'.includes(char))
20
- markers.set(at - 1, {at: at - 1, marker: '\\' + char, line});
21
- at++;
22
- }
23
- slashes = 0;
24
- }
25
- for (const entry of [...markers.values()].reverse()) {
26
- const closing = entry.marker === '\\(' ? '\\)' : entry.marker === '\\[' ? '\\]' : entry.marker;
27
- entry.close = next[closing];
28
- next[entry.marker] = entry;
29
- }
30
- return function match(start, limit = source.length) {
31
- const open = markers.get(start), close = open?.close;
32
- if (!close || open.marker === '\\)' || open.marker === '\\]' || close.at + close.marker.length > limit) return null;
33
- const bodyStart = start + open.marker.length, bodyEnd = close.at;
34
- if (open.marker === '$' && (open.line !== close.line || bodyStart === bodyEnd ||
35
- /\s/.test(source[bodyStart]) || /\s/.test(source[bodyEnd - 1]) || /[0-9]/.test(source[bodyEnd + 1] || ''))) return null;
36
- return {start, end: bodyEnd + close.marker.length, bodyStart, bodyEnd,
37
- open: open.marker, close: close.marker, displayMode: open.marker === '$$' || open.marker === '\\['};
38
- };
39
- }
@@ -1,25 +0,0 @@
1
- # Run the installed examples
2
-
3
- From a consumer directory, install `rapier-math`, then run
4
- `node node_modules/rapier-math/examples/formula.mjs`.
5
-
6
- For Markdown and streaming, also install `markdown-it` and run `markdown.mjs` or `stream.mjs`.
7
- For unified, install `unified remark-parse remark-math remark-rehype rehype-sanitize rehype-stringify hast-util-from-html`
8
- and run `unified.mjs`. The remark example uses remark's syntax; it does not recognize backslash delimiters.
9
-
10
- Serve the package directory over HTTP and open `examples/browser.html`. Its external module imports the
11
- installed ESM renderer, fits the output and releases observation before replacement and on page exit.
12
- Start `new Worker('./worker.mjs', {type: 'module'})` from this directory and post `{id, source}`.
13
- Use an id owned by the current message and ignore stale replies. Workers render SVG; they do not call `observe`.
14
-
15
- `react.tsx` is a small React 19/SSR component to copy into an existing TypeScript application. Install
16
- `react react-dom` and the development types `@types/react @types/react-dom`. No framework is required by the core.
17
-
18
- For streamed UTF-8, use `TextDecoderStream` or `decoder.decode(bytes, {stream: true})` and flush the decoder
19
- at EOF. Feed decoded strings into one stream per message. Append incoming chunks to a text node for immediate
20
- literal progress, and replace the whole preview when `write` returns a snapshot. Replace it with `finish()` at EOF.
21
- Do not concatenate transport data into HTML. On cancellation call `abort`; on replacement cancel the old producer
22
- before `reset`. A producer that still runs needs its own generation check before calling `write`.
23
-
24
- The examples retain the original source as the editable/copyable authority. Markdown hosts can normalize
25
- newlines or escapes in their syntax nodes; an HTML serialization is not an exact source archive.
@@ -1,10 +0,0 @@
1
- <!doctype html>
2
- <meta charset="utf-8">
3
- <meta name="viewport" content="width=device-width">
4
- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src-attr 'unsafe-inline'; style-src-elem 'none'; worker-src 'self'; connect-src 'none'; base-uri 'none'">
5
- <title>Rapier Math example</title>
6
- <label>TeX <textarea id="source">\frac{-b\pm\sqrt{b^2-4ac}}{2a}</textarea></label>
7
- <button id="render" type="button">Render</button>
8
- <main id="equation"></main>
9
- <pre id="errors"></pre>
10
- <script type="module" src="./browser.mjs"></script>
@@ -1,24 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- import {render, observe} from '../index.mjs';
3
- const container = document.querySelector('#equation');
4
- const source = document.querySelector('#source');
5
- let stop = () => {};
6
- function update() {
7
- stop();
8
- try {
9
- const result = render(source.value, {displayMode: true});
10
- document.querySelector('#errors').textContent = JSON.stringify(result.errors);
11
- if (result.errors.length) container.replaceChildren(document.createTextNode(source.value));
12
- else {
13
- // Only this renderer's freshly returned SVG reaches the HTML sink.
14
- container.innerHTML = result.svg;
15
- stop = observe(container);
16
- }
17
- } catch (error) {
18
- container.replaceChildren(document.createTextNode(source.value));
19
- document.querySelector('#errors').textContent = error.message;
20
- }
21
- }
22
- document.querySelector('#render').addEventListener('click', update);
23
- window.addEventListener('pagehide', () => stop());
24
- update();
@@ -1,12 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- import {render, renderToString} from 'rapier-math';
3
-
4
- // Works in Node/SSR: the result needs no browser JavaScript or remote font.
5
- const source = String.raw`\frac{-b\pm\sqrt{b^2-4ac}}{2a}`;
6
- const result = render(source, {displayMode: true});
7
- if (result.errors.length) throw new Error(JSON.stringify(result.errors));
8
- console.log(result.svg);
9
- console.log(renderToString('E=mc^2'));
10
- const failure = render(String.raw`\unsupported{x}`);
11
- console.error({source: String.raw`\unsupported{x}`, errors: failure.errors});
12
- // Retain the original source for editing/copying, even if admission throws.
@@ -1,9 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- import MarkdownIt from 'markdown-it';
3
- import rapierMath from 'rapier-math/markdown-it';
4
-
5
- export const md = new MarkdownIt({html: false}).use(rapierMath);
6
- const source = 'It costs $5 and $10. Code: `$$x$$`. Math: \\(x^2\\).\n\n$$\\frac{1}{2}$$\n';
7
- const env = {};
8
- console.log(md.render(source, env));
9
- console.error(env.rapierMathErrors || []);
@@ -1,19 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- import {useEffect, useMemo, useRef} from 'react';
3
- import {render, observe} from 'rapier-math';
4
-
5
- export function Equation({source, displayMode = false}: {source: string; displayMode?: boolean}) {
6
- const ref = useRef<HTMLSpanElement>(null);
7
- const result = useMemo(() => {
8
- try { return render(source, {displayMode}); }
9
- catch { return null; }
10
- }, [source, displayMode]);
11
- const svg = result && result.errors.length === 0 ? result.svg : null;
12
- useEffect(() => {
13
- if (ref.current && svg) return observe(ref.current);
14
- }, [svg]); // Cleanup runs before replacement setup and on unmount.
15
- if (!svg) return <code>{source}</code>;
16
- // The server and initial client render use identical source/options. Fit only
17
- // after hydration; never pass authored HTML to dangerouslySetInnerHTML.
18
- return <span ref={ref} dangerouslySetInnerHTML={{__html: svg}} />;
19
- }
@@ -1,19 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- import MarkdownIt from 'markdown-it';
3
- import rapierMath from 'rapier-math/markdown-it';
4
- import {createMarkdownStream} from 'rapier-math/stream';
5
-
6
- const md = new MarkdownIt({html: false}).use(rapierMath);
7
- const stream = createMarkdownStream(source => md.render(source, {}), {previewEvery: 16});
8
- for (const chunk of ['The answer is \\(', '\\frac{1}', '{2}', '\\)', '. Code: `$$x$$`.']) {
9
- const preview = stream.write(chunk);
10
- if (preview) console.log({phase: 'preview', ...preview});
11
- }
12
- const final = stream.finish();
13
- console.log({phase: 'complete', ...final});
14
- if (final.html !== md.render(final.source, {})) throw new Error('Batch mismatch');
15
-
16
- // One stream per message. On replacement: cancel its transport, reset, write.
17
- stream.reset();
18
- stream.write('Replacement \\(y\\).');
19
- console.log(stream.finish());
@@ -1,26 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- import {unified} from 'unified';
3
- import remarkParse from 'remark-parse';
4
- import remarkMath from 'remark-math';
5
- import remarkRehype from 'remark-rehype';
6
- import rehypeSanitize, {defaultSchema} from 'rehype-sanitize';
7
- import rehypeRapierMath from 'rapier-math/rehype';
8
- import rehypeStringify from 'rehype-stringify';
9
- import {pathToFileURL} from 'node:url';
10
-
11
- export const processor = unified().use(remarkParse)
12
- .use(remarkMath, {singleDollarTextMath: false}).use(remarkRehype)
13
- .use(rehypeSanitize, {
14
- ...defaultSchema,
15
- attributes: {...defaultSchema.attributes, code: [
16
- ...(defaultSchema.attributes.code || []).filter(rule => !(Array.isArray(rule) && rule[0] === 'className')),
17
- ['className', 'language-math', 'math-inline', 'math-display'],
18
- ]},
19
- })
20
- .use(rehypeRapierMath).use(rehypeStringify);
21
-
22
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
23
- const file = await processor.process('Price $5. Code `$$x$$`. Math $$x^2$$.\n\n$$\n\\frac{1}{2}\n$$');
24
- console.log(String(file));
25
- console.error(file.messages);
26
- }