@casoon/pages-theme 0.0.0-stage → 0.12.8

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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +279 -2
  3. package/assets/casoon-logo-dark.svg +70 -0
  4. package/assets/casoon-logo.svg +71 -0
  5. package/assets/favicon.svg +1 -0
  6. package/components/AnchorGrid.astro +135 -0
  7. package/components/ApiEntry.astro +136 -0
  8. package/components/Badge.astro +31 -0
  9. package/components/Badges.astro +10 -0
  10. package/components/BuildOutput.astro +84 -0
  11. package/components/Button.astro +55 -0
  12. package/components/CallToAction.astro +64 -0
  13. package/components/Callout.astro +66 -0
  14. package/components/CodeBlock.astro +84 -0
  15. package/components/Demo.astro +80 -0
  16. package/components/ExamplePanel.astro +153 -0
  17. package/components/Facts.astro +112 -0
  18. package/components/Faq.astro +123 -0
  19. package/components/Features.astro +139 -0
  20. package/components/FileSet.astro +258 -0
  21. package/components/Footer.astro +160 -0
  22. package/components/Header.astro +278 -0
  23. package/components/Hero.astro +318 -0
  24. package/components/Install.astro +154 -0
  25. package/components/Integrations.astro +125 -0
  26. package/components/Keymap.astro +102 -0
  27. package/components/Quickstart.astro +95 -0
  28. package/components/ReleaseHighlights.astro +115 -0
  29. package/components/Spotlight.astro +177 -0
  30. package/components/Swatch.astro +45 -0
  31. package/components/Tabs.astro +90 -0
  32. package/components/Terminal.astro +79 -0
  33. package/components/index.ts +25 -0
  34. package/content.ts +23 -0
  35. package/fonts/OFL.txt +95 -0
  36. package/fonts/inter-latin-400-normal.woff2 +0 -0
  37. package/fonts/inter-latin-500-normal.woff2 +0 -0
  38. package/fonts/inter-latin-600-normal.woff2 +0 -0
  39. package/fonts/jetbrains-mono-latin-400-normal.woff2 +0 -0
  40. package/fonts/jetbrains-mono-latin-500-normal.woff2 +0 -0
  41. package/fonts/onest-latin-wght-normal.woff2 +0 -0
  42. package/index.ts +204 -0
  43. package/layouts/Base.astro +131 -0
  44. package/layouts/Docs.astro +286 -0
  45. package/lib/ansi.ts +168 -0
  46. package/lib/changelog.ts +85 -0
  47. package/lib/docs.ts +54 -0
  48. package/lib/i18n.ts +136 -0
  49. package/lib/og.ts +91 -0
  50. package/lib/showcase.ts +48 -0
  51. package/lib/url.ts +16 -0
  52. package/lib/version.ts +50 -0
  53. package/package.json +71 -4
  54. package/routes/404.astro +49 -0
  55. package/routes/changelog.astro +129 -0
  56. package/routes/docs/[...slug].astro +39 -0
  57. package/routes/showcase/[slug].astro +108 -0
  58. package/routes/showcase/index.astro +195 -0
  59. package/styles/base.css +307 -0
  60. package/styles/fonts.css +52 -0
  61. package/styles/tokens.css +136 -0
  62. package/virtual.d.ts +12 -0
