@gofreego/tsutils 0.1.11 → 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.d.mts CHANGED
@@ -120,6 +120,7 @@ interface ReadmeViewerProps {
120
120
  content: string;
121
121
  className?: string;
122
122
  isDark?: boolean;
123
+ muiTheme?: any;
123
124
  }
124
125
  declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
125
126
 
package/dist/index.d.ts CHANGED
@@ -120,6 +120,7 @@ interface ReadmeViewerProps {
120
120
  content: string;
121
121
  className?: string;
122
122
  isDark?: boolean;
123
+ muiTheme?: any;
123
124
  }
124
125
  declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
125
126
 
package/dist/index.js CHANGED
@@ -415,8 +415,10 @@ var getHighlighter = async () => {
415
415
  var ReadmeViewer = ({
416
416
  content,
417
417
  className = "",
418
- isDark = false
418
+ isDark: propIsDark,
419
+ muiTheme
419
420
  }) => {
421
+ const isDark = propIsDark !== void 0 ? propIsDark : muiTheme?.palette?.mode === "dark";
420
422
  const [highlighter, setHighlighter] = react.useState(null);
421
423
  const [copiedBlocks, setCopiedBlocks] = react.useState(/* @__PURE__ */ new Set());
422
424
  react.useEffect(() => {
@@ -437,74 +439,85 @@ var ReadmeViewer = ({
437
439
  console.error("Failed to copy text: ", err);
438
440
  }
439
441
  };
440
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `readme-viewer markdown-body ${className}`, children: /* @__PURE__ */ jsxRuntime.jsx(
441
- ReactMarkdown__default.default,
442
- {
443
- remarkPlugins: [remarkGfm__default.default, remarkMath__default.default],
444
- rehypePlugins: [rehypeKatex__default.default],
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) {
442
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `readme-viewer markdown-body ${className}`, children: [
443
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: `
444
+ .shiki-wrapper pre.shiki {
445
+ padding: 16px !important;
446
+ border-radius: 8px !important;
447
+ overflow-x: auto;
448
+ margin-bottom: 16px;
449
+ border: 1px solid var(--md-sys-color-outline-variant, #e0e0e0);
450
+ }
451
+ ` }),
452
+ /* @__PURE__ */ jsxRuntime.jsx(
453
+ ReactMarkdown__default.default,
454
+ {
455
+ remarkPlugins: [remarkGfm__default.default, remarkMath__default.default],
456
+ rehypePlugins: [rehypeKatex__default.default],
457
+ components: {
458
+ code({ className: className2, children, ...props }) {
459
+ const match = /language-(\w+)/.exec(className2 || "");
460
+ if (match && highlighter) {
461
+ const codeText = String(children).replace(/\n$/, "");
462
+ const blockId = `code-${Math.random().toString(36).substr(2, 9)}`;
463
+ let highlightedHtml = "";
458
464
  try {
459
465
  highlightedHtml = highlighter.codeToHtml(codeText, {
460
- lang: "text",
466
+ lang: match[1],
461
467
  theme: isDark ? "github-dark" : "github-light"
462
468
  });
463
- } catch (fallbackError) {
464
- highlightedHtml = `<pre><code>${codeText}</code></pre>`;
469
+ } catch (e) {
470
+ try {
471
+ highlightedHtml = highlighter.codeToHtml(codeText, {
472
+ lang: "text",
473
+ theme: isDark ? "github-dark" : "github-light"
474
+ });
475
+ } catch (fallbackError) {
476
+ highlightedHtml = `<pre><code>${codeText}</code></pre>`;
477
+ }
465
478
  }
479
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
480
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shiki-wrapper", dangerouslySetInnerHTML: { __html: highlightedHtml } }),
481
+ /* @__PURE__ */ jsxRuntime.jsx(
482
+ "button",
483
+ {
484
+ onClick: () => copyToClipboard(codeText, blockId),
485
+ style: {
486
+ position: "absolute",
487
+ top: "8px",
488
+ right: "8px",
489
+ backgroundColor: "var(--md-sys-color-surface-container-high)",
490
+ border: "1px solid var(--md-sys-color-outline-variant)",
491
+ borderRadius: "4px",
492
+ padding: "6px",
493
+ fontSize: "14px",
494
+ cursor: "pointer",
495
+ color: "var(--md-sys-color-on-surface-variant)",
496
+ alignItems: "center",
497
+ justifyContent: "center",
498
+ transition: "all 0.2s ease",
499
+ width: "32px",
500
+ height: "32px"
501
+ },
502
+ onMouseEnter: (e) => {
503
+ e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-highest)" : "var(--md-sys-color-surface-container-high)";
504
+ },
505
+ onMouseLeave: (e) => {
506
+ e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-high)" : "var(--md-sys-color-surface-container-highest)";
507
+ },
508
+ title: copiedBlocks.has(blockId) ? "Copied!" : "Copy code",
509
+ children: copiedBlocks.has(blockId) ? /* @__PURE__ */ jsxRuntime.jsx(CheckIcon__default.default, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsxRuntime.jsx(ContentCopyIcon__default.default, { style: { fontSize: "16px" } })
510
+ }
511
+ )
512
+ ] });
466
513
  }
467
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
468
- /* @__PURE__ */ jsxRuntime.jsx("div", { dangerouslySetInnerHTML: { __html: highlightedHtml } }),
469
- /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(CheckIcon__default.default, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsxRuntime.jsx(ContentCopyIcon__default.default, { style: { fontSize: "16px" } })
498
- }
499
- )
500
- ] });
514
+ return /* @__PURE__ */ jsxRuntime.jsx("code", { className: className2, ...props, children });
501
515
  }
502
- return /* @__PURE__ */ jsxRuntime.jsx("code", { className: className2, ...props, children });
503
- }
504
- },
505
- children: content
506
- }
507
- ) });
516
+ },
517
+ children: content
518
+ }
519
+ )
520
+ ] });
508
521
  };
509
522
  var ReadmeViewer_default = ReadmeViewer;
510
523
  var NotificationContext = react.createContext(void 0);