@redvars/peacock 3.16.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 (147) 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 +1675 -222
  31. package/dist/custom-elements.json +13351 -3970
  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/path-CJ0Arqcy.js +166 -0
  42. package/dist/path-CJ0Arqcy.js.map +1 -0
  43. package/dist/snackbar.js +89 -34
  44. package/dist/snackbar.js.map +1 -1
  45. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  46. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  47. package/dist/src/__internal/chart/paths.d.ts +5 -0
  48. package/dist/src/__internal/chart/types.d.ts +42 -0
  49. package/dist/src/card/card-content.d.ts +2 -3
  50. package/dist/src/card/card.d.ts +31 -17
  51. package/dist/src/chart-area/chart-area.d.ts +54 -0
  52. package/dist/src/chart-area/index.d.ts +1 -0
  53. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  54. package/dist/src/chart-bar/index.d.ts +0 -1
  55. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  56. package/dist/src/chart-line/chart-line.d.ts +69 -0
  57. package/dist/src/chart-line/index.d.ts +1 -0
  58. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  59. package/dist/src/code-editor/code-editor.d.ts +52 -13
  60. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  61. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  62. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  63. package/dist/src/code-highlighter/index.d.ts +1 -0
  64. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  65. package/dist/src/code-highlighter/local.d.ts +4 -1
  66. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  67. package/dist/src/index.d.ts +4 -2
  68. package/dist/src/snackbar/snackbar.d.ts +13 -1
  69. package/dist/src/toolbar/toolbar.d.ts +56 -51
  70. package/dist/table.js +9 -4
  71. package/dist/table.js.map +1 -1
  72. package/dist/test/chart.test.d.ts +1 -0
  73. package/dist/test/code-highlighter.test.d.ts +1 -0
  74. package/dist/token-colors-0TFHWbcq.js +81 -0
  75. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  76. package/dist/toolbar.js +195 -184
  77. package/dist/toolbar.js.map +1 -1
  78. package/dist/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +1 -2
  80. package/readme.md +7 -6
  81. package/scss/_code-block.scss +139 -0
  82. package/scss/tokens.css +24 -0
  83. package/src/__internal/chart/cartesian-chart.ts +404 -0
  84. package/src/__internal/chart/chart-base.scss +252 -0
  85. package/src/__internal/chart/chart-base.ts +474 -0
  86. package/src/__internal/chart/paths.ts +28 -0
  87. package/src/__internal/chart/types.ts +49 -0
  88. package/src/card/card-content.ts +12 -9
  89. package/src/card/card.scss +66 -54
  90. package/src/card/card.ts +109 -73
  91. package/src/chart-area/chart-area.ts +82 -0
  92. package/src/chart-area/index.ts +1 -0
  93. package/src/chart-bar/chart-bar.ts +336 -250
  94. package/src/chart-bar/index.ts +0 -1
  95. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  96. package/src/chart-doughnut/demo/index.html +14 -22
  97. package/src/chart-line/chart-line.scss +25 -0
  98. package/src/chart-line/chart-line.ts +346 -0
  99. package/src/chart-line/index.ts +1 -0
  100. package/src/chart-pie/chart-pie.scss +35 -16
  101. package/src/chart-pie/chart-pie.ts +282 -188
  102. package/src/chart-pie/demo/index.html +13 -21
  103. package/src/code-editor/code-editor.scss +132 -36
  104. package/src/code-editor/code-editor.ts +308 -88
  105. package/src/code-editor/demo/index.html +39 -12
  106. package/src/code-editor/editor-theme.ts +213 -0
  107. package/src/code-highlighter/code-group.scss +34 -0
  108. package/src/code-highlighter/code-group.ts +173 -0
  109. package/src/code-highlighter/code-highlighter.scss +226 -111
  110. package/src/code-highlighter/code-highlighter.ts +554 -199
  111. package/src/code-highlighter/demo/index.html +68 -4
  112. package/src/code-highlighter/index.ts +1 -0
  113. package/src/code-highlighter/line-ranges.ts +81 -0
  114. package/src/code-highlighter/local.ts +9 -3
  115. package/src/code-highlighter/token-colors.ts +42 -0
  116. package/src/index.ts +4 -2
  117. package/src/loader.ts +8 -2
  118. package/src/snackbar/demo/index.html +39 -4
  119. package/src/snackbar/snackbar.scss +27 -10
  120. package/src/snackbar/snackbar.ts +80 -37
  121. package/src/table/table.scss +7 -1
  122. package/src/table/table.ts +4 -3
  123. package/src/toolbar/toolbar-colors.scss +6 -7
  124. package/src/toolbar/toolbar.scss +35 -106
  125. package/src/toolbar/toolbar.ts +180 -80
  126. package/dist/array-D5vjT2Xm.js +0 -14
  127. package/dist/array-D5vjT2Xm.js.map +0 -1
  128. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  129. package/dist/chart-stacked-bar.js +0 -403
  130. package/dist/chart-stacked-bar.js.map +0 -1
  131. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  132. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  133. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  134. package/dist/pie-Dz0IDiPt.js +0 -537
  135. package/dist/pie-Dz0IDiPt.js.map +0 -1
  136. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  137. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  138. package/dist/pierre-light-BEkAPImt.js +0 -4
  139. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  140. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  141. package/dist/src/code-highlighter/constants.d.ts +0 -1
  142. package/dist/transform-DSwFSqzD.js.map +0 -1
  143. package/src/chart-bar/chart-bar.scss +0 -58
  144. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  145. package/src/chart-doughnut/chart-donut.scss +0 -37
  146. package/src/code-highlighter/constants.ts +0 -117
  147. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
