@gofreego/tsutils 0.1.10 → 0.1.12

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.
package/dist/index.mjs CHANGED
@@ -5,6 +5,9 @@ import { BrowserRouter, useLocation, Routes, Route, Outlet, NavLink } from 'reac
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import ReactMarkdown from 'react-markdown';
7
7
  import remarkGfm from 'remark-gfm';
8
+ import remarkMath from 'remark-math';
9
+ import rehypeKatex from 'rehype-katex';
10
+ import 'katex/dist/katex.min.css';
8
11
  import ContentCopyIcon from '@mui/icons-material/ContentCopy';
9
12
  import CheckIcon from '@mui/icons-material/Check';
10
13
  import { createHighlighter } from 'shiki';
@@ -390,7 +393,7 @@ var getHighlighter = async () => {
390
393
  }
391
394
  highlighterPromise = createHighlighter({
392
395
  themes: ["github-light", "github-dark"],
393
- langs: ["js", "ts", "go", "json", "bash", "yaml", "md", "python", "java", "cpp", "c", "html", "css", "sql"]
396
+ langs: ["js", "ts", "go", "json", "bash", "yaml", "md", "python", "java", "cpp", "c", "html", "css", "sql", "http", "text"]
394
397
  }).then((highlighter) => {
395
398
  highlighterInstance = highlighter;
396
399
  return highlighter;
@@ -400,8 +403,10 @@ var getHighlighter = async () => {
400
403
  var ReadmeViewer = ({
401
404
  content,
402
405
  className = "",
403
- isDark = false
406
+ isDark: propIsDark,
407
+ muiTheme
404
408
  }) => {
409
+ const isDark = propIsDark !== void 0 ? propIsDark : muiTheme?.palette?.mode === "dark";
405
410
  const [highlighter, setHighlighter] = useState(null);
406
411
  const [copiedBlocks, setCopiedBlocks] = useState(/* @__PURE__ */ new Set());
407
412
  useEffect(() => {
@@ -422,70 +427,85 @@ var ReadmeViewer = ({
422
427
  console.error("Failed to copy text: ", err);
423
428
  }
424
429
  };
425
- return /* @__PURE__ */ jsx("div", { className: `readme-viewer markdown-body ${className}`, children: /* @__PURE__ */ jsx(
426
- ReactMarkdown,
427
- {
428
- remarkPlugins: [remarkGfm],
429
- components: {
430
- code({ className: className2, children, ...props }) {
431
- const match = /language-(\w+)/.exec(className2 || "");
432
- if (match && highlighter) {
433
- const codeText = String(children).replace(/\n$/, "");
434
- const blockId = `code-${Math.random().toString(36).substr(2, 9)}`;
435
- return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
436
- /* @__PURE__ */ jsx(
437
- "div",
438
- {
439
- dangerouslySetInnerHTML: {
440
- __html: highlighter.codeToHtml(
441
- codeText,
442
- {
443
- lang: match[1],
444
- theme: isDark ? "github-dark" : "github-light"
445
- }
446
- )
447
- }
448
- }
449
- ),
450
- /* @__PURE__ */ jsx(
451
- "button",
452
- {
453
- onClick: () => copyToClipboard(codeText, blockId),
454
- style: {
455
- position: "absolute",
456
- top: "8px",
457
- right: "8px",
458
- backgroundColor: "var(--md-sys-color-surface-container-high)",
459
- border: "1px solid var(--md-sys-color-outline-variant)",
460
- borderRadius: "4px",
461
- padding: "6px",
462
- fontSize: "14px",
463
- cursor: "pointer",
464
- color: "var(--md-sys-color-on-surface-variant)",
465
- alignItems: "center",
466
- justifyContent: "center",
467
- transition: "all 0.2s ease",
468
- width: "32px",
469
- height: "32px"
470
- },
471
- onMouseEnter: (e) => {
472
- e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-highest)" : "var(--md-sys-color-surface-container-high)";
473
- },
474
- onMouseLeave: (e) => {
475
- e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-high)" : "var(--md-sys-color-surface-container-highest)";
476
- },
477
- title: copiedBlocks.has(blockId) ? "Copied!" : "Copy code",
478
- children: copiedBlocks.has(blockId) ? /* @__PURE__ */ jsx(CheckIcon, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsx(ContentCopyIcon, { style: { fontSize: "16px" } })
430
+ return /* @__PURE__ */ jsxs("div", { className: `readme-viewer markdown-body ${className}`, children: [
431
+ /* @__PURE__ */ jsx("style", { children: `
432
+ .shiki-wrapper pre.shiki {
433
+ padding: 16px !important;
434
+ border-radius: 8px !important;
435
+ overflow-x: auto;
436
+ margin-bottom: 16px;
437
+ border: 1px solid var(--md-sys-color-outline-variant, #e0e0e0);
438
+ }
439
+ ` }),
440
+ /* @__PURE__ */ jsx(
441
+ ReactMarkdown,
442
+ {
443
+ remarkPlugins: [remarkGfm, remarkMath],
444
+ rehypePlugins: [rehypeKatex],
445
+ components: {
446
+ code({ className: className2, children, ...props }) {
447
+ const match = /language-(\w+)/.exec(className2 || "");
448
+ if (match && highlighter) {
449
+ const codeText = String(children).replace(/\n$/, "");
450
+ const blockId = `code-${Math.random().toString(36).substr(2, 9)}`;
451
+ let highlightedHtml = "";
452
+ try {
453
+ highlightedHtml = highlighter.codeToHtml(codeText, {
454
+ lang: match[1],
455
+ theme: isDark ? "github-dark" : "github-light"
456
+ });
457
+ } catch (e) {
458
+ try {
459
+ highlightedHtml = highlighter.codeToHtml(codeText, {
460
+ lang: "text",
461
+ theme: isDark ? "github-dark" : "github-light"
462
+ });
463
+ } catch (fallbackError) {
464
+ highlightedHtml = `<pre><code>${codeText}</code></pre>`;
479
465
  }
480
- )
481
- ] });
466
+ }
467
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
468
+ /* @__PURE__ */ jsx("div", { className: "shiki-wrapper", dangerouslySetInnerHTML: { __html: highlightedHtml } }),
469
+ /* @__PURE__ */ jsx(
470
+ "button",
471
+ {
472
+ onClick: () => copyToClipboard(codeText, blockId),
473
+ style: {
474
+ position: "absolute",
475
+ top: "8px",
476
+ right: "8px",
477
+ backgroundColor: "var(--md-sys-color-surface-container-high)",
478
+ border: "1px solid var(--md-sys-color-outline-variant)",
479
+ borderRadius: "4px",
480
+ padding: "6px",
481
+ fontSize: "14px",
482
+ cursor: "pointer",
483
+ color: "var(--md-sys-color-on-surface-variant)",
484
+ alignItems: "center",
485
+ justifyContent: "center",
486
+ transition: "all 0.2s ease",
487
+ width: "32px",
488
+ height: "32px"
489
+ },
490
+ onMouseEnter: (e) => {
491
+ e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-highest)" : "var(--md-sys-color-surface-container-high)";
492
+ },
493
+ onMouseLeave: (e) => {
494
+ e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-high)" : "var(--md-sys-color-surface-container-highest)";
495
+ },
496
+ title: copiedBlocks.has(blockId) ? "Copied!" : "Copy code",
497
+ children: copiedBlocks.has(blockId) ? /* @__PURE__ */ jsx(CheckIcon, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsx(ContentCopyIcon, { style: { fontSize: "16px" } })
498
+ }
499
+ )
500
+ ] });
501
+ }
502
+ return /* @__PURE__ */ jsx("code", { className: className2, ...props, children });
482
503
  }
483
- return /* @__PURE__ */ jsx("code", { className: className2, ...props, children });
484
- }
485
- },
486
- children: content
487
- }
488
- ) });
504
+ },
505
+ children: content
506
+ }
507
+ )
508
+ ] });
489
509
  };
