@openelement/ui 1.0.0-alpha.1 → 1.0.0-alpha.10
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/CUSTOMIZATION.md +272 -0
- package/README.md +59 -54
- package/package.json +19 -13
- package/src/component-recipes.js +80 -83
- package/src/generated-manifest.json +19 -9
- package/src/index.d.ts +14 -42
- package/src/index.js +14 -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 +208 -262
- package/src/open-button.d.ts +296 -898
- package/src/open-button.js +1163 -1355
- package/src/open-callout.d.ts +225 -366
- package/src/open-callout.js +483 -584
- package/src/open-card.d.ts +114 -144
- package/src/open-card.js +208 -274
- package/src/open-code-block.d.ts +158 -168
- package/src/open-code-block.js +242 -445
- package/src/open-dialog.d.ts +241 -424
- package/src/open-dialog.js +705 -850
- package/src/open-dropdown.d.ts +195 -252
- package/src/open-dropdown.js +353 -473
- package/src/open-input.d.ts +404 -1420
- package/src/open-input.js +1809 -2116
- package/src/open-tabs.d.ts +163 -191
- package/src/open-tabs.js +302 -372
- package/src/open-theme-toggle.d.ts +171 -287
- package/src/open-theme-toggle.js +524 -765
- package/src/register.d.ts +4 -1
- package/src/register.js +27 -58
- package/src/theme.css +205 -0
- package/THIRD_PARTY_NOTICES.md +0 -45
- package/src/open-props-tokens.d.ts +0 -9
- package/src/open-props-tokens.js +0 -459
- package/src/semantic-tokens.css +0 -413
package/src/open-code-block.js
CHANGED
|
@@ -1,336 +1,229 @@
|
|
|
1
|
-
|
|
2
|
-
import { OpenElement } from
|
|
3
|
-
|
|
4
|
-
import { readInstanceState, writeInstanceState } from './instance-state.js';
|
|
1
|
+
import { CODE_BLOCK_CONSTANTS, log, recipe } from "./component-recipes.js";
|
|
2
|
+
import { OpenElement } from "@openelement/element";
|
|
3
|
+
//#region src/open-code-block.tsx
|
|
5
4
|
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
|
-
}
|
|
5
|
+
"version": 1,
|
|
6
|
+
"tag": "open-code-block",
|
|
7
|
+
"root": {
|
|
8
|
+
"id": "root",
|
|
9
|
+
"kind": "shadow-open",
|
|
10
|
+
"nodes": ["e0"]
|
|
11
|
+
},
|
|
12
|
+
"template": [{
|
|
13
|
+
"k": "el",
|
|
14
|
+
"id": "e0",
|
|
15
|
+
"tag": "div",
|
|
16
|
+
"attrs": [["style", "display:contents"]],
|
|
17
|
+
"children": [{
|
|
18
|
+
"k": "el",
|
|
19
|
+
"id": "e1",
|
|
20
|
+
"tag": "slot",
|
|
21
|
+
"attrs": [],
|
|
22
|
+
"children": []
|
|
23
|
+
}, {
|
|
24
|
+
"k": "el",
|
|
25
|
+
"id": "e2",
|
|
26
|
+
"tag": "button",
|
|
27
|
+
"attrs": [
|
|
28
|
+
["type", "button"],
|
|
29
|
+
["class", "copy-btn"],
|
|
30
|
+
["part", "copy"]
|
|
31
|
+
],
|
|
32
|
+
"children": [{
|
|
33
|
+
"k": "part",
|
|
34
|
+
"id": "p1",
|
|
35
|
+
"index": 1
|
|
36
|
+
}]
|
|
37
|
+
}]
|
|
38
|
+
}],
|
|
39
|
+
"parts": [{
|
|
40
|
+
"k": "event",
|
|
41
|
+
"event": "click",
|
|
42
|
+
"handler": "copy",
|
|
43
|
+
"action": {
|
|
44
|
+
"kind": "method",
|
|
45
|
+
"name": "copy"
|
|
46
|
+
},
|
|
47
|
+
"path": [0, 1],
|
|
48
|
+
"index": 0,
|
|
49
|
+
"location": {
|
|
50
|
+
"id": "p0",
|
|
51
|
+
"kind": "sink",
|
|
52
|
+
"path": [0, 1],
|
|
53
|
+
"node": "e2"
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
"k": "text",
|
|
57
|
+
"signal": "copyLabel",
|
|
58
|
+
"index": 1,
|
|
59
|
+
"location": {
|
|
60
|
+
"id": "p1",
|
|
61
|
+
"kind": "anchor",
|
|
62
|
+
"path": [
|
|
63
|
+
0,
|
|
64
|
+
1,
|
|
65
|
+
0
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}],
|
|
69
|
+
"regions": [],
|
|
70
|
+
"dependencies": [{
|
|
71
|
+
"signal": "copyLabel",
|
|
72
|
+
"owner": {
|
|
73
|
+
"kind": "part",
|
|
74
|
+
"index": 1
|
|
75
|
+
},
|
|
76
|
+
"location": "p1"
|
|
77
|
+
}],
|
|
78
|
+
"locations": [
|
|
79
|
+
{
|
|
80
|
+
"id": "e0",
|
|
81
|
+
"kind": "element",
|
|
82
|
+
"tag": "div",
|
|
83
|
+
"path": [0]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"id": "e1",
|
|
87
|
+
"kind": "element",
|
|
88
|
+
"tag": "slot",
|
|
89
|
+
"path": [0, 0]
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"id": "e2",
|
|
93
|
+
"kind": "element",
|
|
94
|
+
"tag": "button",
|
|
95
|
+
"path": [0, 1]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"id": "p0",
|
|
99
|
+
"kind": "sink",
|
|
100
|
+
"part": 0,
|
|
101
|
+
"node": "e2",
|
|
102
|
+
"path": [0, 1]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"id": "p1",
|
|
106
|
+
"kind": "anchor",
|
|
107
|
+
"part": 1,
|
|
108
|
+
"path": [
|
|
109
|
+
0,
|
|
110
|
+
1,
|
|
111
|
+
0
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
"metadata": {
|
|
116
|
+
"tag": "open-code-block",
|
|
117
|
+
"className": "OpenCodeBlock",
|
|
118
|
+
"sourceFile": "open-code-block.tsx",
|
|
119
|
+
"properties": [{
|
|
120
|
+
"name": "copyLabel",
|
|
121
|
+
"attribute": null,
|
|
122
|
+
"type": "string",
|
|
123
|
+
"converter": "string",
|
|
124
|
+
"reflect": false,
|
|
125
|
+
"default": "Copy"
|
|
126
|
+
}],
|
|
127
|
+
"observedAttributes": [],
|
|
128
|
+
"cem": {
|
|
129
|
+
"tagName": "open-code-block",
|
|
130
|
+
"className": "OpenCodeBlock",
|
|
131
|
+
"declaration": {
|
|
132
|
+
"name": "OpenCodeBlock",
|
|
133
|
+
"module": "open-code-block.tsx"
|
|
134
|
+
},
|
|
135
|
+
"attributes": [],
|
|
136
|
+
"members": [{
|
|
137
|
+
"name": "copyLabel",
|
|
138
|
+
"fieldName": "copyLabel",
|
|
139
|
+
"type": "string",
|
|
140
|
+
"attribute": null,
|
|
141
|
+
"reflect": false
|
|
142
|
+
}]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
195
145
|
};
|
|
196
|
-
const __compiledProperties = [
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
];
|
|
146
|
+
const __compiledProperties = [{
|
|
147
|
+
"name": "copyLabel",
|
|
148
|
+
"attribute": null,
|
|
149
|
+
"type": "string",
|
|
150
|
+
"converter": "string",
|
|
151
|
+
"reflect": false,
|
|
152
|
+
"default": "Copy"
|
|
153
|
+
}];
|
|
206
154
|
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
|
-
}
|
|
155
|
+
"tag": "open-code-block",
|
|
156
|
+
"className": "OpenCodeBlock",
|
|
157
|
+
"sourceFile": "open-code-block.tsx",
|
|
158
|
+
"properties": [{
|
|
159
|
+
"name": "copyLabel",
|
|
160
|
+
"attribute": null,
|
|
161
|
+
"type": "string",
|
|
162
|
+
"converter": "string",
|
|
163
|
+
"reflect": false,
|
|
164
|
+
"default": "Copy"
|
|
165
|
+
}],
|
|
166
|
+
"observedAttributes": [],
|
|
167
|
+
"cem": {
|
|
168
|
+
"tagName": "open-code-block",
|
|
169
|
+
"className": "OpenCodeBlock",
|
|
170
|
+
"declaration": {
|
|
171
|
+
"name": "OpenCodeBlock",
|
|
172
|
+
"module": "open-code-block.tsx"
|
|
173
|
+
},
|
|
174
|
+
"attributes": [],
|
|
175
|
+
"members": [{
|
|
176
|
+
"name": "copyLabel",
|
|
177
|
+
"fieldName": "copyLabel",
|
|
178
|
+
"type": "string",
|
|
179
|
+
"attribute": null,
|
|
180
|
+
"reflect": false
|
|
181
|
+
}]
|
|
182
|
+
}
|
|
239
183
|
};
|
|
240
184
|
const __observedAttributes = [];
|
|
241
|
-
const __compiledProps = {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
static observedAttributes = __observedAttributes;
|
|
255
|
-
static styles = [
|
|
256
|
-
recipe(`
|
|
185
|
+
const __compiledProps = { copyLabel: {
|
|
186
|
+
type: String,
|
|
187
|
+
default: "Copy",
|
|
188
|
+
reflect: false,
|
|
189
|
+
attribute: false
|
|
190
|
+
} };
|
|
191
|
+
var OpenCodeBlock = class extends OpenElement {
|
|
192
|
+
static __partProgram = __partProgram;
|
|
193
|
+
static __compiledProperties = __compiledProperties;
|
|
194
|
+
static __elementMetadata = __elementMetadata;
|
|
195
|
+
static props = __compiledProps;
|
|
196
|
+
static observedAttributes = __observedAttributes;
|
|
197
|
+
static styles = [recipe(`
|
|
257
198
|
:host {
|
|
258
199
|
display: block;
|
|
259
200
|
position: relative;
|
|
260
201
|
}
|
|
261
202
|
|
|
262
|
-
pre {
|
|
263
|
-
margin: 0;
|
|
264
|
-
padding: var(--size-5);
|
|
265
|
-
/* Clear the copy chip (top var(--size-2) + ~25px tall) so the first line
|
|
266
|
-
never runs underneath it. */
|
|
267
|
-
padding-block-start: calc(var(--size-5) + var(--size-4));
|
|
268
|
-
background: var(--bg-code);
|
|
269
|
-
border: var(--border-size-1) solid var(--code-border);
|
|
270
|
-
border-radius: var(--radius-2);
|
|
271
|
-
overflow-x: auto;
|
|
272
|
-
font-family: var(--font-mono);
|
|
273
|
-
font-size: var(--font-size-0);
|
|
274
|
-
line-height: var(--font-lineheight-4);
|
|
275
|
-
color: var(--code-text);
|
|
276
|
-
scrollbar-width: thin;
|
|
277
|
-
scrollbar-color: var(--brand-subtle) transparent;
|
|
278
|
-
white-space: pre-wrap;
|
|
279
|
-
word-break: break-word;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
::slotted(pre) {
|
|
283
|
-
margin: 0;
|
|
284
|
-
padding: var(--size-5);
|
|
285
|
-
padding-block-start: calc(var(--size-5) + var(--size-4));
|
|
286
|
-
background: var(--bg-code);
|
|
287
|
-
border: var(--border-size-1) solid var(--code-border);
|
|
288
|
-
border-radius: var(--radius-2);
|
|
289
|
-
overflow-x: auto;
|
|
290
|
-
font-family: var(--font-mono);
|
|
291
|
-
font-size: var(--font-size-0);
|
|
292
|
-
line-height: var(--font-lineheight-4);
|
|
293
|
-
color: var(--code-text);
|
|
294
|
-
scrollbar-width: thin;
|
|
295
|
-
scrollbar-color: var(--brand-subtle) transparent;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
.lang-badge {
|
|
299
|
-
position: absolute;
|
|
300
|
-
top: var(--size-2);
|
|
301
|
-
left: var(--size-3);
|
|
302
|
-
font-size: var(--font-size-00);
|
|
303
|
-
font-weight: var(--font-weight-7);
|
|
304
|
-
text-transform: uppercase;
|
|
305
|
-
letter-spacing: var(--font-letterspacing-5);
|
|
306
|
-
color: var(--code-text);
|
|
307
|
-
pointer-events: none;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
203
|
.copy-btn {
|
|
311
204
|
position: absolute;
|
|
312
|
-
top: var(--
|
|
313
|
-
right: var(--
|
|
314
|
-
background: var(--
|
|
315
|
-
color: var(--
|
|
316
|
-
padding: var(--
|
|
317
|
-
font-size: var(--
|
|
205
|
+
top: calc(var(--spacing) * 2);
|
|
206
|
+
right: calc(var(--spacing) * 2);
|
|
207
|
+
background: color-mix(in srgb, var(--color-primary) 14%, transparent);
|
|
208
|
+
color: var(--color-foreground);
|
|
209
|
+
padding: calc(var(--spacing) * 1) calc(var(--spacing) * 3);
|
|
210
|
+
font-size: var(--text-xs);
|
|
318
211
|
font-family: var(--font-sans);
|
|
319
|
-
font-weight: var(--font-weight-
|
|
212
|
+
font-weight: var(--font-weight-semibold);
|
|
320
213
|
border: 0.5px solid transparent;
|
|
321
214
|
cursor: pointer;
|
|
322
|
-
border-radius: var(--radius-
|
|
323
|
-
transition: all var(--ease-
|
|
215
|
+
border-radius: var(--radius-md);
|
|
216
|
+
transition: all var(--ease-in-out) var(--default-transition-duration);
|
|
324
217
|
z-index: 1;
|
|
325
|
-
letter-spacing: var(--
|
|
218
|
+
letter-spacing: var(--tracking-wider);
|
|
326
219
|
}
|
|
327
220
|
|
|
328
|
-
/* No ink override on hover:
|
|
329
|
-
this chip's hover surface is a translucent brand tint
|
|
330
|
-
chip keeps the code surface's
|
|
221
|
+
/* No ink override on hover: the primary-foreground ink belongs to a brand
|
|
222
|
+
*fill*, and this chip's hover surface is a translucent brand tint
|
|
223
|
+
instead, so the chip keeps the code surface's ink. */
|
|
331
224
|
.copy-btn:hover {
|
|
332
|
-
background: var(--
|
|
333
|
-
border-color: var(--
|
|
225
|
+
background: color-mix(in srgb, var(--color-primary) 23%, transparent);
|
|
226
|
+
border-color: var(--color-primary);
|
|
334
227
|
}
|
|
335
228
|
|
|
336
229
|
:host(:state(copied)) .copy-btn {
|
|
@@ -340,135 +233,39 @@ export class OpenCodeBlock extends OpenElement {
|
|
|
340
233
|
}
|
|
341
234
|
|
|
342
235
|
:host(:state(failed)) .copy-btn {
|
|
343
|
-
color: var(--
|
|
344
|
-
border-color: var(--
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/* Comment gray: #7d8590 (5.2:1 on --bg-code) — #6a737d was 4.0:1. */
|
|
348
|
-
.token.cdata, .token.comment, .token.doctype, .token.prolog { color: #7d8590; }
|
|
349
|
-
.token.punctuation { color: #8b949e; }
|
|
350
|
-
.token.namespace { opacity: 0.7; }
|
|
351
|
-
.token.boolean, .token.constant, .token.deleted, .token.number, .token.property, .token.symbol, .token.tag { color: #79c0ff; }
|
|
352
|
-
.token.attr-name, .token.builtin, .token.char, .token.inserted, .token.selector, .token.string { color: #a5d6ff; }
|
|
353
|
-
.token.entity, .token.operator, .token.url, .language-css .token.string, .style .token.string { color: #d2a8ff; }
|
|
354
|
-
.token.atrule, .token.attr-value, .token.keyword { color: #ff7b72; }
|
|
355
|
-
.token.class-name, .token.function { color: #d2a8ff; }
|
|
356
|
-
.token.important, .token.regex, .token.variable { color: #ffa657; }
|
|
357
|
-
.token.bold, .token.important { font-weight: 700; }
|
|
358
|
-
.token.italic { font-style: italic; }
|
|
359
|
-
.token.entity { cursor: help; }
|
|
360
|
-
`)
|
|
361
|
-
];
|
|
362
|
-
copyLabel = 'Copy';
|
|
363
|
-
onDsdHydrated() {
|
|
364
|
-
this.tryHighlight();
|
|
365
|
-
}
|
|
366
|
-
onCsrRendered() {
|
|
367
|
-
this.tryHighlight();
|
|
368
|
-
}
|
|
369
|
-
disconnectedCallback() {
|
|
370
|
-
// Compiled-kernel ownership: restore the program's static structure before
|
|
371
|
-
// teardown so a reconnect re-claims cleanly (the injected highlight <pre>
|
|
372
|
-
// and the copy-label text are imperative writes, not program content).
|
|
373
|
-
const slot = this.shadowRoot?.querySelector('slot');
|
|
374
|
-
if (!slot) {
|
|
375
|
-
const root = this.shadowRoot;
|
|
376
|
-
const highlighted = root?.querySelector('pre');
|
|
377
|
-
if (root && highlighted) {
|
|
378
|
-
const restored = root.ownerDocument.createElement('slot');
|
|
379
|
-
highlighted.replaceWith(restored);
|
|
380
|
-
}
|
|
381
|
-
const lightPre = this.querySelector('pre');
|
|
382
|
-
if (lightPre) lightPre.style.display = '';
|
|
383
|
-
writeInstanceState(this, 'highlighted', false);
|
|
384
|
-
}
|
|
385
|
-
super.disconnectedCallback();
|
|
386
|
-
}
|
|
387
|
-
prismGlobal() {
|
|
388
|
-
return globalThis.Prism;
|
|
389
|
-
}
|
|
390
|
-
tryHighlight() {
|
|
391
|
-
const p = this.prismGlobal();
|
|
392
|
-
if (typeof p === 'undefined') {
|
|
393
|
-
// Prism not loaded yet: backoff 10, 20, 40, ..., 500ms cap.
|
|
394
|
-
this.scheduleRetry(10, 500);
|
|
395
|
-
return;
|
|
236
|
+
color: var(--color-destructive);
|
|
237
|
+
border-color: var(--color-destructive);
|
|
396
238
|
}
|
|
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
|
-
const slot = this.shadowRoot.querySelector('slot');
|
|
431
|
-
if (!slot) return;
|
|
432
|
-
const highlightedPre = document.createElement('pre');
|
|
433
|
-
const highlightedCode = document.createElement('code');
|
|
434
|
-
highlightedCode.className = `language-${lang}`;
|
|
435
|
-
highlightedCode.innerHTML = html;
|
|
436
|
-
highlightedPre.appendChild(highlightedCode);
|
|
437
|
-
slot.replaceWith(highlightedPre);
|
|
438
|
-
const lightPre = this.querySelector('pre');
|
|
439
|
-
if (lightPre) lightPre.style.display = 'none';
|
|
440
|
-
}
|
|
441
|
-
getCodeText() {
|
|
442
|
-
if (this.shadowRoot) {
|
|
443
|
-
const shadowCode = this.shadowRoot.querySelector('pre code');
|
|
444
|
-
if (shadowCode) return shadowCode.textContent || '';
|
|
445
|
-
}
|
|
446
|
-
return this.textContent || '';
|
|
447
|
-
}
|
|
448
|
-
async copy() {
|
|
449
|
-
try {
|
|
450
|
-
const text = this.getCodeText();
|
|
451
|
-
await navigator.clipboard.writeText(text);
|
|
452
|
-
this.copyLabel = 'Copied!';
|
|
453
|
-
this._internals?.states.add('copied');
|
|
454
|
-
this._internals?.states.delete('failed');
|
|
455
|
-
this._setTimeout(()=>{
|
|
456
|
-
this.copyLabel = 'Copy';
|
|
457
|
-
this._internals?.states.delete('copied');
|
|
458
|
-
}, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
|
|
459
|
-
} catch (e) {
|
|
460
|
-
log.warn('Clipboard write failed:', e);
|
|
461
|
-
this.copyLabel = 'Failed';
|
|
462
|
-
this._internals?.states.add('failed');
|
|
463
|
-
this._internals?.states.delete('copied');
|
|
464
|
-
this._setTimeout(()=>{
|
|
465
|
-
this.copyLabel = 'Copy';
|
|
466
|
-
this._internals?.states.delete('failed');
|
|
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 };
|
|
239
|
+
`)];
|
|
240
|
+
copyLabel = "Copy";
|
|
241
|
+
getCodeText() {
|
|
242
|
+
return this.textContent || "";
|
|
243
|
+
}
|
|
244
|
+
async copy() {
|
|
245
|
+
try {
|
|
246
|
+
const text = this.getCodeText();
|
|
247
|
+
await navigator.clipboard.writeText(text);
|
|
248
|
+
this.copyLabel = "Copied!";
|
|
249
|
+
this._internals?.states.add("copied");
|
|
250
|
+
this._internals?.states.delete("failed");
|
|
251
|
+
this._setTimeout(() => {
|
|
252
|
+
this.copyLabel = "Copy";
|
|
253
|
+
this._internals?.states.delete("copied");
|
|
254
|
+
}, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
|
|
255
|
+
} catch (e) {
|
|
256
|
+
log.warn("Clipboard write failed:", e);
|
|
257
|
+
this.copyLabel = "Failed";
|
|
258
|
+
this._internals?.states.add("failed");
|
|
259
|
+
this._internals?.states.delete("copied");
|
|
260
|
+
this._setTimeout(() => {
|
|
261
|
+
this.copyLabel = "Copy";
|
|
262
|
+
this._internals?.states.delete("failed");
|
|
263
|
+
}, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
render() {
|
|
267
|
+
throw new Error("[open:compiled-element] open-code-block is compiled to a Part Program; the runtime JSX render path is not available.");
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
//#endregion
|
|
271
|
+
export { OpenCodeBlock, __elementMetadata, __partProgram };
|