@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,50 +1,85 @@
1
- import { LitElement, PropertyValues } from 'lit';
2
- export type ChartPieColor = {
3
- color: string;
4
- };
1
+ import { ChartBase } from '../__internal/chart/chart-base.js';
2
+ import type { ChartSeries, ChartTooltipModel } from '../__internal/chart/types.js';
3
+ export type { ChartSelectDetail, ChartValueFormatter, } from '../__internal/chart/types.js';
4
+ /** One slice. */
5
5
  export type ChartPieItem = {
6
+ /** Unique key of the slice. */
6
7
  name: string;
7
8
  value: number;
9
+ /** Display name in the legend and tooltip. Defaults to `name`. */
8
10
  label?: string;
11
+ /** Any CSS color. Defaults to the next `--color-chart-n` token. */
9
12
  color?: string;
10
13
  };
11
14
  /**
12
- * @label Chart Pie
15
+ * @label Pie Chart
13
16
  * @tag wc-chart-pie
14
17
  * @rawTag chart-pie
15
- * @summary A pie chart is a circular statistical graphic that visually represents numerical proportions.
18
+ * @summary Shows how parts make up a whole. Best with a handful of slices.
16
19
  * @tags charts
17
20
  *
18
21
  * @example
19
22
  * ```html
20
- * <wc-chart-pie width="400"></wc-chart-pie>
23
+ * <wc-chart-pie label="Visitors by browser"></wc-chart-pie>
21
24
  * <script>
22
25
  * document.querySelector('wc-chart-pie').data = [
23
- * { name: 'A', value: 30, label: 'Category A' },
24
- * { name: 'B', value: 50, label: 'Category B' },
25
- * { name: 'C', value: 20, label: 'Category C' },
26
+ * { name: 'chrome', label: 'Chrome', value: 275 },
27
+ * { name: 'safari', label: 'Safari', value: 200 },
28
+ * { name: 'firefox', label: 'Firefox', value: 187 },
26
29
  * ];
27
30
  * </script>
28
31
  * ```
32
+ *
33
+ * @slot empty - Shown when there is no data. Defaults to "No data".
34
+ *
35
+ * @fires chart-select - A slice was clicked or chosen with Enter. `detail` holds `index`, `series` (the slice name) and `datum`.
36
+ *
37
+ * @csspart container - The outer wrapper.
38
+ * @csspart plot - The focusable plot area holding the SVG.
39
+ * @csspart tooltip - The tooltip.
40
+ * @csspart legend - The legend.
41
+ *
42
+ * @cssprop --color-chart-1 - Color of the first slice; slices cycle through `--color-chart-1` to `--color-chart-8`.
43
+ * @cssprop --chart-dim-opacity - Opacity of slices that are not hovered. Defaults to `0.4`.
29
44
  */
