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