Commit node_modules

This commit is contained in:
Will Faught
2023-03-27 20:36:01 -07:00
parent 53a30a4c3e
commit 18ea53bb81
2693 changed files with 193960 additions and 70 deletions

39
paige/node_modules/katex/contrib/copy-tex/README.md generated vendored Normal file
View File

@@ -0,0 +1,39 @@
# Copy-tex extension
This extension modifies the copy/paste behavior in any browser supporting the
[Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent)
so that, when selecting and copying KaTeX-rendered elements, the text
content of the resulting clipboard renders KaTeX elements as their LaTeX source
surrounded by specified delimiters. (The HTML content of the resulting
clipboard remains the selected HTML content, as it normally would.)
The default delimiters are `$...$` for inline math and `$$...$$` for display
math, but you can easy switch them to e.g. `\(...\)` and `\[...\]` by
modifying `copyDelimiters` in [the source code](copy-tex.js).
Note that a selection containing part of a KaTeX formula gets extended to
include the entire KaTeX formula.
## Usage
This extension isn't part of KaTeX proper, so the script should be separately
included in the page.
```html
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/copy-tex.min.js" integrity="sha384-ww/583aHhxWkz5DEVn6OKtNiIaLi2iBRNZXfJRiY1Ai7tnJ9UXpEsyvOITVpTl4A" crossorigin="anonymous"></script>
```
(Note that, as of KaTeX 0.16.0, there is no longer a corresponding CSS file.)
See [index.html](index.html) for an example.
(To run this example from a clone of the repository, run `yarn start`
in the root KaTeX directory, and then visit
http://localhost:7936/contrib/copy-tex/index.html
with your web browser.)
If you want to build your own custom copy handler based on this one,
copy the `copy-tex.js` into your codebase and replace the `require`
statement with `require('katex/contrib/copy-tex/katex2tex.js')`.
ECMAScript module is also available:
```html
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/copy-tex.mjs" integrity="sha384-bVEnwt0PtX+1EuJoOEcm4rgTUWvb2ILTdjHfI1gUe/r5fdqrTcQaUuRdHG2DciuQ" crossorigin="anonymous"></script>
```

51
paige/node_modules/katex/contrib/copy-tex/copy-tex.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
// @flow
import katexReplaceWithTex from './katex2tex';
// Return <div class="katex"> element containing node, or null if not found.
function closestKatex(node: Node): ?Element {
// If node is a Text Node, for example, go up to containing Element,
// where we can apply the `closest` method.
const element: ?Element =
(node instanceof Element ? node : node.parentElement);
return element && element.closest('.katex');
}
// Global copy handler to modify behavior on/within .katex elements.
document.addEventListener('copy', function(event: ClipboardEvent) {
const selection = window.getSelection();
if (selection.isCollapsed || !event.clipboardData) {
return; // default action OK if selection is empty or unchangeable
}
const clipboardData = event.clipboardData;
const range = selection.getRangeAt(0);
// When start point is within a formula, expand to entire formula.
const startKatex = closestKatex(range.startContainer);
if (startKatex) {
range.setStartBefore(startKatex);
}
// Similarly, when end point is within a formula, expand to entire formula.
const endKatex = closestKatex(range.endContainer);
if (endKatex) {
range.setEndAfter(endKatex);
}
const fragment = range.cloneContents();
if (!fragment.querySelector('.katex-mathml')) {
return; // default action OK if no .katex-mathml elements
}
const htmlContents = Array.prototype.map.call(fragment.childNodes,
(el) => (el instanceof Text ? el.textContent : el.outerHTML)
).join('');
// Preserve usual HTML copy/paste behavior.
clipboardData.setData('text/html', htmlContents);
// Rewrite plain-text version.
clipboardData.setData('text/plain',
katexReplaceWithTex(fragment).textContent);
// Prevent normal copy handling.
event.preventDefault();
});

38
paige/node_modules/katex/contrib/copy-tex/index.html generated vendored Normal file
View File

@@ -0,0 +1,38 @@
<!DOCTYPE html>
<!--To run this example from a clone of the repository, run `yarn start`
in the root KaTeX directory and then visit with your web browser:
http://localhost:7936/contrib/copy-tex/index.html
-->
<html>
<head>
<meta charset="UTF-8">
<title>Copy-tex test</title>
<script src="/katex.js" type="text/javascript"></script>
<script src="/contrib/auto-render.js" type="text/javascript"></script>
<script src="/contrib/copy-tex.js" type="text/javascript"></script>
<style type="text/css">
body {
margin: 0px;
padding: 0px;
font-size: 36px;
}
#test > .blue {
color: blue;
}
</style>
</head>
<body>
<h1>Copy-tex test</h1>
<h2>Try copy/pasting some of the text below!</h2>
<p>
Here is some \(\KaTeX\) math: $$ x^2+y^2=z^2 $$
The variables are \(x\), \(y\), and \(z\),
which are all in \(\mathbb{R}^+\).
Q.E.D.
</p>
<script>
renderMathInElement(document.body);
</script>
</body>
</html>

61
paige/node_modules/katex/contrib/copy-tex/katex2tex.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
// @flow
export interface CopyDelimiters {
inline: [string, string],
display: [string, string],
}
// Set these to how you want inline and display math to be delimited.
export const defaultCopyDelimiters: CopyDelimiters = {
inline: ['$', '$'], // alternative: ['\(', '\)']
display: ['$$', '$$'], // alternative: ['\[', '\]']
};
// Replace .katex elements with their TeX source (<annotation> element).
// Modifies fragment in-place. Useful for writing your own 'copy' handler,
// as in copy-tex.js.
export function katexReplaceWithTex(
fragment: DocumentFragment,
copyDelimiters: CopyDelimiters = defaultCopyDelimiters
): DocumentFragment {
// Remove .katex-html blocks that are preceded by .katex-mathml blocks
// (which will get replaced below).
const katexHtml = fragment.querySelectorAll('.katex-mathml + .katex-html');
for (let i = 0; i < katexHtml.length; i++) {
const element = katexHtml[i];
if (element.remove) {
element.remove();
} else if (element.parentNode) {
element.parentNode.removeChild(element);
}
}
// Replace .katex-mathml elements with their annotation (TeX source)
// descendant, with inline delimiters.
const katexMathml = fragment.querySelectorAll('.katex-mathml');
for (let i = 0; i < katexMathml.length; i++) {
const element = katexMathml[i];
const texSource = element.querySelector('annotation');
if (texSource) {
if (element.replaceWith) {
element.replaceWith(texSource);
} else if (element.parentNode) {
element.parentNode.replaceChild(texSource, element);
}
texSource.innerHTML = copyDelimiters.inline[0] +
texSource.innerHTML + copyDelimiters.inline[1];
}
}
// Switch display math to display delimiters.
const displays = fragment.querySelectorAll('.katex-display annotation');
for (let i = 0; i < displays.length; i++) {
const element = displays[i];
element.innerHTML = copyDelimiters.display[0] +
element.innerHTML.substr(copyDelimiters.inline[0].length,
element.innerHTML.length - copyDelimiters.inline[0].length
- copyDelimiters.inline[1].length)
+ copyDelimiters.display[1];
}
return fragment;
}
export default katexReplaceWithTex;