490
510
  var ReadmeViewer_default = ReadmeViewer;
491
511
  var NotificationContext = createContext(void 0);
@@ -574,13 +594,13 @@ var ConfirmDialog = ({
574
594
  onConfirm,
575
595
  onCancel
576
596
  }) => {
577
- return /* @__PURE__ */ jsxs(Dialog, { open, onClose: onCancel, maxWidth: "xs", fullWidth: true, children: [
597
+ return /* @__PURE__ */ jsxs(Dialog, { open, onClose: onCancel, maxWidth: "xs", fullWidth: true, slotProps: { paper: { sx: { borderRadius: 4 } } }, children: [
578
598
  /* @__PURE__ */ jsx(DialogTitle, { children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
579
599
  /* @__PURE__ */ jsx(WarningAmberIcon, { color: confirmColor }),
580
600
  title
581
601
  ] }) }),
582
602
  /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(Typography, { variant: "body1", children: message }) }),
583
- /* @__PURE__ */ jsxs(DialogActions, { children: [
603
+ /* @__PURE__ */ jsxs(DialogActions, { sx: { px: 3, pb: 2 }, children: [
584
604
  /* @__PURE__ */ jsx(Button, { onClick: onCancel, variant: "outlined", children: cancelText }),
585
605
  /* @__PURE__ */ jsx(Button, { onClick: onConfirm, variant: "contained", color: confirmColor, autoFocus: true, children: confirmText })
586
606
  ] })