package/fonts/OFL.txt ADDED
@@ -0,0 +1,95 @@
1
+ Inter: Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+ Onest: Copyright 2021 The Onest Project Authors (https://github.com/simpals/onest)
3
+ JetBrains Mono: Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
4
+
5
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
6
+ This license is copied below, and is also available with a FAQ at:
7
+ http://scripts.sil.org/OFL
8
+
9
+
10
+ -----------------------------------------------------------
11
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
12
+ -----------------------------------------------------------
13
+
14
+ PREAMBLE
15
+ The goals of the Open Font License (OFL) are to stimulate worldwide
16
+ development of collaborative font projects, to support the font creation
17
+ efforts of academic and linguistic communities, and to provide a free and
18
+ open framework in which fonts may be shared and improved in partnership
19
+ with others.
20
+
21
+ The OFL allows the licensed fonts to be used, studied, modified and
22
+ redistributed freely as long as they are not sold by themselves. The
23
+ fonts, including any derivative works, can be bundled, embedded,
24
+ redistributed and/or sold with any software provided that any reserved
25
+ names are not used by derivative works. The fonts and derivatives,
26
+ however, cannot be released under any other type of license. The
27
+ requirement for fonts to remain under this license does not apply
28
+ to any document created using the fonts or their derivatives.
29
+
30
+ DEFINITIONS
31
+ "Font Software" refers to the set of files released by the Copyright
32
+ Holder(s) under this license and clearly marked as such. This may
33
+ include source files, build scripts and documentation.
34
+
35
+ "Reserved Font Name" refers to any names specified as such after the
36
+ copyright statement(s).
37
+
38
+ "Original Version" refers to the collection of Font Software components as
39
+ distributed by the Copyright Holder(s).
40
+
41
+ "Modified Version" refers to any derivative made by adding to, deleting,
42
+ or substituting -- in part or in whole -- any of the components of the
43
+ Original Version, by changing formats or by porting the Font Software to a
44
+ new environment.
45
+
46
+ "Author" refers to any designer, engineer, programmer, technical
47
+ writer or other person who contributed to the Font Software.
48
+
49
+ PERMISSION & CONDITIONS
50
+ Permission is hereby granted, free of charge, to any person obtaining
51
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
52
+ redistribute, and sell modified and unmodified copies of the Font
53
+ Software, subject to the following conditions:
54
+
55
+ 1) Neither the Font Software nor any of its individual components,
56
+ in Original or Modified Versions, may be sold by itself.
57
+
58
+ 2) Original or Modified Versions of the Font Software may be bundled,
59
+ redistributed and/or sold with any software, provided that each copy
60
+ contains the above copyright notice and this license. These can be
61
+ included either as stand-alone text files, human-readable headers or
62
+ in the appropriate machine-readable metadata fields within text or
63
+ binary files as long as those fields can be easily viewed by the user.
64
+
65
+ 3) No Modified Version of the Font Software may use the Reserved Font
66
+ Name(s) unless explicit written permission is granted by the corresponding
67
+ Copyright Holder. This restriction only applies to the primary font name as
68
+ presented to the users.
69
+
70
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
71
+ Software shall not be used to promote, endorse or advertise any
72
+ Modified Version, except to acknowledge the contribution(s) of the
73
+ Copyright Holder(s) and the Author(s) or with their explicit written
74
+ permission.
75
+
76
+ 5) The Font Software, modified or unmodified, in part or in whole,
77
+ must be distributed entirely under this license, and must not be
78
+ distributed under any other license. The requirement for fonts to
79
+ remain under this license does not apply to any document created
80
+ using the Font Software.
81
+
82
+ TERMINATION
83
+ This license becomes null and void if any of the above conditions are
84
+ not met.
85
+
86
+ DISCLAIMER
87
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
88
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
89
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
90
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
91
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
92
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
93
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
94
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
95
+ OTHER DEALINGS IN THE FONT SOFTWARE.
package/index.ts ADDED
@@ -0,0 +1,204 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { writeFile } from 'node:fs/promises';
3
+ import { resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import mdx from '@astrojs/mdx';
6
+ import type { AstroIntegration } from 'astro';
7
+ import type { Lang } from './lib/i18n';
8
+ import { renderOgImage } from './lib/og';
9
+ import { projectVersion } from './lib/version';
10
+
11
+ export interface PackageLink {
12
+ /** Label shown in the footer and as badge, e.g. "crates.io" or "npm". */
13
+ label: string;
14
+ href: string;
15
+ }
16
+
17
+ export interface CasoonPagesOptions {
18
+ /** Project name as shown in the header, e.g. "runemark". */
19
+ name: string;
20
+ /** One sentence; used as default meta description. */
21
+ description: string;
22
+ /** A few words for the start page's `<title>` and the OG image: "<name> – <tagline> | CASOON". */
23
+ tagline?: string;
24
+ /** The project's own landing page, e.g. "https://example.com". Linked in header and footer. */
25
+ website?: string;
26
+ /** Slug of the project's entry on casoon.dev (`#projekt-<slug>`), or false. Default: repository name. */
27
+ catalog?: string | false;
28
+ /** GitHub repository as "owner/name". Omit for a private repository: no GitHub or edit links. */
29
+ repo?: string;
30
+ /** Current release, shown in the header and on docs pages.
31
+ * Omitted: read from package.json or Cargo.toml next to site/. `false` shows none. */
32
+ version?: string | false;
33
+ /** SPDX licence identifier, or false for proprietary code (no licence named). Default: "MIT". */
34
+ license?: string | false;
35
+ /** Default branch, used for "Edit this page" links. Default: "main". */
36
+ branch?: string;
37
+ /** Project accent colour for light and dark theme. Default: CASOON petrol. Both must meet 4.5:1 on the page background. */
38
+ accent?: { light: string; dark: string };
39
+ /** Registry and API-doc links (crates.io, npm, docs.rs …). */
40
+ packages?: PackageLink[];
41
+ /** Docs sidebar groups: folder name in docs/ → label, in display order. Root-level pages join the first group. */
42
+ docsGroups?: Record<string, string>;
43
+ /** Path to the docs folder relative to the repository root, for edit links. Default: "docs". */
44
+ docsDir?: string;
45
+ /** Path to CHANGELOG.md relative to the site root, or false. Default: "../CHANGELOG.md". */
46
+ changelog?: string | false;
47
+ /** Module exporting `examples: ShowcaseExample[]`, relative to the site root, or false. Default: "./src/showcase.ts". */
48
+ showcase?: string | false;
49
+ /**
50
+ * Live demo: the header label linking to /demo/, or false for none. Default: false.
51
+ *
52
+ * The page itself belongs to the project (`src/pages/demo.astro`) and wraps its
53
+ * running instance in the `Demo` component — the theme only adds the entry.
54
+ */
55
+ demo?: string | false;
56
+ /**
57
+ * Module exporting `components: Record<string, AstroComponent>`, relative to the site
58
+ * root, for docs MDX next to the theme's own. `docs/` cannot import anything, so this
59
+ * is how a page reaches something only the site can build — a component rendering the
60
+ * project's own output, say. Same name as a theme component: the project's wins.
61
+ */
62
+ mdxComponents?: string;
63
+ /** Language of the theme's own UI strings and of `<html lang>`. Default: "en". */
64
+ lang?: Lang;
65
+ /** Lead paragraph of the showcase overview, instead of the theme's generic one. */
66
+ showcaseLead?: string;
67
+ }
68
+
69
+ export interface ResolvedConfig
70
+ extends Required<
71
+ Omit<
72
+ CasoonPagesOptions,
73
+ 'accent' | 'changelog' | 'showcase' | 'demo' | 'mdxComponents' | 'catalog'
74
+ >
75
+ > {
76
+ accent: { light: string; dark: string } | null;
77
+ /** Absolute path to CHANGELOG.md, or null when disabled. */
78
+ changelog: string | null;
79
+ hasShowcase: boolean;
80
+ /** Header label of the demo page, or an empty string when there is none. */
81
+ demo: string;
82
+ /** casoon.dev catalog slug, or an empty string when there is none. */
83
+ catalog: string;
84
+ }
85
+
86
+ const CONFIG_ID = 'virtual:casoon-pages/config';
87
+ const SHOWCASE_ID = 'virtual:casoon-pages/showcase';
88
+ const MDX_COMPONENTS_ID = 'virtual:casoon-pages/mdx-components';
89
+
90
+ export default function casoonPages(options: CasoonPagesOptions): AstroIntegration {
91
+ let resolved: ResolvedConfig;
92
+ /** Absolute URL of the site's base path, or null without `site`. */
93
+ let site: URL | null = null;
94
+ return {
95
+ name: '@casoon/pages-theme',
96
+ hooks: {
97
+ 'astro:config:setup': ({ config, updateConfig, injectRoute }) => {
98
+ site = config.site ? new URL(config.base.replace(/\/?$/, '/'), config.site) : null;
99
+ const root = fileURLToPath(config.root);
100
+ const showcasePath =
101
+ options.showcase === false
102
+ ? null
103
+ : resolve(root, options.showcase ?? './src/showcase.ts');
104
+
105
+ resolved = {
106
+ name: options.name,
107
+ description: options.description,
108
+ tagline: options.tagline ?? '',
109
+ website: options.website ?? '',
110
+ catalog:
111
+ options.catalog === false ? '' : (options.catalog ?? options.repo?.split('/')[1] ?? ''),
112
+ repo: options.repo ?? '',
113
+ version:
114
+ options.version === false
115
+ ? ''
116
+ : (options.version ?? projectVersion(resolve(root, '..'))),
117
+ license: options.license ?? 'MIT',
118
+ branch: options.branch ?? 'main',
119
+ accent: options.accent ?? null,
120
+ packages: options.packages ?? [],
121
+ docsGroups: options.docsGroups ?? {},
122
+ docsDir: options.docsDir ?? 'docs',
123
+ changelog:
124
+ options.changelog === false
125
+ ? null
126
+ : resolve(root, options.changelog ?? '../CHANGELOG.md'),
127
+ hasShowcase: showcasePath !== null,
128
+ demo: options.demo === false || options.demo === undefined ? '' : options.demo,
129
+ lang: options.lang ?? 'en',
130
+ showcaseLead: options.showcaseLead ?? '',
131
+ };
132
+
133
+ const route = (pattern: string, file: string) =>
134
+ injectRoute({ pattern, entrypoint: `@casoon/pages-theme/routes/${file}` });
135
+ route('/docs/[...slug]', 'docs/[...slug].astro');
136
+ if (resolved.hasShowcase) {
137
+ route('/showcase', 'showcase/index.astro');
138
+ route('/showcase/[slug]', 'showcase/[slug].astro');
139
+ }
140
+ if (resolved.changelog) route('/changelog', 'changelog.astro');
141
+ route('/404', '404.astro');
142
+
143
+ const modules: Record<string, string> = {
144
+ [CONFIG_ID]: `export default ${JSON.stringify(resolved)};`,
145
+ [SHOWCASE_ID]: showcasePath
146
+ ? `export { examples } from ${JSON.stringify(showcasePath)};`
147
+ : 'export const examples = [];',
148
+ [MDX_COMPONENTS_ID]: options.mdxComponents
149
+ ? `export { components } from ${JSON.stringify(resolve(root, options.mdxComponents))};`
150
+ : 'export const components = {};',
151
+ };
152
+
153
+ updateConfig({
154
+ integrations: [mdx()],
155
+ markdown: { shikiConfig: { theme: 'css-variables' } },
156
+ vite: {
157
+ plugins: [
158
+ {
159
+ name: 'casoon-pages-virtual',
160
+ resolveId: (id: string) => (id in modules ? `\0${id}` : undefined),
161
+ load: (id: string) =>
162
+ id.startsWith('\0') && id.slice(1) in modules ? modules[id.slice(1)] : undefined,
163
+ },
164
+ ],
165
+ // docs/, examples/ and CHANGELOG.md live next to site/ in the project repository.
166
+ server: { fs: { allow: [resolve(root, '..')] } },
167
+ },
168
+ });
169
+ },
170
+ // Project pages may import the virtual modules too (`config.version` on a start page),
171
+ // so the declarations go into the project's generated types, not just the theme's.
172
+ 'astro:config:done': ({ injectTypes }) => {
173
+ injectTypes({
174
+ filename: 'virtual.d.ts',
175
+ content: readFileSync(new URL('./virtual.d.ts', import.meta.url), 'utf8').replace(
176
+ "'./index'",
177
+ "'@casoon/pages-theme'"
178
+ ),
179
+ });
180
+ },
181
+ // Sitemap and OG image need absolute URLs, so both depend on `site`.
182
+ 'astro:build:done': async ({ dir, pages }) => {
183
+ const base = site;
184
+ if (!base) return;
185
+ // A project that writes its own sitemap keeps it: this one is the fallback, not the
186
+ // authority. It only sees that file when the project's integration is listed first.
187
+ const sitemap = new URL('sitemap.xml', dir);
188
+ if (!existsSync(sitemap)) {
189
+ const urls = pages
190
+ .map((page) => page.pathname)
191
+ .filter((pathname) => pathname !== '404/')
192
+ .map((pathname) => ` <url><loc>${new URL(pathname, base).href}</loc></url>`);
193
+ await writeFile(
194
+ sitemap,
195
+ '<?xml version="1.0" encoding="UTF-8"?>\n' +
196
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
197
+ `${urls.join('\n')}\n</urlset>\n`
198
+ );
199
+ }
200
+ await writeFile(new URL('og.png', dir), await renderOgImage(resolved, base));
201
+ },
202
+ },
203
+ };
204
+ }
@@ -0,0 +1,131 @@
1
+ ---
2
+ import '../styles/fonts.css';
3
+ import '../styles/tokens.css';
4
+ import '../styles/base.css';
5
+ import config from 'virtual:casoon-pages/config';
6
+ import favicon from '../assets/favicon.svg';
7
+ import Footer from '../components/Footer.astro';
8
+ import Header from '../components/Header.astro';
9
+ import { t } from '../lib/i18n';
10
+ import { CASOON_URL, url } from '../lib/url';
11
+
12
+ interface Props {
13
+ /** Page title; the project name is appended. Omit on the home page. */
14
+ title?: string;
15
+ description?: string;
16
+ }
17
+
18
+ const { title, description = config.description } = Astro.props;
19
+ const s = t(config.lang);
20
+ const fullTitle = title
21
+ ? `${title} · ${config.name}`
22
+ : `${config.name}${config.tagline && ` – ${config.tagline}`} | CASOON`;
23
+ const canonical = Astro.site ? new URL(Astro.url.pathname, Astro.site).href : undefined;
24
+ // Written by the integration after the build (index.ts), so only with `site`.
25
+ const home = Astro.site && new URL(url(), Astro.site).href;
26
+ const ogImage = Astro.site && new URL(url('og.png'), Astro.site).href;
27
+ const sameAs = [config.website, ...config.packages.map((p) => p.href)].filter(Boolean);
28
+
29
+ // tokens.css sets --accent with the same selectors and is linked after this inline style, so the
30
+ // selectors repeat :root to outrank it whatever the order in <head> (scripts/test-accent.mjs).
31
+ const accentCss = config.accent
32
+ ? `:root:root{--accent:${config.accent.light}}` +
33
+ `:root:root[data-theme="dark"]{--accent:${config.accent.dark}}` +
34
+ `@media (prefers-color-scheme:dark){:root:root:not([data-theme="light"]){--accent:${config.accent.dark}}}`
35
+ : '';
36
+
37
+ const structuredData = {
38
+ '@context': 'https://schema.org',
39
+ '@type': 'SoftwareSourceCode',
40
+ name: config.name,
41
+ description: config.description,
42
+ ...(home && { url: home }),
43
+ ...(sameAs.length > 0 && { sameAs }),
44
+ ...(config.repo && { codeRepository: `https://github.com/${config.repo}` }),
45
+ ...(config.license && { license: `https://spdx.org/licenses/${config.license}.html` }),
46
+ ...(config.version && { version: config.version }),
47
+ author: { '@type': 'Person', name: 'Jörn Seidel', url: CASOON_URL },
48
+ publisher: { '@type': 'Organization', name: 'CASOON', url: CASOON_URL },
49
+ };
50
+ ---
51
+
52
+ <!doctype html>
53
+ <html lang={config.lang}>
54
+ <head>
55
+ <meta charset="utf-8" />
56
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
57
+ <title>{fullTitle}</title>
58
+ <meta name="description" content={description} />
59
+ {canonical && <link rel="canonical" href={canonical} />}
60
+ <meta property="og:type" content="website" />
61
+ <meta property="og:title" content={fullTitle} />
62
+ <meta property="og:description" content={description} />
63
+ {canonical && <meta property="og:url" content={canonical} />}
64
+ {
65
+ ogImage && (
66
+ <>
67
+ <meta property="og:image" content={ogImage} />
68
+ <meta property="og:image:width" content="1200" />
69
+ <meta property="og:image:height" content="630" />
70
+ <meta property="og:image:alt" content={`${config.name} – ${config.tagline || config.description}`} />
71
+ <meta name="twitter:card" content="summary_large_image" />
72
+ <link rel="sitemap" href={url('sitemap.xml')} />
73
+ </>
74
+ )
75
+ }
76
+ <link rel="icon" href={favicon.src} type="image/svg+xml" />
77
+ {accentCss && <style is:inline set:html={accentCss} />}
78
+ <script is:inline>
79
+ // Theme before first paint: stored choice, else system preference.
80
+ (() => {
81
+ let theme = null;
82
+ try {
83
+ theme = localStorage.getItem('casoon-pages-theme');
84
+ } catch {}
85
+ if (theme !== 'dark' && theme !== 'light') {
86
+ theme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
87
+ }
88
+ document.documentElement.dataset.theme = theme;
89
+ })();
90
+ </script>
91
+ <script is:inline type="application/ld+json" set:html={JSON.stringify(structuredData)} />
92
+ </head>
93
+ <body>
94
+ <a class="skip-link" href="#main">{s.skipLink}</a>
95
+ <Header />
96
+ <main id="main">
97
+ <slot />
98
+ </main>
99
+ <Footer />
100
+ <script is:inline>
101
+ (() => {
102
+ const root = document.documentElement;
103
+ for (const button of document.querySelectorAll('[data-theme-toggle]')) {
104
+ button.hidden = false;
105
+ button.setAttribute('aria-pressed', String(root.dataset.theme === 'dark'));
106
+ button.addEventListener('click', () => {
107
+ const theme = root.dataset.theme === 'dark' ? 'light' : 'dark';
108
+ root.dataset.theme = theme;
109
+ button.setAttribute('aria-pressed', String(theme === 'dark'));
110
+ try {
111
+ localStorage.setItem('casoon-pages-theme', theme);
112
+ } catch {}
113
+ });
114
+ }
115
+ if (!navigator.clipboard) return;
116
+ for (const button of document.querySelectorAll('[data-copy]')) {
117
+ button.hidden = false;
118
+ const label = button.textContent;
119
+ button.addEventListener('click', async () => {
120
+ const source = document.getElementById(button.dataset.copy);
121
+ await navigator.clipboard.writeText(source.textContent.trim());
122
+ button.textContent = button.dataset.copied;
123
+ setTimeout(() => {
124
+ button.textContent = label;
125
+ }, 1600);
126
+ });
127
+ }
128
+ })();
129
+ </script>
130
+ </body>
131
+ </html>