@govbr-ds/playground 0.0.0-stage → 5.2.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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -2
  3. package/dist/Playground.d.ts +7 -0
  4. package/dist/Playground.d.ts.map +1 -0
  5. package/dist/browser/chunks/babel-TRTEHJWP.js +16 -0
  6. package/dist/browser/chunks/chunk-3JEV5GFZ.js +1 -0
  7. package/dist/browser/chunks/chunk-5A3ZKBRD.js +11 -0
  8. package/dist/browser/chunks/chunk-EP7B2XPY.js +13 -0
  9. package/dist/browser/chunks/chunk-JM73XHPL.js +25 -0
  10. package/dist/browser/chunks/chunk-TFWQIFOZ.js +1 -0
  11. package/dist/browser/chunks/chunk-UVFYWQD2.js +1 -0
  12. package/dist/browser/chunks/chunk-WUR2JRNJ.js +1 -0
  13. package/dist/browser/chunks/chunk-Y6SLVHK3.js +1 -0
  14. package/dist/browser/chunks/chunk-ZIL2IWZ3.js +1 -0
  15. package/dist/browser/chunks/dist-AKMJXMTZ.js +1 -0
  16. package/dist/browser/chunks/dist-KS4J6S7U.js +1 -0
  17. package/dist/browser/chunks/dist-VIVGCYF5.js +1 -0
  18. package/dist/browser/chunks/esm-BWS4JPZG.js +2 -0
  19. package/dist/browser/chunks/esm-R75BP3LA.js +1 -0
  20. package/dist/browser/chunks/estree-UYKKTIFA.js +44 -0
  21. package/dist/browser/chunks/html-TM3VAO62.js +25 -0
  22. package/dist/browser/chunks/postcss-JAVHFEUM.js +62 -0
  23. package/dist/browser/chunks/standalone-IDMVEPER.js +29 -0
  24. package/dist/browser/index.d.ts +8 -0
  25. package/dist/browser/index.d.ts.map +1 -0
  26. package/dist/browser/index.js +397 -0
  27. package/dist/components/CodeMirrorEditor.d.ts +22 -0
  28. package/dist/components/CodeMirrorEditor.d.ts.map +1 -0
  29. package/dist/components/ControlsPanel.d.ts +17 -0
  30. package/dist/components/ControlsPanel.d.ts.map +1 -0
  31. package/dist/components/Workbench.d.ts +21 -0
  32. package/dist/components/Workbench.d.ts.map +1 -0
  33. package/dist/core/index.d.ts +233 -0
  34. package/dist/core/index.d.ts.map +1 -0
  35. package/dist/core/index.js +410 -0
  36. package/dist/index.d.ts +6 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/library/components.d.ts +36 -0
  39. package/dist/library/components.d.ts.map +1 -0
  40. package/dist/library/profile.d.ts +23 -0
  41. package/dist/library/profile.d.ts.map +1 -0
  42. package/dist/react/chunks/babel-TRTEHJWP.js +16 -0
  43. package/dist/react/chunks/chunk-3JEV5GFZ.js +1 -0
  44. package/dist/react/chunks/chunk-5A3ZKBRD.js +11 -0
  45. package/dist/react/chunks/chunk-EP7B2XPY.js +13 -0
  46. package/dist/react/chunks/chunk-TFWQIFOZ.js +1 -0
  47. package/dist/react/chunks/chunk-UVFYWQD2.js +1 -0
  48. package/dist/react/chunks/chunk-WUR2JRNJ.js +1 -0
  49. package/dist/react/chunks/chunk-Y6SLVHK3.js +1 -0
  50. package/dist/react/chunks/chunk-ZIL2IWZ3.js +1 -0
  51. package/dist/react/chunks/dist-AKMJXMTZ.js +1 -0
  52. package/dist/react/chunks/dist-KS4J6S7U.js +1 -0
  53. package/dist/react/chunks/dist-VIVGCYF5.js +1 -0
  54. package/dist/react/chunks/esm-R75BP3LA.js +1 -0
  55. package/dist/react/chunks/esm-WLDNKOOE.js +2 -0
  56. package/dist/react/chunks/estree-UYKKTIFA.js +44 -0
  57. package/dist/react/chunks/html-TM3VAO62.js +25 -0
  58. package/dist/react/chunks/postcss-JAVHFEUM.js +62 -0
  59. package/dist/react/chunks/standalone-IDMVEPER.js +29 -0
  60. package/dist/react/index.js +354 -0
  61. package/dist/sources.d.ts +47 -0
  62. package/dist/sources.d.ts.map +1 -0
  63. package/dist/styles.css +2046 -0
  64. package/dist/utils/drafts.d.ts +9 -0
  65. package/dist/utils/drafts.d.ts.map +1 -0
  66. package/dist/utils/editorHistory.d.ts +14 -0
  67. package/dist/utils/editorHistory.d.ts.map +1 -0
  68. package/dist/utils/encoders.d.ts +43 -0
  69. package/dist/utils/encoders.d.ts.map +1 -0
  70. package/dist/utils/formatters.d.ts +6 -0
  71. package/dist/utils/formatters.d.ts.map +1 -0
  72. package/dist/utils/frameworks.d.ts +15 -0
  73. package/dist/utils/frameworks.d.ts.map +1 -0
  74. package/dist/utils/previewLocale.d.ts +19 -0
  75. package/dist/utils/previewLocale.d.ts.map +1 -0
  76. package/dist/utils/sourceModel.d.ts +52 -0
  77. package/dist/utils/sourceModel.d.ts.map +1 -0
  78. package/dist/utils/visibility.d.ts +3 -0
  79. package/dist/utils/visibility.d.ts.map +1 -0
  80. package/docs/configuration.md +400 -0
  81. package/package.json +59 -3
