@stackone/malachite 2.130.0 → 2.131.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,34 +1,34 @@
1
- import { jsxs as S, jsx as c } from "react/jsx-runtime";
1
+ import { jsxs as A, jsx as c } from "react/jsx-runtime";
2
2
  import v from "@uiw/react-json-view";
3
- import $ from "react";
4
- import G from "./CopyOverlayButton.js";
5
- import { diffHunks as M } from "./codeBlockDiff.js";
6
- import { CodeLine as H } from "./codeBlockLine.js";
7
- import { rowsWrapperStyle as P } from "./codeBlockStyles.js";
8
- import { devWarning as q } from "./devWarning.js";
9
- import { FOCUS_RING_INSET as J, FOCUS_RING as T } from "./focusRing.js";
10
- const C = (e, o) => (r, { type: t }) => t === "value" ? /* @__PURE__ */ c("span", { ...r, style: { ...r.style, color: `var(--w-rjv-type-${o}-color)` }, children: e }) : null, z = (e) => e !== null && typeof e == "object" ? Object.keys(e).length : 0, A = (e, o, r) => r.length > 0 && z(o) > e, B = (e) => {
11
- const o = z(e);
3
+ import j from "react";
4
+ import M from "./CopyOverlayButton.js";
5
+ import { diffHunks as H } from "./codeBlockDiff.js";
6
+ import { CodeLine as P } from "./codeBlockLine.js";
7
+ import { rowsWrapperStyle as q } from "./codeBlockStyles.js";
8
+ import { devWarning as J } from "./devWarning.js";
9
+ import { FOCUS_RING_INSET as W, FOCUS_RING as z } from "./focusRing.js";
10
+ const I = (e, o) => (r, { type: t }) => t === "value" ? /* @__PURE__ */ c("span", { ...r, style: { ...r.style, color: `var(--w-rjv-type-${o}-color)` }, children: e }) : null, E = (e) => e !== null && typeof e == "object" ? Object.keys(e).length : 0, O = (e, o, r) => r.length > 0 && E(o) > e, B = (e) => {
11
+ const o = E(e);
12
12
  return `${o} ${o === 1 ? "item" : "items"}`;
13
- }, W = (e) => e.map((o) => String(o) || '""').join("."), V = (e) => (o, { value: r, keys: t }) => o || A(e, r, t), Q = (e) => (o, { value: r, keys: t }) => {
14
- var b;
15
- if (!A(e, r, t ?? []))
13
+ }, V = (e) => e.map((o) => String(o) || '""').join("."), Q = (e) => (o, { value: r, keys: t }) => o || O(e, r, t), X = (e) => (o, { value: r, keys: t }) => {
14
+ var m;
15
+ if (!O(e, r, t ?? []))
16
16
  return null;
17
- const k = String(((b = o.style) == null ? void 0 : b.transform) ?? "").includes("-90");
17
+ const k = String(((m = o.style) == null ? void 0 : m.transform) ?? "").includes("-90");
18
18
  return /* @__PURE__ */ c(
19
19
  "button",
20
20
  {
21
21
  type: "button",
22
22
  "aria-expanded": !k,
23
- "aria-label": `${W(t ?? [])}, ${B(r)}`,
24
- className: `${o.className ?? ""} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${T}`,
23
+ "aria-label": `${V(t ?? [])}, ${B(r)}`,
24
+ className: `${o.className ?? ""} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${z}`,
25
25
  style: o.style,
26
26
  children: o.children
27
27
  }
28
28
  );
29
- }, X = (e) => (
29
+ }, Y = (e) => (
30
30
  // This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.
31
- ((o, { value: r, keyName: t }) => Reflect.get(o, "data-expanded") && A(e, r, t === void 0 ? [] : [t]) ? (
31
+ ((o, { value: r, keyName: t }) => Reflect.get(o, "data-expanded") && O(e, r, t === void 0 ? [] : [t]) ? (
32
32
  // Its toggle already names the size, so this would say it twice.
33
33
  /* @__PURE__ */ c(
34
34
  "span",
@@ -39,67 +39,67 @@ const C = (e, o) => (r, { type: t }) => t === "value" ? /* @__PURE__ */ c("span"
39
39
  }
40
40
  )
41
41
  ) : null)
42
- ), D = $.lazy(() => import("./CodeBlockHighlighter.js")), Y = {
42
+ ), T = j.lazy(() => import("./CodeBlockHighlighter.js")), Z = {
43
43
  added: "var(--malachite-codeblock-diff-added-background)",
44
44
  removed: "var(--malachite-codeblock-diff-removed-background)",
45
45
  context: void 0
46
- }, Z = {
46
+ }, L = {
47
47
  added: "+",
48
48
  removed: "-",
49
49
  context: void 0
50
- }, L = {
50
+ }, ee = {
51
51
  added: "var(--malachite-codeblock-diff-assistant-background)",
52
52
  removed: "var(--malachite-codeblock-diff-assistant-removed-background)",
53
53
  context: void 0
54
- }, ee = {
54
+ }, oe = {
55
55
  added: "✦",
56
56
  // U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.
57
57
  removed: "−",
58
58
  context: "·"
59
- }, oe = {
59
+ }, re = {
60
60
  added: "var(--malachite-codeblock-diff-assistant-foreground)",
61
61
  removed: "var(--malachite-codeblock-diff-removed-foreground)",
62
62
  context: "var(--malachite-codeblock-diff-context-foreground)"
63
- }, re = (e) => `⋯ ${e} unchanged ${e === 1 ? "line" : "lines"}`, te = (e, o, r) => {
63
+ }, te = (e) => `⋯ ${e} unchanged ${e === 1 ? "line" : "lines"}`, ce = (e, o, r) => {
64
64
  const t = r === "assistant";
65
65
  return {
66
- background: t ? L[e.type] : Y[e.type],
67
- marker: t ? ee[e.type] : Z[e.type],
68
- markerColor: t ? oe[e.type] : void 0,
66
+ background: t ? ee[e.type] : Z[e.type],
67
+ marker: t ? oe[e.type] : L[e.type],
68
+ markerColor: t ? re[e.type] : void 0,
69
69
  // Reserved on unchanged rows too, so the code column does not step in and out.
70
70
  reserveMarker: !0,
71
71
  // Context rows read as de-emphasised, not just unmarked, in the assistant palette.
72
72
  textColor: t && e.type === "context" ? "var(--malachite-codeblock-diff-context-text)" : void 0,
73
73
  strikethrough: t && e.type === "removed",
74
- separatorAbove: e.skippedAbove === void 0 ? void 0 : re(e.skippedAbove),
74
+ separatorAbove: e.skippedAbove === void 0 ? void 0 : te(e.skippedAbove),
75
75
  // A removed line has no number in the after-text, so it keeps the one it had before.
76
76
  lineNumber: o ? e.afterNumber ?? e.beforeNumber : void 0
77
77
  };
78
- }, ue = ({
78
+ }, ke = ({
79
79
  code: e,
80
80
  json: o,
81
81
  showLineNumbers: r = !0,
82
82
  className: t = "",
83
83
  style: k = {},
84
- height: b,
85
- enableCopy: g = !0,
84
+ height: m,
85
+ enableCopy: w = !0,
86
86
  wrapLines: h = !1,
87
87
  language: f,
88
- collapsed: E = !1,
88
+ collapsed: K = !1,
89
89
  collapseLargerThan: a,
90
90
  diff: d,
91
- "aria-label": O,
92
- "aria-labelledby": R
91
+ "aria-label": p,
92
+ "aria-labelledby": y
93
93
  }) => {
94
- const n = a !== void 0 && Number.isInteger(a) && a >= 0 ? a : void 0;
95
- a !== void 0 && n === void 0 && q(
94
+ const R = j.useId(), n = a !== void 0 && Number.isInteger(a) && a >= 0 ? a : void 0;
95
+ a !== void 0 && n === void 0 && J(
96
96
  `CodeBlock.collapseLargerThan:${a}`,
97
97
  `CodeBlock's collapseLargerThan takes a whole count of 0 or more; ${a} is ignored.`
98
98
  );
99
- const l = d ? M(d.before, d.after, d.context) : null, p = (l == null ? void 0 : l.map((s) => s.text).join(`
100
- `)) ?? "", I = (() => {
99
+ const l = d ? H(d.before, d.after, d.context) : null, g = (l == null ? void 0 : l.map((s) => s.text).join(`
100
+ `)) ?? "", _ = (() => {
101
101
  if (l)
102
- return p;
102
+ return g;
103
103
  if (e)
104
104
  return e;
105
105
  if (o !== void 0)
@@ -108,36 +108,40 @@ const C = (e, o) => (r, { type: t }) => t === "value" ? /* @__PURE__ */ c("span"
108
108
  } catch {
109
109
  return;
110
110
  }
111
- })(), _ = g && I !== void 0 && /* @__PURE__ */ c(
112
- G,
111
+ })(), F = w && _ !== void 0 && /* @__PURE__ */ c(
112
+ M,
113
113
  {
114
- text: I,
115
- "aria-label": "Copy",
114
+ text: _,
115
+ ...y ? {
116
+ id: R,
117
+ "aria-label": "Copy",
118
+ "aria-labelledby": `${R} ${y}`
119
+ } : { "aria-label": p ? `Copy ${p}` : "Copy" },
116
120
  iconSize: 14,
117
- 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)] ${T}`,
121
+ 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}`,
118
122
  style: { color: "var(--malachite-codeblock-line-number)" }
119
123
  }
120
- ), m = {
124
+ ), b = {
121
125
  role: "region",
122
- "aria-label": R ? O : O ?? "Code",
123
- "aria-labelledby": R,
126
+ "aria-label": y ? p : p ?? "Code",
127
+ "aria-labelledby": y,
124
128
  tabIndex: 0,
125
- className: `box-border h-full overflow-auto ${J}`
129
+ className: `box-border h-full overflow-auto ${W}`
126
130
  };
127
131
  if (o && !l)
128
- return /* @__PURE__ */ S(
132
+ return /* @__PURE__ */ A(
129
133
  "div",
130
134
  {
131
135
  className: `relative border border-solid rounded-lg overflow-hidden ${t}`,
132
136
  style: {
133
137
  backgroundColor: "var(--malachite-codeblock-background)",
134
138
  borderColor: "var(--malachite-codeblock-border)",
135
- height: b,
139
+ height: m,
136
140
  ...k
137
141
  },
138
142
  children: [
139
- _,
140
- /* @__PURE__ */ c("div", { ...m, children: /* @__PURE__ */ S(
143
+ F,
144
+ /* @__PURE__ */ c("div", { ...b, children: /* @__PURE__ */ A(
141
145
  v,
142
146
  {
143
147
  value: o,
@@ -176,24 +180,24 @@ const C = (e, o) => (r, { type: t }) => t === "value" ? /* @__PURE__ */ c("span"
176
180
  "--w-rjv-type-undefined-color": "var(--malachite-codeblock-keyword)"
177
181
  },
178
182
  displayDataTypes: !1,
179
- enableClipboard: g,
180
- collapsed: E,
181
- shouldExpandNodeInitially: n === void 0 ? void 0 : V(n),
183
+ enableClipboard: w,
184
+ collapsed: K,
185
+ shouldExpandNodeInitially: n === void 0 ? void 0 : Q(n),
182
186
  displayObjectSize: !1,
183
187
  children: [
184
- /* @__PURE__ */ c(v.Null, { render: C("null", "null") }),
185
- /* @__PURE__ */ c(v.Undefined, { render: C("undefined", "undefined") }),
186
- /* @__PURE__ */ c(v.Nan, { render: C("NaN", "nan") }),
188
+ /* @__PURE__ */ c(v.Null, { render: I("null", "null") }),
189
+ /* @__PURE__ */ c(v.Undefined, { render: I("undefined", "undefined") }),
190
+ /* @__PURE__ */ c(v.Nan, { render: I("NaN", "nan") }),
187
191
  /* @__PURE__ */ c(
188
192
  v.Arrow,
189
193
  {
190
- render: n === void 0 ? void 0 : Q(n)
194
+ render: n === void 0 ? void 0 : X(n)
191
195
  }
192
196
  ),
193
197
  /* @__PURE__ */ c(
194
198
  v.Ellipsis,
195
199
  {
196
- render: n === void 0 ? void 0 : X(n)
200
+ render: n === void 0 ? void 0 : Y(n)
197
201
  }
198
202
  )
199
203
  ]
@@ -202,32 +206,32 @@ const C = (e, o) => (r, { type: t }) => t === "value" ? /* @__PURE__ */ c("span"
202
206
  ]
203
207
  }
204
208
  );
205
- const x = g && (!!e || !!l), j = (s, i) => {
206
- const w = s.split(`
209
+ const N = w && (!!e || !!l), C = (s, i) => {
210
+ const S = s.split(`
207
211
  `);
208
212
  return /* @__PURE__ */ c(
209
213
  "div",
210
214
  {
211
- ...m,
212
- className: `${m.className} p-4 text-left`,
213
- style: { paddingRight: x ? 44 : void 0 },
214
- children: /* @__PURE__ */ c("div", { style: P(h), children: w.map((u, N) => {
215
- const y = i == null ? void 0 : i(N);
215
+ ...b,
216
+ className: `${b.className} p-4 text-left`,
217
+ style: { paddingRight: N ? 44 : void 0 },
218
+ children: /* @__PURE__ */ c("div", { style: q(h), children: S.map((u, $) => {
219
+ const x = i == null ? void 0 : i($);
216
220
  return /* @__PURE__ */ c(
217
- H,
221
+ P,
218
222
  {
219
223
  line: u,
220
- lineNumber: (y == null ? void 0 : y.lineNumber) ?? (r ? N + 1 : void 0),
224
+ lineNumber: (x == null ? void 0 : x.lineNumber) ?? (r ? $ + 1 : void 0),
221
225
  wrap: h,
222
- decoration: y,
226
+ decoration: x,
223
227
  children: u
224
228
  },
225
- N
229
+ $
226
230
  );
227
231
  }) })
228
232
  }
229
233
  );
230
- }, F = () => e ? j(e) : null, K = (s) => {
234
+ }, D = () => e ? C(e) : null, U = (s) => {
231
235
  if (s.length === 0)
232
236
  return /* @__PURE__ */ c(
233
237
  "div",
@@ -237,51 +241,51 @@ const C = (e, o) => (r, { type: t }) => t === "value" ? /* @__PURE__ */ c("span"
237
241
  children: "No changes"
238
242
  }
239
243
  );
240
- const i = (w) => {
241
- const u = s[w];
242
- return u ? te(u, r, d == null ? void 0 : d.origin) : void 0;
244
+ const i = (S) => {
245
+ const u = s[S];
246
+ return u ? ce(u, r, d == null ? void 0 : d.origin) : void 0;
243
247
  };
244
- return f ? /* @__PURE__ */ c($.Suspense, { fallback: j(p, i), children: /* @__PURE__ */ c(
245
- D,
248
+ return f ? /* @__PURE__ */ c(j.Suspense, { fallback: C(g, i), children: /* @__PURE__ */ c(
249
+ T,
246
250
  {
247
- code: p,
251
+ code: g,
248
252
  language: f,
249
253
  showLineNumbers: r,
250
254
  wrapLines: h,
251
- copyClearance: x,
255
+ copyClearance: N,
252
256
  decorate: i,
253
- viewportProps: m
257
+ viewportProps: b
254
258
  }
255
- ) }) : j(p, i);
256
- }, U = () => e ? f ? /* @__PURE__ */ c($.Suspense, { fallback: F(), children: /* @__PURE__ */ c(
257
- D,
259
+ ) }) : C(g, i);
260
+ }, G = () => e ? f ? /* @__PURE__ */ c(j.Suspense, { fallback: D(), children: /* @__PURE__ */ c(
261
+ T,
258
262
  {
259
263
  code: e,
260
264
  language: f,
261
265
  showLineNumbers: r,
262
266
  wrapLines: h,
263
- copyClearance: x,
264
- viewportProps: m
267
+ copyClearance: N,
268
+ viewportProps: b
265
269
  }
266
- ) }) : F() : null;
267
- return /* @__PURE__ */ S(
270
+ ) }) : D() : null;
271
+ return /* @__PURE__ */ A(
268
272
  "div",
269
273
  {
270
274
  className: `relative border border-solid rounded-lg overflow-hidden ${t}`,
271
275
  style: {
272
276
  backgroundColor: "var(--malachite-codeblock-background)",
273
277
  borderColor: "var(--malachite-codeblock-border)",
274
- height: b,
278
+ height: m,
275
279
  ...k
276
280
  },
277
281
  children: [
278
- _,
279
- l ? K(l) : U()
282
+ F,
283
+ l ? U(l) : G()
280
284
  ]
281
285
  }
282
286
  );
283
287
  };
284
288
  export {
285
- ue as default
289
+ ke as default
286
290
  };
287
291
  //# 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 CopyOverlayButton from './CopyOverlayButton';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { devWarning } from './devWarning';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\n\n/**\n * The value side of a JSON literal that has no value of its own to print, in its type's\n * colour. These read as keywords, as `true` and `false` do: the comment grey is under AA\n * contrast on the light background.\n */\nconst renderLiteral =\n (text: string, type: 'null' | 'undefined' | 'nan') =>\n (props: React.HTMLAttributes<HTMLSpanElement>, { type: part }: { type: 'type' | 'value' }) =>\n part === 'value' ? (\n <span {...props} style={{ ...props.style, color: `var(--w-rjv-type-${type}-color)` }}>\n {text}\n </span>\n ) : null;\n\n/** A json node's own entries, as the library counts them to draw it. */\nconst entryCount = (value: unknown): number =>\n value !== null && typeof value === 'object' ? Object.keys(value).length : 0;\n\n/** A nested node over the limit: the only kind the limit folds, toggles and sizes. */\nconst isOverLimit = (limit: number, value: unknown, keys: readonly (number | string)[]): boolean =>\n keys.length > 0 && entryCount(value) > limit;\n\nconst sizeOf = (value: unknown): string => {\n const count = entryCount(value);\n return `${count} ${count === 1 ? 'item' : 'items'}`;\n};\n\n/** Where a node sits, so two toggles for nodes sharing a key read apart: `users.0.roles`. */\nconst pathOf = (keys: readonly (number | string)[]): string =>\n keys.map((key) => String(key) || '\"\"').join('.');\n\n// The library's flag is the inverse of its name: returning true starts the node collapsed.\nconst collapseNodesLargerThan =\n (limit: number) =>\n (\n isCollapsed: boolean,\n { value, keys }: { value?: unknown; keys: (number | string)[] },\n ): boolean =>\n isCollapsed || isOverLimit(limit, value, keys);\n\n// The row around the arrow owns the click and the arrow's rotation is its only state, so this\n// button is a keyboard toggle that reads `aria-expanded` from it.\nconst toggleArrowOver =\n (limit: number) =>\n (\n props: { className?: string; style?: React.CSSProperties; children?: React.ReactNode },\n { value, keys }: { value?: unknown; keys?: (number | string)[] },\n ) => {\n if (!isOverLimit(limit, value, keys ?? [])) {\n return null;\n }\n const collapsed = String(props.style?.transform ?? '').includes('-90');\n return (\n <button\n type=\"button\"\n aria-expanded={!collapsed}\n aria-label={`${pathOf(keys ?? [])}, ${sizeOf(value)}`}\n className={`${props.className ?? ''} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${FOCUS_RING}`}\n style={props.style}\n >\n {props.children}\n </button>\n );\n };\n\nconst foldedSizeOver =\n (limit: number) =>\n // This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.\n (props: object, { value, keyName }: { value?: unknown; keyName?: string | number }) =>\n Reflect.get(props, 'data-expanded') &&\n isOverLimit(limit, value, keyName === undefined ? [] : [keyName]) ? (\n // Its toggle already names the size, so this would say it twice.\n <span\n aria-hidden=\"true\"\n className={`${Reflect.get(props, 'className') ?? ''} mx-[4px] cursor-pointer select-none text-[var(--malachite-codeblock-foreground)]`}\n >\n {`\\u2026 ${sizeOf(value)}`}\n </span>\n ) : null;\n\nconst CodeBlockHighlighter = React.lazy(() => import('./CodeBlockHighlighter'));\n\nexport interface CodeBlockProps {\n /** The code content to display */\n code?: string;\n /** JSON object to display as formatted JSON */\n json?: object;\n /** Show line numbers */\n showLineNumbers?: boolean;\n /** Custom class name */\n className?: string;\n /** Custom styles */\n style?: React.CSSProperties;\n /** Height of the code block */\n height?: string | number;\n /** Enable copy functionality */\n enableCopy?: boolean;\n /** Wrap long lines instead of scrolling horizontally */\n wrapLines?: boolean;\n /**\n * Highlight the code with this language's grammar. `cedar` is a grammar this library\n * ships itself (`prismCedar.ts`), since Prism and refractor carry none; widen the union\n * as further grammars are registered in CodeBlockHighlighter.\n */\n language?: 'yaml' | 'cedar';\n /** How much of a `json` tree starts collapsed: `true` all of it, a number below that depth. */\n collapsed?: boolean | number;\n /**\n * Starts any nested node with more entries than this collapsed, at any depth, behind a keyboard\n * toggle naming its path and size; nodes within the limit keep the library's arrow. 0 or more.\n */\n collapseLargerThan?: number;\n /**\n * Renders the change between two texts rather than one text, and takes precedence over\n * `code` and `json`. Only the changed lines are shown, with `context` unchanged ones either\n * side, so a small edit to a long document reads as a few hunks instead of the whole thing.\n */\n diff?: {\n before: string;\n after: string;\n /** Unchanged lines kept either side of each change. Three by convention. */\n context?: number;\n /**\n * Swaps the `+`/`-` gutter and tinted rows for the palette a mock specified for\n * AI-authored changes: star, minus-sign and middle-dot markers, and a struck-through\n * removal. Omit to keep the neutral markers; there is no default consumer for the\n * assistant look yet.\n */\n origin?: 'assistant';\n };\n /** Names the scrollable region. 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 // Declared once and rendered by both the JSON branch and the code branch below, so the\n // two tabs of one document do not disagree about whether it can be copied.\n const copyButton = enableCopy && textToCopy !== undefined && (\n <CopyOverlayButton\n text={textToCopy}\n aria-label=\"Copy\"\n iconSize={14}\n className={`absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${FOCUS_RING}`}\n style={{ color: 'var(--malachite-codeblock-line-number)' }}\n />\n );\n\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n const viewportProps = {\n role: 'region',\n 'aria-label': ariaLabelledBy ? ariaLabel : (ariaLabel ?? 'Code'),\n 'aria-labelledby': ariaLabelledBy,\n tabIndex: 0,\n className: `box-border h-full overflow-auto ${FOCUS_RING_INSET}`,\n } satisfies React.HTMLAttributes<HTMLElement>;\n\n // If JSON is provided, use JsonView component\n if (json && !diffRows) {\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {/* The frame clips at `height`; this scrolls inside it, so the copy button stays put. */}\n <div {...viewportProps}>\n <JsonView\n value={json}\n style={\n {\n backgroundColor: 'var(--malachite-codeblock-background)',\n color: 'var(--malachite-codeblock-foreground)',\n fontSize: '14px',\n fontFamily: 'var(--malachite-font-mono, monospace)',\n padding: '16px',\n lineHeight: '1.5',\n textAlign: 'left',\n '--w-rjv-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-key-string': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-background-color': 'var(--malachite-codeblock-background)',\n '--w-rjv-line-color': 'var(--malachite-codeblock-border)',\n '--w-rjv-arrow-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-edit-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-info-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-update-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-copied-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-copied-success-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-curlybraces-color':\n 'var(--malachite-codeblock-foreground)',\n '--w-rjv-colon-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-brackets-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-quotes-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-quotes-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-int-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-float-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-bigint-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-boolean-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-date-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-url-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-null-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-nan-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-undefined-color':\n 'var(--malachite-codeblock-keyword)',\n } as React.CSSProperties\n }\n displayDataTypes={false}\n enableClipboard={enableCopy}\n collapsed={collapsed}\n shouldExpandNodeInitially={\n limit === undefined ? undefined : collapseNodesLargerThan(limit)\n }\n displayObjectSize={false}\n >\n {/* The library draws these three only as their type label, which\n `displayDataTypes` turns off, so without a value of their own a\n `null` reads as a key with nothing after it. */}\n <JsonView.Null render={renderLiteral('null', 'null')} />\n <JsonView.Undefined render={renderLiteral('undefined', 'undefined')} />\n <JsonView.Nan render={renderLiteral('NaN', 'nan')} />\n {/* Mounted either way: the library keeps a slot's last render, so it is\n switched off by passing none rather than by unmounting. */}\n <JsonView.Arrow\n render={limit === undefined ? undefined : toggleArrowOver(limit)}\n />\n <JsonView.Ellipsis\n render={limit === undefined ? undefined : foldedSizeOver(limit)}\n />\n </JsonView>\n </div>\n </div>\n );\n }\n\n // Reserve clearance so a wide first line never sits under the floating copy button.\n const copyClearance = enableCopy && (!!code || !!diffRows);\n\n const renderPlainLines = (\n text: string,\n decorate?: (index: number) => CodeLineDecoration | undefined,\n ) => {\n const lines = text.split('\\n');\n\n return (\n <div\n {...viewportProps}\n className={`${viewportProps.className} p-4 text-left`}\n style={{ paddingRight: copyClearance ? 44 : undefined }}\n >\n <div style={rowsWrapperStyle(wrapLines)}>\n {lines.map((line, index) => {\n const decoration = decorate?.(index);\n\n return (\n <CodeLine\n key={index}\n line={line}\n lineNumber={\n decoration?.lineNumber ??\n (showLineNumbers ? index + 1 : undefined)\n }\n wrap={wrapLines}\n decoration={decoration}\n >\n {line}\n </CodeLine>\n );\n })}\n </div>\n </div>\n );\n };\n\n const renderPlainCode = () => (code ? renderPlainLines(code) : null);\n\n const renderDiff = (rows: DiffDisplayRow[]) => {\n if (rows.length === 0) {\n return (\n <div\n className=\"p-4 text-left\"\n style={{ color: 'var(--malachite-codeblock-comment)' }}\n >\n No changes\n </div>\n );\n }\n\n const decorate = (index: number) => {\n const row = rows[index];\n\n return row ? diffDecoration(row, showLineNumbers, diff?.origin) : undefined;\n };\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainLines(diffText, decorate)}>\n {/*\n * The whole merged text goes to the highlighter in one piece, so a hunk\n * is tokenised in the company of its neighbours rather than on its own.\n * Prism still cannot see the lines the hunks left out, so a construct\n * spanning an omitted run can highlight oddly — the reason `context`\n * defaults to a few lines rather than none.\n */}\n <CodeBlockHighlighter\n code={diffText}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n decorate={decorate}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainLines(diffText, decorate);\n };\n\n // For code strings, create a simple syntax-highlighted view\n const renderCodeContent = () => {\n if (!code) {\n return null;\n }\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainCode()}>\n <CodeBlockHighlighter\n code={code}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainCode();\n };\n\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {diffRows ? renderDiff(diffRows) : renderCodeContent()}\n </div>\n );\n};\n\nexport default CodeBlock;\n"],"names":["renderLiteral","text","type","props","part","jsx","entryCount","value","isOverLimit","limit","keys","sizeOf","count","pathOf","key","collapseNodesLargerThan","isCollapsed","toggleArrowOver","collapsed","_a","FOCUS_RING","foldedSizeOver","keyName","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapseLargerThan","diff","ariaLabel","ariaLabelledBy","devWarning","diffRows","diffHunks","diffText","textToCopy","copyButton","CopyOverlayButton","viewportProps","FOCUS_RING_INSET","jsxs","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;AAcA,MAAMA,IACF,CAACC,GAAcC,MACf,CAACC,GAA8C,EAAE,MAAMC,EAAA,MACnDA,MAAS,UACL,gBAAAC,EAAC,QAAA,EAAM,GAAGF,GAAO,OAAO,EAAE,GAAGA,EAAM,OAAO,OAAO,oBAAoBD,CAAI,UAAA,GACpE,UAAAD,EAAA,CACL,IACA,MAGNK,IAAa,CAACC,MAChBA,MAAU,QAAQ,OAAOA,KAAU,WAAW,OAAO,KAAKA,CAAK,EAAE,SAAS,GAGxEC,IAAc,CAACC,GAAeF,GAAgBG,MAChDA,EAAK,SAAS,KAAKJ,EAAWC,CAAK,IAAIE,GAErCE,IAAS,CAACJ,MAA2B;AACvC,QAAMK,IAAQN,EAAWC,CAAK;AAC9B,SAAO,GAAGK,CAAK,IAAIA,MAAU,IAAI,SAAS,OAAO;AACrD,GAGMC,IAAS,CAACH,MACZA,EAAK,IAAI,CAACI,MAAQ,OAAOA,CAAG,KAAK,IAAI,EAAE,KAAK,GAAG,GAG7CC,IACF,CAACN,MACD,CACIO,GACA,EAAE,OAAAT,GAAO,MAAAG,EAAA,MAETM,KAAeR,EAAYC,GAAOF,GAAOG,CAAI,GAI/CO,IACF,CAACR,MACD,CACIN,GACA,EAAE,OAAAI,GAAO,MAAAG,QACR;;AACD,MAAI,CAACF,EAAYC,GAAOF,GAAOG,KAAQ,CAAA,CAAE;AACrC,WAAO;AAEX,QAAMQ,IAAY,SAAOC,IAAAhB,EAAM,UAAN,gBAAAgB,EAAa,cAAa,EAAE,EAAE,SAAS,KAAK;AACrE,SACI,gBAAAd;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,iBAAe,CAACa;AAAA,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,QACA,eAAAiB;AAAA,QACA,UAAAE;AAAA,QACA,eAAAN;AAAA,MAAA;AAAA,IAAA,GAER,IAIDK,EAAiBT,GAAUU,CAAQ;AAAA,EAC9C,GAGMU,IAAoB,MACjBnC,IAIDO,sBAEKpB,EAAM,UAAN,EAAe,UAAU6C,KACtB,UAAA,gBAAAhE;AAAA,IAACkB;AAAA,IAAA;AAAA,MACG,MAAAc;AAAA,MACA,UAAAO;AAAA,MACA,iBAAAX;AAAA,MACA,WAAAU;AAAA,MACA,eAAAiB;AAAA,MACA,eAAAJ;AAAA,IAAA;AAAA,EAAA,GAER,IAIDa,EAAA,IAlBI;AAqBf,SACI,gBAAAX;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,QAAAc;AAAA,QACAJ,IAAWoB,EAAWpB,CAAQ,IAAIsB,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
1
+ {"version":3,"file":"CodeBlock.js","sources":["../../src/components/CodeBlock.tsx"],"sourcesContent":["import JsonView from '@uiw/react-json-view';\nimport React from 'react';\nimport CopyOverlayButton from './CopyOverlayButton';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { devWarning } from './devWarning';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\n\n/**\n * The value side of a JSON literal that has no value of its own to print, in its type's\n * colour. These read as keywords, as `true` and `false` do: the comment grey is under AA\n * contrast on the light background.\n */\nconst renderLiteral =\n (text: string, type: 'null' | 'undefined' | 'nan') =>\n (props: React.HTMLAttributes<HTMLSpanElement>, { type: part }: { type: 'type' | 'value' }) =>\n part === 'value' ? (\n <span {...props} style={{ ...props.style, color: `var(--w-rjv-type-${type}-color)` }}>\n {text}\n </span>\n ) : null;\n\n/** A json node's own entries, as the library counts them to draw it. */\nconst entryCount = (value: unknown): number =>\n value !== null && typeof value === 'object' ? Object.keys(value).length : 0;\n\n/** A nested node over the limit: the only kind the limit folds, toggles and sizes. */\nconst isOverLimit = (limit: number, value: unknown, keys: readonly (number | string)[]): boolean =>\n keys.length > 0 && entryCount(value) > limit;\n\nconst sizeOf = (value: unknown): string => {\n const count = entryCount(value);\n return `${count} ${count === 1 ? 'item' : 'items'}`;\n};\n\n/** Where a node sits, so two toggles for nodes sharing a key read apart: `users.0.roles`. */\nconst pathOf = (keys: readonly (number | string)[]): string =>\n keys.map((key) => String(key) || '\"\"').join('.');\n\n// The library's flag is the inverse of its name: returning true starts the node collapsed.\nconst collapseNodesLargerThan =\n (limit: number) =>\n (\n isCollapsed: boolean,\n { value, keys }: { value?: unknown; keys: (number | string)[] },\n ): boolean =>\n isCollapsed || isOverLimit(limit, value, keys);\n\n// The row around the arrow owns the click and the arrow's rotation is its only state, so this\n// button is a keyboard toggle that reads `aria-expanded` from it.\nconst toggleArrowOver =\n (limit: number) =>\n (\n props: { className?: string; style?: React.CSSProperties; children?: React.ReactNode },\n { value, keys }: { value?: unknown; keys?: (number | string)[] },\n ) => {\n if (!isOverLimit(limit, value, keys ?? [])) {\n return null;\n }\n const collapsed = String(props.style?.transform ?? '').includes('-90');\n return (\n <button\n type=\"button\"\n aria-expanded={!collapsed}\n aria-label={`${pathOf(keys ?? [])}, ${sizeOf(value)}`}\n className={`${props.className ?? ''} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${FOCUS_RING}`}\n style={props.style}\n >\n {props.children}\n </button>\n );\n };\n\nconst foldedSizeOver =\n (limit: number) =>\n // This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.\n (props: object, { value, keyName }: { value?: unknown; keyName?: string | number }) =>\n Reflect.get(props, 'data-expanded') &&\n isOverLimit(limit, value, keyName === undefined ? [] : [keyName]) ? (\n // Its toggle already names the size, so this would say it twice.\n <span\n aria-hidden=\"true\"\n className={`${Reflect.get(props, 'className') ?? ''} mx-[4px] cursor-pointer select-none text-[var(--malachite-codeblock-foreground)]`}\n >\n {`\\u2026 ${sizeOf(value)}`}\n </span>\n ) : null;\n\nconst CodeBlockHighlighter = React.lazy(() => import('./CodeBlockHighlighter'));\n\nexport interface CodeBlockProps {\n /** The code content to display */\n code?: string;\n /** JSON object to display as formatted JSON */\n json?: object;\n /** Show line numbers */\n showLineNumbers?: boolean;\n /** Custom class name */\n className?: string;\n /** Custom styles */\n style?: React.CSSProperties;\n /** Height of the code block */\n height?: string | number;\n /** Enable copy functionality */\n enableCopy?: boolean;\n /** Wrap long lines instead of scrolling horizontally */\n wrapLines?: boolean;\n /**\n * Highlight the code with this language's grammar. `cedar` is a grammar this library\n * ships itself (`prismCedar.ts`), since Prism and refractor carry none; widen the union\n * as further grammars are registered in CodeBlockHighlighter.\n */\n language?: 'yaml' | 'cedar';\n /** How much of a `json` tree starts collapsed: `true` all of it, a number below that depth. */\n collapsed?: boolean | number;\n /**\n * Starts any nested node with more entries than this collapsed, at any depth, behind a keyboard\n * toggle naming its path and size; nodes within the limit keep the library's arrow. 0 or more.\n */\n collapseLargerThan?: number;\n /**\n * Renders the change between two texts rather than one text, and takes precedence over\n * `code` and `json`. Only the changed lines are shown, with `context` unchanged ones either\n * side, so a small edit to a long document reads as a few hunks instead of the whole thing.\n */\n diff?: {\n before: string;\n after: string;\n /** Unchanged lines kept either side of each change. Three by convention. */\n context?: number;\n /**\n * Swaps the `+`/`-` gutter and tinted rows for the palette a mock specified for\n * AI-authored changes: star, minus-sign and middle-dot markers, and a struck-through\n * removal. Omit to keep the neutral markers; there is no default consumer for the\n * assistant look yet.\n */\n origin?: 'assistant';\n };\n /** Names the scrollable region, and the copy button as \"Copy\" and this. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region and the copy button by a visible label instead of `aria-label`. */\n 'aria-labelledby'?: string;\n}\n\nconst DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-added-background)',\n removed: 'var(--malachite-codeblock-diff-removed-background)',\n context: undefined,\n};\n\nconst DIFF_MARKERS: Record<DiffRowType, string | undefined> = {\n added: '+',\n removed: '-',\n context: undefined,\n};\n\n// The assistant palette also marks context rows, which the neutral one leaves bare.\nconst ASSISTANT_DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-assistant-background)',\n removed: 'var(--malachite-codeblock-diff-assistant-removed-background)',\n context: undefined,\n};\n\nconst ASSISTANT_DIFF_MARKERS: Record<DiffRowType, string> = {\n added: '\\u2726',\n // U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.\n removed: '\\u2212',\n context: '\\u00b7',\n};\n\nconst ASSISTANT_DIFF_MARKER_COLORS: Record<DiffRowType, string> = {\n added: 'var(--malachite-codeblock-diff-assistant-foreground)',\n removed: 'var(--malachite-codeblock-diff-removed-foreground)',\n context: 'var(--malachite-codeblock-diff-context-foreground)',\n};\n\nconst unchangedRun = (count: number): string =>\n `\\u22ef ${count} unchanged ${count === 1 ? 'line' : 'lines'}`;\n\nconst diffDecoration = (\n row: DiffDisplayRow,\n showLineNumbers: boolean,\n origin?: 'assistant',\n): CodeLineDecoration => {\n const assistant = origin === 'assistant';\n\n return {\n background: assistant ? ASSISTANT_DIFF_BACKGROUNDS[row.type] : DIFF_BACKGROUNDS[row.type],\n marker: assistant ? ASSISTANT_DIFF_MARKERS[row.type] : DIFF_MARKERS[row.type],\n markerColor: assistant ? ASSISTANT_DIFF_MARKER_COLORS[row.type] : undefined,\n // Reserved on unchanged rows too, so the code column does not step in and out.\n reserveMarker: true,\n // Context rows read as de-emphasised, not just unmarked, in the assistant palette.\n textColor:\n assistant && row.type === 'context'\n ? 'var(--malachite-codeblock-diff-context-text)'\n : undefined,\n strikethrough: assistant && row.type === 'removed',\n separatorAbove: row.skippedAbove === undefined ? undefined : unchangedRun(row.skippedAbove),\n // A removed line has no number in the after-text, so it keeps the one it had before.\n lineNumber: showLineNumbers ? (row.afterNumber ?? row.beforeNumber) : undefined,\n };\n};\n\nconst CodeBlock: React.FC<CodeBlockProps> = ({\n code,\n json,\n showLineNumbers = true,\n className = '',\n style = {},\n height,\n enableCopy = true,\n wrapLines = false,\n language,\n collapsed = false,\n collapseLargerThan,\n diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const copyId = React.useId();\n const limit =\n collapseLargerThan !== undefined &&\n Number.isInteger(collapseLargerThan) &&\n collapseLargerThan >= 0\n ? collapseLargerThan\n : undefined;\n if (collapseLargerThan !== undefined && limit === undefined) {\n devWarning(\n `CodeBlock.collapseLargerThan:${collapseLargerThan}`,\n `CodeBlock's collapseLargerThan takes a whole count of 0 or more; ${collapseLargerThan} is ignored.`,\n );\n }\n const diffRows = diff ? diffHunks(diff.before, diff.after, diff.context) : null;\n const diffText = diffRows?.map((row) => row.text).join('\\n') ?? '';\n\n /**\n * What the button puts on the clipboard, in the same form the block is showing. A JSON\n * block is pretty-printed rather than handed over minified: the reader is copying what\n * they can see. `undefined` means there is nothing to copy and no button to offer.\n */\n const copyText = (): string | undefined => {\n if (diffRows) {\n return diffText;\n }\n\n // An empty block has nothing to copy, so it offers no button — `!== undefined` would\n // hand back the empty string and put a dead control on it.\n if (code) {\n return code;\n }\n\n if (json !== undefined) {\n try {\n return JSON.stringify(json, null, 2);\n } catch {\n // A cycle or a BigInt: no honest text to copy, so offer no button.\n return undefined;\n }\n }\n\n return undefined;\n };\n\n const textToCopy = copyText();\n\n // Declared once and rendered by both the JSON branch and the code branch below, so the\n // two tabs of one document do not disagree about whether it can be copied.\n const copyButton = enableCopy && textToCopy !== undefined && (\n <CopyOverlayButton\n text={textToCopy}\n // Named after the block, so a page of blocks has a \"Copy\" for each rather than\n // several alike. Its own id leads the list to keep the word \"Copy\" in the name.\n {...(ariaLabelledBy\n ? {\n id: copyId,\n 'aria-label': 'Copy',\n 'aria-labelledby': `${copyId} ${ariaLabelledBy}`,\n }\n : { 'aria-label': ariaLabel ? `Copy ${ariaLabel}` : 'Copy' })}\n iconSize={14}\n className={`absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${FOCUS_RING}`}\n style={{ color: 'var(--malachite-codeblock-line-number)' }}\n />\n );\n\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n const viewportProps = {\n role: 'region',\n 'aria-label': ariaLabelledBy ? ariaLabel : (ariaLabel ?? 'Code'),\n 'aria-labelledby': ariaLabelledBy,\n tabIndex: 0,\n className: `box-border h-full overflow-auto ${FOCUS_RING_INSET}`,\n } satisfies React.HTMLAttributes<HTMLElement>;\n\n // If JSON is provided, use JsonView component\n if (json && !diffRows) {\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {/* The frame clips at `height`; this scrolls inside it, so the copy button stays put. */}\n <div {...viewportProps}>\n <JsonView\n value={json}\n style={\n {\n backgroundColor: 'var(--malachite-codeblock-background)',\n color: 'var(--malachite-codeblock-foreground)',\n fontSize: '14px',\n fontFamily: 'var(--malachite-font-mono, monospace)',\n padding: '16px',\n lineHeight: '1.5',\n textAlign: 'left',\n '--w-rjv-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-key-string': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-background-color': 'var(--malachite-codeblock-background)',\n '--w-rjv-line-color': 'var(--malachite-codeblock-border)',\n '--w-rjv-arrow-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-edit-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-info-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-update-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-copied-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-copied-success-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-curlybraces-color':\n 'var(--malachite-codeblock-foreground)',\n '--w-rjv-colon-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-brackets-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-quotes-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-quotes-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-int-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-float-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-bigint-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-boolean-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-date-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-url-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-null-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-nan-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-undefined-color':\n 'var(--malachite-codeblock-keyword)',\n } as React.CSSProperties\n }\n displayDataTypes={false}\n enableClipboard={enableCopy}\n collapsed={collapsed}\n shouldExpandNodeInitially={\n limit === undefined ? undefined : collapseNodesLargerThan(limit)\n }\n displayObjectSize={false}\n >\n {/* The library draws these three only as their type label, which\n `displayDataTypes` turns off, so without a value of their own a\n `null` reads as a key with nothing after it. */}\n <JsonView.Null render={renderLiteral('null', 'null')} />\n <JsonView.Undefined render={renderLiteral('undefined', 'undefined')} />\n <JsonView.Nan render={renderLiteral('NaN', 'nan')} />\n {/* Mounted either way: the library keeps a slot's last render, so it is\n switched off by passing none rather than by unmounting. */}\n <JsonView.Arrow\n render={limit === undefined ? undefined : toggleArrowOver(limit)}\n />\n <JsonView.Ellipsis\n render={limit === undefined ? undefined : foldedSizeOver(limit)}\n />\n </JsonView>\n </div>\n </div>\n );\n }\n\n // Reserve clearance so a wide first line never sits under the floating copy button.\n const copyClearance = enableCopy && (!!code || !!diffRows);\n\n const renderPlainLines = (\n text: string,\n decorate?: (index: number) => CodeLineDecoration | undefined,\n ) => {\n const lines = text.split('\\n');\n\n return (\n <div\n {...viewportProps}\n className={`${viewportProps.className} p-4 text-left`}\n style={{ paddingRight: copyClearance ? 44 : undefined }}\n >\n <div style={rowsWrapperStyle(wrapLines)}>\n {lines.map((line, index) => {\n const decoration = decorate?.(index);\n\n return (\n <CodeLine\n key={index}\n line={line}\n lineNumber={\n decoration?.lineNumber ??\n (showLineNumbers ? index + 1 : undefined)\n }\n wrap={wrapLines}\n decoration={decoration}\n >\n {line}\n </CodeLine>\n );\n })}\n </div>\n </div>\n );\n };\n\n const renderPlainCode = () => (code ? renderPlainLines(code) : null);\n\n const renderDiff = (rows: DiffDisplayRow[]) => {\n if (rows.length === 0) {\n return (\n <div\n className=\"p-4 text-left\"\n style={{ color: 'var(--malachite-codeblock-comment)' }}\n >\n No changes\n </div>\n );\n }\n\n const decorate = (index: number) => {\n const row = rows[index];\n\n return row ? diffDecoration(row, showLineNumbers, diff?.origin) : undefined;\n };\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainLines(diffText, decorate)}>\n {/*\n * The whole merged text goes to the highlighter in one piece, so a hunk\n * is tokenised in the company of its neighbours rather than on its own.\n * Prism still cannot see the lines the hunks left out, so a construct\n * spanning an omitted run can highlight oddly — the reason `context`\n * defaults to a few lines rather than none.\n */}\n <CodeBlockHighlighter\n code={diffText}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n decorate={decorate}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainLines(diffText, decorate);\n };\n\n // For code strings, create a simple syntax-highlighted view\n const renderCodeContent = () => {\n if (!code) {\n return null;\n }\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainCode()}>\n <CodeBlockHighlighter\n code={code}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainCode();\n };\n\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {diffRows ? renderDiff(diffRows) : renderCodeContent()}\n </div>\n );\n};\n\nexport default CodeBlock;\n"],"names":["renderLiteral","text","type","props","part","jsx","entryCount","value","isOverLimit","limit","keys","sizeOf","count","pathOf","key","collapseNodesLargerThan","isCollapsed","toggleArrowOver","collapsed","_a","FOCUS_RING","foldedSizeOver","keyName","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapseLargerThan","diff","ariaLabel","ariaLabelledBy","copyId","devWarning","diffRows","diffHunks","diffText","textToCopy","copyButton","CopyOverlayButton","viewportProps","FOCUS_RING_INSET","jsxs","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;AAcA,MAAMA,IACF,CAACC,GAAcC,MACf,CAACC,GAA8C,EAAE,MAAMC,EAAA,MACnDA,MAAS,UACL,gBAAAC,EAAC,QAAA,EAAM,GAAGF,GAAO,OAAO,EAAE,GAAGA,EAAM,OAAO,OAAO,oBAAoBD,CAAI,UAAA,GACpE,UAAAD,EAAA,CACL,IACA,MAGNK,IAAa,CAACC,MAChBA,MAAU,QAAQ,OAAOA,KAAU,WAAW,OA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A,WAAAU;AAAA,MACA,eAAAkB;AAAA,MACA,eAAAJ;AAAA,IAAA;AAAA,EAAA,GAER,IAIDa,EAAA,IAlBI;AAqBf,SACI,gBAAAX;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,2DAA2DpB,CAAS;AAAA,MAC/E,OAAO;AAAA,QACH,iBAAiB;AAAA,QACjB,aAAa;AAAA,QACb,QAAAE;AAAA,QACA,GAAGD;AAAA,MAAA;AAAA,MAGN,UAAA;AAAA,QAAAe;AAAA,QACAJ,IAAWoB,EAAWpB,CAAQ,IAAIsB,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
@@ -1,31 +1,35 @@
1
- import { jsxs as n, Fragment as s, jsx as o } from "react/jsx-runtime";
2
- import m from "./CustomIcons/CheckmarkIcon.js";
3
- import d from "./CustomIcons/CopyIcon.js";
1
+ import { jsxs as d, Fragment as m, jsx as o } from "react/jsx-runtime";
2
+ import b from "./CustomIcons/CheckmarkIcon.js";
3
+ import y from "./CustomIcons/CopyIcon.js";
4
4
  import { useClipboardCopy as u } from "./useClipboardCopy.js";
5
- const h = ({
5
+ const v = ({
6
6
  text: r,
7
- "aria-label": t,
8
- iconSize: e,
9
- className: a,
10
- style: p
7
+ "aria-label": l,
8
+ "aria-labelledby": i,
9
+ id: t,
10
+ iconSize: a,
11
+ className: p,
12
+ style: c
11
13
  }) => {
12
- const { outcome: l, copy: c } = u(r), i = l === "copied";
13
- return /* @__PURE__ */ n(s, { children: [
14
+ const { outcome: n, copy: s } = u(r), e = n === "copied";
15
+ return /* @__PURE__ */ d(m, { children: [
14
16
  /* @__PURE__ */ o(
15
17
  "button",
16
18
  {
17
19
  type: "button",
18
- "aria-label": t,
19
- onClick: () => void c(r),
20
- className: a,
21
- style: p,
22
- children: i ? /* @__PURE__ */ o(m, { size: e }) : /* @__PURE__ */ o(d, { size: e })
20
+ id: t,
21
+ "aria-label": l,
22
+ "aria-labelledby": i,
23
+ onClick: () => void s(r),
24
+ className: p,
25
+ style: c,
26
+ children: e ? /* @__PURE__ */ o(b, { size: a }) : /* @__PURE__ */ o(y, { size: a })
23
27
  }
24
28
  ),
25
- /* @__PURE__ */ o("span", { "aria-live": "polite", className: "sr-only", children: i ? "Copied to clipboard" : "" })
29
+ /* @__PURE__ */ o("span", { "aria-live": "polite", className: "sr-only", children: e ? "Copied to clipboard" : "" })
26
30
  ] });
27
31
  };
28
32
  export {
29
- h as default
33
+ v as default
30
34
  };
31
35
  //# sourceMappingURL=CopyOverlayButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CopyOverlayButton.js","sources":["../../src/components/CopyOverlayButton.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { useClipboardCopy } from './useClipboardCopy';\n\ninterface CopyOverlayButtonProps {\n text: string;\n 'aria-label': string;\n iconSize: number;\n className: string;\n style?: React.CSSProperties;\n}\n\nconst CopyOverlayButton: React.FC<CopyOverlayButtonProps> = ({\n text,\n 'aria-label': ariaLabel,\n iconSize,\n className,\n style,\n}) => {\n const { outcome, copy } = useClipboardCopy(text);\n const copied = outcome === 'copied';\n return (\n <>\n <button\n type=\"button\"\n aria-label={ariaLabel}\n onClick={() => void copy(text)}\n className={className}\n style={style}\n >\n {copied ? <CheckmarkIcon size={iconSize} /> : <CopyIcon size={iconSize} />}\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\nexport default CopyOverlayButton;\n"],"names":["CopyOverlayButton","text","ariaLabel","iconSize","className","style","outcome","copy","useClipboardCopy","copied","jsxs","Fragment","jsx","CheckmarkIcon","CopyIcon"],"mappings":";;;;AAaA,MAAMA,IAAsD,CAAC;AAAA,EACzD,MAAAC;AAAA,EACA,cAAcC;AAAA,EACd,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AACJ,MAAM;AACF,QAAM,EAAE,SAAAC,GAAS,MAAAC,MAASC,EAAiBP,CAAI,GACzCQ,IAASH,MAAY;AAC3B,SACI,gBAAAI,EAAAC,GAAA,EACI,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,MAAK;AAAA,QACL,cAAYV;AAAA,QACZ,SAAS,MAAM,KAAKK,EAAKN,CAAI;AAAA,QAC7B,WAAAG;AAAA,QACA,OAAAC;AAAA,QAEC,UAAAI,sBAAUI,GAAA,EAAc,MAAMV,GAAU,IAAK,gBAAAS,EAACE,GAAA,EAAS,MAAMX,EAAA,CAAU;AAAA,MAAA;AAAA,IAAA;AAAA,IAG5E,gBAAAS,EAAC,UAAK,aAAU,UAAS,WAAU,WAC9B,UAAAH,IAAS,wBAAwB,GAAA,CACtC;AAAA,EAAA,GACJ;AAER;"}
1
+ {"version":3,"file":"CopyOverlayButton.js","sources":["../../src/components/CopyOverlayButton.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { useClipboardCopy } from './useClipboardCopy';\n\ninterface CopyOverlayButtonProps {\n text: string;\n 'aria-label': string;\n /** Names the button by these ids instead; list the button's own `id` first to keep its label. */\n 'aria-labelledby'?: string;\n id?: string;\n iconSize: number;\n className: string;\n style?: React.CSSProperties;\n}\n\nconst CopyOverlayButton: React.FC<CopyOverlayButtonProps> = ({\n text,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n id,\n iconSize,\n className,\n style,\n}) => {\n const { outcome, copy } = useClipboardCopy(text);\n const copied = outcome === 'copied';\n return (\n <>\n <button\n type=\"button\"\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n onClick={() => void copy(text)}\n className={className}\n style={style}\n >\n {copied ? <CheckmarkIcon size={iconSize} /> : <CopyIcon size={iconSize} />}\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\nexport default CopyOverlayButton;\n"],"names":["CopyOverlayButton","text","ariaLabel","ariaLabelledBy","id","iconSize","className","style","outcome","copy","useClipboardCopy","copied","jsxs","Fragment","jsx","CheckmarkIcon","CopyIcon"],"mappings":";;;;AAgBA,MAAMA,IAAsD,CAAC;AAAA,EACzD,MAAAC;AAAA,EACA,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,IAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AACJ,MAAM;AACF,QAAM,EAAE,SAAAC,GAAS,MAAAC,MAASC,EAAiBT,CAAI,GACzCU,IAASH,MAAY;AAC3B,SACI,gBAAAI,EAAAC,GAAA,EACI,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,MAAK;AAAA,QACL,IAAAV;AAAA,QACA,cAAYF;AAAA,QACZ,mBAAiBC;AAAA,QACjB,SAAS,MAAM,KAAKM,EAAKR,CAAI;AAAA,QAC7B,WAAAK;AAAA,QACA,OAAAC;AAAA,QAEC,UAAAI,sBAAUI,GAAA,EAAc,MAAMV,GAAU,IAAK,gBAAAS,EAACE,GAAA,EAAS,MAAMX,EAAA,CAAU;AAAA,MAAA;AAAA,IAAA;AAAA,IAG5E,gBAAAS,EAAC,UAAK,aAAU,UAAS,WAAU,WAC9B,UAAAH,IAAS,wBAAwB,GAAA,CACtC;AAAA,EAAA,GACJ;AAER;"}