sproutsite 0.5.20 → 0.5.22
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/THIRD_PARTY_NOTICES.md +4 -0
- package/VERSION +1 -1
- package/package.json +1 -1
- package/src/lib/sproutsite/badges.ts +43 -0
- package/src/lib/sproutsite/validation.ts +92 -20
- package/src/package/components.ts +1 -0
- package/src/themes/default/components/atoms/Badge/Badge.astro +5 -12
- package/src/themes/default/components/molecules/Card/Card.astro +72 -12
- package/src/themes/default/components/molecules/Card/Card.css +79 -2
- package/src/themes/default/components/molecules/Card/Card.ts +97 -0
- package/src/themes/default/components/organisms/Hero/Hero.css +0 -1
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -71,6 +71,10 @@ Copyright licensing of artwork and trademark rights are separate. Apache-2.0 Sec
|
|
|
71
71
|
|
|
72
72
|
## Other visual assets: provenance review remains open
|
|
73
73
|
|
|
74
|
+
Generation record: the 18 topic-card PNGs in `src/content/pages/documentation/getting-started/contributing/_assets/` were generated on 2026-11-20 with OpenAI's built-in image-generation tool. Each request used the existing first-party showcase `buttons.png` as its sole visual style input and specified a separate contributor topic. No new third-party artwork or logos were supplied. Full prompts, the input hash and retained output paths are recorded in [docs/assets/contributing-images.md](docs/assets/contributing-images.md). This records provenance, not a separate artwork-license grant.
|
|
75
|
+
|
|
76
|
+
Generation record: the 22 topic-card PNGs in `src/content/pages/documentation/getting-started/your-website/_assets/` were generated and subsequently replaced on 2026-11-19 with OpenAI's built-in image-generation tool. The current replacements use the maintainer-supplied rendition of the existing showcase buttons illustration as a visual style input, with close foreground subjects, a pale upper wall and a defined wave crest fading into the floor. The original text-only series is superseded. Both prompt sets, the style input and retained output paths are recorded in [docs/assets/your-website-images.md](docs/assets/your-website-images.md). This documents provenance and does not establish a separate artwork-license grant.
|
|
77
|
+
|
|
74
78
|
Background refinement record: on 2026-11-18, the eight documentation-overview and six blog PNGs were edited with OpenAI's built-in image-generation tool to match the broad, softly fading wave in the existing first-party showcase `cards.png`. Each edit used the existing illustration as its target and the showcase image as its background-style reference. Foreground subjects were retained. The full prompt, input paths and retained output filenames are recorded in [docs/assets/background-wave-refinements.md](docs/assets/background-wave-refinements.md). Earlier text-only generation records below describe the source illustrations before this refinement. No new third-party image inputs were used; this provenance record does not add an artwork-license grant.
|
|
75
79
|
|
|
76
80
|
Generation record: all six current PNG illustrations in `src/content/blog/_assets/` were regenerated on 2026-11-18 using OpenAI's built-in image-generation tool, following the maintainer-approved navy-and-teal 3D style. Full text-only prompts and output paths are recorded in [docs/assets/blog-images.md](docs/assets/blog-images.md). No image inputs or third-party logos were supplied. The new `sproutsite-brand.png` is an editorial seedling-and-website illustration, replacing the earlier wordmark composite; the official branding SVGs are unchanged. This supersedes the earlier generation record for the replaced Apache-license illustration and does not constitute a separate artwork-license grant.
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.5.
|
|
1
|
+
0.5.22
|
package/package.json
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Semantic options shared by Badge, Card and content validation. */
|
|
4
|
+
export const badgeVariants = [
|
|
5
|
+
'default',
|
|
6
|
+
'primary',
|
|
7
|
+
'secondary',
|
|
8
|
+
'accent',
|
|
9
|
+
'neutral',
|
|
10
|
+
'info',
|
|
11
|
+
'success',
|
|
12
|
+
'warning',
|
|
13
|
+
'error',
|
|
14
|
+
] as const;
|
|
15
|
+
export const badgeStyles = ['solid', 'outline', 'soft', 'dash'] as const;
|
|
16
|
+
export const badgeSizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
|
|
17
|
+
export type BadgeVariant = (typeof badgeVariants)[number];
|
|
18
|
+
export type BadgeStyle = (typeof badgeStyles)[number];
|
|
19
|
+
export type BadgeSize = (typeof badgeSizes)[number];
|
|
20
|
+
|
|
21
|
+
const cardBadgeSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
text: z.string().trim().min(1),
|
|
24
|
+
variant: z.enum(badgeVariants).optional(),
|
|
25
|
+
style: z.enum(badgeStyles).optional(),
|
|
26
|
+
hover: z.string().trim().min(1).optional(),
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
|
|
30
|
+
export type CardBadge = z.infer<typeof cardBadgeSchema>;
|
|
31
|
+
|
|
32
|
+
/** Accept one descriptor or a list without changing Badge's own defaults. */
|
|
33
|
+
export function normalizeCardBadges(value: unknown): CardBadge[] {
|
|
34
|
+
if (value === undefined) return [];
|
|
35
|
+
const result = z
|
|
36
|
+
.array(cardBadgeSchema)
|
|
37
|
+
.safeParse(Array.isArray(value) ? value : [value]);
|
|
38
|
+
if (!result.success)
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Card badges must contain non-empty text, optional Badge variant and style, and optional non-empty hover text only: ${result.error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ')}`,
|
|
41
|
+
);
|
|
42
|
+
return result.data;
|
|
43
|
+
}
|
|
@@ -2,6 +2,7 @@ import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
|
2
2
|
import { extname, join, relative, resolve } from 'node:path';
|
|
3
3
|
import GithubSlugger from 'github-slugger';
|
|
4
4
|
import type { Root } from 'mdast';
|
|
5
|
+
import type { Expression, Program, SpreadElement } from 'estree';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
import { parse as parseYaml } from 'yaml';
|
|
7
8
|
import { unified } from 'unified';
|
|
@@ -12,6 +13,12 @@ import { visit } from 'unist-util-visit';
|
|
|
12
13
|
import { loadSiteConfig } from './site-config.js';
|
|
13
14
|
import { heroTypes, sectionSpacings, tones } from './types.js';
|
|
14
15
|
import { isHexColor } from './colors.js';
|
|
16
|
+
import {
|
|
17
|
+
badgeVariants,
|
|
18
|
+
badgeStyles,
|
|
19
|
+
badgeSizes,
|
|
20
|
+
normalizeCardBadges,
|
|
21
|
+
} from './badges.js';
|
|
15
22
|
import { routeFromPageId } from './urls.js';
|
|
16
23
|
|
|
17
24
|
const pageSchema = z.object({
|
|
@@ -132,7 +139,65 @@ interface MdxNode {
|
|
|
132
139
|
interface MdxAttribute {
|
|
133
140
|
type: string;
|
|
134
141
|
name?: string;
|
|
135
|
-
value?:
|
|
142
|
+
value?:
|
|
143
|
+
| string
|
|
144
|
+
| { type: string; value?: string; data?: { estree?: Program } }
|
|
145
|
+
| null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Read only literal badge descriptors from MDX's existing ESTree; never evaluate code. */
|
|
149
|
+
function cardBadgesFromAttribute(attribute: MdxAttribute): unknown {
|
|
150
|
+
const value = attribute.value;
|
|
151
|
+
const body =
|
|
152
|
+
value && typeof value === 'object'
|
|
153
|
+
? value.data?.estree?.body
|
|
154
|
+
: undefined;
|
|
155
|
+
const statement = body?.length === 1 ? body[0] : undefined;
|
|
156
|
+
const expression =
|
|
157
|
+
statement?.type === 'ExpressionStatement'
|
|
158
|
+
? statement.expression
|
|
159
|
+
: undefined;
|
|
160
|
+
const descriptor = (
|
|
161
|
+
node: Expression | SpreadElement | null,
|
|
162
|
+
): Record<string, string> => {
|
|
163
|
+
if (node?.type !== 'ObjectExpression')
|
|
164
|
+
throw new Error('Expected a literal badge object.');
|
|
165
|
+
const entries: [string, string][] = [];
|
|
166
|
+
for (const property of node.properties) {
|
|
167
|
+
if (
|
|
168
|
+
property.type !== 'Property' ||
|
|
169
|
+
property.computed ||
|
|
170
|
+
property.method ||
|
|
171
|
+
property.shorthand ||
|
|
172
|
+
property.kind !== 'init'
|
|
173
|
+
)
|
|
174
|
+
throw new Error(
|
|
175
|
+
'Badge properties must be literal text fields.',
|
|
176
|
+
);
|
|
177
|
+
const key =
|
|
178
|
+
property.key.type === 'Identifier'
|
|
179
|
+
? property.key.name
|
|
180
|
+
: property.key.type === 'Literal' &&
|
|
181
|
+
typeof property.key.value === 'string'
|
|
182
|
+
? property.key.value
|
|
183
|
+
: undefined;
|
|
184
|
+
if (
|
|
185
|
+
!key ||
|
|
186
|
+
property.value.type !== 'Literal' ||
|
|
187
|
+
typeof property.value.value !== 'string' ||
|
|
188
|
+
entries.some(([name]) => name === key)
|
|
189
|
+
)
|
|
190
|
+
throw new Error(
|
|
191
|
+
'Badge fields must have unique names and literal string values.',
|
|
192
|
+
);
|
|
193
|
+
entries.push([key, property.value.value]);
|
|
194
|
+
}
|
|
195
|
+
return Object.fromEntries(entries);
|
|
196
|
+
};
|
|
197
|
+
if (expression?.type === 'ObjectExpression') return descriptor(expression);
|
|
198
|
+
if (expression?.type === 'ArrayExpression')
|
|
199
|
+
return expression.elements.map(descriptor);
|
|
200
|
+
throw new Error('Expected a literal badge object or array.');
|
|
136
201
|
}
|
|
137
202
|
|
|
138
203
|
function filesIn(directory: string): string[] {
|
|
@@ -940,25 +1005,15 @@ function validateMdxLayout(
|
|
|
940
1005
|
new Set(attributes.map((attribute) => attribute.name))
|
|
941
1006
|
.size !== attributes.length ||
|
|
942
1007
|
(variant &&
|
|
943
|
-
!
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
'secondary',
|
|
947
|
-
'accent',
|
|
948
|
-
'neutral',
|
|
949
|
-
'info',
|
|
950
|
-
'success',
|
|
951
|
-
'warning',
|
|
952
|
-
'error',
|
|
953
|
-
].includes(String(variant.value))) ||
|
|
1008
|
+
!badgeVariants.some(
|
|
1009
|
+
(option) => option === variant.value,
|
|
1010
|
+
)) ||
|
|
954
1011
|
(style &&
|
|
955
|
-
!
|
|
956
|
-
|
|
1012
|
+
!badgeStyles.some(
|
|
1013
|
+
(option) => option === style.value,
|
|
957
1014
|
)) ||
|
|
958
1015
|
(size &&
|
|
959
|
-
!
|
|
960
|
-
String(size.value),
|
|
961
|
-
))
|
|
1016
|
+
!badgeSizes.some((option) => option === size.value))
|
|
962
1017
|
)
|
|
963
1018
|
fail(
|
|
964
1019
|
contentRoot,
|
|
@@ -1113,6 +1168,20 @@ function validateMdxLayout(
|
|
|
1113
1168
|
} else if (mdxNode.name === 'Card') {
|
|
1114
1169
|
cardCount += 1;
|
|
1115
1170
|
const attributes = mdxNode.attributes ?? [];
|
|
1171
|
+
const badges = attributes.find(
|
|
1172
|
+
(attribute) => attribute.name === 'badges',
|
|
1173
|
+
);
|
|
1174
|
+
if (badges) {
|
|
1175
|
+
try {
|
|
1176
|
+
normalizeCardBadges(cardBadgesFromAttribute(badges));
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
fail(
|
|
1179
|
+
contentRoot,
|
|
1180
|
+
path,
|
|
1181
|
+
`Card badges: ${error instanceof Error ? error.message : 'Invalid badge descriptors.'}`,
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1116
1185
|
const image = attributes.find(
|
|
1117
1186
|
(attribute) =>
|
|
1118
1187
|
attribute.type === 'mdxJsxAttribute' &&
|
|
@@ -1140,13 +1209,16 @@ function validateMdxLayout(
|
|
|
1140
1209
|
);
|
|
1141
1210
|
actions.forEach((action) => validatedCardActions.add(action));
|
|
1142
1211
|
if (
|
|
1143
|
-
attributes.length >
|
|
1212
|
+
attributes.length > 4 ||
|
|
1213
|
+
new Set(attributes.map((attribute) => attribute.name))
|
|
1214
|
+
.size !== attributes.length ||
|
|
1144
1215
|
attributes.some(
|
|
1145
1216
|
(attribute) =>
|
|
1146
1217
|
attribute.type !== 'mdxJsxAttribute' ||
|
|
1147
1218
|
(attribute.name !== 'image' &&
|
|
1148
1219
|
attribute.name !== 'imageAlt' &&
|
|
1149
|
-
attribute.name !== 'shadow'
|
|
1220
|
+
attribute.name !== 'shadow' &&
|
|
1221
|
+
attribute.name !== 'badges'),
|
|
1150
1222
|
) ||
|
|
1151
1223
|
Boolean(image) !== Boolean(imageAlt) ||
|
|
1152
1224
|
(image && !localImageImports.has(imageImport ?? '')) ||
|
|
@@ -1163,7 +1235,7 @@ function validateMdxLayout(
|
|
|
1163
1235
|
fail(
|
|
1164
1236
|
contentRoot,
|
|
1165
1237
|
path,
|
|
1166
|
-
'Card accepts image and imageAlt together, or neither; optional shadow is none, sm, md, lg, or xl; it may contain one direct CardActions component',
|
|
1238
|
+
'Card accepts image and imageAlt together, or neither; optional shadow is none, sm, md, lg, or xl; badges is a literal object or list with text and optional Badge variant, style and hover text; it may contain one direct CardActions component',
|
|
1167
1239
|
);
|
|
1168
1240
|
} else if (mdxNode.name === 'CardActions') {
|
|
1169
1241
|
if (
|
|
@@ -4,6 +4,7 @@ export { default as FoundationSample } from '../themes/default/components/molecu
|
|
|
4
4
|
export { default as Tabs } from '../themes/default/components/molecules/Tabs/Tabs.astro';
|
|
5
5
|
export { default as Tab } from '../themes/default/components/atoms/Tab/Tab.astro';
|
|
6
6
|
export { default as Card } from '../themes/default/components/molecules/Card/Card.astro';
|
|
7
|
+
export type { CardBadge } from '../lib/sproutsite/badges.js';
|
|
7
8
|
export { default as CardActions } from '../themes/default/components/molecules/CardActions/CardActions.astro';
|
|
8
9
|
export { default as ContentImage } from '../themes/default/components/atoms/ContentImage/ContentImage.astro';
|
|
9
10
|
export { default as Eyebrow } from '../themes/default/components/atoms/Eyebrow/Eyebrow.astro';
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
| 'neutral'
|
|
8
|
-
| 'info'
|
|
9
|
-
| 'success'
|
|
10
|
-
| 'warning'
|
|
11
|
-
| 'error';
|
|
12
|
-
type BadgeStyle = 'solid' | 'outline' | 'soft' | 'dash';
|
|
13
|
-
type BadgeSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
2
|
+
import type {
|
|
3
|
+
BadgeVariant,
|
|
4
|
+
BadgeStyle,
|
|
5
|
+
BadgeSize,
|
|
6
|
+
} from '../../../../../lib/sproutsite/badges.js';
|
|
14
7
|
|
|
15
8
|
/** A compact DaisyUI status or category label with a default slot for its text. */
|
|
16
9
|
interface Props {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { ImageMetadata } from 'astro';
|
|
3
3
|
import { Image } from 'astro:assets';
|
|
4
|
+
import {
|
|
5
|
+
normalizeCardBadges,
|
|
6
|
+
type CardBadge,
|
|
7
|
+
} from '../../../../../lib/sproutsite/badges.js';
|
|
8
|
+
import Badge from '../../atoms/Badge/Badge.astro';
|
|
4
9
|
|
|
5
10
|
type CardShadow = 'none' | 'sm' | 'md' | 'lg' | 'xl';
|
|
6
11
|
|
|
@@ -12,9 +17,15 @@ interface Props {
|
|
|
12
17
|
imageAlt?: string;
|
|
13
18
|
/** Elevation treatment for the card. */
|
|
14
19
|
shadow?: CardShadow;
|
|
20
|
+
/** One status label or a list, displayed at the bottom right of the media area. */
|
|
21
|
+
badges?: CardBadge | readonly CardBadge[];
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
const { image, imageAlt, shadow = 'sm' } = Astro.props;
|
|
24
|
+
const { image, imageAlt, shadow = 'sm', badges } = Astro.props;
|
|
25
|
+
const labels = normalizeCardBadges(badges);
|
|
26
|
+
const hintPrefix = labels.some((label) => label.hover)
|
|
27
|
+
? `ss-card-hint-${crypto.randomUUID()}`
|
|
28
|
+
: '';
|
|
18
29
|
const shadowClasses: Record<CardShadow, string> = {
|
|
19
30
|
none: 'shadow-none',
|
|
20
31
|
sm: 'shadow-sm',
|
|
@@ -37,17 +48,62 @@ if (Boolean(image) !== Boolean(imageAlt))
|
|
|
37
48
|
'not-prose',
|
|
38
49
|
]}
|
|
39
50
|
>
|
|
40
|
-
{image && (
|
|
41
|
-
<figure
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
{(image || labels.length > 0) && (
|
|
52
|
+
<figure
|
|
53
|
+
class:list={[
|
|
54
|
+
'ss-card__figure',
|
|
55
|
+
{ 'ss-card__figure--placeholder': !image },
|
|
56
|
+
]}
|
|
57
|
+
>
|
|
58
|
+
{image && (
|
|
59
|
+
<Image
|
|
60
|
+
src={image}
|
|
61
|
+
alt={imageAlt!}
|
|
62
|
+
format="webp"
|
|
63
|
+
quality={80}
|
|
64
|
+
loading="lazy"
|
|
65
|
+
decoding="async"
|
|
66
|
+
class="ss-card__image"
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
{labels.length > 0 && (
|
|
70
|
+
<ul class="ss-card__badges">
|
|
71
|
+
{labels.map((label, index) => (
|
|
72
|
+
<li>
|
|
73
|
+
{label.hover ? (
|
|
74
|
+
<span
|
|
75
|
+
class="ss-card__badge-hint"
|
|
76
|
+
tabindex="0"
|
|
77
|
+
aria-describedby={`${hintPrefix}-${index}`}
|
|
78
|
+
>
|
|
79
|
+
<Badge
|
|
80
|
+
variant={label.variant}
|
|
81
|
+
style={label.style}
|
|
82
|
+
>
|
|
83
|
+
{label.text}
|
|
84
|
+
</Badge>
|
|
85
|
+
<span
|
|
86
|
+
class="ss-card__badge-tooltip"
|
|
87
|
+
id={`${hintPrefix}-${index}`}
|
|
88
|
+
role="tooltip"
|
|
89
|
+
popover="manual"
|
|
90
|
+
hidden
|
|
91
|
+
>
|
|
92
|
+
{label.hover}
|
|
93
|
+
</span>
|
|
94
|
+
</span>
|
|
95
|
+
) : (
|
|
96
|
+
<Badge
|
|
97
|
+
variant={label.variant}
|
|
98
|
+
style={label.style}
|
|
99
|
+
>
|
|
100
|
+
{label.text}
|
|
101
|
+
</Badge>
|
|
102
|
+
)}
|
|
103
|
+
</li>
|
|
104
|
+
))}
|
|
105
|
+
</ul>
|
|
106
|
+
)}
|
|
51
107
|
</figure>
|
|
52
108
|
)}
|
|
53
109
|
<div class="ss-card__body card-body">
|
|
@@ -55,3 +111,7 @@ if (Boolean(image) !== Boolean(imageAlt))
|
|
|
55
111
|
<slot />
|
|
56
112
|
</div>
|
|
57
113
|
</article>
|
|
114
|
+
|
|
115
|
+
<script>
|
|
116
|
+
import './Card';
|
|
117
|
+
</script>
|
|
@@ -4,10 +4,87 @@
|
|
|
4
4
|
border: 1px solid var(--color-base-300);
|
|
5
5
|
|
|
6
6
|
.ss-card__figure {
|
|
7
|
-
@apply overflow-hidden;
|
|
7
|
+
@apply relative overflow-hidden;
|
|
8
|
+
/* Override DaisyUI's figure display to keep a growing overlay row. */
|
|
9
|
+
display: grid !important;
|
|
10
|
+
grid-template-columns: minmax(0, 1fr);
|
|
11
|
+
min-height: 14rem;
|
|
12
|
+
|
|
13
|
+
&.ss-card__figure--placeholder {
|
|
14
|
+
@apply w-full;
|
|
15
|
+
background: color-mix(
|
|
16
|
+
in srgb,
|
|
17
|
+
var(--color-primary) 6%,
|
|
18
|
+
var(--color-base-100)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
8
21
|
|
|
9
22
|
.ss-card__image {
|
|
10
|
-
@apply h-
|
|
23
|
+
@apply absolute inset-0 h-full w-full object-cover;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.ss-card__badges {
|
|
27
|
+
position: relative;
|
|
28
|
+
z-index: 1;
|
|
29
|
+
align-self: end;
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-wrap: wrap;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: flex-end;
|
|
34
|
+
gap: 0.5rem;
|
|
35
|
+
margin: 1rem;
|
|
36
|
+
padding: 0;
|
|
37
|
+
list-style: none;
|
|
38
|
+
|
|
39
|
+
> li {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
min-width: 0;
|
|
43
|
+
max-width: 100%;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ss-badge {
|
|
47
|
+
margin: 0;
|
|
48
|
+
max-width: 100%;
|
|
49
|
+
/* Badge size utilities set a fixed height; allow text wrapping here. */
|
|
50
|
+
height: auto !important;
|
|
51
|
+
min-height: 1.5rem;
|
|
52
|
+
padding-block: 0.125rem;
|
|
53
|
+
line-height: 1.25;
|
|
54
|
+
white-space: normal;
|
|
55
|
+
overflow-wrap: anywhere;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.ss-card__badge-hint {
|
|
59
|
+
display: inline-flex;
|
|
60
|
+
min-width: 0;
|
|
61
|
+
max-width: 100%;
|
|
62
|
+
border-radius: var(--radius-selector);
|
|
63
|
+
cursor: help;
|
|
64
|
+
scroll-margin-block: 8rem 2rem;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.ss-card__badge-tooltip {
|
|
68
|
+
@apply shadow-md;
|
|
69
|
+
position: fixed;
|
|
70
|
+
inset: auto;
|
|
71
|
+
margin: 0;
|
|
72
|
+
width: max-content;
|
|
73
|
+
max-width: min(20rem, calc(100vw - 2rem));
|
|
74
|
+
max-height: calc(100dvh - 2rem);
|
|
75
|
+
overflow: auto;
|
|
76
|
+
padding: 0.625rem 0.875rem;
|
|
77
|
+
border: 1px solid var(--color-neutral);
|
|
78
|
+
border-radius: 0.5rem;
|
|
79
|
+
background: var(--color-neutral);
|
|
80
|
+
color: var(--color-neutral-content);
|
|
81
|
+
font-size: 0.875rem;
|
|
82
|
+
font-weight: 400;
|
|
83
|
+
line-height: 1.5;
|
|
84
|
+
text-align: start;
|
|
85
|
+
white-space: normal;
|
|
86
|
+
overflow-wrap: anywhere;
|
|
87
|
+
}
|
|
11
88
|
}
|
|
12
89
|
}
|
|
13
90
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
interface ActiveHint {
|
|
2
|
+
element: HTMLElement;
|
|
3
|
+
close: () => void;
|
|
4
|
+
position: () => void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
let activeHint: ActiveHint | undefined;
|
|
8
|
+
|
|
9
|
+
function initializeCardHints() {
|
|
10
|
+
if (activeHint && !activeHint.element.isConnected) activeHint.close();
|
|
11
|
+
for (const hint of document.querySelectorAll<HTMLElement>(
|
|
12
|
+
'.ss-card__badge-hint:not([data-enhanced])',
|
|
13
|
+
)) {
|
|
14
|
+
const tooltip = hint.querySelector<HTMLElement>('[role="tooltip"]');
|
|
15
|
+
if (!tooltip) continue;
|
|
16
|
+
let closeTimer: number | undefined;
|
|
17
|
+
const cancelClose = () => window.clearTimeout(closeTimer);
|
|
18
|
+
const close = () => {
|
|
19
|
+
cancelClose();
|
|
20
|
+
if (
|
|
21
|
+
typeof tooltip.hidePopover === 'function' &&
|
|
22
|
+
tooltip.matches(':popover-open')
|
|
23
|
+
)
|
|
24
|
+
tooltip.hidePopover();
|
|
25
|
+
tooltip.hidden = true;
|
|
26
|
+
if (activeHint?.element === hint) activeHint = undefined;
|
|
27
|
+
};
|
|
28
|
+
const position = () => {
|
|
29
|
+
const anchor = hint.getBoundingClientRect();
|
|
30
|
+
const width = document.documentElement.clientWidth;
|
|
31
|
+
const height = window.innerHeight;
|
|
32
|
+
if (anchor.bottom < 0 || anchor.top > height) {
|
|
33
|
+
close();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const box = tooltip.getBoundingClientRect();
|
|
37
|
+
const above = anchor.top - box.height - 8;
|
|
38
|
+
const top = above >= 16 ? above : anchor.bottom + 8;
|
|
39
|
+
tooltip.style.left = `${Math.max(16, Math.min(anchor.right - box.width, width - box.width - 16))}px`;
|
|
40
|
+
tooltip.style.top = `${Math.max(16, Math.min(top, height - box.height - 16))}px`;
|
|
41
|
+
};
|
|
42
|
+
const show = () => {
|
|
43
|
+
cancelClose();
|
|
44
|
+
if (activeHint?.element === hint) return;
|
|
45
|
+
activeHint?.close();
|
|
46
|
+
tooltip.hidden = false;
|
|
47
|
+
// The native top layer prevents clipping at the card's rounded edges.
|
|
48
|
+
if (typeof tooltip.showPopover === 'function')
|
|
49
|
+
tooltip.showPopover();
|
|
50
|
+
activeHint = { element: hint, close, position };
|
|
51
|
+
position();
|
|
52
|
+
};
|
|
53
|
+
const scheduleClose = () => {
|
|
54
|
+
cancelClose();
|
|
55
|
+
closeTimer = window.setTimeout(() => {
|
|
56
|
+
if (
|
|
57
|
+
!hint.matches(':hover') &&
|
|
58
|
+
!tooltip.matches(':hover') &&
|
|
59
|
+
document.activeElement !== hint
|
|
60
|
+
)
|
|
61
|
+
close();
|
|
62
|
+
}, 100);
|
|
63
|
+
};
|
|
64
|
+
hint.addEventListener('pointerenter', show);
|
|
65
|
+
hint.addEventListener('pointerleave', scheduleClose);
|
|
66
|
+
hint.addEventListener('focus', () => {
|
|
67
|
+
// Resolve focus scrolling before positioning, including smooth-scroll pages.
|
|
68
|
+
hint.scrollIntoView({
|
|
69
|
+
block: 'nearest',
|
|
70
|
+
inline: 'nearest',
|
|
71
|
+
behavior: 'instant',
|
|
72
|
+
});
|
|
73
|
+
show();
|
|
74
|
+
});
|
|
75
|
+
hint.addEventListener('blur', scheduleClose);
|
|
76
|
+
tooltip.addEventListener('pointerenter', cancelClose);
|
|
77
|
+
tooltip.addEventListener('pointerleave', scheduleClose);
|
|
78
|
+
hint.dataset.enhanced = 'true';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
document.addEventListener('keydown', (event) => {
|
|
83
|
+
if (event.key === 'Escape' && activeHint) {
|
|
84
|
+
activeHint.close();
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
window.addEventListener('resize', () => activeHint?.position());
|
|
89
|
+
window.addEventListener('scroll', () => activeHint?.position(), true);
|
|
90
|
+
document.addEventListener('astro:before-swap', () => activeHint?.close());
|
|
91
|
+
document.addEventListener('astro:page-load', initializeCardHints);
|
|
92
|
+
initializeCardHints();
|
|
93
|
+
// Match the existing component workshop lifecycle when Storybook replaces a story.
|
|
94
|
+
new MutationObserver(initializeCardHints).observe(document.body, {
|
|
95
|
+
childList: true,
|
|
96
|
+
subtree: true,
|
|
97
|
+
});
|