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,942 @@
|
|
|
1
|
+
// The small parts of the System view: a swatch, a token's name that copies, a contrast badge, number and color fields, the
|
|
2
|
+
// alias picker, and the editor of one token. They draw what `system.js` computes; they keep no state of the system's own.
|
|
3
|
+
import { parseColor, ratioText, swatchCss, toHex, toOklchText, toRgbText } from "./color.js";
|
|
4
|
+
import {
|
|
5
|
+
amountOf,
|
|
6
|
+
EDITABLE,
|
|
7
|
+
linkOf,
|
|
8
|
+
readInput,
|
|
9
|
+
shadowValue,
|
|
10
|
+
showValue,
|
|
11
|
+
withPart,
|
|
12
|
+
writeAmount,
|
|
13
|
+
} from "./system.js";
|
|
14
|
+
|
|
15
|
+
/** Put `text` on the clipboard: the async API where the page may use it, else a hidden field and a copy command. */
|
|
16
|
+
export async function copyText(text) {
|
|
17
|
+
try {
|
|
18
|
+
await navigator.clipboard.writeText(text);
|
|
19
|
+
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
const field = document.createElement("textarea");
|
|
23
|
+
|
|
24
|
+
field.value = text;
|
|
25
|
+
field.setAttribute("readonly", "");
|
|
26
|
+
field.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none";
|
|
27
|
+
document.body.append(field);
|
|
28
|
+
field.select();
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
return document.execCommand("copy");
|
|
32
|
+
} finally {
|
|
33
|
+
field.remove();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The word for a contrast: its level when it passes, else how far it gets. A pair that is exempt (a disabled or decorative
|
|
40
|
+
* color) is not a failure: it says so.
|
|
41
|
+
*/
|
|
42
|
+
export const verdictOf = (info) =>
|
|
43
|
+
info.pass
|
|
44
|
+
? info.level
|
|
45
|
+
: info.exempt
|
|
46
|
+
? "Exempt"
|
|
47
|
+
: info.level === "AA large"
|
|
48
|
+
? "Large only"
|
|
49
|
+
: "Fail";
|
|
50
|
+
|
|
51
|
+
/** The title-cased name of a mode (`high-contrast` → `High contrast`). */
|
|
52
|
+
export const modeTitle = (mode) =>
|
|
53
|
+
mode === "" ? "" : mode[0].toUpperCase() + mode.slice(1).replace(/[-_]+/g, " ");
|
|
54
|
+
|
|
55
|
+
const UNITS = { dimension: ["px", "rem", "em"], duration: ["ms", "s"] };
|
|
56
|
+
const round = (value) => Math.round(value * 10000) / 10000;
|
|
57
|
+
|
|
58
|
+
export function createSystemWidgets(env) {
|
|
59
|
+
const { pocket } = env;
|
|
60
|
+
const { html, useState } = pocket;
|
|
61
|
+
const { Ico, Popover } = env.parts;
|
|
62
|
+
|
|
63
|
+
/** A color, or a pair of them (a split swatch: one half for each mode). */
|
|
64
|
+
function Swatch({ values, size = 36 }) {
|
|
65
|
+
return html`<span
|
|
66
|
+
class="dsy-swatch"
|
|
67
|
+
style=${`--size:${size}px`}
|
|
68
|
+
data-parts=${values.length}
|
|
69
|
+
aria-hidden="true"
|
|
70
|
+
>
|
|
71
|
+
${values.map((value, index) => {
|
|
72
|
+
const css = swatchCss(value);
|
|
73
|
+
|
|
74
|
+
return html`<span
|
|
75
|
+
key=${index}
|
|
76
|
+
class="dsy-swatch-part"
|
|
77
|
+
data-empty=${css === ""}
|
|
78
|
+
style=${css === "" ? "" : `background:${css}`}
|
|
79
|
+
></span>`;
|
|
80
|
+
})}
|
|
81
|
+
</span>`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A token's name, which copies on a tap: its last word strong, the rest of the path quiet. */
|
|
85
|
+
function CopyName({ name, copy = name, size = "" }) {
|
|
86
|
+
const [done, setDone] = useState(false);
|
|
87
|
+
const parts = name.split(".");
|
|
88
|
+
const leaf = parts.pop();
|
|
89
|
+
|
|
90
|
+
return html`<button
|
|
91
|
+
type="button"
|
|
92
|
+
class=${`dsy-name ${size}`}
|
|
93
|
+
title=${`Copy ${copy}`}
|
|
94
|
+
aria-label=${`Copy ${copy}`}
|
|
95
|
+
onClick=${async (event) => {
|
|
96
|
+
event.stopPropagation();
|
|
97
|
+
|
|
98
|
+
if (await copyText(copy)) {
|
|
99
|
+
setDone(true);
|
|
100
|
+
setTimeout(() => setDone(false), 1400);
|
|
101
|
+
pocket.notify("info", `Copied ${copy}`);
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<span class="dsy-name-path">${parts.map((part) => html`${part}.<wbr />`)}</span
|
|
106
|
+
><span class="dsy-name-leaf">${leaf}</span>
|
|
107
|
+
<span class=${`dsy-name-icon ${done ? "done" : ""}`}
|
|
108
|
+
><${Ico} name=${done ? "check" : "copy"} size=${12}
|
|
109
|
+
/></span>
|
|
110
|
+
</button>`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** What a text color's contrast comes to on its pair: `7.1:1 AAA`. A token with no pair of its own shows dashed. */
|
|
114
|
+
function ContrastBadge({ info, mode, modes = 1 }) {
|
|
115
|
+
if (!info) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const verdict = verdictOf(info);
|
|
120
|
+
const exempt = !info.pass && info.exempt !== undefined;
|
|
121
|
+
const kind = info.pass ? (info.level === "AAA" ? "aaa" : "aa") : exempt ? "exempt" : "fail";
|
|
122
|
+
|
|
123
|
+
return html`<span
|
|
124
|
+
class=${`dsy-badge ${kind} ${info.auto ? "auto" : ""}`}
|
|
125
|
+
title=${`${mode ? `${modeTitle(mode)}: ` : ""}${ratioText(info.ratio)} on ${info.on}. It needs ${info.min}:1.${exempt ? ` The pair is exempt (${info.exempt}): that is not a failure.` : ""}${info.auto ? " Checked against the page background: this color has no pair of its own." : ""}`}
|
|
126
|
+
>
|
|
127
|
+
${modes > 1 && html`<span class="dsy-badge-mode">${modeTitle(mode).slice(0, 1)}</span>`}
|
|
128
|
+
<span class="dsy-badge-ratio">${ratioText(info.ratio)}</span>
|
|
129
|
+
<span class="dsy-badge-level">${verdict}</span>
|
|
130
|
+
</span>`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A number with steppers and, for sizes and times, a unit. `onChange` gets `{ n, unit }`. */
|
|
134
|
+
function AmountField({ amount, units, step = 1, label, onChange, disabled }) {
|
|
135
|
+
const [text, setText] = useState(null);
|
|
136
|
+
const shown = text ?? String(amount.n);
|
|
137
|
+
const set = (n, unit = amount.unit) => onChange({ n: round(n), unit });
|
|
138
|
+
|
|
139
|
+
// The unit changes by what it is worth: 16px is 1rem.
|
|
140
|
+
const convert = (unit) => {
|
|
141
|
+
const per = { px: 1, rem: 16, em: 16, ms: 1, s: 1000 };
|
|
142
|
+
|
|
143
|
+
if (per[amount.unit] && per[unit] && amount.unit !== unit) {
|
|
144
|
+
set((amount.n * per[amount.unit]) / per[unit], unit);
|
|
145
|
+
} else {
|
|
146
|
+
set(amount.n, unit);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return html`<div class="dsy-amount">
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
class="dsy-step"
|
|
154
|
+
aria-label=${`Decrease ${label}`}
|
|
155
|
+
disabled=${disabled}
|
|
156
|
+
onClick=${() => set(amount.n - step)}
|
|
157
|
+
>
|
|
158
|
+
<${Ico} name="minus" size=${14} />
|
|
159
|
+
</button>
|
|
160
|
+
<input
|
|
161
|
+
type="text"
|
|
162
|
+
inputmode="decimal"
|
|
163
|
+
class="mono"
|
|
164
|
+
value=${shown}
|
|
165
|
+
disabled=${disabled}
|
|
166
|
+
aria-label=${label}
|
|
167
|
+
spellcheck="false"
|
|
168
|
+
onInput=${(event) => {
|
|
169
|
+
const value = event.currentTarget.value;
|
|
170
|
+
const next = amountOf(value);
|
|
171
|
+
|
|
172
|
+
setText(value);
|
|
173
|
+
|
|
174
|
+
if (next !== null && (units === undefined ? next.unit === "" : true)) {
|
|
175
|
+
set(next.n, next.unit === "" ? amount.unit : next.unit);
|
|
176
|
+
}
|
|
177
|
+
}}
|
|
178
|
+
onBlur=${() => setText(null)}
|
|
179
|
+
onKeyDown=${(event) => {
|
|
180
|
+
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
set(
|
|
183
|
+
amount.n +
|
|
184
|
+
(event.key === "ArrowUp" ? step : -step) *
|
|
185
|
+
(event.shiftKey ? 10 : 1),
|
|
186
|
+
);
|
|
187
|
+
setText(null);
|
|
188
|
+
}
|
|
189
|
+
}}
|
|
190
|
+
/>
|
|
191
|
+
<button
|
|
192
|
+
type="button"
|
|
193
|
+
class="dsy-step"
|
|
194
|
+
aria-label=${`Increase ${label}`}
|
|
195
|
+
disabled=${disabled}
|
|
196
|
+
onClick=${() => set(amount.n + step)}
|
|
197
|
+
>
|
|
198
|
+
<${Ico} name="plus" size=${14} />
|
|
199
|
+
</button>
|
|
200
|
+
${
|
|
201
|
+
units &&
|
|
202
|
+
html`<select
|
|
203
|
+
class="dsy-unit"
|
|
204
|
+
value=${amount.unit}
|
|
205
|
+
disabled=${disabled}
|
|
206
|
+
aria-label=${`${label}: unit`}
|
|
207
|
+
onChange=${(event) => convert(event.currentTarget.value)}
|
|
208
|
+
>
|
|
209
|
+
${(units.includes(amount.unit) ? units : [amount.unit, ...units]).map(
|
|
210
|
+
(unit) => html`<option value=${unit}>${unit}</option>`,
|
|
211
|
+
)}
|
|
212
|
+
</select>`
|
|
213
|
+
}
|
|
214
|
+
</div>`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const FORMATS = ["hex", "oklch", "rgb"];
|
|
218
|
+
|
|
219
|
+
/** A color: the system's picker, and a field that takes any CSS color. `onChange` gets the new DTCG value. */
|
|
220
|
+
function ColorField({ value, like, label, onChange, disabled }) {
|
|
221
|
+
const [draft, setDraft] = useState(null);
|
|
222
|
+
const [format, setFormat] = useState("hex");
|
|
223
|
+
const color = parseColor(value);
|
|
224
|
+
const text =
|
|
225
|
+
color === null
|
|
226
|
+
? ""
|
|
227
|
+
: format === "oklch"
|
|
228
|
+
? toOklchText(color)
|
|
229
|
+
: format === "rgb"
|
|
230
|
+
? toRgbText(color)
|
|
231
|
+
: toHex(color);
|
|
232
|
+
const problem = draft === null ? "" : (readInput("color", draft, like).error ?? "");
|
|
233
|
+
|
|
234
|
+
const take = (input) => {
|
|
235
|
+
const result = readInput("color", input, like);
|
|
236
|
+
|
|
237
|
+
if (result.value !== undefined) {
|
|
238
|
+
onChange(result.value);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
return html`<div class="dsy-colorfield">
|
|
243
|
+
<label class="dsy-well" style=${color ? `--well:${swatchCss(value)}` : ""}>
|
|
244
|
+
<input
|
|
245
|
+
type="color"
|
|
246
|
+
value=${color ? toHex({ ...color, a: 1 }) : "#000000"}
|
|
247
|
+
disabled=${disabled}
|
|
248
|
+
aria-label=${`${label}: pick`}
|
|
249
|
+
onInput=${(event) => take(event.currentTarget.value)}
|
|
250
|
+
/>
|
|
251
|
+
</label>
|
|
252
|
+
<input
|
|
253
|
+
type="text"
|
|
254
|
+
class=${`mono ${problem ? "bad" : ""}`}
|
|
255
|
+
value=${draft ?? text}
|
|
256
|
+
disabled=${disabled}
|
|
257
|
+
spellcheck="false"
|
|
258
|
+
autocomplete="off"
|
|
259
|
+
aria-label=${`${label}: color`}
|
|
260
|
+
aria-invalid=${problem !== ""}
|
|
261
|
+
onInput=${(event) => {
|
|
262
|
+
setDraft(event.currentTarget.value);
|
|
263
|
+
take(event.currentTarget.value);
|
|
264
|
+
}}
|
|
265
|
+
onBlur=${() => setDraft(null)}
|
|
266
|
+
/>
|
|
267
|
+
<button
|
|
268
|
+
type="button"
|
|
269
|
+
class="dsy-format"
|
|
270
|
+
title="Show it as hex, oklch, or rgb"
|
|
271
|
+
aria-label=${`Shown as ${format}. Change.`}
|
|
272
|
+
onClick=${() => {
|
|
273
|
+
setDraft(null);
|
|
274
|
+
setFormat(FORMATS[(FORMATS.indexOf(format) + 1) % FORMATS.length]);
|
|
275
|
+
}}
|
|
276
|
+
>
|
|
277
|
+
${format}
|
|
278
|
+
</button>
|
|
279
|
+
${problem && html`<p class="dsy-problem" role="alert">${problem}</p>`}
|
|
280
|
+
</div>`;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The cubic-bezier of an easing, drawn (the curve, its two handles) in a 64 px square. */
|
|
284
|
+
function Curve({ value, size = 64, play = false }) {
|
|
285
|
+
const [x1, y1, x2, y2] = value;
|
|
286
|
+
const pad = 10;
|
|
287
|
+
const span = size - pad * 2;
|
|
288
|
+
const at = (x, y) => `${(pad + x * span).toFixed(1)} ${(size - pad - y * span).toFixed(1)}`;
|
|
289
|
+
|
|
290
|
+
return html`<svg
|
|
291
|
+
class="dsy-curve"
|
|
292
|
+
width=${size}
|
|
293
|
+
height=${size}
|
|
294
|
+
viewBox=${`0 0 ${size} ${size}`}
|
|
295
|
+
aria-hidden="true"
|
|
296
|
+
>
|
|
297
|
+
<path
|
|
298
|
+
class="dsy-curve-axis"
|
|
299
|
+
d=${`M${at(0, 0)} L${at(1, 0)} M${at(0, 0)} L${at(0, 1)}`}
|
|
300
|
+
/>
|
|
301
|
+
<path
|
|
302
|
+
class="dsy-curve-handle"
|
|
303
|
+
d=${`M${at(0, 0)} L${at(x1, y1)} M${at(1, 1)} L${at(x2, y2)}`}
|
|
304
|
+
/>
|
|
305
|
+
<path
|
|
306
|
+
class="dsy-curve-line"
|
|
307
|
+
d=${`M${at(0, 0)} C${at(x1, y1)} ${at(x2, y2)} ${at(1, 1)}`}
|
|
308
|
+
/>
|
|
309
|
+
<circle
|
|
310
|
+
class="dsy-curve-dot"
|
|
311
|
+
cx=${at(x1, y1).split(" ")[0]}
|
|
312
|
+
cy=${at(x1, y1).split(" ")[1]}
|
|
313
|
+
r="2.5"
|
|
314
|
+
/>
|
|
315
|
+
<circle
|
|
316
|
+
class="dsy-curve-dot"
|
|
317
|
+
cx=${at(x2, y2).split(" ")[0]}
|
|
318
|
+
cy=${at(x2, y2).split(" ")[1]}
|
|
319
|
+
r="2.5"
|
|
320
|
+
/>
|
|
321
|
+
${play && html`<circle class="dsy-curve-dot end" cx=${at(1, 1).split(" ")[0]} cy=${at(1, 1).split(" ")[1]} r="2.5" />`}
|
|
322
|
+
</svg>`;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Four numbers of an easing, with its curve. */
|
|
326
|
+
function BezierField({ value, label, onChange, disabled }) {
|
|
327
|
+
const names = ["x1", "y1", "x2", "y2"];
|
|
328
|
+
|
|
329
|
+
return html`<div class="dsy-bezier">
|
|
330
|
+
<${Curve} value=${value} size=${72} />
|
|
331
|
+
<div class="dsy-bezier-fields">
|
|
332
|
+
${names.map(
|
|
333
|
+
(name, index) =>
|
|
334
|
+
html`<label>
|
|
335
|
+
<span class="muted small mono">${name}</span>
|
|
336
|
+
<input
|
|
337
|
+
type="text"
|
|
338
|
+
inputmode="decimal"
|
|
339
|
+
class="mono"
|
|
340
|
+
value=${String(value[index])}
|
|
341
|
+
disabled=${disabled}
|
|
342
|
+
aria-label=${`${label}: ${name}`}
|
|
343
|
+
onChange=${(event) => {
|
|
344
|
+
const next = [...value];
|
|
345
|
+
|
|
346
|
+
next[index] = Number(event.currentTarget.value);
|
|
347
|
+
|
|
348
|
+
const result = readInput("cubicBezier", next.join(" "), value);
|
|
349
|
+
|
|
350
|
+
if (result.value !== undefined) {
|
|
351
|
+
onChange(result.value);
|
|
352
|
+
} else {
|
|
353
|
+
pocket.notify("error", result.error);
|
|
354
|
+
event.currentTarget.value = String(value[index]);
|
|
355
|
+
}
|
|
356
|
+
}}
|
|
357
|
+
/>
|
|
358
|
+
</label>`,
|
|
359
|
+
)}
|
|
360
|
+
</div>
|
|
361
|
+
</div>`;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The tokens an alias may point to: those of the same type that do not lead back. Searchable, in a card over the view. */
|
|
365
|
+
function AliasPicker({ model, token, mode, part, current, onPick, onClose, narrow }) {
|
|
366
|
+
const [query, setQuery] = useState("");
|
|
367
|
+
const words = query.trim().toLowerCase();
|
|
368
|
+
// A part of a shadow links to a token of its own kind (a size, a color); a token links to one that does not lead back.
|
|
369
|
+
const kind = part ? part.type : token.type;
|
|
370
|
+
const targets = (
|
|
371
|
+
part
|
|
372
|
+
? model.tokens.filter((each) => each.type === part.type && each.name !== token.name)
|
|
373
|
+
: model.targets(token.name)
|
|
374
|
+
).filter((each) => words === "" || each.name.toLowerCase().includes(words));
|
|
375
|
+
const linked = part ? current : model.value(token.name, mode).alias;
|
|
376
|
+
|
|
377
|
+
return html`<${Popover}
|
|
378
|
+
label="Link to a token"
|
|
379
|
+
onClose=${onClose}
|
|
380
|
+
wide=${true}
|
|
381
|
+
sheet=${narrow}
|
|
382
|
+
>
|
|
383
|
+
<input
|
|
384
|
+
class="dsn-search"
|
|
385
|
+
type="search"
|
|
386
|
+
placeholder=${`Find a ${kind} token`}
|
|
387
|
+
value=${query}
|
|
388
|
+
autofocus
|
|
389
|
+
onInput=${(event) => setQuery(event.currentTarget.value)}
|
|
390
|
+
/>
|
|
391
|
+
<ul class="dsn-list dsy-targets" aria-label="Tokens">
|
|
392
|
+
${targets.slice(0, 120).map((each) => {
|
|
393
|
+
const value = model.value(each.name, mode);
|
|
394
|
+
|
|
395
|
+
return html`<li key=${each.name}>
|
|
396
|
+
<button
|
|
397
|
+
type="button"
|
|
398
|
+
class=${`dsn-list-item ${each.name === linked ? "on" : ""}`}
|
|
399
|
+
onClick=${() => onPick(each.name)}
|
|
400
|
+
>
|
|
401
|
+
${
|
|
402
|
+
each.type === "color"
|
|
403
|
+
? html`<${Swatch} values=${[value.value]} size=${28} />`
|
|
404
|
+
: html`<span class="dsy-target-value mono"
|
|
405
|
+
>${showValue(each, value).slice(0, 14)}</span
|
|
406
|
+
>`
|
|
407
|
+
}
|
|
408
|
+
<span class="dsn-list-main">
|
|
409
|
+
<strong class="mono dsy-target-name">${each.name}</strong>
|
|
410
|
+
<span class="muted small"
|
|
411
|
+
>${each.tier}${each.description ? ` · ${each.description}` : ""}</span
|
|
412
|
+
>
|
|
413
|
+
</span>
|
|
414
|
+
${each.name === linked && html`<${Ico} name="check" size=${15} />`}
|
|
415
|
+
</button>
|
|
416
|
+
</li>`;
|
|
417
|
+
})}
|
|
418
|
+
${targets.length === 0 && html`<li class="muted small dsn-empty">No token of this kind${words ? " by that name" : ""}.</li>`}
|
|
419
|
+
${targets.length > 120 && html`<li class="muted small dsn-empty">Type to narrow ${targets.length} tokens.</li>`}
|
|
420
|
+
</ul>
|
|
421
|
+
<//>`;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** The words and kinds of a shadow layer's members, in the order they are shown. */
|
|
425
|
+
const SHADOW_PARTS = [
|
|
426
|
+
["offsetX", "X offset", "dimension"],
|
|
427
|
+
["offsetY", "Y offset", "dimension"],
|
|
428
|
+
["blur", "Blur", "dimension"],
|
|
429
|
+
["spread", "Spread", "dimension"],
|
|
430
|
+
["color", "Color", "color"],
|
|
431
|
+
];
|
|
432
|
+
|
|
433
|
+
/** One member of a shadow layer: a value of its own in the field of its kind, or a link to a token that holds it. */
|
|
434
|
+
function PartField({ model, token, mode, layers, at, part, canEdit }) {
|
|
435
|
+
const [key, name, type] = part;
|
|
436
|
+
const member = layers[at][key];
|
|
437
|
+
const link = linkOf(member);
|
|
438
|
+
const target = link === null ? null : model.token(link);
|
|
439
|
+
const label = `${token.name} in ${mode}: layer ${at + 1} ${name.toLowerCase()}`;
|
|
440
|
+
const write = (next) =>
|
|
441
|
+
env.editToken(token.name, mode, {
|
|
442
|
+
value: shadowValue(withPart(layers, at, key, next)),
|
|
443
|
+
});
|
|
444
|
+
const pick = () => env.pickPart(token.name, mode, { layer: at, key, type });
|
|
445
|
+
|
|
446
|
+
if (link !== null) {
|
|
447
|
+
const now = target ? model.value(link, mode) : null;
|
|
448
|
+
|
|
449
|
+
return html`<div class="dsy-part" data-part=${key}>
|
|
450
|
+
<span class="dsy-part-name">${name}</span>
|
|
451
|
+
<div class="dsy-part-link">
|
|
452
|
+
<${Ico} name="link" size=${13} />
|
|
453
|
+
${
|
|
454
|
+
target
|
|
455
|
+
? html`<button
|
|
456
|
+
type="button"
|
|
457
|
+
class="dsy-chip"
|
|
458
|
+
aria-label=${`${label} links to ${link}`}
|
|
459
|
+
onClick=${() => env.openToken(link)}
|
|
460
|
+
>
|
|
461
|
+
${link}
|
|
462
|
+
</button>`
|
|
463
|
+
: html`<span class="dsy-chip">${link}</span>`
|
|
464
|
+
}
|
|
465
|
+
${now && html`<span class="muted small mono">${showValue(target, now)}</span>`}
|
|
466
|
+
</div>
|
|
467
|
+
${
|
|
468
|
+
canEdit &&
|
|
469
|
+
html`<div class="dsy-part-actions">
|
|
470
|
+
<button type="button" class="dsn-link" onClick=${pick}>Change</button>
|
|
471
|
+
${
|
|
472
|
+
now &&
|
|
473
|
+
html`<button
|
|
474
|
+
type="button"
|
|
475
|
+
class="dsn-link"
|
|
476
|
+
onClick=${() => write(now.value)}
|
|
477
|
+
>
|
|
478
|
+
Use a value
|
|
479
|
+
</button>`
|
|
480
|
+
}
|
|
481
|
+
</div>`
|
|
482
|
+
}
|
|
483
|
+
</div>`;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
const amount = type === "dimension" ? amountOf(member) : null;
|
|
487
|
+
|
|
488
|
+
return html`<div class="dsy-part" data-part=${key}>
|
|
489
|
+
<span class="dsy-part-name">${name}</span>
|
|
490
|
+
${
|
|
491
|
+
type === "color"
|
|
492
|
+
? html`<${ColorField}
|
|
493
|
+
value=${member}
|
|
494
|
+
like=${member}
|
|
495
|
+
label=${label}
|
|
496
|
+
disabled=${!canEdit}
|
|
497
|
+
onChange=${write}
|
|
498
|
+
/>`
|
|
499
|
+
: amount
|
|
500
|
+
? html`<${AmountField}
|
|
501
|
+
amount=${amount}
|
|
502
|
+
units=${UNITS.dimension}
|
|
503
|
+
step=${amount.unit === "px" ? 1 : 0.25}
|
|
504
|
+
label=${label}
|
|
505
|
+
disabled=${!canEdit}
|
|
506
|
+
onChange=${(next) => write(writeAmount(next, member))}
|
|
507
|
+
/>`
|
|
508
|
+
: html`<p class="muted small mono">${String(member)}</p>`
|
|
509
|
+
}
|
|
510
|
+
${
|
|
511
|
+
canEdit &&
|
|
512
|
+
html`<div class="dsy-part-actions">
|
|
513
|
+
<button type="button" class="dsn-link" onClick=${pick}>Link to a token</button>
|
|
514
|
+
</div>`
|
|
515
|
+
}
|
|
516
|
+
</div>`;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* A shadow by its parts: for each layer its offsets, blur, spread, color and whether it is inset, each a value or a link to
|
|
521
|
+
* a token, kept as the file has it. A layer is added (a copy of the last) or taken away. A shadow that is a link to another
|
|
522
|
+
* shadow shows that one's parts, and is changed by linking elsewhere or by using a value.
|
|
523
|
+
*/
|
|
524
|
+
function ShadowField({ model, token, mode, canEdit }) {
|
|
525
|
+
const now = model.value(token.name, mode);
|
|
526
|
+
const { layers } = model.shadowRaw(token.name, mode);
|
|
527
|
+
// A link to another shadow: its parts are that one's, so they are shown and not changed here.
|
|
528
|
+
const mine = canEdit && now.alias === undefined;
|
|
529
|
+
const write = (next) => env.editToken(token.name, mode, { value: shadowValue(next) });
|
|
530
|
+
|
|
531
|
+
return html`<div class="dsy-layers" data-layers=${layers.length}>
|
|
532
|
+
${layers.map(
|
|
533
|
+
(layer, at) =>
|
|
534
|
+
html`<fieldset class="dsy-layer" key=${at}>
|
|
535
|
+
<legend>
|
|
536
|
+
Layer ${at + 1}
|
|
537
|
+
${
|
|
538
|
+
mine &&
|
|
539
|
+
layers.length > 1 &&
|
|
540
|
+
html`<button
|
|
541
|
+
type="button"
|
|
542
|
+
class="dsn-link"
|
|
543
|
+
aria-label=${`Remove layer ${at + 1} of ${token.name} in ${mode}`}
|
|
544
|
+
onClick=${() => write(layers.filter((_, index) => index !== at))}
|
|
545
|
+
>
|
|
546
|
+
Remove
|
|
547
|
+
</button>`
|
|
548
|
+
}
|
|
549
|
+
</legend>
|
|
550
|
+
<div class="dsy-parts">
|
|
551
|
+
${SHADOW_PARTS.map(
|
|
552
|
+
(part) =>
|
|
553
|
+
html`<${PartField}
|
|
554
|
+
key=${part[0]}
|
|
555
|
+
model=${model}
|
|
556
|
+
token=${token}
|
|
557
|
+
mode=${mode}
|
|
558
|
+
layers=${layers}
|
|
559
|
+
at=${at}
|
|
560
|
+
part=${part}
|
|
561
|
+
canEdit=${mine}
|
|
562
|
+
/>`,
|
|
563
|
+
)}
|
|
564
|
+
</div>
|
|
565
|
+
<label class="dsy-inset">
|
|
566
|
+
<input
|
|
567
|
+
type="checkbox"
|
|
568
|
+
checked=${layer.inset === true}
|
|
569
|
+
disabled=${!mine}
|
|
570
|
+
aria-label=${`${token.name} in ${mode}: layer ${at + 1} inset`}
|
|
571
|
+
onChange=${(event) =>
|
|
572
|
+
write(
|
|
573
|
+
withPart(layers, at, "inset", event.currentTarget.checked),
|
|
574
|
+
)}
|
|
575
|
+
/>
|
|
576
|
+
Inset
|
|
577
|
+
</label>
|
|
578
|
+
</fieldset>`,
|
|
579
|
+
)}
|
|
580
|
+
${
|
|
581
|
+
mine &&
|
|
582
|
+
layers.length < 6 &&
|
|
583
|
+
html`<button
|
|
584
|
+
type="button"
|
|
585
|
+
class="dsn-link"
|
|
586
|
+
onClick=${() => write([...layers, { ...layers.at(-1) }])}
|
|
587
|
+
>
|
|
588
|
+
Add a layer
|
|
589
|
+
</button>`
|
|
590
|
+
}
|
|
591
|
+
</div>`;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/** The value of one token in one mode, as the field of its kind (or what to do when it has none). */
|
|
595
|
+
function ValueField({ model, token, mode, canEdit, like }) {
|
|
596
|
+
const now = model.value(token.name, mode);
|
|
597
|
+
// A token that links to another can be edited too: a new value replaces the link (undo puts it back).
|
|
598
|
+
const disabled = !canEdit;
|
|
599
|
+
const label = `${token.name} in ${mode}`;
|
|
600
|
+
const edit = (value) => env.editToken(token.name, mode, { value });
|
|
601
|
+
|
|
602
|
+
switch (token.type) {
|
|
603
|
+
case "shadow":
|
|
604
|
+
return html`<${ShadowField}
|
|
605
|
+
model=${model}
|
|
606
|
+
token=${token}
|
|
607
|
+
mode=${mode}
|
|
608
|
+
canEdit=${canEdit}
|
|
609
|
+
/>`;
|
|
610
|
+
case "color":
|
|
611
|
+
return html`<${ColorField}
|
|
612
|
+
value=${now.value}
|
|
613
|
+
like=${like}
|
|
614
|
+
label=${label}
|
|
615
|
+
disabled=${disabled}
|
|
616
|
+
onChange=${edit}
|
|
617
|
+
/>`;
|
|
618
|
+
case "dimension":
|
|
619
|
+
|
|
620
|
+
case "duration": {
|
|
621
|
+
const amount = amountOf(now.value);
|
|
622
|
+
|
|
623
|
+
return amount
|
|
624
|
+
? html`<${AmountField}
|
|
625
|
+
amount=${amount}
|
|
626
|
+
units=${UNITS[token.type]}
|
|
627
|
+
step=${token.type === "duration" ? 10 : amount.unit === "px" ? 1 : 0.25}
|
|
628
|
+
label=${label}
|
|
629
|
+
disabled=${disabled}
|
|
630
|
+
onChange=${(next) => edit(writeAmount(next, like))}
|
|
631
|
+
/>`
|
|
632
|
+
: html`<p class="muted small">This value has no size to edit.</p>`;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
case "number":
|
|
636
|
+
case "fontWeight":
|
|
637
|
+
return typeof now.value === "number"
|
|
638
|
+
? html`<${AmountField}
|
|
639
|
+
amount=${{ n: now.value, unit: "" }}
|
|
640
|
+
step=${token.type === "fontWeight" ? 100 : 0.05}
|
|
641
|
+
label=${label}
|
|
642
|
+
disabled=${disabled}
|
|
643
|
+
onChange=${(next) => edit(token.type === "fontWeight" ? Math.max(1, Math.min(1000, Math.round(next.n))) : next.n)}
|
|
644
|
+
/>`
|
|
645
|
+
: html`<p class="muted small mono">${String(now.value)}</p>`;
|
|
646
|
+
case "fontFamily":
|
|
647
|
+
return html`<input
|
|
648
|
+
type="text"
|
|
649
|
+
class="dsy-text mono"
|
|
650
|
+
value=${Array.isArray(now.value) ? now.value.join(", ") : String(now.value ?? "")}
|
|
651
|
+
disabled=${disabled}
|
|
652
|
+
spellcheck="false"
|
|
653
|
+
aria-label=${label}
|
|
654
|
+
onChange=${(event) => {
|
|
655
|
+
const result = readInput("fontFamily", event.currentTarget.value, like);
|
|
656
|
+
|
|
657
|
+
if (result.value === undefined) {
|
|
658
|
+
pocket.notify("error", result.error);
|
|
659
|
+
} else {
|
|
660
|
+
edit(result.value);
|
|
661
|
+
}
|
|
662
|
+
}}
|
|
663
|
+
/>`;
|
|
664
|
+
case "cubicBezier":
|
|
665
|
+
return Array.isArray(now.value) && now.value.length === 4
|
|
666
|
+
? html`<${BezierField}
|
|
667
|
+
value=${now.value}
|
|
668
|
+
label=${label}
|
|
669
|
+
disabled=${disabled}
|
|
670
|
+
onChange=${edit}
|
|
671
|
+
/>`
|
|
672
|
+
: null;
|
|
673
|
+
default:
|
|
674
|
+
return html`<p class="dsy-composite mono">${showValue(token, now)}</p>`;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** Whether a mode takes the token from the default mode (so its file does not set it), with the edits made. */
|
|
679
|
+
const inherited = (model, token, mode) =>
|
|
680
|
+
mode !== model.defaultMode && !model.overridden(token.name, mode);
|
|
681
|
+
|
|
682
|
+
/** The pairs of a color token, each with its ratio and level; a pair that is exempt says so, and is not a failure. */
|
|
683
|
+
function ContrastList({ model, token, mode, modes }) {
|
|
684
|
+
const pairs = model.contrastsOf(token.name, mode);
|
|
685
|
+
|
|
686
|
+
if (pairs.length === 0) {
|
|
687
|
+
return null;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return html`<div class="dsy-contrasts" data-pairs=${pairs.length}>
|
|
691
|
+
<h5>${pairs.length === 1 ? "Contrast" : `Contrast on ${pairs.length} pairs`}</h5>
|
|
692
|
+
<ul
|
|
693
|
+
aria-label=${`Contrast of ${token.name}${modes > 1 ? ` in ${modeTitle(mode)}` : ""}`}
|
|
694
|
+
>
|
|
695
|
+
${pairs.map(
|
|
696
|
+
(pair) =>
|
|
697
|
+
html`<li key=${pair.on}>
|
|
698
|
+
<span class="muted small">on</span>
|
|
699
|
+
<button
|
|
700
|
+
type="button"
|
|
701
|
+
class="dsy-chip"
|
|
702
|
+
onClick=${() => env.openToken(pair.on)}
|
|
703
|
+
>
|
|
704
|
+
${pair.on}
|
|
705
|
+
</button>
|
|
706
|
+
<${ContrastBadge} info=${pair} mode=${mode} modes=${1} />
|
|
707
|
+
${
|
|
708
|
+
pair.exempt &&
|
|
709
|
+
html`<span class="dsy-exempt-note">exempt: ${pair.exempt}</span>`
|
|
710
|
+
}
|
|
711
|
+
${
|
|
712
|
+
pair.auto &&
|
|
713
|
+
html`<span class="muted small">checked against the page</span>`
|
|
714
|
+
}
|
|
715
|
+
</li>`,
|
|
716
|
+
)}
|
|
717
|
+
</ul>
|
|
718
|
+
</div>`;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* One token's editor: for each mode in view, its alias (link, change, or use a value), and its value in the field of its
|
|
723
|
+
* kind. A shadow is edited by its parts (each a value or a link); a typography style is shown, and changed with Pi. A mode
|
|
724
|
+
* other than the default says whether it sets the token or takes the default's, and can give a value back.
|
|
725
|
+
*/
|
|
726
|
+
function TokenEditor({ model, token, modes, canEdit, narrow }) {
|
|
727
|
+
const editable = EDITABLE.has(token.type);
|
|
728
|
+
const dependents = model.dependents(token.name);
|
|
729
|
+
const anyEdit = model.modes.some((mode) => model.edited(token.name, mode));
|
|
730
|
+
|
|
731
|
+
return html`<div class="dsy-editor">
|
|
732
|
+
${token.description && html`<p class="dsy-editor-note">${token.description}</p>`}
|
|
733
|
+
${
|
|
734
|
+
token.deprecated &&
|
|
735
|
+
html`<p class="dsy-editor-warn">
|
|
736
|
+
<${Ico} name="alert" size=${13} />
|
|
737
|
+
Deprecated${typeof token.deprecated === "string" ? `: ${token.deprecated}` : ""}
|
|
738
|
+
</p>`
|
|
739
|
+
}
|
|
740
|
+
${modes.map((mode) => {
|
|
741
|
+
const now = model.value(token.name, mode);
|
|
742
|
+
const saved = token.modes[mode];
|
|
743
|
+
// The dialect to write in: that of the saved value (or the default mode's, when this one only follows it).
|
|
744
|
+
const like =
|
|
745
|
+
(saved?.alias === undefined
|
|
746
|
+
? saved?.value
|
|
747
|
+
: model.value(token.name, mode).value) ??
|
|
748
|
+
token.modes[model.defaultMode]?.value;
|
|
749
|
+
const chain = model.chain(token.name, mode);
|
|
750
|
+
|
|
751
|
+
return html`<section class="dsy-mode" key=${mode} aria-label=${modeTitle(mode)}>
|
|
752
|
+
${modes.length > 1 && html`<h4 class="dsy-mode-name">${modeTitle(mode)}</h4>`}
|
|
753
|
+
${now.error && html`<p class="dsy-problem" role="alert">${now.error}</p>`}
|
|
754
|
+
${
|
|
755
|
+
mode !== model.defaultMode &&
|
|
756
|
+
html`<div class="dsy-inherit" data-inherit=${inherited(model, token, mode)}>
|
|
757
|
+
${
|
|
758
|
+
inherited(model, token, mode)
|
|
759
|
+
? html`<span class="dsy-inherit-tag"
|
|
760
|
+
><${Ico} name="link" size=${12} />
|
|
761
|
+
${`Inherited from ${modeTitle(model.defaultMode)}`}</span
|
|
762
|
+
>
|
|
763
|
+
<span class="muted small"
|
|
764
|
+
>${`Change it to give ${modeTitle(mode)} a value of its own.`}</span
|
|
765
|
+
>`
|
|
766
|
+
: html`<span class="dsy-inherit-tag own"
|
|
767
|
+
>${modeTitle(mode)} sets this itself</span
|
|
768
|
+
>
|
|
769
|
+
${
|
|
770
|
+
canEdit &&
|
|
771
|
+
html`<button
|
|
772
|
+
type="button"
|
|
773
|
+
class="dsn-link dsy-match"
|
|
774
|
+
onClick=${() => env.inheritToken(token.name, mode)}
|
|
775
|
+
>
|
|
776
|
+
Use ${modeTitle(model.defaultMode)}'s value
|
|
777
|
+
</button>`
|
|
778
|
+
}`
|
|
779
|
+
}
|
|
780
|
+
</div>`
|
|
781
|
+
}
|
|
782
|
+
${
|
|
783
|
+
editable
|
|
784
|
+
? html`<${ValueField}
|
|
785
|
+
model=${model}
|
|
786
|
+
token=${token}
|
|
787
|
+
mode=${mode}
|
|
788
|
+
canEdit=${canEdit}
|
|
789
|
+
like=${like}
|
|
790
|
+
/>`
|
|
791
|
+
: html`<${ValueField}
|
|
792
|
+
model=${model}
|
|
793
|
+
token=${token}
|
|
794
|
+
mode=${mode}
|
|
795
|
+
canEdit=${false}
|
|
796
|
+
like=${like}
|
|
797
|
+
/>`
|
|
798
|
+
}
|
|
799
|
+
<${ContrastList}
|
|
800
|
+
model=${model}
|
|
801
|
+
token=${token}
|
|
802
|
+
mode=${mode}
|
|
803
|
+
modes=${modes.length}
|
|
804
|
+
/>
|
|
805
|
+
<div class="dsy-alias">
|
|
806
|
+
<${Ico} name="link" size=${14} />
|
|
807
|
+
${
|
|
808
|
+
now.alias
|
|
809
|
+
? html`<span class="dsy-chain mono">
|
|
810
|
+
${chain
|
|
811
|
+
.slice(1)
|
|
812
|
+
.map(
|
|
813
|
+
(name, index) =>
|
|
814
|
+
html`${index > 0 && html`<span class="dsy-arrow">→</span>`}<button
|
|
815
|
+
type="button"
|
|
816
|
+
class="dsy-chip"
|
|
817
|
+
onClick=${() => env.openToken(name)}
|
|
818
|
+
>
|
|
819
|
+
${name}
|
|
820
|
+
</button>`,
|
|
821
|
+
)}
|
|
822
|
+
</span>`
|
|
823
|
+
: html`<span class="muted small">A value of its own</span>`
|
|
824
|
+
}
|
|
825
|
+
<span class="grow"></span>
|
|
826
|
+
${
|
|
827
|
+
canEdit &&
|
|
828
|
+
html`<button
|
|
829
|
+
type="button"
|
|
830
|
+
class="dsn-link"
|
|
831
|
+
onClick=${() => env.pickAlias(token.name, mode)}
|
|
832
|
+
>
|
|
833
|
+
${now.alias ? "Change" : "Link to a token"}
|
|
834
|
+
</button>`
|
|
835
|
+
}
|
|
836
|
+
${
|
|
837
|
+
canEdit &&
|
|
838
|
+
now.alias &&
|
|
839
|
+
html`<button
|
|
840
|
+
type="button"
|
|
841
|
+
class="dsn-link"
|
|
842
|
+
onClick=${() =>
|
|
843
|
+
env.editToken(token.name, mode, {
|
|
844
|
+
value:
|
|
845
|
+
token.type === "shadow"
|
|
846
|
+
? shadowValue(
|
|
847
|
+
model.shadowRaw(token.name, mode).layers,
|
|
848
|
+
)
|
|
849
|
+
: now.value,
|
|
850
|
+
})}
|
|
851
|
+
>
|
|
852
|
+
Use a value
|
|
853
|
+
</button>`
|
|
854
|
+
}
|
|
855
|
+
</div>
|
|
856
|
+
</section>`;
|
|
857
|
+
})}
|
|
858
|
+
${
|
|
859
|
+
!editable &&
|
|
860
|
+
html`<div class="dsy-askpi">
|
|
861
|
+
<span class="muted small">
|
|
862
|
+
This kind of token is made of parts that link to other tokens. Change the
|
|
863
|
+
tokens it uses, or ask Pi to change it.
|
|
864
|
+
</span>
|
|
865
|
+
${
|
|
866
|
+
canEdit &&
|
|
867
|
+
html`<button
|
|
868
|
+
type="button"
|
|
869
|
+
class="button small"
|
|
870
|
+
onClick=${() => env.askPiAbout(token)}
|
|
871
|
+
>
|
|
872
|
+
<${Ico} name="sparkle" size=${14} /> Ask Pi
|
|
873
|
+
</button>`
|
|
874
|
+
}
|
|
875
|
+
</div>`
|
|
876
|
+
}
|
|
877
|
+
<div class="dsy-editor-foot">
|
|
878
|
+
<button
|
|
879
|
+
type="button"
|
|
880
|
+
class="dsn-link"
|
|
881
|
+
onClick=${async () => {
|
|
882
|
+
if (await copyText(`var(${token.cssVar})`)) {
|
|
883
|
+
pocket.notify("info", `Copied var(${token.cssVar})`);
|
|
884
|
+
}
|
|
885
|
+
}}
|
|
886
|
+
>
|
|
887
|
+
<${Ico} name="copy" size=${13} /> var(${token.cssVar})
|
|
888
|
+
</button>
|
|
889
|
+
${
|
|
890
|
+
dependents.length > 0 &&
|
|
891
|
+
html`<span class="muted small"
|
|
892
|
+
>${`Used by ${dependents.length} token${dependents.length === 1 ? "" : "s"}`}</span
|
|
893
|
+
>`
|
|
894
|
+
}
|
|
895
|
+
<span class="grow"></span>
|
|
896
|
+
${
|
|
897
|
+
canEdit &&
|
|
898
|
+
anyEdit &&
|
|
899
|
+
html`<button
|
|
900
|
+
type="button"
|
|
901
|
+
class="dsn-link"
|
|
902
|
+
onClick=${() => env.resetToken(token.name)}
|
|
903
|
+
>
|
|
904
|
+
<${Ico} name="undo" size=${13} /> Reset
|
|
905
|
+
</button>`
|
|
906
|
+
}
|
|
907
|
+
</div>
|
|
908
|
+
${
|
|
909
|
+
dependents.length > 0 &&
|
|
910
|
+
html`<div class="dsy-used">
|
|
911
|
+
${dependents
|
|
912
|
+
.slice(0, 12)
|
|
913
|
+
.map(
|
|
914
|
+
(name) =>
|
|
915
|
+
html`<button
|
|
916
|
+
type="button"
|
|
917
|
+
class="dsy-chip"
|
|
918
|
+
key=${name}
|
|
919
|
+
onClick=${() => env.openToken(name)}
|
|
920
|
+
>
|
|
921
|
+
${name}
|
|
922
|
+
</button>`,
|
|
923
|
+
)}
|
|
924
|
+
${dependents.length > 12 && html`<span class="muted small">and ${dependents.length - 12} more</span>`}
|
|
925
|
+
</div>`
|
|
926
|
+
}
|
|
927
|
+
</div>`;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
return {
|
|
931
|
+
Swatch,
|
|
932
|
+
CopyName,
|
|
933
|
+
ContrastBadge,
|
|
934
|
+
AmountField,
|
|
935
|
+
ColorField,
|
|
936
|
+
BezierField,
|
|
937
|
+
Curve,
|
|
938
|
+
AliasPicker,
|
|
939
|
+
ValueField,
|
|
940
|
+
TokenEditor,
|
|
941
|
+
};
|
|
942
|
+
}
|