@liqvid/katex 0.1.0 → 1.0.0-alpha.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.
@@ -1,11 +1,11 @@
1
1
  import { recursiveMap, usePromise } from "@liqvid/utils/react";
2
2
  import { usePlayer } from "liqvid";
3
- import { cloneElement, forwardRef, isValidElement, useEffect, useImperativeHandle, useRef } from "react";
4
- import { KTX } from "./fancy.mjs";
5
- import { KTX as KTXPlain } from "./plain.mjs";
3
+ import React, { cloneElement, forwardRef, isValidElement, useEffect, useImperativeHandle, useRef, } from "react";
4
+ import { KTX } from "./fancy";
5
+ import { Handle as KTXHandle, KTX as KTXPlain } from "./plain";
6
6
  /**
7
7
  * Wait for several things to be rendered
8
- */
8
+ */
9
9
  export const RenderGroup = forwardRef(function RenderGroup(props, ref) {
10
10
  const [ready, resolve] = usePromise();
11
11
  // handle
@@ -25,7 +25,7 @@ export const RenderGroup = forwardRef(function RenderGroup(props, ref) {
25
25
  resolve();
26
26
  });
27
27
  }, []);
28
- return recursiveMap(props.children, node => {
28
+ return recursiveMap(props.children, (node) => {
29
29
  if (shouldInspect(node)) {
30
30
  const originalRef = node.ref;
31
31
  return cloneElement(node, {
@@ -41,7 +41,7 @@ export const RenderGroup = forwardRef(function RenderGroup(props, ref) {
41
41
  else if (originalRef && typeof originalRef === "object") {
42
42
  originalRef.current = ref;
43
43
  }
44
- }
44
+ },
45
45
  });
46
46
  }
47
47
  return node;
@@ -52,7 +52,9 @@ export const RenderGroup = forwardRef(function RenderGroup(props, ref) {
52
52
  * @param node Element to check
53
53
  */
54
54
  function shouldInspect(node) {
55
- return isValidElement(node) && typeof node.type === "object" && (node.type === KTX || node.type === KTXPlain);
55
+ return (isValidElement(node) &&
56
+ typeof node.type === "object" &&
57
+ (node.type === KTX || node.type === KTXPlain));
56
58
  }
57
59
  /**
58
60
  * Find least common ancestor of an array of elements
@@ -67,7 +69,7 @@ function leastCommonAncestor(elements) {
67
69
  let failing = elements.slice(1);
68
70
  while (failing.length > 0) {
69
71
  ancestor = ancestor.parentElement;
70
- failing = failing.filter(node => !ancestor.contains(node));
72
+ failing = failing.filter((node) => !ancestor.contains(node));
71
73
  }
72
74
  return ancestor;
73
75
  }
@@ -0,0 +1,85 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { combineRefs } from "@liqvid/utils";
4
+ import katex from "katex";
5
+ import { useEffect, useRef, useState } from "react";
6
+ import { useKaTeXContext } from "./context";
7
+ /** Component for KaTeX code */
8
+ export const KTX = function KTX({ children, ref: propRef,
9
+ // katex options
10
+ colorIsTextColor, displayMode, errorColor, fleqn, globalGroup, leqno, macros, maxExpand, maxSize, minRuleThickness, output, strict, throwOnError, trust, ...props }) {
11
+ const ref = useRef(null);
12
+ const defaults = useKaTeXContext();
13
+ const isFirstRender = useFirstRender();
14
+ useEffect(() => {
15
+ if (!ref.current)
16
+ return;
17
+ // needed for initial client render
18
+ isFirstRender;
19
+ katex.render(children, ref.current, {
20
+ colorIsTextColor: colorIsTextColor ?? defaults.colorIsTextColor,
21
+ displayMode: displayMode,
22
+ errorColor: errorColor ?? defaults.errorColor,
23
+ fleqn: fleqn ?? defaults.fleqn,
24
+ globalGroup: globalGroup ?? defaults.globalGroup,
25
+ leqno: leqno ?? defaults.leqno,
26
+ macros: macros ?? defaults.macros,
27
+ maxExpand: maxExpand ?? defaults.maxExpand,
28
+ maxSize: maxSize ?? defaults.maxSize,
29
+ minRuleThickness: minRuleThickness ?? defaults.minRuleThickness,
30
+ output: output ?? defaults.output,
31
+ strict: strict ?? defaults.strict,
32
+ throwOnError: throwOnError ?? defaults.throwOnError,
33
+ trust: trust ?? defaults.trust,
34
+ });
35
+ }, [
36
+ children,
37
+ defaults,
38
+ isFirstRender,
39
+ // katex options
40
+ colorIsTextColor,
41
+ displayMode,
42
+ errorColor,
43
+ fleqn,
44
+ globalGroup,
45
+ leqno,
46
+ macros,
47
+ maxExpand,
48
+ maxSize,
49
+ minRuleThickness,
50
+ output,
51
+ strict,
52
+ throwOnError,
53
+ trust,
54
+ ]);
55
+ // ensure that it is server-rendered
56
+ if (isFirstRender) {
57
+ const tex = katex.renderToString(children, {
58
+ colorIsTextColor: colorIsTextColor ?? defaults.colorIsTextColor,
59
+ displayMode: displayMode,
60
+ errorColor: errorColor ?? defaults.errorColor,
61
+ fleqn: fleqn ?? defaults.fleqn,
62
+ globalGroup: globalGroup ?? defaults.globalGroup,
63
+ leqno: leqno ?? defaults.leqno,
64
+ macros: macros ?? defaults.macros,
65
+ maxExpand: maxExpand ?? defaults.maxExpand,
66
+ maxSize: maxSize ?? defaults.maxSize,
67
+ minRuleThickness: minRuleThickness ?? defaults.minRuleThickness,
68
+ output: output ?? defaults.output,
69
+ strict: strict ?? defaults.strict,
70
+ throwOnError: throwOnError ?? defaults.throwOnError,
71
+ trust: trust ?? defaults.trust,
72
+ });
73
+ return (_jsx("span", { dangerouslySetInnerHTML: {
74
+ __html: tex,
75
+ }, ref: combineRefs(ref, propRef), ...props }));
76
+ }
77
+ return _jsx("span", { ref: combineRefs(ref, propRef), ...props });
78
+ };
79
+ function useFirstRender() {
80
+ const [isFirstRender, setFirstRender] = useState(true);
81
+ useEffect(() => {
82
+ setFirstRender(false);
83
+ }, []);
84
+ return isFirstRender;
85
+ }
@@ -0,0 +1,47 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ import { parseMacros } from "./macros";
5
+ const KaTeXContext = createContext({});
6
+ export function useKaTeXContext() {
7
+ return useContext(KaTeXContext);
8
+ }
9
+ export function KaTeXProvider({ children, colorIsTextColor, displayMode, errorColor, fleqn, globalGroup, leqno, macros, maxExpand, maxSize, minRuleThickness, output, strict = "ignore", throwOnError = false, trust = true, }) {
10
+ const context = useMemo(() => {
11
+ if (typeof macros === "string") {
12
+ macros = parseMacros(macros);
13
+ }
14
+ return {
15
+ colorIsTextColor,
16
+ displayMode,
17
+ errorColor,
18
+ fleqn,
19
+ globalGroup,
20
+ leqno,
21
+ macros,
22
+ maxExpand,
23
+ maxSize,
24
+ minRuleThickness,
25
+ output,
26
+ strict,
27
+ throwOnError,
28
+ trust,
29
+ };
30
+ }, [
31
+ colorIsTextColor,
32
+ displayMode,
33
+ errorColor,
34
+ fleqn,
35
+ globalGroup,
36
+ leqno,
37
+ macros,
38
+ maxExpand,
39
+ maxSize,
40
+ minRuleThickness,
41
+ output,
42
+ strict,
43
+ throwOnError,
44
+ trust,
45
+ ]);
46
+ return (_jsx(KaTeXContext.Provider, { value: context, children: children }));
47
+ }
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { combineRefs } from "@liqvid/utils/react";
3
3
  import { usePlayer } from "liqvid";
4
4
  import { forwardRef, useEffect, useRef } from "react";
5
- import { KTX as KTXPlain } from "./plain.mjs";
5
+ import { Handle, KTX as KTXPlain } from "./plain";
6
6
  /** Component for KaTeX code */
7
7
  export const KTX = forwardRef(function KTX(props, ref) {
8
8
  const { obstruct = "canplay canplaythrough", reparse = false, ...attrs } = props;
@@ -22,5 +22,5 @@ export const KTX = forwardRef(function KTX(props, ref) {
22
22
  plain.current.ready.then(() => player.reparseTree(plain.current.domElement));
23
23
  }
24
24
  }, []);
25
- return (_jsx(KTXPlain, { ref: combined, ...attrs }));
25
+ return _jsx(KTXPlain, { ref: combined, ...attrs });
26
26
  });
@@ -0,0 +1,3 @@
1
+ export { KTX } from "./component";
2
+ export { KaTeXProvider } from "./context";
3
+ export { parseMacros } from "./macros";
@@ -1,6 +1,6 @@
1
1
  // option of loading KaTeX asynchronously
2
2
  const KaTeXLoad = new Promise((resolve) => {
3
- const script = document.querySelector("script[src*=\"katex.js\"], script[src*=\"katex.min.js\"]");
3
+ const script = document.querySelector('script[src*="katex.js"], script[src*="katex.min.js"]');
4
4
  if (!script)
5
5
  return;
6
6
  if (window.hasOwnProperty("katex")) {
@@ -14,13 +14,13 @@ const KaTeXLoad = new Promise((resolve) => {
14
14
  const KaTeXMacros = new Promise((resolve) => {
15
15
  const macros = {};
16
16
  const scripts = Array.from(document.querySelectorAll("head > script[type='math/tex']"));
17
- return Promise.all(scripts.map(script => fetch(script.src)
18
- .then(res => {
17
+ return Promise.all(scripts.map((script) => fetch(script.src)
18
+ .then((res) => {
19
19
  if (res.ok)
20
20
  return res.text();
21
21
  throw new Error(`${res.status} ${res.statusText}: ${script.src}`);
22
22
  })
23
- .then(tex => {
23
+ .then((tex) => {
24
24
  Object.assign(macros, parseMacros(tex));
25
25
  }))).then(() => resolve(macros));
26
26
  });
@@ -32,16 +32,16 @@ export const KaTeXReady = Promise.all([KaTeXLoad, KaTeXMacros]);
32
32
  * Parse \newcommand macros in a file.
33
33
  * Also supports \ktxnewcommand (for use in conjunction with MathJax).
34
34
  * @param file TeX file to parse
35
- */
35
+ */
36
36
  function parseMacros(file) {
37
37
  const macros = {};
38
38
  const rgx = /\\(?:ktx)?newcommand\{(.+?)\}(?:\[\d+\])?\{/g;
39
39
  let match;
40
- while (match = rgx.exec(file)) {
40
+ while ((match = rgx.exec(file))) {
41
41
  let body = "";
42
42
  const macro = match[1];
43
43
  let braceCount = 1;
44
- for (let i = match.index + match[0].length; (braceCount > 0) && (i < file.length); ++i) {
44
+ for (let i = match.index + match[0].length; braceCount > 0 && i < file.length; ++i) {
45
45
  const char = file[i];
46
46
  if (char === "{") {
47
47
  braceCount++;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Parse \newcommand macros in a file.
3
+ * Also supports \ktxnewcommand (for use in conjunction with MathJax).
4
+ * @param file TeX file to parse
5
+ */
6
+ export function parseMacros(file) {
7
+ const macros = {};
8
+ const rgx = /\\(?:ktx)?newcommand\{(.+?)\}(?:\[\d+\])?\{/g;
9
+ let match;
10
+ // biome-ignore lint/suspicious/noAssignInExpressions: this is fine
11
+ while ((match = rgx.exec(file))) {
12
+ let body = "";
13
+ const macro = match[1];
14
+ let braceCount = 1;
15
+ for (let i = match.index + match[0].length; braceCount > 0 && i < file.length; ++i) {
16
+ const char = file[i];
17
+ if (char === "{") {
18
+ braceCount++;
19
+ }
20
+ else if (char === "}") {
21
+ braceCount--;
22
+ if (braceCount === 0)
23
+ break;
24
+ }
25
+ else if (char === "\\") {
26
+ body += file.slice(i, i + 2);
27
+ ++i;
28
+ continue;
29
+ }
30
+ body += char;
31
+ }
32
+ macros[macro] = body;
33
+ }
34
+ return macros;
35
+ }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { usePromise } from "@liqvid/utils/react";
3
3
  import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
4
- import { KaTeXReady } from "./loading.mjs";
4
+ import { KaTeXReady } from "./loading";
5
5
  /** Component for KaTeX code */
6
6
  export const KTX = forwardRef(function KTX(props, ref) {
7
7
  const spanRef = useRef();
@@ -10,7 +10,7 @@ export const KTX = forwardRef(function KTX(props, ref) {
10
10
  // handle
11
11
  useImperativeHandle(ref, () => ({
12
12
  domElement: spanRef.current,
13
- ready
13
+ ready,
14
14
  }));
15
15
  useEffect(() => {
16
16
  KaTeXReady.then(([katex, macros]) => {
@@ -19,7 +19,7 @@ export const KTX = forwardRef(function KTX(props, ref) {
19
19
  macros,
20
20
  strict: "ignore",
21
21
  throwOnError: false,
22
- trust: true
22
+ trust: true,
23
23
  });
24
24
  /* move katex into placeholder element */
25
25
  const child = spanRef.current.firstElementChild;
@@ -43,5 +43,5 @@ export const KTX = forwardRef(function KTX(props, ref) {
43
43
  attrs.style = {};
44
44
  attrs.style.display = "block";
45
45
  }
46
- return (_jsx("span", { ...attrs, ref: spanRef }));
46
+ return _jsx("span", { ...attrs, ref: spanRef });
47
47
  });
@@ -0,0 +1 @@
1
+ {"fileNames":["../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/.pnpm/@types+react@19.2.14/node_modules/@types/react/global.d.ts","../../../node_modules/.pnpm/csstype@3.2.3/node_modules/csstype/index.d.ts","../../../node_modules/.pnpm/@types+react@19.2.14/node_modules/@types/react/index.d.ts","../../../node_modules/.pnpm/@types+react@19.2.14/node_modules/@types/react/jsx-runtime.d.ts","../../duration/dist/types/index.d.mts","../../../node_modules/.pnpm/bezier-easing@2.1.0/node_modules/bezier-easing/src/index.d.ts","../../utils/dist/types/replay-data.d.ts","../../utils/dist/types/animation.d.ts","../../utils/dist/types/collections.d.ts","../../utils/dist/types/interaction.d.ts","../../utils/dist/types/math.d.ts","../../utils/dist/types/misc.d.ts","../../utils/dist/types/react.d.ts","../../utils/dist/types/svg.d.ts","../../utils/dist/types/time.d.ts","../../utils/dist/types/types.d.ts","../../utils/dist/types/index.d.ts","../../../node_modules/.pnpm/katex@0.16.28/node_modules/katex/types/katex.d.ts","../src/macros.ts","../src/context.tsx","../src/component.tsx","../src/index.ts","../../../node_modules/.pnpm/@types+katex@0.16.8/node_modules/@types/katex/index.d.ts"],"fileIdsList":[[60,61],[62],[62,63,76,77,79],[62,63,78],[63,78,79,80],[63],[64,65,66],[66,67,68,69,70,71,72,73,74,75],[69],[64]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","impliedFormat":1},{"version":"ee7bad0c15b58988daa84371e0b89d313b762ab83cb5b31b8a2d1162e8eb41c2","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"2e80ee7a49e8ac312cc11b77f1475804bee36b3b2bc896bead8b6e1266befb43","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"a680117f487a4d2f30ea46f1b4b7f58bef1480456e18ba53ee85c2746eeca012","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"d6d7ae4d1f1f3772e2a3cde568ed08991a8ae34a080ff1151af28b7f798e22ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true,"impliedFormat":1},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true,"impliedFormat":1},{"version":"959d36cddf5e7d572a65045b876f2956c973a586da58e5d26cde519184fd9b8a","affectsGlobalScope":true,"impliedFormat":1},{"version":"965f36eae237dd74e6cca203a43e9ca801ce38824ead814728a2807b1910117d","affectsGlobalScope":true,"impliedFormat":1},{"version":"3925a6c820dcb1a06506c90b1577db1fdbf7705d65b62b99dce4be75c637e26b","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a3d63ef2b853447ec4f749d3f368ce642264246e02911fcb1590d8c161b8005","affectsGlobalScope":true,"impliedFormat":1},{"version":"8cdf8847677ac7d20486e54dd3fcf09eda95812ac8ace44b4418da1bbbab6eb8","affectsGlobalScope":true,"impliedFormat":1},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true,"impliedFormat":1},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true,"impliedFormat":1},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"7e29f41b158de217f94cb9676bf9cbd0cd9b5a46e1985141ed36e075c52bf6ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac51dd7d31333793807a6abaa5ae168512b6131bd41d9c5b98477fc3b7800f9f","impliedFormat":1},{"version":"dc0a7f107690ee5cd8afc8dbf05c4df78085471ce16bdd9881642ec738bc81fe","impliedFormat":1},{"version":"42c169fb8c2d42f4f668c624a9a11e719d5d07dacbebb63cbcf7ef365b0a75b3","impliedFormat":1},{"version":"6f2dfeeb74d340004f68f576add21aac0668ae1da4c4e9ba3193541f3e865867","impliedFormat":99},{"version":"5e221d7876afbd3b808798515c5dd53d49e8aa4fe4c6095bc6760b30acff4b37","impliedFormat":1},"3ec9f283a3eb75a2fb4a89467a97ae6d13d3cd7589dadb5e1e5b59a875e6f6c9","fc7857b603145340e3bdd87e48603b1dbee90bcdee7d4d08006b40c613cdcd4e","06f5a3f26c2c2dddab05df1375db0a6353efa4bcd818d53e0bbde7b94024d732",{"version":"8005021af1514f4193c860c4b7eeb2f01f660c443c2f7180f2c93aed44af3b16","affectsGlobalScope":true},"2b0dafed8302e979ebbee421ac05e790ee5621457a264cb1b8e76ef3afd72f3b","7f8b57b8dd275f27fc63e58f9f0d608054060cd7f2d57a3bc53653c39f6326e3","a5910106a85d7077f899ee12fb89fed65a3b8aaa444a314a0e1480a29f4e67b8","69eaf11c5a8479bc92d32da085bfb9cba8ca6884366b4941369a4d24a27992c6","eca06e9eb6ebd0a81decc4d04aa1d0df7a2e6cb4588c3059269321c9e0fecc09","239f3c704fc87252b5dd00f70e35bc57af83a33e20a3ad71d14c3d2d99c3b4a4","3db60448ebc41502a9869dd39a4a6a3682ca9b5fcb8297399676fea8c88b7678",{"version":"5bb37c8ed3d343ae525902e64be52edbc1ce0a5ad86ca2201118c0d8168078e5","impliedFormat":1},{"version":"04daa14a7096f21f0bd4cce3d03b334d936e9171887bf54726d27cb8a40617c1","signature":"07fbf982cc4f8de23b1a36da934e268ddfcc29b536d87bb6e66ddee1d65d728e"},{"version":"fcdab0036032c5ec6b9d0dd5bf45d5227171dd3949fbf04cecbe4dd01cc144d2","signature":"4116da3cb2ef452323b10b8759b5585d3b4aee337440742743106a0a11f660f3"},{"version":"55d9af754a8f252f8a58f61f62c27b8fbd81770e2039cbc51d61e960bd0459d9","signature":"665cad1d49d7d95b1cc6627d1adb840433b4ff5f58b629b5f905fc3e36d38008"},"5348fc7edceeb42a436a769d8a8434fd0af1f87a88a4141662009b126a05ef7b",{"version":"8cbbb12bfb321de8bd58ba74329f683d82e4e0abb56d998c7f1eef2e764a74c8","impliedFormat":1}],"root":[[78,81]],"options":{"alwaysStrict":true,"composite":true,"declaration":true,"declarationDir":"./types","esModuleInterop":true,"jsx":4,"module":99,"noImplicitAny":true,"noImplicitOverride":true,"noUncheckedIndexedAccess":false,"outDir":"./esm","removeComments":false,"rewriteRelativeImportExtensions":true,"rootDir":"../src","skipLibCheck":true,"strict":true,"target":9,"verbatimModuleSyntax":true},"referencedMap":[[62,1],[63,2],[80,3],[79,4],[81,5],[78,6],[67,7],[76,8],[72,9],[74,10]],"latestChangedDtsFile":"./types/index.d.ts","version":"5.9.3"}
@@ -9,11 +9,11 @@ interface Props {
9
9
  /**
10
10
  * Whether to reparse descendants for `during()` and `from()`
11
11
  * @default false
12
- */
12
+ */
13
13
  reparse?: boolean;
14
14
  }
15
15
  /**
16
16
  * Wait for several things to be rendered
17
- */
17
+ */
18
18
  export declare const RenderGroup: React.ForwardRefExoticComponent<Props & React.RefAttributes<Handle>>;
19
19
  export {};
@@ -0,0 +1,4 @@
1
+ /** Component for KaTeX code */
2
+ export declare const KTX: ({ children, ref: propRef, colorIsTextColor, displayMode, errorColor, fleqn, globalGroup, leqno, macros, maxExpand, maxSize, minRuleThickness, output, strict, throwOnError, trust, ...props }: katex.KatexOptions & React.JSX.IntrinsicElements["span"] & {
3
+ children: string;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ export declare function useKaTeXContext(): import("katex").KatexOptions;
2
+ export declare function KaTeXProvider({ children, colorIsTextColor, displayMode, errorColor, fleqn, globalGroup, leqno, macros, maxExpand, maxSize, minRuleThickness, output, strict, throwOnError, trust, }: {
3
+ children?: React.ReactNode;
4
+ macros?: string | Record<string, string>;
5
+ } & katex.KatexOptions): import("react/jsx-runtime").JSX.Element;
@@ -1,17 +1,16 @@
1
- /// <reference types="react" />
2
1
  import { Handle, KTX as KTXPlain } from "./plain";
3
2
  interface Props extends React.ComponentProps<typeof KTXPlain> {
4
3
  /**
5
4
  * Player events to obstruct
6
5
  * @default "canplay canplaythrough"
7
- */
6
+ */
8
7
  obstruct?: string;
9
8
  /**
10
9
  * Whether to reparse descendants for `during()` and `from()`
11
10
  * @default false
12
- */
11
+ */
13
12
  reparse?: boolean;
14
13
  }
15
14
  /** Component for KaTeX code */
16
- export declare const KTX: import("react").ForwardRefExoticComponent<Pick<Props, "key" | "id" | "color" | "display" | "translate" | "hidden" | "dir" | "slot" | "style" | "title" | "accessKey" | "draggable" | "lang" | "className" | "prefix" | "children" | "contentEditable" | "inputMode" | "tabIndex" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "obstruct" | "reparse"> & import("react").RefAttributes<Handle>>;
15
+ export declare const KTX: import("react").ForwardRefExoticComponent<Omit<Props, "ref"> & import("react").RefAttributes<Handle>>;
17
16
  export {};
@@ -1,7 +1,3 @@
1
- export { KTX } from "./fancy";
2
- export { KaTeXReady } from "./loading";
3
- export { Handle } from "./plain";
4
- export { RenderGroup } from "./RenderGroup";
5
- declare global {
6
- const katex: typeof katex;
7
- }
1
+ export { KTX } from "./component";
2
+ export { KaTeXProvider } from "./context";
3
+ export { parseMacros } from "./macros";
@@ -1,6 +1,4 @@
1
1
  /**
2
2
  * Ready Promise
3
3
  */
4
- export declare const KaTeXReady: Promise<[typeof import("katex"), {
5
- [key: string]: string;
6
- }]>;
4
+ export declare const KaTeXReady: Promise<any>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Parse \newcommand macros in a file.
3
+ * Also supports \ktxnewcommand (for use in conjunction with MathJax).
4
+ * @param file TeX file to parse
5
+ */
6
+ export declare function parseMacros(file: string): Record<string, string>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * KTX element API
4
3
  */
package/package.json CHANGED
@@ -1,18 +1,14 @@
1
1
  {
2
2
  "name": "@liqvid/katex",
3
- "version": "0.1.0",
3
+ "version": "1.0.0-alpha.0",
4
4
  "description": "KaTeX integration for Liqvid",
5
5
  "files": [
6
6
  "dist/*"
7
7
  ],
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./dist/esm/index.mjs",
11
- "require": "./dist/cjs/index.cjs"
12
- },
13
- "./plain": {
14
- "import": "./dist/esm/plain.mjs",
15
- "require": "./dist/cjs/plain.cjs"
10
+ "import": "./dist/esm/index.js",
11
+ "types": "./dist/types/index.d.ts"
16
12
  }
17
13
  },
18
14
  "typesVersions": {
@@ -36,31 +32,34 @@
36
32
  },
37
33
  "homepage": "https://github.com/liqvidjs/liqvid/tree/main/packages/katex",
38
34
  "license": "MIT",
35
+ "dependencies": {
36
+ "@liqvid/utils": "^2.0.0-alpha.2"
37
+ },
38
+ "devDependencies": {
39
+ "@biomejs/biome": "2.4.8",
40
+ "@types/react": "^19",
41
+ "typescript": "^5.9",
42
+ "@liqvid/player": "^1.0.0-alpha.1"
43
+ },
39
44
  "peerDependencies": {
40
- "@types/katex": ">=0.14.0",
41
- "@types/react": ">=18.0.0",
42
- "liqvid": "^2.1.7",
43
- "react": ">=18.1.0"
45
+ "katex": ">=0.16",
46
+ "@types/react": ">=18",
47
+ "@liqvid/player": "^1.0.0-alpha.0",
48
+ "react": ">=18"
44
49
  },
45
50
  "peerDependenciesMeta": {
46
- "liqvid": {
51
+ "@liqvid/player": {
47
52
  "optional": true
48
53
  }
49
54
  },
50
- "devDependencies": {
51
- "liqvid": "^2.1.7"
52
- },
53
- "dependencies": {
54
- "@liqvid/utils": "^1.6.0"
55
- },
56
55
  "sideEffects": false,
57
56
  "type": "module",
58
57
  "scripts": {
59
58
  "build": "pnpm build:clean && pnpm build:js && pnpm build:postclean",
60
59
  "build:clean": "rm -rf dist",
61
- "build:js": "tsc --module esnext --outDir dist/esm; tsc --module commonjs --outDir dist/cjs; node ../../build.mjs",
60
+ "build:js": "tsc",
62
61
  "build:postclean": "rm dist/tsconfig.tsbuildinfo",
63
- "lint": "eslint --ext ts,tsx --fix src"
64
- },
65
- "readme": "# @liqvid/katex\n\n[KaTeX](https://katex.org/) integration for [Liqvid](https://liqvidjs.org). See https://liqvidjs.org/docs/integrations/katex/ for documentation.\n"
62
+ "lint": "biome check --fix",
63
+ "watch": "tsc --watch"
64
+ }
66
65
  }
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RenderGroup = void 0;
4
- const react_1 = require("@liqvid/utils/react");
5
- const liqvid_1 = require("liqvid");
6
- const react_2 = require("react");
7
- const fancy_1 = require("./fancy.cjs");
8
- const plain_1 = require("./plain.cjs");
9
- /**
10
- * Wait for several things to be rendered
11
- */
12
- exports.RenderGroup = (0, react_2.forwardRef)(function RenderGroup(props, ref) {
13
- const [ready, resolve] = (0, react_1.usePromise)();
14
- // handle
15
- (0, react_2.useImperativeHandle)(ref, () => ({ ready }));
16
- const elements = (0, react_2.useRef)([]);
17
- const promises = (0, react_2.useRef)([]);
18
- // reparsing
19
- const player = (0, liqvid_1.usePlayer)();
20
- (0, react_2.useEffect)(() => {
21
- // promises
22
- Promise.all(promises.current).then(() => {
23
- // reparse
24
- if (props.reparse) {
25
- player.reparseTree(leastCommonAncestor(elements.current));
26
- }
27
- // ready()
28
- resolve();
29
- });
30
- }, []);
31
- return (0, react_1.recursiveMap)(props.children, node => {
32
- if (shouldInspect(node)) {
33
- const originalRef = node.ref;
34
- return (0, react_2.cloneElement)(node, {
35
- ref: (ref) => {
36
- if (!ref)
37
- return;
38
- elements.current.push(ref.domElement);
39
- promises.current.push(ref.ready);
40
- // pass along original ref
41
- if (typeof originalRef === "function") {
42
- originalRef(ref);
43
- }
44
- else if (originalRef && typeof originalRef === "object") {
45
- originalRef.current = ref;
46
- }
47
- }
48
- });
49
- }
50
- return node;
51
- });
52
- });
53
- /**
54
- * Determine whether the node is a <KTX> element
55
- * @param node Element to check
56
- */
57
- function shouldInspect(node) {
58
- return (0, react_2.isValidElement)(node) && typeof node.type === "object" && (node.type === fancy_1.KTX || node.type === plain_1.KTX);
59
- }
60
- /**
61
- * Find least common ancestor of an array of elements
62
- * @param elements Elements
63
- * @returns Deepest node containing all passed elements
64
- */
65
- function leastCommonAncestor(elements) {
66
- if (elements.length === 0) {
67
- throw new Error("Must pass at least one element");
68
- }
69
- let ancestor = elements[0];
70
- let failing = elements.slice(1);
71
- while (failing.length > 0) {
72
- ancestor = ancestor.parentElement;
73
- failing = failing.filter(node => !ancestor.contains(node));
74
- }
75
- return ancestor;
76
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KTX = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("@liqvid/utils/react");
6
- const liqvid_1 = require("liqvid");
7
- const react_2 = require("react");
8
- const plain_1 = require("./plain.cjs");
9
- /** Component for KaTeX code */
10
- exports.KTX = (0, react_2.forwardRef)(function KTX(props, ref) {
11
- const { obstruct = "canplay canplaythrough", reparse = false, ...attrs } = props;
12
- const plain = (0, react_2.useRef)();
13
- const combined = (0, react_1.combineRefs)(plain, ref);
14
- const player = (0, liqvid_1.usePlayer)();
15
- (0, react_2.useEffect)(() => {
16
- // obstruction
17
- if (obstruct.match(/\bcanplay\b/)) {
18
- player.obstruct("canplay", plain.current.ready);
19
- }
20
- if (obstruct.match("canplaythrough")) {
21
- player.obstruct("canplaythrough", plain.current.ready);
22
- }
23
- // reparsing
24
- if (reparse) {
25
- plain.current.ready.then(() => player.reparseTree(plain.current.domElement));
26
- }
27
- }, []);
28
- return ((0, jsx_runtime_1.jsx)(plain_1.KTX, { ref: combined, ...attrs }));
29
- });
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RenderGroup = exports.KaTeXReady = exports.KTX = void 0;
4
- var fancy_1 = require("./fancy.cjs");
5
- Object.defineProperty(exports, "KTX", { enumerable: true, get: function () { return fancy_1.KTX; } });
6
- var loading_1 = require("./loading.cjs");
7
- Object.defineProperty(exports, "KaTeXReady", { enumerable: true, get: function () { return loading_1.KaTeXReady; } });
8
- var RenderGroup_1 = require("./RenderGroup.cjs");
9
- Object.defineProperty(exports, "RenderGroup", { enumerable: true, get: function () { return RenderGroup_1.RenderGroup; } });
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KaTeXReady = void 0;
4
- // option of loading KaTeX asynchronously
5
- const KaTeXLoad = new Promise((resolve) => {
6
- const script = document.querySelector("script[src*=\"katex.js\"], script[src*=\"katex.min.js\"]");
7
- if (!script)
8
- return;
9
- if (window.hasOwnProperty("katex")) {
10
- resolve(katex);
11
- }
12
- else {
13
- script.addEventListener("load", () => resolve(katex));
14
- }
15
- });
16
- // load macros from <head>
17
- const KaTeXMacros = new Promise((resolve) => {
18
- const macros = {};
19
- const scripts = Array.from(document.querySelectorAll("head > script[type='math/tex']"));
20
- return Promise.all(scripts.map(script => fetch(script.src)
21
- .then(res => {
22
- if (res.ok)
23
- return res.text();
24
- throw new Error(`${res.status} ${res.statusText}: ${script.src}`);
25
- })
26
- .then(tex => {
27
- Object.assign(macros, parseMacros(tex));
28
- }))).then(() => resolve(macros));
29
- });
30
- /**
31
- * Ready Promise
32
- */
33
- exports.KaTeXReady = Promise.all([KaTeXLoad, KaTeXMacros]);
34
- /**
35
- * Parse \newcommand macros in a file.
36
- * Also supports \ktxnewcommand (for use in conjunction with MathJax).
37
- * @param file TeX file to parse
38
- */
39
- function parseMacros(file) {
40
- const macros = {};
41
- const rgx = /\\(?:ktx)?newcommand\{(.+?)\}(?:\[\d+\])?\{/g;
42
- let match;
43
- while (match = rgx.exec(file)) {
44
- let body = "";
45
- const macro = match[1];
46
- let braceCount = 1;
47
- for (let i = match.index + match[0].length; (braceCount > 0) && (i < file.length); ++i) {
48
- const char = file[i];
49
- if (char === "{") {
50
- braceCount++;
51
- }
52
- else if (char === "}") {
53
- braceCount--;
54
- if (braceCount === 0)
55
- break;
56
- }
57
- else if (char === "\\") {
58
- body += file.slice(i, i + 2);
59
- ++i;
60
- continue;
61
- }
62
- body += char;
63
- }
64
- macros[macro] = body;
65
- }
66
- return macros;
67
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KTX = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("@liqvid/utils/react");
6
- const react_2 = require("react");
7
- const loading_1 = require("./loading.cjs");
8
- /** Component for KaTeX code */
9
- exports.KTX = (0, react_2.forwardRef)(function KTX(props, ref) {
10
- const spanRef = (0, react_2.useRef)();
11
- const { children, display = false, ...attrs } = props;
12
- const [ready, resolve] = (0, react_1.usePromise)();
13
- // handle
14
- (0, react_2.useImperativeHandle)(ref, () => ({
15
- domElement: spanRef.current,
16
- ready
17
- }));
18
- (0, react_2.useEffect)(() => {
19
- loading_1.KaTeXReady.then(([katex, macros]) => {
20
- katex.render(children.toString(), spanRef.current, {
21
- displayMode: !!display,
22
- macros,
23
- strict: "ignore",
24
- throwOnError: false,
25
- trust: true
26
- });
27
- /* move katex into placeholder element */
28
- const child = spanRef.current.firstElementChild;
29
- // copy classes
30
- for (let i = 0, len = child.classList.length; i < len; ++i) {
31
- spanRef.current.classList.add(child.classList.item(i));
32
- }
33
- // move children
34
- while (child.childNodes.length > 0) {
35
- spanRef.current.appendChild(child.firstChild);
36
- }
37
- // delete child
38
- child.remove();
39
- // resolve promise
40
- resolve();
41
- });
42
- }, [children]);
43
- // Google Chrome fails without this
44
- if (display) {
45
- if (!attrs.style)
46
- attrs.style = {};
47
- attrs.style.display = "block";
48
- }
49
- return ((0, jsx_runtime_1.jsx)("span", { ...attrs, ref: spanRef }));
50
- });
@@ -1,3 +0,0 @@
1
- export { KTX } from "./fancy.mjs";
2
- export { KaTeXReady } from "./loading.mjs";
3
- export { RenderGroup } from "./RenderGroup.mjs";