@zzish/math-rich-input 0.1.57 → 0.1.59

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.
@@ -1,39 +1,21 @@
1
- // This function adds the katex css stylesheet to the document head
2
- export const setupKatex = () => {
3
- let links = document.getElementsByTagName("link")
4
- for (let i = 0; i < links.length; i++) {
5
- if (links[i].id === "katex-css")
6
- return
7
- }
8
-
9
- let link = document.createElement("link")
10
- link.id = "katex-css"
11
- link.rel = "stylesheet"
12
- link.href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css"
13
- // link.integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq"
14
- link.crossorigin="anonymous"
15
- document.head.appendChild(link);
16
- console.log("Added katex css to document head")
17
-
18
- // The following two scripts are required to have pages auto-render embedded latex.
19
- // We don't need to do this as we render everything programatically.
20
- // These are inlcuded here only for reference in case of future need.
1
+ import { KATEX_CSS } from "./katexStylesheet.generated.js";
21
2
 
22
- // let script = document.createElement("script");
23
- // script.id = "katex-js"
24
- // script.defer = true;
25
- // script.src = "https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js"
26
- // // script.integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz"
27
- // script.crossorigin="anonymous"
28
- // document.head.appendChild(script);
29
- // console.log("Added script")
30
-
31
- // script = document.createElement("script");
32
- // script.id = "katex-js-auto-render"
33
- // script.defer = true;
34
- // script.src = "https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js"
35
- // // script.integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI"
36
- // script.crossorigin="anonymous"
37
- // document.head.appendChild(script);
38
- // console.log("Added script")
39
- }
3
+ /**
4
+ * Put KaTeX's stylesheet on the page, once, from inside the package.
5
+ *
6
+ * The field draws formulas with KaTeX and every host has looked the way `katex@0.11.1`'s stylesheet draws
7
+ * them, because up to 0.1.58 this appended that stylesheet from jsdelivr. It is the same stylesheet now,
8
+ * appended at the same moments under the same id, but carried in the bundle with its fonts inlined
9
+ * (`scripts/build-katex-stylesheet.js`): no request leaves the page, nothing waits on a third party, and
10
+ * there is no late arrival to resize a field that was already drawn.
11
+ *
12
+ * A host that already provides its own KaTeX stylesheet under the id `katex-css` keeps it: this adds
13
+ * nothing then, as before.
14
+ */
15
+ export const setupKatex = () => {
16
+ if (typeof document === "undefined" || document.getElementById("katex-css")) return;
17
+ const style = document.createElement("style");
18
+ style.id = "katex-css";
19
+ style.textContent = KATEX_CSS;
20
+ document.head.appendChild(style);
21
+ };