30
- export declare class ChartPie extends LitElement {
45
+ export declare class ChartPie extends ChartBase {
31
46
  static styles: import("lit").CSSResultGroup[];
32
- private svgElement?;
33
- /** Width (and height) of the chart in pixels. */
34
- width: number;
35
- /** Margin around the chart. */
36
- margin: number;
37
- /** Whether to show labels outside the chart. */
38
- showLabels: boolean;
39
- /** Chart data array. Each item should have name, value, and optional label and color. */
47
+ /** Slices to draw. */
40
48
  data: ChartPieItem[];
41
- private _initialized;
42
- private _debouncedRenderChart;
43
- firstUpdated(): void;
44
- updated(changedProperties: PropertyValues): void;
45
- private _getRadius;
46
- private _getPieData;
47
- private _getColorScale;
48
- private _renderChart;
49
- render(): import("lit-html").TemplateResult<1>;
49
+ /** Size of the hole as a fraction of the radius, from 0 (pie) to 0.9. */
50
+ innerRadius: number;
51
+ /** Prints each slice's percentage inside it when it fits. */
52
+ showLabels: boolean;
53
+ /** Arcs from the last draw. */
54
+ private arcs;
55
+ /** Outer radius from the last draw. */
56
+ protected radius: number;
57
+ /** Pie centre from the last draw, in plot coordinates. */
58
+ private center;
59
+ protected drawProperties(): string[];
60
+ protected hasData(): boolean;
61
+ protected getSeries(): ChartSeries[];
62
+ protected legendVisible(): boolean;
63
+ protected getItemCount(): number;
64
+ /** Sum of the visible slices. */
65
+ protected visibleTotal(): number;
66
+ protected percent(value: number): string;
67
+ private innerFraction;
68
+ protected draw(animate: boolean): void;
69
+ protected drawHighlight(): void;
70
+ protected itemAtPoint(x: number, y: number): number;
71
+ protected getTooltip(index: number): ChartTooltipModel | undefined;
72
+ protected getSelectDetail(index: number): {
73
+ index: number;
74
+ series: string;
75
+ datum: ChartPieItem;
76
+ };
77
+ protected renderSkeleton(): import("lit-html").TemplateResult<1>;
78
+ protected renderSvgContent(): import("lit-html").TemplateResult<2>;
79
+ protected renderTable(): import("lit-html").TemplateResult<1>;
80
+ }
81
+ declare global {
82
+ interface HTMLElementTagNameMap {
83
+ 'wc-chart-pie': ChartPie;
84
+ }
50
85
  }
@@ -1,6 +1,7 @@
1
1
  import { PropertyValues } from 'lit';
2
2
  import BaseInput from '../input/BaseInput.js';
3
3
  export type CodeEditorLanguage = 'javascript' | 'typescript' | 'json' | 'html' | 'css' | 'scss' | 'markdown';
4
+ export type CodeEditorSize = 'sm' | 'md';
4
5
  /** A problem shown in the editor: a squiggle under the text and a mark in the scroll bar. Lines and columns count from 1. */
5
6
  export type CodeEditorMarker = {
6
7
  line: number;
@@ -18,16 +19,30 @@ type Monaco = typeof import('./monaco.js');
18
19
  *
19
20
  * @summary A Monaco-based code editing component with syntax highlighting, completions and debugging marks.
20
21
  * @overview
21
- * - CodeEditor wraps Monaco Editor as a web component. Monaco is bundled with Peacock and loaded when the first editor appears; nothing comes from a CDN, so it works under a content security policy that allows only its own origin.
22
- * - Supports TypeScript, JavaScript, JSON, HTML, CSS, SCSS and Markdown, with completions and errors for TypeScript, JavaScript and JSON; read-only mode, line numbers, minimap, and dark/light theme.
22
+ * - CodeEditor wraps Monaco Editor as a web component, in the same frame as `wc-code-highlighter`: an optional header with a title and actions, or a copy button that floats at the top end. Monaco is bundled with Peacock and loaded when the first editor appears; nothing comes from a CDN, so it works under a content security policy that allows only its own origin. The code shows as plain text until Monaco is ready.
23
+ * - Its colors come from the theme's color roles and the code highlighter's syntax colors, so light, dark, the system color scheme and custom themes all follow the tokens.
24
+ * - Supports TypeScript, JavaScript, JSON, HTML, CSS, SCSS and Markdown, with completions and errors for TypeScript, JavaScript and JSON; read-only mode, line numbers, line wrapping and a minimap.
23
25
  * - `lib-source` adds TypeScript declarations for completions, such as the modules a script may import.
24
26
  * - With `breakpoint-gutter`, a click in the gutter fires `breakpoint-toggle`; `breakpoints` and `current-line` draw the marks a debugger shows.
25
27
  * - `markers` underline problems, such as where a run failed.
26
- * - With `fill`, the editor takes the height of its container.
27
- * - Has a copy button; hide it with `hide-copy`.
28
+ * - With `fill`, the editor drops its frame and takes the height of its container, as a pane of its own.
28
29
  * - Emits `change` when content is edited and updates value from property changes.
29
30
  *
30
- * @cssprop --code-editor-height - Height of the editor. Defaults to 300px.
31
+ * @slot title - Header title content. Overrides `label` and shows the header.
32
+ * @slot icon - Icon shown before the title in the header.
33
+ * @slot actions - Extra action buttons, shown in the header or floating at the top end.
34
+ *
35
+ * @csspart container - The outer frame.
36
+ * @csspart header - The header row.
37
+ * @csspart title - The header title.
38
+ * @csspart actions - The action buttons group.
39
+ * @csspart editor - The area Monaco renders into.
40
+ *
41
+ * @cssprop --code-editor-height - Height of the editing area. Defaults to 300px. Ignored with `fill`.
42
+ * @cssprop --code-editor-background - Frame background. Defaults to `--color-surface-container-low`.
43
+ * @cssprop --code-editor-border-color - Frame border color. Defaults to `--color-outline-variant`.
44
+ * @cssprop --code-editor-shape - Frame corner radius. Defaults to `--shape-corner-medium`.
45
+ * @cssprop --code-highlighter-token-keyword - Keyword color, shared with `wc-code-highlighter`, like the other `--code-highlighter-token-*` colors.
31
46
  *
32
47
  * @fires {Event} change - Dispatched when the user edits the content.
33
48
  * @fires {CustomEvent<{value: string}>} copied - Dispatched after the copy button copies the content.
@@ -37,6 +52,7 @@ type Monaco = typeof import('./monaco.js');
37
52
  * ```html
38
53
  * <wc-code-editor
39
54
  * language="css"
55
+ * label="theme.css"
40
56
  * readonly
41
57
  * style="width: 100%; --code-editor-height: 10rem;"
42
58
  * value=":root { --color-primary: #6341d5; }">
@@ -50,17 +66,25 @@ export default class CodeEditor extends BaseInput {
50
66
  value: string;
51
67
  /** Language used for syntax highlighting. Can be changed after the editor loads. */
52
68
  language: CodeEditorLanguage;
69
+ /** Header title, such as a file name. Shows the header. */
70
+ label: string;
53
71
  /** TypeScript declarations (a `.d.ts`) for completions in TypeScript and JavaScript, such as the modules the code may import. */
54
72
  libSource: string | undefined;
55
73
  /** Compiler options for TypeScript and JavaScript, over the editor's defaults (target and modules ESNext, strict), such as `{ lib: ['es2022'] }`. */
56
74
  compilerOptions: Record<string, unknown> | undefined;
57
75
  /** Whether line numbers show in the gutter. */
58
76
  lineNumbers: 'off' | 'on';
77
+ /** Wraps long lines instead of scrolling horizontally. */
78
+ wrap: boolean;
79
+ /** Shows a button that turns line wrapping on and off. */
80
+ wrapToggle: boolean;
59
81
  /** Shows the minimap. Leave the attribute out to hide it. */
60
82
  minimap: boolean;
83
+ /** Size of the editor. `sm` uses smaller text and padding. */
84
+ size: CodeEditorSize;
61
85
  /** Hides the copy button. */
62
86
  hideCopy: boolean;
63
- /** Shows a "Read Only" badge while the editor is read-only or disabled. */
87
+ /** Shows a "Read only" badge while the editor is read-only or disabled. */
64
88
  showReadonlyBadge: boolean;
65
89
  /** Shows a gutter for breakpoints; a click there, or on a line number, fires `breakpoint-toggle`. */
66
90
  breakpointGutter: boolean;
@@ -70,29 +94,34 @@ export default class CodeEditor extends BaseInput {
70
94
  currentLine: number | undefined;
71
95
  /** Problems to underline, such as where a run failed. */
72
96
  markers: CodeEditorMarker[];
73
- /** Takes the height of the container instead of `--code-editor-height`. */
97
+ /** Drops the frame and takes the height of the container instead of `--code-editor-height`. */
74
98
  fill: boolean;
75
- /** Whether the page is in dark mode; picks the Monaco theme. */
76
- private _isDarkMode;
77
99
  /** Whether the editor text has focus. */
78
100
  private hasFocus;
79
- /** Whether the copy button was just used; shows a check for a few seconds. */
101
+ /** Whether the copy button was just used; shows a check for a moment. */
80
102
  private _copied;
81
103
  /** The Monaco editor instance, once loaded. */
82
104
  private editorMonacoInstance?;
83
- private editorElement;
105
+ private editorElement?;
106
+ private probeElement?;
84
107
  /** The Monaco API, once loaded. */
85
108
  monaco: Monaco | undefined;
86
109
  /** This editor's model's address, unique on the page so two editors never share a model. */
87
110
  private readonly __id;
88
111
  /** Stops listening for theme changes. */
89
112
  private __unobserveTheme?;
113
+ /** The system color scheme, watched so the editor follows it. */
114
+ private __colorScheme?;
115
+ /** Re-renders when slotted header content is added or removed. */
116
+ private __childObserver?;
90
117
  /** Resets the copied state of the copy button. */
91
118
  private __copiedTimer?;
92
119
  /** The declarations added for `libSource`. */
93
120
  private __lib?;
94
121
  /** The breakpoint and current-line marks. */
95
122
  private __decorations?;
123
+ /** The font and padding last given to Monaco, to skip unchanged updates. */
124
+ private __layoutKey;
96
125
  connectedCallback(): void;
97
126
  disconnectedCallback(): void;
98
127
  protected firstUpdated(): void;
@@ -102,12 +131,22 @@ export default class CodeEditor extends BaseInput {
102
131
  setBlur(): Promise<void>;
103
132
  /** Scrolls `line` into view and puts the cursor at its start. */
104
133
  revealLine(line: number): void;
134
+ /** Defines the page's editor theme from the tokens around this editor. */
135
+ private __applyTheme;
136
+ /** The font and padding the styles give the code, for Monaco's options. */
137
+ private __readLayout;
138
+ /** Gives Monaco the font and padding when the header or size changed them. */
139
+ private __applyLayout;
140
+ /** Whether light-DOM children are assigned to the named slot. */
141
+ private __hasSlotted;
105
142
  private libSourceChanged;
106
143
  private drawDecorations;
107
144
  private drawMarkers;
108
- private getTheme;
109
145
  private __handleCopyClick;
110
- private renderToolbar;
146
+ private __handleWrapClick;
147
+ private renderBadge;
148
+ private renderActions;
149
+ private renderHeader;
111
150
  render(): import("lit-html").TemplateResult<1>;
112
151
  }
113
152
  export {};
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The colors the editor theme is built from: Peacock color roles, plus the syntax colors
3
+ * wc-code-highlighter uses, so the two show code alike. Monaco takes hex colors only, so these
4
+ * are resolved on the page and converted.
5
+ */
6
+ export declare const PALETTE_SOURCES: {
7
+ readonly surface: "var(--color-surface)";
8
+ readonly surfaceContainerHigh: "var(--color-surface-container-high)";
9
+ readonly surfaceContainerHighest: "var(--color-surface-container-highest)";
10
+ readonly onSurface: "var(--color-on-surface)";
11
+ readonly onSurfaceVariant: "var(--color-on-surface-variant)";
12
+ readonly outline: "var(--color-outline)";
13
+ readonly outlineVariant: "var(--color-outline-variant)";
14
+ readonly primary: "var(--color-primary)";
15
+ readonly secondary: "var(--color-secondary)";
16
+ readonly tertiary: "var(--color-tertiary)";
17
+ readonly secondaryContainer: "var(--color-secondary-container)";
18
+ readonly onSecondaryContainer: "var(--color-on-secondary-container)";
19
+ readonly error: "var(--color-error)";
20
+ readonly warning: "var(--color-warning)";
21
+ readonly info: "var(--color-blue)";
22
+ readonly foreground: string;
23
+ readonly keyword: string;
24
+ readonly string: string;
25
+ readonly func: string;
26
+ readonly constant: string;
27
+ readonly comment: string;
28
+ readonly punctuation: string;
29
+ readonly parameter: string;
30
+ readonly link: string;
31
+ };
32
+ export type EditorPalette = Record<keyof typeof PALETTE_SOURCES, string>;
33
+ /** Monaco's standalone theme data, as `monaco.editor.defineTheme` takes it. */
34
+ export type EditorThemeData = {
35
+ base: 'vs' | 'vs-dark';
36
+ inherit: boolean;
37
+ rules: {
38
+ token: string;
39
+ foreground?: string;
40
+ fontStyle?: string;
41
+ }[];
42
+ colors: Record<string, string>;
43
+ };
44
+ /**
45
+ * Converts any CSS color the browser understands (`rgb()`, `oklch()`, `color()`, …) to
46
+ * `#rrggbb`, or `#rrggbbaa` when it is not opaque, by painting one pixel.
47
+ */
48
+ export declare function cssColorToHex(color: string): string;
49
+ /**
50
+ * Resolves the palette where `probe` sits, so it follows the theme around the editor:
51
+ * `data-theme`, the system color scheme, or a custom theme.
52
+ */
53
+ export declare function resolvePalette(probe: HTMLElement): EditorPalette;
54
+ /** Whether a `#rrggbb` color is dark, by relative luminance. */
55
+ export declare function isDark(hex: string): boolean;
56
+ /**
57
+ * Builds the editor theme from a palette. The editor background is transparent, so the frame
58
+ * around it shows through; widgets such as suggestions and hovers sit on surface containers.
59
+ */
60
+ export declare function buildEditorTheme(p: EditorPalette): EditorThemeData;
@@ -0,0 +1,52 @@
1
+ import { LitElement } from 'lit';
2
+ /**
3
+ * @label Code Group
4
+ * @tag wc-code-group
5
+ * @rawTag code-group
6
+ *
7
+ * @summary Shows several code blocks in one frame, with a tab for each block.
8
+ * @overview
9
+ * <p>Put <code>wc-code-highlighter</code> elements inside. Each block's <code>label</code> names its tab,
10
+ * and only the selected block is shown. The group draws the frame, so the blocks drop their own
11
+ * border and header, and their actions float at the top end.</p>
12
+ *
13
+ * @example
14
+ * ```html
15
+ * <wc-code-group>
16
+ * <wc-code-highlighter label="greeting.ts" language="typescript"><pre><code>
17
+ * export const greeting = 'Hello';</code></pre></wc-code-highlighter>
18
+ * <wc-code-highlighter label="greeting.css" language="css"><pre><code>
19
+ * p { color: var(--color-primary); }</code></pre></wc-code-highlighter>
20
+ * </wc-code-group>
21
+ * ```
22
+ *
23
+ * @slot - `wc-code-highlighter` elements, one per tab.
24
+ *
25
+ * @csspart container - The outer frame.
26
+ * @csspart header - The tab bar.
27
+ *
28
+ * @fires {CustomEvent<{index: number}>} change - Dispatched when the user selects another tab.
29
+ *
30
+ * @tags display
31
+ */
32
+ export declare class CodeGroup extends LitElement {
33
+ static styles: import("lit").CSSResultGroup[];
34
+ /** Index of the shown block. */
35
+ selectedIndex: number;
36
+ /** The grouped code blocks, in slot order. */
37
+ private _blocks;
38
+ /** Re-renders the tabs when a block's label changes. */
39
+ private __labelObserver?;
40
+ connectedCallback(): void;
41
+ disconnectedCallback(): void;
42
+ protected updated(changed: Map<PropertyKey, unknown>): void;
43
+ /** The selected index, kept within the blocks. */
44
+ private get __activeIndex();
45
+ /** Marks every block as grouped and shows only the selected one. */
46
+ private __syncBlocks;
47
+ private __handleSlotChange;
48
+ private __handleTabChange;
49
+ private __stopEvent;
50
+ private __tabLabel;
51
+ render(): import("lit-html").TemplateResult<1>;
52
+ }
@@ -1,40 +1,147 @@
1
- import { LitElement } from 'lit';
2
- import type { BundledLanguage } from 'shiki';
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ import type { BundledLanguage, SpecialLanguage } from 'shiki';
3
+ export type CodeHighlighterLanguage = BundledLanguage | SpecialLanguage;
4
+ export type CodeHighlighterSize = 'sm' | 'md';
5
+ export type CodeHighlighterVariant = 'default' | 'error';
3
6
  /**
4
7
  * @label Code Highlighter
5
8
  * @tag wc-code-highlighter
6
9
  * @rawTag code-highlighter
7
10
  *
8
- * @summary A component that provides syntax highlighting for code snippets.
11
+ * @summary Displays a block of code with syntax highlighting, line numbers, line highlights, diffs and a copy button.
9
12
  *
10
13
  * @example
11
14
  * ```html
12
- * <wc-code-highlighter language="javascript" style="height: 9rem"><pre><code>
15
+ * <wc-code-highlighter language="javascript" label="hello.js" line-numbers highlight-lines="2"><pre><code>
13
16
  * function helloWorld() {
14
17
  * console.log('Hello, world!');
15
18
  * }</code></pre>
16
19
  * </wc-code-highlighter>
17
20
  * ```
21
+ *
22
+ * @slot title - Header title content. Overrides `label` and shows the header.
23
+ * @slot icon - Icon shown before the title in the header.
24
+ * @slot actions - Extra action buttons, shown in the header or floating at the top end.
25
+ *
26
+ * @csspart container - The outer block.
27
+ * @csspart header - The header row.
28
+ * @csspart title - The header title.
29
+ * @csspart actions - The action buttons group.
30
+ * @csspart content - The scrollable code area (`pre`).
31
+ * @csspart line - Each code line.
32
+ * @csspart footer - The footer holding the show more button.
33
+ *
34
+ * @cssprop --code-highlighter-background - Block background. Defaults to `--color-surface-container-low`.
35
+ * @cssprop --code-highlighter-border-color - Block border color. Defaults to `--color-outline-variant`.
36
+ * @cssprop --code-highlighter-shape - Block corner radius. Defaults to `--shape-corner-medium`.
37
+ * @cssprop --code-highlighter-max-height - Caps the code area height; it scrolls beyond. Defaults to `none`.
38
+ * @cssprop --code-highlighter-collapsed-height - Height of a collapsed `collapsible` block. Defaults to `16rem`.
39
+ * @cssprop --code-highlighter-foreground - Plain code color. Defaults to `--color-on-surface`.
40
+ * @cssprop --code-highlighter-token-keyword - Keyword color. Defaults to `--color-purple`.
41
+ * @cssprop --code-highlighter-token-string - String color. Defaults to `--color-green`.
42
+ * @cssprop --code-highlighter-token-function - Function color. Defaults to `--color-blue`.
43
+ * @cssprop --code-highlighter-token-constant - Constant and number color. Defaults to `--color-orange`.
44
+ * @cssprop --code-highlighter-token-comment - Comment color. Defaults to `--color-on-surface-variant`.
45
+ * @cssprop --code-highlighter-token-punctuation - Punctuation color. Defaults to `--color-on-surface-variant`.
46
+ *
47
+ * @fires {CustomEvent<{value: string}>} copied - Dispatched after the copy button copies the code.
48
+ * @fires {CustomEvent<{expanded: boolean}>} expanded-change - Dispatched when a collapsible block is expanded or collapsed.
49
+ *
18
50
  * @tags display
19
51
  */
20
52
  export declare class CodeHighlighter extends LitElement {
21
53
  static styles: import("lit").CSSResultGroup[];
22
54
  private static readonly COPY_FEEDBACK_DURATION;
23
- language: BundledLanguage;
24
- lineNumbers: boolean;
55
+ /** Language of the code. Unknown languages render as plain text. */
56
+ language: CodeHighlighterLanguage;
57
+ /** Code to display. When empty, the code is read from a light-DOM `<pre><code>`. */
25
58
  value: string;
26
- format?: boolean;
59
+ /**
60
+ * Formats JavaScript, HTML and CSS with Prettier before display.
61
+ * Set `format="false"` to show the code as written.
62
+ */
63
+ format: boolean;
64
+ /** Header title, such as a file path. Shows the header. */
65
+ label: string;
66
+ /** Shows line numbers. */
67
+ lineNumbers: boolean;
68
+ /** Number of the first line when line numbers are shown. */
69
+ startLine: number;
70
+ /** Wraps long lines instead of scrolling horizontally. */
71
+ wrap: boolean;
72
+ /** Shows a button that turns line wrapping on and off. */
73
+ wrapToggle: boolean;
74
+ /** Lines to highlight, such as `"1, 3-5"`. Counts displayed lines, after formatting. */
75
+ highlightLines: string;
76
+ /** Lines shown as added in a diff, such as `"4-6"`. */
77
+ addedLines: string;
78
+ /** Lines shown as removed in a diff, such as `"3"`. */
79
+ removedLines: string;
80
+ /** Caps the height and adds a show more button when the code is taller. */
81
+ collapsible: boolean;
82
+ /** Whether a collapsible block is expanded. */
83
+ expanded: boolean;
84
+ /** Size of the block. `sm` suits tool output and dense layouts. */
85
+ size: CodeHighlighterSize;
86
+ /** Visual variant. `error` tints the block for failure output. */
87
+ variant: CodeHighlighterVariant;
88
+ /** Hides the copy button. */
27
89
  hideCopy: boolean;
28
- private compiledCode;
90
+ /** Text the copy button copies instead of the displayed code. */
91
+ copyValue?: string;
92
+ /** Renders the code inline, as a compact chip within text. */
93
+ inline: boolean;
94
+ /**
95
+ * Set by `wc-code-group`. The group draws the frame and shows the label as a
96
+ * tab, so the block drops its border and header.
97
+ */
98
+ grouped: boolean;
99
+ /** The code as displayed, after formatting, without a trailing newline. */
100
+ private _code;
101
+ /** Tokens per line, or `null` until highlighting finishes. */
102
+ private _tokens;
103
+ /** Whether the copy button shows its copied feedback. */
29
104
  private _copied;
30
- private parsedCode;
31
- private _copyFeedbackTimeout;
32
- connectedCallback(): Promise<void>;
105
+ /** Whether the collapsed code is taller than the collapsed height. */
106
+ private _overflowing;
107
+ private __content?;
108
+ private __codeElement?;
109
+ /** Source read from `value` or the light DOM, before formatting. */
110
+ private __source;
111
+ /** Line variants keyed by 1-based line number. */
112
+ private __lineVariants;
113
+ /** Increments per highlight run so stale async results are dropped. */
114
+ private __run;
115
+ /** Timer that resets the copy feedback. */
116
+ private __copyFeedbackTimeout;
117
+ /** Measures whether collapsed code overflows. */
118
+ private __resizeObserver?;
119
+ /** Element currently measured by the resize observer. */
120
+ private __observedContent?;
121
+ /** Re-renders when slotted header content is added or removed. */
122
+ private __childObserver?;
123
+ connectedCallback(): void;
33
124
  disconnectedCallback(): void;
34
- firstUpdated(): void;
35
- private decode;
36
- private __highlightCode;
37
- protected updated(changed: Map<PropertyKey, unknown>): void;
125
+ protected willUpdate(changed: PropertyValues<this>): void;
126
+ protected updated(): void;
127
+ /** Reads the source from `value`, or from the light DOM. */
128
+ private __readSource;
129
+ /** Formats then tokenizes the source; plain lines stay until both finish. */
130
+ private __highlight;
131
+ /** Watches the code area so the show more button appears only when needed. */
132
+ private __observeContent;
133
+ /** Checks whether the collapsed code is taller than its cap. */
134
+ private __measure;
135
+ /** Whether light-DOM children are assigned to the named slot. */
136
+ private __hasSlotted;
38
137
  private __handleCopyClick;
138
+ private __handleWrapClick;
139
+ private __handleExpandClick;
140
+ private __renderToken;
141
+ private __renderLine;
142
+ private __renderActions;
143
+ private __renderHeader;
144
+ private __renderFooter;
145
+ private __renderInline;
39
146
  render(): import("lit-html").TemplateResult<1>;
40
147
  }
@@ -1 +1,2 @@
1
1
  export { CodeHighlighter } from './code-highlighter.js';
2
+ export { CodeGroup } from './code-group.js';
@@ -0,0 +1,24 @@
1
+ export type LineVariant = 'highlighted' | 'added' | 'removed';
2
+ /**
3
+ * Parses a line range list such as `"1, 3-5"` into 1-based line numbers.
4
+ * Blank or malformed parts are skipped; a reversed range such as `"5-3"` is read as `3-5`.
5
+ */
6
+ export declare function parseLineRanges(value: string | null | undefined): Set<number>;
7
+ /**
8
+ * Maps 1-based line numbers to their variant. Where ranges overlap,
9
+ * `removed` wins over `added`, and `added` wins over `highlighted`.
10
+ */
11
+ export declare function buildLineVariants(ranges: {
12
+ highlighted?: string | null;
13
+ added?: string | null;
14
+ removed?: string | null;
15
+ }): Map<number, LineVariant>;
16
+ /**
17
+ * Removes leading and trailing blank lines and the indentation common to
18
+ * every non-blank line, so indented markup reads as written.
19
+ */
20
+ export declare function dedent(source: string): string;
21
+ /** Decodes the entities `innerHTML` produces for text, ending with `&amp;`. */
22
+ export declare function decodeEntities(source: string): string;
23
+ /** Splits code into display lines, ignoring one trailing newline. */
24
+ export declare function splitLines(code: string): string[];
@@ -1,6 +1,9 @@
1
1
  export declare const locale: {
2
- loading: string;
3
2
  copyToClipboard: string;
4
3
  copied: string;
5
4
  copiedCode: string;
5
+ wrapLines: string;
6
+ unwrapLines: string;
7
+ showMore: string;
8
+ showLess: string;
6
9
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Syntax colors shared by wc-code-highlighter and wc-code-editor. Each is a CSS variable,
3
+ * `--code-highlighter-<name>`, that falls back to a Peacock color role, so light, dark and
4
+ * custom themes all follow the tokens, and one override restyles both components.
5
+ */
6
+ export declare const TOKEN_DEFAULTS: Record<string, string>;
7
+ /** The CSS value for a syntax color: its public variable, falling back to the color role. */
8
+ export declare function tokenColor(name: string): string;
@@ -39,7 +39,7 @@ export { Menu, MenuItem, SubMenu } from './menu/index.js';
39
39
  export { List, ListItem } from './list/index.js';
40
40
  export { Timeline, TimelineItem } from './timeline/index.js';
41
41
  export { Item } from './item/index.js';
42
- export { CodeHighlighter } from './code-highlighter/index.js';
42
+ export { CodeHighlighter, CodeGroup } from './code-highlighter/index.js';
43
43
  export { CodeEditor } from './code-editor/index.js';
44
44
  export { HtmlEditor } from './html-editor/index.js';
45
45
  export { MarkdownEditor } from './markdown-editor/index.js';
@@ -51,7 +51,9 @@ export { ColorPicker } from './color-picker/index.js';
51
51
  export { ColorField } from './color-field/index.js';
52
52
  export { ChartDoughnut } from './chart-doughnut/index.js';
53
53
  export { ChartPie } from './chart-pie/index.js';
54
- export { ChartBar, ChartStackedBar } from './chart-bar/index.js';
54
+ export { ChartBar } from './chart-bar/index.js';
55
+ export { ChartLine } from './chart-line/index.js';
56
+ export { ChartArea } from './chart-area/index.js';
55
57
  export { Table } from './table/index.js';
56
58
  export { Pagination } from './pagination/index.js';
57
59
  export { SidebarMenu, SidebarMenuItem, SidebarSubMenu, } from './sidebar-menu/index.js';
@@ -0,0 +1,14 @@
1
+ /** A slot in the page list: a page number, or a gap shown as an ellipsis. */
2
+ export type PageItem = number | 'ellipsis';
3
+ /**
4
+ * Builds the page list shown by the `full` pagination variant.
5
+ *
6
+ * The list always keeps the first and last page, the current page and `siblings` pages on each
7
+ * side of it, and fills the rest with an ellipsis. It never holds more than
8
+ * `2 * siblings + 5` slots, so the control keeps its width while the user moves through pages.
9
+ *
10
+ * @example
11
+ * getPageItems(5, 24); // [1, 'ellipsis', 4, 5, 6, 'ellipsis', 24]
12
+ * getPageItems(2, 24); // [1, 2, 3, 4, 5, 'ellipsis', 24]
13
+ */
14
+ export declare function getPageItems(current: number, total: number, siblings?: number): PageItem[];