pi-pocket 0.26.0 → 0.27.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/docs/design/design-system.md +165 -0
  3. package/docs/design/ds-notes-b.md +61 -0
  4. package/docs/design/ds-notes-g.md +170 -0
  5. package/docs/design/ds-notes-t.md +303 -0
  6. package/docs/design/ds-notes-u.md +220 -0
  7. package/docs/design/ds-notes-v.md +186 -0
  8. package/docs/design/ds-rounds.md +160 -0
  9. package/docs/design/ds-u-bridge.patch +732 -0
  10. package/docs/examples/design-system/README.md +15 -0
  11. package/docs/examples/design-system/pocket/.pi/design/components/badge.html +112 -0
  12. package/docs/examples/design-system/pocket/.pi/design/components/button.html +203 -0
  13. package/docs/examples/design-system/pocket/.pi/design/components/card.html +125 -0
  14. package/docs/examples/design-system/pocket/.pi/design/components/code-block.html +155 -0
  15. package/docs/examples/design-system/pocket/.pi/design/components/input.html +156 -0
  16. package/docs/examples/design-system/pocket/.pi/design/components/menu-row.html +167 -0
  17. package/docs/examples/design-system/pocket/.pi/design/components/notice.html +171 -0
  18. package/docs/examples/design-system/pocket/.pi/design/components/segmented.html +120 -0
  19. package/docs/examples/design-system/pocket/.pi/design/components/switch.html +117 -0
  20. package/docs/examples/design-system/pocket/.pi/design/components/tool-step.html +163 -0
  21. package/docs/examples/design-system/pocket/.pi/design/dist/components.css +730 -0
  22. package/docs/examples/design-system/pocket/.pi/design/dist/names.md +495 -0
  23. package/docs/examples/design-system/pocket/.pi/design/dist/tailwind.css +1132 -0
  24. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.css +1126 -0
  25. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.dark.resolved.json +2022 -0
  26. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.high-contrast.resolved.json +2022 -0
  27. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.light.resolved.json +2022 -0
  28. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.resolved.json +371 -0
  29. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.studio.json +5915 -0
  30. package/docs/examples/design-system/pocket/.pi/design/guidelines.md +81 -0
  31. package/docs/examples/design-system/pocket/.pi/design/tokens.dark.json +182 -0
  32. package/docs/examples/design-system/pocket/.pi/design/tokens.high-contrast.json +185 -0
  33. package/docs/examples/design-system/pocket/.pi/design/tokens.json +2034 -0
  34. package/docs/features.md +6 -2
  35. package/docs/index.md +1 -0
  36. package/docs/map.md +34 -25
  37. package/docs/release-notes.md +1 -1
  38. package/docs/releases.md +45 -0
  39. package/package.json +2 -1
  40. package/src/server/design/check-cli.ts +283 -0
  41. package/src/server/design/color.ts +654 -0
  42. package/src/server/design/components.ts +328 -0
  43. package/src/server/design/docsite-assets.ts +29 -0
  44. package/src/server/design/docsite-color-section.ts +366 -0
  45. package/src/server/design/docsite-color.ts +303 -0
  46. package/src/server/design/docsite-components.ts +89 -0
  47. package/src/server/design/docsite-core.ts +634 -0
  48. package/src/server/design/docsite-css-base.ts +397 -0
  49. package/src/server/design/docsite-css-content.ts +477 -0
  50. package/src/server/design/docsite-css-phone.ts +251 -0
  51. package/src/server/design/docsite-css-reference.ts +374 -0
  52. package/src/server/design/docsite-css-specimens.ts +465 -0
  53. package/src/server/design/docsite-js-code.ts +96 -0
  54. package/src/server/design/docsite-js-core.ts +72 -0
  55. package/src/server/design/docsite-js-demos.ts +24 -0
  56. package/src/server/design/docsite-js-links.ts +25 -0
  57. package/src/server/design/docsite-js-nav.ts +73 -0
  58. package/src/server/design/docsite-js-stages.ts +81 -0
  59. package/src/server/design/docsite-js-table.ts +81 -0
  60. package/src/server/design/docsite-markdown.ts +221 -0
  61. package/src/server/design/docsite-motion.ts +110 -0
  62. package/src/server/design/docsite-reference.ts +269 -0
  63. package/src/server/design/docsite-sanitize.ts +193 -0
  64. package/src/server/design/docsite-shadows.ts +45 -0
  65. package/src/server/design/docsite-space.ts +289 -0
  66. package/src/server/design/docsite-type.ts +167 -0
  67. package/src/server/design/docsite.ts +508 -0
  68. package/src/server/design/export.ts +86 -9
  69. package/src/server/design/fix.ts +666 -0
  70. package/src/server/design/guide.ts +137 -22
  71. package/src/server/design/index.ts +368 -15
  72. package/src/server/design/lint-color.ts +293 -0
  73. package/src/server/design/lint-page-checks.ts +204 -0
  74. package/src/server/design/lint-page-elements.ts +252 -0
  75. package/src/server/design/lint-page-focus.ts +165 -0
  76. package/src/server/design/lint-page-literals.ts +293 -0
  77. package/src/server/design/lint-page-setup.ts +102 -0
  78. package/src/server/design/lint-page-states.ts +121 -0
  79. package/src/server/design/lint-page-values.ts +329 -0
  80. package/src/server/design/lint-page.ts +101 -0
  81. package/src/server/design/lint-suggest.ts +340 -0
  82. package/src/server/design/lint.ts +1136 -0
  83. package/src/server/design/render.ts +369 -18
  84. package/src/server/design/scan-braces.ts +115 -0
  85. package/src/server/design/scan-categorize.ts +187 -0
  86. package/src/server/design/scan-channels.ts +113 -0
  87. package/src/server/design/scan-color-base.ts +209 -0
  88. package/src/server/design/scan-color-names.ts +403 -0
  89. package/src/server/design/scan-color-palette.ts +91 -0
  90. package/src/server/design/scan-color-roles.ts +565 -0
  91. package/src/server/design/scan-colors.ts +22 -0
  92. package/src/server/design/scan-facts-antd.ts +171 -0
  93. package/src/server/design/scan-facts-files.ts +300 -0
  94. package/src/server/design/scan-facts-lists.ts +538 -0
  95. package/src/server/design/scan-facts-sass.ts +113 -0
  96. package/src/server/design/scan-facts-theme.ts +400 -0
  97. package/src/server/design/scan-facts-use.ts +674 -0
  98. package/src/server/design/scan-facts-wordpress.ts +374 -0
  99. package/src/server/design/scan-facts.ts +285 -0
  100. package/src/server/design/scan-files.ts +384 -0
  101. package/src/server/design/scan-import-convert.ts +277 -0
  102. package/src/server/design/scan-import-eval.ts +583 -0
  103. package/src/server/design/scan-import-material.ts +745 -0
  104. package/src/server/design/scan-import-sd-config.ts +370 -0
  105. package/src/server/design/scan-import-sd.ts +381 -0
  106. package/src/server/design/scan-import-studio.ts +242 -0
  107. package/src/server/design/scan-import.ts +336 -0
  108. package/src/server/design/scan-infer.ts +313 -0
  109. package/src/server/design/scan-js-eval.ts +1267 -0
  110. package/src/server/design/scan-palette.ts +485 -0
  111. package/src/server/design/scan-parse.ts +1134 -0
  112. package/src/server/design/scan-prepare.ts +402 -0
  113. package/src/server/design/scan-render-pages.ts +367 -0
  114. package/src/server/design/scan-render-probe.ts +229 -0
  115. package/src/server/design/scan-render.ts +524 -0
  116. package/src/server/design/scan-review.ts +54 -0
  117. package/src/server/design/scan-roles.ts +259 -0
  118. package/src/server/design/scan-sass-colors.ts +275 -0
  119. package/src/server/design/scan-sass-eval.ts +269 -0
  120. package/src/server/design/scan-sass-expr.ts +911 -0
  121. package/src/server/design/scan-sass-modules.ts +353 -0
  122. package/src/server/design/scan-sass-run.ts +1003 -0
  123. package/src/server/design/scan-sass-stmt.ts +256 -0
  124. package/src/server/design/scan-sass-values.ts +886 -0
  125. package/src/server/design/scan-scales.ts +983 -0
  126. package/src/server/design/scan-tailwind.ts +34 -0
  127. package/src/server/design/scan-theme-shapes.ts +579 -0
  128. package/src/server/design/scan-tree.ts +290 -0
  129. package/src/server/design/scan-util.ts +44 -0
  130. package/src/server/design/scan-variables.ts +470 -0
  131. package/src/server/design/scan.ts +703 -0
  132. package/src/server/design/system-schema.ts +68 -0
  133. package/src/server/design/system-types.ts +279 -0
  134. package/src/server/design/system.ts +510 -82
  135. package/src/server/design/tokens-base.ts +123 -0
  136. package/src/server/design/tokens-compile.ts +440 -0
  137. package/src/server/design/tokens-dtcg.ts +354 -0
  138. package/src/server/design/tokens-io.ts +417 -0
  139. package/src/server/design/tokens-model.ts +1163 -0
  140. package/src/server/design/tokens-names.ts +112 -0
  141. package/src/server/design/tokens-ramps.ts +112 -0
  142. package/src/server/design/tokens-summary.ts +317 -0
  143. package/src/server/design/tokens-tailwind.ts +324 -0
  144. package/src/server/design/tokens-values.ts +921 -0
  145. package/src/server/design/tokens.ts +533 -0
  146. package/src/server/docs.ts +8 -0
  147. package/src/server/extensions/artifacts.ts +87 -2
  148. package/src/server/extensions/design/app.js +280 -0
  149. package/src/server/extensions/design/canvas.js +142 -17
  150. package/src/server/extensions/design/check.js +656 -0
  151. package/src/server/extensions/design/color.js +383 -0
  152. package/src/server/extensions/design/data.js +102 -7
  153. package/src/server/extensions/design/devices.js +26 -0
  154. package/src/server/extensions/design/docks.js +117 -3
  155. package/src/server/extensions/design/index.js +171 -219
  156. package/src/server/extensions/design/messages.js +49 -0
  157. package/src/server/extensions/design/parts.js +15 -1
  158. package/src/server/extensions/design/paths.js +4 -0
  159. package/src/server/extensions/design/picker.js +123 -0
  160. package/src/server/extensions/design/specimen.js +55 -0
  161. package/src/server/extensions/design/state.js +72 -7
  162. package/src/server/extensions/design/style.css +546 -0
  163. package/src/server/extensions/design/system-actions.js +214 -0
  164. package/src/server/extensions/design/system-api.ts +62 -0
  165. package/src/server/extensions/design/system-data.js +315 -0
  166. package/src/server/extensions/design/system-preview.js +41 -0
  167. package/src/server/extensions/design/system-routes.ts +1122 -0
  168. package/src/server/extensions/design/system-sections.js +1344 -0
  169. package/src/server/extensions/design/system-ui.js +32 -0
  170. package/src/server/extensions/design/system-view.js +1196 -0
  171. package/src/server/extensions/design/system-widgets.js +942 -0
  172. package/src/server/extensions/design/system.css +2313 -0
  173. package/src/server/extensions/design/system.js +1479 -0
  174. package/src/server/extensions/design/unsaved.js +20 -0
  175. package/src/server/extensions/design/views.js +2 -2
  176. package/src/server/extensions/design/workspace.js +200 -105
  177. package/src/server/extensions/design.ts +89 -6
  178. package/src/server/extensions/updates/index.js +31 -9
  179. package/src/server/extensions/updates/style.css +11 -0
  180. package/src/server/extensions/updates.ts +29 -1
  181. package/src/server/host.ts +4 -1
  182. package/src/server/http/artifact-inspect.ts +338 -24
  183. package/src/server/updates.ts +235 -53
  184. package/src/server/versions.ts +71 -0
  185. package/web/artifact-bridge.js +34 -1
  186. package/npm-shrinkwrap.json +0 -3162