@@ -0,0 +1,54 @@
1
+ import { ChartLine } from '../chart-line/chart-line.js';
2
+ export type { ChartConfig, ChartDatum, ChartSelectDetail, ChartSeriesConfig, ChartValueFormatter, } from '../__internal/chart/types.js';
3
+ export type { ChartCurve } from '../chart-line/chart-line.js';
4
+ /**
5
+ * @label Area Chart
6
+ * @tag wc-chart-area
7
+ * @rawTag chart-area
8
+ * @summary A line chart with the area under each line filled, optionally stacked to show parts of a total over time.
9
+ * @tags charts
10
+ *
11
+ * @example
12
+ * ```html
13
+ * <wc-chart-area index="month" stacked label="Visitors by month"></wc-chart-area>
14
+ * <script>
15
+ * const chart = document.querySelector('wc-chart-area');
16
+ * chart.config = {
17
+ * desktop: { label: 'Desktop' },
18
+ * mobile: { label: 'Mobile' },
19
+ * };
20
+ * chart.data = [
21
+ * { month: 'January', desktop: 186, mobile: 80 },
22
+ * { month: 'February', desktop: 305, mobile: 200 },
23
+ * { month: 'March', desktop: 237, mobile: 120 },
24
+ * ];
25
+ * </script>
26
+ * ```
27
+ *
28
+ * @slot empty - Shown when there is no data. Defaults to "No data".
29
+ *
30
+ * @fires chart-select - A category was clicked or chosen with Enter. `detail` holds `index` and `datum`.
31
+ *
32
+ * @csspart container - The outer wrapper.
33
+ * @csspart plot - The focusable plot area holding the SVG.
34
+ * @csspart tooltip - The tooltip.
35
+ * @csspart legend - The legend.
36
+ *
37
+ * @cssprop --color-chart-1 - Color of the first series; series cycle through `--color-chart-1` to `--color-chart-8`.
38
+ * @cssprop --chart-line-width - Stroke width of the lines. Defaults to `2px`.
39
+ * @cssprop --chart-grid-color - Gridline and baseline color. Defaults to `--color-outline-variant`.
40
+ * @cssprop --chart-axis-color - Axis label color. Defaults to `--color-on-surface-variant`.
41
+ * @cssprop --chart-dim-opacity - Opacity of series that are not highlighted. Defaults to `0.4`.
42
+ */
43
+ export declare class ChartArea extends ChartLine {
44
+ /** Stacks the series on each other so the top line shows the total. */
45
+ stacked: boolean;
46
+ constructor();
47
+ protected drawProperties(): string[];
48
+ protected isStacked(): boolean;
49
+ }
50
+ declare global {
51
+ interface HTMLElementTagNameMap {
52
+ 'wc-chart-area': ChartArea;
53
+ }
54
+ }
@@ -0,0 +1 @@
1
+ export { ChartArea } from './chart-area.js';
@@ -1,50 +1,61 @@
1
- import { LitElement, PropertyValues } from 'lit';
2
- export type ChartBarItem = {
3
- name: string;
4
- value: number;
5
- label?: string;
6
- color?: string;
7
- };
1
+ import { CartesianChart, ChartOrientation } from '../__internal/chart/cartesian-chart.js';
2
+ export type { ChartConfig, ChartDatum, ChartSelectDetail, ChartSeriesConfig, ChartValueFormatter, } from '../__internal/chart/types.js';
8
3
  /**
9
- * @label Chart Bar
4
+ * @label Bar Chart
10
5
  * @tag wc-chart-bar
11
6
  * @rawTag chart-bar
12
- * @summary A vertical bar chart that follows color and spacing tokens.
7
+ * @summary Compares values across categories with vertical or horizontal bars, grouped or stacked by series.
13
8
  * @tags charts
14
9
  *
15
10
  * @example
16
11
  * ```html
17
- * <wc-chart-bar width="520" height="320"></wc-chart-bar>
12
+ * <wc-chart-bar index="month" label="Visitors by month"></wc-chart-bar>
18
13
  * <script>
19
- * document.querySelector('wc-chart-bar').data = [
20
- * { name: 'apples', label: 'Apples', value: 20 },
21
- * { name: 'bananas', label: 'Bananas', value: 35 },
22
- * { name: 'cherries', label: 'Cherries', value: 15 },
14
+ * const chart = document.querySelector('wc-chart-bar');
15
+ * chart.config = {
16
+ * desktop: { label: 'Desktop' },
17
+ * mobile: { label: 'Mobile' },
18
+ * };
19
+ * chart.data = [
20
+ * { month: 'January', desktop: 186, mobile: 80 },
21
+ * { month: 'February', desktop: 305, mobile: 200 },
22
+ * { month: 'March', desktop: 237, mobile: 120 },
23
23
  * ];
24
24
  * </script>
25
25
  * ```
26
+ *
27
+ * @slot empty - Shown when there is no data. Defaults to "No data".
28
+ *
29
+ * @fires chart-select - A bar group was clicked or chosen with Enter. `detail` holds `index` and `datum`.
30
+ *
31
+ * @csspart container - The outer wrapper.
32
+ * @csspart plot - The focusable plot area holding the SVG.
33
+ * @csspart tooltip - The tooltip.
34
+ * @csspart legend - The legend.
35
+ *
36
+ * @cssprop --color-chart-1 - Color of the first series; series cycle through `--color-chart-1` to `--color-chart-8`.
37
+ * @cssprop --chart-grid-color - Gridline and baseline color. Defaults to `--color-outline-variant`.
38
+ * @cssprop --chart-axis-color - Axis label color. Defaults to `--color-on-surface-variant`.
39
+ * @cssprop --chart-dim-opacity - Opacity of marks that are not hovered. Defaults to `0.4`.
26
40
  */
