@mintplayer/web-components 2.10.0 → 2.12.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/accordion/index.mjs +4 -4
- package/charts/core/index.d.ts +1 -0
- package/charts/core/index.mjs +19 -0
- package/charts/core/src/arc.d.ts +28 -0
- package/charts/core/src/color.d.ts +11 -0
- package/charts/core/src/hierarchy-layout.d.ts +68 -0
- package/charts/core/src/index.d.ts +5 -0
- package/charts/core/src/scale.d.ts +21 -0
- package/charts/core/src/types.d.ts +52 -0
- package/charts/hierarchy/index.d.ts +1 -0
- package/charts/hierarchy/index.mjs +816 -0
- package/charts/hierarchy/src/components/index.d.ts +1 -0
- package/charts/hierarchy/src/components/mp-hierarchy-chart.d.ts +188 -0
- package/charts/hierarchy/src/index.d.ts +2 -0
- package/charts/hierarchy/src/styles/hierarchy-chart.styles.d.ts +2 -0
- package/charts/hierarchy/src/styles/index.d.ts +1 -0
- package/charts/sparkline/index.d.ts +1 -0
- package/charts/sparkline/index.mjs +162 -0
- package/charts/sparkline/src/components/index.d.ts +1 -0
- package/charts/sparkline/src/components/mp-sparkline.d.ts +51 -0
- package/charts/sparkline/src/index.d.ts +1 -0
- package/charts/sparkline/src/styles/index.d.ts +1 -0
- package/charts/sparkline/src/styles/sparkline.styles.d.ts +2 -0
- package/charts/trend/index.d.ts +1 -0
- package/charts/trend/index.mjs +432 -0
- package/charts/trend/src/components/index.d.ts +1 -0
- package/charts/trend/src/components/mp-trend-chart.d.ts +104 -0
- package/charts/trend/src/index.d.ts +2 -0
- package/charts/trend/src/styles/index.d.ts +1 -0
- package/charts/trend/src/styles/trend-chart.styles.d.ts +2 -0
- package/checkbox/index.mjs +1 -1
- package/chunks/color-5yPBn70k.mjs +179 -0
- package/chunks/{form-check.styles-jBlHetYX.mjs → form-check.styles-B0pxJ6YC.mjs} +2 -2
- package/chunks/{form-control.styles-BOTBdmvg.mjs → form-control.styles-C3j87Sn3.mjs} +1 -1
- package/chunks/{mp-checkbox-6EJwdUIn.mjs → mp-checkbox-CzwS7Y_t.mjs} +2 -2
- package/chunks/{mp-datatable-25O1GtvU.mjs → mp-datatable-GmKqaN8y.mjs} +1 -1
- package/chunks/{mp-radio-DvKgrTFL.mjs → mp-radio-cL46sUA0.mjs} +2 -2
- package/chunks/{mp-select-lHP00OBH.mjs → mp-select-BNrbPwN4.mjs} +1 -1
- package/chunks/{mp-toggle-button-C4Loq_p4.mjs → mp-toggle-button-eo_aTQtu.mjs} +32 -32
- package/chunks/scale-B0bRUdc7.mjs +91 -0
- package/code-snippet/index.mjs +788 -176
- package/code-snippet/src/core/highlighter.d.ts +39 -0
- package/code-snippet/src/core/split-lines.d.ts +44 -0
- package/code-snippet/src/hljs-loaders.generated.d.ts +14 -0
- package/code-snippet/src/index.d.ts +2 -0
- package/code-snippet/src/mp-code-snippet.element.d.ts +172 -2
- package/code-snippet/src/styles/code-snippet.styles.d.ts +2 -0
- package/code-snippet/src/styles/index.d.ts +1 -0
- package/code-snippet/src/types/code-line-annotation.d.ts +29 -0
- package/code-snippet/src/types/index.d.ts +1 -0
- package/datatable/index.mjs +1 -1
- package/file-manager/index.mjs +1 -1
- package/package.json +17 -1
- package/phone-input/index.mjs +26 -12
- package/phone-input/src/components/mp-phone-input.d.ts +9 -0
- package/query-builder/index.mjs +101 -101
- package/radio/index.mjs +1 -1
- package/radio-group/index.mjs +1 -1
- package/scheduler/index.mjs +3 -3
- package/select/index.mjs +1 -1
- package/toggle-button/index.mjs +1 -1
package/code-snippet/index.mjs
CHANGED
|
@@ -1,137 +1,565 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as
|
|
3
|
-
import { unsafeHTML as
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
the master branch's ngx-highlightjs setup loads for the Angular
|
|
19
|
-
demo. That theme has only a dark variant; the code-snippet
|
|
20
|
-
intentionally renders dark-on-light-page like in an IDE, so the
|
|
21
|
-
host's own background is fixed (no Bootstrap data-bs-theme
|
|
22
|
-
branch). Tokens not explicitly mapped (e.g. .hljs-attr inside
|
|
23
|
-
.hljs-tag) inherit from their parent, matching production. */
|
|
24
|
-
:host {
|
|
25
|
-
display: block;
|
|
26
|
-
position: relative;
|
|
27
|
-
font-family: var(--bs-font-monospace);
|
|
28
|
-
background: #2b2b2b;
|
|
29
|
-
color: #f8f8f2;
|
|
30
|
-
border: 1px solid var(--bs-border-color);
|
|
31
|
-
border-radius: var(--bs-border-radius);
|
|
32
|
-
overflow: hidden;
|
|
33
|
-
}
|
|
1
|
+
import { unsafeCSS as j, LitElement as x, nothing as c, html as h } from "lit";
|
|
2
|
+
import { property as s, state as u } from "lit/decorators.js";
|
|
3
|
+
import { unsafeHTML as L } from "lit/directives/unsafe-html.js";
|
|
4
|
+
import d from "highlight.js/lib/core";
|
|
5
|
+
const $ = j(`@charset "UTF-8";
|
|
6
|
+
:host {
|
|
7
|
+
--mp-code-bg: light-dark(#fefefe, #2b2b2b);
|
|
8
|
+
--mp-code-fg: light-dark(#545454, #f8f8f2);
|
|
9
|
+
--mp-code-comment: light-dark(#696969, #d4d0ab);
|
|
10
|
+
--mp-code-red: light-dark(#d91e18, #ffa07a);
|
|
11
|
+
--mp-code-orange: light-dark(#aa5d00, #f5ab35);
|
|
12
|
+
--mp-code-yellow: light-dark(#7c4a03, #ffd700);
|
|
13
|
+
--mp-code-green: light-dark(#008000, #abe338);
|
|
14
|
+
--mp-code-blue: light-dark(#007faa, #00e0e0);
|
|
15
|
+
--mp-code-purple: light-dark(#7928a1, #dcc6e0);
|
|
16
|
+
--mp-code-punctuation: light-dark(#6a6a66, #c8c8c2);
|
|
17
|
+
}
|
|
34
18
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
tab-size: 2;
|
|
41
|
-
}
|
|
19
|
+
/* Comment */
|
|
20
|
+
.hljs-comment,
|
|
21
|
+
.hljs-quote {
|
|
22
|
+
color: var(--mp-code-comment);
|
|
23
|
+
}
|
|
42
24
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
25
|
+
/* Red */
|
|
26
|
+
.hljs-variable,
|
|
27
|
+
.hljs-template-variable,
|
|
28
|
+
.hljs-tag,
|
|
29
|
+
.hljs-name,
|
|
30
|
+
.hljs-selector-id,
|
|
31
|
+
.hljs-selector-class,
|
|
32
|
+
.hljs-regexp,
|
|
33
|
+
.hljs-deletion {
|
|
34
|
+
color: var(--mp-code-red);
|
|
35
|
+
}
|
|
50
36
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
cursor: pointer;
|
|
62
|
-
opacity: 0.85;
|
|
63
|
-
transition: opacity 120ms ease;
|
|
64
|
-
}
|
|
37
|
+
/* Orange */
|
|
38
|
+
.hljs-number,
|
|
39
|
+
.hljs-built_in,
|
|
40
|
+
.hljs-literal,
|
|
41
|
+
.hljs-type,
|
|
42
|
+
.hljs-params,
|
|
43
|
+
.hljs-meta,
|
|
44
|
+
.hljs-link {
|
|
45
|
+
color: var(--mp-code-orange);
|
|
46
|
+
}
|
|
65
47
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
48
|
+
/* Yellow */
|
|
49
|
+
.hljs-attribute,
|
|
50
|
+
.hljs-attr {
|
|
51
|
+
color: var(--mp-code-yellow);
|
|
52
|
+
}
|
|
70
53
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
background: var(--bs-success);
|
|
79
|
-
border-radius: var(--bs-border-radius-sm);
|
|
80
|
-
opacity: 0;
|
|
81
|
-
transform: translateY(0.5rem);
|
|
82
|
-
transition: opacity 150ms ease, transform 150ms ease;
|
|
83
|
-
pointer-events: none;
|
|
84
|
-
}
|
|
54
|
+
/* Green */
|
|
55
|
+
.hljs-string,
|
|
56
|
+
.hljs-symbol,
|
|
57
|
+
.hljs-bullet,
|
|
58
|
+
.hljs-addition {
|
|
59
|
+
color: var(--mp-code-green);
|
|
60
|
+
}
|
|
85
61
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
62
|
+
/* Muted (JSON punctuation — braces, brackets, commas, colons) */
|
|
63
|
+
.hljs-punctuation {
|
|
64
|
+
color: var(--mp-code-punctuation);
|
|
65
|
+
}
|
|
90
66
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
67
|
+
/* Blue */
|
|
68
|
+
.hljs-title,
|
|
69
|
+
.hljs-section {
|
|
70
|
+
color: var(--mp-code-blue);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* Purple */
|
|
74
|
+
.hljs-keyword,
|
|
75
|
+
.hljs-selector-tag {
|
|
76
|
+
color: var(--mp-code-purple);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.hljs-emphasis {
|
|
80
|
+
font-style: italic;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.hljs-strong {
|
|
84
|
+
font-weight: bold;
|
|
85
|
+
}`), C = j(`:host {
|
|
86
|
+
display: flex;
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
position: relative;
|
|
89
|
+
font-family: var(--bs-font-monospace);
|
|
90
|
+
background: var(--mp-code-bg);
|
|
91
|
+
color: var(--mp-code-fg);
|
|
92
|
+
border: 1px solid var(--bs-border-color);
|
|
93
|
+
border-radius: var(--bs-border-radius);
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
:host([theme=light]) {
|
|
98
|
+
color-scheme: only light;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
:host([theme=dark]) {
|
|
102
|
+
color-scheme: only dark;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
pre {
|
|
106
|
+
margin: 0;
|
|
107
|
+
padding: 2.25rem 0 1rem;
|
|
108
|
+
overflow: auto;
|
|
109
|
+
flex: 1 1 auto;
|
|
110
|
+
min-height: 0;
|
|
111
|
+
tab-size: 2;
|
|
112
|
+
direction: ltr;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
code {
|
|
116
|
+
display: grid;
|
|
117
|
+
grid-template-columns: auto auto auto 1fr;
|
|
118
|
+
font-family: inherit;
|
|
119
|
+
font-size: 0.875rem;
|
|
120
|
+
line-height: 1.5;
|
|
121
|
+
color: inherit;
|
|
122
|
+
min-width: max-content;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.line {
|
|
126
|
+
display: grid;
|
|
127
|
+
grid-template-columns: subgrid;
|
|
128
|
+
grid-column: 1/-1;
|
|
129
|
+
white-space: normal;
|
|
130
|
+
min-height: 1.5em;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.line-text {
|
|
134
|
+
grid-column: 4;
|
|
135
|
+
white-space: pre;
|
|
136
|
+
padding-inline: 1rem 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.line-number {
|
|
140
|
+
grid-column: 1;
|
|
141
|
+
box-sizing: content-box;
|
|
142
|
+
min-width: 2.5ch;
|
|
143
|
+
padding-inline: 0.375rem;
|
|
144
|
+
text-align: right;
|
|
145
|
+
user-select: none;
|
|
146
|
+
opacity: 0.55;
|
|
147
|
+
position: sticky;
|
|
148
|
+
left: 0;
|
|
149
|
+
background: var(--mp-code-bg);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.line.active {
|
|
153
|
+
outline: 2px solid var(--bs-primary);
|
|
154
|
+
outline-offset: -2px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.line-mark {
|
|
158
|
+
padding-inline-start: 0.375rem;
|
|
159
|
+
text-align: right;
|
|
160
|
+
user-select: none;
|
|
161
|
+
font-size: 0.85em;
|
|
162
|
+
font-variant-numeric: tabular-nums;
|
|
163
|
+
opacity: 0.75;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.line-mark:not(.secondary) {
|
|
167
|
+
grid-column: 2;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.line-mark.secondary {
|
|
171
|
+
grid-column: 3;
|
|
172
|
+
padding-inline-end: 0.375rem;
|
|
173
|
+
color: var(--mp-code-mark-secondary, var(--mp-code-yellow));
|
|
174
|
+
opacity: 0.9;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
a.line-number {
|
|
178
|
+
color: inherit;
|
|
179
|
+
text-decoration: none;
|
|
180
|
+
cursor: pointer;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
a.line-number:hover {
|
|
184
|
+
text-decoration: underline;
|
|
185
|
+
opacity: 1;
|
|
186
|
+
}
|
|
102
187
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
188
|
+
a.line-number:focus-visible {
|
|
189
|
+
outline: 2px solid var(--bs-primary);
|
|
190
|
+
outline-offset: -2px;
|
|
191
|
+
opacity: 1;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
:host([wrap]) code {
|
|
195
|
+
min-width: 0;
|
|
196
|
+
}
|
|
197
|
+
:host([wrap]) .line-text {
|
|
198
|
+
white-space: pre-wrap;
|
|
199
|
+
overflow-wrap: anywhere;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.copy {
|
|
203
|
+
position: absolute;
|
|
204
|
+
top: 0.5rem;
|
|
205
|
+
right: 0.5rem;
|
|
206
|
+
padding: 0.25rem 0.75rem;
|
|
207
|
+
font-size: 0.75rem;
|
|
208
|
+
color: var(--bs-body-color);
|
|
209
|
+
background: var(--bs-body-bg);
|
|
210
|
+
border: 1px solid var(--bs-border-color);
|
|
211
|
+
border-radius: var(--bs-border-radius-sm);
|
|
212
|
+
cursor: pointer;
|
|
213
|
+
opacity: 0.85;
|
|
214
|
+
transition: opacity 120ms ease;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.copy:hover,
|
|
218
|
+
.copy:focus-visible {
|
|
219
|
+
opacity: 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.toast {
|
|
223
|
+
position: absolute;
|
|
224
|
+
bottom: 0.5rem;
|
|
225
|
+
right: 0.5rem;
|
|
226
|
+
padding: 0.25rem 0.75rem;
|
|
227
|
+
font-size: 0.75rem;
|
|
228
|
+
color: var(--bs-body-bg);
|
|
229
|
+
background: var(--bs-success);
|
|
230
|
+
border-radius: var(--bs-border-radius-sm);
|
|
231
|
+
opacity: 0;
|
|
232
|
+
transform: translateY(0.5rem);
|
|
233
|
+
transition: opacity 150ms ease, transform 150ms ease;
|
|
234
|
+
pointer-events: none;
|
|
235
|
+
user-select: none;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.toast.visible {
|
|
239
|
+
opacity: 1;
|
|
240
|
+
transform: translateY(0);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@media (prefers-reduced-motion: reduce) {
|
|
244
|
+
.copy,
|
|
245
|
+
.toast {
|
|
246
|
+
transition: none;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
.sr-only {
|
|
250
|
+
position: absolute;
|
|
251
|
+
width: 1px;
|
|
252
|
+
height: 1px;
|
|
253
|
+
padding: 0;
|
|
254
|
+
margin: -1px;
|
|
255
|
+
overflow: hidden;
|
|
256
|
+
clip: rect(0, 0, 0, 0);
|
|
257
|
+
white-space: nowrap;
|
|
258
|
+
border: 0;
|
|
259
|
+
user-select: none;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
slot {
|
|
263
|
+
display: none;
|
|
264
|
+
}`);
|
|
265
|
+
function T(t) {
|
|
266
|
+
return t.replace(/\r\n?/g, `
|
|
267
|
+
`).replace(/\n$/, "");
|
|
268
|
+
}
|
|
269
|
+
function S(t) {
|
|
270
|
+
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
271
|
+
}
|
|
272
|
+
function y(t) {
|
|
273
|
+
const e = [], i = [];
|
|
274
|
+
let n = "", a = 0;
|
|
275
|
+
for (; a < t.length; ) {
|
|
276
|
+
const l = t[a];
|
|
277
|
+
if (l === "<") {
|
|
278
|
+
const p = t.indexOf(">", a);
|
|
279
|
+
if (p === -1) {
|
|
280
|
+
n += t.slice(a);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
const m = t.slice(a, p + 1);
|
|
284
|
+
m[1] === "/" ? i.pop() : t[p - 1] !== "/" && i.push(m), n += m, a = p + 1;
|
|
285
|
+
} else l === `
|
|
286
|
+
` ? (e.push(n + "</span>".repeat(i.length)), n = i.join(""), a++) : (n += l, a++);
|
|
287
|
+
}
|
|
288
|
+
return e.push(n + "</span>".repeat(i.length)), e;
|
|
289
|
+
}
|
|
290
|
+
const k = {
|
|
291
|
+
atom: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
292
|
+
bash: () => import("highlight.js/lib/languages/bash").then((t) => t.default),
|
|
293
|
+
c: () => import("highlight.js/lib/languages/c").then((t) => t.default),
|
|
294
|
+
"c#": () => import("highlight.js/lib/languages/csharp").then((t) => t.default),
|
|
295
|
+
"c++": () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
296
|
+
cc: () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
297
|
+
cjs: () => import("highlight.js/lib/languages/javascript").then((t) => t.default),
|
|
298
|
+
console: () => import("highlight.js/lib/languages/shell").then((t) => t.default),
|
|
299
|
+
cpp: () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
300
|
+
cs: () => import("highlight.js/lib/languages/csharp").then((t) => t.default),
|
|
301
|
+
csharp: () => import("highlight.js/lib/languages/csharp").then((t) => t.default),
|
|
302
|
+
css: () => import("highlight.js/lib/languages/css").then((t) => t.default),
|
|
303
|
+
cts: () => import("highlight.js/lib/languages/typescript").then((t) => t.default),
|
|
304
|
+
cxx: () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
305
|
+
diff: () => import("highlight.js/lib/languages/diff").then((t) => t.default),
|
|
306
|
+
gemspec: () => import("highlight.js/lib/languages/ruby").then((t) => t.default),
|
|
307
|
+
go: () => import("highlight.js/lib/languages/go").then((t) => t.default),
|
|
308
|
+
golang: () => import("highlight.js/lib/languages/go").then((t) => t.default),
|
|
309
|
+
gql: () => import("highlight.js/lib/languages/graphql").then((t) => t.default),
|
|
310
|
+
graphql: () => import("highlight.js/lib/languages/graphql").then((t) => t.default),
|
|
311
|
+
gyp: () => import("highlight.js/lib/languages/python").then((t) => t.default),
|
|
312
|
+
h: () => import("highlight.js/lib/languages/c").then((t) => t.default),
|
|
313
|
+
"h++": () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
314
|
+
hh: () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
315
|
+
hpp: () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
316
|
+
html: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
317
|
+
hxx: () => import("highlight.js/lib/languages/cpp").then((t) => t.default),
|
|
318
|
+
ini: () => import("highlight.js/lib/languages/ini").then((t) => t.default),
|
|
319
|
+
ipython: () => import("highlight.js/lib/languages/python").then((t) => t.default),
|
|
320
|
+
irb: () => import("highlight.js/lib/languages/ruby").then((t) => t.default),
|
|
321
|
+
java: () => import("highlight.js/lib/languages/java").then((t) => t.default),
|
|
322
|
+
javascript: () => import("highlight.js/lib/languages/javascript").then((t) => t.default),
|
|
323
|
+
js: () => import("highlight.js/lib/languages/javascript").then((t) => t.default),
|
|
324
|
+
json: () => import("highlight.js/lib/languages/json").then((t) => t.default),
|
|
325
|
+
json5: () => import("highlight.js/lib/languages/json").then((t) => t.default),
|
|
326
|
+
jsonc: () => import("highlight.js/lib/languages/json").then((t) => t.default),
|
|
327
|
+
jsp: () => import("highlight.js/lib/languages/java").then((t) => t.default),
|
|
328
|
+
jsx: () => import("highlight.js/lib/languages/javascript").then((t) => t.default),
|
|
329
|
+
kotlin: () => import("highlight.js/lib/languages/kotlin").then((t) => t.default),
|
|
330
|
+
kt: () => import("highlight.js/lib/languages/kotlin").then((t) => t.default),
|
|
331
|
+
kts: () => import("highlight.js/lib/languages/kotlin").then((t) => t.default),
|
|
332
|
+
less: () => import("highlight.js/lib/languages/less").then((t) => t.default),
|
|
333
|
+
lua: () => import("highlight.js/lib/languages/lua").then((t) => t.default),
|
|
334
|
+
mak: () => import("highlight.js/lib/languages/makefile").then((t) => t.default),
|
|
335
|
+
make: () => import("highlight.js/lib/languages/makefile").then((t) => t.default),
|
|
336
|
+
makefile: () => import("highlight.js/lib/languages/makefile").then((t) => t.default),
|
|
337
|
+
markdown: () => import("highlight.js/lib/languages/markdown").then((t) => t.default),
|
|
338
|
+
md: () => import("highlight.js/lib/languages/markdown").then((t) => t.default),
|
|
339
|
+
mjs: () => import("highlight.js/lib/languages/javascript").then((t) => t.default),
|
|
340
|
+
mk: () => import("highlight.js/lib/languages/makefile").then((t) => t.default),
|
|
341
|
+
mkd: () => import("highlight.js/lib/languages/markdown").then((t) => t.default),
|
|
342
|
+
mkdown: () => import("highlight.js/lib/languages/markdown").then((t) => t.default),
|
|
343
|
+
mm: () => import("highlight.js/lib/languages/objectivec").then((t) => t.default),
|
|
344
|
+
mts: () => import("highlight.js/lib/languages/typescript").then((t) => t.default),
|
|
345
|
+
"obj-c": () => import("highlight.js/lib/languages/objectivec").then((t) => t.default),
|
|
346
|
+
"obj-c++": () => import("highlight.js/lib/languages/objectivec").then((t) => t.default),
|
|
347
|
+
objc: () => import("highlight.js/lib/languages/objectivec").then((t) => t.default),
|
|
348
|
+
"objective-c++": () => import("highlight.js/lib/languages/objectivec").then((t) => t.default),
|
|
349
|
+
objectivec: () => import("highlight.js/lib/languages/objectivec").then((t) => t.default),
|
|
350
|
+
patch: () => import("highlight.js/lib/languages/diff").then((t) => t.default),
|
|
351
|
+
perl: () => import("highlight.js/lib/languages/perl").then((t) => t.default),
|
|
352
|
+
php: () => import("highlight.js/lib/languages/php").then((t) => t.default),
|
|
353
|
+
"php-template": () => import("highlight.js/lib/languages/php-template").then((t) => t.default),
|
|
354
|
+
pl: () => import("highlight.js/lib/languages/perl").then((t) => t.default),
|
|
355
|
+
plaintext: () => import("highlight.js/lib/languages/plaintext").then((t) => t.default),
|
|
356
|
+
plist: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
357
|
+
pluto: () => import("highlight.js/lib/languages/lua").then((t) => t.default),
|
|
358
|
+
pm: () => import("highlight.js/lib/languages/perl").then((t) => t.default),
|
|
359
|
+
podspec: () => import("highlight.js/lib/languages/ruby").then((t) => t.default),
|
|
360
|
+
py: () => import("highlight.js/lib/languages/python").then((t) => t.default),
|
|
361
|
+
pycon: () => import("highlight.js/lib/languages/python-repl").then((t) => t.default),
|
|
362
|
+
python: () => import("highlight.js/lib/languages/python").then((t) => t.default),
|
|
363
|
+
"python-repl": () => import("highlight.js/lib/languages/python-repl").then((t) => t.default),
|
|
364
|
+
r: () => import("highlight.js/lib/languages/r").then((t) => t.default),
|
|
365
|
+
rb: () => import("highlight.js/lib/languages/ruby").then((t) => t.default),
|
|
366
|
+
rs: () => import("highlight.js/lib/languages/rust").then((t) => t.default),
|
|
367
|
+
rss: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
368
|
+
ruby: () => import("highlight.js/lib/languages/ruby").then((t) => t.default),
|
|
369
|
+
rust: () => import("highlight.js/lib/languages/rust").then((t) => t.default),
|
|
370
|
+
scss: () => import("highlight.js/lib/languages/scss").then((t) => t.default),
|
|
371
|
+
sh: () => import("highlight.js/lib/languages/bash").then((t) => t.default),
|
|
372
|
+
shell: () => import("highlight.js/lib/languages/shell").then((t) => t.default),
|
|
373
|
+
shellsession: () => import("highlight.js/lib/languages/shell").then((t) => t.default),
|
|
374
|
+
sql: () => import("highlight.js/lib/languages/sql").then((t) => t.default),
|
|
375
|
+
svg: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
376
|
+
swift: () => import("highlight.js/lib/languages/swift").then((t) => t.default),
|
|
377
|
+
text: () => import("highlight.js/lib/languages/plaintext").then((t) => t.default),
|
|
378
|
+
thor: () => import("highlight.js/lib/languages/ruby").then((t) => t.default),
|
|
379
|
+
toml: () => import("highlight.js/lib/languages/ini").then((t) => t.default),
|
|
380
|
+
ts: () => import("highlight.js/lib/languages/typescript").then((t) => t.default),
|
|
381
|
+
tsx: () => import("highlight.js/lib/languages/typescript").then((t) => t.default),
|
|
382
|
+
txt: () => import("highlight.js/lib/languages/plaintext").then((t) => t.default),
|
|
383
|
+
typescript: () => import("highlight.js/lib/languages/typescript").then((t) => t.default),
|
|
384
|
+
vb: () => import("highlight.js/lib/languages/vbnet").then((t) => t.default),
|
|
385
|
+
vbnet: () => import("highlight.js/lib/languages/vbnet").then((t) => t.default),
|
|
386
|
+
wasm: () => import("highlight.js/lib/languages/wasm").then((t) => t.default),
|
|
387
|
+
wsf: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
388
|
+
xhtml: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
389
|
+
xjb: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
390
|
+
xml: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
391
|
+
xsd: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
392
|
+
xsl: () => import("highlight.js/lib/languages/xml").then((t) => t.default),
|
|
393
|
+
yaml: () => import("highlight.js/lib/languages/yaml").then((t) => t.default),
|
|
394
|
+
yml: () => import("highlight.js/lib/languages/yaml").then((t) => t.default),
|
|
395
|
+
zsh: () => import("highlight.js/lib/languages/bash").then((t) => t.default)
|
|
396
|
+
}, H = {
|
|
397
|
+
atom: "xml",
|
|
398
|
+
bash: "bash",
|
|
399
|
+
c: "c",
|
|
400
|
+
"c#": "csharp",
|
|
401
|
+
"c++": "cpp",
|
|
402
|
+
cc: "cpp",
|
|
403
|
+
cjs: "javascript",
|
|
404
|
+
console: "shell",
|
|
405
|
+
cpp: "cpp",
|
|
406
|
+
cs: "csharp",
|
|
407
|
+
csharp: "csharp",
|
|
408
|
+
css: "css",
|
|
409
|
+
cts: "typescript",
|
|
410
|
+
cxx: "cpp",
|
|
411
|
+
diff: "diff",
|
|
412
|
+
gemspec: "ruby",
|
|
413
|
+
go: "go",
|
|
414
|
+
golang: "go",
|
|
415
|
+
gql: "graphql",
|
|
416
|
+
graphql: "graphql",
|
|
417
|
+
gyp: "python",
|
|
418
|
+
h: "c",
|
|
419
|
+
"h++": "cpp",
|
|
420
|
+
hh: "cpp",
|
|
421
|
+
hpp: "cpp",
|
|
422
|
+
html: "xml",
|
|
423
|
+
hxx: "cpp",
|
|
424
|
+
ini: "ini",
|
|
425
|
+
ipython: "python",
|
|
426
|
+
irb: "ruby",
|
|
427
|
+
java: "java",
|
|
428
|
+
javascript: "javascript",
|
|
429
|
+
js: "javascript",
|
|
430
|
+
json: "json",
|
|
431
|
+
json5: "json",
|
|
432
|
+
jsonc: "json",
|
|
433
|
+
jsp: "java",
|
|
434
|
+
jsx: "javascript",
|
|
435
|
+
kotlin: "kotlin",
|
|
436
|
+
kt: "kotlin",
|
|
437
|
+
kts: "kotlin",
|
|
438
|
+
less: "less",
|
|
439
|
+
lua: "lua",
|
|
440
|
+
mak: "makefile",
|
|
441
|
+
make: "makefile",
|
|
442
|
+
makefile: "makefile",
|
|
443
|
+
markdown: "markdown",
|
|
444
|
+
md: "markdown",
|
|
445
|
+
mjs: "javascript",
|
|
446
|
+
mk: "makefile",
|
|
447
|
+
mkd: "markdown",
|
|
448
|
+
mkdown: "markdown",
|
|
449
|
+
mm: "objectivec",
|
|
450
|
+
mts: "typescript",
|
|
451
|
+
"obj-c": "objectivec",
|
|
452
|
+
"obj-c++": "objectivec",
|
|
453
|
+
objc: "objectivec",
|
|
454
|
+
"objective-c++": "objectivec",
|
|
455
|
+
objectivec: "objectivec",
|
|
456
|
+
patch: "diff",
|
|
457
|
+
perl: "perl",
|
|
458
|
+
php: "php",
|
|
459
|
+
"php-template": "php-template",
|
|
460
|
+
pl: "perl",
|
|
461
|
+
plaintext: "plaintext",
|
|
462
|
+
plist: "xml",
|
|
463
|
+
pluto: "lua",
|
|
464
|
+
pm: "perl",
|
|
465
|
+
podspec: "ruby",
|
|
466
|
+
py: "python",
|
|
467
|
+
pycon: "python-repl",
|
|
468
|
+
python: "python",
|
|
469
|
+
"python-repl": "python-repl",
|
|
470
|
+
r: "r",
|
|
471
|
+
rb: "ruby",
|
|
472
|
+
rs: "rust",
|
|
473
|
+
rss: "xml",
|
|
474
|
+
ruby: "ruby",
|
|
475
|
+
rust: "rust",
|
|
476
|
+
scss: "scss",
|
|
477
|
+
sh: "bash",
|
|
478
|
+
shell: "shell",
|
|
479
|
+
shellsession: "shell",
|
|
480
|
+
sql: "sql",
|
|
481
|
+
svg: "xml",
|
|
482
|
+
swift: "swift",
|
|
483
|
+
text: "plaintext",
|
|
484
|
+
thor: "ruby",
|
|
485
|
+
toml: "ini",
|
|
486
|
+
ts: "typescript",
|
|
487
|
+
tsx: "typescript",
|
|
488
|
+
txt: "plaintext",
|
|
489
|
+
typescript: "typescript",
|
|
490
|
+
vb: "vbnet",
|
|
491
|
+
vbnet: "vbnet",
|
|
492
|
+
wasm: "wasm",
|
|
493
|
+
wsf: "xml",
|
|
494
|
+
xhtml: "xml",
|
|
495
|
+
xjb: "xml",
|
|
496
|
+
xml: "xml",
|
|
497
|
+
xsd: "xml",
|
|
498
|
+
xsl: "xml",
|
|
499
|
+
yaml: "yaml",
|
|
500
|
+
yml: "yaml",
|
|
501
|
+
zsh: "bash"
|
|
502
|
+
}, f = /* @__PURE__ */ new Map(), w = (t) => t in k, b = (t) => d.getLanguage(t) != null;
|
|
503
|
+
function K(t, e) {
|
|
504
|
+
d.registerLanguage(t, e);
|
|
505
|
+
}
|
|
506
|
+
function P(t) {
|
|
507
|
+
return b(t) || w(t);
|
|
508
|
+
}
|
|
509
|
+
async function q(t) {
|
|
510
|
+
if (b(t)) return "ready";
|
|
511
|
+
if (!w(t)) return "unknown-language";
|
|
512
|
+
const e = H[t];
|
|
513
|
+
let i = f.get(e);
|
|
514
|
+
return i || (i = k[t]().then((n) => (b(e) || d.registerLanguage(e, n), !0)).catch(() => (f.delete(e), !1)), f.set(e, i)), await i ? "ready" : "load-failed";
|
|
515
|
+
}
|
|
516
|
+
let g = null;
|
|
517
|
+
function A() {
|
|
518
|
+
return g ??= import("highlight.js/lib/common").then(() => !0).catch(() => (g = null, !1)), g;
|
|
519
|
+
}
|
|
520
|
+
async function E(t, e) {
|
|
521
|
+
if (!t) return { value: "", language: null, load: "ready" };
|
|
522
|
+
if (e) {
|
|
523
|
+
const n = await q(e);
|
|
524
|
+
if (n !== "ready") return { value: "", language: null, load: n };
|
|
525
|
+
const a = d.highlight(t, { language: e, ignoreIllegals: !0 });
|
|
526
|
+
return { value: a.value, language: a.language ?? e, load: "ready" };
|
|
527
|
+
}
|
|
528
|
+
if (!await A())
|
|
529
|
+
return { value: "", language: null, load: "load-failed" };
|
|
530
|
+
const i = d.highlightAuto(t);
|
|
531
|
+
return { value: i.value, language: i.language ?? null, load: "ready" };
|
|
532
|
+
}
|
|
533
|
+
var M = Object.defineProperty, r = (t, e, i, n) => {
|
|
534
|
+
for (var a = void 0, l = t.length - 1, p; l >= 0; l--)
|
|
535
|
+
(p = t[l]) && (a = p(e, i, a) || a);
|
|
536
|
+
return a && M(e, i, a), a;
|
|
537
|
+
};
|
|
538
|
+
const v = "mp-code-snippet";
|
|
539
|
+
class o extends x {
|
|
540
|
+
constructor() {
|
|
541
|
+
super(...arguments), this.language = "", this.theme = "auto", this.copyLabel = "Copy ${language} code to clipboard", this.code = "", this.lineNumbers = !1, this.startLine = 1, this.wrap = !1, this.annotations = [], this.activeLine = null, this.lineHref = null, this.lineLabel = "Line ${line}", this.label = "", this.regionLabel = "${language} code sample", this.copiedLabel = "Copied!", this.copiedAnnouncement = "Copied to clipboard", this.keymapHint = "Use the up and down arrow keys to move between line links, Home and End for the first and last line.", this.detectedLanguage = "code", this.lines = [], this.toastVisible = !1, this.rovingLine = null, this.toastTimer = null, this.annotationsByLine = /* @__PURE__ */ new Map(), this.highlightToken = 0, this.highlightPending = Promise.resolve();
|
|
542
|
+
}
|
|
543
|
+
static {
|
|
544
|
+
this.styles = [$, C];
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Explicit `label` wins; otherwise the pattern, so the region is never
|
|
548
|
+
* nameless. The keymap is NOT folded in here — it belongs to the
|
|
549
|
+
* description, and a name that grows a paragraph of help is unusable in a
|
|
550
|
+
* landmark list.
|
|
551
|
+
*/
|
|
552
|
+
get regionName() {
|
|
553
|
+
return this.label || this.regionLabel.replace("${language}", this.detectedLanguage);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Keeps `await el.updateComplete` meaning what it has always meant: the
|
|
557
|
+
* rendered output is on screen. Highlighting now resolves a chunk load AFTER
|
|
558
|
+
* the first paint, so without this every consumer and every spec would have
|
|
559
|
+
* to know to await something extra.
|
|
560
|
+
*/
|
|
561
|
+
async getUpdateComplete() {
|
|
562
|
+
return await super.getUpdateComplete(), await this.highlightPending, super.getUpdateComplete();
|
|
135
563
|
}
|
|
136
564
|
connectedCallback() {
|
|
137
565
|
super.connectedCallback();
|
|
@@ -139,29 +567,34 @@ class i extends g {
|
|
|
139
567
|
disconnectedCallback() {
|
|
140
568
|
super.disconnectedCallback(), this.toastTimer !== null && (clearTimeout(this.toastTimer), this.toastTimer = null);
|
|
141
569
|
}
|
|
142
|
-
willUpdate(
|
|
143
|
-
(
|
|
570
|
+
willUpdate(e) {
|
|
571
|
+
(e.has("code") || e.has("language")) && this.runHighlight(), e.has("annotations") && (this.annotationsByLine = new Map((this.annotations ?? []).map((i) => [i.line, i])));
|
|
144
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* Highlighting is asynchronous because the grammar is fetched on demand, so
|
|
575
|
+
* this paints escaped plain text FIRST and upgrades in place when the
|
|
576
|
+
* grammar lands. A block that flashes empty is worse than one that flashes
|
|
577
|
+
* unstyled, and if the grammar never arrives the plain text is the final,
|
|
578
|
+
* still-readable state rather than a blank box.
|
|
579
|
+
*/
|
|
145
580
|
runHighlight() {
|
|
146
|
-
const
|
|
147
|
-
if (!
|
|
148
|
-
this.
|
|
581
|
+
const e = T(this.code ?? "");
|
|
582
|
+
if (!e) {
|
|
583
|
+
this.lines = [], this.setDetectedLanguage("code");
|
|
149
584
|
return;
|
|
150
585
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
this.
|
|
161
|
-
const s = e.language ?? "code";
|
|
162
|
-
s !== this.detectedLanguage && (this.detectedLanguage = s, this.dispatchEvent(
|
|
586
|
+
this.lines = y(S(e));
|
|
587
|
+
const i = ++this.highlightToken, n = this.language;
|
|
588
|
+
this.highlightPending = E(e, n).then(({ value: a, language: l, load: p }) => {
|
|
589
|
+
i === this.highlightToken && (p === "unknown-language" ? console.warn(
|
|
590
|
+
`[mp-code-snippet] unknown language "${n}" — rendering as plain text. Register it with registerLanguage() if it is outside the bundled set.`
|
|
591
|
+
) : p === "load-failed" && console.warn(`[mp-code-snippet] failed to load the grammar for "${n || "auto"}".`), a && (this.lines = y(a)), this.setDetectedLanguage(l ?? "code"));
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
setDetectedLanguage(e) {
|
|
595
|
+
e !== this.detectedLanguage && (this.detectedLanguage = e, this.dispatchEvent(
|
|
163
596
|
new CustomEvent("language-detected", {
|
|
164
|
-
detail: { language:
|
|
597
|
+
detail: { language: e },
|
|
165
598
|
bubbles: !0,
|
|
166
599
|
composed: !0
|
|
167
600
|
})
|
|
@@ -170,8 +603,8 @@ class i extends g {
|
|
|
170
603
|
async handleCopy() {
|
|
171
604
|
try {
|
|
172
605
|
await navigator.clipboard.writeText(this.code ?? ""), this.showToast();
|
|
173
|
-
} catch (
|
|
174
|
-
console.warn("[mp-code-snippet] clipboard write failed",
|
|
606
|
+
} catch (e) {
|
|
607
|
+
console.warn("[mp-code-snippet] clipboard write failed", e);
|
|
175
608
|
}
|
|
176
609
|
}
|
|
177
610
|
showToast() {
|
|
@@ -180,7 +613,7 @@ class i extends g {
|
|
|
180
613
|
}, 3e3);
|
|
181
614
|
}
|
|
182
615
|
render() {
|
|
183
|
-
return
|
|
616
|
+
return h`
|
|
184
617
|
<slot @slotchange=${this.onSlotChange}></slot>
|
|
185
618
|
<button
|
|
186
619
|
type="button"
|
|
@@ -193,37 +626,216 @@ class i extends g {
|
|
|
193
626
|
part="pre"
|
|
194
627
|
tabindex="0"
|
|
195
628
|
role="region"
|
|
196
|
-
aria-label="${this.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
629
|
+
aria-label="${this.regionName}"
|
|
630
|
+
aria-describedby="${this.lineHref ? "keymap" : c}"
|
|
631
|
+
><code part="code" class="hljs">${Array.from(
|
|
632
|
+
{ length: this.rowCount },
|
|
633
|
+
(e, i) => this.renderLine(i)
|
|
634
|
+
)}</code></pre>
|
|
635
|
+
${this.lineHref ? h`<div id="keymap" class="sr-only">${this.keymapHint}</div>` : c}
|
|
636
|
+
<div class="toast ${this.toastVisible ? "visible" : ""}" part="toast" aria-hidden="${!this.toastVisible}">${this.copiedLabel}</div>
|
|
637
|
+
<div class="sr-only" role="status" aria-live="polite">${this.toastVisible ? this.copiedAnnouncement : ""}</div>
|
|
200
638
|
`;
|
|
201
639
|
}
|
|
202
|
-
|
|
640
|
+
/**
|
|
641
|
+
* Rows to render. Normally one per source line, but annotations may name
|
|
642
|
+
* lines beyond the source's extent — a coverage report for a file whose
|
|
643
|
+
* source could not be fetched still renders its full gutter — so the count
|
|
644
|
+
* is the larger of the two.
|
|
645
|
+
*/
|
|
646
|
+
get rowCount() {
|
|
647
|
+
const e = this.annotations.reduce((n, a) => Math.max(n, a.line), 0), i = e === 0 ? 0 : e - this.startLine + 1;
|
|
648
|
+
return Math.max(this.lines.length, i);
|
|
649
|
+
}
|
|
650
|
+
/** Scroll a line into view. A method, not a side effect of `activeLine`, so
|
|
651
|
+
* re-requesting the line the user is already on still scrolls. */
|
|
652
|
+
scrollToLine(e) {
|
|
653
|
+
this.renderRoot?.querySelector(`#L${e}`)?.scrollIntoView({ block: "center", behavior: "auto" });
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* A bare fragment resolves against `document.baseURI`, and every Angular app
|
|
657
|
+
* sets that to `/` with `<base href="/">` — so the obvious `#L7` means "the
|
|
658
|
+
* ROOT document, anchor L7" and navigates away from the current route
|
|
659
|
+
* entirely. Resolving it against the current URL here means the obvious thing
|
|
660
|
+
* is also the correct thing, instead of a trap each consumer has to be warned
|
|
661
|
+
* about.
|
|
662
|
+
*
|
|
663
|
+
* Absolute and path-relative hrefs are left exactly as given.
|
|
664
|
+
*/
|
|
665
|
+
resolveLineHref(e) {
|
|
666
|
+
return !e.startsWith("#") || typeof location > "u" ? e : `${location.pathname}${location.search}${e}`;
|
|
667
|
+
}
|
|
668
|
+
onLineActivate(e, i) {
|
|
669
|
+
if (i.button !== 0 || i.ctrlKey || i.metaKey || i.shiftKey || i.altKey)
|
|
670
|
+
return;
|
|
671
|
+
this.dispatchEvent(
|
|
672
|
+
new CustomEvent("line-activate", {
|
|
673
|
+
detail: { line: e },
|
|
674
|
+
bubbles: !0,
|
|
675
|
+
composed: !0,
|
|
676
|
+
cancelable: !0
|
|
677
|
+
})
|
|
678
|
+
) || i.preventDefault();
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* One row per line.
|
|
682
|
+
*
|
|
683
|
+
* Each cell is a DIRECT child of the row and is placed on a named column by
|
|
684
|
+
* the stylesheet, because the row is a `subgrid` of column tracks defined
|
|
685
|
+
* once on `code`. That is what keeps the code text in one vertical line
|
|
686
|
+
* whether or not a given row happens to carry a gutter label: a row missing a
|
|
687
|
+
* cell leaves that track empty instead of shifting everything left. Wrapping
|
|
688
|
+
* the two marks in a container would defeat it — the container would be one
|
|
689
|
+
* content-sized cell, and every row would size it differently.
|
|
690
|
+
*
|
|
691
|
+
* Written with no whitespace between the cells: under `white-space: pre` a
|
|
692
|
+
* whitespace-only text node between grid items does NOT collapse away and
|
|
693
|
+
* would become an anonymous item in its own track.
|
|
694
|
+
*/
|
|
695
|
+
renderLine(e) {
|
|
696
|
+
const i = this.startLine + e, n = this.annotationFor(i), a = this.activeLine === i, l = this.lineLabel.replace("${line}", String(i)), p = ["line", n?.kind ? `annotation-${n.kind}` : "", a ? "active-line" : ""].filter(Boolean).join(" ");
|
|
697
|
+
return h`<span
|
|
698
|
+
class="line${a ? " active" : ""}${n ? " annotated" : ""}"
|
|
699
|
+
part="${p}"
|
|
700
|
+
id="L${i}"
|
|
701
|
+
title="${n?.description ?? c}"
|
|
702
|
+
>${this.lineNumbers ? this.renderGutter(i, l) : c}${n?.label !== void 0 ? h`<span class="line-mark" part="line-mark" aria-hidden="true">${n.label}</span>` : c}${n?.secondaryLabel !== void 0 ? h`<span class="line-mark secondary" part="line-mark-secondary" aria-hidden="true"
|
|
703
|
+
>${n.secondaryLabel}</span
|
|
704
|
+
>` : c}<span class="line-text" part="line-text">${L(this.lines[e] ?? "")}</span
|
|
705
|
+
>${n?.description ? h`<span class="sr-only">${n.description}</span>` : c}</span
|
|
706
|
+
>`;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* The gutter is a real link when `lineHref` is set and inert text otherwise.
|
|
710
|
+
* Inert text is `aria-hidden`: an unlinked line number is decoration, and
|
|
711
|
+
* announcing "42" before every line would drown the code.
|
|
712
|
+
*
|
|
713
|
+
* The links carry a ROVING tabindex — exactly one is tabbable and the arrow
|
|
714
|
+
* keys move between them. A file view puts one anchor per line in the DOM,
|
|
715
|
+
* so without this a 2 000-line file would be 2 000 tab stops between the
|
|
716
|
+
* reader and the rest of the page.
|
|
717
|
+
*/
|
|
718
|
+
renderGutter(e, i) {
|
|
719
|
+
return this.lineHref ? h`<a
|
|
720
|
+
class="line-number"
|
|
721
|
+
part="line-number"
|
|
722
|
+
href="${this.resolveLineHref(this.lineHref(e))}"
|
|
723
|
+
aria-label="${i}"
|
|
724
|
+
tabindex="${e === this.tabbableLine ? 0 : -1}"
|
|
725
|
+
@click=${(n) => this.onLineActivate(e, n)}
|
|
726
|
+
@keydown=${(n) => this.onGutterKeydown(e, n)}
|
|
727
|
+
>${e}</a
|
|
728
|
+
>` : h`<span class="line-number" part="line-number" aria-hidden="true">${e}</span>`;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* The single tabbable line link: wherever the user last was, else the active
|
|
732
|
+
* line, else the first. Landing on the active line means Tab reaches the
|
|
733
|
+
* line the consumer considers current rather than the top of a long file.
|
|
734
|
+
*/
|
|
735
|
+
get tabbableLine() {
|
|
736
|
+
return this.rovingLine ?? this.activeLine ?? this.startLine;
|
|
737
|
+
}
|
|
738
|
+
onGutterKeydown(e, i) {
|
|
739
|
+
const n = this.startLine, a = this.startLine + this.rowCount - 1;
|
|
740
|
+
let l = null;
|
|
741
|
+
switch (i.key) {
|
|
742
|
+
case "ArrowDown":
|
|
743
|
+
l = Math.min(e + 1, a);
|
|
744
|
+
break;
|
|
745
|
+
case "ArrowUp":
|
|
746
|
+
l = Math.max(e - 1, n);
|
|
747
|
+
break;
|
|
748
|
+
case "Home":
|
|
749
|
+
l = n;
|
|
750
|
+
break;
|
|
751
|
+
case "End":
|
|
752
|
+
l = a;
|
|
753
|
+
break;
|
|
754
|
+
default:
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
i.preventDefault(), l !== e && (this.rovingLine = l, this.moveFocusToLine(l));
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Focus follows the roving index by stable LINE NUMBER, never by DOM index:
|
|
761
|
+
* the rows are rebuilt on every highlight, and an index would land on
|
|
762
|
+
* whatever now occupies that position.
|
|
763
|
+
*/
|
|
764
|
+
async moveFocusToLine(e) {
|
|
765
|
+
await this.updateComplete, this.renderRoot?.querySelector(`#L${e} a.line-number`)?.focus();
|
|
766
|
+
}
|
|
767
|
+
annotationFor(e) {
|
|
768
|
+
return this.annotationsByLine.get(e);
|
|
769
|
+
}
|
|
770
|
+
onSlotChange(e) {
|
|
203
771
|
if (this.code) return;
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
],
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
],
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
],
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
],
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
],
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
],
|
|
226
|
-
|
|
772
|
+
const n = e.target.assignedNodes({ flatten: !0 }).map((a) => a.textContent ?? "").join("").trim();
|
|
773
|
+
n && (this.code = n);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
r([
|
|
777
|
+
s({ type: String })
|
|
778
|
+
], o.prototype, "language");
|
|
779
|
+
r([
|
|
780
|
+
s({ type: String, reflect: !0 })
|
|
781
|
+
], o.prototype, "theme");
|
|
782
|
+
r([
|
|
783
|
+
s({ type: String, attribute: "copy-label" })
|
|
784
|
+
], o.prototype, "copyLabel");
|
|
785
|
+
r([
|
|
786
|
+
s({ type: String })
|
|
787
|
+
], o.prototype, "code");
|
|
788
|
+
r([
|
|
789
|
+
s({ type: Boolean, attribute: "line-numbers", reflect: !0 })
|
|
790
|
+
], o.prototype, "lineNumbers");
|
|
791
|
+
r([
|
|
792
|
+
s({ type: Number, attribute: "start-line" })
|
|
793
|
+
], o.prototype, "startLine");
|
|
794
|
+
r([
|
|
795
|
+
s({ type: Boolean, reflect: !0 })
|
|
796
|
+
], o.prototype, "wrap");
|
|
797
|
+
r([
|
|
798
|
+
s({ attribute: !1 })
|
|
799
|
+
], o.prototype, "annotations");
|
|
800
|
+
r([
|
|
801
|
+
s({ type: Number, attribute: "active-line" })
|
|
802
|
+
], o.prototype, "activeLine");
|
|
803
|
+
r([
|
|
804
|
+
s({ attribute: !1 })
|
|
805
|
+
], o.prototype, "lineHref");
|
|
806
|
+
r([
|
|
807
|
+
s({ type: String, attribute: "line-label" })
|
|
808
|
+
], o.prototype, "lineLabel");
|
|
809
|
+
r([
|
|
810
|
+
s({ type: String })
|
|
811
|
+
], o.prototype, "label");
|
|
812
|
+
r([
|
|
813
|
+
s({ type: String, attribute: "region-label" })
|
|
814
|
+
], o.prototype, "regionLabel");
|
|
815
|
+
r([
|
|
816
|
+
s({ type: String, attribute: "copied-label" })
|
|
817
|
+
], o.prototype, "copiedLabel");
|
|
818
|
+
r([
|
|
819
|
+
s({ type: String, attribute: "copied-announcement" })
|
|
820
|
+
], o.prototype, "copiedAnnouncement");
|
|
821
|
+
r([
|
|
822
|
+
s({ type: String, attribute: "keymap-hint" })
|
|
823
|
+
], o.prototype, "keymapHint");
|
|
824
|
+
r([
|
|
825
|
+
u()
|
|
826
|
+
], o.prototype, "detectedLanguage");
|
|
827
|
+
r([
|
|
828
|
+
u()
|
|
829
|
+
], o.prototype, "lines");
|
|
830
|
+
r([
|
|
831
|
+
u()
|
|
832
|
+
], o.prototype, "toastVisible");
|
|
833
|
+
r([
|
|
834
|
+
u()
|
|
835
|
+
], o.prototype, "rovingLine");
|
|
836
|
+
typeof customElements < "u" && !customElements.get(v) && customElements.define(v, o);
|
|
227
837
|
export {
|
|
228
|
-
|
|
838
|
+
o as MpCodeSnippet,
|
|
839
|
+
P as canHighlight,
|
|
840
|
+
K as registerLanguage
|
|
229
841
|
};
|