@aliens-syndicate/cli 0.1.1 → 0.1.3
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 +122 -93
- package/package.json +6 -2
- package/tools/build.mjs +326 -26
- package/tools/cli.mjs +31 -9
- package/tools/create.mjs +38 -12
- package/tools/icon-docs.mjs +132 -0
- package/tools/runtime.mjs +216 -8
- package/tools/starter/ai/agents/codingbot.agent +5 -0
- package/tools/starter/ai/rules/architecture.rule +11 -0
- package/tools/starter/ai/skills/create-element.skill +6 -0
- package/tools/starter/app/elements/molecules/kit-card-link/kit-card-link.markup +0 -2
- package/tools/starter/app/pages/kit-overview/kit-overview.markup +6 -6
- package/tools/starter/app/pages/style-guide/style-guide.style +57 -57
- package/tools/starter/styles/components/alerts.style +6 -5
- package/tools/starter/styles/components/badges.style +6 -5
- package/tools/starter/styles/components/borders.style +2 -1
- package/tools/starter/styles/components/buttons.style +14 -13
- package/tools/starter/styles/components/cards.style +1 -1
- package/tools/starter/styles/components/feedback.style +3 -2
- package/tools/starter/styles/components/forms.style +5 -4
- package/tools/starter/styles/components/tables.style +4 -3
- package/tools/starter/styles/components/typography.style +6 -5
- package/tools/starter/styles/generic/ui-base.style +1 -1
- package/tools/starter/styles/objects/ui-layout.style +1 -1
- package/tools/style-docs.mjs +274 -0
- package/tools/vscode-space/package.json +5 -8
- package/tools/vscode-space/space.tmLanguage.json +1 -1
- package/tools/vscode-space/syntax.cjs +103 -62
- package/tools/watch.mjs +48 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// Generates the Style page (project/app/pages/style-docs) from the utility catalog of the style extension that .config
|
|
2
|
+
// declares under style: from: (usually @aliens-syndicate/style), so every class the page lists is a class the build
|
|
3
|
+
// accepts. Run it after updating the package: node tools/style-docs.mjs
|
|
4
|
+
import { readFile, readdir, writeFile, mkdir } from 'node:fs/promises';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const workspace = resolve(import.meta.dirname, '..');
|
|
10
|
+
const config = await readFile(join(workspace, '.config'), 'utf8');
|
|
11
|
+
const from = /^style:\r?\n(?: {3}.*\r?\n)*? {3}from: (.+)$/m.exec(config)?.[1].trim();
|
|
12
|
+
if (!from) throw new Error('style-docs: declare the style extension in .config under style: from:.');
|
|
13
|
+
const entry = /^\.{1,2}\//.test(from) ? join(workspace, from, 'index.mjs') : createRequire(join(workspace, 'package.json')).resolve(from);
|
|
14
|
+
const {
|
|
15
|
+
breakpoints, describeVariant, groups, paletteNames, registeredDefaults, resolveUtility, shadeSteps, variantCatalog
|
|
16
|
+
} = await import(pathToFileURL(entry).href);
|
|
17
|
+
const page = join(workspace, 'project/app/pages/style-docs');
|
|
18
|
+
const styles = join(workspace, 'project/styles');
|
|
19
|
+
|
|
20
|
+
async function styleFiles(directory) {
|
|
21
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
22
|
+
const nested = await Promise.all(entries.map(entry => entry.isDirectory() ? styleFiles(join(directory, entry.name))
|
|
23
|
+
: entry.name.endsWith('.style') ? [join(directory, entry.name)] : []));
|
|
24
|
+
return nested.flat();
|
|
25
|
+
}
|
|
26
|
+
const themeColors = [];
|
|
27
|
+
for (const file of (await styleFiles(styles)).sort()) {
|
|
28
|
+
for (const match of (await readFile(file, 'utf8')).matchAll(/^ +--color-([a-z][a-z0-9-]*):\s/gm)) {
|
|
29
|
+
if (!themeColors.includes(match[1])) themeColors.push(match[1]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The page shows the CSS a reader expects: the --tw-* helpers are folded into the declarations that read them.
|
|
34
|
+
const displayDefaults = { ...registeredDefaults, '--tw-shadow': '', '--tw-ring-shadow': '', '--tw-content': "''" };
|
|
35
|
+
function pretty(declarations) {
|
|
36
|
+
const helpers = Object.fromEntries(declarations.filter(([property]) => property.startsWith('--tw-')));
|
|
37
|
+
const visible = declarations.filter(([property]) => !property.startsWith('--tw-'));
|
|
38
|
+
const shown = (visible.length ? visible : declarations).map(([property, value]) => {
|
|
39
|
+
let resolved = value;
|
|
40
|
+
for (let previous = ''; previous !== resolved;) {
|
|
41
|
+
previous = resolved;
|
|
42
|
+
resolved = resolved.replace(/var\((--tw-[\w-]+)(?:,\s*([^()]*(?:\([^()]*\))?[^()]*))?\)/g, (_, name, fallback) =>
|
|
43
|
+
helpers[name] ?? (fallback !== undefined && fallback.trim() ? fallback.trim() : displayDefaults[name] ?? ''));
|
|
44
|
+
}
|
|
45
|
+
const clean = resolved.replace(/\s+/g, ' ').replace(/^[\s,]+|[\s,]+$/g, '').replace(/,\s*,/g, ',').replace(/\(\s*,\s*/g, '(').trim();
|
|
46
|
+
return `${property}: ${clean || 'none'}`;
|
|
47
|
+
});
|
|
48
|
+
return shown.join('; ');
|
|
49
|
+
}
|
|
50
|
+
function row(name) {
|
|
51
|
+
const utility = resolveUtility(name, { colors: themeColors });
|
|
52
|
+
if (utility.error) throw new Error(`style-docs: ${name}: ${utility.error}`);
|
|
53
|
+
const css = pretty(utility.declarations);
|
|
54
|
+
return { name, css: utility.child ? `${utility.child.trim()} { ${css} }` : css };
|
|
55
|
+
}
|
|
56
|
+
const camel = id => id.replace(/-([a-z0-9])/g, (_, letter) => letter.toUpperCase());
|
|
57
|
+
const titleKey = id => `@styleDocs.group.${camel(id)}`;
|
|
58
|
+
const properties = rows => [...new Set(rows.flatMap(({ css }) => css.replace(/^[^{]*\{ | \}$/g, '').split('; ')
|
|
59
|
+
.map(entry => entry.slice(0, entry.indexOf(':'))).filter(property => property && !property.startsWith('-webkit-'))))].slice(0, 2);
|
|
60
|
+
|
|
61
|
+
const lists = [];
|
|
62
|
+
function list(name, items) {
|
|
63
|
+
lists.push(` list ${name}:\n${items.map((fields, index) => ` r${index + 1}:\n${Object.entries(fields)
|
|
64
|
+
.map(([key, value]) => ` ${key}: ${value}`).join('\n')}`).join('\n')}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const sections = groups.map(group => ({
|
|
68
|
+
...group,
|
|
69
|
+
sections: group.sections.map(section => {
|
|
70
|
+
const rows = [...new Set([...section.statics, ...section.examples])].map(row);
|
|
71
|
+
list(camel(section.id), rows);
|
|
72
|
+
return { ...section, rows, properties: properties(rows) };
|
|
73
|
+
})
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
list('benefits', ['Names', 'Typing', 'Prefix', 'Responsive', 'States', 'Arbitrary', 'Checked', 'Css'].map(name => ({
|
|
77
|
+
title: `@styleDocs.benefit${name}Title`, text: `@styleDocs.benefit${name}`
|
|
78
|
+
})));
|
|
79
|
+
const variantRows = names => names.map(name => {
|
|
80
|
+
const described = describeVariant(name);
|
|
81
|
+
return { name: `${name}:`, css: described.startsWith('@') ? described.slice(1) : described };
|
|
82
|
+
});
|
|
83
|
+
list('responsiveVariants', variantRows(variantCatalog.responsive));
|
|
84
|
+
list('stateVariants', variantRows([...variantCatalog.states, ...variantCatalog.elements, ...variantCatalog.media]));
|
|
85
|
+
list('arbitraryValues', ['w-[1240px]', 'grid-cols-[minmax(220px,1fr)_2fr]', 'text-[clamp(1rem,2vw,1.18rem)]', 'bg-(--surface)',
|
|
86
|
+
'text-(length:--text-small)', 'shadow-[0_18px_30px_var(--shadow)]', '[mask-type:luminance]', 'max-lg:[font:0.9rem_var(--mono)]']
|
|
87
|
+
.map(row));
|
|
88
|
+
list('themeColors', themeColors.map(name => ({ ...row(`bg-${name}`), swatch: `background: var(--color-${name})` })));
|
|
89
|
+
list('palette', paletteNames.flatMap(family => shadeSteps.map(shade => ({
|
|
90
|
+
name: `${family}-${shade}`, swatch: `background: ${row(`bg-${family}-${shade}`).css.slice('background-color: '.length)}`
|
|
91
|
+
}))));
|
|
92
|
+
|
|
93
|
+
const indent = level => ' '.repeat(level);
|
|
94
|
+
const lines = [];
|
|
95
|
+
const add = (level, text) => lines.push(indent(level) + text);
|
|
96
|
+
function table(level, listName, first = '@styleDocs.classColumn', second = '@styleDocs.stylesColumn') {
|
|
97
|
+
add(level, 'div variant="style-docs-table-frame" tabindex="0"');
|
|
98
|
+
add(level + 1, 'table variant="style-docs-table"');
|
|
99
|
+
add(level + 2, 'thead');
|
|
100
|
+
add(level + 3, 'tr');
|
|
101
|
+
add(level + 4, `th={${first}} scope="col"`);
|
|
102
|
+
add(level + 4, `th={${second}} scope="col"`);
|
|
103
|
+
add(level + 2, 'tbody');
|
|
104
|
+
add(level + 3, `for row in ${listName}`);
|
|
105
|
+
add(level + 4, 'tr data-filter-item');
|
|
106
|
+
add(level + 5, 'td');
|
|
107
|
+
add(level + 6, 'code={$row.name} variant="style-docs-class"');
|
|
108
|
+
add(level + 5, 'td');
|
|
109
|
+
add(level + 6, 'code={$row.css}');
|
|
110
|
+
}
|
|
111
|
+
function window(level, title, source) {
|
|
112
|
+
add(level, 'div variant="home-guide-window"');
|
|
113
|
+
add(level + 1, 'div variant="home-guide-window-bar"');
|
|
114
|
+
add(level + 2, 'span variant="home-guide-window-dots" aria-hidden="true"');
|
|
115
|
+
add(level + 2, `code={${title}}`);
|
|
116
|
+
add(level + 1, 'pre variant="home-guide-window-code" tabindex="0"');
|
|
117
|
+
add(level + 2, `code data-source="${source}"`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
lines.push('Markup StyleDocs');
|
|
121
|
+
add(1, 'article variant="home-view" id="style-docs" data-view data-search-entry hidden tabindex="-1"');
|
|
122
|
+
add(2, 'aside id="style-docs-sidebar"');
|
|
123
|
+
// The search field sits on top of the sidebar, which stays in view while the page scrolls, and filters the sections.
|
|
124
|
+
add(3, 'div id="style-docs-finder"');
|
|
125
|
+
add(4, 'form id="style-docs-finder-form" role="search"');
|
|
126
|
+
add(5, 'label={@styleDocs.searchLabel} for="style-docs-finder-input" id="style-docs-finder-label"');
|
|
127
|
+
add(5, 'icon search-01 id="style-docs-finder-icon"');
|
|
128
|
+
add(5, 'input type="search" id="style-docs-finder-input" placeholder={@styleDocs.searchPlaceholder} autocomplete="off" spellcheck="false" data-filter');
|
|
129
|
+
add(4, 'p id="style-docs-finder-status" data-filter-status aria-live="polite" hidden');
|
|
130
|
+
add(5, 'span text="0" id="style-docs-finder-count" data-filter-count');
|
|
131
|
+
add(5, 'span={@styleDocs.searchResults}');
|
|
132
|
+
add(3, 'nav id="style-docs-nav" aria-label={@styleDocs.navLabel} data-toc');
|
|
133
|
+
add(4, 'p={@styleDocs.groupStart} variant="style-docs-nav-title"');
|
|
134
|
+
for (const [anchor, key] of [['overview', 'overviewNav'], ['install', 'installNav'], ['benefits', 'benefitsNav'], ['writing', 'writingNav'],
|
|
135
|
+
['responsive', 'responsiveNav'], ['states', 'statesNav'], ['arbitrary', 'arbitraryNav'], ['colors', 'colorsNav']]) {
|
|
136
|
+
add(4, `a={@styleDocs.${key}} href="#style-docs-${anchor}" variant="style-docs-nav-link"`);
|
|
137
|
+
}
|
|
138
|
+
add(4, 'a={@styleDocs.libraryNav} href="#kit-overview" variant="style-docs-nav-link"');
|
|
139
|
+
for (const group of sections) {
|
|
140
|
+
add(4, `p={${titleKey(group.id)}} variant="style-docs-nav-title"`);
|
|
141
|
+
for (const section of group.sections) add(4, `a={${section.title}} href="#style-docs-${section.id}" variant="style-docs-nav-link"`);
|
|
142
|
+
}
|
|
143
|
+
add(2, 'div id="style-docs-main"');
|
|
144
|
+
add(3, 'header id="style-docs-overview"');
|
|
145
|
+
add(4, 'p variant="home-breadcrumb"');
|
|
146
|
+
add(5, 'a={@nav.home} href="#home-guide"');
|
|
147
|
+
add(5, 'span={/} aria-hidden="true"');
|
|
148
|
+
add(5, 'span={@nav.styles}');
|
|
149
|
+
add(4, 'p={@styleDocs.eyebrow} id="style-docs-eyebrow"');
|
|
150
|
+
add(4, 'h1={@styleDocs.title} data-search-label');
|
|
151
|
+
add(4, 'p={@styleDocs.lead} variant="home-topic-lead" data-search-summary');
|
|
152
|
+
add(4, 'div id="style-docs-hero-code" aria-hidden="true"');
|
|
153
|
+
add(5, 'code={flex items-center gap-4 md:flex-row hover:bg-surface dark:text-white} id="style-docs-hero-line"');
|
|
154
|
+
|
|
155
|
+
add(3, 'p={@styleDocs.searchEmpty} id="style-docs-finder-empty" data-filter-empty hidden');
|
|
156
|
+
// Installation: plain CSS works without the package; utilities need it installed and declared in .config.
|
|
157
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-install"');
|
|
158
|
+
add(4, 'h2={@styleDocs.installTitle}');
|
|
159
|
+
add(4, 'p={@styleDocs.installDetail} variant="style-docs-lead"');
|
|
160
|
+
add(4, 'ol variant="style-docs-steps"');
|
|
161
|
+
for (const [key, title, code] of [
|
|
162
|
+
['installStep', 'terminal', ['npm install @aliens-syndicate/style']],
|
|
163
|
+
['configStep', '.config', ['style:', ' from: @aliens-syndicate/style']],
|
|
164
|
+
['useStep', 'counter.style', ['Style Counter', ' counter', ' flex items-center gap-3 md:gap-4', ' transition: color .15s',
|
|
165
|
+
' counter-button', ' px-4 py-2 rounded-lg hover:bg-(--surface)']]]) {
|
|
166
|
+
add(5, 'li');
|
|
167
|
+
add(6, `p={@styleDocs.${key}}`);
|
|
168
|
+
add(6, 'div variant="home-guide-window"');
|
|
169
|
+
add(7, 'div variant="home-guide-window-bar"');
|
|
170
|
+
add(8, 'span variant="home-guide-window-dots" aria-hidden="true"');
|
|
171
|
+
add(8, `code={${title}}`);
|
|
172
|
+
add(7, 'div variant="home-guide-window-code home-guide-code" tabindex="0"');
|
|
173
|
+
for (const text of code) add(8, `code text="${text}" variant="home-guide-code-line"`);
|
|
174
|
+
}
|
|
175
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-benefits"');
|
|
176
|
+
add(4, 'h2={@styleDocs.benefitsTitle}');
|
|
177
|
+
add(4, 'p={@styleDocs.benefitsDetail} variant="style-docs-lead"');
|
|
178
|
+
add(4, 'ul id="style-docs-benefit-list"');
|
|
179
|
+
add(5, 'for benefit in benefits');
|
|
180
|
+
add(6, 'li data-filter-item');
|
|
181
|
+
add(7, 'strong={$benefit.title}');
|
|
182
|
+
add(7, 'span={$benefit.text}');
|
|
183
|
+
add(4, 'h3={@styleDocs.compareTitle}');
|
|
184
|
+
add(4, 'p={@styleDocs.compareDetail} variant="style-docs-lead"');
|
|
185
|
+
add(4, 'div id="style-docs-compare"');
|
|
186
|
+
add(5, 'div variant="home-guide-window"');
|
|
187
|
+
add(6, 'div variant="home-guide-window-bar"');
|
|
188
|
+
add(7, 'span variant="home-guide-window-dots" aria-hidden="true"');
|
|
189
|
+
add(7, 'code={@styleDocs.compareBefore}');
|
|
190
|
+
add(6, 'div variant="home-guide-window-code home-guide-code" tabindex="0"');
|
|
191
|
+
for (const text of ['Style SiteHeader', ' site-header', ' position: sticky', ' top: 0', ' z-index: 5',
|
|
192
|
+
' border-bottom: 1px solid var(--line)', ' background: color-mix(in srgb, var(--page) 82%, transparent)',
|
|
193
|
+
' backdrop-filter: saturate(1.8) blur(12px)', ' -webkit-backdrop-filter: saturate(1.8) blur(12px)',
|
|
194
|
+
' @media (max-width: 900px)', ' site-header-inner', ' min-height: 58px', ' padding: 0 14px']) {
|
|
195
|
+
add(7, `code text="${text}" variant="home-guide-code-line"`);
|
|
196
|
+
}
|
|
197
|
+
add(5, 'div variant="home-guide-window"');
|
|
198
|
+
add(6, 'div variant="home-guide-window-bar"');
|
|
199
|
+
add(7, 'span variant="home-guide-window-dots" aria-hidden="true"');
|
|
200
|
+
add(7, 'code={@styleDocs.compareAfter}');
|
|
201
|
+
add(6, 'div variant="home-guide-window-code home-guide-code" tabindex="0"');
|
|
202
|
+
for (const text of ['Style SiteHeader', ' site-header', ' sticky top-0 z-5 border-b border-b-(--line) bg-(--page)/82',
|
|
203
|
+
' backdrop-saturate-180 backdrop-blur-md', ' site-header-inner', ' max-lg:min-h-14.5 max-lg:py-0 max-lg:px-3.5']) {
|
|
204
|
+
add(7, `code text="${text}" variant="home-guide-code-line"`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-writing"');
|
|
208
|
+
add(4, 'h2={@styleDocs.writingTitle}');
|
|
209
|
+
add(4, 'p={@styleDocs.writingDetail} variant="style-docs-lead"');
|
|
210
|
+
add(4, 'ul variant="home-guide-checks"');
|
|
211
|
+
for (const key of ['writingDeclaration', 'writingUtilities', 'writingVariants', 'writingImportant']) {
|
|
212
|
+
add(5, 'li');
|
|
213
|
+
add(6, 'icon tick-02 variant="home-guide-check"');
|
|
214
|
+
add(6, `span={@styleDocs.${key}}`);
|
|
215
|
+
}
|
|
216
|
+
window(4, 'site-header.style', 'project/app/elements/organisms/site-header/site-header.style');
|
|
217
|
+
|
|
218
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-responsive"');
|
|
219
|
+
add(4, 'h2={@styleDocs.responsiveTitle}');
|
|
220
|
+
add(4, 'p={@styleDocs.responsiveDetail} variant="style-docs-lead"');
|
|
221
|
+
table(4, 'responsiveVariants', '@styleDocs.variantColumn', '@styleDocs.conditionColumn');
|
|
222
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-states"');
|
|
223
|
+
add(4, 'h2={@styleDocs.statesTitle}');
|
|
224
|
+
add(4, 'p={@styleDocs.statesDetail} variant="style-docs-lead"');
|
|
225
|
+
table(4, 'stateVariants', '@styleDocs.variantColumn', '@styleDocs.conditionColumn');
|
|
226
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-arbitrary"');
|
|
227
|
+
add(4, 'h2={@styleDocs.arbitraryTitle}');
|
|
228
|
+
add(4, 'p={@styleDocs.arbitraryDetail} variant="style-docs-lead"');
|
|
229
|
+
table(4, 'arbitraryValues');
|
|
230
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-colors"');
|
|
231
|
+
add(4, 'h2={@styleDocs.colorsTitle}');
|
|
232
|
+
add(4, 'p={@styleDocs.colorsDetail} variant="style-docs-lead"');
|
|
233
|
+
add(4, 'h3={@styleDocs.themeColorsTitle}');
|
|
234
|
+
add(4, 'ul id="style-docs-theme-colors"');
|
|
235
|
+
add(5, 'for color in themeColors');
|
|
236
|
+
add(6, 'li data-filter-item');
|
|
237
|
+
add(7, 'span variant="style-docs-swatch" style={$color.swatch} aria-hidden="true"');
|
|
238
|
+
add(7, 'code={$color.name}');
|
|
239
|
+
add(4, 'h3={@styleDocs.paletteTitle}');
|
|
240
|
+
add(4, 'ul id="style-docs-palette"');
|
|
241
|
+
add(5, 'for color in palette');
|
|
242
|
+
add(6, 'li title={$color.name} data-filter-item');
|
|
243
|
+
add(7, 'span variant="style-docs-swatch" style={$color.swatch} aria-hidden="true"');
|
|
244
|
+
add(7, 'code={$color.name}');
|
|
245
|
+
for (const group of sections) {
|
|
246
|
+
add(3, `section variant="style-docs-group" data-filter-set id="style-docs-${group.id}"`);
|
|
247
|
+
add(4, `h2={${titleKey(group.id)}}`);
|
|
248
|
+
for (const section of group.sections) {
|
|
249
|
+
add(4, `section variant="style-docs-section" data-filter-group id="style-docs-${section.id}"`);
|
|
250
|
+
add(5, `h3={${section.title}}`);
|
|
251
|
+
add(5, 'p variant="style-docs-lead"');
|
|
252
|
+
add(6, 'span={@styleDocs.setsBefore}');
|
|
253
|
+
section.properties.forEach((property, index) => {
|
|
254
|
+
if (index) add(6, 'span={@styleDocs.and}');
|
|
255
|
+
add(6, `code={${property}}`);
|
|
256
|
+
});
|
|
257
|
+
add(6, 'span={@styleDocs.setsAfter}');
|
|
258
|
+
table(5, camel(section.id));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
add(3, 'section variant="style-docs-block" data-filter-group id="style-docs-library"');
|
|
262
|
+
add(4, 'h2={@styleDocs.libraryTitle}');
|
|
263
|
+
add(4, 'p={@styleDocs.libraryDetail} variant="style-docs-lead"');
|
|
264
|
+
add(4, `ui-link href="#kit-overview" variant="ui-link_secondary" label={@styleDocs.libraryLink} icon="arrow-up-right-01"`);
|
|
265
|
+
|
|
266
|
+
await mkdir(page, { recursive: true });
|
|
267
|
+
await writeFile(join(page, 'style-docs.markup'), lines.join('\n') + '\n');
|
|
268
|
+
await writeFile(join(page, 'style-docs.logic'), `Logic StyleDocs
|
|
269
|
+
# Generated by tools/style-docs.mjs from the utility catalog of @aliens-syndicate/style. Update the package, not this file.
|
|
270
|
+
${lists.join('\n')}
|
|
271
|
+
`);
|
|
272
|
+
const total = sections.reduce((sum, group) => sum + group.sections.reduce((count, section) => count + section.rows.length, 0), 0);
|
|
273
|
+
console.log(`Style page generated: ${sections.reduce((sum, group) => sum + group.sections.length, 0)} sections, ${total} classes, ` +
|
|
274
|
+
`breakpoints ${Object.keys(breakpoints).join(', ')}.`);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "space-language-preview",
|
|
3
3
|
"displayName": "Space Language",
|
|
4
4
|
"description": "Native semantic highlighting and inline stylesheet colors for Space.",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.3",
|
|
6
6
|
"publisher": "aliens-local",
|
|
7
7
|
"private": true,
|
|
8
8
|
"engines": {"vscode": "^1.90.0"},
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
{"id": "spaceTranslation", "superType": "string", "description": "Space translation reference."},
|
|
55
55
|
{"id": "spaceSelector", "superType": "class", "description": "Space stylesheet selector."},
|
|
56
56
|
{"id": "spaceElement", "superType": "class", "description": "Space markup element."},
|
|
57
|
-
{"id": "spaceColor", "superType": "number", "description": "Space stylesheet color literal."},
|
|
58
57
|
{"id": "spaceActions", "superType": "keyword", "description": "Space action declaration block."},
|
|
59
58
|
{"id": "spaceLiteral", "superType": "keyword", "description": "Space boolean or null literal."}
|
|
60
59
|
],
|
|
@@ -67,7 +66,6 @@
|
|
|
67
66
|
"spaceTranslation": ["string.unquoted"],
|
|
68
67
|
"spaceSelector": ["entity.name.tag.css"],
|
|
69
68
|
"spaceElement": ["entity.name.tag"],
|
|
70
|
-
"spaceColor": ["constant.other.color.rgb-value.hex.css"],
|
|
71
69
|
"spaceActions": ["entity.name.function"],
|
|
72
70
|
"spaceLiteral": ["constant.language"]
|
|
73
71
|
}
|
|
@@ -80,7 +78,8 @@
|
|
|
80
78
|
"editor.insertSpaces": true,
|
|
81
79
|
"editor.detectIndentation": false,
|
|
82
80
|
"editor.semanticHighlighting.enabled": true,
|
|
83
|
-
"editor.colorDecorators": true
|
|
81
|
+
"editor.colorDecorators": true,
|
|
82
|
+
"editor.bracketPairColorization.enabled": false
|
|
84
83
|
},
|
|
85
84
|
"editor.semanticTokenColorCustomizations": {
|
|
86
85
|
"rules": {
|
|
@@ -89,7 +88,7 @@
|
|
|
89
88
|
"type:space": "#75dbd3",
|
|
90
89
|
"function:space": "#81c7ff",
|
|
91
90
|
"spaceActions:space": "#81c7ff",
|
|
92
|
-
"spaceSelector:space": "#
|
|
91
|
+
"spaceSelector:space": "#d5a9ff",
|
|
93
92
|
"spaceElement:space": "#81c7ff",
|
|
94
93
|
"variable:space": "#ff9098",
|
|
95
94
|
"property:space": "#ff9098",
|
|
@@ -98,7 +97,6 @@
|
|
|
98
97
|
"spaceReturn:space": "#81e0a1",
|
|
99
98
|
"spaceLiteral:space": "#81e0a1",
|
|
100
99
|
"spaceTranslation:space": "#81e0a1",
|
|
101
|
-
"spaceColor:space": "#81e0a1",
|
|
102
100
|
"spaceReactive:space": "#d5a9ff",
|
|
103
101
|
"comment:space": "#b0b0b0"
|
|
104
102
|
},
|
|
@@ -109,7 +107,7 @@
|
|
|
109
107
|
"type:space": "#006864",
|
|
110
108
|
"function:space": "#145c9e",
|
|
111
109
|
"spaceActions:space": "#145c9e",
|
|
112
|
-
"spaceSelector:space": "#
|
|
110
|
+
"spaceSelector:space": "#6d349e",
|
|
113
111
|
"spaceElement:space": "#145c9e",
|
|
114
112
|
"variable:space": "#a22c37",
|
|
115
113
|
"property:space": "#a22c37",
|
|
@@ -118,7 +116,6 @@
|
|
|
118
116
|
"spaceReturn:space": "#17683b",
|
|
119
117
|
"spaceLiteral:space": "#17683b",
|
|
120
118
|
"spaceTranslation:space": "#17683b",
|
|
121
|
-
"spaceColor:space": "#17683b",
|
|
122
119
|
"spaceReactive:space": "#6d349e",
|
|
123
120
|
"comment:space": "#595959"
|
|
124
121
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"scopeName": "source.space",
|
|
3
3
|
"name": "Space",
|
|
4
4
|
"patterns": [
|
|
5
|
-
{ "name": "comment.line.number-sign.space", "match": "^\\s*#(?:\\s.*|(?:AI|TODO|FIXME|NOTE|WARN|DEPRECATED)\\b.*)?$" },
|
|
5
|
+
{ "name": "comment.line.number-sign.space", "match": "^\\s*#(?:\\s.*|(?:AGENT|AI|TODO|FIXME|NOTE|WARN|DEPRECATED)\\b.*)?$" },
|
|
6
6
|
{
|
|
7
7
|
"match": "^([A-Z][a-z]+)( +)([A-Z]\\w*)\\s*$",
|
|
8
8
|
"captures": {
|
|
@@ -1,46 +1,61 @@
|
|
|
1
1
|
const { findColors } = require('./style-colors.cjs');
|
|
2
2
|
|
|
3
3
|
const reserved = new Map([
|
|
4
|
-
['signal',
|
|
5
|
-
['effect',
|
|
6
|
-
['returns',
|
|
7
|
-
['import',
|
|
8
|
-
['onInit',
|
|
9
|
-
['onDestroy',
|
|
10
|
-
['if',
|
|
11
|
-
['
|
|
12
|
-
['
|
|
13
|
-
['
|
|
4
|
+
['signal', 'spaceReactive'], ['computed', 'spaceReactive'],
|
|
5
|
+
['effect', 'spaceReactive'], ['actions', 'spaceActions'],
|
|
6
|
+
['returns', 'spaceReturn'], ['return', 'spaceReturn'],
|
|
7
|
+
['import', 'keyword'], ['body', 'keyword'],
|
|
8
|
+
['onInit', 'keyword'], ['onMount', 'keyword'],
|
|
9
|
+
['onDestroy', 'keyword'], ['function', 'keyword'],
|
|
10
|
+
['if', 'keyword'], ['else', 'keyword'],
|
|
11
|
+
['for', 'keyword'], ['list', 'keyword'],
|
|
12
|
+
['number', 'type'], ['integer', 'type'], ['string', 'type'],
|
|
13
|
+
['boolean', 'type'], ['void', 'type'],
|
|
14
|
+
['true', 'spaceLiteral'], ['false', 'spaceLiteral'], ['null', 'spaceLiteral']
|
|
14
15
|
]);
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
'
|
|
20
|
-
|
|
17
|
+
// Each token type belongs to one color role. The editor colors a type with its rule in package.json, and the site
|
|
18
|
+
// highlights with a space-<role> class whose color the build reads from those same rules, so both always match.
|
|
19
|
+
const roles = {
|
|
20
|
+
keyword: 'control', class: 'type', type: 'type', function: 'action', spaceActions: 'action', spaceElement: 'action',
|
|
21
|
+
property: 'value', variable: 'value', number: 'return', string: 'return', spaceReturn: 'return',
|
|
22
|
+
spaceLiteral: 'return', spaceTranslation: 'return', spaceReactive: 'reactive', spaceSelector: 'reactive',
|
|
23
|
+
comment: 'comment'
|
|
24
|
+
};
|
|
25
|
+
const tokenTypes = Object.keys(roles);
|
|
26
|
+
|
|
27
|
+
const htmlTags = new Set(('a abbr address article aside audio b blockquote body br button canvas caption cite code col ' +
|
|
28
|
+
'colgroup data datalist dd del details dfn dialog div dl dt em fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 ' +
|
|
29
|
+
'head header hgroup hr html i iframe img input ins kbd label legend li link main mark menu meter nav noscript object ol ' +
|
|
30
|
+
'optgroup option output p picture pre progress q rp rt ruby s samp search section select slot small source span strong ' +
|
|
31
|
+
'sub summary sup svg table tbody td template textarea tfoot th thead time tr track u ul var video wbr').split(' '));
|
|
32
|
+
|
|
33
|
+
// Each part of a selector takes the color of its kind: the markup id or variant ("site-header"), its _modifier
|
|
34
|
+
// ("_menu-open") and [attribute] filters, HTML tags ("li", "*"), and :states (":hover", "::before", ":nth-child(2)").
|
|
35
|
+
// Combinators, commas and parentheses stay uncolored.
|
|
36
|
+
const selectorPart = /\[[^\]]*\]|:nth-[a-z-]+\([^)]*\)|::?[A-Za-z-]+|_[A-Za-z0-9-]+|[A-Za-z][A-Za-z0-9-]*|\*/g;
|
|
37
|
+
|
|
38
|
+
function selectorType(part) {
|
|
39
|
+
if (part.startsWith('[') || part.startsWith('_')) return 'string';
|
|
40
|
+
if (part.startsWith(':')) return 'keyword';
|
|
41
|
+
if (part === '*' || htmlTags.has(part)) return 'spaceElement';
|
|
42
|
+
return 'spaceSelector';
|
|
43
|
+
}
|
|
21
44
|
|
|
22
45
|
function isSpaceComment(value, style) {
|
|
23
|
-
return value.startsWith('#') && (!style || /^#(?:\s|$|(?:AI|TODO|FIXME|NOTE|WARN|DEPRECATED)\b)/.test(value));
|
|
46
|
+
return value.startsWith('#') && (!style || /^#(?:\s|$|(?:AGENT|AI|TODO|FIXME|NOTE|WARN|DEPRECATED)\b)/.test(value));
|
|
24
47
|
}
|
|
25
48
|
|
|
26
49
|
function lexicalType(value) {
|
|
27
50
|
if (reserved.has(value)) return reserved.get(value);
|
|
28
|
-
if (value.startsWith('/*')) return
|
|
29
|
-
if (value.startsWith('@')) return
|
|
30
|
-
if (value.startsWith('$')) return
|
|
31
|
-
if (/^["']/.test(value)) return
|
|
32
|
-
if (/^\d/.test(value)) return
|
|
51
|
+
if (value.startsWith('/*')) return 'comment';
|
|
52
|
+
if (value.startsWith('@')) return 'spaceTranslation';
|
|
53
|
+
if (value.startsWith('$')) return 'variable';
|
|
54
|
+
if (/^["']/.test(value)) return 'string';
|
|
55
|
+
if (/^\d/.test(value)) return 'number';
|
|
33
56
|
return null;
|
|
34
57
|
}
|
|
35
58
|
|
|
36
|
-
function styleValueType(token, rest) {
|
|
37
|
-
if (token.startsWith('/*')) return ['comment', 'comment'];
|
|
38
|
-
if (token.startsWith('--')) return ['variable', 'value'];
|
|
39
|
-
if (/^\d/.test(token)) return ['number', 'return'];
|
|
40
|
-
if (rest.startsWith('(')) return ['function', 'action'];
|
|
41
|
-
return ['string', 'return'];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
59
|
function analyzeSpace(source, extension) {
|
|
45
60
|
const tokens = [];
|
|
46
61
|
const colors = [];
|
|
@@ -52,12 +67,12 @@ function analyzeSpace(source, extension) {
|
|
|
52
67
|
const body = text.trim();
|
|
53
68
|
if (!body) continue;
|
|
54
69
|
const indent = text.length - text.trimStart().length;
|
|
55
|
-
const emit = (start, length, type,
|
|
56
|
-
tokens.push({ line, start, length, type, role, declaration });
|
|
70
|
+
const emit = (start, length, type, declaration = false) => {
|
|
71
|
+
tokens.push({ line, start, length, type, role: roles[type], declaration });
|
|
57
72
|
};
|
|
58
73
|
|
|
59
74
|
if (isSpaceComment(body, style)) {
|
|
60
|
-
emit(indent, body.length, 'comment'
|
|
75
|
+
emit(indent, body.length, 'comment');
|
|
61
76
|
continue;
|
|
62
77
|
}
|
|
63
78
|
|
|
@@ -65,58 +80,84 @@ function analyzeSpace(source, extension) {
|
|
|
65
80
|
const parent = parents.at(-1)?.kind;
|
|
66
81
|
const header = indent === 0 && /^([A-Z][a-z]+)( +)([A-Z][\w]*)$/.exec(body);
|
|
67
82
|
if (header && '.' + header[1].toLowerCase() === extension) {
|
|
68
|
-
emit(0, header[1].length, 'keyword'
|
|
69
|
-
emit(header[1].length + header[2].length, header[3].length, 'class',
|
|
83
|
+
emit(0, header[1].length, 'keyword');
|
|
84
|
+
emit(header[1].length + header[2].length, header[3].length, 'class', true);
|
|
70
85
|
parents.push({ indent, kind: 'header' });
|
|
71
86
|
continue;
|
|
72
87
|
}
|
|
73
88
|
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
// A .style reads in three colors: the selector (the markup id or variant being styled), the style itself
|
|
90
|
+
// (utilities and "property: value" declarations alike) and the variants or at-rules that say when it applies.
|
|
76
91
|
if (style) {
|
|
77
|
-
const property = parent === 'selector' && /^([\w-]
|
|
92
|
+
const property = parent === 'selector' && /^(-{0,2}[A-Za-z][\w-]*):\s+/.exec(body);
|
|
78
93
|
if (property) {
|
|
79
|
-
emit(indent, property[1].length, 'property'
|
|
80
|
-
valueStart = indent + property[0].length;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
emit(
|
|
94
|
+
emit(indent, property[1].length, 'property');
|
|
95
|
+
const valueStart = indent + property[0].length;
|
|
96
|
+
colors.push(...findColors(text.slice(valueStart), property[1])
|
|
97
|
+
.map(color => ({ ...color, line, start: valueStart + color.start })));
|
|
98
|
+
const words = /\/\*[^]*?\*\/|\S+/g;
|
|
99
|
+
words.lastIndex = valueStart;
|
|
100
|
+
for (let match = words.exec(text); match; match = words.exec(text)) {
|
|
101
|
+
emit(match.index, match[0].length, match[0].startsWith('/*') ? 'comment' : 'property');
|
|
87
102
|
}
|
|
88
|
-
parents.push({ indent, kind });
|
|
103
|
+
parents.push({ indent, kind: 'node' });
|
|
89
104
|
continue;
|
|
90
105
|
}
|
|
106
|
+
// Any other line inside a selector lists utilities, like "flex gap-4 md:flex-row": the variants before
|
|
107
|
+
// the last ":" read as keywords and the utility as a property.
|
|
108
|
+
if (parent === 'selector') {
|
|
109
|
+
const utilities = /\S+/g;
|
|
110
|
+
for (let match = utilities.exec(text); match; match = utilities.exec(text)) {
|
|
111
|
+
const token = match[0];
|
|
112
|
+
let depth = 0;
|
|
113
|
+
let split = -1;
|
|
114
|
+
for (let index = 0; index < token.length; index++) {
|
|
115
|
+
if ('[('.includes(token[index])) depth++;
|
|
116
|
+
else if ('])'.includes(token[index])) depth--;
|
|
117
|
+
else if (token[index] === ':' && depth === 0) split = index;
|
|
118
|
+
}
|
|
119
|
+
if (split >= 0) emit(match.index, split + 1, 'keyword');
|
|
120
|
+
emit(match.index + split + 1, token.length - split - 1, 'property');
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const kind = body.startsWith('@') ? 'atRule' : /^(?:default|import):$/.test(body) ? 'manifest' : 'selector';
|
|
125
|
+
if (kind === 'selector' && parent !== 'manifest') {
|
|
126
|
+
selectorPart.lastIndex = indent;
|
|
127
|
+
for (let match = selectorPart.exec(text); match; match = selectorPart.exec(text)) {
|
|
128
|
+
emit(match.index, match[0].length, selectorType(match[0]));
|
|
129
|
+
}
|
|
130
|
+
} else if (parent !== 'manifest') emit(indent, body.length, 'keyword');
|
|
131
|
+
parents.push({ indent, kind });
|
|
132
|
+
continue;
|
|
91
133
|
}
|
|
92
134
|
|
|
93
|
-
const
|
|
135
|
+
const loop = markup && /^for\s/.test(body);
|
|
136
|
+
const element = markup && !loop && /^[a-z][\w-]*/.exec(body)?.[0];
|
|
94
137
|
const signal = /^signal\s+(\w+):/.exec(body)?.[1];
|
|
95
138
|
const action = parent === 'actions' && /^(\w+):$/.exec(body)?.[1];
|
|
96
139
|
const callable = /^function\s+(\w+)\(/.exec(body)?.[1];
|
|
97
|
-
const field = parent && !
|
|
98
|
-
const
|
|
99
|
-
const lexemes = value.matchAll(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\/\*[^]*?\*\/|--[A-Za-z_][\w-]*|[@$][a-zA-Z_][\w.-]*|\b[A-Za-z_-][\w-]*\b|\b\d+(?:\.\d+)?\b/g);
|
|
140
|
+
const field = parent && !markup && /^(\w[\w-]*):/.exec(body)?.[1];
|
|
141
|
+
const lexemes = text.matchAll(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\/\*[^]*?\*\/|--[A-Za-z_][\w-]*|[@$][a-zA-Z_][\w.-]*|\b[A-Za-z_-][\w-]*\b|\b\d+(?:\.\d+)?\b/g);
|
|
100
142
|
for (const match of lexemes) {
|
|
101
143
|
const token = match[0];
|
|
102
|
-
const start =
|
|
144
|
+
const start = match.index;
|
|
103
145
|
const rest = text.slice(start + token.length);
|
|
104
|
-
|
|
105
|
-
let type = style ? styleValueType(token, rest) : lexicalType(token);
|
|
146
|
+
let type = lexicalType(token);
|
|
106
147
|
let declaration = false;
|
|
107
|
-
if (start === indent && token === element) type =
|
|
108
|
-
else if (
|
|
109
|
-
else if (
|
|
110
|
-
else if (token ===
|
|
111
|
-
else if (
|
|
112
|
-
else if (!type &&
|
|
113
|
-
if (type
|
|
148
|
+
if (start === indent && token === element) type = 'spaceElement';
|
|
149
|
+
else if (loop && token === 'in') type = 'keyword';
|
|
150
|
+
else if (markup && /^\s*=/.test(rest) && /^[a-z][\w-]*$/.test(token)) type = 'property';
|
|
151
|
+
else if (token === signal) { type = 'variable'; declaration = true; }
|
|
152
|
+
else if (token === action || token === callable) { type = 'function'; declaration = true; }
|
|
153
|
+
else if (!type && !markup && text.slice(0, start).endsWith('this.')) type = 'property';
|
|
154
|
+
else if (!type && start === indent && token === field) type = 'property';
|
|
155
|
+
if (type) emit(start, token.length, type, declaration);
|
|
114
156
|
}
|
|
115
|
-
for (const color of lineColors) emit(valueStart + color.start, color.length, 'spaceColor', 'return');
|
|
116
157
|
parents.push({ indent, kind: body === 'actions:' ? 'actions' : 'node' });
|
|
117
158
|
}
|
|
118
159
|
|
|
119
160
|
return { tokens: tokens.sort((left, right) => left.line - right.line || left.start - right.start), colors };
|
|
120
161
|
}
|
|
121
162
|
|
|
122
|
-
module.exports = { analyzeSpace, isSpaceComment, tokenTypes };
|
|
163
|
+
module.exports = { analyzeSpace, htmlTags, isSpaceComment, roles, tokenTypes };
|
package/tools/watch.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { join, resolve, sep } from 'node:path';
|
|
4
|
+
|
|
5
|
+
// Watch mode: every saved file runs the build again, so dist/ and ai/.map always describe the current code.
|
|
6
|
+
const language = (() => {
|
|
7
|
+
const tag = (process.env.ALIENS_LANG || process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG ||
|
|
8
|
+
Intl.DateTimeFormat().resolvedOptions().locale || 'en').toLowerCase();
|
|
9
|
+
return ['pt', 'es', 'zh'].find(code => tag.startsWith(code)) ?? 'en';
|
|
10
|
+
})();
|
|
11
|
+
const watching = {
|
|
12
|
+
en: 'Watching the project. Each saved file rebuilds dist/ and ai/.map (Ctrl+C to stop).',
|
|
13
|
+
pt: 'Observando o projeto. Cada arquivo salvo refaz dist/ e ai/.map (Ctrl+C para parar).',
|
|
14
|
+
es: 'Observando el proyecto. Cada archivo guardado rehace dist/ y ai/.map (Ctrl+C para detener).',
|
|
15
|
+
zh: '正在监听项目。每次保存文件都会重新生成 dist/ 和 ai/.map(按 Ctrl+C 停止)。'
|
|
16
|
+
}[language];
|
|
17
|
+
|
|
18
|
+
const workspace = resolve(import.meta.dirname, '..');
|
|
19
|
+
const build = join(import.meta.dirname, 'build.mjs');
|
|
20
|
+
// The build writes dist/ and the .map itself, so those changes never start another build.
|
|
21
|
+
const ignored = new Set(['dist', 'node_modules', '.git', '.DS_Store']);
|
|
22
|
+
const skip = file => file.split(sep).some(part => ignored.has(part)) || file.endsWith('.map');
|
|
23
|
+
|
|
24
|
+
let running = null;
|
|
25
|
+
let pending = false;
|
|
26
|
+
let timer;
|
|
27
|
+
function run() {
|
|
28
|
+
if (running) {
|
|
29
|
+
pending = true;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
running = spawn(process.execPath, ['--disable-warning=ExperimentalWarning', build], { stdio: 'inherit' });
|
|
33
|
+
running.on('exit', () => {
|
|
34
|
+
running = null;
|
|
35
|
+
if (pending) {
|
|
36
|
+
pending = false;
|
|
37
|
+
run();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
watch(workspace, { recursive: true }, (event, file) => {
|
|
43
|
+
if (!file || skip(file)) return;
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
timer = setTimeout(run, 120);
|
|
46
|
+
});
|
|
47
|
+
console.log(watching);
|
|
48
|
+
run();
|