@openelement/ui 1.0.0-alpha.6 → 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.
@@ -1,259 +1,216 @@
1
- // <auto-generated by open:compiled-element; part-program format 1 / module ABI 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 { 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
- "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
- }
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
- "name": "copyLabel",
199
- "attribute": null,
200
- "type": "string",
201
- "converter": "string",
202
- "reflect": false,
203
- "default": "Copy"
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
- "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
- }
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
- 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(`
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
- 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;
396
- }
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.');
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 };