@alis-build/design-system 0.52.0 → 0.53.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 CHANGED
@@ -54,14 +54,15 @@ subfolder, the rules are under that folder's `node_modules`. Never copy the
54
54
  rules into your repo: a copy stops moving with the version.
55
55
 
56
56
  **2. Check your styles.** Add `stylelint` (16.11 or later) as a dev dependency,
57
- with `postcss-html` if you have `<style>` blocks in Svelte or Vue files and
58
- `postcss-scss` if any of them is `lang="scss"` (without it those blocks are
59
- skipped, silently). Then in `stylelint.config.js`:
57
+ with `postcss-html` if you have Svelte, Vue, HTML or templ files (it reads
58
+ their `<style>` blocks and static `style=""` attributes) and `postcss-scss` if
59
+ any block is `lang="scss"` (without it those blocks are skipped, silently).
60
+ Then in `stylelint.config.js`:
60
61
 
61
62
  ```js
62
63
  export default {
63
64
  extends: ['@alis-build/design-system/stylelint'],
64
- overrides: [{ files: ['**/*.svelte', '**/*.vue'], customSyntax: 'postcss-html' }],
65
+ overrides: [{ files: ['**/*.svelte', '**/*.vue', '**/*.html', '**/*.templ'], customSyntax: 'postcss-html' }],
65
66
  }
66
67
  ```
67
68
 
@@ -109,7 +110,9 @@ export default {
109
110
  rule on that line), gives no reason, or silences nothing.
110
111
 
111
112
  - It reads what is written in CSS. A value held in a Sass variable or a mixin,
112
- or a literal behind a custom property of your own (`--pad: 13px`), is not seen.
113
+ or a literal behind a custom property of your own (`--pad: 13px`), is not seen,
114
+ and nor is a bound style (`:style`, `style={ … }`). A templ `css` component
115
+ can't be read at all, so `alisx-check styles` stops on one.
113
116
 
114
117
  **3. Run the checks in your build.**
115
118
 
