ampless 0.2.0-alpha.3 → 0.2.0-alpha.5
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 +30 -1
- package/dist/index.js +41 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -452,6 +452,13 @@ interface KvStore {
|
|
|
452
452
|
}
|
|
453
453
|
declare function setKvStore(s: KvStore): void;
|
|
454
454
|
declare function hasKvStore(): boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Access the injected `KvStore` directly. Use the site-setting helpers
|
|
457
|
+
* (`getSiteSetting` etc.) when storing per-site configuration; reach
|
|
458
|
+
* for this lower-level handle only when you need a different PK
|
|
459
|
+
* namespace (e.g. `mcp-tokens`).
|
|
460
|
+
*/
|
|
461
|
+
declare function getKvStore(): KvStore;
|
|
455
462
|
declare const SITE_CONFIG_PK: (siteId: string) => string;
|
|
456
463
|
declare function getSiteSetting<T = unknown>(siteId: string, key: string): Promise<T | null>;
|
|
457
464
|
declare function setSiteSetting(siteId: string, key: string, value: unknown): Promise<void>;
|
|
@@ -667,6 +674,28 @@ declare function themeSettingKey(fieldKey: string): string;
|
|
|
667
674
|
*
|
|
668
675
|
* Returns the normalized value, or null if the input is rejected.
|
|
669
676
|
*/
|
|
677
|
+
/**
|
|
678
|
+
* Split a stored color value into its light / dark components.
|
|
679
|
+
*
|
|
680
|
+
* Accepts two storage forms:
|
|
681
|
+
* - Single value: `oklch(...)` / `#abcdef` / etc. → `{ light: value, dark: null }`
|
|
682
|
+
* - Pair: `light-dark(L, D)` → `{ light: L, dark: D }`
|
|
683
|
+
*
|
|
684
|
+
* Splits on the top-level comma (depth-aware) so nested commas inside
|
|
685
|
+
* `rgb(...)` / `hsl(...)` don't trip the parser.
|
|
686
|
+
*/
|
|
687
|
+
declare function parseColorPair(value: string): {
|
|
688
|
+
light: string;
|
|
689
|
+
dark: string | null;
|
|
690
|
+
};
|
|
691
|
+
/**
|
|
692
|
+
* Build the storage string for a color field. When `dark` is non-empty
|
|
693
|
+
* and differs from `light`, returns `light-dark(light, dark)`; otherwise
|
|
694
|
+
* returns the bare `light` value. The runtime emits the result verbatim
|
|
695
|
+
* into the inline `:root { --foo: <value> }` override; `light-dark()`
|
|
696
|
+
* is a Baseline-2024 CSS function so the browser picks per mode.
|
|
697
|
+
*/
|
|
698
|
+
declare function formatColorPair(light: string, dark?: string | null): string;
|
|
670
699
|
declare function validateThemeValue(field: ThemeField, raw: unknown): string | null;
|
|
671
700
|
/** Parse a stored linkList JSON value into typed items. Tolerant: bad
|
|
672
701
|
* shapes resolve to []. Throwing here would cascade into rendering. */
|
|
@@ -690,4 +719,4 @@ declare function resolveThemeValues(manifest: ThemeManifest, stored: Record<stri
|
|
|
690
719
|
|
|
691
720
|
declare const VERSION = "0.0.1";
|
|
692
721
|
|
|
693
|
-
export { type AmplessEvent, type AmplessPlugin, type AuthContext, type Config, type ContentEventPayload, type ContentEventType, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_SITE_ID, type DateFormat, type EventPayloadOf, type EventType, type FieldDefinition, type FieldType, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type LocalizedString, type Media, type MediaEventPayload, type MediaEventType, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, type Page, type PluginEventHandler, type PluginMetadata, type PluginRuntimeContext, type Post, type PostMetadata, type PostStatus, type PostsProvider, type Role, SITE_CONFIG_PK, type SiteConfig, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StreamEventName, type ThemeColorField, type ThemeField, type ThemeFieldType, type ThemeFontFamilyField, type ThemeImageField, type ThemeLengthField, type ThemeLinkListField, type ThemeManifest, type ThemeModule, type ThemeRouteContext, type ThemeSelectField, type ThemeTextField, type TrustLevel, VERSION, composeSiteIdSlug, composeSiteIdStatus, createPost, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, escapeXml, extractFirstImageUrl, flattenSettings, formatDate, formatPublicAssetUrl, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isMultiSite, isTagListUrl, listPosts, listSiteSettings, parseLinkList, resolveLocalized, resolveSiteId, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, siteFor, stringifyLinkList, themeSettingKey, unflattenSettings, updatePost, validateThemeValue };
|
|
722
|
+
export { type AmplessEvent, type AmplessPlugin, type AuthContext, type Config, type ContentEventPayload, type ContentEventType, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_SITE_ID, type DateFormat, type EventPayloadOf, type EventType, type FieldDefinition, type FieldType, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type LocalizedString, type Media, type MediaEventPayload, type MediaEventType, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, type Page, type PluginEventHandler, type PluginMetadata, type PluginRuntimeContext, type Post, type PostMetadata, type PostStatus, type PostsProvider, type Role, SITE_CONFIG_PK, type SiteConfig, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StreamEventName, type ThemeColorField, type ThemeField, type ThemeFieldType, type ThemeFontFamilyField, type ThemeImageField, type ThemeLengthField, type ThemeLinkListField, type ThemeManifest, type ThemeModule, type ThemeRouteContext, type ThemeSelectField, type ThemeTextField, type TrustLevel, VERSION, composeSiteIdSlug, composeSiteIdStatus, createPost, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, escapeXml, extractFirstImageUrl, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isMultiSite, isTagListUrl, listPosts, listSiteSettings, parseColorPair, parseLinkList, resolveLocalized, resolveSiteId, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, siteFor, stringifyLinkList, themeSettingKey, unflattenSettings, updatePost, validateThemeValue };
|
package/dist/index.js
CHANGED
|
@@ -136,6 +136,9 @@ function requireStore() {
|
|
|
136
136
|
}
|
|
137
137
|
return store;
|
|
138
138
|
}
|
|
139
|
+
function getKvStore() {
|
|
140
|
+
return requireStore();
|
|
141
|
+
}
|
|
139
142
|
var SITE_CONFIG_PK = (siteId) => `siteconfig:${siteId}`;
|
|
140
143
|
async function getSiteSetting(siteId, key) {
|
|
141
144
|
return requireStore().get(SITE_CONFIG_PK(siteId), key);
|
|
@@ -325,14 +328,48 @@ function themeSettingKey(fieldKey) {
|
|
|
325
328
|
var COLOR_RE = /^(#[0-9a-fA-F]{3,8}|rgb\([^)]+\)|rgba\([^)]+\)|hsl\([^)]+\)|hsla\([^)]+\)|oklch\([^)]+\)|oklab\([^)]+\))$/;
|
|
326
329
|
var LENGTH_RE = /^[\d.]+(px|rem|em|%|vh|vw)$/;
|
|
327
330
|
var DANGEROUS_IMAGE_URL_RE = /^\s*(javascript|vbscript):/i;
|
|
331
|
+
function parseColorPair(value) {
|
|
332
|
+
const v = value.trim();
|
|
333
|
+
const prefix = "light-dark(";
|
|
334
|
+
if (!v.startsWith(prefix) || !v.endsWith(")")) {
|
|
335
|
+
return { light: value, dark: null };
|
|
336
|
+
}
|
|
337
|
+
const inner = v.slice(prefix.length, -1);
|
|
338
|
+
let depth = 0;
|
|
339
|
+
for (let i = 0; i < inner.length; i++) {
|
|
340
|
+
const ch = inner[i];
|
|
341
|
+
if (ch === "(") depth++;
|
|
342
|
+
else if (ch === ")") depth--;
|
|
343
|
+
else if (ch === "," && depth === 0) {
|
|
344
|
+
return {
|
|
345
|
+
light: inner.slice(0, i).trim(),
|
|
346
|
+
dark: inner.slice(i + 1).trim()
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return { light: value, dark: null };
|
|
351
|
+
}
|
|
352
|
+
function formatColorPair(light, dark) {
|
|
353
|
+
const l = light.trim();
|
|
354
|
+
const d = (dark ?? "").trim();
|
|
355
|
+
if (!d || d === l) return l;
|
|
356
|
+
return `light-dark(${l}, ${d})`;
|
|
357
|
+
}
|
|
328
358
|
function validateThemeValue(field, raw) {
|
|
329
359
|
if (field.type === "linkList") return validateLinkListValue(field, raw);
|
|
330
360
|
if (typeof raw !== "string") return null;
|
|
331
361
|
const v = raw.trim();
|
|
332
362
|
if (!v) return null;
|
|
333
363
|
switch (field.type) {
|
|
334
|
-
case "color":
|
|
364
|
+
case "color": {
|
|
365
|
+
if (v.startsWith("light-dark(")) {
|
|
366
|
+
const { light, dark } = parseColorPair(v);
|
|
367
|
+
if (dark === null) return null;
|
|
368
|
+
if (!COLOR_RE.test(light) || !COLOR_RE.test(dark)) return null;
|
|
369
|
+
return formatColorPair(light, dark);
|
|
370
|
+
}
|
|
335
371
|
return COLOR_RE.test(v) ? v : null;
|
|
372
|
+
}
|
|
336
373
|
case "length":
|
|
337
374
|
return LENGTH_RE.test(v) ? v : null;
|
|
338
375
|
case "image":
|
|
@@ -438,8 +475,10 @@ export {
|
|
|
438
475
|
escapeXml,
|
|
439
476
|
extractFirstImageUrl,
|
|
440
477
|
flattenSettings,
|
|
478
|
+
formatColorPair,
|
|
441
479
|
formatDate,
|
|
442
480
|
formatPublicAssetUrl,
|
|
481
|
+
getKvStore,
|
|
443
482
|
getPost,
|
|
444
483
|
getPostById,
|
|
445
484
|
getSiteSetting,
|
|
@@ -449,6 +488,7 @@ export {
|
|
|
449
488
|
isTagListUrl,
|
|
450
489
|
listPosts,
|
|
451
490
|
listSiteSettings,
|
|
491
|
+
parseColorPair,
|
|
452
492
|
parseLinkList,
|
|
453
493
|
resolveLocalized,
|
|
454
494
|
resolveSiteId,
|