@@ -0,0 +1,269 @@
1
+ /**
2
+ * The reference parts of the documentation page: the table of every token, the validator notes, and the code to use it. (Split from `docsite.ts`; see it for how the page is built and kept safe.)
3
+ */
4
+ import { escapeHtml as esc, plural } from "./docsite-markdown.ts";
5
+ import type { ResolvedToken } from "./system-types.ts";
6
+ import {
7
+ clip,
8
+ modeLabel,
9
+ pxOf,
10
+ sectionOf,
11
+ type Ctx,
12
+ valueIn,
13
+ findToken,
14
+ varOf,
15
+ BASE_GROUNDS,
16
+ tableRows,
17
+ } from "./docsite-core.ts";
18
+
19
+ /**
20
+ * The table of every token: a column for each mode, and above it a search of names and values and a filter by type and
21
+ * by tier. (The page's script filters the rows, and on a phone draws them a screenful at a time.)
22
+ */
23
+ export function referenceSection(ctx: Ctx, max: number): { html: string; count: number } {
24
+ const all = ctx.system.tokens;
25
+ const tokens = all.slice(0, max);
26
+ const cut =
27
+ tokens.length < all.length
28
+ ? `<p class="sub">This table shows the first ${tokens.length} of ${all.length} tokens, to keep the page small. The sections above show the rest.</p>`
29
+ : "";
30
+ const types = [...new Set(tokens.map((token) => token.type))].sort();
31
+ const tiers = ["primitive", "semantic", "component"].filter((tier) =>
32
+ tokens.some((token) => token.tier === tier),
33
+ );
34
+ const option = (value: string, label: string) =>
35
+ `<option value="${esc(value)}">${esc(label)}</option>`;
36
+ const toolbar = `<div class="toolbar" role="search"><input id="tq" type="search" placeholder="Search names and values" aria-label="Search the table of tokens" autocomplete="off" spellcheck="false"><select id="tt" aria-label="Filter by type">${option("", "All types")}${types.map((type) => option(type, `${type} (${tokens.filter((token) => token.type === type).length})`)).join("")}</select><select id="tr" aria-label="Filter by tier">${option("", "All tiers")}${tiers.map((tier) => option(tier, tier)).join("")}</select><span class="rows-count" id="tc" aria-live="polite"></span></div>`;
37
+
38
+ return {
39
+ html: `<p class="intro">Every token with its CSS variable and its value in each mode. Click a name to copy it.</p>${cut}${toolbar}<div class="table-wrap ref"><table><thead><tr><th>Token</th><th>Type</th>${ctx.modes.map((mode) => `<th>${esc(modeLabel(mode))}</th>`).join("")}</tr></thead><tbody>${tableRows(ctx, tokens, true)}</tbody></table></div>`,
40
+ count: all.length,
41
+ };
42
+ }
43
+
44
+ export function problemsHtml(ctx: Ctx): string {
45
+ const problems = ctx.system.problems;
46
+
47
+ if (problems.length === 0) {
48
+ return "";
49
+ }
50
+
51
+ const errors = problems.filter((problem) => problem.level === "error").length;
52
+
53
+ return `<details class="notes"><summary>${errors > 0 ? `${errors} error${errors === 1 ? "" : "s"} and ` : ""}${problems.length - errors} warning${problems.length - errors === 1 ? "" : "s"} from the validator</summary><ul>${problems
54
+ .slice(0, 50)
55
+ .map(
56
+ (problem) =>
57
+ `<li><strong>${problem.level === "error" ? "Error" : "Warning"}</strong>${problem.file === undefined ? "" : ` in <code>${esc(problem.file)}</code>`}${problem.token === undefined ? "" : ` at <code>${esc(problem.token)}</code>`}: ${esc(clip(problem.message, 300))}</li>`,
58
+ )
59
+ .join("")}</ul></details>`;
60
+ }
61
+
62
+ /** Notes that need no action (an exempt contrast pair, for one): a small area of their own, apart from problems. */
63
+ export function notesHtml(ctx: Ctx): string {
64
+ const notes = ctx.system.notes ?? [];
65
+
66
+ if (notes.length === 0) {
67
+ return "";
68
+ }
69
+
70
+ return `<details class="notes"><summary>${plural(notes.length, "note")} from the validator</summary><ul>${notes
71
+ .slice(0, 50)
72
+ .map(
73
+ (note) =>
74
+ `<li>${note.file === undefined ? "" : `<code>${esc(note.file)}</code> `}${note.token === undefined ? "" : `<code>${esc(note.token)}</code>: `}${esc(clip(note.message, 300))}</li>`,
75
+ )
76
+ .join("")}</ul></details>`;
77
+ }
78
+
79
+ /** The most of a generated file that the page prints: the files are large, and the page is one file too. */
80
+ const FILE_PREVIEW = 3_000;
81
+
82
+ /**
83
+ * A short, real piece of `tokens.studio.json`: the first mode's set with one token, the first theme, and the order of
84
+ * the sets, cut from the generated file, so that what is shown is what the file holds.
85
+ */
86
+ function studioSnippet(ctx: Ctx, sample: ResolvedToken | undefined): string {
87
+ let file: Record<string, unknown> | undefined;
88
+
89
+ try {
90
+ file = JSON.parse(ctx.system.compiled.studio ?? "") as Record<string, unknown>;
91
+ } catch {
92
+ file = undefined;
93
+ }
94
+
95
+ const first = ctx.modes[0]!;
96
+ const set = file?.[first] as Record<string, unknown> | undefined;
97
+ const themes = file?.$themes as { selectedTokenSets?: Record<string, string> }[] | undefined;
98
+
99
+ if (file === undefined || set === undefined || sample === undefined) {
100
+ return JSON.stringify(
101
+ { [first]: {}, $themes: [], $metadata: { tokenSetOrder: ctx.modes } },
102
+ null,
103
+ 2,
104
+ );
105
+ }
106
+
107
+ // One token of the set, by its path (color.bg.surface), as the file has it.
108
+ let node: unknown = set;
109
+ const leaf: Record<string, unknown> = {};
110
+ let into = leaf;
111
+
112
+ for (const [index, key] of sample.path.entries()) {
113
+ node = (node as Record<string, unknown> | undefined)?.[key];
114
+ into[key] = index === sample.path.length - 1 ? node : {};
115
+ into = into[key] as Record<string, unknown>;
116
+ }
117
+
118
+ const theme = themes?.[0];
119
+ const sets = Object.fromEntries(Object.entries(theme?.selectedTokenSets ?? {}).slice(0, 2));
120
+
121
+ return JSON.stringify(
122
+ {
123
+ [first]: leaf,
124
+ $themes: [{ ...(theme ?? {}), selectedTokenSets: sets }],
125
+ $metadata: file.$metadata,
126
+ },
127
+ null,
128
+ 2,
129
+ );
130
+ }
131
+
132
+ /** A snippet in a box with a Copy button; the text is project data, so it is escaped. */
133
+ export function snippet(id: string, text: string, lang = ""): string {
134
+ return `<div class="snip-wrap"><button class="copy" type="button" data-copy-from="${esc(id)}" data-copy="">Copy</button><pre class="snip" id="${esc(id)}"${lang === "" ? "" : ` data-lang="${esc(lang)}"`}><code>${esc(text)}</code></pre></div>`;
135
+ }
136
+
137
+ /** What the generated files are and how to use each: CSS, Tailwind v4, and JSON for Style Dictionary or Tokens Studio. */
138
+ export function codeSection(ctx: Ctx): { html: string; count: number } {
139
+ const { compiled } = ctx.system;
140
+ const first = ctx.modes[0]!;
141
+ const sample =
142
+ findToken(ctx, BASE_GROUNDS) ??
143
+ ctx.system.tokens.find((token) => token.type === "color" && token.tier === "semantic") ??
144
+ ctx.system.tokens[0];
145
+ // A middle step of the spacing scale reads better than step zero.
146
+ const steps = ctx.system.tokens.filter(
147
+ (token) =>
148
+ sectionOf(token) === "spacing" &&
149
+ token.tier !== "component" &&
150
+ (pxOf(valueIn(token, first)?.value) ?? 0) > 0,
151
+ );
152
+ const spacing =
153
+ steps.find((token) => pxOf(valueIn(token, first)?.value) === 16) ??
154
+ steps[Math.floor(steps.length / 2)];
155
+ const dark = ctx.modes.find((mode) => ctx.theme.get(mode) === "dark" && mode !== first);
156
+ const cssVar = sample?.cssVar ?? "--color-bg-surface";
157
+ const css = `<link rel="stylesheet" href="tokens.css">\n\n.card {\n background: var(${cssVar});\n padding: var(${spacing?.cssVar ?? "--space-4"});\n}${dark === undefined ? "" : `\n\n<!-- ${modeLabel(dark)} mode -->\n<html data-theme="${dark}">`}`;
158
+ // The utilities come from the variables that the compiled theme gives the sample tokens (`tailwindNames`): no utility
159
+ // name is written here. A system with no color or no spacing token shows no class for it.
160
+ const sampleVar = sample === undefined ? undefined : ctx.twVar.get(sample.name);
161
+ const spacingVar = spacing === undefined ? undefined : ctx.twVar.get(spacing.name);
162
+ const classes = [
163
+ sampleVar?.startsWith("--color-") ? `bg-${sampleVar.slice("--color-".length)}` : undefined,
164
+ spacingVar?.startsWith("--spacing-")
165
+ ? `p-${spacingVar.slice("--spacing-".length)}`
166
+ : undefined,
167
+ ].filter((name) => name !== undefined);
168
+ const tailwind = `@import "tailwindcss";\n@import "./tailwind.css";${classes.length === 0 ? "" : `\n\n<div class="${classes.join(" ")}">…</div>`}`;
169
+ const modeFiles = Object.entries(compiled.modes ?? {});
170
+ const jsonName =
171
+ modeFiles[0] === undefined
172
+ ? "tokens.resolved.json"
173
+ : `tokens.${modeFiles[0][0]}.resolved.json`;
174
+ // Style Dictionary reads the DTCG files as they are. The config is plain JSON: what it means is written beside it.
175
+ const json = JSON.stringify(
176
+ {
177
+ source: [jsonName],
178
+ platforms: {
179
+ css: {
180
+ transformGroup: "css",
181
+ buildPath: "build/",
182
+ files: [{ destination: "variables.css", format: "css/variables" }],
183
+ },
184
+ },
185
+ },
186
+ null,
187
+ 2,
188
+ );
189
+ // Tokens Studio: the first entry of the generated file, so that what a person sees is what the file holds.
190
+ const studio = studioSnippet(ctx, sample);
191
+ // `dist/README.md` is written by the compiler (stream T); the page lists it when the system has it.
192
+ const readme = (compiled as { readme?: string }).readme ?? "";
193
+ const files = [
194
+ {
195
+ id: "code-readme",
196
+ title: "README.md",
197
+ note: "What each file is, and how to use it with CSS, Tailwind v4, Style Dictionary, and Tokens Studio.",
198
+ text: readme,
199
+ },
200
+ {
201
+ id: "code-css",
202
+ title: "tokens.css",
203
+ note: "Variables for every mode. Link it from every page.",
204
+ text: compiled.css,
205
+ },
206
+ {
207
+ id: "code-tailwind",
208
+ title: "tailwind.css",
209
+ note: "A Tailwind v4 @theme block, one variable for each token.",
210
+ text: compiled.tailwind,
211
+ },
212
+ {
213
+ id: "code-names",
214
+ title: "names.md",
215
+ note: "Every token with its variable in tokens.css and in tailwind.css, and its Tailwind utilities.",
216
+ text: compiled.names ?? "",
217
+ },
218
+ ...modeFiles.map(([mode, text], index) => ({
219
+ id: `code-mode-${index}`,
220
+ title: `tokens.${mode}.resolved.json`,
221
+ note: `The ${modeLabel(mode).toLowerCase()} mode as a DTCG file (with $value and $type).`,
222
+ text,
223
+ })),
224
+ {
225
+ id: "code-mode-studio",
226
+ title: "tokens.studio.json",
227
+ note: "For Tokens Studio: a token set for each mode, and a $themes array.",
228
+ text: compiled.studio ?? "",
229
+ },
230
+ {
231
+ id: "code-json",
232
+ title: "tokens.resolved.json",
233
+ note: "A compact summary for scripts. Prefer the DTCG files above.",
234
+ text: compiled.json,
235
+ },
236
+ ].filter((file) => file.text.trim() !== "");
237
+ const use = (title: string, note: string, id: string, text: string, lang: string) =>
238
+ `<div class="use"><h4>${esc(title)}</h4><p class="sub">${note}</p>${snippet(id, text, lang)}</div>`;
239
+
240
+ // The colors of the code come from the system's own code tokens, so that they follow the mode and sit on the ground
241
+ // that the system made for code. Each is left out when the system has no such token (the CSS has a fallback).
242
+ const syntax = (
243
+ [
244
+ ["bg", ["color.code.bg"]],
245
+ ["text", ["color.code.text"]],
246
+ ["c", ["color.code.comment", "color.text.muted"]],
247
+ ["s", ["color.code.string"]],
248
+ ["n", ["color.code.number"]],
249
+ ["k", ["color.code.keyword"]],
250
+ ["f", ["color.code.function"]],
251
+ ["p", ["color.code.type", "color.code.property"]],
252
+ ["t", ["color.code.tag"]],
253
+ ] as [string, string[]][]
254
+ )
255
+ .map(([key, names]) => [key, findToken(ctx, names)] as const)
256
+ .filter(([, token]) => token !== undefined && token.type === "color")
257
+ .map(([key, token]) => `--sx-${key}:${varOf(token!)}`)
258
+ .join(";");
259
+
260
+ return {
261
+ html: `<div class="sx"${syntax === "" ? "" : ` style="${esc(syntax)}"`}><p class="intro">The files that the system generates in <code>.pi/design/dist/</code> (<code>components.css</code> holds the CSS of every component, which each component above shows). Read tokens as variables, classes, or JSON. Never copy a value by hand.</p><div class="uses">${use("CSS", "Link tokens.css, then read a token with var(). Set data-theme for a mode.", "code-use-css", css, "web")}${use("Tailwind v4", `Import Tailwind, then tailwind.css. Each token is a variable, so the utilities follow it.${compiled.names === undefined || compiled.names.trim() === "" ? "" : ' <a href="#code-names">names.md</a> lists every name and utility.'}`, "code-use-tailwind", tailwind, "web")}${use("JSON (DTCG)", `Style Dictionary reads the file for each mode as it is. For DTCG 2025.10 objects and not strings (<code>"#7aa2f7"</code>, <code>"16px"</code>), set <code>"format": "2025.10"</code> in the <code>com.pi-pocket</code> extension of tokens.json.`, "code-use-json", json, "json")}${use("Tokens Studio", "In Tokens Studio open Tools, Load from file or URL, and pick tokens.studio.json. Each mode is a token set, and each theme turns its set on.", "code-use-studio", studio, "json")}</div><h3>The files</h3>${files
262
+ .map(
263
+ (file) =>
264
+ `<details class="code"><summary>${esc(file.title)}<span class="desc" style="margin-left:10px;font-weight:400">${esc(file.note)}</span></summary><div class="code-body">${file.text.length > FILE_PREVIEW ? `<p class="sub">The first ${FILE_PREVIEW / 1000} KB of ${Math.round(file.text.length / 1024)} KB. The whole file is in <code>.pi/design/dist/</code>, and in the zip that the System view exports.</p>` : ""}${snippet(file.id, clip(file.text, FILE_PREVIEW), file.title.endsWith(".css") ? "css" : file.title.endsWith(".json") ? "json" : "")}</div></details>`,
265
+ )
266
+ .join("")}</div>`,
267
+ count: files.length,
268
+ };
269
+ }
@@ -0,0 +1,193 @@
1
+ /**
2
+ * The allowlist that the documentation page applies to a component's markup and CSS before it shows them (see
3
+ * `docsite-components.ts`). The markup is project text. The page parses it in an inert document and then builds a new
4
+ * tree from it: an element and an attribute that are not on a list below are not copied, so nothing that the lists do not
5
+ * name can reach the page, and no new element or attribute of a browser (SMIL, `foreignObject`, `math`, …) is let in by
6
+ * being missing from a denylist. The lists are data here and text in the page's script (`SANITIZER_JS`), and a test runs
7
+ * probes through the real thing in Chromium.
8
+ */
9
+
10
+ /** HTML elements that a specimen may use. Others are unwrapped (their children stay), or dropped whole (below). */
11
+ export const HTML_ELEMENTS =
12
+ "a abbr address article aside b bdi bdo blockquote br button caption cite code col colgroup dd del details dfn div dl dt em fieldset figcaption figure footer h1 h2 h3 h4 h5 h6 header hgroup hr i img input ins kbd label legend li main mark meter nav ol optgroup option output p pre progress q rp rt ruby s samp section select small span strong style sub summary sup table tbody td textarea tfoot th thead time tr u ul var wbr".split(
13
+ " ",
14
+ );
15
+
16
+ /** SVG elements: shapes, text, gradients, and the small set of filters. No animation, no `foreignObject`, no script, no image. */
17
+ export const SVG_ELEMENTS =
18
+ "svg g path circle ellipse rect line polyline polygon text tspan defs lineargradient radialgradient stop clippath mask pattern symbol title desc use marker a style filter fegaussianblur feoffset fecolormatrix femerge femergenode feflood fecomposite feblend fedropshadow".split(
19
+ " ",
20
+ );
21
+
22
+ /** Elements that are dropped with everything inside them (an unlisted element is only unwrapped). */
23
+ export const DROPPED_ELEMENTS =
24
+ "script iframe frame frameset object embed template noscript math foreignobject animate set animatetransform animatemotion mpath discard portal applet link meta base head".split(
25
+ " ",
26
+ );
27
+
28
+ /** Attributes of any element, besides `aria-*` and `data-*`. `style` is cleaned, and an address is checked, below. */
29
+ export const GLOBAL_ATTRIBUTES = "class id role title lang dir tabindex hidden style".split(" ");
30
+
31
+ /** Attributes of HTML elements. `href` (links) and `src` (images) are checked as addresses. */
32
+ export const HTML_ATTRIBUTES =
33
+ "type value placeholder disabled checked selected readonly required for alt width height colspan rowspan min max step rows cols open label multiple maxlength size scope headers datetime name href src abbr cite span start reversed".split(
34
+ " ",
35
+ );
36
+
37
+ /** Attributes of SVG elements. None names an animation target or value (`attributeName`, `to`, `from`, `by`). */
38
+ export const SVG_ATTRIBUTES =
39
+ "viewbox preserveaspectratio xmlns d fill fill-opacity fill-rule clip-rule stroke stroke-width stroke-linecap stroke-linejoin stroke-dasharray stroke-dashoffset stroke-opacity stroke-miterlimit opacity transform cx cy r rx ry x y x1 y1 x2 y2 points width height offset stop-color stop-opacity gradientunits gradienttransform patternunits patterntransform clippathunits maskunits clip-path mask filter text-anchor dominant-baseline font-size font-family font-weight letter-spacing dx dy rotate textlength marker-start marker-mid marker-end markerwidth markerheight refx refy orient fx fy pathlength vector-effect shape-rendering color display visibility overflow in in2 result stddeviation mode type values flood-color flood-opacity href xlink:href".split(
40
+ " ",
41
+ );
42
+
43
+ /** Presentation attributes whose value may name another element of the picture, as `url(#id)` and nothing else. */
44
+ export const URL_ATTRIBUTES =
45
+ "fill stroke clip-path mask filter marker-start marker-mid marker-end".split(" ");
46
+
47
+ /**
48
+ * The script that cleans markup and CSS: `window.__dsClean(parsedDocument, targetElement)` copies what the lists allow;
49
+ * `window.__dsCss(text)` removes `@import` and every `url()` but `#id` and a small image. ES5, run by the page.
50
+ */
51
+ export const SANITIZER_JS = `
52
+ var HTML_NS = "http://www.w3.org/1999/xhtml";
53
+ var SVG_NS = "http://www.w3.org/2000/svg";
54
+ function setOf(list) { var set = {}; list.forEach(function (name) { set[name] = true; }); return set; }
55
+ var OK_HTML = setOf(${JSON.stringify(HTML_ELEMENTS)});
56
+ var OK_SVG = setOf(${JSON.stringify(SVG_ELEMENTS)});
57
+ var DROPPED = setOf(${JSON.stringify(DROPPED_ELEMENTS)});
58
+ var OK_GLOBAL = setOf(${JSON.stringify(GLOBAL_ATTRIBUTES)});
59
+ var OK_HTML_ATTR = setOf(${JSON.stringify(HTML_ATTRIBUTES)});
60
+ var OK_SVG_ATTR = setOf(${JSON.stringify(SVG_ATTRIBUTES)});
61
+ var URL_ATTR = setOf(${JSON.stringify(URL_ATTRIBUTES)});
62
+ var MAX_NODES = 4000;
63
+ var MAX_DEPTH = 40;
64
+
65
+ // CSS. A regex that looks for bad words misses an escape (\\69mport, u\\72l) and a function that takes an address
66
+ // (image-set, image, cross-fade, element, src), so this reads the CSS as rules and declarations and keeps only what is
67
+ // safe: a declaration is checked after its escapes are decoded, and it goes whole when it holds a function that fetches
68
+ // or an address that is not "#id" or a small image in the text itself. Only @media, @supports, @keyframes, and
69
+ // @container rules stay; every other at-rule (@import, @font-face, @namespace, @property, @page, ...) goes.
70
+ function decodeCss(text) {
71
+ return text.replace(/\\\\([0-9a-fA-F]{1,6})[ \\t\\n\\r\\f]?|\\\\([^\\n])/g, function (all, hex, character) {
72
+ if (hex) { var code = parseInt(hex, 16); return code > 0 && code < 0x110000 ? String.fromCodePoint(code) : "\\ufffd"; }
73
+ return character;
74
+ });
75
+ }
76
+ function badCss(text) {
77
+ var decoded = decodeCss(text);
78
+ if (/image-set|image\\s*\\(|cross-fade|element\\s*\\(|(^|[^\\w-])src\\s*\\(|paint\\s*\\(|expression\\s*\\(|behavior\\s*:|-moz-binding|@import|javascript:|vbscript:/i.test(decoded)) { return true; }
79
+ var addresses = decoded.match(/url\\s*\\(/gi);
80
+ if (addresses) {
81
+ var allowed = decoded.match(/url\\(\\s*(["']?)(#[\\w:.-]+|data:image\\/(png|gif|jpeg|webp)[;,][^)"']*)\\1\\s*\\)/gi);
82
+ if (!allowed || allowed.length !== addresses.length) { return true; }
83
+ }
84
+ return false;
85
+ }
86
+ function skipQuoted(text, at) {
87
+ var quote = text.charAt(at);
88
+ at++;
89
+ while (at < text.length && text.charAt(at) !== quote) { at += text.charAt(at) === "\\\\" ? 2 : 1; }
90
+ return at;
91
+ }
92
+ // A block's items, each up to a ";" or a "{" (outside strings and parentheses). \`inRule\` says that a bare item is a
93
+ // declaration (inside a style rule, or a keyframe); at the top a bare item is an at-rule statement, and goes.
94
+ function cleanBlock(text, inRule, depth) {
95
+ var out = "";
96
+ var i = 0;
97
+ var n = text.length;
98
+ if (depth > 8) { return ""; }
99
+ while (i < n) {
100
+ var start = i;
101
+ var paren = 0;
102
+ while (i < n) {
103
+ var c = text.charAt(i);
104
+ if (c === '"' || c === "'") { i = skipQuoted(text, i); }
105
+ else if (c === "\\\\") { i++; }
106
+ else if (c === "(") { paren++; }
107
+ else if (c === ")") { if (paren > 0) { paren--; } }
108
+ else if (paren === 0 && (c === ";" || c === "{" || c === "}")) { break; }
109
+ i++;
110
+ }
111
+ var head = text.slice(start, i).trim();
112
+ var end = text.charAt(i);
113
+ if (end === "{") {
114
+ var level = 1;
115
+ var j = i + 1;
116
+ while (j < n && level > 0) {
117
+ var d = text.charAt(j);
118
+ if (d === '"' || d === "'") { j = skipQuoted(text, j); }
119
+ else if (d === "\\\\") { j++; }
120
+ else if (d === "{") { level++; }
121
+ else if (d === "}") { level--; }
122
+ j++;
123
+ }
124
+ var inner = text.slice(i + 1, level === 0 ? j - 1 : j);
125
+ i = j;
126
+ if (!head || badCss(head)) { continue; }
127
+ if (head.charAt(0) === "@") {
128
+ var name = (/^@([\\w-]+)/.exec(decodeCss(head)) || [])[1];
129
+ name = name ? name.toLowerCase() : "";
130
+ if (/^(-webkit-)?keyframes$/.test(name) || name === "media" || name === "supports" || name === "container") {
131
+ out += head + "{" + cleanBlock(inner, false, depth + 1) + "}";
132
+ }
133
+ } else {
134
+ out += head + "{" + cleanBlock(inner, true, depth + 1) + "}";
135
+ }
136
+ } else {
137
+ if (end) { i++; }
138
+ if (inRule && head && head.indexOf(":") !== -1 && !badCss(head)) { out += head + ";"; }
139
+ }
140
+ }
141
+ return out;
142
+ }
143
+ function cleanCss(text) { return cleanBlock(String(text).replace(/\\/\\*[\\s\\S]*?(\\*\\/|$)/g, ""), false, 0); }
144
+ function cleanDeclarations(text) { return cleanBlock(String(text).replace(/\\/\\*[\\s\\S]*?(\\*\\/|$)/g, ""), true, 0); }
145
+
146
+ // Whether an attribute (already on its element's list) may keep its value.
147
+ function okValue(name, value, tag) {
148
+ var flat = value.replace(/[\\u0000-\\u0020\\u007f-\\u009f]+/g, "").toLowerCase();
149
+ if (/(javascript|vbscript|livescript):|data:(text|application)|<\\s*script/.test(flat)) { return false; }
150
+ if (name === "href" || name === "xlink:href") { return (tag === "a" || tag === "use") && /^#[\\w:.-]*$/.test(value.trim()); }
151
+ if (name === "src") { return tag === "img" && /^data:image\\/(png|gif|jpeg|webp);base64,[a-z0-9+\\/=]*$/i.test(value.trim()); }
152
+ if (URL_ATTR[name] && /url\\s*\\(/i.test(value)) { return /^\\s*url\\(\\s*#[\\w:.-]+\\s*\\)\\s*$/.test(value); }
153
+ if (name === "values") { return tag === "fecolormatrix"; }
154
+ return true;
155
+ }
156
+
157
+ function copyAttributes(from, to, svg, tag) {
158
+ Array.prototype.slice.call(from.attributes).forEach(function (attribute) {
159
+ var name = attribute.name.toLowerCase();
160
+ var listed = OK_GLOBAL[name] || (svg ? OK_SVG_ATTR[name] : OK_HTML_ATTR[name]) || /^(aria|data)-[a-z0-9._-]+$/.test(name);
161
+ if (!listed) { return; }
162
+ var value = attribute.value;
163
+ if (name === "style") { value = cleanDeclarations(value); }
164
+ else if (!okValue(name, value, tag)) { return; }
165
+ try { to.setAttributeNS(attribute.namespaceURI, attribute.name, value); } catch (error) { /* a name that cannot be set is left out */ }
166
+ });
167
+ }
168
+
169
+ function copyChildren(from, to, state, depth) {
170
+ Array.prototype.slice.call(from.childNodes).forEach(function (child) {
171
+ if (state.count > MAX_NODES || depth > MAX_DEPTH) { return; }
172
+ if (child.nodeType === 3) { to.appendChild(document.createTextNode(child.data)); state.count++; return; }
173
+ if (child.nodeType !== 1) { return; }
174
+ var svg = child.namespaceURI === SVG_NS;
175
+ if (!svg && child.namespaceURI !== HTML_NS) { return; }
176
+ var tag = child.localName.toLowerCase();
177
+ if (DROPPED[tag] || (!svg && tag === "title")) { return; }
178
+ if (!(svg ? OK_SVG : OK_HTML)[tag]) { copyChildren(child, to, state, depth + 1); return; }
179
+ var out = svg ? document.createElementNS(SVG_NS, child.localName) : document.createElement(tag);
180
+ state.count++;
181
+ copyAttributes(child, out, svg, tag);
182
+ to.appendChild(out);
183
+ if (tag === "style") { out.textContent = cleanCss(child.textContent); } else { copyChildren(child, out, state, depth + 1); }
184
+ });
185
+ }
186
+
187
+ // Builds a new tree in \`to\` from a parsed document: the head's styles first, then the body.
188
+ function cleanInto(parsed, to) {
189
+ var state = { count: 0 };
190
+ copyChildren(parsed.head, to, state, 0);
191
+ copyChildren(parsed.body, to, state, 0);
192
+ }
193
+ `;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The Shadows section of the documentation page. (Split from `docsite.ts`; see it for how the page is built and kept safe.)
3
+ */
4
+ import { escapeHtml as esc } from "./docsite-markdown.ts";
5
+ import {
6
+ varOf,
7
+ shadowLayers,
8
+ limiter,
9
+ type Ctx,
10
+ valueIn,
11
+ variants,
12
+ copyName,
13
+ tokensOf,
14
+ moreTokens,
15
+ } from "./docsite-core.ts";
16
+
17
+ // ── Shadows and motion ─────────────────────────────────────────────────────────────────────────────────────────────
18
+
19
+ export function shadowSection(ctx: Ctx): { html: string; count: number } | undefined {
20
+ const { limit, note } = limiter();
21
+ const mine = tokensOf(ctx, "shadows");
22
+ const shadows = limit(
23
+ mine.filter((token) => token.type === "shadow" && token.tier !== "component"),
24
+ );
25
+
26
+ if (mine.length === 0) {
27
+ return undefined;
28
+ }
29
+
30
+ for (const token of shadows) {
31
+ ctx.claimed.add(token);
32
+ }
33
+
34
+ return {
35
+ html: `<p class="intro">Shadows lift a surface off the page. The shadow color follows the mode.</p><div class="shadows">${shadows
36
+ .map(
37
+ (token) =>
38
+ `<div class="shadow-tile" data-q="${esc(`${token.name} ${token.description ?? ""}`.toLowerCase())}" style="box-shadow:${varOf(token, "none")}">${copyName(token)}<span class="desc">${esc(token.description ?? "")}</span><span class="desc mono layered">${variants(ctx, (mode) => shadowLayers(valueIn(token, mode)?.value))}</span></div>`,
39
+ )
40
+ .join("")}</div>${note()}${moreTokens(ctx, "shadows")}`,
41
+ count: mine.length,
42
+ };
43
+ }
44
+
45
+ /** The cubic Bézier of a value as an SVG path in a 100 by 100 box, with the y axis up. */