@liqvid/katex 0.0.5 → 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.
@@ -0,0 +1,75 @@
1
+ import { recursiveMap, usePromise } from "@liqvid/utils/react";
2
+ import { usePlayer } from "liqvid";
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
+ /**
7
+ * Wait for several things to be rendered
8
+ */
9
+ export const RenderGroup = forwardRef(function RenderGroup(props, ref) {
10
+ const [ready, resolve] = usePromise();
11
+ // handle
12
+ useImperativeHandle(ref, () => ({ ready }));
13
+ const elements = useRef([]);
14
+ const promises = useRef([]);
15
+ // reparsing
16
+ const player = usePlayer();
17
+ useEffect(() => {
18
+ // promises
19
+ Promise.all(promises.current).then(() => {
20
+ // reparse
21
+ if (props.reparse) {
22
+ player.reparseTree(leastCommonAncestor(elements.current));
23
+ }
24
+ // ready()
25
+ resolve();
26
+ });
27
+ }, []);
28
+ return recursiveMap(props.children, (node) => {
29
+ if (shouldInspect(node)) {
30
+ const originalRef = node.ref;
31
+ return cloneElement(node, {
32
+ ref: (ref) => {
33
+ if (!ref)
34
+ return;
35
+ elements.current.push(ref.domElement);
36
+ promises.current.push(ref.ready);
37
+ // pass along original ref
38
+ if (typeof originalRef === "function") {
39
+ originalRef(ref);
40
+ }
41
+ else if (originalRef && typeof originalRef === "object") {
42
+ originalRef.current = ref;
43
+ }
44
+ },
45
+ });
46
+ }
47
+ return node;
48
+ });
49
+ });
50
+ /**
51
+ * Determine whether the node is a <KTX> element
52
+ * @param node Element to check
53
+ */
54
+ function shouldInspect(node) {
55
+ return (isValidElement(node) &&
56
+ typeof node.type === "object" &&
57
+ (node.type === KTX || node.type === KTXPlain));
58
+ }
59
+ /**
60
+ * Find least common ancestor of an array of elements
61
+ * @param elements Elements
62
+ * @returns Deepest node containing all passed elements
63
+ */
64
+ function leastCommonAncestor(elements) {
65
+ if (elements.length === 0) {
66
+ throw new Error("Must pass at least one element");
67
+ }
68
+ let ancestor = elements[0];
69
+ let failing = elements.slice(1);
70
+ while (failing.length > 0) {
71
+ ancestor = ancestor.parentElement;
72
+ failing = failing.filter((node) => !ancestor.contains(node));
73
+ }
74
+ return ancestor;
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
+ }
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { combineRefs } from "@liqvid/utils/react";
3
+ import { usePlayer } from "liqvid";
4
+ import { forwardRef, useEffect, useRef } from "react";
5
+ import { Handle, KTX as KTXPlain } from "./plain";
6
+ /** Component for KaTeX code */
7
+ export const KTX = forwardRef(function KTX(props, ref) {
8
+ const { obstruct = "canplay canplaythrough", reparse = false, ...attrs } = props;
9
+ const plain = useRef();
10
+ const combined = combineRefs(plain, ref);
11
+ const player = usePlayer();
12
+ useEffect(() => {
13
+ // obstruction
14
+ if (obstruct.match(/\bcanplay\b/)) {
15
+ player.obstruct("canplay", plain.current.ready);
16
+ }
17
+ if (obstruct.match("canplaythrough")) {
18
+ player.obstruct("canplaythrough", plain.current.ready);
19
+ }
20
+ // reparsing
21
+ if (reparse) {
22
+ plain.current.ready.then(() => player.reparseTree(plain.current.domElement));
23
+ }
24
+ }, []);
25
+ return _jsx(KTXPlain, { ref: combined, ...attrs });
26
+ });
@@ -0,0 +1,3 @@
1
+ export { KTX } from "./component";
2
+ export { KaTeXProvider } from "./context";
3
+ export { parseMacros } from "./macros";
@@ -0,0 +1,64 @@
1
+ // option of loading KaTeX asynchronously
2
+ const KaTeXLoad = new Promise((resolve) => {
3
+ const script = document.querySelector('script[src*="katex.js"], script[src*="katex.min.js"]');
4
+ if (!script)
5
+ return;
6
+ if (window.hasOwnProperty("katex")) {
7
+ resolve(katex);
8
+ }
9
+ else {
10
+ script.addEventListener("load", () => resolve(katex));
11
+ }
12
+ });
13
+ // load macros from <head>
14
+ const KaTeXMacros = new Promise((resolve) => {
15
+ const macros = {};
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) => {
19
+ if (res.ok)
20
+ return res.text();
21
+ throw new Error(`${res.status} ${res.statusText}: ${script.src}`);
22
+ })
23
+ .then((tex) => {
24
+ Object.assign(macros, parseMacros(tex));
25
+ }))).then(() => resolve(macros));
26
+ });
27
+ /**
28
+ * Ready Promise
29
+ */
30
+ export const KaTeXReady = Promise.all([KaTeXLoad, KaTeXMacros]);
31
+ /**
32
+ * Parse \newcommand macros in a file.
33
+ * Also supports \ktxnewcommand (for use in conjunction with MathJax).
34
+ * @param file TeX file to parse
35
+ */
36
+ function parseMacros(file) {
37
+ const macros = {};
38
+ const rgx = /\\(?:ktx)?newcommand\{(.+?)\}(?:\[\d+\])?\{/g;
39
+ let match;
40
+ while ((match = rgx.exec(file))) {
41
+ let body = "";
42
+ const macro = match[1];
43
+ let braceCount = 1;
44
+ for (let i = match.index + match[0].length; braceCount > 0 && i < file.length; ++i) {
45
+ const char = file[i];
46
+ if (char === "{") {
47
+ braceCount++;
48
+ }
49
+ else if (char === "}") {
50
+ braceCount--;
51
+ if (braceCount === 0)
52
+ break;
53
+ }
54
+ else if (char === "\\") {
55
+ body += file.slice(i, i + 2);
56
+ ++i;
57
+ continue;
58
+ }
59
+ body += char;
60
+ }
61
+ macros[macro] = body;
62
+ }
63
+ return macros;
64
+ }
@@ -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
+ }
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { usePromise } from "@liqvid/utils/react";
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
4
+ import { KaTeXReady } from "./loading";
5
+ /** Component for KaTeX code */
6
+ export const KTX = forwardRef(function KTX(props, ref) {
7
+ const spanRef = useRef();
8
+ const { children, display = false, ...attrs } = props;
9
+ const [ready, resolve] = usePromise();
10
+ // handle
11
+ useImperativeHandle(ref, () => ({
12
+ domElement: spanRef.current,
13
+ ready,
14
+ }));
15
+ useEffect(() => {
16
+ KaTeXReady.then(([katex, macros]) => {
17
+ katex.render(children.toString(), spanRef.current, {
18
+ displayMode: !!display,
19
+ macros,
20
+ strict: "ignore",
21
+ throwOnError: false,
22
+ trust: true,
23
+ });
24
+ /* move katex into placeholder element */
25
+ const child = spanRef.current.firstElementChild;
26
+ // copy classes
27
+ for (let i = 0, len = child.classList.length; i < len; ++i) {
28
+ spanRef.current.classList.add(child.classList.item(i));
29
+ }
30
+ // move children
31
+ while (child.childNodes.length > 0) {
32
+ spanRef.current.appendChild(child.firstChild);
33
+ }
34
+ // delete child
35
+ child.remove();
36
+ // resolve promise
37
+ resolve();
38
+ });
39
+ }, [children]);
40
+ // Google Chrome fails without this
41
+ if (display) {
42
+ if (!attrs.style)
43
+ attrs.style = {};
44
+ attrs.style.display = "block";
45
+ }
46
+ return _jsx("span", { ...attrs, ref: spanRef });
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"}
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ /** RenderGroup element API */
3
+ interface Handle {
4
+ /** Promise that resolves once all KTX descendants have finished typesetting */
5
+ ready: Promise<void>;
6
+ }
7
+ interface Props {
8
+ children?: React.ReactNode;
9
+ /**
10
+ * Whether to reparse descendants for `during()` and `from()`
11
+ * @default false
12
+ */
13
+ reparse?: boolean;
14
+ }
15
+ /**
16
+ * Wait for several things to be rendered
17
+ */
18
+ export declare const RenderGroup: React.ForwardRefExoticComponent<Props & React.RefAttributes<Handle>>;
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;
@@ -0,0 +1,16 @@
1
+ import { Handle, KTX as KTXPlain } from "./plain";
2
+ interface Props extends React.ComponentProps<typeof KTXPlain> {
3
+ /**
4
+ * Player events to obstruct
5
+ * @default "canplay canplaythrough"
6
+ */
7
+ obstruct?: string;
8
+ /**
9
+ * Whether to reparse descendants for `during()` and `from()`
10
+ * @default false
11
+ */
12
+ reparse?: boolean;
13
+ }
14
+ /** Component for KaTeX code */
15
+ export declare const KTX: import("react").ForwardRefExoticComponent<Omit<Props, "ref"> & import("react").RefAttributes<Handle>>;
16
+ export {};
@@ -0,0 +1,3 @@
1
+ export { KTX } from "./component";
2
+ export { KaTeXProvider } from "./context";
3
+ export { parseMacros } from "./macros";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Ready Promise
3
+ */
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,10 +1,7 @@
1
- /// <reference types="react" />
2
- import * as react from 'react';
3
-
4
1
  /**
5
2
  * KTX element API
6
3
  */
7
- interface Handle {
4
+ export interface Handle {
8
5
  /** The underlying <span> element */
9
6
  domElement: HTMLSpanElement;
10
7
  /** Promise that resolves once typesetting is finished */
@@ -18,6 +15,5 @@ interface Props extends React.HTMLAttributes<HTMLSpanElement> {
18
15
  display?: boolean;
19
16
  }
20
17
  /** Component for KaTeX code */
21
- declare const KTX: react.ForwardRefExoticComponent<Props & react.RefAttributes<Handle>>;
22
-
23
- export { Handle, KTX };
18
+ export declare const KTX: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<Handle>>;
19
+ export {};
package/package.json CHANGED
@@ -1,24 +1,20 @@
1
1
  {
2
2
  "name": "@liqvid/katex",
3
- "version": "0.0.5",
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/index.mjs",
11
- "require": "./dist/index.cjs"
12
- },
13
- "./plain": {
14
- "import": "./dist/plain.mjs",
15
- "require": "./dist/plain.cjs"
10
+ "import": "./dist/esm/index.js",
11
+ "types": "./dist/types/index.d.ts"
16
12
  }
17
13
  },
18
14
  "typesVersions": {
19
15
  "*": {
20
16
  "*": [
21
- "./dist/*.d.ts"
17
+ "./dist/types/*.d.ts"
22
18
  ]
23
19
  }
24
20
  },
@@ -36,28 +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.11.1",
41
- "@types/react": ">=17.0.0",
42
- "liqvid": "^2.1.4",
43
- "react": ">=17.0.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.4"
52
- },
53
- "dependencies": {
54
- "@liqvid/utils": "^1.3.0"
55
- },
55
+ "sideEffects": false,
56
+ "type": "module",
56
57
  "scripts": {
57
58
  "build": "pnpm build:clean && pnpm build:js && pnpm build:postclean",
58
59
  "build:clean": "rm -rf dist",
59
- "build:js": "tsc && node ../../build.mjs && rollup -c",
60
- "build:postclean": "rm -rf dist/esm dist/types dist/tsconfig.tsbuildinfo",
61
- "lint": "eslint --ext ts,tsx --fix src"
60
+ "build:js": "tsc",
61
+ "build:postclean": "rm dist/tsconfig.tsbuildinfo",
62
+ "lint": "biome check --fix",
63
+ "watch": "tsc --watch"
62
64
  }
63
65
  }