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.
- package/CONTRIBUTING.md +1 -1
- package/docs/design/design-system.md +165 -0
- package/docs/design/ds-notes-b.md +61 -0
- package/docs/design/ds-notes-g.md +170 -0
- package/docs/design/ds-notes-t.md +303 -0
- package/docs/design/ds-notes-u.md +220 -0
- package/docs/design/ds-notes-v.md +186 -0
- package/docs/design/ds-rounds.md +160 -0
- package/docs/design/ds-u-bridge.patch +732 -0
- package/docs/examples/design-system/README.md +15 -0
- package/docs/examples/design-system/pocket/.pi/design/components/badge.html +112 -0
- package/docs/examples/design-system/pocket/.pi/design/components/button.html +203 -0
- package/docs/examples/design-system/pocket/.pi/design/components/card.html +125 -0
- package/docs/examples/design-system/pocket/.pi/design/components/code-block.html +155 -0
- package/docs/examples/design-system/pocket/.pi/design/components/input.html +156 -0
- package/docs/examples/design-system/pocket/.pi/design/components/menu-row.html +167 -0
- package/docs/examples/design-system/pocket/.pi/design/components/notice.html +171 -0
- package/docs/examples/design-system/pocket/.pi/design/components/segmented.html +120 -0
- package/docs/examples/design-system/pocket/.pi/design/components/switch.html +117 -0
- package/docs/examples/design-system/pocket/.pi/design/components/tool-step.html +163 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/components.css +730 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/names.md +495 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tailwind.css +1132 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.css +1126 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.dark.resolved.json +2022 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.high-contrast.resolved.json +2022 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.light.resolved.json +2022 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.resolved.json +371 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.studio.json +5915 -0
- package/docs/examples/design-system/pocket/.pi/design/guidelines.md +81 -0
- package/docs/examples/design-system/pocket/.pi/design/tokens.dark.json +182 -0
- package/docs/examples/design-system/pocket/.pi/design/tokens.high-contrast.json +185 -0
- package/docs/examples/design-system/pocket/.pi/design/tokens.json +2034 -0
- package/docs/features.md +6 -2
- package/docs/index.md +1 -0
- package/docs/map.md +34 -25
- package/docs/release-notes.md +1 -1
- package/docs/releases.md +45 -0
- package/package.json +2 -1
- package/src/server/design/check-cli.ts +283 -0
- package/src/server/design/color.ts +654 -0
- package/src/server/design/components.ts +328 -0
- package/src/server/design/docsite-assets.ts +29 -0
- package/src/server/design/docsite-color-section.ts +366 -0
- package/src/server/design/docsite-color.ts +303 -0
- package/src/server/design/docsite-components.ts +89 -0
- package/src/server/design/docsite-core.ts +634 -0
- package/src/server/design/docsite-css-base.ts +397 -0
- package/src/server/design/docsite-css-content.ts +477 -0
- package/src/server/design/docsite-css-phone.ts +251 -0
- package/src/server/design/docsite-css-reference.ts +374 -0
- package/src/server/design/docsite-css-specimens.ts +465 -0
- package/src/server/design/docsite-js-code.ts +96 -0
- package/src/server/design/docsite-js-core.ts +72 -0
- package/src/server/design/docsite-js-demos.ts +24 -0
- package/src/server/design/docsite-js-links.ts +25 -0
- package/src/server/design/docsite-js-nav.ts +73 -0
- package/src/server/design/docsite-js-stages.ts +81 -0
- package/src/server/design/docsite-js-table.ts +81 -0
- package/src/server/design/docsite-markdown.ts +221 -0
- package/src/server/design/docsite-motion.ts +110 -0
- package/src/server/design/docsite-reference.ts +269 -0
- package/src/server/design/docsite-sanitize.ts +193 -0
- package/src/server/design/docsite-shadows.ts +45 -0
- package/src/server/design/docsite-space.ts +289 -0
- package/src/server/design/docsite-type.ts +167 -0
- package/src/server/design/docsite.ts +508 -0
- package/src/server/design/export.ts +86 -9
- package/src/server/design/fix.ts +666 -0
- package/src/server/design/guide.ts +137 -22
- package/src/server/design/index.ts +368 -15
- package/src/server/design/lint-color.ts +293 -0
- package/src/server/design/lint-page-checks.ts +204 -0
- package/src/server/design/lint-page-elements.ts +252 -0
- package/src/server/design/lint-page-focus.ts +165 -0
- package/src/server/design/lint-page-literals.ts +293 -0
- package/src/server/design/lint-page-setup.ts +102 -0
- package/src/server/design/lint-page-states.ts +121 -0
- package/src/server/design/lint-page-values.ts +329 -0
- package/src/server/design/lint-page.ts +101 -0
- package/src/server/design/lint-suggest.ts +340 -0
- package/src/server/design/lint.ts +1136 -0
- package/src/server/design/render.ts +369 -18
- package/src/server/design/scan-braces.ts +115 -0
- package/src/server/design/scan-categorize.ts +187 -0
- package/src/server/design/scan-channels.ts +113 -0
- package/src/server/design/scan-color-base.ts +209 -0
- package/src/server/design/scan-color-names.ts +403 -0
- package/src/server/design/scan-color-palette.ts +91 -0
- package/src/server/design/scan-color-roles.ts +565 -0
- package/src/server/design/scan-colors.ts +22 -0
- package/src/server/design/scan-facts-antd.ts +171 -0
- package/src/server/design/scan-facts-files.ts +300 -0
- package/src/server/design/scan-facts-lists.ts +538 -0
- package/src/server/design/scan-facts-sass.ts +113 -0
- package/src/server/design/scan-facts-theme.ts +400 -0
- package/src/server/design/scan-facts-use.ts +674 -0
- package/src/server/design/scan-facts-wordpress.ts +374 -0
- package/src/server/design/scan-facts.ts +285 -0
- package/src/server/design/scan-files.ts +384 -0
- package/src/server/design/scan-import-convert.ts +277 -0
- package/src/server/design/scan-import-eval.ts +583 -0
- package/src/server/design/scan-import-material.ts +745 -0
- package/src/server/design/scan-import-sd-config.ts +370 -0
- package/src/server/design/scan-import-sd.ts +381 -0
- package/src/server/design/scan-import-studio.ts +242 -0
- package/src/server/design/scan-import.ts +336 -0
- package/src/server/design/scan-infer.ts +313 -0
- package/src/server/design/scan-js-eval.ts +1267 -0
- package/src/server/design/scan-palette.ts +485 -0
- package/src/server/design/scan-parse.ts +1134 -0
- package/src/server/design/scan-prepare.ts +402 -0
- package/src/server/design/scan-render-pages.ts +367 -0
- package/src/server/design/scan-render-probe.ts +229 -0
- package/src/server/design/scan-render.ts +524 -0
- package/src/server/design/scan-review.ts +54 -0
- package/src/server/design/scan-roles.ts +259 -0
- package/src/server/design/scan-sass-colors.ts +275 -0
- package/src/server/design/scan-sass-eval.ts +269 -0
- package/src/server/design/scan-sass-expr.ts +911 -0
- package/src/server/design/scan-sass-modules.ts +353 -0
- package/src/server/design/scan-sass-run.ts +1003 -0
- package/src/server/design/scan-sass-stmt.ts +256 -0
- package/src/server/design/scan-sass-values.ts +886 -0
- package/src/server/design/scan-scales.ts +983 -0
- package/src/server/design/scan-tailwind.ts +34 -0
- package/src/server/design/scan-theme-shapes.ts +579 -0
- package/src/server/design/scan-tree.ts +290 -0
- package/src/server/design/scan-util.ts +44 -0
- package/src/server/design/scan-variables.ts +470 -0
- package/src/server/design/scan.ts +703 -0
- package/src/server/design/system-schema.ts +68 -0
- package/src/server/design/system-types.ts +279 -0
- package/src/server/design/system.ts +510 -82
- package/src/server/design/tokens-base.ts +123 -0
- package/src/server/design/tokens-compile.ts +440 -0
- package/src/server/design/tokens-dtcg.ts +354 -0
- package/src/server/design/tokens-io.ts +417 -0
- package/src/server/design/tokens-model.ts +1163 -0
- package/src/server/design/tokens-names.ts +112 -0
- package/src/server/design/tokens-ramps.ts +112 -0
- package/src/server/design/tokens-summary.ts +317 -0
- package/src/server/design/tokens-tailwind.ts +324 -0
- package/src/server/design/tokens-values.ts +921 -0
- package/src/server/design/tokens.ts +533 -0
- package/src/server/docs.ts +8 -0
- package/src/server/extensions/artifacts.ts +87 -2
- package/src/server/extensions/design/app.js +280 -0
- package/src/server/extensions/design/canvas.js +142 -17
- package/src/server/extensions/design/check.js +656 -0
- package/src/server/extensions/design/color.js +383 -0
- package/src/server/extensions/design/data.js +102 -7
- package/src/server/extensions/design/devices.js +26 -0
- package/src/server/extensions/design/docks.js +117 -3
- package/src/server/extensions/design/index.js +171 -219
- package/src/server/extensions/design/messages.js +49 -0
- package/src/server/extensions/design/parts.js +15 -1
- package/src/server/extensions/design/paths.js +4 -0
- package/src/server/extensions/design/picker.js +123 -0
- package/src/server/extensions/design/specimen.js +55 -0
- package/src/server/extensions/design/state.js +72 -7
- package/src/server/extensions/design/style.css +546 -0
- package/src/server/extensions/design/system-actions.js +214 -0
- package/src/server/extensions/design/system-api.ts +62 -0
- package/src/server/extensions/design/system-data.js +315 -0
- package/src/server/extensions/design/system-preview.js +41 -0
- package/src/server/extensions/design/system-routes.ts +1122 -0
- package/src/server/extensions/design/system-sections.js +1344 -0
- package/src/server/extensions/design/system-ui.js +32 -0
- package/src/server/extensions/design/system-view.js +1196 -0
- package/src/server/extensions/design/system-widgets.js +942 -0
- package/src/server/extensions/design/system.css +2313 -0
- package/src/server/extensions/design/system.js +1479 -0
- package/src/server/extensions/design/unsaved.js +20 -0
- package/src/server/extensions/design/views.js +2 -2
- package/src/server/extensions/design/workspace.js +200 -105
- package/src/server/extensions/design.ts +89 -6
- package/src/server/extensions/updates/index.js +31 -9
- package/src/server/extensions/updates/style.css +11 -0
- package/src/server/extensions/updates.ts +29 -1
- package/src/server/host.ts +4 -1
- package/src/server/http/artifact-inspect.ts +338 -24
- package/src/server/updates.ts +235 -53
- package/src/server/versions.ts +71 -0
- package/web/artifact-bridge.js +34 -1
- package/npm-shrinkwrap.json +0 -3162
|
@@ -0,0 +1,1344 @@
|
|
|
1
|
+
// The sections of the System view: Colors, Type, Spacing, Radii, Shadows, Motion, Other, Components, and Guidelines. Each
|
|
2
|
+
// draws the tokens of its kind as what they are (a swatch, a specimen, a bar, a corner, a shadow, a motion), and opens the
|
|
3
|
+
// editor of one token under its row. They read the model (`system.js`) and change nothing but through `env`.
|
|
4
|
+
import { parseColor, ratioText, swatchCss, toHex } from "./color.js";
|
|
5
|
+
import { specimenDocument } from "./specimen.js";
|
|
6
|
+
import {
|
|
7
|
+
cssOf,
|
|
8
|
+
groupsOf,
|
|
9
|
+
matches,
|
|
10
|
+
millisecondsOf,
|
|
11
|
+
pixelsOf,
|
|
12
|
+
safeCss,
|
|
13
|
+
shadowOf,
|
|
14
|
+
shadowLines,
|
|
15
|
+
shadowSummary,
|
|
16
|
+
showValue,
|
|
17
|
+
tails,
|
|
18
|
+
themeCss,
|
|
19
|
+
typographyMeta,
|
|
20
|
+
typographyStyle,
|
|
21
|
+
typographyStyleOf,
|
|
22
|
+
} from "./system.js";
|
|
23
|
+
import { copyText, modeTitle, verdictOf } from "./system-widgets.js";
|
|
24
|
+
|
|
25
|
+
const SAMPLE = "Sphinx of black quartz, judge my vow";
|
|
26
|
+
|
|
27
|
+
const hexOf = (value) => {
|
|
28
|
+
const color = parseColor(value);
|
|
29
|
+
|
|
30
|
+
return color === null ? "" : toHex(color);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The line under a typography style's name: `20px / 1.15 · 600 · Geist`. */
|
|
34
|
+
function styleMeta(value) {
|
|
35
|
+
if (typeof value !== "object" || value === null) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const size = cssOf("dimension", value.fontSize);
|
|
40
|
+
const height =
|
|
41
|
+
typeof value.lineHeight === "number"
|
|
42
|
+
? `/ ${value.lineHeight}`
|
|
43
|
+
: value.lineHeight
|
|
44
|
+
? `/ ${cssOf("dimension", value.lineHeight)}`
|
|
45
|
+
: "";
|
|
46
|
+
const family = Array.isArray(value.fontFamily) ? value.fontFamily[0] : value.fontFamily;
|
|
47
|
+
|
|
48
|
+
return [[size, height].filter(Boolean).join(" "), value.fontWeight, family]
|
|
49
|
+
.filter((part) => part !== undefined && part !== "")
|
|
50
|
+
.join(" · ");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createSystemSections(env, widgets) {
|
|
54
|
+
const { pocket, store } = env;
|
|
55
|
+
const { html, useEffect, useRef, useState, Markdown } = pocket;
|
|
56
|
+
const { Ico } = env.parts;
|
|
57
|
+
const { Swatch, CopyName, ContrastBadge, TokenEditor, Curve } = widgets;
|
|
58
|
+
|
|
59
|
+
// ─── Rows and groups ─────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/** One token: a visual, its name (which copies), a line under it, its value; a tap opens its editor under it. */
|
|
62
|
+
function TokenRow({ ctx, token, visual, sub, value, stacked = false, children }) {
|
|
63
|
+
const open = ctx.s.sysOpen === token.name;
|
|
64
|
+
const edited = ctx.modes.some((mode) => ctx.model.edited(token.name, mode));
|
|
65
|
+
|
|
66
|
+
return html`<li
|
|
67
|
+
class=${`dsy-row ${open ? "open" : ""} ${edited ? "edited" : ""} ${stacked ? "stacked" : ""}`}
|
|
68
|
+
data-token=${token.name}
|
|
69
|
+
>
|
|
70
|
+
<div class="dsy-row-main" onClick=${() => env.toggleToken(token.name)}>
|
|
71
|
+
${visual && html`<span class="dsy-row-visual">${visual}</span>`}
|
|
72
|
+
<span class="dsy-row-text">
|
|
73
|
+
<span class="dsy-row-title">
|
|
74
|
+
<${CopyName} name=${token.name} />
|
|
75
|
+
${token.deprecated && html`<span class="dsy-tag warn">deprecated</span>`}
|
|
76
|
+
${edited && html`<span class="dsy-tag edit">edited</span>`}
|
|
77
|
+
</span>
|
|
78
|
+
${sub && html`<span class="dsy-row-sub">${sub}</span>`}
|
|
79
|
+
</span>
|
|
80
|
+
${value && html`<span class="dsy-row-value">${value}</span>`}
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
class="dsy-row-open"
|
|
84
|
+
aria-expanded=${open}
|
|
85
|
+
aria-label=${`${open ? "Close" : "Open"} ${token.name}`}
|
|
86
|
+
onClick=${(event) => {
|
|
87
|
+
event.stopPropagation();
|
|
88
|
+
env.toggleToken(token.name);
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<${Ico} name="down" size=${15} />
|
|
92
|
+
</button>
|
|
93
|
+
</div>
|
|
94
|
+
${children}
|
|
95
|
+
${
|
|
96
|
+
open &&
|
|
97
|
+
html`<${TokenEditor}
|
|
98
|
+
model=${ctx.model}
|
|
99
|
+
token=${token}
|
|
100
|
+
modes=${ctx.modes}
|
|
101
|
+
canEdit=${ctx.canEdit}
|
|
102
|
+
narrow=${ctx.narrow}
|
|
103
|
+
/>`
|
|
104
|
+
}
|
|
105
|
+
</li>`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Whether a group is folded now: what the person chose, else how it starts. A search opens every group with a match. */
|
|
109
|
+
const foldedNow = (ctx, group) =>
|
|
110
|
+
ctx.query === "" && (ctx.s.sysFolded[group.id] ?? group.fold === true);
|
|
111
|
+
|
|
112
|
+
/** A group of tokens in a card, with a head that folds it. */
|
|
113
|
+
function Group({ ctx, group, strip, children, bare = false, note = "" }) {
|
|
114
|
+
const folded = foldedNow(ctx, group);
|
|
115
|
+
|
|
116
|
+
const more =
|
|
117
|
+
group.hidden > 0 &&
|
|
118
|
+
html`<button
|
|
119
|
+
type="button"
|
|
120
|
+
class="dsn-link dsy-more"
|
|
121
|
+
onClick=${() => env.showAll(group.id)}
|
|
122
|
+
>
|
|
123
|
+
Show ${group.hidden} more
|
|
124
|
+
</button>`;
|
|
125
|
+
|
|
126
|
+
if (bare) {
|
|
127
|
+
return html`<section class="dsy-group bare">${children}${more}</section>`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return html`<section
|
|
131
|
+
class="dsy-group"
|
|
132
|
+
data-folded=${folded}
|
|
133
|
+
data-tier=${group.tier}
|
|
134
|
+
aria-label=${group.title}
|
|
135
|
+
>
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
class="dsy-group-head"
|
|
139
|
+
aria-expanded=${!folded}
|
|
140
|
+
onClick=${() => env.toggleGroup(group.id, !folded)}
|
|
141
|
+
>
|
|
142
|
+
<span class="dsy-group-title">${group.title}</span>
|
|
143
|
+
<span class="dsy-group-count">${group.total ?? group.tokens.length}</span>
|
|
144
|
+
${note && html`<span class="dsy-group-note">${note}</span>`} ${strip}
|
|
145
|
+
<${Ico} name="down" size=${15} class="dsy-group-chev" />
|
|
146
|
+
</button>
|
|
147
|
+
${!folded && html`<div class="dsy-group-body">${children}${more}</div>`}
|
|
148
|
+
</section>`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const Empty = ({ text }) => html`<p class="dsy-empty muted">${text}</p>`;
|
|
152
|
+
|
|
153
|
+
/** A group shows this many tokens until its "Show more" is tapped: a big system stays quick to draw. */
|
|
154
|
+
const SHOWN = 120;
|
|
155
|
+
|
|
156
|
+
/** The groups of a section, filtered by the search; a long one is cut, with `hidden` the number it leaves out. */
|
|
157
|
+
function groupsFor(ctx, section) {
|
|
158
|
+
return groupsOf(ctx.model.tokens, section)
|
|
159
|
+
.map((group) => {
|
|
160
|
+
const found = group.tokens.filter((token) => matches(token, ctx.query));
|
|
161
|
+
const cut = ctx.query === "" && !ctx.s.sysAll[group.id] && found.length > SHOWN;
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
...group,
|
|
165
|
+
total: found.length,
|
|
166
|
+
tokens: cut ? found.slice(0, SHOWN) : found,
|
|
167
|
+
hidden: cut ? found.length - SHOWN : 0,
|
|
168
|
+
};
|
|
169
|
+
})
|
|
170
|
+
.filter((group) => group.tokens.length > 0);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ─── Colors ──────────────────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The system's look, for each mode, as a small card built from its own roles: a title, body text, quiet text, a primary
|
|
177
|
+
* button, and a chip for each status. The words are plain on purpose: they say nothing about any product.
|
|
178
|
+
*/
|
|
179
|
+
function Overview({ ctx }) {
|
|
180
|
+
const found = ctx.model.roles();
|
|
181
|
+
|
|
182
|
+
if (found.canvas === undefined || found.surface === undefined || found.text === undefined) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const chips = [
|
|
187
|
+
["danger", "Error"],
|
|
188
|
+
["warning", "Warning"],
|
|
189
|
+
["success", "Success"],
|
|
190
|
+
].filter(([role]) => found[role] !== undefined);
|
|
191
|
+
|
|
192
|
+
return html`<div class="dsy-overview" data-count=${ctx.modes.length}>
|
|
193
|
+
${ctx.modes.map((mode) => {
|
|
194
|
+
const color = (role, fallback = "") => {
|
|
195
|
+
const name = found[role];
|
|
196
|
+
|
|
197
|
+
return name === undefined
|
|
198
|
+
? fallback
|
|
199
|
+
: swatchCss(ctx.model.value(name, mode).value) || fallback;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const quiet = color("muted", color("text"));
|
|
203
|
+
|
|
204
|
+
return html`<figure
|
|
205
|
+
class="dsy-look"
|
|
206
|
+
key=${mode}
|
|
207
|
+
style=${`background:${color("canvas")}`}
|
|
208
|
+
aria-label=${`A card in ${mode}, drawn with the system's roles`}
|
|
209
|
+
>
|
|
210
|
+
<div
|
|
211
|
+
class="dsy-look-card"
|
|
212
|
+
style=${`background:${color("surface")};box-shadow:0 0 0 1px ${color("border", "rgb(127 127 127 / .3)")}`}
|
|
213
|
+
>
|
|
214
|
+
<strong style=${`color:${color("text")}`}>Card title</strong>
|
|
215
|
+
<span style=${`color:${color("text")}`}>Body text reads at a glance.</span>
|
|
216
|
+
<span style=${`color:${quiet}`}>Muted text for the details.</span>
|
|
217
|
+
<span class="dsy-look-row">
|
|
218
|
+
<span
|
|
219
|
+
class="dsy-look-button"
|
|
220
|
+
style=${`background:${color("accent", color("text"))};color:${color("onAccent", color("surface"))}`}
|
|
221
|
+
>Primary</span
|
|
222
|
+
>
|
|
223
|
+
<span
|
|
224
|
+
class="dsy-look-button ghost"
|
|
225
|
+
style=${`color:${color("text")};box-shadow:inset 0 0 0 1px ${color("border", quiet)}`}
|
|
226
|
+
>Secondary</span
|
|
227
|
+
>
|
|
228
|
+
</span>
|
|
229
|
+
${
|
|
230
|
+
chips.length > 0 &&
|
|
231
|
+
html`<span class="dsy-look-chips">
|
|
232
|
+
${chips.map(
|
|
233
|
+
([role, label]) =>
|
|
234
|
+
html`<span
|
|
235
|
+
class="dsy-look-chip"
|
|
236
|
+
key=${role}
|
|
237
|
+
style=${`color:${color("text")};box-shadow:inset 0 0 0 1px ${color("border", quiet)}`}
|
|
238
|
+
><i style=${`background:${color(role)}`}></i
|
|
239
|
+
>${label}</span
|
|
240
|
+
>`,
|
|
241
|
+
)}
|
|
242
|
+
</span>`
|
|
243
|
+
}
|
|
244
|
+
</div>
|
|
245
|
+
${ctx.modes.length > 1 && html`<figcaption style=${`color:${quiet}`}>${mode}</figcaption>`}
|
|
246
|
+
</figure>`;
|
|
247
|
+
})}
|
|
248
|
+
</div>`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Whether a color is the same in every mode shown: then it is drawn once, not once for each mode. */
|
|
252
|
+
const alike = (values) =>
|
|
253
|
+
values.every((each) => swatchCss(each.value) === swatchCss(values[0].value));
|
|
254
|
+
|
|
255
|
+
/** The editor of the open token of a group, under the group's cards or strip, in a box of its own. */
|
|
256
|
+
function Opened({ ctx, group }) {
|
|
257
|
+
const open = group.tokens.find((token) => token.name === ctx.s.sysOpen);
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
open &&
|
|
261
|
+
html`<div class="dsy-ramp-editor" data-token=${open.name}>
|
|
262
|
+
<div class="dsy-ramp-editor-head">
|
|
263
|
+
<${CopyName} name=${open.name} />
|
|
264
|
+
${
|
|
265
|
+
ctx.modes.length === 1 &&
|
|
266
|
+
ctx.model.modes.length > 1 &&
|
|
267
|
+
html`<span class="dsy-mode-chip">${modeTitle(ctx.modes[0])}</span>`
|
|
268
|
+
}
|
|
269
|
+
<span class="grow"></span>
|
|
270
|
+
<button
|
|
271
|
+
type="button"
|
|
272
|
+
class="icon-button"
|
|
273
|
+
aria-label=${`Close ${open.name}`}
|
|
274
|
+
onClick=${() => env.toggleToken(open.name)}
|
|
275
|
+
>
|
|
276
|
+
<${Ico} name="close" size=${15} />
|
|
277
|
+
</button>
|
|
278
|
+
</div>
|
|
279
|
+
<${TokenEditor}
|
|
280
|
+
model=${ctx.model}
|
|
281
|
+
token=${open}
|
|
282
|
+
modes=${ctx.modes}
|
|
283
|
+
canEdit=${ctx.canEdit}
|
|
284
|
+
narrow=${ctx.narrow}
|
|
285
|
+
/>
|
|
286
|
+
</div>`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** What the cards and strips of a color show of it: one swatch (split when its modes differ), its value, and its pair. */
|
|
291
|
+
function colorFacts(ctx, token) {
|
|
292
|
+
const all = ctx.modes.map((mode) => ctx.model.value(token.name, mode));
|
|
293
|
+
const infos = ctx.modes.map((mode) => ctx.model.contrastOf(token.name, mode));
|
|
294
|
+
// The same color, and the same fortune on its pair, in every mode: drawn once.
|
|
295
|
+
const merged =
|
|
296
|
+
ctx.modes.length > 1 &&
|
|
297
|
+
alike(all) &&
|
|
298
|
+
new Set(infos.map((info) => (info ? `${Math.round(info.ratio * 10)}${info.pass}` : "")))
|
|
299
|
+
.size === 1;
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
values: merged ? all.slice(0, 1) : all,
|
|
303
|
+
modes: merged ? ctx.modes.slice(0, 1) : ctx.modes,
|
|
304
|
+
infos: merged ? infos.slice(0, 1) : infos,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Roles as cards in a grid: the swatch, the name, the value, and the contrast on its pair. A tap opens its editor. */
|
|
309
|
+
function RoleCards({ ctx, group }) {
|
|
310
|
+
const names = tails(group.tokens);
|
|
311
|
+
|
|
312
|
+
return html`<${Tiles}
|
|
313
|
+
ctx=${ctx}
|
|
314
|
+
group=${group}
|
|
315
|
+
size="role"
|
|
316
|
+
label=${(token) => {
|
|
317
|
+
const facts = colorFacts(ctx, token);
|
|
318
|
+
const pairs = facts.infos.flatMap((info, index) =>
|
|
319
|
+
info
|
|
320
|
+
? [
|
|
321
|
+
`${facts.modes.length > 1 ? `${modeTitle(facts.modes[index])} ` : ""}contrast ${ratioText(info.ratio)} ${verdictOf(info)}`,
|
|
322
|
+
]
|
|
323
|
+
: [],
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
return [
|
|
327
|
+
token.name,
|
|
328
|
+
hexOf(facts.values[0].value),
|
|
329
|
+
...pairs,
|
|
330
|
+
inheritedIn(ctx, token)
|
|
331
|
+
? `inherited from ${modeTitle(ctx.model.defaultMode)}`
|
|
332
|
+
: "",
|
|
333
|
+
]
|
|
334
|
+
.filter(Boolean)
|
|
335
|
+
.join(", ");
|
|
336
|
+
}}
|
|
337
|
+
tile=${(token) => {
|
|
338
|
+
const facts = colorFacts(ctx, token);
|
|
339
|
+
|
|
340
|
+
return html`<${Swatch}
|
|
341
|
+
values=${facts.values.map((each) => each.value)}
|
|
342
|
+
size=${46}
|
|
343
|
+
/>
|
|
344
|
+
<span class="dsy-card-name mono">${names.get(token.name)}</span>
|
|
345
|
+
<span class="dsy-card-meta">
|
|
346
|
+
<span class="dsy-hex mono">${hexOf(facts.values[0].value) || "—"}</span>
|
|
347
|
+
${facts.infos.map(
|
|
348
|
+
(info, index) =>
|
|
349
|
+
html`<${ContrastBadge}
|
|
350
|
+
key=${facts.modes[index]}
|
|
351
|
+
info=${info}
|
|
352
|
+
mode=${facts.modes[index]}
|
|
353
|
+
modes=${facts.modes.length}
|
|
354
|
+
/>`,
|
|
355
|
+
)}
|
|
356
|
+
</span>`;
|
|
357
|
+
}}
|
|
358
|
+
/>`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** A ramp as one strip: its swatches side by side, each a button that opens the editor of its step under the strip. */
|
|
362
|
+
function Strip({ ctx, group }) {
|
|
363
|
+
const names = tails(group.tokens);
|
|
364
|
+
|
|
365
|
+
return html`<div class="dsy-strip-row">
|
|
366
|
+
<div class="dsy-strip-head">
|
|
367
|
+
<strong>${group.title}</strong>
|
|
368
|
+
<span class="muted small">${group.tokens.length}</span>
|
|
369
|
+
</div>
|
|
370
|
+
<div class="dsy-strip-steps" role="group" aria-label=${`${group.title} palette`}>
|
|
371
|
+
${group.tokens.map((token) => {
|
|
372
|
+
const facts = colorFacts(ctx, token);
|
|
373
|
+
const edited = ctx.modes.some((mode) => ctx.model.edited(token.name, mode));
|
|
374
|
+
|
|
375
|
+
return html`<button
|
|
376
|
+
type="button"
|
|
377
|
+
key=${token.name}
|
|
378
|
+
data-token=${token.name}
|
|
379
|
+
class=${`dsy-step-tile ${token.name === ctx.s.sysOpen ? "on" : ""} ${edited ? "edited" : ""}`}
|
|
380
|
+
aria-pressed=${token.name === ctx.s.sysOpen}
|
|
381
|
+
aria-label=${`${token.name}, ${hexOf(facts.values[0].value)}`}
|
|
382
|
+
title=${`${token.name} ${hexOf(facts.values[0].value)}`}
|
|
383
|
+
onClick=${() => env.toggleToken(token.name)}
|
|
384
|
+
>
|
|
385
|
+
<${Swatch} values=${facts.values.map((each) => each.value)} size=${40} />
|
|
386
|
+
<span class="dsy-step-label mono">${names.get(token.name)}</span>
|
|
387
|
+
</button>`;
|
|
388
|
+
})}
|
|
389
|
+
</div>
|
|
390
|
+
<${Opened} ctx=${ctx} group=${group} />
|
|
391
|
+
</div>`;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** The swatches of a group, overlapped, for its head. */
|
|
395
|
+
const stripOf = (ctx, group) =>
|
|
396
|
+
html`<span class="dsy-strip" aria-hidden="true">
|
|
397
|
+
${group.tokens
|
|
398
|
+
.slice(0, 9)
|
|
399
|
+
.map(
|
|
400
|
+
(token) =>
|
|
401
|
+
html`<i
|
|
402
|
+
key=${token.name}
|
|
403
|
+
style=${`background:${swatchCss(ctx.model.value(token.name, ctx.modes[0]).value)}`}
|
|
404
|
+
></i>`,
|
|
405
|
+
)}
|
|
406
|
+
</span>`;
|
|
407
|
+
|
|
408
|
+
function Colors({ ctx }) {
|
|
409
|
+
const groups = groupsFor(ctx, "colors");
|
|
410
|
+
|
|
411
|
+
if (groups.length === 0) {
|
|
412
|
+
return html`<${Empty}
|
|
413
|
+
text=${ctx.query ? "No color matches." : "This system has no colors yet."}
|
|
414
|
+
/>`;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const roles = groups.filter((group) => group.tier === "semantic");
|
|
418
|
+
const palette = groups.filter((group) => group.tier === "primitive");
|
|
419
|
+
const components = groups.filter((group) => group.tier === "component");
|
|
420
|
+
// All the ramps are one folded group: the roles are what people edit; the palette is what they point at.
|
|
421
|
+
const together = (id, title, list, tier) => ({
|
|
422
|
+
id: `colors:${id}`,
|
|
423
|
+
title,
|
|
424
|
+
tier,
|
|
425
|
+
tokens: list.flatMap((group) => group.tokens),
|
|
426
|
+
total: list.reduce((sum, group) => sum + (group.total ?? group.tokens.length), 0),
|
|
427
|
+
hidden: list.reduce((sum, group) => sum + (group.hidden ?? 0), 0),
|
|
428
|
+
// The palette starts folded when there are roles to look at; a system of nothing but a palette shows it.
|
|
429
|
+
fold: roles.length > 0 || tier === "component",
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
return html`${ctx.query === "" && html`<${Overview} ctx=${ctx} />`}
|
|
433
|
+
${
|
|
434
|
+
roles.length > 0 &&
|
|
435
|
+
html`<h3 class="dsy-section-label">
|
|
436
|
+
Roles
|
|
437
|
+
<span class="dsy-group-count"
|
|
438
|
+
>${roles.reduce((sum, group) => sum + group.total, 0)}</span
|
|
439
|
+
>
|
|
440
|
+
</h3>`
|
|
441
|
+
}
|
|
442
|
+
${roles.map(
|
|
443
|
+
(group) =>
|
|
444
|
+
html`<${Group}
|
|
445
|
+
key=${group.id}
|
|
446
|
+
ctx=${ctx}
|
|
447
|
+
group=${group}
|
|
448
|
+
strip=${stripOf(ctx, group)}
|
|
449
|
+
>
|
|
450
|
+
<${RoleCards} ctx=${ctx} group=${group} />
|
|
451
|
+
<//>`,
|
|
452
|
+
)}
|
|
453
|
+
${
|
|
454
|
+
palette.length > 0 &&
|
|
455
|
+
html`<${Group}
|
|
456
|
+
ctx=${ctx}
|
|
457
|
+
group=${together("palette", "Palette", palette, "primitive")}
|
|
458
|
+
note="the raw colors that roles point at"
|
|
459
|
+
>
|
|
460
|
+
${palette.map((group) => html`<${Strip} key=${group.id} ctx=${ctx} group=${group} />`)}
|
|
461
|
+
<//>`
|
|
462
|
+
}
|
|
463
|
+
${
|
|
464
|
+
components.length > 0 &&
|
|
465
|
+
html`<${Group}
|
|
466
|
+
ctx=${ctx}
|
|
467
|
+
group=${together("components", "Component colors", components, "component")}
|
|
468
|
+
note="each component's own colors"
|
|
469
|
+
>
|
|
470
|
+
${components.map(
|
|
471
|
+
(group) =>
|
|
472
|
+
html`<div class="dsy-sub" key=${group.id}>
|
|
473
|
+
<h4 class="dsy-sub-title">${group.title}</h4>
|
|
474
|
+
<${RoleCards} ctx=${ctx} group=${group} />
|
|
475
|
+
</div>`,
|
|
476
|
+
)}
|
|
477
|
+
<//>`
|
|
478
|
+
}`;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// ─── Type ────────────────────────────────────────────────────────────────
|
|
482
|
+
|
|
483
|
+
function Type({ ctx }) {
|
|
484
|
+
const groups = groupsFor(ctx, "type");
|
|
485
|
+
const mode = ctx.modes[0];
|
|
486
|
+
|
|
487
|
+
if (groups.length === 0) {
|
|
488
|
+
return html`<${Empty}
|
|
489
|
+
text=${ctx.query ? "No type token matches." : "This system has no type tokens yet."}
|
|
490
|
+
/>`;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const row = (token, group) => {
|
|
494
|
+
const now = ctx.model.value(token.name, mode);
|
|
495
|
+
|
|
496
|
+
if (token.type === "typography") {
|
|
497
|
+
return html`<${TokenRow}
|
|
498
|
+
key=${token.name}
|
|
499
|
+
ctx=${ctx}
|
|
500
|
+
token=${token}
|
|
501
|
+
stacked=${true}
|
|
502
|
+
sub=${html`<span class="mono"
|
|
503
|
+
>${typographyMeta(ctx.model, mode, now) ?? styleMeta(now.value)}</span
|
|
504
|
+
>`}
|
|
505
|
+
>
|
|
506
|
+
<p class="dsy-specimen" style=${typographyStyleOf(ctx.model, mode, now)}>
|
|
507
|
+
${SAMPLE}
|
|
508
|
+
</p>
|
|
509
|
+
<//>`;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (token.type === "fontFamily") {
|
|
513
|
+
const css = cssOf("fontFamily", now.value) ?? "";
|
|
514
|
+
const style = typographyStyle({ fontFamily: now.value });
|
|
515
|
+
|
|
516
|
+
return html`<${TokenRow}
|
|
517
|
+
key=${token.name}
|
|
518
|
+
ctx=${ctx}
|
|
519
|
+
token=${token}
|
|
520
|
+
visual=${html`<span class="dsy-glyph" style=${style}>Ag</span>`}
|
|
521
|
+
sub=${html`<span class="mono">${css}</span>`}
|
|
522
|
+
value=${html`<span class="dsy-hex mono">${showValue(token, now)}</span>`}
|
|
523
|
+
/>`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (token.type === "fontWeight") {
|
|
527
|
+
return html`<${TokenRow}
|
|
528
|
+
key=${token.name}
|
|
529
|
+
ctx=${ctx}
|
|
530
|
+
token=${token}
|
|
531
|
+
visual=${html`<span class="dsy-glyph" style=${`font-weight:${safeCss(now.value) || 400}`}>Aa</span>`}
|
|
532
|
+
value=${html`<span class="dsy-hex mono">${showValue(token, now)}</span>`}
|
|
533
|
+
/>`;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (token.type === "number") {
|
|
537
|
+
return html`<${TokenRow}
|
|
538
|
+
key=${token.name}
|
|
539
|
+
ctx=${ctx}
|
|
540
|
+
token=${token}
|
|
541
|
+
visual=${html`<span class="dsy-leading" style=${`line-height:${safeCss(now.value) || 1.4}`}>Aa<br />Aa</span>`}
|
|
542
|
+
value=${html`<span class="dsy-hex mono">${showValue(token, now)}</span>`}
|
|
543
|
+
/>`;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const px = pixelsOf(now.value);
|
|
547
|
+
|
|
548
|
+
return html`<${TokenRow}
|
|
549
|
+
key=${token.name}
|
|
550
|
+
ctx=${ctx}
|
|
551
|
+
token=${token}
|
|
552
|
+
visual=${html`<span class="dsy-glyph" style=${px === null ? "" : `font-size:${Math.min(px, 30)}px`}>Aa</span>`}
|
|
553
|
+
sub=${px === null ? null : html`<span class="mono">${px}px${px % 16 === 0 ? ` · ${px / 16}rem` : ""}</span>`}
|
|
554
|
+
value=${html`<span class="dsy-hex mono">${showValue(token, now)}</span>`}
|
|
555
|
+
/>`;
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
return html`${groups.map(
|
|
559
|
+
(group) =>
|
|
560
|
+
html`<${Group} key=${group.id} ctx=${ctx} group=${group}>
|
|
561
|
+
<ul class="dsy-rows">
|
|
562
|
+
${group.tokens.map((token) => row(token, group))}
|
|
563
|
+
</ul>
|
|
564
|
+
<//>`,
|
|
565
|
+
)}`;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ─── Spacing, radii, shadows ─────────────────────────────────────────────
|
|
569
|
+
|
|
570
|
+
/** Last words that say little alone (`in`, `out`, `md`, `default`): a tile with one gets its whole path. */
|
|
571
|
+
const VAGUE = new Set(
|
|
572
|
+
"in out on off sm md lg xs xl xxl x y top bottom left right start end inner outer base default main alt hover active".split(
|
|
573
|
+
" ",
|
|
574
|
+
),
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* The names of a group's tiles: the shortest tail of the path that tells them apart, and for a token whose last word alone is
|
|
579
|
+
* not clear (`layout.gap.in`: not `in`) the whole path. The steps of a scale are their own numbers and sizes, as the
|
|
580
|
+
* head of their group says what they are the steps of.
|
|
581
|
+
*/
|
|
582
|
+
const labelsOf = (group) => {
|
|
583
|
+
const names = tails(group.tokens);
|
|
584
|
+
|
|
585
|
+
if (group.kind === "steps" || group.kind === "scale") {
|
|
586
|
+
return names;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return new Map(
|
|
590
|
+
group.tokens.map((token) => {
|
|
591
|
+
const tail = names.get(token.name);
|
|
592
|
+
const last = token.path[token.path.length - 1].toLowerCase();
|
|
593
|
+
|
|
594
|
+
return [token.name, token.path.length > 1 && VAGUE.has(last) ? token.name : tail];
|
|
595
|
+
}),
|
|
596
|
+
);
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
/** What each kind of group says it is, in its head. */
|
|
600
|
+
const GROUP_NOTES = {
|
|
601
|
+
steps: "the scale that padding, margins, and gaps move in",
|
|
602
|
+
sizes: "heights and widths for controls, icons, and marks",
|
|
603
|
+
scale: "the corners: every role points at one of these",
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Roles in a group, each under the step of the scale that it points at (`radius.card` under `lg · 8px`): roles may share a
|
|
608
|
+
* value and a step, and one that points at no step of the section is under "Own value". `steps` are the scale's tokens.
|
|
609
|
+
*/
|
|
610
|
+
function ByStep({ ctx, group, steps, tile, size }) {
|
|
611
|
+
const mode = ctx.modes[0];
|
|
612
|
+
const px = (token) => pixelsOf(ctx.model.value(token.name, mode).value) ?? 0;
|
|
613
|
+
const ordered = [...steps].sort((a, b) => px(a) - px(b));
|
|
614
|
+
const names = new Set(ordered.map((token) => token.name));
|
|
615
|
+
const buckets = new Map(ordered.map((token) => [token.name, []]));
|
|
616
|
+
const own = [];
|
|
617
|
+
|
|
618
|
+
for (const token of group.tokens) {
|
|
619
|
+
const step = ctx.model
|
|
620
|
+
.chain(token.name, mode)
|
|
621
|
+
.slice(1)
|
|
622
|
+
.find((name) => names.has(name));
|
|
623
|
+
|
|
624
|
+
(step === undefined ? own : buckets.get(step)).push(token);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const sets = [
|
|
628
|
+
...ordered.map((token) => [token, buckets.get(token.name)]),
|
|
629
|
+
[null, own],
|
|
630
|
+
].filter(([, tokens]) => tokens.length > 0);
|
|
631
|
+
const label = tails(ordered);
|
|
632
|
+
|
|
633
|
+
return html`${sets.map(([step, tokens]) => {
|
|
634
|
+
const id = `${group.id}>${step?.name ?? ""}`;
|
|
635
|
+
const part = { ...group, id, tokens };
|
|
636
|
+
|
|
637
|
+
return html`<div class="dsy-by-step" key=${id}>
|
|
638
|
+
<h4 class="dsy-by-step-head">
|
|
639
|
+
${
|
|
640
|
+
step
|
|
641
|
+
? html`<span class="mono"
|
|
642
|
+
>${/^\d+$/.test(label.get(step.name)) ? step.name : label.get(step.name)}</span
|
|
643
|
+
>
|
|
644
|
+
<span class="muted mono"
|
|
645
|
+
>${showValue(step, ctx.model.value(step.name, mode))}</span
|
|
646
|
+
>`
|
|
647
|
+
: html`<span>Own value</span>
|
|
648
|
+
<span class="muted">not a step of the scale</span>`
|
|
649
|
+
}
|
|
650
|
+
</h4>
|
|
651
|
+
<${Tiles}
|
|
652
|
+
ctx=${ctx}
|
|
653
|
+
group=${part}
|
|
654
|
+
size=${size}
|
|
655
|
+
tile=${(token) => tile(token, labelsOf(group))}
|
|
656
|
+
/>
|
|
657
|
+
</div>`;
|
|
658
|
+
})}`;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/** The scale's tokens of a section, whatever the search has left out: what the roles are grouped under. */
|
|
662
|
+
const stepsOf = (ctx, section, kind) =>
|
|
663
|
+
groupsOf(ctx.model.tokens, section)
|
|
664
|
+
.filter((group) => group.kind === kind)
|
|
665
|
+
.flatMap((group) => group.tokens);
|
|
666
|
+
|
|
667
|
+
function Spacing({ ctx }) {
|
|
668
|
+
const groups = groupsFor(ctx, "spacing");
|
|
669
|
+
const mode = ctx.modes[0];
|
|
670
|
+
|
|
671
|
+
if (groups.length === 0) {
|
|
672
|
+
return html`<${Empty}
|
|
673
|
+
text=${ctx.query ? "No spacing token matches." : "This system has no spacing yet."}
|
|
674
|
+
/>`;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
const widest = Math.max(
|
|
678
|
+
1,
|
|
679
|
+
...groups
|
|
680
|
+
.filter((group) => group.kind !== "sizes")
|
|
681
|
+
.flatMap((group) =>
|
|
682
|
+
group.tokens.map(
|
|
683
|
+
(token) => pixelsOf(ctx.model.value(token.name, mode).value) ?? 0,
|
|
684
|
+
),
|
|
685
|
+
),
|
|
686
|
+
);
|
|
687
|
+
|
|
688
|
+
// A step or a role: a bar at its own scale (the longest step fills the tile). A size: a square of its own size.
|
|
689
|
+
const tileOf = (token, names, kind) => {
|
|
690
|
+
const now = ctx.model.value(token.name, mode);
|
|
691
|
+
const px = pixelsOf(now.value);
|
|
692
|
+
|
|
693
|
+
return html`${
|
|
694
|
+
kind === "sizes"
|
|
695
|
+
? html`<span class="dsy-space"
|
|
696
|
+
><i
|
|
697
|
+
class="dsy-size"
|
|
698
|
+
style=${`width:${Math.min(px ?? 0, 44)}px;height:${Math.min(px ?? 0, 44)}px`}
|
|
699
|
+
></i
|
|
700
|
+
></span>`
|
|
701
|
+
: html`<span class="dsy-space"
|
|
702
|
+
><i
|
|
703
|
+
style=${`width:${px === null ? 0 : Math.max(2, Math.min(100, (px / widest) * 100))}%`}
|
|
704
|
+
></i
|
|
705
|
+
></span>`
|
|
706
|
+
}
|
|
707
|
+
<span class="dsy-tile-name mono">${names.get(token.name)}</span>
|
|
708
|
+
<span class="dsy-tile-hex dsy-hex mono">${showValue(token, now)}</span>`;
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
return html`${groups.map(
|
|
712
|
+
(group) =>
|
|
713
|
+
html`<${Group}
|
|
714
|
+
key=${group.id}
|
|
715
|
+
ctx=${ctx}
|
|
716
|
+
group=${group}
|
|
717
|
+
note=${GROUP_NOTES[group.kind] ?? (group.kind === "roles" ? "where the system uses a step" : "")}
|
|
718
|
+
bare=${groups.length === 1}
|
|
719
|
+
>
|
|
720
|
+
${
|
|
721
|
+
group.kind === "roles"
|
|
722
|
+
? html`<${ByStep}
|
|
723
|
+
ctx=${ctx}
|
|
724
|
+
group=${group}
|
|
725
|
+
steps=${stepsOf(ctx, "spacing", "steps")}
|
|
726
|
+
size="space"
|
|
727
|
+
tile=${(token, names) => tileOf(token, names, "roles")}
|
|
728
|
+
/>`
|
|
729
|
+
: html`<${Tiles}
|
|
730
|
+
ctx=${ctx}
|
|
731
|
+
group=${group}
|
|
732
|
+
size="space"
|
|
733
|
+
tile=${(token) => tileOf(token, labelsOf(group), group.kind)}
|
|
734
|
+
/>`
|
|
735
|
+
}
|
|
736
|
+
<//>`,
|
|
737
|
+
)}`;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/** Tiles that open the editor of one token under the grid (roles, radii, shadows). `size` is the room each takes. */
|
|
741
|
+
/** Whether the one mode in view takes this token from the default mode, rather than setting it. */
|
|
742
|
+
const inheritedIn = (ctx, token) =>
|
|
743
|
+
ctx.modes.length === 1 &&
|
|
744
|
+
ctx.modes[0] !== ctx.model.defaultMode &&
|
|
745
|
+
!ctx.model.overridden(token.name, ctx.modes[0]);
|
|
746
|
+
|
|
747
|
+
function Tiles({ ctx, group, tile, label, extra, size = "sm" }) {
|
|
748
|
+
return html`<div class="dsy-ramp-wrap">
|
|
749
|
+
<div class="dsy-tiles" data-size=${size}>
|
|
750
|
+
${group.tokens.map((token) => {
|
|
751
|
+
const edited = ctx.modes.some((mode) => ctx.model.edited(token.name, mode));
|
|
752
|
+
const button = html`<button
|
|
753
|
+
type="button"
|
|
754
|
+
key=${token.name}
|
|
755
|
+
data-token=${token.name}
|
|
756
|
+
class=${`dsy-card-tile ${token.name === ctx.s.sysOpen ? "on" : ""} ${edited ? "edited" : ""} ${inheritedIn(ctx, token) ? "inherited" : ""}`}
|
|
757
|
+
title=${inheritedIn(ctx, token) ? `Inherited from ${modeTitle(ctx.model.defaultMode)}` : undefined}
|
|
758
|
+
aria-pressed=${token.name === ctx.s.sysOpen}
|
|
759
|
+
aria-label=${label ? label(token) : token.name}
|
|
760
|
+
onClick=${() => env.toggleToken(token.name)}
|
|
761
|
+
>
|
|
762
|
+
${tile(token)}
|
|
763
|
+
</button>`;
|
|
764
|
+
|
|
765
|
+
// What sits beside a tile and is a button of its own (a button does not hold another): the wrapper holds both.
|
|
766
|
+
return extra
|
|
767
|
+
? html`<div class="dsy-tile-wrap" key=${token.name}>
|
|
768
|
+
${button}${extra(token)}
|
|
769
|
+
</div>`
|
|
770
|
+
: button;
|
|
771
|
+
})}
|
|
772
|
+
</div>
|
|
773
|
+
<${Opened} ctx=${ctx} group=${group} />
|
|
774
|
+
</div>`;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function Radii({ ctx }) {
|
|
778
|
+
const groups = groupsFor(ctx, "radii");
|
|
779
|
+
const mode = ctx.modes[0];
|
|
780
|
+
|
|
781
|
+
if (groups.length === 0) {
|
|
782
|
+
return html`<${Empty}
|
|
783
|
+
text=${ctx.query ? "No radius matches." : "This system has no corner radii yet."}
|
|
784
|
+
/>`;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
const tileOf = (token, names) => {
|
|
788
|
+
const now = ctx.model.value(token.name, mode);
|
|
789
|
+
const px = pixelsOf(now.value);
|
|
790
|
+
|
|
791
|
+
return html`<span
|
|
792
|
+
class="dsy-corner"
|
|
793
|
+
style=${`border-radius:${px === null ? 0 : Math.min(px, 36)}px`}
|
|
794
|
+
></span>
|
|
795
|
+
<span class="dsy-tile-name mono">${names.get(token.name)}</span>
|
|
796
|
+
<span class="dsy-tile-hex mono">${showValue(token, now)}</span>`;
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
return html`${groups.map(
|
|
800
|
+
(group) =>
|
|
801
|
+
html`<${Group}
|
|
802
|
+
key=${group.id}
|
|
803
|
+
ctx=${ctx}
|
|
804
|
+
group=${group}
|
|
805
|
+
note=${GROUP_NOTES[group.kind] ?? (group.kind === "roles" ? "by use, under the step each points at" : "")}
|
|
806
|
+
bare=${groups.length === 1}
|
|
807
|
+
>
|
|
808
|
+
${
|
|
809
|
+
group.kind === "roles"
|
|
810
|
+
? html`<${ByStep}
|
|
811
|
+
ctx=${ctx}
|
|
812
|
+
group=${group}
|
|
813
|
+
steps=${stepsOf(ctx, "radii", "scale")}
|
|
814
|
+
size="sm"
|
|
815
|
+
tile=${tileOf}
|
|
816
|
+
/>`
|
|
817
|
+
: html`<${Tiles}
|
|
818
|
+
ctx=${ctx}
|
|
819
|
+
group=${group}
|
|
820
|
+
tile=${(token) => tileOf(token, labelsOf(group))}
|
|
821
|
+
/>`
|
|
822
|
+
}
|
|
823
|
+
<//>`,
|
|
824
|
+
)}`;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/** Every layer of a shadow, one line each, with its color: and, side by side, each mode's when they differ. */
|
|
828
|
+
function ShadowLines({ ctx, token }) {
|
|
829
|
+
const sets = ctx.modes.map((mode) => ({
|
|
830
|
+
mode,
|
|
831
|
+
lines: shadowLines(ctx.model.value(token.name, mode).value),
|
|
832
|
+
}));
|
|
833
|
+
const same = sets.every(
|
|
834
|
+
(set) => JSON.stringify(set.lines) === JSON.stringify(sets[0].lines),
|
|
835
|
+
);
|
|
836
|
+
|
|
837
|
+
return html`<span class="dsy-shadow-lines">
|
|
838
|
+
${(same ? [sets[0]] : sets).map(
|
|
839
|
+
(set) =>
|
|
840
|
+
html`<span class="dsy-shadow-set" key=${set.mode}>
|
|
841
|
+
${!same && html`<em>${modeTitle(set.mode)}</em>`}
|
|
842
|
+
${set.lines.map(
|
|
843
|
+
(line, at) =>
|
|
844
|
+
html`<span class="dsy-shadow-line" key=${at}>
|
|
845
|
+
<i
|
|
846
|
+
style=${`--c:${swatchCss(line.color)}`}
|
|
847
|
+
title=${typeof line.color === "string" ? line.color : undefined}
|
|
848
|
+
aria-hidden="true"
|
|
849
|
+
></i>
|
|
850
|
+
<span class="mono">${line.words}</span>
|
|
851
|
+
</span>`,
|
|
852
|
+
)}
|
|
853
|
+
</span>`,
|
|
854
|
+
)}
|
|
855
|
+
</span>`;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
function Shadows({ ctx }) {
|
|
859
|
+
const groups = groupsFor(ctx, "shadows");
|
|
860
|
+
const found = ctx.model.roles();
|
|
861
|
+
|
|
862
|
+
if (groups.length === 0) {
|
|
863
|
+
return html`<${Empty}
|
|
864
|
+
text=${ctx.query ? "No shadow matches." : "This system has no shadows yet."}
|
|
865
|
+
/>`;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
return html`${groups.map(
|
|
869
|
+
(group) =>
|
|
870
|
+
html`<${Group}
|
|
871
|
+
key=${group.id}
|
|
872
|
+
ctx=${ctx}
|
|
873
|
+
group=${group}
|
|
874
|
+
bare=${groups.length === 1}
|
|
875
|
+
>
|
|
876
|
+
<${Tiles}
|
|
877
|
+
ctx=${ctx}
|
|
878
|
+
group=${group}
|
|
879
|
+
size="shadow"
|
|
880
|
+
tile=${(token) =>
|
|
881
|
+
html`<span class="dsy-stages">
|
|
882
|
+
${ctx.modes.map((mode) => {
|
|
883
|
+
const now = ctx.model.value(token.name, mode);
|
|
884
|
+
const ground = found.canvas
|
|
885
|
+
? swatchCss(ctx.model.value(found.canvas, mode).value)
|
|
886
|
+
: "";
|
|
887
|
+
const card = found.surface
|
|
888
|
+
? swatchCss(ctx.model.value(found.surface, mode).value)
|
|
889
|
+
: "";
|
|
890
|
+
|
|
891
|
+
return html`<span
|
|
892
|
+
class="dsy-stage"
|
|
893
|
+
key=${mode}
|
|
894
|
+
style=${ground ? `background:${ground}` : ""}
|
|
895
|
+
>
|
|
896
|
+
<i
|
|
897
|
+
style=${`${card ? `background:${card};` : ""}box-shadow:${shadowOf(now.value) || "none"}`}
|
|
898
|
+
></i>
|
|
899
|
+
</span>`;
|
|
900
|
+
})}
|
|
901
|
+
</span>
|
|
902
|
+
<span class="dsy-tile-name mono"
|
|
903
|
+
>${tails(group.tokens).get(token.name)}</span
|
|
904
|
+
>
|
|
905
|
+
<${ShadowLines} ctx=${ctx} token=${token} />`}
|
|
906
|
+
extra=${(token) =>
|
|
907
|
+
html`<button
|
|
908
|
+
type="button"
|
|
909
|
+
class="dsy-copy"
|
|
910
|
+
title="Copy the CSS value"
|
|
911
|
+
aria-label=${`Copy the CSS value of ${token.name}`}
|
|
912
|
+
onClick=${async () => {
|
|
913
|
+
const css = shadowOf(
|
|
914
|
+
ctx.model.value(token.name, ctx.modes[0]).value,
|
|
915
|
+
);
|
|
916
|
+
|
|
917
|
+
if (css && (await copyText(css))) {
|
|
918
|
+
pocket.notify(
|
|
919
|
+
"info",
|
|
920
|
+
`Copied ${css.length > 60 ? `${css.slice(0, 60)}…` : css}`,
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
}}
|
|
924
|
+
>
|
|
925
|
+
<${Ico} name="copy" size=${13} />
|
|
926
|
+
</button>`}
|
|
927
|
+
/>
|
|
928
|
+
<//>`,
|
|
929
|
+
)}`;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// ─── Motion ──────────────────────────────────────────────────────────────
|
|
933
|
+
|
|
934
|
+
/** A dot that runs along a track once, there and back, for `ms` with `easing`. */
|
|
935
|
+
function useRun() {
|
|
936
|
+
const dot = useRef(null);
|
|
937
|
+
const track = useRef(null);
|
|
938
|
+
|
|
939
|
+
return {
|
|
940
|
+
dot,
|
|
941
|
+
track,
|
|
942
|
+
run(ms, easing) {
|
|
943
|
+
const element = dot.current;
|
|
944
|
+
const room = track.current;
|
|
945
|
+
|
|
946
|
+
if (!element || !room || typeof element.animate !== "function") {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
for (const animation of element.getAnimations()) {
|
|
951
|
+
animation.cancel();
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
const distance = Math.max(0, room.clientWidth - element.clientWidth);
|
|
955
|
+
|
|
956
|
+
element.animate(
|
|
957
|
+
[{ transform: "translateX(0)" }, { transform: `translateX(${distance}px)` }],
|
|
958
|
+
{
|
|
959
|
+
duration: Math.max(1, Math.min(5000, ms)),
|
|
960
|
+
easing,
|
|
961
|
+
direction: "alternate",
|
|
962
|
+
iterations: 2,
|
|
963
|
+
delay: 0,
|
|
964
|
+
endDelay: 120,
|
|
965
|
+
},
|
|
966
|
+
);
|
|
967
|
+
},
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
function Track({ motion }) {
|
|
972
|
+
return html`<span class="dsy-track" ref=${motion.track}><i ref=${motion.dot}></i></span>`;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
function DurationRow({ ctx, token, easing }) {
|
|
976
|
+
const motion = useRun();
|
|
977
|
+
const now = ctx.model.value(token.name, ctx.modes[0]);
|
|
978
|
+
const ms = millisecondsOf(now.value);
|
|
979
|
+
|
|
980
|
+
return html`<${TokenRow}
|
|
981
|
+
ctx=${ctx}
|
|
982
|
+
token=${token}
|
|
983
|
+
visual=${html`<button
|
|
984
|
+
type="button"
|
|
985
|
+
class="dsy-play"
|
|
986
|
+
aria-label=${`Play ${token.name}`}
|
|
987
|
+
disabled=${ms === null}
|
|
988
|
+
onClick=${(event) => {
|
|
989
|
+
event.stopPropagation();
|
|
990
|
+
motion.run(ms ?? 0, easing);
|
|
991
|
+
}}
|
|
992
|
+
>
|
|
993
|
+
<${Ico} name="play" size=${14} />
|
|
994
|
+
</button>`}
|
|
995
|
+
sub=${html`<${Track} motion=${motion} />`}
|
|
996
|
+
value=${html`<span class="dsy-hex mono">${showValue(token, now)}</span>`}
|
|
997
|
+
/>`;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function EasingRow({ ctx, token }) {
|
|
1001
|
+
const motion = useRun();
|
|
1002
|
+
const now = ctx.model.value(token.name, ctx.modes[0]);
|
|
1003
|
+
const curve = Array.isArray(now.value) && now.value.length === 4 ? now.value : null;
|
|
1004
|
+
const css = cssOf("cubicBezier", now.value);
|
|
1005
|
+
|
|
1006
|
+
return html`<${TokenRow}
|
|
1007
|
+
ctx=${ctx}
|
|
1008
|
+
token=${token}
|
|
1009
|
+
visual=${curve ? html`<${Curve} value=${curve} size=${56} />` : null}
|
|
1010
|
+
sub=${html`<span class="dsy-motion-sub"><span class="mono">${showValue(token, now)}</span><${Track} motion=${motion} /></span>`}
|
|
1011
|
+
value=${html`<button
|
|
1012
|
+
type="button"
|
|
1013
|
+
class="dsy-play"
|
|
1014
|
+
aria-label=${`Play ${token.name}`}
|
|
1015
|
+
disabled=${css === undefined}
|
|
1016
|
+
onClick=${(event) => {
|
|
1017
|
+
event.stopPropagation();
|
|
1018
|
+
motion.run(900, css);
|
|
1019
|
+
}}
|
|
1020
|
+
>
|
|
1021
|
+
<${Ico} name="play" size=${14} />
|
|
1022
|
+
</button>`}
|
|
1023
|
+
/>`;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
function Motion({ ctx }) {
|
|
1027
|
+
const groups = groupsFor(ctx, "motion");
|
|
1028
|
+
|
|
1029
|
+
if (groups.length === 0) {
|
|
1030
|
+
return html`<${Empty}
|
|
1031
|
+
text=${ctx.query ? "No motion token matches." : "This system has no motion yet."}
|
|
1032
|
+
/>`;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// Durations play on the first easing the system has.
|
|
1036
|
+
const first = ctx.model.tokens.find((token) => token.type === "cubicBezier");
|
|
1037
|
+
const easing =
|
|
1038
|
+
(first && cssOf("cubicBezier", ctx.model.value(first.name, ctx.modes[0]).value)) ||
|
|
1039
|
+
"ease";
|
|
1040
|
+
|
|
1041
|
+
return html`${groups.map(
|
|
1042
|
+
(group) =>
|
|
1043
|
+
html`<${Group} key=${group.id} ctx=${ctx} group=${group}>
|
|
1044
|
+
<ul class="dsy-rows">
|
|
1045
|
+
${group.tokens.map((token) =>
|
|
1046
|
+
token.type === "duration"
|
|
1047
|
+
? html`<${DurationRow}
|
|
1048
|
+
key=${token.name}
|
|
1049
|
+
ctx=${ctx}
|
|
1050
|
+
token=${token}
|
|
1051
|
+
easing=${easing}
|
|
1052
|
+
/>`
|
|
1053
|
+
: token.type === "cubicBezier"
|
|
1054
|
+
? html`<${EasingRow}
|
|
1055
|
+
key=${token.name}
|
|
1056
|
+
ctx=${ctx}
|
|
1057
|
+
token=${token}
|
|
1058
|
+
/>`
|
|
1059
|
+
: html`<${TokenRow}
|
|
1060
|
+
key=${token.name}
|
|
1061
|
+
ctx=${ctx}
|
|
1062
|
+
token=${token}
|
|
1063
|
+
value=${html`<span class="dsy-hex mono">${showValue(token, ctx.model.value(token.name, ctx.modes[0]))}</span>`}
|
|
1064
|
+
/>`,
|
|
1065
|
+
)}
|
|
1066
|
+
</ul>
|
|
1067
|
+
<//>`,
|
|
1068
|
+
)}`;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
function Other({ ctx }) {
|
|
1072
|
+
const groups = groupsFor(ctx, "other");
|
|
1073
|
+
|
|
1074
|
+
return html`${groups.map(
|
|
1075
|
+
(group) =>
|
|
1076
|
+
html`<${Group} key=${group.id} ctx=${ctx} group=${group}>
|
|
1077
|
+
<ul class="dsy-rows">
|
|
1078
|
+
${group.tokens.map((token) => {
|
|
1079
|
+
const now = ctx.model.value(token.name, ctx.modes[0]);
|
|
1080
|
+
|
|
1081
|
+
return html`<${TokenRow}
|
|
1082
|
+
key=${token.name}
|
|
1083
|
+
ctx=${ctx}
|
|
1084
|
+
token=${token}
|
|
1085
|
+
sub=${token.description ?? ""}
|
|
1086
|
+
value=${html`<span class="dsy-hex mono">${showValue(token, now)}</span>`}
|
|
1087
|
+
/>`;
|
|
1088
|
+
})}
|
|
1089
|
+
</ul>
|
|
1090
|
+
<//>`,
|
|
1091
|
+
)}`;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// ─── Components ──────────────────────────────────────────────────────────
|
|
1095
|
+
|
|
1096
|
+
/** One component in one mode: its states in a frame with no scripts and no network. The frame grows to fit them. */
|
|
1097
|
+
function Specimen({ ctx, component, mode }) {
|
|
1098
|
+
const frame = useRef(null);
|
|
1099
|
+
const found = ctx.model.roles();
|
|
1100
|
+
const color = (role, fallback) =>
|
|
1101
|
+
(found[role] ? swatchCss(ctx.model.value(found[role], mode).value) : "") || fallback;
|
|
1102
|
+
const scheme = ctx.model.system.schemes?.[mode];
|
|
1103
|
+
const dark = scheme === undefined ? /dark/i.test(mode) : scheme === "dark";
|
|
1104
|
+
const doc = specimenDocument({
|
|
1105
|
+
component,
|
|
1106
|
+
mode,
|
|
1107
|
+
scheme,
|
|
1108
|
+
theme: themeCss(ctx.model, mode),
|
|
1109
|
+
colors: {
|
|
1110
|
+
canvas: color("canvas", dark ? "#12131a" : "#f6f7fb"),
|
|
1111
|
+
surface: color("surface", dark ? "#1c1e26" : "#ffffff"),
|
|
1112
|
+
text: color("text", dark ? "#f6f7fb" : "#1c1e26"),
|
|
1113
|
+
},
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
// No scripts and no network (a policy in the document, and no `allow-scripts`). `allow-same-origin` is only so that the
|
|
1117
|
+
// page can read the frame's height once it loads: nothing in the frame can run to use it.
|
|
1118
|
+
return html`<iframe
|
|
1119
|
+
ref=${frame}
|
|
1120
|
+
class="dsy-specimen-frame"
|
|
1121
|
+
title=${`${component.name}, ${mode}`}
|
|
1122
|
+
sandbox="allow-same-origin"
|
|
1123
|
+
referrerpolicy="no-referrer"
|
|
1124
|
+
srcdoc=${doc}
|
|
1125
|
+
loading="lazy"
|
|
1126
|
+
onLoad=${() => {
|
|
1127
|
+
const body = frame.current?.contentDocument?.body;
|
|
1128
|
+
|
|
1129
|
+
if (body && frame.current) {
|
|
1130
|
+
frame.current.style.height = `${Math.min(900, Math.max(60, Math.ceil(body.getBoundingClientRect().height)))}px`;
|
|
1131
|
+
}
|
|
1132
|
+
}}
|
|
1133
|
+
></iframe>`;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
function Components({ ctx }) {
|
|
1137
|
+
const list = ctx.model.system.components.filter((component) => {
|
|
1138
|
+
const words = ctx.query.trim().toLowerCase();
|
|
1139
|
+
|
|
1140
|
+
return (
|
|
1141
|
+
words === "" ||
|
|
1142
|
+
`${component.name} ${component.description} ${component.slug}`
|
|
1143
|
+
.toLowerCase()
|
|
1144
|
+
.includes(words)
|
|
1145
|
+
);
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
if (list.length === 0) {
|
|
1149
|
+
return html`<div class="dsy-blank">
|
|
1150
|
+
<${Ico} name="box" size=${28} />
|
|
1151
|
+
<h3>${ctx.query ? "No component matches." : "No components yet"}</h3>
|
|
1152
|
+
${
|
|
1153
|
+
!ctx.query &&
|
|
1154
|
+
html`<p class="muted">
|
|
1155
|
+
A component is a button, a field, or a card, written once with the system's
|
|
1156
|
+
tokens, with each of its states (default, hover, focus, disabled, error). Pi
|
|
1157
|
+
reuses their markup in designs.
|
|
1158
|
+
</p>`
|
|
1159
|
+
}
|
|
1160
|
+
${
|
|
1161
|
+
!ctx.query &&
|
|
1162
|
+
ctx.canEdit &&
|
|
1163
|
+
html`<button
|
|
1164
|
+
type="button"
|
|
1165
|
+
class="button primary"
|
|
1166
|
+
onClick=${() => env.askPi("components")}
|
|
1167
|
+
>
|
|
1168
|
+
<${Ico} name="sparkle" size=${15} /> Ask Pi for the core components
|
|
1169
|
+
</button>`
|
|
1170
|
+
}
|
|
1171
|
+
</div>`;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
return html`${list.map(
|
|
1175
|
+
(component) =>
|
|
1176
|
+
html`<article class="dsy-component" key=${component.slug}>
|
|
1177
|
+
<header>
|
|
1178
|
+
<h3>${component.name}</h3>
|
|
1179
|
+
<span class="dsy-chip-static mono"
|
|
1180
|
+
>${`${component.states.length} state${component.states.length === 1 ? "" : "s"}`}</span
|
|
1181
|
+
>
|
|
1182
|
+
<span class="grow"></span>
|
|
1183
|
+
<${CopyName} name=${component.slug} copy=${component.slug} />
|
|
1184
|
+
</header>
|
|
1185
|
+
${component.description && html`<p class="muted dsy-component-note">${component.description}</p>`}
|
|
1186
|
+
<div class="dsy-specimens" data-count=${ctx.modes.length}>
|
|
1187
|
+
${ctx.modes.map(
|
|
1188
|
+
(mode) =>
|
|
1189
|
+
html`<div class="dsy-specimen-box" key=${mode}>
|
|
1190
|
+
${ctx.modes.length > 1 && html`<span class="dsy-specimen-mode mono">${mode}</span>`}
|
|
1191
|
+
<${Specimen} ctx=${ctx} component=${component} mode=${mode} />
|
|
1192
|
+
</div>`,
|
|
1193
|
+
)}
|
|
1194
|
+
</div>
|
|
1195
|
+
${
|
|
1196
|
+
component.usage &&
|
|
1197
|
+
(component.usage.do.length > 0 || component.usage.dont.length > 0) &&
|
|
1198
|
+
html`<div class="dsy-usage">
|
|
1199
|
+
${
|
|
1200
|
+
component.usage.do.length > 0 &&
|
|
1201
|
+
html`<ul class="do">
|
|
1202
|
+
${component.usage.do.slice(0, 6).map((line) => html`<li>${line}</li>`)}
|
|
1203
|
+
</ul>`
|
|
1204
|
+
}
|
|
1205
|
+
${
|
|
1206
|
+
component.usage.dont.length > 0 &&
|
|
1207
|
+
html`<ul class="dont">
|
|
1208
|
+
${component.usage.dont.slice(0, 6).map((line) => html`<li>${line}</li>`)}
|
|
1209
|
+
</ul>`
|
|
1210
|
+
}
|
|
1211
|
+
</div>`
|
|
1212
|
+
}
|
|
1213
|
+
${
|
|
1214
|
+
component.tokens.length > 0 &&
|
|
1215
|
+
html`<div class="dsy-used">
|
|
1216
|
+
${component.tokens
|
|
1217
|
+
.slice(0, 8)
|
|
1218
|
+
.map(
|
|
1219
|
+
(name) =>
|
|
1220
|
+
html`<button
|
|
1221
|
+
type="button"
|
|
1222
|
+
class="dsy-chip"
|
|
1223
|
+
key=${name}
|
|
1224
|
+
disabled=${!ctx.model.has(name)}
|
|
1225
|
+
onClick=${() => env.openToken(name)}
|
|
1226
|
+
>
|
|
1227
|
+
${name}
|
|
1228
|
+
</button>`,
|
|
1229
|
+
)}
|
|
1230
|
+
${
|
|
1231
|
+
component.tokens.length > 8 &&
|
|
1232
|
+
html`<span class="muted small dsy-used-more"
|
|
1233
|
+
>${`and ${component.tokens.length - 8} more`}</span
|
|
1234
|
+
>`
|
|
1235
|
+
}
|
|
1236
|
+
</div>`
|
|
1237
|
+
}
|
|
1238
|
+
</article>`,
|
|
1239
|
+
)}
|
|
1240
|
+
${
|
|
1241
|
+
ctx.canEdit &&
|
|
1242
|
+
ctx.query === "" &&
|
|
1243
|
+
html`<button
|
|
1244
|
+
type="button"
|
|
1245
|
+
class="dsn-link dsy-more"
|
|
1246
|
+
onClick=${() => env.askPi("component")}
|
|
1247
|
+
>
|
|
1248
|
+
<${Ico} name="sparkle" size=${14} /> Ask Pi for another component
|
|
1249
|
+
</button>`
|
|
1250
|
+
}`;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// ─── Guidelines ──────────────────────────────────────────────────────────
|
|
1254
|
+
|
|
1255
|
+
function Guidelines({ ctx }) {
|
|
1256
|
+
const text = ctx.guidelines;
|
|
1257
|
+
const writing = ctx.s.sysWriting;
|
|
1258
|
+
const [draft, setDraft] = useState(null);
|
|
1259
|
+
const area = useRef(null);
|
|
1260
|
+
|
|
1261
|
+
useEffect(() => {
|
|
1262
|
+
if (writing) {
|
|
1263
|
+
area.current?.focus({ preventScroll: true });
|
|
1264
|
+
}
|
|
1265
|
+
}, [writing]);
|
|
1266
|
+
|
|
1267
|
+
if (writing && ctx.canEdit) {
|
|
1268
|
+
return html`<div class="dsy-write">
|
|
1269
|
+
<textarea
|
|
1270
|
+
ref=${area}
|
|
1271
|
+
class="mono"
|
|
1272
|
+
value=${draft ?? text}
|
|
1273
|
+
maxlength="16000"
|
|
1274
|
+
spellcheck="true"
|
|
1275
|
+
aria-label="Guidelines, in Markdown"
|
|
1276
|
+
onInput=${(event) => {
|
|
1277
|
+
setDraft(event.currentTarget.value);
|
|
1278
|
+
env.editGuidelines(event.currentTarget.value);
|
|
1279
|
+
}}
|
|
1280
|
+
></textarea>
|
|
1281
|
+
<div class="dsy-write-foot">
|
|
1282
|
+
<span class="muted small"
|
|
1283
|
+
>${(draft ?? text).length.toLocaleString()} of 16,000 characters.
|
|
1284
|
+
Markdown.</span
|
|
1285
|
+
>
|
|
1286
|
+
<span class="grow"></span>
|
|
1287
|
+
<button
|
|
1288
|
+
type="button"
|
|
1289
|
+
class="button small"
|
|
1290
|
+
onClick=${() => store.set({ sysWriting: false })}
|
|
1291
|
+
>
|
|
1292
|
+
Done
|
|
1293
|
+
</button>
|
|
1294
|
+
</div>
|
|
1295
|
+
</div>`;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
if (text.trim() === "") {
|
|
1299
|
+
return html`<div class="dsy-blank">
|
|
1300
|
+
<${Ico} name="book" size=${28} />
|
|
1301
|
+
<h3>No guidelines yet</h3>
|
|
1302
|
+
<p class="muted">
|
|
1303
|
+
Guidelines are the rules in words: the voice, the layout, what to do and what
|
|
1304
|
+
not to do. Pi reads them before it designs.
|
|
1305
|
+
</p>
|
|
1306
|
+
${
|
|
1307
|
+
ctx.canEdit &&
|
|
1308
|
+
html`<div class="dsy-blank-actions">
|
|
1309
|
+
<button
|
|
1310
|
+
type="button"
|
|
1311
|
+
class="button primary"
|
|
1312
|
+
onClick=${() => store.set({ sysWriting: true })}
|
|
1313
|
+
>
|
|
1314
|
+
<${Ico} name="pen" size=${15} /> Write them
|
|
1315
|
+
</button>
|
|
1316
|
+
<button
|
|
1317
|
+
type="button"
|
|
1318
|
+
class="button"
|
|
1319
|
+
onClick=${() => env.askPi("guidelines")}
|
|
1320
|
+
>
|
|
1321
|
+
<${Ico} name="sparkle" size=${15} /> Ask Pi
|
|
1322
|
+
</button>
|
|
1323
|
+
</div>`
|
|
1324
|
+
}
|
|
1325
|
+
</div>`;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
return html`<article class="dsy-prose">
|
|
1329
|
+
${
|
|
1330
|
+
ctx.canEdit &&
|
|
1331
|
+
html`<button
|
|
1332
|
+
type="button"
|
|
1333
|
+
class="dsn-link dsy-edit-guidelines"
|
|
1334
|
+
onClick=${() => store.set({ sysWriting: true })}
|
|
1335
|
+
>
|
|
1336
|
+
<${Ico} name="pen" size=${13} /> Edit
|
|
1337
|
+
</button>`
|
|
1338
|
+
}
|
|
1339
|
+
<${Markdown} text=${text} />
|
|
1340
|
+
</article>`;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
return { Colors, Type, Spacing, Radii, Shadows, Motion, Other, Components, Guidelines };
|
|
1344
|
+
}
|