@kushagradhawan/kookie-blocks 0.1.10 → 0.1.11

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.
Files changed (55) hide show
  1. package/dist/cjs/components/index.d.ts +1 -0
  2. package/dist/cjs/components/index.d.ts.map +1 -1
  3. package/dist/cjs/components/index.js +1 -1
  4. package/dist/cjs/components/index.js.map +2 -2
  5. package/dist/cjs/components/markdown/StreamingMarkdown.d.ts +78 -0
  6. package/dist/cjs/components/markdown/StreamingMarkdown.d.ts.map +1 -0
  7. package/dist/cjs/components/markdown/StreamingMarkdown.js +2 -0
  8. package/dist/cjs/components/markdown/StreamingMarkdown.js.map +7 -0
  9. package/dist/cjs/components/markdown/createMarkdownComponents.d.ts +27 -0
  10. package/dist/cjs/components/markdown/createMarkdownComponents.d.ts.map +1 -0
  11. package/dist/cjs/components/markdown/createMarkdownComponents.js +3 -0
  12. package/dist/cjs/components/markdown/createMarkdownComponents.js.map +7 -0
  13. package/dist/cjs/components/markdown/index.d.ts +6 -0
  14. package/dist/cjs/components/markdown/index.d.ts.map +1 -0
  15. package/dist/cjs/components/markdown/index.js +2 -0
  16. package/dist/cjs/components/markdown/index.js.map +7 -0
  17. package/dist/cjs/components/markdown/types.d.ts +32 -0
  18. package/dist/cjs/components/markdown/types.d.ts.map +1 -0
  19. package/dist/cjs/components/markdown/types.js +2 -0
  20. package/dist/cjs/components/markdown/types.js.map +7 -0
  21. package/dist/cjs/components/markdown/utils/markdownStreaming.d.ts +32 -0
  22. package/dist/cjs/components/markdown/utils/markdownStreaming.d.ts.map +1 -0
  23. package/dist/cjs/components/markdown/utils/markdownStreaming.js +5 -0
  24. package/dist/cjs/components/markdown/utils/markdownStreaming.js.map +7 -0
  25. package/dist/esm/components/index.d.ts +1 -0
  26. package/dist/esm/components/index.d.ts.map +1 -1
  27. package/dist/esm/components/index.js +1 -1
  28. package/dist/esm/components/index.js.map +2 -2
  29. package/dist/esm/components/markdown/StreamingMarkdown.d.ts +78 -0
  30. package/dist/esm/components/markdown/StreamingMarkdown.d.ts.map +1 -0
  31. package/dist/esm/components/markdown/StreamingMarkdown.js +2 -0
  32. package/dist/esm/components/markdown/StreamingMarkdown.js.map +7 -0
  33. package/dist/esm/components/markdown/createMarkdownComponents.d.ts +27 -0
  34. package/dist/esm/components/markdown/createMarkdownComponents.d.ts.map +1 -0
  35. package/dist/esm/components/markdown/createMarkdownComponents.js +3 -0
  36. package/dist/esm/components/markdown/createMarkdownComponents.js.map +7 -0
  37. package/dist/esm/components/markdown/index.d.ts +6 -0
  38. package/dist/esm/components/markdown/index.d.ts.map +1 -0
  39. package/dist/esm/components/markdown/index.js +2 -0
  40. package/dist/esm/components/markdown/index.js.map +7 -0
  41. package/dist/esm/components/markdown/types.d.ts +32 -0
  42. package/dist/esm/components/markdown/types.d.ts.map +1 -0
  43. package/dist/esm/components/markdown/types.js +1 -0
  44. package/dist/esm/components/markdown/types.js.map +7 -0
  45. package/dist/esm/components/markdown/utils/markdownStreaming.d.ts +32 -0
  46. package/dist/esm/components/markdown/utils/markdownStreaming.d.ts.map +1 -0
  47. package/dist/esm/components/markdown/utils/markdownStreaming.js +5 -0
  48. package/dist/esm/components/markdown/utils/markdownStreaming.js.map +7 -0
  49. package/package.json +10 -1
  50. package/src/components/index.ts +1 -0
  51. package/src/components/markdown/StreamingMarkdown.tsx +183 -0
  52. package/src/components/markdown/createMarkdownComponents.tsx +206 -0
  53. package/src/components/markdown/index.ts +8 -0
  54. package/src/components/markdown/types.ts +31 -0
  55. package/src/components/markdown/utils/markdownStreaming.ts +297 -0
@@ -1,3 +1,4 @@
1
1
  export * from './code';
2
2
  export * from './hero';
3
+ export * from './markdown';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(r,o,p,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let m of c(o))!d.call(r,m)&&m!==p&&a(r,m,{get:()=>o[m],enumerable:!(x=b(o,m))||x.enumerable});return r},f=(r,o,p)=>(t(r,o,"default"),p&&t(p,o,"default"));var g=r=>t(a({},"__esModule",{value:!0}),r);var e={};module.exports=g(e);f(e,require("./code"),module.exports);f(e,require("./hero"),module.exports);
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,r,p,x)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of c(r))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>r[m],enumerable:!(x=b(r,m))||x.enumerable});return f},e=(f,r,p)=>(t(f,r,"default"),p&&t(p,r,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);e(o,require("./code"),module.exports);e(o,require("./hero"),module.exports);e(o,require("./markdown"),module.exports);
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/index.ts"],
4
- "sourcesContent": ["export * from './code';\nexport * from './hero';\n"],
5
- "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,kBAAd,gBACAE,EAAAF,EAAc,kBADd",
4
+ "sourcesContent": ["export * from './code';\nexport * from './hero';\nexport * from './markdown';\n"],
5
+ "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,kBAAd,gBACAE,EAAAF,EAAc,kBADd,gBAEAE,EAAAF,EAAc,sBAFd",
6
6
  "names": ["components_exports", "__toCommonJS", "__reExport"]
7
7
  }
