@sinnstack/ui 0.2.0 → 0.3.0
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/CHANGELOG.md +74 -0
- package/README.md +6 -4
- package/docs/blocks.md +373 -364
- package/docs/data.md +128 -128
- package/docs/finishes.md +165 -0
- package/docs/primitives.md +4 -4
- package/docs/seo.md +191 -187
- package/package.json +15 -24
- package/src/blocks/BlockRenderer.astro +13 -7
- package/src/blocks/CTABanner.astro +8 -8
- package/src/blocks/CTAPair.astro +9 -9
- package/src/blocks/CardGrid.astro +7 -7
- package/src/blocks/ConsentEmbed.astro +1 -1
- package/src/blocks/ConsentManager.astro +1 -1
- package/src/blocks/ContactCard.astro +14 -14
- package/src/blocks/ContactForm.astro +4 -4
- package/src/blocks/ErrorPage.astro +1 -1
- package/src/blocks/FAQ.astro +9 -9
- package/src/blocks/FeatureGrid.astro +7 -7
- package/src/blocks/Hero.astro +11 -11
- package/src/blocks/HeroCarousel.astro +11 -11
- package/src/blocks/HighlightCards.astro +10 -10
- package/src/blocks/LocationHours.astro +14 -14
- package/src/blocks/LogoCloud.astro +7 -7
- package/src/blocks/MaintenancePage.astro +8 -3
- package/src/blocks/MediaText.astro +12 -12
- package/src/blocks/PageHeader.astro +9 -9
- package/src/blocks/ProseSection.astro +8 -8
- package/src/blocks/Reviews.astro +11 -11
- package/src/blocks/RichText.astro +58 -57
- package/src/blocks/StatsBand.astro +117 -117
- package/src/blocks/Steps.astro +9 -9
- package/src/blocks/Testimonials.astro +13 -13
- package/src/blocks/cms/card-grid.ts +48 -80
- package/src/blocks/cms/consent.ts +1 -30
- package/src/blocks/cms/contact-card.ts +4 -46
- package/src/blocks/cms/contact-form.ts +2 -20
- package/src/blocks/cms/cta-banner.ts +2 -23
- package/src/blocks/cms/cta-pair.ts +4 -37
- package/src/blocks/cms/data-base.ts +2 -4
- package/src/blocks/cms/data.ts +19 -19
- package/src/blocks/cms/faq.ts +4 -36
- package/src/blocks/cms/feature-grid.ts +47 -80
- package/src/blocks/cms/fixtures.ts +591 -599
- package/src/blocks/cms/hero-carousel.ts +4 -48
- package/src/blocks/cms/hero.ts +2 -46
- package/src/blocks/cms/highlight-cards.ts +4 -39
- package/src/blocks/cms/images.ts +1 -2
- package/src/blocks/cms/index.ts +59 -87
- package/src/blocks/cms/location-hours.ts +3 -85
- package/src/blocks/cms/logo-cloud.ts +36 -62
- package/src/blocks/cms/media-text.ts +2 -20
- package/src/blocks/cms/page-header.ts +27 -49
- package/src/blocks/cms/pages.ts +35 -81
- package/src/blocks/cms/prose-section.ts +2 -22
- package/src/blocks/cms/reviews.ts +5 -56
- package/src/blocks/cms/schema-dsl.ts +134 -0
- package/src/blocks/cms/schema.ts +794 -0
- package/src/blocks/cms/shared.ts +63 -115
- package/src/blocks/cms/stats-band.ts +35 -61
- package/src/blocks/cms/steps.ts +4 -31
- package/src/blocks/cms/testimonials.ts +4 -38
- package/src/blocks/cms/topbar.ts +4 -41
- package/src/blocks/cms/types.ts +1 -37
- package/src/blocks/consent.ts +2 -2
- package/src/blocks/index.ts +2 -2
- package/src/blocks/internal/Actions.astro +11 -5
- package/src/blocks/internal/BlockHeader.astro +7 -7
- package/src/blocks/internal/Placeholder.astro +3 -3
- package/src/blocks/internal/fields.ts +18 -0
- package/src/blocks/internal/registry-contract.ts +67 -0
- package/src/blocks/internal/util.ts +4 -4
- package/src/blocks/lib/contact.ts +10 -4
- package/src/blocks/lib/faq.ts +1 -1
- package/src/blocks/lib/markdown.ts +350 -0
- package/src/blocks/lib/rich-text.ts +132 -143
- package/src/blocks/scripts/consent-manager.ts +1 -1
- package/src/blocks/scripts/consent-store.ts +1 -1
- package/src/blocks/scripts/hours.ts +3 -2
- package/src/blocks/types.ts +33 -23
- package/src/data/ChartContainer.astro +2 -1
- package/src/data/cms.ts +130 -190
- package/src/data/lib/chart.ts +13 -4
- package/src/data/schema.ts +65 -0
- package/src/finishes/aurora.css +75 -0
- package/src/finishes/autumn.css +87 -0
- package/src/finishes/blueprint.css +69 -0
- package/src/finishes/brutalist.css +55 -0
- package/src/finishes/clay.css +48 -0
- package/src/finishes/day-cycle.css +46 -0
- package/src/finishes/fog.css +71 -0
- package/src/finishes/glass.css +149 -0
- package/src/finishes/holographic.css +91 -0
- package/src/finishes/night.css +77 -0
- package/src/finishes/paper.css +58 -0
- package/src/finishes/polished-glass.css +159 -0
- package/src/finishes/rain.css +84 -0
- package/src/finishes/scripts/day-cycle.ts +30 -0
- package/src/finishes/scripts/holographic.ts +37 -0
- package/src/finishes/scripts/spotlight.ts +30 -0
- package/src/finishes/spotlight.css +41 -0
- package/src/finishes/spring.css +80 -0
- package/src/finishes/terminal.css +49 -0
- package/src/primitives/Divider.astro +1 -1
- package/src/primitives/FocusRing.astro +1 -1
- package/src/primitives/FormField.astro +2 -2
- package/src/primitives/Image.astro +3 -3
- package/src/primitives/Input.astro +4 -2
- package/src/primitives/MetricCard.astro +3 -1
- package/src/primitives/Picture.astro +3 -3
- package/src/primitives/Prose.astro +1 -1
- package/src/primitives/Select.astro +4 -2
- package/src/primitives/Slider.astro +1 -1
- package/src/primitives/Table.astro +1 -1
- package/src/primitives/Textarea.astro +4 -2
- package/src/primitives/Thumbnail.astro +2 -2
- package/src/primitives/index.ts +4 -4
- package/src/primitives/internal/ChoiceField.astro +4 -2
- package/src/primitives/scripts/slider.ts +1 -1
- package/src/primitives/scripts/table-sort.ts +2 -2
- package/src/seo/cms.ts +59 -80
- package/src/seo/index.ts +1 -1
- package/src/seo/integration.ts +40 -3
- package/src/seo/lib/jsonld.ts +10 -2
- package/src/seo/lib/meta.ts +2 -2
- package/src/seo/lib/redirects.ts +14 -4
- package/src/seo/lib/rss.ts +1 -1
- package/src/seo/lib/sitemap.ts +1 -1
- package/src/seo/schema.ts +43 -0
- package/src/blocks/internal/tina.ts +0 -19
- /package/src/blocks/{lib → internal}/consent.ts +0 -0
- /package/src/blocks/{lib → internal}/reviews.ts +0 -0
- /package/src/blocks/{lib → internal}/slug.ts +0 -0
- /package/src/data/{lib → internal}/scale.ts +0 -0
- /package/src/primitives/{lib → internal}/image-plan.ts +0 -0
- /package/src/primitives/{lib → internal}/image.ts +0 -0
- /package/src/primitives/{lib → internal}/slider.ts +0 -0
- /package/src/seo/{lib → internal}/url.ts +0 -0
package/src/data/cms.ts
CHANGED
|
@@ -1,190 +1,130 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* "by the numbers" section
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import type {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
format
|
|
83
|
-
labels
|
|
84
|
-
series
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const slug = (s: string) => s.toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '') || 'chart';
|
|
133
|
-
|
|
134
|
-
/** CMS chart → a chart model and ChartContainer props. Problems come back as plain sentences. */
|
|
135
|
-
export function chartFromCms(data: CmsChart | null | undefined): {
|
|
136
|
-
chart: ChartModel;
|
|
137
|
-
frame: { title: string; description?: string; source?: { label: string; href?: string }; height?: 's' | 'm' | 'l'; table: true | 'open' };
|
|
138
|
-
errors: string[];
|
|
139
|
-
} {
|
|
140
|
-
const errors: string[] = [];
|
|
141
|
-
const title = data?.title?.trim() || 'Chart';
|
|
142
|
-
const format = toFormat(data?.format);
|
|
143
|
-
const x = lines(data?.labels).map((l) => l.trim());
|
|
144
|
-
const series = (data?.series ?? []).filter(Boolean).map((s, i) => {
|
|
145
|
-
const label = s!.label?.trim() || `Series ${i + 1}`;
|
|
146
|
-
const values = parseValues(s!.values, format, label, errors);
|
|
147
|
-
if (values.length !== x.length) errors.push(`${label} has ${values.length} values for ${x.length} labels.`);
|
|
148
|
-
return { label, values: x.map((_, k) => values[k] ?? null) };
|
|
149
|
-
});
|
|
150
|
-
if (!series.length) errors.push('Add at least one series.');
|
|
151
|
-
const input: ChartInput = {
|
|
152
|
-
id: slug(title),
|
|
153
|
-
type: data?.type ?? 'line',
|
|
154
|
-
stacked: Boolean(data?.stacked),
|
|
155
|
-
x,
|
|
156
|
-
yFormat: format,
|
|
157
|
-
yTitle: data?.yTitle?.trim() || undefined,
|
|
158
|
-
// "Site visits" → "site visits" for the summary sentence; leave acronyms ("SEO visits") alone.
|
|
159
|
-
subject: /^[A-Z][a-z]/.test(title) ? title.charAt(0).toLowerCase() + title.slice(1) : title,
|
|
160
|
-
series: series.length ? series : [{ label: title, values: x.map(() => null) }],
|
|
161
|
-
};
|
|
162
|
-
const chart = defineChart(input);
|
|
163
|
-
return {
|
|
164
|
-
chart,
|
|
165
|
-
frame: {
|
|
166
|
-
title,
|
|
167
|
-
description: data?.description?.trim() || undefined,
|
|
168
|
-
source: data?.sourceLabel?.trim() ? { label: data.sourceLabel.trim(), href: data.sourceHref?.trim() || undefined } : undefined,
|
|
169
|
-
height: data?.height ?? undefined,
|
|
170
|
-
table: data?.tableOpen ? 'open' : true,
|
|
171
|
-
},
|
|
172
|
-
errors: [...errors, ...chart.warnings],
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** CMS sparkline → Sparkline props. */
|
|
177
|
-
export function sparklineFromCms(data: CmsSparkline | null | undefined): SparklineInput & { errors: string[] } {
|
|
178
|
-
const errors: string[] = [];
|
|
179
|
-
const format = toFormat(data?.format);
|
|
180
|
-
const labels = data?.labels ? lines(data.labels).map((l) => l.trim()) : undefined;
|
|
181
|
-
return {
|
|
182
|
-
label: data?.label?.trim() || 'Trend',
|
|
183
|
-
values: parseValues(data?.values, format, data?.label || 'Sparkline', errors),
|
|
184
|
-
labels,
|
|
185
|
-
format,
|
|
186
|
-
type: data?.type ?? 'line',
|
|
187
|
-
reference: data?.reference ?? undefined,
|
|
188
|
-
errors,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Editor-managed charts: maps a stored `chart` object (small, hand-entered data such as a page's
|
|
3
|
+
* "by the numbers" section or a report summary) and a `sparkline` object to component input.
|
|
4
|
+
* Charts fed from an API or a database should call defineChart() in code instead.
|
|
5
|
+
*
|
|
6
|
+
* const { chart, frame, errors } = chartFromCms(block.chart);
|
|
7
|
+
* <ChartContainer chart={chart} {...frame}> … </ChartContainer>
|
|
8
|
+
*
|
|
9
|
+
* Editors type one value per line, lined up with the labels; an empty line is a missing value.
|
|
10
|
+
* "1,240", "$9,000" and "91%" are all understood.
|
|
11
|
+
*/
|
|
12
|
+
import type { ValueFormat } from '../primitives/types';
|
|
13
|
+
import { defineChart, type ChartInput, type ChartModel } from './lib/chart';
|
|
14
|
+
import type { SparklineInput } from './lib/sparkline';
|
|
15
|
+
import { safeHref } from '../blocks/lib/contact';
|
|
16
|
+
|
|
17
|
+
export interface CmsChart {
|
|
18
|
+
title?: string | null;
|
|
19
|
+
description?: string | null;
|
|
20
|
+
type?: 'line' | 'area' | 'bar' | null;
|
|
21
|
+
stacked?: boolean | null;
|
|
22
|
+
format?: string | null;
|
|
23
|
+
labels?: string | null;
|
|
24
|
+
series?: Array<{ label?: string | null; values?: string | null } | null> | null;
|
|
25
|
+
yTitle?: string | null;
|
|
26
|
+
sourceLabel?: string | null;
|
|
27
|
+
sourceHref?: string | null;
|
|
28
|
+
height?: 's' | 'm' | 'l' | null;
|
|
29
|
+
tableOpen?: boolean | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CmsSparkline {
|
|
33
|
+
label?: string | null;
|
|
34
|
+
values?: string | null;
|
|
35
|
+
labels?: string | null;
|
|
36
|
+
format?: string | null;
|
|
37
|
+
type?: 'line' | 'area' | 'bar' | null;
|
|
38
|
+
reference?: number | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const lines = (s?: string | null) => (s ?? '').replace(/\r\n?/g, '\n').replace(/\n+$/, '').split('\n');
|
|
42
|
+
|
|
43
|
+
function toFormat(f?: string | null): ValueFormat {
|
|
44
|
+
if (f === 'currency-compact') return { kind: 'currency', compact: 'auto' };
|
|
45
|
+
if (f === 'integer' || f === 'number' || f === 'percent' || f === 'currency') return f;
|
|
46
|
+
return 'number';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** "1,240" → 1240, "$9,000" → 9000, "91%" → 0.91, "" → null; anything else is an error. */
|
|
50
|
+
export function parseCmsNumber(raw: string): number | null | undefined {
|
|
51
|
+
const t = raw.trim().replace(/[\s,$€£]/g, '').replace(/[−–]/g, '-');
|
|
52
|
+
if (!t) return null;
|
|
53
|
+
const pct = t.endsWith('%');
|
|
54
|
+
const n = Number(pct ? t.slice(0, -1) : t);
|
|
55
|
+
if (!Number.isFinite(n)) return undefined;
|
|
56
|
+
return pct ? n / 100 : n;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseValues(raw: string | null | undefined, format: ValueFormat, name: string, errors: string[]): Array<number | null> {
|
|
60
|
+
const isPercent = (typeof format === 'string' ? format : format.kind) === 'percent';
|
|
61
|
+
return lines(raw).map((line, i) => {
|
|
62
|
+
const v = parseCmsNumber(line);
|
|
63
|
+
if (v === undefined) {
|
|
64
|
+
errors.push(`${name}, line ${i + 1}: "${line.trim()}" isn't a number.`);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
// In a percent chart "91" means 91%, as editors type it.
|
|
68
|
+
return v !== null && isPercent && !line.includes('%') && Math.abs(v) > 1 ? v / 100 : v;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const slug = (s: string) => s.toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '') || 'chart';
|
|
73
|
+
|
|
74
|
+
/** CMS chart → a chart model and ChartContainer props. Problems come back as plain sentences. */
|
|
75
|
+
export function chartFromCms(data: CmsChart | null | undefined): {
|
|
76
|
+
chart: ChartModel;
|
|
77
|
+
frame: { title: string; description?: string; source?: { label: string; href?: string }; height?: 's' | 'm' | 'l'; table: true | 'open' };
|
|
78
|
+
errors: string[];
|
|
79
|
+
} {
|
|
80
|
+
const errors: string[] = [];
|
|
81
|
+
const title = data?.title?.trim() || 'Chart';
|
|
82
|
+
const format = toFormat(data?.format);
|
|
83
|
+
const x = lines(data?.labels).map((l) => l.trim());
|
|
84
|
+
const series = (data?.series ?? []).filter(Boolean).map((s, i) => {
|
|
85
|
+
const label = s!.label?.trim() || `Series ${i + 1}`;
|
|
86
|
+
const values = parseValues(s!.values, format, label, errors);
|
|
87
|
+
if (values.length !== x.length) errors.push(`${label} has ${values.length} values for ${x.length} labels.`);
|
|
88
|
+
return { label, values: x.map((_, k) => values[k] ?? null) };
|
|
89
|
+
});
|
|
90
|
+
if (!series.length) errors.push('Add at least one series.');
|
|
91
|
+
const input: ChartInput = {
|
|
92
|
+
id: slug(title),
|
|
93
|
+
type: data?.type ?? 'line',
|
|
94
|
+
stacked: Boolean(data?.stacked),
|
|
95
|
+
x,
|
|
96
|
+
yFormat: format,
|
|
97
|
+
yTitle: data?.yTitle?.trim() || undefined,
|
|
98
|
+
// "Site visits" → "site visits" for the summary sentence; leave acronyms ("SEO visits") alone.
|
|
99
|
+
subject: /^[A-Z][a-z]/.test(title) ? title.charAt(0).toLowerCase() + title.slice(1) : title,
|
|
100
|
+
series: series.length ? series : [{ label: title, values: x.map(() => null) }],
|
|
101
|
+
};
|
|
102
|
+
const chart = defineChart(input);
|
|
103
|
+
return {
|
|
104
|
+
chart,
|
|
105
|
+
frame: {
|
|
106
|
+
title,
|
|
107
|
+
description: data?.description?.trim() || undefined,
|
|
108
|
+
source: data?.sourceLabel?.trim() ? { label: data.sourceLabel.trim(), href: safeHref(data.sourceHref) } : undefined,
|
|
109
|
+
height: data?.height ?? undefined,
|
|
110
|
+
table: data?.tableOpen ? 'open' : true,
|
|
111
|
+
},
|
|
112
|
+
errors: [...errors, ...chart.warnings],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** CMS sparkline → Sparkline props. */
|
|
117
|
+
export function sparklineFromCms(data: CmsSparkline | null | undefined): SparklineInput & { errors: string[] } {
|
|
118
|
+
const errors: string[] = [];
|
|
119
|
+
const format = toFormat(data?.format);
|
|
120
|
+
const labels = data?.labels ? lines(data.labels).map((l) => l.trim()) : undefined;
|
|
121
|
+
return {
|
|
122
|
+
label: data?.label?.trim() || 'Trend',
|
|
123
|
+
values: parseValues(data?.values, format, data?.label || 'Sparkline', errors),
|
|
124
|
+
labels,
|
|
125
|
+
format,
|
|
126
|
+
type: data?.type ?? 'line',
|
|
127
|
+
reference: data?.reference ?? undefined,
|
|
128
|
+
errors,
|
|
129
|
+
};
|
|
130
|
+
}
|
package/src/data/lib/chart.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { formatValue } from '../../primitives/utils';
|
|
17
17
|
import type { ValueFormat } from '../../primitives/types';
|
|
18
|
-
import { dataGranularity, niceDomain, timeFullLabel, timeTickLabel, timeTicks, xPct as xp, yPct as yp } from '
|
|
18
|
+
import { dataGranularity, niceDomain, timeFullLabel, timeTickLabel, timeTicks, xPct as xp, yPct as yp } from '../internal/scale';
|
|
19
19
|
|
|
20
20
|
export type ChartType = 'line' | 'area' | 'bar';
|
|
21
21
|
export type SeriesSlot = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
@@ -37,7 +37,10 @@ export interface SeriesInput {
|
|
|
37
37
|
|
|
38
38
|
export interface ChartInput {
|
|
39
39
|
type: ChartType;
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Categories ("Q1", "Fort Worth", 2024) or dates (Date or ISO string). Numbers are categories
|
|
42
|
+
* (years plot as "2024", not as milliseconds); they're read as timestamps only with `xType: 'time'`.
|
|
43
|
+
*/
|
|
41
44
|
x: Array<string | number | Date>;
|
|
42
45
|
/** `time` positions points by date; `category` spaces them evenly. Auto: time for dates on line/area. */
|
|
43
46
|
xType?: 'category' | 'time';
|
|
@@ -191,7 +194,8 @@ export function defineChart(input: ChartInput): ChartModel {
|
|
|
191
194
|
|
|
192
195
|
// ---------- x ----------
|
|
193
196
|
const times = input.x.map(toTime);
|
|
194
|
-
|
|
197
|
+
// Auto-detection skips numbers: x: [2019, 2020] are years (categories), not ms since 1970.
|
|
198
|
+
const canTime = type !== 'bar' && times.every((t) => t !== undefined) && (input.xType === 'time' || !input.x.some((v) => typeof v === 'number'));
|
|
195
199
|
const xType = input.xType === 'category' ? 'category' : input.xType === 'time' || canTime ? (canTime ? 'time' : 'category') : 'category';
|
|
196
200
|
if (input.xType === 'time' && !canTime) warnings.push('xType "time" needs dates for every x value (or bars, which are always categories); using categories.');
|
|
197
201
|
const granularity = xType === 'time' ? dataGranularity(times as number[]) : undefined;
|
|
@@ -418,7 +422,12 @@ export function defineChart(input: ChartInput): ChartModel {
|
|
|
418
422
|
const xHeader = input.xTitle ?? (xType === 'time' ? 'Date' : 'Category');
|
|
419
423
|
const headers = [xHeader, ...series.map((s) => s.label)];
|
|
420
424
|
const rows = Array.from({ length: n }, (_, k) => [xLabelFull(k), ...series.map((s) => fmtY(s.values[k]))]);
|
|
421
|
-
|
|
425
|
+
// Text cells that start like a formula (=, +, -, @) get a leading ' so spreadsheets show them as
|
|
426
|
+
// text instead of running them (CSV injection). Series values are numbers, written as they are.
|
|
427
|
+
const csvCell = (raw: string) => {
|
|
428
|
+
const v = /^[=+\-@\t\r]/.test(raw) ? `'${raw}` : raw;
|
|
429
|
+
return /[",\r\n]/.test(v) ? `"${v.replace(/"/g, '""')}"` : v;
|
|
430
|
+
};
|
|
422
431
|
const rawX = (k: number) => (xType === 'time' ? new Date(times[k]!).toISOString().slice(0, granularity === 'day' ? 10 : granularity === 'month' ? 7 : 4) : String(input.x[k]));
|
|
423
432
|
const csv = [headers.map(csvCell).join(','), ...Array.from({ length: n }, (_, k) => [csvCell(rawX(k)), ...series.map((s) => (s.values[k] === null ? '' : String(s.values[k])))].join(','))].join('\n');
|
|
424
433
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ready-made SinnStackCMS fields for editor-managed charts, checked against the stored shapes in
|
|
3
|
+
* `./cms`:
|
|
4
|
+
*
|
|
5
|
+
* import { chartSchema, sparklineSchema } from '@sinnstack/ui/data/schema';
|
|
6
|
+
* fields: { chart: chartSchema } → chartFromCms(entry.chart)
|
|
7
|
+
*/
|
|
8
|
+
import { objectSchema, type ObjectField, type SelectOption } from '../blocks/cms/schema-dsl';
|
|
9
|
+
import type { CmsChart, CmsSparkline } from './cms';
|
|
10
|
+
|
|
11
|
+
const format = {
|
|
12
|
+
type: 'select' as const,
|
|
13
|
+
label: 'Number format',
|
|
14
|
+
options: [
|
|
15
|
+
{ value: 'number', label: 'Number (1,240.5)' },
|
|
16
|
+
{ value: 'integer', label: 'Whole number (1,240)' },
|
|
17
|
+
{ value: 'percent', label: 'Percent (91%)' },
|
|
18
|
+
{ value: 'currency', label: 'Money ($9,000)' },
|
|
19
|
+
{ value: 'currency-compact', label: 'Money, short ($9K)' },
|
|
20
|
+
] as SelectOption[],
|
|
21
|
+
};
|
|
22
|
+
const chartType = (label: string) => ({
|
|
23
|
+
type: 'select' as const,
|
|
24
|
+
label,
|
|
25
|
+
options: [{ value: 'line', label: 'Line' }, { value: 'area', label: 'Area' }, { value: 'bar', label: 'Bar' }] as Array<{ value: 'line' | 'area' | 'bar'; label: string }>,
|
|
26
|
+
});
|
|
27
|
+
const oneValuePerLine = 'One value per line, lined up with the labels. Leave a line empty for a missing value.';
|
|
28
|
+
|
|
29
|
+
/** A `chart` object for chartFromCms. */
|
|
30
|
+
export const chartSchema: ObjectField = objectSchema<CmsChart>({
|
|
31
|
+
label: 'Chart',
|
|
32
|
+
fields: {
|
|
33
|
+
title: { type: 'text', label: 'Title', required: true },
|
|
34
|
+
description: { type: 'textarea', label: 'Description', rows: 2, help: 'What the chart shows, in a sentence. Read out by screen readers.' },
|
|
35
|
+
type: chartType('Chart type'),
|
|
36
|
+
stacked: { type: 'boolean', label: 'Stack the series' },
|
|
37
|
+
format,
|
|
38
|
+
labels: { type: 'textarea', label: 'Labels', rows: 6, help: 'One per line, e.g. months.' },
|
|
39
|
+
series: {
|
|
40
|
+
type: 'list',
|
|
41
|
+
label: 'Series',
|
|
42
|
+
itemLabel: 'label',
|
|
43
|
+
min: 1,
|
|
44
|
+
of: { type: 'object', fields: { label: { type: 'text', label: 'Name', required: true }, values: { type: 'textarea', label: 'Values', rows: 6, help: oneValuePerLine } } },
|
|
45
|
+
},
|
|
46
|
+
yTitle: { type: 'text', label: 'Axis title' },
|
|
47
|
+
sourceLabel: { type: 'text', label: 'Source' },
|
|
48
|
+
sourceHref: { type: 'link', label: 'Source link' },
|
|
49
|
+
height: { type: 'select', label: 'Height', options: [{ value: 's', label: 'Small' }, { value: 'm', label: 'Medium' }, { value: 'l', label: 'Large' }] },
|
|
50
|
+
tableOpen: { type: 'boolean', label: 'Show the data table open' },
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** A `sparkline` object for sparklineFromCms. */
|
|
55
|
+
export const sparklineSchema: ObjectField = objectSchema<CmsSparkline>({
|
|
56
|
+
label: 'Sparkline',
|
|
57
|
+
fields: {
|
|
58
|
+
label: { type: 'text', label: 'Label', required: true },
|
|
59
|
+
values: { type: 'textarea', label: 'Values', rows: 6, help: oneValuePerLine },
|
|
60
|
+
labels: { type: 'textarea', label: 'Labels', rows: 6, help: 'One per line.' },
|
|
61
|
+
format,
|
|
62
|
+
type: chartType('Type'),
|
|
63
|
+
reference: { type: 'number', label: 'Reference line', help: 'Draws a line at this value, e.g. a target.' },
|
|
64
|
+
},
|
|
65
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
@layer sinn.reset, sinn.tokens, sinn.primitives, sinn.data, sinn.motion, sinn.blocks, sinn.overrides;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Aurora finish: large soft blobs of the palette's accent-soft fill drifting slowly behind the page.
|
|
5
|
+
*
|
|
6
|
+
* import '@sinnstack/ui/finishes/aurora.css';
|
|
7
|
+
* <html data-finish="aurora"> (pairs well with glass: data-finish="glass aurora")
|
|
8
|
+
*
|
|
9
|
+
* Colour: only accent-soft, a fill every palette guarantees text, muted text and links on (≥ 4.5:1).
|
|
10
|
+
* Overlapping blobs only blend the page surface toward that fill, so text on the page keeps its contrast.
|
|
11
|
+
* Motion: two layers drifting on 48s and 62s loops (transform only, no repaint). Still under reduced motion.
|
|
12
|
+
* Scene finishes (aurora, autumn, rain, fog) each use the root's ::before and ::after, so use one at a time.
|
|
13
|
+
*
|
|
14
|
+
* Tune: --sinn-finish-aurora-color (a colour; keep it a soft fill text was checked on),
|
|
15
|
+
* --sinn-finish-aurora-strength (0–100%, default 100%), --sinn-finish-aurora-duration (default 48s).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
@layer sinn.tokens {
|
|
19
|
+
:root {
|
|
20
|
+
--sinn-finish-aurora-color: var(--sinn-color-accent-soft);
|
|
21
|
+
--sinn-finish-aurora-strength: 100%;
|
|
22
|
+
--sinn-finish-aurora-duration: 48s;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@layer sinn.blocks {
|
|
27
|
+
/* The page colour moves from body to the root so the scene layers (fixed, behind the body) show.
|
|
28
|
+
Zero specificity: glass and polished-glass set their own root background and win when combined. */
|
|
29
|
+
:where(:root[data-finish~='aurora']) { background-color: var(--sinn-color-surface); }
|
|
30
|
+
[data-finish~='aurora'] :where(body) { background-color: transparent; }
|
|
31
|
+
:root[data-finish~='aurora']::before,
|
|
32
|
+
:root[data-finish~='aurora']::after {
|
|
33
|
+
content: '';
|
|
34
|
+
position: fixed;
|
|
35
|
+
z-index: -1;
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
will-change: transform;
|
|
38
|
+
}
|
|
39
|
+
:root[data-finish~='aurora']::before,
|
|
40
|
+
:root[data-finish~='aurora']::after { inset: -25%; }
|
|
41
|
+
:root[data-finish~='aurora']::before {
|
|
42
|
+
background-image:
|
|
43
|
+
radial-gradient(32% 26% at 28% 30%, color-mix(in oklch, var(--sinn-finish-aurora-color) var(--sinn-finish-aurora-strength), transparent), transparent 72%),
|
|
44
|
+
radial-gradient(26% 30% at 72% 62%, color-mix(in oklch, var(--sinn-finish-aurora-color) calc(var(--sinn-finish-aurora-strength) * 0.85), transparent), transparent 72%);
|
|
45
|
+
animation: sinn-finish-aurora-a var(--sinn-finish-aurora-duration) ease-in-out infinite alternate;
|
|
46
|
+
}
|
|
47
|
+
:root[data-finish~='aurora']::after {
|
|
48
|
+
background-image:
|
|
49
|
+
radial-gradient(36% 22% at 62% 24%, color-mix(in oklch, var(--sinn-finish-aurora-color) calc(var(--sinn-finish-aurora-strength) * 0.7), transparent), transparent 72%),
|
|
50
|
+
radial-gradient(28% 24% at 34% 76%, color-mix(in oklch, var(--sinn-finish-aurora-color) calc(var(--sinn-finish-aurora-strength) * 0.8), transparent), transparent 72%);
|
|
51
|
+
animation: sinn-finish-aurora-b calc(var(--sinn-finish-aurora-duration) * 1.3) ease-in-out infinite alternate;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Still when the reader prefers reduced motion (unless the site's motion switch says full), or when the
|
|
55
|
+
site's switch says reduce: the same rule the motion group follows. */
|
|
56
|
+
@media (prefers-reduced-motion: reduce) {
|
|
57
|
+
:root[data-finish~='aurora']:not([data-motion='full'])::before,
|
|
58
|
+
:root[data-finish~='aurora']:not([data-motion='full'])::after { animation: none; }
|
|
59
|
+
}
|
|
60
|
+
:root[data-finish~='aurora'][data-motion='reduce']::before,
|
|
61
|
+
:root[data-finish~='aurora'][data-motion='reduce']::after { animation: none; }
|
|
62
|
+
@media print {
|
|
63
|
+
:root[data-finish~='aurora']::before,
|
|
64
|
+
:root[data-finish~='aurora']::after { display: none; }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@keyframes sinn-finish-aurora-a {
|
|
69
|
+
from { transform: translate3d(-6%, -4%, 0) rotate(0deg) scale(1); }
|
|
70
|
+
to { transform: translate3d(7%, 5%, 0) rotate(10deg) scale(1.12); }
|
|
71
|
+
}
|
|
72
|
+
@keyframes sinn-finish-aurora-b {
|
|
73
|
+
from { transform: translate3d(5%, 4%, 0) rotate(0deg) scale(1.1); }
|
|
74
|
+
to { transform: translate3d(-7%, -5%, 0) rotate(-12deg) scale(0.95); }
|
|
75
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
@layer sinn.reset, sinn.tokens, sinn.primitives, sinn.data, sinn.motion, sinn.blocks, sinn.overrides;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Autumn finish: leaves drifting down behind the page, under a warm glow from the top corner.
|
|
5
|
+
*
|
|
6
|
+
* import '@sinnstack/ui/finishes/autumn.css';
|
|
7
|
+
* <html data-finish="autumn">
|
|
8
|
+
*
|
|
9
|
+
* Colour: the leaves and glow are their own physical colours (they're decoration, not the palette), at low
|
|
10
|
+
* opacity, behind the page; palette tokens are untouched. Leaves and glow are --sinn-finish-autumn-* tokens,
|
|
11
|
+
* so a site can retint them. Text sitting directly on the page can cross a leaf: check client sites in a
|
|
12
|
+
* browser if they put small muted text on the page background.
|
|
13
|
+
* Motion: one tiled layer falling with a gentle sway (transform only). Leaves stay still under reduced motion.
|
|
14
|
+
* Scene finishes (aurora, autumn, rain, fog) each use the root's ::before and ::after, so use one at a time.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
@layer sinn.tokens {
|
|
18
|
+
:root {
|
|
19
|
+
--sinn-finish-autumn-leaf-1: light-dark(rgb(200 98 30 / 0.5), rgb(226 128 54 / 0.42));
|
|
20
|
+
--sinn-finish-autumn-leaf-2: light-dark(rgb(170 52 36 / 0.45), rgb(214 86 60 / 0.38));
|
|
21
|
+
--sinn-finish-autumn-leaf-3: light-dark(rgb(186 140 34 / 0.5), rgb(224 178 70 / 0.38));
|
|
22
|
+
--sinn-finish-autumn-glow: light-dark(rgb(255 150 60 / 0.16), rgb(255 140 60 / 0.12));
|
|
23
|
+
--sinn-finish-autumn-tile: 420px;
|
|
24
|
+
--sinn-finish-autumn-duration: 24s;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@layer sinn.blocks {
|
|
29
|
+
/* The page colour moves from body to the root so the scene layers (fixed, behind the body) show.
|
|
30
|
+
Zero specificity: glass and polished-glass set their own root background and win when combined. */
|
|
31
|
+
:where(:root[data-finish~='autumn']) { background-color: var(--sinn-color-surface); }
|
|
32
|
+
[data-finish~='autumn'] :where(body) { background-color: transparent; }
|
|
33
|
+
:root[data-finish~='autumn']::before,
|
|
34
|
+
:root[data-finish~='autumn']::after {
|
|
35
|
+
content: '';
|
|
36
|
+
position: fixed;
|
|
37
|
+
z-index: -1;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
will-change: transform;
|
|
40
|
+
}
|
|
41
|
+
/* Warm light from the top end corner. Static. */
|
|
42
|
+
:root[data-finish~='autumn']::before {
|
|
43
|
+
inset: 0;
|
|
44
|
+
background-image: radial-gradient(70rem 50rem at 100% 0%, var(--sinn-finish-autumn-glow), transparent 70%);
|
|
45
|
+
will-change: auto;
|
|
46
|
+
}
|
|
47
|
+
/* Leaves: one tile, repeated; the layer starts one tile above the viewport and falls one tile per loop. */
|
|
48
|
+
:root[data-finish~='autumn']::after {
|
|
49
|
+
inset: calc(-1 * var(--sinn-finish-autumn-tile)) -4rem 0;
|
|
50
|
+
background-image:
|
|
51
|
+
radial-gradient(6px 3.5px at 8% 12%, var(--sinn-finish-autumn-leaf-1) 92%, transparent),
|
|
52
|
+
radial-gradient(3.5px 6px at 27% 44%, var(--sinn-finish-autumn-leaf-2) 92%, transparent),
|
|
53
|
+
radial-gradient(6px 3.5px at 46% 8%, var(--sinn-finish-autumn-leaf-3) 92%, transparent),
|
|
54
|
+
radial-gradient(3.5px 6px at 63% 57%, var(--sinn-finish-autumn-leaf-1) 92%, transparent),
|
|
55
|
+
radial-gradient(6px 3.5px at 82% 23%, var(--sinn-finish-autumn-leaf-2) 92%, transparent),
|
|
56
|
+
radial-gradient(3.5px 6px at 15% 72%, var(--sinn-finish-autumn-leaf-3) 92%, transparent),
|
|
57
|
+
radial-gradient(6px 3.5px at 38% 88%, var(--sinn-finish-autumn-leaf-1) 92%, transparent),
|
|
58
|
+
radial-gradient(3.5px 6px at 57% 33%, var(--sinn-finish-autumn-leaf-2) 92%, transparent),
|
|
59
|
+
radial-gradient(6px 3.5px at 74% 80%, var(--sinn-finish-autumn-leaf-3) 92%, transparent),
|
|
60
|
+
radial-gradient(3.5px 6px at 93% 64%, var(--sinn-finish-autumn-leaf-1) 92%, transparent),
|
|
61
|
+
radial-gradient(6px 3.5px at 4% 40%, var(--sinn-finish-autumn-leaf-2) 92%, transparent),
|
|
62
|
+
radial-gradient(3.5px 6px at 51% 66%, var(--sinn-finish-autumn-leaf-3) 92%, transparent);
|
|
63
|
+
background-size: var(--sinn-finish-autumn-tile) var(--sinn-finish-autumn-tile);
|
|
64
|
+
animation: sinn-finish-autumn-fall var(--sinn-finish-autumn-duration) linear infinite;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Still when the reader prefers reduced motion (unless the site's motion switch says full), or when the
|
|
68
|
+
site's switch says reduce: the same rule the motion group follows. */
|
|
69
|
+
@media (prefers-reduced-motion: reduce) {
|
|
70
|
+
:root[data-finish~='autumn']:not([data-motion='full'])::before,
|
|
71
|
+
:root[data-finish~='autumn']:not([data-motion='full'])::after { animation: none; }
|
|
72
|
+
}
|
|
73
|
+
:root[data-finish~='autumn'][data-motion='reduce']::before,
|
|
74
|
+
:root[data-finish~='autumn'][data-motion='reduce']::after { animation: none; }
|
|
75
|
+
@media print {
|
|
76
|
+
:root[data-finish~='autumn']::before,
|
|
77
|
+
:root[data-finish~='autumn']::after { display: none; }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@keyframes sinn-finish-autumn-fall {
|
|
82
|
+
0% { transform: translate3d(0, 0, 0); }
|
|
83
|
+
25% { transform: translate3d(2rem, calc(var(--sinn-finish-autumn-tile) * 0.25), 0); }
|
|
84
|
+
50% { transform: translate3d(0, calc(var(--sinn-finish-autumn-tile) * 0.5), 0); }
|
|
85
|
+
75% { transform: translate3d(-2rem, calc(var(--sinn-finish-autumn-tile) * 0.75), 0); }
|
|
86
|
+
100% { transform: translate3d(0, var(--sinn-finish-autumn-tile), 0); }
|
|
87
|
+
}
|