@reqvire-org/ads 0.3.45 → 0.3.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -11
- package/dist/a11y.mjs +102 -0
- package/dist/assets.mjs +37 -8
- package/dist/atomic-composition.mjs +3 -2
- package/dist/brand-assets.mjs +48 -11
- package/dist/brands.mjs +82 -0
- package/dist/browser-audit/worker.mjs +45 -0
- package/dist/browser-audit.mjs +117 -0
- package/dist/capture/worker.mjs +2 -1
- package/dist/capture-store.mjs +4 -1
- package/dist/capture.mjs +10 -4
- package/dist/check.mjs +40 -9
- package/dist/cli.mjs +55 -8
- package/dist/color-values.mjs +325 -0
- package/dist/config.mjs +19 -2
- package/dist/contracts/tokens.json +1 -1
- package/dist/control-padding.mjs +93 -0
- package/dist/design-values.mjs +11 -4
- package/dist/finding-rules.mjs +61 -0
- package/dist/foundation.mjs +17 -1
- package/dist/icons.mjs +107 -0
- package/dist/init.mjs +3 -0
- package/dist/mcp/apps.mjs +9 -6
- package/dist/mcp/drafts.mjs +3 -0
- package/dist/mcp/mutations.mjs +17 -1
- package/dist/mcp/preview-widget.bundle.js +45 -39
- package/dist/mcp/project-widget.bundle.js +26 -26
- package/dist/mcp/server.mjs +23 -9
- package/dist/mcp/widget.bundle.js +17 -17
- package/dist/palette-generated.mjs +180 -0
- package/dist/preview-resources.mjs +12 -3
- package/dist/render-color-probe.mjs +148 -0
- package/dist/runtime-contracts.mjs +14 -4
- package/dist/scenarios.mjs +1 -1
- package/dist/showcase/client.bundle.js +28 -28
- package/dist/showcase/icons.js +146 -0
- package/dist/showcase/index.html +2 -1
- package/dist/showcase/style.css +19 -2
- package/dist/skills/README.md +2 -1
- package/dist/skills/ads-break-ui/SKILL.md +6 -5
- package/dist/skills/ads-break-ui/references/atomic-styles.md +12 -12
- package/dist/skills/ads-break-ui/references/captures.md +3 -2
- package/dist/skills/ads-break-ui/references/contracts.md +13 -10
- package/dist/skills/ads-break-ui/references/design-data.md +199 -2
- package/dist/skills/ads-break-ui/references/validation.md +8 -4
- package/dist/skills/ads-designer/SKILL.md +32 -15
- package/dist/skills/ads-designer/references/accessibility.md +77 -0
- package/dist/skills/ads-designer/references/atomic-styles.md +12 -12
- package/dist/skills/ads-designer/references/branding.md +61 -6
- package/dist/skills/ads-designer/references/captures.md +3 -2
- package/dist/skills/ads-designer/references/cli.md +8 -2
- package/dist/skills/ads-designer/references/contracts.md +13 -10
- package/dist/skills/ads-designer/references/design-data.md +199 -2
- package/dist/skills/ads-designer/references/validation.md +8 -4
- package/dist/skills/ads-import/SKILL.md +9 -8
- package/dist/skills/ads-import/references/atomic-styles.md +12 -12
- package/dist/skills/ads-import/references/captures.md +3 -2
- package/dist/skills/ads-import/references/cli.md +8 -2
- package/dist/skills/ads-import/references/contracts.md +13 -10
- package/dist/skills/ads-import/references/design-data.md +199 -2
- package/dist/skills/ads-import/references/tokens.md +7 -3
- package/dist/skills/ads-import/references/validation.md +8 -4
- package/dist/skills/ads-motion/SKILL.md +6 -5
- package/dist/skills/ads-motion/references/atomic-styles.md +12 -12
- package/dist/skills/ads-motion/references/build.md +33 -0
- package/dist/skills/ads-motion/references/captures.md +3 -2
- package/dist/skills/ads-motion/references/contracts.md +13 -10
- package/dist/skills/ads-motion/references/design-data.md +199 -2
- package/dist/skills/ads-motion/references/motion-review.md +2 -2
- package/dist/skills/ads-motion/references/validation.md +8 -4
- package/dist/skills/ads-port/SKILL.md +6 -5
- package/dist/skills/ads-port/references/atomic-styles.md +12 -12
- package/dist/skills/ads-port/references/captures.md +3 -2
- package/dist/skills/ads-port/references/cli.md +8 -2
- package/dist/skills/ads-port/references/contracts.md +13 -10
- package/dist/skills/ads-port/references/design-data.md +199 -2
- package/dist/skills/ads-port/references/validation.md +8 -4
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +76 -0
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +19 -1
- package/dist/starters/preact/ds.config.json +13 -1
- package/dist/starters/react/ADS.md +43 -10
- package/dist/starters/react/README.md +61 -9
- package/dist/starters/react/design-system/assets/brand/README.md +8 -3
- package/dist/starters/react/design-system/assets/glyphs/README.md +15 -0
- package/dist/starters/react/design-system/assets/glyphs/aliases.json +1 -0
- package/dist/starters/react/design-system/assets/glyphs/check.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/chevron-down.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/chevron-right.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/close.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/external-link.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/info.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/menu.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/plus.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/search.svg +1 -0
- package/dist/starters/react/design-system/assets/glyphs/warning.svg +1 -0
- package/dist/starters/react/design-system/components/Actions/Button/Button.tsx +11 -4
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.fixture.ts +9 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.scenario.tsx +16 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +44 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/README.md +14 -0
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.fixture.ts +6 -0
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.scenario.tsx +16 -0
- package/dist/starters/react/design-system/components/Content/Icon/Icon.tsx +42 -0
- package/dist/starters/react/design-system/components/Content/Icon/README.md +17 -0
- package/dist/starters/react/design-system/components/Content/Icon/glyphs.ts +17 -0
- package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +3 -9
- package/dist/starters/react/design-system/components/Content/Logo/README.md +4 -2
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.tsx +9 -5
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +12 -0
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +17 -0
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +75 -0
- package/dist/starters/react/design-system/components/Layout/Grid/README.md +21 -0
- package/dist/starters/react/design-system/controllers/Palette/Palette.ts +164 -0
- package/dist/starters/react/design-system/index.ts +6 -0
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +2 -5
- package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +18 -0
- package/dist/starters/react/design-system/review/index.ts +1 -0
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +19 -1
- package/dist/starters/react/design-system/styles.css +1 -0
- package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +114 -8
- package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +23 -0
- package/dist/starters/react/design-system/tokens/{SpaceTypeMotion.ads.scenario.tsx → Layout.ads.scenario.tsx} +1 -1
- package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +18 -0
- package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +4 -0
- package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +30 -0
- package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +4 -0
- package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +37 -0
- package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +4 -0
- package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +29 -0
- package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +4 -0
- package/dist/starters/react/design-system/tokens/base.css +9 -3
- package/dist/starters/react/design-system/tokens/colors.css +210 -24
- package/dist/starters/react/design-system/tokens/elevation.css +44 -6
- package/dist/starters/react/design-system/tokens/spacing.css +67 -3
- package/dist/starters/react/design-system/tokens/themes.generated.css +142 -0
- package/dist/starters/react/design-system/tokens/themes.generated.ts +402 -0
- package/dist/starters/react/design-system/tokens/typography.css +25 -7
- package/dist/starters/react/ds.config.json +13 -1
- package/dist/style-boundaries.mjs +2 -1
- package/dist/themes-generated.mjs +150 -0
- package/dist/themes-watch.mjs +42 -0
- package/dist/themes.mjs +257 -0
- package/dist/token-export.mjs +69 -0
- package/dist/token-policy.mjs +2 -1
- package/dist/token-quality.mjs +112 -0
- package/dist/tokens.mjs +32 -30
- package/dist/validation.mjs +18 -1
- package/dist/verification/browser.mjs +14 -3
- package/docs/ADS.md +56 -13
- package/docs/ARCHITECTURE.md +82 -10
- package/docs/CACHING.md +2 -3
- package/docs/CHANGELOG.md +149 -13
- package/docs/CONTRACTS.md +13 -10
- package/docs/GUIDE.md +104 -8
- package/docs/MCP.md +46 -27
- package/docs/benchmarks/bun-previews.md +5 -5
- package/docs/benchmarks/{gidi-preview-memory.md → preview-memory.md} +14 -12
- package/docs/benchmarks/turbo-poc.md +24 -6
- package/package.json +2 -1
- package/dist/starters/react/design-system/tokens/SpaceTypeMotion.ads.fixture.ts +0 -36
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m9 6 6 6-6 6"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 6 6 18M6 6l12 12"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M12 16v-5M12 8h.01"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 6h16M4 12h16M4 18h16"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="11" cy="11" r="7"/><path d="m20 20-4.35-4.35"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 3 2 20h20L12 3Z"/><path d="M12 10v4M12 17h.01"/></svg>
|
|
@@ -13,17 +13,24 @@ const base = css`
|
|
|
13
13
|
display: inline-flex;
|
|
14
14
|
align-items: center;
|
|
15
15
|
justify-content: center;
|
|
16
|
-
|
|
17
|
-
padding-inline: var(--
|
|
16
|
+
min-height: var(--control-height-md);
|
|
17
|
+
padding-inline: var(--control-padding-md);
|
|
18
18
|
border-width: var(--border-w);
|
|
19
19
|
border-style: solid;
|
|
20
20
|
border-color: transparent;
|
|
21
21
|
border-radius: var(--radius-md);
|
|
22
22
|
font-size: var(--text-base);
|
|
23
23
|
font-weight: var(--weight-semibold);
|
|
24
|
-
line-height: var(--leading-
|
|
24
|
+
line-height: var(--leading-tight);
|
|
25
25
|
cursor: pointer;
|
|
26
|
-
|
|
26
|
+
transition: background-color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard);
|
|
27
|
+
/* Disabled is neutral, whatever the variant (exempt from contrast, WCAG 1.4.3). */
|
|
28
|
+
&:disabled {
|
|
29
|
+
cursor: default;
|
|
30
|
+
background: var(--bg-disabled);
|
|
31
|
+
border-color: var(--border-disabled);
|
|
32
|
+
color: var(--text-disabled);
|
|
33
|
+
}
|
|
27
34
|
`;
|
|
28
35
|
const variants = {
|
|
29
36
|
primary: css`
|
package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.scenario.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IconButton } from "@ds";
|
|
2
|
+
import { DemoFrame } from "@ds/review";
|
|
3
|
+
import { fixture } from "./IconButton.ads.fixture";
|
|
4
|
+
export const scenario = { title: fixture.title, covers: ["IconButton"] };
|
|
5
|
+
export default function Scenario() {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
{(["sm", "md", "lg"] as const).map(size => (
|
|
9
|
+
<DemoFrame key={size}>
|
|
10
|
+
{fixture.actions.map(action => <IconButton key={action.icon} icon={action.icon} label={action.label} size={size} />)}
|
|
11
|
+
<IconButton icon="check" label="Unavailable" size={size} disabled />
|
|
12
|
+
</DemoFrame>
|
|
13
|
+
))}
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { css, cx } from "@linaria/atomic";
|
|
2
|
+
import { Icon, type IconName } from "../../Content/Icon/Icon";
|
|
3
|
+
|
|
4
|
+
export interface IconButtonProps {
|
|
5
|
+
icon: IconName;
|
|
6
|
+
/** Required: the button's accessible name, also shown as its tooltip. */
|
|
7
|
+
label: string;
|
|
8
|
+
size?: "sm" | "md" | "lg";
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
onClick?: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// A square control-height target around a smaller glyph; only the background has states.
|
|
14
|
+
const base = css`
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
padding: 0;
|
|
19
|
+
border-width: var(--border-w);
|
|
20
|
+
border-style: solid;
|
|
21
|
+
border-color: transparent;
|
|
22
|
+
border-radius: var(--radius-md);
|
|
23
|
+
background: transparent;
|
|
24
|
+
color: var(--text-body);
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
transition: background-color var(--dur-fast) var(--ease-standard);
|
|
27
|
+
&:hover:not(:disabled) { background: var(--bg-hover); }
|
|
28
|
+
&:active:not(:disabled) { background: var(--bg-active); }
|
|
29
|
+
&:disabled { cursor: default; color: var(--text-disabled); }
|
|
30
|
+
`;
|
|
31
|
+
const sizes = {
|
|
32
|
+
sm: css`width: var(--control-height-sm); height: var(--control-height-sm);`,
|
|
33
|
+
md: css`width: var(--control-height-md); height: var(--control-height-md);`,
|
|
34
|
+
lg: css`width: var(--control-height-lg); height: var(--control-height-lg);`,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** An action shown as an icon, named for assistive technology and in its tooltip. */
|
|
38
|
+
export function IconButton({ icon, label, size = "md", disabled, onClick }: IconButtonProps) {
|
|
39
|
+
return (
|
|
40
|
+
<button type="button" className={cx("ds-icon-button", base, sizes[size])} aria-label={label} title={label} disabled={disabled} onClick={onClick}>
|
|
41
|
+
<Icon name={icon} size={size === "lg" ? "md" : "sm"} />
|
|
42
|
+
</button>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# IconButton
|
|
2
|
+
|
|
3
|
+
An action shown as an icon. `label` is required: it is the button's accessible name and its
|
|
4
|
+
tooltip, so an icon-only control is never anonymous (WCAG 4.1.2). The glyph is centered in a
|
|
5
|
+
square target of the control height (32/40/48 px). Only the background has states (hover,
|
|
6
|
+
pressed, disabled); the icon keeps the text color.
|
|
7
|
+
|
|
8
|
+
| Prop | Type | Default |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| `icon` | `IconName` | — |
|
|
11
|
+
| `label` | `string` | — |
|
|
12
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` |
|
|
13
|
+
| `disabled` | `boolean` | `false` |
|
|
14
|
+
| `onClick` | `() => void` | — |
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const fixture = {
|
|
2
|
+
title: "Icon",
|
|
3
|
+
sizes: ["sm", "md", "lg", "xl"],
|
|
4
|
+
// Decorative icons beside their text; the showcase's Icons tab lists the whole glyph set.
|
|
5
|
+
examples: [{ name: "search", text: "Search" }, { name: "info", text: "Details" }, { name: "warning", text: "Needs attention" }],
|
|
6
|
+
} as const;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Icon } from "@ds";
|
|
2
|
+
import { DemoFrame } from "@ds/review";
|
|
3
|
+
import { fixture } from "./Icon.ads.fixture";
|
|
4
|
+
export const scenario = { title: fixture.title, covers: ["Icon"] };
|
|
5
|
+
export default function Scenario() {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
{fixture.sizes.map(size => (
|
|
9
|
+
<DemoFrame key={size}>
|
|
10
|
+
{fixture.examples.map(example => <span key={example.name}><Icon name={example.name} size={size} /> {example.text}</span>)}
|
|
11
|
+
<Icon name="add" size={size} label="Add" />
|
|
12
|
+
</DemoFrame>
|
|
13
|
+
))}
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { css, cx } from "@linaria/atomic";
|
|
2
|
+
import { glyphAliases, glyphs } from "./glyphs";
|
|
3
|
+
|
|
4
|
+
export type IconName = keyof typeof glyphs | keyof typeof glyphAliases;
|
|
5
|
+
export interface IconProps {
|
|
6
|
+
name: IconName;
|
|
7
|
+
/** 16 px beside sm/base text (default), 20 px beside lg, 24 and 32 px on their own. */
|
|
8
|
+
size?: "sm" | "md" | "lg" | "xl";
|
|
9
|
+
/** Announced name for an icon that carries meaning on its own; without it the icon is decorative. */
|
|
10
|
+
label?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Every canonical glyph, for catalogues; aliases name the same drawings. */
|
|
13
|
+
export const iconNames = Object.keys(glyphs).sort() as IconName[];
|
|
14
|
+
|
|
15
|
+
// Centered beside text, never on the baseline; colored by the text it sits in.
|
|
16
|
+
const base = css`
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
flex: none;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
vertical-align: middle;
|
|
22
|
+
color: inherit;
|
|
23
|
+
& > svg { display: block; width: 100%; height: 100%; }
|
|
24
|
+
`;
|
|
25
|
+
const sizes = {
|
|
26
|
+
sm: css`width: var(--icon-sm); height: var(--icon-sm);`,
|
|
27
|
+
md: css`width: var(--icon-md); height: var(--icon-md);`,
|
|
28
|
+
lg: css`width: var(--icon-lg); height: var(--icon-lg);`,
|
|
29
|
+
xl: css`width: var(--icon-xl); height: var(--icon-xl);`,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** A glyph from the project's icon set. */
|
|
33
|
+
export function Icon({ name, size = "sm", label }: IconProps) {
|
|
34
|
+
const canonical = (name in glyphAliases ? glyphAliases[name as keyof typeof glyphAliases] : name) as keyof typeof glyphs;
|
|
35
|
+
return (
|
|
36
|
+
<span
|
|
37
|
+
className={cx("ds-icon", base, sizes[size])}
|
|
38
|
+
{...(label ? { role: "img", "aria-label": label } : { "aria-hidden": true })}
|
|
39
|
+
dangerouslySetInnerHTML={{ __html: glyphs[canonical] }}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Icon
|
|
2
|
+
|
|
3
|
+
A glyph from the project's icon set (`assets/glyphs/`, generated into `glyphs.ts` by
|
|
4
|
+
`ads assets`). It takes the color of the surrounding text (`currentColor`) and sits centered
|
|
5
|
+
beside it. Sizes pair with text: `sm` (16 px) beside sm/base text, `md` (20 px) beside lg,
|
|
6
|
+
`lg` and `xl` (24 and 32 px) on their own; keep one size per context.
|
|
7
|
+
|
|
8
|
+
Without `label` the icon is decorative and hidden from assistive technology; pass `label`
|
|
9
|
+
when the icon alone carries meaning. Icons have no states of their own: interactive icons
|
|
10
|
+
live in an `IconButton`, whose background changes. Review the whole glyph set in the
|
|
11
|
+
showcase's Icons tab; the Icon scenario shows the component in use.
|
|
12
|
+
|
|
13
|
+
| Prop | Type | Default |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `name` | `IconName` (a glyph or alias) | — |
|
|
16
|
+
| `size` | `"sm" \| "md" \| "lg" \| "xl"` | `"sm"` |
|
|
17
|
+
| `label` | `string` | decorative |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Generated by `ads assets` from assets/glyphs/. Edit the SVGs, not this file.
|
|
2
|
+
export const glyphs = {
|
|
3
|
+
"check": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M20 6 9 17l-5-5\"/></svg>",
|
|
4
|
+
"chevron-down": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"m6 9 6 6 6-6\"/></svg>",
|
|
5
|
+
"chevron-right": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"m9 6 6 6-6 6\"/></svg>",
|
|
6
|
+
"close": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M18 6 6 18M6 6l12 12\"/></svg>",
|
|
7
|
+
"external-link": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5\"/></svg>",
|
|
8
|
+
"info": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><circle cx=\"12\" cy=\"12\" r=\"9\"/><path d=\"M12 16v-5M12 8h.01\"/></svg>",
|
|
9
|
+
"menu": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M4 6h16M4 12h16M4 18h16\"/></svg>",
|
|
10
|
+
"plus": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 5v14M5 12h14\"/></svg>",
|
|
11
|
+
"search": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><circle cx=\"11\" cy=\"11\" r=\"7\"/><path d=\"m20 20-4.35-4.35\"/></svg>",
|
|
12
|
+
"warning": "<svg fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 3 2 20h20L12 3Z\"/><path d=\"M12 10v4M12 17h.01\"/></svg>"
|
|
13
|
+
} as const;
|
|
14
|
+
export const glyphAliases = {
|
|
15
|
+
"x": "close",
|
|
16
|
+
"add": "plus"
|
|
17
|
+
} as const;
|
|
@@ -17,18 +17,12 @@ const sizes = {
|
|
|
17
17
|
large: css`height: calc(var(--space-16) * 2);`,
|
|
18
18
|
};
|
|
19
19
|
const image = css`
|
|
20
|
-
display: block;
|
|
21
20
|
height: 100%;
|
|
22
21
|
width: auto;
|
|
23
22
|
`;
|
|
24
|
-
// Both variants are in the page; the theme shows one, so switching needs no script.
|
|
25
|
-
const light = css`
|
|
26
|
-
|
|
27
|
-
`;
|
|
28
|
-
const dark = css`
|
|
29
|
-
display: none;
|
|
30
|
-
:root[data-theme="dark"] & { display: block; }
|
|
31
|
-
`;
|
|
23
|
+
// Both variants are in the page; the nearest theme shows one, so switching needs no script.
|
|
24
|
+
const light = css`display: var(--display-light, block);`;
|
|
25
|
+
const dark = css`display: var(--display-dark, block);`;
|
|
32
26
|
|
|
33
27
|
/** The product logo, in its light- or dark-theme artwork. */
|
|
34
28
|
export function Logo({ label, size = "small" }: LogoProps) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Logo
|
|
2
2
|
|
|
3
3
|
The product logo from `assets/brand/`: `logo.svg` in the light theme and `logo.dark.svg`
|
|
4
|
-
in the dark theme. Both images are in the page and
|
|
5
|
-
|
|
4
|
+
in the dark theme. Both images are in the page and each shows only under its display
|
|
5
|
+
switch (`display: var(--display-light, block)`, `display: var(--display-dark, block)`), so
|
|
6
|
+
the logo follows the nearest `data-theme` and switching themes needs no script. `label` is
|
|
7
|
+
the accessible name.
|
|
6
8
|
|
|
7
9
|
| Prop | Type | Default |
|
|
8
10
|
|---|---|---|
|
|
@@ -25,16 +25,20 @@ const labelStyle = css`
|
|
|
25
25
|
color: var(--text-body);
|
|
26
26
|
`;
|
|
27
27
|
const input = css`
|
|
28
|
-
|
|
29
|
-
padding-inline: var(--
|
|
30
|
-
border: var(--border-w) solid var(--border-
|
|
28
|
+
min-height: var(--control-height-md);
|
|
29
|
+
padding-inline: var(--control-padding-md);
|
|
30
|
+
border: var(--border-w) solid var(--border-strong);
|
|
31
31
|
border-radius: var(--radius-md);
|
|
32
|
-
background: var(--bg-
|
|
32
|
+
background: var(--bg-field);
|
|
33
33
|
color: var(--text-body);
|
|
34
34
|
font-size: var(--text-base);
|
|
35
35
|
line-height: var(--leading-normal);
|
|
36
36
|
&::placeholder { color: var(--text-muted); }
|
|
37
|
-
&:disabled {
|
|
37
|
+
&:disabled {
|
|
38
|
+
background: var(--bg-disabled);
|
|
39
|
+
border-color: var(--border-disabled);
|
|
40
|
+
color: var(--text-disabled);
|
|
41
|
+
}
|
|
38
42
|
`;
|
|
39
43
|
|
|
40
44
|
/** A labelled single-line text input. */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const fixture = {
|
|
2
|
+
title: "Grid",
|
|
3
|
+
columns: Array.from({ length: 16 }, (_, index) => `${index + 1}`),
|
|
4
|
+
layout: [
|
|
5
|
+
{ label: "Main", span: { sm: 4, md: 5, lg: 11 } },
|
|
6
|
+
{ label: "Aside", span: { sm: 4, md: 3, lg: 5 } },
|
|
7
|
+
{ label: "Card", span: { sm: 2, md: 4, lg: 4 } },
|
|
8
|
+
{ label: "Card", span: { sm: 2, md: 4, lg: 4 } },
|
|
9
|
+
{ label: "Card", span: { sm: 2, md: 4, lg: 4 } },
|
|
10
|
+
{ label: "Card", span: { sm: 2, md: 4, lg: 4 } },
|
|
11
|
+
],
|
|
12
|
+
} as const;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Grid, GridItem } from "@ds";
|
|
2
|
+
import { GridCell } from "@ds/review";
|
|
3
|
+
import { fixture } from "./Grid.ads.fixture";
|
|
4
|
+
export const scenario = { title: fixture.title, covers: ["Grid", "GridItem"] };
|
|
5
|
+
// Edge to edge, so the grid lines up with the showcase's grid overlay at every width.
|
|
6
|
+
export default function Scenario() {
|
|
7
|
+
return (
|
|
8
|
+
<Grid>
|
|
9
|
+
{fixture.columns.map(column => (
|
|
10
|
+
<GridItem key={column} span={{ sm: 1, md: 1, lg: 1 }}><GridCell label={column} /></GridItem>
|
|
11
|
+
))}
|
|
12
|
+
{fixture.layout.map((cell, index) => (
|
|
13
|
+
<GridItem key={index} span={cell.span}><GridCell label={cell.label} /></GridItem>
|
|
14
|
+
))}
|
|
15
|
+
</Grid>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, type ReactNode } from "react";
|
|
2
|
+
import { css, cx } from "@linaria/atomic";
|
|
3
|
+
|
|
4
|
+
export interface GridProps {
|
|
5
|
+
/** `wide` 32 px gutters (default), `narrow` 16 px, `condensed` 1 px for tightly related content. */
|
|
6
|
+
gutter?: "wide" | "narrow" | "condensed";
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export interface GridItemProps {
|
|
10
|
+
/** Columns to span at each container size (of 4, 8 and 16). A size left out spans the full row. */
|
|
11
|
+
span?: { sm?: number; md?: number; lg?: number };
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The grid follows its container, not the window: it sits in any pane at the right columns.
|
|
16
|
+
const container = css`
|
|
17
|
+
container-type: inline-size;
|
|
18
|
+
width: 100%;
|
|
19
|
+
`;
|
|
20
|
+
const grid = css`
|
|
21
|
+
display: grid;
|
|
22
|
+
grid-template-columns: repeat(var(--grid-columns-sm), minmax(0, 1fr));
|
|
23
|
+
padding-inline: var(--grid-margin-sm);
|
|
24
|
+
@container (min-width: 768px) {
|
|
25
|
+
grid-template-columns: repeat(var(--grid-columns-md), minmax(0, 1fr));
|
|
26
|
+
padding-inline: var(--grid-margin-md);
|
|
27
|
+
}
|
|
28
|
+
@container (min-width: 1024px) {
|
|
29
|
+
grid-template-columns: repeat(var(--grid-columns-lg), minmax(0, 1fr));
|
|
30
|
+
}
|
|
31
|
+
@container (min-width: 1280px) {
|
|
32
|
+
padding-inline: var(--grid-margin-lg);
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
const gutters = {
|
|
36
|
+
wide: css`gap: var(--grid-gutter);`,
|
|
37
|
+
narrow: css`gap: var(--grid-gutter-narrow);`,
|
|
38
|
+
condensed: css`gap: var(--grid-gutter-condensed);`,
|
|
39
|
+
};
|
|
40
|
+
const item = css`
|
|
41
|
+
min-width: 0;
|
|
42
|
+
grid-column: span var(--ds-grid-span-sm, var(--grid-columns-sm));
|
|
43
|
+
@container (min-width: 768px) {
|
|
44
|
+
grid-column: span var(--ds-grid-span-md, var(--grid-columns-md));
|
|
45
|
+
}
|
|
46
|
+
@container (min-width: 1024px) {
|
|
47
|
+
grid-column: span var(--ds-grid-span-lg, var(--grid-columns-lg));
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
/** A column grid: 4, 8 or 16 columns by its container's width, with spacing-scale gutters. */
|
|
52
|
+
export function Grid({ gutter = "wide", children }: GridProps) {
|
|
53
|
+
return (
|
|
54
|
+
<div className={cx("ds-grid", container)}>
|
|
55
|
+
<div className={cx(grid, gutters[gutter])}>{children}</div>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** One cell of a `Grid`, spanning some of its columns at each size. */
|
|
61
|
+
export function GridItem({ span, children }: GridItemProps) {
|
|
62
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
const element = ref.current;
|
|
65
|
+
if (!element) return;
|
|
66
|
+
// Each size names its own variable: ADS allows only declared, literal style writes.
|
|
67
|
+
if (span?.sm) element.style.setProperty("--ds-grid-span-sm", String(span.sm));
|
|
68
|
+
else element.style.removeProperty("--ds-grid-span-sm");
|
|
69
|
+
if (span?.md) element.style.setProperty("--ds-grid-span-md", String(span.md));
|
|
70
|
+
else element.style.removeProperty("--ds-grid-span-md");
|
|
71
|
+
if (span?.lg) element.style.setProperty("--ds-grid-span-lg", String(span.lg));
|
|
72
|
+
else element.style.removeProperty("--ds-grid-span-lg");
|
|
73
|
+
}, [span?.sm, span?.md, span?.lg]);
|
|
74
|
+
return <div ref={ref} className={cx("ds-grid__item", item)}>{children}</div>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Grid
|
|
2
|
+
|
|
3
|
+
A column grid: 4 columns, then 8 from 768 px and 16 from 1024 px of
|
|
4
|
+
**container** width (container queries), so it fits any pane. Margins are 0, 16 and 24 px;
|
|
5
|
+
`gutter` is `wide` (32 px, default), `narrow` (16 px) or `condensed` (1 px, for tightly
|
|
6
|
+
related content). All lengths come from the `--grid-*` tokens, which alias spacing steps.
|
|
7
|
+
|
|
8
|
+
`GridItem` spans `span.sm`, `span.md` and `span.lg` columns; a size left out spans the full
|
|
9
|
+
row. Align text to the item's edge; never let content touch the gutter.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<Grid>
|
|
13
|
+
<GridItem span={{ md: 5, lg: 11 }}>Main</GridItem>
|
|
14
|
+
<GridItem span={{ md: 3, lg: 5 }}>Aside</GridItem>
|
|
15
|
+
</Grid>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| Prop | Type | Default |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| `Grid` `gutter` | `"wide" \| "narrow" \| "condensed"` | `"wide"` |
|
|
21
|
+
| `GridItem` `span` | `{ sm?: number; md?: number; lg?: number }` | full row |
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Renderer colors for Canvas, WebGL and SVG drawing. Read a palette once per render or
|
|
2
|
+
// context change with paletteFor(element), look colors up inside per-item loops, and
|
|
3
|
+
// redraw from observePalette(element, callback). Nothing here inserts DOM nodes.
|
|
4
|
+
import {
|
|
5
|
+
brands,
|
|
6
|
+
contexts,
|
|
7
|
+
defaultContext,
|
|
8
|
+
palette,
|
|
9
|
+
systemThemes,
|
|
10
|
+
themes,
|
|
11
|
+
type ColorToken,
|
|
12
|
+
type Palette,
|
|
13
|
+
type PaletteColor,
|
|
14
|
+
type PaletteContext,
|
|
15
|
+
} from "../../tokens/themes.generated";
|
|
16
|
+
|
|
17
|
+
export type { ColorToken, Palette, PaletteColor, PaletteContext };
|
|
18
|
+
|
|
19
|
+
const themeSelector = themes.map((name) => `[data-theme="${name}"]`).join(", ");
|
|
20
|
+
const brandSelector = brands.map((name) => `[data-brand="${name}"]`).join(", ");
|
|
21
|
+
const darkScheme = "(prefers-color-scheme: dark)";
|
|
22
|
+
|
|
23
|
+
/** The nearest ancestor (or the element itself) matching a selector, crossing shadow roots. */
|
|
24
|
+
function closest(element: Element, selector: string): Element | null {
|
|
25
|
+
let node: Element | null = element;
|
|
26
|
+
while (node) {
|
|
27
|
+
const found = node.closest(selector);
|
|
28
|
+
if (found) return found;
|
|
29
|
+
const root = node.getRootNode();
|
|
30
|
+
node = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.host : null;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function systemTheme(): string | null {
|
|
36
|
+
// Like the generated sheet, the OS scheme applies only to a root without data-theme.
|
|
37
|
+
if (!systemThemes || typeof matchMedia !== "function" || document.documentElement.hasAttribute("data-theme")) return null;
|
|
38
|
+
return matchMedia(darkScheme).matches ? systemThemes.dark : systemThemes.light;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The palette context an element renders in: its nearest declared data-theme and data-brand,
|
|
42
|
+
* else the OS color scheme (with followSystemTheme) or the default theme and brand. */
|
|
43
|
+
export function paletteContext(element: Element): PaletteContext {
|
|
44
|
+
const theme = closest(element, themeSelector)?.getAttribute("data-theme") ?? systemTheme() ?? themes[0];
|
|
45
|
+
const brand = brandSelector ? closest(element, brandSelector)?.getAttribute("data-brand") : null;
|
|
46
|
+
const key = brand && brand !== (brands as readonly string[])[0] ? `${brand}/${theme}` : theme;
|
|
47
|
+
return (contexts as readonly string[]).includes(key) ? (key as PaletteContext) : defaultContext;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Every color token resolved for the element's context. Read it once per render, outside
|
|
51
|
+
* per-node and per-edge loops; it is a static object, so lookups cost nothing. */
|
|
52
|
+
export function paletteFor(element: Element): Palette {
|
|
53
|
+
return palette[paletteContext(element)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Colors outside the palette, normalized once by one offscreen 2D context.
|
|
57
|
+
const cacheSize = 256;
|
|
58
|
+
const colors = new Map<string, PaletteColor | null>();
|
|
59
|
+
let context2d: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null | undefined;
|
|
60
|
+
|
|
61
|
+
type Subscriber = { element: Element; callback: (palette: Palette, context: PaletteContext) => void; context: PaletteContext };
|
|
62
|
+
const subscribers = new Set<Subscriber>();
|
|
63
|
+
let observer: MutationObserver | null = null;
|
|
64
|
+
let media: MediaQueryList | null = null;
|
|
65
|
+
|
|
66
|
+
function refresh(records?: MutationRecord[]) {
|
|
67
|
+
let changed = false;
|
|
68
|
+
for (const subscriber of subscribers) {
|
|
69
|
+
if (!subscribers.has(subscriber)) continue; // unsubscribed by an earlier callback
|
|
70
|
+
// Only an attribute change on the element or an ancestor can change its context.
|
|
71
|
+
if (records && subscriber.element.getRootNode() === document && !records.some((record) => record.target === subscriber.element || record.target.contains(subscriber.element))) continue;
|
|
72
|
+
const context = paletteContext(subscriber.element);
|
|
73
|
+
if (context === subscriber.context) continue;
|
|
74
|
+
subscriber.context = context;
|
|
75
|
+
changed = true;
|
|
76
|
+
subscriber.callback(palette[context], context);
|
|
77
|
+
}
|
|
78
|
+
if (changed) colors.clear();
|
|
79
|
+
}
|
|
80
|
+
const onMedia = () => refresh();
|
|
81
|
+
|
|
82
|
+
/** Calls back with the new palette whenever the element's effective context changes: a
|
|
83
|
+
* data-theme or data-brand change on it or an ancestor, or the OS color scheme with
|
|
84
|
+
* followSystemTheme. Returns the unsubscribe function. One shared observer serves all. */
|
|
85
|
+
export function observePalette(element: Element, callback: (palette: Palette, context: PaletteContext) => void): () => void {
|
|
86
|
+
const subscriber: Subscriber = { element, callback, context: paletteContext(element) };
|
|
87
|
+
subscribers.add(subscriber);
|
|
88
|
+
if (!observer && typeof MutationObserver === "function") {
|
|
89
|
+
observer = new MutationObserver((records) => refresh(records));
|
|
90
|
+
observer.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ["data-theme", "data-brand"] });
|
|
91
|
+
}
|
|
92
|
+
if (!media && systemThemes && typeof matchMedia === "function") {
|
|
93
|
+
media = matchMedia(darkScheme);
|
|
94
|
+
media.addEventListener("change", onMedia);
|
|
95
|
+
}
|
|
96
|
+
return () => {
|
|
97
|
+
subscribers.delete(subscriber);
|
|
98
|
+
if (subscribers.size) return;
|
|
99
|
+
observer?.disconnect();
|
|
100
|
+
observer = null;
|
|
101
|
+
media?.removeEventListener("change", onMedia);
|
|
102
|
+
media = null;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function canvas2d() {
|
|
107
|
+
if (context2d !== undefined) return context2d;
|
|
108
|
+
const canvas = typeof OffscreenCanvas === "function" ? new OffscreenCanvas(1, 1) : typeof document !== "undefined" ? Object.assign(document.createElement("canvas"), { width: 1, height: 1 }) : null;
|
|
109
|
+
context2d = (canvas?.getContext("2d", { willReadFrequently: true }) as OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null | undefined) ?? null;
|
|
110
|
+
return context2d;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const hex = (value: number) => value.toString(16).padStart(2, "0");
|
|
114
|
+
function fromChannels(r: number, g: number, b: number, a: number): PaletteColor {
|
|
115
|
+
const alpha = Math.round(a * 10000) / 10000;
|
|
116
|
+
return { css: alpha >= 1 ? `#${hex(r)}${hex(g)}${hex(b)}` : `rgba(${r}, ${g}, ${b}, ${alpha})`, rgba: [r, g, b, alpha] };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function normalize(value: string): PaletteColor | null {
|
|
120
|
+
const ctx = canvas2d();
|
|
121
|
+
if (!ctx) return null;
|
|
122
|
+
// An invalid color leaves fillStyle unchanged; two sentinels tell it apart from a valid one.
|
|
123
|
+
ctx.fillStyle = "#000000";
|
|
124
|
+
ctx.fillStyle = value;
|
|
125
|
+
const first = String(ctx.fillStyle);
|
|
126
|
+
ctx.fillStyle = "#ffffff";
|
|
127
|
+
ctx.fillStyle = value;
|
|
128
|
+
if (first !== String(ctx.fillStyle)) return null;
|
|
129
|
+
const legacy = first.match(/^#([\da-f]{6})$/i) ?? first.match(/^rgba\((\d+), (\d+), (\d+), ([\d.]+)\)$/);
|
|
130
|
+
if (legacy) return legacy.length === 2 ? fromChannels(parseInt(legacy[1].slice(0, 2), 16), parseInt(legacy[1].slice(2, 4), 16), parseInt(legacy[1].slice(4), 16), 1) : fromChannels(Number(legacy[1]), Number(legacy[2]), Number(legacy[3]), Number(legacy[4]));
|
|
131
|
+
// Wider color syntax: draw one pixel; the canvas clips to sRGB.
|
|
132
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
133
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
134
|
+
const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
|
|
135
|
+
return fromChannels(r, g, b, a / 255);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A color for a value outside the palette: a palette token (--name or var(--name)) from the
|
|
139
|
+
* element's context, currentColor or another token from the element's computed style, or any
|
|
140
|
+
* absolute CSS color. Absolute strings are normalized once by an offscreen canvas and kept in a
|
|
141
|
+
* bounded cache; the cache clears when an observed context changes. Null when not a color. */
|
|
142
|
+
export function resolveColor(element: Element, value: string): PaletteColor | null {
|
|
143
|
+
let text = value.trim();
|
|
144
|
+
const token = text.match(/^var\(\s*(--[\w-]+)\s*\)$/)?.[1] ?? (text.startsWith("--") ? text : null);
|
|
145
|
+
if (token) {
|
|
146
|
+
const own = (paletteFor(element) as Record<string, PaletteColor | undefined>)[token];
|
|
147
|
+
if (own) return own;
|
|
148
|
+
text = getComputedStyle(element).getPropertyValue(token).trim();
|
|
149
|
+
} else if (/^currentcolor$/i.test(text) || text.includes("var(")) {
|
|
150
|
+
const style = getComputedStyle(element);
|
|
151
|
+
text = /^currentcolor$/i.test(text) ? style.color : text.replace(/var\(\s*(--[\w-]+)\s*\)/g, (_match, name: string) => style.getPropertyValue(name).trim());
|
|
152
|
+
}
|
|
153
|
+
if (!text) return null;
|
|
154
|
+
if (colors.has(text)) {
|
|
155
|
+
const cached = colors.get(text) ?? null;
|
|
156
|
+
colors.delete(text);
|
|
157
|
+
colors.set(text, cached);
|
|
158
|
+
return cached;
|
|
159
|
+
}
|
|
160
|
+
const color = normalize(text);
|
|
161
|
+
colors.set(text, color);
|
|
162
|
+
if (colors.size > cacheSize) colors.delete(colors.keys().next().value as string);
|
|
163
|
+
return color;
|
|
164
|
+
}
|
|
@@ -3,6 +3,12 @@ import "./styles.css";
|
|
|
3
3
|
|
|
4
4
|
// Public components and patterns. Add new ones here as they are implemented.
|
|
5
5
|
export { Button, type ButtonProps } from "./components/Actions/Button/Button";
|
|
6
|
+
export { IconButton, type IconButtonProps } from "./components/Actions/IconButton/IconButton";
|
|
7
|
+
export { Icon, iconNames, type IconName, type IconProps } from "./components/Content/Icon/Icon";
|
|
6
8
|
export { Logo, type LogoProps } from "./components/Content/Logo/Logo";
|
|
7
9
|
export { TextField, type TextFieldProps } from "./components/Forms/TextField/TextField";
|
|
10
|
+
export { Grid, GridItem, type GridProps, type GridItemProps } from "./components/Layout/Grid/Grid";
|
|
8
11
|
export { SearchBar, type SearchBarProps } from "./patterns/Search/SearchBar/SearchBar";
|
|
12
|
+
|
|
13
|
+
// Renderer colors for Canvas, WebGL and SVG drawing, from the generated tokens/themes.generated.ts.
|
|
14
|
+
export { observePalette, paletteContext, paletteFor, resolveColor, type ColorToken, type Palette, type PaletteColor, type PaletteContext } from "./controllers/Palette/Palette";
|
|
@@ -57,11 +57,8 @@ const label = css`
|
|
|
57
57
|
overflow-wrap: anywhere;
|
|
58
58
|
`;
|
|
59
59
|
// Paired artwork shows the variant of the current theme, as the UI does.
|
|
60
|
-
const light = css
|
|
61
|
-
const dark = css`
|
|
62
|
-
display: none;
|
|
63
|
-
:root[data-theme="dark"] & { display: block; }
|
|
64
|
-
`;
|
|
60
|
+
const light = css`display: var(--display-light, block);`;
|
|
61
|
+
const dark = css`display: var(--display-dark, block);`;
|
|
65
62
|
const icons = css`
|
|
66
63
|
display: flex;
|
|
67
64
|
flex-wrap: wrap;
|