@redvars/peacock 3.15.0 → 3.17.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.
Files changed (157) hide show
  1. package/dist/assets/styles.css +1 -1
  2. package/dist/assets/styles.css.map +1 -1
  3. package/dist/assets/theme.js +19 -19
  4. package/dist/assets/tokens.css +1 -1
  5. package/dist/assets/tokens.css.map +1 -1
  6. package/dist/card-content.js +8 -7
  7. package/dist/card-content.js.map +1 -1
  8. package/dist/card.js +142 -98
  9. package/dist/card.js.map +1 -1
  10. package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
  11. package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
  12. package/dist/chart-area.js +78 -0
  13. package/dist/chart-area.js.map +1 -0
  14. package/dist/chart-bar.js +283 -213
  15. package/dist/chart-bar.js.map +1 -1
  16. package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
  17. package/dist/chart-base-C2qRMF48.js.map +1 -0
  18. package/dist/chart-doughnut.js +55 -287
  19. package/dist/chart-doughnut.js.map +1 -1
  20. package/dist/chart-line.js +626 -0
  21. package/dist/chart-line.js.map +1 -0
  22. package/dist/chart-pie.js +637 -195
  23. package/dist/chart-pie.js.map +1 -1
  24. package/dist/code-editor.js +704 -131
  25. package/dist/code-editor.js.map +1 -1
  26. package/dist/code-group.js +188 -0
  27. package/dist/code-group.js.map +1 -0
  28. package/dist/code-highlighter.js +895 -257
  29. package/dist/code-highlighter.js.map +1 -1
  30. package/dist/custom-elements-jsdocs.json +2278 -677
  31. package/dist/custom-elements.json +13962 -3690
  32. package/dist/image.js +5 -1
  33. package/dist/image.js.map +1 -1
  34. package/dist/index.js +8 -7
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader-full.js +1 -1
  37. package/dist/loader.js +9 -3
  38. package/dist/loader.js.map +1 -1
  39. package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
  40. package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
  41. package/dist/pagination.js +408 -110
  42. package/dist/pagination.js.map +1 -1
  43. package/dist/path-CJ0Arqcy.js +166 -0
  44. package/dist/path-CJ0Arqcy.js.map +1 -0
  45. package/dist/snackbar.js +89 -34
  46. package/dist/snackbar.js.map +1 -1
  47. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  48. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  49. package/dist/src/__internal/chart/paths.d.ts +5 -0
  50. package/dist/src/__internal/chart/types.d.ts +42 -0
  51. package/dist/src/card/card-content.d.ts +2 -3
  52. package/dist/src/card/card.d.ts +31 -17
  53. package/dist/src/chart-area/chart-area.d.ts +54 -0
  54. package/dist/src/chart-area/index.d.ts +1 -0
  55. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  56. package/dist/src/chart-bar/index.d.ts +0 -1
  57. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  58. package/dist/src/chart-line/chart-line.d.ts +69 -0
  59. package/dist/src/chart-line/index.d.ts +1 -0
  60. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  61. package/dist/src/code-editor/code-editor.d.ts +52 -13
  62. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  63. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  64. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  65. package/dist/src/code-highlighter/index.d.ts +1 -0
  66. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  67. package/dist/src/code-highlighter/local.d.ts +4 -1
  68. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  69. package/dist/src/index.d.ts +4 -2
  70. package/dist/src/pagination/page-items.d.ts +14 -0
  71. package/dist/src/pagination/pagination.d.ts +46 -7
  72. package/dist/src/snackbar/snackbar.d.ts +13 -1
  73. package/dist/src/table/table.d.ts +125 -27
  74. package/dist/src/toolbar/toolbar.d.ts +56 -51
  75. package/dist/table.js +1007 -338
  76. package/dist/table.js.map +1 -1
  77. package/dist/test/chart.test.d.ts +1 -0
  78. package/dist/test/code-highlighter.test.d.ts +1 -0
  79. package/dist/test/pagination.test.d.ts +1 -0
  80. package/dist/test/table.test.d.ts +1 -0
  81. package/dist/token-colors-0TFHWbcq.js +81 -0
  82. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  83. package/dist/toolbar.js +195 -184
  84. package/dist/toolbar.js.map +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +1 -2
  87. package/readme.md +7 -6
  88. package/scss/_code-block.scss +139 -0
  89. package/scss/tokens.css +24 -0
  90. package/src/__internal/chart/cartesian-chart.ts +404 -0
  91. package/src/__internal/chart/chart-base.scss +252 -0
  92. package/src/__internal/chart/chart-base.ts +474 -0
  93. package/src/__internal/chart/paths.ts +28 -0
  94. package/src/__internal/chart/types.ts +49 -0
  95. package/src/card/card-content.ts +12 -9
  96. package/src/card/card.scss +66 -54
  97. package/src/card/card.ts +109 -73
  98. package/src/chart-area/chart-area.ts +82 -0
  99. package/src/chart-area/index.ts +1 -0
  100. package/src/chart-bar/chart-bar.ts +336 -250
  101. package/src/chart-bar/index.ts +0 -1
  102. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  103. package/src/chart-doughnut/demo/index.html +14 -22
  104. package/src/chart-line/chart-line.scss +25 -0
  105. package/src/chart-line/chart-line.ts +346 -0
  106. package/src/chart-line/index.ts +1 -0
  107. package/src/chart-pie/chart-pie.scss +35 -16
  108. package/src/chart-pie/chart-pie.ts +282 -188
  109. package/src/chart-pie/demo/index.html +13 -21
  110. package/src/code-editor/code-editor.scss +132 -36
  111. package/src/code-editor/code-editor.ts +308 -88
  112. package/src/code-editor/demo/index.html +39 -12
  113. package/src/code-editor/editor-theme.ts +213 -0
  114. package/src/code-highlighter/code-group.scss +34 -0
  115. package/src/code-highlighter/code-group.ts +173 -0
  116. package/src/code-highlighter/code-highlighter.scss +226 -111
  117. package/src/code-highlighter/code-highlighter.ts +554 -199
  118. package/src/code-highlighter/demo/index.html +68 -4
  119. package/src/code-highlighter/index.ts +1 -0
  120. package/src/code-highlighter/line-ranges.ts +81 -0
  121. package/src/code-highlighter/local.ts +9 -3
  122. package/src/code-highlighter/token-colors.ts +42 -0
  123. package/src/index.ts +4 -2
  124. package/src/loader.ts +8 -2
  125. package/src/pagination/page-items.ts +50 -0
  126. package/src/pagination/pagination.scss +159 -44
  127. package/src/pagination/pagination.ts +275 -74
  128. package/src/snackbar/demo/index.html +39 -4
  129. package/src/snackbar/snackbar.scss +27 -10
  130. package/src/snackbar/snackbar.ts +80 -37
  131. package/src/table/table.scss +337 -109
  132. package/src/table/table.ts +812 -272
  133. package/src/toolbar/toolbar-colors.scss +6 -7
  134. package/src/toolbar/toolbar.scss +35 -106
  135. package/src/toolbar/toolbar.ts +180 -80
  136. package/dist/array-D5vjT2Xm.js +0 -14
  137. package/dist/array-D5vjT2Xm.js.map +0 -1
  138. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  139. package/dist/chart-stacked-bar.js +0 -403
  140. package/dist/chart-stacked-bar.js.map +0 -1
  141. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  142. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  143. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  144. package/dist/pie-Dz0IDiPt.js +0 -537
  145. package/dist/pie-Dz0IDiPt.js.map +0 -1
  146. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  147. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  148. package/dist/pierre-light-BEkAPImt.js +0 -4
  149. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  150. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  151. package/dist/src/code-highlighter/constants.d.ts +0 -1
  152. package/dist/transform-DSwFSqzD.js.map +0 -1
  153. package/src/chart-bar/chart-bar.scss +0 -58
  154. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  155. package/src/chart-doughnut/chart-donut.scss +0 -37
  156. package/src/code-highlighter/constants.ts +0 -117
  157. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
