ampless 0.2.0-alpha.2 → 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 +48 -2
- package/dist/index.js +37 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -166,7 +166,31 @@ interface AmplessPlugin {
|
|
|
166
166
|
}
|
|
167
167
|
declare function definePlugin(p: AmplessPlugin): AmplessPlugin;
|
|
168
168
|
|
|
169
|
-
type ContentFormat = 'tiptap' | 'markdown' | 'html';
|
|
169
|
+
type ContentFormat = 'tiptap' | 'markdown' | 'html' | 'static';
|
|
170
|
+
/**
|
|
171
|
+
* Body shape for `format: 'static'` posts. The actual asset bytes
|
|
172
|
+
* live under S3 at `public/static/<siteId>/<slug>/<files...>` — the
|
|
173
|
+
* body here is the manifest describing which entrypoint to serve and
|
|
174
|
+
* which files are part of the bundle.
|
|
175
|
+
*
|
|
176
|
+
* Stored as JSON in the `body` column (same encoding pattern as the
|
|
177
|
+
* tiptap doc / html string / markdown string for the other formats).
|
|
178
|
+
*
|
|
179
|
+
* Hard constraint enforced at upload time: every asset must reference
|
|
180
|
+
* other assets in the bundle by **relative path** only. Absolute paths
|
|
181
|
+
* (`/foo`) and protocol-relative paths (`//cdn.example/foo`) inside
|
|
182
|
+
* referenced HTML / CSS are rejected so a bundle stays portable across
|
|
183
|
+
* any URL prefix without rewriting at serve time. See the admin's
|
|
184
|
+
* StaticUploader for the validation logic.
|
|
185
|
+
*/
|
|
186
|
+
interface StaticPostBody {
|
|
187
|
+
/** Relative path to the entrypoint inside the bundle (default 'index.html'). */
|
|
188
|
+
entrypoint: string;
|
|
189
|
+
/** Every file in the bundle (relative paths). Used for delete cleanup and admin display. */
|
|
190
|
+
files: string[];
|
|
191
|
+
/** ISO 8601 timestamp of the most recent upload. */
|
|
192
|
+
uploadedAt: string;
|
|
193
|
+
}
|
|
170
194
|
type PostStatus = 'draft' | 'published';
|
|
171
195
|
/**
|
|
172
196
|
* Free-form per-post metadata. The `metadata` JSON column carries
|
|
@@ -643,6 +667,28 @@ declare function themeSettingKey(fieldKey: string): string;
|
|
|
643
667
|
*
|
|
644
668
|
* Returns the normalized value, or null if the input is rejected.
|
|
645
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;
|
|
646
692
|
declare function validateThemeValue(field: ThemeField, raw: unknown): string | null;
|
|
647
693
|
/** Parse a stored linkList JSON value into typed items. Tolerant: bad
|
|
648
694
|
* shapes resolve to []. Throwing here would cascade into rendering. */
|
|
@@ -666,4 +712,4 @@ declare function resolveThemeValues(manifest: ThemeManifest, stored: Record<stri
|
|
|
666
712
|
|
|
667
713
|
declare const VERSION = "0.0.1";
|
|
668
714
|
|
|
669
|
-
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 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,
|