@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.
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/assets/theme.js +19 -19
- package/dist/assets/tokens.css +1 -1
- package/dist/assets/tokens.css.map +1 -1
- package/dist/card-content.js +8 -7
- package/dist/card-content.js.map +1 -1
- package/dist/card.js +142 -98
- package/dist/card.js.map +1 -1
- package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
- package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
- package/dist/chart-area.js +78 -0
- package/dist/chart-area.js.map +1 -0
- package/dist/chart-bar.js +283 -213
- package/dist/chart-bar.js.map +1 -1
- package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
- package/dist/chart-base-C2qRMF48.js.map +1 -0
- package/dist/chart-doughnut.js +55 -287
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-line.js +626 -0
- package/dist/chart-line.js.map +1 -0
- package/dist/chart-pie.js +637 -195
- package/dist/chart-pie.js.map +1 -1
- package/dist/code-editor.js +704 -131
- package/dist/code-editor.js.map +1 -1
- package/dist/code-group.js +188 -0
- package/dist/code-group.js.map +1 -0
- package/dist/code-highlighter.js +895 -257
- package/dist/code-highlighter.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +2278 -677
- package/dist/custom-elements.json +13962 -3690
- package/dist/image.js +5 -1
- package/dist/image.js.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/loader-full.js +1 -1
- package/dist/loader.js +9 -3
- package/dist/loader.js.map +1 -1
- package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
- package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
- package/dist/pagination.js +408 -110
- package/dist/pagination.js.map +1 -1
- package/dist/path-CJ0Arqcy.js +166 -0
- package/dist/path-CJ0Arqcy.js.map +1 -0
- package/dist/snackbar.js +89 -34
- package/dist/snackbar.js.map +1 -1
- package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
- package/dist/src/__internal/chart/chart-base.d.ts +113 -0
- package/dist/src/__internal/chart/paths.d.ts +5 -0
- package/dist/src/__internal/chart/types.d.ts +42 -0
- package/dist/src/card/card-content.d.ts +2 -3
- package/dist/src/card/card.d.ts +31 -17
- package/dist/src/chart-area/chart-area.d.ts +54 -0
- package/dist/src/chart-area/index.d.ts +1 -0
- package/dist/src/chart-bar/chart-bar.d.ts +44 -33
- package/dist/src/chart-bar/index.d.ts +0 -1
- package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
- package/dist/src/chart-line/chart-line.d.ts +69 -0
- package/dist/src/chart-line/index.d.ts +1 -0
- package/dist/src/chart-pie/chart-pie.d.ts +63 -28
- package/dist/src/code-editor/code-editor.d.ts +52 -13
- package/dist/src/code-editor/editor-theme.d.ts +60 -0
- package/dist/src/code-highlighter/code-group.d.ts +52 -0
- package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
- package/dist/src/code-highlighter/index.d.ts +1 -0
- package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
- package/dist/src/code-highlighter/local.d.ts +4 -1
- package/dist/src/code-highlighter/token-colors.d.ts +8 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/pagination/page-items.d.ts +14 -0
- package/dist/src/pagination/pagination.d.ts +46 -7
- package/dist/src/snackbar/snackbar.d.ts +13 -1
- package/dist/src/table/table.d.ts +125 -27
- package/dist/src/toolbar/toolbar.d.ts +56 -51
- package/dist/table.js +1007 -338
- package/dist/table.js.map +1 -1
- package/dist/test/chart.test.d.ts +1 -0
- package/dist/test/code-highlighter.test.d.ts +1 -0
- package/dist/test/pagination.test.d.ts +1 -0
- package/dist/test/table.test.d.ts +1 -0
- package/dist/token-colors-0TFHWbcq.js +81 -0
- package/dist/token-colors-0TFHWbcq.js.map +1 -0
- package/dist/toolbar.js +195 -184
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/readme.md +7 -6
- package/scss/_code-block.scss +139 -0
- package/scss/tokens.css +24 -0
- package/src/__internal/chart/cartesian-chart.ts +404 -0
- package/src/__internal/chart/chart-base.scss +252 -0
- package/src/__internal/chart/chart-base.ts +474 -0
- package/src/__internal/chart/paths.ts +28 -0
- package/src/__internal/chart/types.ts +49 -0
- package/src/card/card-content.ts +12 -9
- package/src/card/card.scss +66 -54
- package/src/card/card.ts +109 -73
- package/src/chart-area/chart-area.ts +82 -0
- package/src/chart-area/index.ts +1 -0
- package/src/chart-bar/chart-bar.ts +336 -250
- package/src/chart-bar/index.ts +0 -1
- package/src/chart-doughnut/chart-doughnut.ts +62 -262
- package/src/chart-doughnut/demo/index.html +14 -22
- package/src/chart-line/chart-line.scss +25 -0
- package/src/chart-line/chart-line.ts +346 -0
- package/src/chart-line/index.ts +1 -0
- package/src/chart-pie/chart-pie.scss +35 -16
- package/src/chart-pie/chart-pie.ts +282 -188
- package/src/chart-pie/demo/index.html +13 -21
- package/src/code-editor/code-editor.scss +132 -36
- package/src/code-editor/code-editor.ts +308 -88
- package/src/code-editor/demo/index.html +39 -12
- package/src/code-editor/editor-theme.ts +213 -0
- package/src/code-highlighter/code-group.scss +34 -0
- package/src/code-highlighter/code-group.ts +173 -0
- package/src/code-highlighter/code-highlighter.scss +226 -111
- package/src/code-highlighter/code-highlighter.ts +554 -199
- package/src/code-highlighter/demo/index.html +68 -4
- package/src/code-highlighter/index.ts +1 -0
- package/src/code-highlighter/line-ranges.ts +81 -0
- package/src/code-highlighter/local.ts +9 -3
- package/src/code-highlighter/token-colors.ts +42 -0
- package/src/index.ts +4 -2
- package/src/loader.ts +8 -2
- package/src/pagination/page-items.ts +50 -0
- package/src/pagination/pagination.scss +159 -44
- package/src/pagination/pagination.ts +275 -74
- package/src/snackbar/demo/index.html +39 -4
- package/src/snackbar/snackbar.scss +27 -10
- package/src/snackbar/snackbar.ts +80 -37
- package/src/table/table.scss +337 -109
- package/src/table/table.ts +812 -272
- package/src/toolbar/toolbar-colors.scss +6 -7
- package/src/toolbar/toolbar.scss +35 -106
- package/src/toolbar/toolbar.ts +180 -80
- package/dist/array-D5vjT2Xm.js +0 -14
- package/dist/array-D5vjT2Xm.js.map +0 -1
- package/dist/chart-bar-D5dGFJfK.js.map +0 -1
- package/dist/chart-stacked-bar.js +0 -403
- package/dist/chart-stacked-bar.js.map +0 -1
- package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
- package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
- package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
- package/dist/pie-Dz0IDiPt.js +0 -537
- package/dist/pie-Dz0IDiPt.js.map +0 -1
- package/dist/pierre-dark-DFWl0m-C.js +0 -4
- package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
- package/dist/pierre-light-BEkAPImt.js +0 -4
- package/dist/pierre-light-BEkAPImt.js.map +0 -1
- package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
- package/dist/src/code-highlighter/constants.d.ts +0 -1
- package/dist/transform-DSwFSqzD.js.map +0 -1
- package/src/chart-bar/chart-bar.scss +0 -58
- package/src/chart-bar/chart-stacked-bar.ts +0 -398
- package/src/chart-doughnut/chart-donut.scss +0 -37
- package/src/code-highlighter/constants.ts +0 -117
- /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
|
@@ -14,17 +14,81 @@
|
|
|
14
14
|
|
|
15
15
|
<style>
|
|
16
16
|
body {
|
|
17
|
-
|
|
17
|
+
display: grid;
|
|
18
|
+
gap: 1.5rem;
|
|
19
|
+
max-width: 48rem;
|
|
20
|
+
margin: 2rem auto;
|
|
21
|
+
padding: 0 1rem;
|
|
22
|
+
background: var(--color-surface);
|
|
23
|
+
color: var(--color-on-surface);
|
|
24
|
+
font-family: var(--font-family-sans, sans-serif);
|
|
18
25
|
}
|
|
19
26
|
</style>
|
|
20
27
|
</head>
|
|
21
28
|
<body>
|
|
22
|
-
<
|
|
29
|
+
<button
|
|
30
|
+
type="button"
|
|
31
|
+
onclick="document.documentElement.dataset.theme = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'"
|
|
32
|
+
>
|
|
33
|
+
Toggle dark theme
|
|
34
|
+
</button>
|
|
35
|
+
|
|
36
|
+
<wc-code-highlighter language="javascript">
|
|
23
37
|
<pre><code>
|
|
24
38
|
const helloWorld = () => alert ('Hello World!');
|
|
25
39
|
export { helloWorld };
|
|
26
|
-
</code></pre>
|
|
27
|
-
</
|
|
40
|
+
</code></pre>
|
|
41
|
+
</wc-code-highlighter>
|
|
42
|
+
|
|
43
|
+
<wc-code-highlighter
|
|
44
|
+
language="javascript"
|
|
45
|
+
label="src/math.js"
|
|
46
|
+
line-numbers
|
|
47
|
+
start-line="41"
|
|
48
|
+
highlight-lines="2"
|
|
49
|
+
wrap-toggle
|
|
50
|
+
format="false"
|
|
51
|
+
>
|
|
52
|
+
<wc-icon slot="icon" name="description"></wc-icon>
|
|
53
|
+
<pre><code>
|
|
54
|
+
export function clamp(value, min, max) {
|
|
55
|
+
return Math.min(Math.max(value, min), max);
|
|
56
|
+
}
|
|
57
|
+
</code></pre>
|
|
58
|
+
</wc-code-highlighter>
|
|
59
|
+
|
|
60
|
+
<wc-code-highlighter
|
|
61
|
+
language="css"
|
|
62
|
+
label="button.scss"
|
|
63
|
+
removed-lines="2"
|
|
64
|
+
added-lines="3"
|
|
65
|
+
format="false"
|
|
66
|
+
>
|
|
67
|
+
<pre><code>
|
|
68
|
+
.button {
|
|
69
|
+
border-radius: 4px;
|
|
70
|
+
border-radius: var(--shape-corner-full);
|
|
71
|
+
}
|
|
72
|
+
</code></pre>
|
|
73
|
+
</wc-code-highlighter>
|
|
74
|
+
|
|
75
|
+
<wc-code-highlighter
|
|
76
|
+
size="sm"
|
|
77
|
+
variant="error"
|
|
78
|
+
language="text"
|
|
79
|
+
label="Build failed"
|
|
80
|
+
>
|
|
81
|
+
<pre><code>
|
|
82
|
+
TypeError: Cannot read properties of undefined (reading 'map')
|
|
83
|
+
</code></pre>
|
|
84
|
+
</wc-code-highlighter>
|
|
85
|
+
|
|
86
|
+
<p>
|
|
87
|
+
Inline:
|
|
88
|
+
<wc-code-highlighter inline language="javascript"
|
|
89
|
+
>button.focus()</wc-code-highlighter
|
|
90
|
+
>
|
|
91
|
+
</p>
|
|
28
92
|
|
|
29
93
|
<script type="module" src="/dist/loader.js"></script>
|
|
30
94
|
</body>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type LineVariant = 'highlighted' | 'added' | 'removed';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses a line range list such as `"1, 3-5"` into 1-based line numbers.
|
|
5
|
+
* Blank or malformed parts are skipped; a reversed range such as `"5-3"` is read as `3-5`.
|
|
6
|
+
*/
|
|
7
|
+
export function parseLineRanges(value: string | null | undefined): Set<number> {
|
|
8
|
+
const lines = new Set<number>();
|
|
9
|
+
if (!value) return lines;
|
|
10
|
+
|
|
11
|
+
for (const part of value.split(',')) {
|
|
12
|
+
const match = part.trim().match(/^(\d+)(?:\s*-\s*(\d+))?$/);
|
|
13
|
+
if (match) {
|
|
14
|
+
const start = Number(match[1]);
|
|
15
|
+
const end = match[2] === undefined ? start : Number(match[2]);
|
|
16
|
+
const from = Math.max(1, Math.min(start, end));
|
|
17
|
+
const to = Math.max(start, end);
|
|
18
|
+
for (let line = from; line <= to; line += 1) lines.add(line);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return lines;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Maps 1-based line numbers to their variant. Where ranges overlap,
|
|
26
|
+
* `removed` wins over `added`, and `added` wins over `highlighted`.
|
|
27
|
+
*/
|
|
28
|
+
export function buildLineVariants(ranges: {
|
|
29
|
+
highlighted?: string | null;
|
|
30
|
+
added?: string | null;
|
|
31
|
+
removed?: string | null;
|
|
32
|
+
}): Map<number, LineVariant> {
|
|
33
|
+
const variants = new Map<number, LineVariant>();
|
|
34
|
+
const order: LineVariant[] = ['highlighted', 'added', 'removed'];
|
|
35
|
+
for (const variant of order) {
|
|
36
|
+
for (const line of parseLineRanges(ranges[variant])) {
|
|
37
|
+
variants.set(line, variant);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return variants;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Removes leading and trailing blank lines and the indentation common to
|
|
45
|
+
* every non-blank line, so indented markup reads as written.
|
|
46
|
+
*/
|
|
47
|
+
export function dedent(source: string): string {
|
|
48
|
+
const lines = source.replace(/\r\n?/g, '\n').split('\n');
|
|
49
|
+
while (lines.length && lines[0].trim() === '') lines.shift();
|
|
50
|
+
while (lines.length && lines[lines.length - 1].trim() === '') lines.pop();
|
|
51
|
+
|
|
52
|
+
let indent = Infinity;
|
|
53
|
+
for (const line of lines) {
|
|
54
|
+
if (line.trim() !== '') {
|
|
55
|
+
const leading = line.match(/^[ \t]*/)?.[0].length ?? 0;
|
|
56
|
+
indent = Math.min(indent, leading);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!Number.isFinite(indent) || indent === 0) return lines.join('\n');
|
|
60
|
+
return lines.map(line => line.slice(indent)).join('\n');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Decodes the entities `innerHTML` produces for text, ending with `&`. */
|
|
64
|
+
export function decodeEntities(source: string): string {
|
|
65
|
+
return source
|
|
66
|
+
.replace(/</g, '<')
|
|
67
|
+
.replace(/>/g, '>')
|
|
68
|
+
.replace(/"/g, '"')
|
|
69
|
+
.replace(/'/g, "'")
|
|
70
|
+
.replace(/ /g, ' ')
|
|
71
|
+
.replace(/&/g, '&');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Splits code into display lines, ignoring one trailing newline. */
|
|
75
|
+
export function splitLines(code: string): string[] {
|
|
76
|
+
const normalized = code.replace(/\r\n?/g, '\n');
|
|
77
|
+
const trimmed = normalized.endsWith('\n')
|
|
78
|
+
? normalized.slice(0, -1)
|
|
79
|
+
: normalized;
|
|
80
|
+
return trimmed.split('\n');
|
|
81
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export 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
|
} = {
|
|
7
|
-
loading: 'Loading code...',
|
|
8
10
|
copyToClipboard: 'Copy to clipboard',
|
|
9
11
|
copied: 'Copied',
|
|
10
|
-
copiedCode: 'Copied code',
|
|
12
|
+
copiedCode: 'Copied code to clipboard',
|
|
13
|
+
wrapLines: 'Wrap lines',
|
|
14
|
+
unwrapLines: 'Turn off line wrap',
|
|
15
|
+
showMore: 'Show more',
|
|
16
|
+
showLess: 'Show less',
|
|
11
17
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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 const TOKEN_DEFAULTS: Record<string, string> = {
|
|
7
|
+
foreground: 'var(--color-on-surface)',
|
|
8
|
+
background: 'transparent',
|
|
9
|
+
'token-constant': 'var(--color-orange)',
|
|
10
|
+
'token-string': 'var(--color-green)',
|
|
11
|
+
'token-comment': 'var(--color-on-surface-variant)',
|
|
12
|
+
'token-keyword': 'var(--color-purple)',
|
|
13
|
+
'token-parameter': 'var(--color-on-surface)',
|
|
14
|
+
'token-function': 'var(--color-blue)',
|
|
15
|
+
'token-string-expression': 'var(--color-green)',
|
|
16
|
+
'token-punctuation': 'var(--color-on-surface-variant)',
|
|
17
|
+
'token-link': 'var(--color-primary)',
|
|
18
|
+
'token-inserted': 'var(--color-green)',
|
|
19
|
+
'token-deleted': 'var(--color-red)',
|
|
20
|
+
'token-changed': 'var(--color-orange)',
|
|
21
|
+
'ansi-black': 'var(--color-on-surface)',
|
|
22
|
+
'ansi-red': 'var(--color-red)',
|
|
23
|
+
'ansi-green': 'var(--color-green)',
|
|
24
|
+
'ansi-yellow': 'var(--color-yellow)',
|
|
25
|
+
'ansi-blue': 'var(--color-blue)',
|
|
26
|
+
'ansi-magenta': 'var(--color-purple)',
|
|
27
|
+
'ansi-cyan': 'var(--color-tertiary)',
|
|
28
|
+
'ansi-white': 'var(--color-on-surface-variant)',
|
|
29
|
+
'ansi-bright-black': 'var(--color-on-surface-variant)',
|
|
30
|
+
'ansi-bright-red': 'var(--color-red)',
|
|
31
|
+
'ansi-bright-green': 'var(--color-green)',
|
|
32
|
+
'ansi-bright-yellow': 'var(--color-yellow)',
|
|
33
|
+
'ansi-bright-blue': 'var(--color-blue)',
|
|
34
|
+
'ansi-bright-magenta': 'var(--color-purple)',
|
|
35
|
+
'ansi-bright-cyan': 'var(--color-tertiary)',
|
|
36
|
+
'ansi-bright-white': 'var(--color-on-surface)',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** The CSS value for a syntax color: its public variable, falling back to the color role. */
|
|
40
|
+
export function tokenColor(name: string): string {
|
|
41
|
+
return `var(--code-highlighter-${name}, ${TOKEN_DEFAULTS[name]})`;
|
|
42
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -45,7 +45,7 @@ export { List, ListItem } from './list/index.js';
|
|
|
45
45
|
export { Timeline, TimelineItem } from './timeline/index.js';
|
|
46
46
|
export { Item } from './item/index.js';
|
|
47
47
|
|
|
48
|
-
export { CodeHighlighter } from './code-highlighter/index.js';
|
|
48
|
+
export { CodeHighlighter, CodeGroup } from './code-highlighter/index.js';
|
|
49
49
|
export { CodeEditor } from './code-editor/index.js';
|
|
50
50
|
export { HtmlEditor } from './html-editor/index.js';
|
|
51
51
|
export { MarkdownEditor } from './markdown-editor/index.js';
|
|
@@ -57,7 +57,9 @@ export { ColorPicker } from './color-picker/index.js';
|
|
|
57
57
|
export { ColorField } from './color-field/index.js';
|
|
58
58
|
export { ChartDoughnut } from './chart-doughnut/index.js';
|
|
59
59
|
export { ChartPie } from './chart-pie/index.js';
|
|
60
|
-
export { ChartBar
|
|
60
|
+
export { ChartBar } from './chart-bar/index.js';
|
|
61
|
+
export { ChartLine } from './chart-line/index.js';
|
|
62
|
+
export { ChartArea } from './chart-area/index.js';
|
|
61
63
|
export { Table } from './table/index.js';
|
|
62
64
|
export { Pagination } from './pagination/index.js';
|
|
63
65
|
export {
|
package/src/loader.ts
CHANGED
|
@@ -279,6 +279,9 @@ const loaderConfig: LoaderConfig = {
|
|
|
279
279
|
'wc-code-highlighter': {
|
|
280
280
|
importPath: `${distDirectory}/code-highlighter.js`,
|
|
281
281
|
},
|
|
282
|
+
'wc-code-group': {
|
|
283
|
+
importPath: `${distDirectory}/code-group.js`,
|
|
284
|
+
},
|
|
282
285
|
'wc-breadcrumb': {
|
|
283
286
|
CustomElementClass: Breadcrumb,
|
|
284
287
|
},
|
|
@@ -427,8 +430,11 @@ const loaderConfig: LoaderConfig = {
|
|
|
427
430
|
'wc-chart-bar': {
|
|
428
431
|
importPath: `${distDirectory}/chart-bar.js`,
|
|
429
432
|
},
|
|
430
|
-
'wc-chart-
|
|
431
|
-
importPath: `${distDirectory}/chart-
|
|
433
|
+
'wc-chart-line': {
|
|
434
|
+
importPath: `${distDirectory}/chart-line.js`,
|
|
435
|
+
},
|
|
436
|
+
'wc-chart-area': {
|
|
437
|
+
importPath: `${distDirectory}/chart-area.js`,
|
|
432
438
|
},
|
|
433
439
|
'wc-condition-builder': {
|
|
434
440
|
importPath: `${distDirectory}/condition-builder.js`,
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
function range(from: number, to: number): number[] {
|
|
5
|
+
return Array.from({ length: to - from + 1 }, (_, index) => from + index);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds the page list shown by the `full` pagination variant.
|
|
10
|
+
*
|
|
11
|
+
* The list always keeps the first and last page, the current page and `siblings` pages on each
|
|
12
|
+
* side of it, and fills the rest with an ellipsis. It never holds more than
|
|
13
|
+
* `2 * siblings + 5` slots, so the control keeps its width while the user moves through pages.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* getPageItems(5, 24); // [1, 'ellipsis', 4, 5, 6, 'ellipsis', 24]
|
|
17
|
+
* getPageItems(2, 24); // [1, 2, 3, 4, 5, 'ellipsis', 24]
|
|
18
|
+
*/
|
|
19
|
+
export function getPageItems(
|
|
20
|
+
current: number,
|
|
21
|
+
total: number,
|
|
22
|
+
siblings: number = 1,
|
|
23
|
+
): PageItem[] {
|
|
24
|
+
const totalPages = Math.max(1, Math.trunc(total));
|
|
25
|
+
const page = Math.min(Math.max(1, Math.trunc(current)), totalPages);
|
|
26
|
+
const maxSlots = 2 * siblings + 5;
|
|
27
|
+
|
|
28
|
+
if (totalPages <= maxSlots) {
|
|
29
|
+
return range(1, totalPages);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const start = Math.max(page - siblings, 1);
|
|
33
|
+
const end = Math.min(page + siblings, totalPages);
|
|
34
|
+
// A gap of one page is shown as that page; only a gap of two or more becomes an ellipsis.
|
|
35
|
+
const showStartGap = start > 3;
|
|
36
|
+
const showEndGap = end < totalPages - 2;
|
|
37
|
+
// Pages shown on the side without a gap: the window, the edge page and the slot the
|
|
38
|
+
// ellipsis would have taken.
|
|
39
|
+
const edgeCount = 2 * siblings + 3;
|
|
40
|
+
|
|
41
|
+
if (!showStartGap && showEndGap) {
|
|
42
|
+
return [...range(1, edgeCount), 'ellipsis', totalPages];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (showStartGap && !showEndGap) {
|
|
46
|
+
return [1, 'ellipsis', ...range(totalPages - edgeCount + 1, totalPages)];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return [1, 'ellipsis', ...range(start, end), 'ellipsis', totalPages];
|
|
50
|
+
}
|
|
@@ -5,69 +5,184 @@
|
|
|
5
5
|
:host {
|
|
6
6
|
display: block;
|
|
7
7
|
container-type: inline-size;
|
|
8
|
+
--pagination-background: var(--color-surface, #fff);
|
|
9
|
+
--_pagination-target-size: 2.5rem;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
.pagination {
|
|
11
13
|
display: flex;
|
|
12
|
-
align-items: center;
|
|
13
|
-
justify-content: space-between;
|
|
14
14
|
flex-wrap: wrap;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: var(--spacing-100, 0.5rem) var(--spacing-300, 1.5rem);
|
|
17
|
+
padding: var(--spacing-100, 0.5rem) var(--spacing-200, 1rem);
|
|
18
|
+
background: var(--pagination-background);
|
|
19
|
+
color: var(--color-on-surface-variant);
|
|
20
|
+
|
|
21
|
+
@include mixin.get-typography-not-important('body-medium');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Status on the start side, actions on the end side.
|
|
25
|
+
.range {
|
|
26
|
+
flex: 1 1 auto;
|
|
27
|
+
white-space: nowrap;
|
|
28
|
+
font-variant-numeric: tabular-nums;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.page-size {
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: var(--spacing-100, 0.5rem);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.page-size-label {
|
|
38
|
+
white-space: nowrap;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.page-size-select {
|
|
42
|
+
inline-size: 5.5rem;
|
|
43
|
+
--field-height: var(--_pagination-target-size);
|
|
44
|
+
--field-padding-block: 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.controls {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: var(--spacing-050, 0.25rem);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.nav-button {
|
|
54
|
+
--button-container-shape: var(--shape-corner-full);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.page-list {
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
gap: var(--spacing-025, 0.125rem);
|
|
61
|
+
margin: 0;
|
|
62
|
+
padding: 0;
|
|
63
|
+
list-style: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.page-button {
|
|
67
|
+
@include mixin.reset-button-styles;
|
|
68
|
+
@include mixin.get-typography-not-important('label-large');
|
|
69
|
+
|
|
70
|
+
display: inline-flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
min-inline-size: var(--_pagination-target-size);
|
|
74
|
+
block-size: var(--_pagination-target-size);
|
|
75
|
+
padding: 0 var(--spacing-100, 0.5rem);
|
|
76
|
+
border-radius: var(--shape-corner-full);
|
|
77
|
+
color: var(--color-on-surface-variant);
|
|
78
|
+
font-variant-numeric: tabular-nums;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
transition: background-color var(--duration-short2, 100ms) ease;
|
|
81
|
+
|
|
82
|
+
&:hover {
|
|
83
|
+
background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
24
84
|
}
|
|
25
85
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
align-items: center;
|
|
29
|
-
gap: var(--spacing-100, 0.5rem);
|
|
30
|
-
min-inline-size: max-content;
|
|
86
|
+
&:active {
|
|
87
|
+
background: color-mix(in srgb, var(--color-on-surface) 12%, transparent);
|
|
31
88
|
}
|
|
32
89
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
white-space: nowrap;
|
|
90
|
+
&:focus-visible {
|
|
91
|
+
outline: 2px solid var(--color-primary);
|
|
92
|
+
outline-offset: 2px;
|
|
37
93
|
}
|
|
38
94
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
95
|
+
&.current {
|
|
96
|
+
background: var(--color-secondary-container);
|
|
97
|
+
color: var(--color-on-secondary-container);
|
|
98
|
+
cursor: default;
|
|
43
99
|
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.page-ellipsis {
|
|
103
|
+
display: inline-flex;
|
|
104
|
+
align-items: center;
|
|
105
|
+
justify-content: center;
|
|
106
|
+
min-inline-size: var(--_pagination-target-size);
|
|
107
|
+
block-size: var(--_pagination-target-size);
|
|
108
|
+
user-select: none;
|
|
109
|
+
}
|
|
44
110
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
111
|
+
.page-jump {
|
|
112
|
+
display: inline-flex;
|
|
113
|
+
align-items: center;
|
|
114
|
+
gap: var(--spacing-100, 0.5rem);
|
|
115
|
+
padding-inline: var(--spacing-050, 0.25rem);
|
|
116
|
+
white-space: nowrap;
|
|
117
|
+
font-variant-numeric: tabular-nums;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.page-input {
|
|
121
|
+
@include mixin.get-typography-not-important('body-medium');
|
|
122
|
+
|
|
123
|
+
inline-size: 3.5rem;
|
|
124
|
+
block-size: 2rem;
|
|
125
|
+
padding: 0 var(--spacing-100, 0.5rem);
|
|
126
|
+
border: 1px solid var(--color-outline-variant);
|
|
127
|
+
border-radius: var(--shape-corner-small);
|
|
128
|
+
background: var(--color-surface);
|
|
129
|
+
color: var(--color-on-surface);
|
|
130
|
+
text-align: center;
|
|
131
|
+
font-variant-numeric: tabular-nums;
|
|
132
|
+
appearance: textfield;
|
|
133
|
+
|
|
134
|
+
&::-webkit-inner-spin-button,
|
|
135
|
+
&::-webkit-outer-spin-button {
|
|
136
|
+
appearance: none;
|
|
137
|
+
margin: 0;
|
|
57
138
|
}
|
|
58
139
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
color: var(--color-on-surface-variant);
|
|
140
|
+
&:hover {
|
|
141
|
+
border-color: var(--color-outline);
|
|
62
142
|
}
|
|
63
143
|
|
|
64
|
-
|
|
144
|
+
&:focus-visible {
|
|
145
|
+
outline: 2px solid var(--color-primary);
|
|
146
|
+
outline-offset: -1px;
|
|
147
|
+
border-color: transparent;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// In the full variant the jump field is the narrow-screen fallback for the page list.
|
|
152
|
+
.variant-full .page-jump {
|
|
153
|
+
display: none;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@container (max-width: 40rem) {
|
|
157
|
+
.variant-full .page-list {
|
|
158
|
+
display: none;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.variant-full .page-jump {
|
|
65
162
|
display: inline-flex;
|
|
66
|
-
align-items: center;
|
|
67
|
-
gap: var(--spacing-025, 0.125rem);
|
|
68
163
|
}
|
|
69
164
|
|
|
70
|
-
.
|
|
71
|
-
|
|
165
|
+
.page-size-label {
|
|
166
|
+
display: none;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Phone width: range and rows per page share the first line, page controls take the second.
|
|
171
|
+
@container (max-width: 26rem) {
|
|
172
|
+
.controls {
|
|
173
|
+
flex-basis: 100%;
|
|
174
|
+
justify-content: space-between;
|
|
72
175
|
}
|
|
73
176
|
}
|
|
177
|
+
|
|
178
|
+
.visually-hidden {
|
|
179
|
+
position: absolute;
|
|
180
|
+
inline-size: 1px;
|
|
181
|
+
block-size: 1px;
|
|
182
|
+
margin: -1px;
|
|
183
|
+
padding: 0;
|
|
184
|
+
overflow: hidden;
|
|
185
|
+
clip-path: inset(50%);
|
|
186
|
+
white-space: nowrap;
|
|
187
|
+
border: 0;
|
|
188
|
+
}
|