@stackone/malachite 2.130.1 → 2.132.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlock.js","sources":["../../src/components/CodeBlock.tsx"],"sourcesContent":["import JsonView from '@uiw/react-json-view';\nimport React from 'react';\nimport CopyOverlayButton from './CopyOverlayButton';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { devWarning } from './devWarning';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\n\n/**\n * The value side of a JSON literal that has no value of its own to print, in its type's\n * colour. These read as keywords, as `true` and `false` do: the comment grey is under AA\n * contrast on the light background.\n */\nconst renderLiteral =\n (text: string, type: 'null' | 'undefined' | 'nan') =>\n (props: React.HTMLAttributes<HTMLSpanElement>, { type: part }: { type: 'type' | 'value' }) =>\n part === 'value' ? (\n <span {...props} style={{ ...props.style, color: `var(--w-rjv-type-${type}-color)` }}>\n {text}\n </span>\n ) : null;\n\n/** A json node's own entries, as the library counts them to draw it. */\nconst entryCount = (value: unknown): number =>\n value !== null && typeof value === 'object' ? Object.keys(value).length : 0;\n\n/** A nested node over the limit: the only kind the limit folds, toggles and sizes. */\nconst isOverLimit = (limit: number, value: unknown, keys: readonly (number | string)[]): boolean =>\n keys.length > 0 && entryCount(value) > limit;\n\nconst sizeOf = (value: unknown): string => {\n const count = entryCount(value);\n return `${count} ${count === 1 ? 'item' : 'items'}`;\n};\n\n/** Where a node sits, so two toggles for nodes sharing a key read apart: `users.0.roles`. */\nconst pathOf = (keys: readonly (number | string)[]): string =>\n keys.map((key) => String(key) || '\"\"').join('.');\n\n// The library's flag is the inverse of its name: returning true starts the node collapsed.\nconst collapseNodesLargerThan =\n (limit: number) =>\n (\n isCollapsed: boolean,\n { value, keys }: { value?: unknown; keys: (number | string)[] },\n ): boolean =>\n isCollapsed || isOverLimit(limit, value, keys);\n\n// The row around the arrow owns the click and the arrow's rotation is its only state, so this\n// button is a keyboard toggle that reads `aria-expanded` from it.\nconst toggleArrowOver =\n (limit: number) =>\n (\n props: { className?: string; style?: React.CSSProperties; children?: React.ReactNode },\n { value, keys }: { value?: unknown; keys?: (number | string)[] },\n ) => {\n if (!isOverLimit(limit, value, keys ?? [])) {\n return null;\n }\n const collapsed = String(props.style?.transform ?? '').includes('-90');\n return (\n <button\n type=\"button\"\n aria-expanded={!collapsed}\n aria-label={`${pathOf(keys ?? [])}, ${sizeOf(value)}`}\n className={`${props.className ?? ''} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${FOCUS_RING}`}\n style={props.style}\n >\n {props.children}\n </button>\n );\n };\n\nconst foldedSizeOver =\n (limit: number) =>\n // This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.\n (props: object, { value, keyName }: { value?: unknown; keyName?: string | number }) =>\n Reflect.get(props, 'data-expanded') &&\n isOverLimit(limit, value, keyName === undefined ? [] : [keyName]) ? (\n // Its toggle already names the size, so this would say it twice.\n <span\n aria-hidden=\"true\"\n className={`${Reflect.get(props, 'className') ?? ''} mx-[4px] cursor-pointer select-none text-[var(--malachite-codeblock-foreground)]`}\n >\n {`\\u2026 ${sizeOf(value)}`}\n </span>\n ) : null;\n\nconst CodeBlockHighlighter = React.lazy(() => import('./CodeBlockHighlighter'));\n\nexport interface CodeBlockProps {\n /** The code content to display */\n code?: string;\n /** JSON object to display as formatted JSON */\n json?: object;\n /** Show line numbers */\n showLineNumbers?: boolean;\n /** Custom class name */\n className?: string;\n /** Custom styles */\n style?: React.CSSProperties;\n /** Height of the code block */\n height?: string | number;\n /** Enable copy functionality */\n enableCopy?: boolean;\n /** Wrap long lines instead of scrolling horizontally */\n wrapLines?: boolean;\n /**\n * Highlight the code with this language's grammar. `cedar` is a grammar this library\n * ships itself (`prismCedar.ts`), since Prism and refractor carry none; widen the union\n * as further grammars are registered in CodeBlockHighlighter.\n */\n language?: 'yaml' | 'cedar';\n /** How much of a `json` tree starts collapsed: `true` all of it, a number below that depth. */\n collapsed?: boolean | number;\n /**\n * Starts any nested node with more entries than this collapsed, at any depth, behind a keyboard\n * toggle naming its path and size; nodes within the limit keep the library's arrow. 0 or more.\n */\n collapseLargerThan?: number;\n /**\n * Renders the change between two texts rather than one text, and takes precedence over\n * `code` and `json`. Only the changed lines are shown, with `context` unchanged ones either\n * side, so a small edit to a long document reads as a few hunks instead of the whole thing.\n */\n diff?: {\n before: string;\n after: string;\n /** Unchanged lines kept either side of each change. Three by convention. */\n context?: number;\n /**\n * Swaps the `+`/`-` gutter and tinted rows for the palette a mock specified for\n * AI-authored changes: star, minus-sign and middle-dot markers, and a struck-through\n * removal. Omit to keep the neutral markers; there is no default consumer for the\n * assistant look yet.\n */\n origin?: 'assistant';\n };\n /** Names the scrollable region, and the copy button as \"Copy\" and this. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region and the copy button by a visible label instead of `aria-label`. */\n 'aria-labelledby'?: string;\n}\n\nconst DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-added-background)',\n removed: 'var(--malachite-codeblock-diff-removed-background)',\n context: undefined,\n};\n\nconst DIFF_MARKERS: Record<DiffRowType, string | undefined> = {\n added: '+',\n removed: '-',\n context: undefined,\n};\n\n// The assistant palette also marks context rows, which the neutral one leaves bare.\nconst ASSISTANT_DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-assistant-background)',\n removed: 'var(--malachite-codeblock-diff-assistant-removed-background)',\n context: undefined,\n};\n\nconst ASSISTANT_DIFF_MARKERS: Record<DiffRowType, string> = {\n added: '\\u2726',\n // U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.\n removed: '\\u2212',\n context: '\\u00b7',\n};\n\nconst ASSISTANT_DIFF_MARKER_COLORS: Record<DiffRowType, string> = {\n added: 'var(--malachite-codeblock-diff-assistant-foreground)',\n removed: 'var(--malachite-codeblock-diff-removed-foreground)',\n context: 'var(--malachite-codeblock-diff-context-foreground)',\n};\n\nconst unchangedRun = (count: number): string =>\n `\\u22ef ${count} unchanged ${count === 1 ? 'line' : 'lines'}`;\n\nconst diffDecoration = (\n row: DiffDisplayRow,\n showLineNumbers: boolean,\n origin?: 'assistant',\n): CodeLineDecoration => {\n const assistant = origin === 'assistant';\n\n return {\n background: assistant ? ASSISTANT_DIFF_BACKGROUNDS[row.type] : DIFF_BACKGROUNDS[row.type],\n marker: assistant ? ASSISTANT_DIFF_MARKERS[row.type] : DIFF_MARKERS[row.type],\n markerColor: assistant ? ASSISTANT_DIFF_MARKER_COLORS[row.type] : undefined,\n // Reserved on unchanged rows too, so the code column does not step in and out.\n reserveMarker: true,\n // Context rows read as de-emphasised, not just unmarked, in the assistant palette.\n textColor:\n assistant && row.type === 'context'\n ? 'var(--malachite-codeblock-diff-context-text)'\n : undefined,\n strikethrough: assistant && row.type === 'removed',\n separatorAbove: row.skippedAbove === undefined ? undefined : unchangedRun(row.skippedAbove),\n // A removed line has no number in the after-text, so it keeps the one it had before.\n lineNumber: showLineNumbers ? (row.afterNumber ?? row.beforeNumber) : undefined,\n };\n};\n\nconst CodeBlock: React.FC<CodeBlockProps> = ({\n code,\n json,\n showLineNumbers = true,\n className = '',\n style = {},\n height,\n enableCopy = true,\n wrapLines = false,\n language,\n collapsed = false,\n collapseLargerThan,\n diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const copyId = React.useId();\n const limit =\n collapseLargerThan !== undefined &&\n Number.isInteger(collapseLargerThan) &&\n collapseLargerThan >= 0\n ? collapseLargerThan\n : undefined;\n if (collapseLargerThan !== undefined && limit === undefined) {\n devWarning(\n `CodeBlock.collapseLargerThan:${collapseLargerThan}`,\n `CodeBlock's collapseLargerThan takes a whole count of 0 or more; ${collapseLargerThan} is ignored.`,\n );\n }\n const diffRows = diff ? diffHunks(diff.before, diff.after, diff.context) : null;\n const diffText = diffRows?.map((row) => row.text).join('\\n') ?? '';\n\n /**\n * What the button puts on the clipboard, in the same form the block is showing. A JSON\n * block is pretty-printed rather than handed over minified: the reader is copying what\n * they can see. `undefined` means there is nothing to copy and no button to offer.\n */\n const copyText = (): string | undefined => {\n if (diffRows) {\n return diffText;\n }\n\n // An empty block has nothing to copy, so it offers no button — `!== undefined` would\n // hand back the empty string and put a dead control on it.\n if (code) {\n return code;\n }\n\n if (json !== undefined) {\n try {\n return JSON.stringify(json, null, 2);\n } catch {\n // A cycle or a BigInt: no honest text to copy, so offer no button.\n return undefined;\n }\n }\n\n return undefined;\n };\n\n const textToCopy = copyText();\n\n // Declared once and rendered by both the JSON branch and the code branch below, so the\n // two tabs of one document do not disagree about whether it can be copied.\n const copyButton = enableCopy && textToCopy !== undefined && (\n <CopyOverlayButton\n text={textToCopy}\n // Named after the block, so a page of blocks has a \"Copy\" for each rather than\n // several alike. Its own id leads the list to keep the word \"Copy\" in the name.\n {...(ariaLabelledBy\n ? {\n id: copyId,\n 'aria-label': 'Copy',\n 'aria-labelledby': `${copyId} ${ariaLabelledBy}`,\n }\n : { 'aria-label': ariaLabel ? `Copy ${ariaLabel}` : 'Copy' })}\n iconSize={14}\n className={`absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${FOCUS_RING}`}\n style={{ color: 'var(--malachite-codeblock-line-number)' }}\n />\n );\n\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n const viewportProps = {\n role: 'region',\n 'aria-label': ariaLabelledBy ? ariaLabel : (ariaLabel ?? 'Code'),\n 'aria-labelledby': ariaLabelledBy,\n tabIndex: 0,\n className: `box-border h-full overflow-auto ${FOCUS_RING_INSET}`,\n } satisfies React.HTMLAttributes<HTMLElement>;\n\n // If JSON is provided, use JsonView component\n if (json && !diffRows) {\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {/* The frame clips at `height`; this scrolls inside it, so the copy button stays put. */}\n <div {...viewportProps}>\n <JsonView\n value={json}\n style={\n {\n backgroundColor: 'var(--malachite-codeblock-background)',\n color: 'var(--malachite-codeblock-foreground)',\n fontSize: '14px',\n fontFamily: 'var(--malachite-font-mono, monospace)',\n padding: '16px',\n lineHeight: '1.5',\n textAlign: 'left',\n '--w-rjv-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-key-string': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-background-color': 'var(--malachite-codeblock-background)',\n '--w-rjv-line-color': 'var(--malachite-codeblock-border)',\n '--w-rjv-arrow-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-edit-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-info-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-update-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-copied-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-copied-success-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-curlybraces-color':\n 'var(--malachite-codeblock-foreground)',\n '--w-rjv-colon-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-brackets-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-quotes-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-quotes-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-int-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-float-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-bigint-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-boolean-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-date-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-url-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-null-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-nan-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-undefined-color':\n 'var(--malachite-codeblock-keyword)',\n } as React.CSSProperties\n }\n displayDataTypes={false}\n enableClipboard={enableCopy}\n collapsed={collapsed}\n shouldExpandNodeInitially={\n limit === undefined ? undefined : collapseNodesLargerThan(limit)\n }\n displayObjectSize={false}\n >\n {/* The library draws these three only as their type label, which\n `displayDataTypes` turns off, so without a value of their own a\n `null` reads as a key with nothing after it. */}\n <JsonView.Null render={renderLiteral('null', 'null')} />\n <JsonView.Undefined render={renderLiteral('undefined', 'undefined')} />\n <JsonView.Nan render={renderLiteral('NaN', 'nan')} />\n {/* Mounted either way: the library keeps a slot's last render, so it is\n switched off by passing none rather than by unmounting. */}\n <JsonView.Arrow\n render={limit === undefined ? undefined : toggleArrowOver(limit)}\n />\n <JsonView.Ellipsis\n render={limit === undefined ? undefined : foldedSizeOver(limit)}\n />\n </JsonView>\n </div>\n </div>\n );\n }\n\n // Reserve clearance so a wide first line never sits under the floating copy button.\n const copyClearance = enableCopy && (!!code || !!diffRows);\n\n const renderPlainLines = (\n text: string,\n decorate?: (index: number) => CodeLineDecoration | undefined,\n ) => {\n const lines = text.split('\\n');\n\n return (\n <div\n {...viewportProps}\n className={`${viewportProps.className} p-4 text-left`}\n style={{ paddingRight: copyClearance ? 44 : undefined }}\n >\n <div style={rowsWrapperStyle(wrapLines)}>\n {lines.map((line, index) => {\n const decoration = decorate?.(index);\n\n return (\n <CodeLine\n key={index}\n line={line}\n lineNumber={\n decoration?.lineNumber ??\n (showLineNumbers ? index + 1 : undefined)\n }\n wrap={wrapLines}\n decoration={decoration}\n >\n {line}\n </CodeLine>\n );\n })}\n </div>\n </div>\n );\n };\n\n const renderPlainCode = () => (code ? renderPlainLines(code) : null);\n\n const renderDiff = (rows: DiffDisplayRow[]) => {\n if (rows.length === 0) {\n return (\n <div\n className=\"p-4 text-left\"\n style={{ color: 'var(--malachite-codeblock-comment)' }}\n >\n No changes\n </div>\n );\n }\n\n const decorate = (index: number) => {\n const row = rows[index];\n\n return row ? diffDecoration(row, showLineNumbers, diff?.origin) : undefined;\n };\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainLines(diffText, decorate)}>\n {/*\n * The whole merged text goes to the highlighter in one piece, so a hunk\n * is tokenised in the company of its neighbours rather than on its own.\n * Prism still cannot see the lines the hunks left out, so a construct\n * spanning an omitted run can highlight oddly — the reason `context`\n * defaults to a few lines rather than none.\n */}\n <CodeBlockHighlighter\n code={diffText}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n decorate={decorate}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainLines(diffText, decorate);\n };\n\n // For code strings, create a simple syntax-highlighted view\n const renderCodeContent = () => {\n if (!code) {\n return null;\n }\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainCode()}>\n <CodeBlockHighlighter\n code={code}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainCode();\n };\n\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {diffRows ? renderDiff(diffRows) : renderCodeContent()}\n </div>\n );\n};\n\nexport default CodeBlock;\n"],"names":["renderLiteral","text","type","props","part","jsx","entryCount","value","isOverLimit","limit","keys","sizeOf","count","pathOf","key","collapseNodesLargerThan","isCollapsed","toggleArrowOver","collapsed","_a","FOCUS_RING","foldedSizeOver","keyName","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapseLargerThan","diff","ariaLabel","ariaLabelledBy","copyId","devWarning","diffRows","diffHunks","diffText","textToCopy","copyButton","CopyOverlayButton","viewportProps","FOCUS_RING_INSET","jsxs","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;AAcA,MAAMA,IACF,CAACC,GAAcC,MACf,CAACC,GAA8C,EAAE,MAAMC,EAAA,MACnDA,MAAS,UACL,gBAAAC,EAAC,QAAA,EAAM,GAAGF,GAAO,OAAO,EAAE,GAAGA,EAAM,OAAO,OAAO,oBAAoBD,CAAI,UAAA,GACpE,UAAAD,EAAA,CACL,IACA,MAGNK,IAAa,CAACC,MAChBA,MAAU,QAAQ,OAAOA,KAAU,WAAW,OAAO,KAAKA,CAAK,EAAE,SAAS,GAGxEC,IAAc,CAACC,GAAeF,GAAgBG,MAChDA,EAAK,SAAS,KAAKJ,EAAWC,CAAK,IAAIE,GAErCE,IAAS,CAACJ,MAA2B;AACvC,QAAMK,IAAQN,EAAWC,CAAK;AAC9B,SAAO,GAAGK,CAAK,IAAIA,MAAU,IAAI,SAAS,OAAO;AACrD,GAGMC,IAAS,CAACH,MACZA,EAAK,IAAI,CAACI,MAAQ,OAAOA,CAAG,KAAK,IAAI,EAAE,KAAK,GAAG,GAG7CC,IACF,CAACN,MACD,CACIO,GACA,EAAE,OAAAT,GAAO,MAAAG,EAAA,MAETM,KAAeR,EAAYC,GAAOF,GAAOG,CAAI,GAI/CO,IACF,CAACR,MACD,CACIN,GACA,EAAE,OAAAI,GAAO,MAAAG,QACR;;AACD,MAAI,CAACF,EAAYC,GAAOF,GAAOG,KAAQ,CAAA,CAAE;AACrC,WAAO;AAEX,QAA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AAkB;AAChC,YAAMnC,IAAMwC,EAAKL,CAAK;AAEtB,aAAOnC,IAAMD,GAAeC,GAAKC,GAAiBa,KAAA,gBAAAA,EAAM,MAAM,IAAI;AAAA,IACtE;AAEA,WAAIF,IAEI,gBAAAvC,EAACmB,EAAM,UAAN,EAAe,UAAUsC,EAAiBT,GAAUU,CAAQ,GAQzD,UAAA,gBAAA1D;AAAA,MAACkB;AAAA,MAAA;AAAA,QACG,MAAM8B;AAAA,QACN,UAAAT;AAAA,QACA,iBAAAX;AAAA,QACA,WAAAU;AAAA,QACA,eAAAkB;AAAA,QACA,UAAAE;AAAA,QACA,eAAAN;AAAA,MAAA;AAAA,IAAA,GAER,IAIDK,EAAiBT,GAAUU,CAAQ;AAAA,EAC9C,GAGMU,IAAoB,MACjBpC,IAIDO,sBAEKpB,EAAM,UAAN,EAAe,UAAU8C,KACtB,UAAA,gBAAAjE;AAAA,IAACkB;AAAA,IAAA;AAAA,MACG,MAAAc;AAAA,MACA,UAAAO;AAAA,MACA,iBAAAX;AAAA,MACA,WAAAU;AAAA,MACA,eAAAkB;AAAA,MACA,eAAAJ;AAAA,IAAA;AAAA,EAAA,GAER,IAIDa,EAAA,IAlBI;AAqBf,SACI,gBAAAX;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,2DAA2DpB,CAAS;AAAA,MAC/E,OAAO;AAAA,QACH,iBAAiB;AAAA,QACjB,aAAa;AAAA,QACb,QAAAE;AAAA,QACA,GAAGD;AAAA,MAAA;AAAA,MAGN,UAAA;AAAA,QAAAe;AAAA,QACAJ,IAAWoB,EAAWpB,CAAQ,IAAIsB,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
1
+ {"version":3,"file":"CodeBlock.js","sources":["../../src/components/CodeBlock.tsx"],"sourcesContent":["import JsonView from '@uiw/react-json-view';\nimport React from 'react';\nimport CopyOverlayButton from './CopyOverlayButton';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { CODE_TOKEN_COLOR, rowsWrapperStyle } from './codeBlockStyles';\nimport { devWarning } from './devWarning';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\n\n/**\n * The value side of a JSON literal that has no value of its own to print, in its type's\n * colour. These read as keywords, as `true` and `false` do: the comment grey is under AA\n * contrast on the light background.\n */\nconst renderLiteral =\n (text: string, type: 'null' | 'undefined' | 'nan') =>\n (props: React.HTMLAttributes<HTMLSpanElement>, { type: part }: { type: 'type' | 'value' }) =>\n part === 'value' ? (\n <span {...props} style={{ ...props.style, color: `var(--w-rjv-type-${type}-color)` }}>\n {text}\n </span>\n ) : null;\n\n/** A json node's own entries, as the library counts them to draw it. */\nconst entryCount = (value: unknown): number =>\n value !== null && typeof value === 'object' ? Object.keys(value).length : 0;\n\n/** A nested node over the limit: the only kind the limit folds, toggles and sizes. */\nconst isOverLimit = (limit: number, value: unknown, keys: readonly (number | string)[]): boolean =>\n keys.length > 0 && entryCount(value) > limit;\n\nconst sizeOf = (value: unknown): string => {\n const count = entryCount(value);\n return `${count} ${count === 1 ? 'item' : 'items'}`;\n};\n\n/** Where a node sits, so two toggles for nodes sharing a key read apart: `users.0.roles`. */\nconst pathOf = (keys: readonly (number | string)[]): string =>\n keys.map((key) => String(key) || '\"\"').join('.');\n\n// The library's flag is the inverse of its name: returning true starts the node collapsed.\nconst collapseNodesLargerThan =\n (limit: number) =>\n (\n isCollapsed: boolean,\n { value, keys }: { value?: unknown; keys: (number | string)[] },\n ): boolean =>\n isCollapsed || isOverLimit(limit, value, keys);\n\n// The row around the arrow owns the click and the arrow's rotation is its only state, so this\n// button is a keyboard toggle that reads `aria-expanded` from it.\nconst toggleArrowOver =\n (limit: number) =>\n (\n props: { className?: string; style?: React.CSSProperties; children?: React.ReactNode },\n { value, keys }: { value?: unknown; keys?: (number | string)[] },\n ) => {\n if (!isOverLimit(limit, value, keys ?? [])) {\n return null;\n }\n const collapsed = String(props.style?.transform ?? '').includes('-90');\n return (\n <button\n type=\"button\"\n aria-expanded={!collapsed}\n aria-label={`${pathOf(keys ?? [])}, ${sizeOf(value)}`}\n className={`${props.className ?? ''} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${FOCUS_RING}`}\n style={props.style}\n >\n {props.children}\n </button>\n );\n };\n\nconst foldedSizeOver =\n (limit: number) =>\n // This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.\n (props: object, { value, keyName }: { value?: unknown; keyName?: string | number }) =>\n Reflect.get(props, 'data-expanded') &&\n isOverLimit(limit, value, keyName === undefined ? [] : [keyName]) ? (\n // Its toggle already names the size, so this would say it twice.\n <span\n aria-hidden=\"true\"\n className={`${Reflect.get(props, 'className') ?? ''} mx-[4px] cursor-pointer select-none text-[var(--malachite-codeblock-foreground)]`}\n >\n {`\\u2026 ${sizeOf(value)}`}\n </span>\n ) : null;\n\nconst CodeBlockHighlighter = React.lazy(() => import('./CodeBlockHighlighter'));\n\nexport interface CodeBlockProps {\n /** The code content to display */\n code?: string;\n /** JSON object to display as formatted JSON */\n json?: object;\n /** Show line numbers */\n showLineNumbers?: boolean;\n /** Custom class name */\n className?: string;\n /** Custom styles */\n style?: React.CSSProperties;\n /** Height of the code block */\n height?: string | number;\n /** Enable copy functionality */\n enableCopy?: boolean;\n /** Wrap long lines instead of scrolling horizontally */\n wrapLines?: boolean;\n /**\n * Highlight the code with this language's grammar. `cedar` is a grammar this library\n * ships itself (`prismCedar.ts`), since Prism and refractor carry none; widen the union\n * as further grammars are registered in CodeBlockHighlighter.\n */\n language?: 'yaml' | 'cedar';\n /** How much of a `json` tree starts collapsed: `true` all of it, a number below that depth. */\n collapsed?: boolean | number;\n /**\n * Starts any nested node with more entries than this collapsed, at any depth, behind a keyboard\n * toggle naming its path and size; nodes within the limit keep the library's arrow. 0 or more.\n */\n collapseLargerThan?: number;\n /**\n * Renders the change between two texts rather than one text, and takes precedence over\n * `code` and `json`. Only the changed lines are shown, with `context` unchanged ones either\n * side, so a small edit to a long document reads as a few hunks instead of the whole thing.\n */\n diff?: {\n before: string;\n after: string;\n /** Unchanged lines kept either side of each change. Three by convention. */\n context?: number;\n /**\n * Swaps the `+`/`-` gutter and tinted rows for the palette a mock specified for\n * AI-authored changes: star, minus-sign and middle-dot markers, and a struck-through\n * removal. Omit to keep the neutral markers; there is no default consumer for the\n * assistant look yet.\n */\n origin?: 'assistant';\n };\n /** Names the scrollable region, and the copy button as \"Copy\" and this. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region and the copy button by a visible label instead of `aria-label`. */\n 'aria-labelledby'?: string;\n}\n\nconst DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-added-background)',\n removed: 'var(--malachite-codeblock-diff-removed-background)',\n context: undefined,\n};\n\nconst DIFF_MARKERS: Record<DiffRowType, string | undefined> = {\n added: '+',\n removed: '-',\n context: undefined,\n};\n\n// The assistant palette also marks context rows, which the neutral one leaves bare.\nconst ASSISTANT_DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-assistant-background)',\n removed: 'var(--malachite-codeblock-diff-assistant-removed-background)',\n context: undefined,\n};\n\nconst ASSISTANT_DIFF_MARKERS: Record<DiffRowType, string> = {\n added: '\\u2726',\n // U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.\n removed: '\\u2212',\n context: '\\u00b7',\n};\n\nconst ASSISTANT_DIFF_MARKER_COLORS: Record<DiffRowType, string> = {\n added: 'var(--malachite-codeblock-diff-assistant-foreground)',\n removed: 'var(--malachite-codeblock-diff-removed-foreground)',\n context: 'var(--malachite-codeblock-diff-context-foreground)',\n};\n\nconst unchangedRun = (count: number): string =>\n `\\u22ef ${count} unchanged ${count === 1 ? 'line' : 'lines'}`;\n\nconst diffDecoration = (\n row: DiffDisplayRow,\n showLineNumbers: boolean,\n origin?: 'assistant',\n): CodeLineDecoration => {\n const assistant = origin === 'assistant';\n\n return {\n background: assistant ? ASSISTANT_DIFF_BACKGROUNDS[row.type] : DIFF_BACKGROUNDS[row.type],\n marker: assistant ? ASSISTANT_DIFF_MARKERS[row.type] : DIFF_MARKERS[row.type],\n markerColor: assistant ? ASSISTANT_DIFF_MARKER_COLORS[row.type] : undefined,\n // Reserved on unchanged rows too, so the code column does not step in and out.\n reserveMarker: true,\n // Context rows read as de-emphasised, not just unmarked, in the assistant palette.\n textColor:\n assistant && row.type === 'context'\n ? 'var(--malachite-codeblock-diff-context-text)'\n : undefined,\n strikethrough: assistant && row.type === 'removed',\n separatorAbove: row.skippedAbove === undefined ? undefined : unchangedRun(row.skippedAbove),\n // A removed line has no number in the after-text, so it keeps the one it had before.\n lineNumber: showLineNumbers ? (row.afterNumber ?? row.beforeNumber) : undefined,\n };\n};\n\nconst CodeBlock: React.FC<CodeBlockProps> = ({\n code,\n json,\n showLineNumbers = true,\n className = '',\n style = {},\n height,\n enableCopy = true,\n wrapLines = false,\n language,\n collapsed = false,\n collapseLargerThan,\n diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const copyId = React.useId();\n const limit =\n collapseLargerThan !== undefined &&\n Number.isInteger(collapseLargerThan) &&\n collapseLargerThan >= 0\n ? collapseLargerThan\n : undefined;\n if (collapseLargerThan !== undefined && limit === undefined) {\n devWarning(\n `CodeBlock.collapseLargerThan:${collapseLargerThan}`,\n `CodeBlock's collapseLargerThan takes a whole count of 0 or more; ${collapseLargerThan} is ignored.`,\n );\n }\n const diffRows = diff ? diffHunks(diff.before, diff.after, diff.context) : null;\n const diffText = diffRows?.map((row) => row.text).join('\\n') ?? '';\n\n /**\n * What the button puts on the clipboard, in the same form the block is showing. A JSON\n * block is pretty-printed rather than handed over minified: the reader is copying what\n * they can see. `undefined` means there is nothing to copy and no button to offer.\n */\n const copyText = (): string | undefined => {\n if (diffRows) {\n return diffText;\n }\n\n // An empty block has nothing to copy, so it offers no button — `!== undefined` would\n // hand back the empty string and put a dead control on it.\n if (code) {\n return code;\n }\n\n if (json !== undefined) {\n try {\n return JSON.stringify(json, null, 2);\n } catch {\n // A cycle or a BigInt: no honest text to copy, so offer no button.\n return undefined;\n }\n }\n\n return undefined;\n };\n\n const textToCopy = copyText();\n\n // Declared once and rendered by both the JSON branch and the code branch below, so the\n // two tabs of one document do not disagree about whether it can be copied.\n const copyButton = enableCopy && textToCopy !== undefined && (\n <CopyOverlayButton\n text={textToCopy}\n // Named after the block, so a page of blocks has a \"Copy\" for each rather than\n // several alike. Its own id leads the list to keep the word \"Copy\" in the name.\n {...(ariaLabelledBy\n ? {\n id: copyId,\n 'aria-label': 'Copy',\n 'aria-labelledby': `${copyId} ${ariaLabelledBy}`,\n }\n : { 'aria-label': ariaLabel ? `Copy ${ariaLabel}` : 'Copy' })}\n iconSize={14}\n className={`absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${FOCUS_RING}`}\n style={{ color: 'var(--malachite-codeblock-line-number)' }}\n />\n );\n\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n const viewportProps = {\n role: 'region',\n 'aria-label': ariaLabelledBy ? ariaLabel : (ariaLabel ?? 'Code'),\n 'aria-labelledby': ariaLabelledBy,\n tabIndex: 0,\n className: `box-border h-full overflow-auto ${FOCUS_RING_INSET}`,\n } satisfies React.HTMLAttributes<HTMLElement>;\n\n // If JSON is provided, use JsonView component\n if (json && !diffRows) {\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {/* The frame clips at `height`; this scrolls inside it, so the copy button stays put. */}\n <div {...viewportProps}>\n <JsonView\n value={json}\n style={\n {\n backgroundColor: 'var(--malachite-codeblock-background)',\n color: 'var(--malachite-codeblock-foreground)',\n fontSize: '14px',\n fontFamily: 'var(--malachite-font-mono, monospace)',\n padding: '16px',\n lineHeight: '1.5',\n textAlign: 'left',\n '--w-rjv-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-key-string': CODE_TOKEN_COLOR.keyword,\n '--w-rjv-background-color': 'var(--malachite-codeblock-background)',\n '--w-rjv-line-color': 'var(--malachite-codeblock-border)',\n '--w-rjv-arrow-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-edit-color': CODE_TOKEN_COLOR.keyword,\n '--w-rjv-info-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-update-color': CODE_TOKEN_COLOR.keyword,\n '--w-rjv-copied-color': CODE_TOKEN_COLOR.string,\n '--w-rjv-copied-success-color': CODE_TOKEN_COLOR.string,\n '--w-rjv-curlybraces-color':\n 'var(--malachite-codeblock-foreground)',\n '--w-rjv-colon-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-brackets-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-quotes-color': CODE_TOKEN_COLOR.string,\n '--w-rjv-quotes-string-color': CODE_TOKEN_COLOR.string,\n '--w-rjv-type-string-color': CODE_TOKEN_COLOR.string,\n '--w-rjv-type-int-color': CODE_TOKEN_COLOR.number,\n '--w-rjv-type-float-color': CODE_TOKEN_COLOR.number,\n '--w-rjv-type-bigint-color': CODE_TOKEN_COLOR.number,\n '--w-rjv-type-boolean-color': CODE_TOKEN_COLOR.keyword,\n '--w-rjv-type-date-color': CODE_TOKEN_COLOR.string,\n '--w-rjv-type-url-color': CODE_TOKEN_COLOR.keyword,\n '--w-rjv-type-null-color': CODE_TOKEN_COLOR.keyword,\n '--w-rjv-type-nan-color': CODE_TOKEN_COLOR.keyword,\n '--w-rjv-type-undefined-color': CODE_TOKEN_COLOR.keyword,\n } as React.CSSProperties\n }\n displayDataTypes={false}\n enableClipboard={enableCopy}\n collapsed={collapsed}\n shouldExpandNodeInitially={\n limit === undefined ? undefined : collapseNodesLargerThan(limit)\n }\n displayObjectSize={false}\n >\n {/* The library draws these three only as their type label, which\n `displayDataTypes` turns off, so without a value of their own a\n `null` reads as a key with nothing after it. */}\n <JsonView.Null render={renderLiteral('null', 'null')} />\n <JsonView.Undefined render={renderLiteral('undefined', 'undefined')} />\n <JsonView.Nan render={renderLiteral('NaN', 'nan')} />\n {/* Mounted either way: the library keeps a slot's last render, so it is\n switched off by passing none rather than by unmounting. */}\n <JsonView.Arrow\n render={limit === undefined ? undefined : toggleArrowOver(limit)}\n />\n <JsonView.Ellipsis\n render={limit === undefined ? undefined : foldedSizeOver(limit)}\n />\n </JsonView>\n </div>\n </div>\n );\n }\n\n // Reserve clearance so a wide first line never sits under the floating copy button.\n const copyClearance = enableCopy && (!!code || !!diffRows);\n\n const renderPlainLines = (\n text: string,\n decorate?: (index: number) => CodeLineDecoration | undefined,\n ) => {\n const lines = text.split('\\n');\n\n return (\n <div\n {...viewportProps}\n className={`${viewportProps.className} p-4 text-left`}\n style={{ paddingRight: copyClearance ? 44 : undefined }}\n >\n <div style={rowsWrapperStyle(wrapLines)}>\n {lines.map((line, index) => {\n const decoration = decorate?.(index);\n\n return (\n <CodeLine\n key={index}\n line={line}\n lineNumber={\n decoration?.lineNumber ??\n (showLineNumbers ? index + 1 : undefined)\n }\n wrap={wrapLines}\n decoration={decoration}\n >\n {line}\n </CodeLine>\n );\n })}\n </div>\n </div>\n );\n };\n\n const renderPlainCode = () => (code ? renderPlainLines(code) : null);\n\n const renderDiff = (rows: DiffDisplayRow[]) => {\n if (rows.length === 0) {\n return (\n <div\n className=\"p-4 text-left\"\n style={{ color: 'var(--malachite-codeblock-comment)' }}\n >\n No changes\n </div>\n );\n }\n\n const decorate = (index: number) => {\n const row = rows[index];\n\n return row ? diffDecoration(row, showLineNumbers, diff?.origin) : undefined;\n };\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainLines(diffText, decorate)}>\n {/*\n * The whole merged text goes to the highlighter in one piece, so a hunk\n * is tokenised in the company of its neighbours rather than on its own.\n * Prism still cannot see the lines the hunks left out, so a construct\n * spanning an omitted run can highlight oddly — the reason `context`\n * defaults to a few lines rather than none.\n */}\n <CodeBlockHighlighter\n code={diffText}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n decorate={decorate}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainLines(diffText, decorate);\n };\n\n // For code strings, create a simple syntax-highlighted view\n const renderCodeContent = () => {\n if (!code) {\n return null;\n }\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainCode()}>\n <CodeBlockHighlighter\n code={code}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainCode();\n };\n\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {diffRows ? renderDiff(diffRows) : renderCodeContent()}\n </div>\n );\n};\n\nexport default CodeBlock;\n"],"names":["renderLiteral","text","type","props","part","jsx","entryCount","value","isOverLimit","limit","keys","sizeOf","count","pathOf","key","collapseNodesLargerThan","isCollapsed","toggleArrowOver","collapsed","_a","FOCUS_RING","foldedSizeOver","keyName","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapseLargerThan","diff","ariaLabel","ariaLabelledBy","copyId","devWarning","diffRows","diffHunks","diffText","textToCopy","copyButton","CopyOverlayButton","viewportProps","FOCUS_RING_INSET","jsxs","JsonView","CODE_TOKEN_COLOR","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;AAcA,MAAMA,IACF,CAACC,GAAcC,MACf,CAACC,GAA8C,EAAE,MAAMC,EAAA,MACnDA,MAAS,UACL,gBAAAC,EAAC,QAAA,EAAM,GAAGF,GAAO,OAAO,EAAE,GAAGA,EAAM,OAAO,OAAO,oBAAoBD,CAAI,UAAA,GACpE,UAAAD,EAAA,CACL,IACA,MAGNK,IAAa,CAACC,MAChBA,MAAU,QAAQ,OAAOA,KAAU,WAAW,OAAO,KAAKA,CAAK,EAAE,SAAS,GAGxEC,IAAc,CAACC,GAAeF,GAAgBG,MAChDA,EAAK,SAAS,KAAKJ,EAAWC,CAAK,IAAIE,GAErCE,IAAS,CAACJ,MAA2B;AACvC,QAAMK,IAAQN,EAAWC,CAAK;AAC9B,SAAO,GAAGK,CAAK,IAAIA,MAAU,IAAI,SAAS,OAAO;AACrD,GAGMC,IAAS,CAACH,MACZA,EAAK,IAAI,CAACI,MAAQ,OAAOA,CAAG,KAAK,IAAI,EAAE,KAAK,GAAG,GAG7CC,IACF,CAACN,MACD,CACIO,GACA,EAAE,OAAAT,GAAO,MAAAG,EAAA,MAETM,KAAeR,EAAYC,GAAOF,GAAOG,CAAI,GAI/CO,IACF,CAACR,MACD,CACIN,GACA,EAAE,OAAAI,GAAO,MAAAG,QACR;;AACD,MAAI,CAACF,EAAYC,GAAOF,GAAOG,KAAQ,CAAA,CAAE;AACrC,WAAO;AAEX,QAAMQ,IAAY,SAAOC,IAAAhB,EAAM,UAAN,gBAAAgB,EAAa,cAAa,EAAE,EAAE,SAAS,KAAK;AACrE,SACI,gBAAAd;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,iBAAe,CAACa;AAAA,MAChB,cAAY,GAAGL,EAAOH,KAAQ,CAAA,CAAE,CAAC,KAAKC,EAAOJ,CAAK,CAAC;AAAA,MACnD,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AAA,IACtE;AAEA,WAAIF,IAEI,gBAAAvC,EAACmB,EAAM,UAAN,EAAe,UAAUuC,EAAiBV,GAAUW,CAAQ,GAQzD,UAAA,gBAAA3D;AAAA,MAACkB;AAAA,MAAA;AAAA,QACG,MAAM8B;AAAA,QACN,UAAAT;AAAA,QACA,iBAAAX;AAAA,QACA,WAAAU;AAAA,QACA,eAAAmB;AAAA,QACA,UAAAE;AAAA,QACA,eAAAP;AAAA,MAAA;AAAA,IAAA,GAER,IAIDM,EAAiBV,GAAUW,CAAQ;AAAA,EAC9C,GAGMU,IAAoB,MACjBrC,IAIDO,sBAEKpB,EAAM,UAAN,EAAe,UAAU+C,KACtB,UAAA,gBAAAlE;AAAA,IAACkB;AAAA,IAAA;AAAA,MACG,MAAAc;AAAA,MACA,UAAAO;AAAA,MACA,iBAAAX;AAAA,MACA,WAAAU;AAAA,MACA,eAAAmB;AAAA,MACA,eAAAL;AAAA,IAAA;AAAA,EAAA,GAER,IAIDc,EAAA,IAlBI;AAqBf,SACI,gBAAAZ;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,2DAA2DpB,CAAS;AAAA,MAC/E,OAAO;AAAA,QACH,iBAAiB;AAAA,QACjB,aAAa;AAAA,QACb,QAAAE;AAAA,QACA,GAAGD;AAAA,MAAA;AAAA,MAGN,UAAA;AAAA,QAAAe;AAAA,QACAJ,IAAWqB,EAAWrB,CAAQ,IAAIuB,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
@@ -1,108 +1,108 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import w from "react-syntax-highlighter/dist/esm/create-element.js";
3
- import m from "react-syntax-highlighter/dist/esm/prism-light.js";
4
- import f from "refractor/yaml";
5
- import L from "./prismCedar.js";
6
- import { CodeLine as R } from "./codeBlockLine.js";
7
- import { CODE_FONT as t, rowsWrapperStyle as E } from "./codeBlockStyles.js";
8
- let s = !1;
9
- const T = () => {
10
- s || (s = !0, m.registerLanguage("yaml", f), m.registerLanguage("cedar", L));
11
- }, x = {
12
- 'code[class*="language-"]': t,
13
- 'pre[class*="language-"]': t,
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import v from "react-syntax-highlighter/dist/esm/create-element.js";
3
+ import s from "react-syntax-highlighter/dist/esm/prism-light.js";
4
+ import E from "refractor/yaml";
5
+ import { CodeLine as L } from "./codeBlockLine.js";
6
+ import { CODE_FONT as i, CODE_TOKEN_COLOR as r, rowsWrapperStyle as R } from "./codeBlockStyles.js";
7
+ import C from "./prismCedar.js";
8
+ let g = !1;
9
+ const O = () => {
10
+ g || (g = !0, s.registerLanguage("yaml", E), s.registerLanguage("cedar", C));
11
+ }, T = {
12
+ 'code[class*="language-"]': i,
13
+ 'pre[class*="language-"]': i,
14
14
  comment: { color: "var(--malachite-codeblock-comment)" },
15
15
  prolog: { color: "var(--malachite-codeblock-comment)" },
16
16
  cdata: { color: "var(--malachite-codeblock-comment)" },
17
17
  punctuation: { color: "var(--malachite-codeblock-foreground)" },
18
- key: { color: "var(--malachite-codeblock-keyword)" },
19
- atrule: { color: "var(--malachite-codeblock-keyword)" },
20
- "attr-name": { color: "var(--malachite-codeblock-keyword)" },
21
- directive: { color: "var(--malachite-codeblock-keyword)" },
22
- keyword: { color: "var(--malachite-codeblock-keyword)" },
23
- property: { color: "var(--malachite-codeblock-keyword)" },
24
- boolean: { color: "var(--malachite-codeblock-keyword)" },
25
- important: { color: "var(--malachite-codeblock-keyword)" },
26
- null: { color: "var(--malachite-codeblock-keyword)" },
27
- tag: { color: "var(--malachite-codeblock-keyword)" },
28
- anchor: { color: "var(--malachite-codeblock-keyword)" },
29
- alias: { color: "var(--malachite-codeblock-keyword)" },
18
+ key: { color: r.keyword },
19
+ atrule: { color: r.keyword },
20
+ "attr-name": { color: r.keyword },
21
+ directive: { color: r.keyword },
22
+ keyword: { color: r.keyword },
23
+ property: { color: r.keyword },
24
+ boolean: { color: r.keyword },
25
+ important: { color: r.keyword },
26
+ null: { color: r.keyword },
27
+ tag: { color: r.keyword },
28
+ anchor: { color: r.keyword },
29
+ alias: { color: r.keyword },
30
30
  // Cedar's entity paths (`StackOne::Action`) are types, which is what this token is for.
31
31
  "class-name": { color: "var(--malachite-codeblock-type)" },
32
32
  // The scope variables. Given the one remaining distinct hue so they read as language
33
33
  // rather than as another blue keyword.
34
- builtin: { color: "var(--malachite-codeblock-number)" },
34
+ builtin: { color: r.number },
35
35
  operator: { color: "var(--malachite-codeblock-line-number)" },
36
- string: { color: "var(--malachite-codeblock-string)" },
37
- scalar: { color: "var(--malachite-codeblock-string)" },
38
- char: { color: "var(--malachite-codeblock-string)" },
39
- url: { color: "var(--malachite-codeblock-string)" },
40
- number: { color: "var(--malachite-codeblock-number)" },
41
- datetime: { color: "var(--malachite-codeblock-number)" }
42
- }, d = (o) => {
36
+ string: { color: r.string },
37
+ scalar: { color: r.string },
38
+ char: { color: r.string },
39
+ url: { color: r.string },
40
+ number: { color: r.number },
41
+ datetime: { color: r.number }
42
+ }, u = (o) => {
43
43
  if (o.type === "text")
44
44
  return typeof o.value == "string" && o.value.endsWith(`
45
45
  `) ? { ...o, value: o.value.slice(0, -1) } : o;
46
46
  const e = o.children;
47
47
  if (!(e != null && e.length))
48
48
  return o;
49
- const a = e[e.length - 1], r = d(a);
50
- return r === a ? o : { ...o, children: [...e.slice(0, -1), r] };
51
- }, I = ({
49
+ const c = e[e.length - 1], l = u(c);
50
+ return l === c ? o : { ...o, children: [...e.slice(0, -1), l] };
51
+ }, D = ({
52
52
  code: o,
53
53
  language: e,
54
- showLineNumbers: a = !0,
55
- wrapLines: r = !1,
56
- copyClearance: k = !1,
57
- decorate: i,
58
- viewportProps: h
54
+ showLineNumbers: c = !0,
55
+ wrapLines: l = !1,
56
+ copyClearance: d = !1,
57
+ decorate: n,
58
+ viewportProps: p
59
59
  }) => {
60
- T();
61
- const b = o.split(`
60
+ O();
61
+ const y = o.split(`
62
62
  `);
63
- return /* @__PURE__ */ n(
64
- m,
63
+ return /* @__PURE__ */ m(
64
+ s,
65
65
  {
66
66
  language: e,
67
- style: x,
67
+ style: T,
68
68
  wrapLines: !0,
69
- renderer: ({ rows: g, stylesheet: u, useInlineStyles: v }) => g.map((p, c) => {
70
- const l = i == null ? void 0 : i(c), y = (l == null ? void 0 : l.lineNumber) ?? (a ? c + 1 : void 0);
71
- return /* @__PURE__ */ n(
72
- R,
69
+ renderer: ({ rows: k, stylesheet: h, useInlineStyles: w }) => k.map((b, t) => {
70
+ const a = n == null ? void 0 : n(t), f = (a == null ? void 0 : a.lineNumber) ?? (c ? t + 1 : void 0);
71
+ return /* @__PURE__ */ m(
72
+ L,
73
73
  {
74
- line: b[c] ?? "",
75
- lineNumber: y,
76
- wrap: r,
77
- decoration: l,
78
- children: w({
79
- node: d(p),
80
- stylesheet: u,
81
- useInlineStyles: v,
82
- key: `code-line-${c}`
74
+ line: y[t] ?? "",
75
+ lineNumber: f,
76
+ wrap: l,
77
+ decoration: a,
78
+ children: v({
79
+ node: u(b),
80
+ stylesheet: h,
81
+ useInlineStyles: w,
82
+ key: `code-line-${t}`
83
83
  })
84
84
  },
85
- c
85
+ t
86
86
  );
87
87
  }),
88
- ...h,
88
+ ...p,
89
89
  customStyle: {
90
- ...t,
90
+ ...i,
91
91
  boxSizing: "border-box",
92
92
  height: "100%",
93
93
  margin: 0,
94
94
  padding: "16px",
95
- paddingRight: k ? "44px" : "16px",
95
+ paddingRight: d ? "44px" : "16px",
96
96
  overflow: "auto"
97
97
  },
98
98
  codeTagProps: {
99
- style: { ...t, display: "block", ...E(r) }
99
+ style: { ...i, display: "block", ...R(l) }
100
100
  },
101
101
  children: o
102
102
  }
103
103
  );
104
104
  };
105
105
  export {
106
- I as default
106
+ D as default
107
107
  };
108
108
  //# sourceMappingURL=CodeBlockHighlighter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockHighlighter.js","sources":["../../src/components/CodeBlockHighlighter.tsx"],"sourcesContent":["import type React from 'react';\nimport createElement from 'react-syntax-highlighter/dist/esm/create-element.js';\nimport PrismLight from 'react-syntax-highlighter/dist/esm/prism-light.js';\nimport yaml from 'refractor/yaml';\nimport cedar from './prismCedar';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { CODE_FONT, rowsWrapperStyle } from './codeBlockStyles';\n\n// Registered on first render rather than at import. A bare top-level call is an import-time\n// side effect, which `sideEffects: false` in package.json tells a bundler it may drop; the\n// same reason the font faces go in through ensureInterFontFace and not a top-level call.\nlet languagesRegistered = false;\n\nconst ensureLanguagesRegistered = (): void => {\n if (languagesRegistered) {\n return;\n }\n languagesRegistered = true;\n PrismLight.registerLanguage('yaml', yaml);\n PrismLight.registerLanguage('cedar', cedar);\n};\n\n// Prism token colors bound to the codeblock theme tokens so highlighting follows the theme.\nconst PRISM_MALACHITE_THEME: { [key: string]: React.CSSProperties } = {\n 'code[class*=\"language-\"]': CODE_FONT,\n 'pre[class*=\"language-\"]': CODE_FONT,\n comment: { color: 'var(--malachite-codeblock-comment)' },\n prolog: { color: 'var(--malachite-codeblock-comment)' },\n cdata: { color: 'var(--malachite-codeblock-comment)' },\n punctuation: { color: 'var(--malachite-codeblock-foreground)' },\n key: { color: 'var(--malachite-codeblock-keyword)' },\n atrule: { color: 'var(--malachite-codeblock-keyword)' },\n 'attr-name': { color: 'var(--malachite-codeblock-keyword)' },\n directive: { color: 'var(--malachite-codeblock-keyword)' },\n keyword: { color: 'var(--malachite-codeblock-keyword)' },\n property: { color: 'var(--malachite-codeblock-keyword)' },\n boolean: { color: 'var(--malachite-codeblock-keyword)' },\n important: { color: 'var(--malachite-codeblock-keyword)' },\n null: { color: 'var(--malachite-codeblock-keyword)' },\n tag: { color: 'var(--malachite-codeblock-keyword)' },\n anchor: { color: 'var(--malachite-codeblock-keyword)' },\n alias: { color: 'var(--malachite-codeblock-keyword)' },\n // Cedar's entity paths (`StackOne::Action`) are types, which is what this token is for.\n 'class-name': { color: 'var(--malachite-codeblock-type)' },\n // The scope variables. Given the one remaining distinct hue so they read as language\n // rather than as another blue keyword.\n builtin: { color: 'var(--malachite-codeblock-number)' },\n operator: { color: 'var(--malachite-codeblock-line-number)' },\n string: { color: 'var(--malachite-codeblock-string)' },\n scalar: { color: 'var(--malachite-codeblock-string)' },\n char: { color: 'var(--malachite-codeblock-string)' },\n url: { color: 'var(--malachite-codeblock-string)' },\n number: { color: 'var(--malachite-codeblock-number)' },\n datetime: { color: 'var(--malachite-codeblock-number)' },\n};\n\ntype SyntaxNode = {\n type: 'text' | 'element';\n value?: string | number;\n children?: SyntaxNode[];\n};\n\n/** Local, not the ambient `rendererProps`: that global leaks out of DefinitelyTyped by accident. */\ntype RowRendererProps = {\n rows: SyntaxNode[];\n stylesheet: { [key: string]: React.CSSProperties };\n useInlineStyles: boolean;\n};\n\n/** Prism keeps the source newline on each row's last token; `CodeLine` supplies the break now. */\nconst withoutTrailingNewline = <T extends SyntaxNode>(node: T): T => {\n if (node.type === 'text') {\n return typeof node.value === 'string' && node.value.endsWith('\\n')\n ? { ...node, value: node.value.slice(0, -1) }\n : node;\n }\n const children = node.children;\n if (!children?.length) {\n return node;\n }\n const last = children[children.length - 1];\n const trimmed = withoutTrailingNewline(last);\n return trimmed === last ? node : { ...node, children: [...children.slice(0, -1), trimmed] };\n};\n\nexport interface CodeBlockHighlighterProps {\n code: string;\n language: 'yaml' | 'cedar';\n showLineNumbers?: boolean;\n wrapLines?: boolean;\n /** Right padding reserving space for the floating copy button. */\n copyClearance?: boolean;\n /**\n * Per-line markup, by index into `code`. How a diff tints its rows and numbers them from\n * the text each line actually came from.\n */\n decorate?: (index: number) => CodeLineDecoration | undefined;\n /** Spread onto the `pre`, which is the block's scroll viewport. */\n viewportProps?: Pick<\n React.HTMLAttributes<HTMLElement>,\n 'role' | 'aria-label' | 'aria-labelledby' | 'tabIndex' | 'className'\n >;\n}\n\nconst CodeBlockHighlighter: React.FC<CodeBlockHighlighterProps> = ({\n code,\n language,\n showLineNumbers = true,\n wrapLines = false,\n copyClearance = false,\n decorate,\n viewportProps,\n}) => {\n ensureLanguagesRegistered();\n\n const lines = code.split('\\n');\n\n // We lay rows out ourselves rather than passing `showLineNumbers`/`wrapLongLines` down:\n // that mode makes every line a flex container, so the Prism token spans become flex items\n // and the line shreds into out-of-order fragments.\n const renderRows = ({ rows, stylesheet, useInlineStyles }: RowRendererProps) =>\n rows.map((row, index) => {\n const decoration = decorate?.(index);\n // A decoration's own number wins: in a diff the row's position in the merged\n // text is not its line number in either of the texts it came from.\n const lineNumber = decoration?.lineNumber ?? (showLineNumbers ? index + 1 : undefined);\n\n return (\n <CodeLine\n key={index}\n line={lines[index] ?? ''}\n lineNumber={lineNumber}\n wrap={wrapLines}\n decoration={decoration}\n >\n {createElement({\n node: withoutTrailingNewline(row),\n stylesheet,\n useInlineStyles,\n key: `code-line-${index}`,\n })}\n </CodeLine>\n );\n });\n\n return (\n <PrismLight\n language={language}\n style={PRISM_MALACHITE_THEME}\n wrapLines\n renderer={renderRows}\n {...viewportProps}\n customStyle={{\n ...CODE_FONT,\n boxSizing: 'border-box',\n height: '100%',\n margin: 0,\n padding: '16px',\n paddingRight: copyClearance ? '44px' : '16px',\n overflow: 'auto',\n }}\n // The `code` element is the rows' wrapper here, so it takes the sizing the plain\n // path puts on a div of its own.\n codeTagProps={{\n style: { ...CODE_FONT, display: 'block', ...rowsWrapperStyle(wrapLines) },\n }}\n >\n {code}\n </PrismLight>\n );\n};\n\nexport default CodeBlockHighlighter;\n"],"names":["languagesRegistered","ensureLanguagesRegistered","PrismLight","yaml","cedar","PRISM_MALACHITE_THEME","CODE_FONT","withoutTrailingNewline","node","children","last","trimmed","CodeBlockHighlighter","code","language","showLineNumbers","wrapLines","copyClearance","decorate","viewportProps","lines","jsx","rows","stylesheet","useInlineStyles","row","index","decoration","lineNumber","CodeLine","createElement","rowsWrapperStyle"],"mappings":";;;;;;;AAWA,IAAIA,IAAsB;AAE1B,MAAMC,IAA4B,MAAY;AAC1C,EAAID,MAGJA,IAAsB,IACtBE,EAAW,iBAAiB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QI,GAAGP;AAAA,MACJ,aAAa;AAAA,QACT,GAAGb;AAAA,QACH,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,cAAcW,IAAgB,SAAS;AAAA,QACvC,UAAU;AAAA,MAAA;AAAA,MAId,cAAc;AAAA,QACV,OAAO,EAAE,GAAGX,GAAW,SAAS,SAAS,GAAGyB,EAAiBf,CAAS,EAAA;AAAA,MAAE;AAAA,MAG3E,UAAAH;AAAA,IAAA;AAAA,EAAA;AAGb;"}
1
+ {"version":3,"file":"CodeBlockHighlighter.js","sources":["../../src/components/CodeBlockHighlighter.tsx"],"sourcesContent":["import type React from 'react';\nimport createElement from 'react-syntax-highlighter/dist/esm/create-element.js';\nimport PrismLight from 'react-syntax-highlighter/dist/esm/prism-light.js';\nimport yaml from 'refractor/yaml';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { CODE_FONT, CODE_TOKEN_COLOR, rowsWrapperStyle } from './codeBlockStyles';\nimport cedar from './prismCedar';\n\n// Registered on first render rather than at import. A bare top-level call is an import-time\n// side effect, which `sideEffects: false` in package.json tells a bundler it may drop; the\n// same reason the font faces go in through ensureInterFontFace and not a top-level call.\nlet languagesRegistered = false;\n\nconst ensureLanguagesRegistered = (): void => {\n if (languagesRegistered) {\n return;\n }\n languagesRegistered = true;\n PrismLight.registerLanguage('yaml', yaml);\n PrismLight.registerLanguage('cedar', cedar);\n};\n\n// Prism token colors bound to the codeblock theme tokens so highlighting follows the theme.\nconst PRISM_MALACHITE_THEME: { [key: string]: React.CSSProperties } = {\n 'code[class*=\"language-\"]': CODE_FONT,\n 'pre[class*=\"language-\"]': CODE_FONT,\n comment: { color: 'var(--malachite-codeblock-comment)' },\n prolog: { color: 'var(--malachite-codeblock-comment)' },\n cdata: { color: 'var(--malachite-codeblock-comment)' },\n punctuation: { color: 'var(--malachite-codeblock-foreground)' },\n key: { color: CODE_TOKEN_COLOR.keyword },\n atrule: { color: CODE_TOKEN_COLOR.keyword },\n 'attr-name': { color: CODE_TOKEN_COLOR.keyword },\n directive: { color: CODE_TOKEN_COLOR.keyword },\n keyword: { color: CODE_TOKEN_COLOR.keyword },\n property: { color: CODE_TOKEN_COLOR.keyword },\n boolean: { color: CODE_TOKEN_COLOR.keyword },\n important: { color: CODE_TOKEN_COLOR.keyword },\n null: { color: CODE_TOKEN_COLOR.keyword },\n tag: { color: CODE_TOKEN_COLOR.keyword },\n anchor: { color: CODE_TOKEN_COLOR.keyword },\n alias: { color: CODE_TOKEN_COLOR.keyword },\n // Cedar's entity paths (`StackOne::Action`) are types, which is what this token is for.\n 'class-name': { color: 'var(--malachite-codeblock-type)' },\n // The scope variables. Given the one remaining distinct hue so they read as language\n // rather than as another blue keyword.\n builtin: { color: CODE_TOKEN_COLOR.number },\n operator: { color: 'var(--malachite-codeblock-line-number)' },\n string: { color: CODE_TOKEN_COLOR.string },\n scalar: { color: CODE_TOKEN_COLOR.string },\n char: { color: CODE_TOKEN_COLOR.string },\n url: { color: CODE_TOKEN_COLOR.string },\n number: { color: CODE_TOKEN_COLOR.number },\n datetime: { color: CODE_TOKEN_COLOR.number },\n};\n\ntype SyntaxNode = {\n type: 'text' | 'element';\n value?: string | number;\n children?: SyntaxNode[];\n};\n\n/** Local, not the ambient `rendererProps`: that global leaks out of DefinitelyTyped by accident. */\ntype RowRendererProps = {\n rows: SyntaxNode[];\n stylesheet: { [key: string]: React.CSSProperties };\n useInlineStyles: boolean;\n};\n\n/** Prism keeps the source newline on each row's last token; `CodeLine` supplies the break now. */\nconst withoutTrailingNewline = <T extends SyntaxNode>(node: T): T => {\n if (node.type === 'text') {\n return typeof node.value === 'string' && node.value.endsWith('\\n')\n ? { ...node, value: node.value.slice(0, -1) }\n : node;\n }\n const children = node.children;\n if (!children?.length) {\n return node;\n }\n const last = children[children.length - 1];\n const trimmed = withoutTrailingNewline(last);\n return trimmed === last ? node : { ...node, children: [...children.slice(0, -1), trimmed] };\n};\n\nexport interface CodeBlockHighlighterProps {\n code: string;\n language: 'yaml' | 'cedar';\n showLineNumbers?: boolean;\n wrapLines?: boolean;\n /** Right padding reserving space for the floating copy button. */\n copyClearance?: boolean;\n /**\n * Per-line markup, by index into `code`. How a diff tints its rows and numbers them from\n * the text each line actually came from.\n */\n decorate?: (index: number) => CodeLineDecoration | undefined;\n /** Spread onto the `pre`, which is the block's scroll viewport. */\n viewportProps?: Pick<\n React.HTMLAttributes<HTMLElement>,\n 'role' | 'aria-label' | 'aria-labelledby' | 'tabIndex' | 'className'\n >;\n}\n\nconst CodeBlockHighlighter: React.FC<CodeBlockHighlighterProps> = ({\n code,\n language,\n showLineNumbers = true,\n wrapLines = false,\n copyClearance = false,\n decorate,\n viewportProps,\n}) => {\n ensureLanguagesRegistered();\n\n const lines = code.split('\\n');\n\n // We lay rows out ourselves rather than passing `showLineNumbers`/`wrapLongLines` down:\n // that mode makes every line a flex container, so the Prism token spans become flex items\n // and the line shreds into out-of-order fragments.\n const renderRows = ({ rows, stylesheet, useInlineStyles }: RowRendererProps) =>\n rows.map((row, index) => {\n const decoration = decorate?.(index);\n // A decoration's own number wins: in a diff the row's position in the merged\n // text is not its line number in either of the texts it came from.\n const lineNumber = decoration?.lineNumber ?? (showLineNumbers ? index + 1 : undefined);\n\n return (\n <CodeLine\n key={index}\n line={lines[index] ?? ''}\n lineNumber={lineNumber}\n wrap={wrapLines}\n decoration={decoration}\n >\n {createElement({\n node: withoutTrailingNewline(row),\n stylesheet,\n useInlineStyles,\n key: `code-line-${index}`,\n })}\n </CodeLine>\n );\n });\n\n return (\n <PrismLight\n language={language}\n style={PRISM_MALACHITE_THEME}\n wrapLines\n renderer={renderRows}\n {...viewportProps}\n customStyle={{\n ...CODE_FONT,\n boxSizing: 'border-box',\n height: '100%',\n margin: 0,\n padding: '16px',\n paddingRight: copyClearance ? '44px' : '16px',\n overflow: 'auto',\n }}\n // The `code` element is the rows' wrapper here, so it takes the sizing the plain\n // path puts on a div of its own.\n codeTagProps={{\n style: { ...CODE_FONT, display: 'block', ...rowsWrapperStyle(wrapLines) },\n }}\n >\n {code}\n </PrismLight>\n );\n};\n\nexport default CodeBlockHighlighter;\n"],"names":["languagesRegistered","ensureLanguagesRegistered","PrismLight","yaml","cedar","PRISM_MALACHITE_THEME","CODE_FONT","CODE_TOKEN_COLOR","withoutTrailingNewline","node","children","last","trimmed","CodeBlockHighlighter","code","language","showLineNumbers","wrapLines","copyClearance","decorate","viewportProps","lines","jsx","rows","stylesheet","useInlineStyles","row","index","decoration","lineNumber","CodeLine","createElement","rowsWrapperStyle"],"mappings":";;;;;;;AAWA,IAAIA,IAAsB;AAE1B,MAAMC,IAA4B,MAAY;AAC1C,EAAID,MAGJA,IAAsB,IACtBE,EAAW,iBAAiB,QAAQC,CAAI,GACxCD,EAAW,iBAAiB,SAASE,CAAK;AAC9C,GAGMC,IAAgE;AAAA,EAClE,4BAA4BC;AAAA,EAC5B,2BAA2BA;AAAA,EAC3B,SAAS,EAAE,OAAO,qCAAA;AAAA,EAClB,QAAQ,EAAE,OAAO,qCAAA;AAAA,EACjB,OAAO,EAAE,OAAO,qCAAA;AAAA,EAChB,aAAa,EAAE,OAAO,wCAAA;AAAA,EACtB,KAAK,EAAE,OAAOC,EAAiB,QAAA;AAAA,EAC/B,QAAQ,EAAE,OAAOA,EAAiB,QAAA;AAAA,EAClC,aAAa,EAAE,OAAOA,EAAiB,QAAA;AAAA,EACvC,WAAW,EAAE,OAAOA,EAAiB,QAAA;AAAA,EACrC,SAAS,EAAE,OAAOA,EAAiB,QAAA;AAAA,EACnC,UAAU,EAAE,OAAOA,EAAiB,QAAA;AAAA,EACpC,SAAS,EAAE,OAAOA,EAAiB,QAAA;AAAA,EACnC,WAAW,EAAE,OAAOA,EAAiB,QAAA;AAAA,EACrC,MAAM,EAAE,OAAOA,EAAiB,QAAA;AAAA,EAChC,KAAK,EAAE,OAAOA,EAAiB,QAAA;AAAA,EAC/B,QAAQ,EAAE,OAAOA,EAAiB,QAAA;AAAA,EA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UAAAa;AAAA,MACA,OAAOV;AAAA,MACP,WAAS;AAAA,MACT,UA9BW,CAAC,EAAE,MAAAkB,GAAM,YAAAC,GAAY,iBAAAC,QACpCF,EAAK,IAAI,CAACG,GAAKC,MAAU;AACrB,cAAMC,IAAaT,KAAA,gBAAAA,EAAWQ,IAGxBE,KAAaD,KAAA,gBAAAA,EAAY,gBAAeZ,IAAkBW,IAAQ,IAAI;AAE5E,eACI,gBAAAL;AAAA,UAACQ;AAAA,UAAA;AAAA,YAEG,MAAMT,EAAMM,CAAK,KAAK;AAAA,YACtB,YAAAE;AAAA,YACA,MAAMZ;AAAA,YACN,YAAAW;AAAA,YAEC,UAAAG,EAAc;AAAA,cACX,MAAMvB,EAAuBkB,CAAG;AAAA,cAChC,YAAAF;AAAA,cACA,iBAAAC;AAAA,cACA,KAAK,aAAaE,CAAK;AAAA,YAAA,CAC1B;AAAA,UAAA;AAAA,UAXIA;AAAA,QAAA;AAAA,MAcjB,CAAC;AAAA,MAQI,GAAGP;AAAA,MACJ,aAAa;AAAA,QACT,GAAGd;AAAA,QACH,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,cAAcY,IAAgB,SAAS;AAAA,QACvC,UAAU;AAAA,MAAA;AAAA,MAId,cAAc;AAAA,QACV,OAAO,EAAE,GAAGZ,GAAW,SAAS,SAAS,GAAG0B,EAAiBf,CAAS,EAAA;AAAA,MAAE;AAAA,MAG3E,UAAAH;AAAA,IAAA;AAAA,EAAA;AAGb;"}
@@ -1,68 +1,79 @@
1
- import { jsxs as o, jsx as r } from "react/jsx-runtime";
2
- import { useState as M, useId as N, useMemo as E } from "react";
3
- import j from "./CopyOverlayButton.js";
4
- import B from "./CustomIcons/CaretDownIcon.js";
5
- import i from "./Typography/Text.js";
6
- import { rowsWrapperStyle as L } from "./codeBlockStyles.js";
7
- import { FOCUS_RING_INSET as I, FOCUS_RING as U } from "./focusRing.js";
8
- import { isRenderableNode as W } from "./renderableNode.js";
9
- import { canCopyToClipboard as G } from "./useClipboardCopy.js";
10
- const w = 5, C = 2e3, H = 360, P = (e) => e ? 11 : 6, S = "var(--malachite-card-border,rgb(232,232,232))", $ = "var(--malachite-card-subtle-divider,rgb(241,241,241))", V = (e) => e === "" ? [] : e.replace(/\r?\n$/, "").split(/\r\n|\r|\n/), k = (e, l) => !Number.isNaN(e) && e >= 1 ? Math.floor(e) : l, X = (e) => e ? "flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]" : "flex border-0 border-s-[3px] border-solid border-transparent", Y = (e, l, c) => {
1
+ import { jsxs as l, jsx as r, Fragment as A } from "react/jsx-runtime";
2
+ import { useState as M, useId as v, useMemo as E, memo as B } from "react";
3
+ import J from "./CopyOverlayButton.js";
4
+ import U from "./CustomIcons/CaretDownIcon.js";
5
+ import c from "./Typography/Text.js";
6
+ import { rowsWrapperStyle as W } from "./codeBlockStyles.js";
7
+ import { jsonTokensOf as G, JSON_TOKEN_COLORS as H } from "./codePreviewJson.js";
8
+ import { FOCUS_RING_INSET as S, FOCUS_RING as P } from "./focusRing.js";
9
+ import { isRenderableNode as K } from "./renderableNode.js";
10
+ import { canCopyToClipboard as V } from "./useClipboardCopy.js";
11
+ const C = 5, I = 2e3, X = 360, Y = (e) => e ? 11 : 6, O = "var(--malachite-card-border,rgb(232,232,232))", w = "var(--malachite-card-subtle-divider,rgb(241,241,241))", q = (e) => e === "" ? [] : e.replace(/\r?\n$/, "").split(/\r\n|\r|\n/), _ = (e, t) => !Number.isNaN(e) && e >= 1 ? Math.floor(e) : t, Q = (e) => e ? "flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]" : "flex border-0 border-s-[3px] border-solid border-transparent", Z = (e, t, o) => {
11
12
  if (e)
12
13
  return "Show Less";
13
- const n = c > 0 ? ` · ${c} flagged` : "";
14
- return `Show All ${l} Lines${n}`;
15
- }, oe = ({
14
+ const s = o > 0 ? ` · ${o} flagged` : "";
15
+ return `Show All ${t} Lines${s}`;
16
+ }, ee = Object.fromEntries(
17
+ Object.entries(H).map(([e, t]) => [e, { color: t }])
18
+ ), re = B(function({ line: t }) {
19
+ return /* @__PURE__ */ r(A, { children: G(t).map(
20
+ (o, s) => o.kind === "plain" ? o.text : (
21
+ // A token's position is its identity: its text can repeat.
22
+ /* @__PURE__ */ r("span", { "data-token": o.kind, style: ee[o.kind], children: o.text }, s)
23
+ )
24
+ ) });
25
+ }), me = ({
16
26
  title: e,
17
- meta: l,
18
- titleHidden: c = !1,
19
- code: n,
20
- previewLines: R = w,
27
+ meta: t,
28
+ titleHidden: o = !1,
29
+ code: s,
30
+ language: $,
31
+ previewLines: k = C,
21
32
  highlightLines: y = [],
22
- showLineNumbers: s = !0,
23
- copyable: _ = !1,
24
- maxRenderedLines: z = C,
25
- className: D = ""
33
+ showLineNumbers: i = !0,
34
+ copyable: R = !1,
35
+ maxRenderedLines: T = I,
36
+ className: z = ""
26
37
  }) => {
27
- const [p, O] = M(!1), x = _ && G(), m = N(), u = N(), a = E(() => V(n), [n]), b = E(
38
+ const [p, D] = M(!1), x = R && V(), m = v(), u = v(), n = E(() => q(s), [s]), b = E(
28
39
  () => new Set(
29
40
  y.filter(
30
- (t) => Number.isInteger(t) && t >= 1 && t <= a.length
41
+ (a) => Number.isInteger(a) && a >= 1 && a <= n.length
31
42
  )
32
43
  ),
33
- [y, a.length]
34
- ), g = k(R, w), v = a.length > g, h = p || !v, f = Math.min(
35
- h ? a.length : g,
36
- k(z, C)
37
- ), T = a.slice(0, f), A = [...b].filter((t) => t > g).length, F = `max(40px, calc(${String(a.length).length}ch + 14px))`;
38
- return /* @__PURE__ */ o(
44
+ [y, n.length]
45
+ ), g = _(k, C), N = n.length > g, h = p || !N, f = Math.min(
46
+ h ? n.length : g,
47
+ _(T, I)
48
+ ), j = n.slice(0, f), L = [...b].filter((a) => a > g).length, F = `max(40px, calc(${String(n.length).length}ch + 14px))`;
49
+ return /* @__PURE__ */ l(
39
50
  "div",
40
51
  {
41
- className: `overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${D}`,
42
- style: { borderColor: S },
52
+ className: `overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${z}`,
53
+ style: { borderColor: O },
43
54
  children: [
44
- c ? /* @__PURE__ */ r("span", { id: m, className: "sr-only", children: e }) : /* @__PURE__ */ o(
55
+ o ? /* @__PURE__ */ r("span", { id: m, className: "sr-only", children: e }) : /* @__PURE__ */ l(
45
56
  "div",
46
57
  {
47
58
  className: "flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]",
48
- style: { borderColor: $ },
59
+ style: { borderColor: w },
49
60
  children: [
50
- /* @__PURE__ */ r("span", { id: m, className: "flex min-w-0", children: /* @__PURE__ */ r(i, { size: "xsmall", color: "secondary", fontWeight: "semi-bold", children: e }) }),
51
- W(l) && /* @__PURE__ */ r(
52
- i,
61
+ /* @__PURE__ */ r("span", { id: m, className: "flex min-w-0", children: /* @__PURE__ */ r(c, { size: "xsmall", color: "secondary", fontWeight: "semi-bold", children: e }) }),
62
+ K(t) && /* @__PURE__ */ r(
63
+ c,
53
64
  {
54
65
  size: "xsmall",
55
66
  color: "secondary",
56
67
  font: "mono",
57
68
  wrap: !1,
58
69
  className: "truncate",
59
- children: l
70
+ children: t
60
71
  }
61
72
  )
62
73
  ]
63
74
  }
64
75
  ),
65
- a.length === 0 ? /* @__PURE__ */ r(i, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] py-[8px]", children: "Empty" }) : /* @__PURE__ */ o("div", { className: "relative", children: [
76
+ n.length === 0 ? /* @__PURE__ */ r(c, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] py-[8px]", children: "Empty" }) : /* @__PURE__ */ l("div", { className: "relative", children: [
66
77
  /* @__PURE__ */ r(
67
78
  "pre",
68
79
  {
@@ -70,22 +81,22 @@ const w = 5, C = 2e3, H = 360, P = (e) => e ? 11 : 6, S = "var(--malachite-card-
70
81
  role: "region",
71
82
  "aria-labelledby": m,
72
83
  tabIndex: 0,
73
- className: `m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${s ? "leading-[14px]" : "py-[10px] leading-[1.65]"} text-[var(--malachite-text-primary,rgb(10,10,10))] ${I}`,
84
+ className: `m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${i ? "leading-[14px]" : "py-[10px] leading-[1.65]"} text-[var(--malachite-text-primary,rgb(10,10,10))] ${S}`,
74
85
  style: {
75
- maxHeight: H,
86
+ maxHeight: X,
76
87
  paddingInlineEnd: x ? 40 : void 0,
77
- paddingBlock: s ? P(x) : void 0
88
+ paddingBlock: i ? Y(x) : void 0
78
89
  },
79
- children: /* @__PURE__ */ o("span", { className: "block", style: L(!1), children: [
80
- T.map((t, d) => (
90
+ children: /* @__PURE__ */ l("span", { className: "block", style: W(!1), children: [
91
+ j.map((a, d) => (
81
92
  // A line's position is its identity: its text can repeat.
82
- /* @__PURE__ */ o(
93
+ /* @__PURE__ */ l(
83
94
  "span",
84
95
  {
85
96
  "data-flagged": b.has(d + 1) || void 0,
86
- className: X(b.has(d + 1)),
97
+ className: Q(b.has(d + 1)),
87
98
  children: [
88
- s && /* @__PURE__ */ r(
99
+ i && /* @__PURE__ */ r(
89
100
  "span",
90
101
  {
91
102
  "aria-hidden": "true",
@@ -94,13 +105,13 @@ const w = 5, C = 2e3, H = 360, P = (e) => e ? 11 : 6, S = "var(--malachite-card-
94
105
  children: d + 1
95
106
  }
96
107
  ),
97
- /* @__PURE__ */ o(
108
+ /* @__PURE__ */ l(
98
109
  "span",
99
110
  {
100
- className: `min-w-0 whitespace-pre ${s ? "" : "px-[11px]"}`,
111
+ className: `min-w-0 whitespace-pre ${i ? "" : "px-[11px]"}`,
101
112
  children: [
102
113
  b.has(d + 1) && /* @__PURE__ */ r("span", { className: "sr-only select-none", children: "Flagged: " }),
103
- t || " "
114
+ a ? $ === "json" ? /* @__PURE__ */ r(re, { line: a }) : a : " "
104
115
  ]
105
116
  }
106
117
  )
@@ -109,36 +120,36 @@ const w = 5, C = 2e3, H = 360, P = (e) => e ? 11 : 6, S = "var(--malachite-card-
109
120
  d
110
121
  )
111
122
  )),
112
- !h && !s && /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "block select-none px-[14px]", children: "…" })
123
+ !h && !i && /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "block select-none px-[14px]", children: "…" })
113
124
  ] })
114
125
  }
115
126
  ),
116
127
  x && /* @__PURE__ */ r(
117
- j,
128
+ J,
118
129
  {
119
- text: n,
130
+ text: s,
120
131
  "aria-label": `Copy ${e}`,
121
132
  iconSize: 12,
122
- className: `absolute end-[6px] top-[6px] z-[1] flex cursor-pointer items-center justify-center rounded-md border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] p-[5px] text-[var(--malachite-text-secondary,rgb(115,115,115))] hover:text-[var(--malachite-text-primary,rgb(10,10,10))] ${U}`,
123
- style: { borderColor: S }
133
+ className: `absolute end-[6px] top-[6px] z-[1] flex cursor-pointer items-center justify-center rounded-md border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] p-[5px] text-[var(--malachite-text-secondary,rgb(115,115,115))] hover:text-[var(--malachite-text-primary,rgb(10,10,10))] ${P}`,
134
+ style: { borderColor: O }
124
135
  }
125
136
  )
126
137
  ] }),
127
- h && f < a.length && /* @__PURE__ */ r(i, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] pb-[8px]", children: `Showing the first ${f.toLocaleString()} of ${a.length.toLocaleString()} lines.` }),
128
- v && /* @__PURE__ */ o(
138
+ h && f < n.length && /* @__PURE__ */ r(c, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] pb-[8px]", children: `Showing the first ${f.toLocaleString()} of ${n.length.toLocaleString()} lines.` }),
139
+ N && /* @__PURE__ */ l(
129
140
  "button",
130
141
  {
131
142
  type: "button",
132
143
  "aria-expanded": p,
133
144
  "aria-controls": u,
134
145
  "aria-describedby": m,
135
- onClick: () => O((t) => !t),
136
- className: `m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${I}`,
137
- style: { borderColor: $ },
146
+ onClick: () => D((a) => !a),
147
+ className: `m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${S}`,
148
+ style: { borderColor: w },
138
149
  children: [
139
- /* @__PURE__ */ r(i, { size: "xsmall", fontWeight: "semi-bold", color: "inherit", children: Y(p, a.length, A) }),
150
+ /* @__PURE__ */ r(c, { size: "xsmall", fontWeight: "semi-bold", color: "inherit", children: Z(p, n.length, L) }),
140
151
  /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "flex", children: /* @__PURE__ */ r(
141
- B,
152
+ U,
142
153
  {
143
154
  size: 12,
144
155
  className: "transition-transform",
@@ -153,7 +164,7 @@ const w = 5, C = 2e3, H = 360, P = (e) => e ? 11 : 6, S = "var(--malachite-card-
153
164
  );
154
165
  };
155
166
  export {
156
- oe as CodePreview,
157
- oe as default
167
+ me as CodePreview,
168
+ me as default
158
169
  };
159
170
  //# sourceMappingURL=CodePreview.js.map