ampless 0.2.0-alpha.3 → 0.2.0-alpha.4

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 CHANGED
@@ -667,6 +667,28 @@ declare function themeSettingKey(fieldKey: string): string;
667
667
  *
668
668
  * Returns the normalized value, or null if the input is rejected.
669
669
  */
670
+ /**
671
+ * Split a stored color value into its light / dark components.
672
+ *
673
+ * Accepts two storage forms:
674
+ * - Single value: `oklch(...)` / `#abcdef` / etc. → `{ light: value, dark: null }`
675
+ * - Pair: `light-dark(L, D)` → `{ light: L, dark: D }`
676
+ *
677
+ * Splits on the top-level comma (depth-aware) so nested commas inside
678
+ * `rgb(...)` / `hsl(...)` don't trip the parser.
679
+ */
680
+ declare function parseColorPair(value: string): {
681
+ light: string;
682
+ dark: string | null;
683
+ };
684
+ /**
685
+ * Build the storage string for a color field. When `dark` is non-empty
686
+ * and differs from `light`, returns `light-dark(light, dark)`; otherwise
687
+ * returns the bare `light` value. The runtime emits the result verbatim
688
+ * into the inline `:root { --foo: <value> }` override; `light-dark()`
689
+ * is a Baseline-2024 CSS function so the browser picks per mode.
690
+ */
691
+ declare function formatColorPair(light: string, dark?: string | null): string;
670
692
  declare function validateThemeValue(field: ThemeField, raw: unknown): string | null;
671
693
  /** Parse a stored linkList JSON value into typed items. Tolerant: bad
672
694
  * shapes resolve to []. Throwing here would cascade into rendering. */
@@ -690,4 +712,4 @@ declare function resolveThemeValues(manifest: ThemeManifest, stored: Record<stri
690
712
 
691
713
  declare const VERSION = "0.0.1";
692
714
 
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 };
715
+ 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, 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
@@ -325,14 +325,48 @@ function themeSettingKey(fieldKey) {
325
325
  var COLOR_RE = /^(#[0-9a-fA-F]{3,8}|rgb\([^)]+\)|rgba\([^)]+\)|hsl\([^)]+\)|hsla\([^)]+\)|oklch\([^)]+\)|oklab\([^)]+\))$/;
326
326
  var LENGTH_RE = /^[\d.]+(px|rem|em|%|vh|vw)$/;
327
327
  var DANGEROUS_IMAGE_URL_RE = /^\s*(javascript|vbscript):/i;
328
+ function parseColorPair(value) {
329
+ const v = value.trim();
330
+ const prefix = "light-dark(";
331
+ if (!v.startsWith(prefix) || !v.endsWith(")")) {
332
+ return { light: value, dark: null };
333
+ }
334
+ const inner = v.slice(prefix.length, -1);
335
+ let depth = 0;
336
+ for (let i = 0; i < inner.length; i++) {
337
+ const ch = inner[i];
338
+ if (ch === "(") depth++;
339
+ else if (ch === ")") depth--;
340
+ else if (ch === "," && depth === 0) {
341
+ return {
342
+ light: inner.slice(0, i).trim(),
343
+ dark: inner.slice(i + 1).trim()
344
+ };
345
+ }
346
+ }
347
+ return { light: value, dark: null };
348
+ }
349
+ function formatColorPair(light, dark) {
350
+ const l = light.trim();
351
+ const d = (dark ?? "").trim();
352
+ if (!d || d === l) return l;
353
+ return `light-dark(${l}, ${d})`;
354
+ }
328
355
  function validateThemeValue(field, raw) {
329
356
  if (field.type === "linkList") return validateLinkListValue(field, raw);
330
357
  if (typeof raw !== "string") return null;
331
358
  const v = raw.trim();
332
359
  if (!v) return null;
333
360
  switch (field.type) {
334
- case "color":
361
+ case "color": {
362
+ if (v.startsWith("light-dark(")) {
363
+ const { light, dark } = parseColorPair(v);
364
+ if (dark === null) return null;
365
+ if (!COLOR_RE.test(light) || !COLOR_RE.test(dark)) return null;
366
+ return formatColorPair(light, dark);
367
+ }
335
368
  return COLOR_RE.test(v) ? v : null;
369
+ }
336
370
  case "length":
337
371
  return LENGTH_RE.test(v) ? v : null;
338
372
  case "image":
@@ -438,6 +472,7 @@ export {
438
472
  escapeXml,
439
473
  extractFirstImageUrl,
440
474
  flattenSettings,
475
+ formatColorPair,
441
476
  formatDate,
442
477
  formatPublicAssetUrl,
443
478
  getPost,
@@ -449,6 +484,7 @@ export {
449
484
  isTagListUrl,
450
485
  listPosts,
451
486
  listSiteSettings,
487
+ parseColorPair,
452
488
  parseLinkList,
453
489
  resolveLocalized,
454
490
  resolveSiteId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ampless",
3
- "version": "0.2.0-alpha.3",
3
+ "version": "0.2.0-alpha.4",
4
4
  "description": "Serverless CMS for AWS Amplify",
5
5
  "license": "MIT",
6
6
  "type": "module",