@@ -1,12 +1,100 @@
1
- import { i, _ as __decorate, I as IndividualComponent, a as i$1, b } from './IndividualComponent-Bdwyrvd6.js';
1
+ import { i, _ as __decorate, I as IndividualComponent, a as i$1, b, A } from './IndividualComponent-Bdwyrvd6.js';
2
2
  import { n } from './property-B49QQ8pS.js';
3
3
  import { r } from './state-DkTK9EGF.js';
4
- import { o } from './unsafe-html-Ct0N2_UU.js';
5
- import { e } from './class-map-DG7CA1et.js';
6
- import { c as copyToClipboard } from './copy-to-clipboard-upGx-Ueo.js';
4
+ import { e } from './query-CHb9Ft_d.js';
5
+ import { e as e$1 } from './class-map-DG7CA1et.js';
6
+ import { o } from './style-map-BQD5Et1D.js';
7
+ import { c as copyToClipboard, T as TOKEN_DEFAULTS } from './token-colors-0TFHWbcq.js';
8
+ import './base-Cl6v8-BZ.js';
7
9
  import './directive-ZPhl09Yt.js';
8
10
 
9
- var css_248z = i`* {
11
+ const locale = {
12
+ copyToClipboard: 'Copy to clipboard',
13
+ copied: 'Copied',
14
+ copiedCode: 'Copied code to clipboard',
15
+ wrapLines: 'Wrap lines',
16
+ unwrapLines: 'Turn off line wrap',
17
+ showMore: 'Show more',
18
+ showLess: 'Show less',
19
+ };
20
+
21
+ /**
22
+ * Parses a line range list such as `"1, 3-5"` into 1-based line numbers.
23
+ * Blank or malformed parts are skipped; a reversed range such as `"5-3"` is read as `3-5`.
24
+ */
25
+ function parseLineRanges(value) {
26
+ const lines = new Set();
27
+ if (!value)
28
+ return lines;
29
+ for (const part of value.split(',')) {
30
+ const match = part.trim().match(/^(\d+)(?:\s*-\s*(\d+))?$/);
31
+ if (match) {
32
+ const start = Number(match[1]);
33
+ const end = match[2] === undefined ? start : Number(match[2]);
34
+ const from = Math.max(1, Math.min(start, end));
35
+ const to = Math.max(start, end);
36
+ for (let line = from; line <= to; line += 1)
37
+ lines.add(line);
38
+ }
39
+ }
40
+ return lines;
41
+ }
42
+ /**
43
+ * Maps 1-based line numbers to their variant. Where ranges overlap,
44
+ * `removed` wins over `added`, and `added` wins over `highlighted`.
45
+ */
46
+ function buildLineVariants(ranges) {
47
+ const variants = new Map();
48
+ const order = ['highlighted', 'added', 'removed'];
49
+ for (const variant of order) {
50
+ for (const line of parseLineRanges(ranges[variant])) {
51
+ variants.set(line, variant);
52
+ }
53
+ }
54
+ return variants;
55
+ }
56
+ /**
57
+ * Removes leading and trailing blank lines and the indentation common to
58
+ * every non-blank line, so indented markup reads as written.
59
+ */
60
+ function dedent(source) {
61
+ const lines = source.replace(/\r\n?/g, '\n').split('\n');
62
+ while (lines.length && lines[0].trim() === '')
63
+ lines.shift();
64
+ while (lines.length && lines[lines.length - 1].trim() === '')
65
+ lines.pop();
66
+ let indent = Infinity;
67
+ for (const line of lines) {
68
+ if (line.trim() !== '') {
69
+ const leading = line.match(/^[ \t]*/)?.[0].length ?? 0;
70
+ indent = Math.min(indent, leading);
71
+ }
72
+ }
73
+ if (!Number.isFinite(indent) || indent === 0)
74
+ return lines.join('\n');
75
+ return lines.map(line => line.slice(indent)).join('\n');
76
+ }
77
+ /** Decodes the entities `innerHTML` produces for text, ending with `&amp;`. */
78
+ function decodeEntities(source) {
79
+ return source
80
+ .replace(/&lt;/g, '<')
81
+ .replace(/&gt;/g, '>')
82
+ .replace(/&quot;/g, '"')
83
+ .replace(/&#39;/g, "'")
84
+ .replace(/&nbsp;/g, ' ')
85
+ .replace(/&amp;/g, '&');
86
+ }
87
+ /** Splits code into display lines, ignoring one trailing newline. */
88
+ function splitLines(code) {
89
+ const normalized = code.replace(/\r\n?/g, '\n');
90
+ const trimmed = normalized.endsWith('\n')
91
+ ? normalized.slice(0, -1)
92
+ : normalized;
93
+ return trimmed.split('\n');
94
+ }
95
+
96
+ var css_248z = i`@charset "UTF-8";
97
+ * {
10
98
  box-sizing: border-box;
11
99
  -webkit-tap-highlight-color: transparent;
12
100
  }
