@stackone/malachite 2.97.0 → 2.99.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,115 +1,154 @@
1
- import { jsxs as p, jsx as o, Fragment as U } from "react/jsx-runtime";
2
- import h from "@uiw/react-json-view";
3
- import x from "react";
4
- import B from "./CustomIcons/CheckmarkIcon.js";
5
- import E from "./CustomIcons/CopyIcon.js";
6
- import { diffHunks as G } from "./codeBlockDiff.js";
7
- import { CodeLine as M } from "./codeBlockLine.js";
8
- import { rowsWrapperStyle as H } from "./codeBlockStyles.js";
9
- import { FOCUS_RING_INSET as P, FOCUS_RING as q } from "./focusRing.js";
10
- import { useClipboardCopy as J } from "./useClipboardCopy.js";
11
- const w = (e, a) => (c, { type: r }) => r === "value" ? /* @__PURE__ */ o("span", { ...c, style: { ...c.style, color: `var(--w-rjv-type-${a}-color)` }, children: e }) : null, T = x.lazy(() => import("./CodeBlockHighlighter.js")), V = {
1
+ import { jsxs as x, jsx as r, Fragment as P } from "react/jsx-runtime";
2
+ import v from "@uiw/react-json-view";
3
+ import A from "react";
4
+ import q from "./CustomIcons/CheckmarkIcon.js";
5
+ import J from "./CustomIcons/CopyIcon.js";
6
+ import { diffHunks as W } from "./codeBlockDiff.js";
7
+ import { CodeLine as V } from "./codeBlockLine.js";
8
+ import { rowsWrapperStyle as Q } from "./codeBlockStyles.js";
9
+ import { devWarning as X } from "./devWarning.js";
10
+ import { FOCUS_RING_INSET as Y, FOCUS_RING as z } from "./focusRing.js";
11
+ import { useClipboardCopy as Z } from "./useClipboardCopy.js";
12
+ const $ = (e, o) => (t, { type: c }) => c === "value" ? /* @__PURE__ */ r("span", { ...t, style: { ...t.style, color: `var(--w-rjv-type-${o}-color)` }, children: e }) : null, B = (e) => e !== null && typeof e == "object" ? Object.keys(e).length : 0, I = (e, o, t) => t.length > 0 && B(o) > e, E = (e) => {
13
+ const o = B(e);
14
+ return `${o} ${o === 1 ? "item" : "items"}`;
15
+ }, L = (e) => e.map((o) => String(o) || '""').join("."), ee = (e) => (o, { value: t, keys: c }) => o || I(e, t, c), oe = (e) => (o, { value: t, keys: c }) => {
16
+ var m;
17
+ if (!I(e, t, c ?? []))
18
+ return null;
19
+ const k = String(((m = o.style) == null ? void 0 : m.transform) ?? "").includes("-90");
20
+ return /* @__PURE__ */ r(
21
+ "button",
22
+ {
23
+ type: "button",
24
+ "aria-expanded": !k,
25
+ "aria-label": `${L(c ?? [])}, ${E(t)}`,
26
+ className: `${o.className ?? ""} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${z}`,
27
+ style: o.style,
28
+ children: o.children
29
+ }
30
+ );
31
+ }, re = (e) => (
32
+ // This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.
33
+ (o, { value: t, keyName: c }) => Reflect.get(o, "data-expanded") && I(e, t, c === void 0 ? [] : [c]) ? (
34
+ // Its toggle already names the size, so this would say it twice.
35
+ /* @__PURE__ */ r(
36
+ "span",
37
+ {
38
+ "aria-hidden": "true",
39
+ className: `${Reflect.get(o, "className") ?? ""} mx-[4px] cursor-pointer select-none text-[var(--malachite-codeblock-foreground)]`,
40
+ children: `… ${E(t)}`
41
+ }
42
+ )
43
+ ) : null
44
+ ), T = A.lazy(() => import("./CodeBlockHighlighter.js")), te = {
12
45
  added: "var(--malachite-codeblock-diff-added-background)",
13
46
  removed: "var(--malachite-codeblock-diff-removed-background)",
14
47
  context: void 0
15
- }, W = {
48
+ }, ce = {
16
49
  added: "+",
17
50
  removed: "-",
18
51
  context: void 0
19
- }, Q = {
52
+ }, le = {
20
53
  added: "var(--malachite-codeblock-diff-assistant-background)",
21
54
  removed: "var(--malachite-codeblock-diff-assistant-removed-background)",
22
55
  context: void 0
23
- }, X = {
56
+ }, ae = {
24
57
  added: "✦",
25
58
  // U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.
26
59
  removed: "−",
27
60
  context: "·"
28
- }, Y = {
61
+ }, ne = {
29
62
  added: "var(--malachite-codeblock-diff-assistant-foreground)",
30
63
  removed: "var(--malachite-codeblock-diff-removed-foreground)",
31
64
  context: "var(--malachite-codeblock-diff-context-foreground)"
32
- }, Z = (e) => `⋯ ${e} unchanged ${e === 1 ? "line" : "lines"}`, L = (e, a, c) => {
33
- const r = c === "assistant";
65
+ }, de = (e) => `⋯ ${e} unchanged ${e === 1 ? "line" : "lines"}`, ie = (e, o, t) => {
66
+ const c = t === "assistant";
34
67
  return {
35
- background: r ? Q[e.type] : V[e.type],
36
- marker: r ? X[e.type] : W[e.type],
37
- markerColor: r ? Y[e.type] : void 0,
68
+ background: c ? le[e.type] : te[e.type],
69
+ marker: c ? ae[e.type] : ce[e.type],
70
+ markerColor: c ? ne[e.type] : void 0,
38
71
  // Reserved on unchanged rows too, so the code column does not step in and out.
39
72
  reserveMarker: !0,
40
73
  // Context rows read as de-emphasised, not just unmarked, in the assistant palette.
41
- textColor: r && e.type === "context" ? "var(--malachite-codeblock-diff-context-text)" : void 0,
42
- strikethrough: r && e.type === "removed",
43
- separatorAbove: e.skippedAbove === void 0 ? void 0 : Z(e.skippedAbove),
74
+ textColor: c && e.type === "context" ? "var(--malachite-codeblock-diff-context-text)" : void 0,
75
+ strikethrough: c && e.type === "removed",
76
+ separatorAbove: e.skippedAbove === void 0 ? void 0 : de(e.skippedAbove),
44
77
  // A removed line has no number in the after-text, so it keeps the one it had before.
45
- lineNumber: a ? e.afterNumber ?? e.beforeNumber : void 0
78
+ lineNumber: o ? e.afterNumber ?? e.beforeNumber : void 0
46
79
  };
47
- }, be = ({
80
+ }, je = ({
48
81
  code: e,
49
- json: a,
50
- showLineNumbers: c = !0,
51
- className: r = "",
52
- style: N = {},
53
- height: S,
54
- enableCopy: f = !0,
55
- wrapLines: s = !1,
56
- language: b,
57
- collapsed: D = !1,
58
- diff: t,
59
- "aria-label": A,
60
- "aria-labelledby": F
82
+ json: o,
83
+ showLineNumbers: t = !0,
84
+ className: c = "",
85
+ style: k = {},
86
+ height: m,
87
+ enableCopy: C = !0,
88
+ wrapLines: h = !1,
89
+ language: p,
90
+ collapsed: K = !1,
91
+ collapseLargerThan: a,
92
+ diff: n,
93
+ "aria-label": O,
94
+ "aria-labelledby": R
61
95
  }) => {
62
- const l = t ? G(t.before, t.after, t.context) : null, m = (l == null ? void 0 : l.map((n) => n.text).join(`
63
- `)) ?? "", u = (() => {
96
+ const d = a !== void 0 && Number.isInteger(a) && a >= 0 ? a : void 0;
97
+ a !== void 0 && d === void 0 && X(
98
+ `CodeBlock.collapseLargerThan:${a}`,
99
+ `CodeBlock's collapseLargerThan takes a whole count of 0 or more; ${a} is ignored.`
100
+ );
101
+ const l = n ? W(n.before, n.after, n.context) : null, f = (l == null ? void 0 : l.map((s) => s.text).join(`
102
+ `)) ?? "", y = (() => {
64
103
  if (l)
65
- return m;
104
+ return f;
66
105
  if (e)
67
106
  return e;
68
- if (a !== void 0)
107
+ if (o !== void 0)
69
108
  try {
70
- return JSON.stringify(a, null, 2);
109
+ return JSON.stringify(o, null, 2);
71
110
  } catch {
72
111
  return;
73
112
  }
74
- })(), { outcome: O, copy: $ } = J(u), I = O === "copied", _ = f && u !== void 0 && /* @__PURE__ */ p(U, { children: [
75
- /* @__PURE__ */ o(
113
+ })(), { outcome: U, copy: G } = Z(y), F = U === "copied", _ = C && y !== void 0 && /* @__PURE__ */ x(P, { children: [
114
+ /* @__PURE__ */ r(
76
115
  "button",
77
116
  {
78
117
  type: "button",
79
118
  "aria-label": "Copy",
80
119
  onClick: () => {
81
- u !== void 0 && $(u);
120
+ y !== void 0 && G(y);
82
121
  },
83
- 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)] ${q}`,
122
+ 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)] ${z}`,
84
123
  style: { color: "var(--malachite-codeblock-line-number)" },
85
- children: I ? /* @__PURE__ */ o(B, { size: 14 }) : /* @__PURE__ */ o(E, { size: 14 })
124
+ children: F ? /* @__PURE__ */ r(q, { size: 14 }) : /* @__PURE__ */ r(J, { size: 14 })
86
125
  }
87
126
  ),
88
- /* @__PURE__ */ o("span", { "aria-live": "polite", className: "sr-only", children: I ? "Copied to clipboard" : "" })
89
- ] }), i = {
127
+ /* @__PURE__ */ r("span", { "aria-live": "polite", className: "sr-only", children: F ? "Copied to clipboard" : "" })
128
+ ] }), b = {
90
129
  role: "region",
91
- "aria-label": F ? A : A ?? "Code",
92
- "aria-labelledby": F,
130
+ "aria-label": R ? O : O ?? "Code",
131
+ "aria-labelledby": R,
93
132
  tabIndex: 0,
94
- className: `box-border h-full overflow-auto ${P}`
133
+ className: `box-border h-full overflow-auto ${Y}`
95
134
  };
96
- if (a && !l)
97
- return /* @__PURE__ */ p(
135
+ if (o && !l)
136
+ return /* @__PURE__ */ x(
98
137
  "div",
99
138
  {
100
- className: `relative border border-solid rounded-lg overflow-hidden ${r}`,
139
+ className: `relative border border-solid rounded-lg overflow-hidden ${c}`,
101
140
  style: {
102
141
  backgroundColor: "var(--malachite-codeblock-background)",
103
142
  borderColor: "var(--malachite-codeblock-border)",
104
- height: S,
105
- ...N
143
+ height: m,
144
+ ...k
106
145
  },
107
146
  children: [
108
147
  _,
109
- /* @__PURE__ */ o("div", { ...i, children: /* @__PURE__ */ p(
110
- h,
148
+ /* @__PURE__ */ r("div", { ...b, children: /* @__PURE__ */ x(
149
+ v,
111
150
  {
112
- value: a,
151
+ value: o,
113
152
  style: {
114
153
  backgroundColor: "var(--malachite-codeblock-background)",
115
154
  color: "var(--malachite-codeblock-foreground)",
@@ -145,47 +184,60 @@ const w = (e, a) => (c, { type: r }) => r === "value" ? /* @__PURE__ */ o("span"
145
184
  "--w-rjv-type-undefined-color": "var(--malachite-codeblock-keyword)"
146
185
  },
147
186
  displayDataTypes: !1,
148
- enableClipboard: f,
149
- collapsed: D,
187
+ enableClipboard: C,
188
+ collapsed: K,
189
+ shouldExpandNodeInitially: d === void 0 ? void 0 : ee(d),
150
190
  displayObjectSize: !1,
151
191
  children: [
152
- /* @__PURE__ */ o(h.Null, { render: w("null", "null") }),
153
- /* @__PURE__ */ o(h.Undefined, { render: w("undefined", "undefined") }),
154
- /* @__PURE__ */ o(h.Nan, { render: w("NaN", "nan") })
192
+ /* @__PURE__ */ r(v.Null, { render: $("null", "null") }),
193
+ /* @__PURE__ */ r(v.Undefined, { render: $("undefined", "undefined") }),
194
+ /* @__PURE__ */ r(v.Nan, { render: $("NaN", "nan") }),
195
+ /* @__PURE__ */ r(
196
+ v.Arrow,
197
+ {
198
+ render: d === void 0 ? void 0 : oe(d)
199
+ }
200
+ ),
201
+ /* @__PURE__ */ r(
202
+ v.Ellipsis,
203
+ {
204
+ render: d === void 0 ? void 0 : re(d)
205
+ }
206
+ )
155
207
  ]
156
208
  }
157
209
  ) })
158
210
  ]
159
211
  }
160
212
  );
161
- const y = f && (!!e || !!l), g = (n, d) => {
162
- const C = n.split(`
213
+ const j = C && (!!e || !!l), N = (s, i) => {
214
+ const w = s.split(`
163
215
  `);
164
- return /* @__PURE__ */ o(
216
+ return /* @__PURE__ */ r(
165
217
  "div",
166
218
  {
167
- ...i,
168
- className: `${i.className} p-4 text-left`,
169
- style: { paddingRight: y ? 44 : void 0 },
170
- children: /* @__PURE__ */ o("div", { style: H(s), children: C.map((v, j) => {
171
- const k = d == null ? void 0 : d(j);
172
- return /* @__PURE__ */ o(
173
- M,
219
+ ...b,
220
+ className: `${b.className} p-4 text-left`,
221
+ style: { paddingRight: j ? 44 : void 0 },
222
+ children: /* @__PURE__ */ r("div", { style: Q(h), children: w.map((u, S) => {
223
+ const g = i == null ? void 0 : i(S);
224
+ return /* @__PURE__ */ r(
225
+ V,
174
226
  {
175
- line: v,
176
- lineNumber: (k == null ? void 0 : k.lineNumber) ?? (c ? j + 1 : void 0),
177
- wrap: s,
178
- decoration: k,
179
- children: v
227
+ line: u,
228
+ lineNumber: (g == null ? void 0 : g.lineNumber) ?? (t ? S + 1 : void 0),
229
+ wrap: h,
230
+ decoration: g,
231
+ children: u
180
232
  },
181
- j
233
+ S
182
234
  );
183
235
  }) })
184
236
  }
185
237
  );
186
- }, R = () => e ? g(e) : null, z = (n) => {
187
- if (n.length === 0)
188
- return /* @__PURE__ */ o(
238
+ }, D = () => e ? N(e) : null, M = (s) => {
239
+ if (s.length === 0)
240
+ return /* @__PURE__ */ r(
189
241
  "div",
190
242
  {
191
243
  className: "p-4 text-left",
@@ -193,51 +245,51 @@ const w = (e, a) => (c, { type: r }) => r === "value" ? /* @__PURE__ */ o("span"
193
245
  children: "No changes"
194
246
  }
195
247
  );
196
- const d = (C) => {
197
- const v = n[C];
198
- return v ? L(v, c, t == null ? void 0 : t.origin) : void 0;
248
+ const i = (w) => {
249
+ const u = s[w];
250
+ return u ? ie(u, t, n == null ? void 0 : n.origin) : void 0;
199
251
  };
200
- return b ? /* @__PURE__ */ o(x.Suspense, { fallback: g(m, d), children: /* @__PURE__ */ o(
252
+ return p ? /* @__PURE__ */ r(A.Suspense, { fallback: N(f, i), children: /* @__PURE__ */ r(
201
253
  T,
202
254
  {
203
- code: m,
204
- language: b,
205
- showLineNumbers: c,
206
- wrapLines: s,
207
- copyClearance: y,
208
- decorate: d,
209
- viewportProps: i
255
+ code: f,
256
+ language: p,
257
+ showLineNumbers: t,
258
+ wrapLines: h,
259
+ copyClearance: j,
260
+ decorate: i,
261
+ viewportProps: b
210
262
  }
211
- ) }) : g(m, d);
212
- }, K = () => e ? b ? /* @__PURE__ */ o(x.Suspense, { fallback: R(), children: /* @__PURE__ */ o(
263
+ ) }) : N(f, i);
264
+ }, H = () => e ? p ? /* @__PURE__ */ r(A.Suspense, { fallback: D(), children: /* @__PURE__ */ r(
213
265
  T,
214
266
  {
215
267
  code: e,
216
- language: b,
217
- showLineNumbers: c,
218
- wrapLines: s,
219
- copyClearance: y,
220
- viewportProps: i
268
+ language: p,
269
+ showLineNumbers: t,
270
+ wrapLines: h,
271
+ copyClearance: j,
272
+ viewportProps: b
221
273
  }
222
- ) }) : R() : null;
223
- return /* @__PURE__ */ p(
274
+ ) }) : D() : null;
275
+ return /* @__PURE__ */ x(
224
276
  "div",
225
277
  {
226
- className: `relative border border-solid rounded-lg overflow-hidden ${r}`,
278
+ className: `relative border border-solid rounded-lg overflow-hidden ${c}`,
227
279
  style: {
228
280
  backgroundColor: "var(--malachite-codeblock-background)",
229
281
  borderColor: "var(--malachite-codeblock-border)",
230
- height: S,
231
- ...N
282
+ height: m,
283
+ ...k
232
284
  },
233
285
  children: [
234
286
  _,
235
- l ? z(l) : K()
287
+ l ? M(l) : H()
236
288
  ]
237
289
  }
238
290
  );
239
291
  };
240
292
  export {
241
- be as default
293
+ je as default
242
294
  };
243
295
  //# sourceMappingURL=CodeBlock.js.map
@@ -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 { 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,WACIG,KAAaH,EAAI,SAAS,YACpB,iDACA;AAAA,IACV,eAA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AAjB;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;"}
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 { devWarning } from './devWarning';\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\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. 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 collapseLargerThan,\n diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\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 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 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","devWarning","diffRows","diffHunks","diffText","textToCopy","copyOutcome","copy","useClipboardCopy","copied","copyButton","jsxs","Fragment","CheckmarkIcon","CopyIcon","viewportProps","FOCUS_RING_INSET","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;;;AAgBA,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,EA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,MACA,eAAAH;AAAA,IAAA;AAAA,EAAA,GAER,IAIDY,EAAA,IAlBI;AAqBf,SACI,gBAAAhB;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,QAAAkB;AAAA,QACAR,IAAW0B,EAAW1B,CAAQ,IAAI4B,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
@@ -0,0 +1,37 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import d from "./CustomIcons/CheckmarkIcon.js";
3
+ import { ICON_BADGE_FILL as i } from "./iconBadgeVariants.js";
4
+ const l = {
5
+ small: { box: 18, glyph: 9 },
6
+ medium: { box: 22, glyph: 10 }
7
+ }, s = {
8
+ accent: "bg-[var(--malachite-accent-background,rgb(0,175,102))] text-white",
9
+ neutral: "text-[var(--malachite-card-background,rgb(255,255,255))]"
10
+ }, g = ({
11
+ children: o,
12
+ size: a = "medium",
13
+ tone: r = "accent",
14
+ className: n = ""
15
+ }) => {
16
+ const { box: e, glyph: c } = l[a];
17
+ return /* @__PURE__ */ t(
18
+ "span",
19
+ {
20
+ "aria-hidden": "true",
21
+ className: `pointer-events-none absolute box-border flex items-center justify-center rounded-full border-2 border-solid border-[var(--malachite-card-background,rgb(255,255,255))] ${s[r]} ${n}`,
22
+ style: {
23
+ width: e,
24
+ height: e,
25
+ top: -e / 3,
26
+ insetInlineEnd: -e / 3,
27
+ backgroundColor: r === "neutral" ? i.default : void 0
28
+ },
29
+ children: o ?? /* @__PURE__ */ t(d, { size: c })
30
+ }
31
+ );
32
+ };
33
+ export {
34
+ g as CornerBadge,
35
+ g as default
36
+ };
37
+ //# sourceMappingURL=CornerBadge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CornerBadge.js","sources":["../../src/components/CornerBadge.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport { ICON_BADGE_FILL } from './iconBadgeVariants';\n\nexport type CornerBadgeSize = 'small' | 'medium';\n\nexport type CornerBadgeTone = 'accent' | 'neutral';\n\nexport interface CornerBadgeProps {\n /** The mark inside; a tick when omitted. An svg painting with `currentColor`. */\n children?: React.ReactNode;\n size?: CornerBadgeSize;\n /** `accent` marks a choice; `neutral` any other note, such as a recommended option. */\n tone?: CornerBadgeTone;\n className?: string;\n}\n\nconst SIZES: Record<CornerBadgeSize, { box: number; glyph: number }> = {\n small: { box: 18, glyph: 9 },\n medium: { box: 22, glyph: 10 },\n};\n\n// The accent tick is white on the fill in both themes, as Checkbox draws its tick; the neutral\n// mark is IconBadge's default, the card colour on its fill.\nconst TONE_CLASSES: Record<CornerBadgeTone, string> = {\n accent: 'bg-[var(--malachite-accent-background,rgb(0,175,102))] text-white',\n neutral: 'text-[var(--malachite-card-background,rgb(255,255,255))]',\n};\n\n/**\n * A round mark pinned over the top-right corner of its parent, such as the accent tick on a chosen\n * tile. The parent must be positioned, and the badge comes after what it overlaps so it paints\n * on top. Decorative and click-through: the parent's own state says what it marks.\n */\nconst CornerBadge: React.FC<CornerBadgeProps> = ({\n children,\n size = 'medium',\n tone = 'accent',\n className = '',\n}) => {\n const { box, glyph } = SIZES[size];\n return (\n <span\n aria-hidden=\"true\"\n className={`pointer-events-none absolute box-border flex items-center justify-center rounded-full border-2 border-solid border-[var(--malachite-card-background,rgb(255,255,255))] ${TONE_CLASSES[tone]} ${className}`}\n style={{\n width: box,\n height: box,\n top: -box / 3,\n insetInlineEnd: -box / 3,\n backgroundColor: tone === 'neutral' ? ICON_BADGE_FILL.default : undefined,\n }}\n >\n {children ?? <CheckmarkIcon size={glyph} />}\n </span>\n );\n};\n\nexport default CornerBadge;\nexport { CornerBadge };\n"],"names":["SIZES","TONE_CLASSES","CornerBadge","children","size","tone","className","box","glyph","jsx","ICON_BADGE_FILL","CheckmarkIcon"],"mappings":";;;AAiBA,MAAMA,IAAiE;AAAA,EACnE,OAAO,EAAE,KAAK,IAAI,OAAO,EAAA;AAAA,EACzB,QAAQ,EAAE,KAAK,IAAI,OAAO,GAAA;AAC9B,GAIMC,IAAgD;AAAA,EAClD,QAAQ;AAAA,EACR,SAAS;AACb,GAOMC,IAA0C,CAAC;AAAA,EAC7C,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,MAAAC,IAAO;AAAA,EACP,WAAAC,IAAY;AAChB,MAAM;AACF,QAAM,EAAE,KAAAC,GAAK,OAAAC,MAAUR,EAAMI,CAAI;AACjC,SACI,gBAAAK;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,eAAY;AAAA,MACZ,WAAW,0KAA0KR,EAAaI,CAAI,CAAC,IAAIC,CAAS;AAAA,MACpN,OAAO;AAAA,QACH,OAAOC;AAAA,QACP,QAAQA;AAAA,QACR,KAAK,CAACA,IAAM;AAAA,QACZ,gBAAgB,CAACA,IAAM;AAAA,QACvB,iBAAiBF,MAAS,YAAYK,EAAgB,UAAU;AAAA,MAAA;AAAA,MAGnE,UAAAP,KAAY,gBAAAM,EAACE,GAAA,EAAc,MAAMH,EAAA,CAAO;AAAA,IAAA;AAAA,EAAA;AAGrD;"}
@@ -0,0 +1,56 @@
1
+ import { jsxs as a, jsx as e } from "react/jsx-runtime";
2
+ import m from "./CustomIcons/ArrowUpRightIcon.js";
3
+ import { Link as h } from "./Link.js";
4
+ import c from "./Typography/Text.js";
5
+ const p = "overflow-hidden [display:-webkit-box] [-webkit-box-orient:vertical] [-webkit-line-clamp:2]", x = "flex size-[32px] shrink-0 items-center justify-center rounded-[var(--malachite-radius-md,6px)] bg-[var(--malachite-card-dimmed-background,rgb(250,250,250))] text-[length:var(--malachite-font-size-large,16px)] text-[var(--malachite-text-muted,rgb(115,115,115))]", d = ({ icon: r, title: i, description: s, titleAs: n, block: l }) => {
6
+ const t = l ? "div" : "span";
7
+ return /* @__PURE__ */ a(t, { className: "flex min-w-0 flex-col gap-[4px]", children: [
8
+ /* @__PURE__ */ a(t, { className: "flex items-center gap-[10px]", children: [
9
+ /* @__PURE__ */ e("span", { "aria-hidden": "true", className: x, children: r }),
10
+ /* @__PURE__ */ e(c, { as: n, size: "medium", fontWeight: "semi-bold", style: { margin: 0 }, children: i })
11
+ ] }),
12
+ s && /* @__PURE__ */ e(c, { size: "small", color: "secondary", className: p, children: s })
13
+ ] });
14
+ }, b = (r) => /* @__PURE__ */ e(d, { ...r, titleAs: "span", block: !1 }), k = Object.assign(
15
+ ({
16
+ icon: r,
17
+ title: i,
18
+ description: s,
19
+ href: n,
20
+ linkLabel: l = "Documentation",
21
+ titleAs: t = "h4",
22
+ className: o = ""
23
+ }) => /* @__PURE__ */ a(
24
+ "div",
25
+ {
26
+ className: `flex flex-col gap-[8px] rounded-[var(--malachite-radius-lg,8px)] border border-solid border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] p-[16px] ${o}`,
27
+ children: [
28
+ /* @__PURE__ */ e(
29
+ d,
30
+ {
31
+ icon: r,
32
+ title: i,
33
+ description: s,
34
+ titleAs: t,
35
+ block: !0
36
+ }
37
+ ),
38
+ /* @__PURE__ */ e("div", { children: /* @__PURE__ */ a(h, { href: n, size: "small", underline: !1, children: [
39
+ /* @__PURE__ */ a("span", { "aria-hidden": "true", children: [
40
+ l,
41
+ " "
42
+ ] }),
43
+ /* @__PURE__ */ e("span", { className: "sr-only", children: `${l} for ${i} (opens in a new tab)` }),
44
+ /* @__PURE__ */ e(m, { size: 12 })
45
+ ] }) })
46
+ ]
47
+ }
48
+ ),
49
+ { Header: b }
50
+ );
51
+ export {
52
+ k as ResourceCard,
53
+ b as ResourceHeader,
54
+ k as default
55
+ };
56
+ //# sourceMappingURL=ResourceCard.js.map