@ampless/runtime 0.2.0-alpha.5 → 0.2.0-alpha.6
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/dist/index.d.ts +27 -1
- package/dist/index.js +12 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -109,6 +109,22 @@ interface ThemeActiveApi {
|
|
|
109
109
|
resolveActiveTheme(siteId?: string): Promise<ResolvedTheme>;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
type ColorScheme = 'auto' | 'light' | 'dark';
|
|
113
|
+
declare const DEFAULT_COLOR_SCHEME: ColorScheme;
|
|
114
|
+
/**
|
|
115
|
+
* Storage key for the per-site color-scheme override. Lives under the
|
|
116
|
+
* same `theme.*` namespace as manifest fields so it flows through the
|
|
117
|
+
* existing KvStore → S3 cache pipeline, but is read separately from
|
|
118
|
+
* the manifest field set (it's a site-wide concern, not theme-specific).
|
|
119
|
+
*/
|
|
120
|
+
declare const COLOR_SCHEME_SETTING_KEY = "theme.colorScheme";
|
|
121
|
+
/**
|
|
122
|
+
* Narrow an arbitrary stored value to a known `ColorScheme`. Anything
|
|
123
|
+
* unrecognised (including `undefined`, malformed strings, accidental
|
|
124
|
+
* objects) falls back to `'auto'` so a typo never strands a site
|
|
125
|
+
* forced into a mode it can't undo.
|
|
126
|
+
*/
|
|
127
|
+
declare function validateColorScheme(raw: unknown): ColorScheme;
|
|
112
128
|
interface EffectiveThemeConfig {
|
|
113
129
|
/** Resolved active theme name (e.g. 'blog'). */
|
|
114
130
|
activeTheme: string;
|
|
@@ -117,6 +133,16 @@ interface EffectiveThemeConfig {
|
|
|
117
133
|
values: Record<string, string>;
|
|
118
134
|
/** Subset of `values` for fields that have a `cssVar`. */
|
|
119
135
|
cssVars: Record<string, string>;
|
|
136
|
+
/**
|
|
137
|
+
* Per-site color-scheme override. `'auto'` (default) lets the
|
|
138
|
+
* visitor's system `prefers-color-scheme` decide; `'light'` /
|
|
139
|
+
* `'dark'` pin one mode regardless of system preference.
|
|
140
|
+
*
|
|
141
|
+
* Consumed by the root layout to set `<html data-color-scheme>`,
|
|
142
|
+
* which the theme tokens.css files key off in combination with the
|
|
143
|
+
* `light-dark()` CSS function.
|
|
144
|
+
*/
|
|
145
|
+
colorScheme: ColorScheme;
|
|
120
146
|
}
|
|
121
147
|
interface ThemeConfigApi {
|
|
122
148
|
loadThemeConfig(siteId?: string): Promise<EffectiveThemeConfig>;
|
|
@@ -204,4 +230,4 @@ interface Ampless {
|
|
|
204
230
|
*/
|
|
205
231
|
declare function createAmpless(opts: CreateAmplessOpts): Ampless;
|
|
206
232
|
|
|
207
|
-
export { type Ampless, type AmplessOutputs, type CreateAmplessOpts, type DataOutput, type EffectiveSiteSettings, type EffectiveThemeConfig, type ListPostsByTagOptions, type ListPostsOptions, type ListPostsResult, type PostsApi, type PublicPostConnectionShape, type PublicPostShape, type ResolvedTheme, type SeoApi, type SiteSettingsApi, type StorageOutput, type ThemeActiveApi, type ThemeConfigApi, type ThemesRegistry, createAmpless, htmlToMarkdown, markdownToHtml, renderBody, renderThemeCss, tiptapToHtml, tiptapToMarkdown };
|
|
233
|
+
export { type Ampless, type AmplessOutputs, COLOR_SCHEME_SETTING_KEY, type ColorScheme, type CreateAmplessOpts, DEFAULT_COLOR_SCHEME, type DataOutput, type EffectiveSiteSettings, type EffectiveThemeConfig, type ListPostsByTagOptions, type ListPostsOptions, type ListPostsResult, type PostsApi, type PublicPostConnectionShape, type PublicPostShape, type ResolvedTheme, type SeoApi, type SiteSettingsApi, type StorageOutput, type ThemeActiveApi, type ThemeConfigApi, type ThemesRegistry, createAmpless, htmlToMarkdown, markdownToHtml, renderBody, renderThemeCss, tiptapToHtml, tiptapToMarkdown, validateColorScheme };
|
package/dist/index.js
CHANGED
|
@@ -240,6 +240,12 @@ import {
|
|
|
240
240
|
resolveThemeValues,
|
|
241
241
|
themeSettingKey
|
|
242
242
|
} from "ampless";
|
|
243
|
+
var DEFAULT_COLOR_SCHEME = "auto";
|
|
244
|
+
var COLOR_SCHEME_SETTING_KEY = "theme.colorScheme";
|
|
245
|
+
function validateColorScheme(raw) {
|
|
246
|
+
if (raw === "light" || raw === "dark" || raw === "auto") return raw;
|
|
247
|
+
return DEFAULT_COLOR_SCHEME;
|
|
248
|
+
}
|
|
243
249
|
function createThemeConfig(themeActive, storage) {
|
|
244
250
|
async function fetchRemote(siteId) {
|
|
245
251
|
if (!storage.isStorageConfigured()) return null;
|
|
@@ -269,7 +275,8 @@ function createThemeConfig(themeActive, storage) {
|
|
|
269
275
|
}
|
|
270
276
|
const values = resolveThemeValues(manifest, stored);
|
|
271
277
|
const cssVars = collectCssVars(manifest.fields, values);
|
|
272
|
-
|
|
278
|
+
const colorScheme = validateColorScheme(flat?.[COLOR_SCHEME_SETTING_KEY]);
|
|
279
|
+
return { activeTheme: active.name, manifest, values, cssVars, colorScheme };
|
|
273
280
|
}
|
|
274
281
|
};
|
|
275
282
|
}
|
|
@@ -533,11 +540,14 @@ function createAmpless(opts) {
|
|
|
533
540
|
};
|
|
534
541
|
}
|
|
535
542
|
export {
|
|
543
|
+
COLOR_SCHEME_SETTING_KEY,
|
|
544
|
+
DEFAULT_COLOR_SCHEME,
|
|
536
545
|
createAmpless,
|
|
537
546
|
htmlToMarkdown,
|
|
538
547
|
markdownToHtml,
|
|
539
548
|
renderBody,
|
|
540
549
|
renderThemeCss,
|
|
541
550
|
tiptapToHtml,
|
|
542
|
-
tiptapToMarkdown
|
|
551
|
+
tiptapToMarkdown,
|
|
552
|
+
validateColorScheme
|
|
543
553
|
};
|
package/package.json
CHANGED