@@ -19,373 +107,923 @@ var css_248z = i`* {
19
107
  display: none !important;
20
108
  }
21
109
 
22
- :host {
23
- display: block;
110
+ .code-block {
111
+ --_pad-block: var(--spacing-200);
112
+ --_pad-inline: var(--spacing-200);
113
+ --_pad-near: var(--spacing-100);
114
+ --_background: var(
115
+ --code-highlighter-background,
116
+ var(--color-surface-container-low)
117
+ );
118
+ --_border-color: var(--code-highlighter-border-color, var(--color-outline-variant));
119
+ --_foreground: var(--code-highlighter-foreground, var(--color-on-surface));
120
+ position: relative;
121
+ display: flex;
122
+ flex-direction: column;
24
123
  height: 100%;
25
- --code-highlighter-background: var(--color-surface-container);
124
+ min-width: 0;
125
+ overflow: hidden;
126
+ background: var(--_background);
127
+ color: var(--_foreground);
128
+ border: 1px solid var(--_border-color);
129
+ border-radius: var(--code-highlighter-shape, var(--shape-corner-medium));
26
130
  }
27
131
 
28
- .code-loader {
29
- height: 10rem;
30
- background-color: var(--code-highlighter-background);
31
- color: var(--color-on-surface);
132
+ .header {
32
133
  display: flex;
33
134
  align-items: center;
34
- justify-content: center;
35
- gap: var(--spacing-050);
135
+ gap: var(--spacing-100);
136
+ min-width: 0;
137
+ padding: var(--_pad-block) var(--_pad-inline) 0;
138
+ color: var(--color-on-surface-variant);
36
139
  }
37
140
 
38
- .code-highlighter {
39
- height: 100%;
40
- display: flex;
41
- flex-direction: column;
141
+ ::slotted([slot=icon]) {
142
+ --icon-size: 1.125rem;
143
+ flex: none;
144
+ color: var(--color-on-surface-variant);
145
+ }
146
+
147
+ .title {
148
+ flex: 1 1 auto;
149
+ min-width: 0;
150
+ overflow: hidden;
151
+ text-overflow: ellipsis;
152
+ white-space: nowrap;
42
153
  color: var(--color-on-surface);
154
+ font-family: var(--typography-title-small-font-family) !important;
155
+ font-size: var(--typography-title-small-font-size) !important;
156
+ font-weight: var(--typography-title-small-font-weight) !important;
157
+ line-height: var(--typography-title-small-line-height) !important;
158
+ letter-spacing: var(--typography-title-small-letter-spacing) !important;
43
159
  }
44
- .code-highlighter .header {
45
- padding: var(--spacing-100);
46
- padding-inline-start: var(--spacing-200);
160
+
161
+ .actions {
47
162
  display: flex;
163
+ flex: none;
48
164
  align-items: center;
49
- justify-content: space-between;
50
- background-color: var(--code-highlighter-background);
51
- border-bottom: 1px solid var(--color-outline-variant);
52
- font-family: var(--typography-body-medium-font-family) !important;
53
- font-size: var(--typography-body-medium-font-size) !important;
54
- font-weight: var(--typography-body-medium-font-weight) !important;
55
- line-height: var(--typography-body-medium-line-height) !important;
56
- letter-spacing: var(--typography-body-medium-letter-spacing) !important;
57
- }
58
- .code-highlighter .header .copy-button {
59
- --button-container-shape: var(--shape-corner-full);
60
- }
61
- .code-highlighter .scroll-wrapper {
62
- flex: 1;
63
- overflow-y: auto;
64
- background-color: var(--code-highlighter-background);
65
- }
66
- .code-highlighter .scroll-wrapper .highlighter {
67
- margin: 0;
68
- position: relative;
165
+ gap: var(--spacing-025);
166
+ margin-inline-start: auto;
69
167
  }
70
- .code-highlighter .scroll-wrapper .highlighter .shiki {
71
- margin: 0;
72
- padding: var(--spacing-200);
73
- width: fit-content;
74
- background: transparent !important;
75
- font-family: var(--font-family-monospace);
76
- --shiki-dark-bg: transparent !important;
168
+
169
+ .header .actions {
170
+ margin-block: calc(-1 * var(--spacing-100));
171
+ margin-inline-end: calc(-1 * var(--spacing-100));
172
+ }
173
+
174
+ .actions.floating {
175
+ position: absolute;
176
+ z-index: 1;
177
+ inset-block-start: var(--spacing-100);
178
+ inset-inline-end: var(--spacing-100);
179
+ padding: var(--spacing-025);
180
+ background: var(--color-surface);
181
+ border: 1px solid var(--color-outline-variant);
182
+ border-radius: var(--shape-corner-full);
183
+ opacity: 0;
184
+ transition: opacity var(--duration-short4) var(--easing-standard);
185
+ }
186
+
187
+ .code-block:hover .actions.floating,
188
+ .code-block:focus-within .actions.floating {
189
+ opacity: 1;
190
+ }
191
+
192
+ @media (pointer: coarse) {
193
+ .actions.floating {
194
+ opacity: 1;
195
+ }
196
+ }
197
+ @media (prefers-reduced-motion: reduce) {
198
+ .actions.floating {
199
+ transition: none;
200
+ }
201
+ }
202
+ .sr-only {
203
+ position: absolute;
204
+ width: 1px;
205
+ height: 1px;
206
+ padding: 0;
207
+ margin: -1px;
208
+ overflow: hidden;
209
+ clip-path: inset(50%);
210
+ white-space: nowrap;
211
+ border: 0;
212
+ }
213
+
214
+ :host([size=sm]) .code-block {
215
+ --_pad-block: var(--spacing-150);
216
+ --_pad-inline: var(--spacing-150);
217
+ --_pad-near: var(--spacing-075);
218
+ border-radius: var(--code-highlighter-shape, var(--shape-corner-small));
219
+ }
220
+ :host([size=sm]) .title {
221
+ font-family: var(--typography-label-medium-font-family) !important;
222
+ font-size: var(--typography-label-medium-font-size) !important;
223
+ font-weight: var(--typography-label-medium-font-weight) !important;
224
+ line-height: var(--typography-label-medium-line-height) !important;
225
+ letter-spacing: var(--typography-label-medium-letter-spacing) !important;
226
+ }
227
+
228
+ :host {
229
+ display: block;
230
+ min-width: 0;
231
+ }
232
+
233
+ :host([hidden]) {
234
+ display: none;
235
+ }
236
+
237
+ .code-block:has(.content:focus-visible) {
238
+ outline: 3px solid var(--color-primary);
239
+ outline-offset: 2px;
77
240
  }
78
- .code-highlighter .scroll-wrapper .highlighter .shiki code {
241
+
242
+ .content {
243
+ flex: 1 1 auto;
244
+ min-height: 0;
245
+ max-height: var(--code-highlighter-max-height, none);
246
+ margin: 0;
247
+ padding-block: var(--_pad-block);
248
+ padding-inline: 0;
249
+ overflow: auto;
250
+ outline: none;
251
+ white-space: pre;
252
+ text-align: start;
253
+ scrollbar-width: thin;
254
+ scrollbar-color: var(--color-outline-variant) transparent;
79
255
  font-family: var(--typography-code-medium-font-family) !important;
80
256
  font-size: var(--typography-code-medium-font-size) !important;
81
257
  font-weight: var(--typography-code-medium-font-weight) !important;
82
258
  line-height: var(--typography-code-medium-line-height) !important;
83
259
  letter-spacing: var(--typography-code-medium-letter-spacing) !important;
84
260
  }
85
- .code-highlighter.line-numbers .highlighter .shiki {
86
- /* Reset counter for line numbers */
87
- counter-reset: line-counter;
261
+
262
+ .has-header .content {
263
+ padding-block-start: var(--_pad-near);
264
+ }
265
+
266
+ .has-footer .content {
267
+ padding-block-end: var(--_pad-near);
88
268
  }
89
- .code-highlighter.line-numbers .line {
269
+
270
+ .code {
271
+ display: grid;
272
+ grid-template-columns: minmax(0, 1fr);
273
+ align-content: start;
274
+ min-width: max-content;
275
+ min-height: 1lh;
276
+ font: inherit;
277
+ }
278
+
279
+ .line {
90
280
  position: relative;
91
- padding-left: 2rem; /* Space for numbers */
281
+ display: block;
282
+ min-height: 1lh;
283
+ padding-inline: var(--_pad-inline);
284
+ }
285
+
286
+ .line-numbers .code {
287
+ grid-template-columns: auto minmax(0, 1fr);
288
+ column-gap: var(--spacing-200);
289
+ }
290
+ .line-numbers .line {
291
+ display: grid;
292
+ grid-column: 1/-1;
293
+ grid-template-columns: subgrid;
92
294
  }
93
- .code-highlighter.line-numbers .line::before {
94
- counter-increment: line-counter;
95
- content: counter(line-counter);
96
- /* Positioning */
295
+ .line-numbers .line::before {
296
+ min-width: 1.5rem;
297
+ color: var(--color-on-surface-variant);
298
+ text-align: end;
299
+ font-variant-numeric: tabular-nums;
300
+ counter-increment: line;
301
+ content: counter(line);
302
+ content: counter(line)/"";
303
+ user-select: none;
304
+ pointer-events: none;
305
+ }
306
+
307
+ .wrap .code {
308
+ min-width: 0;
309
+ }
310
+ .wrap .line-content {
311
+ white-space: pre-wrap;
312
+ overflow-wrap: anywhere;
313
+ }
314
+
315
+ .line[data-variant=highlighted] {
316
+ background: color-mix(in srgb, var(--color-primary) 12%, transparent);
317
+ }
318
+
319
+ .line[data-variant=added] {
320
+ background: color-mix(in srgb, var(--color-success) 12%, transparent);
321
+ }
322
+
323
+ .line[data-variant=removed] {
324
+ background: color-mix(in srgb, var(--color-error) 12%, transparent);
325
+ }
326
+
327
+ .line[data-variant=added]::after,
328
+ .line[data-variant=removed]::after {
97
329
  position: absolute;
98
- left: -1.5rem; /* Pull back into padding */
99
- width: 2.5rem; /* Fixed width for alignment */
100
- text-align: right;
101
- padding-right: 1rem;
102
- /* Visuals */
103
- color: var(--num-color);
104
- opacity: 0.6;
105
- font-variant-numeric: tabular-nums; /* Ensures numbers align vertically */
106
- user-select: none; /* Don't copy line numbers when selecting text */
330
+ inset-block-start: 0;
331
+ inset-inline-start: var(--spacing-050);
332
+ user-select: none;
107
333
  pointer-events: none;
108
334
  }
109
335
 
110
- :host-context([data-theme=dark]) .highlighter .shiki,
111
- :host-context([data-theme=dark]) .highlighter .shiki span {
112
- color: var(--shiki-dark) !important;
113
- background-color: var(--shiki-dark-bg) !important;
336
+ .line[data-variant=added]::after {
337
+ color: var(--color-success);
338
+ content: "+";
114
339
  }
115
340
 
116
- :host([inline]) {
117
- display: inline;
118
- height: initial;
341
+ .line[data-variant=removed]::after {
342
+ color: var(--color-error);
343
+ content: "−";
119
344
  }
120
- :host([inline]) .code-highlighter {
121
- display: inline;
122
- cursor: pointer;
345
+
346
+ .italic {
347
+ font-style: italic;
123
348
  }
124
- :host([inline]) .code-highlighter .scroll-wrapper {
125
- display: inline;
349
+
350
+ .bold {
351
+ font-weight: 700;
126
352
  }
127
- :host([inline]) .code-highlighter .scroll-wrapper .line-numbers-wrapper {
128
- padding: 0 var(--spacing-100);
129
- font-size: inherit;
130
- display: inline;
131
- word-wrap: break-word;
353
+
354
+ .underline {
355
+ text-decoration: underline;
132
356
  }
133
- :host([inline]) .code-highlighter .scroll-wrapper .line-numbers-wrapper .highlighter {
134
- display: inline;
357
+
358
+ .strikethrough {
359
+ text-decoration: line-through;
360
+ }
361
+
362
+ .collapsed .content {
363
+ max-height: var(--code-highlighter-collapsed-height, 16rem);
364
+ overflow-y: hidden;
365
+ }
366
+
367
+ .overflowing .content {
368
+ mask-image: linear-gradient(to bottom, black calc(100% - var(--spacing-600)), transparent);
369
+ }
370
+
371
+ .footer {
372
+ display: flex;
373
+ justify-content: center;
374
+ padding: 0 var(--_pad-inline) var(--spacing-100);
375
+ }
376
+
377
+ .expand-icon {
378
+ transition: transform var(--duration-short4) var(--easing-standard);
379
+ }
380
+ .expand-icon.flipped {
381
+ transform: rotate(180deg);
382
+ }
383
+
384
+ @media (prefers-reduced-motion: reduce) {
385
+ .expand-icon {
386
+ transition: none;
387
+ }
388
+ }
389
+ :host([size=sm]) .content {
390
+ font-family: var(--typography-code-small-font-family) !important;
391
+ font-size: var(--typography-code-small-font-size) !important;
392
+ font-weight: var(--typography-code-small-font-weight) !important;
393
+ line-height: var(--typography-code-small-line-height) !important;
394
+ letter-spacing: var(--typography-code-small-letter-spacing) !important;
395
+ }
396
+ :host([size=sm]) .line[data-variant=added]::after,
397
+ :host([size=sm]) .line[data-variant=removed]::after {
398
+ inset-inline-start: var(--spacing-025);
399
+ }
400
+
401
+ :host([variant=error]) .code-block {
402
+ --_background: var(
403
+ --code-highlighter-background,
404
+ color-mix(
405
+ in srgb,
406
+ var(--color-error-container) 40%,
407
+ var(--color-surface-container-low)
408
+ )
409
+ );
410
+ --_border-color: var(
411
+ --code-highlighter-border-color,
412
+ color-mix(in srgb, var(--color-error) 40%, transparent)
413
+ );
414
+ --_foreground: var(--code-highlighter-foreground, var(--color-error));
415
+ }
416
+ :host([variant=error]) .title,
417
+ :host([variant=error]) ::slotted([slot=icon]) {
418
+ color: var(--color-error);
419
+ }
420
+
421
+ :host([grouped]) .code-block {
422
+ border: 0;
423
+ border-radius: 0;
424
+ }
425
+ :host([grouped]) .code-block:has(.content:focus-visible) {
426
+ outline-offset: -3px;
135
427
  }
136
- :host([inline]) .code-loader {
137
- height: initial;
428
+
429
+ :host([inline]) {
138
430
  display: inline;
431
+ }
432
+
433
+ .inline {
434
+ padding: 0 var(--spacing-050);
435
+ font-family: var(--font-family-monospace);
436
+ font-size: 0.875em;
437
+ color: var(--code-highlighter-foreground, var(--color-on-surface));
438
+ background: var(--color-surface-container-high);
439
+ border-radius: var(--shape-corner-extra-small);
440
+ box-decoration-break: clone;
441
+ -webkit-box-decoration-break: clone;
139
442
  }`;
