@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.
@@ -1,336 +1,229 @@
1
- // <auto-generated by open:compiled-element; v0.44.0-alpha.1 - do not edit>
2
- import { OpenElement } from '@openelement/element';
3
- import { CODE_BLOCK_CONSTANTS, log, recipe } from './component-recipes.js';
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
- "version": 1,
7
- "tag": "open-code-block",
8
- "root": {
9
- "id": "root",
10
- "kind": "shadow-open",
11
- "nodes": [
12
- "e0"
13
- ]
14
- },
15
- "template": [
16
- {
17
- "k": "el",
18
- "id": "e0",
19
- "tag": "div",
20
- "attrs": [
21
- [
22
- "style",
23
- "display:contents"
24
- ]
25
- ],
26
- "children": [
27
- {
28
- "k": "el",
29
- "id": "e1",
30
- "tag": "slot",
31
- "attrs": [],
32
- "children": []
33
- },
34
- {
35
- "k": "el",
36
- "id": "e2",
37
- "tag": "button",
38
- "attrs": [
39
- [
40
- "type",
41
- "button"
42
- ],
43
- [
44
- "class",
45
- "copy-btn"
46
- ],
47
- [
48
- "part",
49
- "copy"
50
- ]
51
- ],
52
- "children": [
53
- {
54
- "k": "part",
55
- "id": "p1",
56
- "index": 1
57
- }
58
- ]
59
- }
60
- ]
61
- }
62
- ],
63
- "parts": [
64
- {
65
- "k": "event",
66
- "event": "click",
67
- "handler": "copy",
68
- "action": {
69
- "kind": "method",
70
- "name": "copy"
71
- },
72
- "path": [
73
- 0,
74
- 1
75
- ],
76
- "index": 0,
77
- "location": {
78
- "id": "p0",
79
- "kind": "sink",
80
- "path": [
81
- 0,
82
- 1
83
- ],
84
- "node": "e2"
85
- }
86
- },
87
- {
88
- "k": "text",
89
- "signal": "copyLabel",
90
- "index": 1,
91
- "location": {
92
- "id": "p1",
93
- "kind": "anchor",
94
- "path": [
95
- 0,
96
- 1,
97
- 0
98
- ]
99
- }
100
- }
101
- ],
102
- "regions": [],
103
- "dependencies": [
104
- {
105
- "signal": "copyLabel",
106
- "owner": {
107
- "kind": "part",
108
- "index": 1
109
- },
110
- "location": "p1"
111
- }
112
- ],
113
- "locations": [
114
- {
115
- "id": "e0",
116
- "kind": "element",
117
- "tag": "div",
118
- "path": [
119
- 0
120
- ]
121
- },
122
- {
123
- "id": "e1",
124
- "kind": "element",
125
- "tag": "slot",
126
- "path": [
127
- 0,
128
- 0
129
- ]
130
- },
131
- {
132
- "id": "e2",
133
- "kind": "element",
134
- "tag": "button",
135
- "path": [
136
- 0,
137
- 1
138
- ]
139
- },
140
- {
141
- "id": "p0",
142
- "kind": "sink",
143
- "part": 0,
144
- "node": "e2",
145
- "path": [
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
- "name": "copyLabel",
199
- "attribute": null,
200
- "type": "string",
201
- "converter": "string",
202
- "reflect": false,
203
- "default": "Copy"
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
- "tag": "open-code-block",
208
- "className": "OpenCodeBlock",
209
- "sourceFile": "open-code-block.tsx",
210
- "properties": [
211
- {
212
- "name": "copyLabel",
213
- "attribute": null,
214
- "type": "string",
215
- "converter": "string",
216
- "reflect": false,
217
- "default": "Copy"
218
- }
219
- ],
220
- "observedAttributes": [],
221
- "cem": {
222
- "tagName": "open-code-block",
223
- "className": "OpenCodeBlock",
224
- "declaration": {
225
- "name": "OpenCodeBlock",
226
- "module": "open-code-block.tsx"
227
- },
228
- "attributes": [],
229
- "members": [
230
- {
231
- "name": "copyLabel",
232
- "fieldName": "copyLabel",
233
- "type": "string",
234
- "attribute": null,
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
- copyLabel: {
243
- type: String,
244
- default: 'Copy',
245
- reflect: false,
246
- attribute: false
247
- }
248
- };
249
- export class OpenCodeBlock extends OpenElement {
250
- static __partProgram = __partProgram;
251
- static __compiledProperties = __compiledProperties;
252
- static __elementMetadata = __elementMetadata;
253
- static props = __compiledProps;
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(--size-2);
313
- right: var(--size-2);
314
- background: var(--brand-subtle);
315
- color: var(--code-text);
316
- padding: var(--size-1) var(--size-3);
317
- font-size: var(--font-size-00);
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-6);
212
+ font-weight: var(--font-weight-semibold);
320
213
  border: 0.5px solid transparent;
321
214
  cursor: pointer;
322
- border-radius: var(--radius-1);
323
- transition: all var(--ease-2) var(--duration-2);
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(--font-letterspacing-4);
218
+ letter-spacing: var(--tracking-wider);
326
219
  }
327
220
 
328
- /* No ink override on hover: --on-brand is the ink for a brand *fill*, and
329
- this chip's hover surface is a translucent brand tint instead, so the
330
- chip keeps the code surface's --code-text ink. */
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(--brand-glow);
333
- border-color: var(--brand);
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(--error);
344
- border-color: var(--error);
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
- const pre = this.querySelector(':scope > pre') || Array.from(this.children).find((c)=>c.tagName === 'PRE');
398
- if (!pre) return;
399
- const codeEl = pre.querySelector('code');
400
- if (!codeEl) return;
401
- let lang = 'typescript';
402
- const classes = codeEl.classList;
403
- for(let i = 0; i < classes.length; i++){
404
- if (classes[i].startsWith('language-')) {
405
- lang = classes[i].slice(9);
406
- break;
407
- }
408
- }
409
- const raw = codeEl.textContent || '';
410
- const grammar = p.languages?.[lang];
411
- if (!grammar) {
412
- // Grammar not registered yet: backoff 20, 40, 80, ..., 1000ms cap.
413
- this.scheduleRetry(20, 1000);
414
- return;
415
- }
416
- writeInstanceState(this, 'highlightRetries', 0);
417
- const highlightedHtml = p.highlight(raw, grammar, lang);
418
- this.injectHighlighted(highlightedHtml, lang);
419
- }
420
- scheduleRetry(base, cap) {
421
- const retries = readInstanceState(this, 'highlightRetries', ()=>0);
422
- if (retries >= CODE_BLOCK_CONSTANTS.maxHighlightRetries) return;
423
- writeInstanceState(this, 'highlightRetries', retries + 1);
424
- const delay = Math.min(base * Math.pow(2, Math.min(retries + 1, 6)), cap);
425
- this._setTimeout(()=>this.tryHighlight(), delay);
426
- }
427
- injectHighlighted(html, lang) {
428
- if (!this.shadowRoot || readInstanceState(this, 'highlighted', ()=>false)) return;
429
- writeInstanceState(this, 'highlighted', true);
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 };