@@ -0,0 +1,78 @@
1
+ import React from "react";
2
+ import { type Components } from "react-markdown";
3
+ import type { MarkdownComponentOptions } from "./types";
4
+ /**
5
+ * Options for StreamingMarkdown component
6
+ */
7
+ export type StreamingMarkdownOptions = MarkdownComponentOptions & {
8
+ /**
9
+ * Security origin for link/image validation
10
+ * @default window.location.origin or "https://app.kookie.ai"
11
+ */
12
+ defaultOrigin?: string;
13
+ /**
14
+ * Whether to enable block-level memoization for performance
15
+ * Recommended for streaming scenarios where content updates frequently
16
+ * @default true
17
+ */
18
+ enableBlockMemoization?: boolean;
19
+ /**
20
+ * Custom parser for splitting content into blocks
21
+ * If not provided, content will be rendered as a single block
22
+ * For optimal streaming performance, use marked.lexer with GFM enabled
23
+ */
24
+ blockParser?: (content: string) => Array<{
25
+ raw?: string;
26
+ }>;
27
+ /**
28
+ * Override default component mappings
29
+ */
30
+ components?: Partial<Components>;
31
+ };
32
+ type StreamingMarkdownProps = {
33
+ /**
34
+ * Markdown content to render (supports streaming/incomplete markdown)
35
+ */
36
+ content: string;
37
+ /**
38
+ * Unique identifier for this markdown instance (used for keys)
39
+ */
40
+ id: string;
41
+ /**
42
+ * Optional configuration
43
+ */
44
+ options?: StreamingMarkdownOptions;
45
+ };
46
+ /**
47
+ * StreamingMarkdown - A drop-in markdown renderer designed for AI streaming.
48
+ *
49
+ * Features:
50
+ * - Unterminated block parsing (handles incomplete markdown during streaming)
51
+ * - Block-level memoization for performance
52
+ * - Security hardening (validates links/images)
53
+ * - GitHub Flavored Markdown support
54
+ * - KookieUI component integration
55
+ * - Code syntax highlighting via CodeBlock
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * import { StreamingMarkdown } from '@kushagradhawan/kookie-blocks';
60
+ * import { marked } from 'marked';
61
+ *
62
+ * function ChatMessage({ message }) {
63
+ * return (
64
+ * <StreamingMarkdown
65
+ * content={message.content}
66
+ * id={message.id}
67
+ * options={{
68
+ * blockParser: (content) => marked.lexer(content, { gfm: true }),
69
+ * enableBlockMemoization: true,
70
+ * }}
71
+ * />
72
+ * );
73
+ * }
74
+ * ```
75
+ */
76
+ export declare function StreamingMarkdown({ content, id, options }: StreamingMarkdownProps): React.JSX.Element | null;
77
+ export {};
78
+ //# sourceMappingURL=StreamingMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingMarkdown.d.ts","sourceRoot":"","sources":["../../../../src/components/markdown/StreamingMarkdown.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAC7D,OAAsB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAOhE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AASxD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,GAAG;IAChE;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE3D;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CAClC,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACpC,CAAC;AA6CF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAY,EAAE,EAAE,sBAAsB,4BA2CtF"}
@@ -0,0 +1,2 @@
1
+ "use strict";"use client";var B=Object.create;var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var L=(o,n)=>{for(var t in n)m(o,t,{get:n[t],enumerable:!0})},M=(o,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of S(n))!x.call(o,r)&&r!==t&&m(o,r,{get:()=>n[r],enumerable:!(i=I(n,r))||i.enumerable});return o};var s=(o,n,t)=>(t=o!=null?B(E(o)):{},M(n||!o||!o.__esModule?m(t,"default",{value:o,enumerable:!0}):t,o)),A=o=>M(m({},"__esModule",{value:!0}),o);var H={};L(H,{StreamingMarkdown:()=>z});module.exports=A(H);var e=s(require("react")),O=s(require("react-markdown")),P=s(require("remark-gfm")),h=s(require("rehype-raw")),y=s(require("harden-react-markdown")),l=require("@kushagradhawan/kookie-ui"),C=require("./createMarkdownComponents"),d=require("./utils/markdownStreaming");const F=(0,y.default)(O.default),_=["https://","http://","/"],D=["https://","http://","/","data:"],N=["mailto:","tel:","data:","http:","https:"],R=typeof window<"u"&&window.location?.origin?window.location.origin:"https://app.kookie.ai";function G(o){return o||R}const k=(0,e.memo)(({content:o,defaultOrigin:n,components:t})=>e.default.createElement(l.Box,{width:"100%"},e.default.createElement(F,{defaultOrigin:n,allowedLinkPrefixes:_,allowedImagePrefixes:D,allowedProtocols:N,allowDataImages:!0,components:t,remarkPlugins:[P.default],rehypePlugins:[h.default]},o)),(o,n)=>o.content===n.content&&o.defaultOrigin===n.defaultOrigin&&o.components===n.components);k.displayName="MarkdownBlock";function z({content:o,id:n,options:t={}}){const{defaultOrigin:i,enableBlockMemoization:r=!0,blockParser:c,components:g={},...w}=t,f=(0,e.useMemo)(()=>G(i),[i]),u=(0,e.useMemo)(()=>({...(0,C.createMarkdownComponents)(w),...g}),[w,g]),p=(0,e.useMemo)(()=>{if(!r||!c){const a=(0,d.completeUnterminatedMarkdown)(o);return a.trim()?[a]:[]}return(0,d.parseMarkdownIntoBlocks)(o,c)},[o,r,c]);return p.length?p.length===1?e.default.createElement(k,{content:p[0],defaultOrigin:f,components:u}):e.default.createElement(l.Flex,{direction:"column",gap:"2",width:"100%"},p.map((a,b)=>e.default.createElement(k,{key:`${n}-block-${b}`,content:a,defaultOrigin:f,components:u}))):null}
2
+ //# sourceMappingURL=StreamingMarkdown.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/markdown/StreamingMarkdown.tsx"],
4
+ "sourcesContent": ["\"use client\";\n\nimport React, { memo, useMemo, type ReactNode } from \"react\";\nimport ReactMarkdown, { type Components } from \"react-markdown\";\nimport remarkGfm from \"remark-gfm\";\nimport rehypeRaw from \"rehype-raw\";\nimport hardenReactMarkdown from \"harden-react-markdown\";\nimport { Box, Flex } from \"@kushagradhawan/kookie-ui\";\nimport { createMarkdownComponents } from \"./createMarkdownComponents\";\nimport { completeUnterminatedMarkdown, parseMarkdownIntoBlocks } from \"./utils/markdownStreaming\";\nimport type { MarkdownComponentOptions } from \"./types\";\n\nconst HardenedMarkdown = hardenReactMarkdown(ReactMarkdown);\n\nconst LINK_PREFIXES = [\"https://\", \"http://\", \"/\"];\nconst IMAGE_PREFIXES = [\"https://\", \"http://\", \"/\", \"data:\"];\nconst ALLOWED_PROTOCOLS = [\"mailto:\", \"tel:\", \"data:\", \"http:\", \"https:\"];\nconst DEFAULT_APP_ORIGIN = typeof window !== \"undefined\" && window.location?.origin ? window.location.origin : \"https://app.kookie.ai\";\n\n/**\n * Options for StreamingMarkdown component\n */\nexport type StreamingMarkdownOptions = MarkdownComponentOptions & {\n /**\n * Security origin for link/image validation\n * @default window.location.origin or \"https://app.kookie.ai\"\n */\n defaultOrigin?: string;\n\n /**\n * Whether to enable block-level memoization for performance\n * Recommended for streaming scenarios where content updates frequently\n * @default true\n */\n enableBlockMemoization?: boolean;\n\n /**\n * Custom parser for splitting content into blocks\n * If not provided, content will be rendered as a single block\n * For optimal streaming performance, use marked.lexer with GFM enabled\n */\n blockParser?: (content: string) => Array<{ raw?: string }>;\n\n /**\n * Override default component mappings\n */\n components?: Partial<Components>;\n};\n\ntype StreamingMarkdownProps = {\n /**\n * Markdown content to render (supports streaming/incomplete markdown)\n */\n content: string;\n\n /**\n * Unique identifier for this markdown instance (used for keys)\n */\n id: string;\n\n /**\n * Optional configuration\n */\n options?: StreamingMarkdownOptions;\n};\n\ntype MarkdownBlockProps = {\n content: string;\n defaultOrigin: string;\n components: Components;\n};\n\n/**\n * Resolves the default origin for security validation\n */\nfunction resolveDefaultOrigin(customOrigin?: string): string {\n if (customOrigin) {\n return customOrigin;\n }\n return DEFAULT_APP_ORIGIN;\n}\n\n/**\n * Memoized markdown block component for efficient streaming rendering\n */\nconst MarkdownBlock = memo(\n ({ content, defaultOrigin, components }: MarkdownBlockProps) => {\n return (\n <Box width=\"100%\">\n <HardenedMarkdown\n defaultOrigin={defaultOrigin}\n allowedLinkPrefixes={LINK_PREFIXES}\n allowedImagePrefixes={IMAGE_PREFIXES}\n allowedProtocols={ALLOWED_PROTOCOLS}\n allowDataImages\n components={components}\n remarkPlugins={[remarkGfm]}\n rehypePlugins={[rehypeRaw]}\n >\n {content}\n </HardenedMarkdown>\n </Box>\n );\n },\n (previous, next) => previous.content === next.content && previous.defaultOrigin === next.defaultOrigin && previous.components === next.components\n);\n\nMarkdownBlock.displayName = \"MarkdownBlock\";\n\n/**\n * StreamingMarkdown - A drop-in markdown renderer designed for AI streaming.\n *\n * Features:\n * - Unterminated block parsing (handles incomplete markdown during streaming)\n * - Block-level memoization for performance\n * - Security hardening (validates links/images)\n * - GitHub Flavored Markdown support\n * - KookieUI component integration\n * - Code syntax highlighting via CodeBlock\n *\n * @example\n * ```tsx\n * import { StreamingMarkdown } from '@kushagradhawan/kookie-blocks';\n * import { marked } from 'marked';\n *\n * function ChatMessage({ message }) {\n * return (\n * <StreamingMarkdown\n * content={message.content}\n * id={message.id}\n * options={{\n * blockParser: (content) => marked.lexer(content, { gfm: true }),\n * enableBlockMemoization: true,\n * }}\n * />\n * );\n * }\n * ```\n */\nexport function StreamingMarkdown({ content, id, options = {} }: StreamingMarkdownProps) {\n const { defaultOrigin: customOrigin, enableBlockMemoization = true, blockParser, components: customComponents = {}, ...componentOptions } = options;\n\n // Resolve security origin\n const defaultOrigin = useMemo(() => resolveDefaultOrigin(customOrigin), [customOrigin]);\n\n // Create component mappings with custom overrides\n const markdownComponents = useMemo(() => {\n const baseComponents = createMarkdownComponents(componentOptions);\n return {\n ...baseComponents,\n ...customComponents,\n };\n }, [componentOptions, customComponents]);\n\n // Parse content into blocks for memoization (if enabled and parser provided)\n const blocks = useMemo(() => {\n if (!enableBlockMemoization || !blockParser) {\n // No block splitting - just complete unterminated markdown\n const completed = completeUnterminatedMarkdown(content);\n return completed.trim() ? [completed] : [];\n }\n\n return parseMarkdownIntoBlocks(content, blockParser);\n }, [content, enableBlockMemoization, blockParser]);\n\n if (!blocks.length) {\n return null;\n }\n\n // Single block - no need for wrapper\n if (blocks.length === 1) {\n return <MarkdownBlock content={blocks[0]} defaultOrigin={defaultOrigin} components={markdownComponents} />;\n }\n\n // Multiple blocks - render with flex wrapper\n return (\n <Flex direction=\"column\" gap=\"2\" width=\"100%\">\n {blocks.map((block, index) => (\n <MarkdownBlock key={`${id}-block-${index}`} content={block} defaultOrigin={defaultOrigin} components={markdownComponents} />\n ))}\n </Flex>\n );\n}\n"],
5
+ "mappings": "ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAAqD,oBACrDC,EAA+C,6BAC/CC,EAAsB,yBACtBC,EAAsB,yBACtBC,EAAgC,oCAChCC,EAA0B,qCAC1BC,EAAyC,sCACzCC,EAAsE,qCAGtE,MAAMC,KAAmB,EAAAC,SAAoB,EAAAC,OAAa,EAEpDC,EAAgB,CAAC,WAAY,UAAW,GAAG,EAC3CC,EAAiB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AAW,CACrD,EAAG,CAACX,EAASU,EAAwBC,CAAW,CAAC,EAEjD,OAAKI,EAAO,OAKRA,EAAO,SAAW,EACb,EAAAZ,QAAA,cAACJ,EAAA,CAAc,QAASgB,EAAO,CAAC,EAAG,cAAed,EAAe,WAAYa,EAAoB,EAKxG,EAAAX,QAAA,cAAC,QAAK,UAAU,SAAS,IAAI,IAAI,MAAM,QACpCY,EAAO,IAAI,CAACE,EAAOC,IAClB,EAAAf,QAAA,cAACJ,EAAA,CAAc,IAAK,GAAGS,CAAE,UAAUU,CAAK,GAAI,QAASD,EAAO,cAAehB,EAAe,WAAYa,EAAoB,CAC3H,CACH,EAdO,IAgBX",
6
+ "names": ["StreamingMarkdown_exports", "__export", "StreamingMarkdown", "__toCommonJS", "import_react", "import_react_markdown", "import_remark_gfm", "import_rehype_raw", "import_harden_react_markdown", "import_kookie_ui", "import_createMarkdownComponents", "import_markdownStreaming", "HardenedMarkdown", "hardenReactMarkdown", "ReactMarkdown", "LINK_PREFIXES", "IMAGE_PREFIXES", "ALLOWED_PROTOCOLS", "DEFAULT_APP_ORIGIN", "resolveDefaultOrigin", "customOrigin", "MarkdownBlock", "content", "defaultOrigin", "components", "React", "remarkGfm", "rehypeRaw", "previous", "next", "id", "options", "enableBlockMemoization", "blockParser", "customComponents", "componentOptions", "markdownComponents", "blocks", "completed", "block", "index"]
7
+ }
@@ -0,0 +1,27 @@
1
+ import type { Components } from "react-markdown";
2
+ import type { MarkdownComponentOptions } from "./types";
3
+ /**
4
+ * Creates markdown component mappings that work with both react-markdown and MDX.
5
+ * Uses KookieUI components for consistent styling across all projects.
6
+ *
7
+ * @param options - Optional configuration for component behavior
8
+ * @returns Component mappings for markdown/MDX renderers
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * // In react-markdown
13
+ * <ReactMarkdown components={createMarkdownComponents()}>
14
+ * {content}
15
+ * </ReactMarkdown>
16
+ *
17
+ * // In MDX
18
+ * export function useMDXComponents(components: MDXComponents) {
19
+ * return {
20
+ * ...createMarkdownComponents(),
21
+ * ...components,
22
+ * };
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function createMarkdownComponents(options?: MarkdownComponentOptions): Components;
27
+ //# sourceMappingURL=createMarkdownComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMarkdownComponents.d.ts","sourceRoot":"","sources":["../../../../src/components/markdown/createMarkdownComponents.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,wBAAwB,EAAyB,MAAM,SAAS,CAAC;AA8B/E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,wBAA6B,GAAG,UAAU,CAmJ3F"}
@@ -0,0 +1,3 @@
1
+ "use strict";var u=Object.create;var a=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var M=(o,i)=>{for(var t in i)a(o,t,{get:i[t],enumerable:!0})},p=(o,i,t,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let e of w(i))!k.call(o,e)&&e!==t&&a(o,e,{get:()=>i[e],enumerable:!(s=C(i,e))||s.enumerable});return o};var f=(o,i,t)=>(t=o!=null?u(y(o)):{},p(i||!o||!o.__esModule?a(t,"default",{value:o,enumerable:!0}):t,o)),P=o=>p(a({},"__esModule",{value:!0}),o);var B={};M(B,{createMarkdownComponents:()=>b});module.exports=P(B);var r=f(require("react")),n=require("@kushagradhawan/kookie-ui"),h=require("../code");function T(o){return o?o.match(/language-([\w-]+)/i)?.[1]??"text":"text"}function H(o){let i="";return o?(typeof o=="string"?i=o:Array.isArray(o)&&(i=o.map(t=>typeof t=="string"?t:"").join("")),i.replace(/^\n+|\n+$/g,"")):i}function b(o={}){const{codeBlockCollapsible:i=!1,imageComponent:t,inlineCodeHighContrast:s=!0}=o;return{h1:({children:e})=>r.default.createElement(n.Heading,{size:"8",weight:"medium",as:"h1",style:{marginTop:"1rem",marginBottom:"0.5rem"}},e),h2:({children:e})=>r.default.createElement(n.Heading,{weight:"medium",size:"5",as:"h2",style:{marginTop:"0.875rem",marginBottom:"0.5rem"}},e),h3:({children:e})=>r.default.createElement(n.Heading,{weight:"medium",size:"4",as:"h3",style:{marginTop:"0.75rem",marginBottom:"0.5rem"}},e),h4:({children:e})=>r.default.createElement(n.Heading,{weight:"medium",size:"3",as:"h4",style:{marginTop:"0.625rem",marginBottom:"0.5rem"}},e),h5:({children:e})=>r.default.createElement(n.Heading,{weight:"medium",size:"3",as:"h5",style:{marginTop:"0.5rem",marginBottom:"0.5rem"}},e),h6:({children:e})=>r.default.createElement(n.Heading,{weight:"medium",size:"3",as:"h6",style:{marginTop:"0.5rem",marginBottom:"0.5rem"}},e),p:({children:e})=>r.default.createElement(n.Text,{size:"3",as:"p",style:{lineHeight:"1.6"}},e),code:({className:e,children:d,inline:m})=>{const l=H(d);return m===!0||m===void 0&&!e&&!l.includes(`
2
+ `)&&l.length<100?r.default.createElement(n.Code,{highContrast:s,size:"3"},l):r.default.createElement(n.Box,{my:"2",style:{minWidth:0}},r.default.createElement(h.CodeBlock,{code:l,language:T(e),collapsible:i}))},ul:({children:e})=>r.default.createElement("ul",{style:{marginTop:"0.5rem",marginBottom:"0.5rem",lineHeight:"1.6",paddingLeft:"1.5rem",listStyleType:"disc"}},e),ol:({children:e})=>r.default.createElement("ol",{style:{marginTop:"0.5rem",marginBottom:"0.5rem",lineHeight:"1.6",paddingLeft:"1.5rem",listStyleType:"decimal"}},e),li:({children:e})=>r.default.createElement("li",{style:{marginBottom:"0.25rem",lineHeight:"1.6"}},e),blockquote:({children:e})=>r.default.createElement(n.Blockquote,null,e),a:({href:e,children:d})=>r.default.createElement("a",{href:e,style:{color:"var(--accent-9)",textDecoration:"underline"}},d),strong:({children:e})=>r.default.createElement(n.Text,{weight:"medium",style:{lineHeight:"1.6"}},e),em:({children:e})=>r.default.createElement(n.Text,{style:{lineHeight:"1.6",fontStyle:"italic"}},e),hr:()=>r.default.createElement("hr",{style:{color:"var(--gray-6)",marginTop:"0.5rem",marginBottom:"0.5rem",height:"1px",width:"100%",opacity:.5}}),pre:({children:e})=>r.default.createElement(r.default.Fragment,null,e),table:({children:e})=>r.default.createElement(n.Box,{my:"2",style:{overflowX:"auto"}},r.default.createElement(n.Table.Root,{size:"2",variant:"ghost"},e)),thead:({children:e})=>r.default.createElement(n.Table.Header,null,e),tbody:({children:e})=>r.default.createElement(n.Table.Body,null,e),tr:({children:e})=>r.default.createElement(n.Table.Row,null,e),th:({children:e})=>r.default.createElement(n.Table.ColumnHeaderCell,null,e),td:({children:e})=>r.default.createElement(n.Table.Cell,null,e),sub:({children:e})=>r.default.createElement("sub",null,e),sup:({children:e})=>r.default.createElement("sup",null,e),br:()=>r.default.createElement("br",null),img:t?e=>{const{src:d,alt:m,width:l,height:g}=e;return!d||typeof d!="string"?null:t({src:d,alt:m??"Image",width:l?String(l):void 0,height:g?String(g):void 0})}:void 0,details:({children:e})=>r.default.createElement("details",{style:{padding:"0.5rem 0"}},e),summary:({children:e})=>r.default.createElement("summary",{style:{cursor:"pointer",fontWeight:500}},e)}}
3
+ //# sourceMappingURL=createMarkdownComponents.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/markdown/createMarkdownComponents.tsx"],
4
+ "sourcesContent": ["import React, { type ReactNode } from \"react\";\nimport type { Components } from \"react-markdown\";\nimport { Blockquote, Box, Code, Flex, Heading, Text, Table } from \"@kushagradhawan/kookie-ui\";\nimport { CodeBlock } from \"../code\";\nimport type { MarkdownComponentOptions, MarkdownChildrenProps } from \"./types\";\n\n/**\n * Extracts language from className (e.g., \"language-typescript\" -> \"typescript\")\n */\nfunction extractLanguage(className?: string): string {\n if (!className) {\n return \"text\";\n }\n const match = className.match(/language-([\\w-]+)/i);\n return match?.[1] ?? \"text\";\n}\n\n/**\n * Extracts code string from ReactNode children\n */\nfunction extractCode(children?: ReactNode): string {\n let code = \"\";\n if (!children) {\n return code;\n }\n if (typeof children === \"string\") {\n code = children;\n } else if (Array.isArray(children)) {\n code = children.map((child) => (typeof child === \"string\" ? child : \"\")).join(\"\");\n }\n // Trim trailing newlines but preserve internal whitespace\n return code.replace(/^\\n+|\\n+$/g, \"\");\n}\n\n/**\n * Creates markdown component mappings that work with both react-markdown and MDX.\n * Uses KookieUI components for consistent styling across all projects.\n *\n * @param options - Optional configuration for component behavior\n * @returns Component mappings for markdown/MDX renderers\n *\n * @example\n * ```tsx\n * // In react-markdown\n * <ReactMarkdown components={createMarkdownComponents()}>\n * {content}\n * </ReactMarkdown>\n *\n * // In MDX\n * export function useMDXComponents(components: MDXComponents) {\n * return {\n * ...createMarkdownComponents(),\n * ...components,\n * };\n * }\n * ```\n */\nexport function createMarkdownComponents(options: MarkdownComponentOptions = {}): Components {\n const { codeBlockCollapsible = false, imageComponent, inlineCodeHighContrast = true } = options;\n\n return {\n // Headings with consistent visual hierarchy\n h1: ({ children }: MarkdownChildrenProps) => (\n <Heading size=\"8\" weight=\"medium\" as=\"h1\" style={{ marginTop: \"1rem\", marginBottom: \"0.5rem\" }}>\n {children}\n </Heading>\n ),\n h2: ({ children }: MarkdownChildrenProps) => (\n <Heading weight=\"medium\" size=\"5\" as=\"h2\" style={{ marginTop: \"0.875rem\", marginBottom: \"0.5rem\" }}>\n {children}\n </Heading>\n ),\n h3: ({ children }: MarkdownChildrenProps) => (\n <Heading weight=\"medium\" size=\"4\" as=\"h3\" style={{ marginTop: \"0.75rem\", marginBottom: \"0.5rem\" }}>\n {children}\n </Heading>\n ),\n h4: ({ children }: MarkdownChildrenProps) => (\n <Heading weight=\"medium\" size=\"3\" as=\"h4\" style={{ marginTop: \"0.625rem\", marginBottom: \"0.5rem\" }}>\n {children}\n </Heading>\n ),\n h5: ({ children }: MarkdownChildrenProps) => (\n <Heading weight=\"medium\" size=\"3\" as=\"h5\" style={{ marginTop: \"0.5rem\", marginBottom: \"0.5rem\" }}>\n {children}\n </Heading>\n ),\n h6: ({ children }: MarkdownChildrenProps) => (\n <Heading weight=\"medium\" size=\"3\" as=\"h6\" style={{ marginTop: \"0.5rem\", marginBottom: \"0.5rem\" }}>\n {children}\n </Heading>\n ),\n\n // Paragraph text\n p: ({ children }: MarkdownChildrenProps) => (\n <Text size=\"3\" as=\"p\" style={{ lineHeight: \"1.6\" }}>\n {children}\n </Text>\n ),\n\n // Code - inline vs block\n code: ({ className, children, inline }: { className?: string; children?: ReactNode; inline?: boolean }) => {\n const code = extractCode(children);\n\n // Block code: has className (language) OR is not marked as inline\n // Inline code: explicitly marked as inline=true, or no className and short single-line content\n const isInlineCode = inline === true || (inline === undefined && !className && !code.includes(\"\\n\") && code.length < 100);\n\n if (isInlineCode) {\n return (\n <Code highContrast={inlineCodeHighContrast} size=\"3\">\n {code}\n </Code>\n );\n }\n\n return (\n <Box my=\"2\" style={{ minWidth: 0 }}>\n <CodeBlock code={code} language={extractLanguage(className)} collapsible={codeBlockCollapsible} />\n </Box>\n );\n },\n\n // Lists\n ul: ({ children }: MarkdownChildrenProps) => (\n <ul style={{ marginTop: \"0.5rem\", marginBottom: \"0.5rem\", lineHeight: \"1.6\", paddingLeft: \"1.5rem\", listStyleType: \"disc\" }}>{children}</ul>\n ),\n ol: ({ children }: MarkdownChildrenProps) => (\n <ol style={{ marginTop: \"0.5rem\", marginBottom: \"0.5rem\", lineHeight: \"1.6\", paddingLeft: \"1.5rem\", listStyleType: \"decimal\" }}>{children}</ol>\n ),\n li: ({ children }: MarkdownChildrenProps) => <li style={{ marginBottom: \"0.25rem\", lineHeight: \"1.6\" }}>{children}</li>,\n\n // Blockquote\n blockquote: ({ children }: MarkdownChildrenProps) => <Blockquote>{children}</Blockquote>,\n\n // Links\n a: ({ href, children }: { href?: string; children?: ReactNode }) => (\n <a href={href} style={{ color: \"var(--accent-9)\", textDecoration: \"underline\" }}>\n {children}\n </a>\n ),\n\n // Text styling\n strong: ({ children }: MarkdownChildrenProps) => (\n <Text weight=\"medium\" style={{ lineHeight: \"1.6\" }}>\n {children}\n </Text>\n ),\n em: ({ children }: MarkdownChildrenProps) => <Text style={{ lineHeight: \"1.6\", fontStyle: \"italic\" }}>{children}</Text>,\n\n // Horizontal rule\n hr: () => (\n <hr\n style={{\n color: \"var(--gray-6)\",\n marginTop: \"0.5rem\",\n marginBottom: \"0.5rem\",\n height: \"1px\",\n width: \"100%\",\n opacity: 0.5,\n }}\n />\n ),\n\n // Pre wrapper (pass through to let code handle it)\n pre: ({ children }: MarkdownChildrenProps) => <>{children}</>,\n\n // Tables using KookieUI\n table: ({ children }: MarkdownChildrenProps) => (\n <Box my=\"2\" style={{ overflowX: \"auto\" }}>\n <Table.Root size=\"2\" variant=\"ghost\">\n {children}\n </Table.Root>\n </Box>\n ),\n thead: ({ children }: MarkdownChildrenProps) => <Table.Header>{children}</Table.Header>,\n tbody: ({ children }: MarkdownChildrenProps) => <Table.Body>{children}</Table.Body>,\n tr: ({ children }: MarkdownChildrenProps) => <Table.Row>{children}</Table.Row>,\n th: ({ children }: MarkdownChildrenProps) => <Table.ColumnHeaderCell>{children}</Table.ColumnHeaderCell>,\n td: ({ children }: MarkdownChildrenProps) => <Table.Cell>{children}</Table.Cell>,\n\n // HTML elements for raw HTML support\n sub: ({ children }: MarkdownChildrenProps) => <sub>{children}</sub>,\n sup: ({ children }: MarkdownChildrenProps) => <sup>{children}</sup>,\n br: () => <br />,\n\n // Images - use custom component if provided\n img: imageComponent\n ? (props: React.ImgHTMLAttributes<HTMLImageElement>) => {\n const { src, alt, width, height } = props;\n if (!src || typeof src !== \"string\") return null;\n return imageComponent({\n src,\n alt: alt ?? \"Image\",\n width: width ? String(width) : undefined,\n height: height ? String(height) : undefined,\n });\n }\n : undefined,\n\n // Details/Summary for expandable sections\n details: ({ children }: MarkdownChildrenProps) => <details style={{ padding: \"0.5rem 0\" }}>{children}</details>,\n summary: ({ children }: MarkdownChildrenProps) => <summary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EAAAO,QAAA,cAAC,QAAM,IAAN,KAAWP,CAAS,EAClE,GAAI,CAAC,CAAE,SAAAA,CAAS,IAA6B,EAAAO,QAAA,cAAC,QAAM,iBAAN,KAAwBP,CAAS,EAC/E,GAAI,CAAC,CAAE,SAAAA,CAAS,IAA6B,EAAAO,QAAA,cAAC,QAAM,KAAN,KAAYP,CAAS,EAGnE,IAAK,CAAC,CAAE,SAAAA,CAAS,IAA6B,EAAAO,QAAA,cAAC,WAAKP,CAAS,EAC7D,IAAK,CAAC,CAAE,SAAAA,CAAS,IAA6B,EAAAO,QAAA,cAAC,WAAKP,CAAS,EAC7D,GAAI,IAAM,EAAAO,QAAA,cAAC,SAAG,EAGd,IAAKF,EACAK,GAAqD,CACpD,KAAM,CAAE,IAAAC,EAAK,IAAAC,EAAK,MAAAC,EAAO,OAAAC,CAAO,EAAIJ,EACpC,MAAI,CAACC,GAAO,OAAOA,GAAQ,SAAiB,KACrCN,EAAe,CACpB,IAAAM,EACA,IAAKC,GAAO,QACZ,MAAOC,EAAQ,OAAOA,CAAK,EAAI,OAC/B,OAAQC,EAAS,OAAOA,CAAM,EAAI,MACpC,CAAC,CACH,EACA,OAGJ,QAAS,CAAC,CAAE,SAAAd,CAAS,IAA6B,EAAAO,QAAA,cAAC,WAAQ,MAAO,CAAE,QAAS,UAAW,GAAIP,CAAS,EACrG,QAAS,CAAC,CAAE,SAAAA,CAAS,IAA6B,EAAAO,QAAA,cAAC,WAAQ,MAAO,CAAE,OAAQ,UAAW,WAAY,GAAI,GAAIP,CAAS,CACtH,CACF",
6
+ "names": ["createMarkdownComponents_exports", "__export", "createMarkdownComponents", "__toCommonJS", "import_react", "import_kookie_ui", "import_code", "extractLanguage", "className", "extractCode", "children", "code", "child", "options", "codeBlockCollapsible", "imageComponent", "inlineCodeHighContrast", "React", "inline", "href", "props", "src", "alt", "width", "height"]
7
+ }
@@ -0,0 +1,6 @@
1
+ export { StreamingMarkdown } from "./StreamingMarkdown";
2
+ export type { StreamingMarkdownOptions } from "./StreamingMarkdown";
3
+ export { createMarkdownComponents } from "./createMarkdownComponents";
4
+ export type { MarkdownComponentOptions, MarkdownChildrenProps } from "./types";
5
+ export { completeUnterminatedMarkdown, parseMarkdownIntoBlocks } from "./utils/markdownStreaming";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,YAAY,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var i=(r,o)=>{for(var n in o)p(r,n,{get:o[n],enumerable:!0})},s=(r,o,n,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of w(o))!M.call(r,e)&&e!==n&&p(r,e,{get:()=>o[e],enumerable:!(a=k(o,e))||a.enumerable});return r};var f=r=>s(p({},"__esModule",{value:!0}),r);var x={};i(x,{StreamingMarkdown:()=>m.StreamingMarkdown,completeUnterminatedMarkdown:()=>t.completeUnterminatedMarkdown,createMarkdownComponents:()=>d.createMarkdownComponents,parseMarkdownIntoBlocks:()=>t.parseMarkdownIntoBlocks});module.exports=f(x);var m=require("./StreamingMarkdown"),d=require("./createMarkdownComponents"),t=require("./utils/markdownStreaming");
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/markdown/index.ts"],
4
+ "sourcesContent": ["export { StreamingMarkdown } from \"./StreamingMarkdown\";\nexport type { StreamingMarkdownOptions } from \"./StreamingMarkdown\";\n\nexport { createMarkdownComponents } from \"./createMarkdownComponents\";\nexport type { MarkdownComponentOptions, MarkdownChildrenProps } from \"./types\";\n\nexport { completeUnterminatedMarkdown, parseMarkdownIntoBlocks } from \"./utils/markdownStreaming\";\n\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0OAAAE,EAAAF,GAAA,IAAAG,EAAkC,+BAGlCC,EAAyC,sCAGzCC,EAAsE",
6
+ "names": ["markdown_exports", "__export", "__toCommonJS", "import_StreamingMarkdown", "import_createMarkdownComponents", "import_markdownStreaming"]
7
+ }
@@ -0,0 +1,32 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * Options for customizing markdown component behavior
4
+ */
5
+ export type MarkdownComponentOptions = {
6
+ /**
7
+ * Whether code blocks should be collapsible
8
+ * @default false
9
+ */
10
+ codeBlockCollapsible?: boolean;
11
+ /**
12
+ * Custom image component
13
+ */
14
+ imageComponent?: (props: {
15
+ src?: string;
16
+ alt?: string;
17
+ width?: string;
18
+ height?: string;
19
+ }) => ReactNode;
20
+ /**
21
+ * Whether to use high contrast for inline code
22
+ * @default true
23
+ */
24
+ inlineCodeHighContrast?: boolean;
25
+ };
26
+ /**
27
+ * Common props for markdown child components
28
+ */
29
+ export type MarkdownChildrenProps = {
30
+ children?: ReactNode;
31
+ };
32
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/markdown/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,SAAS,CAAC;IAEvG;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(e,o,i,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of a(o))!d.call(e,t)&&t!==i&&r(e,t,{get:()=>o[t],enumerable:!(n=p(o,t))||n.enumerable});return e};var s=e=>l(r({},"__esModule",{value:!0}),e);var c={};module.exports=s(c);
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/markdown/types.ts"],
4
+ "sourcesContent": ["import type { ReactNode } from \"react\";\n\n/**\n * Options for customizing markdown component behavior\n */\nexport type MarkdownComponentOptions = {\n /**\n * Whether code blocks should be collapsible\n * @default false\n */\n codeBlockCollapsible?: boolean;\n\n /**\n * Custom image component\n */\n imageComponent?: (props: { src?: string; alt?: string; width?: string; height?: string }) => ReactNode;\n\n /**\n * Whether to use high contrast for inline code\n * @default true\n */\n inlineCodeHighContrast?: boolean;\n};\n\n/**\n * Common props for markdown child components\n */\nexport type MarkdownChildrenProps = {\n children?: ReactNode;\n};\n\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["types_exports", "__toCommonJS"]
7
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Utilities for handling streaming markdown content.
3
+ * Completes unterminated markdown blocks to enable proper parsing during streaming.
4
+ */
5
+ /**
6
+ * Completes unterminated markdown syntax at the end of content.
7
+ * This allows streaming markdown to be parsed correctly even when syntax is incomplete.
8
+ *
9
+ * Handles:
10
+ * - Headings (# Heading)
11
+ * - Inline code (`code)
12
+ * - Bold (**text or __text)
13
+ * - Italic (*text or _text)
14
+ * - Links ([text](url or [text]()
15
+ * - Code blocks (```language\ncode)
16
+ * - Lists (- item or * item or 1. item)
17
+ * - Blockquotes (> text)
18
+ * - Strikethrough (~~text)
19
+ */
20
+ export declare function completeUnterminatedMarkdown(content: string): string;
21
+ /**
22
+ * Parses markdown content into blocks for efficient rendering.
23
+ * Each block is a separate markdown token that can be memoized independently.
24
+ *
25
+ * @param content - The markdown content to parse
26
+ * @param parser - Optional parser function (defaults to using marked.lexer)
27
+ * @returns Array of markdown block strings
28
+ */
29
+ export declare function parseMarkdownIntoBlocks(content: string, parser?: (content: string) => Array<{
30
+ raw?: string;
31
+ }>): string[];
32
+ //# sourceMappingURL=markdownStreaming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownStreaming.d.ts","sourceRoot":"","sources":["../../../../../src/components/markdown/utils/markdownStreaming.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2IH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsGpE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GACpD,MAAM,EAAE,CAuBV"}
@@ -0,0 +1,5 @@
1
+ "use strict";var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var k=(e,r)=>{for(var n in r)o(e,n,{get:r[n],enumerable:!0})},M=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of d(r))!p.call(e,i)&&i!==n&&o(e,i,{get:()=>r[i],enumerable:!(t=m(r,i))||t.enumerable});return e};var w=e=>M(o({},"__esModule",{value:!0}),e);var _={};k(_,{completeUnterminatedMarkdown:()=>g,parseMarkdownIntoBlocks:()=>C});module.exports=w(_);function u(e,r){const n=r==="**"?"\\*\\*":"__",t=new RegExp(n,"g");if((e.match(t)||[]).length%2===0)return!1;const s=e.lastIndexOf(r);return s===-1?!1:e.slice(s+r.length).length>0}function x(e){if((e.match(/~~/g)||[]).length%2===0)return!1;const n=e.lastIndexOf("~~");return n===-1?!1:e.slice(n+2).length>0}function b(e,r,n){if(n!=="*")return!1;const t=r===0||e[r-1]===`
2
+ `,i=r<e.length-1&&e[r+1]===" ";return t&&i}function h(e,r){let n=0,t=-1;for(let s=0;s<e.length;s++)if(e[s]===r){if(b(e,s,r))continue;const a=s>0&&e[s-1]===r,l=s<e.length-1&&e[s+1]===r;if(a||l){l&&s++;continue}n++,t=s}return n%2===0||t===-1?!1:t===e.length-1?t>0:e.slice(t+1).length>0}function I(e){const r=/```/g,n=[];let t;for(;(t=r.exec(e))!==null;)n.push(t.index);return n.length%2===1}function g(e){if(!e.trim())return e;const r=e.trimEnd(),n=e.slice(r.length);let t=r;if(t.match(/```[\w-]*$/)&&!t.includes("```\n")&&!t.match(/```[\w-]+\n/)||I(t))return t+="\n```",t+n;if((t.replace(/```[\w-]*/g,"").match(/`/g)||[]).length%2===1)return t+="`",t+n;if(t.match(/\[([^\]]*)\]\(([^)]*)$/))return t+=")",t+n;if(u(t,"**"))return t+="**",t+n;if(u(t,"__"))return t+="__",t+n;if(x(t))return t+="~~",t+n;const f=t.split(`
3
+ `),c=f[f.length-1];return c.match(/^#{1,6}\s+.+$/)||c.match(/^(\s*)([-*+]|\d+\.)\s+.+$/)||c.match(/^>\s+.+$/)?(t+=`
4
+ `,t+n):h(t,"*")?(t+="*",t+n):(h(t,"_")&&(t+="_"),t+n)}function C(e,r){if(!e.trim())return[];const n=g(e);return r?r(n).map(i=>"raw"in i&&typeof i.raw=="string"?i.raw:"").filter(i=>!!i.trim()):[n]}
5
+ //# sourceMappingURL=markdownStreaming.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/components/markdown/utils/markdownStreaming.ts"],
4
+ "sourcesContent": ["/**\n * Utilities for handling streaming markdown content.\n * Completes unterminated markdown blocks to enable proper parsing during streaming.\n */\n\n/**\n * Checks if there's an unpaired double marker (** or __) with content after the last opener.\n * Returns true only if there's text after the unclosed marker (not just the marker itself).\n */\nfunction hasUnpairedDoubleMarkerWithContent(content: string, marker: string): boolean {\n const escaped = marker === \"**\" ? \"\\\\*\\\\*\" : \"__\";\n const regex = new RegExp(escaped, \"g\");\n const matches = content.match(regex) || [];\n\n if (matches.length % 2 === 0) {\n return false; // All paired\n }\n\n // Find the last occurrence of the marker - there should be content after it\n const lastIndex = content.lastIndexOf(marker);\n if (lastIndex === -1) {\n return false;\n }\n\n // Check if there's actual content after the marker\n const afterMarker = content.slice(lastIndex + marker.length);\n return afterMarker.length > 0;\n}\n\n/**\n * Checks if there's an unpaired strikethrough with content after the last opener.\n */\nfunction hasUnpairedStrikethroughWithContent(content: string): boolean {\n const matches = content.match(/~~/g) || [];\n\n if (matches.length % 2 === 0) {\n return false; // All paired\n }\n\n // Find the last occurrence - there should be content after it\n const lastIndex = content.lastIndexOf(\"~~\");\n if (lastIndex === -1) {\n return false;\n }\n\n const afterMarker = content.slice(lastIndex + 2);\n return afterMarker.length > 0;\n}\n\n/**\n * Checks if a marker at position i is a list marker (at start of line followed by space).\n */\nfunction isListMarker(content: string, i: number, marker: string): boolean {\n // Only * can be a list marker (not _)\n if (marker !== \"*\") {\n return false;\n }\n\n // Check if at start of line (or start of content)\n const isStartOfLine = i === 0 || content[i - 1] === \"\\n\";\n // Check if followed by space\n const followedBySpace = i < content.length - 1 && content[i + 1] === \" \";\n\n return isStartOfLine && followedBySpace;\n}\n\n/**\n * Checks if there's an unpaired single italic marker (* or _) that needs closing.\n * Must distinguish from bold markers (** or __) and list markers (* ).\n *\n * Returns true if:\n * - There's an odd number of single markers (not part of double markers or list markers)\n * - Either there's content after the last marker, OR the content ends with the marker\n */\nfunction hasUnpairedItalicWithContent(content: string, marker: string): boolean {\n // Count single markers (not part of double markers or list markers)\n let singleCount = 0;\n let lastSingleIndex = -1;\n\n for (let i = 0; i < content.length; i++) {\n if (content[i] === marker) {\n // Check if it's a list marker\n if (isListMarker(content, i, marker)) {\n continue;\n }\n\n // Check if it's part of a double marker\n const prevIsMarker = i > 0 && content[i - 1] === marker;\n const nextIsMarker = i < content.length - 1 && content[i + 1] === marker;\n\n if (prevIsMarker || nextIsMarker) {\n // Part of ** or __, skip\n if (nextIsMarker) {\n i++; // Skip the next one too\n }\n continue;\n }\n\n singleCount++;\n lastSingleIndex = i;\n }\n }\n\n if (singleCount % 2 === 0) {\n return false; // All paired\n }\n\n if (lastSingleIndex === -1) {\n return false;\n }\n\n // If content ends with the marker, it's an opener that needs closing\n // (e.g., \"*text* more *\" - the last * is a new opener)\n // BUT only if there's content before it (not just a lone marker)\n if (lastSingleIndex === content.length - 1) {\n // Must have content before the marker for it to be a meaningful opener\n return lastSingleIndex > 0;\n }\n\n // Otherwise, check if there's content after the last unpaired marker\n const afterMarker = content.slice(lastSingleIndex + 1);\n return afterMarker.length > 0;\n}\n\n/**\n * Checks if content has an unclosed code block.\n * Returns true if the last ``` opens a block that isn't closed.\n */\nfunction hasUnclosedCodeBlock(content: string): boolean {\n // Find all ``` occurrences\n const fenceRegex = /```/g;\n const matches: number[] = [];\n let match;\n\n while ((match = fenceRegex.exec(content)) !== null) {\n matches.push(match.index);\n }\n\n // Odd number of fences means unclosed\n return matches.length % 2 === 1;\n}\n\n/**\n * Completes unterminated markdown syntax at the end of content.\n * This allows streaming markdown to be parsed correctly even when syntax is incomplete.\n *\n * Handles:\n * - Headings (# Heading)\n * - Inline code (`code)\n * - Bold (**text or __text)\n * - Italic (*text or _text)\n * - Links ([text](url or [text]()\n * - Code blocks (```language\\ncode)\n * - Lists (- item or * item or 1. item)\n * - Blockquotes (> text)\n * - Strikethrough (~~text)\n */\nexport function completeUnterminatedMarkdown(content: string): string {\n if (!content.trim()) {\n return content;\n }\n\n // Work backwards from the end to find the last incomplete markdown pattern\n const trimmed = content.trimEnd();\n const trailingWhitespace = content.slice(trimmed.length);\n let result = trimmed;\n\n // Check for incomplete code fence without newline yet (e.g., \"```python\" with no \\n)\n // This must come before the code block check\n const incompleteFenceMatch = result.match(/```[\\w-]*$/);\n if (incompleteFenceMatch && !result.includes(\"```\\n\") && !result.match(/```[\\w-]+\\n/)) {\n // Code fence just started, hasn't gotten content yet - add newline and closing\n result += \"\\n```\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete code blocks using fence counting\n if (hasUnclosedCodeBlock(result)) {\n result += \"\\n```\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete inline code (backticks)\n // Count backticks that are NOT part of code fences\n // First, remove all code fence markers to count only inline backticks\n const withoutFences = result.replace(/```[\\w-]*/g, \"\");\n const backtickCount = (withoutFences.match(/`/g) || []).length;\n if (backtickCount % 2 === 1) {\n result += \"`\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete links [text](url\n const linkMatch = result.match(/\\[([^\\]]*)\\]\\(([^)]*)$/);\n if (linkMatch) {\n // Incomplete link - close the URL part\n result += \")\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete bold (**text or __text)\n // Only complete if there's actual content after the marker\n if (hasUnpairedDoubleMarkerWithContent(result, \"**\")) {\n result += \"**\";\n return result + trailingWhitespace;\n }\n\n if (hasUnpairedDoubleMarkerWithContent(result, \"__\")) {\n result += \"__\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete strikethrough (~~text)\n if (hasUnpairedStrikethroughWithContent(result)) {\n result += \"~~\";\n return result + trailingWhitespace;\n }\n\n // Check structural elements BEFORE italic to avoid false positives\n // (e.g., \"* item\" is a list, not italic)\n const lines = result.split(\"\\n\");\n const lastLine = lines[lines.length - 1];\n\n // Check for incomplete headings (# Heading without newline)\n // Look for # at the start of the last line\n if (lastLine.match(/^#{1,6}\\s+.+$/)) {\n // Heading without trailing newline - add one for proper parsing\n result += \"\\n\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete list items (- item, * item, 1. item)\n // Look for list markers at the start of the last line\n if (lastLine.match(/^(\\s*)([-*+]|\\d+\\.)\\s+.+$/)) {\n // List item without trailing newline - add one for proper parsing\n result += \"\\n\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete blockquotes (> text)\n if (lastLine.match(/^>\\s+.+$/)) {\n // Blockquote without trailing newline - add one for proper parsing\n result += \"\\n\";\n return result + trailingWhitespace;\n }\n\n // Check for incomplete italic (*text or _text) AFTER structural elements\n // This prevents \"* item\" from being treated as italic\n if (hasUnpairedItalicWithContent(result, \"*\")) {\n result += \"*\";\n return result + trailingWhitespace;\n }\n\n if (hasUnpairedItalicWithContent(result, \"_\")) {\n result += \"_\";\n return result + trailingWhitespace;\n }\n\n return result + trailingWhitespace;\n}\n\n/**\n * Parses markdown content into blocks for efficient rendering.\n * Each block is a separate markdown token that can be memoized independently.\n *\n * @param content - The markdown content to parse\n * @param parser - Optional parser function (defaults to using marked.lexer)\n * @returns Array of markdown block strings\n */\nexport function parseMarkdownIntoBlocks(\n content: string,\n parser?: (content: string) => Array<{ raw?: string }>\n): string[] {\n if (!content.trim()) {\n return [];\n }\n\n // Complete unterminated markdown blocks for streaming support\n const completedContent = completeUnterminatedMarkdown(content);\n\n // If no parser provided, return the content as a single block\n // This allows usage without marked dependency\n if (!parser) {\n return [completedContent];\n }\n\n const tokens = parser(completedContent);\n return tokens\n .map((token) => {\n if (\"raw\" in token && typeof token.raw === \"string\") {\n return token.raw;\n }\n return \"\";\n })\n .filter((raw) => Boolean(raw.trim()));\n}\n\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,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B,GAO1CA,EAAS,MAAM,UAAU,GAE3BF,GAAU;AAAA,EACHA,EAASD,GAKdV,EAA6BW,EAAQ,GAAG,GAC1CA,GAAU,IACHA,EAASD,IAGdV,EAA6BW,EAAQ,GAAG,IAC1CA,GAAU,KACHA,EAASD,EAIpB,CAUO,SAASvB,EACdG,EACAwB,EACU,CACV,GAAI,CAACxB,EAAQ,KAAK,EAChB,MAAO,CAAC,EAIV,MAAMyB,EAAmB7B,EAA6BI,CAAO,EAI7D,OAAKwB,EAIUA,EAAOC,CAAgB,EAEnC,IAAKC,GACA,QAASA,GAAS,OAAOA,EAAM,KAAQ,SAClCA,EAAM,IAER,EACR,EACA,OAAQC,GAAQ,EAAQA,EAAI,KAAK,CAAE,EAX7B,CAACF,CAAgB,CAY5B",
6
+ "names": ["markdownStreaming_exports", "__export", "completeUnterminatedMarkdown", "parseMarkdownIntoBlocks", "__toCommonJS", "hasUnpairedDoubleMarkerWithContent", "content", "marker", "escaped", "regex", "lastIndex", "hasUnpairedStrikethroughWithContent", "isListMarker", "i", "isStartOfLine", "followedBySpace", "hasUnpairedItalicWithContent", "singleCount", "lastSingleIndex", "prevIsMarker", "nextIsMarker", "hasUnclosedCodeBlock", "fenceRegex", "matches", "match", "trimmed", "trailingWhitespace", "result", "lines", "lastLine", "parser", "completedContent", "token", "raw"]
7
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './code';
2
2
  export * from './hero';
3
+ export * from './markdown';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
@@ -1,2 +1,2 @@
1
- export*from"./code";export*from"./hero";
1
+ export*from"./code";export*from"./hero";export*from"./markdown";
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/index.ts"],
4
- "sourcesContent": ["export * from './code';\nexport * from './hero';\n"],
5
- "mappings": "AAAA,WAAc,SACd,WAAc",
4
+ "sourcesContent": ["export * from './code';\nexport * from './hero';\nexport * from './markdown';\n"],
5
+ "mappings": "AAAA,WAAc,SACd,WAAc,SACd,WAAc",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,78 @@
1
+ import React from "react";
2
+ import { type Components } from "react-markdown";
3
+ import type { MarkdownComponentOptions } from "./types";
4
+ /**
5
+ * Options for StreamingMarkdown component
6
+ */
7
+ export type StreamingMarkdownOptions = MarkdownComponentOptions & {
8
+ /**
9
+ * Security origin for link/image validation
10
+ * @default window.location.origin or "https://app.kookie.ai"
11
+ */
12
+ defaultOrigin?: string;
13
+ /**
14
+ * Whether to enable block-level memoization for performance
15
+ * Recommended for streaming scenarios where content updates frequently
16
+ * @default true
17
+ */
18
+ enableBlockMemoization?: boolean;
19
+ /**
20
+ * Custom parser for splitting content into blocks
21
+ * If not provided, content will be rendered as a single block
22
+ * For optimal streaming performance, use marked.lexer with GFM enabled
23
+ */
24
+ blockParser?: (content: string) => Array<{
25
+ raw?: string;
26
+ }>;
27
+ /**
28
+ * Override default component mappings
29
+ */
30
+ components?: Partial<Components>;
31
+ };
32
+ type StreamingMarkdownProps = {
33
+ /**
34
+ * Markdown content to render (supports streaming/incomplete markdown)
35
+ */
36
+ content: string;
37
+ /**
38
+ * Unique identifier for this markdown instance (used for keys)
39
+ */
40
+ id: string;
41
+ /**
42
+ * Optional configuration
43
+ */
44
+ options?: StreamingMarkdownOptions;
45
+ };
46
+ /**
47
+ * StreamingMarkdown - A drop-in markdown renderer designed for AI streaming.
48
+ *
49
+ * Features:
50
+ * - Unterminated block parsing (handles incomplete markdown during streaming)
51
+ * - Block-level memoization for performance
52
+ * - Security hardening (validates links/images)
53
+ * - GitHub Flavored Markdown support
54
+ * - KookieUI component integration
55
+ * - Code syntax highlighting via CodeBlock
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * import { StreamingMarkdown } from '@kushagradhawan/kookie-blocks';
60
+ * import { marked } from 'marked';
61
+ *
62
+ * function ChatMessage({ message }) {
63
+ * return (
64
+ * <StreamingMarkdown
65
+ * content={message.content}
66
+ * id={message.id}
67
+ * options={{
68
+ * blockParser: (content) => marked.lexer(content, { gfm: true }),
69
+ * enableBlockMemoization: true,
70
+ * }}
71
+ * />
72
+ * );
73
+ * }
74
+ * ```
75
+ */
76
+ export declare function StreamingMarkdown({ content, id, options }: StreamingMarkdownProps): React.JSX.Element | null;
77
+ export {};
78
+ //# sourceMappingURL=StreamingMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingMarkdown.d.ts","sourceRoot":"","sources":["../../../../src/components/markdown/StreamingMarkdown.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAC7D,OAAsB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAOhE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AASxD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,GAAG;IAChE;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE3D;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CAClC,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACpC,CAAC;AA6CF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAY,EAAE,EAAE,sBAAsB,4BA2CtF"}
@@ -0,0 +1,2 @@
1
+ "use client";import e,{memo as f,useMemo as s}from"react";import u from"react-markdown";import M from"remark-gfm";import O from"rehype-raw";import P from"harden-react-markdown";import{Box as h,Flex as y}from"@kushagradhawan/kookie-ui";import{createMarkdownComponents as C}from"./createMarkdownComponents";import{completeUnterminatedMarkdown as b,parseMarkdownIntoBlocks as B}from"./utils/markdownStreaming";const I=P(u),S=["https://","http://","/"],E=["https://","http://","/","data:"],x=["mailto:","tel:","data:","http:","https:"],L=typeof window<"u"&&window.location?.origin?window.location.origin:"https://app.kookie.ai";function A(o){return o||L}const p=f(({content:o,defaultOrigin:n,components:i})=>e.createElement(h,{width:"100%"},e.createElement(I,{defaultOrigin:n,allowedLinkPrefixes:S,allowedImagePrefixes:E,allowedProtocols:x,allowDataImages:!0,components:i,remarkPlugins:[M],rehypePlugins:[O]},o)),(o,n)=>o.content===n.content&&o.defaultOrigin===n.defaultOrigin&&o.components===n.components);p.displayName="MarkdownBlock";function T({content:o,id:n,options:i={}}){const{defaultOrigin:m,enableBlockMemoization:l=!0,blockParser:a,components:d={},...c}=i,k=s(()=>A(m),[m]),g=s(()=>({...C(c),...d}),[c,d]),r=s(()=>{if(!l||!a){const t=b(o);return t.trim()?[t]:[]}return B(o,a)},[o,l,a]);return r.length?r.length===1?e.createElement(p,{content:r[0],defaultOrigin:k,components:g}):e.createElement(y,{direction:"column",gap:"2",width:"100%"},r.map((t,w)=>e.createElement(p,{key:`${n}-block-${w}`,content:t,defaultOrigin:k,components:g}))):null}export{T as StreamingMarkdown};
2
+ //# sourceMappingURL=StreamingMarkdown.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/markdown/StreamingMarkdown.tsx"],
4
+ "sourcesContent": ["\"use client\";\n\nimport React, { memo, useMemo, type ReactNode } from \"react\";\nimport ReactMarkdown, { type Components } from \"react-markdown\";\nimport remarkGfm from \"remark-gfm\";\nimport rehypeRaw from \"rehype-raw\";\nimport hardenReactMarkdown from \"harden-react-markdown\";\nimport { Box, Flex } from \"@kushagradhawan/kookie-ui\";\nimport { createMarkdownComponents } from \"./createMarkdownComponents\";\nimport { completeUnterminatedMarkdown, parseMarkdownIntoBlocks } from \"./utils/markdownStreaming\";\nimport type { MarkdownComponentOptions } from \"./types\";\n\nconst HardenedMarkdown = hardenReactMarkdown(ReactMarkdown);\n\nconst LINK_PREFIXES = [\"https://\", \"http://\", \"/\"];\nconst IMAGE_PREFIXES = [\"https://\", \"http://\", \"/\", \"data:\"];\nconst ALLOWED_PROTOCOLS = [\"mailto:\", \"tel:\", \"data:\", \"http:\", \"https:\"];\nconst DEFAULT_APP_ORIGIN = typeof window !== \"undefined\" && window.location?.origin ? window.location.origin : \"https://app.kookie.ai\";\n\n/**\n * Options for StreamingMarkdown component\n */\nexport type StreamingMarkdownOptions = MarkdownComponentOptions & {\n /**\n * Security origin for link/image validation\n * @default window.location.origin or \"https://app.kookie.ai\"\n */\n defaultOrigin?: string;\n\n /**\n * Whether to enable block-level memoization for performance\n * Recommended for streaming scenarios where content updates frequently\n * @default true\n */\n enableBlockMemoization?: boolean;\n\n /**\n * Custom parser for splitting content into blocks\n * If not provided, content will be rendered as a single block\n * For optimal streaming performance, use marked.lexer with GFM enabled\n */\n blockParser?: (content: string) => Array<{ raw?: string }>;\n\n /**\n * Override default component mappings\n */\n components?: Partial<Components>;\n};\n\ntype StreamingMarkdownProps = {\n /**\n * Markdown content to render (supports streaming/incomplete markdown)\n */\n content: string;\n\n /**\n * Unique identifier for this markdown instance (used for keys)\n */\n id: string;\n\n /**\n * Optional configuration\n */\n options?: StreamingMarkdownOptions;\n};\n\ntype MarkdownBlockProps = {\n content: string;\n defaultOrigin: string;\n components: Components;\n};\n\n/**\n * Resolves the default origin for security validation\n */\nfunction resolveDefaultOrigin(customOrigin?: string): string {\n if (customOrigin) {\n return customOrigin;\n }\n return DEFAULT_APP_ORIGIN;\n}\n\n/**\n * Memoized markdown block component for efficient streaming rendering\n */\nconst MarkdownBlock = memo(\n ({ content, defaultOrigin, components }: MarkdownBlockProps) => {\n return (\n <Box width=\"100%\">\n <HardenedMarkdown\n defaultOrigin={defaultOrigin}\n allowedLinkPrefixes={LINK_PREFIXES}\n allowedImagePrefixes={IMAGE_PREFIXES}\n allowedProtocols={ALLOWED_PROTOCOLS}\n allowDataImages\n components={components}\n remarkPlugins={[remarkGfm]}\n rehypePlugins={[rehypeRaw]}\n >\n {content}\n </HardenedMarkdown>\n </Box>\n );\n },\n (previous, next) => previous.content === next.content && previous.defaultOrigin === next.defaultOrigin && previous.components === next.components\n);\n\nMarkdownBlock.displayName = \"MarkdownBlock\";\n\n/**\n * StreamingMarkdown - A drop-in markdown renderer designed for AI streaming.\n *\n * Features:\n * - Unterminated block parsing (handles incomplete markdown during streaming)\n * - Block-level memoization for performance\n * - Security hardening (validates links/images)\n * - GitHub Flavored Markdown support\n * - KookieUI component integration\n * - Code syntax highlighting via CodeBlock\n *\n * @example\n * ```tsx\n * import { StreamingMarkdown } from '@kushagradhawan/kookie-blocks';\n * import { marked } from 'marked';\n *\n * function ChatMessage({ message }) {\n * return (\n * <StreamingMarkdown\n * content={message.content}\n * id={message.id}\n * options={{\n * blockParser: (content) => marked.lexer(content, { gfm: true }),\n * enableBlockMemoization: true,\n * }}\n * />\n * );\n * }\n * ```\n */\nexport function StreamingMarkdown({ content, id, options = {} }: StreamingMarkdownProps) {\n const { defaultOrigin: customOrigin, enableBlockMemoization = true, blockParser, components: customComponents = {}, ...componentOptions } = options;\n\n // Resolve security origin\n const defaultOrigin = useMemo(() => resolveDefaultOrigin(customOrigin), [customOrigin]);\n\n // Create component mappings with custom overrides\n const markdownComponents = useMemo(() => {\n const baseComponents = createMarkdownComponents(componentOptions);\n return {\n ...baseComponents,\n ...customComponents,\n };\n }, [componentOptions, customComponents]);\n\n // Parse content into blocks for memoization (if enabled and parser provided)\n const blocks = useMemo(() => {\n if (!enableBlockMemoization || !blockParser) {\n // No block splitting - just complete unterminated markdown\n const completed = completeUnterminatedMarkdown(content);\n return completed.trim() ? [completed] : [];\n }\n\n return parseMarkdownIntoBlocks(content, blockParser);\n }, [content, enableBlockMemoization, blockParser]);\n\n if (!blocks.length) {\n return null;\n }\n\n // Single block - no need for wrapper\n if (blocks.length === 1) {\n return <MarkdownBlock content={blocks[0]} defaultOrigin={defaultOrigin} components={markdownComponents} />;\n }\n\n // Multiple blocks - render with flex wrapper\n return (\n <Flex direction=\"column\" gap=\"2\" width=\"100%\">\n {blocks.map((block, index) => (\n <MarkdownBlock key={`${id}-block-${index}`} content={block} defaultOrigin={defaultOrigin} components={markdownComponents} />\n ))}\n </Flex>\n );\n}\n"],
5
+ "mappings": "aAEA,OAAOA,GAAS,QAAAC,EAAM,WAAAC,MAA+B,QACrD,OAAOC,MAAwC,iBAC/C,OAAOC,MAAe,aACtB,OAAOC,MAAe,aACtB,OAAOC,MAAyB,wBAChC,OAAS,OAAAC,EAAK,QAAAC,MAAY,4BAC1B,OAAS,4BAAAC,MAAgC,6BACzC,OAAS,gCAAAC,EAA8B,2BAAAC,MAA+B,4BAGtE,MAAMC,EAAmBN,EAAoBH,CAAa,EAEpDU,EAAgB,CAAC,WAAY,UAAW,GAAG,EAC3CC,EAAiB,CAAC,WAAY,UAAW,IAAK,OAAO,EACrDC,EAAoB,CAAC,UAAW,OAAQ,QAAS,QAAS,QAAQ,EAClEC,EAAqB,OAAO,OAAW,KAAe,OAAO,UAAU,OAAS,OAAO,SAAS,OAAS,wBA0D/G,SAASC,EAAqBC,EAA+B,CAC3D,OAAIA,GAGGF,CACT,CAKA,MAAMG,EAAgBlB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pCyB,EAAO,IAAI,CAACE,EAAOC,IAClBpC,EAAA,cAACmB,EAAA,CAAc,IAAK,GAAGO,CAAE,UAAUU,CAAK,GAAI,QAASD,EAAO,cAAed,EAAe,WAAYW,EAAoB,CAC3H,CACH,EAdO,IAgBX",
6
+ "names": ["React", "memo", "useMemo", "ReactMarkdown", "remarkGfm", "rehypeRaw", "hardenReactMarkdown", "Box", "Flex", "createMarkdownComponents", "completeUnterminatedMarkdown", "parseMarkdownIntoBlocks", "HardenedMarkdown", "LINK_PREFIXES", "IMAGE_PREFIXES", "ALLOWED_PROTOCOLS", "DEFAULT_APP_ORIGIN", "resolveDefaultOrigin", "customOrigin", "MarkdownBlock", "content", "defaultOrigin", "components", "previous", "next", "StreamingMarkdown", "id", "options", "enableBlockMemoization", "blockParser", "customComponents", "componentOptions", "markdownComponents", "blocks", "completed", "block", "index"]
7
+ }
@@ -0,0 +1,27 @@
1
+ import type { Components } from "react-markdown";
2
+ import type { MarkdownComponentOptions } from "./types";
3
+ /**
4
+ * Creates markdown component mappings that work with both react-markdown and MDX.
5
+ * Uses KookieUI components for consistent styling across all projects.
6
+ *
7
+ * @param options - Optional configuration for component behavior
8
+ * @returns Component mappings for markdown/MDX renderers
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * // In react-markdown
13
+ * <ReactMarkdown components={createMarkdownComponents()}>
14
+ * {content}
15
+ * </ReactMarkdown>
16
+ *
17
+ * // In MDX
18
+ * export function useMDXComponents(components: MDXComponents) {
19
+ * return {
20
+ * ...createMarkdownComponents(),
21
+ * ...components,
22
+ * };
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function createMarkdownComponents(options?: MarkdownComponentOptions): Components;
27
+ //# sourceMappingURL=createMarkdownComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMarkdownComponents.d.ts","sourceRoot":"","sources":["../../../../src/components/markdown/createMarkdownComponents.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,wBAAwB,EAAyB,MAAM,SAAS,CAAC;AA8B/E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,wBAA6B,GAAG,UAAU,CAmJ3F"}
@@ -0,0 +1,3 @@
1
+ import r from"react";import{Blockquote as u,Box as p,Code as C,Heading as d,Text as g,Table as l}from"@kushagradhawan/kookie-ui";import{CodeBlock as w}from"../code";function y(o){return o?o.match(/language-([\w-]+)/i)?.[1]??"text":"text"}function k(o){let n="";return o?(typeof o=="string"?n=o:Array.isArray(o)&&(n=o.map(s=>typeof s=="string"?s:"").join("")),n.replace(/^\n+|\n+$/g,"")):n}function H(o={}){const{codeBlockCollapsible:n=!1,imageComponent:s,inlineCodeHighContrast:h=!0}=o;return{h1:({children:e})=>r.createElement(d,{size:"8",weight:"medium",as:"h1",style:{marginTop:"1rem",marginBottom:"0.5rem"}},e),h2:({children:e})=>r.createElement(d,{weight:"medium",size:"5",as:"h2",style:{marginTop:"0.875rem",marginBottom:"0.5rem"}},e),h3:({children:e})=>r.createElement(d,{weight:"medium",size:"4",as:"h3",style:{marginTop:"0.75rem",marginBottom:"0.5rem"}},e),h4:({children:e})=>r.createElement(d,{weight:"medium",size:"3",as:"h4",style:{marginTop:"0.625rem",marginBottom:"0.5rem"}},e),h5:({children:e})=>r.createElement(d,{weight:"medium",size:"3",as:"h5",style:{marginTop:"0.5rem",marginBottom:"0.5rem"}},e),h6:({children:e})=>r.createElement(d,{weight:"medium",size:"3",as:"h6",style:{marginTop:"0.5rem",marginBottom:"0.5rem"}},e),p:({children:e})=>r.createElement(g,{size:"3",as:"p",style:{lineHeight:"1.6"}},e),code:({className:e,children:i,inline:m})=>{const t=k(i);return m===!0||m===void 0&&!e&&!t.includes(`
2
+ `)&&t.length<100?r.createElement(C,{highContrast:h,size:"3"},t):r.createElement(p,{my:"2",style:{minWidth:0}},r.createElement(w,{code:t,language:y(e),collapsible:n}))},ul:({children:e})=>r.createElement("ul",{style:{marginTop:"0.5rem",marginBottom:"0.5rem",lineHeight:"1.6",paddingLeft:"1.5rem",listStyleType:"disc"}},e),ol:({children:e})=>r.createElement("ol",{style:{marginTop:"0.5rem",marginBottom:"0.5rem",lineHeight:"1.6",paddingLeft:"1.5rem",listStyleType:"decimal"}},e),li:({children:e})=>r.createElement("li",{style:{marginBottom:"0.25rem",lineHeight:"1.6"}},e),blockquote:({children:e})=>r.createElement(u,null,e),a:({href:e,children:i})=>r.createElement("a",{href:e,style:{color:"var(--accent-9)",textDecoration:"underline"}},i),strong:({children:e})=>r.createElement(g,{weight:"medium",style:{lineHeight:"1.6"}},e),em:({children:e})=>r.createElement(g,{style:{lineHeight:"1.6",fontStyle:"italic"}},e),hr:()=>r.createElement("hr",{style:{color:"var(--gray-6)",marginTop:"0.5rem",marginBottom:"0.5rem",height:"1px",width:"100%",opacity:.5}}),pre:({children:e})=>r.createElement(r.Fragment,null,e),table:({children:e})=>r.createElement(p,{my:"2",style:{overflowX:"auto"}},r.createElement(l.Root,{size:"2",variant:"ghost"},e)),thead:({children:e})=>r.createElement(l.Header,null,e),tbody:({children:e})=>r.createElement(l.Body,null,e),tr:({children:e})=>r.createElement(l.Row,null,e),th:({children:e})=>r.createElement(l.ColumnHeaderCell,null,e),td:({children:e})=>r.createElement(l.Cell,null,e),sub:({children:e})=>r.createElement("sub",null,e),sup:({children:e})=>r.createElement("sup",null,e),br:()=>r.createElement("br",null),img:s?e=>{const{src:i,alt:m,width:t,height:a}=e;return!i||typeof i!="string"?null:s({src:i,alt:m??"Image",width:t?String(t):void 0,height:a?String(a):void 0})}:void 0,details:({children:e})=>r.createElement("details",{style:{padding:"0.5rem 0"}},e),summary:({children:e})=>r.createElement("summary",{style:{cursor:"pointer",fontWeight:500}},e)}}export{H as createMarkdownComponents};
3
+ //# sourceMappingURL=createMarkdownComponents.js.map