@aliens-syndicate/cli 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/README.md +215 -2
- package/package.json +29 -4
- package/tools/build.mjs +607 -0
- package/tools/cli.mjs +39 -0
- package/tools/create.mjs +102 -0
- package/tools/project-layout.mjs +41 -0
- package/tools/runtime.mjs +294 -0
- package/tools/starter/app/animations/hero-enter.animation +8 -0
- package/tools/starter/app/apis/hero.api +9 -0
- package/tools/starter/app/directives/hero-highlight.directive +8 -0
- package/tools/starter/app/elements/atoms/kit-nav-link/kit-nav-link.markup +2 -0
- package/tools/starter/app/elements/molecules/hero-card/hero-card.logic +15 -0
- package/tools/starter/app/elements/molecules/hero-card/hero-card.markup +8 -0
- package/tools/starter/app/elements/molecules/hero-card/hero-card.style +12 -0
- package/tools/starter/app/elements/molecules/hero-card/hero-card.test +8 -0
- package/tools/starter/app/elements/molecules/kit-button-demo/kit-button-demo.logic +14 -0
- package/tools/starter/app/elements/molecules/kit-button-demo/kit-button-demo.markup +8 -0
- package/tools/starter/app/elements/molecules/kit-card-link/kit-card-link.markup +6 -0
- package/tools/starter/app/elements/organisms/kit-navigation/kit-navigation.markup +19 -0
- package/tools/starter/app/enums/hero-status.enum +7 -0
- package/tools/starter/app/errors/hero-not-found.error +7 -0
- package/tools/starter/app/guards/hero-editor.guard +8 -0
- package/tools/starter/app/interceptors/hero-request.interceptor +8 -0
- package/tools/starter/app/interfaces/hero.interface +8 -0
- package/tools/starter/app/mocks/hero.mock +8 -0
- package/tools/starter/app/models/hero.model +8 -0
- package/tools/starter/app/pages/kit-border/kit-border.markup +38 -0
- package/tools/starter/app/pages/kit-color/kit-color.markup +58 -0
- package/tools/starter/app/pages/kit-components/kit-components.markup +95 -0
- package/tools/starter/app/pages/kit-overview/kit-overview.markup +25 -0
- package/tools/starter/app/pages/kit-radius/kit-radius.markup +34 -0
- package/tools/starter/app/pages/kit-space/kit-space.markup +61 -0
- package/tools/starter/app/pages/kit-type/kit-type.markup +48 -0
- package/tools/starter/app/pages/style-guide/style-guide.markup +10 -0
- package/tools/starter/app/pages/style-guide/style-guide.style +252 -0
- package/tools/starter/app/pipes/hero-label.pipe +6 -0
- package/tools/starter/app/routes/hero-archive.route +8 -0
- package/tools/starter/app/routes/hero-detail.route +11 -0
- package/tools/starter/app/routes/hero-edit.route +14 -0
- package/tools/starter/app/routes/hero-filter.route +14 -0
- package/tools/starter/app/routes/hero-list.route +9 -0
- package/tools/starter/app/routes/hero-not-found.route +7 -0
- package/tools/starter/app/routes/hero-preview.route +11 -0
- package/tools/starter/app/routes/hero-redirect.route +8 -0
- package/tools/starter/app/routes/hero-search.route +15 -0
- package/tools/starter/app/routes/hero-tabs.route +17 -0
- package/tools/starter/app/routes/hero-team.route +11 -0
- package/tools/starter/app/services/hero-roster.service +8 -0
- package/tools/starter/app/storage/hero-favorite.storage +8 -0
- package/tools/starter/app/validators/hero-energy.validator +8 -0
- package/tools/starter/language/.en-US +73 -0
- package/tools/starter/language/.es-ES +73 -0
- package/tools/starter/language/.pt-BR +73 -0
- package/tools/starter/language/.zh-CN +73 -0
- package/tools/starter/styles/components/alerts.style +16 -0
- package/tools/starter/styles/components/badges.style +18 -0
- package/tools/starter/styles/components/borders.style +11 -0
- package/tools/starter/styles/components/buttons.style +34 -0
- package/tools/starter/styles/components/cards.style +9 -0
- package/tools/starter/styles/components/feedback.style +21 -0
- package/tools/starter/styles/components/forms.style +38 -0
- package/tools/starter/styles/components/spacing.style +13 -0
- package/tools/starter/styles/components/tables.style +17 -0
- package/tools/starter/styles/components/typography.style +51 -0
- package/tools/starter/styles/generic/ui-base.style +12 -0
- package/tools/starter/styles/objects/ui-layout.style +13 -0
- package/tools/starter/styles/settings/border-tokens.style +9 -0
- package/tools/starter/styles/settings/color-tokens.style +40 -0
- package/tools/starter/styles/settings/elevation-tokens.style +8 -0
- package/tools/starter/styles/settings/radius-tokens.style +8 -0
- package/tools/starter/styles/settings/space-tokens.style +11 -0
- package/tools/starter/styles/settings/theme.style +52 -0
- package/tools/starter/styles/settings/type-tokens.style +18 -0
- package/tools/vscode-space/extension.cjs +56 -0
- package/tools/vscode-space/language-configuration.json +9 -0
- package/tools/vscode-space/package.json +129 -0
- package/tools/vscode-space/space.tmLanguage.json +32 -0
- package/tools/vscode-space/style-colors.cjs +69 -0
- package/tools/vscode-space/syntax.cjs +122 -0
- package/tools/vscode-space/vendor/color-name.LICENSE +8 -0
- package/tools/vscode-space/vendor/color-name.cjs +152 -0
package/tools/create.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { copyFile, cp, mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, join, resolve } from 'node:path';
|
|
3
|
+
import { createProjectDirectories, styleLayers } from './project-layout.mjs';
|
|
4
|
+
|
|
5
|
+
const starter = join(import.meta.dirname, 'starter');
|
|
6
|
+
const editorExtension = join(import.meta.dirname, 'vscode-space');
|
|
7
|
+
|
|
8
|
+
async function create([path, ...extra]) {
|
|
9
|
+
if (!path || extra.length) throw new Error('Uso: node tools/create.mjs <pasta-do-novo-projeto>');
|
|
10
|
+
const destination = resolve(path);
|
|
11
|
+
const name = basename(destination);
|
|
12
|
+
if (!name || /[\r\n\u2028\u2029]/u.test(name) || name !== name.trim()) {
|
|
13
|
+
throw new Error('Use um nome de pasta em uma única linha, sem espaços nas pontas.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await mkdir(destination);
|
|
17
|
+
try {
|
|
18
|
+
const project = join(destination, 'project');
|
|
19
|
+
const tools = join(destination, 'tools');
|
|
20
|
+
await mkdir(project);
|
|
21
|
+
await cp(join(starter, 'app'), join(project, 'app'), { recursive: true });
|
|
22
|
+
await cp(join(starter, 'styles'), join(project, 'styles'), { recursive: true });
|
|
23
|
+
await createProjectDirectories(destination);
|
|
24
|
+
await mkdir(join(project, 'app', 'pages', 'home'));
|
|
25
|
+
await mkdir(tools);
|
|
26
|
+
await mkdir(join(destination, '.vscode'));
|
|
27
|
+
const manifest = JSON.parse(await readFile(join(editorExtension, 'package.json'), 'utf8'));
|
|
28
|
+
const paletteSetting = 'editor.semanticTokenColorCustomizations';
|
|
29
|
+
const editorSettings = { [paletteSetting]: manifest.contributes.configurationDefaults[paletteSetting] };
|
|
30
|
+
|
|
31
|
+
const translations = Object.fromEntries(await Promise.all(
|
|
32
|
+
(await readdir(join(starter, 'language'))).filter(file => /^\.[a-z]{2}-[A-Z]{2}$/.test(file)).map(async file => [
|
|
33
|
+
'project/language/' + file,
|
|
34
|
+
`site:\n title: ${name}\n\nhome:\n description: ${name}\n\n` + await readFile(join(starter, 'language', file), 'utf8')
|
|
35
|
+
])
|
|
36
|
+
));
|
|
37
|
+
const template = {
|
|
38
|
+
...translations,
|
|
39
|
+
'README.md': `# ${name}
|
|
40
|
+
|
|
41
|
+
Use \`node tools/build.mjs\` para gerar a prévia em \`dist/\`.
|
|
42
|
+
|
|
43
|
+
A configuração fica em \`.config\` e o build gera o índice \`ai/.map\`.
|
|
44
|
+
A Home inclui a biblioteca de estilos, com tokens em \`project/styles/settings/\`, componentes em \`project/styles/components/\` e temas em \`project/styles/settings/theme.style\`.
|
|
45
|
+
Adicione um bloco \`:root[data-theme="nome"]\` nesse arquivo e execute o build para disponibilizar o tema no seletor.
|
|
46
|
+
|
|
47
|
+
As páginas e os Elements ficam em \`project/app/pages/\` e \`project/app/elements/\`.
|
|
48
|
+
`,
|
|
49
|
+
'.config': `project:
|
|
50
|
+
name: ${name}
|
|
51
|
+
version: 0.1.0
|
|
52
|
+
|
|
53
|
+
files:
|
|
54
|
+
entry: project/app/app.logic
|
|
55
|
+
assets: project/assets
|
|
56
|
+
styles: project/styles/main.style
|
|
57
|
+
environment: project/.env
|
|
58
|
+
agent: ai/.map
|
|
59
|
+
|
|
60
|
+
build:
|
|
61
|
+
target: web
|
|
62
|
+
environment: local
|
|
63
|
+
|
|
64
|
+
language:
|
|
65
|
+
directory: project/language
|
|
66
|
+
default: en-US
|
|
67
|
+
detection: browser
|
|
68
|
+
`,
|
|
69
|
+
'project/.env': '# Configure project environment values here.\n',
|
|
70
|
+
'project/app/app.logic': 'Logic App\n',
|
|
71
|
+
'project/app/app.markup': 'Markup App\n home\n',
|
|
72
|
+
'project/app/app.route': 'Route App\n routes:\n home:\n path: /\n element: home\n',
|
|
73
|
+
'project/app/pages/home/home.markup': 'Markup Home\n style-guide\n',
|
|
74
|
+
'project/styles/main.style': 'Style Main\n default:\n' + styleLayers.map(layer => ' ' + layer + '\n').join('')
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const results = await Promise.allSettled([
|
|
78
|
+
...Object.entries(template).map(([file, content]) => writeFile(join(destination, file), content, { flag: 'wx' })),
|
|
79
|
+
...['build.mjs', 'runtime.mjs', 'create.mjs', 'project-layout.mjs'].map(file =>
|
|
80
|
+
copyFile(join(import.meta.dirname, file), join(tools, file))
|
|
81
|
+
),
|
|
82
|
+
cp(starter, join(tools, 'starter'), { recursive: true }),
|
|
83
|
+
cp(editorExtension, join(tools, 'vscode-space'), { recursive: true }),
|
|
84
|
+
writeFile(join(destination, '.vscode', 'settings.json'), JSON.stringify(editorSettings, null, 3) + '\n'),
|
|
85
|
+
writeFile(join(destination, '.gitignore'), 'dist/\n.DS_Store\nproject/.env\n')
|
|
86
|
+
]);
|
|
87
|
+
const failure = results.find(result => result.status === 'rejected');
|
|
88
|
+
if (failure) throw failure.reason;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
await rm(destination, { recursive: true, force: true });
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(`Projeto Aliens criado em ${destination}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
await create(process.argv.slice(2));
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(error.code === 'EEXIST' ? 'A pasta de destino já existe.' : error.message);
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const applicationByType = {
|
|
5
|
+
animation: 'animations',
|
|
6
|
+
api: 'apis',
|
|
7
|
+
directive: 'directives',
|
|
8
|
+
enum: 'enums',
|
|
9
|
+
error: 'errors',
|
|
10
|
+
guard: 'guards',
|
|
11
|
+
interceptor: 'interceptors',
|
|
12
|
+
interface: 'interfaces',
|
|
13
|
+
mock: 'mocks',
|
|
14
|
+
model: 'models',
|
|
15
|
+
pipe: 'pipes',
|
|
16
|
+
route: 'routes',
|
|
17
|
+
service: 'services',
|
|
18
|
+
storage: 'storage',
|
|
19
|
+
validator: 'validators'
|
|
20
|
+
};
|
|
21
|
+
const agentByType = { agent: 'agents', rule: 'rules', skill: 'skills' };
|
|
22
|
+
|
|
23
|
+
export const namedKinds = new Set([...Object.keys(applicationByType), ...Object.keys(agentByType), 'logic', 'markup', 'style', 'test']);
|
|
24
|
+
export const sharedDirectory = 'shared';
|
|
25
|
+
export const exampleMarker = '# Aliens example: Hero';
|
|
26
|
+
export const styleLayers = ['settings', 'tools', 'generic', 'elements', 'objects', 'components', 'utilities'];
|
|
27
|
+
const elementLevels = ['atoms', 'molecules', 'organisms', 'templates'];
|
|
28
|
+
|
|
29
|
+
export async function createProjectDirectories(workspace) {
|
|
30
|
+
const directories = [
|
|
31
|
+
'project/app/pages',
|
|
32
|
+
'project/assets',
|
|
33
|
+
'project/language',
|
|
34
|
+
...Object.values(agentByType).map(directory => join('ai', directory)),
|
|
35
|
+
...styleLayers.map(layer => join('project', 'styles', layer)),
|
|
36
|
+
...Object.values(applicationByType).map(directory => join('project', 'app', directory)),
|
|
37
|
+
...elementLevels.map(level => join('project', 'app', 'elements', level))
|
|
38
|
+
];
|
|
39
|
+
for (const directory of directories) await mkdir(join(workspace, directory), { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// The .logic reaches tags only by id: bind: lists each id with what a signal sets on it.
|
|
2
|
+
const instances = new Map();
|
|
3
|
+
for (const root of document.querySelectorAll('[data-element]')) {
|
|
4
|
+
const entry = logic[root.dataset.element];
|
|
5
|
+
if (!entry) continue;
|
|
6
|
+
const element = id => {
|
|
7
|
+
if (id && root.id === id) return root;
|
|
8
|
+
for (const node of root.querySelectorAll('[id]')) {
|
|
9
|
+
if (node.id === id && node.closest('[data-element]') === root) return node;
|
|
10
|
+
}
|
|
11
|
+
throw new Error(`Aliens: ID "${id}" not found in Element "${root.dataset.element}".`);
|
|
12
|
+
};
|
|
13
|
+
const state = entry.create(element);
|
|
14
|
+
instances.set(root, { state, actions: entry.actions, page: entry.page, binds: entry.bind.map(([id, name, read]) => ({ node: element(id), name, read })) });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A .logic without .markup runs once for the whole page. Markup calls it with action="element.action".
|
|
18
|
+
const standalone = new Map();
|
|
19
|
+
for (const [name, entry] of Object.entries(logic)) {
|
|
20
|
+
if (!entry.standalone) continue;
|
|
21
|
+
const state = entry.create(id => { throw new Error(`Aliens: ${name} has no markup, so it has no tag "${id}".`); });
|
|
22
|
+
const instance = { state, actions: entry.actions, page: entry.page, binds: [] };
|
|
23
|
+
standalone.set(name, instance);
|
|
24
|
+
instances.set(`logic:${name}`, instance);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function owner(node, accepts) {
|
|
28
|
+
let element = node.closest('[data-element]');
|
|
29
|
+
while (element) {
|
|
30
|
+
const instance = instances.get(element);
|
|
31
|
+
if (instance && accepts(instance)) return instance;
|
|
32
|
+
element = element.parentElement?.closest('[data-element]');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function render(instance) {
|
|
37
|
+
for (const current of instance ? [instance] : instances.values()) {
|
|
38
|
+
for (const { node, name, read } of current.binds) {
|
|
39
|
+
const value = read.call(current.state);
|
|
40
|
+
if (name === 'text') node.textContent = String(value);
|
|
41
|
+
if (name === 'show') node.hidden = !value;
|
|
42
|
+
if (name === 'pressed' || name === 'expanded') node.setAttribute('aria-' + name, String(Boolean(value)));
|
|
43
|
+
if (name.startsWith('_')) node.classList.toggle(node.id + name, Boolean(value));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const supported = Object.keys(languages);
|
|
49
|
+
const localeKey = 'aliens-docs-locale';
|
|
50
|
+
const themeKey = 'aliens-docs-theme';
|
|
51
|
+
|
|
52
|
+
function preference(key) {
|
|
53
|
+
try { return localStorage.getItem(key); } catch { return null; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function savePreference(key, value) {
|
|
57
|
+
try { localStorage.setItem(key, value); } catch { /* Storage is optional. */ }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function preferredLocale() {
|
|
61
|
+
const saved = preference(localeKey);
|
|
62
|
+
if (supported.includes(saved)) return saved;
|
|
63
|
+
if (detectLocale) {
|
|
64
|
+
for (const preference of navigator.languages ?? [navigator.language]) {
|
|
65
|
+
const tag = preference.toLowerCase();
|
|
66
|
+
const exact = supported.find(locale => locale.toLowerCase() === tag);
|
|
67
|
+
const base = supported.find(locale => locale.slice(0, 2) === tag.split('-')[0]);
|
|
68
|
+
if (exact || base) return exact ?? base;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return defaultLocale;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// page: in a .logic names the signal that drives the page theme or locale.
|
|
75
|
+
const pageModel = key => [...instances.values()].find(instance => instance.page[key]);
|
|
76
|
+
const localeModel = pageModel('locale');
|
|
77
|
+
const localeField = localeModel?.page.locale;
|
|
78
|
+
const themeModel = pageModel('theme');
|
|
79
|
+
const themeField = themeModel?.page.theme;
|
|
80
|
+
const localizedNodes = [...document.querySelectorAll('*')].flatMap(node =>
|
|
81
|
+
[...node.attributes].filter(attribute => attribute.name === 'data-i18n' || attribute.name.startsWith('data-i18n-')).map(attribute => ({
|
|
82
|
+
node, key: attribute.value, target: attribute.name.slice('data-i18n-'.length)
|
|
83
|
+
})));
|
|
84
|
+
|
|
85
|
+
// Every code sample gets a copy button. The frame hides with its sample, so tabbed samples keep one visible button.
|
|
86
|
+
const copyButtons = [...document.querySelectorAll('pre')].map(pre => {
|
|
87
|
+
const frame = document.createElement('div');
|
|
88
|
+
const button = document.createElement('button');
|
|
89
|
+
frame.className = 'space-copy-frame';
|
|
90
|
+
button.type = 'button';
|
|
91
|
+
button.className = 'space-copy';
|
|
92
|
+
button.textContent = '⧉';
|
|
93
|
+
let timer;
|
|
94
|
+
button.addEventListener('click', () => {
|
|
95
|
+
navigator.clipboard?.writeText(pre.textContent).catch(() => {});
|
|
96
|
+
button.textContent = '✓';
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
timer = setTimeout(() => { button.textContent = '⧉'; }, 1600);
|
|
99
|
+
});
|
|
100
|
+
pre.replaceWith(frame);
|
|
101
|
+
frame.append(pre, button);
|
|
102
|
+
return button;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
function applyLocale(locale) {
|
|
106
|
+
if (!supported.includes(locale)) return;
|
|
107
|
+
const dictionary = languages[locale];
|
|
108
|
+
for (const button of copyButtons) {
|
|
109
|
+
button.setAttribute('aria-label', dictionary['code.copy']);
|
|
110
|
+
button.title = dictionary['code.copy'];
|
|
111
|
+
}
|
|
112
|
+
document.documentElement.lang = locale;
|
|
113
|
+
document.title = dictionary['site.title'];
|
|
114
|
+
document.querySelector('meta[name="description"]').content = dictionary['home.description'];
|
|
115
|
+
for (const { node, key, target } of localizedNodes) {
|
|
116
|
+
if (target) node.setAttribute(target, dictionary[key]);
|
|
117
|
+
else node.textContent = dictionary[key];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const themePickers = [...document.querySelectorAll('[data-theme-picker]')];
|
|
122
|
+
for (const picker of themePickers) {
|
|
123
|
+
for (const name of availableThemes) {
|
|
124
|
+
if ([...picker.options].some(option => option.value === name)) continue;
|
|
125
|
+
const option = document.createElement('option');
|
|
126
|
+
option.value = name;
|
|
127
|
+
option.textContent = name.replaceAll('-', ' ');
|
|
128
|
+
picker.append(option);
|
|
129
|
+
}
|
|
130
|
+
picker.addEventListener('change', () => applyTheme(picker.value, true));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function applyTheme(name, persist = false) {
|
|
134
|
+
const theme = availableThemes.includes(name) ? name : 'light';
|
|
135
|
+
document.documentElement.dataset.theme = theme;
|
|
136
|
+
document.querySelector('meta[name="theme-color"]').content =
|
|
137
|
+
getComputedStyle(document.documentElement).getPropertyValue('--color-canvas').trim() ||
|
|
138
|
+
(theme === 'dark' ? '#000000' : '#ffffff');
|
|
139
|
+
for (const picker of themePickers) picker.value = theme;
|
|
140
|
+
if (themeModel) {
|
|
141
|
+
themeModel.state[themeField] = theme === 'dark';
|
|
142
|
+
render(themeModel);
|
|
143
|
+
}
|
|
144
|
+
if (persist) savePreference(themeKey, theme);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Short fragments from older links: #agent opens type-index-agent, #logic opens logic-guide.
|
|
148
|
+
const shortViews = new Map([['home', 'home-guide'], ['logic', 'logic-guide'], ['markup', 'markup-reference']]);
|
|
149
|
+
const legacyViews = new Map([...shortViews, ['style-kit', 'kit-overview'], ['styles', 'type-index-style'], ['mockup', 'type-index-mock']]);
|
|
150
|
+
// The search shows a view by its short name: type-index-agent is .agent, logic-guide is .logic.
|
|
151
|
+
function shortName(id) {
|
|
152
|
+
for (const [short, full] of shortViews) if (full === id) return short;
|
|
153
|
+
return id.startsWith('type-index-') ? id.slice('type-index-'.length) : id.split('-').at(-1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function normalizeSearch(value) {
|
|
157
|
+
return value.toLowerCase().normalize('NFD').replace(/\p{M}/gu, '').trim();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function setupSearch(form) {
|
|
161
|
+
const input = form.querySelector('input');
|
|
162
|
+
const panel = document.getElementById('doc-search-panel');
|
|
163
|
+
const results = document.getElementById('doc-search-results');
|
|
164
|
+
const empty = document.getElementById('doc-search-empty');
|
|
165
|
+
const entries = [...document.querySelectorAll('[data-search-entry]')].map(section => ({
|
|
166
|
+
id: section.id,
|
|
167
|
+
label: section.querySelector('[data-search-label]'),
|
|
168
|
+
summary: section.querySelector('[data-search-summary]')
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
function refresh() {
|
|
172
|
+
const query = normalizeSearch(input.value);
|
|
173
|
+
panel.hidden = !query;
|
|
174
|
+
if (!query) return;
|
|
175
|
+
|
|
176
|
+
const terms = query.split(/\s+/);
|
|
177
|
+
const matches = [];
|
|
178
|
+
for (const { id, label, summary } of entries) {
|
|
179
|
+
const title = label.textContent;
|
|
180
|
+
const description = summary.textContent;
|
|
181
|
+
const name = normalizeSearch(title);
|
|
182
|
+
const anchor = '.' + shortName(id).toLowerCase();
|
|
183
|
+
const text = normalizeSearch(`${title} ${anchor} ${description}`);
|
|
184
|
+
if (!terms.every(term => text.includes(term))) continue;
|
|
185
|
+
const rank = name === query || anchor === query ? 0 : name.startsWith(query) || anchor.startsWith(query) ? 1 : 2;
|
|
186
|
+
matches.push({ id, title, description, rank });
|
|
187
|
+
}
|
|
188
|
+
matches.sort((left, right) => left.rank - right.rank);
|
|
189
|
+
|
|
190
|
+
results.replaceChildren(...matches.map(({ id, title, description }) => {
|
|
191
|
+
const item = document.createElement('li');
|
|
192
|
+
const link = document.createElement('a');
|
|
193
|
+
const heading = document.createElement('strong');
|
|
194
|
+
const detail = document.createElement('span');
|
|
195
|
+
link.href = '#' + id;
|
|
196
|
+
heading.textContent = title;
|
|
197
|
+
detail.textContent = description;
|
|
198
|
+
link.append(heading, detail);
|
|
199
|
+
item.append(link);
|
|
200
|
+
return item;
|
|
201
|
+
}));
|
|
202
|
+
empty.hidden = matches.length > 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
form.addEventListener('input', refresh);
|
|
206
|
+
form.addEventListener('submit', event => {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
if (!panel.hidden) results.querySelector('a')?.click();
|
|
209
|
+
});
|
|
210
|
+
results.addEventListener('click', event => {
|
|
211
|
+
if (event.target.closest('a') && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
212
|
+
form.reset();
|
|
213
|
+
panel.hidden = true;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
form.addEventListener('keydown', event => {
|
|
217
|
+
if (event.key === 'Escape') {
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
form.reset();
|
|
220
|
+
refresh();
|
|
221
|
+
input.focus();
|
|
222
|
+
} else if (event.key === 'ArrowDown' && event.target === input && !panel.hidden) {
|
|
223
|
+
const firstResult = results.querySelector('a');
|
|
224
|
+
if (firstResult) {
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
firstResult.focus();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
return refresh;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const searchForm = document.querySelector('[data-doc-search]');
|
|
234
|
+
const refreshSearch = searchForm && setupSearch(searchForm);
|
|
235
|
+
// ⌘K on Apple devices, Ctrl+K elsewhere, focuses the documentation search from anywhere on the page.
|
|
236
|
+
const searchShortcut = document.getElementById('doc-search-shortcut');
|
|
237
|
+
if (searchShortcut && !/Mac|iPhone|iPad/.test(navigator.platform)) searchShortcut.textContent = 'Ctrl K';
|
|
238
|
+
document.addEventListener('keydown', event => {
|
|
239
|
+
if (!searchForm || event.key.toLowerCase() !== 'k' || !(event.metaKey || event.ctrlKey)) return;
|
|
240
|
+
event.preventDefault();
|
|
241
|
+
searchForm.querySelector('input').focus();
|
|
242
|
+
});
|
|
243
|
+
const views = [...document.querySelectorAll('[data-view]')];
|
|
244
|
+
const navigation = [...document.querySelectorAll('[data-nav]')];
|
|
245
|
+
function resolveView(id) {
|
|
246
|
+
const direct = document.getElementById(id);
|
|
247
|
+
if (direct?.closest('[data-view]')) return direct;
|
|
248
|
+
const legacy = legacyViews.get(id) ?? views.find(view => view.id.endsWith('-' + id))?.id;
|
|
249
|
+
return legacy ? document.getElementById(legacy) : direct;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function showView({ scroll = false } = {}) {
|
|
253
|
+
const fragment = location.hash.slice(1);
|
|
254
|
+
let id = fragment;
|
|
255
|
+
try { id = decodeURIComponent(fragment); } catch { /* Keep malformed fragment text. */ }
|
|
256
|
+
const target = resolveView(id);
|
|
257
|
+
const requested = target?.closest('[data-view]') ?? views[0];
|
|
258
|
+
for (const view of views) view.hidden = view !== requested;
|
|
259
|
+
for (const link of navigation) {
|
|
260
|
+
if (link.hash === '#' + requested?.id) link.setAttribute('aria-current', 'page');
|
|
261
|
+
else link.removeAttribute('aria-current');
|
|
262
|
+
}
|
|
263
|
+
if (scroll && target && !target.closest('[hidden]')) {
|
|
264
|
+
target.scrollIntoView();
|
|
265
|
+
target.focus({ preventScroll: true });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
document.addEventListener('click', event => {
|
|
270
|
+
const control = event.target.closest('[data-action]');
|
|
271
|
+
if (!control) return;
|
|
272
|
+
const [scope, method] = control.dataset.action.includes('.') ? control.dataset.action.split('.') : [null, control.dataset.action];
|
|
273
|
+
const handler = scope ? standalone.get(scope) : owner(control, ({ actions }) => actions.includes(method));
|
|
274
|
+
if (!handler?.actions.includes(method)) throw new Error(`Aliens: unbound action "${control.dataset.action}".`);
|
|
275
|
+
handler.state[method]();
|
|
276
|
+
render(handler);
|
|
277
|
+
if (handler === localeModel && supported.includes(localeModel.state[localeField])) {
|
|
278
|
+
const updatedLocale = localeModel.state[localeField];
|
|
279
|
+
applyLocale(updatedLocale);
|
|
280
|
+
refreshSearch?.();
|
|
281
|
+
savePreference(localeKey, updatedLocale);
|
|
282
|
+
}
|
|
283
|
+
if (handler === themeModel) {
|
|
284
|
+
applyTheme(themeModel.state[themeField] ? 'dark' : 'light', true);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const initialLocale = preferredLocale();
|
|
289
|
+
if (localeModel) localeModel.state[localeField] = initialLocale;
|
|
290
|
+
applyTheme(preference(themeKey) ?? 'light');
|
|
291
|
+
render();
|
|
292
|
+
applyLocale(initialLocale);
|
|
293
|
+
showView({ scroll: Boolean(location.hash) });
|
|
294
|
+
window.addEventListener('hashchange', () => showView({ scroll: true }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Aliens example: Hero
|
|
2
|
+
# Mantém o estado do favorito local ao cartão e o alterna a cada clique.
|
|
3
|
+
#
|
|
4
|
+
# Logic HeroCard
|
|
5
|
+
# signal favorite: boolean = false
|
|
6
|
+
#
|
|
7
|
+
# bind:
|
|
8
|
+
# hero-card-favorite-button:
|
|
9
|
+
# pressed: this.favorite
|
|
10
|
+
#
|
|
11
|
+
# actions:
|
|
12
|
+
# toggleFavorite:
|
|
13
|
+
# returns: void
|
|
14
|
+
# body:
|
|
15
|
+
# this.favorite = !this.favorite
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Aliens example: Hero
|
|
2
|
+
# Card reutilizável do catálogo. O clique chama a ação do arquivo hero-card.logic.
|
|
3
|
+
#
|
|
4
|
+
# Markup HeroCard
|
|
5
|
+
# article variant="hero-card"
|
|
6
|
+
# h2={Nova}
|
|
7
|
+
# p={Defender of the orbital station.}
|
|
8
|
+
# button={Mark as favorite} id="hero-card-favorite-button" action="toggleFavorite"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Aliens example: Hero
|
|
2
|
+
# Estiliza apenas o cartão e seu botão favoritado.
|
|
3
|
+
#
|
|
4
|
+
# Style HeroCard
|
|
5
|
+
# hero-card
|
|
6
|
+
# display: grid
|
|
7
|
+
# gap: 8px
|
|
8
|
+
# padding: 16px
|
|
9
|
+
# border: 1px solid #c5d0bf
|
|
10
|
+
# border-radius: 8px
|
|
11
|
+
# hero-card button[aria-pressed="true"]
|
|
12
|
+
# font-weight: 700
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Aliens example: Hero
|
|
2
|
+
# O teste fica ao lado do Element. Ilustra o ciclo de marcar e desmarcar um favorito.
|
|
3
|
+
#
|
|
4
|
+
# Test HeroCard
|
|
5
|
+
# scenario: Toggle the favorite button twice
|
|
6
|
+
# given: The hero is not marked as a favorite
|
|
7
|
+
# when: The user presses the favorite button twice
|
|
8
|
+
# then: The button returns to its initial unpressed state
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Markup KitButtonDemo
|
|
2
|
+
section variant="space-card space-stack"
|
|
3
|
+
h2={@kit.buttons} variant="space-h4"
|
|
4
|
+
div variant="space-cluster"
|
|
5
|
+
button={@kit.tryButton} id="kit-button-demo-try-button" variant="space-button_primary" action="toggle"
|
|
6
|
+
a={@kit.typography} variant="space-button" href="#kit-type"
|
|
7
|
+
button={@kit.disabled} variant="space-button_quiet" type="button" disabled
|
|
8
|
+
p={@kit.buttonFeedback} variant="space-alert_success" id="kit-button-demo-feedback" role="status" hidden
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Markup KitCardLink
|
|
2
|
+
a href={$href} variant="space-card kit-card-link space-focus"
|
|
3
|
+
span={$preview} variant="kit-card-link-icon" aria-hidden="true"
|
|
4
|
+
h3={$label} variant="space-h5"
|
|
5
|
+
span={$caption} variant="kit-card-link-caption"
|
|
6
|
+
span={↗} variant="kit-card-link-arrow" aria-hidden="true"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Markup KitNavigation
|
|
2
|
+
div id="kit-navigation"
|
|
3
|
+
header id="kit-navigation-top"
|
|
4
|
+
a href="#kit-overview" id="kit-navigation-brand" variant="space-focus"
|
|
5
|
+
span id="kit-navigation-mark" aria-hidden="true"
|
|
6
|
+
span={@kit.title}
|
|
7
|
+
div id="kit-navigation-theme-field"
|
|
8
|
+
label={@kit.theme} for="kit-navigation-theme"
|
|
9
|
+
select variant="space-input kit-navigation-theme-select" id="kit-navigation-theme" data-theme-picker
|
|
10
|
+
option={@kit.light} value="light"
|
|
11
|
+
option={@kit.dark} value="dark"
|
|
12
|
+
nav id="kit-navigation-nav" aria-label={@kit.nav}
|
|
13
|
+
kit-nav-link href="#kit-overview" label={@kit.overview}
|
|
14
|
+
kit-nav-link href="#kit-color" label={@kit.color}
|
|
15
|
+
kit-nav-link href="#kit-space" label={@kit.spacing}
|
|
16
|
+
kit-nav-link href="#kit-radius" label={@kit.radius}
|
|
17
|
+
kit-nav-link href="#kit-border" label={@kit.borders}
|
|
18
|
+
kit-nav-link href="#kit-type" label={@kit.typography}
|
|
19
|
+
kit-nav-link href="#kit-components" label={@kit.components}
|