@openelement/ui 1.0.0-alpha.5 → 1.0.0-alpha.7
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/README.md +1 -0
- package/package.json +7 -2
- package/src/component-recipes.js +60 -60
- package/src/generated-manifest.json +11 -1
- package/src/index.d.ts +15 -42
- package/src/index.js +15 -46
- package/src/instance-state.d.ts +16 -0
- package/src/instance-state.js +30 -24
- package/src/manifest.d.ts +5 -9
- package/src/manifest.js +6 -11
- package/src/open-badge.d.ts +113 -159
- package/src/open-badge.js +200 -239
- package/src/open-button.d.ts +296 -898
- package/src/open-button.js +1150 -1322
- package/src/open-callout.d.ts +225 -366
- package/src/open-callout.js +488 -569
- package/src/open-card.d.ts +114 -144
- package/src/open-card.js +197 -251
- package/src/open-code-block.d.ts +165 -168
- package/src/open-code-block.js +315 -366
- package/src/open-dialog.d.ts +241 -424
- package/src/open-dialog.js +643 -823
- package/src/open-dropdown.d.ts +195 -252
- package/src/open-dropdown.js +368 -471
- package/src/open-input.d.ts +404 -1420
- package/src/open-input.js +1809 -2095
- package/src/open-props-tokens.d.ts +5 -5
- package/src/open-props-tokens.js +12 -7
- package/src/open-tabs.d.ts +163 -191
- package/src/open-tabs.js +306 -361
- package/src/open-theme-toggle.d.ts +171 -287
- package/src/open-theme-toggle.js +530 -754
- package/src/register.d.ts +4 -1
- package/src/register.js +27 -58
package/src/open-code-block.js
CHANGED
|
@@ -1,259 +1,216 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { readInstanceState, writeInstanceState } from "./instance-state.js";
|
|
2
|
+
import { CODE_BLOCK_CONSTANTS, log, recipe } from "./component-recipes.js";
|
|
3
|
+
import { OpenElement } from "@openelement/element";
|
|
4
|
+
//#region src/open-code-block.tsx
|
|
5
5
|
const __partProgram = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
0,
|
|
147
|
-
1
|
|
148
|
-
]
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"id": "p1",
|
|
152
|
-
"kind": "anchor",
|
|
153
|
-
"part": 1,
|
|
154
|
-
"path": [
|
|
155
|
-
0,
|
|
156
|
-
1,
|
|
157
|
-
0
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
],
|
|
161
|
-
"metadata": {
|
|
162
|
-
"tag": "open-code-block",
|
|
163
|
-
"className": "OpenCodeBlock",
|
|
164
|
-
"sourceFile": "open-code-block.tsx",
|
|
165
|
-
"properties": [
|
|
166
|
-
{
|
|
167
|
-
"name": "copyLabel",
|
|
168
|
-
"attribute": null,
|
|
169
|
-
"type": "string",
|
|
170
|
-
"converter": "string",
|
|
171
|
-
"reflect": false,
|
|
172
|
-
"default": "Copy"
|
|
173
|
-
}
|
|
174
|
-
],
|
|
175
|
-
"observedAttributes": [],
|
|
176
|
-
"cem": {
|
|
177
|
-
"tagName": "open-code-block",
|
|
178
|
-
"className": "OpenCodeBlock",
|
|
179
|
-
"declaration": {
|
|
180
|
-
"name": "OpenCodeBlock",
|
|
181
|
-
"module": "open-code-block.tsx"
|
|
182
|
-
},
|
|
183
|
-
"attributes": [],
|
|
184
|
-
"members": [
|
|
185
|
-
{
|
|
186
|
-
"name": "copyLabel",
|
|
187
|
-
"fieldName": "copyLabel",
|
|
188
|
-
"type": "string",
|
|
189
|
-
"attribute": null,
|
|
190
|
-
"reflect": false
|
|
191
|
-
}
|
|
192
|
-
]
|
|
193
|
-
}
|
|
194
|
-
}
|
|
6
|
+
"version": 1,
|
|
7
|
+
"tag": "open-code-block",
|
|
8
|
+
"root": {
|
|
9
|
+
"id": "root",
|
|
10
|
+
"kind": "shadow-open",
|
|
11
|
+
"nodes": ["e0"]
|
|
12
|
+
},
|
|
13
|
+
"template": [{
|
|
14
|
+
"k": "el",
|
|
15
|
+
"id": "e0",
|
|
16
|
+
"tag": "div",
|
|
17
|
+
"attrs": [["style", "display:contents"]],
|
|
18
|
+
"children": [{
|
|
19
|
+
"k": "el",
|
|
20
|
+
"id": "e1",
|
|
21
|
+
"tag": "slot",
|
|
22
|
+
"attrs": [],
|
|
23
|
+
"children": []
|
|
24
|
+
}, {
|
|
25
|
+
"k": "el",
|
|
26
|
+
"id": "e2",
|
|
27
|
+
"tag": "button",
|
|
28
|
+
"attrs": [
|
|
29
|
+
["type", "button"],
|
|
30
|
+
["class", "copy-btn"],
|
|
31
|
+
["part", "copy"]
|
|
32
|
+
],
|
|
33
|
+
"children": [{
|
|
34
|
+
"k": "part",
|
|
35
|
+
"id": "p1",
|
|
36
|
+
"index": 1
|
|
37
|
+
}]
|
|
38
|
+
}]
|
|
39
|
+
}],
|
|
40
|
+
"parts": [{
|
|
41
|
+
"k": "event",
|
|
42
|
+
"event": "click",
|
|
43
|
+
"handler": "copy",
|
|
44
|
+
"action": {
|
|
45
|
+
"kind": "method",
|
|
46
|
+
"name": "copy"
|
|
47
|
+
},
|
|
48
|
+
"path": [0, 1],
|
|
49
|
+
"index": 0,
|
|
50
|
+
"location": {
|
|
51
|
+
"id": "p0",
|
|
52
|
+
"kind": "sink",
|
|
53
|
+
"path": [0, 1],
|
|
54
|
+
"node": "e2"
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
"k": "text",
|
|
58
|
+
"signal": "copyLabel",
|
|
59
|
+
"index": 1,
|
|
60
|
+
"location": {
|
|
61
|
+
"id": "p1",
|
|
62
|
+
"kind": "anchor",
|
|
63
|
+
"path": [
|
|
64
|
+
0,
|
|
65
|
+
1,
|
|
66
|
+
0
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}],
|
|
70
|
+
"regions": [],
|
|
71
|
+
"dependencies": [{
|
|
72
|
+
"signal": "copyLabel",
|
|
73
|
+
"owner": {
|
|
74
|
+
"kind": "part",
|
|
75
|
+
"index": 1
|
|
76
|
+
},
|
|
77
|
+
"location": "p1"
|
|
78
|
+
}],
|
|
79
|
+
"locations": [
|
|
80
|
+
{
|
|
81
|
+
"id": "e0",
|
|
82
|
+
"kind": "element",
|
|
83
|
+
"tag": "div",
|
|
84
|
+
"path": [0]
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"id": "e1",
|
|
88
|
+
"kind": "element",
|
|
89
|
+
"tag": "slot",
|
|
90
|
+
"path": [0, 0]
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "e2",
|
|
94
|
+
"kind": "element",
|
|
95
|
+
"tag": "button",
|
|
96
|
+
"path": [0, 1]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"id": "p0",
|
|
100
|
+
"kind": "sink",
|
|
101
|
+
"part": 0,
|
|
102
|
+
"node": "e2",
|
|
103
|
+
"path": [0, 1]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "p1",
|
|
107
|
+
"kind": "anchor",
|
|
108
|
+
"part": 1,
|
|
109
|
+
"path": [
|
|
110
|
+
0,
|
|
111
|
+
1,
|
|
112
|
+
0
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"metadata": {
|
|
117
|
+
"tag": "open-code-block",
|
|
118
|
+
"className": "OpenCodeBlock",
|
|
119
|
+
"sourceFile": "open-code-block.tsx",
|
|
120
|
+
"properties": [{
|
|
121
|
+
"name": "copyLabel",
|
|
122
|
+
"attribute": null,
|
|
123
|
+
"type": "string",
|
|
124
|
+
"converter": "string",
|
|
125
|
+
"reflect": false,
|
|
126
|
+
"default": "Copy"
|
|
127
|
+
}],
|
|
128
|
+
"observedAttributes": [],
|
|
129
|
+
"cem": {
|
|
130
|
+
"tagName": "open-code-block",
|
|
131
|
+
"className": "OpenCodeBlock",
|
|
132
|
+
"declaration": {
|
|
133
|
+
"name": "OpenCodeBlock",
|
|
134
|
+
"module": "open-code-block.tsx"
|
|
135
|
+
},
|
|
136
|
+
"attributes": [],
|
|
137
|
+
"members": [{
|
|
138
|
+
"name": "copyLabel",
|
|
139
|
+
"fieldName": "copyLabel",
|
|
140
|
+
"type": "string",
|
|
141
|
+
"attribute": null,
|
|
142
|
+
"reflect": false
|
|
143
|
+
}]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
195
146
|
};
|
|
196
|
-
const __compiledProperties = [
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
];
|
|
147
|
+
const __compiledProperties = [{
|
|
148
|
+
"name": "copyLabel",
|
|
149
|
+
"attribute": null,
|
|
150
|
+
"type": "string",
|
|
151
|
+
"converter": "string",
|
|
152
|
+
"reflect": false,
|
|
153
|
+
"default": "Copy"
|
|
154
|
+
}];
|
|
206
155
|
const __elementMetadata = {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
"reflect": false
|
|
236
|
-
}
|
|
237
|
-
]
|
|
238
|
-
}
|
|
156
|
+
"tag": "open-code-block",
|
|
157
|
+
"className": "OpenCodeBlock",
|
|
158
|
+
"sourceFile": "open-code-block.tsx",
|
|
159
|
+
"properties": [{
|
|
160
|
+
"name": "copyLabel",
|
|
161
|
+
"attribute": null,
|
|
162
|
+
"type": "string",
|
|
163
|
+
"converter": "string",
|
|
164
|
+
"reflect": false,
|
|
165
|
+
"default": "Copy"
|
|
166
|
+
}],
|
|
167
|
+
"observedAttributes": [],
|
|
168
|
+
"cem": {
|
|
169
|
+
"tagName": "open-code-block",
|
|
170
|
+
"className": "OpenCodeBlock",
|
|
171
|
+
"declaration": {
|
|
172
|
+
"name": "OpenCodeBlock",
|
|
173
|
+
"module": "open-code-block.tsx"
|
|
174
|
+
},
|
|
175
|
+
"attributes": [],
|
|
176
|
+
"members": [{
|
|
177
|
+
"name": "copyLabel",
|
|
178
|
+
"fieldName": "copyLabel",
|
|
179
|
+
"type": "string",
|
|
180
|
+
"attribute": null,
|
|
181
|
+
"reflect": false
|
|
182
|
+
}]
|
|
183
|
+
}
|
|
239
184
|
};
|
|
240
185
|
const __observedAttributes = [];
|
|
241
|
-
const __compiledProps = {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
186
|
+
const __compiledProps = { copyLabel: {
|
|
187
|
+
type: String,
|
|
188
|
+
default: "Copy",
|
|
189
|
+
reflect: false,
|
|
190
|
+
attribute: false
|
|
191
|
+
} };
|
|
192
|
+
var OpenCodeBlock = class extends OpenElement {
|
|
193
|
+
constructor(..._args) {
|
|
194
|
+
super(..._args);
|
|
195
|
+
this.copyLabel = "Copy";
|
|
196
|
+
}
|
|
197
|
+
static {
|
|
198
|
+
this.__partProgram = __partProgram;
|
|
199
|
+
}
|
|
200
|
+
static {
|
|
201
|
+
this.__compiledProperties = __compiledProperties;
|
|
202
|
+
}
|
|
203
|
+
static {
|
|
204
|
+
this.__elementMetadata = __elementMetadata;
|
|
205
|
+
}
|
|
206
|
+
static {
|
|
207
|
+
this.props = __compiledProps;
|
|
208
|
+
}
|
|
209
|
+
static {
|
|
210
|
+
this.observedAttributes = __observedAttributes;
|
|
211
|
+
}
|
|
212
|
+
static {
|
|
213
|
+
this.styles = [recipe(`
|
|
257
214
|
:host {
|
|
258
215
|
display: block;
|
|
259
216
|
position: relative;
|
|
@@ -357,118 +314,110 @@ export class OpenCodeBlock extends OpenElement {
|
|
|
357
314
|
.token.bold, .token.important { font-weight: 700; }
|
|
358
315
|
.token.italic { font-style: italic; }
|
|
359
316
|
.token.entity { cursor: help; }
|
|
360
|
-
`)
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
render() {
|
|
471
|
-
throw new Error('[open:compiled-element] open-code-block is compiled to a Part Program; the runtime JSX render path is not available in 0.44.');
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
export { __partProgram, __elementMetadata };
|
|
317
|
+
`)];
|
|
318
|
+
}
|
|
319
|
+
onDsdHydrated() {
|
|
320
|
+
this.tryHighlight();
|
|
321
|
+
}
|
|
322
|
+
onCsrRendered() {
|
|
323
|
+
this.tryHighlight();
|
|
324
|
+
}
|
|
325
|
+
disconnectedCallback() {
|
|
326
|
+
if (!this.shadowRoot?.querySelector("slot")) {
|
|
327
|
+
const root = this.shadowRoot;
|
|
328
|
+
const highlighted = root?.querySelector("pre");
|
|
329
|
+
if (root && highlighted) {
|
|
330
|
+
const restored = root.ownerDocument.createElement("slot");
|
|
331
|
+
highlighted.replaceWith(restored);
|
|
332
|
+
}
|
|
333
|
+
const lightPre = this.querySelector("pre");
|
|
334
|
+
if (lightPre) lightPre.style.display = "";
|
|
335
|
+
writeInstanceState(this, "highlighted", false);
|
|
336
|
+
}
|
|
337
|
+
super.disconnectedCallback();
|
|
338
|
+
}
|
|
339
|
+
prismGlobal() {
|
|
340
|
+
return globalThis.Prism;
|
|
341
|
+
}
|
|
342
|
+
tryHighlight() {
|
|
343
|
+
const p = this.prismGlobal();
|
|
344
|
+
if (typeof p === "undefined") {
|
|
345
|
+
this.scheduleRetry(10, 500);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const pre = this.querySelector(":scope > pre") || Array.from(this.children).find((c) => c.tagName === "PRE");
|
|
349
|
+
if (!pre) return;
|
|
350
|
+
const codeEl = pre.querySelector("code");
|
|
351
|
+
if (!codeEl) return;
|
|
352
|
+
let lang = "typescript";
|
|
353
|
+
const classes = codeEl.classList;
|
|
354
|
+
for (let i = 0; i < classes.length; i++) if (classes[i].startsWith("language-")) {
|
|
355
|
+
lang = classes[i].slice(9);
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
const raw = codeEl.textContent || "";
|
|
359
|
+
const grammar = p.languages?.[lang];
|
|
360
|
+
if (!grammar) {
|
|
361
|
+
this.scheduleRetry(20, 1e3);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
writeInstanceState(this, "highlightRetries", 0);
|
|
365
|
+
const highlightedHtml = p.highlight(raw, grammar, lang);
|
|
366
|
+
this.injectHighlighted(highlightedHtml, lang);
|
|
367
|
+
}
|
|
368
|
+
scheduleRetry(base, cap) {
|
|
369
|
+
const retries = readInstanceState(this, "highlightRetries", () => 0);
|
|
370
|
+
if (retries >= CODE_BLOCK_CONSTANTS.maxHighlightRetries) return;
|
|
371
|
+
writeInstanceState(this, "highlightRetries", retries + 1);
|
|
372
|
+
const delay = Math.min(base * Math.pow(2, Math.min(retries + 1, 6)), cap);
|
|
373
|
+
this._setTimeout(() => this.tryHighlight(), delay);
|
|
374
|
+
}
|
|
375
|
+
injectHighlighted(html, lang) {
|
|
376
|
+
if (!this.shadowRoot || readInstanceState(this, "highlighted", () => false)) return;
|
|
377
|
+
writeInstanceState(this, "highlighted", true);
|
|
378
|
+
const slot = this.shadowRoot.querySelector("slot");
|
|
379
|
+
if (!slot) return;
|
|
380
|
+
const highlightedPre = document.createElement("pre");
|
|
381
|
+
const highlightedCode = document.createElement("code");
|
|
382
|
+
highlightedCode.className = `language-${lang}`;
|
|
383
|
+
highlightedCode.innerHTML = html;
|
|
384
|
+
highlightedPre.appendChild(highlightedCode);
|
|
385
|
+
slot.replaceWith(highlightedPre);
|
|
386
|
+
const lightPre = this.querySelector("pre");
|
|
387
|
+
if (lightPre) lightPre.style.display = "none";
|
|
388
|
+
}
|
|
389
|
+
getCodeText() {
|
|
390
|
+
if (this.shadowRoot) {
|
|
391
|
+
const shadowCode = this.shadowRoot.querySelector("pre code");
|
|
392
|
+
if (shadowCode) return shadowCode.textContent || "";
|
|
393
|
+
}
|
|
394
|
+
return this.textContent || "";
|
|
395
|
+
}
|
|
396
|
+
async copy() {
|
|
397
|
+
try {
|
|
398
|
+
const text = this.getCodeText();
|
|
399
|
+
await navigator.clipboard.writeText(text);
|
|
400
|
+
this.copyLabel = "Copied!";
|
|
401
|
+
this._internals?.states.add("copied");
|
|
402
|
+
this._internals?.states.delete("failed");
|
|
403
|
+
this._setTimeout(() => {
|
|
404
|
+
this.copyLabel = "Copy";
|
|
405
|
+
this._internals?.states.delete("copied");
|
|
406
|
+
}, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
log.warn("Clipboard write failed:", e);
|
|
409
|
+
this.copyLabel = "Failed";
|
|
410
|
+
this._internals?.states.add("failed");
|
|
411
|
+
this._internals?.states.delete("copied");
|
|
412
|
+
this._setTimeout(() => {
|
|
413
|
+
this.copyLabel = "Copy";
|
|
414
|
+
this._internals?.states.delete("failed");
|
|
415
|
+
}, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
render() {
|
|
419
|
+
throw new Error("[open:compiled-element] open-code-block is compiled to a Part Program; the runtime JSX render path is not available.");
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
//#endregion
|
|
423
|
+
export { OpenCodeBlock, __elementMetadata, __partProgram };
|