140
443
 
141
444
  var CodeHighlighter_1;
142
- // Module-level promises – Rollup splits each import() specifier into a separate chunk.
143
- // Caching here prevents parallel loads when multiple instances initialise at the same time.
144
- let _shiki = null;
145
- let _themes = null;
146
- let _prettier = null;
147
- let _pluginBabel = null;
148
- let _pluginHtml = null;
149
- let _pluginPostcss = null;
150
- let _pluginEstree = null;
151
- const loadShiki = () => (_shiki ??= import('./index-_g_oLekF.js'));
152
- const loadThemes = () => (_themes ??= Promise.all([
153
- import('./pierre-dark-DFWl0m-C.js'),
154
- import('./pierre-light-BEkAPImt.js'),
155
- ]));
156
- const loadPrettier = () => (_prettier ??= import('./standalone-Ccq0tWwA.js'));
157
- const loadPluginBabel = () => (_pluginBabel ??= import('./babel-DBsfpl3B.js'));
158
- const loadPluginHtml = () => (_pluginHtml ??= import('./html-D22sQuVy.js'));
159
- const loadPluginPostcss = () => (_pluginPostcss ??= import('./postcss-BhbitHaI.js'));
160
- const loadPluginEstree = () => (_pluginEstree ??= import('./estree-C2LDzX4U.js'));
161
- const locale = {
162
- loading: 'Loading code...',
163
- copyToClipboard: 'Copy to clipboard',
164
- copied: 'Copied'};
445
+ /** Runs a loader once and returns the same promise on every later call. */
446
+ function once(load) {
447
+ let promise = null;
448
+ return () => {
449
+ promise ??= load();
450
+ return promise;
451
+ };
452
+ }
453
+ // Module-level loaders – Rollup splits each import() specifier into a separate chunk.
454
+ // Caching prevents parallel loads when multiple instances initialise at the same time.
455
+ const loadShiki = once(() => import('./index-_g_oLekF.js'));
456
+ // Syntax colors are CSS variables that fall back to Peacock color roles; see token-colors.ts.
457
+ const loadTheme = once(async () => {
458
+ const { createCssVariablesTheme } = await loadShiki();
459
+ return createCssVariablesTheme({
460
+ name: 'peacock',
461
+ variablePrefix: '--code-highlighter-',
462
+ variableDefaults: TOKEN_DEFAULTS,
463
+ fontStyle: true,
464
+ });
465
+ });
466
+ const loadPrettier = once(() => import('./standalone-Ccq0tWwA.js'));
467
+ const loadPluginBabel = once(() => import('./babel-DBsfpl3B.js'));
468
+ const loadPluginHtml = once(() => import('./html-D22sQuVy.js'));
469
+ const loadPluginPostcss = once(() => import('./postcss-BhbitHaI.js'));
470
+ const loadPluginEstree = once(() => import('./estree-C2LDzX4U.js'));
471
+ /** Formats JavaScript, HTML and CSS with Prettier; other languages pass through. */
472
+ async function formatCode(code, language) {
473
+ switch (language) {
474
+ case 'javascript': {
475
+ const [prettier, pluginBabel, pluginEstree] = await Promise.all([
476
+ loadPrettier(),
477
+ loadPluginBabel(),
478
+ loadPluginEstree(),
479
+ ]);
480
+ return prettier.format(code, {
481
+ parser: 'babel',
482
+ plugins: [pluginBabel, pluginEstree],
483
+ bracketSameLine: true,
484
+ htmlWhitespaceSensitivity: 'ignore',
485
+ });
486
+ }
487
+ case 'html': {
488
+ const [prettier, pluginHtml] = await Promise.all([
489
+ loadPrettier(),
490
+ loadPluginHtml(),
491
+ ]);
492
+ return prettier.format(code, {
493
+ parser: 'html',
494
+ plugins: [pluginHtml],
495
+ bracketSameLine: true,
496
+ htmlWhitespaceSensitivity: 'ignore',
497
+ });
498
+ }
499
+ case 'css': {
500
+ const [prettier, pluginPostcss] = await Promise.all([
501
+ loadPrettier(),
502
+ loadPluginPostcss(),
503
+ ]);
504
+ return prettier.format(code, {
505
+ parser: 'css',
506
+ plugins: [pluginPostcss],
507
+ });
508
+ }
509
+ default:
510
+ return code;
511
+ }
512
+ }
513
+ /** Tokenizes code with the Peacock token theme. Throws for unknown languages. */
514
+ async function tokenize(code, language) {
515
+ const [{ codeToTokens }, theme] = await Promise.all([
516
+ loadShiki(),
517
+ loadTheme(),
518
+ ]);
519
+ const result = await codeToTokens(code, {
520
+ lang: language,
521
+ theme,
522
+ });
523
+ // Plain text inherits the block color, so variants can recolor it.
524
+ return result.tokens.map(line => line.map(token => token.color === result.fg ? { ...token, color: undefined } : token));
525
+ }
526
+ // Shiki font style bit flags.
527
+ const FONT_ITALIC = 1;
528
+ const FONT_BOLD = 2;
529
+ const FONT_UNDERLINE = 4;
530
+ const FONT_STRIKETHROUGH = 8;
531
+ /** Whether a Shiki font style value has the given flag. `-1` means not set. */
532
+ const hasFontFlag = (fontStyle, flag) => fontStyle > 0 && Math.floor(fontStyle / flag) % 2 === 1;
165
533
  /**
166
534
  * @label Code Highlighter
167
535
  * @tag wc-code-highlighter
168
536
  * @rawTag code-highlighter
169
537
  *
170
- * @summary A component that provides syntax highlighting for code snippets.
538
+ * @summary Displays a block of code with syntax highlighting, line numbers, line highlights, diffs and a copy button.
171
539
  *
172
540
  * @example
173
541
  * ```html
174
- * <wc-code-highlighter language="javascript" style="height: 9rem"><pre><code>
542
+ * <wc-code-highlighter language="javascript" label="hello.js" line-numbers highlight-lines="2"><pre><code>
175
543
  * function helloWorld() {
176
544
  * console.log('Hello, world!');
177
545
  * }</code></pre>
178
546
  * </wc-code-highlighter>
179
547
  * ```
548
+ *
549
+ * @slot title - Header title content. Overrides `label` and shows the header.
550
+ * @slot icon - Icon shown before the title in the header.
551
+ * @slot actions - Extra action buttons, shown in the header or floating at the top end.
552
+ *
553
+ * @csspart container - The outer block.
554
+ * @csspart header - The header row.
555
+ * @csspart title - The header title.
556
+ * @csspart actions - The action buttons group.
557
+ * @csspart content - The scrollable code area (`pre`).
558
+ * @csspart line - Each code line.
559
+ * @csspart footer - The footer holding the show more button.
560
+ *
561
+ * @cssprop --code-highlighter-background - Block background. Defaults to `--color-surface-container-low`.
562
+ * @cssprop --code-highlighter-border-color - Block border color. Defaults to `--color-outline-variant`.
563
+ * @cssprop --code-highlighter-shape - Block corner radius. Defaults to `--shape-corner-medium`.
564
+ * @cssprop --code-highlighter-max-height - Caps the code area height; it scrolls beyond. Defaults to `none`.
565
+ * @cssprop --code-highlighter-collapsed-height - Height of a collapsed `collapsible` block. Defaults to `16rem`.
566
+ * @cssprop --code-highlighter-foreground - Plain code color. Defaults to `--color-on-surface`.
567
+ * @cssprop --code-highlighter-token-keyword - Keyword color. Defaults to `--color-purple`.
568
+ * @cssprop --code-highlighter-token-string - String color. Defaults to `--color-green`.
569
+ * @cssprop --code-highlighter-token-function - Function color. Defaults to `--color-blue`.
570
+ * @cssprop --code-highlighter-token-constant - Constant and number color. Defaults to `--color-orange`.
571
+ * @cssprop --code-highlighter-token-comment - Comment color. Defaults to `--color-on-surface-variant`.
572
+ * @cssprop --code-highlighter-token-punctuation - Punctuation color. Defaults to `--color-on-surface-variant`.
573
+ *
574
+ * @fires {CustomEvent<{value: string}>} copied - Dispatched after the copy button copies the code.
575
+ * @fires {CustomEvent<{expanded: boolean}>} expanded-change - Dispatched when a collapsible block is expanded or collapsed.
576
+ *
180
577
  * @tags display
181
578
  */