@@ -143,6 +146,9 @@ export default {
143
146
  - `alisx-check words` fails on a name `words.json` has retired ("idea" for a
144
147
  project, "Access and ownership" for Sharing) in text a person reads: text
145
148
  between tags, and quoted text that holds a space or starts with a capital.
149
+ In a templ file the Go is code, read as script is: outside a component, its
150
+ `if`, `for`, `switch` and `case` lines, and an `@Component(…)` call's
151
+ arguments.
146
152
  Its baseline, `alisx-words-baseline.json`, works as the styles one does. A
147
153
  use that must stay is marked on its line or the line above:
148
154
  `alisx-words-ignore -- the reason`.
package/check.mjs CHANGED
@@ -41,6 +41,10 @@
41
41
  // person reads. Lines of the field code or alias are code, and so is what
42
42
  // is in backticks, a printf verb (%s) or a placeholder (<id>). The baseline
43
43
  // counts each block's place, so one gaining a retired name fails.
44
+ //
45
+ // Svelte, Vue, HTML and templ files are read as markup. In templ, the Go is
46
+ // script: outside a component, and inside one its statement lines (if, for,
47
+ // switch, case) and the arguments of an @Component(…) call.
44
48
  import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
45
49
  import { spawnSync } from 'node:child_process'
46
50
  import { tmpdir } from 'node:os'
@@ -81,7 +85,7 @@ function names() {
81
85
  const prefixes = (options.prefix.length ? options.prefix : ['app-', 'text-']).map(escape).join('|')
82
86
  const allowed = options.allow.map((glob) => new RegExp(`^${glob.split('*').map(escape).join('.*')}$`))
83
87
 
84
- const sources = ['.svelte', '.vue', '.html', '.jsx', '.tsx', '.js', '.ts', '.mjs', '.css', '.scss', '.less']
88
+ const sources = ['.svelte', '.vue', '.html', '.templ', '.jsx', '.tsx', '.js', '.ts', '.mjs', '.css', '.scss', '.less']
85
89
  const missing = [...paths, ...options.declared].filter((path) => !existsSync(path))
86
90
  if (missing.length) stop(`alisx-check names: no such path: ${missing.join(', ')}`)
87
91
  const files = paths.flatMap((path) => walk(resolve(path))).filter((file) => sources.includes(extname(file)))
@@ -172,10 +176,16 @@ function styles() {
172
176
  for (const each of result.invalidOptionWarnings ?? []) broken.push(each.text)
173
177
  for (const each of result.parseErrors ?? []) broken.push(`${result.source}: ${each.text}`)
174
178
  for (const each of result.warnings) if (each.rule === 'CssSyntaxError') broken.push(`${result.source}:${each.line}: ${each.text}`)
179
+ // A templ css component is a stylesheet stylelint can't parse out of Go.
180
+ if (extname(result.source) === '.templ') {
181
+ const text = readFileSync(result.source, 'utf8')
182
+ for (const match of text.matchAll(/^css\s+\w+/gm))
183
+ broken.push(`${result.source}:${text.slice(0, match.index).split('\n').length}: a templ css component is not read. Write it in a stylesheet or a <style> block.`)
184
+ }
175
185
  }
176
186
  if (broken.length)
177
187
  stop(
178
- `alisx-check styles: the check could not run as configured, so nothing was compared.\n\n ${[...new Set(broken)].join('\n ')}\n\nA file with a <style> block needs its syntax in your stylelint config (postcss-html; postcss-scss for lang="scss").`,
188
+ `alisx-check styles: the check could not run as configured, so nothing was compared.\n\n ${[...new Set(broken)].join('\n ')}\n\nA Svelte, Vue, HTML or templ file needs its syntax in your stylelint config (postcss-html; postcss-scss for lang="scss").`,
179
189
  )
180
190
 
181
191
  // Keyed by the file's path from the baseline's own directory, so the same
@@ -255,7 +265,7 @@ function words() {
255
265
  .sort((a, b) => b.text.length - a.text.length)
256
266
  .map((each) => ({ ...each, pattern: new RegExp(`(?<![\\w./-])${escape(each.text).replace(/ /g, '\\s+')}(?![\\w/-]|\\.\\w)`, 'gi') }))
257
267
 
258
- const sources = ['.svelte', '.vue', '.html', '.jsx', '.tsx', '.js', '.ts', '.mjs']
268
+ const sources = ['.svelte', '.vue', '.html', '.templ', '.jsx', '.tsx', '.js', '.ts', '.mjs']
259
269
  const missing = paths.filter((path) => !existsSync(path))
260
270
  if (missing.length) stop(`alisx-check words: no such path: ${missing.join(', ')}`)
261
271
  const files = paths
@@ -357,23 +367,29 @@ function readable(text, ext) {
357
367
  const human = (value) => /[A-Za-z]/.test(value) && (/\S\s+\S/.test(value) || /^\s*[A-Z][a-z]/.test(value))
358
368
  // What a log or a console prints is read by nobody on screen.
359
369
  const script = (code, offset) => quoted(unlogged(code), (start, value) => human(value) && pieces.push({ start: offset + start, value }))
360
- if (!['.vue', '.svelte', '.html'].includes(ext)) {
370
+ if (!['.vue', '.svelte', '.html', '.templ'].includes(ext)) {
361
371
  script(text, 0)
362
372
  return pieces
363
373
  }
364
374
 
365
375
  // Script blocks are script; style blocks and comments are nobody's text.
366
376
  const blank = (match) => match.replace(/[^\n]/g, ' ')
367
- let markup = text.replace(/<!--[\s\S]*?-->/g, blank).replace(/<style\b[\s\S]*?<\/style>/gi, blank)
377
+ let markup = ext === '.templ' ? templ(text, script, blank) : text
378
+ markup = markup.replace(/<!--[\s\S]*?-->/g, blank).replace(/<style\b[\s\S]*?<\/style>/gi, blank)
368
379
  markup = markup.replace(/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi, (match, open, code, close, index) => {
369
380
  script(code, index + open.length)
370
381
  return blank(match)
371
382
  })
372
- // An expression in markup ({{ … }} or { … }) is script.
373
- markup = markup.replace(/\{\{([\s\S]*?)\}\}|\{([^{}]*)\}/g, (match, mustache, single, index) => {
374
- script(mustache ?? single, index + (mustache === undefined ? 1 : 2))
375
- return blank(match)
376
- })
383
+ // An expression in markup ({{ … }} or { … }) is script. A templ expression
384
+ // may hold a Go literal's braces (Props{…}), so its file is read until none is left.
385
+ for (let before = null; before !== markup; ) {
386
+ before = markup
387
+ markup = markup.replace(/\{\{([\s\S]*?)\}\}|\{([^{}]*)\}/g, (match, mustache, single, index) => {
388
+ script(mustache ?? single, index + (mustache === undefined ? 1 : 2))
389
+ return blank(match)
390
+ })
391
+ if (ext !== '.templ') break
392
+ }
377
393
  // An attribute: code when bound (:x, @x, #x, v-x, on:x, bind:x), nobody's
378
394
  // text when it names a class, a route or a key; otherwise it may be read.
379
395
  const code = /^(?:[:@#]|v-|on:|bind:)/
@@ -389,6 +405,44 @@ function readable(text, ext) {
389
405
  return pieces
390
406
  }
391
407
 
408
+ // A templ file as markup, every offset kept. Go outside a component (package,
409
+ // import, func, var) is script. Inside one, a statement line (if, for, switch,
410
+ // case, a closing brace) is script and leaves its markup; @Component(…) is a
411
+ // call, so its name is blanked and its arguments are script. The braces a line
412
+ // leaves would otherwise read as one expression around the markup it holds,
413
+ // and the text in it would go unread. A component starts at `templ Name(…) {`
414
+ // and ends at the `}` that starts a line, as templ fmt writes it.
415
+ function templ(text, script, blank) {
416
+ const out = []
417
+ let go = 0 // where the Go outside a component starts; null inside one
418
+ let at = 0
419
+ for (const line of text.split('\n')) {
420
+ const start = at
421
+ at += line.length + 1
422
+ const trimmed = line.trim()
423
+ if (go !== null) {
424
+ if (/^templ\s.*\{\s*$/.test(line)) {
425
+ script(text.slice(go, start), go)
426
+ go = null
427
+ }
428
+ out.push(blank(line))
429
+ } else if (/^\}/.test(line)) {
430
+ go = at
431
+ out.push(blank(line))
432
+ } else if (/^\/\//.test(trimmed)) out.push(blank(line))
433
+ else if (/^(?:if|for|switch|case|default)\b|^\}\s*(?:else\b.*)?$/.test(trimmed)) {
434
+ script(line, start)
435
+ out.push(blank(line))
436
+ } else if (/^@[\w.]+/.test(trimmed)) {
437
+ const call = line.indexOf('@') + /^@[\w.]+/.exec(trimmed)[0].length
438
+ script(' '.repeat(call) + line.slice(call), start)
439
+ out.push(blank(line))
440
+ } else out.push(line)
441
+ }
442
+ if (go !== null) script(text.slice(go), go)
443
+ return out.join('\n')
444
+ }
445
+
392
446
  // The text in a words file a person reads, each line with where it starts and
393
447
  // the place its block names. A code span that a long line wrapped carries on
394
448
  // to the next line of its block.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alis-build/design-system",
3
- "version": "0.52.0",
3
+ "version": "0.53.0",
4
4
  "description": "The AlisX design system for coding agents: tokens, product CSS, component markup, capability marks, words and rules.",
5
5
  "keywords": ["alisx", "design-system", "design-tokens", "css"],
6
6
  "homepage": "https://alisx.com",
@@ -40,9 +40,9 @@ Cite by ID in review. Each is a defect that has shipped in an Alis product.
40
40
  themed or wrapped.
41
41
 
42
42
  - **C5 a second manual**: how the platform works, written into a screen, a dialog,
43
- a help panel or a command, where it drifts from the docs and no search finds it.
44
- One sentence and a "How *thing* works" link instead ([register.md](register.md)
45
- § Show it or explain it).
43
+ a help panel or a command, about nothing on the screen, where it drifts from the
44
+ docs and no search finds it. Explain what is shown, beside it, and link the rest
45
+ with "How *thing* works" ([register.md](register.md) § Show it or explain it).
46
46
 
47
47
  ## D · Config holes
48
48
 
@@ -76,9 +76,10 @@ Seven questions, about a minute. **Run this before handing work back.**
76
76
  6. **Have you looked at it in dark?** Set `data-theme="dark"` on the page. Text
77
77
  that vanishes, a white box, a shadow doing an edge's job → a colour that isn't
78
78
  a role ([themes.md](themes.md)).
79
- 7. **Is anything here written once, for everyone, beyond one sentence?** Concepts,
80
- how-it-works steps, conventions, gotchas → C5: it is the docs; link it. A page
81
- called a Glass view that reads nothing of yours is the docs too.
79
+ 7. **Point at what each explanation is about.** One that points at nothing on the
80
+ screen (concepts, how-it-works steps, conventions, a gotchas list) → C5: it is
81
+ the docs; link it. A page called a Glass view that reads nothing of yours is
82
+ the docs too.
82
83
 
83
84
  ## The agent failure mode
84
85
 
@@ -86,4 +87,4 @@ A developer under-reads a system and invents locally (C3). An agent does the
86
87
  opposite: it **over-produces**. Linters catch shapes, not this. Before handing
87
88
  work back, look for **B6** (a card where spacing would have done), **B1** (a
88
89
  second primary), **B9** (an outline on every card), a fourth type role, a section
89
- nobody asked for, a section explaining how it works (C5), and a colour that is not a role.
90
+ nobody asked for, a section explaining nothing on the screen (C5), and a colour that is not a role.
package/rules/register.md CHANGED
@@ -33,18 +33,24 @@ platform when you open it, or was it written once, for everyone?**
33
33
  deployment stands, the arithmetic behind your score): a product screen.
34
34
  - **Written once, for everyone** (what a workstation is, how a release moves, a
35
35
  Makefile's conventions, what to do when a deploy hangs): the docs, where search,
36
- `alis docs` and every agent find it, and where it is written once rather than
37
- drifting in two places. The screen links to it.
38
- - **A page that does both** is a product screen: the live part stays, the
39
- explanation moves to the docs, and the screen links to it.
40
-
41
- How much a screen explains, so the line is not a judgment:
42
-
43
- - **One sentence that says what a thing is, where you first meet it**: an empty
44
- state's line, a field's supporting line, a dialog's line. Then the link.
45
- - **Never a section of explanation**: no concepts, how-it-works steps, lifecycle,
46
- conventions, worked examples, gotchas or FAQ on a screen, a tab, a dialog or a
47
- help panel; and no screen or dialog that holds only explanation.
36
+ `alis docs` and every agent find it, written in full once. The screen links to
37
+ it.
38
+ - **A page that does both** is a product screen: the live part stays, and so
39
+ does the explanation of what it shows (below). The rest moves to the docs.
40
+
41
+ How much a screen explains is decided by what the person is looking at. The test:
42
+ **can you point at the thing on the screen each explanation is about?**
43
+
44
+ - **Beside the thing it explains, as much as helps**: a line under a state, a
45
+ value, a field or a section, saying what it means, why your thing is like this,
46
+ and what to do. "Production deploys only from `main`; this build came from
47
+ `fix-login`." It may say what the docs also say: the screen holds what this
48
+ thing needs, the docs the whole account. An empty state's line and a field's
49
+ supporting line are the same case.
50
+ - **About nothing on the screen, it is the docs**: a section of concepts, how it
51
+ works, a lifecycle, conventions, worked examples, gotchas or an FAQ, and a
52
+ screen, tab, dialog or help panel of explanation alone. A gotcha your thing has
53
+ now ("Asleep. It wakes when you connect.") points at its state, so it stays.
48
54
  - **The link reads "How *thing* works"** ("How workstations work"): a text
49
55
  button with a trailing `open_in_new` that opens the docs page in a new tab
50
56
  ([buttons.md](buttons.md) § The form). Never "Learn more", "Explain …" or
@@ -71,8 +77,12 @@ result as it lands.
71
77
  - **The product register throughout**: the title bar, sections, tables and
72
78
  states every screen has. No hero, no display type, no petrol band; it is a
73
79
  working screen, and the person on it asked a question.
74
- - **Its explanation is a docs link** ("How build environments work"), by the
75
- rule above.
80
+ - **It explains your thing**, by the rule above: why each part is as it is and
81
+ what to do next, beside that part, built from its state. The person on it is
82
+ working, and this is the most useful explanation they can have. How the
83
+ platform works in general is a docs link ("How build environments work").
84
+ - **An agent sees what you see**: the same data, from the same service, through
85
+ the CLI ([terminal.md](terminal.md)).
76
86
  - **Smaller evidence stays in place**: the arithmetic behind one score, in a
77
87
  dialog from the stat it explains, is part of that screen, not a Glass view.
78
88
 
package/rules/styling.md CHANGED
@@ -96,7 +96,8 @@ The package ships what can be linted, so every app checks the same things
96
96
  radius and shadow written without their tokens, local type, a forced
97
97
  priority, and a selector on a system class. It reads the token and class
98
98
  names from the package, so a new token needs no edit to the check. In a
99
- Svelte or Vue file it reads the `<style>` block and a static `style=""`.
99
+ Svelte, Vue, HTML or templ file it reads the `<style>` block and a static
100
+ `style=""`, under the same rules.
100
101
  - **A gap is said where it is**, by rule and with a reason:
101
102
  `/* stylelint-disable-next-line <rule> -- GAP: what this needs */`. A disable
102
103
  is itself reported when it names no rule, gives no reason, or silences
package/rules/terminal.md CHANGED
@@ -31,7 +31,9 @@ The line in [register.md](register.md) § Show it or explain it holds here too.
31
31
  A command or a key shows your things; what it prints about how the platform works
32
32
  is the docs page's address and `alis docs <topic>`, never an explanation of its
33
33
  own, so there is one manual for people and agents. Where it shows the live inside
34
- of one thing, it calls that the **Glass view**.
34
+ of one thing, it calls that the **Glass view**, and its `--json` carries the
35
+ same data the console's Glass view shows, from the same service, so an agent
36
+ working beside you sees what you see.
35
37
 
36
38
  ## Command and flag names
37
39
 
package/stylelint.mjs CHANGED
@@ -9,7 +9,7 @@
9
9
  //
10
10
  // export default {
11
11
  // extends: ['@alis-build/design-system/stylelint'],
12
- // overrides: [{ files: ['**/*.svelte', '**/*.vue'], customSyntax: 'postcss-html' }],
12
+ // overrides: [{ files: ['**/*.svelte', '**/*.vue', '**/*.html', '**/*.templ'], customSyntax: 'postcss-html' }],
13
13
  // }
14
14
  //
15
15
  // A rule you set under the same name REPLACES the system's: stylelint never
@@ -24,6 +24,7 @@
24
24
  // A disable is itself reported when it names no rule (it would silence every
25
25
  // rule on that line), gives no reason after `--`, or silences nothing.
26
26
  import { readFileSync } from 'node:fs'
27
+ import stylelint from 'stylelint'
27
28
 
28
29
  export const guide = 'rules/styling.md in @alis-build/design-system'
29
30
 
@@ -114,12 +115,33 @@ export const allowed = {
114
115
  /** Every allowed part, as the default config uses them. */
115
116
  export const allowedValues = Object.values(allowed)
116
117
 
117
- /** Type belongs to a text-* class. Refused in a rule; an @font-face is not one. */
118
+ /** Type belongs to a text-* class. Refused in a rule and in a style attribute; an @font-face is neither. */
118
119
  export const refusedProperties = {
119
120
  properties: ['font', 'font-family', 'font-size', 'font-weight', 'font-variation-settings', 'line-height', 'letter-spacing', 'text-transform', 'text-shadow'],
120
121
  message: (selector, property) => `${property} is appearance: a text-* class carries type (${guide}).`,
121
122
  }
122
123
 
124
+ // rule-selector-property-disallowed-list reads a declaration only inside a rule,
125
+ // so a static style="" (a stylesheet without the tag, styling.md) needs its own:
126
+ // a declaration with no rule or at-rule around it is one an attribute holds.
127
+ // Nothing in a rule is read here, so nothing is reported twice.
128
+ const inlineType = 'alisx/inline-type'
129
+ const inlineTypeRule = (on) => (root, result) => {
130
+ if (!on) return
131
+ root.walkDecls((declaration) => {
132
+ if (declaration.parent?.type !== 'root' || !refusedProperties.properties.includes(declaration.prop.toLowerCase())) return
133
+ stylelint.utils.report({
134
+ ruleName: inlineType,
135
+ result,
136
+ node: declaration,
137
+ word: declaration.prop,
138
+ message: `${declaration.prop} in a style attribute is appearance: a text-* class carries type (${guide}).`,
139
+ })
140
+ })
141
+ }
142
+ inlineTypeRule.ruleName = inlineType
143
+ inlineTypeRule.messages = {}
144
+
123
145
  /** A site never restyles a system class. Exact names, so .app-bar-search of your own is yours. */
124
146
  export const refusedSelectors = {
125
147
  selectors: [new RegExp(`\\.(?:${escaped(systemClasses)})(?![\\w-])`)],
@@ -169,6 +191,7 @@ export default {
169
191
  reportDescriptionlessDisables: true,
170
192
  reportUnscopedDisables: true,
171
193
  reportNeedlessDisables: true,
194
+ plugins: [stylelint.createPlugin(inlineType, inlineTypeRule)],
172
195
  rules: {
173
196
  // A named colour is a hex by another name. Hex is refused with the other
174
197
  // literal colours below, so a mask may use either.
@@ -176,6 +199,7 @@ export default {
176
199
  'declaration-property-value-disallowed-list': refuse(refusedValues),
177
200
  'declaration-property-value-allowed-list': allow(allowedValues),
178
201
  'rule-selector-property-disallowed-list': [{ '/.*/': refusedProperties.properties }, { message: refusedProperties.message }],
202
+ [inlineType]: true,
179
203
  'declaration-no-important': [true, { message: `!important fights the system: settle it once, in the theme, or not at all (${guide}).` }],
180
204
  'selector-disallowed-list': [refusedSelectors.selectors, { message: refusedSelectors.message }],
181
205
  },
package/words.json CHANGED
@@ -46,7 +46,7 @@
46
46
  {
47
47
  "name": "docs",
48
48
  "product": "all",
49
- "means": "How the platform works, written once for everyone: the docs site, and `alis docs` in the terminal, the one manual for people and agents. A screen says what a thing is in one sentence and links to its page with \"How *thing* works\", a text button with a trailing open_in_new (register.md § Show it or explain it).",
49
+ "means": "How the platform works, written once for everyone: the docs site, and `alis docs` in the terminal, the one manual for people and agents. A screen explains what it shows, beside it, and links the rest with \"How *thing* works\", a text button with a trailing open_in_new (register.md § Show it or explain it).",
50
50
  "retired": ["Learn more"],
51
51
  "avoid": ["Explain (as a label for a link to the docs)", "Documentation (as a link label)", "help centre", "knowledge base"]
52
52
  },