@ac-base/ac-demo-content 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +88 -2
- package/index.js +8 -0
- package/package.json +45 -3
- package/src/clipboard.js +31 -0
- package/src/demo-case.js +84 -0
- package/src/demo-content.js +664 -0
- package/src/demo-content.styles.js +663 -0
- package/src/demo-content.styles.scss +679 -0
- package/src/highlight-html.js +80 -0
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
import { LitElement, html } from 'lit';
|
|
2
|
+
import { ComponentMixin } from '@ac-base/ac-component-mixin';
|
|
3
|
+
import { setGlobalLocale } from '@ac-base/ac-intl-mixin';
|
|
4
|
+
// Authored in demo-content.styles.scss, compiled to demo-content.styles.js by
|
|
5
|
+
// `pnpm run component:build:styles` (@ac-base/cli/scripts/compile-scss-to-lit.cjs). The compiled file
|
|
6
|
+
// is gitignored — run `pnpm install` then `pnpm component:build` or `pnpm component:serve` to generate it.
|
|
7
|
+
import { DemoContentStyles } from './demo-content.styles.js';
|
|
8
|
+
import { copyToClipboard } from './clipboard.js';
|
|
9
|
+
import { tokenizeHtml, splitTokensIntoLines } from './highlight-html.js';
|
|
10
|
+
|
|
11
|
+
const DEVICE_PRESETS = [
|
|
12
|
+
{ key: 'mobile', label: 'Móvil', width: 375, height: 667 },
|
|
13
|
+
{ key: 'tablet', label: 'Tablet', width: 768, height: 1024 },
|
|
14
|
+
{ key: 'desktop', label: 'Desktop', width: 1280, height: 800 },
|
|
15
|
+
];
|
|
16
|
+
const MAX_EVENT_LOG_ENTRIES = 50;
|
|
17
|
+
const COPIED_FEEDBACK_MS = 1600;
|
|
18
|
+
|
|
19
|
+
const COPY_ICON = html`<svg
|
|
20
|
+
viewBox="0 0 24 24"
|
|
21
|
+
width="14"
|
|
22
|
+
height="14"
|
|
23
|
+
fill="none"
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
stroke-width="2"
|
|
26
|
+
stroke-linecap="round"
|
|
27
|
+
stroke-linejoin="round"
|
|
28
|
+
aria-hidden="true"
|
|
29
|
+
>
|
|
30
|
+
<rect x="9" y="9" width="11" height="11" rx="2" />
|
|
31
|
+
<path d="M5 15V6a2 2 0 0 1 2-2h9" />
|
|
32
|
+
</svg>`;
|
|
33
|
+
|
|
34
|
+
const CHECK_ICON = html`<svg
|
|
35
|
+
viewBox="0 0 24 24"
|
|
36
|
+
width="14"
|
|
37
|
+
height="14"
|
|
38
|
+
fill="none"
|
|
39
|
+
stroke="currentColor"
|
|
40
|
+
stroke-width="2.5"
|
|
41
|
+
stroke-linecap="round"
|
|
42
|
+
stroke-linejoin="round"
|
|
43
|
+
aria-hidden="true"
|
|
44
|
+
>
|
|
45
|
+
<path d="M5 12.5l4.5 4.5L19 7.5" />
|
|
46
|
+
</svg>`;
|
|
47
|
+
|
|
48
|
+
const SUN_ICON = html`<svg
|
|
49
|
+
viewBox="0 0 24 24"
|
|
50
|
+
width="15"
|
|
51
|
+
height="15"
|
|
52
|
+
fill="none"
|
|
53
|
+
stroke="currentColor"
|
|
54
|
+
stroke-width="2"
|
|
55
|
+
stroke-linecap="round"
|
|
56
|
+
stroke-linejoin="round"
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
>
|
|
59
|
+
<circle cx="12" cy="12" r="4" />
|
|
60
|
+
<path
|
|
61
|
+
d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"
|
|
62
|
+
/>
|
|
63
|
+
</svg>`;
|
|
64
|
+
|
|
65
|
+
const MOON_ICON = html`<svg
|
|
66
|
+
viewBox="0 0 24 24"
|
|
67
|
+
width="15"
|
|
68
|
+
height="15"
|
|
69
|
+
fill="none"
|
|
70
|
+
stroke="currentColor"
|
|
71
|
+
stroke-width="2"
|
|
72
|
+
stroke-linecap="round"
|
|
73
|
+
stroke-linejoin="round"
|
|
74
|
+
aria-hidden="true"
|
|
75
|
+
>
|
|
76
|
+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79Z" />
|
|
77
|
+
</svg>`;
|
|
78
|
+
|
|
79
|
+
function parseList(value) {
|
|
80
|
+
return value
|
|
81
|
+
? value
|
|
82
|
+
.split(',')
|
|
83
|
+
.map(item => item.trim())
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
: [];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function languageLabel(localeCode) {
|
|
89
|
+
return localeCode.split('-')[0].toUpperCase();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const PLAIN_TOKEN_TYPES = new Set(['text', 'plain']);
|
|
93
|
+
|
|
94
|
+
function renderToken(token) {
|
|
95
|
+
return PLAIN_TOKEN_TYPES.has(token.type)
|
|
96
|
+
? token.text
|
|
97
|
+
: html`<span class="ac-demo-content__tok ac-demo-content__tok--${token.type}"
|
|
98
|
+
>${token.text}</span
|
|
99
|
+
>`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* ac-demo-content: contenedor centralizado para demos de componentes.
|
|
104
|
+
* Hijos: uno o más <ac-demo-case header="..." href="caso.html">. Controla,
|
|
105
|
+
* para el caso activo: idioma (switch de 2 opciones), ambient (seteado
|
|
106
|
+
* directamente sobre los componentes del caso activo), modo claro/oscuro
|
|
107
|
+
* (switch de 2 iconos, claro por defecto), tamaño de dispositivo (con marco
|
|
108
|
+
* y ALTURA fijos por preset — el contenido scrollea adentro, no empuja el
|
|
109
|
+
* marco), vista visual/código (código muestra el HTML fuente del caso
|
|
110
|
+
* activo) y un panel lateral de eventos con el detalle de cada uno.
|
|
111
|
+
*/
|
|
112
|
+
export class DemoContent extends ComponentMixin(LitElement) {
|
|
113
|
+
static get is() {
|
|
114
|
+
return 'ac-demo-content';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static get styles() {
|
|
118
|
+
return [DemoContentStyles];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static get properties() {
|
|
122
|
+
return {
|
|
123
|
+
name: { type: String },
|
|
124
|
+
tech: { type: String },
|
|
125
|
+
packageName: { type: String, attribute: 'package-name' },
|
|
126
|
+
docsHref: { type: String, attribute: 'docs-href' },
|
|
127
|
+
language: { type: String },
|
|
128
|
+
ambients: { type: String },
|
|
129
|
+
events: { type: String },
|
|
130
|
+
darkMode: { type: Boolean, reflect: true, attribute: 'dark-mode' },
|
|
131
|
+
_activeCaseIndex: { state: true },
|
|
132
|
+
_activeDevice: { state: true },
|
|
133
|
+
_viewMode: { state: true },
|
|
134
|
+
_langIndex: { state: true },
|
|
135
|
+
_theme: { state: true },
|
|
136
|
+
_eventLog: { state: true },
|
|
137
|
+
_eventsPanelOpen: { state: true },
|
|
138
|
+
_copiedCommand: { state: true },
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
constructor() {
|
|
143
|
+
super();
|
|
144
|
+
this.name = '';
|
|
145
|
+
this.tech = '';
|
|
146
|
+
this.packageName = '';
|
|
147
|
+
this.docsHref = '';
|
|
148
|
+
this.language = '';
|
|
149
|
+
this.ambients = '';
|
|
150
|
+
this.events = '';
|
|
151
|
+
this.darkMode = false;
|
|
152
|
+
this._activeCaseIndex = 0;
|
|
153
|
+
this._activeDevice = 'mobile';
|
|
154
|
+
this._viewMode = 'visual';
|
|
155
|
+
this._langIndex = 0;
|
|
156
|
+
this._theme = 'light';
|
|
157
|
+
this._eventLog = [];
|
|
158
|
+
this._eventsPanelOpen = false;
|
|
159
|
+
this._copiedCommand = null;
|
|
160
|
+
this._copiedTimer = undefined;
|
|
161
|
+
this._onEvent = this._onEvent.bind(this);
|
|
162
|
+
this._onPanelKeydown = this._onPanelKeydown.bind(this);
|
|
163
|
+
this._onCaseLoad = this._onCaseLoad.bind(this);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get _languages() {
|
|
167
|
+
return parseList(this.language);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get _ambientOptions() {
|
|
171
|
+
return parseList(this.ambients);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
get _eventNames() {
|
|
175
|
+
return parseList(this.events);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get _cases() {
|
|
179
|
+
return Array.from(this.querySelectorAll(':scope > ac-demo-case'));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
connectedCallback() {
|
|
183
|
+
super.connectedCallback();
|
|
184
|
+
for (const name of this._eventNames) {
|
|
185
|
+
document.addEventListener(name, this._onEvent);
|
|
186
|
+
}
|
|
187
|
+
this.addEventListener('ac-demo-case-load', this._onCaseLoad);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
disconnectedCallback() {
|
|
191
|
+
for (const name of this._eventNames) {
|
|
192
|
+
document.removeEventListener(name, this._onEvent);
|
|
193
|
+
}
|
|
194
|
+
this.removeEventListener('ac-demo-case-load', this._onCaseLoad);
|
|
195
|
+
document.removeEventListener('keydown', this._onPanelKeydown);
|
|
196
|
+
clearTimeout(this._copiedTimer);
|
|
197
|
+
super.disconnectedCallback();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
firstUpdated() {
|
|
201
|
+
this._activateCase(0);
|
|
202
|
+
document.documentElement.setAttribute('data-theme', this._theme);
|
|
203
|
+
if (this._languages.length === 2) {
|
|
204
|
+
setGlobalLocale(this._languages[this._langIndex]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_onEvent(event) {
|
|
209
|
+
const entry = { time: new Date().toLocaleTimeString(), name: event.type, detail: event.detail };
|
|
210
|
+
this._eventLog = [entry, ...this._eventLog].slice(0, MAX_EVENT_LOG_ENTRIES);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
_activateCase(index) {
|
|
214
|
+
const cases = this._cases;
|
|
215
|
+
cases.forEach((caseEl, i) => {
|
|
216
|
+
caseEl.active = i === index;
|
|
217
|
+
});
|
|
218
|
+
this._activeCaseIndex = index;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
_onCaseChange(event) {
|
|
222
|
+
this._activateCase(Number(event.target.value));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
_onLanguageSelect(index) {
|
|
226
|
+
this._langIndex = index;
|
|
227
|
+
setGlobalLocale(this._languages[index]);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
_onAmbientChange(event) {
|
|
231
|
+
const value = event.target.value;
|
|
232
|
+
const activeCase = this._cases[this._activeCaseIndex];
|
|
233
|
+
if (!activeCase) return;
|
|
234
|
+
|
|
235
|
+
for (const el of activeCase.querySelectorAll('*')) {
|
|
236
|
+
if ('ambient' in el) {
|
|
237
|
+
el.ambient = value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Un modal/toast/transition "contenido" de un caso renuncia a la capa
|
|
243
|
+
// superior nativa (`showModal()`/`popover` SIEMPRE bloquean toda la página
|
|
244
|
+
// real e ignoran cualquier ancestro para medirse — ver "Superposiciones" en
|
|
245
|
+
// CONVENTIONS.md) y se abre con `dialog.show()`/`popover="manual"` sin
|
|
246
|
+
// modal. Pero `position: absolute`/`fixed` tampoco resuelve contra un
|
|
247
|
+
// ancestro a través del límite de shadow DOM (probado empíricamente: el
|
|
248
|
+
// `offsetParent` de un `<dialog>` slotteado da `<body>`, no el div del
|
|
249
|
+
// viewport simulado, aun con ese div en `position: relative` y el host en
|
|
250
|
+
// `display: contents`) — así que el componente igual necesita medir el
|
|
251
|
+
// viewport simulado por JS. `getBoundary` es una función (no el elemento)
|
|
252
|
+
// porque ese div se reconstruye al alternar Visual/Código.
|
|
253
|
+
_onCaseLoad(event) {
|
|
254
|
+
this._applyContainment(event.target);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
_applyContainment(caseEl) {
|
|
258
|
+
const getBoundary = () => this.renderRoot.querySelector('.ac-demo-content__viewport');
|
|
259
|
+
for (const el of caseEl.querySelectorAll('*')) {
|
|
260
|
+
if ('contained' in el) {
|
|
261
|
+
el.getBoundary = getBoundary;
|
|
262
|
+
el.contained = true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
_onThemeSelect(theme) {
|
|
268
|
+
this._theme = theme;
|
|
269
|
+
document.documentElement.setAttribute('data-theme', theme);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
_onDeviceSelect(key) {
|
|
273
|
+
this._activeDevice = key;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
_onViewModeSelect(mode) {
|
|
277
|
+
this._viewMode = mode;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async _onInstallCommandClick(command) {
|
|
281
|
+
const copied = await copyToClipboard(command);
|
|
282
|
+
if (!copied) return;
|
|
283
|
+
|
|
284
|
+
this._copiedCommand = command;
|
|
285
|
+
this.dispatchEvent(
|
|
286
|
+
new CustomEvent('ac-demo-content-copy', {
|
|
287
|
+
detail: { text: command },
|
|
288
|
+
bubbles: true,
|
|
289
|
+
composed: true,
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
clearTimeout(this._copiedTimer);
|
|
293
|
+
this._copiedTimer = setTimeout(() => {
|
|
294
|
+
this._copiedCommand = null;
|
|
295
|
+
}, COPIED_FEEDBACK_MS);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
_onEventsButtonClick() {
|
|
299
|
+
this._eventsPanelOpen = true;
|
|
300
|
+
document.addEventListener('keydown', this._onPanelKeydown);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
_onEventsPanelClose() {
|
|
304
|
+
this._eventsPanelOpen = false;
|
|
305
|
+
document.removeEventListener('keydown', this._onPanelKeydown);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
_onPanelKeydown(event) {
|
|
309
|
+
if (event.key === 'Escape') {
|
|
310
|
+
this._onEventsPanelClose();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
render() {
|
|
315
|
+
const hasHeader = Boolean(this.name || this.tech || this.packageName || this.docsHref);
|
|
316
|
+
const devicePreset = DEVICE_PRESETS.find(preset => preset.key === this._activeDevice);
|
|
317
|
+
|
|
318
|
+
return html`
|
|
319
|
+
${hasHeader ? this._renderHeader() : ''}
|
|
320
|
+
|
|
321
|
+
<div part="toolbar" class="ac-demo-content__toolbar">
|
|
322
|
+
<div class="ac-demo-content__toolbar-cases">${this._renderCaseSwitcher(this._cases)}</div>
|
|
323
|
+
<div class="ac-demo-content__toolbar-controls">
|
|
324
|
+
${this._languages.length === 2 ? this._renderLanguageSwitcher() : ''}
|
|
325
|
+
${this._ambientOptions.length ? this._renderAmbientSwitcher() : ''}
|
|
326
|
+
${this.darkMode ? this._renderThemeSwitcher() : ''} ${this._renderDeviceSwitcher()}
|
|
327
|
+
${this._renderViewModeSwitcher()}
|
|
328
|
+
${this._eventNames.length ? this._renderEventsButton() : ''}
|
|
329
|
+
</div>
|
|
330
|
+
</div>
|
|
331
|
+
|
|
332
|
+
<div class="ac-demo-content__stage">
|
|
333
|
+
${this._viewMode === 'code' ? this._renderCodeView() : this._renderDeviceStage(devicePreset)}
|
|
334
|
+
</div>
|
|
335
|
+
|
|
336
|
+
${this._eventsPanelOpen ? this._renderEventsPanel() : ''}
|
|
337
|
+
`;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
_renderHeader() {
|
|
341
|
+
return html`
|
|
342
|
+
<div class="ac-demo-content__header">
|
|
343
|
+
<div class="ac-demo-content__header-title">
|
|
344
|
+
${this.name ? html`<h2 class="ac-demo-content__name">${this.name}</h2>` : ''}
|
|
345
|
+
${this.tech ? html`<span class="ac-demo-content__tech-badge">${this.tech}</span>` : ''}
|
|
346
|
+
</div>
|
|
347
|
+
${
|
|
348
|
+
this.packageName || this.docsHref
|
|
349
|
+
? html`
|
|
350
|
+
<div class="ac-demo-content__header-meta">
|
|
351
|
+
${this.packageName ? this._renderInstallSnippets() : ''}
|
|
352
|
+
${
|
|
353
|
+
this.docsHref
|
|
354
|
+
? html`<a
|
|
355
|
+
class="ac-demo-content__docs-link"
|
|
356
|
+
href=${this.docsHref}
|
|
357
|
+
target="_blank"
|
|
358
|
+
rel="noopener noreferrer"
|
|
359
|
+
>Documentación</a
|
|
360
|
+
>`
|
|
361
|
+
: ''
|
|
362
|
+
}
|
|
363
|
+
</div>
|
|
364
|
+
`
|
|
365
|
+
: ''
|
|
366
|
+
}
|
|
367
|
+
</div>
|
|
368
|
+
`;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
_renderInstallSnippets() {
|
|
372
|
+
const commands = [`pnpm add ${this.packageName}`, `npm i ${this.packageName}`];
|
|
373
|
+
return html`
|
|
374
|
+
<div class="ac-demo-content__install">
|
|
375
|
+
${commands.map(command => this._renderInstallCommand(command))}
|
|
376
|
+
<span class="ac-demo-content__visually-hidden" role="status" aria-live="polite"
|
|
377
|
+
>${this._copiedCommand ? 'Copiado al portapapeles' : ''}</span
|
|
378
|
+
>
|
|
379
|
+
</div>
|
|
380
|
+
`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
_renderInstallCommand(command) {
|
|
384
|
+
const copied = this._copiedCommand === command;
|
|
385
|
+
return html`
|
|
386
|
+
<button
|
|
387
|
+
type="button"
|
|
388
|
+
class=${`ac-demo-content__install-cmd${copied ? ' ac-demo-content__install-cmd--copied' : ''}`}
|
|
389
|
+
aria-label=${`Copiar comando: ${command}`}
|
|
390
|
+
title="Copiar al portapapeles"
|
|
391
|
+
@click=${() => this._onInstallCommandClick(command)}
|
|
392
|
+
>
|
|
393
|
+
${command}${copied ? CHECK_ICON : COPY_ICON}
|
|
394
|
+
</button>
|
|
395
|
+
`;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
_renderSegmented({ wrapperClass, ariaLabel, options, activeValue, onSelect }) {
|
|
399
|
+
return html`
|
|
400
|
+
<div class="ac-demo-content__segmented ${wrapperClass}" role="group" aria-label=${ariaLabel}>
|
|
401
|
+
${options.map(
|
|
402
|
+
(option, index) => html`
|
|
403
|
+
${index > 0 ? html`<span class="ac-demo-content__segmented-divider"></span>` : ''}
|
|
404
|
+
<button
|
|
405
|
+
type="button"
|
|
406
|
+
data-value=${option.value}
|
|
407
|
+
class=${`ac-demo-content__segmented-button${
|
|
408
|
+
option.value === activeValue ? ' ac-demo-content__segmented-button--active' : ''
|
|
409
|
+
}`}
|
|
410
|
+
aria-pressed=${option.value === activeValue}
|
|
411
|
+
aria-label=${option.ariaLabel ?? ''}
|
|
412
|
+
@click=${() => onSelect(option.value)}
|
|
413
|
+
>
|
|
414
|
+
${option.icon ?? option.label}
|
|
415
|
+
</button>
|
|
416
|
+
`,
|
|
417
|
+
)}
|
|
418
|
+
</div>
|
|
419
|
+
`;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
_renderCaseSwitcher(cases) {
|
|
423
|
+
const activeCase = cases[this._activeCaseIndex];
|
|
424
|
+
const activeLabel = activeCase?.header || `Caso ${this._activeCaseIndex + 1}`;
|
|
425
|
+
return html`
|
|
426
|
+
<label class="ac-demo-content__field ac-demo-content__field--case">
|
|
427
|
+
<span class="ac-demo-content__field-label">Caso</span>
|
|
428
|
+
<select
|
|
429
|
+
class="ac-demo-content__case-select"
|
|
430
|
+
title=${activeLabel}
|
|
431
|
+
@change=${this._onCaseChange}
|
|
432
|
+
>
|
|
433
|
+
${cases.map(
|
|
434
|
+
(caseEl, i) => html`
|
|
435
|
+
<option value=${i} ?selected=${i === this._activeCaseIndex}>
|
|
436
|
+
${caseEl.header || `Caso ${i + 1}`}
|
|
437
|
+
</option>
|
|
438
|
+
`,
|
|
439
|
+
)}
|
|
440
|
+
</select>
|
|
441
|
+
</label>
|
|
442
|
+
`;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
_renderLanguageSwitcher() {
|
|
446
|
+
const [first, second] = this._languages;
|
|
447
|
+
return this._renderSegmented({
|
|
448
|
+
wrapperClass: 'ac-demo-content__locale-switcher',
|
|
449
|
+
ariaLabel: 'Idioma',
|
|
450
|
+
activeValue: this._langIndex,
|
|
451
|
+
onSelect: index => this._onLanguageSelect(index),
|
|
452
|
+
options: [
|
|
453
|
+
{ value: 0, label: languageLabel(first), ariaLabel: `Idioma: ${first}` },
|
|
454
|
+
{ value: 1, label: languageLabel(second), ariaLabel: `Idioma: ${second}` },
|
|
455
|
+
],
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
_renderAmbientSwitcher() {
|
|
460
|
+
return html`
|
|
461
|
+
<label class="ac-demo-content__field">
|
|
462
|
+
<span class="ac-demo-content__field-label">Ambiente</span>
|
|
463
|
+
<select class="ac-demo-content__ambient-select" @change=${this._onAmbientChange}>
|
|
464
|
+
${this._ambientOptions.map(ambient => html`<option value=${ambient}>${ambient}</option>`)}
|
|
465
|
+
</select>
|
|
466
|
+
</label>
|
|
467
|
+
`;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
_renderThemeSwitcher() {
|
|
471
|
+
return this._renderSegmented({
|
|
472
|
+
wrapperClass: 'ac-demo-content__theme-switcher',
|
|
473
|
+
ariaLabel: 'Tema',
|
|
474
|
+
activeValue: this._theme,
|
|
475
|
+
onSelect: theme => this._onThemeSelect(theme),
|
|
476
|
+
options: [
|
|
477
|
+
{ value: 'light', icon: SUN_ICON, ariaLabel: 'Modo claro' },
|
|
478
|
+
{ value: 'dark', icon: MOON_ICON, ariaLabel: 'Modo oscuro' },
|
|
479
|
+
],
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
_renderDeviceSwitcher() {
|
|
484
|
+
return this._renderSegmented({
|
|
485
|
+
wrapperClass: 'ac-demo-content__device-switcher',
|
|
486
|
+
ariaLabel: 'Tamaño del dispositivo',
|
|
487
|
+
activeValue: this._activeDevice,
|
|
488
|
+
onSelect: key => this._onDeviceSelect(key),
|
|
489
|
+
options: DEVICE_PRESETS.map(preset => ({
|
|
490
|
+
value: preset.key,
|
|
491
|
+
label: preset.label,
|
|
492
|
+
ariaLabel: preset.label,
|
|
493
|
+
})),
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
_renderViewModeSwitcher() {
|
|
498
|
+
return this._renderSegmented({
|
|
499
|
+
wrapperClass: 'ac-demo-content__viewmode-switcher',
|
|
500
|
+
ariaLabel: 'Tipo de vista',
|
|
501
|
+
activeValue: this._viewMode,
|
|
502
|
+
onSelect: mode => this._onViewModeSelect(mode),
|
|
503
|
+
options: [
|
|
504
|
+
{ value: 'visual', label: 'Visual', ariaLabel: 'Vista visual' },
|
|
505
|
+
{ value: 'code', label: 'Código', ariaLabel: 'Vista de código' },
|
|
506
|
+
],
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
_renderDeviceStage(devicePreset) {
|
|
511
|
+
return html`
|
|
512
|
+
<div
|
|
513
|
+
part="device-frame"
|
|
514
|
+
class="ac-demo-content__device-frame ac-demo-content__device-frame--${this._activeDevice}"
|
|
515
|
+
style="--ac-demo-content-device-width: ${devicePreset.width}px; --ac-demo-content-device-height: ${devicePreset.height}px"
|
|
516
|
+
>
|
|
517
|
+
<div class="ac-demo-content__device-chrome" aria-hidden="true">
|
|
518
|
+
${
|
|
519
|
+
this._activeDevice === 'desktop'
|
|
520
|
+
? html`
|
|
521
|
+
<span class="ac-demo-content__device-dot"></span>
|
|
522
|
+
<span class="ac-demo-content__device-dot"></span>
|
|
523
|
+
<span class="ac-demo-content__device-dot"></span>
|
|
524
|
+
`
|
|
525
|
+
: html`<span class="ac-demo-content__device-notch"></span>`
|
|
526
|
+
}
|
|
527
|
+
</div>
|
|
528
|
+
<div part="viewport" class="ac-demo-content__viewport">
|
|
529
|
+
<slot></slot>
|
|
530
|
+
</div>
|
|
531
|
+
</div>
|
|
532
|
+
`;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
_renderCodeView() {
|
|
536
|
+
const activeCase = this._cases[this._activeCaseIndex];
|
|
537
|
+
const source = (activeCase?.source ?? '')
|
|
538
|
+
.replace(/\r\n?/g, '\n')
|
|
539
|
+
.replace(/^\s*\n/, '')
|
|
540
|
+
.trimEnd();
|
|
541
|
+
const fileName = activeCase?.href?.split('/').pop() || 'caso.html';
|
|
542
|
+
const lines = source
|
|
543
|
+
? splitTokensIntoLines(tokenizeHtml(source))
|
|
544
|
+
: [[{ type: 'text', text: 'Cargando…' }]];
|
|
545
|
+
|
|
546
|
+
return html`
|
|
547
|
+
<div class="ac-demo-content__code-view">
|
|
548
|
+
<div class="ac-demo-content__code-editor">
|
|
549
|
+
<div class="ac-demo-content__code-titlebar">
|
|
550
|
+
<span class="ac-demo-content__code-dots" aria-hidden="true"><i></i><i></i><i></i></span>
|
|
551
|
+
<span class="ac-demo-content__code-filename">${fileName}</span>
|
|
552
|
+
<span class="ac-demo-content__code-lang">HTML</span>
|
|
553
|
+
</div>
|
|
554
|
+
<div
|
|
555
|
+
class="ac-demo-content__code-block"
|
|
556
|
+
role="region"
|
|
557
|
+
tabindex="0"
|
|
558
|
+
aria-label=${`Código fuente de ${fileName}`}
|
|
559
|
+
>
|
|
560
|
+
${lines.map(
|
|
561
|
+
(tokens, index) => html`
|
|
562
|
+
<div class="ac-demo-content__code-line">
|
|
563
|
+
<span class="ac-demo-content__code-gutter" aria-hidden="true">${index + 1}</span>
|
|
564
|
+
<span class="ac-demo-content__code-text">${tokens.map(renderToken)}</span>
|
|
565
|
+
</div>
|
|
566
|
+
`,
|
|
567
|
+
)}
|
|
568
|
+
</div>
|
|
569
|
+
</div>
|
|
570
|
+
</div>
|
|
571
|
+
`;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
_renderEventsButton() {
|
|
575
|
+
return html`
|
|
576
|
+
<button
|
|
577
|
+
type="button"
|
|
578
|
+
class="ac-demo-content__events-button"
|
|
579
|
+
aria-label="Ver eventos disparados: ${this._eventLog.length}"
|
|
580
|
+
@click=${this._onEventsButtonClick}
|
|
581
|
+
>
|
|
582
|
+
<svg
|
|
583
|
+
viewBox="0 0 24 24"
|
|
584
|
+
width="18"
|
|
585
|
+
height="18"
|
|
586
|
+
aria-hidden="true"
|
|
587
|
+
fill="none"
|
|
588
|
+
stroke="currentColor"
|
|
589
|
+
stroke-width="2"
|
|
590
|
+
stroke-linecap="round"
|
|
591
|
+
stroke-linejoin="round"
|
|
592
|
+
>
|
|
593
|
+
<path
|
|
594
|
+
d="M12 2a6 6 0 0 0-6 6v3.5c0 .9-.4 1.7-1 2.3L4 15h16l-1-1.2c-.6-.6-1-1.4-1-2.3V8a6 6 0 0 0-6-6Z"
|
|
595
|
+
/>
|
|
596
|
+
<path d="M9 19a3 3 0 0 0 6 0" />
|
|
597
|
+
</svg>
|
|
598
|
+
${
|
|
599
|
+
this._eventLog.length
|
|
600
|
+
? html`<span class="ac-demo-content__events-count">${this._eventLog.length}</span>`
|
|
601
|
+
: ''
|
|
602
|
+
}
|
|
603
|
+
</button>
|
|
604
|
+
`;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
_renderEventsPanel() {
|
|
608
|
+
return html`
|
|
609
|
+
<div class="ac-demo-content__panel-backdrop" @click=${this._onEventsPanelClose}>
|
|
610
|
+
<div
|
|
611
|
+
class="ac-demo-content__modal"
|
|
612
|
+
role="dialog"
|
|
613
|
+
aria-modal="true"
|
|
614
|
+
aria-label="Eventos del demo"
|
|
615
|
+
@click=${event => event.stopPropagation()}
|
|
616
|
+
>
|
|
617
|
+
<div class="ac-demo-content__modal-header">
|
|
618
|
+
<h2 class="ac-demo-content__modal-title">Eventos</h2>
|
|
619
|
+
<button
|
|
620
|
+
type="button"
|
|
621
|
+
class="ac-demo-content__modal-close"
|
|
622
|
+
aria-label="Cerrar"
|
|
623
|
+
@click=${this._onEventsPanelClose}
|
|
624
|
+
>
|
|
625
|
+
✕
|
|
626
|
+
</button>
|
|
627
|
+
</div>
|
|
628
|
+
<p class="ac-demo-content__modal-config">
|
|
629
|
+
<strong>Escuchando:</strong> <code>${this._eventNames.join(', ')}</code>
|
|
630
|
+
</p>
|
|
631
|
+
<div class="ac-demo-content__modal-list">
|
|
632
|
+
${
|
|
633
|
+
this._eventLog.length
|
|
634
|
+
? this._eventLog.map(
|
|
635
|
+
entry => html`
|
|
636
|
+
<div class="ac-demo-content__modal-entry">
|
|
637
|
+
<div class="ac-demo-content__modal-entry-row">
|
|
638
|
+
<span class="ac-demo-content__modal-entry-label">Evento:</span>
|
|
639
|
+
<span class="ac-demo-content__modal-entry-value">${entry.name}</span>
|
|
640
|
+
</div>
|
|
641
|
+
<div class="ac-demo-content__modal-entry-row">
|
|
642
|
+
<span class="ac-demo-content__modal-entry-label">Hora:</span>
|
|
643
|
+
<span class="ac-demo-content__modal-entry-value">${entry.time}</span>
|
|
644
|
+
</div>
|
|
645
|
+
<div
|
|
646
|
+
class="ac-demo-content__modal-entry-row ac-demo-content__modal-entry-row--block"
|
|
647
|
+
>
|
|
648
|
+
<span class="ac-demo-content__modal-entry-label">Payload:</span>
|
|
649
|
+
<pre class="ac-demo-content__modal-entry-detail">
|
|
650
|
+
${JSON.stringify(entry.detail, null, 2)}</pre>
|
|
651
|
+
</div>
|
|
652
|
+
</div>
|
|
653
|
+
`,
|
|
654
|
+
)
|
|
655
|
+
: html`<p class="ac-demo-content__modal-empty">
|
|
656
|
+
Todavía no se disparó ningún evento.
|
|
657
|
+
</p>`
|
|
658
|
+
}
|
|
659
|
+
</div>
|
|
660
|
+
</div>
|
|
661
|
+
</div>
|
|
662
|
+
`;
|
|
663
|
+
}
|
|
664
|
+
}
|