@tempoxyz/ds 0.3.16 → 0.3.18
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/dist/docs/AGENTS.md +4 -2
- package/dist/docs/marketing.md +699 -0
- package/dist/docs/product/documents.md +248 -0
- package/dist/docs/product/foundations.md +1 -1
- package/dist/document/Document.d.ts +46 -0
- package/dist/document/Document.d.ts.map +1 -0
- package/dist/document/Document.js +190 -0
- package/dist/document/Document.js.map +1 -0
- package/dist/document/Enhance.d.ts +13 -0
- package/dist/document/Enhance.d.ts.map +1 -0
- package/dist/document/Enhance.js +511 -0
- package/dist/document/Enhance.js.map +1 -0
- package/dist/document/bin.d.ts +3 -0
- package/dist/document/bin.d.ts.map +1 -0
- package/dist/document/bin.js +38 -0
- package/dist/document/bin.js.map +1 -0
- package/dist/document/document.css +388 -0
- package/dist/document/index.d.ts +3 -0
- package/dist/document/index.d.ts.map +1 -0
- package/dist/document/index.js +3 -0
- package/dist/document/index.js.map +1 -0
- package/dist/document/internal/Cli.d.ts +43 -0
- package/dist/document/internal/Cli.d.ts.map +1 -0
- package/dist/document/internal/Cli.js +87 -0
- package/dist/document/internal/Cli.js.map +1 -0
- package/dist/document/internal/Template.d.ts +21 -0
- package/dist/document/internal/Template.d.ts.map +1 -0
- package/dist/document/internal/Template.js +15 -0
- package/dist/document/internal/Template.js.map +1 -0
- package/dist/document/script.d.ts +2 -0
- package/dist/document/script.d.ts.map +1 -0
- package/dist/document/script.js +452 -0
- package/dist/document/templates/brief.html +96 -0
- package/dist/document/templates/essay.html +70 -0
- package/dist/document/templates/post.html +69 -0
- package/package.json +19 -1
- package/src/document/Document.ts +277 -0
- package/src/document/Enhance.ts +532 -0
- package/src/document/bin.ts +38 -0
- package/src/document/document.css +388 -0
- package/src/document/index.ts +2 -0
- package/src/document/internal/Cli.ts +132 -0
- package/src/document/internal/Template.ts +25 -0
- package/src/document/script.ts +8 -0
- package/src/document/templates/brief.html +96 -0
- package/src/document/templates/essay.html +70 -0
- package/src/document/templates/post.html +69 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<!--
|
|
3
|
+
Post template for Tempo document mode. Replace every placeholder that a comment marks,
|
|
4
|
+
keep the structure, and run the lint before you publish:
|
|
5
|
+
npx -p @tempoxyz/ds@0.3.18 tempo-document lint post.html
|
|
6
|
+
-->
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="utf-8" />
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
11
|
+
<!-- Replace: the document title. -->
|
|
12
|
+
<title>Title of the post</title>
|
|
13
|
+
<link
|
|
14
|
+
rel="stylesheet"
|
|
15
|
+
href="https://cdn.jsdelivr.net/npm/@tempoxyz/ds@0.3.18/dist/document/document.css"
|
|
16
|
+
/>
|
|
17
|
+
<script
|
|
18
|
+
defer
|
|
19
|
+
src="https://cdn.jsdelivr.net/npm/@tempoxyz/ds@0.3.18/dist/document/script.js"
|
|
20
|
+
></script>
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
<article class="doc" data-template="post">
|
|
24
|
+
<header>
|
|
25
|
+
<!-- Replace: the title, the dek, the authors, and the date. -->
|
|
26
|
+
<h1>Title of the post</h1>
|
|
27
|
+
<p class="dek">One sentence that states what the reader can do after reading.</p>
|
|
28
|
+
<p class="byline">By author name · <time datetime="2026-11-17">Nov 17, 2026</time></p>
|
|
29
|
+
</header>
|
|
30
|
+
|
|
31
|
+
<!-- Replace: the opening paragraph, which states who the post is for. -->
|
|
32
|
+
<p>
|
|
33
|
+
State who the post is for and what it covers.<span class="sn"
|
|
34
|
+
><small
|
|
35
|
+
>A note holds a source or an aside. The script numbers it and lists it at the
|
|
36
|
+
end.</small
|
|
37
|
+
></span
|
|
38
|
+
>
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
<!-- Replace: two or three sections. Number the steps of a procedure with ol.steps. -->
|
|
42
|
+
<h2 id="steps">Steps</h2>
|
|
43
|
+
|
|
44
|
+
<ol class="steps">
|
|
45
|
+
<li>Write the first step as an instruction.</li>
|
|
46
|
+
<li>Write the second step, and name the result the reader sees.</li>
|
|
47
|
+
<li>Write the last step, and say how the reader knows it worked.</li>
|
|
48
|
+
</ol>
|
|
49
|
+
|
|
50
|
+
<!-- Replace: a figure that shows the result. The caption states the takeaway, then the source. -->
|
|
51
|
+
<figure>
|
|
52
|
+
<svg viewBox="0 0 640 88" role="img" aria-labelledby="figure-title">
|
|
53
|
+
<title id="figure-title">Two values drawn as bars, the second twice the first.</title>
|
|
54
|
+
<text class="label" x="0" y="20">Before</text>
|
|
55
|
+
<rect class="fill-quiet" x="96" y="8" width="240" height="16" />
|
|
56
|
+
<text class="meta" x="344" y="20">240</text>
|
|
57
|
+
<text class="label" x="0" y="64">After</text>
|
|
58
|
+
<rect class="fill-ink" x="96" y="52" width="480" height="16" />
|
|
59
|
+
<text class="meta" x="584" y="64">480</text>
|
|
60
|
+
</svg>
|
|
61
|
+
<figcaption>The steps double the result (Source: name the data).</figcaption>
|
|
62
|
+
</figure>
|
|
63
|
+
|
|
64
|
+
<h2 id="next">Next steps</h2>
|
|
65
|
+
|
|
66
|
+
<p>Link what the reader can read or do next.</p>
|
|
67
|
+
</article>
|
|
68
|
+
</body>
|
|
69
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tempoxyz/ds",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.18",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"DESIGN.md",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"!src/**/__screenshots__/**"
|
|
17
17
|
],
|
|
18
18
|
"description": "Tempo Design System",
|
|
19
|
+
"bin": {
|
|
20
|
+
"tempo-document": "./dist/document/bin.js",
|
|
21
|
+
"tempo-document.src": "./src/document/bin.ts"
|
|
22
|
+
},
|
|
19
23
|
"dependencies": {
|
|
20
24
|
"@base-ui/react": "^1.8.0",
|
|
21
25
|
"@oxlint/plugins": "1.79.0",
|
|
@@ -31,6 +35,20 @@
|
|
|
31
35
|
"types": "./dist/web/index.d.ts",
|
|
32
36
|
"default": "./dist/web/index.js"
|
|
33
37
|
},
|
|
38
|
+
"./document": {
|
|
39
|
+
"src": "./src/document/index.ts",
|
|
40
|
+
"types": "./dist/document/index.d.ts",
|
|
41
|
+
"default": "./dist/document/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./document.css": {
|
|
44
|
+
"src": "./src/document/document.css",
|
|
45
|
+
"default": "./dist/document/document.css"
|
|
46
|
+
},
|
|
47
|
+
"./document.js": {
|
|
48
|
+
"src": "./src/document/script.ts",
|
|
49
|
+
"types": "./dist/document/script.d.ts",
|
|
50
|
+
"default": "./dist/document/script.js"
|
|
51
|
+
},
|
|
34
52
|
"./fonts/Inter-cyrillic-ext.woff2": {
|
|
35
53
|
"src": "./src/fonts/Inter-cyrillic-ext.woff2",
|
|
36
54
|
"default": "./dist/fonts/Inter-cyrillic-ext.woff2"
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document mode: the markup contract for agent-written HTML documents, and a lint that checks a
|
|
3
|
+
* document against it. Documents link `@tempoxyz/ds/document.css` and `@tempoxyz/ds/document.js`,
|
|
4
|
+
* or the same files at `dist/document/document.css` and `dist/document/script.js` on a CDN.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Classes an author may write. Anything else is outside the contract. */
|
|
9
|
+
export const classes = [
|
|
10
|
+
'brief',
|
|
11
|
+
'byline',
|
|
12
|
+
'chart',
|
|
13
|
+
'chart-key',
|
|
14
|
+
'chart-plot',
|
|
15
|
+
'chart-scroll',
|
|
16
|
+
'axis',
|
|
17
|
+
'chronology',
|
|
18
|
+
'dek',
|
|
19
|
+
'doc',
|
|
20
|
+
'facts',
|
|
21
|
+
'figures',
|
|
22
|
+
'fill-ink',
|
|
23
|
+
'fill-line',
|
|
24
|
+
'fill-quiet',
|
|
25
|
+
'input',
|
|
26
|
+
'kv',
|
|
27
|
+
'l-body',
|
|
28
|
+
'l-outset',
|
|
29
|
+
'l-page',
|
|
30
|
+
'l-screen',
|
|
31
|
+
'minor',
|
|
32
|
+
'n',
|
|
33
|
+
'note',
|
|
34
|
+
'outcome',
|
|
35
|
+
'phase',
|
|
36
|
+
'results',
|
|
37
|
+
'sn',
|
|
38
|
+
'steps',
|
|
39
|
+
'summary',
|
|
40
|
+
'swatch',
|
|
41
|
+
] as const
|
|
42
|
+
|
|
43
|
+
/** Classes allowed inside inline SVG diagrams and charts. */
|
|
44
|
+
export const svgClasses = [
|
|
45
|
+
'fill-ink',
|
|
46
|
+
'fill-line',
|
|
47
|
+
'fill-quiet',
|
|
48
|
+
'hair',
|
|
49
|
+
'ink',
|
|
50
|
+
'label',
|
|
51
|
+
'meta',
|
|
52
|
+
] as const
|
|
53
|
+
|
|
54
|
+
/** The templates an `article.doc` can name in `data-template`. */
|
|
55
|
+
export const templates = ['brief', 'essay', 'post'] as const
|
|
56
|
+
|
|
57
|
+
// Patterns that read as UI rather than a document. Matched against whole class names.
|
|
58
|
+
const banned = /^(?:badge|badges|callout|card|cards|chip|chips|pill|pills|tab|tabs|tag|tags)$/
|
|
59
|
+
|
|
60
|
+
// The built script and stylesheet, by package path or by the export names a copied file keeps.
|
|
61
|
+
const script = /(?:^|\/)(?:document\.js|document\/script\.js)(?:[?#]|$)/
|
|
62
|
+
const stylesheet = /(?:^|\/)document\.css(?:[?#]|$)/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Checks an HTML document against the document mode contract and returns its diagnostics in
|
|
66
|
+
* line order. An empty array means the document passes.
|
|
67
|
+
*
|
|
68
|
+
* The check reads tags with a small scanner rather than a full HTML parser: it skips comments, text,
|
|
69
|
+
* and the contents of `<script>` and `<style>`, and it pairs `<figure>` tags by nesting. Markup built
|
|
70
|
+
* at runtime is not seen.
|
|
71
|
+
*
|
|
72
|
+
* With `page`, the lint also checks that the tags before `<body>` link the document stylesheet and
|
|
73
|
+
* load the document script with `defer`, as one classic script.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* Document.lint('<article class="doc" data-template="post"><h4>Steps</h4></article>')
|
|
77
|
+
* // [{ line: 1, message: '<h4> is not allowed. Use h2 for sections and h3 below them.', rule: 'heading-depth' }]
|
|
78
|
+
*/
|
|
79
|
+
export function lint(html: string, options: lint.Options = {}): lint.Diagnostic[] {
|
|
80
|
+
const { page = false } = options
|
|
81
|
+
const diagnostics: lint.Diagnostic[] = []
|
|
82
|
+
const report = (index: number, rule: lint.Rule, message: string) =>
|
|
83
|
+
diagnostics.push({ line: html.slice(0, index).split('\n').length, message, rule })
|
|
84
|
+
const figures: {
|
|
85
|
+
caption: boolean
|
|
86
|
+
chart: boolean
|
|
87
|
+
index: number
|
|
88
|
+
key: boolean
|
|
89
|
+
series: number
|
|
90
|
+
}[] = []
|
|
91
|
+
const head = { index: 0, open: true, script: false, stylesheet: false }
|
|
92
|
+
let svg = 0
|
|
93
|
+
|
|
94
|
+
for (const tag of scan(html)) {
|
|
95
|
+
if (tag.name === 'body' || tag.name === 'article' || (tag.name === 'head' && tag.closing))
|
|
96
|
+
head.open = false
|
|
97
|
+
if (tag.name === 'head' && !tag.closing) head.index = tag.index
|
|
98
|
+
if (head.open && !tag.closing) {
|
|
99
|
+
const href = attribute(tag.attributes, 'href') ?? ''
|
|
100
|
+
const src = attribute(tag.attributes, 'src') ?? ''
|
|
101
|
+
if (
|
|
102
|
+
tag.name === 'link' &&
|
|
103
|
+
attribute(tag.attributes, 'rel')?.toLowerCase() === 'stylesheet' &&
|
|
104
|
+
stylesheet.test(href)
|
|
105
|
+
)
|
|
106
|
+
head.stylesheet = true
|
|
107
|
+
if (
|
|
108
|
+
tag.name === 'script' &&
|
|
109
|
+
attribute(tag.attributes, 'defer') !== undefined &&
|
|
110
|
+
attribute(tag.attributes, 'type') === undefined &&
|
|
111
|
+
script.test(src)
|
|
112
|
+
)
|
|
113
|
+
head.script = true
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (tag.name === 'svg' && !tag.selfClosing) svg += tag.closing ? -1 : 1
|
|
117
|
+
if (tag.closing) {
|
|
118
|
+
if (tag.name !== 'figure') continue
|
|
119
|
+
const figure = figures.pop()
|
|
120
|
+
if (!figure) continue
|
|
121
|
+
if (!figure.caption)
|
|
122
|
+
report(
|
|
123
|
+
figure.index,
|
|
124
|
+
'figure-caption',
|
|
125
|
+
'A <figure> needs a <figcaption> that states its takeaway.',
|
|
126
|
+
)
|
|
127
|
+
if (figure.chart && figure.series > 1 && !figure.key)
|
|
128
|
+
report(figure.index, 'chart-key', 'A chart with more than one series needs a ul.chart-key.')
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const names = (attribute(tag.attributes, 'class') ?? '').split(/\s+/).filter(Boolean)
|
|
133
|
+
const inSvg = svg > 0 || tag.name === 'svg'
|
|
134
|
+
|
|
135
|
+
if (/^h[4-6]$/.test(tag.name))
|
|
136
|
+
report(
|
|
137
|
+
tag.index,
|
|
138
|
+
'heading-depth',
|
|
139
|
+
`<${tag.name}> is not allowed. Use h2 for sections and h3 below them.`,
|
|
140
|
+
)
|
|
141
|
+
if (tag.name === 'details')
|
|
142
|
+
report(
|
|
143
|
+
tag.index,
|
|
144
|
+
'no-disclosure',
|
|
145
|
+
`<${tag.name}> is not allowed. A document shows everything it says.`,
|
|
146
|
+
)
|
|
147
|
+
const role = attribute(tag.attributes, 'role')
|
|
148
|
+
if (role === 'tab' || role === 'tablist')
|
|
149
|
+
report(tag.index, 'no-ui', `role="${role}" is not allowed. A document has no tabs.`)
|
|
150
|
+
|
|
151
|
+
for (const name of names) {
|
|
152
|
+
if (banned.test(name) || /^(?:badge|card|chip|pill|tab)-/.test(name))
|
|
153
|
+
report(tag.index, 'no-ui', `.${name} reads as UI. Write it as text, a table, or a list.`)
|
|
154
|
+
else if (!(inSvg ? svgClasses : classes).includes(name as never))
|
|
155
|
+
report(tag.index, 'unknown-class', `.${name} is not in the document mode contract.`)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (tag.name === 'article' && names.includes('doc')) {
|
|
159
|
+
const template = attribute(tag.attributes, 'data-template')
|
|
160
|
+
if (!templates.includes(template as never))
|
|
161
|
+
report(
|
|
162
|
+
tag.index,
|
|
163
|
+
'template',
|
|
164
|
+
'An article.doc needs data-template="essay", "brief", or "post".',
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (tag.name === 'figure') {
|
|
169
|
+
const chart = names.includes('chart')
|
|
170
|
+
if (chart && names.includes('l-screen'))
|
|
171
|
+
report(
|
|
172
|
+
tag.index,
|
|
173
|
+
'chart-width',
|
|
174
|
+
'A chart stays inside the page. Use l-body, l-outset, or l-page.',
|
|
175
|
+
)
|
|
176
|
+
figures.push({
|
|
177
|
+
caption: false,
|
|
178
|
+
chart,
|
|
179
|
+
index: tag.index,
|
|
180
|
+
key: false,
|
|
181
|
+
series: Number(attribute(tag.attributes, 'data-series') ?? 1),
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
const figure = figures.at(-1)
|
|
185
|
+
if (figure && tag.name === 'figcaption') figure.caption = true
|
|
186
|
+
if (figure && names.includes('chart-key')) figure.key = true
|
|
187
|
+
|
|
188
|
+
if (names.includes('chart-scroll')) {
|
|
189
|
+
const named =
|
|
190
|
+
attribute(tag.attributes, 'aria-label') ?? attribute(tag.attributes, 'aria-labelledby')
|
|
191
|
+
if (
|
|
192
|
+
attribute(tag.attributes, 'role') !== 'region' ||
|
|
193
|
+
attribute(tag.attributes, 'tabindex') !== '0' ||
|
|
194
|
+
!named
|
|
195
|
+
)
|
|
196
|
+
report(
|
|
197
|
+
tag.index,
|
|
198
|
+
'chart-scroll',
|
|
199
|
+
'.chart-scroll needs role="region", tabindex="0", and an accessible name.',
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (page && !head.stylesheet)
|
|
205
|
+
report(
|
|
206
|
+
head.index,
|
|
207
|
+
'stylesheet',
|
|
208
|
+
'The <head> needs <link rel="stylesheet"> to the document stylesheet, dist/document/document.css.',
|
|
209
|
+
)
|
|
210
|
+
if (page && !head.script)
|
|
211
|
+
report(
|
|
212
|
+
head.index,
|
|
213
|
+
'script',
|
|
214
|
+
'The <head> needs <script defer src> with the document script, dist/document/script.js, and no type.',
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
return diagnostics.sort((a, b) => a.line - b.line)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export declare namespace lint {
|
|
221
|
+
/** One problem in a document, at the line of the tag that causes it. */
|
|
222
|
+
type Diagnostic = { line: number; message: string; rule: Rule }
|
|
223
|
+
|
|
224
|
+
type Options = {
|
|
225
|
+
/**
|
|
226
|
+
* Whether the HTML is a whole page, whose head must link the document stylesheet and load the
|
|
227
|
+
* document script with `defer`. Defaults to false, which checks a fragment.
|
|
228
|
+
*/
|
|
229
|
+
page?: boolean | undefined
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The checks the lint runs. */
|
|
233
|
+
type Rule =
|
|
234
|
+
| 'chart-key'
|
|
235
|
+
| 'chart-scroll'
|
|
236
|
+
| 'chart-width'
|
|
237
|
+
| 'figure-caption'
|
|
238
|
+
| 'heading-depth'
|
|
239
|
+
| 'no-disclosure'
|
|
240
|
+
| 'no-ui'
|
|
241
|
+
| 'script'
|
|
242
|
+
| 'stylesheet'
|
|
243
|
+
| 'template'
|
|
244
|
+
| 'unknown-class'
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Returns an attribute's value, or undefined when the tag does not have it. */
|
|
248
|
+
function attribute(attributes: string, name: string): string | undefined {
|
|
249
|
+
const pattern = new RegExp(
|
|
250
|
+
`(?:^|\\s)${name}(?:\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+)))?(?=\\s|$)`,
|
|
251
|
+
'i',
|
|
252
|
+
)
|
|
253
|
+
const match = pattern.exec(attributes)
|
|
254
|
+
if (!match) return undefined
|
|
255
|
+
return match[1] ?? match[2] ?? match[3] ?? ''
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Yields each tag in source order, skipping comments. A raw text element, such as `<script>`, yields
|
|
260
|
+
* its start tag and skips its contents and end tag.
|
|
261
|
+
*/
|
|
262
|
+
function* scan(html: string) {
|
|
263
|
+
const pattern =
|
|
264
|
+
/<!--[\s\S]*?-->|<(script|style|textarea)\b((?:[^>"']|"[^"]*"|'[^']*')*)>[\s\S]*?<\/\1\s*>|<(\/?)([a-zA-Z][\w-]*)((?:[^>"']|"[^"]*"|'[^']*')*)>/g
|
|
265
|
+
|
|
266
|
+
for (const match of html.matchAll(pattern)) {
|
|
267
|
+
if (match[0].startsWith('<!--')) continue
|
|
268
|
+
const attributes = (match[1] ? match[2] : match[5])?.trim() ?? ''
|
|
269
|
+
yield {
|
|
270
|
+
attributes: attributes.replace(/\/$/, ''),
|
|
271
|
+
closing: match[3] === '/',
|
|
272
|
+
index: match.index,
|
|
273
|
+
name: (match[1] ?? match[4] ?? '').toLowerCase(),
|
|
274
|
+
selfClosing: attributes.endsWith('/'),
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|