@stackone/malachite 2.92.0 → 2.93.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPONENTS.md +2 -2
- package/dist/components/Chat/ChatModelPicker.js +121 -110
- package/dist/components/Chat/ChatModelPicker.js.map +1 -1
- package/dist/components/Chat/ChatReasoning.js +40 -0
- package/dist/components/Chat/ChatReasoning.js.map +1 -0
- package/dist/components/Chat/ChatToolCall.js +57 -43
- package/dist/components/Chat/ChatToolCall.js.map +1 -1
- package/dist/components/Chat/index.js +12 -10
- package/dist/components/Chat/index.js.map +1 -1
- package/dist/components/Chat/stickToBottom.js +23 -17
- package/dist/components/Chat/stickToBottom.js.map +1 -1
- package/dist/components/CodeBlock.js +49 -48
- package/dist/components/CodeBlock.js.map +1 -1
- package/dist/components/CodeBlockHighlighter.js +22 -22
- package/dist/components/CodeBlockHighlighter.js.map +1 -1
- package/dist/components/TimeBarChart/TimeBarChartBars.js +24 -22
- package/dist/components/TimeBarChart/TimeBarChartBars.js.map +1 -1
- package/dist/components/TimeBarChart/tones.js +4 -3
- package/dist/components/TimeBarChart/tones.js.map +1 -1
- package/dist/components/Typography/MarkdownBlock.js +136 -103
- package/dist/components/Typography/MarkdownBlock.js.map +1 -1
- package/dist/components/codeBlockStyles.js +6 -5
- package/dist/components/codeBlockStyles.js.map +1 -1
- package/dist/index.d.ts +19 -4
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
|
@@ -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 CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\nimport { useClipboardCopy } from './useClipboardCopy';\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\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 * 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. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region 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 diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\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 const { outcome: copyOutcome, copy } = useClipboardCopy(textToCopy);\n const copied = copyOutcome === 'copied';\n\n const handleCopy = () => {\n if (textToCopy !== undefined) {\n void copy(textToCopy);\n }\n };\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 <>\n <button\n type=\"button\"\n aria-label=\"Copy\"\n onClick={handleCopy}\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 {copied ? <CheckmarkIcon size={14} /> : <CopyIcon size={14} />}\n </button>\n {/* Not role=\"status\": one per block would collide with a page's own status queries. */}\n <span aria-live=\"polite\" className=\"sr-only\">\n {copied ? 'Copied to clipboard' : ''}\n </span>\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 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 </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 {/* As wide as the widest line, floored at the view, so rows filling it end level. */}\n <div style={{ width: 'max-content', minWidth: '100%' }}>\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","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","count","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapsed","diff","ariaLabel","ariaLabelledBy","diffRows","diffHunks","diffText","textToCopy","copyOutcome","copy","useClipboardCopy","copied","copyButton","jsxs","Fragment","FOCUS_RING","CheckmarkIcon","CopyIcon","viewportProps","FOCUS_RING_INSET","JsonView","copyClearance","renderPlainLines","decorate","lines","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,MAENK,IAAuBC,EAAM,KAAK,MAAM,OAAO,2BAAwB,CAAC,GAmDxEC,IAA4D;AAAA,EAC9D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAwD;AAAA,EAC1D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAGMC,IAAsE;AAAA,EACxE,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAsD;AAAA,EACxD,OAAO;AAAA;AAAA,EAEP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAA4D;AAAA,EAC9D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAe,CAACC,MAClB,KAAUA,CAAK,cAAcA,MAAU,IAAI,SAAS,OAAO,IAEzDC,IAAiB,CACnBC,GACAC,GACAC,MACqB;AACr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,IAAA,GAER,IAIDI,EAAiBhB,GAAUiB,CAAQ;AAAA,EAC9C,GAGMS,IAAoB,MACjBxC,IAIDO,sBAEKrB,EAAM,UAAN,EAAe,UAAUmD,KACtB,UAAA,gBAAArD;AAAA,IAACC;AAAA,IAAA;AAAA,MACG,MAAAe;AAAA,MACA,UAAAO;AAAA,MACA,iBAAAX;AAAA,MACA,WAAAU;AAAA,MACA,eAAAuB;AAAA,MACA,eAAAH;AAAA,IAAA;AAAA,EAAA,GAER,IAIDW,EAAA,IAlBI;AAqBf,SACI,gBAAAhB;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,2DAA2DnB,CAAS;AAAA,MAC/E,OAAO;AAAA,QACH,iBAAiB;AAAA,QACjB,aAAa;AAAA,QACb,QAAAE;AAAA,QACA,GAAGD;AAAA,MAAA;AAAA,MAGN,UAAA;AAAA,QAAAiB;AAAA,QACAR,IAAW0B,EAAW1B,CAAQ,IAAI4B,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 CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\nimport { useClipboardCopy } from './useClipboardCopy';\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\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 * 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. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region 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 diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\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 const { outcome: copyOutcome, copy } = useClipboardCopy(textToCopy);\n const copied = copyOutcome === 'copied';\n\n const handleCopy = () => {\n if (textToCopy !== undefined) {\n void copy(textToCopy);\n }\n };\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 <>\n <button\n type=\"button\"\n aria-label=\"Copy\"\n onClick={handleCopy}\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 {copied ? <CheckmarkIcon size={14} /> : <CopyIcon size={14} />}\n </button>\n {/* Not role=\"status\": one per block would collide with a page's own status queries. */}\n <span aria-live=\"polite\" className=\"sr-only\">\n {copied ? 'Copied to clipboard' : ''}\n </span>\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 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 </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","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","count","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapsed","diff","ariaLabel","ariaLabelledBy","diffRows","diffHunks","diffText","textToCopy","copyOutcome","copy","useClipboardCopy","copied","copyButton","jsxs","Fragment","FOCUS_RING","CheckmarkIcon","CopyIcon","viewportProps","FOCUS_RING_INSET","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;;AAeA,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,MAENK,IAAuBC,EAAM,KAAK,MAAM,OAAO,2BAAwB,CAAC,GAmDxEC,IAA4D;AAAA,EAC9D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAwD;AAAA,EAC1D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAGMC,IAAsE;AAAA,EACxE,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAsD;AAAA,EACxD,OAAO;AAAA;AAAA,EAEP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAA4D;AAAA,EAC9D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAe,CAACC,MAClB,KAAUA,CAAK,cAAcA,MAAU,IAAI,SAAS,OAAO,IAEzDC,IAAiB,CACnBC,GACAC,GACAC,MACqB;AACrB,QAAMC,IAAYD,MAAW;AAE7B,SAAO;AAAA,IACH,YAAYC,IAAYT,EAA2BM,EAAI,IAAI,IAAIR,EAAiBQ,EAAI,IAAI;AAAA,IACxF,QAAQG,IAAYR,EAAuBK,EAAI,IAAI,IAAIP,EAAaO,EAAI,IAAI;AAAA,IAC5E,aAAaG,IAAYP,EAA6BI,EAAI,IAAI,IAAI;AAAA;AAAA,IAElE,eAAe;AAAA;AAAA,IAEf,WACI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,EAAA,GAER,IAIDY,EAAA,IAlBI;AAqBf,SACI,gBAAAjB;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,2DAA2DnB,CAAS;AAAA,MAC/E,OAAO;AAAA,QACH,iBAAiB;AAAA,QACjB,aAAa;AAAA,QACb,QAAAE;AAAA,QACA,GAAGD;AAAA,MAAA;AAAA,MAGN,UAAA;AAAA,QAAAiB;AAAA,QACAR,IAAW2B,EAAW3B,CAAQ,IAAI6B,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
|
|
@@ -4,11 +4,11 @@ import m from "react-syntax-highlighter/dist/esm/prism-light.js";
|
|
|
4
4
|
import f from "refractor/yaml";
|
|
5
5
|
import L from "./prismCedar.js";
|
|
6
6
|
import { CodeLine as R } from "./codeBlockLine.js";
|
|
7
|
-
import { CODE_FONT as t } from "./codeBlockStyles.js";
|
|
7
|
+
import { CODE_FONT as t, rowsWrapperStyle as E } from "./codeBlockStyles.js";
|
|
8
8
|
let s = !1;
|
|
9
|
-
const
|
|
9
|
+
const T = () => {
|
|
10
10
|
s || (s = !0, m.registerLanguage("yaml", f), m.registerLanguage("cedar", L));
|
|
11
|
-
},
|
|
11
|
+
}, x = {
|
|
12
12
|
'code[class*="language-"]': t,
|
|
13
13
|
'pre[class*="language-"]': t,
|
|
14
14
|
comment: { color: "var(--malachite-codeblock-comment)" },
|
|
@@ -46,63 +46,63 @@ const x = () => {
|
|
|
46
46
|
const e = o.children;
|
|
47
47
|
if (!(e != null && e.length))
|
|
48
48
|
return o;
|
|
49
|
-
const
|
|
50
|
-
return
|
|
51
|
-
},
|
|
49
|
+
const a = e[e.length - 1], r = d(a);
|
|
50
|
+
return r === a ? o : { ...o, children: [...e.slice(0, -1), r] };
|
|
51
|
+
}, I = ({
|
|
52
52
|
code: o,
|
|
53
53
|
language: e,
|
|
54
|
-
showLineNumbers:
|
|
55
|
-
wrapLines:
|
|
56
|
-
copyClearance:
|
|
54
|
+
showLineNumbers: a = !0,
|
|
55
|
+
wrapLines: r = !1,
|
|
56
|
+
copyClearance: k = !1,
|
|
57
57
|
decorate: i,
|
|
58
|
-
viewportProps:
|
|
58
|
+
viewportProps: h
|
|
59
59
|
}) => {
|
|
60
|
-
|
|
60
|
+
T();
|
|
61
61
|
const b = o.split(`
|
|
62
62
|
`);
|
|
63
63
|
return /* @__PURE__ */ n(
|
|
64
64
|
m,
|
|
65
65
|
{
|
|
66
66
|
language: e,
|
|
67
|
-
style:
|
|
67
|
+
style: x,
|
|
68
68
|
wrapLines: !0,
|
|
69
|
-
renderer: ({ rows: g, stylesheet: u, useInlineStyles: v }) => g.map((p,
|
|
70
|
-
const l = i == null ? void 0 : i(
|
|
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
71
|
return /* @__PURE__ */ n(
|
|
72
72
|
R,
|
|
73
73
|
{
|
|
74
|
-
line: b[
|
|
74
|
+
line: b[c] ?? "",
|
|
75
75
|
lineNumber: y,
|
|
76
|
-
wrap:
|
|
76
|
+
wrap: r,
|
|
77
77
|
decoration: l,
|
|
78
78
|
children: w({
|
|
79
79
|
node: d(p),
|
|
80
80
|
stylesheet: u,
|
|
81
81
|
useInlineStyles: v,
|
|
82
|
-
key: `code-line-${
|
|
82
|
+
key: `code-line-${c}`
|
|
83
83
|
})
|
|
84
84
|
},
|
|
85
|
-
|
|
85
|
+
c
|
|
86
86
|
);
|
|
87
87
|
}),
|
|
88
|
-
...
|
|
88
|
+
...h,
|
|
89
89
|
customStyle: {
|
|
90
90
|
...t,
|
|
91
91
|
boxSizing: "border-box",
|
|
92
92
|
height: "100%",
|
|
93
93
|
margin: 0,
|
|
94
94
|
padding: "16px",
|
|
95
|
-
paddingRight:
|
|
95
|
+
paddingRight: k ? "44px" : "16px",
|
|
96
96
|
overflow: "auto"
|
|
97
97
|
},
|
|
98
98
|
codeTagProps: {
|
|
99
|
-
style: { ...t, display: "block",
|
|
99
|
+
style: { ...t, display: "block", ...E(r) }
|
|
100
100
|
},
|
|
101
101
|
children: o
|
|
102
102
|
}
|
|
103
103
|
);
|
|
104
104
|
};
|
|
105
105
|
export {
|
|
106
|
-
|
|
106
|
+
I 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 } 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', width: 'max-content', minWidth: '100%' },\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"],"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,OAAO,qCAAA;AAAA,EACd,QAAQ,EAAE,OAAO,qCAAA;AAAA,EACjB,aAAa,EAAE,OAAO,qCAAA;AAAA,EACtB,WAAW,EAAE,OAAO,qCAAA;AAAA,EACpB,SAAS,EAAE,OAAO,qCAAA;AAAA,EAClB,UAAU,EAAE,OAAO,qCAAA;AAAA,EACnB,SAAS,EAAE,OAAO,qCAAA;AAAA,EAClB,WAAW,EAAE,OAAO,qCAAA;AAAA,EACpB,MAAM,EAAE,OAAO,qCAAA;AAAA,EACf,KAAK,EAAE,OAAO,qCAAA;AAAA,EACd,QAAQ,EAAE,OAAO,qCAAA;AAAA,EACjB,OAAO,EAAE,OAAO,qCAAA;AAAA;AAAA,EAEhB,cAAc,EAAE,OAAO,kCAAA;AAAA;AAAA;AAAA,EAGvB,SAAS,EAAE,OAAO,oCAAA;AAAA,EAClB,UAAU,EAAE,OAAO,yCAAA;AAAA,EACn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Z,IAAkBW,IAAQ,IAAI;AAE5E,eACA,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,MAcb,CAAC;AAAA,MAQI,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,OAAO,eAAe,UAAU,OAAA;AAAA,MAAO;AAAA,MAGnF,UAAAO;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 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,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,OAAO,qCAAA;AAAA,EACd,QAAQ,EAAE,OAAO,qCAAA;AAAA,EACjB,aAAa,EAAE,OAAO,qCAAA;AAAA,EACtB,WAAW,EAAE,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utStack as
|
|
3
|
-
import { TONE_STACK as p, TONE_FILL as
|
|
4
|
-
const
|
|
5
|
-
const r = Math.min(
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { layoutStack as R } from "./stackLayout.js";
|
|
3
|
+
import { TONE_STACK as p, TONE_FILL as h, BAR_FILL_OPACITY as B } from "./tones.js";
|
|
4
|
+
const y = 24, C = 0.7, F = 4, S = (t, a, c, e) => {
|
|
5
|
+
const r = Math.min(F, c / 2, e);
|
|
6
6
|
return [
|
|
7
7
|
`M${t},${a + e}`,
|
|
8
8
|
`V${a + r}`,
|
|
@@ -12,40 +12,42 @@ const S = 24, b = 0.7, j = 4, C = (t, a, c, e) => {
|
|
|
12
12
|
`V${a + e}`,
|
|
13
13
|
"Z"
|
|
14
14
|
].join(" ");
|
|
15
|
-
},
|
|
15
|
+
}, N = ({
|
|
16
16
|
series: t,
|
|
17
17
|
slots: a,
|
|
18
18
|
values: c,
|
|
19
19
|
totals: e,
|
|
20
20
|
xOf: r,
|
|
21
|
-
plotTop:
|
|
22
|
-
plotBottom:
|
|
23
|
-
yMax:
|
|
21
|
+
plotTop: L,
|
|
22
|
+
plotBottom: T,
|
|
23
|
+
yMax: I
|
|
24
24
|
}) => {
|
|
25
|
-
const
|
|
25
|
+
const M = t.map((n, o) => o).sort((n, o) => p[t[n].tone] - p[t[o].tone]);
|
|
26
26
|
return a.map((n, o) => {
|
|
27
27
|
if (!e[o]) return null;
|
|
28
|
-
const
|
|
29
|
-
return /* @__PURE__ */
|
|
30
|
-
const
|
|
31
|
-
return
|
|
28
|
+
const u = r(n.start), d = r(n.end) - u, $ = Math.max(1, Math.min(y, d * C)), s = u + (d - $) / 2, _ = R(M, c[o], { plotTop: L, plotBottom: T, yMax: I });
|
|
29
|
+
return /* @__PURE__ */ l("g", { "data-bucket": n.start, children: _.map(({ position: m, top: f, height: A }, O) => {
|
|
30
|
+
const k = h[t[m].tone];
|
|
31
|
+
return O === _.length - 1 ? /* @__PURE__ */ l(
|
|
32
32
|
"path",
|
|
33
33
|
{
|
|
34
34
|
"data-series": t[m].key,
|
|
35
35
|
"data-malachite-shape": !0,
|
|
36
|
-
d:
|
|
37
|
-
fill:
|
|
36
|
+
d: S(s, f, $, A),
|
|
37
|
+
fill: k,
|
|
38
|
+
fillOpacity: B
|
|
38
39
|
},
|
|
39
40
|
t[m].key
|
|
40
|
-
) : /* @__PURE__ */
|
|
41
|
+
) : /* @__PURE__ */ l(
|
|
41
42
|
"rect",
|
|
42
43
|
{
|
|
43
44
|
"data-series": t[m].key,
|
|
44
|
-
x:
|
|
45
|
-
y:
|
|
45
|
+
x: s,
|
|
46
|
+
y: f,
|
|
46
47
|
width: $,
|
|
47
|
-
height:
|
|
48
|
-
fill:
|
|
48
|
+
height: A,
|
|
49
|
+
fill: k,
|
|
50
|
+
fillOpacity: B
|
|
49
51
|
},
|
|
50
52
|
t[m].key
|
|
51
53
|
);
|
|
@@ -53,6 +55,6 @@ const S = 24, b = 0.7, j = 4, C = (t, a, c, e) => {
|
|
|
53
55
|
});
|
|
54
56
|
};
|
|
55
57
|
export {
|
|
56
|
-
|
|
58
|
+
N as default
|
|
57
59
|
};
|
|
58
60
|
//# sourceMappingURL=TimeBarChartBars.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeBarChartBars.js","sources":["../../../src/components/TimeBarChart/TimeBarChartBars.tsx"],"sourcesContent":["import type React from 'react';\nimport type { TimeBarChartSeries } from './TimeBarChart';\nimport { layoutStack } from './stackLayout';\nimport type { TimeSlot } from './timeBuckets';\nimport { TONE_FILL, TONE_STACK } from './tones';\n\n/** Bars stay thin however wide their slot, and fill this much of a narrow one. */\nconst MAX_BAR_PX = 24;\nconst BAR_FILL = 0.7;\nconst BAR_RADIUS = 4;\n\nconst roundedTop = (x: number, y: number, width: number, height: number) => {\n const radius = Math.min(BAR_RADIUS, width / 2, height);\n return [\n `M${x},${y + height}`,\n `V${y + radius}`,\n `Q${x},${y} ${x + radius},${y}`,\n `H${x + width - radius}`,\n `Q${x + width},${y} ${x + width},${y + radius}`,\n `V${y + height}`,\n 'Z',\n ].join(' ');\n};\n\ninterface TimeBarChartBarsProps {\n series: TimeBarChartSeries[];\n slots: TimeSlot[];\n values: number[][];\n totals: number[];\n xOf: (instant: number) => number;\n plotTop: number;\n plotBottom: number;\n yMax: number;\n}\n\n/** One stack per non-empty bucket, its top segment rounded. */\nconst TimeBarChartBars: React.FC<TimeBarChartBarsProps> = ({\n series,\n slots,\n values,\n totals,\n xOf,\n plotTop,\n plotBottom,\n yMax,\n}) => {\n // Stable, so series sharing a tone keep the order they were given in.\n const stackOrder = series\n .map((_entry, position) => position)\n .sort((left, right) => TONE_STACK[series[left].tone] - TONE_STACK[series[right].tone]);\n return slots.map((slot, index) => {\n if (!totals[index]) return null;\n const left = xOf(slot.start);\n const slotWidth = xOf(slot.end) - left;\n const barWidth = Math.max(1, Math.min(MAX_BAR_PX, slotWidth * BAR_FILL));\n const x = left + (slotWidth - barWidth) / 2;\n const segments = layoutStack(stackOrder, values[index], { plotTop, plotBottom, yMax });\n return (\n <g key={slot.start} data-bucket={slot.start}>\n {segments.map(({ position, top, height }, place) => {\n const fill = TONE_FILL[series[position].tone];\n return place === segments.length - 1 ? (\n <path\n key={series[position].key}\n data-series={series[position].key}\n data-malachite-shape\n d={roundedTop(x, top, barWidth, height)}\n fill={fill}\n />\n ) : (\n <rect\n key={series[position].key}\n data-series={series[position].key}\n x={x}\n y={top}\n width={barWidth}\n height={height}\n fill={fill}\n />\n );\n })}\n </g>\n );\n });\n};\n\nexport default TimeBarChartBars;\n"],"names":["MAX_BAR_PX","BAR_FILL","BAR_RADIUS","roundedTop","x","y","width","height","radius","TimeBarChartBars","series","slots","values","totals","xOf","plotTop","plotBottom","yMax","stackOrder","_entry","position","left","right","TONE_STACK","slot","index","slotWidth","barWidth","segments","layoutStack","jsx","top","place","fill","TONE_FILL"],"mappings":";;;AAOA,MAAMA,IAAa,IACbC,IAAW,K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,KAAA,EAAmB,eAAaN,EAAK,OACjC,UAAAI,EAAS,IAAI,CAAC,EAAE,UAAAR,GAAU,KAAAW,GAAK,QAAAxB,EAAA,GAAUyB,MAAU;AAChD,YAAMC,IAAOC,EAAUxB,EAAOU,CAAQ,EAAE,IAAI;AAC5C,aAAOY,MAAUJ,EAAS,SAAS,IAC/B,gBAAAE;AAAA,QAAC;AAAA,QAAA;AAAA,UAEG,eAAapB,EAAOU,CAAQ,EAAE;AAAA,UAC9B,wBAAoB;AAAA,UACpB,GAAGjB,EAAWC,GAAG2B,GAAKJ,GAAUpB,CAAM;AAAA,UACtC,MAAA0B;AAAA,QAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"TimeBarChartBars.js","sources":["../../../src/components/TimeBarChart/TimeBarChartBars.tsx"],"sourcesContent":["import type React from 'react';\nimport type { TimeBarChartSeries } from './TimeBarChart';\nimport { layoutStack } from './stackLayout';\nimport type { TimeSlot } from './timeBuckets';\nimport { BAR_FILL_OPACITY, TONE_FILL, TONE_STACK } from './tones';\n\n/** Bars stay thin however wide their slot, and fill this much of a narrow one. */\nconst MAX_BAR_PX = 24;\nconst BAR_FILL = 0.7;\nconst BAR_RADIUS = 4;\n\nconst roundedTop = (x: number, y: number, width: number, height: number) => {\n const radius = Math.min(BAR_RADIUS, width / 2, height);\n return [\n `M${x},${y + height}`,\n `V${y + radius}`,\n `Q${x},${y} ${x + radius},${y}`,\n `H${x + width - radius}`,\n `Q${x + width},${y} ${x + width},${y + radius}`,\n `V${y + height}`,\n 'Z',\n ].join(' ');\n};\n\ninterface TimeBarChartBarsProps {\n series: TimeBarChartSeries[];\n slots: TimeSlot[];\n values: number[][];\n totals: number[];\n xOf: (instant: number) => number;\n plotTop: number;\n plotBottom: number;\n yMax: number;\n}\n\n/** One stack per non-empty bucket, its top segment rounded. */\nconst TimeBarChartBars: React.FC<TimeBarChartBarsProps> = ({\n series,\n slots,\n values,\n totals,\n xOf,\n plotTop,\n plotBottom,\n yMax,\n}) => {\n // Stable, so series sharing a tone keep the order they were given in.\n const stackOrder = series\n .map((_entry, position) => position)\n .sort((left, right) => TONE_STACK[series[left].tone] - TONE_STACK[series[right].tone]);\n return slots.map((slot, index) => {\n if (!totals[index]) return null;\n const left = xOf(slot.start);\n const slotWidth = xOf(slot.end) - left;\n const barWidth = Math.max(1, Math.min(MAX_BAR_PX, slotWidth * BAR_FILL));\n const x = left + (slotWidth - barWidth) / 2;\n const segments = layoutStack(stackOrder, values[index], { plotTop, plotBottom, yMax });\n return (\n <g key={slot.start} data-bucket={slot.start}>\n {segments.map(({ position, top, height }, place) => {\n const fill = TONE_FILL[series[position].tone];\n return place === segments.length - 1 ? (\n <path\n key={series[position].key}\n data-series={series[position].key}\n data-malachite-shape\n d={roundedTop(x, top, barWidth, height)}\n fill={fill}\n fillOpacity={BAR_FILL_OPACITY}\n />\n ) : (\n <rect\n key={series[position].key}\n data-series={series[position].key}\n x={x}\n y={top}\n width={barWidth}\n height={height}\n fill={fill}\n fillOpacity={BAR_FILL_OPACITY}\n />\n );\n })}\n </g>\n );\n });\n};\n\nexport default TimeBarChartBars;\n"],"names":["MAX_BAR_PX","BAR_FILL","BAR_RADIUS","roundedTop","x","y","width","height","radius","TimeBarChartBars","series","slots","values","totals","xOf","plotTop","plotBottom","yMax","stackOrder","_entry","position","left","right","TONE_STACK","slot","index","slotWidth","barWidth","segments","layoutStack","jsx","top","place","fill","TONE_FILL","BAR_FILL_OPACITY"],"mappings":";;;AAOA,MAAMA,IAAa,IACbC,IAAW,KACXC,IAAa,GAEbC,IAAa,CAACC,GAAWC,GAAWC,GAAeC,MAAmB;AACxE,QAAMC,IAAS,KAAK,IAAIN,GAAYI,IAAQ,GAAGC,CAAM;AACrD,SAAO;AAAA,IACH,IAAIH,CAAC,IAAIC,IAAIE,CAAM;AAAA,IACnB,IAAIF,IAAIG,CAAM;AAAA,IACd,IAAIJ,CAAC,IAAIC,CAAC,IAAID,IAAII,CAAM,IAAIH,CAAC;AAAA,IAC7B,IA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A,UAC9B,wBAAoB;AAAA,UACpB,GAAGjB,EAAWC,GAAG2B,GAAKJ,GAAUpB,CAAM;AAAA,UACtC,MAAA0B;AAAA,UACA,aAAaE;AAAA,QAAA;AAAA,QALRzB,EAAOU,CAAQ,EAAE;AAAA,MAAA,IAQ1B,gBAAAU;AAAA,QAAC;AAAA,QAAA;AAAA,UAEG,eAAapB,EAAOU,CAAQ,EAAE;AAAA,UAC9B,GAAAhB;AAAA,UACA,GAAG2B;AAAA,UACH,OAAOJ;AAAA,UACP,QAAApB;AAAA,UACA,MAAA0B;AAAA,UACA,aAAaE;AAAA,QAAA;AAAA,QAPRzB,EAAOU,CAAQ,EAAE;AAAA,MAAA;AAAA,IAUlC,CAAC,EAAA,GAxBGI,EAAK,KAyBb;AAAA,EAER,CAAC;AACL;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
const r = { neutral: 0, success: 1, error: 2 },
|
|
1
|
+
const r = { neutral: 0, success: 1, error: 2 }, c = {
|
|
2
2
|
success: "var(--malachite-success-background, rgb(0, 175, 102))",
|
|
3
3
|
error: "var(--malachite-error-background, rgb(197, 63, 63))",
|
|
4
4
|
neutral: "var(--malachite-text-dimmed, rgb(161, 161, 161))"
|
|
5
|
-
};
|
|
5
|
+
}, e = 0.4;
|
|
6
6
|
export {
|
|
7
|
-
e as
|
|
7
|
+
e as BAR_FILL_OPACITY,
|
|
8
|
+
c as TONE_FILL,
|
|
8
9
|
r as TONE_STACK
|
|
9
10
|
};
|
|
10
11
|
//# sourceMappingURL=tones.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tones.js","sources":["../../../src/components/TimeBarChart/tones.ts"],"sourcesContent":["import type { TimeBarChartTone } from './TimeBarChart';\n\n/** Stacking order by tone, so failures sit on top whatever order the series come in: position\n * then separates them where the success and error colours alone might not. */\nexport const TONE_STACK: Record<TimeBarChartTone, number> = { neutral: 0, success: 1, error: 2 };\n\nexport const TONE_FILL: Record<TimeBarChartTone, string> = {\n success: 'var(--malachite-success-background, rgb(0, 175, 102))',\n error: 'var(--malachite-error-background, rgb(197, 63, 63))',\n neutral: 'var(--malachite-text-dimmed, rgb(161, 161, 161))',\n};\n"],"names":["TONE_STACK","TONE_FILL"],"mappings":"AAIO,MAAMA,IAA+C,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,EAAA,GAEhFC,IAA8C;AAAA,EACvD,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACb;"}
|
|
1
|
+
{"version":3,"file":"tones.js","sources":["../../../src/components/TimeBarChart/tones.ts"],"sourcesContent":["import type { TimeBarChartTone } from './TimeBarChart';\n\n/** Stacking order by tone, so failures sit on top whatever order the series come in: position\n * then separates them where the success and error colours alone might not. */\nexport const TONE_STACK: Record<TimeBarChartTone, number> = { neutral: 0, success: 1, error: 2 };\n\nexport const TONE_FILL: Record<TimeBarChartTone, string> = {\n success: 'var(--malachite-success-background, rgb(0, 175, 102))',\n error: 'var(--malachite-error-background, rgb(197, 63, 63))',\n neutral: 'var(--malachite-text-dimmed, rgb(161, 161, 161))',\n};\n\n/**\n * How strongly a bar draws its tone. Full-strength status colour across a whole chart is loud\n * next to the tags and badges that use the same tokens, and a dense chart reads as a wall of red.\n * The swatch and tooltip keep the full colour, so the mark that names a series is the strongest.\n * An opacity rather than a mixed colour, so a renderer without `color-mix` still draws the tone.\n */\nexport const BAR_FILL_OPACITY = 0.4;\n"],"names":["TONE_STACK","TONE_FILL","BAR_FILL_OPACITY"],"mappings":"AAIO,MAAMA,IAA+C,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,EAAA,GAEhFC,IAA8C;AAAA,EACvD,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACb,GAQaC,IAAmB;"}
|