27
- export declare class ChartBar extends LitElement {
41
+ export declare class ChartBar extends CartesianChart {
28
42
  static styles: import("lit").CSSResultGroup[];
29
- private svgElement?;
30
- /** Width of the chart in pixels. */
31
- width: number;
32
- /** Height of the chart in pixels. */
33
- height: number;
34
- /** Margin around the chart drawing area. */
35
- margin: number;
36
- /** Chart data array. Each item should have name, value, and optional label and color. */
37
- data: ChartBarItem[];
38
- /** Whether to render value labels above bars. */
43
+ /** Stacks the series in each category instead of placing them side by side. */
44
+ stacked: boolean;
45
+ /** `vertical` draws columns; `horizontal` draws bars from the left. */
46
+ orientation: ChartOrientation;
47
+ /** Prints each bar's value (each stack's total when stacked) at its end. */
39
48
  showValues: boolean;
40
- private _initialized;
41
- private _debouncedRenderChart;
42
- firstUpdated(): void;
43
- updated(changedProperties: PropertyValues): void;
44
- private _getPaletteScale;
45
- private _resolveColor;
46
- private _renderChart;
47
- render(): import("lit-html").TemplateResult<1>;
49
+ /** Bars from the last draw, for highlighting. */
50
+ private bars;
51
+ protected drawProperties(): string[];
52
+ /** Corner radius of the rounded end, from `--shape-corner-extra-small`. */
53
+ private cornerRadius;
54
+ /** Bars and value labels in data space; positions are filled once scales exist. */
55
+ private buildModels;
56
+ protected draw(animate: boolean): void;
57
+ protected drawHighlight(): void;
58
+ protected getSelectDetail(index: number): import("../__internal/chart/types.js").ChartSelectDetail;
48
59
  }
49
60
  declare global {
50
61
  interface HTMLElementTagNameMap {
@@ -1,2 +1 @@
1
1
  export { ChartBar } from './chart-bar.js';
2
- export { ChartStackedBar } from './chart-stacked-bar.js';
@@ -1,53 +1,47 @@
1
- import { LitElement, PropertyValues } from 'lit';
2
- export type ChartDoughnutColor = {
3
- color: string;
4
- };
5
- export type ChartDoughnutItem = {
6
- name: string;
7
- value: number;
8
- label?: string;
9
- color?: string;
10
- };
1
+ import { ChartPie } from '../chart-pie/chart-pie.js';
2
+ export type { ChartPieItem, ChartSelectDetail, ChartValueFormatter, } from '../chart-pie/chart-pie.js';
11
3
  /**
12
- * @label Chart Doughnut
4
+ * @label Doughnut Chart
13
5
  * @tag wc-chart-doughnut
14
6
  * @rawTag chart-doughnut
15
- * @summary A doughnut chart is a circular chart with a blank center. The area in the center can be used to display information.
7
+ * @summary A pie chart with a hole that shows the total, or the hovered slice, in its centre.
16
8
  * @tags charts
17
9
  *
18
10
  * @example
19
11
  * ```html
20
- * <wc-chart-doughnut width="400" label="Total"></wc-chart-doughnut>
12
+ * <wc-chart-doughnut label="Visitors by browser" center-label="Visitors"></wc-chart-doughnut>
21
13
  * <script>
22
14
  * document.querySelector('wc-chart-doughnut').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' },
15
+ * { name: 'chrome', label: 'Chrome', value: 275 },
16
+ * { name: 'safari', label: 'Safari', value: 200 },
17
+ * { name: 'firefox', label: 'Firefox', value: 187 },
26
18
  * ];
27
19
  * </script>
28
20
  * ```
21
+ *
22
+ * @slot center - Replaces the total and caption in the centre.
23
+ * @slot empty - Shown when there is no data. Defaults to "No data".
24
+ *
25
+ * @fires chart-select - A slice was clicked or chosen with Enter. `detail` holds `index`, `series` (the slice name) and `datum`.
26
+ *
27
+ * @csspart container - The outer wrapper.
28
+ * @csspart plot - The focusable plot area holding the SVG.
29
+ * @csspart center - The centre content.
30
+ * @csspart tooltip - The tooltip.
31
+ * @csspart legend - The legend.
32
+ *
33
+ * @cssprop --color-chart-1 - Color of the first slice; slices cycle through `--color-chart-1` to `--color-chart-8`.
34
+ * @cssprop --chart-dim-opacity - Opacity of slices that are not hovered. Defaults to `0.4`.
29
35
  */
30
- export declare class ChartDoughnut extends LitElement {
31
- 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. */
40
- data: ChartDoughnutItem[];
41
- /** Label displayed in the center of the doughnut. */
42
- label?: string;
43
- private _initialized;
44
- private _debouncedRenderChart;
45
- firstUpdated(): void;
46
- updated(changedProperties: PropertyValues): void;
47
- private _getRadius;
48
- private _getTotal;
49
- private _getPieData;
50
- private _getColorScale;
51
- private _renderChart;
52
- render(): import("lit-html").TemplateResult<1>;
36
+ export declare class ChartDoughnut extends ChartPie {
37
+ /** Size of the hole as a fraction of the radius. */
38
+ innerRadius: number;
39
+ /** Caption under the total in the centre. */
40
+ centerLabel: string;
41
+ protected renderOverlay(): import("lit-html").TemplateResult<1>;
42
+ }
43
+ declare global {
44
+ interface HTMLElementTagNameMap {
45
+ 'wc-chart-doughnut': ChartDoughnut;
46
+ }
53
47
  }
@@ -0,0 +1,69 @@
1
+ import { CartesianChart } from '../__internal/chart/cartesian-chart.js';
2
+ export type { ChartConfig, ChartDatum, ChartSelectDetail, ChartSeriesConfig, ChartValueFormatter, } from '../__internal/chart/types.js';
3
+ export type ChartCurve = 'monotone' | 'linear' | 'step';
4
+ /**
5
+ * @label Line Chart
6
+ * @tag wc-chart-line
7
+ * @rawTag chart-line
8
+ * @summary Shows how values change across ordered categories such as time, with one line per series.
9
+ * @tags charts
10
+ *
11
+ * @example
12
+ * ```html
13
+ * <wc-chart-line index="month" label="Visitors by month"></wc-chart-line>
14
+ * <script>
15
+ * const chart = document.querySelector('wc-chart-line');
16
+ * chart.config = {
17
+ * desktop: { label: 'Desktop' },
18
+ * mobile: { label: 'Mobile' },
19
+ * };
20
+ * chart.data = [
21
+ * { month: 'January', desktop: 186, mobile: 80 },
22
+ * { month: 'February', desktop: 305, mobile: 200 },
23
+ * { month: 'March', desktop: 237, mobile: 120 },
24
+ * ];
25
+ * </script>
26
+ * ```
27
+ *
28
+ * @slot empty - Shown when there is no data. Defaults to "No data".
29
+ *
30
+ * @fires chart-select - A category was clicked or chosen with Enter. `detail` holds `index` and `datum`.
31
+ *
32
+ * @csspart container - The outer wrapper.
33
+ * @csspart plot - The focusable plot area holding the SVG.
34
+ * @csspart tooltip - The tooltip.
35
+ * @csspart legend - The legend.
36
+ *
37
+ * @cssprop --color-chart-1 - Color of the first series; series cycle through `--color-chart-1` to `--color-chart-8`.
38
+ * @cssprop --chart-line-width - Stroke width of the lines. Defaults to `2px`.
39
+ * @cssprop --chart-grid-color - Gridline and baseline color. Defaults to `--color-outline-variant`.
40
+ * @cssprop --chart-axis-color - Axis label color. Defaults to `--color-on-surface-variant`.
41
+ * @cssprop --chart-dim-opacity - Opacity of series that are not highlighted. Defaults to `0.4`.
42
+ */
43
+ export declare class ChartLine extends CartesianChart {
44
+ static styles: import("lit").CSSResultGroup[];
45
+ /** How points are joined: `monotone` (smooth), `linear` or `step`. */
46
+ curve: ChartCurve;
47
+ /** Draws a dot at every point. Dots always show for the hovered category. */
48
+ showDots: boolean;
49
+ /** Whether the area under each line is filled. */
50
+ protected filled: boolean;
51
+ /** Value scale from the last draw, used to place active dots. */
52
+ private y;
53
+ /** Category positions from the last draw. */
54
+ private x;
55
+ /** Series from the last draw. */
56
+ private models;
57
+ constructor();
58
+ protected drawProperties(): string[];
59
+ /** Whether series stack on each other. Only areas stack. */
60
+ protected isStacked(): boolean;
61
+ private buildModels;
62
+ protected draw(animate: boolean): void;
63
+ protected drawHighlight(): void;
64
+ }
65
+ declare global {
66
+ interface HTMLElementTagNameMap {
67
+ 'wc-chart-line': ChartLine;
68
+ }
69
+ }
@@ -0,0 +1 @@
1
+ export { ChartLine } from './chart-line.js';
@@ -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;