@@ -0,0 +1,410 @@
1
+ // src/library/profile.ts
2
+ var DEFAULT_LIBRARY = { profile: "wbc", version: "2.7.0", fontAwesomeVersion: "6.7.2" };
3
+ function resolveLibrary(library = DEFAULT_LIBRARY) {
4
+ const profile = library.profile;
5
+ if (profile !== "wbc" && profile !== "wbc-v4") throw new TypeError("library.profile deve ser wbc ou wbc-v4.");
6
+ if (library.fontAwesomeVersion !== void 0 && !["5.15.4", "6.7.2"].includes(library.fontAwesomeVersion))
7
+ throw new TypeError("library.fontAwesomeVersion deve ser 5.15.4 ou 6.7.2.");
8
+ const version = library.version ?? (profile === "wbc" ? "2.7.0" : void 0);
9
+ if (!library.moduleUrl && !version) throw new Error("Informe version ou moduleUrl para WBC v4.");
10
+ const packageName = profile === "wbc" ? "@govbr-ds/webcomponents" : "@govbr-ds/components";
11
+ const directory = profile === "wbc" ? "components" : "custom-elements";
12
+ return {
13
+ profile,
14
+ registration: library.registration ?? "module",
15
+ fontAwesomeVersion: library.fontAwesomeVersion ?? "6.7.2",
16
+ moduleUrl: library.moduleUrl ?? `https://cdn.jsdelivr.net/npm/${packageName}@${version}/dist/${directory}/index.js`,
17
+ styles: library.styles ?? (profile === "wbc" ? ["https://cdn.jsdelivr.net/npm/@govbr-ds/core@3.6.2/dist/core.min.css"] : [
18
+ ...[
19
+ "tokens.css",
20
+ "theme/light/tokens.css",
21
+ "theme/dark/tokens.css",
22
+ "theme/light/contrast-mode.css",
23
+ "theme/dark/contrast-mode.css"
24
+ ].map(
25
+ (file) => `https://cdn.jsdelivr.net/npm/@govbr-ds/tokens@${library.tokensVersion ?? "4.0.0-next.39"}/dist/css/${file}`
26
+ ),
27
+ "https://cdn.jsdelivr.net/npm/@fontsource/noto-sans@5.3.0/latin.css",
28
+ "https://cdn.jsdelivr.net/npm/@fontsource/noto-sans@5.3.0/latin-italic.css"
29
+ ])
30
+ };
31
+ }
32
+ var globalRegistry = globalThis;
33
+ var documents = globalRegistry.__govbrPlaygroundLibraries ??= /* @__PURE__ */ new WeakMap();
34
+ function libraryResources(config) {
35
+ const library = resolveLibrary(config);
36
+ return [
37
+ ...library.styles.map((href, index) => ({ id: `library-style-${index}`, type: "style", href })),
38
+ {
39
+ id: "library-registration",
40
+ type: "inline-module",
41
+ content: `import * as library from ${JSON.stringify(library.moduleUrl)}; for (const [name, register] of Object.entries(library)) { if (/^defineCustomElement/.test(name) && typeof register === 'function') await register(); }`
42
+ }
43
+ ];
44
+ }
45
+
46
+ // src/core/index.ts
47
+ var escapeInline = (value) => value.replace(/<\/(script)/gi, "<\\/$1");
48
+ var escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
49
+ var escapeText = (value) => escapeAttribute(value).replace(/>/g, "&gt;");
50
+ function createPreviewDocument(config, channelId) {
51
+ const library = resolveLibrary(config.runtime.library ?? config.library);
52
+ const resources = [
53
+ ...libraryResources(config.runtime.library ?? config.library),
54
+ ...config.runtime.resources ?? []
55
+ ];
56
+ const ids = /* @__PURE__ */ new Set();
57
+ for (const resource of resources) {
58
+ if (!resource.id || ids.has(resource.id)) throw new TypeError(`ID de recurso ausente ou duplicado: ${resource.id}`);
59
+ ids.add(resource.id);
60
+ }
61
+ const base = config.runtime.baseUrl ? `<base href="${escapeAttribute(config.runtime.baseUrl)}">` : "";
62
+ const imports = config.runtime.importMap ? `<script type="importmap">${escapeInline(JSON.stringify({ imports: config.runtime.importMap }))}<\/script>` : "";
63
+ const styles = resources.map((resource) => {
64
+ if (resource.type === "style")
65
+ return `<link rel="stylesheet" href="${escapeAttribute(resource.href)}"${resource.integrity ? ` integrity="${escapeAttribute(resource.integrity)}"` : ""}${resource.crossOrigin ? ` crossorigin="${resource.crossOrigin}"` : ""}>`;
66
+ if (resource.type === "inline-style") return `<style>${escapeInline(resource.content)}</style>`;
67
+ return "";
68
+ }).join("\n");
69
+ const scripts = resources.flatMap((resource) => {
70
+ if (resource.type === "script" || resource.type === "module")
71
+ return [
72
+ { type: resource.type, src: resource.src, integrity: resource.integrity, crossOrigin: resource.crossOrigin }
73
+ ];
74
+ if (resource.type === "inline-script") return [{ type: "script", content: resource.content }];
75
+ if (resource.type === "inline-module") return [{ type: "module", content: resource.content }];
76
+ return [];
77
+ });
78
+ const css = config.example.css ? `<style data-playground-example>${escapeInline(config.example.css)}</style>` : "";
79
+ const modeStyles = `<style>${escapeInline(config.runtime.modeStyles ?? "")}
80
+ html, body { margin: 0; min-height: 1px; }
81
+ body { box-sizing: border-box; padding: 24px 16px; }
82
+ html[data-wbc-reduced-motion='true'] *, html[data-wbc-reduced-motion='true'] *::before, html[data-wbc-reduced-motion='true'] *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
83
+ [data-wbc-preview-skeleton] { color: transparent !important; border-color: transparent !important; background-color: color-mix(in srgb, currentColor 12%, transparent) !important; }
84
+ </style>`;
85
+ if (config.runtime.bootstrap) scripts.push({ type: "module", content: config.runtime.bootstrap });
86
+ if (config.example.javascript) scripts.push({ type: "module", content: config.example.javascript });
87
+ const scriptData = escapeInline(JSON.stringify(scripts));
88
+ const scriptLoader = `<script type="module">for(const [index,resource] of ${scriptData}.entries()){await new Promise((resolve)=>{const script=document.createElement('script');script.async=false;if(resource.type==='module')script.type='module';if(resource.src)script.src=resource.src;else script.textContent=resource.content;if(resource.integrity)script.integrity=resource.integrity;if(resource.crossOrigin)script.crossOrigin=resource.crossOrigin;script.onload=resolve;script.onerror=()=>{console.error('Falha ao carregar recurso do playground:',resource.src??'script inline');resolve()};if(!resource.src&&resource.type==='module'){const eventName='pg-module:'+index;window.addEventListener(eventName,resolve,{once:true});script.textContent+='\\n;window.dispatchEvent(new Event('+JSON.stringify(eventName)+'))'}document.body.append(script);if(!resource.src&&resource.type==='script')resolve()})};window.dispatchEvent(new Event('playground-runtime-ready'))<\/script>`;
89
+ const eventTypes = JSON.stringify([
90
+ .../* @__PURE__ */ new Set([
91
+ "click",
92
+ "input",
93
+ "change",
94
+ "focus",
95
+ "blur",
96
+ "submit",
97
+ "reset",
98
+ "invalid",
99
+ "keydown",
100
+ ...config.runtime.eventTypes ?? []
101
+ ])
102
+ ]);
103
+ const protocol = `<script>
104
+ (function () {
105
+ const channel = ${JSON.stringify(channelId)};
106
+ const parentOrigin = new URL(document.referrer).origin;
107
+ const eventTypes = ${eventTypes};
108
+ const safeValue = (value) => {
109
+ if (value instanceof Error) return { name: value.name, message: value.message, stack: value.stack };
110
+ if (value === null || ['string', 'number', 'boolean'].includes(typeof value)) return value;
111
+ try { return JSON.parse(JSON.stringify(value)); } catch { return String(value); }
112
+ };
113
+ const send = (type, value) => {
114
+ parent.postMessage({ type, channel, value }, parentOrigin);
115
+ };
116
+ const describe = (node) => {
117
+ if (!(node instanceof Element)) return node?.nodeName?.toLowerCase() ?? 'document';
118
+ return node.localName + (node.id ? '#' + node.id : '') + (typeof node.className === 'string' && node.className.trim() ? '.' + node.className.trim().split(/\\s+/).join('.') : '');
119
+ };
120
+ let inspectionEnabled = false;
121
+ let eventTargetSequence = 0;
122
+ const eventTargets = new Map();
123
+ let selectedElement = null;
124
+ const hoverOverlay = document.createElement('div');
125
+ hoverOverlay.setAttribute('aria-hidden', 'true');
126
+ hoverOverlay.style.cssText = 'position:fixed;pointer-events:none;border:2px solid #f5c400;background:rgba(255,220,0,.22);box-sizing:border-box;display:none;z-index:2';
127
+ document.body.append(hoverOverlay);
128
+ let hoveredElement = null;
129
+ function paintHover(element) {
130
+ hoveredElement = element;
131
+ if (!element?.isConnected) { hoverOverlay.style.display = 'none'; return; }
132
+ const rect = element.getBoundingClientRect();
133
+ Object.assign(hoverOverlay.style, { display:'block', left:rect.left+'px', top:rect.top+'px', width:rect.width+'px', height:rect.height+'px' });
134
+ }
135
+ window.addEventListener('scroll', () => paintHover(hoveredElement), true);
136
+ window.addEventListener('resize', () => paintHover(hoveredElement));
137
+ function highlightAuthoredElement(element) {
138
+ if (element?.localName === 'br-action-group-item') {
139
+ const group = element.parentElement?.closest('br-action-group');
140
+ const label = (element.getAttribute('label') ?? '').trim();
141
+ const rendered = Array.from(group?.shadowRoot?.querySelectorAll('[part="action"], [part="menu-item"]') ?? []);
142
+ const matching = rendered.find((candidate) => (candidate.getAttribute('aria-label') ?? candidate.textContent ?? '').trim() === label);
143
+ if (matching) element = matching;
144
+ else if (group) element = group;
145
+ }
146
+ paintHover(element);
147
+ }
148
+ const selectionOverlay = document.createElement('div');
149
+ selectionOverlay.setAttribute('aria-hidden', 'true');
150
+ selectionOverlay.style.cssText = 'position:fixed;pointer-events:none;border:2px solid #1351b4;box-sizing:border-box;display:none;z-index:1';
151
+ document.body.append(selectionOverlay);
152
+ function paintSelection() {
153
+ if (!selectedElement?.isConnected) { selectionOverlay.style.display = 'none'; return; }
154
+ const rect = selectedElement.getBoundingClientRect();
155
+ Object.assign(selectionOverlay.style, { display: 'block', left: rect.left + 'px', top: rect.top + 'px', width: rect.width + 'px', height: rect.height + 'px' });
156
+ }
157
+ window.addEventListener('scroll', paintSelection, true);
158
+ window.addEventListener('resize', paintSelection);
159
+
160
+ const inspectionTags = new Set(${escapeInline(JSON.stringify((config.controls?.manifest?.components ?? []).map((component) => component.tag)))});
161
+ document.addEventListener('click', (event) => {
162
+ if (!inspectionEnabled) return;
163
+ const element = event.composedPath().find((node) => node instanceof Element && document.body.contains(node) && (inspectionTags.size ? inspectionTags.has(node.localName) : node.localName.startsWith('br-')));
164
+ if (!element) return;
165
+ event.preventDefault(); event.stopImmediatePropagation();
166
+ selectedElement = element; paintSelection();
167
+ send('inspect-element', { tag: element.localName, index: Array.from(document.body.getElementsByTagName(element.localName)).indexOf(element) });
168
+ }, true);
169
+ const reportSize = () => {
170
+ const bottoms = managedNodes.flatMap((node) => { if (node instanceof Element) return [node.getBoundingClientRect().bottom + window.scrollY]; if (node.nodeType === Node.TEXT_NODE && node.textContent.trim()) { const range = document.createRange(); range.selectNodeContents(node); return [range.getBoundingClientRect().bottom + window.scrollY]; } return []; });
171
+ paintSelection();
172
+ send('preview-size', Math.ceil(Math.max(0, ...bottoms) + parseFloat(getComputedStyle(document.body).paddingBottom || '0')));
173
+ };
174
+ const sizeObserver = new ResizeObserver(reportSize);
175
+ sizeObserver.observe(document.body);
176
+ const authored = new WeakMap();
177
+ const authoredChildren = new WeakMap();
178
+ function remember(node, source = node) {
179
+ authored.set(node, source.cloneNode(true));
180
+ const children = Array.from(node.childNodes);
181
+ authoredChildren.set(node, children);
182
+ children.forEach((child, index) => remember(child, source.childNodes[index] ?? child));
183
+ return node;
184
+ }
185
+ const previewContent = document.querySelector('[data-playground-content]');
186
+ const syncLandmark = () => {
187
+ if (previewContent.querySelector('main, [role="main"]')) previewContent.removeAttribute('role');
188
+ else previewContent.setAttribute('role', 'main');
189
+ };
190
+ syncLandmark();
191
+ const initialNodes = Array.from(previewContent.childNodes);
192
+ const initialStart = initialNodes.findIndex((node) => node.nodeType === Node.COMMENT_NODE && node.nodeValue === 'pg-start:' + channel);
193
+ const initialEnd = initialNodes.findIndex((node) => node.nodeType === Node.COMMENT_NODE && node.nodeValue === 'pg-end:' + channel);
194
+ let managedNodes = initialNodes.slice(initialStart + 1, initialEnd);
195
+ const initialTemplate = document.createElement('template');
196
+ initialTemplate.innerHTML = ${escapeInline(JSON.stringify(config.example.html))};
197
+ managedNodes.forEach((node, index) => remember(node, initialTemplate.content.childNodes[index] ?? node));
198
+ function sync(target, source) {
199
+ if (target.nodeType !== source.nodeType || target.nodeName !== source.nodeName) {
200
+ const replacement = remember(source.cloneNode(true));
201
+ target.replaceWith(replacement);
202
+ return replacement;
203
+ }
204
+ const previous = authored.get(target);
205
+ if (previous?.isEqualNode(source)) return target;
206
+ if (target.nodeType === Node.TEXT_NODE || target.nodeType === Node.COMMENT_NODE) {
207
+ if (previous?.nodeValue !== source.nodeValue) target.nodeValue = source.nodeValue;
208
+ } else if (target.nodeType === Node.ELEMENT_NODE) {
209
+ const names = new Set([...Array.from(previous?.attributes ?? [], (attribute) => attribute.name), ...Array.from(source.attributes, (attribute) => attribute.name)]);
210
+ for (const name of names) {
211
+ const before = previous?.getAttribute(name) ?? null;
212
+ const after = source.getAttribute(name);
213
+ if (before === after) continue;
214
+ if (name === 'class') {
215
+ const beforeTokens = new Set((before ?? '').split(/\\s+/).filter(Boolean));
216
+ const afterTokens = new Set((after ?? '').split(/\\s+/).filter(Boolean));
217
+ beforeTokens.forEach((token) => { if (!afterTokens.has(token)) target.classList.remove(token); });
218
+ afterTokens.forEach((token) => { if (!beforeTokens.has(token)) target.classList.add(token); });
219
+ } else if (after === null) target.removeAttribute(name);
220
+ else target.setAttribute(name, after);
221
+ }
222
+ syncChildren(target, source);
223
+ }
224
+ authored.set(target, source.cloneNode(true));
225
+ return target;
226
+ }
227
+ function syncChildren(target, source) {
228
+ const oldChildren = authoredChildren.get(target) ?? [];
229
+ const newChildren = Array.from(source.childNodes);
230
+ const nextChildren = newChildren.map((child, index) => {
231
+ if (oldChildren[index]) return sync(oldChildren[index], child);
232
+ const added = remember(child.cloneNode(true));
233
+ target.append(added);
234
+ return added;
235
+ });
236
+ oldChildren.slice(newChildren.length).forEach((child) => child.remove());
237
+ authoredChildren.set(target, nextChildren);
238
+ }
239
+ let activeMode = {};
240
+ const skeletonState = new WeakMap();
241
+ function walkElements(root, callback) {
242
+ root.querySelectorAll('*').forEach((element) => {
243
+ callback(element);
244
+ if (element.shadowRoot) walkElements(element.shadowRoot, callback);
245
+ });
246
+ }
247
+ function applySkeleton(element, enabled) {
248
+ if (!element.localName.includes('-')) return;
249
+ if (enabled) {
250
+ if (!skeletonState.has(element)) skeletonState.set(element, {
251
+ attribute: element.getAttribute('skeleton'),
252
+ property: 'skeleton' in element ? element.skeleton : undefined,
253
+ });
254
+ if ('skeleton' in element) element.skeleton = true;
255
+ else if (element.constructor?.observedAttributes?.includes('skeleton')) element.setAttribute('skeleton', '');
256
+ else element.setAttribute('data-wbc-preview-skeleton', '');
257
+ } else {
258
+ const previous = skeletonState.get(element);
259
+ if (previous) {
260
+ if (previous.property !== undefined) element.skeleton = previous.property;
261
+ if (previous.attribute === null) element.removeAttribute('skeleton');
262
+ else if (previous.attribute !== null) element.setAttribute('skeleton', previous.attribute);
263
+ skeletonState.delete(element);
264
+ }
265
+ element.removeAttribute('data-wbc-preview-skeleton');
266
+ }
267
+ }
268
+ const originalColorModes = new WeakMap();
269
+ function syncBackground() {
270
+ const boards = managedNodes.filter((node) => node instanceof Element && node.hasAttribute('data-dsg-board'));
271
+ const boardBackground = boards.length === 1 ? getComputedStyle(boards[0]).backgroundColor : '';
272
+ const background = typeof activeMode.background === 'string'
273
+ ? activeMode.background
274
+ : boardBackground;
275
+ document.documentElement.style.backgroundColor = background;
276
+ document.body.style.backgroundColor = background;
277
+ }
278
+ function applyMode(mode) {
279
+ activeMode = mode;
280
+ const root = document.documentElement;
281
+ root.dataset.theme = mode.theme === 'dark' ? 'dark' : 'light';
282
+ root.dataset.wbcTheme = mode.theme === 'dark' ? 'dark' : 'light';
283
+ root.dataset.colorMode = mode.contrast ? 'contrast' : 'main';
284
+ if (mode.contrast) root.setAttribute('data-contrast', 'enabled'); else root.removeAttribute('data-contrast');
285
+ if (mode.contrast) root.setAttribute('data-wbc-high-contrast', 'true'); else root.removeAttribute('data-wbc-high-contrast');
286
+ if (mode.reducedMotion) root.setAttribute('data-wbc-reduced-motion', 'true'); else root.removeAttribute('data-wbc-reduced-motion');
287
+ root.lang = mode.lang || 'pt-BR';
288
+ root.dir = mode.dir || 'ltr';
289
+ root.dataset.wbcReducedMotion = String(Boolean(mode.reducedMotion));
290
+ walkElements(document, (element) => {
291
+ if (element.localName.includes('-')) {
292
+ if (${JSON.stringify(library.profile)} === 'wbc' && 'colorMode' in element) {
293
+ if (!originalColorModes.has(element)) originalColorModes.set(element, element.colorMode);
294
+ element.colorMode = mode.theme === 'dark' ? 'dark' : originalColorModes.get(element);
295
+ }
296
+ if (mode.reducedMotion) element.setAttribute('data-wbc-reduced-motion', 'true');
297
+ else element.removeAttribute('data-wbc-reduced-motion');
298
+ }
299
+ applySkeleton(element, Boolean(mode.skeleton));
300
+ if (mode.reducedMotion) element.getAnimations().forEach((animation) => animation.cancel());
301
+ });
302
+ document.dispatchEvent(new CustomEvent('wbcReducedMotionChange', { detail: { reducedMotion: Boolean(mode.reducedMotion) } }));
303
+ const content = document.body;
304
+ content.setAttribute('aria-busy', mode.skeleton ? 'true' : 'false');
305
+ syncBackground();
306
+ }
307
+ let managedHtmlSource = ${escapeInline(JSON.stringify(config.example.html))};
308
+ function replaceManagedHtml(html) {
309
+ if (html === managedHtmlSource) return;
310
+ managedHtmlSource = html;
311
+ const nodes = Array.from(previewContent.childNodes);
312
+ const start = nodes.findIndex((node) => node.nodeType === Node.COMMENT_NODE && node.nodeValue === 'pg-start:' + channel);
313
+ const end = nodes.findIndex((node) => node.nodeType === Node.COMMENT_NODE && node.nodeValue === 'pg-end:' + channel);
314
+ if (start < 0 || end <= start) return;
315
+ const template = document.createElement('template');
316
+ template.innerHTML = html;
317
+ const newChildren = Array.from(template.content.childNodes);
318
+ const nextNodes = newChildren.map((node, index) => {
319
+ if (managedNodes[index]) return sync(managedNodes[index], node);
320
+ const added = remember(node.cloneNode(true));
321
+ previewContent.insertBefore(added, nodes[end]);
322
+ return added;
323
+ });
324
+ managedNodes.slice(newChildren.length).forEach((node) => node.remove());
325
+ managedNodes = nextNodes;
326
+ syncLandmark();
327
+ applyMode(activeMode);
328
+ requestAnimationFrame(reportSize);
329
+ }
330
+ window.addEventListener('message', async (event) => {
331
+ if (event.source !== parent || event.origin !== parentOrigin || event.data?.channel !== channel) return;
332
+ const data = event.data;
333
+ if (data.type === 'inspect-preview') {
334
+ const tag = ${JSON.stringify(config.controls?.tag ?? "")};
335
+ const elements = tag ? Array.from(document.body.getElementsByTagName(tag)) : [];
336
+ send('preview-diagnostic', {
337
+ tag,
338
+ registered: tag ? Boolean(customElements.get(tag)) : null,
339
+ count: elements.length,
340
+ viewport: { width: innerWidth, height: innerHeight, bodyDisplay: getComputedStyle(document.body).display, htmlDisplay: getComputedStyle(document.documentElement).display },
341
+ elements: elements.slice(0, 3).map((element) => ({
342
+ html: element.outerHTML,
343
+ shadow: Boolean(element.shadowRoot),
344
+ visibility: getComputedStyle(element).visibility,
345
+ display: getComputedStyle(element).display,
346
+ opacity: getComputedStyle(element).opacity,
347
+ width: element.getBoundingClientRect().width,
348
+ height: element.getBoundingClientRect().height,
349
+ shadowHtml: element.shadowRoot?.innerHTML,
350
+ })),
351
+ });
352
+ }
353
+ if (data.type === 'highlight-element') {
354
+ let element = typeof data.tag === 'string' && Number.isInteger(data.index) && data.index >= 0 ? (document.body.getElementsByTagName(data.tag)[data.index] ?? null) : null;
355
+ highlightAuthoredElement(element);
356
+ }
357
+ if (data.type === 'highlight-event') highlightAuthoredElement(eventTargets.get(data.targetKey) ?? null);
358
+ if (data.type === 'select-element' && typeof data.tag === 'string' && /^[a-z][a-z0-9-]*$/.test(data.tag) && Number.isInteger(data.index) && data.index >= 0 && data.index <= 10000) { selectedElement = document.body.getElementsByTagName(data.tag)[data.index] ?? null; paintSelection(); }
359
+ if (data.type === 'set-inspection') { inspectionEnabled = data.enabled === true; document.documentElement.style.cursor = inspectionEnabled ? 'crosshair' : ''; }
360
+ if (data.type === 'set-mode' && data.mode && typeof data.mode === 'object') applyMode(data.mode);
361
+ if (data.type === 'set-html' && typeof data.html === 'string') replaceManagedHtml(data.html);
362
+ if (data.type === 'set-css' && typeof data.css === 'string') {
363
+ let style = document.querySelector('style[data-playground-example]');
364
+ if (!style) { style = document.createElement('style'); style.dataset.playgroundExample = ''; document.head.append(style); }
365
+ style.textContent = data.css;
366
+ syncBackground();
367
+ }
368
+
369
+ });
370
+ for (const method of ['log', 'info', 'warn', 'error', 'debug']) {
371
+ const original = console[method].bind(console);
372
+ console[method] = (...args) => { original(...args); send('console', { occurredAt: Date.now(), method, args: args.map(safeValue) }); };
373
+ }
374
+ window.addEventListener('error', (event) => send('console', { method: 'exception', args: [event.message], source: event.filename, line: event.lineno, column: event.colno }));
375
+ window.addEventListener('unhandledrejection', (event) => send('console', { method: 'unhandledrejection', args: [safeValue(event.reason)] }));
376
+ function reportExampleEvent(event) {
377
+ const type = event.type;
378
+ if (!managedNodes.some((node) => node === event.target || node.contains?.(event.target))) return;
379
+ const componentOrigin = event.composedPath().find((node) => node instanceof Element && node.localName.startsWith('br-') && document.body.contains(node));
380
+ if (['click', 'dblclick', 'auxclick', 'contextmenu'].includes(type) && !componentOrigin) return;
381
+ const origin = componentOrigin ?? event.target;
382
+ const targetKey = ++eventTargetSequence;
383
+ eventTargets.set(targetKey, origin);
384
+ if (eventTargets.size > 1000) eventTargets.delete(eventTargets.keys().next().value);
385
+ send('event', { targetKey, occurredAt: Date.now(), eventType: type, custom: type.includes('-') || type.startsWith('br'), detail: safeValue(event.detail), target: describe(event.target), currentTarget: describe(event.currentTarget), composedPath: event.composedPath().slice(0, 8).map(describe), bubbles: event.bubbles, composed: event.composed, cancelable: event.cancelable, timeStamp: event.timeStamp });
386
+ }
387
+ eventTypes.forEach((type) => {
388
+ document.addEventListener(type, (event) => { if (!event.bubbles) reportExampleEvent(event); }, true);
389
+ document.addEventListener(type, (event) => { if (event.bubbles) reportExampleEvent(event); });
390
+ });
391
+ window.addEventListener('playground-runtime-ready', () => {
392
+ if (activeMode) applyMode(activeMode);
393
+ parent.postMessage({ type: 'ready', channel }, parentOrigin);
394
+ });
395
+ window.addEventListener('load', syncBackground);
396
+ syncBackground();
397
+ parent.postMessage({ type: 'ready', channel }, parentOrigin);
398
+ })();
399
+ <\/script>`;
400
+ return `<!doctype html><html lang="pt-BR"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">${base}${imports}${styles}${modeStyles}${css}<title>${escapeText(config.ui?.title ?? "Playground")}</title></head><body><div data-playground-content role="main" style="display:contents"><!--pg-start:${channelId}-->${config.example.html}<!--pg-end:${channelId}--></div>${scriptLoader}${protocol}</body></html>`;
401
+ }
402
+ function isPlaygroundConfig(value) {
403
+ if (!value || typeof value !== "object") return false;
404
+ const candidate = value;
405
+ return typeof candidate.runtime?.id === "string" && typeof candidate.example?.html === "string";
406
+ }
407
+ export {
408
+ createPreviewDocument,
409
+ isPlaygroundConfig
410
+ };
@@ -0,0 +1,6 @@
1
+ export { Playground } from './Playground.js';
2
+ export type { PlaygroundProps } from './Playground.js';
3
+ export * from './core/index.js';
4
+ export { ensureLibrary, resolveLibrary, DEFAULT_LIBRARY } from './library/profile.js';
5
+ export * from './sources.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAErF,cAAc,cAAc,CAAA"}
@@ -0,0 +1,36 @@
1
+ import { type ButtonHTMLAttributes, type SelectHTMLAttributes, type InputHTMLAttributes, type TextareaHTMLAttributes, type OptionHTMLAttributes, type ReactNode } from 'react';
2
+ import type { PlaygroundHiddenItems } from '../core/index.js';
3
+ import { type PlaygroundLibrary } from './profile.js';
4
+ export declare const ControlVisibilityProvider: import("react").Provider<PlaygroundHiddenItems | undefined>;
5
+ export declare function LibraryProvider({ library, hiddenControls, children, }: {
6
+ library?: PlaygroundLibrary;
7
+ hiddenControls?: PlaygroundHiddenItems;
8
+ children: ReactNode;
9
+ }): import("react").JSX.Element;
10
+ export declare function Button({ children, type, title, iconOnly, emphasis, ...props }: ButtonHTMLAttributes<HTMLButtonElement> & {
11
+ iconOnly?: boolean;
12
+ emphasis?: 'primary' | 'secondary' | 'tertiary';
13
+ }): import("react").DOMElement<any, Element> | null;
14
+ export declare function Select({ children, onChange, value, ...props }: SelectHTMLAttributes<HTMLSelectElement>): import("react").DOMElement<any, Element> | null;
15
+ export declare function Option({ children, value, ...props }: OptionHTMLAttributes<HTMLOptionElement>): import("react").DOMElement<any, Element>;
16
+ export declare function Input({ onChange, type, ...props }: InputHTMLAttributes<HTMLInputElement>): import("react").DOMElement<any, Element> | null;
17
+ export declare function Textarea({ children, onChange, ...props }: TextareaHTMLAttributes<HTMLTextAreaElement>): import("react").JSX.Element | null;
18
+ export declare function Switch({ id, label, checked, onChange, }: {
19
+ id: string;
20
+ label: string;
21
+ checked: boolean;
22
+ onChange: (checked: boolean) => void;
23
+ }): import("react").DOMElement<any, Element> | null;
24
+ export declare function Tabs({ label, items, active, onChange, children, }: {
25
+ label?: string;
26
+ items: {
27
+ id: string;
28
+ label: string;
29
+ icon?: string;
30
+ iconOnly?: boolean;
31
+ }[];
32
+ active?: string;
33
+ onChange: (id: string) => void;
34
+ children: ReactNode;
35
+ }): import("react").JSX.Element;
36
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/library/components.tsx"],"names":[],"mappings":"AAAA,OAAO,EAWL,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEpE,eAAO,MAAM,yBAAyB,6DAA0B,CAAA;AAEhE,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,cAAc,EACd,QAAQ,GACT,EAAE;IACD,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,cAAc,CAAC,EAAE,qBAAqB,CAAA;IACtC,QAAQ,EAAE,SAAS,CAAA;CACpB,+BAwBA;AAID,wBAAgB,MAAM,CAAC,EACrB,QAAQ,EACR,IAAe,EACf,KAAK,EACL,QAAgB,EAChB,QAA6C,EAC7C,GAAG,KAAK,EACT,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,GAAG;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAA;CAChD,mDAoBA;AACD,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,mDAmCtG;AACD,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,4CAK5F;AACD,wBAAgB,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,mDA0BxF;AACD,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,sCAoBrG;AAED,wBAAgB,MAAM,CAAC,EACrB,EAAE,EACF,KAAK,EACL,OAAO,EACP,QAAQ,GACT,EAAE;IACD,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CACrC,mDAaA;AAED,wBAAgB,IAAI,CAAC,EACnB,KAAmC,EACnC,KAAK,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;IACzE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,QAAQ,EAAE,SAAS,CAAA;CACpB,+BAsIA"}
@@ -0,0 +1,23 @@
1
+ import type { PlaygroundResource } from '../core/index.js';
2
+ export type PlaygroundLibrary = {
3
+ registration?: 'module' | 'existing';
4
+ profile: 'wbc' | 'wbc-v4';
5
+ fontAwesomeVersion?: '5.15.4' | '6.7.2';
6
+ version?: string;
7
+ tokensVersion?: string;
8
+ manifestUrl?: string;
9
+ moduleUrl?: string;
10
+ styles?: string[];
11
+ };
12
+ export declare const DEFAULT_LIBRARY: PlaygroundLibrary;
13
+ export declare function fontAwesomeClasses(version: PlaygroundLibrary['fontAwesomeVersion'], icon: string): string;
14
+ export declare function resolveLibrary(library?: PlaygroundLibrary): {
15
+ profile: "wbc" | "wbc-v4";
16
+ registration: "module" | "existing";
17
+ fontAwesomeVersion: "5.15.4" | "6.7.2";
18
+ moduleUrl: string;
19
+ styles: string[];
20
+ };
21
+ export declare function ensureLibrary(library?: PlaygroundLibrary): Promise<void>;
22
+ export declare function libraryResources(config?: PlaygroundLibrary): PlaygroundResource[];
23
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/library/profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IACpC,OAAO,EAAE,KAAK,GAAG,QAAQ,CAAA;IACzB,kBAAkB,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AACD,eAAO,MAAM,eAAe,EAAE,iBAAqF,CAAA;AACnH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,MAAM,UAEhG;AACD,wBAAgB,cAAc,CAAC,OAAO,GAAE,iBAAmC;;;;;;EAiC1E;AAID,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuCxE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,kBAAkB,EAAE,CAUjF"}