182
579
  let CodeHighlighter = CodeHighlighter_1 = class CodeHighlighter extends i$1 {
183
580
  constructor() {
581
+ // ── Static ────────────────────────────────────────────────────────────────
184
582
  super(...arguments);
583
+ // ── Properties ────────────────────────────────────────────────────────────
584
+ /** Language of the code. Unknown languages render as plain text. */
185
585
  this.language = 'javascript';
186
- this.lineNumbers = false;
586
+ /** Code to display. When empty, the code is read from a light-DOM `<pre><code>`. */
187
587
  this.value = '';
588
+ /**
589
+ * Formats JavaScript, HTML and CSS with Prettier before display.
590
+ * Set `format="false"` to show the code as written.
591
+ */
188
592
  this.format = true;
593
+ /** Header title, such as a file path. Shows the header. */
594
+ this.label = '';
595
+ /** Shows line numbers. */
596
+ this.lineNumbers = false;
597
+ /** Number of the first line when line numbers are shown. */
598
+ this.startLine = 1;
599
+ /** Wraps long lines instead of scrolling horizontally. */
600
+ this.wrap = false;
601
+ /** Shows a button that turns line wrapping on and off. */
602
+ this.wrapToggle = false;
603
+ /** Lines to highlight, such as `"1, 3-5"`. Counts displayed lines, after formatting. */
604
+ this.highlightLines = '';
605
+ /** Lines shown as added in a diff, such as `"4-6"`. */
606
+ this.addedLines = '';
607
+ /** Lines shown as removed in a diff, such as `"3"`. */
608
+ this.removedLines = '';
609
+ /** Caps the height and adds a show more button when the code is taller. */
610
+ this.collapsible = false;
611
+ /** Whether a collapsible block is expanded. */
612
+ this.expanded = false;
613
+ /** Size of the block. `sm` suits tool output and dense layouts. */
614
+ this.size = 'md';
615
+ /** Visual variant. `error` tints the block for failure output. */
616
+ this.variant = 'default';
617
+ /** Hides the copy button. */
189
618
  this.hideCopy = false;
190
- this.compiledCode = null;
619
+ /** Renders the code inline, as a compact chip within text. */
620
+ this.inline = false;
621
+ /**
622
+ * Set by `wc-code-group`. The group draws the frame and shows the label as a
623
+ * tab, so the block drops its border and header.
624
+ */
625
+ this.grouped = false;
626
+ /** The code as displayed, after formatting, without a trailing newline. */
627
+ this._code = '';
628
+ /** Tokens per line, or `null` until highlighting finishes. */
629
+ this._tokens = null;
630
+ /** Whether the copy button shows its copied feedback. */
191
631
  this._copied = false;
192
- this.parsedCode = null;
193
- this._copyFeedbackTimeout = null;
632
+ /** Whether the collapsed code is taller than the collapsed height. */
633
+ this._overflowing = false;
634
+ // ── Private fields ────────────────────────────────────────────────────────
635
+ /** Source read from `value` or the light DOM, before formatting. */
636
+ this.__source = '';
637
+ /** Line variants keyed by 1-based line number. */
638
+ this.__lineVariants = new Map();
639
+ /** Increments per highlight run so stale async results are dropped. */
640
+ this.__run = 0;
641
+ /** Timer that resets the copy feedback. */
642
+ this.__copyFeedbackTimeout = null;
194
643
  }
195
- async connectedCallback() {
196
- // eslint-disable-next-line wc/guard-super-call
644
+ // ── Lifecycle ─────────────────────────────────────────────────────────────
645
+ connectedCallback() {
197
646
  super.connectedCallback();
647
+ this.__childObserver = new MutationObserver(() => this.requestUpdate());
648
+ this.__childObserver.observe(this, {
649
+ childList: true,
650
+ attributes: true,
651
+ attributeFilter: ['slot'],
652
+ subtree: true,
653
+ });
198
654
  }
199
655
  disconnectedCallback() {
200
- if (this._copyFeedbackTimeout !== null) {
201
- window.clearTimeout(this._copyFeedbackTimeout);
202
- this._copyFeedbackTimeout = null;
656
+ if (this.__copyFeedbackTimeout !== null) {
657
+ window.clearTimeout(this.__copyFeedbackTimeout);
658
+ this.__copyFeedbackTimeout = null;
203
659
  }
660
+ this.__childObserver?.disconnect();
661
+ this.__resizeObserver?.disconnect();
662
+ this.__observedContent = undefined;
204
663
  super.disconnectedCallback();
205
664
  }
206
- firstUpdated() {
207
- this.__highlightCode();
208
- }
209
- // eslint-disable-next-line class-methods-use-this
210
- decode(str) {
211
- return str.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
665
+ willUpdate(changed) {
666
+ if (!this.hasUpdated ||
667
+ changed.has('value') ||
668
+ changed.has('language') ||
669
+ changed.has('format') ||
670
+ changed.has('inline')) {
671
+ this.__source = this.__readSource();
672
+ this._code = splitLines(this.__source).join('\n');
673
+ this._tokens = null;
674
+ this.__highlight();
675
+ }
676
+ if (!this.hasUpdated ||
677
+ changed.has('highlightLines') ||
678
+ changed.has('addedLines') ||
679
+ changed.has('removedLines')) {
680
+ this.__lineVariants = buildLineVariants({
681
+ highlighted: this.highlightLines,
682
+ added: this.addedLines,
683
+ removed: this.removedLines,
684
+ });
685
+ }
212
686
  }
213
- async __highlightCode() {
214
- let codeString = '';
215
- if (this.value) {
216
- codeString = this.value;
687
+ updated() {
688
+ // The resize observer measures overflow after layout, including when
689
+ // collapsing or expanding changes the code area's height.
690
+ if (this.__content !== this.__observedContent) {
691
+ this.__observeContent();
217
692
  }
218
- else {
219
- // Accessing light DOM children
220
- const codeTag = this.querySelector('code');
221
- if (codeTag) {
222
- codeString = codeTag.innerHTML;
693
+ }
694
+ // ── Private methods ───────────────────────────────────────────────────────
695
+ /** Reads the source from `value`, or from the light DOM. */
696
+ __readSource() {
697
+ if (this.value)
698
+ return this.value;
699
+ const codeTag = this.querySelector('code');
700
+ if (codeTag)
701
+ return dedent(decodeEntities(codeTag.innerHTML));
702
+ const text = Array.from(this.childNodes)
703
+ .filter(node => node.nodeType === Node.TEXT_NODE)
704
+ .map(node => node.textContent ?? '')
705
+ .join('');
706
+ return dedent(text);
707
+ }
708
+ /** Formats then tokenizes the source; plain lines stay until both finish. */
709
+ async __highlight() {
710
+ this.__run += 1;
711
+ const run = this.__run;
712
+ const { language } = this;
713
+ let code = this.__source;
714
+ if (this.format && !this.inline) {
715
+ try {
716
+ code = await formatCode(code, language);
223
717
  }
224
- else if (this.childNodes.length > 0) {
225
- codeString = this.innerText;
718
+ catch {
719
+ // Invalid code cannot be formatted; show it as written.
226
720
  }
721
+ if (run !== this.__run)
722
+ return;
723
+ this._code = splitLines(code).join('\n');
227
724
  }
228
- codeString = this.decode(codeString);
229
- if (this.format !== false) {
230
- // eslint-disable-next-line default-case
231
- switch (this.language) {
232
- case 'javascript': {
233
- const [prettier, pluginBabel, pluginEstree] = await Promise.all([
234
- loadPrettier(),
235
- loadPluginBabel(),
236
- loadPluginEstree(),
237
- ]);
238
- codeString = await prettier.format(codeString, {
239
- parser: 'babel',
240
- plugins: [pluginBabel, pluginEstree],
241
- bracketSameLine: true,
242
- htmlWhitespaceSensitivity: 'ignore',
243
- });
244
- break;
245
- }
246
- case 'html': {
247
- const [prettier, pluginHtml] = await Promise.all([
248
- loadPrettier(),
249
- loadPluginHtml(),
250
- ]);
251
- codeString = await prettier.format(codeString, {
252
- parser: 'html',
253
- plugins: [pluginHtml],
254
- bracketSameLine: true,
255
- htmlWhitespaceSensitivity: 'ignore',
256
- });
257
- break;
258
- }
259
- case 'css': {
260
- const [prettier, pluginPostcss] = await Promise.all([
261
- loadPrettier(),
262
- loadPluginPostcss(),
263
- ]);
264
- codeString = await prettier.format(codeString, {
265
- parser: 'css',
266
- plugins: [pluginPostcss],
267
- });
268
- break;
269
- }
270
- }
725
+ try {
726
+ const tokens = await tokenize(this._code, language);
727
+ if (run === this.__run)
728
+ this._tokens = tokens;
271
729
  }
272
- this.parsedCode = codeString;
273
- const transformers = [];
274
- // If line numbers are enabled, we inject a transformer
275
- // that adds the 'line' class to every line node.
276
- if (this.lineNumbers) {
277
- transformers.push({
278
- name: 'add-line-class',
279
- line(node) {
280
- // Shiki v1 helper to add classes to the AST
281
- this.addClassToHast(node, 'line');
282
- },
283
- });
730
+ catch {
731
+ // Unknown language: keep the plain lines.
284
732
  }
285
- const [{ codeToHtml }, [{ default: pierreDark }, { default: pierreLight }],] = await Promise.all([loadShiki(), loadThemes()]);
286
- this.compiledCode = await codeToHtml(codeString, {
287
- lang: this.language,
288
- themes: {
289
- // @ts-ignore
290
- light: pierreLight,
291
- // @ts-ignore
292
- dark: pierreDark,
293
- },
294
- transformers,
295
- });
296
733
  }
297
- updated(changed) {
298
- // Only re-highlight when the source content or rendering options change,
299
- // not on unrelated state updates like the copy-button feedback toggle.
300
- if (changed.has('value') ||
301
- changed.has('language') ||
302
- changed.has('lineNumbers') ||
303
- changed.has('format')) {
304
- this.__highlightCode();
305
- }
734
+ /** Watches the code area so the show more button appears only when needed. */
735
+ __observeContent() {
736
+ this.__resizeObserver?.disconnect();
737
+ this.__observedContent = this.__content;
738
+ if (!this.__content || typeof ResizeObserver === 'undefined')
739
+ return;
740
+ this.__resizeObserver ??= new ResizeObserver(() => this.__measure());
741
+ this.__resizeObserver.observe(this.__content);
742
+ if (this.__codeElement)
743
+ this.__resizeObserver.observe(this.__codeElement);
306
744
  }
307
- async __handleCopyClick() {
308
- if (this.parsedCode == null) {
745
+ /** Checks whether the collapsed code is taller than its cap. */
746
+ __measure() {
747
+ const content = this.__content;
748
+ if (!content || !this.collapsible) {
749
+ this._overflowing = false;
309
750
  return;
310
751
  }
311
- await copyToClipboard(this.parsedCode);
752
+ if (this.expanded)
753
+ return;
754
+ this._overflowing = content.scrollHeight > content.clientHeight + 1;
755
+ }
756
+ /** Whether light-DOM children are assigned to the named slot. */
757
+ __hasSlotted(name) {
758
+ return Array.from(this.children).some(child => child.getAttribute('slot') === name);
759
+ }
760
+ async __handleCopyClick() {
761
+ const value = this.copyValue ?? this._code;
762
+ await copyToClipboard(value);
312
763
  this._copied = true;
313
- if (this._copyFeedbackTimeout !== null) {
314
- window.clearTimeout(this._copyFeedbackTimeout);
764
+ this.dispatchEvent(new CustomEvent('copied', {
765
+ detail: { value },
766
+ bubbles: true,
767
+ composed: true,
768
+ }));
769
+ if (this.__copyFeedbackTimeout !== null) {
770
+ window.clearTimeout(this.__copyFeedbackTimeout);
315
771
  }
316
- this._copyFeedbackTimeout = window.setTimeout(() => {
772
+ this.__copyFeedbackTimeout = window.setTimeout(() => {
317
773
  this._copied = false;
318
- this._copyFeedbackTimeout = null;
774
+ this.__copyFeedbackTimeout = null;
319
775
  }, CodeHighlighter_1.COPY_FEEDBACK_DURATION);
320
776
  }
321
- render() {
322
- if (this.compiledCode === null) {
323
- return b `
324
- <div class="code-loader">
325
- <wc-circular-progress indeterminate></wc-circular-progress>
326
- ${locale.loading}
327
- </div>
328
- `;
329
- }
330
- return b `
331
- <div
332
- class=${e({
333
- 'code-highlighter': true,
334
- 'line-numbers': this.lineNumbers,
777
+ __handleWrapClick() {
778
+ this.wrap = !this.wrap;
779
+ }
780
+ __handleExpandClick() {
781
+ this.expanded = !this.expanded;
782
+ if (!this.expanded && this.__content)
783
+ this.__content.scrollTop = 0;
784
+ this.dispatchEvent(new CustomEvent('expanded-change', {
785
+ detail: { expanded: this.expanded },
786
+ bubbles: true,
787
+ composed: true,
788
+ }));
789
+ }
790
+ // ── Render helpers ────────────────────────────────────────────────────────
791
+ // eslint-disable-next-line class-methods-use-this
792
+ __renderToken(token) {
793
+ const fontStyle = token.fontStyle ?? 0;
794
+ if (!token.color && fontStyle <= 0)
795
+ return token.content;
796
+ return b `<span
797
+ class=${e$1({
798
+ italic: hasFontFlag(fontStyle, FONT_ITALIC),
799
+ bold: hasFontFlag(fontStyle, FONT_BOLD),
800
+ underline: hasFontFlag(fontStyle, FONT_UNDERLINE),
801
+ strikethrough: hasFontFlag(fontStyle, FONT_STRIKETHROUGH),
335
802
  })}
336
- >
337
- <div class="header">
338
- <div class="header-title">
339
- <slot name="title">${this.language?.toUpperCase()}</slot>
340
- </div>
341
- <div class="header-actions">
342
- <wc-icon-button
343
- color=${this._copied ? 'success' : 'surface'}
803
+ style=${o({ color: token.color })}
804
+ >${token.content}</span
805
+ >`;
806
+ }
807
+ __renderLine(line, index) {
808
+ const tokens = this._tokens?.[index];
809
+ const variant = this.__lineVariants.get(index + 1);
810
+ let content = line;
811
+ if (line === '')
812
+ content = '\n';
813
+ else if (tokens)
814
+ content = tokens.map(token => this.__renderToken(token));
815
+ // No whitespace between tags: this renders inside <pre>.
816
+ return b `<span
817
+ class="line"
818
+ part="line"
819
+ data-variant=${variant ?? A}
820
+ ><span class="line-content">${content}</span></span
821
+ >`;
822
+ }
823
+ __renderActions(floating) {
824
+ return b `
825
+ <div class=${e$1({ actions: true, floating })} part="actions">
826
+ <slot name="actions"></slot>
827
+ ${this.wrapToggle
828
+ ? b `<wc-icon-button
829
+ class="wrap-button"
344
830
  variant="text"
345
831
  size="xs"
832
+ shape="round"
833
+ color="surface"
834
+ toggle
835
+ ?selected=${this.wrap}
836
+ aria-label=${this.wrap ? locale.unwrapLines : locale.wrapLines}
837
+ tooltip=${this.wrap ? locale.unwrapLines : locale.wrapLines}
838
+ @click=${this.__handleWrapClick}
839
+ >
840
+ <wc-icon name="wrap_text"></wc-icon>
841
+ </wc-icon-button>`
842
+ : A}
843
+ ${this.hideCopy
844
+ ? A
845
+ : b `<wc-icon-button
846
+ class="copy-button"
847
+ variant="text"
848
+ size="xs"
849
+ shape="round"
850
+ color=${this._copied ? 'success' : 'surface'}
346
851
  aria-label=${this._copied
347
- ? locale.copied
348
- : locale.copyToClipboard}
852
+ ? locale.copied
853
+ : locale.copyToClipboard}
349
854
  tooltip=${this._copied ? locale.copied : locale.copyToClipboard}
350
855
  @click=${this.__handleCopyClick}
351
856
  >
352
857
  <wc-icon
353
858
  name=${this._copied ? 'check' : 'content_copy'}
354
859
  ></wc-icon>
355
- </wc-icon-button>
356
- </div>
357
- </div>
358
-
359
- <div class="scroll-wrapper">
360
- <div class="highlighter">${o(this.compiledCode || '')}</div>
860
+ </wc-icon-button>`}
861
+ </div>
862
+ `;
863
+ }
864
+ __renderHeader() {
865
+ return b `
866
+ <div class="header" part="header">
867
+ <slot name="icon"></slot>
868
+ <div class="title" part="title">
869
+ <slot name="title">${this.label}</slot>
361
870
  </div>
871
+ ${this.__renderActions(false)}
872
+ </div>
873
+ `;
874
+ }
875
+ __renderFooter() {
876
+ return b `
877
+ <div class="footer" part="footer">
878
+ <wc-button
879
+ class="expand-button"
880
+ variant="text"
881
+ size="xs"
882
+ trailing-icon
883
+ aria-expanded=${this.expanded ? 'true' : 'false'}
884
+ @click=${this.__handleExpandClick}
885
+ >
886
+ <wc-icon
887
+ slot="icon"
888
+ class=${e$1({ 'expand-icon': true, flipped: this.expanded })}
889
+ name="keyboard_arrow_down"
890
+ ></wc-icon>
891
+ ${this.expanded ? locale.showLess : locale.showMore}
892
+ </wc-button>
893
+ </div>
894
+ `;
895
+ }
896
+ __renderInline() {
897
+ const lines = splitLines(this._code);
898
+ return b `<code class="inline" part="content"
899
+ >${lines.map((line, index) => {
900
+ const tokens = this._tokens?.[index];
901
+ const content = tokens
902
+ ? tokens.map(token => this.__renderToken(token))
903
+ : line;
904
+ return index === 0 ? content : [' ', content];
905
+ })}</code
906
+ >`;
907
+ }
908
+ // ── Render ────────────────────────────────────────────────────────────────
909
+ render() {
910
+ if (this.inline)
911
+ return this.__renderInline();
912
+ const lines = splitLines(this._code);
913
+ const hasHeader = !this.grouped && (!!this.label || this.__hasSlotted('title'));
914
+ const hasActions = !this.hideCopy || this.wrapToggle || this.__hasSlotted('actions');
915
+ const showFooter = this.collapsible && (this._overflowing || this.expanded);
916
+ const collapsed = this.collapsible && !this.expanded;
917
+ return b `
918
+ <div
919
+ class=${e$1({
920
+ 'code-block': true,
921
+ 'has-header': hasHeader,
922
+ 'has-footer': showFooter,
923
+ 'line-numbers': this.lineNumbers,
924
+ wrap: this.wrap,
925
+ collapsed,
926
+ overflowing: collapsed && this._overflowing,
927
+ })}
928
+ part="container"
929
+ >
930
+ ${hasHeader ? this.__renderHeader() : A}
931
+ ${!hasHeader && hasActions ? this.__renderActions(true) : A}
932
+ <pre
933
+ class="content"
934
+ part="content"
935
+ dir="ltr"
936
+ tabindex="0"
937
+ ><code class="code" style=${o({
938
+ counterReset: `line ${this.startLine - 1}`,
939
+ })}>${lines.map((line, index) => this.__renderLine(line, index))}</code></pre>
940
+ ${showFooter ? this.__renderFooter() : A}
941
+ <span class="sr-only" aria-live="polite"
942
+ >${this._copied ? locale.copiedCode : ''}</span
943
+ >
362
944
  </div>
363
945
  `;
364
946
  }
365
947
  };
366
948
  CodeHighlighter.styles = [css_248z];
367
- CodeHighlighter.COPY_FEEDBACK_DURATION = 3000;
949
+ CodeHighlighter.COPY_FEEDBACK_DURATION = 2000;
368
950
  __decorate([
369
951
  n({ type: String, reflect: true })
370
952
  ], CodeHighlighter.prototype, "language", void 0);
953
+ __decorate([
954
+ n({ type: String })
955
+ ], CodeHighlighter.prototype, "value", void 0);
956
+ __decorate([
957
+ n({
958
+ converter: { fromAttribute: (value) => value !== 'false' },
959
+ })
960
+ ], CodeHighlighter.prototype, "format", void 0);
961
+ __decorate([
962
+ n({ type: String })
963
+ ], CodeHighlighter.prototype, "label", void 0);
371
964
  __decorate([
372
965
  n({ attribute: 'line-numbers', type: Boolean, reflect: true })
373
966
  ], CodeHighlighter.prototype, "lineNumbers", void 0);
374
967
  __decorate([
375
- n({ type: String })
376
- ], CodeHighlighter.prototype, "value", void 0);
968
+ n({ attribute: 'start-line', type: Number })
969
+ ], CodeHighlighter.prototype, "startLine", void 0);
377
970
  __decorate([
378
971
  n({ type: Boolean, reflect: true })
379
- ], CodeHighlighter.prototype, "format", void 0);
972
+ ], CodeHighlighter.prototype, "wrap", void 0);
973
+ __decorate([
974
+ n({ attribute: 'wrap-toggle', type: Boolean })
975
+ ], CodeHighlighter.prototype, "wrapToggle", void 0);
976
+ __decorate([
977
+ n({ attribute: 'highlight-lines', type: String })
978
+ ], CodeHighlighter.prototype, "highlightLines", void 0);
979
+ __decorate([
980
+ n({ attribute: 'added-lines', type: String })
981
+ ], CodeHighlighter.prototype, "addedLines", void 0);
982
+ __decorate([
983
+ n({ attribute: 'removed-lines', type: String })
984
+ ], CodeHighlighter.prototype, "removedLines", void 0);
985
+ __decorate([
986
+ n({ type: Boolean, reflect: true })
987
+ ], CodeHighlighter.prototype, "collapsible", void 0);
988
+ __decorate([
989
+ n({ type: Boolean, reflect: true })
990
+ ], CodeHighlighter.prototype, "expanded", void 0);
991
+ __decorate([
992
+ n({ type: String, reflect: true })
993
+ ], CodeHighlighter.prototype, "size", void 0);
994
+ __decorate([
995
+ n({ type: String, reflect: true })
996
+ ], CodeHighlighter.prototype, "variant", void 0);
380
997
  __decorate([
381
- n({ type: Boolean })
998
+ n({ attribute: 'hide-copy', type: Boolean })
382
999
  ], CodeHighlighter.prototype, "hideCopy", void 0);
1000
+ __decorate([
1001
+ n({ attribute: 'copy-value', type: String })
1002
+ ], CodeHighlighter.prototype, "copyValue", void 0);
1003
+ __decorate([
1004
+ n({ type: Boolean, reflect: true })
1005
+ ], CodeHighlighter.prototype, "inline", void 0);
1006
+ __decorate([
1007
+ n({ type: Boolean, reflect: true })
1008
+ ], CodeHighlighter.prototype, "grouped", void 0);
1009
+ __decorate([
1010
+ r()
1011
+ ], CodeHighlighter.prototype, "_code", void 0);
383
1012
  __decorate([
384
1013
  r()
385
- ], CodeHighlighter.prototype, "compiledCode", void 0);
1014
+ ], CodeHighlighter.prototype, "_tokens", void 0);
386
1015
  __decorate([
387
1016
  r()
388
1017
  ], CodeHighlighter.prototype, "_copied", void 0);
1018
+ __decorate([
1019
+ r()
1020
+ ], CodeHighlighter.prototype, "_overflowing", void 0);
1021
+ __decorate([
1022
+ e('.content')
1023
+ ], CodeHighlighter.prototype, "__content", void 0);
1024
+ __decorate([
1025
+ e('.code')
1026
+ ], CodeHighlighter.prototype, "__codeElement", void 0);
389
1027
  CodeHighlighter = CodeHighlighter_1 = __decorate([
390
1028
  IndividualComponent
391
1029
  ], CodeHighlighter);